|
| 1 | +/** |
| 2 | + * Types for the {@link AccountsModule | accounts} module (multi-tenancy). |
| 3 | + * |
| 4 | + * An Account groups the app's end-users into an isolated tenant (a company, |
| 5 | + * team, or organization). Users join accounts via membership and act inside one |
| 6 | + * active account at a time. Account-scoped entities are transparently isolated |
| 7 | + * to the active account (carried by the `X-Active-Account-Id` header, derived |
| 8 | + * from the `/<account_id>/...` URL path). |
| 9 | + */ |
| 10 | + |
| 11 | +/** Account-management role. Distinct from the app's business roles. */ |
| 12 | +export type AccountRole = "owner" | "admin" | "member"; |
| 13 | + |
| 14 | +/** Assignable (non-owner) role used for invites/role changes. */ |
| 15 | +export type AssignableAccountRole = "admin" | "member"; |
| 16 | + |
| 17 | +export type AccountStatus = "active" | "suspended"; |
| 18 | +export type AccountMembershipStatus = "pending" | "active"; |
| 19 | + |
| 20 | +/** An account (tenant) within the app. */ |
| 21 | +export interface Account { |
| 22 | + id: string; |
| 23 | + app_id: string; |
| 24 | + name: string; |
| 25 | + status: AccountStatus; |
| 26 | + plan_id?: string | null; |
| 27 | + billing_status?: string; |
| 28 | + /** The current user's role in this account (present on `listMine()` results). */ |
| 29 | + my_role?: AccountRole; |
| 30 | + /** Builder-defined custom fields. */ |
| 31 | + data?: Record<string, unknown>; |
| 32 | + created_date?: string; |
| 33 | +} |
| 34 | + |
| 35 | +/** The accounts the current user belongs to, plus the active one. */ |
| 36 | +export interface MyAccountsResponse { |
| 37 | + accounts: Account[]; |
| 38 | + active_account_id: string | null; |
| 39 | +} |
| 40 | + |
| 41 | +/** A user's membership in an account. */ |
| 42 | +export interface AccountMembership { |
| 43 | + id: string; |
| 44 | + account_id: string; |
| 45 | + email: string; |
| 46 | + role: AccountRole; |
| 47 | + status: AccountMembershipStatus; |
| 48 | +} |
| 49 | + |
| 50 | +/** A subscription plan/tier offered to accounts. */ |
| 51 | +export interface AccountPlan { |
| 52 | + id: string; |
| 53 | + name: string; |
| 54 | + description?: string | null; |
| 55 | + price_amount: number; |
| 56 | + currency: string; |
| 57 | + interval: "month" | "year"; |
| 58 | + is_active: boolean; |
| 59 | +} |
| 60 | + |
| 61 | +/** A provider checkout session. */ |
| 62 | +export interface CheckoutSession { |
| 63 | + url: string; |
| 64 | + session_id: string; |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * The accounts module — manage multi-tenancy ("Accounts") from inside the app. |
| 69 | + * |
| 70 | + * Access via `base44.accounts`. Available when the app has multi-tenancy enabled. |
| 71 | + */ |
| 72 | +export interface AccountsModule { |
| 73 | + /** The active account id, read from the current URL path (or `undefined`). */ |
| 74 | + getActiveAccountId(): string | undefined; |
| 75 | + /** |
| 76 | + * Switch the active account by navigating to its folder (`/<accountId>/...`). |
| 77 | + * A full navigation re-roots the app so all data follows the new account. |
| 78 | + * @param accountId - The account to switch to. |
| 79 | + * @param subPath - Optional in-account route to land on (defaults to the root). |
| 80 | + */ |
| 81 | + switchAccount(accountId: string, subPath?: string): void; |
| 82 | + /** List the accounts the current user belongs to, plus the active one. */ |
| 83 | + listMine(): Promise<MyAccountsResponse>; |
| 84 | + /** Create a new account; the current user becomes its owner. */ |
| 85 | + create(params: { name: string; data?: Record<string, unknown> }): Promise<Account>; |
| 86 | + /** Rename and/or update an account's custom fields (managers only). */ |
| 87 | + update( |
| 88 | + accountId: string, |
| 89 | + params: { name?: string; data?: Record<string, unknown> } |
| 90 | + ): Promise<Account>; |
| 91 | + /** List an account's members (any active member). */ |
| 92 | + listMembers(accountId: string): Promise<AccountMembership[]>; |
| 93 | + /** Invite a user by email to an account (managers only). */ |
| 94 | + invite( |
| 95 | + accountId: string, |
| 96 | + email: string, |
| 97 | + role?: AssignableAccountRole |
| 98 | + ): Promise<AccountMembership>; |
| 99 | + /** Accept a pending invite to an account for the current user. */ |
| 100 | + acceptInvite(accountId: string): Promise<AccountMembership>; |
| 101 | + /** Change a member's role (managers only; not for the owner). */ |
| 102 | + changeMemberRole( |
| 103 | + accountId: string, |
| 104 | + email: string, |
| 105 | + role: AssignableAccountRole |
| 106 | + ): Promise<AccountMembership>; |
| 107 | + /** Remove a member from an account (managers only; not the owner). */ |
| 108 | + removeMember(accountId: string, email: string): Promise<{ removed: boolean }>; |
| 109 | + /** Transfer ownership to another active member (owner only). */ |
| 110 | + transferOwnership( |
| 111 | + accountId: string, |
| 112 | + email: string |
| 113 | + ): Promise<{ transferred: boolean }>; |
| 114 | + /** Per-account billing. */ |
| 115 | + billing: { |
| 116 | + /** List the active plans available to this account. */ |
| 117 | + listPlans(accountId: string): Promise<AccountPlan[]>; |
| 118 | + /** Start a subscription checkout session for a plan. */ |
| 119 | + startCheckout( |
| 120 | + accountId: string, |
| 121 | + params: { plan_id: string; success_url: string; cancel_url: string } |
| 122 | + ): Promise<CheckoutSession>; |
| 123 | + }; |
| 124 | +} |
0 commit comments