@base44-preview/sdk 0.8.44-pr.264.d98f3ac → 0.8.44-pr.265.8da157e
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/build-session.d.ts +79 -0
- package/dist/build-session.js +59 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +3 -1
- package/dist/modules/auth.js +12 -7
- package/dist/modules/build.d.ts +38 -0
- package/dist/modules/build.js +499 -0
- package/dist/modules/build.types.d.ts +566 -0
- package/dist/modules/build.types.js +1 -0
- package/dist/modules/platforms.d.ts +14 -0
- package/dist/modules/platforms.js +41 -0
- package/dist/modules/platforms.types.d.ts +139 -0
- package/dist/modules/platforms.types.js +1 -0
- package/dist/platform-client.d.ts +63 -0
- package/dist/platform-client.js +160 -0
- package/dist/platform-client.types.d.ts +182 -0
- package/dist/platform-client.types.js +1 -0
- package/dist/utils/principal-tokens.d.ts +64 -0
- package/dist/utils/principal-tokens.js +120 -0
- package/dist/utils/sse.d.ts +31 -0
- package/dist/utils/sse.js +80 -0
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BuildSessionReader } from "./modules/build.types.js";
|
|
2
|
+
import type { CreateClientOptions } from "./client.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for reading a build session with a grant.
|
|
5
|
+
*/
|
|
6
|
+
export interface CreateBuildSessionConfig {
|
|
7
|
+
/** The app being built. A build session *is* an app — there is nothing separate to open. */
|
|
8
|
+
appId: string;
|
|
9
|
+
/**
|
|
10
|
+
* The Base44 server URL.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue `"https://base44.app"`
|
|
13
|
+
*/
|
|
14
|
+
serverUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* A grant token.
|
|
17
|
+
*
|
|
18
|
+
* Use {@link CreateBuildSessionConfig.getToken | getToken} instead for anything
|
|
19
|
+
* that outlives one grant, which most builds do.
|
|
20
|
+
*/
|
|
21
|
+
token?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Called for a grant before every request and every stream (re)connect.
|
|
24
|
+
*
|
|
25
|
+
* The shape to prefer. A grant is short-lived on purpose, so a build routinely
|
|
26
|
+
* outlasts the one it started with; re-reading the credential rather than
|
|
27
|
+
* capturing it is what makes a refresh invisible to the caller, and it is the
|
|
28
|
+
* habit the SDK's actors module already has internally.
|
|
29
|
+
*/
|
|
30
|
+
getToken?: () => string | Promise<string> | undefined;
|
|
31
|
+
/** Additional client options. */
|
|
32
|
+
options?: CreateClientOptions;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads one build session with a grant.
|
|
36
|
+
*
|
|
37
|
+
* The browser's entry point. A grant is read-only, scoped to one session and
|
|
38
|
+
* short-lived, so this returns the read half of a build session and nothing else
|
|
39
|
+
* — the writes live on the server, where the credential that can start a turn
|
|
40
|
+
* belongs.
|
|
41
|
+
*
|
|
42
|
+
* That asymmetry is the design rather than a limitation, and it is the thing an
|
|
43
|
+
* integrator gets wrong first: reads go browser to Base44 directly, keeping an
|
|
44
|
+
* open stream off your serverless function path, while writes go browser to your
|
|
45
|
+
* server to Base44. Because a grant cannot send, no configuration lets a leaked
|
|
46
|
+
* browser credential spend your workspace's credits.
|
|
47
|
+
*
|
|
48
|
+
* Mint the grant on your server with
|
|
49
|
+
* {@link BuildSession.createGrant | createGrant()}.
|
|
50
|
+
*
|
|
51
|
+
* @param config - The app, and how to get a grant for it.
|
|
52
|
+
* @returns The read-only session.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { createBuildSession } from '@base44/sdk';
|
|
57
|
+
*
|
|
58
|
+
* const build = createBuildSession({
|
|
59
|
+
* appId,
|
|
60
|
+
* // Re-read on every reconnect, so a build outliving its grant just works.
|
|
61
|
+
* getToken: () =>
|
|
62
|
+
* fetch('/api/base44/grant', { method: 'POST', body: JSON.stringify({ appId }) })
|
|
63
|
+
* .then((response) => response.json())
|
|
64
|
+
* .then((grant) => grant.token),
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* const unsubscribe = build.subscribe((event) => {
|
|
68
|
+
* switch (event.type) {
|
|
69
|
+
* case 'message.updated': upsertMessage(event.data); break; // by messageId
|
|
70
|
+
* case 'state.changed': setStatus(event.data); break;
|
|
71
|
+
* case 'turn.finished': markDone(event.turnId); break;
|
|
72
|
+
* }
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Sending goes to YOUR server, which holds the write credential.
|
|
76
|
+
* await fetch('/api/base44/message', { method: 'POST', body: … });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function createBuildSession(config: CreateBuildSessionConfig): BuildSessionReader;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createAxiosClient } from "./utils/axios-client.js";
|
|
2
|
+
import { createBuildSessionReader } from "./modules/build.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reads one build session with a grant.
|
|
5
|
+
*
|
|
6
|
+
* The browser's entry point. A grant is read-only, scoped to one session and
|
|
7
|
+
* short-lived, so this returns the read half of a build session and nothing else
|
|
8
|
+
* — the writes live on the server, where the credential that can start a turn
|
|
9
|
+
* belongs.
|
|
10
|
+
*
|
|
11
|
+
* That asymmetry is the design rather than a limitation, and it is the thing an
|
|
12
|
+
* integrator gets wrong first: reads go browser to Base44 directly, keeping an
|
|
13
|
+
* open stream off your serverless function path, while writes go browser to your
|
|
14
|
+
* server to Base44. Because a grant cannot send, no configuration lets a leaked
|
|
15
|
+
* browser credential spend your workspace's credits.
|
|
16
|
+
*
|
|
17
|
+
* Mint the grant on your server with
|
|
18
|
+
* {@link BuildSession.createGrant | createGrant()}.
|
|
19
|
+
*
|
|
20
|
+
* @param config - The app, and how to get a grant for it.
|
|
21
|
+
* @returns The read-only session.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { createBuildSession } from '@base44/sdk';
|
|
26
|
+
*
|
|
27
|
+
* const build = createBuildSession({
|
|
28
|
+
* appId,
|
|
29
|
+
* // Re-read on every reconnect, so a build outliving its grant just works.
|
|
30
|
+
* getToken: () =>
|
|
31
|
+
* fetch('/api/base44/grant', { method: 'POST', body: JSON.stringify({ appId }) })
|
|
32
|
+
* .then((response) => response.json())
|
|
33
|
+
* .then((grant) => grant.token),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const unsubscribe = build.subscribe((event) => {
|
|
37
|
+
* switch (event.type) {
|
|
38
|
+
* case 'message.updated': upsertMessage(event.data); break; // by messageId
|
|
39
|
+
* case 'state.changed': setStatus(event.data); break;
|
|
40
|
+
* case 'turn.finished': markDone(event.turnId); break;
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Sending goes to YOUR server, which holds the write credential.
|
|
45
|
+
* await fetch('/api/base44/message', { method: 'POST', body: … });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function createBuildSession(config) {
|
|
49
|
+
const { appId, serverUrl = "https://base44.app", token, getToken, options, } = config;
|
|
50
|
+
return createBuildSessionReader({
|
|
51
|
+
axios: createAxiosClient({
|
|
52
|
+
baseURL: `${serverUrl}/api`,
|
|
53
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
54
|
+
}),
|
|
55
|
+
appId,
|
|
56
|
+
serverUrl,
|
|
57
|
+
getToken: getToken !== null && getToken !== void 0 ? getToken : (() => token),
|
|
58
|
+
});
|
|
59
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createClient, createClientFromRequest, type Base44Client, type CreateClientConfig, type CreateClientOptions } from "./client.js";
|
|
2
|
+
import { createPlatformClient, type CreatePlatformClientConfig, type PlatformClient, type PrincipalClient } from "./platform-client.js";
|
|
3
|
+
import { createBuildSession, type CreateBuildSessionConfig } from "./build-session.js";
|
|
2
4
|
import { Base44Error, type Base44ErrorJSON } from "./utils/axios-client.js";
|
|
3
5
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from "./utils/auth-utils.js";
|
|
4
|
-
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
|
-
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
|
+
export { createClient, createClientFromRequest, createPlatformClient, createBuildSession, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
7
|
+
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, CreatePlatformClientConfig, PlatformClient, PrincipalClient, CreateBuildSessionConfig, };
|
|
6
8
|
export * from "./types.js";
|
|
7
9
|
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
8
10
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
@@ -13,6 +15,8 @@ export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway
|
|
|
13
15
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
14
16
|
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
15
17
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
18
|
+
export type { PlatformsModule, PrincipalRole, ProvisionPrincipalParams, ServicePrincipal, DeprovisionResult, } from "./modules/platforms.types.js";
|
|
19
|
+
export type { BuildEvent, BuildEventType, BuildGrant, BuildMessage, BuildMessagePage, BuildResponse, BuildSession, BuildSessionReader, BuildState, BuildStatus, BuildToolCall, BuildTurn, BuildTurnRef, BuildWaitingKind, BuildWaitingOn, CreateBuildGrantOptions, ListBuildMessagesOptions, RespondToBuildOptions, SendBuildMessageOptions, SubscribeToBuildOptions, WaitForTurnOptions, } from "./modules/build.types.js";
|
|
16
20
|
export { Actor, type Conn } from "./actor.js";
|
|
17
21
|
export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
|
|
18
22
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createClient, createClientFromRequest, } from "./client.js";
|
|
2
|
+
import { createPlatformClient, } from "./platform-client.js";
|
|
3
|
+
import { createBuildSession, } from "./build-session.js";
|
|
2
4
|
import { Base44Error } from "./utils/axios-client.js";
|
|
3
5
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
|
-
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
6
|
+
export { createClient, createClientFromRequest, createPlatformClient, createBuildSession, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
7
|
export * from "./types.js";
|
|
6
8
|
export { Actor } from "./actor.js";
|
package/dist/modules/auth.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { removeAccessToken } from "../utils/auth-utils.js";
|
|
2
1
|
import { resetAnalyticsSessionContext } from "./analytics.js";
|
|
3
2
|
function isInsideIframe() {
|
|
4
3
|
if (typeof window === "undefined")
|
|
@@ -116,10 +115,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
116
115
|
: window.location.href;
|
|
117
116
|
// Build the login URL
|
|
118
117
|
const loginUrl = `${options.appBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
119
|
-
//
|
|
120
|
-
// or a rejected token redirects to /login forever.
|
|
121
|
-
removeAccessToken({});
|
|
122
|
-
removeAccessToken({ storageKey: "token" });
|
|
118
|
+
// Redirect to the login page
|
|
123
119
|
window.location.href = loginUrl;
|
|
124
120
|
},
|
|
125
121
|
// Redirects the user to a provider's login page
|
|
@@ -158,8 +154,17 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
158
154
|
hasAccessToken = false;
|
|
159
155
|
// Only do the rest if in a browser environment
|
|
160
156
|
if (typeof window !== "undefined") {
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
// Remove token from localStorage
|
|
158
|
+
if (window.localStorage) {
|
|
159
|
+
try {
|
|
160
|
+
window.localStorage.removeItem("base44_access_token");
|
|
161
|
+
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
162
|
+
window.localStorage.removeItem("token");
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
console.error("Failed to remove token from localStorage:", e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
163
168
|
// Determine the from_url parameter
|
|
164
169
|
const fromUrl = redirectUrl || window.location.href;
|
|
165
170
|
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import type { BuildSession, BuildSessionReader } from "./build.types.js";
|
|
3
|
+
/** What the build module needs to talk to one app's session. @internal */
|
|
4
|
+
export interface BuildSessionDeps {
|
|
5
|
+
/** An Axios client based at `${serverUrl}/api`. */
|
|
6
|
+
axios: AxiosInstance;
|
|
7
|
+
/** The app whose build session this is. */
|
|
8
|
+
appId: string;
|
|
9
|
+
/** Used to build the absolute stream URL, which `fetch` needs. */
|
|
10
|
+
serverUrl: string;
|
|
11
|
+
/**
|
|
12
|
+
* Re-read before every request and every stream (re)connect.
|
|
13
|
+
*
|
|
14
|
+
* A getter rather than a string because both credentials that reach here
|
|
15
|
+
* rotate: a grant expires inside a single build, and a principal's access
|
|
16
|
+
* token lives an hour. Capturing either would work right up until the first
|
|
17
|
+
* build long enough to matter.
|
|
18
|
+
*
|
|
19
|
+
* Omitted when the Axios client already carries a static credential.
|
|
20
|
+
*/
|
|
21
|
+
getToken?: () => string | Promise<string> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The read half of a build session — what a grant can do.
|
|
25
|
+
*
|
|
26
|
+
* @param deps - Transport, app id and credential.
|
|
27
|
+
* @returns The read-only session.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function createBuildSessionReader(deps: BuildSessionDeps): BuildSessionReader;
|
|
31
|
+
/**
|
|
32
|
+
* A build session with the writes, for a credential that may start turns.
|
|
33
|
+
*
|
|
34
|
+
* @param deps - Transport, app id and credential.
|
|
35
|
+
* @returns The full session.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare function createBuildSessionModule(deps: BuildSessionDeps): BuildSession;
|