@letsgo/tenant
This package consolidates functions for managing LetsGo tenants, users, and users' memberhips in tenants, including invitations. It also support management of tenant's subscriptions and keeping track of changes in subscription plans.
- AddIdentityToTenantOptions
- CreateInvitationOptions
- CreateTenantOptions
- DeleteInvitationOptions
- DeleteTenantOptions
- GetIdentitiesOfTenantOptions
- GetInvitationOptions
- GetInvitationsOptions
- GetTenantOptions
- GetTenantsOfIdentityOptions
- Invitation
- IsIdentityInTenantOptions
- PutTenantOptions
- RemoveIdentityFromTenantOptions
- SubscriptionPlan
- SubscriptionPlanChange
- Tenant
- addIdentityToTenant
- createInvitation
- createTenant
- deleteInvitation
- deleteTenant
- getIdentitiesOfTenant
- getInvitation
- getInvitations
- getTenant
- getTenantsOfIdentity
- isIdentityInTenant
- putTenant
- reconcileSubscriptionStatus
- removeIdentityFromTenant
- setNewPlan
• Const
IdentityTenantCategory: "letsgo-identity-tenant"
The database category for items representing a specific tenant's users.
• Const
InvitationCategory: "letsgo-invitation"
The database category for items representing invitations for a specific tenant.
• Const
TenantCategory: "letsgo-tenant"
The database category for items representing LetsGo tenants.
• Const
TenantIdentityCategory: "letsgo-tenant-identity"
The database category for items representing a specific user's access to tenants.
▸ addIdentityToTenant(options
): Promise
<void
>
Adds a new user to a tenant.
Name | Type | Description |
---|---|---|
options |
AddIdentityToTenantOptions |
Options for adding the user. |
Promise
<void
>
▸ createInvitation(options
): Promise
<Invitation
>
Create an invitation to join a tenant.
Name | Type | Description |
---|---|---|
options |
CreateInvitationOptions |
Options for creating the invitation. |
Promise
<Invitation
>
New invitation
▸ createTenant(options
): Promise
<Tenant
>
Creates a new tenant. The new tenant has a unique ID and is associated with the DefaultPlanId
subscription plan defined in the @letsgo/pricing package.
Name | Type | Description |
---|---|---|
options |
CreateTenantOptions |
Options for creating the tenant. |
Promise
<Tenant
>
The newly created tenant.
▸ deleteInvitation(options
): Promise
<void
>
Revoke an inviation to join a tenant.
Name | Type | Description |
---|---|---|
options |
DeleteInvitationOptions |
Options for deleting the invitation. |
Promise
<void
>
▸ deleteTenant(options
): Promise
<Tenant
| undefined
>
Deletes a tenant. No data is removed from the database, but the tenant is marked as deleted.
Name | Type | Description |
---|---|---|
options |
DeleteTenantOptions |
Options for deleting the tenant. |
Promise
<Tenant
| undefined
>
The deleted tenant, or undefined if the tenant was alrady deleted or does not exist.
▸ getIdentitiesOfTenant(options
): Promise
<Identity
[]>
Get users who are members of a specific tenant.
Name | Type | Description |
---|---|---|
options |
GetIdentitiesOfTenantOptions |
Options for getting the users. |
Promise
<Identity
[]>
Array of users who are members of the tenant.
▸ getInvitation(options
): Promise
<Invitation
| undefined
>
Gets an existing invitation to join a tenant.
Name | Type | Description |
---|---|---|
options |
GetInvitationOptions |
Options for getting the invitation. |
Promise
<Invitation
| undefined
>
The invitation if it exists and has not expired, undefined otherwise.
▸ getInvitations(options
): Promise
<Invitation
[]>
Returns all active, non-expired invitations for a given tenant.
Name | Type | Description |
---|---|---|
options |
GetInvitationsOptions |
Options for getting the invitations. |
Promise
<Invitation
[]>
Array of active invitations.
▸ getTenant(options
): Promise
<Tenant
| undefined
>
Get an existing tenant. If the tenant is deleted, it is returned only if options.includeDeleted
is true.
Name | Type | Description |
---|---|---|
options |
GetTenantOptions |
Options for getting the tenant. |
Promise
<Tenant
| undefined
>
The tenant if it exists and is not deleted, undefined otherwise.
▸ getTenantsOfIdentity(options
): Promise
<Tenant
[]>
Get tenants a specific user has access to.
Name | Type | Description |
---|---|---|
options |
GetTenantsOfIdentityOptions |
Options for getting the tenants. |
Promise
<Tenant
[]>
Array of tenants the user has access to.
▸ isIdentityInTenant(options
): Promise
<boolean
>
Checks if a user is a member of a tenant.
Name | Type | Description |
---|---|---|
options |
IsIdentityInTenantOptions |
Options for checking the membership. |
Promise
<boolean
>
True if the user is member of the tenant, false otherwise.
▸ putTenant(options
): Promise
<Tenant
>
Update a tenant.
Name | Type | Description |
---|---|---|
options |
PutTenantOptions |
Options for updating the tenant. |
Promise
<Tenant
>
The updated tenant.
▸ reconcileSubscriptionStatus(tenant
, identity
): Promise
<Tenant
| undefined
>
Update the status of the Stripe subscription for a LetsGo tenant based on the source of truth in Stripe.
Name | Type | Description |
---|---|---|
tenant |
Tenant |
LetsGo tenant to update the subscription status for. |
identity |
Identity |
The idenantity of the user who triggered the update. |
Promise
<Tenant
| undefined
>
The updated tenant if the subscription status changed, undefined if there were no changes in status.
▸ removeIdentityFromTenant(options
): Promise
<void
>
Removes a user from a tenant.
Name | Type | Description |
---|---|---|
options |
RemoveIdentityFromTenantOptions |
Options for removing the user. |
Promise
<void
>
▸ setNewPlan(tenant
, planId
, identity
): void
Update the tenant with a new plan ID and record the change.
Name | Type | Description |
---|---|---|
tenant |
Tenant |
The tenant to update. |
planId |
string |
The new plan ID. |
identity |
Identity |
The identity of the user who made the change. |
void