@base44-preview/sdk 0.8.60-pr.376.c2b0448 → 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 -4
- 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/dist/utils/auth-utils.d.ts +0 -1
- package/dist/utils/auth-utils.js +0 -16
- package/package.json +1 -1
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
|
@@ -6,7 +6,7 @@ import { createSsoModule } from "./modules/sso.js";
|
|
|
6
6
|
import { createBrowserModule } from "./modules/browser.js";
|
|
7
7
|
import { createVoiceModule } from "./modules/voice.js";
|
|
8
8
|
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
9
|
-
import { getAccessToken
|
|
9
|
+
import { getAccessToken } from "./utils/auth-utils.js";
|
|
10
10
|
import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
|
|
11
11
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
12
12
|
import { createAgentsModule } from "./modules/agents.js";
|
|
@@ -17,7 +17,7 @@ import { createUsersModule } from "./modules/users.js";
|
|
|
17
17
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
18
18
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
19
19
|
import { createPaymentsModule, createServiceRolePaymentsModule, } from "./modules/payments.js";
|
|
20
|
-
import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
20
|
+
import { createActorsModule, createServiceRoleActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
21
21
|
/**
|
|
22
22
|
* Creates a Base44 client.
|
|
23
23
|
*
|
|
@@ -58,8 +58,8 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
58
58
|
export function createClient(config) {
|
|
59
59
|
var _a, _b, _c, _d;
|
|
60
60
|
const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
61
|
-
//
|
|
62
|
-
const normalizedAppBaseUrl =
|
|
61
|
+
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
62
|
+
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
63
63
|
const socketConfig = {
|
|
64
64
|
serverUrl,
|
|
65
65
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -121,6 +121,20 @@ export function createClient(config) {
|
|
|
121
121
|
token: serviceToken,
|
|
122
122
|
interceptResponses: false,
|
|
123
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
|
+
};
|
|
124
138
|
// Dedicated client for actor connection-token mints: no onError (a legacy
|
|
125
139
|
// actor answers every mint with an expected 409 before the proxy fallback,
|
|
126
140
|
// which must not reach the app's error handler — the actors module forwards
|
|
@@ -167,6 +181,7 @@ export function createClient(config) {
|
|
|
167
181
|
},
|
|
168
182
|
transport: options === null || options === void 0 ? void 0 : options.actorsTransport,
|
|
169
183
|
onMintError: options === null || options === void 0 ? void 0 : options.onError,
|
|
184
|
+
postRequest: actorRequestPoster(axiosClient),
|
|
170
185
|
});
|
|
171
186
|
const userModules = {
|
|
172
187
|
entities: createEntitiesModule({
|
|
@@ -259,6 +274,7 @@ export function createClient(config) {
|
|
|
259
274
|
}),
|
|
260
275
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
261
276
|
payments: createServiceRolePaymentsModule(serviceRoleAxiosClient, appId),
|
|
277
|
+
actors: createServiceRoleActorsModule(actorRequestPoster(serviceRoleAxiosClient)),
|
|
262
278
|
cleanup: () => {
|
|
263
279
|
if (socket) {
|
|
264
280
|
socket.disconnect();
|
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/dist/utils/auth-utils.js
CHANGED
|
@@ -187,19 +187,3 @@ export function getLoginUrl(nextUrl, options) {
|
|
|
187
187
|
const encodedRedirectUrl = encodeURIComponent(nextUrl || (typeof window !== "undefined" ? window.location.href : ""));
|
|
188
188
|
return `${serverUrl}${loginPath}?from_url=${encodedRedirectUrl}&app_id=${appId}`;
|
|
189
189
|
}
|
|
190
|
-
// appBaseUrl becomes a navigation target, so only http(s) values may pass.
|
|
191
|
-
export function sanitizeAppBaseUrl(value) {
|
|
192
|
-
var _a;
|
|
193
|
-
if (typeof value !== "string")
|
|
194
|
-
return "";
|
|
195
|
-
try {
|
|
196
|
-
const base = typeof window !== "undefined" && ((_a = window.location) === null || _a === void 0 ? void 0 : _a.origin)
|
|
197
|
-
? window.location.origin
|
|
198
|
-
: "http://localhost";
|
|
199
|
-
const { protocol } = new URL(value, base);
|
|
200
|
-
return protocol === "http:" || protocol === "https:" ? value : "";
|
|
201
|
-
}
|
|
202
|
-
catch (_b) {
|
|
203
|
-
return "";
|
|
204
|
-
}
|
|
205
|
-
}
|