@base44-preview/sdk 0.8.53-pr.308.2df7905 → 0.8.53-pr.311.53c78b4

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/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 room's entire persisted storage (match-end cleanup). Safe: a
29
- * later rejoin re-bootstraps exactly like a brand-new room. */
28
+ /** Deletes all persisted storage for the session. A later connection starts
29
+ * with empty storage, the same as a new session. */
30
30
  deleteAll(): Promise<void>;
31
31
  }
32
32
  /**
@@ -1,15 +1,23 @@
1
1
  /**
2
- * Extend this interface to add typed `subscribe` callbacks and `send` payloads
3
- * for your deployed Actors.
2
+ * Maps actor names to their incoming and outgoing message types.
4
3
  *
5
- * This is separate from {@link ActorNameRegistry} (which is auto-generated
6
- * by `base44 types generate`), so there are no conflicts.
4
+ * Extend this interface when you want typed actor
5
+ * messages without generating types with the CLI:
6
+ * - `toServer`: Defines incoming messages that a client sends to the actor.
7
+ * - `toClient`: Defines outgoing messages that the actor sends to connected clients.
8
+ *
9
+ * To generate types from deployed actors, use the
10
+ * [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
11
+ *
12
+ * To learn how incoming and outgoing messages work, see
13
+ * [message types](/developers/backend/resources/actors/overview#message-types).
7
14
  *
8
15
  * @example
9
16
  * ```typescript
17
+ * // Type messages for an actor
10
18
  * declare module "@base44/sdk" {
11
19
  * interface ActorRegistry {
12
- * ChatRoom: {
20
+ * chatRoom: {
13
21
  * toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
14
22
  * toServer: { type: "message"; text: string };
15
23
  * };
@@ -20,8 +28,11 @@
20
28
  export interface ActorRegistry {
21
29
  }
22
30
  /**
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.
31
+ * Lists actor names when your project includes types generated by the CLI
32
+ * with [`types generate`](/developers/references/cli/commands/types-generate).
33
+ *
34
+ * The generated names provide autocomplete for deployed actors. To define
35
+ * incoming and outgoing message types manually, augment {@linkcode ActorRegistry}.
25
36
  */
26
37
  export interface ActorNameRegistry {
27
38
  }
@@ -32,75 +43,169 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
32
43
  type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
33
44
  toServer: infer O;
34
45
  } ? O : unknown : unknown;
35
- /** Options for {@link ActorRef.connect}. */
46
+ /**
47
+ * Configures the connection that {@linkcode ActorRef.connect | connect()} opens.
48
+ */
36
49
  export interface ActorConnectOptions {
37
50
  /**
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.
51
+ * Connection ID that the actor receives as `conn.id`.
52
+ *
53
+ * To let the actor recognize a client when it reconnects, use a stable
54
+ * value, such as an ID stored per browser tab. If you omit this property, the
55
+ * SDK generates a new connection ID.
41
56
  */
42
57
  id?: string;
43
58
  }
44
- /** Handle for one listener registered via {@link Connection.subscribe}. */
59
+ /**
60
+ * Represents a listener for messages from the actor, registered with
61
+ * {@linkcode Connection.subscribe | subscribe()}.
62
+ */
45
63
  export interface ActorSubscription {
46
- /** Remove this listener; other listeners and the socket stay live. */
64
+ /**
65
+ * Removes this listener. Other listeners and the socket stay open.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // Remove a listener
70
+ * sub.unsubscribe();
71
+ * ```
72
+ */
47
73
  unsubscribe(): void;
48
74
  }
49
75
  /**
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.
76
+ * Represents a client's [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) connection to an actor session, returned after calling
77
+ * [`connect()`](#connect). The WebSocket queues messages you send before it opens.
78
+ *
79
+ * Learn more about
80
+ * [connections](/developers/backend/resources/actors/reference#connections).
53
81
  */
54
82
  export interface Connection<N extends string = string> {
55
- /** The connection id (the value the actor sees as `conn.id`). */
83
+ /** Connection ID that the actor receives as `conn.id`. */
56
84
  readonly id: string;
57
- /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
85
+ /**
86
+ * Registers a listener for messages from the actor.
87
+ *
88
+ * You can register multiple listeners on the same connection.
89
+ *
90
+ * @param callback - Callback that runs for each message the actor sends to this connection.
91
+ * @returns A subscription handle. Call `unsubscribe()` on it to remove this listener without closing the socket.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // Listen for messages from the actor
96
+ * const sub = conn.subscribe((msg) => {
97
+ * console.log(msg);
98
+ * });
99
+ *
100
+ * // Stop listening without closing the socket.
101
+ * sub.unsubscribe();
102
+ * ```
103
+ */
58
104
  subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
59
- /** Send a message. Buffered by the socket until it's open; dropped after
60
- * {@link close}. */
105
+ /**
106
+ * Sends a message to the actor.
107
+ *
108
+ * The WebSocket queues messages until it opens. When you call {@linkcode Connection.close | close()},
109
+ * the WebSocket drops any messages you send afterward.
110
+ *
111
+ * @param data - Message to send to the actor. The type comes from {@linkcode ActorRegistry} when you register the actor there.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Send a message to the actor
116
+ * conn.send({ type: "message", text: "Hello" });
117
+ * ```
118
+ */
61
119
  send(data: ToServerFor<N>): void;
62
120
  /**
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}.
121
+ * Closes the connection and removes all listeners.
122
+ *
123
+ * You can call this method more than once. A connection also closes itself
124
+ * when it fails permanently.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Close the connection
129
+ * conn.close();
130
+ * ```
66
131
  */
67
132
  close(): void;
68
133
  }
