@base44-preview/sdk 0.8.59-pr.372.142c509 → 0.8.60-pr.375.db5e899
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 +20 -3
- package/dist/index.d.ts +1 -1
- package/dist/modules/integrations.types.d.ts +53 -5
- package/dist/utils/build-commit-source.d.ts +19 -0
- package/dist/utils/build-commit-source.fallback.d.ts +14 -0
- package/dist/utils/build-commit-source.fallback.js +16 -0
- package/dist/utils/build-commit-source.js +26 -0
- package/dist/utils/build-commit.d.ts +12 -0
- package/dist/utils/build-commit.js +24 -0
- package/package.json +8 -1
package/dist/client.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createVoiceModule } from "./modules/voice.js";
|
|
|
8
8
|
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
9
9
|
import { getAccessToken } 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";
|
|
11
12
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
12
13
|
import { createAgentsModule } from "./modules/agents.js";
|
|
13
14
|
import { createAiGatewayModule } from "./modules/ai-gateway.js";
|
|
@@ -56,6 +57,9 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
56
57
|
* ```
|
|
57
58
|
*/
|
|
58
59
|
export function createClient(config) {
|
|
60
|
+
return buildClient(config, { sendBuildCommit: true });
|
|
61
|
+
}
|
|
62
|
+
function buildClient(config, { sendBuildCommit }) {
|
|
59
63
|
var _a, _b, _c, _d;
|
|
60
64
|
const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
61
65
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
@@ -76,7 +80,18 @@ export function createClient(config) {
|
|
|
76
80
|
}
|
|
77
81
|
return socket;
|
|
78
82
|
};
|
|
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
|
+
: {};
|
|
79
93
|
const headers = {
|
|
94
|
+
...(callerBuildCommit ? {} : buildCommitHeaders),
|
|
80
95
|
...optionalHeaders,
|
|
81
96
|
"X-App-Id": String(appId),
|
|
82
97
|
};
|
|
@@ -179,7 +194,7 @@ export function createClient(config) {
|
|
|
179
194
|
auth: userAuthModule,
|
|
180
195
|
functions: createFunctionsModule(functionsAxiosClient, appId, {
|
|
181
196
|
getAuthHeaders: () => {
|
|
182
|
-
const headers = {};
|
|
197
|
+
const headers = { ...buildCommitHeaders };
|
|
183
198
|
// Get current token from storage or initial config
|
|
184
199
|
const currentToken = token || getAccessToken();
|
|
185
200
|
if (currentToken) {
|
|
@@ -456,12 +471,14 @@ export function createClientFromRequest(request) {
|
|
|
456
471
|
if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
|
|
457
472
|
additionalHeaders["X-Data-Env"] = dataEnvHeader;
|
|
458
473
|
}
|
|
459
|
-
|
|
474
|
+
// A backend function isn't the browser bundle, so it never reports a build
|
|
475
|
+
// commit, whatever its runtime looks like.
|
|
476
|
+
return buildClient({
|
|
460
477
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
461
478
|
appId,
|
|
462
479
|
token: userToken,
|
|
463
480
|
serviceToken: serviceRoleToken,
|
|
464
481
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
465
482
|
headers: additionalHeaders,
|
|
466
|
-
});
|
|
483
|
+
}, { sendBuildCommit: false });
|
|
467
484
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { Base44Client, CreateClientAnalyticsConfig, CreateClientConfig, Cre
|
|
|
6
6
|
export * from "./types.js";
|
|
7
7
|
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucket, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
|
-
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
9
|
+
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, EmailAttachment, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
|
|
@@ -86,6 +86,21 @@ export interface UploadFileResult {
|
|
|
86
86
|
/** URL of the uploaded file. */
|
|
87
87
|
file_url: string;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* A file to attach to an email.
|
|
91
|
+
*/
|
|
92
|
+
export interface EmailAttachment {
|
|
93
|
+
/**
|
|
94
|
+
* File name the recipient sees, including the extension. The supported extensions are `csv`, `docx`, `gif`, `ics`, `jpeg`, `jpg`, `md`, `pdf`, `png`, `txt`, `webp`, and `xlsx`.
|
|
95
|
+
*/
|
|
96
|
+
filename: string;
|
|
97
|
+
/**
|
|
98
|
+
* A file your app already uploaded, such as the `file_url` returned by [`UploadFile()`](#uploadfile) or the `file_uri` returned by [`UploadPrivateFile()`](#uploadprivatefile). Files uploaded by other apps are rejected.
|
|
99
|
+
*/
|
|
100
|
+
file_url?: string;
|
|
101
|
+
/** Base64-encoded file contents, for a file your code generated. */
|
|
102
|
+
content?: string;
|
|
103
|
+
}
|
|
89
104
|
/**
|
|
90
105
|
* Parameters for the SendEmail function.
|
|
91
106
|
*/
|
|
@@ -94,10 +109,18 @@ export interface SendEmailParams {
|
|
|
94
109
|
to: string;
|
|
95
110
|
/** Email subject line. */
|
|
96
111
|
subject: string;
|
|
97
|
-
/**
|
|
98
|
-
body
|
|
99
|
-
/** The
|
|
112
|
+
/** HTML email body. The same as `html`, so set one or the other, not both. */
|
|
113
|
+
body?: string;
|
|
114
|
+
/** HTML email body. The same as `body`, so set one or the other, not both. */
|
|
115
|
+
html?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Plain-text email body. On its own, it sends a plain-text email. Set it together with `body` or `html` to send both versions in one email, and the recipient's mail client shows whichever it prefers. Make sure both versions say the same thing.
|
|
118
|
+
*/
|
|
119
|
+
text?: string;
|
|
120
|
+
/** The name of the sender. If omitted, the app's name is used. */
|
|
100
121
|
from_name?: string;
|
|
122
|
+
/** Files to attach. You can attach up to 5 files, up to 5 MB each and 10 MB in total. Set `filename` and exactly one of `file_url` or `content` on each file. */
|
|
123
|
+
attachments?: EmailAttachment[];
|
|
101
124
|
}
|
|
102
125
|
export type SendEmailResult = any;
|
|
103
126
|
/**
|
|
@@ -236,10 +259,35 @@ export interface CoreIntegrations {
|
|
|
236
259
|
*/
|
|
237
260
|
UploadFile(params: UploadFileParams): Promise<UploadFileResult>;
|
|
238
261
|
/**
|
|
239
|
-
* Send
|
|
262
|
+
* Send an email from your app.
|
|
263
|
+
*
|
|
264
|
+
* You can always email registered users of your app. To email anyone else, the app needs a paid plan and a connected custom domain.
|
|
240
265
|
*
|
|
241
|
-
* @param params - Parameters for sending email
|
|
266
|
+
* @param params - Parameters for sending email. Set at least one of `body`, `html`, or `text`.
|
|
242
267
|
* @returns Promise resolving when the email is sent.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* // Send an HTML email with a plain-text version
|
|
272
|
+
* await base44.integrations.Core.SendEmail({
|
|
273
|
+
* to: "user@example.com",
|
|
274
|
+
* subject: "Your order has shipped",
|
|
275
|
+
* html: "<p>Your order <strong>#1234</strong> is on its way.</p>",
|
|
276
|
+
* text: "Your order #1234 is on its way.",
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // Attach a file your app uploaded
|
|
283
|
+
* const { file_url } = await base44.integrations.Core.UploadFile({ file });
|
|
284
|
+
* await base44.integrations.Core.SendEmail({
|
|
285
|
+
* to: "user@example.com",
|
|
286
|
+
* subject: "Your invoice",
|
|
287
|
+
* html: "<p>Your invoice is attached.</p>",
|
|
288
|
+
* attachments: [{ filename: "invoice.pdf", file_url }],
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
243
291
|
*/
|
|
244
292
|
SendEmail(params: SendEmailParams): Promise<SendEmailResult>;
|
|
245
293
|
/**
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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>;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.60-pr.375.db5e899",
|
|
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
|
+
},
|
|
7
13
|
"type": "module",
|
|
8
14
|
"files": [
|
|
9
15
|
"dist"
|
|
@@ -16,6 +22,7 @@
|
|
|
16
22
|
"test:e2e": "vitest run tests/e2e",
|
|
17
23
|
"test:watch": "vitest",
|
|
18
24
|
"test:coverage": "vitest run --coverage",
|
|
25
|
+
"test:build-commit": "scripts/verify-build-commit.sh",
|
|
19
26
|
"docs": "typedoc",
|
|
20
27
|
"prepublishOnly": "npm run build",
|
|
21
28
|
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|