@base44-preview/platform 0.0.0 → 0.1.0-pr.319.850fe58
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/LICENSE +21 -0
- package/README.md +225 -0
- package/dist/client/client.d.ts +9 -0
- package/dist/client/client.js +9 -0
- package/dist/client/client.types.d.ts +12 -0
- package/dist/client/client.types.js +1 -0
- package/dist/client/errors.d.ts +10 -0
- package/dist/client/errors.js +10 -0
- package/dist/client/errors.types.d.ts +2 -0
- package/dist/client/errors.types.js +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +3 -0
- package/dist/client/modules/builder-protocol.d.ts +15 -0
- package/dist/client/modules/builder-protocol.js +34 -0
- package/dist/client/modules/builder-socket.d.ts +42 -0
- package/dist/client/modules/builder-socket.js +252 -0
- package/dist/client/modules/builder-subscription.d.ts +23 -0
- package/dist/client/modules/builder-subscription.js +55 -0
- package/dist/client/modules/builder.d.ts +4 -0
- package/dist/client/modules/builder.events.types.d.ts +368 -0
- package/dist/client/modules/builder.events.types.js +1 -0
- package/dist/client/modules/builder.js +7 -0
- package/dist/client/modules/builder.types.d.ts +47 -0
- package/dist/client/modules/builder.types.js +1 -0
- package/dist/server/errors.d.ts +15 -0
- package/dist/server/errors.js +18 -0
- package/dist/server/errors.types.d.ts +4 -0
- package/dist/server/errors.types.js +1 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +3 -0
- package/dist/server/modules/webhooks-signature.d.ts +11 -0
- package/dist/server/modules/webhooks-signature.js +65 -0
- package/dist/server/modules/webhooks.d.ts +3 -0
- package/dist/server/modules/webhooks.events.generated.d.ts +174 -0
- package/dist/server/modules/webhooks.events.generated.js +3 -0
- package/dist/server/modules/webhooks.js +77 -0
- package/dist/server/modules/webhooks.types.d.ts +102 -0
- package/dist/server/modules/webhooks.types.js +1 -0
- package/dist/server/server.d.ts +10 -0
- package/dist/server/server.js +23 -0
- package/dist/server/server.types.d.ts +10 -0
- package/dist/server/server.types.js +1 -0
- package/dist/shared/server-url.d.ts +2 -0
- package/dist/shared/server-url.js +8 -0
- package/package.json +63 -3
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { WebhookConfigurationError, WebhookVerificationError } from "../errors.js";
|
|
2
|
+
import { anySignatureVerifies, importPublicKey, parsePublicKeys, parseSignatures, readHeader, signedPayload } from "./webhooks-signature.js";
|
|
3
|
+
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
4
|
+
/** Webhook receiving utilities. Verification is local: no network calls, no timers. */
|
|
5
|
+
export function createWebhooks(options = {}) {
|
|
6
|
+
// Imported keys are cached by their wire form so a pinned key is imported once.
|
|
7
|
+
const imported = new Map();
|
|
8
|
+
const keysFor = (publicKeys = options.publicKeys) => Promise.all(parsePublicKeys(publicKeys).map(raw => {
|
|
9
|
+
const id = raw.join(",");
|
|
10
|
+
if (!imported.has(id))
|
|
11
|
+
imported.set(id, importPublicKey(raw));
|
|
12
|
+
return imported.get(id);
|
|
13
|
+
}));
|
|
14
|
+
const verifyEvent = async (body, headers, verifyOptions = {}) => {
|
|
15
|
+
var _a;
|
|
16
|
+
// Configuration problems surface first, whatever the request looks like: a missing key is ours to fix.
|
|
17
|
+
const keys = await keysFor(verifyOptions.publicKeys);
|
|
18
|
+
const id = readHeader(headers, "webhook-id");
|
|
19
|
+
const timestamp = readHeader(headers, "webhook-timestamp");
|
|
20
|
+
const signature = readHeader(headers, "webhook-signature", " ");
|
|
21
|
+
if (!id || !timestamp || !signature)
|
|
22
|
+
throw new WebhookVerificationError("missing_headers");
|
|
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))) {
|
|
25
|
+
throw new WebhookVerificationError("timestamp_outside_tolerance");
|
|
26
|
+
}
|
|
27
|
+
const signatures = parseSignatures(signature);
|
|
28
|
+
if (signatures.length === 0)
|
|
29
|
+
throw new WebhookVerificationError("no_signature_entries");
|
|
30
|
+
if (!(await anySignatureVerifies(keys, signatures, signedPayload(id, timestamp, body)))) {
|
|
31
|
+
throw new WebhookVerificationError("signature_mismatch");
|
|
32
|
+
}
|
|
33
|
+
// Only now is the body trusted enough to parse.
|
|
34
|
+
let event;
|
|
35
|
+
try {
|
|
36
|
+
event = JSON.parse(typeof body === "string" ? body : new TextDecoder().decode(body));
|
|
37
|
+
}
|
|
38
|
+
catch (_b) {
|
|
39
|
+
throw new WebhookVerificationError("invalid_payload");
|
|
40
|
+
}
|
|
41
|
+
const { type, id: eventId, data } = (event !== null && event !== void 0 ? event : {});
|
|
42
|
+
if (typeof type !== "string" || typeof eventId !== "string" || typeof data !== "object" || data === null) {
|
|
43
|
+
throw new WebhookVerificationError("invalid_payload");
|
|
44
|
+
}
|
|
45
|
+
return event;
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
verifyEvent,
|
|
49
|
+
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
|
+
};
|
|
54
|
+
return async (request) => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
let event;
|
|
57
|
+
try {
|
|
58
|
+
event = await verifyEvent(new Uint8Array(await request.arrayBuffer()), request.headers, verifyOptions);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return fail(error, error instanceof WebhookVerificationError ? 400 : 500);
|
|
62
|
+
}
|
|
63
|
+
// Activation probe: echo the challenge, only after the signature verified. Never reaches your callbacks.
|
|
64
|
+
if (event.type === "webhook.test.v1")
|
|
65
|
+
return Response.json({ challenge: event.data.challenge });
|
|
66
|
+
try {
|
|
67
|
+
await (onEvent === null || onEvent === void 0 ? void 0 : onEvent(event));
|
|
68
|
+
await ((_a = on[event.type]) === null || _a === void 0 ? void 0 : _a.call(on, event));
|
|
69
|
+
return (_b = (await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event)))) !== null && _b !== void 0 ? _b : new Response(null, { status: 204 });
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return fail(error, 500, event);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { WebhookEventMap, WebhookTestV1Data } from "./webhooks.events.generated.js";
|
|
2
|
+
export type * from "./webhooks.events.generated.js";
|
|
3
|
+
/** Name of a webhook event, e.g. `app.deleted.v1`. */
|
|
4
|
+
export type WebhookEventType = keyof WebhookEventMap;
|
|
5
|
+
/** CloudEvents 1.0 envelope every Base44 webhook is delivered in. */
|
|
6
|
+
export interface CloudEvent<TType extends string, TData> {
|
|
7
|
+
/** CloudEvents version. Always `1.0`. */
|
|
8
|
+
specversion: "1.0";
|
|
9
|
+
/** Unique event id (`evt_…`). Identical across redeliveries, so use it to deduplicate. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** The workspace the event happened in, as a URL. */
|
|
12
|
+
source: string;
|
|
13
|
+
/** Event type, including its version. */
|
|
14
|
+
type: TType;
|
|
15
|
+
/** The resource the event is about, e.g. `apps/<app id>`. */
|
|
16
|
+
subject: string;
|
|
17
|
+
/** When the event occurred (RFC 3339, UTC). */
|
|
18
|
+
time: string;
|
|
19
|
+
/** Content type of `data`. Always `application/json`. */
|
|
20
|
+
datacontenttype: string;
|
|
21
|
+
/** URL of the JSON Schema describing `data`. */
|
|
22
|
+
dataschema: string;
|
|
23
|
+
/** W3C trace context, when the event was produced inside a trace. */
|
|
24
|
+
traceparent?: string;
|
|
25
|
+
/** W3C trace state, when present. */
|
|
26
|
+
tracestate?: string;
|
|
27
|
+
/** Kind of actor that caused the event. */
|
|
28
|
+
authtype: string;
|
|
29
|
+
/** Identifier of the actor that caused the event. */
|
|
30
|
+
authid: string;
|
|
31
|
+
/** Event-specific payload. */
|
|
32
|
+
data: TData;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A verified Base44 webhook event. Narrow on `type` to read `data`.
|
|
36
|
+
* Base44 may add event types later, so give a `switch` a default branch that still answers 2xx.
|
|
37
|
+
*/
|
|
38
|
+
export type WebhookEvent = {
|
|
39
|
+
[K in WebhookEventType]: CloudEvent<K, WebhookEventMap[K]>;
|
|
40
|
+
}[WebhookEventType];
|
|
41
|
+
/** Request headers in any common shape: a fetch `Headers`, or a Node-style object. Names are case-insensitive. */
|
|
42
|
+
export type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
43
|
+
/** One Ed25519 public key (`whpk_…`), or several separated by commas or whitespace. */
|
|
44
|
+
export type WebhookPublicKeys = string | string[];
|
|
45
|
+
/** Webhook settings for {@link Base44PlatformServer}. */
|
|
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`. */
|
|
51
|
+
export interface VerifyEventOptions {
|
|
52
|
+
/** Public keys to verify against, instead of the ones the client was created with. */
|
|
53
|
+
publicKeys?: WebhookPublicKeys;
|
|
54
|
+
/** Maximum age or clock skew of a delivery, in seconds. Defaults to 300. */
|
|
55
|
+
toleranceSeconds?: number;
|
|
56
|
+
}
|
|
57
|
+
/** An event your handler receives: every event except the `webhook.test.v1` probe, which `createHandler` answers itself. */
|
|
58
|
+
export type DeliveredWebhookEvent = Exclude<WebhookEvent, CloudEvent<"webhook.test.v1", WebhookTestV1Data>>;
|
|
59
|
+
/** Per-type handlers for `createHandler`, each receiving the event already narrowed to its type. */
|
|
60
|
+
export type WebhookEventHandlers = {
|
|
61
|
+
[K in DeliveredWebhookEvent["type"]]?: (event: Extract<DeliveredWebhookEvent, {
|
|
62
|
+
type: K;
|
|
63
|
+
}>) => unknown;
|
|
64
|
+
};
|
|
65
|
+
/** Options for `createHandler`. Every callback may be async. */
|
|
66
|
+
export interface CreateHandlerOptions extends VerifyEventOptions {
|
|
67
|
+
/** Handlers keyed by event type. Types without a handler are still answered 2xx, so Base44 does not retry them. */
|
|
68
|
+
on?: WebhookEventHandlers;
|
|
69
|
+
/** Called for every verified event, before its handler in `on`. */
|
|
70
|
+
onEvent?: (event: DeliveredWebhookEvent) => unknown;
|
|
71
|
+
/**
|
|
72
|
+
* Called once `onEvent` and the event's handler finished without throwing. Return a `Response` to replace the default
|
|
73
|
+
* empty 204.
|
|
74
|
+
*/
|
|
75
|
+
onSuccess?: (event: DeliveredWebhookEvent) => Response | void | Promise<Response | void>;
|
|
76
|
+
/**
|
|
77
|
+
* Called when a delivery fails: a `WebhookVerificationError` (default response 400), a
|
|
78
|
+
* `WebhookConfigurationError` (500), or whatever a handler threw (500, so Base44 retries). `event`
|
|
79
|
+
* is set when verification passed and a callback failed. Return a `Response` to replace the default.
|
|
80
|
+
*/
|
|
81
|
+
onError?: (error: unknown, event?: DeliveredWebhookEvent) => Response | void | Promise<Response | void>;
|
|
82
|
+
}
|
|
83
|
+
/** Receive and verify Base44 outbound webhooks. Makes no network requests. */
|
|
84
|
+
export interface WebhooksModule {
|
|
85
|
+
/**
|
|
86
|
+
* Verify a delivery and return the event.
|
|
87
|
+
*
|
|
88
|
+
* Pass the body exactly as received, before any JSON parsing. Nothing is parsed until the
|
|
89
|
+
* signature checks out. Rejects with `WebhookVerificationError` for a delivery you should
|
|
90
|
+
* refuse (respond 400) and `WebhookConfigurationError` when the public keys are missing
|
|
91
|
+
* or malformed (let it surface as a 500 so Base44 retries). To activate an endpoint, answer
|
|
92
|
+
* the `webhook.test.v1` event with `{ "challenge": event.data.challenge }`.
|
|
93
|
+
*/
|
|
94
|
+
verifyEvent(body: string | Uint8Array, headers: WebhookHeaders, options?: VerifyEventOptions): Promise<WebhookEvent>;
|
|
95
|
+
/**
|
|
96
|
+
* Build a fetch-style route handler (`(request: Request) => Promise<Response>`) for Next.js, Hono,
|
|
97
|
+
* Cloudflare Workers, Deno or Bun. It reads the raw body, verifies it, answers the activation
|
|
98
|
+
* challenge, then runs your callbacks. Delivery is at least once, so handlers must tolerate
|
|
99
|
+
* the same event (same `event.id`) arriving twice.
|
|
100
|
+
*/
|
|
101
|
+
createHandler(options?: CreateHandlerOptions): (request: Request) => Promise<Response>;
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WebhooksModule } from "./modules/webhooks.types.js";
|
|
2
|
+
import type { PlatformServerOptions } from "./server.types.js";
|
|
3
|
+
/** Server platform client, authenticated with a workspace API key. Construction performs no network requests. */
|
|
4
|
+
export declare class Base44PlatformServer {
|
|
5
|
+
#private;
|
|
6
|
+
/** Verify Base44 outbound webhooks and answer the activation challenge. */
|
|
7
|
+
readonly webhooks: WebhooksModule;
|
|
8
|
+
/** Configure shared service/auth settings; modules are added on top of this. */
|
|
9
|
+
constructor(options: PlatformServerOptions);
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var _Base44PlatformServer_serverUrl, _Base44PlatformServer_apiKey;
|
|
8
|
+
import { normalizeServerUrl } from "../shared/server-url.js";
|
|
9
|
+
import { createWebhooks } from "./modules/webhooks.js";
|
|
10
|
+
/** Server platform client, authenticated with a workspace API key. Construction performs no network requests. */
|
|
11
|
+
export class Base44PlatformServer {
|
|
12
|
+
/** Configure shared service/auth settings; modules are added on top of this. */
|
|
13
|
+
constructor(options) {
|
|
14
|
+
_Base44PlatformServer_serverUrl.set(this, void 0);
|
|
15
|
+
_Base44PlatformServer_apiKey.set(this, void 0);
|
|
16
|
+
if (!options.apiKey)
|
|
17
|
+
throw new TypeError("apiKey is required");
|
|
18
|
+
__classPrivateFieldSet(this, _Base44PlatformServer_serverUrl, normalizeServerUrl(options.serverUrl), "f");
|
|
19
|
+
__classPrivateFieldSet(this, _Base44PlatformServer_apiKey, options.apiKey, "f");
|
|
20
|
+
this.webhooks = Object.freeze(createWebhooks(options.webhooks));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
_Base44PlatformServer_serverUrl = new WeakMap(), _Base44PlatformServer_apiKey = new WeakMap();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WebhooksOptions } from "./modules/webhooks.types.js";
|
|
2
|
+
/** Shared configuration for server platform modules. */
|
|
3
|
+
export interface PlatformServerOptions {
|
|
4
|
+
/** Origin of the platform service, e.g. https://base44.app. No path/query/credentials. */
|
|
5
|
+
serverUrl: string;
|
|
6
|
+
/** Workspace API key. Keep it on your server; never ship it to a browser. */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Webhook receiving settings. */
|
|
9
|
+
webhooks?: WebhooksOptions;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Validate a platform origin and return it normalized. Shared by the client and server entrypoints. */
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/platform",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-pr.319.850fe58",
|
|
4
|
+
"description": "Client and server SDK for building on the Base44 platform",
|
|
5
|
+
"main": "dist/client/index.js",
|
|
6
|
+
"types": "dist/client/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/client/index.d.ts",
|
|
11
|
+
"default": "./dist/client/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./server": {
|
|
14
|
+
"types": "./dist/server/index.d.ts",
|
|
15
|
+
"default": "./dist/server/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"docs": "typedoc",
|
|
28
|
+
"test": "npm run test:types && npm run test:unit && npm run docs && npm run test:package",
|
|
29
|
+
"test:types": "tsc --noEmit -p tsconfig.type-tests.json",
|
|
30
|
+
"test:unit": "vitest run",
|
|
31
|
+
"test:package": "npm run build && node --test tests/package.test.mjs",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"generate:webhooks": "node scripts/generate-webhook-types.mjs"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"socket.io-client": "^4.8.3"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"base44",
|
|
40
|
+
"platform",
|
|
41
|
+
"white-label"
|
|
42
|
+
],
|
|
43
|
+
"author": "Base44",
|
|
5
44
|
"license": "MIT",
|
|
6
|
-
"repository": {
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/base44/javascript-sdk.git",
|
|
48
|
+
"directory": "packages/platform"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/base44/javascript-sdk/issues"
|
|
52
|
+
},
|
|
53
|
+
"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
|
+
"devDependencies": {
|
|
62
|
+
"json-schema-to-typescript": "^16.0.0"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=20"
|
|
66
|
+
}
|
|
7
67
|
}
|