@notionhq/custom-blocks 0.3.5 → 0.5.0
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 +2 -2
- package/dist/bridge/SandboxBridge.d.ts +4 -39
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +36 -142
- package/dist/bridge/requests.d.ts +35 -0
- package/dist/bridge/requests.d.ts.map +1 -0
- package/dist/bridge/requests.js +97 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
- package/dist/dataSources/bridge/resolveDataSourceQuery.js +18 -4
- package/dist/dataSources/bridge/resolveDataSources.js +4 -4
- package/dist/dataSources/createDataSourcePage.d.ts.map +1 -1
- package/dist/dataSources/createDataSourcePage.js +5 -1
- package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -1
- package/dist/dataSources/filters/resolveFilter.js +13 -3
- package/dist/dataSources/filters/types.d.ts +9 -3
- package/dist/dataSources/filters/types.d.ts.map +1 -1
- package/dist/dataSources/properties/resolvePropertyAddress.js +1 -1
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.js +1 -1
- package/dist/dataSources/resolvePageDataSource.js +2 -2
- package/dist/dataSources/subscribeToDataSource.d.ts +1 -4
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
- package/dist/dataSources/subscribeToDataSource.js +2 -3
- package/dist/dataSources/types.d.ts +2 -0
- package/dist/dataSources/types.d.ts.map +1 -1
- package/dist/files/files.d.ts +2 -0
- package/dist/files/files.d.ts.map +1 -0
- package/dist/files/files.js +1 -0
- package/dist/files/icons.d.ts +2 -0
- package/dist/files/icons.d.ts.map +1 -0
- package/dist/files/icons.js +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/initialization/getInitBindingError.js +2 -2
- package/dist/manifest/types.d.ts +5 -4
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.js +2 -1
- package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
- package/dist/pages/bridge/getPageForDataSource.js +3 -2
- package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
- package/dist/pages/bridge/sendCreatePageRequest.js +2 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +14 -2
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +0 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -8
- package/dist/pages/bridge/updatePage.d.ts.map +1 -1
- package/dist/pages/bridge/updatePage.js +20 -5
- package/dist/pages/createPage.d.ts.map +1 -1
- package/dist/pages/createPage.js +5 -1
- package/dist/pages/openPage.d.ts.map +1 -1
- package/dist/pages/openPage.js +2 -1
- package/dist/pages/properties/getPropertyByKey.js +2 -2
- package/dist/pages/types.d.ts +10 -14
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.d.ts +530 -0
- package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.js +25 -0
- package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +12 -11
- package/dist/protocol/compatibility/protocol3To5/bridgePage.js +3 -3
- package/dist/protocol/context/containingPage.d.ts +3 -0
- package/dist/protocol/context/messages/pageChanged.d.ts +3 -0
- package/dist/protocol/context/messages/parentChanged.d.ts +3 -0
- package/dist/protocol/context/parent.d.ts +5 -0
- package/dist/protocol/context/parent.js +6 -1
- package/dist/protocol/dataSources/bridgeArchiveStatus.d.ts +3 -0
- package/dist/protocol/dataSources/bridgeArchiveStatus.js +6 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +3 -11
- package/dist/protocol/dataSources/bridgeDataSourceBinding.js +5 -5
- package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +2 -10
- package/dist/protocol/dataSources/{collectionPointer.d.ts → dataSourcePointer.d.ts} +2 -2
- package/dist/protocol/dataSources/{collectionPointer.js → dataSourcePointer.js} +1 -1
- package/dist/protocol/dataSources/{collectionSchema.d.ts → dataSourceSchema.d.ts} +2 -10
- package/dist/protocol/dataSources/{collectionSchema.js → dataSourceSchema.js} +1 -1
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.d.ts +1458 -12
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.d.ts +729 -6
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.js +14 -2
- package/dist/protocol/dataSources/filters/peopleFilterOperator.d.ts +3 -3
- package/dist/protocol/dataSources/filters/peopleFilterOperator.js +1 -1
- package/dist/protocol/dataSources/filters/timestampFilterOperator.d.ts +354 -0
- package/dist/protocol/dataSources/filters/timestampFilterOperator.js +4 -0
- package/dist/protocol/dataSources/messages/dataSourcesChanged.d.ts +2 -10
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +1485 -38
- package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
- package/dist/protocol/dataSources/notionDataSource.d.ts +3 -19
- package/dist/protocol/dataSources/notionDataSource.js +5 -5
- package/dist/protocol/dataSources/properties/propertySchema.d.ts +4 -13
- package/dist/protocol/dataSources/properties/propertySchema.js +2 -6
- package/dist/protocol/dataSources/resolveDataSourceBinding.d.ts +4 -4
- package/dist/protocol/dataSources/resolveDataSourceBinding.js +2 -2
- package/dist/protocol/files.d.ts +32 -0
- package/dist/protocol/files.js +17 -0
- package/dist/protocol/handshake/connect.d.ts +15 -4
- package/dist/protocol/handshake/init.d.ts +23 -14
- package/dist/protocol/icons.d.ts +32 -0
- package/dist/protocol/icons.js +39 -0
- package/dist/protocol/index.d.ts +25 -19
- package/dist/protocol/index.js +15 -9
- package/dist/protocol/manifest/grants.d.ts +48 -0
- package/dist/protocol/manifest/grants.js +19 -0
- package/dist/protocol/manifest/manifest.d.ts +39 -16
- package/dist/protocol/manifest/manifest.js +17 -11
- package/dist/protocol/messages/hostToSandbox.d.ts +196 -177
- package/dist/protocol/messages/invalidHostMessage.d.ts +2 -0
- package/dist/protocol/messages/invalidHostMessage.js +2 -0
- package/dist/protocol/messages/invalidSandboxMessage.d.ts +2 -0
- package/dist/protocol/messages/invalidSandboxMessage.js +2 -0
- package/dist/protocol/messages/sandboxToHost.d.ts +1571 -50
- package/dist/protocol/navigation/openExternalUrl.d.ts +2 -2
- package/dist/protocol/pages/bridgePage.d.ts +12 -12
- package/dist/protocol/pages/bridgePage.js +3 -4
- package/dist/protocol/pages/makeBridgePage.d.ts +3 -1
- package/dist/protocol/pages/messages/createPage.d.ts +645 -62
- package/dist/protocol/pages/messages/createPage.js +27 -13
- package/dist/protocol/pages/messages/getPage.d.ts +38 -37
- package/dist/protocol/pages/messages/openPage.d.ts +2 -2
- package/dist/protocol/pages/messages/updatePage.d.ts +47 -48
- package/dist/protocol/pages/messages/updatePage.js +3 -3
- package/dist/protocol/pages/pageAppearance.d.ts +9 -28
- package/dist/protocol/pages/pageAppearance.js +11 -31
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +4 -20
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +2 -10
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +2 -12
- package/dist/protocol/users/makeBridgeUser.d.ts +3 -1
- package/dist/protocol/users/messages/getUser.d.ts +2 -2
- package/dist/protocol/users/messages/listUsers.d.ts +2 -2
- package/dist/protocol/utils/errors.d.ts +6 -4
- package/dist/protocol/utils/errors.js +3 -3
- package/dist/protocol/utils/ids.d.ts +2 -0
- package/dist/protocol/utils/ids.js +1 -0
- package/dist/protocol/utils/protocolVersion.d.ts +3 -1
- package/dist/protocol/utils/protocolVersion.js +5 -1
- package/dist/protocol/utils/readRequestId.d.ts +2 -0
- package/dist/protocol/utils/readRequestId.js +7 -0
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +1 -15
- package/dist/users/getUser.d.ts.map +1 -1
- package/dist/users/getUser.js +2 -1
- package/dist/users/listUsers.d.ts.map +1 -1
- package/dist/users/listUsers.js +4 -2
- package/dist/utils/version.js +1 -1
- package/docs/data-sources.md +85 -83
- package/docs/deployment.md +4 -5
- package/docs/errors.md +47 -5
- package/docs/grants.md +127 -0
- package/docs/pages.md +105 -56
- package/docs/users.md +2 -2
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +44 -243
- package/src/bridge/requests.ts +138 -0
- package/src/dataSources/bridge/resolveDataSourceQuery.ts +24 -4
- package/src/dataSources/bridge/resolveDataSources.ts +4 -4
- package/src/dataSources/createDataSourcePage.ts +5 -1
- package/src/dataSources/filters/resolveFilter.ts +12 -3
- package/src/dataSources/filters/types.ts +7 -4
- package/src/dataSources/properties/resolvePropertyAddress.ts +1 -1
- package/src/dataSources/properties/resolvePropertyWriteMapForDataSource.ts +1 -1
- package/src/dataSources/resolvePageDataSource.ts +2 -2
- package/src/dataSources/subscribeToDataSource.ts +7 -19
- package/src/dataSources/types.ts +3 -0
- package/src/files/files.ts +5 -0
- package/src/files/icons.ts +9 -0
- package/src/index.ts +10 -11
- package/src/initialization/getInitBindingError.ts +2 -2
- package/src/manifest/types.ts +10 -4
- package/src/navigation/openExternalUrl.ts +5 -1
- package/src/pages/bridge/getPageForDataSource.ts +6 -2
- package/src/pages/bridge/sendCreatePageRequest.ts +5 -1
- package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +0 -1
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -8
- package/src/pages/bridge/updatePage.ts +29 -9
- package/src/pages/createPage.ts +5 -1
- package/src/pages/openPage.ts +5 -1
- package/src/pages/properties/getPropertyByKey.ts +2 -2
- package/src/pages/types.ts +14 -16
- package/src/react/NotionCustomBlock.tsx +1 -16
- package/src/users/getUser.ts +5 -1
- package/src/users/listUsers.ts +9 -4
- package/dist/bridge/pendingRequests.d.ts +0 -14
- package/dist/bridge/pendingRequests.d.ts.map +0 -1
- package/dist/bridge/pendingRequests.js +0 -28
- package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +0 -17
- package/dist/protocol/dataSources/filters/createdByFilterOperator.js +0 -11
- package/dist/protocol/manifest/capabilities.d.ts +0 -37
- package/dist/protocol/manifest/capabilities.js +0 -13
- package/dist/protocol/pages/properties/fileInput.d.ts +0 -16
- package/dist/protocol/pages/properties/fileInput.js +0 -16
- package/dist/react/DebugMessageLog.d.ts +0 -2
- package/dist/react/DebugMessageLog.d.ts.map +0 -1
- package/dist/react/DebugMessageLog.js +0 -23
- package/docs/capabilities.md +0 -111
- package/src/bridge/pendingRequests.ts +0 -28
- package/src/react/DebugMessageLog.tsx +0 -34
package/README.md
CHANGED
|
@@ -123,8 +123,8 @@ Import React hooks and components from `@notionhq/custom-blocks/react`.
|
|
|
123
123
|
- [`docs/users.md`](docs/users.md) — `users.list / get`, the `NotionUser` shape, paging.
|
|
124
124
|
- [`docs/errors.md`](docs/errors.md) — request results, error format, error codes, retries, and
|
|
125
125
|
initialization failures.
|
|
126
|
-
- [`docs/
|
|
127
|
-
|
|
126
|
+
- [`docs/grants.md`](docs/grants.md) — the block manifest's `grants`, viewer approval, and the
|
|
127
|
+
reserved `not_granted` code.
|
|
128
128
|
- [`docs/bridge-interceptors.md`](docs/bridge-interceptors.md) — `registerMessageInterceptor` and
|
|
129
129
|
`MessageInterceptor` for controlled bridge responses.
|
|
130
130
|
- [`docs/deployment.md`](docs/deployment.md) — worker-backed deploys, localhost self-hosted
|
|
@@ -1,38 +1,14 @@
|
|
|
1
1
|
import type { QueryDataSourceResultMessage } from "../protocol/dataSources/messages/queryDataSource.js";
|
|
2
|
-
import type { BridgeMessagePayload } from "../protocol/messages/messagePayload.js";
|
|
3
2
|
import type { SandboxToHostMessage } from "../protocol/messages/sandboxToHost.js";
|
|
4
|
-
import type { OpenExternalUrlMessage, OpenExternalUrlResultMessage } from "../protocol/navigation/openExternalUrl.js";
|
|
5
|
-
import type { CreatePageMessage, CreatePageResultMessage } from "../protocol/pages/messages/createPage.js";
|
|
6
|
-
import type { GetPageMessage, GetPageResultMessage } from "../protocol/pages/messages/getPage.js";
|
|
7
|
-
import type { OpenPageMessage, OpenPageResultMessage } from "../protocol/pages/messages/openPage.js";
|
|
8
|
-
import type { UpdatePageMessage, UpdatePageResultMessage } from "../protocol/pages/messages/updatePage.js";
|
|
9
|
-
import type { GetUserMessage, GetUserResultMessage } from "../protocol/users/messages/getUser.js";
|
|
10
|
-
import type { ListUsersMessage, ListUsersResultMessage } from "../protocol/users/messages/listUsers.js";
|
|
11
3
|
import type { CustomBlockHostState } from "../context/hostState.js";
|
|
12
4
|
import type { MessageInterceptor } from "./messageInterceptor.js";
|
|
13
|
-
|
|
14
|
-
* A single entry in the bridge message log. Kept intentionally plain so the log is copy-pasteable
|
|
15
|
-
* to a local coding agent without needing extra context.
|
|
16
|
-
*/
|
|
17
|
-
type MessageLogEntry = {
|
|
18
|
-
timestamp: string;
|
|
19
|
-
direction: "sent" | "received";
|
|
20
|
-
data: unknown;
|
|
21
|
-
};
|
|
5
|
+
import { type RequestMessage, type ResponseSchema } from "./requests.js";
|
|
22
6
|
export declare class SandboxBridge {
|
|
23
7
|
private hostState;
|
|
24
8
|
private listeners;
|
|
25
9
|
private dataSourceQueryListeners;
|
|
26
10
|
private messageInterceptors;
|
|
27
|
-
private
|
|
28
|
-
private messageLogListeners;
|
|
29
|
-
private readonly pendingCreatePage;
|
|
30
|
-
private readonly pendingGetPage;
|
|
31
|
-
private readonly pendingGetUser;
|
|
32
|
-
private readonly pendingListUsers;
|
|
33
|
-
private readonly pendingOpenPage;
|
|
34
|
-
private readonly pendingOpenExternalUrl;
|
|
35
|
-
private readonly pendingUpdatePage;
|
|
11
|
+
private readonly requests;
|
|
36
12
|
private latestDataSourceBindings;
|
|
37
13
|
private isListening;
|
|
38
14
|
private isDisposed;
|
|
@@ -43,14 +19,10 @@ export declare class SandboxBridge {
|
|
|
43
19
|
* acknowledgment callbacks, removes the message listener, and discards queued
|
|
44
20
|
* outbound messages. Further host messages are ignored.
|
|
45
21
|
*
|
|
46
|
-
* Pending
|
|
22
|
+
* Pending requests complete with request_disposed, and their timers are cleared.
|
|
47
23
|
*/
|
|
48
24
|
dispose(): void;
|
|
49
25
|
startListening(): void;
|
|
50
|
-
private static MAX_LOG_ENTRIES;
|
|
51
|
-
private logMessage;
|
|
52
|
-
getMessageLog: () => readonly MessageLogEntry[];
|
|
53
|
-
subscribeToMessageLog: (listener: () => void) => () => boolean;
|
|
54
26
|
registerMessageInterceptor(interceptor: MessageInterceptor): () => void;
|
|
55
27
|
postToHost(message: SandboxToHostMessage): void;
|
|
56
28
|
private sendToHost;
|
|
@@ -62,13 +34,6 @@ export declare class SandboxBridge {
|
|
|
62
34
|
subscribeToDataSourceQueryResults(subscriptionId: string, listener: (message: QueryDataSourceResultMessage) => void): () => void;
|
|
63
35
|
completeInitialization(): void;
|
|
64
36
|
private applyInit;
|
|
65
|
-
|
|
66
|
-
requestGetPage(args: Omit<GetPageMessage, "type" | "requestId">): Promise<BridgeMessagePayload<GetPageResultMessage>>;
|
|
67
|
-
requestUpdatePage(args: Omit<UpdatePageMessage, "type" | "requestId">): Promise<BridgeMessagePayload<UpdatePageResultMessage>>;
|
|
68
|
-
requestGetUser(args: Omit<GetUserMessage, "type" | "requestId">): Promise<BridgeMessagePayload<GetUserResultMessage>>;
|
|
69
|
-
requestListUsers(args: Omit<ListUsersMessage, "type" | "requestId">): Promise<BridgeMessagePayload<ListUsersResultMessage>>;
|
|
70
|
-
requestOpenPage(args: Omit<OpenPageMessage, "type" | "requestId">): Promise<BridgeMessagePayload<OpenPageResultMessage>>;
|
|
71
|
-
requestOpenExternalUrl(args: Omit<OpenExternalUrlMessage, "type" | "requestId">): Promise<BridgeMessagePayload<OpenExternalUrlResultMessage>>;
|
|
37
|
+
request<Schema extends ResponseSchema>(message: RequestMessage, responseSchema: Schema): Promise<import("./requests.js").RequestResult<Schema>>;
|
|
72
38
|
}
|
|
73
|
-
export {};
|
|
74
39
|
//# sourceMappingURL=SandboxBridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0EAA0E,CAAA;AAM5H,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0EAA0E,CAAA;AAM5H,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AAItG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAQnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EACN,KAAK,cAAc,EAEnB,KAAK,cAAc,EACnB,MAAM,eAAe,CAAA;AAEtB,qBAAa,aAAa;IACzB,OAAO,CAAC,SAAS,CAIhB;IAED,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,wBAAwB,CAG7B;IACH,OAAO,CAAC,mBAAmB,CAAgC;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoD;IAC7E,OAAO,CAAC,wBAAwB,CAA+B;IAC/D,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAM7B;IAEF,UAAU,0DAET;IAED;;;;;;OAMG;IACH,OAAO,SAUN;IAED,cAAc,SAMb;IAED,0BAA0B,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAGtE;IAED,UAAU,CAAC,OAAO,EAAE,oBAAoB,QAEvC;IAED,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,cAAc;IAgItB,SAAS,aAAc,MAAM,IAAI,mBAGhC;IAED,YAAY,QAAO,oBAAoB,CAEtC;IAED,OAAO,CAAC,eAAe;IAevB,iCAAiC,CAChC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,CAAC,OAAO,EAAE,4BAA4B,KAAK,IAAI,GACvD,MAAM,IAAI,CAKZ;IAED,sBAAsB,SAErB;IAED,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,MAAM,SAAS,cAAc,EACpC,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,MAAM,0DAGtB;CACD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_CONTRAST_MODE } from "../protocol/context/contrast.js";
|
|
2
2
|
import { hostToSandboxMessageSchema } from "../protocol/messages/hostToSandbox.js";
|
|
3
3
|
import { readIncomingType } from "../protocol/messages/incomingType.js";
|
|
4
|
+
import { readRequestId } from "../protocol/utils/readRequestId.js";
|
|
4
5
|
import * as v from "valibot";
|
|
5
6
|
import { applyContextMessage } from "../context/applyContextMessage.js";
|
|
6
7
|
import { syncDocumentAppearance } from "../context/syncDocumentAppearance.js";
|
|
@@ -10,7 +11,7 @@ import { getInitialContentHeight } from "../layout/getInitialContentHeight.js";
|
|
|
10
11
|
import { notifyListener } from "../utils/notifyListener.js";
|
|
11
12
|
import { unreachable } from "../utils/unreachable.js";
|
|
12
13
|
import { SandboxInitialization } from "./initialization/SandboxInitialization.js";
|
|
13
|
-
import {
|
|
14
|
+
import { Requests, } from "./requests.js";
|
|
14
15
|
export class SandboxBridge {
|
|
15
16
|
hostState = {
|
|
16
17
|
status: "uninitialized",
|
|
@@ -20,15 +21,7 @@ export class SandboxBridge {
|
|
|
20
21
|
listeners = new Set();
|
|
21
22
|
dataSourceQueryListeners = new Map();
|
|
22
23
|
messageInterceptors = new Set();
|
|
23
|
-
|
|
24
|
-
messageLogListeners = new Set();
|
|
25
|
-
pendingCreatePage = new PendingRequests("custom-block-create-page");
|
|
26
|
-
pendingGetPage = new PendingRequests("custom-block-get-page");
|
|
27
|
-
pendingGetUser = new PendingRequests("custom-block-get-user");
|
|
28
|
-
pendingListUsers = new PendingRequests("custom-block-list-users");
|
|
29
|
-
pendingOpenPage = new PendingRequests("custom-block-open-page");
|
|
30
|
-
pendingOpenExternalUrl = new PendingRequests("custom-block-open-url");
|
|
31
|
-
pendingUpdatePage = new PendingRequests("custom-block-update-page");
|
|
24
|
+
requests = new Requests(message => this.postToHost(message));
|
|
32
25
|
latestDataSourceBindings = {};
|
|
33
26
|
isListening = false;
|
|
34
27
|
isDisposed = false;
|
|
@@ -47,10 +40,11 @@ export class SandboxBridge {
|
|
|
47
40
|
* acknowledgment callbacks, removes the message listener, and discards queued
|
|
48
41
|
* outbound messages. Further host messages are ignored.
|
|
49
42
|
*
|
|
50
|
-
* Pending
|
|
43
|
+
* Pending requests complete with request_disposed, and their timers are cleared.
|
|
51
44
|
*/
|
|
52
45
|
dispose() {
|
|
53
46
|
this.isDisposed = true;
|
|
47
|
+
this.requests.disposeAll();
|
|
54
48
|
this.initialization.dispose();
|
|
55
49
|
if (this.isListening) {
|
|
56
50
|
window.removeEventListener("message", this.handleMessage);
|
|
@@ -58,7 +52,6 @@ export class SandboxBridge {
|
|
|
58
52
|
}
|
|
59
53
|
this.listeners.clear();
|
|
60
54
|
this.dataSourceQueryListeners.clear();
|
|
61
|
-
this.messageLogListeners.clear();
|
|
62
55
|
}
|
|
63
56
|
startListening() {
|
|
64
57
|
if (this.isDisposed || this.isListening || typeof window === "undefined") {
|
|
@@ -67,27 +60,6 @@ export class SandboxBridge {
|
|
|
67
60
|
this.isListening = true;
|
|
68
61
|
window.addEventListener("message", this.handleMessage);
|
|
69
62
|
}
|
|
70
|
-
static MAX_LOG_ENTRIES = 100;
|
|
71
|
-
logMessage(direction, data) {
|
|
72
|
-
if (this.messageLog.length >= SandboxBridge.MAX_LOG_ENTRIES) {
|
|
73
|
-
this.messageLog.shift();
|
|
74
|
-
}
|
|
75
|
-
this.messageLog.push({
|
|
76
|
-
timestamp: new Date().toISOString(),
|
|
77
|
-
direction,
|
|
78
|
-
data: redactExternalUrl(data),
|
|
79
|
-
});
|
|
80
|
-
for (const listener of this.messageLogListeners) {
|
|
81
|
-
listener();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
getMessageLog = () => {
|
|
85
|
-
return this.messageLog;
|
|
86
|
-
};
|
|
87
|
-
subscribeToMessageLog = (listener) => {
|
|
88
|
-
this.messageLogListeners.add(listener);
|
|
89
|
-
return () => this.messageLogListeners.delete(listener);
|
|
90
|
-
};
|
|
91
63
|
registerMessageInterceptor(interceptor) {
|
|
92
64
|
this.messageInterceptors.add(interceptor);
|
|
93
65
|
return () => this.messageInterceptors.delete(interceptor);
|
|
@@ -103,7 +75,6 @@ export class SandboxBridge {
|
|
|
103
75
|
return;
|
|
104
76
|
}
|
|
105
77
|
}
|
|
106
|
-
this.logMessage("sent", message);
|
|
107
78
|
window.parent.postMessage(message, "*");
|
|
108
79
|
}
|
|
109
80
|
handleMessage = (event) => {
|
|
@@ -116,7 +87,6 @@ export class SandboxBridge {
|
|
|
116
87
|
if (this.isDisposed) {
|
|
117
88
|
return;
|
|
118
89
|
}
|
|
119
|
-
this.logMessage("received", data);
|
|
120
90
|
const parsed = v.safeParse(hostToSandboxMessageSchema, data);
|
|
121
91
|
if (!parsed.success) {
|
|
122
92
|
console.warn("[custom-blocks-sdk] ignoring malformed host message", parsed.issues);
|
|
@@ -125,6 +95,15 @@ export class SandboxBridge {
|
|
|
125
95
|
this.initialization.handleInvalidInit(readInitializationId(data), invalidInitPayloadError(parsed.issues))) {
|
|
126
96
|
return;
|
|
127
97
|
}
|
|
98
|
+
const requestId = readRequestId(data);
|
|
99
|
+
const reason = formatInvalidHostReason(incomingType, parsed.issues);
|
|
100
|
+
if (requestId !== undefined) {
|
|
101
|
+
this.requests.fail(requestId, {
|
|
102
|
+
code: "invalid_host_message",
|
|
103
|
+
message: reason,
|
|
104
|
+
isRetryable: false,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
128
107
|
// Loop guard: never NACK a NACK. Excludes both directions —
|
|
129
108
|
// `invalidSandboxMessage` is what the host normally sends, but
|
|
130
109
|
// a buggy host that echoes our own `invalidHostMessage` back
|
|
@@ -133,18 +112,22 @@ export class SandboxBridge {
|
|
|
133
112
|
incomingType !== "invalidHostMessage") {
|
|
134
113
|
const nack = {
|
|
135
114
|
type: "invalidHostMessage",
|
|
136
|
-
|
|
115
|
+
...(requestId !== undefined ? { requestId } : {}),
|
|
116
|
+
reason,
|
|
137
117
|
};
|
|
138
118
|
this.postToHost(nack);
|
|
139
119
|
}
|
|
140
120
|
return;
|
|
141
121
|
}
|
|
142
122
|
const message = parsed.output;
|
|
143
|
-
// If the host couldn't parse one of our outbound sandbox-to-host messages, it sends back an
|
|
144
|
-
// `invalidSandboxMessage` NACK with a human-readable `reason`. Log it for developer
|
|
145
|
-
// visibility and stop. We don't retry as the sandbox can't recover from a host-side parse
|
|
146
|
-
// failure on its own.
|
|
147
123
|
if (message.type === "invalidSandboxMessage") {
|
|
124
|
+
if (message.requestId !== undefined) {
|
|
125
|
+
this.requests.fail(message.requestId, {
|
|
126
|
+
code: "invalid_sandbox_message",
|
|
127
|
+
message: message.reason,
|
|
128
|
+
isRetryable: false,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
148
131
|
console.warn("[custom-blocks-sdk] host reported invalid sandbox message:", message.reason);
|
|
149
132
|
return;
|
|
150
133
|
}
|
|
@@ -161,6 +144,17 @@ export class SandboxBridge {
|
|
|
161
144
|
console.warn(`[custom-blocks-sdk] ignoring ${message.type} before init`);
|
|
162
145
|
return;
|
|
163
146
|
}
|
|
147
|
+
if ("requestId" in message) {
|
|
148
|
+
const error = this.requests.receive(message);
|
|
149
|
+
if (error !== undefined) {
|
|
150
|
+
this.postToHost({
|
|
151
|
+
type: "invalidHostMessage",
|
|
152
|
+
requestId: message.requestId,
|
|
153
|
+
reason: error.message,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
164
158
|
switch (message.type) {
|
|
165
159
|
case "themeChanged":
|
|
166
160
|
case "contrastModeChanged":
|
|
@@ -175,55 +169,6 @@ export class SandboxBridge {
|
|
|
175
169
|
this.commitHostState(nextState);
|
|
176
170
|
return;
|
|
177
171
|
}
|
|
178
|
-
case "createPageResult": {
|
|
179
|
-
const { type: _, requestId, ...result } = message;
|
|
180
|
-
if (!this.pendingCreatePage.resolve(requestId, result)) {
|
|
181
|
-
console.warn(`[custom-blocks-sdk] createPageResult for unknown requestId ${message.requestId}`);
|
|
182
|
-
}
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
case "getPageResult": {
|
|
186
|
-
const { type: _, requestId, ...result } = message;
|
|
187
|
-
if (!this.pendingGetPage.resolve(requestId, result)) {
|
|
188
|
-
console.warn(`[custom-blocks-sdk] getPageResult for unknown requestId ${message.requestId}`);
|
|
189
|
-
}
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
case "getUserResult": {
|
|
193
|
-
const { type: _, requestId, ...result } = message;
|
|
194
|
-
if (!this.pendingGetUser.resolve(requestId, result)) {
|
|
195
|
-
console.warn(`[custom-blocks-sdk] getUserResult for unknown requestId ${message.requestId}`);
|
|
196
|
-
}
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
case "listUsersResult": {
|
|
200
|
-
const { type: _, requestId, ...result } = message;
|
|
201
|
-
if (!this.pendingListUsers.resolve(requestId, result)) {
|
|
202
|
-
console.warn(`[custom-blocks-sdk] listUsersResult for unknown requestId ${message.requestId}`);
|
|
203
|
-
}
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
case "openPageResult": {
|
|
207
|
-
const { type: _, requestId, ...result } = message;
|
|
208
|
-
if (!this.pendingOpenPage.resolve(requestId, result)) {
|
|
209
|
-
console.warn(`[custom-blocks-sdk] openPageResult for unknown requestId ${message.requestId}`);
|
|
210
|
-
}
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
case "openExternalUrlResult": {
|
|
214
|
-
const { type: _, requestId, ...result } = message;
|
|
215
|
-
if (!this.pendingOpenExternalUrl.resolve(requestId, result)) {
|
|
216
|
-
console.warn(`[custom-blocks-sdk] openExternalUrlResult for unknown requestId ${message.requestId}`);
|
|
217
|
-
}
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
case "updatePageResult": {
|
|
221
|
-
const { type: _, requestId, ...result } = message;
|
|
222
|
-
if (!this.pendingUpdatePage.resolve(requestId, result)) {
|
|
223
|
-
console.warn(`[custom-blocks-sdk] updatePageResult for unknown requestId ${message.requestId}`);
|
|
224
|
-
}
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
172
|
case "queryDataSourceResult": {
|
|
228
173
|
const listener = this.dataSourceQueryListeners.get(message.subscriptionId);
|
|
229
174
|
if (listener !== undefined) {
|
|
@@ -273,47 +218,8 @@ export class SandboxBridge {
|
|
|
273
218
|
this.commitHostState(result.state);
|
|
274
219
|
return undefined;
|
|
275
220
|
}
|
|
276
|
-
|
|
277
|
-
return
|
|
278
|
-
const requestId = this.pendingCreatePage.allocate(resolve);
|
|
279
|
-
this.postToHost({ type: "createPage", requestId, ...args });
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
requestGetPage(args) {
|
|
283
|
-
return new Promise(resolve => {
|
|
284
|
-
const requestId = this.pendingGetPage.allocate(resolve);
|
|
285
|
-
this.postToHost({ type: "getPage", requestId, ...args });
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
requestUpdatePage(args) {
|
|
289
|
-
return new Promise(resolve => {
|
|
290
|
-
const requestId = this.pendingUpdatePage.allocate(resolve);
|
|
291
|
-
this.postToHost({ type: "updatePage", requestId, ...args });
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
requestGetUser(args) {
|
|
295
|
-
return new Promise(resolve => {
|
|
296
|
-
const requestId = this.pendingGetUser.allocate(resolve);
|
|
297
|
-
this.postToHost({ type: "getUser", requestId, ...args });
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
requestListUsers(args) {
|
|
301
|
-
return new Promise(resolve => {
|
|
302
|
-
const requestId = this.pendingListUsers.allocate(resolve);
|
|
303
|
-
this.postToHost({ type: "listUsers", requestId, ...args });
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
requestOpenPage(args) {
|
|
307
|
-
return new Promise(resolve => {
|
|
308
|
-
const requestId = this.pendingOpenPage.allocate(resolve);
|
|
309
|
-
this.postToHost({ type: "openPage", requestId, ...args });
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
requestOpenExternalUrl(args) {
|
|
313
|
-
return new Promise(resolve => {
|
|
314
|
-
const requestId = this.pendingOpenExternalUrl.allocate(resolve);
|
|
315
|
-
this.postToHost({ type: "openExternalUrl", requestId, ...args });
|
|
316
|
-
});
|
|
221
|
+
request(message, responseSchema) {
|
|
222
|
+
return this.requests.send(message, responseSchema);
|
|
317
223
|
}
|
|
318
224
|
}
|
|
319
225
|
function invalidInitPayloadError(issues) {
|
|
@@ -332,18 +238,6 @@ function readInitializationId(data) {
|
|
|
332
238
|
}
|
|
333
239
|
return undefined;
|
|
334
240
|
}
|
|
335
|
-
function redactExternalUrl(data) {
|
|
336
|
-
if (typeof data === "object" &&
|
|
337
|
-
data !== null &&
|
|
338
|
-
"type" in data &&
|
|
339
|
-
data.type === "openExternalUrl") {
|
|
340
|
-
return {
|
|
341
|
-
type: "openExternalUrl",
|
|
342
|
-
...("requestId" in data ? { requestId: data.requestId } : {}),
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
return data;
|
|
346
|
-
}
|
|
347
241
|
function formatInvalidHostReason(incomingType, issues) {
|
|
348
242
|
const labelled = incomingType
|
|
349
243
|
? `host message of type "${incomingType}"`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SandboxToHostMessage } from "../protocol/messages/sandboxToHost.js";
|
|
2
|
+
import type { CustomBlockErrorInfo } from "../protocol/utils/errors.js";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
export type RequestMessage<Message = SandboxToHostMessage> = Message extends {
|
|
5
|
+
requestId: string;
|
|
6
|
+
} ? Omit<Message, "requestId"> : never;
|
|
7
|
+
export type RequestError = {
|
|
8
|
+
status: "error";
|
|
9
|
+
error: CustomBlockErrorInfo;
|
|
10
|
+
};
|
|
11
|
+
export type ResponseSchema = v.GenericSchema<unknown, {
|
|
12
|
+
type: string;
|
|
13
|
+
requestId: string;
|
|
14
|
+
status: "success";
|
|
15
|
+
} | RequestError>;
|
|
16
|
+
export type RequestResult<Schema extends ResponseSchema> = Omit<Extract<v.InferOutput<Schema>, {
|
|
17
|
+
status: "success";
|
|
18
|
+
}>, "type" | "requestId"> | RequestError;
|
|
19
|
+
/** Owns correlation, response validation, and completion for one bridge's requests. */
|
|
20
|
+
export declare class Requests {
|
|
21
|
+
private readonly post;
|
|
22
|
+
private readonly timeoutMs;
|
|
23
|
+
private nextId;
|
|
24
|
+
private isDisposed;
|
|
25
|
+
private readonly pending;
|
|
26
|
+
constructor(post: (message: SandboxToHostMessage) => void, timeoutMs?: number);
|
|
27
|
+
send<Schema extends ResponseSchema>(message: RequestMessage, responseSchema: Schema): Promise<RequestResult<Schema>>;
|
|
28
|
+
receive<Message extends {
|
|
29
|
+
requestId: string;
|
|
30
|
+
}>(message: Message): CustomBlockErrorInfo | undefined;
|
|
31
|
+
fail(requestId: string, error: CustomBlockErrorInfo): void;
|
|
32
|
+
disposeAll(): void;
|
|
33
|
+
private finish;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../src/bridge/requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AACtG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAA;AAC5F,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,MAAM,MAAM,cAAc,CAAC,OAAO,GAAG,oBAAoB,IAAI,OAAO,SAAS;IAC5E,SAAS,EAAE,MAAM,CAAA;CACjB,GACE,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAC1B,KAAK,CAAA;AAER,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAA;CAAE,CAAA;AAQ3E,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,aAAa,CAC3C,OAAO,EACP;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,GAAG,YAAY,CACrE,CAAA;AACD,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,cAAc,IACpD,IAAI,CACJ,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC,EACrD,MAAM,GAAG,WAAW,CACnB,GACD,YAAY,CAAA;AAEf,uFAAuF;AACvF,qBAAa,QAAQ;IAMnB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN3B,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAE5D,YACkB,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,EAC7C,SAAS,SAAS,EAChC;IAEJ,IAAI,CAAC,MAAM,SAAS,cAAc,EACjC,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CA8ChC;IAED,OAAO,CAAC,OAAO,SAAS;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAC5C,OAAO,EAAE,OAAO,GACd,oBAAoB,GAAG,SAAS,CASlC;IAED,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,QAElD;IAED,UAAU,SAKT;IAED,OAAO,CAAC,MAAM;CAQd"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** Owns correlation, response validation, and completion for one bridge's requests. */
|
|
3
|
+
export class Requests {
|
|
4
|
+
post;
|
|
5
|
+
timeoutMs;
|
|
6
|
+
nextId = 1;
|
|
7
|
+
isDisposed = false;
|
|
8
|
+
pending = new Map();
|
|
9
|
+
constructor(post, timeoutMs = 60_000) {
|
|
10
|
+
this.post = post;
|
|
11
|
+
this.timeoutMs = timeoutMs;
|
|
12
|
+
}
|
|
13
|
+
send(message, responseSchema) {
|
|
14
|
+
if (this.isDisposed) {
|
|
15
|
+
return Promise.resolve({ status: "error", error: disposedError() });
|
|
16
|
+
}
|
|
17
|
+
return new Promise(resolve => {
|
|
18
|
+
const requestId = `custom-block-request-${this.nextId++}`;
|
|
19
|
+
const timeout = setTimeout(() => {
|
|
20
|
+
this.fail(requestId, {
|
|
21
|
+
code: "request_timeout",
|
|
22
|
+
message: `The host did not return a result within ${this.timeoutMs} ms. The operation may still complete.`,
|
|
23
|
+
isRetryable: false,
|
|
24
|
+
});
|
|
25
|
+
}, this.timeoutMs);
|
|
26
|
+
this.pending.set(requestId, {
|
|
27
|
+
timeout,
|
|
28
|
+
fail: error => resolve({ status: "error", error }),
|
|
29
|
+
receive: response => {
|
|
30
|
+
const parsed = v.safeParse(responseSchema, response);
|
|
31
|
+
if (!parsed.success) {
|
|
32
|
+
const error = {
|
|
33
|
+
code: "invalid_host_message",
|
|
34
|
+
message: `The host returned an invalid response to ${message.type}.`,
|
|
35
|
+
isRetryable: false,
|
|
36
|
+
};
|
|
37
|
+
resolve({ status: "error", error });
|
|
38
|
+
return error;
|
|
39
|
+
}
|
|
40
|
+
if (isSuccessResponse(parsed.output)) {
|
|
41
|
+
const { type: _, requestId: __, ...result } = parsed.output;
|
|
42
|
+
resolve(result);
|
|
43
|
+
}
|
|
44
|
+
else if (parsed.output.status === "error") {
|
|
45
|
+
resolve({ status: "error", error: parsed.output.error });
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
this.post({ ...message, requestId });
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.warn("[custom-blocks-sdk] could not send request", error);
|
|
54
|
+
this.fail(requestId, {
|
|
55
|
+
code: "request_send_failed",
|
|
56
|
+
message: "The SDK could not send the request to the host.",
|
|
57
|
+
isRetryable: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
receive(message) {
|
|
63
|
+
const request = this.finish(message.requestId);
|
|
64
|
+
if (request === undefined) {
|
|
65
|
+
console.warn(`[custom-blocks-sdk] result for unknown requestId ${message.requestId}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
return request.receive(message);
|
|
69
|
+
}
|
|
70
|
+
fail(requestId, error) {
|
|
71
|
+
this.finish(requestId)?.fail(error);
|
|
72
|
+
}
|
|
73
|
+
disposeAll() {
|
|
74
|
+
this.isDisposed = true;
|
|
75
|
+
for (const requestId of this.pending.keys()) {
|
|
76
|
+
this.fail(requestId, disposedError());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finish(requestId) {
|
|
80
|
+
const request = this.pending.get(requestId);
|
|
81
|
+
if (request !== undefined) {
|
|
82
|
+
this.pending.delete(requestId);
|
|
83
|
+
clearTimeout(request.timeout);
|
|
84
|
+
}
|
|
85
|
+
return request;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function disposedError() {
|
|
89
|
+
return {
|
|
90
|
+
code: "request_disposed",
|
|
91
|
+
message: "The SDK bridge was disposed. The operation may still complete.",
|
|
92
|
+
isRetryable: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function isSuccessResponse(response) {
|
|
96
|
+
return response.status === "success";
|
|
97
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveDataSourceQuery.d.ts","sourceRoot":"","sources":["../../../src/dataSources/bridge/resolveDataSourceQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mCAAmC,EACnC,sBAAsB,EACtB,MAAM,0EAA0E,CAAA;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kEAAkE,CAAA;AACxG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AAGvG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveDataSourceQuery.d.ts","sourceRoot":"","sources":["../../../src/dataSources/bridge/resolveDataSourceQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mCAAmC,EACnC,sBAAsB,EACtB,MAAM,0EAA0E,CAAA;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kEAAkE,CAAA;AACxG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AAGvG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAYvD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC5C,WAAW,EAAE,gBAAgB,EAAE,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,GACE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,mCAAmC,CAAA;CAAE,GAC/D;IACA,MAAM,EAAE,IAAI,CAAA;IACZ,KAAK,EAAE,oBAAoB,CAAC,sBAAsB,CAAC,CAAA;CAClD,CAmGH;AA+ED,wBAAgB,iCAAiC,CAChD,OAAO,EAAE,oBAAoB,GAAG,SAAS,GACvC,MAAM,CAMR"}
|
|
@@ -19,7 +19,7 @@ export function resolveDataSourceQuery(args) {
|
|
|
19
19
|
if (dataSource.inaccessible === true) {
|
|
20
20
|
return { status: "error", error: dataSourceInaccessibleError(key) };
|
|
21
21
|
}
|
|
22
|
-
if (dataSource.
|
|
22
|
+
if (dataSource.dataSourcePointer === undefined) {
|
|
23
23
|
return {
|
|
24
24
|
status: "error",
|
|
25
25
|
error: {
|
|
@@ -40,7 +40,7 @@ export function resolveDataSourceQuery(args) {
|
|
|
40
40
|
const queryOptions = resolvedOptions.options;
|
|
41
41
|
if ((queryOptions?.filter !== undefined ||
|
|
42
42
|
(Array.isArray(queryOptions?.sorts) && queryOptions.sorts.length > 0)) &&
|
|
43
|
-
dataSource.
|
|
43
|
+
dataSource.dataSourceSchema === undefined) {
|
|
44
44
|
return {
|
|
45
45
|
status: "error",
|
|
46
46
|
error: {
|
|
@@ -70,13 +70,24 @@ export function resolveDataSourceQuery(args) {
|
|
|
70
70
|
if (sorts.status === "error") {
|
|
71
71
|
return { status: "error", error: getInvalidQueryError(sorts.error) };
|
|
72
72
|
}
|
|
73
|
+
const archiveStatus = queryOptions?.archiveStatus;
|
|
74
|
+
if (archiveStatus !== undefined &&
|
|
75
|
+
archiveStatus !== "active" &&
|
|
76
|
+
archiveStatus !== "archived" &&
|
|
77
|
+
archiveStatus !== "all") {
|
|
78
|
+
return {
|
|
79
|
+
status: "error",
|
|
80
|
+
error: getInvalidQueryError('Data source archiveStatus must be "active", "archived", or "all".'),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
73
83
|
return {
|
|
74
84
|
status: "ok",
|
|
75
85
|
query: {
|
|
76
|
-
dataSourceId: dataSource.
|
|
86
|
+
dataSourceId: dataSource.dataSourcePointer.id,
|
|
77
87
|
limit: limit.limit,
|
|
78
88
|
filter: filter.filter,
|
|
79
89
|
sorts: sorts.sorts,
|
|
90
|
+
...(archiveStatus !== undefined ? { archive_status: archiveStatus } : {}),
|
|
80
91
|
},
|
|
81
92
|
};
|
|
82
93
|
}
|
|
@@ -104,7 +115,7 @@ function resolveDataSourceQueryOptions(options) {
|
|
|
104
115
|
};
|
|
105
116
|
}
|
|
106
117
|
const optionsObject = options;
|
|
107
|
-
if (Object.keys(optionsObject).some(key => !["limit", "filter", "sorts"].includes(key))) {
|
|
118
|
+
if (Object.keys(optionsObject).some(key => !["limit", "filter", "sorts", "archiveStatus"].includes(key))) {
|
|
108
119
|
return {
|
|
109
120
|
status: "error",
|
|
110
121
|
error: "Data source query options contain unsupported fields.",
|
|
@@ -113,6 +124,9 @@ function resolveDataSourceQueryOptions(options) {
|
|
|
113
124
|
return {
|
|
114
125
|
status: "ok",
|
|
115
126
|
options: {
|
|
127
|
+
archiveStatus: Object.hasOwn(optionsObject, "archiveStatus")
|
|
128
|
+
? optionsObject.archiveStatus
|
|
129
|
+
: undefined,
|
|
116
130
|
limit: Object.hasOwn(optionsObject, "limit")
|
|
117
131
|
? optionsObject.limit
|
|
118
132
|
: undefined,
|
|
@@ -9,10 +9,10 @@ import { resolveDataSourceBinding } from "../../protocol/dataSources/resolveData
|
|
|
9
9
|
export function resolveDataSources(args) {
|
|
10
10
|
return Object.entries(args.manifest.dataSources).map(([key, manifestDataSource]) => {
|
|
11
11
|
const binding = args.dataSourceBindings[key];
|
|
12
|
-
const collectionProperties = binding?.
|
|
12
|
+
const collectionProperties = binding?.dataSourceSchema?.propertiesById ?? {};
|
|
13
13
|
const resolvedBinding = resolveDataSourceBinding({
|
|
14
14
|
manifestDataSource,
|
|
15
|
-
|
|
15
|
+
dataSourceSchema: binding?.dataSourceSchema,
|
|
16
16
|
propertyIdsByKey: binding?.propertyIdsByKey,
|
|
17
17
|
});
|
|
18
18
|
const propertyIdsByKey = {};
|
|
@@ -22,8 +22,8 @@ export function resolveDataSources(args) {
|
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
key,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
dataSourcePointer: binding?.dataSourcePointer,
|
|
26
|
+
dataSourceSchema: binding?.dataSourceSchema,
|
|
27
27
|
propertyIdsByKey,
|
|
28
28
|
propertySchemasById: collectionProperties,
|
|
29
29
|
...(binding?.inaccessible === true && { inaccessible: true }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDataSourcePage.d.ts","sourceRoot":"","sources":["../../src/dataSources/createDataSourcePage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,wBAAsB,oBAAoB,CACzC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,UAAU,CAAC,GAClD,OAAO,CAAC,qBAAqB,CAAC,
|
|
1
|
+
{"version":3,"file":"createDataSourcePage.d.ts","sourceRoot":"","sources":["../../src/dataSources/createDataSourcePage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,wBAAsB,oBAAoB,CACzC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,UAAU,CAAC,GAClD,OAAO,CAAC,qBAAqB,CAAC,CAuChC"}
|
|
@@ -26,7 +26,11 @@ export async function createDataSourcePage(key, payload) {
|
|
|
26
26
|
}
|
|
27
27
|
const result = await sendCreatePageRequest({
|
|
28
28
|
bridge,
|
|
29
|
-
request:
|
|
29
|
+
request: {
|
|
30
|
+
...prepared.request,
|
|
31
|
+
...(payload.icon === undefined ? {} : { icon: payload.icon }),
|
|
32
|
+
...(payload.cover === undefined ? {} : { cover: payload.cover }),
|
|
33
|
+
},
|
|
30
34
|
dataSource,
|
|
31
35
|
});
|
|
32
36
|
if (result.status === "error") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveFilter.d.ts","sourceRoot":"","sources":["../../../src/dataSources/filters/resolveFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gFAAgF,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveFilter.d.ts","sourceRoot":"","sources":["../../../src/dataSources/filters/resolveFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gFAAgF,CAAA;AAK5H,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kEAAkE,CAAA;AAUxG,wBAAgB,aAAa,CAC5B,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,gBAAgB,GAE1B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,sBAAsB,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAsCpC"}
|