@base44-preview/sdk 0.8.49-pr.280.04af9f9 → 0.8.49-pr.289.78ea614
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 +2 -2
- package/dist/client.js +7 -51
- package/dist/client.types.d.ts +3 -13
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -1
- package/dist/modules/actors.types.d.ts +115 -37
- package/dist/modules/analytics.d.ts +4 -38
- package/dist/modules/analytics.js +154 -107
- package/dist/modules/auth.js +3 -34
- package/dist/modules/auth.types.d.ts +0 -13
- package/dist/utils/fetch-with-auth.js +0 -6
- package/package.json +1 -1
- package/dist/modules/analytics-queue.d.ts +0 -12
- package/dist/modules/analytics-queue.js +0 -128
- package/dist/modules/experiment-exposures.d.ts +0 -19
- package/dist/modules/experiment-exposures.js +0 -30
- package/dist/modules/experiments-config.types.d.ts +0 -39
- package/dist/modules/experiments-config.types.js +0 -1
- package/dist/modules/experiments-context.d.ts +0 -10
- package/dist/modules/experiments-context.js +0 -44
- package/dist/modules/experiments-evaluator.d.ts +0 -11
- package/dist/modules/experiments-evaluator.js +0 -45
- package/dist/modules/experiments-runtime.types.d.ts +0 -19
- package/dist/modules/experiments-runtime.types.js +0 -11
- package/dist/modules/experiments.d.ts +0 -17
- package/dist/modules/experiments.js +0 -134
- package/dist/modules/experiments.types.d.ts +0 -124
- package/dist/modules/experiments.types.js +0 -1
package/dist/actor.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export interface Storage {
|
|
|
25
25
|
get<T>(key: string): Promise<T | undefined>;
|
|
26
26
|
put(key: string, value: unknown): Promise<void>;
|
|
27
27
|
delete(key: string): Promise<boolean>;
|
|
28
|
-
/** Wipe the
|
|
29
|
-
*
|
|
28
|
+
/** Wipe the session's entire persisted storage. A later connection starts
|
|
29
|
+
* with the same empty storage as a new session. */
|
|
30
30
|
deleteAll(): Promise<void>;
|
|
31
31
|
}
|
|
32
32
|
/**
|
package/dist/client.js
CHANGED
|
@@ -14,9 +14,6 @@ import { createAppModule } from "./modules/app.js";
|
|
|
14
14
|
import { createUsersModule } from "./modules/users.js";
|
|
15
15
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
16
16
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
17
|
-
import { createExperimentsModule } from "./modules/experiments.js";
|
|
18
|
-
import { createExposureTracker } from "./modules/experiment-exposures.js";
|
|
19
|
-
import { EXPERIMENTS_CONTEXT_HEADER, getBrowserExperimentsContext, readExperimentsContext } from "./modules/experiments-context.js";
|
|
20
17
|
import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
21
18
|
/**
|
|
22
19
|
* Creates a Base44 client.
|
|
@@ -56,11 +53,10 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
56
53
|
* ```
|
|
57
54
|
*/
|
|
58
55
|
export function createClient(config) {
|
|
59
|
-
var _a, _b, _c, _d
|
|
56
|
+
var _a, _b, _c, _d;
|
|
60
57
|
const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
61
58
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
62
59
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
63
|
-
const experimentsContext = (_a = config.experiments) !== null && _a !== void 0 ? _a : getBrowserExperimentsContext(appId);
|
|
64
60
|
const socketConfig = {
|
|
65
61
|
serverUrl,
|
|
66
62
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -77,14 +73,9 @@ export function createClient(config) {
|
|
|
77
73
|
}
|
|
78
74
|
return socket;
|
|
79
75
|
};
|
|
80
|
-
const { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext, ...requestHeaders } = optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {};
|
|
81
76
|
const headers = {
|
|
82
|
-
...
|
|
77
|
+
...optionalHeaders,
|
|
83
78
|
"X-App-Id": String(appId),
|
|
84
|
-
...(experimentsContext ? {
|
|
85
|
-
"Base44-Visitor-Id": experimentsContext.identity.visitorId,
|
|
86
|
-
"Base44-Experiment-Preview": JSON.stringify((_b = experimentsContext.preview) !== null && _b !== void 0 ? _b : {}),
|
|
87
|
-
} : {}),
|
|
88
79
|
};
|
|
89
80
|
const functionHeaders = functionsVersion
|
|
90
81
|
? {
|
|
@@ -130,25 +121,10 @@ export function createClient(config) {
|
|
|
130
121
|
baseURL: `${serverUrl}/api`,
|
|
131
122
|
headers,
|
|
132
123
|
});
|
|
133
|
-
const exposureTracker = createExposureTracker({
|
|
134
|
-
axiosClient,
|
|
135
|
-
appId,
|
|
136
|
-
enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
|
|
137
|
-
source: typeof window === "undefined" ? "backend" : "browser",
|
|
138
|
-
pageUrl: experimentsContext === null || experimentsContext === void 0 ? void 0 : experimentsContext.pageUrl,
|
|
139
|
-
});
|
|
140
|
-
const experiments = createExperimentsModule({
|
|
141
|
-
appId,
|
|
142
|
-
getAuth: () => userAuthModule,
|
|
143
|
-
trackExposure: exposureTracker.track,
|
|
144
|
-
flushExposures: exposureTracker.flush,
|
|
145
|
-
context: experimentsContext,
|
|
146
|
-
});
|
|
147
124
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
148
125
|
appBaseUrl: normalizedAppBaseUrl,
|
|
149
126
|
serverUrl,
|
|
150
127
|
token,
|
|
151
|
-
onAuthStateChange: experiments.onAuthStateChange,
|
|
152
128
|
});
|
|
153
129
|
// Apply the access token before any module that may issue authenticated
|
|
154
130
|
// requests during construction (notably analytics, which fires an init
|
|
@@ -160,19 +136,11 @@ export function createClient(config) {
|
|
|
160
136
|
userAuthModule.setToken(accessToken);
|
|
161
137
|
}
|
|
162
138
|
}
|
|
163
|
-
if (experimentsContext) {
|
|
164
|
-
const { userId, status } = experimentsContext.identity;
|
|
165
|
-
// The document's cookie identity may differ from this client's localStorage token.
|
|
166
|
-
const needsClientIdentity = typeof window !== "undefined" && userAuthModule.hasToken() &&
|
|
167
|
-
experimentsContext.config.experiments.some((experiment) => experiment.assign_by === "user");
|
|
168
|
-
experiments.onAuthStateChange(status === "pending" || needsClientIdentity ? { status: "pending" } :
|
|
169
|
-
userId ? { status: "authenticated", userId } : { status: "anonymous" });
|
|
170
|
-
}
|
|
171
139
|
const actorsModule = createActorsModule({
|
|
172
140
|
appId,
|
|
173
141
|
// serverUrl is often relative/empty (same-origin app); the proxy-fallback
|
|
174
142
|
// URL needs an absolute host, so fall back to the page origin.
|
|
175
|
-
host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (
|
|
143
|
+
host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
|
|
176
144
|
functionsVersion,
|
|
177
145
|
getAuthToken: () => token || getAccessToken(),
|
|
178
146
|
mintConnectionToken: async (actorName, room, connectionId) => {
|
|
@@ -200,7 +168,6 @@ export function createClient(config) {
|
|
|
200
168
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
201
169
|
connectors: createUserConnectorsModule(axiosClient, appId),
|
|
202
170
|
auth: userAuthModule,
|
|
203
|
-
experiments: experiments.module,
|
|
204
171
|
functions: createFunctionsModule(functionsAxiosClient, appId, {
|
|
205
172
|
getAuthHeaders: () => {
|
|
206
173
|
const headers = {};
|
|
@@ -211,7 +178,7 @@ export function createClient(config) {
|
|
|
211
178
|
}
|
|
212
179
|
return headers;
|
|
213
180
|
},
|
|
214
|
-
baseURL: (
|
|
181
|
+
baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
|
|
215
182
|
}),
|
|
216
183
|
agents: createAgentsModule({
|
|
217
184
|
axios: axiosClient,
|
|
@@ -229,14 +196,11 @@ export function createClient(config) {
|
|
|
229
196
|
serverUrl,
|
|
230
197
|
appId,
|
|
231
198
|
userAuthModule,
|
|
232
|
-
enabled: (
|
|
233
|
-
getVisitorId: experiments.visitorId,
|
|
234
|
-
experimentsContext,
|
|
199
|
+
enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
|
|
235
200
|
}),
|
|
236
201
|
actors: actorsModule.module,
|
|
237
202
|
cleanup: () => {
|
|
238
203
|
userModules.analytics.cleanup();
|
|
239
|
-
experiments.cleanup();
|
|
240
204
|
actorsModule.closeAll();
|
|
241
205
|
if (socket) {
|
|
242
206
|
socket.disconnect();
|
|
@@ -261,7 +225,7 @@ export function createClient(config) {
|
|
|
261
225
|
}
|
|
262
226
|
return headers;
|
|
263
227
|
},
|
|
264
|
-
baseURL: (
|
|
228
|
+
baseURL: (_d = serviceRoleFunctionsAxiosClient.defaults) === null || _d === void 0 ? void 0 : _d.baseURL,
|
|
265
229
|
}),
|
|
266
230
|
agents: createAgentsModule({
|
|
267
231
|
axios: serviceRoleAxiosClient,
|
|
@@ -304,10 +268,7 @@ export function createClient(config) {
|
|
|
304
268
|
appId: String(appId),
|
|
305
269
|
serverUrl,
|
|
306
270
|
functionsVersion,
|
|
307
|
-
platformHeaders:
|
|
308
|
-
...headers,
|
|
309
|
-
...(inheritedExperimentsContext ? { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext } : {}),
|
|
310
|
-
},
|
|
271
|
+
platformHeaders: optionalHeaders,
|
|
311
272
|
}),
|
|
312
273
|
/**
|
|
313
274
|
* Sets a new authentication token for all subsequent requests.
|
|
@@ -459,10 +420,6 @@ export function createClientFromRequest(request) {
|
|
|
459
420
|
}
|
|
460
421
|
// Prepare additional headers to propagate
|
|
461
422
|
const additionalHeaders = {};
|
|
462
|
-
const encodedExperiments = request.headers.get(EXPERIMENTS_CONTEXT_HEADER);
|
|
463
|
-
const experimentsContext = readExperimentsContext(encodedExperiments, appId);
|
|
464
|
-
if (experimentsContext && encodedExperiments)
|
|
465
|
-
additionalHeaders[EXPERIMENTS_CONTEXT_HEADER] = encodedExperiments;
|
|
466
423
|
if (stateHeader) {
|
|
467
424
|
additionalHeaders["Base44-State"] = stateHeader;
|
|
468
425
|
}
|
|
@@ -483,6 +440,5 @@ export function createClientFromRequest(request) {
|
|
|
483
440
|
serviceToken: serviceRoleToken,
|
|
484
441
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
485
442
|
headers: additionalHeaders,
|
|
486
|
-
experiments: experimentsContext ? { ...experimentsContext, pageUrl: request.url ? new URL(request.url).pathname : "/" } : undefined,
|
|
487
443
|
});
|
|
488
444
|
}
|
package/dist/client.types.d.ts
CHANGED
|
@@ -9,8 +9,6 @@ import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
|
|
|
9
9
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
10
10
|
import type { AppModule } from "./modules/app.types.js";
|
|
11
11
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
12
|
-
import type { ExperimentsModule } from "./modules/experiments.types.js";
|
|
13
|
-
import type { ExperimentsContext } from "./modules/experiments-config.types.js";
|
|
14
12
|
import type { ActorsModule } from "./modules/actors.types.js";
|
|
15
13
|
import type { FetchWithAuthInit } from "./utils/fetch-with-auth.js";
|
|
16
14
|
/**
|
|
@@ -41,9 +39,9 @@ export interface CreateClientAnalyticsConfig {
|
|
|
41
39
|
/**
|
|
42
40
|
* Whether app analytics is enabled for this client.
|
|
43
41
|
*
|
|
44
|
-
* When disabled, automatic analytics
|
|
45
|
-
*
|
|
46
|
-
*
|
|
42
|
+
* When disabled, automatic analytics and calls to `analytics.track()` are
|
|
43
|
+
* no-ops. The SDK does not create an analytics session identifier, start
|
|
44
|
+
* heartbeat timers, or send analytics requests.
|
|
47
45
|
*
|
|
48
46
|
* @defaultValue `true`
|
|
49
47
|
*/
|
|
@@ -81,12 +79,6 @@ export interface CreateClientConfig {
|
|
|
81
79
|
* Omit this option to preserve the default analytics behavior.
|
|
82
80
|
*/
|
|
83
81
|
analytics?: CreateClientAnalyticsConfig;
|
|
84
|
-
/**
|
|
85
|
-
* Platform-validated context for local flag evaluation. Request-scoped on servers.
|
|
86
|
-
* Automatically read from the platform bootstrap in browsers and trusted headers
|
|
87
|
-
* by createClientFromRequest(). Not an authorization credential.
|
|
88
|
-
*/
|
|
89
|
-
experiments?: ExperimentsContext;
|
|
90
82
|
/**
|
|
91
83
|
* User authentication token. Used to authenticate as a specific user.
|
|
92
84
|
*
|
|
@@ -142,8 +134,6 @@ export interface Base44Client {
|
|
|
142
134
|
connectors: UserConnectorsModule;
|
|
143
135
|
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
|
|
144
136
|
entities: EntitiesModule;
|
|
145
|
-
/** {@link ExperimentsModule | Experiments module} for local feature flags and exposures. */
|
|
146
|
-
experiments: ExperimentsModule;
|
|
147
137
|
/** {@link FunctionsModule | Functions module} for invoking custom backend functions. */
|
|
148
138
|
functions: FunctionsModule;
|
|
149
139
|
/** {@link IntegrationsModule | Integrations module} for calling pre-built integration endpoints. */
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,6 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientAnalyticsConfig, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export { evaluateExperiments } from "./modules/experiments-evaluator.js";
|
|
8
|
-
export type { ExperimentsConfig, ExperimentsContext, ExperimentsIdentity } from "./modules/experiments-config.types.js";
|
|
9
|
-
export type { ExperimentsModule, ExperimentsSnapshot, } from "./modules/experiments.types.js";
|
|
10
7
|
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucketUnit, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
11
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
12
9
|
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
package/dist/index.js
CHANGED
|
@@ -3,5 +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 { evaluateExperiments } from "./modules/experiments-evaluator.js";
|
|
7
6
|
export { Actor } from "./actor.js";
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* for your deployed Actors.
|
|
2
|
+
* Maps actor names to their incoming and outgoing message types.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Extend this interface through module augmentation when you want typed actor
|
|
5
|
+
* messages without generating types with the CLI. For each actor, `toServer`
|
|
6
|
+
* defines incoming messages that a client sends to the actor. `toClient` defines
|
|
7
|
+
* outgoing messages that the actor sends to connected clients.
|
|
8
|
+
*
|
|
9
|
+
* To generate types from deployed actors instead, use the
|
|
10
|
+
* [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
|
|
11
|
+
* See [Typing messages in the client](/developers/backend/resources/actors/overview#typing-messages-in-the-client)
|
|
12
|
+
* for how to define your message types.
|
|
7
13
|
*
|
|
8
14
|
* @example
|
|
9
15
|
* ```typescript
|
|
@@ -20,8 +26,11 @@
|
|
|
20
26
|
export interface ActorRegistry {
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
29
|
+
* Lists actor names when your project includes types generated by the CLI
|
|
30
|
+
* with [`types generate`](/developers/references/cli/commands/types-generate).
|
|
31
|
+
*
|
|
32
|
+
* The generated names provide autocomplete for deployed actors. To define
|
|
33
|
+
* incoming and outgoing message types manually, augment {@link ActorRegistry}.
|
|
25
34
|
*/
|
|
26
35
|
export interface ActorNameRegistry {
|
|
27
36
|
}
|
|
@@ -32,71 +41,140 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
|
|
|
32
41
|
type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
33
42
|
toServer: infer O;
|
|
34
43
|
} ? O : unknown : unknown;
|
|
35
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Options for {@link ActorRef.connect}.
|
|
46
|
+
*/
|
|
36
47
|
export interface ActorConnectOptions {
|
|
37
48
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
49
|
+
* Connection ID that the actor receives as `conn.id`.
|
|
50
|
+
*
|
|
51
|
+
* Use a stable value, such as one stored per browser tab, so the actor
|
|
52
|
+
* can recognize the same client if it reconnects. If omitted, the SDK generates one.
|
|
53
|
+
*
|
|
54
|
+
* See [Connection ID](/developers/backend/resources/actors/overview#connection-id)
|
|
55
|
+
* for more details.
|
|
41
56
|
*/
|
|
42
57
|
id?: string;
|
|
43
58
|
}
|
|
44
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Represents an outgoing-message listener registered with
|
|
61
|
+
* {@link Connection.subscribe}.
|
|
62
|
+
*/
|
|
45
63
|
export interface ActorSubscription {
|
|
46
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Removes this listener. Other listeners and the socket stay open.
|
|
66
|
+
*/
|
|
47
67
|
unsubscribe(): void;
|
|
48
68
|
}
|
|
49
69
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
70
|
+
* Represents a client's WebSocket connection to an actor session.
|
|
71
|
+
*
|
|
72
|
+
* {@link ActorRef.connect} returns this object while the socket connects.
|
|
73
|
+
* The socket buffers messages sent during connection setup until it opens.
|
|
53
74
|
*/
|
|
54
75
|
export interface Connection<N extends string = string> {
|
|
55
|
-
/**
|
|
76
|
+
/** Connection ID that the actor receives as `conn.id`. */
|
|
56
77
|
readonly id: string;
|
|
57
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Registers a listener for outgoing messages from the actor.
|
|
80
|
+
*
|
|
81
|
+
* You can register multiple listeners on the same connection.
|
|
82
|
+
*
|
|
83
|
+
* @param callback - Called with each outgoing message sent to this connection.
|
|
84
|
+
* @returns A handle you can use to remove this listener without closing the socket.
|
|
85
|
+
*/
|
|
58
86
|
subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
87
|
+
/**
|
|
88
|
+
* Sends an incoming message to the actor.
|
|
89
|
+
*
|
|
90
|
+
* The socket buffers messages until it opens. After {@link close}, the socket
|
|
91
|
+
* drops further sends.
|
|
92
|
+
*
|
|
93
|
+
* @param data - Incoming message to send. Typed through {@link ActorRegistry} when configured.
|
|
94
|
+
*/
|
|
61
95
|
send(data: ToServerFor<N>): void;
|
|
62
96
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
97
|
+
* Closes the connection and removes all listeners.
|
|
98
|
+
*
|
|
99
|
+
* Safe to call more than once. A connection also closes itself when it fails
|
|
100
|
+
* permanently. See {@link ActorRef.connect} for how to open a fresh connection.
|
|
66
101
|
*/
|
|
67
102
|
close(): void;
|
|
68
103
|
}
|
|
69
104
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
105
|
+
* Represents an actor session selected by actor name and session ID.
|
|
106
|
+
*
|
|
107
|
+
* Call {@link connect} to open the WebSocket and get a {@link Connection}.
|
|
72
108
|
*/
|
|
73
109
|
export interface ActorRef<N extends string = string> {
|
|
74
110
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
111
|
+
* Creates or returns the {@link Connection} for this session.
|
|
112
|
+
*
|
|
113
|
+
* Repeated calls return the same connection until it closes. After a permanent
|
|
114
|
+
* failure, such as a missing actor or denied connection, fix the cause and call
|
|
115
|
+
* `connect()` again. Add subscriptions to the new connection.
|
|
77
116
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
117
|
+
* See [Connect a client to a session](/developers/backend/resources/actors/samples#connect-a-client-to-a-session)
|
|
118
|
+
* for a sample flow.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Optional connection settings, such as a stable connection ID.
|
|
121
|
+
* @returns The {@link Connection} for this actor session.
|
|
82
122
|
*/
|
|
83
123
|
connect(options?: ActorConnectOptions): Connection<N>;
|
|
84
124
|
}
|
|
85
125
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* {@link ActorRegistry}
|
|
126
|
+
* Selects a session for a named actor.
|
|
127
|
+
*
|
|
128
|
+
* Typed automatically when the actor is registered in {@link ActorRegistry} or
|
|
129
|
+
* {@link ActorNameRegistry}.
|
|
89
130
|
*/
|
|
90
131
|
export interface ActorClient<N extends string = string> {
|
|
132
|
+
/**
|
|
133
|
+
* Gets a reference to an actor session.
|
|
134
|
+
*
|
|
135
|
+
* Clients that specify the same actor name and session ID join the same session.
|
|
136
|
+
*
|
|
137
|
+
* @param instanceId - Session ID that identifies which session to connect to.
|
|
138
|
+
* @returns A reference to the actor session.
|
|
139
|
+
*/
|
|
91
140
|
(instanceId: string): ActorRef<N>;
|
|
92
141
|
}
|
|
93
142
|
/**
|
|
94
|
-
*
|
|
95
|
-
* Actors deployed by the Base44 platform.
|
|
143
|
+
* Provides access to actors and their shared, live sessions.
|
|
96
144
|
*
|
|
145
|
+
* Select an actor by name and session ID, then connect a client to the
|
|
146
|
+
* session. Clients in the same session can exchange realtime messages through the
|
|
147
|
+
* actor. The client works in the browser and in Node.
|
|
148
|
+
*
|
|
149
|
+
* ## Connection flow
|
|
150
|
+
*
|
|
151
|
+
* - Connect to a session with `base44.actors.<ActorName>(sessionId).connect()`.
|
|
152
|
+
* - Subscribe to outgoing messages with {@link Connection.subscribe}.
|
|
153
|
+
* - Send incoming messages with {@link Connection.send}.
|
|
154
|
+
* - Close the connection with {@link Connection.close}.
|
|
155
|
+
*
|
|
156
|
+
* See [Actors Overview](/developers/backend/resources/actors/overview)
|
|
157
|
+
* for actor concepts and terminology, [Actor Class Reference](/developers/backend/resources/actors/reference)
|
|
158
|
+
* for the backend class API, and [Sample Flows](/developers/backend/resources/actors/samples)
|
|
159
|
+
* for common patterns.
|
|
160
|
+
*
|
|
161
|
+
* ## See also
|
|
162
|
+
*
|
|
163
|
+
* - [Actors Overview](/developers/backend/resources/actors/overview) — Actor concepts, sessions, message types, storage, and timers
|
|
164
|
+
* - [Actor Class Reference](/developers/backend/resources/actors/reference) — Backend class API
|
|
165
|
+
* - [Sample Flows](/developers/backend/resources/actors/samples) — Connect a client, run ticks, schedule wakes, and persist data
|
|
166
|
+
* - [`types generate`](/developers/references/cli/commands/types-generate) — Generate TypeScript types from deployed actors
|
|
167
|
+
*
|
|
168
|
+
* ## Authentication modes
|
|
169
|
+
*
|
|
170
|
+
* This module is available in anonymous or user authentication mode
|
|
171
|
+
* (`base44.actors`). It isn't available with service role authentication. Apps that
|
|
172
|
+
* require login can reject anonymous connections in the actor's `handleConnect()` method.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
97
175
|
* ```typescript
|
|
98
|
-
* const conn = base44.actors.
|
|
99
|
-
* const sub = conn.subscribe((msg) => console.log(msg));
|
|
176
|
+
* const conn = base44.actors.Chat("session-1").connect({ id: "tab-1" });
|
|
177
|
+
* const sub = conn.subscribe((msg) => console.log(msg));
|
|
100
178
|
* conn.send({ type: "message", text: "hi" });
|
|
101
179
|
* sub.unsubscribe();
|
|
102
180
|
* conn.close();
|
|
@@ -1,44 +1,19 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { TrackEventParams, AnalyticsModuleOptions
|
|
2
|
+
import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
|
|
3
3
|
import type { InternalAuthModule } from "./auth.types";
|
|
4
|
-
import type { ExperimentsContext } from "./experiments-config.types.js";
|
|
5
4
|
export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
6
5
|
export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
7
6
|
export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
8
7
|
export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
9
8
|
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
10
|
-
declare function createAnalyticsState(): {
|
|
11
|
-
isHeartBeatProcessing: boolean;
|
|
12
|
-
wasInitializationTracked: boolean;
|
|
13
|
-
sessionContext: SessionContext | null;
|
|
14
|
-
sessionContextPromise: Promise<SessionContext> | null;
|
|
15
|
-
sessionStartTime: string | null;
|
|
16
|
-
fallbackSessionId: string | null;
|
|
17
|
-
config: Required<AnalyticsModuleOptions>;
|
|
18
|
-
};
|
|
19
|
-
type AnalyticsState = ReturnType<typeof createAnalyticsState>;
|
|
20
|
-
/** @internal */
|
|
21
|
-
export declare function getAnalyticsState(axiosClient: AxiosInstance): AnalyticsState;
|
|
22
9
|
export interface AnalyticsModuleArgs {
|
|
23
10
|
axiosClient: AxiosInstance;
|
|
24
11
|
serverUrl: string;
|
|
25
12
|
appId: string;
|
|
26
13
|
userAuthModule: InternalAuthModule;
|
|
27
14
|
enabled: boolean;
|
|
28
|
-
getVisitorId?: () => string | undefined;
|
|
29
|
-
experimentsContext?: ExperimentsContext;
|
|
30
15
|
}
|
|
31
|
-
|
|
32
|
-
export declare function isAnalyticsEnabled(enabled: boolean, state?: {
|
|
33
|
-
isHeartBeatProcessing: boolean;
|
|
34
|
-
wasInitializationTracked: boolean;
|
|
35
|
-
sessionContext: SessionContext | null;
|
|
36
|
-
sessionContextPromise: Promise<SessionContext> | null;
|
|
37
|
-
sessionStartTime: string | null;
|
|
38
|
-
fallbackSessionId: string | null;
|
|
39
|
-
config: Required<AnalyticsModuleOptions>;
|
|
40
|
-
}): boolean;
|
|
41
|
-
export declare const createAnalyticsModule: ({ axiosClient, appId, userAuthModule, enabled, getVisitorId, experimentsContext, }: AnalyticsModuleArgs) => {
|
|
16
|
+
export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, }: AnalyticsModuleArgs) => {
|
|
42
17
|
track: (params: TrackEventParams) => void;
|
|
43
18
|
cleanup: () => void;
|
|
44
19
|
};
|
|
@@ -52,15 +27,6 @@ export declare const createAnalyticsModule: ({ axiosClient, appId, userAuthModul
|
|
|
52
27
|
*
|
|
53
28
|
* @internal
|
|
54
29
|
*/
|
|
55
|
-
export declare function resetAnalyticsSessionContext(
|
|
30
|
+
export declare function resetAnalyticsSessionContext(): void;
|
|
56
31
|
export declare function getAnalyticsConfigFromUrlParams(): AnalyticsModuleOptions | undefined;
|
|
57
|
-
export declare function getAnalyticsSessionId(
|
|
58
|
-
isHeartBeatProcessing: boolean;
|
|
59
|
-
wasInitializationTracked: boolean;
|
|
60
|
-
sessionContext: SessionContext | null;
|
|
61
|
-
sessionContextPromise: Promise<SessionContext> | null;
|
|
62
|
-
sessionStartTime: string | null;
|
|
63
|
-
fallbackSessionId: string | null;
|
|
64
|
-
config: Required<AnalyticsModuleOptions>;
|
|
65
|
-
}): string;
|
|
66
|
-
export {};
|
|
32
|
+
export declare function getAnalyticsSessionId(): string;
|