@base44-preview/sdk 0.8.10-pr.62.8f72a2c → 0.8.11-pr.58.0494dbf
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.js +10 -2
- package/dist/index.d.ts +1 -1
- package/dist/modules/custom-integrations.js +13 -41
- package/dist/modules/custom-integrations.types.d.ts +1 -16
- package/dist/modules/entities.d.ts +19 -0
- package/dist/modules/entities.js +54 -11
- package/dist/modules/entities.types.d.ts +45 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -104,7 +104,11 @@ export function createClient(config) {
|
|
|
104
104
|
serverUrl,
|
|
105
105
|
});
|
|
106
106
|
const userModules = {
|
|
107
|
-
entities: createEntitiesModule(
|
|
107
|
+
entities: createEntitiesModule({
|
|
108
|
+
axios: axiosClient,
|
|
109
|
+
appId,
|
|
110
|
+
getSocket,
|
|
111
|
+
}),
|
|
108
112
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
109
113
|
auth: userAuthModule,
|
|
110
114
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
@@ -131,7 +135,11 @@ export function createClient(config) {
|
|
|
131
135
|
},
|
|
132
136
|
};
|
|
133
137
|
const serviceRoleModules = {
|
|
134
|
-
entities: createEntitiesModule(
|
|
138
|
+
entities: createEntitiesModule({
|
|
139
|
+
axios: serviceRoleAxiosClient,
|
|
140
|
+
appId,
|
|
141
|
+
getSocket,
|
|
142
|
+
}),
|
|
135
143
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
136
144
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
137
145
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { EntitiesModule, EntityHandler, } from "./modules/entities.types.js";
|
|
7
|
+
export type { EntitiesModule, EntityHandler, RealtimeEventType, RealtimeEvent, RealtimeCallback, Subscription, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
9
|
export type { IntegrationsModule, IntegrationPackage, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule } from "./modules/functions.types.js";
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes parameters to snake_case for the API.
|
|
3
|
-
*
|
|
4
|
-
* Supports both camelCase (pathParams) and snake_case (path_params) input,
|
|
5
|
-
* always outputting snake_case for the backend.
|
|
6
|
-
*/
|
|
7
|
-
function normalizeParams(params) {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
if (!params) {
|
|
10
|
-
return {};
|
|
11
|
-
}
|
|
12
|
-
const normalized = {};
|
|
13
|
-
// Handle payload
|
|
14
|
-
if (params.payload !== undefined) {
|
|
15
|
-
normalized.payload = params.payload;
|
|
16
|
-
}
|
|
17
|
-
// Handle path_params (support both camelCase and snake_case)
|
|
18
|
-
const pathParams = (_a = params.pathParams) !== null && _a !== void 0 ? _a : params.path_params;
|
|
19
|
-
if (pathParams !== undefined) {
|
|
20
|
-
normalized.path_params = pathParams;
|
|
21
|
-
}
|
|
22
|
-
// Handle query_params (support both camelCase and snake_case)
|
|
23
|
-
const queryParams = (_b = params.queryParams) !== null && _b !== void 0 ? _b : params.query_params;
|
|
24
|
-
if (queryParams !== undefined) {
|
|
25
|
-
normalized.query_params = queryParams;
|
|
26
|
-
}
|
|
27
|
-
// Handle headers
|
|
28
|
-
if (params.headers !== undefined) {
|
|
29
|
-
normalized.headers = params.headers;
|
|
30
|
-
}
|
|
31
|
-
return normalized;
|
|
32
|
-
}
|
|
33
1
|
/**
|
|
34
2
|
* Creates the custom integrations module for the Base44 SDK.
|
|
35
3
|
*
|
|
@@ -42,18 +10,22 @@ export function createCustomIntegrationsModule(axios, appId) {
|
|
|
42
10
|
return {
|
|
43
11
|
async call(slug, operationId, params) {
|
|
44
12
|
// Validate required parameters
|
|
45
|
-
if (!slug) {
|
|
46
|
-
throw new Error("Integration slug is required");
|
|
13
|
+
if (!(slug === null || slug === void 0 ? void 0 : slug.trim())) {
|
|
14
|
+
throw new Error("Integration slug is required and cannot be empty");
|
|
47
15
|
}
|
|
48
|
-
if (!operationId) {
|
|
49
|
-
throw new Error("Operation ID is required");
|
|
16
|
+
if (!(operationId === null || operationId === void 0 ? void 0 : operationId.trim())) {
|
|
17
|
+
throw new Error("Operation ID is required and cannot be empty");
|
|
50
18
|
}
|
|
51
|
-
//
|
|
52
|
-
const
|
|
19
|
+
// Convert camelCase to snake_case for Python backend
|
|
20
|
+
const { pathParams, queryParams, ...rest } = params !== null && params !== void 0 ? params : {};
|
|
21
|
+
const body = {
|
|
22
|
+
...rest,
|
|
23
|
+
...(pathParams && { path_params: pathParams }),
|
|
24
|
+
...(queryParams && { query_params: queryParams }),
|
|
25
|
+
};
|
|
53
26
|
// Make the API call
|
|
54
|
-
const response = await axios.post(`/apps/${appId}/integrations/custom/${slug}/${operationId}`,
|
|
55
|
-
//
|
|
56
|
-
// Note: axios interceptor already extracts data from response
|
|
27
|
+
const response = await axios.post(`/apps/${appId}/integrations/custom/${slug}/${operationId}`, body);
|
|
28
|
+
// The axios interceptor extracts response.data, so we get the payload directly
|
|
57
29
|
return response;
|
|
58
30
|
},
|
|
59
31
|
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parameters for calling a custom integration endpoint.
|
|
3
|
-
*
|
|
4
|
-
* Supports both camelCase and snake_case parameter names for developer convenience.
|
|
5
|
-
* The SDK will normalize to snake_case before sending to the API.
|
|
6
3
|
*/
|
|
7
4
|
export interface CustomIntegrationCallParams {
|
|
8
5
|
/**
|
|
@@ -11,24 +8,12 @@ export interface CustomIntegrationCallParams {
|
|
|
11
8
|
payload?: Record<string, any>;
|
|
12
9
|
/**
|
|
13
10
|
* Path parameters to substitute in the URL (e.g., `{ owner: "user", repo: "repo" }`).
|
|
14
|
-
* Can use either `pathParams` (camelCase) or `path_params` (snake_case).
|
|
15
11
|
*/
|
|
16
12
|
pathParams?: Record<string, string>;
|
|
17
|
-
/**
|
|
18
|
-
* Path parameters to substitute in the URL (snake_case variant).
|
|
19
|
-
* @see {@link pathParams}
|
|
20
|
-
*/
|
|
21
|
-
path_params?: Record<string, string>;
|
|
22
13
|
/**
|
|
23
14
|
* Query string parameters to append to the URL.
|
|
24
|
-
* Can use either `queryParams` (camelCase) or `query_params` (snake_case).
|
|
25
15
|
*/
|
|
26
16
|
queryParams?: Record<string, any>;
|
|
27
|
-
/**
|
|
28
|
-
* Query string parameters (snake_case variant).
|
|
29
|
-
* @see {@link queryParams}
|
|
30
|
-
*/
|
|
31
|
-
query_params?: Record<string, any>;
|
|
32
17
|
/**
|
|
33
18
|
* Additional headers to send with this specific request.
|
|
34
19
|
* These are merged with the integration's configured headers.
|
|
@@ -107,7 +92,7 @@ export interface CustomIntegrationsModule {
|
|
|
107
92
|
*
|
|
108
93
|
* @param slug - The integration's unique identifier (slug), as defined by the workspace admin.
|
|
109
94
|
* @param operationId - The operation ID from the OpenAPI spec (e.g., "listIssues", "getUser").
|
|
110
|
-
* @param params - Optional parameters including payload,
|
|
95
|
+
* @param params - Optional parameters including payload, pathParams, queryParams, and headers.
|
|
111
96
|
* @returns Promise resolving to the integration call response.
|
|
112
97
|
*
|
|
113
98
|
* @throws {Error} If slug is not provided.
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { EntitiesModule } from "./entities.types";
|
|
3
|
+
import { RoomsSocket } from "../utils/socket-utils";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the entities module.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface EntitiesModuleConfig {
|
|
9
|
+
axios: AxiosInstance;
|
|
10
|
+
appId: string;
|
|
11
|
+
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates the entities module for the Base44 SDK.
|
|
15
|
+
*
|
|
16
|
+
* @param config - Configuration object containing axios, appId, and getSocket
|
|
17
|
+
* @returns Entities module with dynamic entity access
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function createEntitiesModule(config: EntitiesModuleConfig): EntitiesModule;
|
|
3
21
|
/**
|
|
4
22
|
* Creates the entities module for the Base44 SDK.
|
|
5
23
|
*
|
|
@@ -7,5 +25,6 @@ import { EntitiesModule } from "./entities.types";
|
|
|
7
25
|
* @param appId - Application ID
|
|
8
26
|
* @returns Entities module with dynamic entity access
|
|
9
27
|
* @internal
|
|
28
|
+
* @deprecated Use the config object overload instead
|
|
10
29
|
*/
|
|
11
30
|
export declare function createEntitiesModule(axios: AxiosInstance, appId: string): EntitiesModule;
|
package/dist/modules/entities.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export function createEntitiesModule(configOrAxios, appIdArg) {
|
|
2
|
+
// Handle both old and new signatures for backwards compatibility
|
|
3
|
+
const config = "axios" in configOrAxios
|
|
4
|
+
? configOrAxios
|
|
5
|
+
: {
|
|
6
|
+
axios: configOrAxios,
|
|
7
|
+
appId: appIdArg,
|
|
8
|
+
getSocket: () => {
|
|
9
|
+
throw new Error("Realtime subscriptions are not available. Please update your client configuration.");
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
const { axios, appId, getSocket } = config;
|
|
10
13
|
// Using Proxy to dynamically handle entity names
|
|
11
14
|
return new Proxy({}, {
|
|
12
15
|
get(target, entityName) {
|
|
@@ -17,20 +20,40 @@ export function createEntitiesModule(axios, appId) {
|
|
|
17
20
|
return undefined;
|
|
18
21
|
}
|
|
19
22
|
// Create entity handler
|
|
20
|
-
return createEntityHandler(axios, appId, entityName);
|
|
23
|
+
return createEntityHandler(axios, appId, entityName, getSocket);
|
|
21
24
|
},
|
|
22
25
|
});
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses the realtime message data and extracts event information.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function parseRealtimeMessage(dataStr) {
|
|
32
|
+
var _a;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(dataStr);
|
|
35
|
+
return {
|
|
36
|
+
type: parsed.type,
|
|
37
|
+
data: parsed.data,
|
|
38
|
+
id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
|
|
39
|
+
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
24
46
|
/**
|
|
25
47
|
* Creates a handler for a specific entity.
|
|
26
48
|
*
|
|
27
49
|
* @param axios - Axios instance
|
|
28
50
|
* @param appId - Application ID
|
|
29
51
|
* @param entityName - Entity name
|
|
52
|
+
* @param getSocket - Function to get the socket instance
|
|
30
53
|
* @returns Entity handler with CRUD methods
|
|
31
54
|
* @internal
|
|
32
55
|
*/
|
|
33
|
-
function createEntityHandler(axios, appId, entityName) {
|
|
56
|
+
function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
34
57
|
const baseURL = `/apps/${appId}/entities/${entityName}`;
|
|
35
58
|
return {
|
|
36
59
|
// List entities with optional pagination and sorting
|
|
@@ -95,5 +118,25 @@ function createEntityHandler(axios, appId, entityName) {
|
|
|
95
118
|
},
|
|
96
119
|
});
|
|
97
120
|
},
|
|
121
|
+
// Subscribe to realtime updates
|
|
122
|
+
subscribe(callback) {
|
|
123
|
+
const room = `entities:${appId}:${entityName}`;
|
|
124
|
+
// Get the socket and subscribe to the room
|
|
125
|
+
const socket = getSocket();
|
|
126
|
+
const unsubscribe = socket.subscribeToRoom(room, {
|
|
127
|
+
update_model: (msg) => {
|
|
128
|
+
// Only process messages for our room
|
|
129
|
+
if (msg.room !== room) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const event = parseRealtimeMessage(msg.data);
|
|
133
|
+
if (!event) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
callback(event);
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
return unsubscribe;
|
|
140
|
+
},
|
|
98
141
|
};
|
|
99
142
|
}
|
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event types for realtime entity updates.
|
|
3
|
+
*/
|
|
4
|
+
export type RealtimeEventType = "create" | "update" | "delete";
|
|
5
|
+
/**
|
|
6
|
+
* Payload received when a realtime event occurs.
|
|
7
|
+
*/
|
|
8
|
+
export interface RealtimeEvent<T = Record<string, any>> {
|
|
9
|
+
/** The type of change that occurred */
|
|
10
|
+
type: RealtimeEventType;
|
|
11
|
+
/** The entity data (new/updated for create/update, previous for delete) */
|
|
12
|
+
data: T;
|
|
13
|
+
/** The unique identifier of the affected entity */
|
|
14
|
+
id: string;
|
|
15
|
+
/** ISO 8601 timestamp of when the event occurred */
|
|
16
|
+
timestamp: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Callback function invoked when a realtime event occurs.
|
|
20
|
+
*/
|
|
21
|
+
export type RealtimeCallback<T = Record<string, any>> = (event: RealtimeEvent<T>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Function returned from subscribe, call it to unsubscribe.
|
|
24
|
+
*/
|
|
25
|
+
export type Subscription = () => void;
|
|
1
26
|
/**
|
|
2
27
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
3
28
|
*
|
|
@@ -242,6 +267,26 @@ export interface EntityHandler {
|
|
|
242
267
|
* ```
|
|
243
268
|
*/
|
|
244
269
|
importEntities(file: File): Promise<any>;
|
|
270
|
+
/**
|
|
271
|
+
* Subscribes to realtime updates for all records of this entity type.
|
|
272
|
+
*
|
|
273
|
+
* Receives notifications whenever any record is created, updated, or deleted.
|
|
274
|
+
*
|
|
275
|
+
* @param callback - Function called when an entity changes.
|
|
276
|
+
* @returns Unsubscribe function to stop listening.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* // Subscribe to all Task changes
|
|
281
|
+
* const unsubscribe = base44.entities.Task.subscribe((event) => {
|
|
282
|
+
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // Later, unsubscribe
|
|
286
|
+
* unsubscribe();
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
subscribe(callback: RealtimeCallback): Subscription;
|
|
245
290
|
}
|
|
246
291
|
/**
|
|
247
292
|
* Entities module for managing app data.
|