Documentation
¶
Index ¶
- func IsNotFound(err error) bool
- type APIError
- type Client
- func (wc *Client) CreateRole(ctx context.Context, orgID string, opts CreateRoleOpts) (*Role, error)
- func (wc *Client) DeleteOrganizationMembership(ctx context.Context, membershipID string) error
- func (wc *Client) DeleteRole(ctx context.Context, orgID string, roleSlug string) error
- func (wc *Client) FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
- func (wc *Client) GetInvitation(ctx context.Context, invitationID string) (*Invitation, error)
- func (wc *Client) GetOrgMembership(ctx context.Context, workOSUserID, workOSOrgID string) (*Member, error)
- func (wc *Client) GetUser(ctx context.Context, userID string) (*User, error)
- func (wc *Client) GetUserByEmail(ctx context.Context, email string) (*User, error)
- func (wc *Client) ListInvitations(ctx context.Context, orgID string) ([]Invitation, error)
- func (wc *Client) ListMembers(ctx context.Context, orgID string) ([]Member, error)
- func (wc *Client) ListOrgMemberships(ctx context.Context, orgID string) ([]Member, error)
- func (wc *Client) ListOrgUsers(ctx context.Context, orgID string) (map[string]User, error)
- func (wc *Client) ListRoles(ctx context.Context, orgID string) ([]Role, error)
- func (wc *Client) ListUserMemberships(ctx context.Context, userID string) ([]Member, error)
- func (wc *Client) ListUsersInOrg(ctx context.Context, orgID string) ([]User, error)
- func (wc *Client) ResendInvitation(ctx context.Context, invitationID string) (*Invitation, error)
- func (wc *Client) RevokeInvitation(ctx context.Context, invitationID string) (*Invitation, error)
- func (wc *Client) SendInvitation(ctx context.Context, opts SendInvitationOpts) (*Invitation, error)
- func (wc *Client) UpdateMemberRole(ctx context.Context, membershipID string, roleSlug string) (*Member, error)
- func (wc *Client) UpdateRole(ctx context.Context, orgID string, roleSlug string, opts UpdateRoleOpts) (*Role, error)
- type ClientOpts
- type CreateRoleOpts
- type Invitation
- type InvitationState
- type Member
- type Role
- type SendInvitationOpts
- type StubClient
- func (s *StubClient) CreateRole(_ context.Context, orgID string, opts CreateRoleOpts) (*Role, error)
- func (s *StubClient) DeleteOrganizationMembership(_ context.Context, membershipID string) error
- func (s *StubClient) DeleteRole(_ context.Context, orgID string, roleSlug string) error
- func (s *StubClient) FindInvitationByToken(_ context.Context, token string) (*Invitation, error)
- func (s *StubClient) GetInvitation(_ context.Context, invitationID string) (*Invitation, error)
- func (s *StubClient) GetOrgMembership(_ context.Context, workOSUserID, workOSOrgID string) (*Member, error)
- func (s *StubClient) GetUser(_ context.Context, userID string) (*User, error)
- func (s *StubClient) ListInvitations(_ context.Context, orgID string) ([]Invitation, error)
- func (s *StubClient) ListMembers(_ context.Context, orgID string) ([]Member, error)
- func (s *StubClient) ListOrgMemberships(_ context.Context, orgID string) ([]Member, error)
- func (s *StubClient) ListOrgUsers(_ context.Context, orgID string) (map[string]User, error)
- func (s *StubClient) ListRoles(_ context.Context, orgID string) ([]Role, error)
- func (s *StubClient) ListUsersInOrg(_ context.Context, orgID string) ([]User, error)
- func (s *StubClient) ResendInvitation(_ context.Context, invitationID string) (*Invitation, error)
- func (s *StubClient) RevokeInvitation(_ context.Context, invitationID string) (*Invitation, error)
- func (s *StubClient) SendInvitation(_ context.Context, opts SendInvitationOpts) (*Invitation, error)
- func (s *StubClient) UpdateMemberRole(_ context.Context, membershipID string, roleSlug string) (*Member, error)
- func (s *StubClient) UpdateRole(_ context.Context, orgID string, roleSlug string, opts UpdateRoleOpts) (*Role, error)
- type UpdateRoleOpts
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err is an APIError with a 404 status code.
Types ¶
type APIError ¶
APIError is returned by do when the WorkOS API responds with a 4xx or 5xx status. Callers can use errors.As to inspect the StatusCode for specific handling (e.g. 409 conflict).
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps WorkOS API calls for role and membership management. It is designed to have a caching layer added later.
func NewClient ¶
func NewClient(guardianPolicy *guardian.Policy, apiKey string, opts ...ClientOpts) *Client
func (*Client) CreateRole ¶
CreateRole creates a custom role for an organization via the WorkOS REST API. The Go SDK does not expose role CRUD, so we use raw HTTP against the /authorization/ endpoints.
func (*Client) DeleteOrganizationMembership ¶
DeleteOrganizationMembership deletes an organization membership by ID.
func (*Client) DeleteRole ¶
DeleteRole deletes a role by slug via the WorkOS REST API.
func (*Client) FindInvitationByToken ¶
FindInvitationByToken resolves an invitation from its token. Returns an error matching IsNotFound when the token does not match any invitation.
func (*Client) GetInvitation ¶
GetInvitation returns an invitation by ID. Returns an error matching IsNotFound when the invitation does not exist.
func (*Client) GetOrgMembership ¶
func (wc *Client) GetOrgMembership(ctx context.Context, workOSUserID, workOSOrgID string) (*Member, error)
GetOrgMembership returns the first membership matching a user and organization.
func (*Client) GetUserByEmail ¶
GetUserByEmail returns the first WorkOS user for the given email.
func (*Client) ListInvitations ¶
ListInvitations returns all invitations for an organization.
func (*Client) ListMembers ¶
ListMembers lists all active organization memberships for the given org.
func (*Client) ListOrgMemberships ¶
ListOrgMemberships returns all organization memberships for an org.
func (*Client) ListOrgUsers ¶
ListOrgUsers returns all users in the given organization as a map of userID → User.
func (*Client) ListUserMemberships ¶
ListUserMemberships returns all organization memberships for a user across all orgs. This is more efficient than calling GetOrgMembership per org since it batches the lookup.
func (*Client) ListUsersInOrg ¶
ListUsersInOrg returns all users in the given organization.
func (*Client) ResendInvitation ¶
ResendInvitation resends an invitation by ID.
func (*Client) RevokeInvitation ¶
RevokeInvitation revokes an invitation by ID.
func (*Client) SendInvitation ¶
func (wc *Client) SendInvitation(ctx context.Context, opts SendInvitationOpts) (*Invitation, error)
SendInvitation creates an invitation for a user to join an organization.
func (*Client) UpdateMemberRole ¶
func (wc *Client) UpdateMemberRole(ctx context.Context, membershipID string, roleSlug string) (*Member, error)
UpdateMemberRole changes a member's role within an organization membership.
func (*Client) UpdateRole ¶
func (wc *Client) UpdateRole(ctx context.Context, orgID string, roleSlug string, opts UpdateRoleOpts) (*Role, error)
UpdateRole updates a role by slug via the WorkOS REST API (PATCH).
type ClientOpts ¶
type ClientOpts struct {
// Endpoint overrides the WorkOS base URL for both raw HTTP and SDK calls.
Endpoint string
// HTTPClient overrides the default retryable HTTP client.
HTTPClient *guardian.HTTPClient
}
ClientOpts configures optional overrides for New. Zero values use production defaults. Primarily used in tests.
type CreateRoleOpts ¶
type Invitation ¶
type Invitation struct {
ID string
Email string
State InvitationState
AcceptedAt string
RevokedAt string
Token string
AcceptInvitationURL string
OrganizationID string
InviterUserID string
ExpiresAt string
CreatedAt string
UpdatedAt string
}
Invitation represents a WorkOS invitation with the fields used by Gram.
type InvitationState ¶
type InvitationState string
const ( InvitationStatePending InvitationState = "pending" InvitationStateAccepted InvitationState = "accepted" InvitationStateExpired InvitationState = "expired" InvitationStateRevoked InvitationState = "revoked" )
type Member ¶
type Member struct {
ID string
UserID string
OrganizationID string
Organization string
RoleSlug string
Status string
CreatedAt string
UpdatedAt string
}
Member represents an active organization membership. RoleSlug is the slug of the member's assigned role.
type Role ¶
type Role struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Role represents an organization role as returned by WorkOS.
type SendInvitationOpts ¶
type StubClient ¶
type StubClient struct {
// contains filtered or unexported fields
}
func NewStubClient ¶
func NewStubClient() *StubClient
func (*StubClient) CreateRole ¶
func (s *StubClient) CreateRole(_ context.Context, orgID string, opts CreateRoleOpts) (*Role, error)
func (*StubClient) DeleteOrganizationMembership ¶
func (s *StubClient) DeleteOrganizationMembership(_ context.Context, membershipID string) error
func (*StubClient) DeleteRole ¶
func (*StubClient) FindInvitationByToken ¶
func (s *StubClient) FindInvitationByToken(_ context.Context, token string) (*Invitation, error)
func (*StubClient) GetInvitation ¶
func (s *StubClient) GetInvitation(_ context.Context, invitationID string) (*Invitation, error)
func (*StubClient) GetOrgMembership ¶
func (*StubClient) ListInvitations ¶
func (s *StubClient) ListInvitations(_ context.Context, orgID string) ([]Invitation, error)
func (*StubClient) ListMembers ¶
func (*StubClient) ListOrgMemberships ¶
func (*StubClient) ListOrgUsers ¶
func (*StubClient) ListUsersInOrg ¶
func (*StubClient) ResendInvitation ¶
func (s *StubClient) ResendInvitation(_ context.Context, invitationID string) (*Invitation, error)
func (*StubClient) RevokeInvitation ¶
func (s *StubClient) RevokeInvitation(_ context.Context, invitationID string) (*Invitation, error)
func (*StubClient) SendInvitation ¶
func (s *StubClient) SendInvitation(_ context.Context, opts SendInvitationOpts) (*Invitation, error)
func (*StubClient) UpdateMemberRole ¶
func (*StubClient) UpdateRole ¶
func (s *StubClient) UpdateRole(_ context.Context, orgID string, roleSlug string, opts UpdateRoleOpts) (*Role, error)