@base44-preview/sdk 0.8.60-pr.375.db5e899 → 0.8.60-pr.376.c2b0448
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 +6 -23
- package/dist/utils/auth-utils.d.ts +1 -0
- package/dist/utils/auth-utils.js +16 -0
- package/package.json +1 -8
- package/dist/utils/build-commit-source.d.ts +0 -19
- package/dist/utils/build-commit-source.fallback.d.ts +0 -14
- package/dist/utils/build-commit-source.fallback.js +0 -16
- package/dist/utils/build-commit-source.js +0 -26
- package/dist/utils/build-commit.d.ts +0 -12
- package/dist/utils/build-commit.js +0 -24
package/dist/client.js
CHANGED
|
@@ -6,9 +6,8 @@ import { createSsoModule } from "./modules/sso.js";
|
|
|
6
6
|
import { createBrowserModule } from "./modules/browser.js";
|
|
7
7
|
import { createVoiceModule } from "./modules/voice.js";
|
|
8
8
|
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
9
|
-
import { getAccessToken } from "./utils/auth-utils.js";
|
|
9
|
+
import { getAccessToken, sanitizeAppBaseUrl } from "./utils/auth-utils.js";
|
|
10
10
|
import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
|
|
11
|
-
import { BUILD_COMMIT_HEADER, getBuildCommitHeaders, } from "./utils/build-commit.js";
|
|
12
11
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
13
12
|
import { createAgentsModule } from "./modules/agents.js";
|
|
14
13
|
import { createAiGatewayModule } from "./modules/ai-gateway.js";
|
|
@@ -57,13 +56,10 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
57
56
|
* ```
|
|
58
57
|
*/
|
|
59
58
|
export function createClient(config) {
|
|
60
|
-
return buildClient(config, { sendBuildCommit: true });
|
|
61
|
-
}
|
|
62
|
-
function buildClient(config, { sendBuildCommit }) {
|
|
63
59
|
var _a, _b, _c, _d;
|
|
64
60
|
const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
65
|
-
//
|
|
66
|
-
const normalizedAppBaseUrl =
|
|
61
|
+
// Always a string: empty if not provided or not http(s)
|
|
62
|
+
const normalizedAppBaseUrl = sanitizeAppBaseUrl(appBaseUrl);
|
|
67
63
|
const socketConfig = {
|
|
68
64
|
serverUrl,
|
|
69
65
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -80,18 +76,7 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
80
76
|
}
|
|
81
77
|
return socket;
|
|
82
78
|
};
|
|
83
|
-
// The build commit goes on every API call, so the backend can tell which
|
|
84
|
-
// frontend bundle a request came from. One set by the caller, in any
|
|
85
|
-
// casing, replaces it; resolving that once here keeps every call path,
|
|
86
|
-
// functions.fetch() included, reporting the same build.
|
|
87
|
-
const callerBuildCommit = Object.entries(optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {}).find(([name]) => name.toLowerCase() === BUILD_COMMIT_HEADER.toLowerCase());
|
|
88
|
-
const buildCommitHeaders = callerBuildCommit
|
|
89
|
-
? { [BUILD_COMMIT_HEADER]: callerBuildCommit[1] }
|
|
90
|
-
: sendBuildCommit
|
|
91
|
-
? getBuildCommitHeaders()
|
|
92
|
-
: {};
|
|
93
79
|
const headers = {
|
|
94
|
-
...(callerBuildCommit ? {} : buildCommitHeaders),
|
|
95
80
|
...optionalHeaders,
|
|
96
81
|
"X-App-Id": String(appId),
|
|
97
82
|
};
|
|
@@ -194,7 +179,7 @@ function buildClient(config, { sendBuildCommit }) {
|
|
|
194
179
|
auth: userAuthModule,
|
|
195
180
|
functions: createFunctionsModule(functionsAxiosClient, appId, {
|
|
196
181
|
getAuthHeaders: () => {
|
|
197
|
-
const headers = {
|
|
182
|
+
const headers = {};
|
|
198
183
|
// Get current token from storage or initial config
|
|
199
184
|
const currentToken = token || getAccessToken();
|
|
200
185
|
if (currentToken) {
|
|
@@ -471,14 +456,12 @@ export function createClientFromRequest(request) {
|
|
|
471
456
|
if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
|
|
472
457
|
additionalHeaders["X-Data-Env"] = dataEnvHeader;
|
|
473
458
|
}
|
|
474
|
-
|
|
475
|
-
// commit, whatever its runtime looks like.
|
|
476
|
-
return buildClient({
|
|
459
|
+
return createClient({
|
|
477
460
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
478
461
|
appId,
|
|
479
462
|
token: userToken,
|
|
480
463
|
serviceToken: serviceRoleToken,
|
|
481
464
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
482
465
|
headers: additionalHeaders,
|
|
483
|
-
}
|
|
466
|
+
});
|
|
484
467
|
}
|
package/dist/utils/auth-utils.js
CHANGED
|
@@ -187,3 +187,19 @@ export function getLoginUrl(nextUrl, options) {
|
|
|
187
187
|
const encodedRedirectUrl = encodeURIComponent(nextUrl || (typeof window !== "undefined" ? window.location.href : ""));
|
|
188
188
|
return `${serverUrl}${loginPath}?from_url=${encodedRedirectUrl}&app_id=${appId}`;
|
|
189
189
|
}
|
|
190
|
+
// appBaseUrl becomes a navigation target, so only http(s) values may pass.
|
|
191
|
+
export function sanitizeAppBaseUrl(value) {
|
|
192
|
+
var _a;
|
|
193
|
+
if (typeof value !== "string")
|
|
194
|
+
return "";
|
|
195
|
+
try {
|
|
196
|
+
const base = typeof window !== "undefined" && ((_a = window.location) === null || _a === void 0 ? void 0 : _a.origin)
|
|
197
|
+
? window.location.origin
|
|
198
|
+
: "http://localhost";
|
|
199
|
+
const { protocol } = new URL(value, base);
|
|
200
|
+
return protocol === "http:" || protocol === "https:" ? value : "";
|
|
201
|
+
}
|
|
202
|
+
catch (_b) {
|
|
203
|
+
return "";
|
|
204
|
+
}
|
|
205
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.60-pr.
|
|
3
|
+
"version": "0.8.60-pr.376.c2b0448",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"imports": {
|
|
8
|
-
"#build-commit-source": {
|
|
9
|
-
"module": "./dist/utils/build-commit-source.js",
|
|
10
|
-
"default": "./dist/utils/build-commit-source.fallback.js"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
7
|
"type": "module",
|
|
14
8
|
"files": [
|
|
15
9
|
"dist"
|
|
@@ -22,7 +16,6 @@
|
|
|
22
16
|
"test:e2e": "vitest run tests/e2e",
|
|
23
17
|
"test:watch": "vitest",
|
|
24
18
|
"test:coverage": "vitest run --coverage",
|
|
25
|
-
"test:build-commit": "scripts/verify-build-commit.sh",
|
|
26
19
|
"docs": "typedoc",
|
|
27
20
|
"prepublishOnly": "npm run build",
|
|
28
21
|
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads the commit the app's frontend bundle was built from.
|
|
3
|
-
*
|
|
4
|
-
* Base44's publish pipeline sets `VITE_BASE44_BUILD_COMMIT` for the build, and
|
|
5
|
-
* Vite replaces the expression below with that literal string when it bundles
|
|
6
|
-
* this file out of `node_modules`, in `vite build` and in the dev server's
|
|
7
|
-
* prebundled deps alike. The expression must stay spelled out exactly like
|
|
8
|
-
* this: Vite matches it statically, and any indirection leaves a runtime lookup
|
|
9
|
-
* that is always undefined.
|
|
10
|
-
*
|
|
11
|
-
* A bundler that isn't Vite leaves `import.meta.env` undefined, so the lookup
|
|
12
|
-
* throws, and that means "no build commit".
|
|
13
|
-
*
|
|
14
|
-
* Only reached as `#build-commit-source` under the `module` condition; see
|
|
15
|
-
* `build-commit-source.fallback.ts`.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export declare function readBuildCommitSource(): unknown;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What `#build-commit-source` resolves to without the `module` condition: no
|
|
3
|
-
* build commit.
|
|
4
|
-
*
|
|
5
|
-
* The package's `imports` field gives the `import.meta` reader
|
|
6
|
-
* (`build-commit-source.ts`) only to bundlers that match `module`: Vite,
|
|
7
|
-
* webpack and esbuild. Everything else gets this file, so `import.meta` never
|
|
8
|
-
* reaches a runtime or bundler that can't take it. That includes Node, Deno,
|
|
9
|
-
* and Metro on every platform: Hermes rejects `import.meta` outright, and
|
|
10
|
-
* Metro's web build ships a classic script, where it is a SyntaxError.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare function readBuildCommitSource(): unknown;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What `#build-commit-source` resolves to without the `module` condition: no
|
|
3
|
-
* build commit.
|
|
4
|
-
*
|
|
5
|
-
* The package's `imports` field gives the `import.meta` reader
|
|
6
|
-
* (`build-commit-source.ts`) only to bundlers that match `module`: Vite,
|
|
7
|
-
* webpack and esbuild. Everything else gets this file, so `import.meta` never
|
|
8
|
-
* reaches a runtime or bundler that can't take it. That includes Node, Deno,
|
|
9
|
-
* and Metro on every platform: Hermes rejects `import.meta` outright, and
|
|
10
|
-
* Metro's web build ships a classic script, where it is a SyntaxError.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export function readBuildCommitSource() {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads the commit the app's frontend bundle was built from.
|
|
3
|
-
*
|
|
4
|
-
* Base44's publish pipeline sets `VITE_BASE44_BUILD_COMMIT` for the build, and
|
|
5
|
-
* Vite replaces the expression below with that literal string when it bundles
|
|
6
|
-
* this file out of `node_modules`, in `vite build` and in the dev server's
|
|
7
|
-
* prebundled deps alike. The expression must stay spelled out exactly like
|
|
8
|
-
* this: Vite matches it statically, and any indirection leaves a runtime lookup
|
|
9
|
-
* that is always undefined.
|
|
10
|
-
*
|
|
11
|
-
* A bundler that isn't Vite leaves `import.meta.env` undefined, so the lookup
|
|
12
|
-
* throws, and that means "no build commit".
|
|
13
|
-
*
|
|
14
|
-
* Only reached as `#build-commit-source` under the `module` condition; see
|
|
15
|
-
* `build-commit-source.fallback.ts`.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export function readBuildCommitSource() {
|
|
20
|
-
try {
|
|
21
|
-
return import.meta.env.VITE_BASE44_BUILD_COMMIT;
|
|
22
|
-
}
|
|
23
|
-
catch (_a) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** Header the backend reads to tell which frontend build sent a request. */
|
|
2
|
-
export declare const BUILD_COMMIT_HEADER = "X-Base44-Build";
|
|
3
|
-
/**
|
|
4
|
-
* The build-commit header to send from this client, if any.
|
|
5
|
-
*
|
|
6
|
-
* Only a browser sends it: the value names the browser bundle, so a server
|
|
7
|
-
* (Node, Deno, a backend function) or React Native would report a commit that
|
|
8
|
-
* isn't the one running.
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export declare function getBuildCommitHeaders(): Record<string, string>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isNode, isReactNative } from "./common.js";
|
|
2
|
-
import { readBuildCommitSource } from "#build-commit-source";
|
|
3
|
-
/** Header the backend reads to tell which frontend build sent a request. */
|
|
4
|
-
export const BUILD_COMMIT_HEADER = "X-Base44-Build";
|
|
5
|
-
// The backend accepts exactly this shape and ignores anything else, so a value
|
|
6
|
-
// that doesn't match is never sent.
|
|
7
|
-
const BUILD_COMMIT_PATTERN = /^[a-f0-9]{40}$/;
|
|
8
|
-
/**
|
|
9
|
-
* The build-commit header to send from this client, if any.
|
|
10
|
-
*
|
|
11
|
-
* Only a browser sends it: the value names the browser bundle, so a server
|
|
12
|
-
* (Node, Deno, a backend function) or React Native would report a commit that
|
|
13
|
-
* isn't the one running.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export function getBuildCommitHeaders() {
|
|
18
|
-
if (isNode || isReactNative)
|
|
19
|
-
return {};
|
|
20
|
-
const commit = readBuildCommitSource();
|
|
21
|
-
return typeof commit === "string" && BUILD_COMMIT_PATTERN.test(commit)
|
|
22
|
-
? { [BUILD_COMMIT_HEADER]: commit }
|
|
23
|
-
: {};
|
|
24
|
-
}
|