@base44-preview/sdk 0.7.0-pr.28.d052301 → 0.7.0-pr.29.2474cce

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/client.d.ts CHANGED
@@ -14,6 +14,7 @@ export declare function createClient(config: {
14
14
  token?: string;
15
15
  serviceToken?: string;
16
16
  requiresAuth?: boolean;
17
+ functionsVersion?: string;
17
18
  }): {
18
19
  /**
19
20
  * Set authentication token for all requests
@@ -47,10 +48,7 @@ export declare function createClient(config: {
47
48
  redirectToLogin(nextUrl: string): void;
48
49
  logout(redirectUrl?: string): void;
49
50
  setToken(token: string, saveToStorage?: boolean): void;
50
- loginViaEmailPassword(email: string, password: string, options?: {
51
- turnstileToken?: string;
52
- fromUrl?: string;
53
- }): Promise<{
51
+ loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<{
54
52
  access_token: string;
55
53
  user: any;
56
54
  }>;
@@ -93,10 +91,7 @@ export declare function createClientFromRequest(request: Request): {
93
91
  redirectToLogin(nextUrl: string): void;
94
92
  logout(redirectUrl?: string): void;
95
93
  setToken(token: string, saveToStorage?: boolean): void;
96
- loginViaEmailPassword(email: string, password: string, options?: {
97
- turnstileToken?: string;
98
- fromUrl?: string;
99
- }): Promise<{
94
+ loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<{
100
95
  access_token: string;
101
96
  user: any;
102
97
  }>;
package/dist/client.js CHANGED
@@ -16,12 +16,17 @@ import { createFunctionsModule } from "./modules/functions.js";
16
16
  * @returns {Object} Base44 client instance
17
17
  */
18
18
  export function createClient(config) {
19
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, } = config;
19
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, functionsVersion } = config;
20
+ const headers = {
21
+ "X-App-Id": String(appId),
22
+ };
23
+ const functionHeaders = functionsVersion ? {
24
+ ...headers,
25
+ "Base44-Functions-Version": functionsVersion
26
+ } : headers;
20
27
  const axiosClient = createAxiosClient({
21
28
  baseURL: `${serverUrl}/api`,
22
- headers: {
23
- "X-App-Id": String(appId),
24
- },
29
+ headers,
25
30
  token,
26
31
  requiresAuth,
27
32
  appId,
@@ -29,9 +34,7 @@ export function createClient(config) {
29
34
  });
30
35
  const functionsAxiosClient = createAxiosClient({
31
36
  baseURL: `${serverUrl}/api`,
32
- headers: {
33
- "X-App-Id": String(appId),
34
- },
37
+ headers: functionHeaders,
35
38
  token,
36
39
  requiresAuth,
37
40
  appId,
@@ -40,18 +43,14 @@ export function createClient(config) {
40
43
  });
41
44
  const serviceRoleAxiosClient = createAxiosClient({
42
45
  baseURL: `${serverUrl}/api`,
43
- headers: {
44
- "X-App-Id": String(appId),
45
- },
46
+ headers,
46
47
  token: serviceToken,
47
48
  serverUrl,
48
49
  appId,
49
50
  });
50
51
  const serviceRoleFunctionsAxiosClient = createAxiosClient({
51
52
  baseURL: `${serverUrl}/api`,
52
- headers: {
53
- "X-App-Id": String(appId),
54
- },
53
+ headers: functionHeaders,
55
54
  token: serviceToken,
56
55
  serverUrl,
57
56
  appId,
@@ -132,6 +131,7 @@ export function createClientFromRequest(request) {
132
131
  const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
133
132
  const appId = request.headers.get("Base44-App-Id");
134
133
  const serverUrlHeader = request.headers.get("Base44-Api-Url");
134
+ const functionsVersion = request.headers.get("Base44-Functions-Version");
135
135
  if (!appId) {
136
136
  throw new Error("Base44-App-Id header is required, but is was not found on the request");
137
137
  }
@@ -155,5 +155,6 @@ export function createClientFromRequest(request) {
155
155
  appId,
156
156
  token: userToken,
157
157
  serviceToken: serviceRoleToken,
158
+ functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined
158
159
  });
159
160
  }
@@ -41,15 +41,10 @@ export declare function createAuthModule(axios: AxiosInstance, functionsAxiosCli
41
41
  * Login via username and password
42
42
  * @param email - User email
43
43
  * @param password - User password
44
- * @param options - Optional login options
45
- * @param options.turnstileToken - Optional Turnstile captcha token
46
- * @param options.fromUrl - Optional URL to redirect to after login
44
+ * @param turnstileToken - Optional Turnstile captcha token
47
45
  * @returns Login response with access_token and user
48
46
  */
49
- loginViaEmailPassword(email: string, password: string, options?: {
50
- turnstileToken?: string;
51
- fromUrl?: string;
52
- }): Promise<{
47
+ loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<{
53
48
  access_token: string;
54
49
  user: any;
55
50
  }>;
@@ -95,19 +95,16 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
95
95
  * Login via username and password
96
96
  * @param email - User email
97
97
  * @param password - User password
98
- * @param options - Optional login options
99
- * @param options.turnstileToken - Optional Turnstile captcha token
100
- * @param options.fromUrl - Optional URL to redirect to after login
98
+ * @param turnstileToken - Optional Turnstile captcha token
101
99
  * @returns Login response with access_token and user
102
100
  */
103
- async loginViaEmailPassword(email, password, options) {
101
+ async loginViaEmailPassword(email, password, turnstileToken) {
104
102
  var _a;
105
103
  try {
106
104
  const response = await axios.post(`/apps/${appId}/auth/login`, {
107
105
  email,
108
106
  password,
109
- ...((options === null || options === void 0 ? void 0 : options.turnstileToken) && { turnstile_token: options.turnstileToken }),
110
- ...((options === null || options === void 0 ? void 0 : options.fromUrl) && { from_url: options.fromUrl }),
107
+ ...(turnstileToken && { turnstile_token: turnstileToken }),
111
108
  });
112
109
  const { access_token, user } = response;
113
110
  if (access_token) {
@@ -1,3 +1,4 @@
1
+ import { extractSnapshotIdFromHost } from "../utils/extract-snapshot-id-from-host.js";
1
2
  /**
2
3
  * Creates the functions module for the Base44 SDK
3
4
  * @param {import('axios').AxiosInstance} axios - Axios instance
@@ -35,7 +36,14 @@ export function createFunctionsModule(axios, appId) {
35
36
  formData = data;
36
37
  contentType = "application/json";
37
38
  }
38
- return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, { headers: { "Content-Type": contentType } });
39
+ // Extract functions version from the current URL host
40
+ const functionsVersion = extractSnapshotIdFromHost();
41
+ return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, {
42
+ headers: {
43
+ "Content-Type": contentType,
44
+ "X-Functions-Version": functionsVersion
45
+ }
46
+ });
39
47
  },
40
48
  };
41
49
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Extracts the snapshot ID or environment type from the current hostname
3
+ * Used to determine which backend function deployment to call
4
+ *
5
+ * @returns {string} The snapshot ID for checkpoints, 'preview' for preview URLs, or 'prod' for production
6
+ */
7
+ export declare function extractSnapshotIdFromHost(): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Extracts the snapshot ID or environment type from the current hostname
3
+ * Used to determine which backend function deployment to call
4
+ *
5
+ * @returns {string} The snapshot ID for checkpoints, 'preview' for preview URLs, or 'prod' for production
6
+ */
7
+ export function extractSnapshotIdFromHost() {
8
+ if (typeof window === "undefined") {
9
+ return "prod";
10
+ }
11
+ const hostname = window.location.hostname;
12
+ // Check if it's a checkpoint URL
13
+ if (hostname.startsWith("checkpoint--")) {
14
+ // Format: checkpoint--{app_id}--{snapshot_id}.domain
15
+ const parts = hostname.split("--");
16
+ if (parts.length >= 3) {
17
+ // Extract snapshot_id (last part before the domain)
18
+ const snapshotPart = parts[2];
19
+ // Remove domain extension if present
20
+ const snapshotId = snapshotPart.split(".")[0];
21
+ return snapshotId;
22
+ }
23
+ }
24
+ // Check if it's a preview URL
25
+ if (hostname.startsWith("preview--")) {
26
+ return "preview";
27
+ }
28
+ // Production URLs - return "prod"
29
+ return "prod";
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.7.0-pr.28.d052301",
3
+ "version": "0.7.0-pr.29.2474cce",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",