workos

package
v0.0.0-...-0397b96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is an APIError with a 404 status code.

Types

type APIError

type APIError struct {
	Method     string
	Path       string
	StatusCode int
	Body       string
}

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).

func (*APIError) Error

func (e *APIError) Error() string

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

func (wc *Client) CreateRole(ctx context.Context, orgID string, opts CreateRoleOpts) (*Role, error)

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

func (wc *Client) DeleteOrganizationMembership(ctx context.Context, membershipID string) error

DeleteOrganizationMembership deletes an organization membership by ID.

func (*Client) DeleteRole

func (wc *Client) DeleteRole(ctx context.Context, orgID string, roleSlug string) error

DeleteRole deletes a role by slug via the WorkOS REST API.

func (*Client) FindInvitationByToken

func (wc *Client) FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)

FindInvitationByToken resolves an invitation from its token. Returns an error matching IsNotFound when the token does not match any invitation.

func (*Client) GetInvitation

func (wc *Client) GetInvitation(ctx context.Context, invitationID string) (*Invitation, error)

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) GetUser

func (wc *Client) GetUser(ctx context.Context, userID string) (*User, error)

GetUser returns a WorkOS user by ID.

func (*Client) GetUserByEmail

func (wc *Client) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail returns the first WorkOS user for the given email.

func (*Client) ListInvitations

func (wc *Client) ListInvitations(ctx context.Context, orgID string) ([]Invitation, error)

ListInvitations returns all invitations for an organization.

func (*Client) ListMembers

func (wc *Client) ListMembers(ctx context.Context, orgID string) ([]Member, error)

ListMembers lists all active organization memberships for the given org.

func (*Client) ListOrgMemberships

func (wc *Client) ListOrgMemberships(ctx context.Context, orgID string) ([]Member, error)

ListOrgMemberships returns all organization memberships for an org.

func (*Client) ListOrgUsers

func (wc *Client) ListOrgUsers(ctx context.Context, orgID string) (map[string]User, error)

ListOrgUsers returns all users in the given organization as a map of userID → User.

func (*Client) ListRoles

func (wc *Client) ListRoles(ctx context.Context, orgID string) ([]Role, error)

func (*Client) ListUserMemberships

func (wc *Client) ListUserMemberships(ctx context.Context, userID string) ([]Member, error)

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

func (wc *Client) ListUsersInOrg(ctx context.Context, orgID string) ([]User, error)

ListUsersInOrg returns all users in the given organization.

func (*Client) ResendInvitation

func (wc *Client) ResendInvitation(ctx context.Context, invitationID string) (*Invitation, error)

ResendInvitation resends an invitation by ID.

func (*Client) RevokeInvitation

func (wc *Client) RevokeInvitation(ctx context.Context, invitationID string) (*Invitation, error)

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 CreateRoleOpts struct {
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Description string `json:"description"`
}

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 SendInvitationOpts struct {
	Email          string `json:"email"`
	OrganizationID string `json:"organization_id,omitempty"`
	ExpiresInDays  int    `json:"expires_in_days,omitempty"`
	InviterUserID  string `json:"inviter_user_id,omitempty"`
	RoleSlug       string `json:"role_slug,omitempty"`
}

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 (s *StubClient) DeleteRole(_ context.Context, orgID string, roleSlug string) error

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 (s *StubClient) GetOrgMembership(_ context.Context, workOSUserID, workOSOrgID string) (*Member, error)

func (*StubClient) GetUser

func (s *StubClient) GetUser(_ context.Context, userID string) (*User, error)

func (*StubClient) ListInvitations

func (s *StubClient) ListInvitations(_ context.Context, orgID string) ([]Invitation, error)

func (*StubClient) ListMembers

func (s *StubClient) ListMembers(_ context.Context, orgID string) ([]Member, error)

func (*StubClient) ListOrgMemberships

func (s *StubClient) ListOrgMemberships(_ context.Context, orgID string) ([]Member, error)

func (*StubClient) ListOrgUsers

func (s *StubClient) ListOrgUsers(_ context.Context, orgID string) (map[string]User, error)

func (*StubClient) ListRoles

func (s *StubClient) ListRoles(_ context.Context, orgID string) ([]Role, error)

func (*StubClient) ListUsersInOrg

func (s *StubClient) ListUsersInOrg(_ context.Context, orgID string) ([]User, error)

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 (s *StubClient) UpdateMemberRole(_ context.Context, membershipID string, roleSlug string) (*Member, error)

func (*StubClient) UpdateRole

func (s *StubClient) UpdateRole(_ context.Context, orgID string, roleSlug string, opts UpdateRoleOpts) (*Role, error)

type UpdateRoleOpts

type UpdateRoleOpts struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
}

type User

type User struct {
	ID        string
	FirstName string
	LastName  string
	Email     string
}

User represents a WorkOS user with the fields used by Gram.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL