@doany-ai/sdk 0.1.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.
- package/LICENSE +22 -0
- package/README.md +60 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.js +395 -0
- package/dist/client.types.d.ts +149 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +5 -0
- package/dist/modules/agents.d.ts +2 -0
- package/dist/modules/agents.js +89 -0
- package/dist/modules/agents.types.d.ts +397 -0
- package/dist/modules/agents.types.js +1 -0
- package/dist/modules/ai-gateway.d.ts +2 -0
- package/dist/modules/ai-gateway.js +13 -0
- package/dist/modules/ai-gateway.types.d.ts +88 -0
- package/dist/modules/ai-gateway.types.js +1 -0
- package/dist/modules/analytics.d.ts +20 -0
- package/dist/modules/analytics.js +284 -0
- package/dist/modules/analytics.types.d.ts +122 -0
- package/dist/modules/analytics.types.js +1 -0
- package/dist/modules/app-logs.d.ts +11 -0
- package/dist/modules/app-logs.js +27 -0
- package/dist/modules/app-logs.types.d.ts +46 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +142 -0
- package/dist/modules/app.types.js +1 -0
- package/dist/modules/auth.d.ts +13 -0
- package/dist/modules/auth.js +240 -0
- package/dist/modules/auth.types.d.ts +517 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +20 -0
- package/dist/modules/connectors.js +98 -0
- package/dist/modules/connectors.types.d.ts +376 -0
- package/dist/modules/connectors.types.js +1 -0
- package/dist/modules/custom-integrations.d.ts +11 -0
- package/dist/modules/custom-integrations.js +32 -0
- package/dist/modules/custom-integrations.types.d.ts +89 -0
- package/dist/modules/custom-integrations.types.js +1 -0
- package/dist/modules/entities.d.ts +20 -0
- package/dist/modules/entities.js +163 -0
- package/dist/modules/entities.types.d.ts +702 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +12 -0
- package/dist/modules/functions.js +79 -0
- package/dist/modules/functions.types.d.ts +150 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +11 -0
- package/dist/modules/integrations.js +77 -0
- package/dist/modules/integrations.types.d.ts +418 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +11 -0
- package/dist/modules/sso.js +22 -0
- package/dist/modules/sso.types.d.ts +68 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/modules/types.d.ts +5 -0
- package/dist/modules/types.js +5 -0
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.js +1 -0
- package/dist/utils/auth-utils.d.ts +117 -0
- package/dist/utils/auth-utils.js +189 -0
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +100 -0
- package/dist/utils/axios-client.js +202 -0
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +4 -0
- package/dist/utils/common.js +11 -0
- package/dist/utils/sharedInstance.d.ts +1 -0
- package/dist/utils/sharedInstance.js +15 -0
- package/dist/utils/socket-utils.d.ts +47 -0
- package/dist/utils/socket-utils.js +170 -0
- package/package.json +54 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { FunctionsModule, FunctionsModuleConfig } from "./functions.types";
|
|
3
|
+
/**
|
|
4
|
+
* Creates the functions module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance
|
|
7
|
+
* @param appId - Application ID
|
|
8
|
+
* @param config - Optional configuration for fetch functionality
|
|
9
|
+
* @returns Functions module with methods to invoke custom backend functions
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFunctionsModule(axios: AxiosInstance, appId: string, config?: FunctionsModuleConfig): FunctionsModule;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the functions module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance
|
|
5
|
+
* @param appId - Application ID
|
|
6
|
+
* @param config - Optional configuration for fetch functionality
|
|
7
|
+
* @returns Functions module with methods to invoke custom backend functions
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function createFunctionsModule(axios, appId, config) {
|
|
11
|
+
const joinBaseUrl = (base, path) => {
|
|
12
|
+
if (!base)
|
|
13
|
+
return path;
|
|
14
|
+
return `${String(base).replace(/\/$/, "")}${path}`;
|
|
15
|
+
};
|
|
16
|
+
const toHeaders = (inputHeaders) => {
|
|
17
|
+
const headers = new Headers();
|
|
18
|
+
// Get auth headers from the getter function if provided
|
|
19
|
+
if (config === null || config === void 0 ? void 0 : config.getAuthHeaders) {
|
|
20
|
+
const authHeaders = config.getAuthHeaders();
|
|
21
|
+
Object.entries(authHeaders).forEach(([key, value]) => {
|
|
22
|
+
if (value !== undefined && value !== null) {
|
|
23
|
+
headers.set(key, String(value));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (inputHeaders) {
|
|
28
|
+
new Headers(inputHeaders).forEach((value, key) => {
|
|
29
|
+
headers.set(key, value);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return headers;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
// Invoke a custom backend function by name
|
|
36
|
+
async invoke(functionName, data) {
|
|
37
|
+
// Validate input
|
|
38
|
+
if (typeof data === "string") {
|
|
39
|
+
throw new Error(`Function ${functionName} must receive an object with named parameters, received: ${data}`);
|
|
40
|
+
}
|
|
41
|
+
let formData;
|
|
42
|
+
let contentType;
|
|
43
|
+
// Handle file uploads with FormData
|
|
44
|
+
if (data instanceof FormData ||
|
|
45
|
+
(data && Object.values(data).some((value) => value instanceof File))) {
|
|
46
|
+
formData = new FormData();
|
|
47
|
+
Object.keys(data).forEach((key) => {
|
|
48
|
+
if (data[key] instanceof File) {
|
|
49
|
+
formData.append(key, data[key], data[key].name);
|
|
50
|
+
}
|
|
51
|
+
else if (typeof data[key] === "object" && data[key] !== null) {
|
|
52
|
+
formData.append(key, JSON.stringify(data[key]));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
formData.append(key, data[key]);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
contentType = "multipart/form-data";
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
formData = data;
|
|
62
|
+
contentType = "application/json";
|
|
63
|
+
}
|
|
64
|
+
return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, { headers: { "Content-Type": contentType } });
|
|
65
|
+
},
|
|
66
|
+
// Fetch a backend function endpoint directly.
|
|
67
|
+
async fetch(path, init = {}) {
|
|
68
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
69
|
+
const primaryPath = `/functions${normalizedPath}`;
|
|
70
|
+
const headers = toHeaders(init.headers);
|
|
71
|
+
const requestInit = {
|
|
72
|
+
...init,
|
|
73
|
+
headers,
|
|
74
|
+
};
|
|
75
|
+
const response = await fetch(joinBaseUrl(config === null || config === void 0 ? void 0 : config.baseURL, primaryPath), requestInit);
|
|
76
|
+
return response;
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry of function names. The [`types generate`](/developers/references/cli/commands/types-generate) command fills this registry, then [`FunctionName`](#functionname) resolves to a union of the keys.
|
|
3
|
+
*/
|
|
4
|
+
export interface FunctionNameRegistry {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Union of all function names from the [`FunctionNameRegistry`](#functionnameregistry). Defaults to `string` when no types have been generated.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Using generated function name types
|
|
12
|
+
* // With generated types, you get autocomplete on function names
|
|
13
|
+
* await base44.functions.invoke('calculateTotal', { items: ['item1', 'item2'] });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type FunctionName = keyof FunctionNameRegistry extends never ? string : keyof FunctionNameRegistry;
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@linkcode FunctionsModule.fetch}.
|
|
19
|
+
*
|
|
20
|
+
* Alias of the native [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) type.
|
|
21
|
+
* Any option accepted by the browser `fetch` API is valid (`method`, `headers`, `body`, `signal`, etc.).
|
|
22
|
+
* Auth headers are merged in automatically; you do not need to set them.
|
|
23
|
+
*/
|
|
24
|
+
export type FunctionsFetchInit = RequestInit;
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for the functions module.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export interface FunctionsModuleConfig {
|
|
30
|
+
getAuthHeaders?: () => Record<string, string>;
|
|
31
|
+
baseURL?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Functions module for invoking custom backend functions.
|
|
35
|
+
*
|
|
36
|
+
* This module allows you to invoke the custom backend functions defined in the app.
|
|
37
|
+
*
|
|
38
|
+
* ## Authentication Modes
|
|
39
|
+
*
|
|
40
|
+
* This module is available to use with a client in all authentication modes:
|
|
41
|
+
*
|
|
42
|
+
* - **Anonymous or User authentication** (`base44.functions`): Functions are invoked with the current user's permissions. Anonymous users invoke functions without authentication, while authenticated users invoke functions with their authentication context.
|
|
43
|
+
* - **Service role authentication** (`base44.asServiceRole.functions`): Functions are invoked with the service role for backend code that needs elevated permissions.
|
|
44
|
+
*
|
|
45
|
+
* ## Generated Types
|
|
46
|
+
*
|
|
47
|
+
* If you're working in a TypeScript project, you can generate types from your backend functions to get autocomplete on function names when calling `invoke()`. See the [Dynamic Types](/developers/references/sdk/getting-started/dynamic-types) guide to get started.
|
|
48
|
+
*/
|
|
49
|
+
export interface FunctionsModule {
|
|
50
|
+
/**
|
|
51
|
+
* Invokes a custom backend function by name.
|
|
52
|
+
*
|
|
53
|
+
* Sends a POST request to a custom backend function deployed to the app.
|
|
54
|
+
* The function receives the provided data as named parameters and returns
|
|
55
|
+
* the result. If any parameter is a `File` object, the request will automatically be
|
|
56
|
+
* sent as `multipart/form-data`. Otherwise, it will be sent as JSON.
|
|
57
|
+
*
|
|
58
|
+
* For streaming responses, non-POST methods, or raw response access, use {@linkcode fetch | fetch()} instead.
|
|
59
|
+
*
|
|
60
|
+
* @param functionName - The name of the function to invoke.
|
|
61
|
+
* @param data - An object containing named parameters for the function.
|
|
62
|
+
* @returns Promise resolving to the function's response. The `data` property contains the data returned by the function, if there is any.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Basic function call
|
|
67
|
+
* const result = await base44.functions.invoke('calculateTotal', {
|
|
68
|
+
* items: ['item1', 'item2'],
|
|
69
|
+
* });
|
|
70
|
+
* console.log(result.data.total);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Function with file upload in React
|
|
76
|
+
* const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
77
|
+
* const file = event.target.files?.[0];
|
|
78
|
+
* if (file) {
|
|
79
|
+
* const processedImage = await base44.functions.invoke('processImage', {
|
|
80
|
+
* image: file,
|
|
81
|
+
* filter: 'grayscale',
|
|
82
|
+
* quality: 80
|
|
83
|
+
* });
|
|
84
|
+
* }
|
|
85
|
+
* };
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
invoke(functionName: FunctionName, data?: Record<string, any>): Promise<any>;
|
|
89
|
+
/**
|
|
90
|
+
* Performs a direct HTTP request to a backend function path and returns the native `Response`.
|
|
91
|
+
*
|
|
92
|
+
* Use `fetch()` when you need low-level control that {@linkcode invoke | invoke()} doesn't provide, such as:
|
|
93
|
+
* - Streaming responses, like SSE, chunked text, or NDJSON
|
|
94
|
+
* - Custom HTTP methods, like PUT, PATCH, or DELETE
|
|
95
|
+
* - Raw response access, including status codes, headers, and binary bodies
|
|
96
|
+
*
|
|
97
|
+
* @param path - Function path. Leading slash is optional, so `/chat` and `chat` are equivalent. For example, `'/streaming_demo'` or `'reports/export'`.
|
|
98
|
+
* @param init - Optional [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) options such as `method`, `headers`, `body`, and `signal`. Auth headers are added automatically.
|
|
99
|
+
* @returns Promise resolving to a native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Stream an SSE response
|
|
104
|
+
* const response = await base44.functions.fetch('/chat', {
|
|
105
|
+
* method: 'POST',
|
|
106
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
107
|
+
* body: JSON.stringify({ prompt: 'Hello!' }),
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* const reader = response.body!.getReader();
|
|
111
|
+
* const decoder = new TextDecoder();
|
|
112
|
+
*
|
|
113
|
+
* while (true) {
|
|
114
|
+
* const { done, value } = await reader.read();
|
|
115
|
+
* if (done) break;
|
|
116
|
+
* console.log(decoder.decode(value, { stream: true }));
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // PUT request
|
|
123
|
+
* const response = await base44.functions.fetch('/users/profile', {
|
|
124
|
+
* method: 'PUT',
|
|
125
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
126
|
+
* body: JSON.stringify({ name: 'Jane', role: 'admin' }),
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* if (!response.ok) {
|
|
130
|
+
* throw new Error(`Request failed: ${response.status}`);
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* const updated = await response.json();
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Download a binary file
|
|
139
|
+
* const response = await base44.functions.fetch('/export/report');
|
|
140
|
+
* const blob = await response.blob();
|
|
141
|
+
*
|
|
142
|
+
* const url = URL.createObjectURL(blob);
|
|
143
|
+
* const a = document.createElement('a');
|
|
144
|
+
* a.href = url;
|
|
145
|
+
* a.download = 'report.pdf';
|
|
146
|
+
* a.click();
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
fetch(path: string, init?: FunctionsFetchInit): Promise<Response>;
|
|
150
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { IntegrationsModule } from "./integrations.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates the integrations module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance
|
|
7
|
+
* @param appId - Application ID
|
|
8
|
+
* @returns Integrations module with dynamic access to integration endpoints
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function createIntegrationsModule(axios: AxiosInstance, appId: string): IntegrationsModule;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createCustomIntegrationsModule } from "./custom-integrations.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the integrations module for the Base44 SDK.
|
|
4
|
+
*
|
|
5
|
+
* @param axios - Axios instance
|
|
6
|
+
* @param appId - Application ID
|
|
7
|
+
* @returns Integrations module with dynamic access to integration endpoints
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function createIntegrationsModule(axios, appId) {
|
|
11
|
+
// Create the custom integrations module once
|
|
12
|
+
const customModule = createCustomIntegrationsModule(axios, appId);
|
|
13
|
+
return new Proxy({}, {
|
|
14
|
+
get(target, packageName) {
|
|
15
|
+
// Skip internal properties
|
|
16
|
+
if (typeof packageName !== "string" ||
|
|
17
|
+
packageName === "then" ||
|
|
18
|
+
packageName.startsWith("_")) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
// Handle 'custom' specially - return the custom integrations module
|
|
22
|
+
if (packageName === "custom") {
|
|
23
|
+
return customModule;
|
|
24
|
+
}
|
|
25
|
+
// Create a proxy for integration endpoints
|
|
26
|
+
return new Proxy({}, {
|
|
27
|
+
get(target, endpointName) {
|
|
28
|
+
// Skip internal properties
|
|
29
|
+
if (typeof endpointName !== "string" ||
|
|
30
|
+
endpointName === "then" ||
|
|
31
|
+
endpointName.startsWith("_")) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
// Return a function that calls the integration endpoint
|
|
35
|
+
// This allows: client.integrations.PackageName.EndpointName(data)
|
|
36
|
+
return async (data) => {
|
|
37
|
+
// Validate input
|
|
38
|
+
if (typeof data === "string") {
|
|
39
|
+
throw new Error(`Integration ${endpointName} must receive an object with named parameters, received: ${data}`);
|
|
40
|
+
}
|
|
41
|
+
let formData;
|
|
42
|
+
let contentType;
|
|
43
|
+
// Handle file uploads with FormData
|
|
44
|
+
if (data instanceof FormData ||
|
|
45
|
+
(data &&
|
|
46
|
+
Object.values(data).some((value) => value instanceof File))) {
|
|
47
|
+
formData = new FormData();
|
|
48
|
+
Object.keys(data).forEach((key) => {
|
|
49
|
+
if (data[key] instanceof File) {
|
|
50
|
+
formData.append(key, data[key], data[key].name);
|
|
51
|
+
}
|
|
52
|
+
else if (typeof data[key] === "object" &&
|
|
53
|
+
data[key] !== null) {
|
|
54
|
+
formData.append(key, JSON.stringify(data[key]));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
formData.append(key, data[key]);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
contentType = "multipart/form-data";
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
formData = data;
|
|
64
|
+
contentType = "application/json";
|
|
65
|
+
}
|
|
66
|
+
// For Core package
|
|
67
|
+
if (packageName === "Core") {
|
|
68
|
+
return axios.post(`/apps/${appId}/integration-endpoints/Core/${endpointName}`, formData || data, { headers: { "Content-Type": contentType } });
|
|
69
|
+
}
|
|
70
|
+
// For other packages
|
|
71
|
+
return axios.post(`/apps/${appId}/integration-endpoints/installable/${packageName}/integration-endpoints/${endpointName}`, formData || data, { headers: { "Content-Type": contentType } });
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|