@base44-preview/sdk 0.8.60-pr.377.d5ecb0f → 0.8.62-pr.378.dce07b1

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
@@ -17,13 +17,22 @@ export type ActorConnectionIdentity = Readonly<{
17
17
  type: "anonymous";
18
18
  anonymousId: string;
19
19
  }>;
20
- /** Who sent a request to {@link Actor.handleRequest}: a client, or the app's
21
- * server code posting with the service role (`service`). */
22
- export type ActorRequestIdentity = ActorConnectionIdentity | Readonly<{
20
+ /** Who called one of the actor's callable methods: a client, or the app's server
21
+ * code calling with the service role (`service`). */
22
+ export type ActorCallIdentity = ActorConnectionIdentity | Readonly<{
23
23
  type: "service";
24
24
  }>;
25
- export interface ActorRequestContext {
26
- identity: ActorRequestIdentity;
25
+ /** What a callable method receives besides its args. */
26
+ export interface ActorCallContext {
27
+ identity: ActorCallIdentity;
28
+ /** Carries the caller's own credential, so `createClientFromRequest(request)` acts
29
+ * as the caller, as in a backend function. Don't store it. */
30
+ request: Request;
31
+ }
32
+ /** Throw from a callable method to refuse the call with a 4xx status. */
33
+ export declare class ActorError extends Error {
34
+ readonly status: number;
35
+ constructor(status: number, message: string);
27
36
  }
28
37
  /**
29
38
  * A single client connection. `Send` is the message type this connection accepts
@@ -79,24 +88,25 @@ export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
79
88
  */
80
89
  protected handleWake(_key: string): void | Promise<void>;
81
90
  /**
82
- * Optional handler for requests sent to this session with `post()`, by a
83
- * client or by the app's server code. Runs even when no client is connected,
84
- * and can {@link broadcast} to the ones that are. Check `identity` before
85
- * acting: a client can post to any session it can name.
91
+ * The methods a caller may run on a session, as `base44.actors.<Name>(id).<method>(args)`
92
+ * from a client or `base44.asServiceRole.actors.<Name>(id).<method>(args)` from server code.
93
+ * Nothing else is callable, and a hook-shaped name (`handle*`, `on*`, `_*`) never is.
86
94
  *
87
- * Return a `Response` for the caller; returning nothing answers 204, and a
88
- * throw answers 500. An actor without this method refuses requests with 404.
95
+ * Each runs as `method(args, { identity, request })` (see {@link ActorCallContext}), even
96
+ * when no client is connected, and can {@link broadcast} to the ones that are. Check
97
+ * `identity` before acting: a client can call a method on any session it can name. The
98
+ * return value is the caller's reply; throw an {@link ActorError} to refuse with a 4xx.
89
99
  *
90
100
  * @example
91
101
  * ```ts
92
- * async handleRequest(request, { identity }) {
93
- * if (identity.type !== "service") return new Response("Forbidden", { status: 403 });
94
- * const result = await request.json();
95
- * this.broadcast({ type: "result", result });
102
+ * static callable = ["videoReady"];
103
+ * async videoReady(args, { identity }) {
104
+ * if (identity.type !== "service") throw new ActorError(403, "Forbidden");
105
+ * this.broadcast({ type: "video", ...args });
96
106
  * }
97
107
  * ```
98
108
  */
99
- protected handleRequest?(request: Request, context: ActorRequestContext): Response | void | Promise<Response | void>;
109
+ static callable?: readonly string[];
100
110
  /**
101
111
  * Arm a one-shot wake at `at` (epoch ms or a `Date`), identified by `key`.
102
112
  * When it comes due the platform calls {@link handleWake} with this `key`.
package/dist/actor.js CHANGED
@@ -8,6 +8,14 @@
8
8
  * At deploy time the bundler replaces this import with the compiled
9
9
  * Cloudflare Durable Object implementation — this file provides types only.
10
10
  */
11
+ /** Throw from a callable method to refuse the call with a 4xx status. */
12
+ export class ActorError extends Error {
13
+ constructor(status, message) {
14
+ super(message);
15
+ this.status = status;
16
+ this.name = "ActorError";
17
+ }
18
+ }
11
19
  /**
12
20
  * Base class for an Actor.
13
21
  *
package/dist/client.js CHANGED
@@ -8,6 +8,7 @@ import { createVoiceModule } from "./modules/voice.js";
8
8
  import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
9
9
  import { getAccessToken } from "./utils/auth-utils.js";
10
10
  import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
11
+ import { BUILD_COMMIT_HEADER, getBuildCommitHeaders, } from "./utils/build-commit.js";
11
12
  import { createFunctionsModule } from "./modules/functions.js";
12
13
  import { createAgentsModule } from "./modules/agents.js";
13
14
  import { createAiGatewayModule } from "./modules/ai-gateway.js";
@@ -56,6 +57,9 @@ import { createActorsModule, createServiceRoleActorsModule, resolveActorsHost, }
56
57
  * ```
57
58
  */
58
59
  export function createClient(config) {
60
+ return buildClient(config, { sendBuildCommit: true });
61
+ }
62
+ function buildClient(config, { sendBuildCommit }) {
59
63
  var _a, _b, _c, _d;
60
64
  const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
61
65
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
@@ -76,7 +80,18 @@ export function createClient(config) {
76
80
  }
77
81
  return socket;
78
82
  };
83
+ // The build commit goes on every API call, so the backend can tell which
84
+ // frontend bundle a request came from. One set by the caller, in any
85
+ // casing, replaces it; resolving that once here keeps every call path,
86
+ // functions.fetch() included, reporting the same build.
87
+ const callerBuildCommit = Object.entries(optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {}).find(([name]) => name.toLowerCase() === BUILD_COMMIT_HEADER.toLowerCase());
88
+ const buildCommitHeaders = callerBuildCommit
89
+ ? { [BUILD_COMMIT_HEADER]: callerBuildCommit[1] }
90
+ : sendBuildCommit
91
+ ? getBuildCommitHeaders()
92
+ : {};
79
93
  const headers = {
94
+ ...(callerBuildCommit ? {} : buildCommitHeaders),
80
95
  ...optionalHeaders,
81
96
  "X-App-Id": String(appId),
82
97
  };
@@ -122,10 +137,10 @@ export function createClient(config) {
122
137
  interceptResponses: false,
123
138
  });
124
139
  // The backend authenticates the caller from the axios client's token (or the
125
- // anonymous id it adds in a browser) and relays the request to the room.
126
- const actorRequestPoster = (client) => async (actorName, room, body) => {
140
+ // anonymous id it adds in a browser) and relays the call to the room.
141
+ const actorMethodCaller = (client) => async (actorName, room, method, args) => {
127
142
  var _a;
128
- const response = await client.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/rooms/${encodeURIComponent(room)}/requests`, JSON.stringify(body !== null && body !== void 0 ? body : null), {
143
+ const response = await client.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/rooms/${encodeURIComponent(room)}/requests`, JSON.stringify({ method, args }), {
129
144
  headers: {
130
145
  "Content-Type": "application/json",
131
146
  // Draft vs published copy, as for a connection.
@@ -182,7 +197,7 @@ export function createClient(config) {
182
197
  },
183
198
  transport: options === null || options === void 0 ? void 0 : options.actorsTransport,
184
199
  onMintError: options === null || options === void 0 ? void 0 : options.onError,
185
- postRequest: actorRequestPoster(axiosClient),
200
+ callMethod: actorMethodCaller(axiosClient),
186
201
  });
187
202
  const userModules = {
188
203
  entities: createEntitiesModule({
@@ -195,7 +210,7 @@ export function createClient(config) {
195
210
  auth: userAuthModule,
196
211
  functions: createFunctionsModule(functionsAxiosClient, appId, {
197
212
  getAuthHeaders: () => {
198
- const headers = {};
213
+ const headers = { ...buildCommitHeaders };
199
214
  // Get current token from storage or initial config
200
215
  const currentToken = token || getAccessToken();
201
216
  if (currentToken) {
@@ -275,7 +290,7 @@ export function createClient(config) {
275
290
  }),
276
291
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
277
292
  payments: createServiceRolePaymentsModule(serviceRoleAxiosClient, appId),
278
- actors: createServiceRoleActorsModule(actorRequestPoster(serviceRoleAxiosClient)),
293
+ actors: createServiceRoleActorsModule(actorMethodCaller(serviceRoleAxiosClient)),
279
294
  cleanup: () => {
280
295
  if (socket) {
281
296
  socket.disconnect();
@@ -473,12 +488,14 @@ export function createClientFromRequest(request) {
473
488
  if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
474
489
  additionalHeaders["X-Data-Env"] = dataEnvHeader;
475
490
  }
476
- return createClient({
491
+ // A backend function isn't the browser bundle, so it never reports a build
492
+ // commit, whatever its runtime looks like.
493
+ return buildClient({
477
494
  serverUrl: serverUrlHeader || "https://base44.app",
478
495
  appId,
479
496
  token: userToken,
480
497
  serviceToken: serviceRoleToken,
481
498
  functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
482
499
  headers: additionalHeaders,
483
- });
500
+ }, { sendBuildCommit: false });
484
501
  }
package/dist/index.d.ts CHANGED
@@ -12,12 +12,12 @@ export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, Age
12
12
  export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
13
13
  export type { AppLogsModule } from "./modules/app-logs.types.js";
14
14
  export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
15
- export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, ServiceRoleActorRef, ServiceRoleActorsModule, } from "./modules/actors.types.js";
15
+ export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, ActorConnectable, ActorMethods, ServiceRoleActorRef, ServiceRoleActorsModule, } from "./modules/actors.types.js";
16
16
  export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
17
17
  export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalCheckoutOnClick, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
18
18
  export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
19
19
  export type { VoiceModule, VoiceSession, VoiceSessionMessage, VoiceSessionOptions, } from "./modules/voice.types.js";
20
- export { Actor, type Conn, type ActorConnectionIdentity, type ActorRequestIdentity, type ActorRequestContext, } from "./actor.js";
20
+ export { Actor, type Conn, type ActorConnectionIdentity, ActorError, type ActorCallIdentity, type ActorCallContext, } from "./actor.js";
21
21
  export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
22
22
  export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
23
23
  export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
package/dist/index.js CHANGED
@@ -3,4 +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";
6
+ export { Actor, ActorError, } from "./actor.js";
@@ -1,6 +1,6 @@
1
1
  import type { ActorRef, ServiceRoleActorRef } from "./actors.types.js";
2
- /** Sends one request to a session's `handleRequest`; resolves to its JSON reply. */
3
- export type PostActorRequest = (actorName: string, room: string, body: unknown) => Promise<unknown>;
2
+ /** Calls one of a session's callable methods; resolves to its JSON reply. */
3
+ export type CallActorMethod = (actorName: string, room: string, method: string, args: unknown) => Promise<unknown>;
4
4
  /** Credentials minted by the platform for one direct actor connection. */
5
5
  export interface ActorConnectionCredentials {
6
6
  /** Direct actor endpoint, already carrying `?_pk=<connectionId>`. */
@@ -32,7 +32,7 @@ interface ActorsConfig {
32
32
  * direct→proxy fallback (which recovers by itself). Wired to the client's
33
33
  * `options.onError`. */
34
34
  onMintError?: (error: Error) => void;
35
- postRequest: PostActorRequest;
35
+ callMethod: CallActorMethod;
36
36
  }
37
37
  /**
38
38
  * The legacy platform-proxy URL, byte-for-byte what PartySocket built before
@@ -51,6 +51,6 @@ export declare function createActorsModule(config: ActorsConfig): {
51
51
  module: Record<string, (instanceId: string) => ActorRef>;
52
52
  closeAll: () => void;
53
53
  };
54
- /** `asServiceRole.actors`: server code can't hold a connection, so it only posts. */
55
- export declare function createServiceRoleActorsModule(postRequest: PostActorRequest): Record<string, (instanceId: string) => ServiceRoleActorRef>;
54
+ /** `asServiceRole.actors`: server code can't hold a connection, so it only calls methods. */
55
+ export declare function createServiceRoleActorsModule(callMethod: CallActorMethod): Record<string, (instanceId: string) => ServiceRoleActorRef>;
56
56
  export {};
@@ -1,4 +1,23 @@
1
1
  import { WebSocket as ReconnectingWebSocket } from "partysocket";
2
+ // Never actor methods: the ref's own API, what `await`/JSON/frameworks probe for, and
3
+ // Object.prototype (resolved through the `in` check below).
4
+ const NOT_METHODS = new Set(["then", "catch", "finally", "toJSON", "asymmetricMatch", "nodeType", "constructor"]);
5
+ function isMethodName(target, key) {
6
+ return (typeof key === "string" &&
7
+ !(key in target) &&
8
+ !NOT_METHODS.has(key) &&
9
+ !key.startsWith("$$") &&
10
+ !key.startsWith("@@"));
11
+ }
12
+ function withMethods(target, call) {
13
+ return new Proxy(target, {
14
+ get(obj, key) {
15
+ return isMethodName(obj, key)
16
+ ? (args) => call(key, args)
17
+ : Reflect.get(obj, key);
18
+ },
19
+ });
20
+ }
2
21
  // Heartbeat / half-open detection: the socket only reconnects on a close/error
3
22
  // event, so ping periodically and force a reconnect if nothing returns in DEAD_MS.
4
23
  const PING_MS = 1000;
@@ -153,7 +172,7 @@ class Connection {
153
172
  /** Handle for one actor instance: `connect()` opens the socket (idempotent). */
154
173
  function makeActorRef(actorName, instanceId, config, connections) {
155
174
  let conn = null;
156
- return {
175
+ const ref = {
157
176
  connect(options) {
158
177
  if (conn)
159
178
  return conn;
@@ -166,8 +185,8 @@ function makeActorRef(actorName, instanceId, config, connections) {
166
185
  connections.add(c);
167
186
  return c;
168
187
  },
169
- post: (body) => config.postRequest(actorName, instanceId, body),
170
188
  };
189
+ return withMethods(ref, (method, args) => config.callMethod(actorName, instanceId, method, args));
171
190
  }
172
191
  /**
173
192
  * The legacy platform-proxy URL, byte-for-byte what PartySocket built before
@@ -227,15 +246,13 @@ export function createActorsModule(config) {
227
246
  },
228
247
  };
229
248
  }
230
- /** `asServiceRole.actors`: server code can't hold a connection, so it only posts. */
231
- export function createServiceRoleActorsModule(postRequest) {
249
+ /** `asServiceRole.actors`: server code can't hold a connection, so it only calls methods. */
250
+ export function createServiceRoleActorsModule(callMethod) {
232
251
  return new Proxy({}, {
233
252
  get(_, key) {
234
253
  if (typeof key !== "string" || key === "then")
235
254
  return undefined;
236
- return (instanceId) => ({
237
- post: (body) => postRequest(key, instanceId, body),
238
- });
255
+ return (instanceId) => withMethods({}, (method, args) => callMethod(key, instanceId, method, args));
239
256
  },
240
257
  });
241
258
  }
@@ -20,6 +20,7 @@
20
20
  * chatRoom: {
21
21
  * toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
22
22
  * toServer: { type: "message"; text: string };
23
+ * methods: { kick: (args: { userId: string }) => { kicked: boolean } };
23
24
  * };
24
25
  * }
25
26
  * }
@@ -43,6 +44,18 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
43
44
  type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
44
45
  toServer: infer O;
45
46
  } ? O : unknown : unknown;
47
+ type ActorMethodCall<F> = F extends (args: infer A, ...rest: never[]) => infer R ? undefined extends A ? (args?: A) => Promise<Awaited<R>> : (args: A) => Promise<Awaited<R>> : never;
48
+ type UntypedActorMethods = Record<string, (args?: unknown) => Promise<unknown>>;
49
+ /**
50
+ * An actor's callable methods, as seen by a caller: each runs the actor's method of the same
51
+ * name and resolves to its return value. Typed from the actor's `methods` in
52
+ * {@linkcode ActorRegistry}; any name otherwise.
53
+ */
54
+ export type ActorMethods<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
55
+ methods: infer M;
56
+ } ? {
57
+ [K in keyof M]: ActorMethodCall<M[K]>;
58
+ } : UntypedActorMethods : UntypedActorMethods;
46
59
  /**
47
60
  * Configures the connection that {@linkcode ActorRef.connect | connect()} opens.
48
61
  */
@@ -134,9 +147,19 @@ export interface Connection<N extends string = string> {
134
147
  /**
135
148
  * Represents a reference to an actor session, identified by actor name and session ID.
136
149
  *
137
- * Call {@linkcode ActorRef.connect | connect()} to open the WebSocket and get a [connection](/developers/backend/resources/actors/overview#connections).
150
+ * Call {@linkcode ActorRef.connect | connect()} to open the WebSocket and get a [connection](/developers/backend/resources/actors/overview#connections),
151
+ * or call one of the actor's callable methods by name, such as `ref.kick({ userId })`: it runs
152
+ * the actor's method with your identity, even when no client is connected, and resolves to
153
+ * its return value. A refusal rejects with a `Base44Error` carrying the actor's status (404 for
154
+ * a method the actor doesn't list in `static callable`).
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Call a method on a session
159
+ * const { kicked } = await base44.actors.chatRoom("session-1").kick({ userId });
160
+ * ```
138
161
  */
139
- export interface ActorRef<N extends string = string> {
162
+ export interface ActorConnectable<N extends string = string> {
140
163
  /**
141
164
  * Creates or returns the connection for this session.
142
165
  *
@@ -156,55 +179,27 @@ export interface ActorRef<N extends string = string> {
156
179
  * ```
157
180
  */
158
181
  connect(options?: ActorConnectOptions): Connection<N>;
159
- /**
160
- * Sends a request to this session's `handleRequest` and returns its reply.
161
- *
162
- * The actor receives the request with the caller's identity: the logged-in
163
- * user, or an anonymous visitor. Unlike {@linkcode ActorRef.connect | connect()},
164
- * no connection is opened, so the request reaches the session even when no
165
- * client is connected; the actor can still `broadcast()` from it.
166
- *
167
- * @param body - JSON-serializable request body, up to 64 KB.
168
- * @returns The JSON body of the actor's response, or `undefined` when it has none.
169
- * @throws {Base44Error} When the actor refuses the request or doesn't implement
170
- * `handleRequest` (404), with the actor's status code.
171
- *
172
- * @example
173
- * ```typescript
174
- * // Send a request to a session
175
- * const reply = await base44.actors.chatRoom("session-1").post({ type: "ping" });
176
- * ```
177
- */
178
- post<T = unknown>(body?: unknown): Promise<T | undefined>;
179
182
  }
183
+ export type ActorRef<N extends string = string> = ActorConnectable<N> & ActorMethods<N>;
180
184
  /**
181
185
  * Represents a reference to an actor session for server code running with the
182
186
  * [service role](/developers/references/sdk/getting-started/client#service-role).
183
- * Server code can't hold a connection, so it only sends requests.
187
+ * Server code can't hold a connection, so it only calls methods; the actor sees the
188
+ * `service` identity.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Tell a user's session that their video is ready
193
+ * await base44.asServiceRole.actors.VideoRoom(userId).videoReady({ id });
194
+ * ```
184
195
  */
185
- export interface ServiceRoleActorRef {
186
- /**
187
- * Sends a request to this session's `handleRequest` as the app's server code,
188
- * which the actor sees as the `service` identity, and returns its reply.
189
- *
190
- * @param body - JSON-serializable request body, up to 64 KB.
191
- * @returns The JSON body of the actor's response, or `undefined` when it has none.
192
- * @throws {Base44Error} When the actor refuses the request or doesn't implement
193
- * `handleRequest` (404), with the actor's status code.
194
- *
195
- * @example
196
- * ```typescript
197
- * // Tell a user's session that their video is ready
198
- * await base44.asServiceRole.actors.VideoRoom(userId).post({ type: "video_ready", id });
199
- * ```
200
- */
201
- post<T = unknown>(body?: unknown): Promise<T | undefined>;
202
- }
196
+ export type ServiceRoleActorRef<N extends string = string> = ActorMethods<N>;
203
197
  /**
204
- * Actors module available with the service role: selects a session to send
205
- * requests to with {@linkcode ServiceRoleActorRef.post | post()}.
198
+ * Actors module available with the service role: selects a session whose methods to call.
206
199
  */
207
- export type ServiceRoleActorsModule = Record<string, (instanceId: string) => ServiceRoleActorRef>;
200
+ export type ServiceRoleActorsModule = {
201
+ [K in AllActorNames]: (instanceId: string) => ServiceRoleActorRef<string & K>;
202
+ } & Record<string, (instanceId: string) => ServiceRoleActorRef>;
208
203
  /**
209
204
  * Selects a session for a named actor.
210
205
  *
@@ -241,7 +236,7 @@ export interface ActorClient<N extends string = string> {
241
236
  * - Manage connections: {@link ActorRef.connect | Open} and {@link Connection.close | close} a WebSocket connection to a session.
242
237
  * - Exchange messages: {@link Connection.send | Send} and {@link Connection.subscribe | listen} for messages to and from an actor.
243
238
  * - Manage subscriptions: {@link Connection.subscribe | Subscribe} and {@link ActorSubscription.unsubscribe | unsubscribe} from actor messages without closing the connection.
244
- * - Send requests: {@link ActorRef.post | Post} a request to a session's `handleRequest` without connecting.
239
+ * - Call methods: run one of an actor's callable methods on a session, without connecting.
245
240
  *
246
241
  * For a sample flow, see
247
242
  * [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
@@ -251,12 +246,12 @@ export interface ActorClient<N extends string = string> {
251
246
  * This module is available to use with a client in anonymous or user authentication mode. Access it
252
247
  * through `base44.actors`. In
253
248
  * [service role authentication mode](/developers/references/sdk/getting-started/client#service-role),
254
- * `base44.asServiceRole.actors` only sends requests, with {@link ServiceRoleActorRef.post | post()}.
249
+ * `base44.asServiceRole.actors` only calls methods.
255
250
  *
256
251
  * The actor receives each client's [identity](/developers/backend/resources/actors/reference#connections)
257
- * when the client connects or posts. A client that hasn't logged in is anonymous, a client that
252
+ * when the client connects or calls a method. A client that hasn't logged in is anonymous, a client that
258
253
  * has [logged in](/developers/references/sdk/docs/interfaces/auth) is authenticated, and server
259
- * code posting with the service role is `service`.
254
+ * code calling with the service role is `service`.
260
255
  */
261
256
  export type ActorsModule = {
262
257
  [K in AllActorNames]: K extends keyof ActorRegistry ? ActorClient<string & K> : ActorClient;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Reads the commit the app's frontend bundle was built from.
3
+ *
4
+ * Base44's publish pipeline sets `VITE_BASE44_BUILD_COMMIT` for the build, and
5
+ * Vite replaces the expression below with that literal string when it bundles
6
+ * this file out of `node_modules`, in `vite build` and in the dev server's
7
+ * prebundled deps alike. The expression must stay spelled out exactly like
8
+ * this: Vite matches it statically, and any indirection leaves a runtime lookup
9
+ * that is always undefined.
10
+ *
11
+ * A bundler that isn't Vite leaves `import.meta.env` undefined, so the lookup
12
+ * throws, and that means "no build commit".
13
+ *
14
+ * Only reached as `#build-commit-source` under the `module` condition; see
15
+ * `build-commit-source.fallback.ts`.
16
+ *
17
+ * @internal
18
+ */
19
+ export declare function readBuildCommitSource(): unknown;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What `#build-commit-source` resolves to without the `module` condition: no
3
+ * build commit.
4
+ *
5
+ * The package's `imports` field gives the `import.meta` reader
6
+ * (`build-commit-source.ts`) only to bundlers that match `module`: Vite,
7
+ * webpack and esbuild. Everything else gets this file, so `import.meta` never
8
+ * reaches a runtime or bundler that can't take it. That includes Node, Deno,
9
+ * and Metro on every platform: Hermes rejects `import.meta` outright, and
10
+ * Metro's web build ships a classic script, where it is a SyntaxError.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare function readBuildCommitSource(): unknown;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What `#build-commit-source` resolves to without the `module` condition: no
3
+ * build commit.
4
+ *
5
+ * The package's `imports` field gives the `import.meta` reader
6
+ * (`build-commit-source.ts`) only to bundlers that match `module`: Vite,
7
+ * webpack and esbuild. Everything else gets this file, so `import.meta` never
8
+ * reaches a runtime or bundler that can't take it. That includes Node, Deno,
9
+ * and Metro on every platform: Hermes rejects `import.meta` outright, and
10
+ * Metro's web build ships a classic script, where it is a SyntaxError.
11
+ *
12
+ * @internal
13
+ */
14
+ export function readBuildCommitSource() {
15
+ return undefined;
16
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Reads the commit the app's frontend bundle was built from.
3
+ *
4
+ * Base44's publish pipeline sets `VITE_BASE44_BUILD_COMMIT` for the build, and
5
+ * Vite replaces the expression below with that literal string when it bundles
6
+ * this file out of `node_modules`, in `vite build` and in the dev server's
7
+ * prebundled deps alike. The expression must stay spelled out exactly like
8
+ * this: Vite matches it statically, and any indirection leaves a runtime lookup
9
+ * that is always undefined.
10
+ *
11
+ * A bundler that isn't Vite leaves `import.meta.env` undefined, so the lookup
12
+ * throws, and that means "no build commit".
13
+ *
14
+ * Only reached as `#build-commit-source` under the `module` condition; see
15
+ * `build-commit-source.fallback.ts`.
16
+ *
17
+ * @internal
18
+ */
19
+ export function readBuildCommitSource() {
20
+ try {
21
+ return import.meta.env.VITE_BASE44_BUILD_COMMIT;
22
+ }
23
+ catch (_a) {
24
+ return undefined;
25
+ }
26
+ }
@@ -0,0 +1,12 @@
1
+ /** Header the backend reads to tell which frontend build sent a request. */
2
+ export declare const BUILD_COMMIT_HEADER = "X-Base44-Build";
3
+ /**
4
+ * The build-commit header to send from this client, if any.
5
+ *
6
+ * Only a browser sends it: the value names the browser bundle, so a server
7
+ * (Node, Deno, a backend function) or React Native would report a commit that
8
+ * isn't the one running.
9
+ *
10
+ * @internal
11
+ */
12
+ export declare function getBuildCommitHeaders(): Record<string, string>;
@@ -0,0 +1,24 @@
1
+ import { isNode, isReactNative } from "./common.js";
2
+ import { readBuildCommitSource } from "#build-commit-source";
3
+ /** Header the backend reads to tell which frontend build sent a request. */
4
+ export const BUILD_COMMIT_HEADER = "X-Base44-Build";
5
+ // The backend accepts exactly this shape and ignores anything else, so a value
6
+ // that doesn't match is never sent.
7
+ const BUILD_COMMIT_PATTERN = /^[a-f0-9]{40}$/;
8
+ /**
9
+ * The build-commit header to send from this client, if any.
10
+ *
11
+ * Only a browser sends it: the value names the browser bundle, so a server
12
+ * (Node, Deno, a backend function) or React Native would report a commit that
13
+ * isn't the one running.
14
+ *
15
+ * @internal
16
+ */
17
+ export function getBuildCommitHeaders() {
18
+ if (isNode || isReactNative)
19
+ return {};
20
+ const commit = readBuildCommitSource();
21
+ return typeof commit === "string" && BUILD_COMMIT_PATTERN.test(commit)
22
+ ? { [BUILD_COMMIT_HEADER]: commit }
23
+ : {};
24
+ }
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.60-pr.377.d5ecb0f",
3
+ "version": "0.8.62-pr.378.dce07b1",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "imports": {
8
+ "#build-commit-source": {
9
+ "module": "./dist/utils/build-commit-source.js",
10
+ "default": "./dist/utils/build-commit-source.fallback.js"
11
+ }
12
+ },
7
13
  "type": "module",
8
14
  "files": [
9
15
  "dist"
@@ -16,6 +22,7 @@
16
22
  "test:e2e": "vitest run tests/e2e",
17
23
  "test:watch": "vitest",
18
24
  "test:coverage": "vitest run --coverage",
25
+ "test:build-commit": "scripts/verify-build-commit.sh",
19
26
  "docs": "typedoc",
20
27
  "prepublishOnly": "npm run build",
21
28
  "create-docs": "npm run create-docs:generate && npm run create-docs:process",