@base44-preview/sdk 0.8.52-pr.305.d6c90ab → 0.8.53-pr.289.39e1f1f

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,22 @@
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 through module augmentation when you want typed actor
5
+ * messages without generating types with the CLI. For each actor, `toServer`
6
+ * defines incoming messages that a client sends to the actor. `toClient` defines
7
+ * outgoing messages that the actor sends to connected clients.
8
+ *
9
+ * To generate types from deployed actors instead, use the
10
+ * [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
11
+ * To learn how incoming and outgoing messages work, see
12
+ * [message types](/developers/backend/resources/actors/overview#message-types).
7
13
  *
8
14
  * @example
9
15
  * ```typescript
16
+ * // Type messages for an actor
10
17
  * declare module "@base44/sdk" {
11
18
  * interface ActorRegistry {
12
- * ChatRoom: {
19
+ * chatRoom: {
13
20
  * toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
14
21
  * toServer: { type: "message"; text: string };
15
22
  * };
@@ -20,8 +27,11 @@
20
27
  export interface ActorRegistry {
21
28
  }
22
29
  /**
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.
30
+ * Lists actor names when your project includes types generated by the CLI
31
+ * with [`types generate`](/developers/references/cli/commands/types-generate).
32
+ *
33
+ * The generated names provide autocomplete for deployed actors. To define
34
+ * incoming and outgoing message types manually, augment [ActorRegistry](#actorregistry).
25
35
  */
26
36
  export interface ActorNameRegistry {
27
37
  }
@@ -32,71 +42,173 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
32
42
  type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
33
43
  toServer: infer O;
34
44
  } ? O : unknown : unknown;
35
- /** Options for {@link ActorRef.connect}. */
45
+ /**
46
+ * Configures the connection that [ActorRef.connect](#connect) opens.
47
+ */
36
48
  export interface ActorConnectOptions {
37
49
  /**
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.
50
+ * Connection ID that the actor receives as `conn.id`.
51
+ *
52
+ * To let the actor recognize the same client if it reconnects, use a stable
53
+ * value, such as an ID stored per browser tab. If you omit this property, the
54
+ * SDK generates a connection ID.
55
+ *
56
+ * For more about connection IDs, see
57
+ * [connections](/developers/backend/resources/actors/reference#connections).
41
58
  */
42
59
  id?: string;
43
60
  }
44
- /** Handle for one listener registered via {@link Connection.subscribe}. */
61
+ /**
62
+ * Represents a listener for messages from the actor, registered with
63
+ * [Connection.subscribe](#subscribe).
64
+ */
45
65
  export interface ActorSubscription {
46
- /** Remove this listener; other listeners and the socket stay live. */
66
+ /**
67
+ * Removes this listener. Other listeners and the socket stay open.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Remove a listener
72
+ * sub.unsubscribe();
73
+ * ```
74
+ */
47
75
  unsubscribe(): void;
48
76
  }
49
77
  /**
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.
78
+ * Represents a client's WebSocket connection to an actor session.
79
+ *
80
+ * [ActorRef.connect](#connect) returns this object. The socket buffers messages
81
+ * you send before it opens.
53
82
  */
54
83
  export interface Connection<N extends string = string> {
55
- /** The connection id (the value the actor sees as `conn.id`). */
84
+ /** Connection ID that the actor receives as `conn.id`. */
56
85
  readonly id: string;
57
- /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
86
+ /**
87
+ * Registers a listener for messages from the actor.
88
+ *
89
+ * You can register multiple listeners on the same connection.
90
+ *
91
+ * @param callback - Callback that runs for each message the actor sends to this connection.
92
+ * @returns A subscription handle. Call `unsubscribe()` on it to remove this listener without closing the socket.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Listen for messages from the actor
97
+ * const sub = conn.subscribe((msg) => {
98
+ * console.log(msg);
99
+ * });
100
+ *
101
+ * // Stop listening without closing the socket.
102
+ * sub.unsubscribe();
103
+ * ```
104
+ */
58
105
  subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
59
- /** Send a message. Buffered by the socket until it's open; dropped after
60
- * {@link close}. */
106
+ /**
107
+ * Sends a message to the actor.
108
+ *
109
+ * The socket buffers messages until it opens. After you call [close](#close),
110
+ * the socket drops further sends.
111
+ *
112
+ * @param data - Message to send to the actor. The type comes from [ActorRegistry](#actorregistry) when you register the actor there.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Send a message to the actor
117
+ * conn.send({ type: "message", text: "Hello" });
118
+ * ```
119
+ */
61
120
  send(data: ToServerFor<N>): void;
62
121
  /**
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}.
122
+ * Closes the connection and removes all listeners.
123
+ *
124
+ * You can call this method more than once. A connection also closes itself
125
+ * when it fails permanently. To open a new connection, call
126
+ * [ActorRef.connect](#connect) again.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Close the connection
131
+ * conn.close();
132
+ * ```
66
133
  */
67
134
  close(): void;
68
135
  }
69
136
  /**
70
- * A handle to one actor instance — `base44.actors.MyActor(id)`. Call
71
- * {@link connect} to open the socket and get a {@link Connection}.
137
+ * Represents a reference to an actor session, identified by actor name and session ID.
138
+ *
139
+ * Call [connect](#connect) to open the WebSocket and get a [Connection](#connection).
72
140
  */
73
141
  export interface ActorRef<N extends string = string> {
74
142
  /**
75
- * Open the WebSocket and return the {@link Connection}. Idempotent while the
76
- * connection is open.
143
+ * Creates or returns the [Connection](#connection) for this session.
144
+ *
145
+ * Repeated calls return the same connection until it closes. If the connection
146
+ * fails permanently, for example because the actor doesn't exist or the actor
147
+ * denies the connection, fix the cause and call `connect()` again. Then
148
+ * subscribe again on the new connection.
149
+ *
150
+ * For a sample flow, see
151
+ * [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
77
152
  *
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.
153
+ * @param options - Optional connection settings, such as a stable connection ID.
154
+ * @returns The [Connection](#connection) for this actor session.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Connect to a session
159
+ * const conn = base44.actors.chatRoom("session-1").connect({ id: "tab-1" });
160
+ * ```
82
161
  */
83
162
  connect(options?: ActorConnectOptions): Connection<N>;
84
163
  }
85
164
  /**
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}.
165
+ * Selects a session for a named actor.
166
+ *
167
+ * TypeScript infers message types when you register the actor in
168
+ * [ActorRegistry](#actorregistry). [ActorNameRegistry](#actornameregistry)
169
+ * provides autocomplete for actor names only.
89
170
  */
90
171
  export interface ActorClient<N extends string = string> {
172
+ /**
173
+ * Gets a reference to an actor session.
174
+ *
175
+ * Clients that specify the same actor name and session ID join the same session.
176
+ *
177
+ * @param instanceId - Session ID that identifies which session to connect to.
178
+ * @returns A reference to the actor session.
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Select a session
183
+ * const session = base44.actors.chatRoom("session-1");
184
+ * ```
185
+ */
91
186
  (instanceId: string): ActorRef<N>;
92
187
  }
93
188
  /**
94
- * The actors module provides access to Cloudflare Durable Object-backed
95
- * Actors deployed by the Base44 platform.
189
+ * Connects your frontend to [actor sessions](/developers/backend/resources/actors/overview),
190
+ * shared live backend processes where clients can exchange messages in realtime.
96
191
  *
192
+ * The following table lists what you can do with the actors module:
193
+ *
194
+ * | Member | Purpose |
195
+ * |---|---|
196
+ * | [`connect()`](#connect) | Opens a connection to a session. Clients that use the same actor name and session ID join the same session. |
197
+ * | [`subscribe()`](#subscribe) | Receives messages from an actor. |
198
+ * | [`send()`](#send) | Sends a message to an actor. |
199
+ * | [`ActorRegistry`](#actorregistry) | Defines message types for autocomplete and compile-time safety. |
200
+ *
201
+ * ## Authentication modes
202
+ *
203
+ * This module is available in anonymous and user authentication modes.
204
+ * Apps that require login can reject anonymous connections in the actor's `handleConnect()` method.
205
+ * To learn more, see [manage client connections](/developers/backend/resources/actors/sample-flows#manage-client-connections).
206
+ *
207
+ * @example
97
208
  * ```typescript
98
- * const conn = base44.actors.MyActor("room-1").connect();
99
- * const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
209
+ * // Connect, subscribe, send, and close
210
+ * const conn = base44.actors.chatRoom("session-1").connect({ id: "tab-1" });
211
+ * const sub = conn.subscribe((msg) => console.log(msg));
100
212
  * conn.send({ type: "message", text: "hi" });
101
213
  * sub.unsubscribe();
102
214
  * conn.close();
@@ -42,7 +42,7 @@ export interface AiGatewayModuleConfig {
42
42
  /**
43
43
  * AI Gateway module for calling Base44's managed AI models from your own code.
44
44
  *
45
- * Call `connection()` to get a `baseURL`, `token`, and `headers` that
45
+ * `connection()` hands you a `baseURL`, `token`, and `headers` that
46
46
  * authenticate as your Base44 app. An OpenAI-compatible client is any library, such as the `openai`
47
47
  * SDK or the Vercel AI SDK, that has the same request and response format
48
48
  * as OpenAI's API and lets you point it at a custom `baseURL`
@@ -51,9 +51,9 @@ export interface AiGatewayModuleConfig {
51
51
  * against the provider directly, no separate account, API key, or billing
52
52
  * setup with the underlying model provider required.
53
53
  *
54
- * The optional `provider` picks the API you connect to:
54
+ * `connection()` takes an optional `provider`, and each provider serves a different API:
55
55
  *
56
- * - `openai`, the default: OpenAI-compatible chat completions, image, and video endpoints.
56
+ * - `openai` (default): OpenAI-compatible chat completions and image endpoints.
57
57
  * - `typesafe`: structured evaluations with the `jev` model.
58
58
  *
59
59
  * Call `connection()` from a backend function rather than the browser. This
@@ -71,32 +71,20 @@ export interface AiGatewayModuleConfig {
71
71
  *
72
72
  * The gateway also serves OpenAI's image endpoints, `/images/generations`
73
73
  * and `/images/edits`, so you can generate images and edit them using
74
- * reference images. Image requests use their own set of models. Pass
74
+ * reference images. Image requests use their own set of models: pass
75
75
  * `'automatic'` to let Base44 choose one, or pin a model such as
76
76
  * `'gemini_3_1_flash_image'` or `'gpt_image_2'`. For request options, the
77
77
  * full model list, and limits, see [Generate images with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-images).
78
78
  *
79
- * ## Video
80
- *
81
- * The gateway also serves OpenAI's video endpoints, `/videos`, so you can
82
- * generate video from a prompt, from a still image, or from existing media.
83
- * Video generation is asynchronous. `POST /videos` returns a job, and you poll
84
- * `GET /videos/{id}` until its status is `completed` or `failed`, which can
85
- * take minutes. Video models are their own set, and there's no `automatic`
86
- * option, so pin a model such as `'veo_3_1_fast'` or `'seedance_2'`. For
87
- * request options, the full model list, and limits, see
88
- * [Generate video with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-video).
89
- *
90
79
  * ## Structured evaluations
91
80
  *
92
81
  * The `typesafe` provider runs the `jev` evaluation model through
93
82
  * `@ai-sdk/typesafe-ai` and `experimental_evaluate` from the `ai` package,
94
- * version 7.0.105 or later. Pass `evaluationModel("jev")`, and note that the
95
- * gateway rejects other model IDs, such as `"jev-latest"`. Give it some app
96
- * state and a set of questions, each a `choice`, `score`, or `boolean`. Choice
97
- * and score answers come back with `probabilities` per option, and boolean
98
- * answers with a single `probability` of `true`. Use it to classify, score, or
99
- * route records, then
83
+ * version 7.0.105 or later. Pass `evaluationModel("jev")`; the gateway rejects
84
+ * other model IDs, such as `"jev-latest"`. Give it some app state and a set of
85
+ * questions, each a `choice`, `score`, or `boolean`. Choice and score answers
86
+ * come back with `probabilities` per option; boolean answers with a single
87
+ * `probability` of `true`. Use it to classify, score, or route records, then
100
88
  * apply your own thresholds and actions in code.
101
89
  *
102
90
  * ## Authentication Modes
@@ -104,7 +92,7 @@ export interface AiGatewayModuleConfig {
104
92
  * The mode determines which token `connection()` returns:
105
93
  *
106
94
  * - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token.
107
- * - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead. Use it from backend functions, because apps that restrict Core integrations, the default for new apps, reject user-token gateway calls on public apps. It also works when there's no signed-in user, such as from a scheduled automation.
95
+ * - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead. Use it from backend functions: apps that restrict Core integrations, the default for new apps, reject user-token gateway calls on public apps. It also works when there's no signed-in user, such as from a scheduled automation.
108
96
  *
109
97
  * ## Billing and limits
110
98
  *
@@ -212,30 +200,6 @@ export interface AiGatewayModule {
212
200
  *
213
201
  * @example
214
202
  * ```typescript
215
- * // Start a video and record the job to poll later
216
- * import { createClientFromRequest } from "@base44/sdk";
217
- *
218
- * // Runs inside a backend function
219
- * const base44 = createClientFromRequest(request);
220
- * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
221
- *
222
- * const response = await fetch(`${baseURL}/videos`, {
223
- * method: "POST",
224
- * headers: { ...headers, Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
225
- * body: JSON.stringify({
226
- * model: "veo_3_1_fast",
227
- * prompt: "A lighthouse beam sweeping across a calm sea at dawn",
228
- * seconds: 8,
229
- * }),
230
- * });
231
- *
232
- * // Video generation takes minutes, so store the id and poll it from a later request
233
- * const { id } = await response.json();
234
- * await base44.asServiceRole.entities.Clip.update(clipId, { video_id: id });
235
- * ```
236
- *
237
- * @example
238
- * ```typescript
239
203
  * // Route a support ticket with a structured evaluation
240
204
  * import { createClientFromRequest } from "@base44/sdk";
241
205
  * import { experimental_evaluate as evaluate } from "ai";
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from "axios";
2
2
  import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
3
- import type { InternalAuthModule } from "./auth.types";
3
+ import type { AuthModule } from "./auth.types";
4
4
  export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
5
5
  export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
6
6
  export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
@@ -10,7 +10,7 @@ export interface AnalyticsModuleArgs {
10
10
  axiosClient: AxiosInstance;
11
11
  serverUrl: string;
12
12
  appId: string;
13
- userAuthModule: InternalAuthModule;
13
+ userAuthModule: AuthModule;
14
14
  enabled: boolean;
15
15
  }
16
16
  export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, }: AnalyticsModuleArgs) => {
@@ -196,9 +196,33 @@ function trackInitializationEvent(track) {
196
196
  eventName: ANALYTICS_INITIALIZATION_EVENT_NAME,
197
197
  properties: {
198
198
  referrer: document === null || document === void 0 ? void 0 : document.referrer,
199
+ ...getAttributionParams(),
199
200
  },
200
201
  });
201
202
  }
203
+ // Allowlist, never the whole query string: landing URLs carry PII
204
+ // (e.g. `utm_email`) and tokens.
205
+ const ATTRIBUTION_PARAM_KEYS = [
206
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id",
207
+ "gclid", "gbraid", "wbraid", "gad_source", "gad_campaignid",
208
+ "fbclid", "msclkid", "ttclid", "li_fat_id",
209
+ ];
210
+ function getAttributionParams() {
211
+ try {
212
+ const params = new URLSearchParams(window.location.search);
213
+ const out = {};
214
+ for (const key of ATTRIBUTION_PARAM_KEYS) {
215
+ const value = params.get(key);
216
+ if (value)
217
+ out[key] = value.slice(0, 500);
218
+ }
219
+ return out;
220
+ }
221
+ catch (_a) {
222
+ // React Native has no `window.location`.
223
+ return {};
224
+ }
225
+ }
202
226
  function setSessionDurationTimerStart() {
203
227
  if (typeof window === "undefined" ||
204
228
  analyticsSharedState.sessionStartTime !== null) {
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { AuthModuleOptions, InternalAuthModule } from "./auth.types";
2
+ import { AuthModuleOptions, AuthModule } from "./auth.types";
3
3
  /**
4
4
  * Creates the auth module for the Base44 SDK.
5
5
  *
@@ -10,4 +10,4 @@ import { AuthModuleOptions, InternalAuthModule } from "./auth.types";
10
10
  * @returns Auth module with authentication and user management methods
11
11
  * @internal
12
12
  */
13
- export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: AuthModuleOptions): InternalAuthModule;
13
+ export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: AuthModuleOptions): AuthModule;
@@ -321,6 +321,20 @@ export interface AuthModule {
321
321
  * ```
322
322
  */
323
323
  isAuthenticated(): Promise<boolean>;
324
+ /**
325
+ * Checks whether an access token is currently set on the client.
326
+ *
327
+ * Reports only that a token is present, not that it's valid: an expired or revoked token still returns `true`. Use it to skip requests that can't succeed without a session, such as {@linkcode me | me()} for an anonymous visitor, and use {@linkcode isAuthenticated | isAuthenticated()} to confirm a session with the server. The token is the one passed to {@linkcode createClient | createClient()} or set with {@linkcode setToken | setToken()}, and {@linkcode logout | logout()} clears it. A session held only in an HTTP-only cookie isn't visible to the client and returns `false`.
328
+ *
329
+ * @returns `true` if the client has an access token, `false` otherwise.
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * // Skip the user lookup for anonymous visitors
334
+ * const user = base44.auth.hasToken() ? await base44.auth.me() : null;
335
+ * ```
336
+ */
337
+ hasToken(): boolean;
324
338
  /**
325
339
  * Invites a user to the app.
326
340
  *
@@ -523,20 +537,3 @@ export interface AuthModule {
523
537
  */
524
538
  changePassword(params: ChangePasswordParams): Promise<any>;
525
539
  }
526
- /**
527
- * The auth module as constructed internally, before it is narrowed to
528
- * {@link AuthModule} on the public client. Not exported from the package
529
- * index — SDK consumers see only {@link AuthModule}.
530
- *
531
- * @internal
532
- */
533
- export interface InternalAuthModule extends AuthModule {
534
- /**
535
- * Whether an access token is currently set on the client.
536
- *
537
- * Reports only the presence of a token, never its validity — an expired or
538
- * revoked token still reads as `true`. Callers use this to skip requests that
539
- * could not succeed without a session, not to decide that one is valid.
540
- */
541
- hasToken(): boolean;
542
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.52-pr.305.d6c90ab",
3
+ "version": "0.8.53-pr.289.39e1f1f",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",