@notionhq/custom-blocks 0.0.78 → 0.0.79
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/HOST.md +9 -2
- package/README.md +1 -1
- package/dist/bridge/SandboxBridge.d.ts +1 -1
- package/dist/bridge/SandboxBridge.js +1 -1
- package/dist/bridge/messages/connect.d.ts +1 -1
- package/dist/bridge/messages/connect.d.ts.map +1 -1
- package/dist/bridge/messages/connect.js +2 -8
- package/dist/bridge/messages/sandboxToHost.d.ts +1 -1
- package/dist/host/createCustomBlockHost.d.ts +1 -1
- package/dist/host/createCustomBlockHost.d.ts.map +1 -1
- package/dist/host/createCustomBlockHost.js +17 -4
- package/dist/host/lifecycle/{ready.d.ts → protocolVersion.d.ts} +1 -1
- package/dist/host/lifecycle/protocolVersion.d.ts.map +1 -0
- package/dist/version.js +1 -1
- package/docs/data-sources.md +3 -3
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +1 -1
- package/src/bridge/messages/connect.ts +2 -9
- package/src/host/createCustomBlockHost.ts +25 -5
- package/dist/host/lifecycle/ready.d.ts.map +0 -1
- /package/dist/host/lifecycle/{ready.js → protocolVersion.js} +0 -0
- /package/src/host/lifecycle/{ready.ts → protocolVersion.ts} +0 -0
package/HOST.md
CHANGED
|
@@ -25,6 +25,7 @@ import { createCustomBlockHost } from "@notionhq/custom-blocks/host";
|
|
|
25
25
|
|
|
26
26
|
const host = createCustomBlockHost({
|
|
27
27
|
iframe,
|
|
28
|
+
minBridgeProtocolVersion: 3,
|
|
28
29
|
initialState: {
|
|
29
30
|
theme,
|
|
30
31
|
blockId,
|
|
@@ -35,14 +36,20 @@ const host = createCustomBlockHost({
|
|
|
35
36
|
dataSources: { bindings },
|
|
36
37
|
},
|
|
37
38
|
handlers: {
|
|
38
|
-
queryDataSource: async (message) => ({
|
|
39
|
+
queryDataSource: async (message) => ({
|
|
40
|
+
status: "success",
|
|
41
|
+
items: [],
|
|
42
|
+
hasMore: false,
|
|
43
|
+
}),
|
|
39
44
|
},
|
|
40
45
|
});
|
|
41
46
|
```
|
|
42
47
|
|
|
43
48
|
Use it when the generic protocol loop is helpful. Hosts with more specialized runtime needs can keep using the schemas and message types directly.
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
Responses return a `status`-discriminated result: `"success"` carries `items` and required `hasMore`; `"error"` carries the structured `error`. Set `hasMore` to `false` when no additional results are available.
|
|
51
|
+
|
|
52
|
+
Related exports: `CustomBlockHostOptions`, `CustomBlockHostInitialState`, `CustomBlockHostInitialDataSources`, `CustomBlockHostDataSourcesPayload`, `ConnectSuccessMessage`, `CustomBlockHostHandlers`, `CustomBlockHostHandle`, `CustomBlockHostLogDirection`, `CustomBlockHostQueryDataSourceResult`, `CustomBlockHostCreatePageResult`, `CustomBlockHostGetPageResult`, `CustomBlockHostUpdatePageResult`, `CustomBlockHostGetUserResult`, and `CustomBlockHostListUsersResult`.
|
|
46
53
|
|
|
47
54
|
## Bridge protocol
|
|
48
55
|
|
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ export function App() {
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
`<NotionCustomBlock>` runs the SDK ↔ host handshake (
|
|
38
|
+
`<NotionCustomBlock>` runs the SDK ↔ host handshake (`connect` → `init` → `initResult`) and only mounts `children` once it resolves. Inside the wrapper, every hook returns non-nullable values — there's no separate gating component to write. It also runs `useCustomBlockAutoResize` for you by default; pass `autoResize={false}` to opt out.
|
|
39
39
|
|
|
40
40
|
## Reference
|
|
41
41
|
|
|
@@ -9,7 +9,7 @@ import { type InitMessage } from "./messages/init.js";
|
|
|
9
9
|
* single host needs to support multiple custom blocks built with different versions of the bridge
|
|
10
10
|
* protocol. Increment this number any time a breaking change is made to the bridge protocol.
|
|
11
11
|
*/
|
|
12
|
-
export declare const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION =
|
|
12
|
+
export declare const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION = 3;
|
|
13
13
|
/**
|
|
14
14
|
* A single entry in the bridge message log. Kept intentionally plain so the log
|
|
15
15
|
* is copy-pasteable to a local coding agent without needing extra context.
|
|
@@ -13,7 +13,7 @@ import { PendingRequests } from "./pendingRequests.js";
|
|
|
13
13
|
* single host needs to support multiple custom blocks built with different versions of the bridge
|
|
14
14
|
* protocol. Increment this number any time a breaking change is made to the bridge protocol.
|
|
15
15
|
*/
|
|
16
|
-
export const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION =
|
|
16
|
+
export const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION = 3;
|
|
17
17
|
export class SandboxBridge {
|
|
18
18
|
constructor() {
|
|
19
19
|
this.hostState = {
|
|
@@ -41,7 +41,7 @@ export declare const connectMessageSchema: v.VariantSchema<"status", [v.ObjectSc
|
|
|
41
41
|
readonly error: v.ObjectSchema<{
|
|
42
42
|
readonly code: v.StringSchema<undefined>;
|
|
43
43
|
readonly message: v.StringSchema<undefined>;
|
|
44
|
-
readonly isRetryable: v.
|
|
44
|
+
readonly isRetryable: v.BooleanSchema<undefined>;
|
|
45
45
|
}, undefined>;
|
|
46
46
|
}, undefined>], undefined>;
|
|
47
47
|
export type ConnectMessage = v.InferOutput<typeof connectMessageSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/connect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/connect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAoB5B;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;IAG/B;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BASH,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
+
import { customBlockErrorInfoSchema } from "../errors.js";
|
|
2
3
|
import { manifestSchema } from "../manifest.js";
|
|
3
4
|
const connectMessageCommonEntries = {
|
|
4
5
|
type: v.literal("connect"),
|
|
@@ -15,13 +16,6 @@ const connectMessageCommonEntries = {
|
|
|
15
16
|
*/
|
|
16
17
|
sdkVersion: v.string(),
|
|
17
18
|
};
|
|
18
|
-
// TODO(custom-blocks): Replace with `customBlockErrorInfoSchema` which makes `isRetryable` required
|
|
19
|
-
// once min supported bridge protocol version is bumped to 3.
|
|
20
|
-
const connectErrorSchema = v.object({
|
|
21
|
-
code: v.string(),
|
|
22
|
-
message: v.string(),
|
|
23
|
-
isRetryable: v.optional(v.boolean(), false),
|
|
24
|
-
});
|
|
25
19
|
/**
|
|
26
20
|
* First message the sandbox sends after mount. It identifies the sandbox and starts the bridge
|
|
27
21
|
* initialization exchange. The host echoes `initializationId` in its `init` response.
|
|
@@ -38,7 +32,7 @@ export const connectMessageSchema = v.variant("status", [
|
|
|
38
32
|
}),
|
|
39
33
|
v.object({
|
|
40
34
|
status: v.literal("error"),
|
|
41
|
-
error:
|
|
35
|
+
error: customBlockErrorInfoSchema,
|
|
42
36
|
...connectMessageCommonEntries,
|
|
43
37
|
}),
|
|
44
38
|
]);
|
|
@@ -37,7 +37,7 @@ export declare const sandboxToHostMessageSchema: v.UnionSchema<[v.VariantSchema<
|
|
|
37
37
|
readonly error: v.ObjectSchema<{
|
|
38
38
|
readonly code: v.StringSchema<undefined>;
|
|
39
39
|
readonly message: v.StringSchema<undefined>;
|
|
40
|
-
readonly isRetryable: v.
|
|
40
|
+
readonly isRetryable: v.BooleanSchema<undefined>;
|
|
41
41
|
}, undefined>;
|
|
42
42
|
}, undefined>], undefined>, v.VariantSchema<"status", [v.ObjectSchema<{
|
|
43
43
|
readonly type: v.LiteralSchema<"initResult", undefined>;
|
|
@@ -11,7 +11,7 @@ import type { CustomBlockHostQueryDataSourceResult } from "./queries/types.js";
|
|
|
11
11
|
export type CustomBlockHostOptions = {
|
|
12
12
|
iframe: HTMLIFrameElement;
|
|
13
13
|
targetOrigin?: string;
|
|
14
|
-
minBridgeProtocolVersion
|
|
14
|
+
minBridgeProtocolVersion: number;
|
|
15
15
|
noConnectTimeoutMs?: number;
|
|
16
16
|
noInitResultTimeoutMs?: number;
|
|
17
17
|
initialState: CustomBlockHostInitialState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/createCustomBlockHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAc1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAM/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAazE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/createCustomBlockHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAc1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAM/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAazE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAIzD,OAAO,KAAK,EACX,qBAAqB,EACrB,iCAAiC,EACjC,2BAA2B,EAE3B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAA;AAE9E,MAAM,MAAM,sBAAsB,GAAG;IACpC,MAAM,EAAE,iBAAiB,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,wBAAwB,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,YAAY,EAAE,2BAA2B,CAAA;IACzC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAA;IACpD,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAA;IACnD,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CAC1E,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAA;IAC7C,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;IACtC,SAAS,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAA;IACzC,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA;IACxC,cAAc,EAAE,CAAC,WAAW,EAAE,iCAAiC,KAAK,IAAI,CAAA;IACxE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,KAAK,IAAI,CAAA;IACjD,YAAY,EAAE,CAAC,IAAI,EAAE;QACpB,YAAY,EAAE,kBAAkB,CAAA;QAChC,QAAQ,EAAE,oCAAoC,CAAA;KAC9C,KAAK,IAAI,CAAA;CACV,CAAA;AAQD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CA+fvB"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import { sandboxToHostMessageSchema } from "../bridge/messages/sandboxToHost.js";
|
|
3
|
+
import { CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION } from "../bridge/SandboxBridge.js";
|
|
3
4
|
import { unreachable } from "../utils.js";
|
|
4
5
|
import { initErrorForFailureReason } from "./lifecycle/initErrors.js";
|
|
5
|
-
import { isValidBridgeProtocolVersion } from "./lifecycle/
|
|
6
|
+
import { isValidBridgeProtocolVersion } from "./lifecycle/protocolVersion.js";
|
|
6
7
|
import { getInvalidSandboxMessageResponse } from "./messages/invalidSandboxMessage.js";
|
|
7
8
|
import { QuerySubscriptions } from "./queries/querySubscriptions.js";
|
|
8
9
|
const DEFAULT_NO_CONNECT_TIMEOUT_MS = 5000;
|
|
9
10
|
const DEFAULT_NO_INIT_RESULT_TIMEOUT_MS = 5000;
|
|
10
|
-
const
|
|
11
|
+
const initializationIdentitySchema = v.object({
|
|
12
|
+
initializationId: v.string(),
|
|
13
|
+
});
|
|
11
14
|
export function createCustomBlockHost(options) {
|
|
12
|
-
const { iframe, initialState, handlers, onConnect, onInitResult, onLog, targetOrigin = "*", minBridgeProtocolVersion
|
|
15
|
+
const { iframe, initialState, handlers, onConnect, onInitResult, onLog, targetOrigin = "*", minBridgeProtocolVersion: configuredMinBridgeProtocolVersion, noConnectTimeoutMs = DEFAULT_NO_CONNECT_TIMEOUT_MS, noInitResultTimeoutMs = DEFAULT_NO_INIT_RESULT_TIMEOUT_MS, } = options;
|
|
16
|
+
const minBridgeProtocolVersion = Math.max(configuredMinBridgeProtocolVersion ?? CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION, CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION);
|
|
13
17
|
let theme = initialState.theme;
|
|
14
18
|
let parent = initialState.parent;
|
|
15
19
|
let page = initialState.page;
|
|
@@ -286,7 +290,16 @@ export function createCustomBlockHost(options) {
|
|
|
286
290
|
issues,
|
|
287
291
|
});
|
|
288
292
|
const response = getInvalidSandboxMessageResponse(data);
|
|
289
|
-
|
|
293
|
+
const parsedIdentity = v.safeParse(initializationIdentitySchema, data);
|
|
294
|
+
const initializationId = parsedIdentity.success
|
|
295
|
+
? parsedIdentity.output.initializationId
|
|
296
|
+
: undefined;
|
|
297
|
+
if (initStatus === "waitingForConnect" &&
|
|
298
|
+
response.incomingType === "connect" &&
|
|
299
|
+
initializationId !== undefined) {
|
|
300
|
+
sendInitError(initializationId, initErrorForFailureReason("invalid_connect"));
|
|
301
|
+
}
|
|
302
|
+
else if (response.nack !== undefined) {
|
|
290
303
|
post(response.nack);
|
|
291
304
|
}
|
|
292
305
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function isValidBridgeProtocolVersion(version: number): boolean;
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=protocolVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocolVersion.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/lifecycle/protocolVersion.ts"],"names":[],"mappings":"AAAA,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAErE"}
|
package/dist/version.js
CHANGED
package/docs/data-sources.md
CHANGED
|
@@ -115,8 +115,8 @@ export function ScoreList() {
|
|
|
115
115
|
if (error) return <div role="alert">Couldn't load: {error.message}</div>;
|
|
116
116
|
if (isLoading && items.length === 0) return <div>Loading…</div>;
|
|
117
117
|
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
118
|
+
const displayItems = items.filter(isComplete);
|
|
119
|
+
if (displayItems.length === 0) {
|
|
120
120
|
return (
|
|
121
121
|
<div>
|
|
122
122
|
Map a data source with key <code>{KEY}</code> exposing <code>name</code>{" "}
|
|
@@ -128,7 +128,7 @@ export function ScoreList() {
|
|
|
128
128
|
return (
|
|
129
129
|
<div>
|
|
130
130
|
<ul>
|
|
131
|
-
{
|
|
131
|
+
{displayItems.map((item) => (
|
|
132
132
|
<li key={item.id}>
|
|
133
133
|
{String(item.propertiesByKey.name)} —{" "}
|
|
134
134
|
{Number(item.propertiesByKey.score)}
|
package/package.json
CHANGED
|
@@ -63,7 +63,7 @@ import type { NotionUser } from "./users/user.js"
|
|
|
63
63
|
* single host needs to support multiple custom blocks built with different versions of the bridge
|
|
64
64
|
* protocol. Increment this number any time a breaking change is made to the bridge protocol.
|
|
65
65
|
*/
|
|
66
|
-
export const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION =
|
|
66
|
+
export const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION = 3
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* A single entry in the bridge message log. Kept intentionally plain so the log
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as v from "valibot"
|
|
2
|
+
import { customBlockErrorInfoSchema } from "../errors.js"
|
|
2
3
|
import { manifestSchema } from "../manifest.js"
|
|
3
4
|
|
|
4
5
|
const connectMessageCommonEntries = {
|
|
@@ -17,14 +18,6 @@ const connectMessageCommonEntries = {
|
|
|
17
18
|
sdkVersion: v.string(),
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
// TODO(custom-blocks): Replace with `customBlockErrorInfoSchema` which makes `isRetryable` required
|
|
21
|
-
// once min supported bridge protocol version is bumped to 3.
|
|
22
|
-
const connectErrorSchema = v.object({
|
|
23
|
-
code: v.string(),
|
|
24
|
-
message: v.string(),
|
|
25
|
-
isRetryable: v.optional(v.boolean(), false),
|
|
26
|
-
})
|
|
27
|
-
|
|
28
21
|
/**
|
|
29
22
|
* First message the sandbox sends after mount. It identifies the sandbox and starts the bridge
|
|
30
23
|
* initialization exchange. The host echoes `initializationId` in its `init` response.
|
|
@@ -41,7 +34,7 @@ export const connectMessageSchema = v.variant("status", [
|
|
|
41
34
|
}),
|
|
42
35
|
v.object({
|
|
43
36
|
status: v.literal("error"),
|
|
44
|
-
error:
|
|
37
|
+
error: customBlockErrorInfoSchema,
|
|
45
38
|
...connectMessageCommonEntries,
|
|
46
39
|
}),
|
|
47
40
|
])
|
|
@@ -34,11 +34,12 @@ import type { UpdatePageMessage } from "../bridge/messages/updatePage.js"
|
|
|
34
34
|
import type { UpdatePageResultMessage } from "../bridge/messages/updatePageResult.js"
|
|
35
35
|
import type { CustomBlockPage } from "../bridge/pages/page.js"
|
|
36
36
|
import type { NotionParent } from "../bridge/parent.js"
|
|
37
|
+
import { CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION } from "../bridge/SandboxBridge.js"
|
|
37
38
|
import type { NotionTheme } from "../bridge/theme.js"
|
|
38
39
|
import type { NotionUser } from "../bridge/users/user.js"
|
|
39
40
|
import { unreachable } from "../utils.js"
|
|
40
41
|
import { initErrorForFailureReason } from "./lifecycle/initErrors.js"
|
|
41
|
-
import { isValidBridgeProtocolVersion } from "./lifecycle/
|
|
42
|
+
import { isValidBridgeProtocolVersion } from "./lifecycle/protocolVersion.js"
|
|
42
43
|
import type {
|
|
43
44
|
ConnectSuccessMessage,
|
|
44
45
|
CustomBlockHostDataSourcesPayload,
|
|
@@ -56,7 +57,7 @@ import type { CustomBlockHostQueryDataSourceResult } from "./queries/types.js"
|
|
|
56
57
|
export type CustomBlockHostOptions = {
|
|
57
58
|
iframe: HTMLIFrameElement
|
|
58
59
|
targetOrigin?: string
|
|
59
|
-
minBridgeProtocolVersion
|
|
60
|
+
minBridgeProtocolVersion: number
|
|
60
61
|
noConnectTimeoutMs?: number
|
|
61
62
|
noInitResultTimeoutMs?: number
|
|
62
63
|
initialState: CustomBlockHostInitialState
|
|
@@ -82,7 +83,9 @@ export type CustomBlockHostHandle = {
|
|
|
82
83
|
|
|
83
84
|
const DEFAULT_NO_CONNECT_TIMEOUT_MS = 5_000
|
|
84
85
|
const DEFAULT_NO_INIT_RESULT_TIMEOUT_MS = 5_000
|
|
85
|
-
const
|
|
86
|
+
const initializationIdentitySchema = v.object({
|
|
87
|
+
initializationId: v.string(),
|
|
88
|
+
})
|
|
86
89
|
|
|
87
90
|
export function createCustomBlockHost(
|
|
88
91
|
options: CustomBlockHostOptions,
|
|
@@ -95,10 +98,14 @@ export function createCustomBlockHost(
|
|
|
95
98
|
onInitResult,
|
|
96
99
|
onLog,
|
|
97
100
|
targetOrigin = "*",
|
|
98
|
-
minBridgeProtocolVersion
|
|
101
|
+
minBridgeProtocolVersion: configuredMinBridgeProtocolVersion,
|
|
99
102
|
noConnectTimeoutMs = DEFAULT_NO_CONNECT_TIMEOUT_MS,
|
|
100
103
|
noInitResultTimeoutMs = DEFAULT_NO_INIT_RESULT_TIMEOUT_MS,
|
|
101
104
|
} = options
|
|
105
|
+
const minBridgeProtocolVersion = Math.max(
|
|
106
|
+
configuredMinBridgeProtocolVersion ?? CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION,
|
|
107
|
+
CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION,
|
|
108
|
+
)
|
|
102
109
|
|
|
103
110
|
let theme = initialState.theme
|
|
104
111
|
let parent = initialState.parent
|
|
@@ -418,7 +425,20 @@ export function createCustomBlockHost(
|
|
|
418
425
|
})
|
|
419
426
|
const response = getInvalidSandboxMessageResponse(data)
|
|
420
427
|
|
|
421
|
-
|
|
428
|
+
const parsedIdentity = v.safeParse(initializationIdentitySchema, data)
|
|
429
|
+
const initializationId = parsedIdentity.success
|
|
430
|
+
? parsedIdentity.output.initializationId
|
|
431
|
+
: undefined
|
|
432
|
+
if (
|
|
433
|
+
initStatus === "waitingForConnect" &&
|
|
434
|
+
response.incomingType === "connect" &&
|
|
435
|
+
initializationId !== undefined
|
|
436
|
+
) {
|
|
437
|
+
sendInitError(
|
|
438
|
+
initializationId,
|
|
439
|
+
initErrorForFailureReason("invalid_connect"),
|
|
440
|
+
)
|
|
441
|
+
} else if (response.nack !== undefined) {
|
|
422
442
|
post(response.nack)
|
|
423
443
|
}
|
|
424
444
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ready.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/lifecycle/ready.ts"],"names":[],"mappings":"AAAA,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAErE"}
|
|
File without changes
|
|
File without changes
|