@base44-preview/sdk 0.8.52-pr.305.d6c90ab → 0.8.52-pr.307.064de09

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.
@@ -42,7 +42,7 @@ export interface AiGatewayModuleConfig {
42
42
  /**
43
43
  * AI Gateway module for calling Base44's managed AI models from your own code.
44
44
  *
45
- * Call `connection()` to get a `baseURL`, `token`, and `headers` that
45
+ * `connection()` hands you a `baseURL`, `token`, and `headers` that
46
46
  * authenticate as your Base44 app. An OpenAI-compatible client is any library, such as the `openai`
47
47
  * SDK or the Vercel AI SDK, that has the same request and response format
48
48
  * as OpenAI's API and lets you point it at a custom `baseURL`
@@ -51,9 +51,9 @@ export interface AiGatewayModuleConfig {
51
51
  * against the provider directly, no separate account, API key, or billing
52
52
  * setup with the underlying model provider required.
53
53
  *
54
- * The optional `provider` picks the API you connect to:
54
+ * `connection()` takes an optional `provider`, and each provider serves a different API:
55
55
  *
56
- * - `openai`, the default: OpenAI-compatible chat completions, image, and video endpoints.
56
+ * - `openai` (default): OpenAI-compatible chat completions and image endpoints.
57
57
  * - `typesafe`: structured evaluations with the `jev` model.
58
58
  *
59
59
  * Call `connection()` from a backend function rather than the browser. This
@@ -71,32 +71,20 @@ export interface AiGatewayModuleConfig {
71
71
  *
72
72
  * The gateway also serves OpenAI's image endpoints, `/images/generations`
73
73
  * and `/images/edits`, so you can generate images and edit them using
74
- * reference images. Image requests use their own set of models. Pass
74
+ * reference images. Image requests use their own set of models: pass
75
75
  * `'automatic'` to let Base44 choose one, or pin a model such as
76
76
  * `'gemini_3_1_flash_image'` or `'gpt_image_2'`. For request options, the
77
77
  * full model list, and limits, see [Generate images with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-images).
78
78
  *
79
- * ## Video
80
- *
81
- * The gateway also serves OpenAI's video endpoints, `/videos`, so you can
82
- * generate video from a prompt, from a still image, or from existing media.
83
- * Video generation is asynchronous. `POST /videos` returns a job, and you poll
84
- * `GET /videos/{id}` until its status is `completed` or `failed`, which can
85
- * take minutes. Video models are their own set, and there's no `automatic`
86
- * option, so pin a model such as `'veo_3_1_fast'` or `'seedance_2'`. For
87
- * request options, the full model list, and limits, see
88
- * [Generate video with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-video).
89
- *
90
79
  * ## Structured evaluations
91
80
  *
92
81
  * The `typesafe` provider runs the `jev` evaluation model through
93
82
  * `@ai-sdk/typesafe-ai` and `experimental_evaluate` from the `ai` package,
94
- * version 7.0.105 or later. Pass `evaluationModel("jev")`, and note that the
95
- * gateway rejects other model IDs, such as `"jev-latest"`. Give it some app
96
- * state and a set of questions, each a `choice`, `score`, or `boolean`. Choice
97
- * and score answers come back with `probabilities` per option, and boolean
98
- * answers with a single `probability` of `true`. Use it to classify, score, or
99
- * route records, then
83
+ * version 7.0.105 or later. Pass `evaluationModel("jev")`; the gateway rejects
84
+ * other model IDs, such as `"jev-latest"`. Give it some app state and a set of
85
+ * questions, each a `choice`, `score`, or `boolean`. Choice and score answers
86
+ * come back with `probabilities` per option; boolean answers with a single
87
+ * `probability` of `true`. Use it to classify, score, or route records, then
100
88
  * apply your own thresholds and actions in code.
101
89
  *
102
90
  * ## Authentication Modes
@@ -104,7 +92,7 @@ export interface AiGatewayModuleConfig {
104
92
  * The mode determines which token `connection()` returns:
105
93
  *
106
94
  * - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token.
107
- * - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead. Use it from backend functions, because apps that restrict Core integrations, the default for new apps, reject user-token gateway calls on public apps. It also works when there's no signed-in user, such as from a scheduled automation.
95
+ * - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead. Use it from backend functions: apps that restrict Core integrations, the default for new apps, reject user-token gateway calls on public apps. It also works when there's no signed-in user, such as from a scheduled automation.
108
96
  *
109
97
  * ## Billing and limits
110
98
  *
@@ -212,30 +200,6 @@ export interface AiGatewayModule {
212
200
  *
213
201
  * @example
214
202
  * ```typescript
215
- * // Start a video and record the job to poll later
216
- * import { createClientFromRequest } from "@base44/sdk";
217
- *
218
- * // Runs inside a backend function
219
- * const base44 = createClientFromRequest(request);
220
- * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
221
- *
222
- * const response = await fetch(`${baseURL}/videos`, {
223
- * method: "POST",
224
- * headers: { ...headers, Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
225
- * body: JSON.stringify({
226
- * model: "veo_3_1_fast",
227
- * prompt: "A lighthouse beam sweeping across a calm sea at dawn",
228
- * seconds: 8,
229
- * }),
230
- * });
231
- *
232
- * // Video generation takes minutes, so store the id and poll it from a later request
233
- * const { id } = await response.json();
234
- * await base44.asServiceRole.entities.Clip.update(clipId, { video_id: id });
235
- * ```
236
- *
237
- * @example
238
- * ```typescript
239
203
  * // Route a support ticket with a structured evaluation
240
204
  * import { createClientFromRequest } from "@base44/sdk";
241
205
  * import { experimental_evaluate as evaluate } from "ai";
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from "axios";
2
2
  import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
3
- import type { InternalAuthModule } from "./auth.types";
3
+ import type { AuthModule } from "./auth.types";
4
4
  export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
5
5
  export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
6
6
  export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
@@ -10,7 +10,7 @@ export interface AnalyticsModuleArgs {
10
10
  axiosClient: AxiosInstance;
11
11
  serverUrl: string;
12
12
  appId: string;
13
- userAuthModule: InternalAuthModule;
13
+ userAuthModule: AuthModule;
14
14
  enabled: boolean;
15
15
  }
16
16
  export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, }: AnalyticsModuleArgs) => {
@@ -196,9 +196,33 @@ function trackInitializationEvent(track) {
196
196
  eventName: ANALYTICS_INITIALIZATION_EVENT_NAME,
197
197
  properties: {
198
198
  referrer: document === null || document === void 0 ? void 0 : document.referrer,
199
+ ...getAttributionParams(),
199
200
  },
200
201
  });
201
202
  }
203
+ // Allowlist, never the whole query string: landing URLs carry PII
204
+ // (e.g. `utm_email`) and tokens.
205
+ const ATTRIBUTION_PARAM_KEYS = [
206
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id",
207
+ "gclid", "gbraid", "wbraid", "gad_source", "gad_campaignid",
208
+ "fbclid", "msclkid", "ttclid", "li_fat_id",
209
+ ];
210
+ function getAttributionParams() {
211
+ try {
212
+ const params = new URLSearchParams(window.location.search);
213
+ const out = {};
214
+ for (const key of ATTRIBUTION_PARAM_KEYS) {
215
+ const value = params.get(key);
216
+ if (value)
217
+ out[key] = value.slice(0, 500);
218
+ }
219
+ return out;
220
+ }
221
+ catch (_a) {
222
+ // React Native has no `window.location`.
223
+ return {};
224
+ }
225
+ }
202
226
  function setSessionDurationTimerStart() {
203
227
  if (typeof window === "undefined" ||
204
228
  analyticsSharedState.sessionStartTime !== null) {
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { AuthModuleOptions, InternalAuthModule } from "./auth.types";
2
+ import { AuthModuleOptions, AuthModule } from "./auth.types";
3
3
  /**
4
4
  * Creates the auth module for the Base44 SDK.
5
5
  *
@@ -10,4 +10,4 @@ import { AuthModuleOptions, InternalAuthModule } from "./auth.types";
10
10
  * @returns Auth module with authentication and user management methods
11
11
  * @internal
12
12
  */
13
- export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: AuthModuleOptions): InternalAuthModule;
13
+ export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: AuthModuleOptions): AuthModule;
@@ -321,6 +321,20 @@ export interface AuthModule {
321
321
  * ```
322
322
  */
323
323
  isAuthenticated(): Promise<boolean>;
324
+ /**
325
+ * Checks whether an access token is currently set on the client.
326
+ *
327
+ * Reports only that a token is present, not that it's valid: an expired or revoked token still returns `true`. Use it to skip requests that can't succeed without a session, such as {@linkcode me | me()} for an anonymous visitor, and use {@linkcode isAuthenticated | isAuthenticated()} to confirm a session with the server. The token is the one passed to {@linkcode createClient | createClient()} or set with {@linkcode setToken | setToken()}, and {@linkcode logout | logout()} clears it. A session held only in an HTTP-only cookie isn't visible to the client and returns `false`.
328
+ *
329
+ * @returns `true` if the client has an access token, `false` otherwise.
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * // Skip the user lookup for anonymous visitors
334
+ * const user = base44.auth.hasToken() ? await base44.auth.me() : null;
335
+ * ```
336
+ */
337
+ hasToken(): boolean;
324
338
  /**
325
339
  * Invites a user to the app.
326
340
  *
@@ -523,20 +537,3 @@ export interface AuthModule {
523
537
  */
524
538
  changePassword(params: ChangePasswordParams): Promise<any>;
525
539
  }
526
- /**
527
- * The auth module as constructed internally, before it is narrowed to
528
- * {@link AuthModule} on the public client. Not exported from the package
529
- * index — SDK consumers see only {@link AuthModule}.
530
- *
531
- * @internal
532
- */
533
- export interface InternalAuthModule extends AuthModule {
534
- /**
535
- * Whether an access token is currently set on the client.
536
- *
537
- * Reports only the presence of a token, never its validity — an expired or
538
- * revoked token still reads as `true`. Callers use this to skip requests that
539
- * could not succeed without a session, not to decide that one is valid.
540
- */
541
- hasToken(): boolean;
542
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.52-pr.305.d6c90ab",
3
+ "version": "0.8.52-pr.307.064de09",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",