@base44-preview/sdk 0.8.48-pr.280.dac0f98 → 0.8.48-pr.282.2b05017

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.
Files changed (34) hide show
  1. package/dist/client.js +84 -69
  2. package/dist/client.types.d.ts +5 -14
  3. package/dist/index.d.ts +0 -3
  4. package/dist/index.js +0 -1
  5. package/dist/modules/agents.d.ts +1 -1
  6. package/dist/modules/agents.js +3 -4
  7. package/dist/modules/agents.types.d.ts +2 -2
  8. package/dist/modules/ai-gateway.d.ts +1 -1
  9. package/dist/modules/ai-gateway.js +2 -3
  10. package/dist/modules/ai-gateway.types.d.ts +2 -2
  11. package/dist/modules/analytics.d.ts +4 -29
  12. package/dist/modules/analytics.js +82 -107
  13. package/dist/modules/auth.js +13 -34
  14. package/dist/modules/auth.types.d.ts +21 -13
  15. package/dist/utils/embed-session.d.ts +48 -0
  16. package/dist/utils/embed-session.js +139 -0
  17. package/dist/utils/fetch-with-auth.js +0 -6
  18. package/dist/utils/socket-utils.d.ts +3 -1
  19. package/dist/utils/socket-utils.js +1 -2
  20. package/package.json +1 -1
  21. package/dist/modules/experiment-exposures.d.ts +0 -19
  22. package/dist/modules/experiment-exposures.js +0 -65
  23. package/dist/modules/experiments-config.types.d.ts +0 -39
  24. package/dist/modules/experiments-config.types.js +0 -1
  25. package/dist/modules/experiments-context.d.ts +0 -10
  26. package/dist/modules/experiments-context.js +0 -44
  27. package/dist/modules/experiments-evaluator.d.ts +0 -11
  28. package/dist/modules/experiments-evaluator.js +0 -45
  29. package/dist/modules/experiments-runtime.types.d.ts +0 -19
  30. package/dist/modules/experiments-runtime.types.js +0 -7
  31. package/dist/modules/experiments.d.ts +0 -16
  32. package/dist/modules/experiments.js +0 -134
  33. package/dist/modules/experiments.types.d.ts +0 -106
  34. package/dist/modules/experiments.types.js +0 -1
package/dist/client.js CHANGED
@@ -5,6 +5,7 @@ import { createAuthModule } from "./modules/auth.js";
5
5
  import { createSsoModule } from "./modules/sso.js";
6
6
  import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
7
7
  import { getAccessToken } from "./utils/auth-utils.js";
8
+ import { exchangeEmbedToken, isEmbeddedTab, markEmbeddedTab, takeEmbedTokenFromUrl, } from "./utils/embed-session.js";
8
9
  import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
9
10
  import { createFunctionsModule } from "./modules/functions.js";
10
11
  import { createAgentsModule } from "./modules/agents.js";
@@ -14,9 +15,6 @@ import { createAppModule } from "./modules/app.js";
14
15
  import { createUsersModule } from "./modules/users.js";
15
16
  import { RoomsSocket } from "./utils/socket-utils.js";
16
17
  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
18
  import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
21
19
  /**
22
20
  * Creates a Base44 client.
@@ -56,17 +54,28 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
56
54
  * ```
57
55
  */
