@base44-preview/sdk 0.8.20-pr.141.01e370e → 0.8.20-pr.141.620d2a2
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.
|
@@ -12,14 +12,8 @@ export function createFunctionsModule(axios, appId) {
|
|
|
12
12
|
return path;
|
|
13
13
|
return `${String(base).replace(/\/$/, "")}${path}`;
|
|
14
14
|
};
|
|
15
|
-
const isBodyInit = (value) => value instanceof FormData ||
|
|
16
|
-
value instanceof Blob ||
|
|
17
|
-
value instanceof URLSearchParams ||
|
|
18
|
-
value instanceof ReadableStream ||
|
|
19
|
-
value instanceof ArrayBuffer ||
|
|
20
|
-
ArrayBuffer.isView(value);
|
|
21
15
|
const toHeaders = (inputHeaders) => {
|
|
22
|
-
var _a
|
|
16
|
+
var _a;
|
|
23
17
|
const headers = new Headers();
|
|
24
18
|
const appendHeaders = (source) => {
|
|
25
19
|
if (!source)
|
|
@@ -30,9 +24,8 @@ export function createFunctionsModule(axios, appId) {
|
|
|
30
24
|
}
|
|
31
25
|
});
|
|
32
26
|
};
|
|
33
|
-
//
|
|
27
|
+
// Append common headers from axios defaults
|
|
34
28
|
appendHeaders((_a = axios.defaults.headers) === null || _a === void 0 ? void 0 : _a.common);
|
|
35
|
-
appendHeaders((_b = axios.defaults.headers) === null || _b === void 0 ? void 0 : _b.post);
|
|
36
29
|
if (inputHeaders) {
|
|
37
30
|
new Headers(inputHeaders).forEach((value, key) => {
|
|
38
31
|
headers.set(key, value);
|
|
@@ -76,37 +69,12 @@ export function createFunctionsModule(axios, appId) {
|
|
|
76
69
|
async fetch(path, init = {}) {
|
|
77
70
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
78
71
|
const primaryPath = `/functions${normalizedPath}`;
|
|
79
|
-
const
|
|
80
|
-
const { data, ...fetchInit } = init;
|
|
81
|
-
const headers = toHeaders(fetchInit.headers);
|
|
82
|
-
if (!headers.has("X-App-Id")) {
|
|
83
|
-
headers.set("X-App-Id", appId);
|
|
84
|
-
}
|
|
85
|
-
let body = fetchInit.body;
|
|
86
|
-
if (body === undefined && data !== undefined) {
|
|
87
|
-
if (data === null) {
|
|
88
|
-
body = null;
|
|
89
|
-
}
|
|
90
|
-
else if (typeof data === "string" ||
|
|
91
|
-
isBodyInit(data)) {
|
|
92
|
-
body = data;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
body = JSON.stringify(data);
|
|
96
|
-
if (!headers.has("Content-Type")) {
|
|
97
|
-
headers.set("Content-Type", "application/json");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
72
|
+
const headers = toHeaders(init.headers);
|
|
101
73
|
const requestInit = {
|
|
102
|
-
...
|
|
74
|
+
...init,
|
|
103
75
|
headers,
|
|
104
|
-
body,
|
|
105
76
|
};
|
|
106
|
-
|
|
107
|
-
if (response.status === 404) {
|
|
108
|
-
response = await fetch(joinBaseUrl(axios.defaults.baseURL, fallbackPath), requestInit);
|
|
109
|
-
}
|
|
77
|
+
const response = await fetch(joinBaseUrl(axios.defaults.baseURL, primaryPath), requestInit);
|
|
110
78
|
return response;
|
|
111
79
|
},
|
|
112
80
|
};
|
|
@@ -17,13 +17,9 @@ export type FunctionName = keyof FunctionNameRegistry extends never ? string : k
|
|
|
17
17
|
/**
|
|
18
18
|
* Options for {@linkcode FunctionsModule.fetch}.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
* is JSON-stringified when `body` is not provided.
|
|
20
|
+
* Uses native `fetch` options directly.
|
|
22
21
|
*/
|
|
23
|
-
export type FunctionsFetchInit = RequestInit
|
|
24
|
-
/** Convenience payload for JSON requests when `body` is omitted. */
|
|
25
|
-
data?: unknown;
|
|
26
|
-
};
|
|
22
|
+
export type FunctionsFetchInit = RequestInit;
|
|
27
23
|
/**
|
|
28
24
|
* Functions module for invoking custom backend functions.
|
|
29
25
|
*
|
|
@@ -84,11 +80,10 @@ export interface FunctionsModule {
|
|
|
84
80
|
* Use this when you need streaming behavior (SSE, chunked text, NDJSON),
|
|
85
81
|
* because `invoke()` buffers the full response.
|
|
86
82
|
*
|
|
87
|
-
* Requests are sent to `/api/functions/<path
|
|
88
|
-
* `/api/apps/<appId>/functions/<path>` on `404` for compatibility.
|
|
83
|
+
* Requests are sent to `/api/functions/<path>`.
|
|
89
84
|
*
|
|
90
85
|
* @param path - Function path, e.g. `/streaming_demo` or `/streaming_demo/deep/path`
|
|
91
|
-
* @param init - Native fetch options
|
|
86
|
+
* @param init - Native fetch options.
|
|
92
87
|
* @returns Promise resolving to a native fetch `Response`
|
|
93
88
|
*/
|
|
94
89
|
fetch(path: string, init?: FunctionsFetchInit): Promise<Response>;
|