69
134
  /**
70
- * A handle to one actor instance — `base44.actors.MyActor(id)`. Call
71
- * {@link connect} to open the socket and get a {@link Connection}.
135
+ * Represents a reference to an actor session, identified by actor name and session ID.
136
+ *
137
+ * Call {@linkcode ActorRef.connect | connect()} to open the WebSocket and get a [connection](/developers/backend/resources/actors/overview#connections).
72
138
  */
73
139
  export interface ActorRef<N extends string = string> {
74
140
  /**
75
- * Open the WebSocket and return the {@link Connection}. Idempotent while the
76
- * connection is open.
141
+ * Creates or returns the connection for this session.
142
+ *
143
+ * Calling `connect()` again on the same session reference returns the same
144
+ * connection until it closes.
145
+ *
146
+ * For a sample flow, see
147
+ * [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
77
148
  *
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.
149
+ * @param options - Optional connection settings, such as a stable connection ID.
150
+ * @returns The connection for this actor session.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Connect to a session
155
+ * const conn = base44.actors.chatRoom("session-1").connect({ id: "tab-1" });
156
+ * ```
82
157
  */
83
158
  connect(options?: ActorConnectOptions): Connection<N>;
84
159
  }
85
160
  /**
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}.
161
+ * Selects a session for a named actor.
162
+ *
163
+ * TypeScript infers message types when you register the actor in
164
+ * {@linkcode ActorRegistry}. {@linkcode ActorNameRegistry}
165
+ * provides autocomplete for actor names only.
89
166
  */
90
167
  export interface ActorClient<N extends string = string> {
168
+ /**
169
+ * Gets a reference to an actor session.
170
+ *
171
+ * Clients that specify the same actor name and session ID join the same session.
172
+ *
173
+ * @param instanceId - Session ID that identifies which session to connect to.
174
+ * @returns A reference to the actor session.
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * // Select a session
179
+ * const session = base44.actors.chatRoom("session-1");
180
+ * ```
181
+ */
91
182
  (instanceId: string): ActorRef<N>;
92
183
  }
93
184
  /**
94
- * The actors module provides access to Cloudflare Durable Object-backed
95
- * Actors deployed by the Base44 platform.
185
+ * Actors module for interacting with [actors](/developers/backend/resources/actors/overview) from your app.
96
186
  *
97
- * ```typescript
98
- * const conn = base44.actors.MyActor("room-1").connect();
99
- * const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
100
- * conn.send({ type: "message", text: "hi" });
101
- * sub.unsubscribe();
102
- * conn.close();
103
- * ```
187
+ * An actor is a long-running backend process that multiple clients connect to simultaneously. A session
188
+ * is a running instance of an actor, identified by the actor name and a session ID. Each
189
+ * session manages its own state, storage, and client connections independently.
190
+ *
191
+ * The actors module provides the functionality to:
192
+ *
193
+ * - Manage connections: {@link ActorRef.connect | Open} and {@link Connection.close | close} a WebSocket connection to a session.
194
+ * - Exchange messages: {@link Connection.send | Send} and {@link Connection.subscribe | listen} for messages to and from an actor.
195
+ * - Manage subscriptions: {@link Connection.subscribe | Subscribe} and {@link ActorSubscription.unsubscribe | unsubscribe} from actor messages without closing the connection.
196
+ *
197
+ * For a sample flow, see
198
+ * [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
199
+ *
200
+ * ## Authentication modes
201
+ *
202
+ * This module is available to use with a client in anonymous or user authentication mode. Access it
203
+ * through `base44.actors`. It isn't available in
204
+ * [service role authentication mode](/developers/references/sdk/getting-started/client#service-role).
205
+ *
206
+ * The actor receives each client's [identity](/developers/backend/resources/actors/reference#connections)
207
+ * when the client connects. A client that hasn't logged in connects as anonymous, and a client that
208
+ * has [logged in](/developers/references/sdk/docs/interfaces/auth) connects as authenticated.
104
209
  */
105
210
  export type ActorsModule = {
106
211
  [K in AllActorNames]: K extends keyof ActorRegistry ? ActorClient<string & K> : ActorClient;
@@ -470,7 +470,7 @@ export interface UserConnectorsModule {
470
470
  * authenticate with the external service. The scopes and integration type are
471
471
  * derived from the connector configuration in the backend.
472
472
  *
473
- * @param connectorId - The ID of the app user connector configured in your workspace. The AI builder inserts this ID into generated code when it sets up the connector flow. You can also retrieve it from the workspace connectors API.
473
+ * @param connectorId - The ID of the app user connector configured in your workspace. The AI inserts this ID into generated code when it sets up the connector flow. You can also retrieve it from the workspace connectors API.
474
474
  * @returns Promise resolving to the redirect URL string.
475
475
  *
476
476
  * @example
@@ -489,7 +489,7 @@ export interface UserConnectorsModule {
489
489
  * Removes the stored OAuth credentials for the currently authenticated app user's
490
490
  * connection to the specified connector.
491
491
  *
492
- * @param connectorId - The ID of the app user connector configured in your workspace. The AI builder inserts this ID into generated code when it sets up the connector flow. You can also retrieve it from the workspace connectors API.
492
+ * @param connectorId - The ID of the app user connector configured in your workspace. The AI inserts this ID into generated code when it sets up the connector flow. You can also retrieve it from the workspace connectors API.
493
493
  * @returns Promise resolving when the connection has been removed.
494
494
  *
495
495
  * @example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.53-pr.308.2df7905",
3
+ "version": "0.8.53-pr.311.53c78b4",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",