58
56
  export function createClient(config) {
59
- var _a, _b, _c, _d, _e, _f, _g;
57
+ var _a, _b, _c, _d;
60
58
  const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
61
59
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
62
60
  const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
63
- const experimentsContext = (_a = config.experiments) !== null && _a !== void 0 ? _a : getBrowserExperimentsContext(appId);
61
+ const inBrowser = typeof window !== "undefined";
62
+ // A host platform embeds the app with a one-time token on the iframe URL.
63
+ // It comes off the URL here, before any other code can read it; the
64
+ // exchange that turns it into a session runs once the modules exist.
65
+ const embedOtt = inBrowser ? takeEmbedTokenFromUrl() : null;
66
+ const embedded = embedOtt !== null || (inBrowser && isEmbeddedTab());
67
+ if (embedOtt) {
68
+ markEmbeddedTab();
69
+ }
70
+ let currentToken = token !== null && token !== void 0 ? token : null;
64
71
  const socketConfig = {
65
72
  serverUrl,
66
73
  mountPath: "/ws-user-apps/socket.io/",
67
74
  transports: ["websocket"],
68
75
  appId,
69
- token,
76
+ // null (not undefined): an embedded frame's only identity is the one the
77
+ // platform minted, so the socket must not fall back to a stored token.
78
+ token: embedded ? null : token,
70
79
  };
71
80
  let socket = null;
72
81
  const getSocket = () => {
@@ -77,14 +86,9 @@ export function createClient(config) {
77
86
  }
78
87
  return socket;
79
88
  };
80
- const { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext, ...requestHeaders } = optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {};
81
89
  const headers = {
82
- ...requestHeaders,
90
+ ...optionalHeaders,
83
91
  "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
92
  };
89
93
  const functionHeaders = functionsVersion
90
94
  ? {
@@ -130,52 +134,77 @@ export function createClient(config) {
130
134
  baseURL: `${serverUrl}/api`,
131
135
  headers,
132
136
  });
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
- getAuth: () => userAuthModule,
142
- trackExposure: exposureTracker.track,
143
- flushExposures: exposureTracker.flush,
144
- context: experimentsContext,
145
- });
146
137
  const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
147
138
  appBaseUrl: normalizedAppBaseUrl,
148
139
  serverUrl,
149
140
  token,
150
- onAuthStateChange: experiments.onAuthStateChange,
141
+ embedded,
151
142
  });
152
143
  // Apply the access token before any module that may issue authenticated
153
144
  // requests during construction (notably analytics, which fires an init
154
145
  // event whose flush calls auth.me()). Without this, the first User/me
155
146
  // request is built before setToken runs and goes out unauthenticated.
