@depup/base44__sdk 0.8.22-depup.0

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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/changes.json +14 -0
  4. package/dist/client.d.ts +96 -0
  5. package/dist/client.js +375 -0
  6. package/dist/client.types.d.ts +144 -0
  7. package/dist/client.types.js +1 -0
  8. package/dist/index.d.ts +16 -0
  9. package/dist/index.js +5 -0
  10. package/dist/modules/agents.d.ts +2 -0
  11. package/dist/modules/agents.js +77 -0
  12. package/dist/modules/agents.types.d.ts +377 -0
  13. package/dist/modules/agents.types.js +1 -0
  14. package/dist/modules/analytics.d.ts +20 -0
  15. package/dist/modules/analytics.js +277 -0
  16. package/dist/modules/analytics.types.d.ts +122 -0
  17. package/dist/modules/analytics.types.js +1 -0
  18. package/dist/modules/app-logs.d.ts +11 -0
  19. package/dist/modules/app-logs.js +27 -0
  20. package/dist/modules/app-logs.types.d.ts +46 -0
  21. package/dist/modules/app-logs.types.js +1 -0
  22. package/dist/modules/app.types.d.ts +142 -0
  23. package/dist/modules/app.types.js +1 -0
  24. package/dist/modules/auth.d.ts +13 -0
  25. package/dist/modules/auth.js +180 -0
  26. package/dist/modules/auth.types.d.ts +481 -0
  27. package/dist/modules/auth.types.js +1 -0
  28. package/dist/modules/connectors.d.ts +20 -0
  29. package/dist/modules/connectors.js +71 -0
  30. package/dist/modules/connectors.types.d.ts +296 -0
  31. package/dist/modules/connectors.types.js +1 -0
  32. package/dist/modules/custom-integrations.d.ts +11 -0
  33. package/dist/modules/custom-integrations.js +32 -0
  34. package/dist/modules/custom-integrations.types.d.ts +89 -0
  35. package/dist/modules/custom-integrations.types.js +1 -0
  36. package/dist/modules/entities.d.ts +20 -0
  37. package/dist/modules/entities.js +149 -0
  38. package/dist/modules/entities.types.d.ts +552 -0
  39. package/dist/modules/entities.types.js +1 -0
  40. package/dist/modules/functions.d.ts +12 -0
  41. package/dist/modules/functions.js +79 -0
  42. package/dist/modules/functions.types.d.ts +103 -0
  43. package/dist/modules/functions.types.js +1 -0
  44. package/dist/modules/integrations.d.ts +11 -0
  45. package/dist/modules/integrations.js +77 -0
  46. package/dist/modules/integrations.types.d.ts +413 -0
  47. package/dist/modules/integrations.types.js +1 -0
  48. package/dist/modules/sso.d.ts +12 -0
  49. package/dist/modules/sso.js +23 -0
  50. package/dist/modules/sso.types.d.ts +44 -0
  51. package/dist/modules/sso.types.js +1 -0
  52. package/dist/modules/types.d.ts +4 -0
  53. package/dist/modules/types.js +4 -0
  54. package/dist/modules/users.d.ts +16 -0
  55. package/dist/modules/users.js +23 -0
  56. package/dist/types.d.ts +72 -0
  57. package/dist/types.js +1 -0
  58. package/dist/utils/auth-utils.d.ts +117 -0
  59. package/dist/utils/auth-utils.js +189 -0
  60. package/dist/utils/auth-utils.types.d.ts +146 -0
  61. package/dist/utils/auth-utils.types.js +1 -0
  62. package/dist/utils/axios-client.d.ts +100 -0
  63. package/dist/utils/axios-client.js +193 -0
  64. package/dist/utils/axios-client.types.d.ts +28 -0
  65. package/dist/utils/axios-client.types.js +1 -0
  66. package/dist/utils/common.d.ts +3 -0
  67. package/dist/utils/common.js +6 -0
  68. package/dist/utils/sharedInstance.d.ts +1 -0
  69. package/dist/utils/sharedInstance.js +15 -0
  70. package/dist/utils/socket-utils.d.ts +47 -0
  71. package/dist/utils/socket-utils.js +115 -0
  72. package/package.json +87 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 base44
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @depup/base44__sdk
2
+
3
+ > Dependency-bumped version of [@base44/sdk](https://www.npmjs.com/package/@base44/sdk)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/base44__sdk
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [@base44/sdk](https://www.npmjs.com/package/@base44/sdk) @ 0.8.22 |
17
+ | Processed | 2026-03-17 |
18
+ | Smoke test | passed |
19
+ | Deps updated | 2 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | axios | ^1.6.2 | ^1.13.6 |
26
+ | socket.io-client | ^4.7.5 | ^4.8.3 |
27
+
28
+ ---
29
+
30
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@base44/sdk
31
+
32
+ License inherited from the original package.
package/changes.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "bumped": {
3
+ "axios": {
4
+ "from": "^1.6.2",
5
+ "to": "^1.13.6"
6
+ },
7
+ "socket.io-client": {
8
+ "from": "^4.7.5",
9
+ "to": "^4.8.3"
10
+ }
11
+ },
12
+ "timestamp": "2026-03-17T16:30:57.506Z",
13
+ "totalUpdated": 2
14
+ }
@@ -0,0 +1,96 @@
1
+ import type { Base44Client, CreateClientConfig, CreateClientOptions } from "./client.types.js";
2
+ export type { Base44Client, CreateClientConfig, CreateClientOptions };
3
+ /**
4
+ * Creates a Base44 client.
5
+ *
6
+ * This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
7
+ *
8
+ * How you get a client depends on your context:
9
+ * - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
10
+ * - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
11
+ *
12
+ * The client supports three authentication modes:
13
+ * - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
14
+ * - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
15
+ * - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
16
+ *
17
+ * For example, when using the {@linkcode EntitiesModule | entities} module:
18
+ * - **Anonymous**: Can only read public data.
19
+ * - **User authentication**: Can access the current user's data.
20
+ * - **Service role authentication**: Can access all data that admins can access.
21
+ *
22
+ * Most modules are available in all three modes, but with different permission levels. However, some modules are only available in specific authentication modes.
23
+ *
24
+ * @param config - Configuration object for the client.
25
+ * @returns A configured Base44 client instance with access to all SDK modules.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Create a client for your app
30
+ * import { createClient } from '@base44/sdk';
31
+ *
32
+ * const base44 = createClient({
33
+ * appId: 'my-app-id'
34
+ * });
35
+ *
36
+ * // Use the client to access your data
37
+ * const products = await base44.entities.Products.list();
38
+ * ```
39
+ */
40
+ export declare function createClient(config: CreateClientConfig): Base44Client;
41
+ /**
42
+ * Creates a Base44 client from an HTTP request.
43
+ *
44
+ * This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
45
+ *
46
+ * When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
47
+ *
48
+ * To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
49
+ *
50
+ * @param request - The incoming HTTP request object containing Base44 authentication headers.
51
+ * @returns A configured Base44 client instance with authentication from the incoming request.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // User authentication in backend function
56
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
57
+ *
58
+ * Deno.serve(async (req) => {
59
+ * try {
60
+ * const base44 = createClientFromRequest(req);
61
+ * const user = await base44.auth.me();
62
+ *
63
+ * if (!user) {
64
+ * return Response.json({ error: 'Unauthorized' }, { status: 401 });
65
+ * }
66
+ *
67
+ * // Access user's data
68
+ * const userOrders = await base44.entities.Orders.filter({ userId: user.id });
69
+ * return Response.json({ orders: userOrders });
70
+ * } catch (error) {
71
+ * return Response.json({ error: error.message }, { status: 500 });
72
+ * }
73
+ * });
74
+ * ```
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // Service role authentication in backend function
79
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
80
+ *
81
+ * Deno.serve(async (req) => {
82
+ * try {
83
+ * const base44 = createClientFromRequest(req);
84
+ *
85
+ * // Access admin data with service role permissions
86
+ * const recentOrders = await base44.asServiceRole.entities.Orders.list('-created_at', 50);
87
+ *
88
+ * return Response.json({ orders: recentOrders });
89
+ * } catch (error) {
90
+ * return Response.json({ error: error.message }, { status: 500 });
91
+ * }
92
+ * });
93
+ * ```
94
+ *
95
+ */
96
+ export declare function createClientFromRequest(request: Request): Base44Client;
package/dist/client.js ADDED
@@ -0,0 +1,375 @@
1
+ import { createAxiosClient } from "./utils/axios-client.js";
2
+ import { createEntitiesModule } from "./modules/entities.js";
3
+ import { createIntegrationsModule } from "./modules/integrations.js";
4
+ import { createAuthModule } from "./modules/auth.js";
5
+ import { createSsoModule } from "./modules/sso.js";
6
+ import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
7
+ import { getAccessToken } from "./utils/auth-utils.js";
8
+ import { createFunctionsModule } from "./modules/functions.js";
9
+ import { createAgentsModule } from "./modules/agents.js";
10
+ import { createAppLogsModule } from "./modules/app-logs.js";
11
+ import { createUsersModule } from "./modules/users.js";
12
+ import { RoomsSocket } from "./utils/socket-utils.js";
13
+ import { createAnalyticsModule } from "./modules/analytics.js";
14
+ /**
15
+ * Creates a Base44 client.
16
+ *
17
+ * This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
18
+ *
19
+ * How you get a client depends on your context:
20
+ * - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
21
+ * - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
22
+ *
23
+ * The client supports three authentication modes:
24
+ * - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
25
+ * - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
26
+ * - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
27
+ *
28
+ * For example, when using the {@linkcode EntitiesModule | entities} module:
29
+ * - **Anonymous**: Can only read public data.
30
+ * - **User authentication**: Can access the current user's data.
31
+ * - **Service role authentication**: Can access all data that admins can access.
32
+ *
33
+ * Most modules are available in all three modes, but with different permission levels. However, some modules are only available in specific authentication modes.
34
+ *
35
+ * @param config - Configuration object for the client.
36
+ * @returns A configured Base44 client instance with access to all SDK modules.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Create a client for your app
41
+ * import { createClient } from '@base44/sdk';
42
+ *
43
+ * const base44 = createClient({
44
+ * appId: 'my-app-id'
45
+ * });
46
+ *
47
+ * // Use the client to access your data
48
+ * const products = await base44.entities.Products.list();
49
+ * ```
50
+ */
51
+ export function createClient(config) {
52
+ var _a, _b;
53
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
54
+ // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
55
+ const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
56
+ const socketConfig = {
57
+ serverUrl,
58
+ mountPath: "/ws-user-apps/socket.io/",
59
+ transports: ["websocket"],
60
+ appId,
61
+ token,
62
+ };
63
+ let socket = null;
64
+ const getSocket = () => {
65
+ if (!socket) {
66
+ socket = RoomsSocket({
67
+ config: socketConfig,
68
+ });
69
+ }
70
+ return socket;
71
+ };
72
+ const headers = {
73
+ ...optionalHeaders,
74
+ "X-App-Id": String(appId),
75
+ };
76
+ const functionHeaders = functionsVersion
77
+ ? {
78
+ ...headers,
79
+ "Base44-Functions-Version": functionsVersion,
80
+ }
81
+ : headers;
82
+ const axiosClient = createAxiosClient({
83
+ baseURL: `${serverUrl}/api`,
84
+ headers,
85
+ token,
86
+ onError: options === null || options === void 0 ? void 0 : options.onError,
87
+ });
88
+ const functionsAxiosClient = createAxiosClient({
89
+ baseURL: `${serverUrl}/api`,
90
+ headers: functionHeaders,
91
+ token,
92
+ interceptResponses: false,
93
+ onError: options === null || options === void 0 ? void 0 : options.onError,
94
+ });
95
+ const serviceRoleAxiosClient = createAxiosClient({
96
+ baseURL: `${serverUrl}/api`,
97
+ headers,
98
+ token: serviceToken,
99
+ onError: options === null || options === void 0 ? void 0 : options.onError,
100
+ });
101
+ const serviceRoleFunctionsAxiosClient = createAxiosClient({
102
+ baseURL: `${serverUrl}/api`,
103
+ headers: functionHeaders,
104
+ token: serviceToken,
105
+ interceptResponses: false,
106
+ });
107
+ const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
108
+ appBaseUrl: normalizedAppBaseUrl,
109
+ serverUrl,
110
+ });
111
+ const userModules = {
112
+ entities: createEntitiesModule({
113
+ axios: axiosClient,
114
+ appId,
115
+ getSocket,
116
+ }),
117
+ integrations: createIntegrationsModule(axiosClient, appId),
118
+ connectors: createUserConnectorsModule(axiosClient, appId),
119
+ auth: userAuthModule,
120
+ functions: createFunctionsModule(functionsAxiosClient, appId, {
121
+ getAuthHeaders: () => {
122
+ const headers = {};
123
+ // Get current token from storage or initial config
124
+ const currentToken = token || getAccessToken();
125
+ if (currentToken) {
126
+ headers["Authorization"] = `Bearer ${currentToken}`;
127
+ }
128
+ return headers;
129
+ },
130
+ baseURL: (_a = functionsAxiosClient.defaults) === null || _a === void 0 ? void 0 : _a.baseURL,
131
+ }),
132
+ agents: createAgentsModule({
133
+ axios: axiosClient,
134
+ getSocket,
135
+ appId,
136
+ serverUrl,
137
+ token,
138
+ }),
139
+ appLogs: createAppLogsModule(axiosClient, appId),
140
+ users: createUsersModule(axiosClient, appId),
141
+ analytics: createAnalyticsModule({
142
+ axiosClient,
143
+ serverUrl,
144
+ appId,
145
+ userAuthModule,
146
+ }),
147
+ cleanup: () => {
148
+ userModules.analytics.cleanup();
149
+ if (socket) {
150
+ socket.disconnect();
151
+ }
152
+ },
153
+ };
154
+ const serviceRoleModules = {
155
+ entities: createEntitiesModule({
156
+ axios: serviceRoleAxiosClient,
157
+ appId,
158
+ getSocket,
159
+ }),
160
+ integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
161
+ sso: createSsoModule(serviceRoleAxiosClient, appId, token),
162
+ connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
163
+ functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
164
+ getAuthHeaders: () => {
165
+ const headers = {};
166
+ // Use service token for authorization
167
+ if (serviceToken) {
168
+ headers["Authorization"] = `Bearer ${serviceToken}`;
169
+ }
170
+ return headers;
171
+ },
172
+ baseURL: (_b = serviceRoleFunctionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
173
+ }),
174
+ agents: createAgentsModule({
175
+ axios: serviceRoleAxiosClient,
176
+ getSocket,
177
+ appId,
178
+ serverUrl,
179
+ token,
180
+ }),
181
+ appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
182
+ cleanup: () => {
183
+ if (socket) {
184
+ socket.disconnect();
185
+ }
186
+ },
187
+ };
188
+ // Always try to get token from localStorage or URL parameters
189
+ if (typeof window !== "undefined") {
190
+ // Get token from URL or localStorage
191
+ const accessToken = token || getAccessToken();
192
+ if (accessToken) {
193
+ userModules.auth.setToken(accessToken);
194
+ }
195
+ }
196
+ // If authentication is required, verify token and redirect to login if needed
197
+ if (requiresAuth && typeof window !== "undefined") {
198
+ // We perform this check asynchronously to not block client creation
199
+ setTimeout(async () => {
200
+ try {
201
+ const isAuthenticated = await userModules.auth.isAuthenticated();
202
+ if (!isAuthenticated) {
203
+ userModules.auth.redirectToLogin(window.location.href);
204
+ }
205
+ }
206
+ catch (error) {
207
+ console.error("Authentication check failed:", error);
208
+ userModules.auth.redirectToLogin(window.location.href);
209
+ }
210
+ }, 0);
211
+ }
212
+ // Assemble and return the client
213
+ const client = {
214
+ ...userModules,
215
+ /**
216
+ * Sets a new authentication token for all subsequent requests.
217
+ *
218
+ * @param newToken - The new authentication token
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * // Update token after login
223
+ * const { access_token } = await base44.auth.loginViaEmailPassword(
224
+ * 'user@example.com',
225
+ * 'password'
226
+ * );
227
+ * base44.setToken(access_token);
228
+ * ```
229
+ */
230
+ setToken(newToken) {
231
+ userModules.auth.setToken(newToken);
232
+ if (socket) {
233
+ socket.updateConfig({
234
+ token: newToken,
235
+ });
236
+ }
237
+ socketConfig.token = newToken;
238
+ },
239
+ /**
240
+ * Gets the current client configuration.
241
+ *
242
+ * @internal
243
+ */
244
+ getConfig() {
245
+ return {
246
+ serverUrl,
247
+ appId,
248
+ requiresAuth,
249
+ };
250
+ },
251
+ /**
252
+ * Provides access to service role modules.
253
+ *
254
+ * Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication has access to the data and operations available to the app's admin.
255
+ *
256
+ * @throws {Error} When accessed without providing a serviceToken during client creation.
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const base44 = createClient({
261
+ * appId: 'my-app-id',
262
+ * serviceToken: 'service-role-token'
263
+ * });
264
+ *
265
+ * // Also access a module with elevated permissions
266
+ * const allUsers = await base44.asServiceRole.entities.User.list();
267
+ * ```
268
+ */
269
+ get asServiceRole() {
270
+ if (!serviceToken) {
271
+ throw new Error("Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.");
272
+ }
273
+ return serviceRoleModules;
274
+ },
275
+ };
276
+ return client;
277
+ }
278
+ /**
279
+ * Creates a Base44 client from an HTTP request.
280
+ *
281
+ * This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
282
+ *
283
+ * When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
284
+ *
285
+ * To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
286
+ *
287
+ * @param request - The incoming HTTP request object containing Base44 authentication headers.
288
+ * @returns A configured Base44 client instance with authentication from the incoming request.
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * // User authentication in backend function
293
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
294
+ *
295
+ * Deno.serve(async (req) => {
296
+ * try {
297
+ * const base44 = createClientFromRequest(req);
298
+ * const user = await base44.auth.me();
299
+ *
300
+ * if (!user) {
301
+ * return Response.json({ error: 'Unauthorized' }, { status: 401 });
302
+ * }
303
+ *
304
+ * // Access user's data
305
+ * const userOrders = await base44.entities.Orders.filter({ userId: user.id });
306
+ * return Response.json({ orders: userOrders });
307
+ * } catch (error) {
308
+ * return Response.json({ error: error.message }, { status: 500 });
309
+ * }
310
+ * });
311
+ * ```
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * // Service role authentication in backend function
316
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
317
+ *
318
+ * Deno.serve(async (req) => {
319
+ * try {
320
+ * const base44 = createClientFromRequest(req);
321
+ *
322
+ * // Access admin data with service role permissions
323
+ * const recentOrders = await base44.asServiceRole.entities.Orders.list('-created_at', 50);
324
+ *
325
+ * return Response.json({ orders: recentOrders });
326
+ * } catch (error) {
327
+ * return Response.json({ error: error.message }, { status: 500 });
328
+ * }
329
+ * });
330
+ * ```
331
+ *
332
+ */
333
+ export function createClientFromRequest(request) {
334
+ const authHeader = request.headers.get("Authorization");
335
+ const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
336
+ const appId = request.headers.get("Base44-App-Id");
337
+ const serverUrlHeader = request.headers.get("Base44-Api-Url");
338
+ const functionsVersion = request.headers.get("Base44-Functions-Version");
339
+ const stateHeader = request.headers.get("Base44-State");
340
+ if (!appId) {
341
+ throw new Error("Base44-App-Id header is required, but is was not found on the request");
342
+ }
343
+ // Validate authorization header formats
344
+ let serviceRoleToken;
345
+ let userToken;
346
+ if (serviceRoleAuthHeader !== null) {
347
+ if (serviceRoleAuthHeader === "" ||
348
+ !serviceRoleAuthHeader.startsWith("Bearer ") ||
349
+ serviceRoleAuthHeader.split(" ").length !== 2) {
350
+ throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
351
+ }
352
+ serviceRoleToken = serviceRoleAuthHeader.split(" ")[1];
353
+ }
354
+ if (authHeader !== null) {
355
+ if (authHeader === "" ||
356
+ !authHeader.startsWith("Bearer ") ||
357
+ authHeader.split(" ").length !== 2) {
358
+ throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
359
+ }
360
+ userToken = authHeader.split(" ")[1];
361
+ }
362
+ // Prepare additional headers to propagate
363
+ const additionalHeaders = {};
364
+ if (stateHeader) {
365
+ additionalHeaders["Base44-State"] = stateHeader;
366
+ }
367
+ return createClient({
368
+ serverUrl: serverUrlHeader || "https://base44.app",
369
+ appId,
370
+ token: userToken,
371
+ serviceToken: serviceRoleToken,
372
+ functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
373
+ headers: additionalHeaders,
374
+ });
375
+ }
@@ -0,0 +1,144 @@
1
+ import type { EntitiesModule } from "./modules/entities.types.js";
2
+ import type { IntegrationsModule } from "./modules/integrations.types.js";
3
+ import type { AuthModule } from "./modules/auth.types.js";
4
+ import type { SsoModule } from "./modules/sso.types.js";
5
+ import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
6
+ import type { FunctionsModule } from "./modules/functions.types.js";
7
+ import type { AgentsModule } from "./modules/agents.types.js";
8
+ import type { AppLogsModule } from "./modules/app-logs.types.js";
9
+ import type { AnalyticsModule } from "./modules/analytics.types.js";
10
+ /**
11
+ * Options for creating a Base44 client.
12
+ */
13
+ export interface CreateClientOptions {
14
+ /**
15
+ * Optional error handler that will be called whenever an API error occurs.
16
+ */
17
+ onError?: (error: Error) => void;
18
+ }
19
+ /**
20
+ * Configuration for creating a Base44 client.
21
+ */
22
+ export interface CreateClientConfig {
23
+ /**
24
+ * The Base44 server URL.
25
+ *
26
+ * You don't need to set this for production use. The SDK defaults to `https://base44.app`.
27
+ *
28
+ * Set this when using a local development server to point SDK requests at your local machine instead of the hosted backend.
29
+ *
30
+ * @defaultValue `"https://base44.app"`
31
+ */
32
+ serverUrl?: string;
33
+ /**
34
+ * The base URL of the app, which is used for login redirects.
35
+ * @internal
36
+ */
37
+ appBaseUrl?: string;
38
+ /**
39
+ * The Base44 app ID.
40
+ *
41
+ * You can find the `appId` in the browser URL when you're in the app editor.
42
+ * It's the string between `/apps/` and `/editor/`.
43
+ */
44
+ appId: string;
45
+ /**
46
+ * User authentication token. Used to authenticate as a specific user.
47
+ *
48
+ * Inside Base44 apps, the token is managed automatically. For external apps, use auth methods like {@linkcode AuthModule.loginViaEmailPassword | loginViaEmailPassword()} which set the token automatically.
49
+ */
50
+ token?: string;
51
+ /**
52
+ * Service role authentication token. Provides elevated permissions to access data available to the app's admin. Only available in Base44-hosted backend functions. Automatically added to client's created using {@linkcode createClientFromRequest | createClientFromRequest()}.
53
+ * @internal
54
+ */
55
+ serviceToken?: string;
56
+ /**
57
+ * Whether authentication is required. If true, redirects to login if not authenticated.
58
+ * @internal
59
+ */
60
+ requiresAuth?: boolean;
61
+ /**
62
+ * Version string for functions API.
63
+ * @internal
64
+ */
65
+ functionsVersion?: string;
66
+ /**
67
+ * Additional headers to include in API requests.
68
+ * @internal
69
+ */
70
+ headers?: Record<string, string>;
71
+ /**
72
+ * Additional client options.
73
+ */
74
+ options?: CreateClientOptions;
75
+ }
76
+ /**
77
+ * The Base44 client instance.
78
+ *
79
+ * Provides access to all SDK modules for interacting with the app.
80
+ */
81
+ export interface Base44Client {
82
+ /** {@link AgentsModule | Agents module} for managing AI agent conversations. */
83
+ agents: AgentsModule;
84
+ /** {@link AnalyticsModule | Analytics module} for tracking custom events in your app. */
85
+ analytics: AnalyticsModule;
86
+ /** {@link AppLogsModule | App logs module} for tracking app usage. */
87
+ appLogs: AppLogsModule;
88
+ /** {@link AuthModule | Auth module} for user authentication and management. */
89
+ auth: AuthModule;
90
+ /** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
91
+ connectors: UserConnectorsModule;
92
+ /** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
93
+ entities: EntitiesModule;
94
+ /** {@link FunctionsModule | Functions module} for invoking custom backend functions. */
95
+ functions: FunctionsModule;
96
+ /** {@link IntegrationsModule | Integrations module} for calling pre-built integration endpoints. */
97
+ integrations: IntegrationsModule;
98
+ /** Cleanup function to disconnect WebSocket connections. Call when you're done with the client. */
99
+ cleanup: () => void;
100
+ /**
101
+ * Sets a new authentication token for all subsequent requests.
102
+ *
103
+ * Updates the token for both HTTP requests and WebSocket connections.
104
+ *
105
+ * @param newToken - The new authentication token.
106
+ */
107
+ setToken(newToken: string): void;
108
+ /**
109
+ * Gets the current client configuration.
110
+ * @internal
111
+ */
112
+ getConfig(): {
113
+ serverUrl: string;
114
+ appId: string;
115
+ requiresAuth: boolean;
116
+ };
117
+ /**
118
+ * Provides access to supported modules with elevated permissions.
119
+ *
120
+ * Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication has access to the data and operations available to the app's admin.
121
+ *
122
+ * @throws {Error} When accessed without providing a serviceToken during client creation
123
+ */
124
+ readonly asServiceRole: {
125
+ /** {@link AgentsModule | Agents module} with elevated permissions. */
126
+ agents: AgentsModule;
127
+ /** {@link AppLogsModule | App logs module} with elevated permissions. */
128
+ appLogs: AppLogsModule;
129
+ /** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
130
+ connectors: ConnectorsModule;
131
+ /** {@link EntitiesModule | Entities module} with elevated permissions. */
132
+ entities: EntitiesModule;
133
+ /** {@link FunctionsModule | Functions module} with elevated permissions. */
134
+ functions: FunctionsModule;
135
+ /** {@link IntegrationsModule | Integrations module} with elevated permissions. */
136
+ integrations: IntegrationsModule;
137
+ /** {@link SsoModule | SSO module} for generating SSO tokens.
138
+ * @internal
139
+ */
140
+ sso: SsoModule;
141
+ /** Cleanup function to disconnect WebSocket connections. */
142
+ cleanup: () => void;
143
+ };
144
+ }
@@ -0,0 +1 @@
1
+ export {};