@base44/sdk 0.8.21 → 0.8.22
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
CHANGED
|
@@ -49,6 +49,7 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
export function createClient(config) {
|
|
52
|
+
var _a, _b;
|
|
52
53
|
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
53
54
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
54
55
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
@@ -116,7 +117,18 @@ export function createClient(config) {
|
|
|
116
117
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
117
118
|
connectors: createUserConnectorsModule(axiosClient, appId),
|
|
118
119
|
auth: userAuthModule,
|
|
119
|
-
functions: createFunctionsModule(functionsAxiosClient, appId
|
|
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
|
+
}),
|
|
120
132
|
agents: createAgentsModule({
|
|
121
133
|
axios: axiosClient,
|
|
122
134
|
getSocket,
|
|
@@ -148,7 +160,17 @@ export function createClient(config) {
|
|
|
148
160
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
149
161
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
150
162
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
|
151
|
-
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, 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
|
+
}),
|
|
152
174
|
agents: createAgentsModule({
|
|
153
175
|
axios: serviceRoleAxiosClient,
|
|
154
176
|
getSocket,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { FunctionsModule } from "./functions.types";
|
|
2
|
+
import { FunctionsModule, FunctionsModuleConfig } from "./functions.types";
|
|
3
3
|
/**
|
|
4
4
|
* Creates the functions module for the Base44 SDK.
|
|
5
5
|
*
|
|
6
6
|
* @param axios - Axios instance
|
|
7
7
|
* @param appId - Application ID
|
|
8
|
+
* @param config - Optional configuration for fetch functionality
|
|
8
9
|
* @returns Functions module with methods to invoke custom backend functions
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
|
-
export declare function createFunctionsModule(axios: AxiosInstance, appId: string): FunctionsModule;
|
|
12
|
+
export declare function createFunctionsModule(axios: AxiosInstance, appId: string, config?: FunctionsModuleConfig): FunctionsModule;
|
|
@@ -3,10 +3,34 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param axios - Axios instance
|
|
5
5
|
* @param appId - Application ID
|
|
6
|
+
* @param config - Optional configuration for fetch functionality
|
|
6
7
|
* @returns Functions module with methods to invoke custom backend functions
|
|
7
8
|
* @internal
|
|
8
9
|
*/
|
|
9
|
-
export function createFunctionsModule(axios, appId) {
|
|
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
|
+
};
|
|
10
34
|
return {
|
|
11
35
|
// Invoke a custom backend function by name
|
|
12
36
|
async invoke(functionName, data) {
|
|
@@ -39,5 +63,17 @@ export function createFunctionsModule(axios, appId) {
|
|
|
39
63
|
}
|
|
40
64
|
return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, { headers: { "Content-Type": contentType } });
|
|
41
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
|
+
},
|
|
42
78
|
};
|
|
43
79
|
}
|
|
@@ -14,6 +14,20 @@ export interface FunctionNameRegistry {
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export type FunctionName = keyof FunctionNameRegistry extends never ? string : keyof FunctionNameRegistry;
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@linkcode FunctionsModule.fetch}.
|
|
19
|
+
*
|
|
20
|
+
* Uses native `fetch` options directly.
|
|
21
|
+
*/
|
|
22
|
+
export type FunctionsFetchInit = RequestInit;
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for the functions module.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface FunctionsModuleConfig {
|
|
28
|
+
getAuthHeaders?: () => Record<string, string>;
|
|
29
|
+
baseURL?: string;
|
|
30
|
+
}
|
|
17
31
|
/**
|
|
18
32
|
* Functions module for invoking custom backend functions.
|
|
19
33
|
*
|
|
@@ -68,4 +82,22 @@ export interface FunctionsModule {
|
|
|
68
82
|
* ```
|
|
69
83
|
*/
|
|
70
84
|
invoke(functionName: FunctionName, data?: Record<string, any>): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* Performs a direct HTTP request to a backend function path and returns the native `Response`.
|
|
87
|
+
*
|
|
88
|
+
* Use this method when you need low-level control over the request/response that the higher-level
|
|
89
|
+
* `invoke()` abstraction doesn't provide, such as:
|
|
90
|
+
* - Streaming responses (SSE, chunked text, NDJSON)
|
|
91
|
+
* - Custom HTTP methods (PUT, PATCH, DELETE, etc.)
|
|
92
|
+
* - Custom headers or request configuration
|
|
93
|
+
* - Access to raw response metadata (status, headers)
|
|
94
|
+
* - Direct control over request/response bodies
|
|
95
|
+
*
|
|
96
|
+
* Requests are sent to `/api/functions/<path>`.
|
|
97
|
+
*
|
|
98
|
+
* @param path - Function path, e.g. `/streaming_demo` or `/streaming_demo/deep/path`
|
|
99
|
+
* @param init - Native fetch options.
|
|
100
|
+
* @returns Promise resolving to a native fetch `Response`
|
|
101
|
+
*/
|
|
102
|
+
fetch(path: string, init?: FunctionsFetchInit): Promise<Response>;
|
|
71
103
|
}
|