@depup/base44__sdk 0.8.25-depup.0 → 0.8.41-depup.0
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/README.md +4 -4
- package/changes.json +7 -7
- package/dist/actor.d.ts +86 -0
- package/dist/actor.js +73 -0
- package/dist/client.d.ts +4 -4
- package/dist/client.js +44 -17
- package/dist/client.types.d.ts +11 -5
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -0
- package/dist/modules/actors.d.ts +25 -0
- package/dist/modules/actors.js +135 -0
- package/dist/modules/actors.types.d.ts +95 -0
- package/dist/modules/actors.types.js +1 -0
- package/dist/modules/agents.types.d.ts +2 -2
- package/dist/modules/ai-gateway.d.ts +2 -0
- package/dist/modules/ai-gateway.js +13 -0
- package/dist/modules/ai-gateway.types.d.ts +139 -0
- package/dist/modules/ai-gateway.types.js +1 -0
- package/dist/modules/analytics.js +10 -3
- package/dist/modules/auth.js +61 -1
- package/dist/modules/auth.types.d.ts +62 -26
- package/dist/modules/connectors.js +12 -0
- package/dist/modules/connectors.types.d.ts +111 -63
- package/dist/modules/entities.js +14 -0
- package/dist/modules/entities.types.d.ts +110 -4
- package/dist/modules/functions.types.d.ts +1 -1
- package/dist/modules/integrations.types.d.ts +3 -3
- package/dist/modules/sso.d.ts +0 -1
- package/dist/modules/sso.js +5 -1
- package/dist/modules/sso.types.d.ts +50 -20
- package/dist/modules/types.d.ts +1 -0
- package/dist/modules/types.js +1 -0
- package/dist/utils/axios-client.js +10 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.js +5 -0
- package/dist/utils/socket-utils.js +64 -9
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/base44__sdk
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@base44/sdk](https://www.npmjs.com/package/@base44/sdk) @ 0.8.
|
|
17
|
-
| Processed | 2026-
|
|
16
|
+
| Original | [@base44/sdk](https://www.npmjs.com/package/@base44/sdk) @ 0.8.41 |
|
|
17
|
+
| Processed | 2026-07-29 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
19
|
| Deps updated | 2 |
|
|
20
20
|
|
|
@@ -22,8 +22,8 @@ npm install @depup/base44__sdk
|
|
|
22
22
|
|
|
23
23
|
| Dependency | From | To |
|
|
24
24
|
|------------|------|-----|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
25
|
+
| partysocket | ^0.0.23 | ^1.3.0 |
|
|
26
|
+
| uuid | ^13.0.2 | ^14.0.1 |
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
package/changes.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bumped": {
|
|
3
|
-
"
|
|
4
|
-
"from": "^
|
|
5
|
-
"to": "^1.
|
|
3
|
+
"partysocket": {
|
|
4
|
+
"from": "^0.0.23",
|
|
5
|
+
"to": "^1.3.0"
|
|
6
6
|
},
|
|
7
|
-
"
|
|
8
|
-
"from": "^
|
|
9
|
-
"to": "^
|
|
7
|
+
"uuid": {
|
|
8
|
+
"from": "^13.0.2",
|
|
9
|
+
"to": "^14.0.1"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
|
-
"timestamp": "2026-
|
|
12
|
+
"timestamp": "2026-07-29T16:33:33.820Z",
|
|
13
13
|
"totalUpdated": 2
|
|
14
14
|
}
|
package/dist/actor.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-only base class for Actors.
|
|
3
|
+
*
|
|
4
|
+
* Import and extend this in your actor files:
|
|
5
|
+
* import { Actor } from "@base44/sdk";
|
|
6
|
+
* export class MyActor extends Actor { ... }
|
|
7
|
+
*
|
|
8
|
+
* At deploy time the bundler replaces this import with the compiled
|
|
9
|
+
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
|
+
*/
|
|
11
|
+
import type { Base44Client } from "./client";
|
|
12
|
+
/**
|
|
13
|
+
* A single client connection. `Send` is the message type this connection accepts
|
|
14
|
+
* via {@link send} — the actor's *outgoing* (server→client) messages.
|
|
15
|
+
*/
|
|
16
|
+
export interface Conn<Send = unknown> {
|
|
17
|
+
/** Unique per-connection id (one per socket/tab), the same value the client
|
|
18
|
+
* receives from `subscribe()`. Use this — not userId — to identify a distinct
|
|
19
|
+
* client, so multiple tabs of the same user are separate connections. */
|
|
20
|
+
id: string;
|
|
21
|
+
userId: string;
|
|
22
|
+
appId: string;
|
|
23
|
+
instanceId: string;
|
|
24
|
+
send(data: Send): void;
|
|
25
|
+
reject(code: number, reason: string): void;
|
|
26
|
+
}
|
|
27
|
+
export interface Storage {
|
|
28
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
29
|
+
put(key: string, value: unknown): Promise<void>;
|
|
30
|
+
delete(key: string): Promise<boolean>;
|
|
31
|
+
/** Wipe the room's entire persisted storage (match-end cleanup). Safe: a
|
|
32
|
+
* later rejoin re-bootstraps exactly like a brand-new room. */
|
|
33
|
+
deleteAll(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Base class for an Actor.
|
|
37
|
+
*
|
|
38
|
+
* @typeParam Incoming - messages this actor *receives* from clients
|
|
39
|
+
* (`handleMessage`'s `msg`) — the schema's `toServer` section.
|
|
40
|
+
* @typeParam Outgoing - messages this actor *sends* to clients
|
|
41
|
+
* (`conn.send`/`broadcast`) — the schema's `toClient` section.
|
|
42
|
+
*
|
|
43
|
+
* With a generated `schema.jsonc`, wire both from the registry so they can't drift
|
|
44
|
+
* from the client's types:
|
|
45
|
+
* ```ts
|
|
46
|
+
* type Reg = ActorRegistry["MyActor"];
|
|
47
|
+
* class MyActor extends Actor<Reg["toServer"], Reg["toClient"]> { ... }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
|
|
51
|
+
abstract handleConnect(conn: Conn<Outgoing>): void | Promise<void>;
|
|
52
|
+
abstract handleMessage(conn: Conn<Outgoing>, msg: Incoming): void | Promise<void>;
|
|
53
|
+
abstract handleClose(conn: Conn<Outgoing>): void | Promise<void>;
|
|
54
|
+
abstract handleTick(): void | Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Optional wake hook: runs once when the instance starts, before any
|
|
57
|
+
* connection is handled — safe to load persisted state here.
|
|
58
|
+
*/
|
|
59
|
+
handleStart(): void | Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Managed ticker (opt-in). Override {@link shouldTick} and the platform runs
|
|
62
|
+
* {@link handleTick} on a timer of {@link tickIntervalMs} while it returns true,
|
|
63
|
+
* and stops (letting the Durable Object hibernate — no compute cost) when it
|
|
64
|
+
* returns false. The platform owns scheduling, rescheduling, self-heal, and
|
|
65
|
+
* error-safety — you don't call {@link startLoop}/{@link stopLoop}.
|
|
66
|
+
*
|
|
67
|
+
* Re-evaluated after every connect/message/close and on every tick, so keep it
|
|
68
|
+
* cheap and pure (no async, no side effects). Example: `return this.players >= 2`.
|
|
69
|
+
*/
|
|
70
|
+
protected tickIntervalMs: number;
|
|
71
|
+
protected shouldTick?(): boolean;
|
|
72
|
+
protected broadcast(_data: Outgoing): void;
|
|
73
|
+
protected getConnections(): Conn<Outgoing>[];
|
|
74
|
+
protected startLoop(_ms: number): Promise<void>;
|
|
75
|
+
protected stopLoop(): Promise<void>;
|
|
76
|
+
protected get instanceId(): string;
|
|
77
|
+
protected get storage(): Storage;
|
|
78
|
+
/**
|
|
79
|
+
* Anonymous Base44 client scoped to this actor instance — no user or service
|
|
80
|
+
* auth, so entity access is RLS-gated (same as a logged-out visitor). Always
|
|
81
|
+
* operates on production data: an actor runs server-side with no per-connection
|
|
82
|
+
* identity, so a Test DB preview selected in the editor does not apply here.
|
|
83
|
+
* Example: `const rows = await this.client.entities.Score.list();`
|
|
84
|
+
*/
|
|
85
|
+
protected get client(): Base44Client;
|
|
86
|
+
}
|
package/dist/actor.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-only base class for Actors.
|
|
3
|
+
*
|
|
4
|
+
* Import and extend this in your actor files:
|
|
5
|
+
* import { Actor } from "@base44/sdk";
|
|
6
|
+
* export class MyActor extends Actor { ... }
|
|
7
|
+
*
|
|
8
|
+
* At deploy time the bundler replaces this import with the compiled
|
|
9
|
+
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base class for an Actor.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Incoming - messages this actor *receives* from clients
|
|
15
|
+
* (`handleMessage`'s `msg`) — the schema's `toServer` section.
|
|
16
|
+
* @typeParam Outgoing - messages this actor *sends* to clients
|
|
17
|
+
* (`conn.send`/`broadcast`) — the schema's `toClient` section.
|
|
18
|
+
*
|
|
19
|
+
* With a generated `schema.jsonc`, wire both from the registry so they can't drift
|
|
20
|
+
* from the client's types:
|
|
21
|
+
* ```ts
|
|
22
|
+
* type Reg = ActorRegistry["MyActor"];
|
|
23
|
+
* class MyActor extends Actor<Reg["toServer"], Reg["toClient"]> { ... }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class Actor {
|
|
27
|
+
constructor() {
|
|
28
|
+
/**
|
|
29
|
+
* Managed ticker (opt-in). Override {@link shouldTick} and the platform runs
|
|
30
|
+
* {@link handleTick} on a timer of {@link tickIntervalMs} while it returns true,
|
|
31
|
+
* and stops (letting the Durable Object hibernate — no compute cost) when it
|
|
32
|
+
* returns false. The platform owns scheduling, rescheduling, self-heal, and
|
|
33
|
+
* error-safety — you don't call {@link startLoop}/{@link stopLoop}.
|
|
34
|
+
*
|
|
35
|
+
* Re-evaluated after every connect/message/close and on every tick, so keep it
|
|
36
|
+
* cheap and pure (no async, no side effects). Example: `return this.players >= 2`.
|
|
37
|
+
*/
|
|
38
|
+
this.tickIntervalMs = 100;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Optional wake hook: runs once when the instance starts, before any
|
|
42
|
+
* connection is handled — safe to load persisted state here.
|
|
43
|
+
*/
|
|
44
|
+
handleStart() { }
|
|
45
|
+
broadcast(_data) {
|
|
46
|
+
throw new Error("Actor.broadcast() is only available inside a deployed actor");
|
|
47
|
+
}
|
|
48
|
+
getConnections() {
|
|
49
|
+
throw new Error("Actor.getConnections() is only available inside a deployed actor");
|
|
50
|
+
}
|
|
51
|
+
startLoop(_ms) {
|
|
52
|
+
throw new Error("Actor.startLoop() is only available inside a deployed actor");
|
|
53
|
+
}
|
|
54
|
+
stopLoop() {
|
|
55
|
+
throw new Error("Actor.stopLoop() is only available inside a deployed actor");
|
|
56
|
+
}
|
|
57
|
+
get instanceId() {
|
|
58
|
+
throw new Error("Actor.instanceId is only available inside a deployed actor");
|
|
59
|
+
}
|
|
60
|
+
get storage() {
|
|
61
|
+
throw new Error("Actor.storage is only available inside a deployed actor");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Anonymous Base44 client scoped to this actor instance — no user or service
|
|
65
|
+
* auth, so entity access is RLS-gated (same as a logged-out visitor). Always
|
|
66
|
+
* operates on production data: an actor runs server-side with no per-connection
|
|
67
|
+
* identity, so a Test DB preview selected in the editor does not apply here.
|
|
68
|
+
* Example: `const rows = await this.client.entities.Score.list();`
|
|
69
|
+
*/
|
|
70
|
+
get client() {
|
|
71
|
+
throw new Error("Actor.client is only available inside a deployed actor");
|
|
72
|
+
}
|
|
73
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -12,12 +12,12 @@ export type { Base44Client, CreateClientConfig, CreateClientOptions };
|
|
|
12
12
|
* The client supports three authentication modes:
|
|
13
13
|
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
|
|
14
14
|
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
15
|
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations
|
|
15
|
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations bypass entity access rules and field-level security, giving full read and write access to all of the app's data. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
16
16
|
*
|
|
17
17
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
18
18
|
* - **Anonymous**: Can only read public data.
|
|
19
19
|
* - **User authentication**: Can access the current user's data.
|
|
20
|
-
* - **Service role authentication**: Can
|
|
20
|
+
* - **Service role authentication**: Can read and write any record, bypassing access rules.
|
|
21
21
|
*
|
|
22
22
|
* Most modules are available in all three modes, but with different permission levels. However, some modules are only available in specific authentication modes.
|
|
23
23
|
*
|
|
@@ -43,7 +43,7 @@ export declare function createClient(config: CreateClientConfig): Base44Client;
|
|
|
43
43
|
*
|
|
44
44
|
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
45
45
|
*
|
|
46
|
-
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which
|
|
46
|
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which bypasses entity access rules and field-level security.
|
|
47
47
|
*
|
|
48
48
|
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
|
|
49
49
|
*
|
|
@@ -82,7 +82,7 @@ export declare function createClient(config: CreateClientConfig): Base44Client;
|
|
|
82
82
|
* try {
|
|
83
83
|
* const base44 = createClientFromRequest(req);
|
|
84
84
|
*
|
|
85
|
-
* //
|
|
85
|
+
* // Read across all users, bypassing the Orders entity's access rules
|
|
86
86
|
* const recentOrders = await base44.asServiceRole.entities.Orders.list('-created_at', 50);
|
|
87
87
|
*
|
|
88
88
|
* return Response.json({ orders: recentOrders });
|
package/dist/client.js
CHANGED
|
@@ -7,10 +7,12 @@ import { createConnectorsModule, createUserConnectorsModule, } from "./modules/c
|
|
|
7
7
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
8
8
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
9
9
|
import { createAgentsModule } from "./modules/agents.js";
|
|
10
|
+
import { createAiGatewayModule } from "./modules/ai-gateway.js";
|
|
10
11
|
import { createAppLogsModule } from "./modules/app-logs.js";
|
|
11
12
|
import { createUsersModule } from "./modules/users.js";
|
|
12
13
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
13
14
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
15
|
+
import { createActorsModule, resolveActorsHost } from "./modules/actors.js";
|
|
14
16
|
/**
|
|
15
17
|
* Creates a Base44 client.
|
|
16
18
|
*
|
|
@@ -23,12 +25,12 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
23
25
|
* The client supports three authentication modes:
|
|
24
26
|
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
|
|
25
27
|
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
26
|
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations
|
|
28
|
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations bypass entity access rules and field-level security, giving full read and write access to all of the app's data. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
27
29
|
*
|
|
28
30
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
29
31
|
* - **Anonymous**: Can only read public data.
|
|
30
32
|
* - **User authentication**: Can access the current user's data.
|
|
31
|
-
* - **Service role authentication**: Can
|
|
33
|
+
* - **Service role authentication**: Can read and write any record, bypassing access rules.
|
|
32
34
|
*
|
|
33
35
|
* Most modules are available in all three modes, but with different permission levels. However, some modules are only available in specific authentication modes.
|
|
34
36
|
*
|
|
@@ -49,7 +51,7 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
49
51
|
* ```
|
|
50
52
|
*/
|
|
51
53
|
export function createClient(config) {
|
|
52
|
-
var _a, _b;
|
|
54
|
+
var _a, _b, _c;
|
|
53
55
|
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
54
56
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
55
57
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
@@ -112,6 +114,24 @@ export function createClient(config) {
|
|
|
112
114
|
appBaseUrl: normalizedAppBaseUrl,
|
|
113
115
|
serverUrl,
|
|
114
116
|
});
|
|
117
|
+
// Apply the access token before any module that may issue authenticated
|
|
118
|
+
// requests during construction (notably analytics, which fires an init
|
|
119
|
+
// event whose flush calls auth.me()). Without this, the first User/me
|
|
120
|
+
// request is built before setToken runs and goes out unauthenticated.
|
|
121
|
+
if (typeof window !== "undefined") {
|
|
122
|
+
const accessToken = token || getAccessToken();
|
|
123
|
+
if (accessToken) {
|
|
124
|
+
userAuthModule.setToken(accessToken);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const actorsModule = createActorsModule({
|
|
128
|
+
appId,
|
|
129
|
+
// serverUrl is often relative/empty (same-origin app); PartySocket needs an
|
|
130
|
+
// absolute host, so fall back to the page origin.
|
|
131
|
+
host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
|
|
132
|
+
functionsVersion,
|
|
133
|
+
getAuthToken: () => token || getAccessToken(),
|
|
134
|
+
});
|
|
115
135
|
const userModules = {
|
|
116
136
|
entities: createEntitiesModule({
|
|
117
137
|
axios: axiosClient,
|
|
@@ -131,7 +151,7 @@ export function createClient(config) {
|
|
|
131
151
|
}
|
|
132
152
|
return headers;
|
|
133
153
|
},
|
|
134
|
-
baseURL: (
|
|
154
|
+
baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
|
|
135
155
|
}),
|
|
136
156
|
agents: createAgentsModule({
|
|
137
157
|
axios: axiosClient,
|
|
@@ -140,6 +160,7 @@ export function createClient(config) {
|
|
|
140
160
|
serverUrl,
|
|
141
161
|
token,
|
|
142
162
|
}),
|
|
163
|
+
aiGateway: createAiGatewayModule({ serverUrl, token, appId }),
|
|
143
164
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
144
165
|
users: createUsersModule(axiosClient, appId),
|
|
145
166
|
analytics: createAnalyticsModule({
|
|
@@ -148,8 +169,10 @@ export function createClient(config) {
|
|
|
148
169
|
appId,
|
|
149
170
|
userAuthModule,
|
|
150
171
|
}),
|
|
172
|
+
actors: actorsModule.module,
|
|
151
173
|
cleanup: () => {
|
|
152
174
|
userModules.analytics.cleanup();
|
|
175
|
+
actorsModule.closeAll();
|
|
153
176
|
if (socket) {
|
|
154
177
|
socket.disconnect();
|
|
155
178
|
}
|
|
@@ -173,7 +196,7 @@ export function createClient(config) {
|
|
|
173
196
|
}
|
|
174
197
|
return headers;
|
|
175
198
|
},
|
|
176
|
-
baseURL: (
|
|
199
|
+
baseURL: (_c = serviceRoleFunctionsAxiosClient.defaults) === null || _c === void 0 ? void 0 : _c.baseURL,
|
|
177
200
|
}),
|
|
178
201
|
agents: createAgentsModule({
|
|
179
202
|
axios: serviceRoleAxiosClient,
|
|
@@ -182,6 +205,7 @@ export function createClient(config) {
|
|
|
182
205
|
serverUrl,
|
|
183
206
|
token,
|
|
184
207
|
}),
|
|
208
|
+
aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken, appId }),
|
|
185
209
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
186
210
|
cleanup: () => {
|
|
187
211
|
if (socket) {
|
|
@@ -189,14 +213,6 @@ export function createClient(config) {
|
|
|
189
213
|
}
|
|
190
214
|
},
|
|
191
215
|
};
|
|
192
|
-
// Always try to get token from localStorage or URL parameters
|
|
193
|
-
if (typeof window !== "undefined") {
|
|
194
|
-
// Get token from URL or localStorage
|
|
195
|
-
const accessToken = token || getAccessToken();
|
|
196
|
-
if (accessToken) {
|
|
197
|
-
userModules.auth.setToken(accessToken);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
216
|
// If authentication is required, verify token and redirect to login if needed
|
|
201
217
|
if (requiresAuth && typeof window !== "undefined") {
|
|
202
218
|
// We perform this check asynchronously to not block client creation
|
|
@@ -255,7 +271,7 @@ export function createClient(config) {
|
|
|
255
271
|
/**
|
|
256
272
|
* Provides access to service role modules.
|
|
257
273
|
*
|
|
258
|
-
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication
|
|
274
|
+
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication bypasses entity access rules and field-level security entirely, giving full read and write access to all of the app's data.
|
|
259
275
|
*
|
|
260
276
|
* @throws {Error} When accessed without providing a serviceToken during client creation.
|
|
261
277
|
*
|
|
@@ -266,7 +282,7 @@ export function createClient(config) {
|
|
|
266
282
|
* serviceToken: 'service-role-token'
|
|
267
283
|
* });
|
|
268
284
|
*
|
|
269
|
-
* //
|
|
285
|
+
* // Read every user record, bypassing the User entity's access rules
|
|
270
286
|
* const allUsers = await base44.asServiceRole.entities.User.list();
|
|
271
287
|
* ```
|
|
272
288
|
*/
|
|
@@ -284,7 +300,7 @@ export function createClient(config) {
|
|
|
284
300
|
*
|
|
285
301
|
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
286
302
|
*
|
|
287
|
-
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which
|
|
303
|
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which bypasses entity access rules and field-level security.
|
|
288
304
|
*
|
|
289
305
|
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
|
|
290
306
|
*
|
|
@@ -323,7 +339,7 @@ export function createClient(config) {
|
|
|
323
339
|
* try {
|
|
324
340
|
* const base44 = createClientFromRequest(req);
|
|
325
341
|
*
|
|
326
|
-
* //
|
|
342
|
+
* // Read across all users, bypassing the Orders entity's access rules
|
|
327
343
|
* const recentOrders = await base44.asServiceRole.entities.Orders.list('-created_at', 50);
|
|
328
344
|
*
|
|
329
345
|
* return Response.json({ orders: recentOrders });
|
|
@@ -341,6 +357,7 @@ export function createClientFromRequest(request) {
|
|
|
341
357
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
342
358
|
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
343
359
|
const stateHeader = request.headers.get("Base44-State");
|
|
360
|
+
const dataEnvHeader = request.headers.get("X-Data-Env");
|
|
344
361
|
if (!appId) {
|
|
345
362
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
346
363
|
}
|
|
@@ -368,6 +385,16 @@ export function createClientFromRequest(request) {
|
|
|
368
385
|
if (stateHeader) {
|
|
369
386
|
additionalHeaders["Base44-State"] = stateHeader;
|
|
370
387
|
}
|
|
388
|
+
// Propagate the data environment so entity operations from the function stay
|
|
389
|
+
// in the same environment (e.g. test data) as the triggering request. This
|
|
390
|
+
// matters for the user-scoped client: unlike the service token, the user JWT
|
|
391
|
+
// carries no data-env, so without forwarding this header the callbacks fall
|
|
392
|
+
// back to production data even when the app runs in test-data mode.
|
|
393
|
+
// Forward only the known closed set (matches the backend contract) rather
|
|
394
|
+
// than relaying an arbitrary attacker-supplied header value onward.
|
|
395
|
+
if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
|
|
396
|
+
additionalHeaders["X-Data-Env"] = dataEnvHeader;
|
|
397
|
+
}
|
|
371
398
|
return createClient({
|
|
372
399
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
373
400
|
appId,
|
package/dist/client.types.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ import type { SsoModule } from "./modules/sso.types.js";
|
|
|
5
5
|
import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
|
|
6
6
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
7
7
|
import type { AgentsModule } from "./modules/agents.types.js";
|
|
8
|
+
import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
|
|
8
9
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
9
10
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
11
|
+
import type { ActorsModule } from "./modules/actors.types.js";
|
|
10
12
|
/**
|
|
11
13
|
* Options for creating a Base44 client.
|
|
12
14
|
*/
|
|
@@ -49,7 +51,7 @@ export interface CreateClientConfig {
|
|
|
49
51
|
*/
|
|
50
52
|
token?: string;
|
|
51
53
|
/**
|
|
52
|
-
* Service role authentication token. Provides elevated permissions
|
|
54
|
+
* Service role authentication token. Provides elevated permissions that bypass entity access rules and field-level security. Only available in Base44-hosted backend functions. Automatically added to clients created using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
53
55
|
* @internal
|
|
54
56
|
*/
|
|
55
57
|
serviceToken?: string;
|
|
@@ -81,10 +83,14 @@ export interface CreateClientConfig {
|
|
|
81
83
|
export interface Base44Client {
|
|
82
84
|
/** {@link AgentsModule | Agents module} for managing AI agent conversations. */
|
|
83
85
|
agents: AgentsModule;
|
|
86
|
+
/** {@link AiGatewayModule | AI Gateway module} for connecting to the Base44 AI Gateway with your own SDK. */
|
|
87
|
+
aiGateway: AiGatewayModule;
|
|
84
88
|
/** {@link AnalyticsModule | Analytics module} for tracking custom events in your app. */
|
|
85
89
|
analytics: AnalyticsModule;
|
|
86
90
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
87
91
|
appLogs: AppLogsModule;
|
|
92
|
+
/** {@link ActorsModule | Actors module} for subscribing to and sending messages via Cloudflare Durable Object-backed Actors. */
|
|
93
|
+
actors: ActorsModule;
|
|
88
94
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
89
95
|
auth: AuthModule;
|
|
90
96
|
/** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
|
|
@@ -117,13 +123,15 @@ export interface Base44Client {
|
|
|
117
123
|
/**
|
|
118
124
|
* Provides access to supported modules with elevated permissions.
|
|
119
125
|
*
|
|
120
|
-
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication
|
|
126
|
+
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication bypasses entity access rules and field-level security entirely, giving full read and write access to all of the app's data.
|
|
121
127
|
*
|
|
122
128
|
* @throws {Error} When accessed without providing a serviceToken during client creation
|
|
123
129
|
*/
|
|
124
130
|
readonly asServiceRole: {
|
|
125
131
|
/** {@link AgentsModule | Agents module} with elevated permissions. */
|
|
126
132
|
agents: AgentsModule;
|
|
133
|
+
/** {@link AiGatewayModule | AI Gateway module} with the service-role token. */
|
|
134
|
+
aiGateway: AiGatewayModule;
|
|
127
135
|
/** {@link AppLogsModule | App logs module} with elevated permissions. */
|
|
128
136
|
appLogs: AppLogsModule;
|
|
129
137
|
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
|
|
@@ -134,9 +142,7 @@ export interface Base44Client {
|
|
|
134
142
|
functions: FunctionsModule;
|
|
135
143
|
/** {@link IntegrationsModule | Integrations module} with elevated permissions. */
|
|
136
144
|
integrations: IntegrationsModule;
|
|
137
|
-
/** {@link SsoModule | SSO module} for generating SSO tokens.
|
|
138
|
-
* @internal
|
|
139
|
-
*/
|
|
145
|
+
/** {@link SsoModule | SSO module} for generating SSO tokens. */
|
|
140
146
|
sso: SsoModule;
|
|
141
147
|
/** Cleanup function to disconnect WebSocket connections. */
|
|
142
148
|
cleanup: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,16 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
7
|
+
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
9
|
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
|
+
export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
|
|
12
13
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
14
|
+
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
13
15
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
16
|
+
export { Actor, type Conn } from "./actor.js";
|
|
14
17
|
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
15
18
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
16
19
|
export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
|
package/dist/index.js
CHANGED
|
@@ -3,3 +3,4 @@ import { Base44Error } from "./utils/axios-client.js";
|
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export * from "./types.js";
|
|
6
|
+
export { Actor } from "./actor.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ActorRef } from "./actors.types.js";
|
|
2
|
+
interface ActorsConfig {
|
|
3
|
+
appId: string;
|
|
4
|
+
/** Current user access token, if authenticated. Rides the WS query so the
|
|
5
|
+
* platform proxy can authenticate the connection; anonymous connects omit it. */
|
|
6
|
+
getAuthToken(): string | null | undefined;
|
|
7
|
+
/** Same semantics as function calls: editors with a non-prod version get the
|
|
8
|
+
* draft actor script; everyone else gets the published one. */
|
|
9
|
+
functionsVersion?: string;
|
|
10
|
+
/** Absolute host PartySocket dials (it strips the scheme and connects wss, ws
|
|
11
|
+
* for localhost). Resolved by {@link resolveActorsHost}. */
|
|
12
|
+
host: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Absolute host for the actor WebSocket. PartySocket needs an absolute host and
|
|
16
|
+
* can't resolve a relative/empty `serverUrl` (same-origin apps use a relative
|
|
17
|
+
* `/api`, so `serverUrl` is often `""`), so fall back to the page origin.
|
|
18
|
+
* PartySocket handles the scheme (https→wss, ws for localhost).
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveActorsHost(serverUrl: string, browserOrigin?: string): string;
|
|
21
|
+
export declare function createActorsModule(config: ActorsConfig): {
|
|
22
|
+
module: Record<string, (instanceId: string) => ActorRef>;
|
|
23
|
+
closeAll: () => void;
|
|
24
|
+
};
|
|
25
|
+
export {};
|