@base44-preview/sdk 0.8.60-pr.375.db5e899 → 0.8.60-pr.377.f503122
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 +37 -0
- package/dist/client.js +20 -21
- package/dist/client.types.d.ts +3 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/modules/actors.d.ts +6 -1
- package/dist/modules/actors.js +13 -0
- package/dist/modules/actors.types.d.ts +55 -4
- package/package.json +1 -8
- package/dist/utils/build-commit-source.d.ts +0 -19
- package/dist/utils/build-commit-source.fallback.d.ts +0 -14
- package/dist/utils/build-commit-source.fallback.js +0 -16
- package/dist/utils/build-commit-source.js +0 -26
- package/dist/utils/build-commit.d.ts +0 -12
- package/dist/utils/build-commit.js +0 -24
package/dist/actor.d.ts
CHANGED
|
@@ -9,6 +9,22 @@
|
|
|
9
9
|
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
10
|
*/
|
|
11
11
|
import type { Base44Client } from "./client";
|
|
12
|
+
/** Who a client is, verified by the platform: a logged-in user or an anonymous visitor. */
|
|
13
|
+
export type ActorConnectionIdentity = Readonly<{
|
|
14
|
+
type: "authenticated";
|
|
15
|
+
userId: string;
|
|
16
|
+
}> | Readonly<{
|
|
17
|
+
type: "anonymous";
|
|
18
|
+
anonymousId: string;
|
|
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<{
|
|
23
|
+
type: "service";
|
|
24
|
+
}>;
|
|
25
|
+
export interface ActorRequestContext {
|
|
26
|
+
identity: ActorRequestIdentity;
|
|
27
|
+
}
|
|
12
28
|
/**
|
|
13
29
|
* A single client connection. `Send` is the message type this connection accepts
|
|
14
30
|
* via {@link send} — the actor's *outgoing* (server→client) messages.
|
|
@@ -18,6 +34,8 @@ export interface Conn<Send = unknown> {
|
|
|
18
34
|
* receives from `subscribe()`. Identifies a distinct client, so multiple
|
|
19
35
|
* tabs are separate connections. */
|
|
20
36
|
id: string;
|
|
37
|
+
/** The client's identity, verified by the platform before the connection reached the actor. */
|
|
38
|
+
identity?: ActorConnectionIdentity;
|
|
21
39
|
send(data: Send): void;
|
|
22
40
|
reject(code: number, reason: string): void;
|
|
23
41
|
}
|
|
@@ -60,6 +78,25 @@ export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
|
|
|
60
78
|
* The schedule is one-shot: it fires once and is cleared before this runs.
|
|
61
79
|
*/
|
|
62
80
|
protected handleWake(_key: string): void | Promise<void>;
|
|
81
|
+
/**
|
|
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.
|
|
86
|
+
*
|
|
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.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```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 });
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
protected handleRequest?(request: Request, context: ActorRequestContext): Response | void | Promise<Response | void>;
|
|
63
100
|
/**
|
|
64
101
|
* Arm a one-shot wake at `at` (epoch ms or a `Date`), identified by `key`.
|
|
65
102
|
* When it comes due the platform calls {@link handleWake} with this `key`.
|
package/dist/client.js
CHANGED
|
@@ -8,7 +8,6 @@ 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";
|
|
12
11
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
13
12
|
import { createAgentsModule } from "./modules/agents.js";
|
|
14
13
|
import { createAiGatewayModule } from "./modules/ai-gateway.js";
|
|
@@ -18,7 +17,7 @@ import { createUsersModule } from "./modules/users.js";
|
|
|
18
17
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
19
18
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
20
19
|
import { createPaymentsModule, createServiceRolePaymentsModule, } from "./modules/payments.js";
|
|
21
|
-
import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
20
|
+
import { createActorsModule, createServiceRoleActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
22
21
|
/**
|
|
23
22
|
* Creates a Base44 client.
|
|
24
23
|
*
|
|
@@ -57,9 +56,6 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
57
56
|
* ```
|
|
58
57
|
*/
|
|
59
58
|
export function createClient(config) {
|
|
60
|
-
return buildClient(config, { sendBuildCommit: true });
|
|
61
|
-
}
|
|
62
|
-
function buildClient(config, { sendBuildCommit }) {
|
|
63
59
|
var _a, _b, _c, _d;
|
|
64
60
|
const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
65
61
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
@@ -80,18 +76,7 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
80
76
|
}
|
|
81
77
|
return socket;
|
|
82
78
|
};
|
|
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
|
-
: {};
|
|
93
79
|
const headers = {
|
|
94
|
-
...(callerBuildCommit ? {} : buildCommitHeaders),
|
|
95
80
|
...optionalHeaders,
|
|
96
81
|
"X-App-Id": String(appId),
|
|
97
82
|
};
|
|
@@ -136,6 +121,20 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
136
121
|
token: serviceToken,
|
|
137
122
|
interceptResponses: false,
|
|
138
123
|
});
|
|
124
|
+
// 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) => {
|
|
127
|
+
const reply = await client.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/rooms/${encodeURIComponent(room)}/requests`, JSON.stringify(body !== null && body !== void 0 ? body : null), {
|
|
128
|
+
headers: {
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
// Draft vs published copy, as for a connection.
|
|
131
|
+
...(functionsVersion
|
|
132
|
+
? { "Base44-Functions-Version": functionsVersion }
|
|
133
|
+
: {}),
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return reply === "" ? undefined : reply;
|
|
137
|
+
};
|
|
139
138
|
// Dedicated client for actor connection-token mints: no onError (a legacy
|
|
140
139
|
// actor answers every mint with an expected 409 before the proxy fallback,
|
|
141
140
|
// which must not reach the app's error handler — the actors module forwards
|
|
@@ -182,6 +181,7 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
182
181
|
},
|
|
183
182
|
transport: options === null || options === void 0 ? void 0 : options.actorsTransport,
|
|
184
183
|
onMintError: options === null || options === void 0 ? void 0 : options.onError,
|
|
184
|
+
postRequest: actorRequestPoster(axiosClient),
|
|
185
185
|
});
|
|
186
186
|
const userModules = {
|
|
187
187
|
entities: createEntitiesModule({
|
|
@@ -194,7 +194,7 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
194
194
|
auth: userAuthModule,
|
|
195
195
|
functions: createFunctionsModule(functionsAxiosClient, appId, {
|
|
196
196
|
getAuthHeaders: () => {
|
|
197
|
-
const headers = {
|
|
197
|
+
const headers = {};
|
|
198
198
|
// Get current token from storage or initial config
|
|
199
199
|
const currentToken = token || getAccessToken();
|
|
200
200
|
if (currentToken) {
|
|
@@ -274,6 +274,7 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
274
274
|
}),
|
|
275
275
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
276
276
|
payments: createServiceRolePaymentsModule(serviceRoleAxiosClient, appId),
|
|
277
|
+
actors: createServiceRoleActorsModule(actorRequestPoster(serviceRoleAxiosClient)),
|
|
277
278
|
cleanup: () => {
|
|
278
279
|
if (socket) {
|
|
279
280
|
socket.disconnect();
|
|
@@ -471,14 +472,12 @@ export function createClientFromRequest(request) {
|
|
|
471
472
|
if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
|
|
472
473
|
additionalHeaders["X-Data-Env"] = dataEnvHeader;
|
|
473
474
|
}
|
|
474
|
-
|
|
475
|
-
// commit, whatever its runtime looks like.
|
|
476
|
-
return buildClient({
|
|
475
|
+
return createClient({
|
|
477
476
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
478
477
|
appId,
|
|
479
478
|
token: userToken,
|
|
480
479
|
serviceToken: serviceRoleToken,
|
|
481
480
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
482
481
|
headers: additionalHeaders,
|
|
483
|
-
}
|
|
482
|
+
});
|
|
484
483
|
}
|
package/dist/client.types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
|
|
|
12
12
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
13
|
import type { AppModule } from "./modules/app.types.js";
|
|
14
14
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
15
|
-
import type { ActorsModule } from "./modules/actors.types.js";
|
|
15
|
+
import type { ActorsModule, ServiceRoleActorsModule } from "./modules/actors.types.js";
|
|
16
16
|
import type { FetchWithAuthInit } from "./utils/fetch-with-auth.js";
|
|
17
17
|
/**
|
|
18
18
|
* Options for creating a Base44 client.
|
|
@@ -226,6 +226,8 @@ export interface Base44Client {
|
|
|
226
226
|
* @throws {Error} When accessed without providing a serviceToken during client creation
|
|
227
227
|
*/
|
|
228
228
|
readonly asServiceRole: {
|
|
229
|
+
/** {@link ServiceRoleActorsModule | Actors module} for sending requests to actor sessions as the app's server code. */
|
|
230
|
+
actors: ServiceRoleActorsModule;
|
|
229
231
|
/** {@link AgentsModule | Agents module} with elevated permissions. */
|
|
230
232
|
agents: AgentsModule;
|
|
231
233
|
/** {@link AiGatewayModule | AI Gateway module} with the service-role token. */
|
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, } from "./modules/actors.types.js";
|
|
15
|
+
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, 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 } from "./actor.js";
|
|
20
|
+
export { Actor, type Conn, type ActorConnectionIdentity, type ActorRequestIdentity, type ActorRequestContext, } 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, } from "./actor.js";
|
package/dist/modules/actors.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { ActorRef } from "./actors.types.js";
|
|
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
4
|
/** Credentials minted by the platform for one direct actor connection. */
|
|
3
5
|
export interface ActorConnectionCredentials {
|
|
4
6
|
/** Direct actor endpoint, already carrying `?_pk=<connectionId>`. */
|
|
@@ -30,6 +32,7 @@ interface ActorsConfig {
|
|
|
30
32
|
* direct→proxy fallback (which recovers by itself). Wired to the client's
|
|
31
33
|
* `options.onError`. */
|
|
32
34
|
onMintError?: (error: Error) => void;
|
|
35
|
+
postRequest: PostActorRequest;
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* The legacy platform-proxy URL, byte-for-byte what PartySocket built before
|
|
@@ -48,4 +51,6 @@ export declare function createActorsModule(config: ActorsConfig): {
|
|
|
48
51
|
module: Record<string, (instanceId: string) => ActorRef>;
|
|
49
52
|
closeAll: () => void;
|
|
50
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>;
|
|
51
56
|
export {};
|
package/dist/modules/actors.js
CHANGED
|
@@ -166,6 +166,7 @@ function makeActorRef(actorName, instanceId, config, connections) {
|
|
|
166
166
|
connections.add(c);
|
|
167
167
|
return c;
|
|
168
168
|
},
|
|
169
|
+
post: (body) => config.postRequest(actorName, instanceId, body),
|
|
169
170
|
};
|
|
170
171
|
}
|
|
171
172
|
/**
|
|
@@ -226,3 +227,15 @@ export function createActorsModule(config) {
|
|
|
226
227
|
},
|
|
227
228
|
};
|
|
228
229
|
}
|
|
230
|
+
/** `asServiceRole.actors`: server code can't hold a connection, so it only posts. */
|
|
231
|
+
export function createServiceRoleActorsModule(postRequest) {
|
|
232
|
+
return new Proxy({}, {
|
|
233
|
+
get(_, key) {
|
|
234
|
+
if (typeof key !== "string" || key === "then")
|
|
235
|
+
return undefined;
|
|
236
|
+
return (instanceId) => ({
|
|
237
|
+
post: (body) => postRequest(key, instanceId, body),
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
}
|
|
@@ -156,7 +156,55 @@ export interface ActorRef<N extends string = string> {
|
|
|
156
156
|
* ```
|
|
157
157
|
*/
|
|
158
158
|
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
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Represents a reference to an actor session for server code running with the
|
|
182
|
+
* [service role](/developers/references/sdk/getting-started/client#service-role).
|
|
183
|
+
* Server code can't hold a connection, so it only sends requests.
|
|
184
|
+
*/
|
|
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>;
|
|
159
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Actors module available with the service role: selects a session to send
|
|
205
|
+
* requests to with {@linkcode ServiceRoleActorRef.post | post()}.
|
|
206
|
+
*/
|
|
207
|
+
export type ServiceRoleActorsModule = Record<string, (instanceId: string) => ServiceRoleActorRef>;
|
|
160
208
|
/**
|
|
161
209
|
* Selects a session for a named actor.
|
|
162
210
|
*
|
|
@@ -193,6 +241,7 @@ export interface ActorClient<N extends string = string> {
|
|
|
193
241
|
* - Manage connections: {@link ActorRef.connect | Open} and {@link Connection.close | close} a WebSocket connection to a session.
|
|
194
242
|
* - Exchange messages: {@link Connection.send | Send} and {@link Connection.subscribe | listen} for messages to and from an actor.
|
|
195
243
|
* - 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.
|
|
196
245
|
*
|
|
197
246
|
* For a sample flow, see
|
|
198
247
|
* [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
|
|
@@ -200,12 +249,14 @@ export interface ActorClient<N extends string = string> {
|
|
|
200
249
|
* ## Authentication modes
|
|
201
250
|
*
|
|
202
251
|
* This module is available to use with a client in anonymous or user authentication mode. Access it
|
|
203
|
-
* through `base44.actors`.
|
|
204
|
-
* [service role authentication mode](/developers/references/sdk/getting-started/client#service-role)
|
|
252
|
+
* through `base44.actors`. In
|
|
253
|
+
* [service role authentication mode](/developers/references/sdk/getting-started/client#service-role),
|
|
254
|
+
* `base44.asServiceRole.actors` only sends requests, with {@link ServiceRoleActorRef.post | post()}.
|
|
205
255
|
*
|
|
206
256
|
* 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
|
|
208
|
-
* has [logged in](/developers/references/sdk/docs/interfaces/auth)
|
|
257
|
+
* when the client connects or posts. A client that hasn't logged in is anonymous, a client that
|
|
258
|
+
* has [logged in](/developers/references/sdk/docs/interfaces/auth) is authenticated, and server
|
|
259
|
+
* code posting with the service role is `service`.
|
|
209
260
|
*/
|
|
210
261
|
export type ActorsModule = {
|
|
211
262
|
[K in AllActorNames]: K extends keyof ActorRegistry ? ActorClient<string & K> : ActorClient;
|
package/package.json
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.60-pr.
|
|
3
|
+
"version": "0.8.60-pr.377.f503122",
|
|
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
|
-
},
|
|
13
7
|
"type": "module",
|
|
14
8
|
"files": [
|
|
15
9
|
"dist"
|
|
@@ -22,7 +16,6 @@
|
|
|
22
16
|
"test:e2e": "vitest run tests/e2e",
|
|
23
17
|
"test:watch": "vitest",
|
|
24
18
|
"test:coverage": "vitest run --coverage",
|
|
25
|
-
"test:build-commit": "scripts/verify-build-commit.sh",
|
|
26
19
|
"docs": "typedoc",
|
|
27
20
|
"prepublishOnly": "npm run build",
|
|
28
21
|
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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>;
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|