@base44-preview/platform 0.2.0-pr.319.0f5c92a → 0.2.0-pr.319.6735b76
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 +18 -11
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/errors.js +1 -1
- package/dist/server/errors.types.d.ts +11 -5
- package/dist/server/index.d.ts +2 -2
- package/dist/server/modules/webhooks.events.generated.d.ts +2 -0
- package/dist/server/modules/webhooks.events.generated.js +2 -1
- package/dist/server/modules/webhooks.js +24 -10
- package/dist/server/modules/webhooks.types.d.ts +48 -12
- package/dist/server/server.d.ts +6 -11
- package/dist/server/server.js +5 -14
- package/dist/server/server.types.d.ts +0 -20
- package/package.json +4 -3
- package/dist/server/server-url.d.ts +0 -2
- package/dist/server/server-url.js +0 -8
package/README.md
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
npm install @base44/platform
|
|
5
5
|
```
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
The Platform SDK for white-label platforms built on Base44. It is independent of the app SDK
|
|
8
|
+
(`@base44/sdk`) and has two entrypoints:
|
|
9
|
+
|
|
10
|
+
- `@base44/platform`, for the browser: implements the read-only white-label builder socket
|
|
11
|
+
contract. A partner's browser watches the builder chat of up to eight apps over the platform's
|
|
12
|
+
shared socket. The workspace must have white-label sockets enabled; this SDK does not open sessions.
|
|
13
|
+
- `@base44/platform/server`, for your backend: verify the webhooks Base44 sends when apps are
|
|
14
|
+
created, published, unpublished, trashed or restored. See
|
|
15
|
+
[Receiving webhooks](#receiving-webhooks-server).
|
|
11
16
|
|
|
12
17
|
```ts
|
|
13
18
|
import { createPlatformClient } from "@base44/platform";
|
|
@@ -41,16 +46,14 @@ makes no network calls: pass your workspace's public keys (`whpk_…`) to each c
|
|
|
41
46
|
|
|
42
47
|
The simplest route is `createHandler`. It reads the raw body, verifies it, answers the
|
|
43
48
|
activation challenge and picks the status code: 400 for a delivery that fails verification,
|
|
44
|
-
500 when your keys are misconfigured or a callback throws
|
|
45
|
-
including for event types you have no handler for.
|
|
49
|
+
500 when your keys are misconfigured, the body can't be read or a callback throws, and 204
|
|
50
|
+
otherwise, including for event types you have no handler for. Base44 retries any answer that
|
|
51
|
+
isn't 2xx; the status only shows in its delivery log which side failed.
|
|
46
52
|
|
|
47
53
|
```ts
|
|
48
54
|
import { createPlatformServer } from "@base44/platform/server";
|
|
49
55
|
|
|
50
|
-
const platform = createPlatformServer(
|
|
51
|
-
serverUrl: "https://base44.app",
|
|
52
|
-
apiKey: process.env.BASE44_API_KEY!,
|
|
53
|
-
});
|
|
56
|
+
const platform = createPlatformServer();
|
|
54
57
|
const publicKeys = process.env.BASE44_WEBHOOK_PUBLIC_KEYS!; // two keys during a rotation
|
|
55
58
|
|
|
56
59
|
export const POST = platform.webhooks.createHandler({
|
|
@@ -74,7 +77,7 @@ export async function POST(request: Request) {
|
|
|
74
77
|
event = await platform.webhooks.verifyEvent(rawBody, request.headers, { publicKeys });
|
|
75
78
|
} catch (error) {
|
|
76
79
|
if (error instanceof WebhookVerificationError) return new Response(null, { status: 400 });
|
|
77
|
-
throw error; // missing/malformed keys: a 500
|
|
80
|
+
throw error; // missing/malformed keys: a 500. Base44 retries any non-2xx answer
|
|
78
81
|
}
|
|
79
82
|
switch (event.type) {
|
|
80
83
|
case "webhook.test.v1": return Response.json({ challenge: event.data.challenge }); // activates the endpoint
|
|
@@ -84,6 +87,10 @@ export async function POST(request: Request) {
|
|
|
84
87
|
}
|
|
85
88
|
```
|
|
86
89
|
|
|
90
|
+
An event type added to Base44 after your SDK version arrives as `{ type: "unknown", name, data }`,
|
|
91
|
+
with its real type in `name` and an unchecked `data`, the same shape the client uses. After you
|
|
92
|
+
upgrade, it arrives under its own `type`.
|
|
93
|
+
|
|
87
94
|
Delivery is at least once with no ordering guarantee: deduplicate on `event.id`, and answer
|
|
88
95
|
2xx to event types you do not handle. Event types are generated from the schemas published at
|
|
89
96
|
`https://base44.com/webhooks/schemas`; run `npm run generate:webhooks` to refresh them.
|
package/dist/server/errors.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class WebhookVerificationError extends Error {
|
|
|
32
32
|
*
|
|
33
33
|
* You don't create it. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
|
|
34
34
|
* it, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers it with a 500 and passes it
|
|
35
|
-
* to your `onError`.
|
|
35
|
+
* to your `onError`. Base44 retries the delivery, and the retries succeed once you fix the problem.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* ```typescript
|
package/dist/server/errors.js
CHANGED
|
@@ -33,7 +33,7 @@ export class WebhookVerificationError extends Error {
|
|
|
33
33
|
*
|
|
34
34
|
* You don't create it. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
|
|
35
35
|
* it, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers it with a 500 and passes it
|
|
36
|
-
* to your `onError`.
|
|
36
|
+
* to your `onError`. Base44 retries the delivery, and the retries succeed once you fix the problem.
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```typescript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Codes of errors for a delivery that can't be trusted. Answer these with a 400. Base44
|
|
3
|
-
*
|
|
2
|
+
* Codes of errors for a delivery that can't be trusted. Answer these with a 400. Base44 retries any
|
|
3
|
+
* answer that isn't 2xx, so a genuine delivery that failed because of a passing problem verifies on the retry.
|
|
4
4
|
*/
|
|
5
5
|
export type WebhookVerificationErrorCode =
|
|
6
6
|
/**
|
|
@@ -36,8 +36,8 @@ export type WebhookVerificationErrorCode =
|
|
|
36
36
|
| "invalid_payload";
|
|
37
37
|
/**
|
|
38
38
|
* Codes of errors that stop verification before it starts, because the public keys you passed can't
|
|
39
|
-
* be used. They're about your deployment, not the request, so
|
|
40
|
-
*
|
|
39
|
+
* be used. They're about your deployment, not the request, so answer them with a 500. Base44 retries
|
|
40
|
+
* the delivery, as it does for any answer that isn't 2xx, and it succeeds once you fix the problem.
|
|
41
41
|
*/
|
|
42
42
|
export type WebhookConfigurationErrorCode =
|
|
43
43
|
/**
|
|
@@ -51,4 +51,10 @@ export type WebhookConfigurationErrorCode =
|
|
|
51
51
|
*
|
|
52
52
|
* Copy the key again. A truncated key fails this way.
|
|
53
53
|
*/
|
|
54
|
-
| "invalid_public_key"
|
|
54
|
+
| "invalid_public_key"
|
|
55
|
+
/**
|
|
56
|
+
* The runtime can't import Ed25519 keys with WebCrypto.
|
|
57
|
+
*
|
|
58
|
+
* Run your server on Node.js 20 or later, or on an edge runtime that supports Ed25519 in WebCrypto.
|
|
59
|
+
*/
|
|
60
|
+
| "unsupported_runtime";
|
package/dist/server/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
export { createPlatformServer } from "./server.js";
|
|
3
3
|
export { WebhookConfigurationError, WebhookVerificationError } from "./errors.js";
|
|
4
4
|
export type { WebhookConfigurationErrorCode, WebhookVerificationErrorCode } from "./errors.types.js";
|
|
5
|
-
export type { PlatformServer
|
|
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";
|
|
5
|
+
export type { PlatformServer } from "./server.types.js";
|
|
6
|
+
export type { AppCreatedV1Data, AppDeletedV1Data, AppPublishedV1Data, AppRestoredV1Data, AppUnpublishedV1Data, CloudEvent, CreateHandlerOptions, DeliveredWebhookEvent, UnknownWebhookEvent, VerifyEventOptions, WebhookEventHandlers, WebhookEvent, WebhookEventMap, WebhookEventType, WebhookHeaders, WebhookPublicKeys, WebhooksModule, WebhookTestV1Data, } from "./modules/webhooks.types.js";
|
|
@@ -172,3 +172,5 @@ export interface WebhookEventMap {
|
|
|
172
172
|
/** Carries no domain data — its only job is to be verifiable and echoed. */
|
|
173
173
|
"webhook.test.v1": WebhookTestV1Data;
|
|
174
174
|
}
|
|
175
|
+
/** Every event type in {@link WebhookEventMap}, so events from a newer Base44 can be told apart at runtime. @internal */
|
|
176
|
+
export declare const WEBHOOK_EVENT_TYPES: readonly ["app.created.v1", "app.published.v1", "app.unpublished.v1", "app.deleted.v1", "app.restored.v1", "webhook.test.v1"];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
// Generated by scripts/generate-webhook-types.mjs from the schemas published at
|
|
2
2
|
// https://base44.com/webhooks/schemas. Do not edit by hand; run `npm run generate:webhooks`.
|
|
3
|
-
|
|
3
|
+
/** Every event type in {@link WebhookEventMap}, so events from a newer Base44 can be told apart at runtime. @internal */
|
|
4
|
+
export const WEBHOOK_EVENT_TYPES = ["app.created.v1", "app.published.v1", "app.unpublished.v1", "app.deleted.v1", "app.restored.v1", "webhook.test.v1"];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { WebhookConfigurationError, WebhookVerificationError } from "../errors.js";
|
|
2
2
|
import { anySignatureVerifies, importPublicKey, parsePublicKeys, parseSignatures, readHeader, signedPayload } from "./webhooks-signature.js";
|
|
3
|
+
import { WEBHOOK_EVENT_TYPES } from "./webhooks.events.generated.js";
|
|
4
|
+
const knownTypes = new Set(WEBHOOK_EVENT_TYPES);
|
|
3
5
|
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
4
6
|
/** Webhook receiving utilities. Verification is local: no network calls, no timers. */
|
|
5
7
|
export function createWebhooks() {
|
|
@@ -7,8 +9,13 @@ export function createWebhooks() {
|
|
|
7
9
|
const imported = new Map();
|
|
8
10
|
const keysFor = (publicKeys) => Promise.all(parsePublicKeys(publicKeys).map(raw => {
|
|
9
11
|
const id = raw.join(",");
|
|
10
|
-
if (!imported.has(id))
|
|
11
|
-
imported.set(id, importPublicKey(raw))
|
|
12
|
+
if (!imported.has(id)) {
|
|
13
|
+
imported.set(id, importPublicKey(raw).catch(() => {
|
|
14
|
+
// Evicted so a later call retries the import instead of replaying this failure.
|
|
15
|
+
imported.delete(id);
|
|
16
|
+
throw new WebhookConfigurationError("unsupported_runtime", "this runtime can't import Ed25519 keys with WebCrypto");
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
12
19
|
return imported.get(id);
|
|
13
20
|
}));
|
|
14
21
|
const verifyEvent = async (body, headers, verifyOptions) => {
|
|
@@ -42,23 +49,30 @@ export function createWebhooks() {
|
|
|
42
49
|
if (typeof type !== "string" || typeof eventId !== "string" || typeof data !== "object" || data === null) {
|
|
43
50
|
throw new WebhookVerificationError("invalid_payload");
|
|
44
51
|
}
|
|
45
|
-
|
|
52
|
+
// A type from a newer Base44 gets the client's unknown-event shape, so known types keep narrowing.
|
|
53
|
+
return (knownTypes.has(type) ? event : { ...event, type: "unknown", name: type });
|
|
46
54
|
};
|
|
47
55
|
return {
|
|
48
56
|
verifyEvent,
|
|
49
57
|
createHandler({ on = {}, onEvent, onSuccess, onError, ...verifyOptions }) {
|
|
50
|
-
const fail = async (error, status, event) => {
|
|
51
|
-
var _a;
|
|
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 });
|
|
53
|
-
};
|
|
58
|
+
const fail = async (error, status, label, event) => { var _a; return (_a = (await (onError === null || onError === void 0 ? void 0 : onError(error, event)))) !== null && _a !== void 0 ? _a : Response.json({ error: label }, { status }); };
|
|
54
59
|
return async (request) => {
|
|
55
60
|
var _a, _b;
|
|
61
|
+
let body;
|
|
62
|
+
try {
|
|
63
|
+
body = new Uint8Array(await request.arrayBuffer());
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return fail(error, 500, "request_failed");
|
|
67
|
+
}
|
|
56
68
|
let event;
|
|
57
69
|
try {
|
|
58
|
-
event = await verifyEvent(
|
|
70
|
+
event = await verifyEvent(body, request.headers, verifyOptions);
|
|
59
71
|
}
|
|
60
72
|
catch (error) {
|
|
61
|
-
|
|
73
|
+
if (error instanceof WebhookVerificationError)
|
|
74
|
+
return fail(error, 400, error.code);
|
|
75
|
+
return fail(error, 500, error instanceof WebhookConfigurationError ? "receiver_misconfigured" : "request_failed");
|
|
62
76
|
}
|
|
63
77
|
// Activation probe: echo the challenge, only after the signature verified. Never reaches your callbacks.
|
|
64
78
|
if (event.type === "webhook.test.v1")
|
|
@@ -69,7 +83,7 @@ export function createWebhooks() {
|
|
|
69
83
|
return (_b = (await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event)))) !== null && _b !== void 0 ? _b : new Response(null, { status: 204 });
|
|
70
84
|
}
|
|
71
85
|
catch (error) {
|
|
72
|
-
return fail(error, 500, event);
|
|
86
|
+
return fail(error, 500, "handler_failed", event);
|
|
73
87
|
}
|
|
74
88
|
};
|
|
75
89
|
},
|
|
@@ -31,15 +31,42 @@ export interface CloudEvent<TType extends string, TData> {
|
|
|
31
31
|
/** The event's payload. Its shape depends on `type`. */
|
|
32
32
|
data: TData;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* A webhook event whose type this version of the SDK doesn't know, such as one Base44 added later.
|
|
36
|
+
*
|
|
37
|
+
* The envelope is the same as for every event, but `type` is `"unknown"`, the event's real type is
|
|
38
|
+
* in `name`, and `data` isn't checked, so check a field before using it.
|
|
39
|
+
*/
|
|
40
|
+
export interface UnknownWebhookEvent extends Omit<CloudEvent<string, Record<string, unknown>>, "type"> {
|
|
41
|
+
/** Always `"unknown"`. Narrows the event to this shape. */
|
|
42
|
+
type: "unknown";
|
|
43
|
+
/** The event's type as Base44 sent it, such as `app.renamed.v1`. */
|
|
44
|
+
name: string;
|
|
45
|
+
}
|
|
34
46
|
/**
|
|
35
47
|
* A verified webhook event.
|
|
36
48
|
*
|
|
37
|
-
* Check `type` to narrow `data` to that event's payload.
|
|
38
|
-
*
|
|
49
|
+
* Check `type` to narrow `data` to that event's payload. An event added to Base44 after this version
|
|
50
|
+
* of the SDK arrives with `type: "unknown"`, its type in `name` and an unchecked `data`, so check a
|
|
51
|
+
* field before using it. After you upgrade, it arrives under its own `type`. Answer it with a 2xx
|
|
52
|
+
* too: Base44 retries any answer that isn't 2xx.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Narrow an event by type
|
|
57
|
+
* switch (event.type) {
|
|
58
|
+
* case 'app.deleted.v1':
|
|
59
|
+
* await removeApp(event.data.app_id);
|
|
60
|
+
* break;
|
|
61
|
+
* case 'unknown':
|
|
62
|
+
* console.log(`Skipping ${event.name}, which this SDK version doesn't know`);
|
|
63
|
+
* break;
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
39
66
|
*/
|
|
40
67
|
export type WebhookEvent = {
|
|
41
68
|
[K in WebhookEventType]: CloudEvent<K, WebhookEventMap[K]>;
|
|
42
|
-
}[WebhookEventType];
|
|
69
|
+
}[WebhookEventType] | UnknownWebhookEvent;
|
|
43
70
|
/** Request headers, as a fetch `Headers` object or a Node.js-style object. Header names are case-insensitive. */
|
|
44
71
|
export type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
45
72
|
/** One Ed25519 public key, starting with `whpk_`, or several in an array or separated by commas or whitespace. */
|
|
@@ -58,7 +85,10 @@ export interface VerifyEventOptions {
|
|
|
58
85
|
}
|
|
59
86
|
/** An event your callbacks receive. Every event except the `webhook.test.v1` activation probe, which the handler answers itself. */
|
|
60
87
|
export type DeliveredWebhookEvent = Exclude<WebhookEvent, CloudEvent<"webhook.test.v1", WebhookTestV1Data>>;
|
|
61
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Handlers keyed by event type. Each handler receives the event narrowed to its type. The `unknown`
|
|
90
|
+
* key handles every event type this version of the SDK doesn't know.
|
|
91
|
+
*/
|
|
62
92
|
export type WebhookEventHandlers = {
|
|
63
93
|
[K in DeliveredWebhookEvent["type"]]?: (event: Extract<DeliveredWebhookEvent, {
|
|
64
94
|
type: K;
|
|
@@ -66,7 +96,7 @@ export type WebhookEventHandlers = {
|
|
|
66
96
|
};
|
|
67
97
|
/** Options for {@linkcode WebhooksModule.createHandler | createHandler()}. Every callback can be async. */
|
|
68
98
|
export interface CreateHandlerOptions extends VerifyEventOptions {
|
|
69
|
-
/** Handlers keyed by event type. Events without a handler are still answered 2xx, so Base44 doesn't retry them. */
|
|
99
|
+
/** Handlers keyed by event type. Events without a handler, including unknown ones, are still answered 2xx, so Base44 doesn't retry them. */
|
|
70
100
|
on?: WebhookEventHandlers;
|
|
71
101
|
/** Called for every verified event, before its handler in `on`. */
|
|
72
102
|
onEvent?: (event: DeliveredWebhookEvent) => unknown;
|
|
@@ -79,9 +109,11 @@ export interface CreateHandlerOptions extends VerifyEventOptions {
|
|
|
79
109
|
/**
|
|
80
110
|
* Called when a delivery fails.
|
|
81
111
|
*
|
|
82
|
-
* The handler answers a `WebhookVerificationError` with a 400
|
|
83
|
-
* or anything a callback throws
|
|
84
|
-
*
|
|
112
|
+
* The handler answers a `WebhookVerificationError` with a 400, and a `WebhookConfigurationError`, a
|
|
113
|
+
* failed body read or anything a callback throws with a 500. Base44 retries either way, because it
|
|
114
|
+
* retries any answer that isn't 2xx. The status only shows in its delivery log whether the delivery
|
|
115
|
+
* or your side failed. The `event` argument is set when the delivery verified and a callback failed.
|
|
116
|
+
* Return a `Response` to replace the default answer.
|
|
85
117
|
*/
|
|
86
118
|
onError?: (error: unknown, event?: DeliveredWebhookEvent) => Response | void | Promise<Response | void>;
|
|
87
119
|
}
|
|
@@ -115,7 +147,7 @@ export interface WebhooksModule {
|
|
|
115
147
|
* @param options - Verification options, including your public keys.
|
|
116
148
|
* @returns Promise resolving to the verified event.
|
|
117
149
|
* @throws {WebhookVerificationError} When the delivery can't be trusted. Answer with a 400.
|
|
118
|
-
* @throws {WebhookConfigurationError} When the public keys are missing or malformed
|
|
150
|
+
* @throws {WebhookConfigurationError} When the public keys are missing or malformed, or the runtime can't use them. Answer with a 500.
|
|
119
151
|
*
|
|
120
152
|
* @example
|
|
121
153
|
* ```typescript
|
|
@@ -153,9 +185,13 @@ export interface WebhooksModule {
|
|
|
153
185
|
* `on`, and `onSuccess`, in that order.
|
|
154
186
|
*
|
|
155
187
|
* It answers with:
|
|
156
|
-
* - 204 when the event was handled, including events with no handler.
|
|
157
|
-
* - 400 when the delivery doesn't verify.
|
|
158
|
-
* - 500 when the public keys are misconfigured
|
|
188
|
+
* - 204 when the event was handled, including events with no handler and unknown events.
|
|
189
|
+
* - 400 when the delivery doesn't verify, with the error code in the body.
|
|
190
|
+
* - 500 when the public keys are misconfigured (`receiver_misconfigured`), the body can't be read
|
|
191
|
+
* (`request_failed`) or a callback throws (`handler_failed`).
|
|
192
|
+
*
|
|
193
|
+
* Base44 retries any answer that isn't 2xx, 400 and 500 alike. The status only shows in its delivery
|
|
194
|
+
* log whether the delivery or your side failed.
|
|
159
195
|
*
|
|
160
196
|
* Base44 can deliver the same event more than once, so make your handlers safe to run twice for the
|
|
161
197
|
* same `event.id`.
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
import type { PlatformServer
|
|
1
|
+
import type { PlatformServer } from "./server.types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a platform server client.
|
|
4
4
|
*
|
|
5
5
|
* This is the entry point of the Platform SDK on your backend. Import it from
|
|
6
6
|
* `@base44/platform/server`. The client gives your server access to the platform's server modules,
|
|
7
|
-
* such as [`webhooks`](/developers/references/platform-sdk/docs/interfaces/webhooks).
|
|
8
|
-
* makes no network requests.
|
|
7
|
+
* such as [`webhooks`](/developers/references/platform-sdk/docs/interfaces/webhooks). It takes no
|
|
8
|
+
* options and makes no network requests. Each module takes what it needs when you call it.
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @returns A configured server client with access to the platform's server modules.
|
|
12
|
-
* @throws {TypeError} When `serverUrl` isn't an HTTP or HTTPS origin, or `apiKey` is empty.
|
|
10
|
+
* @returns A server client with access to the platform's server modules.
|
|
13
11
|
*
|
|
14
12
|
* @example
|
|
15
13
|
* ```typescript
|
|
16
14
|
* // Create a server client on your backend
|
|
17
15
|
* import { createPlatformServer } from '@base44/platform/server';
|
|
18
16
|
*
|
|
19
|
-
* const platform = createPlatformServer(
|
|
20
|
-
* serverUrl: 'https://base44.app',
|
|
21
|
-
* apiKey: process.env.BASE44_API_KEY,
|
|
22
|
-
* });
|
|
17
|
+
* const platform = createPlatformServer();
|
|
23
18
|
*
|
|
24
19
|
* // Use the client to receive webhooks
|
|
25
20
|
* export const POST = platform.webhooks.createHandler({
|
|
@@ -30,4 +25,4 @@ import type { PlatformServer, PlatformServerOptions } from "./server.types.js";
|
|
|
30
25
|
* });
|
|
31
26
|
* ```
|
|
32
27
|
*/
|
|
33
|
-
export declare function createPlatformServer(
|
|
28
|
+
export declare function createPlatformServer(): PlatformServer;
|
package/dist/server/server.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import { normalizeServerUrl } from "./server-url.js";
|
|
2
1
|
import { createWebhooks } from "./modules/webhooks.js";
|
|
3
2
|
/**
|
|
4
3
|
* Creates a platform server client.
|
|
5
4
|
*
|
|
6
5
|
* This is the entry point of the Platform SDK on your backend. Import it from
|
|
7
6
|
* `@base44/platform/server`. The client gives your server access to the platform's server modules,
|
|
8
|
-
* such as [`webhooks`](/developers/references/platform-sdk/docs/interfaces/webhooks).
|
|
9
|
-
* makes no network requests.
|
|
7
|
+
* such as [`webhooks`](/developers/references/platform-sdk/docs/interfaces/webhooks). It takes no
|
|
8
|
+
* options and makes no network requests. Each module takes what it needs when you call it.
|
|
10
9
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @returns A configured server client with access to the platform's server modules.
|
|
13
|
-
* @throws {TypeError} When `serverUrl` isn't an HTTP or HTTPS origin, or `apiKey` is empty.
|
|
10
|
+
* @returns A server client with access to the platform's server modules.
|
|
14
11
|
*
|
|
15
12
|
* @example
|
|
16
13
|
* ```typescript
|
|
17
14
|
* // Create a server client on your backend
|
|
18
15
|
* import { createPlatformServer } from '@base44/platform/server';
|
|
19
16
|
*
|
|
20
|
-
* const platform = createPlatformServer(
|
|
21
|
-
* serverUrl: 'https://base44.app',
|
|
22
|
-
* apiKey: process.env.BASE44_API_KEY,
|
|
23
|
-
* });
|
|
17
|
+
* const platform = createPlatformServer();
|
|
24
18
|
*
|
|
25
19
|
* // Use the client to receive webhooks
|
|
26
20
|
* export const POST = platform.webhooks.createHandler({
|
|
@@ -31,10 +25,7 @@ import { createWebhooks } from "./modules/webhooks.js";
|
|
|
31
25
|
* });
|
|
32
26
|
* ```
|
|
33
27
|
*/
|
|
34
|
-
export function createPlatformServer(
|
|
35
|
-
if (!options.apiKey)
|
|
36
|
-
throw new TypeError("apiKey is required");
|
|
37
|
-
normalizeServerUrl(options.serverUrl);
|
|
28
|
+
export function createPlatformServer() {
|
|
38
29
|
return Object.freeze({
|
|
39
30
|
webhooks: Object.freeze(createWebhooks()),
|
|
40
31
|
});
|
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
import type { WebhooksModule } from "./modules/webhooks.types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Options for {@linkcode createPlatformServer | createPlatformServer()}.
|
|
4
|
-
*
|
|
5
|
-
* The server client runs on your backend and holds your workspace API key. Never pass these options
|
|
6
|
-
* to code that runs in the browser.
|
|
7
|
-
*/
|
|
8
|
-
export interface PlatformServerOptions {
|
|
9
|
-
/**
|
|
10
|
-
* Origin of the Base44 API, such as `https://base44.app`.
|
|
11
|
-
*
|
|
12
|
-
* It must be an origin with no path, query, fragment, or credentials.
|
|
13
|
-
*/
|
|
14
|
-
serverUrl: string;
|
|
15
|
-
/**
|
|
16
|
-
* Your workspace API key.
|
|
17
|
-
*
|
|
18
|
-
* Keep it on your server. The browser client never needs it.
|
|
19
|
-
*/
|
|
20
|
-
apiKey: string;
|
|
21
|
-
}
|
|
22
2
|
/**
|
|
23
3
|
* The platform server client.
|
|
24
4
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/platform",
|
|
3
|
-
"version": "0.2.0-pr.319.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0-pr.319.6735b76",
|
|
4
|
+
"description": "Base44 Platform SDK for white-label platforms: a browser client for watching the builder and a server entrypoint for webhooks",
|
|
5
5
|
"main": "dist/client/index.js",
|
|
6
6
|
"types": "dist/client/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"keywords": [
|
|
54
54
|
"base44",
|
|
55
55
|
"platform",
|
|
56
|
-
"white-label"
|
|
56
|
+
"white-label",
|
|
57
|
+
"webhooks"
|
|
57
58
|
],
|
|
58
59
|
"author": "Base44",
|
|
59
60
|
"license": "MIT",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Validate a platform origin and return it normalized. Used by the server entrypoint. */
|
|
2
|
-
export function normalizeServerUrl(serverUrl) {
|
|
3
|
-
const url = new URL(serverUrl);
|
|
4
|
-
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || url.pathname !== "/") {
|
|
5
|
-
throw new TypeError("serverUrl must be an HTTP(S) origin without credentials, path, query or fragment");
|
|
6
|
-
}
|
|
7
|
-
return url.origin;
|
|
8
|
-
}
|