@base44-preview/sdk 0.8.60-pr.376.c2b0448 → 0.8.60-pr.377.428760d
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 +47 -0
- package/dist/actor.js +8 -0
- package/dist/client.js +21 -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 +31 -1
- package/dist/modules/actors.types.d.ts +52 -6
- 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,31 @@
|
|
|
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 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
|
+
type: "service";
|
|
24
|
+
}>;
|
|
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);
|
|
36
|
+
}
|
|
12
37
|
/**
|
|
13
38
|
* A single client connection. `Send` is the message type this connection accepts
|
|
14
39
|
* via {@link send} — the actor's *outgoing* (server→client) messages.
|
|
@@ -18,6 +43,8 @@ export interface Conn<Send = unknown> {
|
|
|
18
43
|
* receives from `subscribe()`. Identifies a distinct client, so multiple
|
|
19
44
|
* tabs are separate connections. */
|
|
20
45
|
id: string;
|
|
46
|
+
/** The client's identity, verified by the platform before the connection reached the actor. */
|
|
47
|
+
identity?: ActorConnectionIdentity;
|
|
21
48
|
send(data: Send): void;
|
|
22
49
|
reject(code: number, reason: string): void;
|
|
23
50
|
}
|
|
@@ -60,6 +87,26 @@ export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
|
|
|
60
87
|
* The schedule is one-shot: it fires once and is cleared before this runs.
|
|
61
88
|
*/
|
|
62
89
|
protected handleWake(_key: string): void | Promise<void>;
|
|
90
|
+
/**
|
|
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.
|
|
94
|
+
*
|
|
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.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
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 });
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
static callable?: readonly string[];
|
|
63
110
|
/**
|
|
64
111
|
* Arm a one-shot wake at `at` (epoch ms or a `Date`), identified by `key`.
|
|
65
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
|
@@ -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,21 @@ 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 call to the room.
|
|
126
|
+
const actorMethodCaller = (client) => async (actorName, room, method, args) => {
|
|
127
|
+
var _a;
|
|
128
|
+
const response = await client.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/rooms/${encodeURIComponent(room)}/requests`, JSON.stringify({ method, args }), {
|
|
129
|
+
headers: {
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
// Draft vs published copy, as for a connection.
|
|
132
|
+
...(functionsVersion
|
|
133
|
+
? { "Base44-Functions-Version": functionsVersion }
|
|
134
|
+
: {}),
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return (_a = response === null || response === void 0 ? void 0 : response.reply) !== null && _a !== void 0 ? _a : undefined;
|
|
138
|
+
};
|
|
124
139
|
// Dedicated client for actor connection-token mints: no onError (a legacy
|
|
125
140
|
// actor answers every mint with an expected 409 before the proxy fallback,
|
|
126
141
|
// which must not reach the app's error handler — the actors module forwards
|
|
@@ -167,6 +182,7 @@ export function createClient(config) {
|
|
|
167
182
|
},
|
|
168
183
|
transport: options === null || options === void 0 ? void 0 : options.actorsTransport,
|
|
169
184
|
onMintError: options === null || options === void 0 ? void 0 : options.onError,
|
|
185
|
+
callMethod: actorMethodCaller(axiosClient),
|
|
170
186
|
});
|
|
171
187
|
const userModules = {
|
|
172
188
|
entities: createEntitiesModule({
|
|
@@ -259,6 +275,7 @@ export function createClient(config) {
|
|
|
259
275
|
}),
|
|
260
276
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
261
277
|
payments: createServiceRolePaymentsModule(serviceRoleAxiosClient, appId),
|
|
278
|
+
actors: createServiceRoleActorsModule(actorMethodCaller(serviceRoleAxiosClient)),
|
|
262
279
|
cleanup: () => {
|
|
263
280
|
if (socket) {
|
|
264
281
|
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, 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 } 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";
|
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
|
+
/** 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>;
|
|
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
|
+
callMethod: CallActorMethod;
|
|
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 calls methods. */
|
|
55
|
+
export declare function createServiceRoleActorsModule(callMethod: CallActorMethod): Record<string, (instanceId: string) => ServiceRoleActorRef>;
|
|
51
56
|
export {};
|
package/dist/modules/actors.js
CHANGED
|
@@ -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
|
-
|
|
175
|
+
const ref = {
|
|
157
176
|
connect(options) {
|
|
158
177
|
if (conn)
|
|
159
178
|
return conn;
|
|
@@ -167,6 +186,7 @@ function makeActorRef(actorName, instanceId, config, connections) {
|
|
|
167
186
|
return c;
|
|
168
187
|
},
|
|
169
188
|
};
|
|
189
|
+
return withMethods(ref, (method, args) => config.callMethod(actorName, instanceId, method, args));
|
|
170
190
|
}
|
|
171
191
|
/**
|
|
172
192
|
* The legacy platform-proxy URL, byte-for-byte what PartySocket built before
|
|
@@ -226,3 +246,13 @@ export function createActorsModule(config) {
|
|
|
226
246
|
},
|
|
227
247
|
};
|
|
228
248
|
}
|
|
249
|
+
/** `asServiceRole.actors`: server code can't hold a connection, so it only calls methods. */
|
|
250
|
+
export function createServiceRoleActorsModule(callMethod) {
|
|
251
|
+
return new Proxy({}, {
|
|
252
|
+
get(_, key) {
|
|
253
|
+
if (typeof key !== "string" || key === "then")
|
|
254
|
+
return undefined;
|
|
255
|
+
return (instanceId) => withMethods({}, (method, args) => callMethod(key, instanceId, method, args));
|
|
256
|
+
},
|
|
257
|
+
});
|
|
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
|
|
162
|
+
export interface ActorConnectable<N extends string = string> {
|
|
140
163
|
/**
|
|
141
164
|
* Creates or returns the connection for this session.
|
|
142
165
|
*
|
|
@@ -157,6 +180,26 @@ export interface ActorRef<N extends string = string> {
|
|
|
157
180
|
*/
|
|
158
181
|
connect(options?: ActorConnectOptions): Connection<N>;
|
|
159
182
|
}
|
|
183
|
+
export type ActorRef<N extends string = string> = ActorConnectable<N> & ActorMethods<N>;
|
|
184
|
+
/**
|
|
185
|
+
* Represents a reference to an actor session for server code running with the
|
|
186
|
+
* [service role](/developers/references/sdk/getting-started/client#service-role).
|
|
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
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export type ServiceRoleActorRef<N extends string = string> = ActorMethods<N>;
|
|
197
|
+
/**
|
|
198
|
+
* Actors module available with the service role: selects a session whose methods to call.
|
|
199
|
+
*/
|
|
200
|
+
export type ServiceRoleActorsModule = {
|
|
201
|
+
[K in AllActorNames]: (instanceId: string) => ServiceRoleActorRef<string & K>;
|
|
202
|
+
} & Record<string, (instanceId: string) => ServiceRoleActorRef>;
|
|
160
203
|
/**
|
|
161
204
|
* Selects a session for a named actor.
|
|
162
205
|
*
|
|
@@ -193,6 +236,7 @@ export interface ActorClient<N extends string = string> {
|
|
|
193
236
|
* - Manage connections: {@link ActorRef.connect | Open} and {@link Connection.close | close} a WebSocket connection to a session.
|
|
194
237
|
* - Exchange messages: {@link Connection.send | Send} and {@link Connection.subscribe | listen} for messages to and from an actor.
|
|
195
238
|
* - Manage subscriptions: {@link Connection.subscribe | Subscribe} and {@link ActorSubscription.unsubscribe | unsubscribe} from actor messages without closing the connection.
|
|
239
|
+
* - Call methods: run one of an actor's callable methods on a session, without connecting.
|
|
196
240
|
*
|
|
197
241
|
* For a sample flow, see
|
|
198
242
|
* [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
|
|
@@ -200,12 +244,14 @@ export interface ActorClient<N extends string = string> {
|
|
|
200
244
|
* ## Authentication modes
|
|
201
245
|
*
|
|
202
246
|
* 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)
|
|
247
|
+
* through `base44.actors`. In
|
|
248
|
+
* [service role authentication mode](/developers/references/sdk/getting-started/client#service-role),
|
|
249
|
+
* `base44.asServiceRole.actors` only calls methods.
|
|
205
250
|
*
|
|
206
251
|
* 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)
|
|
252
|
+
* when the client connects or calls a method. A client that hasn't logged in is anonymous, a client that
|
|
253
|
+
* has [logged in](/developers/references/sdk/docs/interfaces/auth) is authenticated, and server
|
|
254
|
+
* code calling with the service role is `service`.
|
|
209
255
|
*/
|
|
210
256
|
export type ActorsModule = {
|
|
211
257
|
[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
|
-
}
|