@base44-preview/platform 0.1.0-pr.319.1e807d1 → 0.1.0-pr.319.3e74a61
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/README.md +7 -6
- package/dist/client/client.d.ts +9 -3
- package/dist/client/client.js +6 -5
- package/dist/client/client.types.d.ts +0 -6
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/modules/webhooks.d.ts +2 -2
- package/dist/server/modules/webhooks.js +6 -6
- package/dist/server/modules/webhooks.types.d.ts +8 -10
- package/dist/server/server.js +1 -1
- package/dist/server/server.types.d.ts +1 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,9 +10,9 @@ shared socket. It is independent of the app SDK (`@base44/sdk`).
|
|
|
10
10
|
The workspace must have white-label sockets enabled; this SDK does not open sessions.
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import {
|
|
13
|
+
import { Base44PlatformClient } from "@base44/platform";
|
|
14
14
|
|
|
15
|
-
const client =
|
|
15
|
+
const client = new Base44PlatformClient({
|
|
16
16
|
serverUrl: "https://base44.app",
|
|
17
17
|
async getSessionToken() {
|
|
18
18
|
const response = await fetch("/api/builder-socket-session", { method: "POST" });
|
|
@@ -38,7 +38,7 @@ builder.close();
|
|
|
38
38
|
|
|
39
39
|
`@base44/platform/server` verifies Base44 outbound webhooks and answers the endpoint
|
|
40
40
|
activation challenge. It uses WebCrypto only (Node 20+, Deno, Bun, Workers, edge runtimes) and
|
|
41
|
-
makes no network calls: pass your workspace's public keys (`whpk_…`)
|
|
41
|
+
makes no network calls: pass your workspace's public keys (`whpk_…`) to each call that verifies.
|
|
42
42
|
|
|
43
43
|
The simplest route is `createHandler`. It reads the raw body, verifies it, answers the
|
|
44
44
|
activation challenge and picks the status code: 400 for a delivery that fails verification,
|
|
@@ -51,10 +51,11 @@ import { createBase44PlatformServer } from "@base44/platform/server";
|
|
|
51
51
|
const platform = createBase44PlatformServer({
|
|
52
52
|
serverUrl: "https://base44.app",
|
|
53
53
|
apiKey: process.env.BASE44_API_KEY!,
|
|
54
|
-
webhooks: { publicKeys: process.env.BASE44_WEBHOOK_PUBLIC_KEYS },
|
|
55
54
|
});
|
|
55
|
+
const publicKeys = process.env.BASE44_WEBHOOK_PUBLIC_KEYS!; // two keys during a rotation
|
|
56
56
|
|
|
57
57
|
export const POST = platform.webhooks.createHandler({
|
|
58
|
+
publicKeys,
|
|
58
59
|
on: {
|
|
59
60
|
"app.deleted.v1": async event => forget(event.data.app_id), // event is narrowed per type
|
|
60
61
|
},
|
|
@@ -71,7 +72,7 @@ export async function POST(request: Request) {
|
|
|
71
72
|
const rawBody = await request.text(); // exactly as received
|
|
72
73
|
let event;
|
|
73
74
|
try {
|
|
74
|
-
event = await platform.webhooks.verifyEvent(rawBody, request.headers);
|
|
75
|
+
event = await platform.webhooks.verifyEvent(rawBody, request.headers, { publicKeys });
|
|
75
76
|
} catch (error) {
|
|
76
77
|
if (error instanceof WebhookVerificationError) return new Response(null, { status: 400 });
|
|
77
78
|
throw error; // missing/malformed keys: a 500, so Base44 retries
|
|
@@ -109,7 +110,7 @@ older one, which stops with `session_replaced`. Open one session per page.
|
|
|
109
110
|
|
|
110
111
|
## Lifecycle
|
|
111
112
|
|
|
112
|
-
`
|
|
113
|
+
`new Base44PlatformClient({ serverUrl, getSessionToken })` creates a lightweight module
|
|
113
114
|
container: no Socket.IO instance, timers, token request or network activity. Its
|
|
114
115
|
`builder` module follows the server SDK's module-factory pattern.
|
|
115
116
|
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { PlatformClientOptions } from "./client.types.js";
|
|
2
|
+
import type { BuilderModule } from "./modules/builder.types.js";
|
|
3
|
+
/** Browser platform client. Construction creates no sockets, timers or network requests. */
|
|
4
|
+
export declare class Base44PlatformClient {
|
|
5
|
+
/** Lazy builder subscriptions with independent session lifecycles. */
|
|
6
|
+
readonly builder: BuilderModule;
|
|
7
|
+
/** Configure shared service/auth settings; each module initializes its own resources. */
|
|
8
|
+
constructor(options: PlatformClientOptions);
|
|
9
|
+
}
|
package/dist/client/client.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { normalizeServerUrl } from "../shared/server-url.js";
|
|
2
2
|
import { createBuilder } from "./modules/builder.js";
|
|
3
|
-
/**
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/** Browser platform client. Construction creates no sockets, timers or network requests. */
|
|
4
|
+
export class Base44PlatformClient {
|
|
5
|
+
/** Configure shared service/auth settings; each module initializes its own resources. */
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.builder = Object.freeze(createBuilder({ ...options, serverUrl: normalizeServerUrl(options.serverUrl) }));
|
|
8
|
+
}
|
|
8
9
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { BuilderModule } from "./modules/builder.types.js";
|
|
2
1
|
/** Shared configuration for browser platform modules. Never supply an API key. */
|
|
3
2
|
export interface PlatformClientOptions {
|
|
4
3
|
/** Origin of the platform service, e.g. https://base44.app. No path/query/credentials. */
|
|
@@ -11,8 +10,3 @@ export interface PlatformClientOptions {
|
|
|
11
10
|
*/
|
|
12
11
|
getSessionToken: () => string | Promise<string>;
|
|
13
12
|
}
|
|
14
|
-
/** Browser platform client, returned by `createBase44PlatformClient`. */
|
|
15
|
-
export interface Base44PlatformClient {
|
|
16
|
-
/** Lazy builder subscriptions with independent session lifecycles. */
|
|
17
|
-
readonly builder: BuilderModule;
|
|
18
|
-
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Browser platform modules, separate from the runtime and server SDKs. */
|
|
2
|
-
export {
|
|
2
|
+
export { Base44PlatformClient } from "./client.js";
|
|
3
3
|
export { PlatformSocketError } from "./errors.js";
|
|
4
4
|
export type { PlatformSocketErrorCode } from "./errors.types.js";
|
|
5
|
-
export type {
|
|
5
|
+
export type { PlatformClientOptions } from "./client.types.js";
|
|
6
6
|
export type { BuilderModule, BuilderInitOptions, BuilderSession, PlatformSubscription, SubscriptionOptions } from "./modules/builder.types.js";
|
|
7
7
|
export type { AppStatus, AppStatusChanged, BranchScoped, ChatMessage, ImageResolved, MessageParams, MessageRemoved, MessageUpdated, PlatformEvent, PlatformEventMap, PreviewNavigationRequested, QueueItem, QueueUpdated, Snapshot, SnapshotQueue, TaskProgressed, ToolArguments, ToolCall, ToolDisplay, ToolEntityMutationArguments, ToolGuardApproval, ToolMediaArguments, ToolMediaResult, ToolPackageArguments, ToolPackageOperation, ToolPlanArguments, ToolPlanUpdate, ToolPrdArguments, ToolQuestion, ToolQuestionAnswer, ToolQuestionArguments, ToolQuestionInput, ToolQuestionOption, ToolSecretArguments, ToolSecretField, } from "./modules/builder.events.types.js";
|
package/dist/client/index.js
CHANGED
package/dist/server/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { createBase44PlatformServer } from "./server.js";
|
|
|
3
3
|
export { WebhookConfigurationError, WebhookVerificationError } from "./errors.js";
|
|
4
4
|
export type { WebhookConfigurationErrorCode, WebhookVerificationErrorCode } from "./errors.types.js";
|
|
5
5
|
export type { Base44PlatformServer, PlatformServerOptions } from "./server.types.js";
|
|
6
|
-
export type { AppCreatedV1Data, AppDeletedV1Data, AppPublishedV1Data, AppRestoredV1Data, AppUnpublishedV1Data, CloudEvent, CreateHandlerOptions, DeliveredWebhookEvent, VerifyEventOptions, WebhookEventHandlers, WebhookEvent, WebhookEventMap, WebhookEventType, WebhookHeaders, WebhookPublicKeys, WebhooksModule,
|
|
6
|
+
export type { AppCreatedV1Data, AppDeletedV1Data, AppPublishedV1Data, AppRestoredV1Data, AppUnpublishedV1Data, CloudEvent, CreateHandlerOptions, DeliveredWebhookEvent, VerifyEventOptions, WebhookEventHandlers, WebhookEvent, WebhookEventMap, WebhookEventType, WebhookHeaders, WebhookPublicKeys, WebhooksModule, WebhookTestV1Data, } from "./modules/webhooks.types.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { WebhooksModule
|
|
1
|
+
import type { WebhooksModule } from "./webhooks.types.js";
|
|
2
2
|
/** Webhook receiving utilities. Verification is local: no network calls, no timers. */
|
|
3
|
-
export declare function createWebhooks(
|
|
3
|
+
export declare function createWebhooks(): WebhooksModule;
|
|
@@ -2,26 +2,26 @@ import { WebhookConfigurationError, WebhookVerificationError } from "../errors.j
|
|
|
2
2
|
import { anySignatureVerifies, importPublicKey, parsePublicKeys, parseSignatures, readHeader, signedPayload } from "./webhooks-signature.js";
|
|
3
3
|
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
4
4
|
/** Webhook receiving utilities. Verification is local: no network calls, no timers. */
|
|
5
|
-
export function createWebhooks(
|
|
5
|
+
export function createWebhooks() {
|
|
6
6
|
// Imported keys are cached by their wire form so a pinned key is imported once.
|
|
7
7
|
const imported = new Map();
|
|
8
|
-
const keysFor = (publicKeys
|
|
8
|
+
const keysFor = (publicKeys) => Promise.all(parsePublicKeys(publicKeys).map(raw => {
|
|
9
9
|
const id = raw.join(",");
|
|
10
10
|
if (!imported.has(id))
|
|
11
11
|
imported.set(id, importPublicKey(raw));
|
|
12
12
|
return imported.get(id);
|
|
13
13
|
}));
|
|
14
|
-
const verifyEvent = async (body, headers, verifyOptions
|
|
14
|
+
const verifyEvent = async (body, headers, verifyOptions) => {
|
|
15
15
|
var _a;
|
|
16
16
|
// Configuration problems surface first, whatever the request looks like: a missing key is ours to fix.
|
|
17
|
-
const keys = await keysFor(verifyOptions.publicKeys);
|
|
17
|
+
const keys = await keysFor(verifyOptions === null || verifyOptions === void 0 ? void 0 : verifyOptions.publicKeys);
|
|
18
18
|
const id = readHeader(headers, "webhook-id");
|
|
19
19
|
const timestamp = readHeader(headers, "webhook-timestamp");
|
|
20
20
|
const signature = readHeader(headers, "webhook-signature", " ");
|
|
21
21
|
if (!id || !timestamp || !signature)
|
|
22
22
|
throw new WebhookVerificationError("missing_headers");
|
|
23
23
|
// Negated so a non-numeric timestamp (NaN) is refused too.
|
|
24
|
-
if (!(Math.abs(Date.now() / 1000 - Number(timestamp)) <= ((_a = verifyOptions.toleranceSeconds) !== null && _a !== void 0 ? _a : DEFAULT_TOLERANCE_SECONDS))) {
|
|
24
|
+
if (!(Math.abs(Date.now() / 1000 - Number(timestamp)) <= ((_a = verifyOptions === null || verifyOptions === void 0 ? void 0 : verifyOptions.toleranceSeconds) !== null && _a !== void 0 ? _a : DEFAULT_TOLERANCE_SECONDS))) {
|
|
25
25
|
throw new WebhookVerificationError("timestamp_outside_tolerance");
|
|
26
26
|
}
|
|
27
27
|
const signatures = parseSignatures(signature);
|
|
@@ -46,7 +46,7 @@ export function createWebhooks(options = {}) {
|
|
|
46
46
|
};
|
|
47
47
|
return {
|
|
48
48
|
verifyEvent,
|
|
49
|
-
createHandler({ on = {}, onEvent, onSuccess, onError, ...verifyOptions }
|
|
49
|
+
createHandler({ on = {}, onEvent, onSuccess, onError, ...verifyOptions }) {
|
|
50
50
|
const fail = async (error, status, event) => {
|
|
51
51
|
var _a;
|
|
52
52
|
return (_a = (await (onError === null || onError === void 0 ? void 0 : onError(error, event)))) !== null && _a !== void 0 ? _a : Response.json({ error: error instanceof WebhookVerificationError ? error.code : error instanceof WebhookConfigurationError ? "receiver_misconfigured" : "handler_failed" }, { status });
|
|
@@ -42,15 +42,13 @@ export type WebhookEvent = {
|
|
|
42
42
|
export type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
43
43
|
/** One Ed25519 public key (`whpk_…`), or several separated by commas or whitespace. */
|
|
44
44
|
export type WebhookPublicKeys = string | string[];
|
|
45
|
-
/**
|
|
46
|
-
export interface WebhooksOptions {
|
|
47
|
-
/** Public keys of your workspace. Pass more than one while a key rotation is in progress. */
|
|
48
|
-
publicKeys?: WebhookPublicKeys;
|
|
49
|
-
}
|
|
50
|
-
/** Per-call overrides for `verifyEvent`. */
|
|
45
|
+
/** Options for `verifyEvent`. */
|
|
51
46
|
export interface VerifyEventOptions {
|
|
52
|
-
/**
|
|
53
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Your workspace's public keys. Pass more than one while a key rotation is in progress.
|
|
49
|
+
* Missing or malformed keys reject with `WebhookConfigurationError`.
|
|
50
|
+
*/
|
|
51
|
+
publicKeys: WebhookPublicKeys;
|
|
54
52
|
/** Maximum age or clock skew of a delivery, in seconds. Defaults to 300. */
|
|
55
53
|
toleranceSeconds?: number;
|
|
56
54
|
}
|
|
@@ -91,12 +89,12 @@ export interface WebhooksModule {
|
|
|
91
89
|
* or malformed (let it surface as a 500 so Base44 retries). To activate an endpoint, answer
|
|
92
90
|
* the `webhook.test.v1` event with `{ "challenge": event.data.challenge }`.
|
|
93
91
|
*/
|
|
94
|
-
verifyEvent(body: string | Uint8Array, headers: WebhookHeaders, options
|
|
92
|
+
verifyEvent(body: string | Uint8Array, headers: WebhookHeaders, options: VerifyEventOptions): Promise<WebhookEvent>;
|
|
95
93
|
/**
|
|
96
94
|
* Build a fetch-style route handler (`(request: Request) => Promise<Response>`) for Next.js, Hono,
|
|
97
95
|
* Cloudflare Workers, Deno or Bun. It reads the raw body, verifies it, answers the activation
|
|
98
96
|
* challenge, then runs your callbacks. Delivery is at least once, so handlers must tolerate
|
|
99
97
|
* the same event (same `event.id`) arriving twice.
|
|
100
98
|
*/
|
|
101
|
-
createHandler(options
|
|
99
|
+
createHandler(options: CreateHandlerOptions): (request: Request) => Promise<Response>;
|
|
102
100
|
}
|
package/dist/server/server.js
CHANGED
|
@@ -6,6 +6,6 @@ export function createBase44PlatformServer(options) {
|
|
|
6
6
|
throw new TypeError("apiKey is required");
|
|
7
7
|
normalizeServerUrl(options.serverUrl);
|
|
8
8
|
return Object.freeze({
|
|
9
|
-
webhooks: Object.freeze(createWebhooks(
|
|
9
|
+
webhooks: Object.freeze(createWebhooks()),
|
|
10
10
|
});
|
|
11
11
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { WebhooksModule
|
|
1
|
+
import type { WebhooksModule } from "./modules/webhooks.types.js";
|
|
2
2
|
/** Shared configuration for server platform modules. */
|
|
3
3
|
export interface PlatformServerOptions {
|
|
4
4
|
/** Origin of the platform service, e.g. https://base44.app. No path/query/credentials. */
|
|
5
5
|
serverUrl: string;
|
|
6
6
|
/** Workspace API key. Keep it on your server; never ship it to a browser. */
|
|
7
7
|
apiKey: string;
|
|
8
|
-
/** Webhook receiving settings. */
|
|
9
|
-
webhooks?: WebhooksOptions;
|
|
10
8
|
}
|
|
11
9
|
/** Server platform client, returned by `createBase44PlatformServer`. */
|
|
12
10
|
export interface Base44PlatformServer {
|
package/package.json
CHANGED