@base44-preview/platform 0.1.0-pr.319.cf89f7f → 0.1.0-pr.332.30ac6b3
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 +71 -124
- package/dist/client/client.d.ts +30 -9
- package/dist/client/client.js +30 -7
- package/dist/client/client.types.d.ts +9 -11
- package/dist/client/errors.d.ts +41 -4
- package/dist/client/errors.js +39 -2
- package/dist/client/errors.types.d.ts +98 -2
- package/dist/client/index.d.ts +6 -5
- package/dist/client/index.js +1 -1
- package/dist/client/modules/builder-protocol.d.ts +16 -5
- package/dist/client/modules/builder-protocol.js +30 -8
- package/dist/client/modules/builder-socket.d.ts +10 -5
- package/dist/client/modules/builder-socket.js +114 -87
- package/dist/client/modules/builder-subscription.d.ts +2 -2
- package/dist/client/modules/builder.d.ts +1 -2
- package/dist/client/modules/builder.events.generated.d.ts +2194 -0
- package/dist/client/modules/builder.events.generated.js +3 -0
- package/dist/client/modules/builder.events.types.d.ts +70 -361
- package/dist/client/modules/builder.js +2 -2
- package/dist/client/modules/builder.types.d.ts +169 -23
- package/dist/server/index.d.ts +2 -5
- package/dist/server/index.js +1 -2
- package/dist/server/server-url.d.ts +2 -0
- package/dist/{shared → server}/server-url.js +1 -1
- package/dist/server/server.d.ts +2 -2
- package/dist/server/server.js +3 -6
- package/dist/server/server.types.d.ts +2 -7
- package/package.json +17 -13
- package/dist/server/errors.d.ts +0 -15
- package/dist/server/errors.js +0 -18
- package/dist/server/errors.types.d.ts +0 -4
- package/dist/server/errors.types.js +0 -1
- package/dist/server/modules/webhooks-signature.d.ts +0 -11
- package/dist/server/modules/webhooks-signature.js +0 -65
- package/dist/server/modules/webhooks.d.ts +0 -3
- package/dist/server/modules/webhooks.events.generated.d.ts +0 -174
- package/dist/server/modules/webhooks.events.generated.js +0 -3
- package/dist/server/modules/webhooks.js +0 -77
- package/dist/server/modules/webhooks.types.d.ts +0 -102
- package/dist/server/modules/webhooks.types.js +0 -1
- package/dist/shared/server-url.d.ts +0 -2
|
@@ -1,47 +1,193 @@
|
|
|
1
|
-
import type { PlatformEvent,
|
|
1
|
+
import type { PlatformEvent, PlatformSnapshot } from "./builder.events.types.js";
|
|
2
2
|
import type { PlatformSocketError } from "../errors.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The socket session your server opened, as [Create socket session](/api-reference/create-socket-session) returned it.
|
|
5
|
+
*
|
|
6
|
+
* Pass the response body through unchanged. The client reads these three fields and ignores the
|
|
7
|
+
* rest, such as `session_id` and `expires_in`.
|
|
8
|
+
*/
|
|
9
|
+
export interface SocketSession {
|
|
10
|
+
/** Token that authenticates the socket. The client keeps it in memory and sends it only when the socket connects. */
|
|
11
|
+
session_token: string;
|
|
12
|
+
/** Origin of the platform socket, with no path, query, fragment or credentials. */
|
|
13
|
+
socket_url: string;
|
|
14
|
+
/** Absolute path the socket connects on, such as `/ws/socket.io/`. */
|
|
15
|
+
socket_path: string;
|
|
16
|
+
}
|
|
17
|
+
/** Options for {@linkcode BuilderModule.init | init()}. */
|
|
4
18
|
export interface BuilderInitOptions {
|
|
5
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Returns a new socket session from your server.
|
|
21
|
+
*
|
|
22
|
+
* Your server opens the session with its workspace API key through
|
|
23
|
+
* [Create socket session](/api-reference/create-socket-session) and returns the response body, a [`SocketSession`](#socketsession).
|
|
24
|
+
* The client calls this on the first `connect()`, and again only when the session expires or
|
|
25
|
+
* Base44 rejects its token. Return a new session on every call. If a new session has a different
|
|
26
|
+
* `socket_url` or `socket_path`, the client moves to it and rejoins every active subscription.
|
|
27
|
+
*
|
|
28
|
+
* @returns The session, as your server received it.
|
|
29
|
+
*/
|
|
30
|
+
getSession: () => Promise<SocketSession>;
|
|
31
|
+
/**
|
|
32
|
+
* Called on errors that affect the whole session, such as a failed connection or an ended session.
|
|
33
|
+
* Errors for one app go to that subscription's `onError` instead. See the
|
|
34
|
+
* [error codes](/developers/references/platform-sdk/docs/classes/PlatformSocketError#platformsocketerrorcode).
|
|
35
|
+
*/
|
|
6
36
|
onError: (error: PlatformSocketError) => void;
|
|
7
37
|
}
|
|
8
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Builder module for following the AI chat in your users' apps live.
|
|
40
|
+
*
|
|
41
|
+
* Each session holds one socket and up to eight app subscriptions. For each app you get a
|
|
42
|
+
* snapshot of its chat, then every change as it happens:
|
|
43
|
+
* - New and updated chat messages, with the AI's tool calls.
|
|
44
|
+
* - The AI's status, from processing to ready.
|
|
45
|
+
* - Preview reloads and navigation, the prompt queue, and generated images.
|
|
46
|
+
*
|
|
47
|
+
* The module does nothing until you call {@linkcode init | init()}.
|
|
48
|
+
*/
|
|
9
49
|
export interface BuilderModule {
|
|
10
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Creates a builder session without connecting it.
|
|
52
|
+
*
|
|
53
|
+
* Call {@linkcode BuilderSession.connect | connect()} on the returned session to open the socket.
|
|
54
|
+
* Each session is independent, with its own socket, socket session and subscriptions.
|
|
55
|
+
*
|
|
56
|
+
* @param options - Session options.
|
|
57
|
+
* @returns The new session.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Create and connect a session
|
|
62
|
+
* const builder = client.builder.init({
|
|
63
|
+
* async getSession() {
|
|
64
|
+
* const response = await fetch('/api/builder-socket-session', { method: 'POST' });
|
|
65
|
+
* return response.json();
|
|
66
|
+
* },
|
|
67
|
+
* onError(error) {
|
|
68
|
+
* console.error('Builder session error', error.code);
|
|
69
|
+
* },
|
|
70
|
+
* });
|
|
71
|
+
* await builder.connect();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
11
74
|
init(options: BuilderInitOptions): BuilderSession;
|
|
12
75
|
}
|
|
13
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* A `BuilderSession`: one socket with its app subscriptions and its reconnection. Use its methods
|
|
78
|
+
* to connect, follow apps and close.
|
|
79
|
+
*/
|
|
14
80
|
export interface BuilderSession {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
81
|
+
/**
|
|
82
|
+
* Connects the session's socket.
|
|
83
|
+
*
|
|
84
|
+
* Resolves once the socket connects, before any snapshot arrives. If the connection drops, the
|
|
85
|
+
* session retries five times and rejoins every active subscription, each with a fresh snapshot.
|
|
86
|
+
* The first call fetches a session through `getSession`, and an expired or rejected token is
|
|
87
|
+
* replaced once the same way. Concurrent calls share one attempt. Call it again after a failure or a `session_replaced` error.
|
|
88
|
+
*
|
|
89
|
+
* @returns Promise that resolves when the socket connects.
|
|
90
|
+
* @throws {PlatformSocketError} With `connection_denied`, `connection_failed` or `session_unavailable`
|
|
91
|
+
* when the session can't connect, or `client_closed` when the session is closed first.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Connect and handle failure
|
|
96
|
+
* try {
|
|
97
|
+
* await builder.connect();
|
|
98
|
+
* } catch (error) {
|
|
99
|
+
* console.error('Could not connect', error.code);
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
19
102
|
*/
|
|
20
103
|
connect(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
104
|
+
/**
|
|
105
|
+
* Subscribes to one app's chat.
|
|
106
|
+
*
|
|
107
|
+
* You can subscribe before or after connecting. Each app can have one subscription per session,
|
|
108
|
+
* and a session can have up to eight. The app must be on the session's allowlist. The
|
|
109
|
+
* subscription first receives a snapshot of the app, then each live event.
|
|
110
|
+
*
|
|
111
|
+
* Callbacks for an app run one at a time, in order, and the session waits for a returned promise
|
|
112
|
+
* before the next one. A slow app doesn't hold up the others. If more than 1,000 deliveries wait
|
|
113
|
+
* for one app, its subscription ends with `delivery_overflow`.
|
|
114
|
+
*
|
|
115
|
+
* @param appId - ID of the app to follow, 24 lowercase hexadecimal characters.
|
|
116
|
+
* @param options - Callbacks for the app's snapshots, events and errors.
|
|
117
|
+
* @returns The subscription.
|
|
118
|
+
* @throws {TypeError} When `appId` isn't a valid app ID or the app already has a subscription.
|
|
119
|
+
* @throws {PlatformSocketError} With `subscription_limit` when the session has eight subscriptions.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Follow an app
|
|
124
|
+
* const subscription = builder.subscribe(appId, {
|
|
125
|
+
* onSnapshot(snapshot) {
|
|
126
|
+
* renderChat(snapshot.messages);
|
|
127
|
+
* },
|
|
128
|
+
* onEvent(event) {
|
|
129
|
+
* if (event.type === 'message.updated') upsertMessage(event.data.message);
|
|
130
|
+
* },
|
|
131
|
+
* onError(error) {
|
|
132
|
+
* console.error(`App ${error.appId}`, error.code);
|
|
133
|
+
* },
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
23
136
|
*/
|
|
24
137
|
subscribe(appId: string, options: SubscriptionOptions): PlatformSubscription;
|
|
25
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Closes the session.
|
|
140
|
+
*
|
|
141
|
+
* Ends every subscription, stops reconnecting and disconnects the socket. Calling it again does
|
|
142
|
+
* nothing. A closed session can't be reused, so call [`init()`](/developers/references/platform-sdk/docs/interfaces/builder#init)
|
|
143
|
+
* for a new one.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Close a session
|
|
148
|
+
* builder.close();
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
26
151
|
close(): void;
|
|
27
152
|
}
|
|
28
|
-
/**
|
|
153
|
+
/** Callbacks for one app subscription. */
|
|
29
154
|
export interface SubscriptionOptions {
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
155
|
+
/**
|
|
156
|
+
* Called with the app's current state, a [`PlatformSnapshot`](#platformsnapshot). Replace everything you hold for the app with it.
|
|
157
|
+
*
|
|
158
|
+
* Arrives after every join and rejoin, and after the main conversation is rewritten by an undo,
|
|
159
|
+
* restore or sync. Live events follow it. It holds only the last 50 messages, so merge by message
|
|
160
|
+
* ID to keep older history.
|
|
161
|
+
*/
|
|
162
|
+
onSnapshot: (snapshot: PlatformSnapshot) => void | Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Called with each live event, a [`PlatformEvent`](#platformevent). Events for an app arrive one at a time, in order. If the callback
|
|
165
|
+
* throws or rejects, the subscription ends with `handler_failed`. New event types can be added at
|
|
166
|
+
* any time, so ignore types you don't handle. An event newer than this SDK arrives with
|
|
167
|
+
* `type: "unknown"` and its name in `name`. For every event and its payload,
|
|
168
|
+
* see [Socket messages](/developers/references/apps-api/sections/socket-messages).
|
|
32
169
|
*/
|
|
33
|
-
onSnapshot: (snapshot: Snapshot) => void | Promise<void>;
|
|
34
|
-
/** Apply each live event. Delivery is serial per app; a rejection ends this subscription. */
|
|
35
170
|
onEvent: (event: PlatformEvent) => void | Promise<void>;
|
|
36
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Called on errors for this app. Every error ends the subscription except `snapshot_unavailable`.
|
|
173
|
+
* See the [error codes](/developers/references/platform-sdk/docs/classes/PlatformSocketError#platformsocketerrorcode).
|
|
174
|
+
*/
|
|
37
175
|
onError: (error: PlatformSocketError) => void;
|
|
38
176
|
}
|
|
39
|
-
/** One app subscription
|
|
177
|
+
/** One app subscription. */
|
|
40
178
|
export interface PlatformSubscription {
|
|
41
|
-
/**
|
|
179
|
+
/** ID of the app. */
|
|
42
180
|
readonly appId: string;
|
|
43
|
-
/**
|
|
181
|
+
/** Whether the subscription still receives updates. It turns false after an error or {@linkcode unsubscribe | unsubscribe()}. */
|
|
44
182
|
readonly active: boolean;
|
|
45
|
-
/**
|
|
183
|
+
/**
|
|
184
|
+
* Stops updates for the app and frees its subscription slot. Calling it again does nothing.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Stop following an app
|
|
189
|
+
* subscription.unsubscribe();
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
46
192
|
unsubscribe(): void;
|
|
47
193
|
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
/** Server platform modules, authenticated with a workspace API key. */
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { WebhookConfigurationErrorCode, WebhookVerificationErrorCode } from "./errors.types.js";
|
|
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, WebhooksOptions, WebhookTestV1Data, } from "./modules/webhooks.types.js";
|
|
2
|
+
export { createPlatformServer } from "./server.js";
|
|
3
|
+
export type { PlatformServer, PlatformServerOptions } from "./server.types.js";
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Validate a platform origin and return it normalized.
|
|
1
|
+
/** Validate a platform origin and return it normalized. Used by the server entrypoint. */
|
|
2
2
|
export function normalizeServerUrl(serverUrl) {
|
|
3
3
|
const url = new URL(serverUrl);
|
|
4
4
|
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || url.pathname !== "/") {
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PlatformServer, PlatformServerOptions } from "./server.types.js";
|
|
2
2
|
/** Create a server platform client, authenticated with a workspace API key. Performs no network requests. */
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function createPlatformServer(options: PlatformServerOptions): PlatformServer;
|
package/dist/server/server.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { normalizeServerUrl } from "
|
|
2
|
-
import { createWebhooks } from "./modules/webhooks.js";
|
|
1
|
+
import { normalizeServerUrl } from "./server-url.js";
|
|
3
2
|
/** Create a server platform client, authenticated with a workspace API key. Performs no network requests. */
|
|
4
|
-
export function
|
|
3
|
+
export function createPlatformServer(options) {
|
|
5
4
|
if (!options.apiKey)
|
|
6
5
|
throw new TypeError("apiKey is required");
|
|
7
6
|
normalizeServerUrl(options.serverUrl);
|
|
8
|
-
return Object.freeze({
|
|
9
|
-
webhooks: Object.freeze(createWebhooks(options.webhooks)),
|
|
10
|
-
});
|
|
7
|
+
return Object.freeze({});
|
|
11
8
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type { WebhooksModule, WebhooksOptions } from "./modules/webhooks.types.js";
|
|
2
1
|
/** Shared configuration for server platform modules. */
|
|
3
2
|
export interface PlatformServerOptions {
|
|
4
3
|
/** Origin of the platform service, e.g. https://base44.app. No path/query/credentials. */
|
|
5
4
|
serverUrl: string;
|
|
6
5
|
/** Workspace API key. Keep it on your server; never ship it to a browser. */
|
|
7
6
|
apiKey: string;
|
|
8
|
-
/** Webhook receiving settings. */
|
|
9
|
-
webhooks?: WebhooksOptions;
|
|
10
7
|
}
|
|
11
|
-
/** Server platform client, returned by `
|
|
12
|
-
export interface
|
|
13
|
-
/** Verify Base44 outbound webhooks and answer the activation challenge. */
|
|
14
|
-
readonly webhooks: WebhooksModule;
|
|
8
|
+
/** Server platform client, returned by `createPlatformServer`. Modules are added as properties. */
|
|
9
|
+
export interface PlatformServer {
|
|
15
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/platform",
|
|
3
|
-
"version": "0.1.0-pr.
|
|
3
|
+
"version": "0.1.0-pr.332.30ac6b3",
|
|
4
4
|
"description": "Client and server SDK for building on the Base44 platform",
|
|
5
5
|
"main": "dist/client/index.js",
|
|
6
6
|
"types": "dist/client/index.d.ts",
|
|
@@ -16,6 +16,13 @@
|
|
|
16
16
|
},
|
|
17
17
|
"./package.json": "./package.json"
|
|
18
18
|
},
|
|
19
|
+
"typesVersions": {
|
|
20
|
+
"*": {
|
|
21
|
+
"server": [
|
|
22
|
+
"dist/server/index.d.ts"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
19
26
|
"files": [
|
|
20
27
|
"dist"
|
|
21
28
|
],
|
|
@@ -24,13 +31,20 @@
|
|
|
24
31
|
},
|
|
25
32
|
"scripts": {
|
|
26
33
|
"build": "tsc",
|
|
34
|
+
"gen:events": "node scripts/gen-events.mjs",
|
|
35
|
+
"check:events": "node scripts/gen-events.mjs --check",
|
|
36
|
+
"sync:asyncapi": "node scripts/sync-asyncapi.mjs",
|
|
27
37
|
"docs": "typedoc",
|
|
28
38
|
"test": "npm run test:types && npm run test:unit && npm run docs && npm run test:package",
|
|
29
39
|
"test:types": "tsc --noEmit -p tsconfig.type-tests.json",
|
|
30
40
|
"test:unit": "vitest run",
|
|
31
41
|
"test:package": "npm run build && node --test tests/package.test.mjs",
|
|
32
42
|
"prepublishOnly": "npm run build",
|
|
33
|
-
"
|
|
43
|
+
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|
|
44
|
+
"create-docs-local": "npm run create-docs && npm run copy-docs-local",
|
|
45
|
+
"copy-docs-local": "node ../sdk/scripts/mintlify-post-processing/copy-to-local-docs.js --package-dir .",
|
|
46
|
+
"create-docs:generate": "node -e \"fs.rmSync('docs',{recursive:true,force:true})\" && typedoc --options typedoc.mintlify.json",
|
|
47
|
+
"create-docs:process": "node ../sdk/scripts/mintlify-post-processing/file-processing/file-processing.js --package-dir ."
|
|
34
48
|
},
|
|
35
49
|
"dependencies": {
|
|
36
50
|
"socket.io-client": "^4.8.3"
|
|
@@ -51,17 +65,7 @@
|
|
|
51
65
|
"url": "https://github.com/base44/javascript-sdk/issues"
|
|
52
66
|
},
|
|
53
67
|
"homepage": "https://github.com/base44/javascript-sdk/tree/main/packages/platform#readme",
|
|
54
|
-
"typesVersions": {
|
|
55
|
-
"*": {
|
|
56
|
-
"server": [
|
|
57
|
-
"dist/server/index.d.ts"
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
68
|
"devDependencies": {
|
|
62
|
-
"json-schema-to-typescript": "
|
|
63
|
-
},
|
|
64
|
-
"engines": {
|
|
65
|
-
"node": ">=20"
|
|
69
|
+
"json-schema-to-typescript": "16.0.0"
|
|
66
70
|
}
|
|
67
71
|
}
|
package/dist/server/errors.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { WebhookConfigurationErrorCode, WebhookVerificationErrorCode } from "./errors.types.js";
|
|
2
|
-
/** A webhook delivery that cannot be trusted. The message never includes the body or signature. */
|
|
3
|
-
export declare class WebhookVerificationError extends Error {
|
|
4
|
-
/** Stable machine-readable reason. */
|
|
5
|
-
readonly code: WebhookVerificationErrorCode;
|
|
6
|
-
/** Create an error carrying only the reason. */
|
|
7
|
-
constructor(code: WebhookVerificationErrorCode);
|
|
8
|
-
}
|
|
9
|
-
/** Webhook public keys are missing or malformed, so no delivery can be verified. */
|
|
10
|
-
export declare class WebhookConfigurationError extends Error {
|
|
11
|
-
/** Stable machine-readable reason. */
|
|
12
|
-
readonly code: WebhookConfigurationErrorCode;
|
|
13
|
-
/** Create an error describing the misconfiguration. */
|
|
14
|
-
constructor(code: WebhookConfigurationErrorCode, detail: string);
|
|
15
|
-
}
|
package/dist/server/errors.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** A webhook delivery that cannot be trusted. The message never includes the body or signature. */
|
|
2
|
-
export class WebhookVerificationError extends Error {
|
|
3
|
-
/** Create an error carrying only the reason. */
|
|
4
|
-
constructor(code) {
|
|
5
|
-
super(`Webhook verification failed: ${code}`);
|
|
6
|
-
this.name = "WebhookVerificationError";
|
|
7
|
-
this.code = code;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
/** Webhook public keys are missing or malformed, so no delivery can be verified. */
|
|
11
|
-
export class WebhookConfigurationError extends Error {
|
|
12
|
-
/** Create an error describing the misconfiguration. */
|
|
13
|
-
constructor(code, detail) {
|
|
14
|
-
super(`Webhook configuration: ${detail}`);
|
|
15
|
-
this.name = "WebhookConfigurationError";
|
|
16
|
-
this.code = code;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** Why a delivery was refused. Respond 400: the request is not a genuine, current Base44 event. */
|
|
2
|
-
export type WebhookVerificationErrorCode = "missing_headers" | "timestamp_outside_tolerance" | "no_signature_entries" | "signature_mismatch" | "invalid_payload";
|
|
3
|
-
/** Why verification could not run at all. This is your deployment, not the request: let it surface as a 500 so Base44 retries. */
|
|
4
|
-
export type WebhookConfigurationErrorCode = "missing_public_keys" | "invalid_public_key";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { WebhookHeaders, WebhookPublicKeys } from "./webhooks.types.js";
|
|
2
|
-
/** Split the configured keys into raw 32-byte Ed25519 keys. A truncated paste throws: a wrong key reads as every event being forged. */
|
|
3
|
-
export declare function parsePublicKeys(keys: WebhookPublicKeys | undefined): Uint8Array[];
|
|
4
|
-
export declare function importPublicKey(raw: Uint8Array): Promise<CryptoKey>;
|
|
5
|
-
/** Read one header from a `Headers` or a Node-style object. */
|
|
6
|
-
export declare function readHeader(headers: WebhookHeaders, name: string, separator?: string): string | null;
|
|
7
|
-
/** The `v1a,<base64>` entries of a `webhook-signature` header, decoded. */
|
|
8
|
-
export declare function parseSignatures(header: string): Uint8Array[];
|
|
9
|
-
/** The signed bytes: `<id>.<timestamp>.<raw body>`. */
|
|
10
|
-
export declare function signedPayload(id: string, timestamp: string, body: string | Uint8Array): Uint8Array;
|
|
11
|
-
export declare function anySignatureVerifies(keys: CryptoKey[], signatures: Uint8Array[], payload: Uint8Array): Promise<boolean>;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { WebhookConfigurationError } from "../errors.js";
|
|
2
|
-
const SIGNATURE_SCHEME = "v1a";
|
|
3
|
-
const encoder = new TextEncoder();
|
|
4
|
-
/** Standard base64 to bytes, or `null` when it is not valid base64. */
|
|
5
|
-
function decodeBase64(value) {
|
|
6
|
-
try {
|
|
7
|
-
const binary = atob(value);
|
|
8
|
-
return Uint8Array.from(binary, char => char.charCodeAt(0));
|
|
9
|
-
}
|
|
10
|
-
catch (_a) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** Split the configured keys into raw 32-byte Ed25519 keys. A truncated paste throws: a wrong key reads as every event being forged. */
|
|
15
|
-
export function parsePublicKeys(keys) {
|
|
16
|
-
const entries = (Array.isArray(keys) ? keys : (keys !== null && keys !== void 0 ? keys : "").split(/[\s,]+/)).map(key => key.trim()).filter(Boolean);
|
|
17
|
-
if (entries.length === 0)
|
|
18
|
-
throw new WebhookConfigurationError("missing_public_keys", "no public keys were provided");
|
|
19
|
-
return entries.map(entry => {
|
|
20
|
-
const raw = decodeBase64(entry.replace(/^whpk_/, ""));
|
|
21
|
-
if (!raw || raw.length !== 32) {
|
|
22
|
-
throw new WebhookConfigurationError("invalid_public_key", "a public key is not a base64-encoded 32-byte Ed25519 key");
|
|
23
|
-
}
|
|
24
|
-
return raw;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
export function importPublicKey(raw) {
|
|
28
|
-
return crypto.subtle.importKey("raw", raw, "Ed25519", false, ["verify"]);
|
|
29
|
-
}
|
|
30
|
-
/** Read one header from a `Headers` or a Node-style object. */
|
|
31
|
-
export function readHeader(headers, name, separator = ", ") {
|
|
32
|
-
if (typeof headers.get === "function")
|
|
33
|
-
return headers.get(name);
|
|
34
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
35
|
-
if (key.toLowerCase() === name && value !== undefined)
|
|
36
|
-
return Array.isArray(value) ? value.join(separator) : value;
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
/** The `v1a,<base64>` entries of a `webhook-signature` header, decoded. */
|
|
41
|
-
export function parseSignatures(header) {
|
|
42
|
-
return header
|
|
43
|
-
.split(" ")
|
|
44
|
-
.filter(entry => entry.startsWith(`${SIGNATURE_SCHEME},`))
|
|
45
|
-
.map(entry => decodeBase64(entry.slice(SIGNATURE_SCHEME.length + 1)))
|
|
46
|
-
.filter((signature) => signature !== null);
|
|
47
|
-
}
|
|
48
|
-
/** The signed bytes: `<id>.<timestamp>.<raw body>`. */
|
|
49
|
-
export function signedPayload(id, timestamp, body) {
|
|
50
|
-
const prefix = encoder.encode(`${id}.${timestamp}.`);
|
|
51
|
-
const bytes = typeof body === "string" ? encoder.encode(body) : body;
|
|
52
|
-
const payload = new Uint8Array(prefix.length + bytes.length);
|
|
53
|
-
payload.set(prefix);
|
|
54
|
-
payload.set(bytes, prefix.length);
|
|
55
|
-
return payload;
|
|
56
|
-
}
|
|
57
|
-
export async function anySignatureVerifies(keys, signatures, payload) {
|
|
58
|
-
for (const key of keys) {
|
|
59
|
-
for (const signature of signatures) {
|
|
60
|
-
if (await crypto.subtle.verify("Ed25519", key, signature, payload))
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `data` object of `app.created.v1`. An app was created.
|
|
3
|
-
*/
|
|
4
|
-
export interface AppCreatedV1Data {
|
|
5
|
-
/**
|
|
6
|
-
* The app the event is about.
|
|
7
|
-
*/
|
|
8
|
-
app_id: string;
|
|
9
|
-
/**
|
|
10
|
-
* The workspace the app belongs to.
|
|
11
|
-
*/
|
|
12
|
-
workspace_id: string;
|
|
13
|
-
/**
|
|
14
|
-
* Opaque platform id of the app's current owner.
|
|
15
|
-
*/
|
|
16
|
-
owner_id: string;
|
|
17
|
-
/**
|
|
18
|
-
* Your own handle for the owner: the `service_external_id` you gave when you created that service user. Absent when the owner is not a service user.
|
|
19
|
-
*/
|
|
20
|
-
owner_service_external_id?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The kind of app. New values arrive as a new event version.
|
|
23
|
-
*/
|
|
24
|
-
app_type: "imported_app" | "user_agent" | "user_app" | "user_game";
|
|
25
|
-
/**
|
|
26
|
-
* When the app was created (UTC).
|
|
27
|
-
*/
|
|
28
|
-
created_at: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The `data` object of `app.published.v1`. An app version was published.
|
|
32
|
-
*/
|
|
33
|
-
export interface AppPublishedV1Data {
|
|
34
|
-
/**
|
|
35
|
-
* The app the event is about.
|
|
36
|
-
*/
|
|
37
|
-
app_id: string;
|
|
38
|
-
/**
|
|
39
|
-
* The workspace the app belongs to.
|
|
40
|
-
*/
|
|
41
|
-
workspace_id: string;
|
|
42
|
-
/**
|
|
43
|
-
* Opaque platform id of the app's current owner.
|
|
44
|
-
*/
|
|
45
|
-
owner_id: string;
|
|
46
|
-
/**
|
|
47
|
-
* Your own handle for the owner: the `service_external_id` you gave when you created that service user. Absent when the owner is not a service user.
|
|
48
|
-
*/
|
|
49
|
-
owner_service_external_id?: string;
|
|
50
|
-
/**
|
|
51
|
-
* Id of the version now live.
|
|
52
|
-
*/
|
|
53
|
-
published_version: string;
|
|
54
|
-
/**
|
|
55
|
-
* When the version went live (UTC).
|
|
56
|
-
*/
|
|
57
|
-
published_at: string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The `data` object of `app.unpublished.v1`. An app was taken offline.
|
|
61
|
-
*/
|
|
62
|
-
export interface AppUnpublishedV1Data {
|
|
63
|
-
/**
|
|
64
|
-
* The app the event is about.
|
|
65
|
-
*/
|
|
66
|
-
app_id: string;
|
|
67
|
-
/**
|
|
68
|
-
* The workspace the app belongs to.
|
|
69
|
-
*/
|
|
70
|
-
workspace_id: string;
|
|
71
|
-
/**
|
|
72
|
-
* Opaque platform id of the app's current owner.
|
|
73
|
-
*/
|
|
74
|
-
owner_id: string;
|
|
75
|
-
/**
|
|
76
|
-
* Your own handle for the owner: the `service_external_id` you gave when you created that service user. Absent when the owner is not a service user.
|
|
77
|
-
*/
|
|
78
|
-
owner_service_external_id?: string;
|
|
79
|
-
/**
|
|
80
|
-
* When the app was taken offline (UTC).
|
|
81
|
-
*/
|
|
82
|
-
unpublished_at: string;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Tombstone identifiers only.
|
|
86
|
-
*
|
|
87
|
-
* Deletion is **not** erasure: the app moves to trash and is self-serve
|
|
88
|
-
* restorable for 30 days, with unbounded restore through support. A receiver
|
|
89
|
-
* that purges on this event will be wrong for every restored app, which is why
|
|
90
|
-
* ``app.restored.v1`` exists and why this is documented as a trash signal.
|
|
91
|
-
*/
|
|
92
|
-
export interface AppDeletedV1Data {
|
|
93
|
-
/**
|
|
94
|
-
* The app the event is about.
|
|
95
|
-
*/
|
|
96
|
-
app_id: string;
|
|
97
|
-
/**
|
|
98
|
-
* The workspace the app belongs to.
|
|
99
|
-
*/
|
|
100
|
-
workspace_id: string;
|
|
101
|
-
/**
|
|
102
|
-
* Opaque platform id of the app's current owner.
|
|
103
|
-
*/
|
|
104
|
-
owner_id: string;
|
|
105
|
-
/**
|
|
106
|
-
* Your own handle for the owner: the `service_external_id` you gave when you created that service user. Absent when the owner is not a service user.
|
|
107
|
-
*/
|
|
108
|
-
owner_service_external_id?: string;
|
|
109
|
-
/**
|
|
110
|
-
* When the app was moved to trash (UTC). It can still be restored.
|
|
111
|
-
*/
|
|
112
|
-
deleted_at: string;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The `data` object of `app.restored.v1`. An app was restored from trash.
|
|
116
|
-
*/
|
|
117
|
-
export interface AppRestoredV1Data {
|
|
118
|
-
/**
|
|
119
|
-
* The app the event is about.
|
|
120
|
-
*/
|
|
121
|
-
app_id: string;
|
|
122
|
-
/**
|
|
123
|
-
* The workspace the app belongs to.
|
|
124
|
-
*/
|
|
125
|
-
workspace_id: string;
|
|
126
|
-
/**
|
|
127
|
-
* Opaque platform id of the app's current owner.
|
|
128
|
-
*/
|
|
129
|
-
owner_id: string;
|
|
130
|
-
/**
|
|
131
|
-
* Your own handle for the owner: the `service_external_id` you gave when you created that service user. Absent when the owner is not a service user.
|
|
132
|
-
*/
|
|
133
|
-
owner_service_external_id?: string;
|
|
134
|
-
/**
|
|
135
|
-
* When the app was restored (UTC).
|
|
136
|
-
*/
|
|
137
|
-
restored_at: string;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Carries no domain data — its only job is to be verifiable and echoed.
|
|
141
|
-
*/
|
|
142
|
-
export interface WebhookTestV1Data {
|
|
143
|
-
/**
|
|
144
|
-
* The endpoint being activated.
|
|
145
|
-
*/
|
|
146
|
-
endpoint_id: string;
|
|
147
|
-
/**
|
|
148
|
-
* The workspace the endpoint belongs to.
|
|
149
|
-
*/
|
|
150
|
-
workspace_id: string;
|
|
151
|
-
/**
|
|
152
|
-
* When the test was sent (UTC).
|
|
153
|
-
*/
|
|
154
|
-
sent_at: string;
|
|
155
|
-
/**
|
|
156
|
-
* Return this value in your response body to activate the endpoint.
|
|
157
|
-
*/
|
|
158
|
-
challenge: string;
|
|
159
|
-
}
|
|
160
|
-
/** Every event type Base44 sends, mapped to the shape of its `data` object. */
|
|
161
|
-
export interface WebhookEventMap {
|
|
162
|
-
/** An app was created. */
|
|
163
|
-
"app.created.v1": AppCreatedV1Data;
|
|
164
|
-
/** An app version was published. */
|
|
165
|
-
"app.published.v1": AppPublishedV1Data;
|
|
166
|
-
/** An app was taken offline. */
|
|
167
|
-
"app.unpublished.v1": AppUnpublishedV1Data;
|
|
168
|
-
/** Tombstone identifiers only. */
|
|
169
|
-
"app.deleted.v1": AppDeletedV1Data;
|
|
170
|
-
/** An app was restored from trash. */
|
|
171
|
-
"app.restored.v1": AppRestoredV1Data;
|
|
172
|
-
/** Carries no domain data — its only job is to be verifiable and echoed. */
|
|
173
|
-
"webhook.test.v1": WebhookTestV1Data;
|
|
174
|
-
}
|