@base44-preview/sdk 0.7.9-dev.d4c62b8 → 0.7.10-pr.39.3c96213

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
@@ -6,6 +6,7 @@ export type Base44Client = ReturnType<typeof createClient>;
6
6
  * Create a Base44 client instance
7
7
  * @param {Object} config - Client configuration
8
8
  * @param {string} [config.serverUrl='https://base44.app'] - API server URL
9
+ * @param {string} [config.appBaseUrl] - Application base URL
9
10
  * @param {string|number} config.appId - Application ID
10
11
  * @param {string} [config.token] - Authentication token
11
12
  * @param {string} [config.serviceToken] - Service role authentication token
@@ -14,6 +15,7 @@ export type Base44Client = ReturnType<typeof createClient>;
14
15
  */
15
16
  export declare function createClient(config: {
16
17
  serverUrl?: string;
18
+ appBaseUrl?: string;
17
19
  appId: string;
18
20
  token?: string;
19
21
  serviceToken?: string;
@@ -21,7 +23,6 @@ export declare function createClient(config: {
21
23
  functionsVersion?: string;
22
24
  headers?: Record<string, string>;
23
25
  options?: CreateClientOptions;
24
- onRedirectToLogin?: () => void;
25
26
  }): {
26
27
  /**
27
28
  * Set authentication token for all requests
package/dist/client.js CHANGED
@@ -11,6 +11,7 @@ import { RoomsSocket } from "./utils/socket-utils.js";
11
11
  * Create a Base44 client instance
12
12
  * @param {Object} config - Client configuration
13
13
  * @param {string} [config.serverUrl='https://base44.app'] - API server URL
14
+ * @param {string} [config.appBaseUrl] - Application base URL
14
15
  * @param {string|number} config.appId - Application ID
15
16
  * @param {string} [config.token] - Authentication token
16
17
  * @param {string} [config.serviceToken] - Service role authentication token
@@ -18,7 +19,7 @@ import { RoomsSocket } from "./utils/socket-utils.js";
18
19
  * @returns {Object} Base44 client instance
19
20
  */
20
21
  export function createClient(config) {
21
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, onRedirectToLogin, headers: optionalHeaders, } = config;
22
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
22
23
  const socketConfig = {
23
24
  serverUrl,
24
25
  mountPath: "/ws-user-apps/socket.io/",
@@ -43,46 +44,32 @@ export function createClient(config) {
43
44
  baseURL: `${serverUrl}/api`,
44
45
  headers,
45
46
  token,
46
- requiresAuth,
47
- appId,
48
- serverUrl,
49
47
  onError: options === null || options === void 0 ? void 0 : options.onError,
50
- onRedirectToLogin,
51
48
  });
52
49
  const functionsAxiosClient = createAxiosClient({
53
50
  baseURL: `${serverUrl}/api`,
54
51
  headers: functionHeaders,
55
52
  token,
56
- requiresAuth,
57
- appId,
58
- serverUrl,
59
53
  interceptResponses: false,
60
54
  onError: options === null || options === void 0 ? void 0 : options.onError,
61
- onRedirectToLogin,
62
55
  });
63
56
  const serviceRoleAxiosClient = createAxiosClient({
64
57
  baseURL: `${serverUrl}/api`,
65
58
  headers,
66
59
  token: serviceToken,
67
- serverUrl,
68
- appId,
69
60
  onError: options === null || options === void 0 ? void 0 : options.onError,
70
- onRedirectToLogin,
71
61
  });
72
62
  const serviceRoleFunctionsAxiosClient = createAxiosClient({
73
63
  baseURL: `${serverUrl}/api`,
74
64
  headers: functionHeaders,
75
65
  token: serviceToken,
76
- serverUrl,
77
- appId,
78
66
  interceptResponses: false,
79
- onRedirectToLogin,
80
67
  });
81
68
  const userModules = {
82
69
  entities: createEntitiesModule(axiosClient, appId),
83
70
  integrations: createIntegrationsModule(axiosClient, appId),
84
71
  auth: createAuthModule(axiosClient, functionsAxiosClient, appId, {
85
- onRedirectToLogin,
72
+ appBaseUrl,
86
73
  serverUrl,
87
74
  }),
88
75
  functions: createFunctionsModule(functionsAxiosClient, appId),
@@ -107,7 +94,7 @@ export function createClient(config) {
107
94
  socket,
108
95
  appId,
109
96
  serverUrl,
110
- token
97
+ token,
111
98
  }),
112
99
  cleanup: () => {
113
100
  socket.disconnect();
@@ -8,7 +8,7 @@ import { AxiosInstance } from "axios";
8
8
  */
9
9
  export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: {
10
10
  serverUrl: string;
11
- onRedirectToLogin?: () => void;
11
+ appBaseUrl?: string;
12
12
  }): {
13
13
  /**
14
14
  * Get current user information
@@ -28,20 +28,17 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
28
28
  * @throws {Error} When not in a browser environment
29
29
  */
30
30
  redirectToLogin(nextUrl) {
31
+ var _a;
31
32
  // This function only works in a browser environment
32
33
  if (typeof window === "undefined") {
33
34
  throw new Error("Login method can only be used in a browser environment");
34
35
  }
35
- if (options.onRedirectToLogin) {
36
- options.onRedirectToLogin();
37
- return;
38
- }
39
36
  // If nextUrl is not provided, use the current URL
40
37
  const redirectUrl = nextUrl
41
38
  ? new URL(nextUrl, window.location.origin).toString()
42
39
  : window.location.href;
43
40
  // Build the login URL
44
- const loginUrl = `${options.serverUrl}/login?from_url=${encodeURIComponent(redirectUrl)}&app_id=${appId}`;
41
+ const loginUrl = `${(_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : ""}/login?from_url=${encodeURIComponent(redirectUrl)}`;
45
42
  // Redirect to the login page
46
43
  window.location.href = loginUrl;
47
44
  },
@@ -23,14 +23,10 @@ export declare class Base44Error extends Error {
23
23
  * @param {string} options.serverUrl - Server URL (needed for login redirect)
24
24
  * @returns {import('axios').AxiosInstance} Configured axios instance
25
25
  */
26
- export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, onError, onRedirectToLogin, }: {
26
+ export declare function createAxiosClient({ baseURL, headers, token, interceptResponses, onError, }: {
27
27
  baseURL: string;
28
28
  headers?: Record<string, string>;
29
29
  token?: string;
30
- requiresAuth?: boolean;
31
- appId: string;
32
- serverUrl: string;
33
30
  interceptResponses?: boolean;
34
31
  onError?: (error: Error) => void;
35
- onRedirectToLogin?: () => void;
36
32
  }): import("axios").AxiosInstance;
@@ -42,19 +42,6 @@ function safeErrorLog(prefix, error) {
42
42
  console.error(`${prefix} ${error instanceof Error ? error.message : String(error)}`);
43
43
  }
44
44
  }
45
- /**
46
- * Redirects to the login page with the current URL as return destination
47
- * @param {string} serverUrl - Base server URL
48
- * @param {string|number} appId - Application ID
49
- */
50
- function redirectToLogin(serverUrl, appId) {
51
- if (typeof window === "undefined") {
52
- return; // Can't redirect in non-browser environment
53
- }
54
- const currentUrl = encodeURIComponent(window.location.href);
55
- const loginUrl = `${serverUrl}/login?from_url=${currentUrl}&app_id=${appId}`;
56
- window.location.href = loginUrl;
57
- }
58
45
  /**
59
46
  * Creates an axios client with default configuration and interceptors
60
47
  * @param {Object} options - Client configuration options
@@ -66,7 +53,7 @@ function redirectToLogin(serverUrl, appId) {
66
53
  * @param {string} options.serverUrl - Server URL (needed for login redirect)
67
54
  * @returns {import('axios').AxiosInstance} Configured axios instance
68
55
  */
69
- export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, onError, onRedirectToLogin, }) {
56
+ export function createAxiosClient({ baseURL, headers = {}, token, interceptResponses = true, onError, }) {
70
57
  const client = axios.create({
71
58
  baseURL,
72
59
  headers: {
@@ -128,7 +115,7 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
128
115
  }
129
116
  return response.data;
130
117
  }, (error) => {
131
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
118
+ var _a, _b, _c, _d, _e, _f, _g, _h;
132
119
  const message = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
133
120
  ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.detail) ||
134
121
  error.message;
@@ -137,19 +124,6 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
137
124
  if (process.env.NODE_ENV !== "production") {
138
125
  safeErrorLog("[Base44 SDK Error]", base44Error);
139
126
  }
140
- // Check for 403 Forbidden (authentication required) and redirect to login if requiresAuth is true
141
- console.log(requiresAuth, (_j = error.response) === null || _j === void 0 ? void 0 : _j.status, typeof window !== "undefined");
142
- if (requiresAuth &&
143
- ((_k = error.response) === null || _k === void 0 ? void 0 : _k.status) === 403 &&
144
- typeof window !== "undefined") {
145
- console.log("Authentication required. Redirecting to login...");
146
- // Use a slight delay to allow the error to propagate first
147
- setTimeout(() => {
148
- onRedirectToLogin
149
- ? onRedirectToLogin()
150
- : redirectToLogin(serverUrl, appId);
151
- }, 100);
152
- }
153
127
  onError === null || onError === void 0 ? void 0 : onError(base44Error);
154
128
  return Promise.reject(base44Error);
155
129
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.7.9-dev.d4c62b8",
3
+ "version": "0.7.10-pr.39.3c96213",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",