@base44-preview/sdk 0.8.31-pr.178.837440f → 0.8.31-pr.178.d362125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/accounts.js +11 -17
- package/dist/modules/accounts.types.d.ts +50 -3
- package/package.json +1 -1
package/dist/modules/accounts.js
CHANGED
|
@@ -36,12 +36,21 @@ export function createAccountsModule(axios, appId) {
|
|
|
36
36
|
return;
|
|
37
37
|
window.location.reload();
|
|
38
38
|
},
|
|
39
|
+
setActiveAccount(accountId) {
|
|
40
|
+
setStoredActiveAccountId(appId, accountId);
|
|
41
|
+
},
|
|
39
42
|
clearActiveAccount() {
|
|
40
43
|
setStoredActiveAccountId(appId, null);
|
|
41
44
|
},
|
|
42
45
|
async listMine() {
|
|
43
46
|
return axios.get(`${base}/me`);
|
|
44
47
|
},
|
|
48
|
+
async getPublicAccount(slug) {
|
|
49
|
+
return axios.get(`${base}/public/by-slug/${enc(slug)}`);
|
|
50
|
+
},
|
|
51
|
+
async joinAccount(slug) {
|
|
52
|
+
return axios.post(`${base}/by-slug/${enc(slug)}/join`, {});
|
|
53
|
+
},
|
|
45
54
|
async create(params) {
|
|
46
55
|
return axios.post(base, params);
|
|
47
56
|
},
|
|
@@ -75,23 +84,8 @@ export function createAccountsModule(axios, appId) {
|
|
|
75
84
|
return axios.get(`${base}/${id}/billing/plans`);
|
|
76
85
|
},
|
|
77
86
|
async getSubscription(accountId) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// resolves the active account id — fetch it once and reuse it.
|
|
81
|
-
const mine = await axios.get(`${base}/me`);
|
|
82
|
-
const id = (_b = (_a = accountId !== null && accountId !== void 0 ? accountId : getStoredActiveAccountId(appId)) !== null && _a !== void 0 ? _a : mine.active_account_id) !== null && _b !== void 0 ? _b : undefined;
|
|
83
|
-
if (!id) {
|
|
84
|
-
throw new Error("No active account: pass an accountId, or have the user select or create an account first.");
|
|
85
|
-
}
|
|
86
|
-
const plans = await axios.get(`${base}/${id}/billing/plans`);
|
|
87
|
-
const account = (_c = mine.accounts.find((a) => a.id === id)) !== null && _c !== void 0 ? _c : null;
|
|
88
|
-
const planId = (_d = account === null || account === void 0 ? void 0 : account.plan_id) !== null && _d !== void 0 ? _d : null;
|
|
89
|
-
return {
|
|
90
|
-
account_id: id,
|
|
91
|
-
plan_id: planId,
|
|
92
|
-
billing_status: (_e = account === null || account === void 0 ? void 0 : account.billing_status) !== null && _e !== void 0 ? _e : "none",
|
|
93
|
-
plan: planId ? (_f = plans.find((p) => p.id === planId)) !== null && _f !== void 0 ? _f : null : null,
|
|
94
|
-
};
|
|
87
|
+
const id = await resolveAccountId(accountId);
|
|
88
|
+
return axios.get(`${base}/${id}/billing/subscription`);
|
|
95
89
|
},
|
|
96
90
|
async startCheckout(accountIdOrParams, maybeParams) {
|
|
97
91
|
const explicitId = typeof accountIdOrParams === "string" ? accountIdOrParams : undefined;
|
|
@@ -32,6 +32,17 @@ export interface MyAccountsResponse {
|
|
|
32
32
|
accounts: Account[];
|
|
33
33
|
active_account_id: string | null;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Public, unauthenticated view of an account (its landing page), resolved by
|
|
37
|
+
* slug. Carries identity plus only the builder-designated public custom fields.
|
|
38
|
+
*/
|
|
39
|
+
export interface PublicAccount {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
slug: string | null;
|
|
43
|
+
/** Builder-flagged public companion fields (e.g. logo, tagline). */
|
|
44
|
+
data: Record<string, unknown>;
|
|
45
|
+
}
|
|
35
46
|
/** A user's membership in an account. */
|
|
36
47
|
export interface AccountMembership {
|
|
37
48
|
id: string;
|
|
@@ -68,8 +79,18 @@ export interface AccountSubscription {
|
|
|
68
79
|
plan_id: string | null;
|
|
69
80
|
/** Lifecycle status: "none" | "active" | "past_due" | "canceled". */
|
|
70
81
|
billing_status: string;
|
|
71
|
-
/** The
|
|
82
|
+
/** The payment rail backing the subscription, or `null`. */
|
|
83
|
+
billing_provider: string | null;
|
|
84
|
+
/** The current plan, or `null` when the account has no subscription. */
|
|
72
85
|
plan: AccountPlan | null;
|
|
86
|
+
/** When the current paid period ends / renews (ISO 8601), or `null`. */
|
|
87
|
+
current_period_end: string | null;
|
|
88
|
+
/** True when the subscription will not renew at period end. */
|
|
89
|
+
cancel_at_period_end: boolean;
|
|
90
|
+
/** When the subscription was canceled (ISO 8601), or `null`. */
|
|
91
|
+
canceled_at: string | null;
|
|
92
|
+
/** When the subscription started (ISO 8601), or `null`. */
|
|
93
|
+
started_at: string | null;
|
|
73
94
|
}
|
|
74
95
|
/**
|
|
75
96
|
* The accounts module — manage multi-tenancy ("Accounts") from inside the app.
|
|
@@ -85,19 +106,45 @@ export interface AccountsModule {
|
|
|
85
106
|
* @param accountId - The account to switch to.
|
|
86
107
|
*/
|
|
87
108
|
switchAccount(accountId: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Persist the active account WITHOUT reloading the page.
|
|
111
|
+
*
|
|
112
|
+
* Use on the public landing page to select the account before redirecting to
|
|
113
|
+
* login, so the app resolves that account after the visitor returns. For
|
|
114
|
+
* switching accounts inside the running app, use {@link switchAccount} (which
|
|
115
|
+
* reloads so all data follows the new account).
|
|
116
|
+
*/
|
|
117
|
+
setActiveAccount(accountId: string): void;
|
|
88
118
|
/** Clear the stored active account (the backend falls back to the default). */
|
|
89
119
|
clearActiveAccount(): void;
|
|
90
120
|
/** List the accounts the current user belongs to, plus the active one. */
|
|
91
121
|
listMine(): Promise<MyAccountsResponse>;
|
|
92
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Resolve a public account by its slug (unauthenticated) for its landing page.
|
|
124
|
+
* @param slug - The account's URL slug.
|
|
125
|
+
*/
|
|
126
|
+
getPublicAccount(slug: string): Promise<PublicAccount>;
|
|
127
|
+
/**
|
|
128
|
+
* Self-join an account by slug (the current user becomes a member). Requires
|
|
129
|
+
* login and that the app enables public joining; otherwise rejects.
|
|
130
|
+
* @param slug - The account's URL slug.
|
|
131
|
+
*/
|
|
132
|
+
joinAccount(slug: string): Promise<AccountMembership>;
|
|
133
|
+
/**
|
|
134
|
+
* Create a new account; the current user becomes its owner.
|
|
135
|
+
* @param params.slug - Optional public landing-page URL segment; auto-derived
|
|
136
|
+
* from the name when omitted.
|
|
137
|
+
*/
|
|
93
138
|
create(params: {
|
|
94
139
|
name: string;
|
|
95
140
|
data?: Record<string, unknown>;
|
|
141
|
+
slug?: string;
|
|
96
142
|
}): Promise<Account>;
|
|
97
|
-
/** Rename and/or update an account's custom fields (managers only). */
|
|
143
|
+
/** Rename, change the landing-page slug, and/or update an account's custom fields (managers only). */
|
|
98
144
|
update(accountId: string, params: {
|
|
99
145
|
name?: string;
|
|
100
146
|
data?: Record<string, unknown>;
|
|
147
|
+
slug?: string;
|
|
101
148
|
}): Promise<Account>;
|
|
102
149
|
/**
|
|
103
150
|
* List an account's members (any active member).
|