API Reference
This comprehensive API reference covers all methods, types, and interfaces available in the Workspaces SDK.
WorkspacesSDK Class
Constructor
new WorkspacesSDK(config: WorkspacesSDKConfig)
Parameters:
config: Configuration object for the SDK
interface WorkspacesSDKConfig {
endpoint: string; // GraphQL API endpoint
accessToken?: string; // JWT access token
refreshToken?: string; // JWT refresh token
timeout?: number; // Request timeout in ms (default: 30000)
retries?: number; // Number of retry attempts (default: 3)
headers?: Record<string, string>; // Additional headers
}
Authentication Methods
setTokens(accessToken: string, refreshToken: string): void
clearTokens(): void
getTokens(): { accessToken?: string; refreshToken?: string }
setEndpoint(endpoint: string): void
getEndpoint(): string
Module Properties
readonly auth: AuthModule
readonly users: UserModule
readonly workspaces: WorkspaceModule
readonly rbac: RBACModule
readonly teams: TeamModule
readonly projects: ProjectModule
readonly resources: ResourceModule
readonly billing: BillingModule
readonly organizations: OrganizationModule
readonly payments: PaymentModule
readonly quotas: QuotaModule
AuthModule
Methods
register
register(input: RegisterInput): Promise<User>
Register a new user account.
verifyUser
verifyUser(input: VerifyUserInput): Promise<User>
Verify user email with verification token.
forgotPassword
forgotPassword(email: string): Promise<boolean>
Initiate password reset process.
resetPassword
resetPassword(input: ResetPasswordInput): Promise<boolean>
Reset password using reset token.
changePassword
changePassword(input: ChangePasswordInput): Promise<boolean>
Change user password (requires current password).
switchWorkspace
switchWorkspace(workspaceId: string): Promise<boolean>
Switch to a different workspace context.
switchProject
switchProject(projectId: string): Promise<boolean>
Switch to a different project context.
logout
logout(): Promise<boolean>
Logout user and invalidate tokens.
Types
interface RegisterInput {
email: string;
name: string;
password: string;
}
interface VerifyUserInput {
email: string;
token: string;
}
interface ResetPasswordInput {
token: string;
newPassword: string;
}
interface ChangePasswordInput {
currentPassword: string;
newPassword: string;
}
UserModule
Methods
getUser
getUser(input: GetUserInput): Promise<User | null>
Get user by ID or email.
editProfile
editProfile(input: EditProfileInput): Promise<User>
Update user profile information.
inviteUser
inviteUser(input: InviteUserInput): Promise<Invitation>
Send user invitation to workspace.
handleInvitation
handleInvitation(input: HandleInvitationInput): Promise<boolean>
Accept or reject user invitation.
Types
interface User {
id: string;
email: string;
name: string;
bio?: string;
avatar?: string;
preferences?: any;
createdAt: string;
updatedAt?: string;
}
interface GetUserInput {
id?: string;
email?: string;
}
interface EditProfileInput {
id: string;
name?: string;
bio?: string;
avatar?: string;
preferences?: any;
}
interface InviteUserInput {
email: string;
workspaceId: string;
role?: string;
message?: string;
}
interface HandleInvitationInput {
invitationId: string;
action: 'accept' | 'reject';
}
WorkspaceModule
Methods
getWorkspace
getWorkspace(id: string): Promise<Workspace | null>
Get workspace by ID.
getWorkspaces
getWorkspaces(): Promise<Workspace[]>
Get all user's workspaces.
createWorkspace
createWorkspace(input: CreateWorkspaceInput): Promise<Workspace>
Create new workspace.
updateWorkspace
updateWorkspace(input: UpdateWorkspaceInput): Promise<Workspace>
Update workspace information.
archiveWorkspace
archiveWorkspace(id: string): Promise<Workspace>
Archive workspace.
reactivateWorkspace
reactivateWorkspace(id: string): Promise<Workspace>
Reactivate archived workspace.
deleteWorkspace
deleteWorkspace(id: string): Promise<boolean>
Permanently delete workspace.
getWorkspaceMembers
getWorkspaceMembers(workspaceId: string): Promise<WorkspaceMember[]>
Get workspace members.
Types
interface Workspace {
id: string;
name: string;
description?: string;
ownerId: string;
members?: WorkspaceMember[];
settings?: WorkspaceSettings;
createdAt: string;
updatedAt?: string;
archivedAt?: string;
}
interface WorkspaceMember {
id: string;
workspaceId: string;
userId: string;
role: string;
joinedAt: string;
user: {
id: string;
email: string;
name: string;
};
}
interface CreateWorkspaceInput {
name: string;
description?: string;
settings?: WorkspaceSettings;
}
interface UpdateWorkspaceInput {
id: string;
name?: string;
description?: string;
settings?: WorkspaceSettings;
}
RBACModule
Methods
checkPermission
checkPermission(input: CheckPermissionInput): Promise<boolean>
Check if user has specific permission.
checkMultiplePermissions
checkMultiplePermissions(input: CheckMultiplePermissionsInput): Promise<PermissionCheck[]>
Check multiple permissions at once.
getRoles
getRoles(): Promise<Role[]>
Get all available roles.
getRole
getRole(id: string): Promise<Role | null>
Get role by ID.
createRole
createRole(input: CreateRoleInput): Promise<Role>
Create new role.
updateRole
updateRole(input: UpdateRoleInput): Promise<Role>
Update role information.
deleteRole
deleteRole(id: string): Promise<boolean>
Delete role.
assignRoleToUser
assignRoleToUser(input: AssignRoleInput): Promise<boolean>
Assign role to user.
removeRoleFromUser
removeRoleFromUser(input: RemoveRoleInput): Promise<boolean>
Remove role from user.
getUserRoles
getUserRoles(userId: string): Promise<UserRole[]>
Get user's roles.
assignPermissionToRole
assignPermissionToRole(input: AssignPermissionToRoleInput): Promise<boolean>
Assign permission to role.
assignPermissionToUser
assignPermissionToUser(input: AssignPermissionToUserInput): Promise<boolean>
Assign permission directly to user.
Types
interface Role {
id: string;
name: string;
description?: string;
permissions?: Permission[];
isSystem: boolean;
createdAt: string;
updatedAt?: string;
}
interface Permission {
id: string;
name: string;
description?: string;
resource?: string;
action?: string;
conditions?: any;
}
interface CheckPermissionInput {
userId: string;
permission: string;
resourceId?: string;
conditions?: any;
}
interface CreateRoleInput {
name: string;
description?: string;
permissions?: string[];
}
interface AssignRoleInput {
userId: string;
roleId: string;
resourceId?: string;
conditions?: any;
}
TeamModule
Methods
createTeam
createTeam(input: CreateTeamInput): Promise<Team>
Create new team.
getTeam
getTeam(id: string): Promise<Team | null>
Get team by ID.
getTeamsByWorkspace
getTeamsByWorkspace(workspaceId: string): Promise<Team[]>
Get teams in workspace.
updateTeam
updateTeam(input: UpdateTeamInput): Promise<Team>
Update team information.
deleteTeam
deleteTeam(id: string): Promise<boolean>
Delete team.
archiveTeam
archiveTeam(id: string): Promise<Team>
Archive team.
reactivateTeam
reactivateTeam(id: string): Promise<Team>
Reactivate archived team.
addUserToTeam
addUserToTeam(input: AddUserToTeamInput): Promise<TeamMember>
Add user to team.
removeUserFromTeam
removeUserFromTeam(input: RemoveUserFromTeamInput): Promise<boolean>
Remove user from team.
getTeamMembers
getTeamMembers(teamId: string): Promise<TeamMember[]>
Get team members.
assignRoleToTeam
assignRoleToTeam(input: AssignRoleToTeamInput): Promise<boolean>
Assign role to team.
getTeamRoles
getTeamRoles(teamId: string): Promise<TeamRole[]>
Get team roles.
Types
interface Team {
id: string;
name: string;
description?: string;
workspaceId: string;
ownerId: string;
members?: TeamMember[];
createdAt: string;
updatedAt?: string;
archivedAt?: string;
}
interface TeamMember {
id: string;
teamId: string;
userId: string;
role: string;
joinedAt: string;
user: {
id: string;
email: string;
name: string;
};
}
interface CreateTeamInput {
name: string;
description?: string;
workspaceId: string;
}
interface AddUserToTeamInput {
teamId: string;
userId: string;
role?: string;
}
ProjectModule
Methods
createProject
createProject(input: CreateProjectInput): Promise<Project>
Create new project.
getProject
getProject(id: string): Promise<Project | null>
Get project by ID with members.
editProject
editProject(input: EditProjectInput): Promise<Project>
Update project information.
archiveProject
archiveProject(id: string): Promise<Project>
Archive project.
unarchiveProject
unarchiveProject(id: string): Promise<Project>
Unarchive project.
getWorkspaceProjects
getWorkspaceProjects(workspaceIDs: string[]): Promise<WorkspaceProjects[]>
Get projects from multiple workspaces.
getProjectMembers
getProjectMembers(projectId: string): Promise<ProjectMember[]>
Get project members.
updateProjectMemberRole
updateProjectMemberRole(input: UpdateProjectMemberRoleInput): Promise<ProjectMember>
Update project member role.
removeProjectMember
removeProjectMember(input: RemoveProjectMemberInput): Promise<boolean>
Remove member from project.
Types
interface Project {
id: string;
name: string;
workspaceID: string;
ownerID: string;
createdAt: string;
updatedAt?: string;
archivedAt?: string;
members?: ProjectMember[];
}
interface ProjectMember {
id: string;
projectID: string;
userID: string;
role: string;
addedAt?: string;
updatedAt?: string;
user: {
id: string;
email: string;
name: string;
};
}
interface CreateProjectInput {
name: string;
workspaceID: string;
}
interface EditProjectInput {
id: string;
name?: string;
}
interface UpdateProjectMemberRoleInput {
projectID: string;
userID: string;
role: string;
}
ResourceModule
Methods
getResources
getResources(): Promise<Resource[]>
Get all resources.
getResource
getResource(id: string): Promise<Resource | null>
Get resource by ID.
createResource
createResource(input: CreateResourceInput): Promise<Resource>
Create new resource.
updateResource
updateResource(input: UpdateResourceInput): Promise<Resource>
Update resource.
deleteResource
deleteResource(id: string): Promise<boolean>
Delete resource.
getResourceByIdentifier
getResourceByIdentifier(identifier: string): Promise<Resource | null>
Get resource by identifier.
getResourceTypes
getResourceTypes(): Promise<ResourceType[]>
Get all resource types.
getResourceType
getResourceType(id: string): Promise<ResourceType | null>
Get resource type by ID.
createResourceType
createResourceType(input: CreateResourceTypeInput): Promise<ResourceType>
Create new resource type.
getResourceTypeByName
getResourceTypeByName(name: string): Promise<ResourceType | null>
Get resource type by name.
Types
interface Resource {
id: string;
name: string;
resourceTypeId: string;
identifier: string;
description?: string;
attributes?: any;
createdAt: string;
updatedAt?: string;
}
interface ResourceType {
id: string;
name: string;
description?: string;
schema?: any;
createdAt: string;
updatedAt?: string;
}
interface CreateResourceInput {
name: string;
resourceTypeId: string;
identifier: string;
description?: string;
attributes?: any;
}
interface CreateResourceTypeInput {
name: string;
description?: string;
schema?: any;
}
BillingModule
Methods
createBillingAccount
createBillingAccount(input: CreateBillingAccountInput): Promise<BillingAccount>
Create new billing account.
updateBillingAccount
updateBillingAccount(input: UpdateBillingAccountInput): Promise<BillingAccount>
Update billing account.
getBillingAccountDetails
getBillingAccountDetails(id: string): Promise<BillingAccount | null>
Get billing account details.
getWorkspaceBillingAccounts
getWorkspaceBillingAccounts(workspaceID: string): Promise<BillingAccount[]>
Get billing accounts for workspace.
getBillingAccountTransactions
getBillingAccountTransactions(billingAccountID: string): Promise<BillingTransaction[]>
Get billing transactions.
getBillingAccountCreditTransactions
getBillingAccountCreditTransactions(billingAccountID: string): Promise<CreditTransaction[]>
Get credit transactions.
spendCredits
spendCredits(input: SpendCreditsInput): Promise<boolean>
Spend credits from account.
addUsage
addUsage(input: AddUsageInput): Promise<boolean>
Add usage to billing account.
Types
interface BillingAccount {
id: string;
workspaceID: string;
name?: string;
email?: string;
currency?: string;
credits: number;
creditUsage: number;
createdAt: string;
updatedAt?: string;
}
interface BillingTransaction {
id: string;
billingAccountID: string;
amount: number;
currency: string;
type: string;
description?: string;
status: string;
createdAt: string;
updatedAt?: string;
}
interface CreateBillingAccountInput {
workspaceID: string;
name?: string;
email?: string;
currency?: string;
}
interface SpendCreditsInput {
billingAccountID: string;
credits: number;
description?: string;
}
OrganizationModule
Methods
createOrganization
createOrganization(input: CreateOrganizationInput): Promise<Organization>
Create new organization.
getOrganization
getOrganization(id: string): Promise<Organization | null>
Get organization by ID.
getOrganizations
getOrganizations(): Promise<Organization[]>
Get all organizations.
updateOrganization
updateOrganization(input: UpdateOrganizationInput): Promise<Organization>
Update organization.
deleteOrganizations
deleteOrganizations(ids: string[]): Promise<boolean>
Delete multiple organizations.
Types
interface Organization {
id: string;
name: string;
description?: string;
domain?: string;
settings?: any;
createdAt: string;
updatedAt?: string;
}
interface CreateOrganizationInput {
name: string;
description?: string;
domain?: string;
settings?: any;
}
PaymentModule
Methods
createRazorpayOrder
createRazorpayOrder(input: CreateRazorpayOrderInput): Promise<PaymentOrder>
Create Razorpay payment order.
createStripeOrder
createStripeOrder(input: CreateStripeOrderInput): Promise<PaymentOrder>
Create Stripe payment order.
getPaymentOrder
getPaymentOrder(id: string): Promise<PaymentOrder | null>
Get payment order details.
subscribeProduct
subscribeProduct(input: SubscribeProductInput): Promise<Subscription>
Subscribe to product.
getSubscription
getSubscription(id: string): Promise<Subscription | null>
Get subscription details.
getBillingAccountSubscriptions
getBillingAccountSubscriptions(billingAccountID: string): Promise<Subscription[]>
Get subscriptions for billing account.
Types
interface PaymentOrder {
id: string;
billingAccountID: string;
amount: number;
currency: string;
provider: string;
providerOrderId: string;
status: string;
description?: string;
metadata?: any;
createdAt: string;
updatedAt?: string;
}
interface Subscription {
id: string;
billingAccountID: string;
productId: string;
planId: string;
status: string;
currentPeriodStart: string;
currentPeriodEnd: string;
quantity: number;
amount: number;
currency: string;
createdAt: string;
updatedAt?: string;
}
interface CreateRazorpayOrderInput {
billingAccountID: string;
amount: number;
currency?: string;
description?: string;
metadata?: any;
}
interface SubscribeProductInput {
billingAccountID: string;
productId: string;
planId: string;
quantity?: number;
metadata?: any;
}
QuotaModule
Methods
createQuota
createQuota(input: CreateQuotaInput): Promise<Quota>
Create new quota.
updateQuota
updateQuota(input: UpdateQuotaInput): Promise<Quota>
Update quota.
getAllQuotas
getAllQuotas(): Promise<Quota[]>
Get all quotas.
getQuota
getQuota(id: string): Promise<Quota | null>
Get quota by ID.
checkQuotaExhausted
checkQuotaExhausted(input: CheckQuotaExhaustedInput): Promise<boolean>
Check if quota is exhausted.
getQuotaUsageAndLimit
getQuotaUsageAndLimit(quotaId: string, resourceId: string): Promise<QuotaUsage | null>
Get quota usage and limit.
getQuotaUsageDetails
getQuotaUsageDetails(resourceId: string): Promise<QuotaUsage[]>
Get detailed quota usage.
Types
interface Quota {
id: string;
name: string;
description?: string;
type: string;
limit: number;
period?: string;
unit?: string;
createdAt: string;
updatedAt?: string;
}
interface QuotaUsage {
quotaId: string;
resourceId: string;
used: number;
limit: number;
percentage: number;
periodStart?: string;
periodEnd?: string;
}
interface CreateQuotaInput {
name: string;
description?: string;
type: string;
limit: number;
period?: string;
unit?: string;
}
interface CheckQuotaExhaustedInput {
quotaId: string;
resourceId: string;
requestedAmount?: number;
}
Common Types
Pagination
interface PaginationInput {
limit?: number;
offset?: number;
cursor?: string;
}
interface PaginationResult<T> {
items: T[];
totalCount: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
cursor?: string;
}
Sorting
interface SortInput {
field: string;
direction: 'ASC' | 'DESC';
}
Filter
interface FilterInput {
field: string;
operator: 'EQ' | 'NE' | 'GT' | 'GTE' | 'LT' | 'LTE' | 'IN' | 'NOT_IN' | 'CONTAINS' | 'STARTS_WITH';
value: any;
}
Error Types
interface SDKError extends Error {
code: string;
statusCode?: number;
details?: any;
}
// Common error codes
const ERROR_CODES = {
AUTHENTICATION_FAILED: 'AUTHENTICATION_FAILED',
AUTHORIZATION_DENIED: 'AUTHORIZATION_DENIED',
RESOURCE_NOT_FOUND: 'RESOURCE_NOT_FOUND',
VALIDATION_ERROR: 'VALIDATION_ERROR',
QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',
RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
NETWORK_ERROR: 'NETWORK_ERROR',
TIMEOUT_ERROR: 'TIMEOUT_ERROR',
UNKNOWN_ERROR: 'UNKNOWN_ERROR'
} as const;
Configuration
Environment Variables
// Supported environment variables
WORKSPACES_API_ENDPOINT // Default API endpoint
WORKSPACES_ACCESS_TOKEN // Default access token
WORKSPACES_REFRESH_TOKEN // Default refresh token
WORKSPACES_TIMEOUT // Default request timeout
WORKSPACES_RETRIES // Default retry attempts
SDK Options
interface SDKOptions {
// Logging
enableLogging?: boolean;
logLevel?: 'debug' | 'info' | 'warn' | 'error';
// Caching
enableCaching?: boolean;
cacheStrategy?: 'memory' | 'localStorage' | 'custom';
cacheTTL?: number;
// Request configuration
timeout?: number;
retries?: number;
retryDelay?: number;
// Custom headers
headers?: Record<string, string>;
// Interceptors
requestInterceptor?: (config: any) => any;
responseInterceptor?: (response: any) => any;
errorInterceptor?: (error: any) => any;
}
This API reference provides comprehensive documentation of all available methods, types, and configuration options in the Workspaces SDK.