@base44-preview/sdk 0.8.48-pr.289.b9ea964 → 0.8.48-pr.301.c32fae8
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 +9 -0
- package/dist/actor.d.ts +2 -2
- package/dist/modules/actors.types.d.ts +37 -132
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -151,3 +151,12 @@ npm run create-docs
|
|
|
151
151
|
cd docs
|
|
152
152
|
mintlify dev
|
|
153
153
|
```
|
|
154
|
+
|
|
155
|
+
### Platform SDK
|
|
156
|
+
|
|
157
|
+
The browser client for the Base44 platform lives in this repo as a separate
|
|
158
|
+
package, [`@base44/platform`](packages/platform). It watches public builder
|
|
159
|
+
updates for up to eight apps over the platform socket, using a socket-session
|
|
160
|
+
token your backend opens with its workspace key. It does not depend on
|
|
161
|
+
`@base44/sdk`. White-label sockets must be enabled for the workspace; never use
|
|
162
|
+
an API key in the browser.
|
package/dist/actor.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export interface Storage {
|
|
|
25
25
|
get<T>(key: string): Promise<T | undefined>;
|
|
26
26
|
put(key: string, value: unknown): Promise<void>;
|
|
27
27
|
delete(key: string): Promise<boolean>;
|
|
28
|
-
/** Wipe the
|
|
29
|
-
*
|
|
28
|
+
/** Wipe the room's entire persisted storage (match-end cleanup). Safe: a
|
|
29
|
+
* later rejoin re-bootstraps exactly like a brand-new room. */
|
|
30
30
|
deleteAll(): Promise<void>;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Extend this interface to add typed `subscribe` callbacks and `send` payloads
|
|
3
|
+
* for your deployed Actors.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* defines incoming messages that a client sends to the actor. `toClient` defines
|
|
7
|
-
* outgoing messages that the actor sends to connected clients.
|
|
5
|
+
* This is separate from {@link ActorNameRegistry} (which is auto-generated
|
|
6
|
+
* by `base44 types generate`), so there are no conflicts.
|
|
8
7
|
*
|
|
9
8
|
* @example
|
|
10
9
|
* ```typescript
|
|
@@ -21,10 +20,8 @@
|
|
|
21
20
|
export interface ActorRegistry {
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* The generated names provide autocomplete for deployed actors. To define
|
|
27
|
-
* incoming and outgoing message types manually, augment {@link ActorRegistry}.
|
|
23
|
+
* Auto-populated by `base44 types generate` with the names of your deployed actors.
|
|
24
|
+
* Do not edit this interface manually — use {@link ActorRegistry} for message types.
|
|
28
25
|
*/
|
|
29
26
|
export interface ActorNameRegistry {
|
|
30
27
|
}
|
|
@@ -35,163 +32,71 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
|
|
|
35
32
|
type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
36
33
|
toServer: infer O;
|
|
37
34
|
} ? O : unknown : unknown;
|
|
38
|
-
/**
|
|
39
|
-
* Options for {@link ActorRef.connect}.
|
|
40
|
-
*/
|
|
35
|
+
/** Options for {@link ActorRef.connect}. */
|
|
41
36
|
export interface ActorConnectOptions {
|
|
42
37
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* reconnections from that client reuse the same connection ID. Omit this property
|
|
47
|
-
* to generate an ID.
|
|
38
|
+
* The connection id — becomes the actor's `conn.id`. Supply a stable value
|
|
39
|
+
* (e.g. persisted per tab) so a reconnect reuses the same server-side
|
|
40
|
+
* identity; omit for an auto-generated per-connection id.
|
|
48
41
|
*/
|
|
49
42
|
id?: string;
|
|
50
43
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Represents an outgoing-message listener registered with
|
|
53
|
-
* {@link Connection.subscribe}.
|
|
54
|
-
*/
|
|
44
|
+
/** Handle for one listener registered via {@link Connection.subscribe}. */
|
|
55
45
|
export interface ActorSubscription {
|
|
56
|
-
/**
|
|
57
|
-
* Removes this listener. Other listeners and the socket stay open.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const sub = conn.subscribe((msg) => console.log(msg));
|
|
62
|
-
* sub.unsubscribe();
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
46
|
+
/** Remove this listener; other listeners and the socket stay live. */
|
|
65
47
|
unsubscribe(): void;
|
|
66
48
|
}
|
|
67
49
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* The socket buffers messages sent during connection setup until it opens.
|
|
50
|
+
* A live connection to an actor instance, returned by {@link ActorRef.connect}.
|
|
51
|
+
* `subscribe`/`send` are always valid — you only get a `Connection` once the
|
|
52
|
+
* socket has been opened, so there's no pre-connect state to guard against.
|
|
72
53
|
*/
|
|
73
54
|
export interface Connection<N extends string = string> {
|
|
74
|
-
/**
|
|
55
|
+
/** The connection id (the value the actor sees as `conn.id`). */
|
|
75
56
|
readonly id: string;
|
|
76
|
-
/**
|
|
77
|
-
* Registers a listener for outgoing messages from the actor.
|
|
78
|
-
*
|
|
79
|
-
* You can register multiple listeners on the same connection.
|
|
80
|
-
*
|
|
81
|
-
* @param callback - Called with each outgoing message sent to this connection.
|
|
82
|
-
* @returns A handle you can use to remove this listener without closing the socket.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const conn = base44.actors.Chat("session-1").connect();
|
|
87
|
-
* const sub = conn.subscribe((msg) => {
|
|
88
|
-
* if (msg.type === "message") console.log(msg.text);
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
57
|
+
/** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
|
|
92
58
|
subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* The socket buffers messages until it opens. After {@link close}, the socket
|
|
97
|
-
* drops further sends.
|
|
98
|
-
*
|
|
99
|
-
* @param data - Incoming message to send. Typed through {@link ActorRegistry} when configured.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* conn.send({ type: "message", text: "Hello" });
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
59
|
+
/** Send a message. Buffered by the socket until it's open; dropped after
|
|
60
|
+
* {@link close}. */
|
|
106
61
|
send(data: ToServerFor<N>): void;
|
|
107
62
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* permanently. See {@link ActorRef.connect} for how to open a fresh connection.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* conn.close();
|
|
116
|
-
* ```
|
|
63
|
+
* Tear down the socket, heartbeat, and all listeners. Safe to call more
|
|
64
|
+
* than once. A connection also closes itself when it fails permanently —
|
|
65
|
+
* see {@link ActorRef.connect}.
|
|
117
66
|
*/
|
|
118
67
|
close(): void;
|
|
119
68
|
}
|
|
120
69
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* Call {@link connect} to open the WebSocket and get a {@link Connection}.
|
|
70
|
+
* A handle to one actor instance — `base44.actors.MyActor(id)`. Call
|
|
71
|
+
* {@link connect} to open the socket and get a {@link Connection}.
|
|
124
72
|
*/
|
|
125
73
|
export interface ActorRef<N extends string = string> {
|
|
126
74
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* Repeated calls return the same connection until it closes. After a permanent
|
|
130
|
-
* failure, such as a missing actor or denied connection, fix the cause and call
|
|
131
|
-
* `connect()` again. Add subscriptions to the new connection.
|
|
75
|
+
* Open the WebSocket and return the {@link Connection}. Idempotent while the
|
|
76
|
+
* connection is open.
|
|
132
77
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @
|
|
137
|
-
* ```typescript
|
|
138
|
-
* const conn = base44.actors.Chat("session-1").connect({ id: "tab-abc" });
|
|
139
|
-
* conn.subscribe((msg) => console.log(msg));
|
|
140
|
-
* ```
|
|
78
|
+
* A connection that fails permanently (for example, the actor doesn't exist
|
|
79
|
+
* or the caller isn't allowed to connect) closes itself and reports the
|
|
80
|
+
* error to the client's `onError` handler. Call `connect()` again after
|
|
81
|
+
* fixing the cause to get a fresh {@link Connection}, and re-subscribe.
|
|
141
82
|
*/
|
|
142
83
|
connect(options?: ActorConnectOptions): Connection<N>;
|
|
143
84
|
}
|
|
144
85
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* {@link ActorNameRegistry}.
|
|
86
|
+
* Client for a single named Actor — call it with an instance id to get an
|
|
87
|
+
* {@link ActorRef}. Typed automatically when the actor is registered in
|
|
88
|
+
* {@link ActorRegistry}.
|
|
149
89
|
*/
|
|
150
90
|
export interface ActorClient<N extends string = string> {
|
|
151
|
-
/**
|
|
152
|
-
* Gets a reference to an actor session.
|
|
153
|
-
*
|
|
154
|
-
* Clients that specify the same actor name and session ID join the same session.
|
|
155
|
-
*
|
|
156
|
-
* @param instanceId - Session ID that identifies which session to connect to.
|
|
157
|
-
* @returns A reference to the actor session.
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* const session = base44.actors.Chat("lobby-1");
|
|
162
|
-
* const conn = session.connect();
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
91
|
(instanceId: string): ActorRef<N>;
|
|
166
92
|
}
|
|
167
93
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* Select an actor by name and session ID, then connect a client to the
|
|
171
|
-
* session. Clients in the same session can exchange realtime messages through the
|
|
172
|
-
* actor. The client works in the browser and in Node.
|
|
173
|
-
*
|
|
174
|
-
* ## Connection flow
|
|
175
|
-
*
|
|
176
|
-
* - Connect to a session with `base44.actors.<ActorName>(sessionId).connect()`.
|
|
177
|
-
* - Subscribe to outgoing messages with {@link Connection.subscribe}.
|
|
178
|
-
* - Send incoming messages with {@link Connection.send}.
|
|
179
|
-
* - Close the connection with {@link Connection.close}.
|
|
94
|
+
* The actors module provides access to Cloudflare Durable Object-backed
|
|
95
|
+
* Actors deployed by the Base44 platform.
|
|
180
96
|
*
|
|
181
|
-
* See [Actors Overview](/developers/backend/resources/actors/overview)
|
|
182
|
-
* for actor concepts and terminology, and the [Actor Class Reference](/developers/backend/resources/actors/reference)
|
|
183
|
-
* for the backend class API.
|
|
184
|
-
*
|
|
185
|
-
* ## Authentication modes
|
|
186
|
-
*
|
|
187
|
-
* This module is available in anonymous or user authentication mode
|
|
188
|
-
* (`base44.actors`). It isn't available with service role authentication. Apps that
|
|
189
|
-
* require login can reject anonymous connections in the actor's `handleConnect()` method.
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
97
|
* ```typescript
|
|
193
|
-
* const conn = base44.actors.
|
|
194
|
-
* const sub = conn.subscribe((msg) => console.log(msg));
|
|
98
|
+
* const conn = base44.actors.MyActor("room-1").connect();
|
|
99
|
+
* const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
|
|
195
100
|
* conn.send({ type: "message", text: "hi" });
|
|
196
101
|
* sub.unsubscribe();
|
|
197
102
|
* conn.close();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.48-pr.
|
|
3
|
+
"version": "0.8.48-pr.301.c32fae8",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"workspaces": [
|
|
12
|
+
"packages/*"
|
|
13
|
+
],
|
|
11
14
|
"scripts": {
|
|
12
15
|
"build": "tsc",
|
|
13
|
-
"lint": "eslint src",
|
|
16
|
+
"lint": "eslint src packages/platform/src packages/platform/examples",
|
|
14
17
|
"test": "npm run test:types && vitest run",
|
|
15
18
|
"test:types": "tsc --noEmit -p tsconfig.type-tests.json",
|
|
16
19
|
"test:unit": "vitest run tests/unit",
|
|
@@ -23,7 +26,9 @@
|
|
|
23
26
|
"create-docs-local": "npm run create-docs && npm run copy-docs-local",
|
|
24
27
|
"copy-docs-local": "node scripts/mintlify-post-processing/copy-to-local-docs.js",
|
|
25
28
|
"create-docs:generate": "typedoc",
|
|
26
|
-
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
|
|
29
|
+
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js",
|
|
30
|
+
"build:platform": "npm run build -w @base44/platform",
|
|
31
|
+
"test:platform": "npm test -w @base44/platform"
|
|
27
32
|
},
|
|
28
33
|
"dependencies": {
|
|
29
34
|
"axios": "^1.18.1",
|