156
- if (typeof window !== "undefined") {
147
+ // An embedded load skips this: its session comes from the exchange below,
148
+ // and a token an earlier visitor left in storage must not become it.
149
+ if (inBrowser && !embedded) {
157
150
  const accessToken = token || getAccessToken();
158
151
  if (accessToken) {
152
+ currentToken = accessToken;
159
153
  userAuthModule.setToken(accessToken);
160
154
  }
161
155
  }
162
- if (experimentsContext) {
163
- const { userId, status } = experimentsContext.identity;
164
- // The document's cookie identity may differ from this client's localStorage token.
165
- const needsClientIdentity = typeof window !== "undefined" && userAuthModule.hasToken() &&
166
- experimentsContext.config.experiments.some((experiment) => experiment.assign_by === "user");
167
- experiments.onAuthStateChange(status === "pending" || needsClientIdentity ? { status: "pending" } :
168
- userId ? { status: "authenticated", userId } : { status: "anonymous" });
156
+ // The one answer every module reads. Follows setToken and logout; outside an
157
+ // embedded frame it still falls back to storage, so a login in another tab is
158
+ // picked up on the next connection, as before.
159
+ const getToken = () => {
160
+ if (userAuthModule.hasToken()) {
161
+ return currentToken;
162
+ }
163
+ return embedded || !inBrowser ? null : getAccessToken();
164
+ };
165
+ const applyToken = (newToken, saveToStorage) => {
166
+ userAuthModule.setToken(newToken, saveToStorage);
167
+ currentToken = newToken;
168
+ socketConfig.token = newToken;
169
+ if (socket) {
170
+ socket.updateConfig({ token: newToken });
171
+ }
172
+ };
173
+ // Resolves once the embedded session is in hand (or known not to be coming);
174
+ // immediately for every other client. The exchanged token is applied without
175
+ // persisting it: the session must not outlive the frame it was minted for.
176
+ const authReady = embedOtt
177
+ ? exchangeEmbedToken({ serverUrl, appId, ott: embedOtt }).then((sessionToken) => {
178
+ if (sessionToken) {
179
+ applyToken(sessionToken, false);
180
+ }
181
+ })
182
+ : Promise.resolve();
183
+ if (embedOtt) {
184
+ // Requests issued while the exchange is in flight wait for it and carry the
185
+ // session it produces. Registered after createAxiosClient's interceptors,
186
+ // so it runs first and the anonymous-visitor header sees the Authorization.
187
+ for (const client of [axiosClient, functionsAxiosClient]) {
188
+ client.interceptors.request.use(async (requestConfig) => {
189
+ await authReady;
190
+ const sessionToken = getToken();
191
+ if (sessionToken && !requestConfig.headers.get("Authorization")) {
192
+ requestConfig.headers.set("Authorization", `Bearer ${sessionToken}`);
193
+ }
194
+ return requestConfig;
195
+ });
196
+ }
169
197
  }
170
198
  const actorsModule = createActorsModule({
171
199
  appId,
172
200
  // serverUrl is often relative/empty (same-origin app); the proxy-fallback
173
201
  // URL needs an absolute host, so fall back to the page origin.
174
- host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_d = window.location) === null || _d === void 0 ? void 0 : _d.origin : undefined),
202
+ host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
175
203
  functionsVersion,
176
- getAuthToken: () => token || getAccessToken(),
204
+ getAuthToken: getToken,
177
205
  mintConnectionToken: async (actorName, room, connectionId) => {
178
- const authToken = token || getAccessToken();
206
+ await authReady;
207
+ const authToken = getToken();
179
208
  return await actorsAxiosClient.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/connection-token`, { room, connection_id: connectionId }, {
180
209
  headers: {
181
210
  ...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
@@ -199,27 +228,25 @@ export function createClient(config) {
199
228
  integrations: createIntegrationsModule(axiosClient, appId),
200
229
  connectors: createUserConnectorsModule(axiosClient, appId),
201
230
  auth: userAuthModule,
202
- experiments: experiments.module,
203
231
  functions: createFunctionsModule(functionsAxiosClient, appId, {
204
232
  getAuthHeaders: () => {
205
233
  const headers = {};
206
- // Get current token from storage or initial config
207
- const currentToken = token || getAccessToken();
208
- if (currentToken) {
209
- headers["Authorization"] = `Bearer ${currentToken}`;
234
+ const sessionToken = getToken();
235
+ if (sessionToken) {
236
+ headers["Authorization"] = `Bearer ${sessionToken}`;
210
237
  }
211
238
  return headers;
212
239
  },
213
- baseURL: (_e = functionsAxiosClient.defaults) === null || _e === void 0 ? void 0 : _e.baseURL,
240
+ baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
214
241
  }),
215
242
  agents: createAgentsModule({
216
243
  axios: axiosClient,
217
244
  getSocket,
218
245
  appId,
219
246
  serverUrl,
220
- token,
247
+ getToken,
221
248
  }),
222
- aiGateway: createAiGatewayModule({ serverUrl, token, appId }),
249
+ aiGateway: createAiGatewayModule({ serverUrl, getToken, appId }),
223
250
  appLogs: createAppLogsModule(axiosClient, appId),
224
251
  app: createAppModule(axiosClient, appId),
225
252
  users: createUsersModule(axiosClient, appId),
@@ -228,14 +255,11 @@ export function createClient(config) {
228
255
  serverUrl,
229
256
  appId,
230
257
  userAuthModule,
231
- enabled: (_f = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _f !== void 0 ? _f : true,
232
- getVisitorId: experiments.visitorId,
233
- experimentsContext,
258
+ enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
234
259
  }),
235
260
  actors: actorsModule.module,
236
261
  cleanup: () => {
237
262
  userModules.analytics.cleanup();
238
- experiments.cleanup();
239
263
  actorsModule.closeAll();
240
264
  if (socket) {
241
265
  socket.disconnect();
@@ -260,16 +284,20 @@ export function createClient(config) {
260
284
  }
261
285
  return headers;
262
286
  },
263
- baseURL: (_g = serviceRoleFunctionsAxiosClient.defaults) === null || _g === void 0 ? void 0 : _g.baseURL,
287
+ baseURL: (_d = serviceRoleFunctionsAxiosClient.defaults) === null || _d === void 0 ? void 0 : _d.baseURL,
264
288
  }),
265
289
  agents: createAgentsModule({
266
290
  axios: serviceRoleAxiosClient,
267
291
  getSocket,
268
292
  appId,
269
293
  serverUrl,
270
- token,
294
+ getToken: () => token,
295
+ }),
296
+ aiGateway: createAiGatewayModule({
297
+ serverUrl,
298
+ getToken: () => serviceToken,
299
+ appId,
271
300
  }),
272
- aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken, appId }),
273
301
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
274
302
  cleanup: () => {
275
303
  if (socket) {
@@ -303,15 +331,13 @@ export function createClient(config) {
303
331
  appId: String(appId),
304
332
  serverUrl,
305
333
  functionsVersion,
306
- platformHeaders: {
307
- ...headers,
308
- ...(inheritedExperimentsContext ? { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext } : {}),
309
- },
334
+ platformHeaders: optionalHeaders,
310
335
  }),
311
336
  /**
312
337
  * Sets a new authentication token for all subsequent requests.
313
338
  *
314
339
  * @param newToken - The new authentication token
340
+ * @param saveToStorage - Whether to also keep the token in local storage. Defaults to `true`.
315
341
  *
316
342
  * @example
317
343
  * ```typescript
@@ -323,14 +349,8 @@ export function createClient(config) {
323
349
  * base44.setToken(access_token);
324
350
  * ```
325
351
  */
326
- setToken(newToken) {
327
- userModules.auth.setToken(newToken);
328
- if (socket) {
329
- socket.updateConfig({
330
- token: newToken,
331
- });
332
- }
333
- socketConfig.token = newToken;
352
+ setToken(newToken, saveToStorage = true) {
353
+ applyToken(newToken, saveToStorage);
334
354
  },
335
355
  /**
336
356
  * Gets the current client configuration.
@@ -458,10 +478,6 @@ export function createClientFromRequest(request) {
458
478
  }
459
479
  // Prepare additional headers to propagate
460
480
  const additionalHeaders = {};
461
- const encodedExperiments = request.headers.get(EXPERIMENTS_CONTEXT_HEADER);
462
- const experimentsContext = readExperimentsContext(encodedExperiments, appId);
463
- if (experimentsContext && encodedExperiments)
464
- additionalHeaders[EXPERIMENTS_CONTEXT_HEADER] = encodedExperiments;
465
481
  if (stateHeader) {
466
482
  additionalHeaders["Base44-State"] = stateHeader;
467
483
  }
@@ -482,6 +498,5 @@ export function createClientFromRequest(request) {
482
498
  serviceToken: serviceRoleToken,
483
499
  functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
484
500
  headers: additionalHeaders,
485
- experiments: experimentsContext ? { ...experimentsContext, pageUrl: request.url ? new URL(request.url).pathname : "/" } : undefined,
486
501
  });
487
502
  }
@@ -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, experiment exposures and calls to
45
- * `analytics.track()` are no-ops. The SDK does not create an analytics session
46
- * identifier, start heartbeat timers, or send analytics requests.
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. */
@@ -210,8 +200,9 @@ export interface Base44Client {
210
200
  * Updates the token for both HTTP requests and WebSocket connections.
211
201
  *
212
202
  * @param newToken - The new authentication token.
203
+ * @param saveToStorage - Whether to also keep the token in local storage so it survives a page load. Defaults to `true`.
213
204
  */
214
- setToken(newToken: string): void;
205
+ setToken(newToken: string, saveToStorage?: boolean): void;
215
206
  /**
216
207
  * Gets the current client configuration.
217
208
  * @internal
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, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityRecord, EntityTypeRegistry, 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,2 +1,2 @@
1
1
  import { AgentsModule, AgentsModuleConfig } from "./agents.types.js";
2
- export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }: AgentsModuleConfig): AgentsModule;
2
+ export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, getToken, }: AgentsModuleConfig): AgentsModule;
@@ -1,5 +1,4 @@
1
- import { getAccessToken } from "../utils/auth-utils.js";
2
- export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
1
+ export function createAgentsModule({ axios, getSocket, appId, serverUrl, getToken, }) {
3
2
  const baseURL = `/apps/${appId}/agents`;
4
3
  // Track active conversations
5
4
  const currentConversations = {};
@@ -56,7 +55,7 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
56
55
  };
57
56
  const getWhatsAppConnectURL = (agentName) => {
58
57
  const baseUrl = `${serverUrl}/api/apps/${appId}/agents/${encodeURIComponent(agentName)}/whatsapp`;
59
- const accessToken = token !== null && token !== void 0 ? token : getAccessToken();
58
+ const accessToken = getToken();
60
59
  if (accessToken) {
61
60
  return `${baseUrl}?token=${accessToken}`;
62
61
  }
@@ -67,7 +66,7 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
67
66
  };
68
67
  const getTelegramConnectURL = (agentName) => {
69
68
  const baseUrl = `${serverUrl}/api/apps/${appId}/agents/${encodeURIComponent(agentName)}/telegram`;
70
- const accessToken = token !== null && token !== void 0 ? token : getAccessToken();
69
+ const accessToken = getToken();
71
70
  if (accessToken) {
72
71
  return `${baseUrl}?token=${accessToken}`;
73
72
  }
@@ -160,8 +160,8 @@ export interface AgentsModuleConfig {
160
160
  appId: string;
161
161
  /** Server URL */
162
162
  serverUrl?: string;
163
- /** Authentication token */
164
- token?: string;
163
+ /** Returns the current authentication token, if any */
164
+ getToken: () => string | null | undefined;
165
165
  }
166
166
  /**
167
167
  * Agents module for managing AI agent conversations.
@@ -1,2 +1,2 @@
1
1
  import { AiGatewayModule, AiGatewayModuleConfig } from "./ai-gateway.types.js";
2
- export declare function createAiGatewayModule({ serverUrl, token, appId, }: AiGatewayModuleConfig): AiGatewayModule;
2
+ export declare function createAiGatewayModule({ serverUrl, getToken, appId, }: AiGatewayModuleConfig): AiGatewayModule;
@@ -1,10 +1,9 @@
1
- import { getAccessToken } from "../utils/auth-utils.js";
2
- export function createAiGatewayModule({ serverUrl, token, appId, }) {
1
+ export function createAiGatewayModule({ serverUrl, getToken, appId, }) {
3
2
  const connection = () => {
4
3
  var _a;
5
4
  return ({
6
5
  baseURL: `${serverUrl}/api/apps/${appId}/ai/openai/v1`,
7
- token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
6
+ token: (_a = getToken()) !== null && _a !== void 0 ? _a : "",
8
7
  });
9
8
  };
10
9
  return {
@@ -17,8 +17,8 @@ export interface AiGatewayConnection {
17
17
  export interface AiGatewayModuleConfig {
18
18
  /** Server URL */
19
19
  serverUrl?: string;
20
- /** Authentication token */
21
- token?: string;
20
+ /** Returns the current authentication token, if any */
21
+ getToken: () => string | null | undefined;
22
22
  /** Application ID */
23
23
  appId: string;
24
24
  }
@@ -1,7 +1,6 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { TrackEventParams, TrackEventData, AnalyticsModuleOptions, SessionContext } from "./analytics.types";
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__";
@@ -13,22 +12,8 @@ export interface AnalyticsModuleArgs {
13
12
  appId: string;
14
13
  userAuthModule: InternalAuthModule;
15
14
  enabled: boolean;
16
- getVisitorId?: () => string | undefined;
17
- experimentsContext?: ExperimentsContext;
18
15
  }
19
- /** @internal */
20
- export declare function isAnalyticsEnabled(enabled: boolean, state?: {
21
- requestsQueue: TrackEventData[];
22
- isProcessing: boolean;
23
- isHeartBeatProcessing: boolean;
24
- wasInitializationTracked: boolean;
25
- sessionContext: SessionContext | null;
26
- sessionContextPromise: Promise<SessionContext> | null;
27
- sessionStartTime: string | null;
28
- fallbackSessionId: string | null;
29
- config: Required<AnalyticsModuleOptions>;
30
- }): boolean;
31
- export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, getVisitorId, experimentsContext, }: AnalyticsModuleArgs) => {
16
+ export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, }: AnalyticsModuleArgs) => {
32
17
  track: (params: TrackEventParams) => void;
33
18
  cleanup: () => void;
34
19
  };
@@ -42,16 +27,6 @@ export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, us
42
27
  *
43
28
  * @internal
44
29
  */
45
- export declare function resetAnalyticsSessionContext(axiosClient?: AxiosInstance): void;
30
+ export declare function resetAnalyticsSessionContext(): void;
46
31
  export declare function getAnalyticsConfigFromUrlParams(): AnalyticsModuleOptions | undefined;
47
- export declare function getAnalyticsSessionId(state?: {
48
- requestsQueue: TrackEventData[];
49
- isProcessing: boolean;
50
- isHeartBeatProcessing: boolean;
51
- wasInitializationTracked: boolean;
52
- sessionContext: SessionContext | null;
53
- sessionContextPromise: Promise<SessionContext> | null;
54
- sessionStartTime: string | null;
55
- fallbackSessionId: string | null;
56
- config: Required<AnalyticsModuleOptions>;
57
- }): string;
32
+ export declare function getAnalyticsSessionId(): string;