@base44-preview/sdk 0.8.44-pr.265.8da157e → 0.8.44-pr.267.4549331
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/index.d.ts +2 -6
- package/dist/index.js +1 -3
- package/dist/modules/integrations.types.d.ts +2 -2
- package/package.json +1 -1
- package/dist/build-session.d.ts +0 -79
- package/dist/build-session.js +0 -59
- package/dist/modules/build.d.ts +0 -38
- package/dist/modules/build.js +0 -499
- package/dist/modules/build.types.d.ts +0 -566
- package/dist/modules/build.types.js +0 -1
- package/dist/modules/platforms.d.ts +0 -14
- package/dist/modules/platforms.js +0 -41
- package/dist/modules/platforms.types.d.ts +0 -139
- package/dist/modules/platforms.types.js +0 -1
- package/dist/platform-client.d.ts +0 -63
- package/dist/platform-client.js +0 -160
- package/dist/platform-client.types.d.ts +0 -182
- package/dist/platform-client.types.js +0 -1
- package/dist/utils/principal-tokens.d.ts +0 -64
- package/dist/utils/principal-tokens.js +0 -120
- package/dist/utils/sse.d.ts +0 -31
- package/dist/utils/sse.js +0 -80
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The role a service principal holds in the workspace.
|
|
3
|
-
*
|
|
4
|
-
* Capped on the server: a principal is never an owner or an admin, whatever a
|
|
5
|
-
* caller asks for. Passing anything outside this set is clamped down rather than
|
|
6
|
-
* rejected, so a typo cannot quietly grant more than intended.
|
|
7
|
-
*/
|
|
8
|
-
export type PrincipalRole = "editor" | "viewer";
|
|
9
|
-
/**
|
|
10
|
-
* Parameters for provisioning a service principal.
|
|
11
|
-
*/
|
|
12
|
-
export interface ProvisionPrincipalParams {
|
|
13
|
-
/**
|
|
14
|
-
* Your own identifier for the person this principal acts for — whatever your
|
|
15
|
-
* platform already calls them (`"user_42"`, a UUID, a tenant-scoped handle).
|
|
16
|
-
*
|
|
17
|
-
* It is opaque to Base44 and is the only thing that addresses this principal
|
|
18
|
-
* afterwards, so it must be stable for the life of the account. Never an
|
|
19
|
-
* email, and never an SSO identity.
|
|
20
|
-
*/
|
|
21
|
-
externalId: string;
|
|
22
|
-
/**
|
|
23
|
-
* A human-readable name, shown wherever the principal appears in Base44.
|
|
24
|
-
*
|
|
25
|
-
* Cosmetic only: nothing resolves a principal by name.
|
|
26
|
-
*/
|
|
27
|
-
displayName?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The workspace role to create the principal with.
|
|
30
|
-
*
|
|
31
|
-
* @defaultValue `"editor"`
|
|
32
|
-
*/
|
|
33
|
-
role?: PrincipalRole;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A provisioned service principal.
|
|
37
|
-
*/
|
|
38
|
-
export interface ServicePrincipal {
|
|
39
|
-
/** The identifier you provisioned it under. */
|
|
40
|
-
externalId: string;
|
|
41
|
-
/** Base44's own user id for the principal. */
|
|
42
|
-
userId: string;
|
|
43
|
-
/**
|
|
44
|
-
* The synthetic address Base44 generated for it.
|
|
45
|
-
*
|
|
46
|
-
* In a reserved, non-routable domain that can never receive mail — a
|
|
47
|
-
* principal is a robot identity, not a person with an inbox.
|
|
48
|
-
*/
|
|
49
|
-
email: string;
|
|
50
|
-
/** The role it actually holds, after the server's ceiling is applied. */
|
|
51
|
-
role: string;
|
|
52
|
-
/**
|
|
53
|
-
* Whether this call created the principal.
|
|
54
|
-
*
|
|
55
|
-
* `false` means it already existed and was returned unchanged. Provisioning is
|
|
56
|
-
* idempotent, so this is informational — not an error to handle.
|
|
57
|
-
*/
|
|
58
|
-
created: boolean;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The outcome of deprovisioning a principal.
|
|
62
|
-
*/
|
|
63
|
-
export interface DeprovisionResult {
|
|
64
|
-
/** The identifier that was addressed. */
|
|
65
|
-
externalId: string;
|
|
66
|
-
/**
|
|
67
|
-
* Whether this call actually tore a principal down.
|
|
68
|
-
*
|
|
69
|
-
* `false` means nothing matched. Repeating a deprovision is safe and still
|
|
70
|
-
* succeeds, so a `false` on the *first* call is the interesting one: it means
|
|
71
|
-
* the id is wrong and some live principal is still holding vended tokens.
|
|
72
|
-
*/
|
|
73
|
-
removed: boolean;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Platform-level operations, scoped to a workspace rather than to one app.
|
|
77
|
-
*
|
|
78
|
-
* Reached through {@link createPlatformClient | createPlatformClient()}, which is
|
|
79
|
-
* the only client that holds workspace keys. This module manages *who* your
|
|
80
|
-
* platform acts as; {@link PlatformClient.asPrincipal | asPrincipal()} is how you
|
|
81
|
-
* then act as one.
|
|
82
|
-
*/
|
|
83
|
-
export interface PlatformsModule {
|
|
84
|
-
/**
|
|
85
|
-
* Creates a service principal for one of your users, or returns the existing one.
|
|
86
|
-
*
|
|
87
|
-
* Idempotent per `(workspace, externalId)`, so the intended use is to call it
|
|
88
|
-
* on every request that needs a principal rather than tracking which of your
|
|
89
|
-
* users you have provisioned. The second call is a plain lookup.
|
|
90
|
-
*
|
|
91
|
-
* The principal is created with **no credential of its own** — nothing can log
|
|
92
|
-
* in as it. The only way to act as it is
|
|
93
|
-
* {@link PlatformClient.asPrincipal | asPrincipal()}, which needs your
|
|
94
|
-
* workspace's mint key.
|
|
95
|
-
*
|
|
96
|
-
* Requires the `service_users:provision` key.
|
|
97
|
-
*
|
|
98
|
-
* @param params - The principal to provision.
|
|
99
|
-
* @returns The principal, whether it was just created or already existed.
|
|
100
|
-
*
|
|
101
|
-
* @throws {Base44Error} 409 if the generated address collides with an existing
|
|
102
|
-
* account, 403 if service principals are not enabled for the workspace.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* // Safe to call on every request — the second call is just a lookup.
|
|
107
|
-
* const principal = await base44.platforms.provisionPrincipal({
|
|
108
|
-
* externalId: 'user_42',
|
|
109
|
-
* displayName: 'Dana',
|
|
110
|
-
* });
|
|
111
|
-
*
|
|
112
|
-
* const asDana = base44.asPrincipal('user_42');
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
provisionPrincipal(params: ProvisionPrincipalParams): Promise<ServicePrincipal>;
|
|
116
|
-
/**
|
|
117
|
-
* Removes a service principal from the workspace.
|
|
118
|
-
*
|
|
119
|
-
* This is the offboarding lever, and it bites immediately: every vended token
|
|
120
|
-
* re-checks the workspace membership on each request, so tokens already handed
|
|
121
|
-
* out stop working now rather than when they expire.
|
|
122
|
-
*
|
|
123
|
-
* Requires the `service_users:provision` key — which is why that key should not
|
|
124
|
-
* be reachable from a request path.
|
|
125
|
-
*
|
|
126
|
-
* Deprovisioning does not delete the apps the principal built; it owns them,
|
|
127
|
-
* and they outlive it.
|
|
128
|
-
*
|
|
129
|
-
* @param externalId - The identifier the principal was provisioned under.
|
|
130
|
-
* @returns Whether a principal was actually torn down.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* // A user closed their account.
|
|
135
|
-
* await base44.platforms.deprovisionPrincipal('user_42');
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
deprovisionPrincipal(externalId: string): Promise<DeprovisionResult>;
|
|
139
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { CreatePlatformClientConfig, PlatformClient, PrincipalClient } from "./platform-client.types.js";
|
|
2
|
-
export type { CreatePlatformClientConfig, PlatformClient, PrincipalClient };
|
|
3
|
-
/**
|
|
4
|
-
* Creates a workspace-scoped Base44 client, for platforms that build apps on
|
|
5
|
-
* behalf of their own users.
|
|
6
|
-
*
|
|
7
|
-
* This is the third client factory, and it exists for the one case neither of
|
|
8
|
-
* the others covers. {@linkcode createClient | createClient()} is scoped to one
|
|
9
|
-
* app and one user; {@linkcode createClientFromRequest | createClientFromRequest()}
|
|
10
|
-
* runs inside a Base44-hosted function. A platform is scoped to a **workspace**:
|
|
11
|
-
* it has many users, none of whom have a Base44 account, and it needs each of
|
|
12
|
-
* them to own the apps they build.
|
|
13
|
-
*
|
|
14
|
-
* The model is a *service principal* — a synthetic member of your workspace,
|
|
15
|
-
* created with no credential of its own, that you act as. Your users never see
|
|
16
|
-
* Base44; you keep your own accounts and map each one to a principal.
|
|
17
|
-
*
|
|
18
|
-
* Two steps, and the first is idempotent:
|
|
19
|
-
*
|
|
20
|
-
* 1. {@linkcode PlatformsModule.provisionPrincipal | provisionPrincipal()} to
|
|
21
|
-
* make sure a principal exists for your user.
|
|
22
|
-
* 2. {@linkcode PlatformClient.asPrincipal | asPrincipal()} to act as them.
|
|
23
|
-
*
|
|
24
|
-
* **Server-side only.** This client holds workspace API keys, which authorize
|
|
25
|
-
* every app in the workspace. Never construct one in a browser, and never send
|
|
26
|
-
* either key to one.
|
|
27
|
-
*
|
|
28
|
-
* Nor a principal's own token: it can start builds and spend credits. The one
|
|
29
|
-
* credential meant for a browser is a *grant* —
|
|
30
|
-
* {@linkcode BuildSession.createGrant | createGrant()} — which reads one build
|
|
31
|
-
* session, expires in minutes, and cannot write.
|
|
32
|
-
*
|
|
33
|
-
* @param config - Configuration object for the platform client.
|
|
34
|
-
* @returns A configured platform client.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* import { createPlatformClient } from '@base44/sdk';
|
|
39
|
-
*
|
|
40
|
-
* const base44 = createPlatformClient({
|
|
41
|
-
* mintKey: process.env.BASE44_MINT_KEY, // user_tokens:mint
|
|
42
|
-
* provisionKey: process.env.BASE44_PROVISION_KEY, // service_users:provision
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* // On a request from one of your users:
|
|
46
|
-
* await base44.platforms.provisionPrincipal({
|
|
47
|
-
* externalId: 'user_42',
|
|
48
|
-
* displayName: 'Dana',
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* const asDana = base44.asPrincipal('user_42');
|
|
52
|
-
*
|
|
53
|
-
* // Drive the builder as them, and watch it happen.
|
|
54
|
-
* const build = asDana.build(appId);
|
|
55
|
-
* const { turnId } = await build.sendMessage('add a footer');
|
|
56
|
-
* const outcome = await build.waitForTurn(turnId);
|
|
57
|
-
*
|
|
58
|
-
* // Or use the rest of the SDK as them.
|
|
59
|
-
* const app = await asDana.forApp(appId);
|
|
60
|
-
* const todos = await app.entities.Todo.list();
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare function createPlatformClient(config: CreatePlatformClientConfig): PlatformClient;
|
package/dist/platform-client.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { createAxiosClient } from "./utils/axios-client.js";
|
|
2
|
-
import { createPlatformsModule } from "./modules/platforms.js";
|
|
3
|
-
import { createBuildSessionModule } from "./modules/build.js";
|
|
4
|
-
import { createPrincipalTokenStore } from "./utils/principal-tokens.js";
|
|
5
|
-
import { createClient } from "./client.js";
|
|
6
|
-
/**
|
|
7
|
-
* Creates a workspace-scoped Base44 client, for platforms that build apps on
|
|
8
|
-
* behalf of their own users.
|
|
9
|
-
*
|
|
10
|
-
* This is the third client factory, and it exists for the one case neither of
|
|
11
|
-
* the others covers. {@linkcode createClient | createClient()} is scoped to one
|
|
12
|
-
* app and one user; {@linkcode createClientFromRequest | createClientFromRequest()}
|
|
13
|
-
* runs inside a Base44-hosted function. A platform is scoped to a **workspace**:
|
|
14
|
-
* it has many users, none of whom have a Base44 account, and it needs each of
|
|
15
|
-
* them to own the apps they build.
|
|
16
|
-
*
|
|
17
|
-
* The model is a *service principal* — a synthetic member of your workspace,
|
|
18
|
-
* created with no credential of its own, that you act as. Your users never see
|
|
19
|
-
* Base44; you keep your own accounts and map each one to a principal.
|
|
20
|
-
*
|
|
21
|
-
* Two steps, and the first is idempotent:
|
|
22
|
-
*
|
|
23
|
-
* 1. {@linkcode PlatformsModule.provisionPrincipal | provisionPrincipal()} to
|
|
24
|
-
* make sure a principal exists for your user.
|
|
25
|
-
* 2. {@linkcode PlatformClient.asPrincipal | asPrincipal()} to act as them.
|
|
26
|
-
*
|
|
27
|
-
* **Server-side only.** This client holds workspace API keys, which authorize
|
|
28
|
-
* every app in the workspace. Never construct one in a browser, and never send
|
|
29
|
-
* either key to one.
|
|
30
|
-
*
|
|
31
|
-
* Nor a principal's own token: it can start builds and spend credits. The one
|
|
32
|
-
* credential meant for a browser is a *grant* —
|
|
33
|
-
* {@linkcode BuildSession.createGrant | createGrant()} — which reads one build
|
|
34
|
-
* session, expires in minutes, and cannot write.
|
|
35
|
-
*
|
|
36
|
-
* @param config - Configuration object for the platform client.
|
|
37
|
-
* @returns A configured platform client.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* import { createPlatformClient } from '@base44/sdk';
|
|
42
|
-
*
|
|
43
|
-
* const base44 = createPlatformClient({
|
|
44
|
-
* mintKey: process.env.BASE44_MINT_KEY, // user_tokens:mint
|
|
45
|
-
* provisionKey: process.env.BASE44_PROVISION_KEY, // service_users:provision
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* // On a request from one of your users:
|
|
49
|
-
* await base44.platforms.provisionPrincipal({
|
|
50
|
-
* externalId: 'user_42',
|
|
51
|
-
* displayName: 'Dana',
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* const asDana = base44.asPrincipal('user_42');
|
|
55
|
-
*
|
|
56
|
-
* // Drive the builder as them, and watch it happen.
|
|
57
|
-
* const build = asDana.build(appId);
|
|
58
|
-
* const { turnId } = await build.sendMessage('add a footer');
|
|
59
|
-
* const outcome = await build.waitForTurn(turnId);
|
|
60
|
-
*
|
|
61
|
-
* // Or use the rest of the SDK as them.
|
|
62
|
-
* const app = await asDana.forApp(appId);
|
|
63
|
-
* const todos = await app.entities.Todo.list();
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export function createPlatformClient(config) {
|
|
67
|
-
const { serverUrl = "https://base44.app", mintKey, provisionKey = mintKey, options, } = config;
|
|
68
|
-
// Three clients, because they carry three different credentials — and the
|
|
69
|
-
// separation is the security property, not tidiness. Nothing reachable from a
|
|
70
|
-
// request should be able to create a principal, and nothing at all should
|
|
71
|
-
// present a workspace key to an endpoint that authenticates a refresh token.
|
|
72
|
-
const mintAxios = createAxiosClient({
|
|
73
|
-
baseURL: serverUrl,
|
|
74
|
-
token: mintKey,
|
|
75
|
-
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
76
|
-
});
|
|
77
|
-
const provisionAxios = createAxiosClient({
|
|
78
|
-
baseURL: serverUrl,
|
|
79
|
-
token: provisionKey,
|
|
80
|
-
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
81
|
-
});
|
|
82
|
-
const oauthAxios = createAxiosClient({
|
|
83
|
-
baseURL: serverUrl,
|
|
84
|
-
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
85
|
-
});
|
|
86
|
-
// A fourth, and for the same reason as the third: it carries no static
|
|
87
|
-
// credential. Every build call is made as a *principal*, whose token rotates,
|
|
88
|
-
// so the token goes on the request rather than into the client.
|
|
89
|
-
const buildAxios = createAxiosClient({
|
|
90
|
-
baseURL: `${serverUrl}/api`,
|
|
91
|
-
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
92
|
-
});
|
|
93
|
-
const tokens = createPrincipalTokenStore({ mintAxios, oauthAxios });
|
|
94
|
-
const platforms = createPlatformsModule(provisionAxios);
|
|
95
|
-
// One principal handle per external id, and one app client per (principal,
|
|
96
|
-
// app). Both are addressed by stable ids and both wrap cached state, so
|
|
97
|
-
// rebuilding them per request would throw away the token cache that makes the
|
|
98
|
-
// mint rate limit survivable.
|
|
99
|
-
const principals = new Map();
|
|
100
|
-
const buildPrincipal = (externalId) => {
|
|
101
|
-
// The token each client was last given, so a rotation can be detected. Held
|
|
102
|
-
// beside the client rather than read back off it because a client does not
|
|
103
|
-
// expose its credential.
|
|
104
|
-
const apps = new Map();
|
|
105
|
-
const getToken = async () => (await tokens.get(externalId)).accessToken;
|
|
106
|
-
return {
|
|
107
|
-
externalId,
|
|
108
|
-
getToken,
|
|
109
|
-
// Not cached, unlike `forApp`. A build session is a handful of closures
|
|
110
|
-
// over the token store rather than a client with sockets and an analytics
|
|
111
|
-
// session, so there is nothing to reuse and nothing to leak.
|
|
112
|
-
build(appId) {
|
|
113
|
-
return createBuildSessionModule({
|
|
114
|
-
axios: buildAxios,
|
|
115
|
-
appId,
|
|
116
|
-
serverUrl,
|
|
117
|
-
getToken,
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
async forApp(appId) {
|
|
121
|
-
const token = await getToken();
|
|
122
|
-
const held = apps.get(appId);
|
|
123
|
-
if (held) {
|
|
124
|
-
// Only on an actual rotation. `setToken` treats the call as an
|
|
125
|
-
// identity change — it discards the in-flight `me()` other callers are
|
|
126
|
-
// awaiting and resets the analytics session — so applying it on every
|
|
127
|
-
// request would undo work the client does on the caller's behalf.
|
|
128
|
-
if (held.token !== token) {
|
|
129
|
-
held.client.setToken(token);
|
|
130
|
-
held.token = token;
|
|
131
|
-
}
|
|
132
|
-
return held.client;
|
|
133
|
-
}
|
|
134
|
-
const client = createClient({ appId, serverUrl, token, options });
|
|
135
|
-
apps.set(appId, { client, token });
|
|
136
|
-
return client;
|
|
137
|
-
},
|
|
138
|
-
async revokeToken() {
|
|
139
|
-
await tokens.revoke(externalId);
|
|
140
|
-
for (const { client } of apps.values())
|
|
141
|
-
client.cleanup();
|
|
142
|
-
apps.clear();
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
return {
|
|
147
|
-
platforms,
|
|
148
|
-
asPrincipal(externalId) {
|
|
149
|
-
let principal = principals.get(externalId);
|
|
150
|
-
if (!principal) {
|
|
151
|
-
principal = buildPrincipal(externalId);
|
|
152
|
-
principals.set(externalId, principal);
|
|
153
|
-
}
|
|
154
|
-
return principal;
|
|
155
|
-
},
|
|
156
|
-
getConfig() {
|
|
157
|
-
return { serverUrl };
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import type { Base44Client, CreateClientOptions } from "./client.types.js";
|
|
2
|
-
import type { BuildSession } from "./modules/build.types.js";
|
|
3
|
-
import type { PlatformsModule } from "./modules/platforms.types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for creating a Base44 platform client.
|
|
6
|
-
*/
|
|
7
|
-
export interface CreatePlatformClientConfig {
|
|
8
|
-
/**
|
|
9
|
-
* The workspace API key used to vend tokens, holding the `user_tokens:mint` scope.
|
|
10
|
-
*
|
|
11
|
-
* This is the hot-path key: it is presented on every request that needs to act
|
|
12
|
-
* as one of your users. A mint-only key can vend tokens for principals that
|
|
13
|
-
* already exist but cannot *create* one, which is what stops it from being an
|
|
14
|
-
* impersonate-anyone primitive if it leaks.
|
|
15
|
-
*/
|
|
16
|
-
mintKey: string;
|
|
17
|
-
/**
|
|
18
|
-
* The workspace API key used to create and remove principals, holding the
|
|
19
|
-
* `service_users:provision` scope.
|
|
20
|
-
*
|
|
21
|
-
* Keep it separate from `mintKey`, and keep it off any code path a request can
|
|
22
|
-
* reach. That separation is what makes deprovisioning stick: with a
|
|
23
|
-
* provision-capable key on the hot path, a removed user can be re-provisioned
|
|
24
|
-
* by the next request that mentions them, quietly undoing the offboarding.
|
|
25
|
-
*
|
|
26
|
-
* @defaultValue `mintKey`, for a single-key deployment. Workable, but weaker
|
|
27
|
-
* for the reason above.
|
|
28
|
-
*/
|
|
29
|
-
provisionKey?: string;
|
|
30
|
-
/**
|
|
31
|
-
* The Base44 server URL.
|
|
32
|
-
*
|
|
33
|
-
* @defaultValue `"https://base44.app"`
|
|
34
|
-
*/
|
|
35
|
-
serverUrl?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Additional client options.
|
|
38
|
-
*/
|
|
39
|
-
options?: CreateClientOptions;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A view of Base44 that acts as one of your users.
|
|
43
|
-
*
|
|
44
|
-
* Obtained from {@link PlatformClient.asPrincipal | asPrincipal()}. Holding one
|
|
45
|
-
* costs nothing — no token is vended until you ask for something.
|
|
46
|
-
*/
|
|
47
|
-
export interface PrincipalClient {
|
|
48
|
-
/** The identifier this principal was provisioned under. */
|
|
49
|
-
readonly externalId: string;
|
|
50
|
-
/**
|
|
51
|
-
* The build session for one app, driven as this principal.
|
|
52
|
-
*
|
|
53
|
-
* This is the partner-facing builder: send a message, answer what the agent
|
|
54
|
-
* asks, stop a turn, and watch the whole thing happen over one resumable
|
|
55
|
-
* stream. Every write returns as soon as the turn is *accepted*, because a
|
|
56
|
-
* build takes minutes and no caller should hold a request open through one.
|
|
57
|
-
*
|
|
58
|
-
* The principal must be able to edit the app, which it is when it built the
|
|
59
|
-
* app itself. A workspace that is not enrolled as a platform gets 404 from
|
|
60
|
-
* every route here — deliberately indistinguishable from "no such app", so an
|
|
61
|
-
* unenrolled caller cannot tell the surface exists.
|
|
62
|
-
*
|
|
63
|
-
* Cheap to call: the session is a handle, not a connection, and it holds no
|
|
64
|
-
* credential of its own — the principal's token is re-read per request, so one
|
|
65
|
-
* held across a long build keeps working as the token rotates underneath it.
|
|
66
|
-
*
|
|
67
|
-
* @param appId - The app to build.
|
|
68
|
-
* @returns The session, ready to read and write.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const build = base44.asPrincipal('user_42').build(appId);
|
|
73
|
-
*
|
|
74
|
-
* const { turnId } = await build.sendMessage('add a footer');
|
|
75
|
-
* const outcome = await build.waitForTurn(turnId);
|
|
76
|
-
*
|
|
77
|
-
* // The browser gets a read-only grant, and nothing else.
|
|
78
|
-
* const grant = await build.createGrant({ ttlSeconds: 900 });
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
build(appId: string): BuildSession;
|
|
82
|
-
/**
|
|
83
|
-
* A Base44 client for one app, acting as this principal.
|
|
84
|
-
*
|
|
85
|
-
* This is the bridge to the rest of the SDK: the returned client is an ordinary
|
|
86
|
-
* {@link Base44Client}, so `entities`, `agents`, `functions` and the rest work
|
|
87
|
-
* exactly as documented — scoped to what this principal may see, which is
|
|
88
|
-
* usually far less than a service role.
|
|
89
|
-
*
|
|
90
|
-
* Cheap to call repeatedly. The token behind it is cached and renewed for you,
|
|
91
|
-
* and the same app gets the same client back, so a long-lived worker can hold
|
|
92
|
-
* one and a serverless handler can ask for one per request.
|
|
93
|
-
*
|
|
94
|
-
* @param appId - The app to act on.
|
|
95
|
-
* @returns A client scoped to that app, authenticated as this principal.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* const asDana = base44.asPrincipal('user_42');
|
|
100
|
-
* const app = await asDana.forApp(appId);
|
|
101
|
-
*
|
|
102
|
-
* // Every module, with Dana's permissions rather than the workspace's.
|
|
103
|
-
* const todos = await app.entities.Todo.list();
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
forApp(appId: string): Promise<Base44Client>;
|
|
107
|
-
/**
|
|
108
|
-
* The raw access token for this principal, minting or renewing as needed.
|
|
109
|
-
*
|
|
110
|
-
* Most code should use {@link PrincipalClient.forApp | forApp()} or
|
|
111
|
-
* {@link PrincipalClient.build | build()} instead. Reach for this when you need
|
|
112
|
-
* to authenticate a request the SDK does not make for you.
|
|
113
|
-
*
|
|
114
|
-
* **Not the thing to send to a browser.** This token can start builds and spend
|
|
115
|
-
* your credits. What a browser gets is a grant from
|
|
116
|
-
* {@link BuildSession.createGrant | createGrant()}, which reads one session and
|
|
117
|
-
* writes nothing.
|
|
118
|
-
*
|
|
119
|
-
* Do not cache what this returns — it is already cached, and holding a copy is
|
|
120
|
-
* how a caller ends up using a token the store has since replaced.
|
|
121
|
-
*
|
|
122
|
-
* @returns A currently-valid access token.
|
|
123
|
-
*
|
|
124
|
-
* @throws {Base44Error} 404 if no principal matches, which is what an
|
|
125
|
-
* un-provisioned `externalId` looks like: minting never creates one.
|
|
126
|
-
*/
|
|
127
|
-
getToken(): Promise<string>;
|
|
128
|
-
/**
|
|
129
|
-
* Forgets this principal's cached token and revokes its refresh token.
|
|
130
|
-
*
|
|
131
|
-
* Use when a user signs out of *your* platform. It does not remove the
|
|
132
|
-
* principal — the apps it built belong to it, and signing out should not hand
|
|
133
|
-
* them to the workspace owner. Removing it is
|
|
134
|
-
* {@link PlatformsModule.deprovisionPrincipal | deprovisionPrincipal()}.
|
|
135
|
-
*
|
|
136
|
-
* Only the refresh token can be revoked; a live access token remains valid for
|
|
137
|
-
* the rest of its hour. Deprovisioning is the lever that cuts one off
|
|
138
|
-
* immediately.
|
|
139
|
-
*/
|
|
140
|
-
revokeToken(): Promise<void>;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* A workspace-scoped Base44 client, for platforms that build apps on behalf of
|
|
144
|
-
* their own users.
|
|
145
|
-
*
|
|
146
|
-
* The third client factory, beside {@link createClient | createClient()} (one
|
|
147
|
-
* app, one user) and {@link createClientFromRequest | createClientFromRequest()}
|
|
148
|
-
* (inside a Base44 function). This one is scoped to a *workspace*: it manages the
|
|
149
|
-
* identities your users act as, and hands you a client per identity.
|
|
150
|
-
*/
|
|
151
|
-
export interface PlatformClient {
|
|
152
|
-
/** {@link PlatformsModule | Platforms module} for managing service principals. */
|
|
153
|
-
platforms: PlatformsModule;
|
|
154
|
-
/**
|
|
155
|
-
* Acts as one of your users.
|
|
156
|
-
*
|
|
157
|
-
* Mirrors `base44.asServiceRole` in shape — the same SDK, different
|
|
158
|
-
* permissions — but parameterised, because a platform has many identities
|
|
159
|
-
* rather than one privileged one.
|
|
160
|
-
*
|
|
161
|
-
* The principal must already exist;
|
|
162
|
-
* {@link PlatformsModule.provisionPrincipal | provisionPrincipal()} is
|
|
163
|
-
* idempotent and safe to call first on every request.
|
|
164
|
-
*
|
|
165
|
-
* @param externalId - The identifier the principal was provisioned under.
|
|
166
|
-
* @returns A view of Base44 that acts as that principal.
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* await base44.platforms.provisionPrincipal({ externalId: 'user_42' });
|
|
171
|
-
* const asDana = base44.asPrincipal('user_42');
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
asPrincipal(externalId: string): PrincipalClient;
|
|
175
|
-
/**
|
|
176
|
-
* Gets the current client configuration.
|
|
177
|
-
* @internal
|
|
178
|
-
*/
|
|
179
|
-
getConfig(): {
|
|
180
|
-
serverUrl: string;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from "axios";
|
|
2
|
-
/**
|
|
3
|
-
* The OAuth client id every service-principal token is issued under.
|
|
4
|
-
*
|
|
5
|
-
* Deliberately not one of Base44's MCP client prefixes — a token whose client id
|
|
6
|
-
* starts with one of those is rejected everywhere except `/mcp`.
|
|
7
|
-
*/
|
|
8
|
-
export declare const SERVICE_CLIENT_ID = "svc_delegate";
|
|
9
|
-
/**
|
|
10
|
-
* Re-mint this long before a token's stated expiry.
|
|
11
|
-
*
|
|
12
|
-
* Access tokens are vended with an explicit one-hour lifetime, so this is a few
|
|
13
|
-
* percent of the token's life — enough that a slow call cannot land after the
|
|
14
|
-
* token it was authorized with has expired.
|
|
15
|
-
*/
|
|
16
|
-
export declare const REFRESH_SKEW_MS: number;
|
|
17
|
-
/** A vended access token and what is needed to renew it. */
|
|
18
|
-
export interface VendedToken {
|
|
19
|
-
accessToken: string;
|
|
20
|
-
refreshToken?: string;
|
|
21
|
-
/** Epoch milliseconds at which the access token stops being accepted. */
|
|
22
|
-
expiresAt: number;
|
|
23
|
-
}
|
|
24
|
-
interface TokenStoreConfig {
|
|
25
|
-
/** Carries the `user_tokens:mint` key. Used for minting and nothing else. */
|
|
26
|
-
mintAxios: AxiosInstance;
|
|
27
|
-
/**
|
|
28
|
-
* Carries no credential at all.
|
|
29
|
-
*
|
|
30
|
-
* `/oauth/token` and `/oauth/revoke` authenticate the *refresh token*, not the
|
|
31
|
-
* caller, so presenting a workspace key there would be sending a
|
|
32
|
-
* long-lived secret somewhere it is neither wanted nor checked.
|
|
33
|
-
*/
|
|
34
|
-
oauthAxios: AxiosInstance;
|
|
35
|
-
refreshSkewMs?: number;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Caches one vended token per principal, and renews it before it lapses.
|
|
39
|
-
*
|
|
40
|
-
* Caching is not an optimization here. Minting is rate-limited **per workspace**,
|
|
41
|
-
* so a platform that mints on every request spends one shared budget on behalf of
|
|
42
|
-
* every user at once and starts failing under exactly the load it was built for.
|
|
43
|
-
* A vended token is good for an hour; this holds it for that hour.
|
|
44
|
-
*
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
export declare function createPrincipalTokenStore({ mintAxios, oauthAxios, refreshSkewMs, }: TokenStoreConfig): {
|
|
48
|
-
/**
|
|
49
|
-
* A currently-valid token for the principal, minting or renewing only when
|
|
50
|
-
* the held one is spent.
|
|
51
|
-
*/
|
|
52
|
-
get(externalId: string): Promise<VendedToken>;
|
|
53
|
-
/**
|
|
54
|
-
* Drops the held token and asks Base44 to revoke its refresh token.
|
|
55
|
-
*
|
|
56
|
-
* Only the refresh half is revocable — the access token is self-contained and
|
|
57
|
-
* stays valid until it expires. To cut a principal off *now*, deprovision it:
|
|
58
|
-
* the workspace membership is re-checked on every request.
|
|
59
|
-
*/
|
|
60
|
-
revoke(externalId: string): Promise<void>;
|
|
61
|
-
};
|
|
62
|
-
/** @internal */
|
|
63
|
-
export type PrincipalTokenStore = ReturnType<typeof createPrincipalTokenStore>;
|
|
64
|
-
export {};
|