@notionhq/custom-blocks 0.3.2 → 0.3.3

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 CHANGED
@@ -6,21 +6,15 @@ Custom blocks let you build custom UI inside Notion that uses workspace data. Th
6
6
  to read and update data the viewer can access. It includes framework-neutral TypeScript APIs and
7
7
  React hooks.
8
8
 
9
- ## Bundle tooling
10
-
11
- Node build tools can import `build` and `upload` from `@notionhq/custom-blocks/bundle`. See
12
- [deployment tooling](./docs/deployment.md#apps-sdk-integration).
13
-
14
9
  ## Install
15
10
 
16
11
  Create a worker project with `ntn workers new --template custom`. Use the dependencies and
17
12
  entrypoint that the Notion CLI generates.
18
13
 
19
14
  React is optional. Blocks that import `@notionhq/custom-blocks/react` need `react` and `react-dom`.
20
- This repository's fixtures use the workspace SDK.
21
15
 
22
- For local preview, run `ntn workers customblocks dev` from the worker project. Then open
23
- `http://localhost:9873`. Install
16
+ For local preview, run `ntn workers customblocks dev` from the worker project. Open the shell URL
17
+ printed by the command. Install
24
18
  [`@notionhq/custom-blocks-dev-shell`](https://www.npmjs.com/package/@notionhq/custom-blocks-dev-shell)
25
19
  as a devDependency to pin the shell and get its reference docs in `node_modules`. See
26
20
  [`docs/deployment.md`](./docs/deployment.md) for local serving details.
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,4DAA4D,CAAA;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAiB3E,OAAO,EACN,KAAK,WAAW,EAEhB,MAAM,mDAAmD,CAAA;AAI1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AASvG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAG5G,OAAO,KAAK,EACX,cAA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,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAChC,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAClC,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;QAC9C,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;KACxC,GAAG,OAAO,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,CAAC,CAiEzD;IAED;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CA2D/B"}
@@ -10,7 +10,7 @@ import { resolveDataSources } from "./dataSources/resolve.js";
10
10
  import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js";
11
11
  import { createEmptyDataSourceQueryState, } from "./hostState.js";
12
12
  import { notifyListener } from "./notifyListener.js";
13
- import { toNotionPageFromNotionPageData } from "./page.js";
13
+ import { makeUpdatePageByKey, toNotionPageFromNotionPageData } from "./page.js";
14
14
  import { PendingRequests } from "./pendingRequests.js";
15
15
  import { SandboxInitialization } from "./SandboxInitialization.js";
16
16
  export class SandboxBridge {
@@ -570,7 +570,6 @@ export class SandboxBridge {
570
570
  const resolvedProperties = resolvePropertyWriteMapForDataSource({
571
571
  dataSource: propertyDataSource,
572
572
  properties: args.properties,
573
- operationName: "createPage",
574
573
  });
575
574
  if (resolvedProperties.status === "error") {
576
575
  resolve(resolvedProperties);
@@ -595,7 +594,10 @@ export class SandboxBridge {
595
594
  getPropertyById: propertyId => this.getPropertyById({ page, propertyId }),
596
595
  getPropertyByKey: propertyKey => this.getPropertyByKey({ page, dataSource, propertyKey }),
597
596
  updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
598
- updateByKey: payload => update({ ...payload, pageId: page.id, dataSource }),
597
+ updateByKey: makeUpdatePageByKey({
598
+ dataSource,
599
+ update: payload => update({ ...payload, pageId: page.id, dataSource }),
600
+ }),
599
601
  });
600
602
  resolve({ status: "success", page });
601
603
  });
@@ -635,7 +637,10 @@ export class SandboxBridge {
635
637
  getPropertyById: propertyId => this.getPropertyById({ page, propertyId }),
636
638
  getPropertyByKey: propertyKey => this.getPropertyByKey({ page, dataSource, propertyKey }),
637
639
  updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
638
- updateByKey: payload => update({ ...payload, pageId: page.id, dataSource }),
640
+ updateByKey: makeUpdatePageByKey({
641
+ dataSource,
642
+ update: payload => update({ ...payload, pageId: page.id, dataSource }),
643
+ }),
639
644
  });
640
645
  resolve({ status: "success", page });
641
646
  });
@@ -719,30 +724,9 @@ export class SandboxBridge {
719
724
  const operation = async () => {
720
725
  const { dataSource } = args;
721
726
  const dataSourceId = dataSource?.collectionPointer?.id;
722
- const propertyIdsByKey = dataSource?.propertyIdsByKey ?? {};
723
- if (dataSource !== undefined) {
724
- for (const propertyKey of Object.keys(args.properties ?? {})) {
725
- const propertyId = Object.hasOwn(propertyIdsByKey, propertyKey)
726
- ? propertyIdsByKey[propertyKey]
727
- : undefined;
728
- if (propertyId &&
729
- dataSource?.collectionSchema?.propertiesById[propertyId]) {
730
- continue;
731
- }
732
- return {
733
- status: "error",
734
- error: {
735
- code: "unmapped_property",
736
- message: `Cannot resolve property key "${propertyKey}" on this page.`,
737
- isRetryable: false,
738
- },
739
- };
740
- }
741
- }
742
727
  const resolved = resolvePropertyWriteMapForDataSource({
743
728
  dataSource,
744
- properties: args.properties ?? {},
745
- operationName: "page.update",
729
+ properties: args.properties === undefined ? {} : args.properties,
746
730
  });
747
731
  if (resolved.status === "error") {
748
732
  return resolved;
@@ -802,12 +786,8 @@ export class SandboxBridge {
802
786
  switch (parent.type) {
803
787
  case "page_id":
804
788
  return { status: "ok", parent, dataSource: undefined };
805
- case "data_source_id": {
806
- const dataSource = this.hostState.status === "initialized"
807
- ? this.hostState.dataSources.find(entry => entry.collectionPointer?.id === parent.data_source_id)
808
- : undefined;
809
- return { status: "ok", parent, dataSource };
810
- }
789
+ case "data_source_id":
790
+ return { status: "ok", parent, dataSource: undefined };
811
791
  case "data_source_key": {
812
792
  if (this.hostState.status !== "initialized") {
813
793
  return {
@@ -11,29 +11,10 @@ export type PropertyWriteMapResolutionResult = {
11
11
  };
12
12
  /**
13
13
  * Resolves a public SDK property write map into the ID-keyed bridge shape.
14
- *
15
- * Identifiers in `properties` may be raw property IDs or data source property keys; the latter
16
- * are looked up in the `dataSource`'s `propertyIdsByKey`. Each value is re-parsed through
17
- * the page property value schema with its `id` rewritten to the resolved property ID.
14
+ * A data source makes every identifier a property key; without one, identifiers are raw IDs.
18
15
  */
19
16
  export declare function resolvePropertyWriteMapForDataSource(args: {
20
17
  dataSource: NotionDataSource | undefined;
21
18
  properties: NotionPagePropertyInputMap;
22
- operationName: string;
23
19
  }): PropertyWriteMapResolutionResult;
24
- /**
25
- * Treats bound data source keys as aliases for property IDs. An unbound key may still be used as
26
- * a raw ID when it exactly matches a property in the data source schema.
27
- */
28
- export declare function resolvePropertyIdentifierForDataSource(args: {
29
- dataSource: NotionDataSource | undefined;
30
- identifier: string;
31
- operationName: string;
32
- }): {
33
- status: "success";
34
- propertyId: string;
35
- } | {
36
- status: "error";
37
- error: CustomBlockPropertyErrorInfo;
38
- };
39
20
  //# sourceMappingURL=resolveProperty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveProperty.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/resolveProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAEX,4BAA4B,EAC5B,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAGhG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEhE,MAAM,MAAM,gCAAgC,GACzC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAA;CAAE,GAClE;IAAE,MAAM,EAAE,OA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AA;CACtC,GAAG,gCAAgC,CAuEnC"}
@@ -5,33 +5,40 @@ function makePropertyError(code, message) {
5
5
  }
6
6
  /**
7
7
  * Resolves a public SDK property write map into the ID-keyed bridge shape.
8
- *
9
- * Identifiers in `properties` may be raw property IDs or data source property keys; the latter
10
- * are looked up in the `dataSource`'s `propertyIdsByKey`. Each value is re-parsed through
11
- * the page property value schema with its `id` rewritten to the resolved property ID.
8
+ * A data source makes every identifier a property key; without one, identifiers are raw IDs.
12
9
  */
13
10
  export function resolvePropertyWriteMapForDataSource(args) {
14
- const { dataSource, properties, operationName } = args;
15
- const resolvedProperties = {};
16
- for (const [identifier, value] of Object.entries(properties)) {
17
- const propertyIdResult = resolvePropertyIdentifierForDataSource({
11
+ const { dataSource, properties } = args;
12
+ const parsedMap = v.safeParse(v.record(v.string(), v.unknown()), properties);
13
+ if (Array.isArray(properties) || !parsedMap.success) {
14
+ return {
15
+ status: "error",
16
+ error: makePropertyError("invalid_property_value", "Property maps must be objects."),
17
+ };
18
+ }
19
+ const resolvedProperties = Object.create(null);
20
+ for (const [identifier, value] of Object.entries(parsedMap.output)) {
21
+ const propertyIdResult = resolveWriteIdentifier({
18
22
  dataSource,
19
23
  identifier,
20
- operationName,
21
24
  });
22
25
  if (propertyIdResult.status === "error") {
23
26
  return propertyIdResult;
24
27
  }
25
28
  const propertyId = propertyIdResult.propertyId;
26
- if (value.id !== undefined &&
27
- value.id !== identifier &&
28
- value.id !== propertyId) {
29
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
30
+ return {
31
+ status: "error",
32
+ error: makePropertyError("invalid_property_value", `Invalid value for property ${identifier}.`),
33
+ };
34
+ }
35
+ if ("id" in value && value.id !== undefined && value.id !== propertyId) {
29
36
  return {
30
37
  status: "error",
31
38
  error: makePropertyError("property_id_mismatch", `Property ${identifier} resolved to ${propertyId} but value id was ${value.id}.`),
32
39
  };
33
40
  }
34
- if (resolvedProperties[propertyId] !== undefined) {
41
+ if (Object.hasOwn(resolvedProperties, propertyId)) {
35
42
  return {
36
43
  status: "error",
37
44
  error: makePropertyError("duplicate_property", `Cannot set property ${propertyId} more than once.`),
@@ -52,25 +59,23 @@ export function resolvePropertyWriteMapForDataSource(args) {
52
59
  return { status: "success", properties: resolvedProperties };
53
60
  }
54
61
  /**
55
- * Treats bound data source keys as aliases for property IDs. An unbound key may still be used as
56
- * a raw ID when it exactly matches a property in the data source schema.
62
+ * Resolves property keys when a data source is present and raw property IDs otherwise.
63
+ * Property keys require a bound, loaded property so an unresolved key cannot become a raw ID.
57
64
  */
58
- export function resolvePropertyIdentifierForDataSource(args) {
59
- const { dataSource, identifier, operationName } = args;
60
- if (dataSource !== undefined && identifier in dataSource.propertyIdsByKey) {
61
- const propertyId = dataSource.propertyIdsByKey[identifier];
62
- if (propertyId === undefined) {
63
- // If the property is not bound to a key, check if it is a valid property ID. If so, we
64
- // can use it directly.
65
- if (identifier in dataSource.propertySchemasById) {
66
- return { status: "success", propertyId: identifier };
67
- }
68
- return {
69
- status: "error",
70
- error: makePropertyError("unmapped_property", `${operationName} cannot resolve property key "${identifier}" because it is not bound to a Notion property.`),
71
- };
72
- }
73
- return { status: "success", propertyId };
65
+ function resolveWriteIdentifier(args) {
66
+ const { dataSource, identifier } = args;
67
+ if (dataSource === undefined) {
68
+ return { status: "success", propertyId: identifier };
69
+ }
70
+ const propertyId = Object.hasOwn(dataSource.propertyIdsByKey, identifier)
71
+ ? dataSource.propertyIdsByKey[identifier]
72
+ : undefined;
73
+ if (propertyId === undefined ||
74
+ !dataSource.collectionSchema?.propertiesById[propertyId]) {
75
+ return {
76
+ status: "error",
77
+ error: makePropertyError("unmapped_property", `Cannot resolve property key "${identifier}" on this page.`),
78
+ };
74
79
  }
75
- return { status: "success", propertyId: identifier };
80
+ return { status: "success", propertyId };
76
81
  }
@@ -1,3 +1,4 @@
1
+ import type { NotionDataSource } from "../protocol/dataSources/dataSource.js";
1
2
  import type { notionPageDataSchema } from "../protocol/pages/page.js";
2
3
  import type { InferOutput } from "valibot";
3
4
  import type { NotionPage } from "../types.js";
@@ -9,4 +10,9 @@ export declare function toNotionPageFromNotionPageData(args: {
9
10
  updateById: NotionPage["updateById"];
10
11
  updateByKey: NotionPage["updateByKey"];
11
12
  }): NotionPage;
13
+ /** Prevents key-based property updates from falling back to raw IDs without data source context. */
14
+ export declare function makeUpdatePageByKey(args: {
15
+ dataSource: NotionDataSource | undefined;
16
+ update: NotionPage["updateByKey"];
17
+ }): NotionPage["updateByKey"];
12
18
  //# sourceMappingURL=page.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/bridge/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,wBAAgB,8BAA8B,CAAC,IAAI,EAAE;IACpD,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;IAC9C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAC9C,gBAAgB,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAChD,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAA;IACpC,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;CACtC,GAAG,UAAU,CAWb"}
1
+ {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/bridge/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,wBAAgB,8BAA8B,CAAC,IAAI,EAAE;IACpD,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;IAC9C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAC9C,gBAAgB,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAChD,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAA;IACpC,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;CACtC,GAAG,UAAU,CAWb;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACzC,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;CACjC,GAAG,UAAU,CAAC,aAAa,CAAC,CAiB5B"}
@@ -10,3 +10,20 @@ export function toNotionPageFromNotionPageData(args) {
10
10
  unarchive: () => args.updateById({ is_archived: false }),
11
11
  };
12
12
  }
13
+ /** Prevents key-based property updates from falling back to raw IDs without data source context. */
14
+ export function makeUpdatePageByKey(args) {
15
+ return async (payload) => {
16
+ if (args.dataSource === undefined &&
17
+ Object.keys(payload.properties ?? {}).length > 0) {
18
+ return {
19
+ status: "error",
20
+ error: {
21
+ code: "unmapped_property",
22
+ message: "Key-based property updates require data source context.",
23
+ isRetryable: false,
24
+ },
25
+ };
26
+ }
27
+ return args.update(payload);
28
+ };
29
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAA;AACpF,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb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IAItB,UAAU,WAAW,MAAM;CAG3B,CAAA;AAED,eAAO,MAAM,sBAAsB;IAClC,oBAAoB;IAIpB,KAAK,SAAS,mBAAmB;IAIjC,OAAO,mBAAmB,MAAM;IAIhC,OAAO,cACK,oBAAoB,OAC1B,MAAM,kBACK,MAAM,KACpB,mBAAmB;CAoCtB,CAAA;AAED,eAAO,MAAM,UAAU;IACtB,WAAW,QAAM,SAAS,eAAe,EAAE;IAI3C,SAAS,aAAa,MAAM,IAAI;CAGhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,MAAM,UAAU,cAAc,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAO1D;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;IAOnD;;OAEG;IACH,IAAI,WACK,YAAY,WACX,eAAe,KACtB,OAAO,CAAC,cAAc,CAAC;CAG1B,CAAA;AAED,sDAAsD;AACtD,eAAO,MAAM,KAAK;IACjB,gEAAgE;IAChE,IAAI,QAAQ,MAAM,KAAG,OAAO,CAAC,qBAAqB,CAAC;CAGnD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,IAAI,WAAW,aAAa,KAAG,OAAO,CAAC,eAAe,CAAC;IAIvD;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;CAGnD,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { getDataSourceQueryView as getDataSourceQueryViewWithBridge, } from "./hostState.js";
2
- import { toNotionPageFromNotionPageData } from "./page.js";
2
+ import { makeUpdatePageByKey, toNotionPageFromNotionPageData } from "./page.js";
3
3
  import { SandboxBridge, } from "./SandboxBridge.js";
4
4
  let bridge;
5
5
  export function getBridge() {
@@ -63,7 +63,10 @@ export const customBlockDataSources = {
63
63
  getPropertyById: propertyId => bridge.getPropertyById({ page, propertyId }),
64
64
  getPropertyByKey: propertyKey => bridge.getPropertyByKey({ page, dataSource, propertyKey }),
65
65
  updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
66
- updateByKey: payload => update({ ...payload, pageId: page.id, dataSource }),
66
+ updateByKey: makeUpdatePageByKey({
67
+ dataSource,
68
+ update: payload => update({ ...payload, pageId: page.id, dataSource }),
69
+ }),
67
70
  });
68
71
  return page;
69
72
  });
@@ -3,5 +3,6 @@
3
3
  * Increase this value for breaking wire changes. Hosts can continue to accept
4
4
  * older versions, so this value does not set the minimum or maximum they accept.
5
5
  */
6
- export declare const LATEST_BRIDGE_PROTOCOL_VERSION = 6;
6
+ export declare const LATEST_BRIDGE_PROTOCOL_VERSION = 7;
7
7
  export declare const LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION = 6;
8
+ export declare const TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION = 7;
@@ -3,7 +3,9 @@
3
3
  * Increase this value for breaking wire changes. Hosts can continue to accept
4
4
  * older versions, so this value does not set the minimum or maximum they accept.
5
5
  */
6
- export const LATEST_BRIDGE_PROTOCOL_VERSION = 6;
6
+ export const LATEST_BRIDGE_PROTOCOL_VERSION = 7;
7
7
  // Protocol 6 introduces unified pages with name-keyed property objects.
8
8
  // Keep this cutoff fixed when the latest protocol version increases.
9
9
  export const LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION = 6;
10
+ // Protocol 7 adds typed text fallbacks for previously unsupported page properties.
11
+ export const TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION = 7;
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  *
5
5
  * WARNING: Generated during SDK publish. Do not edit in the published package.
6
6
  */
7
- export const CUSTOM_BLOCKS_SDK_VERSION = "0.3.2"
7
+ export const CUSTOM_BLOCKS_SDK_VERSION = "0.3.3"
@@ -0,0 +1,55 @@
1
+ # Build-tool reference
2
+
3
+ The `@notionhq/custom-blocks/bundle` entrypoint exposes Node.js functions for deployment tools. It
4
+ provides build and upload operations. Worker projects normally use `ntn workers deploy`.
5
+
6
+ The Apps CLI calls `build` and `upload` from `build-blocks` and `upload-blocks`, respectively.
7
+
8
+ ```ts
9
+ import { build, upload } from "@notionhq/custom-blocks/bundle"
10
+ ```
11
+
12
+ ## Build bundles
13
+
14
+ `build(args: BuildArgs)` returns a `Promise<BuildOutput>`. By default, it imports the worker bundle
15
+ at `dist/index.js` and reads its custom block capabilities. With `manifest`, it reads an Apps SDK
16
+ capability manifest from a JSON file instead. This file contains a `capabilities` array, not the
17
+ block manifest served at `/manifest` during local preview.
18
+
19
+ `BuildArgs` contains these fields:
20
+
21
+ - `out`: Required output directory. Each block's bundle is copied to `<out>/<key>`.
22
+ - `cwd`: Optional project root. Defaults to the process's current directory.
23
+ - `manifest`: Optional path to the Apps SDK capability manifest.
24
+
25
+ Relative `out`, `manifest`, and block source paths resolve from the project root. For a project
26
+ source, `build` installs dependencies, runs the configured build command, and copies its output. For
27
+ a static source, `build` copies the source directory without a build command.
28
+
29
+ `BuildOutput.blocks` is an array of `BuiltBlock` results. Each result contains the block's `key`,
30
+ `bundleDir`, `checksumCrc32`, and `bundleSizeBytes`. The size is the compressed tarball's byte
31
+ length. When the worker or capability manifest declares no custom blocks, `blocks` is empty.
32
+
33
+ The equivalent CLI command is `notion-custom-blocks build --out <dir>`. It accepts `--cwd` and
34
+ `--manifest` with the same path rules. `printBuildOutput` writes a `BuildOutput` as single-line JSON
35
+ between `<__notion_custom_block__>` and `</__notion_custom_block__>`.
36
+
37
+ ## Upload bundles
38
+
39
+ `upload(targets: UploadsInput)` returns a `Promise<UploadOutput>`. `UploadsInput` maps block keys to
40
+ `UploadTarget` objects with these fields:
41
+
42
+ - `uploadUrl`: Required presigned upload URL.
43
+ - `bundleDir`: Required path to the bundle directory.
44
+ - `headers`: Optional map of headers supplied with the presigned URL, such as `Content-Length` and
45
+ object tags.
46
+
47
+ `upload` compresses each directory and sends the tarball with an HTTP PUT request. It forwards the
48
+ supplied headers and sets `Content-Type` to `application/gzip` and `x-amz-checksum-crc32` to the
49
+ archive's checksum. Relative `bundleDir` paths resolve from the process's current directory.
50
+
51
+ On success, `UploadOutput.uploaded` maps every uploaded block key to `true`. A failed upload throws
52
+ an error and stops the remaining uploads. Earlier uploads are not rolled back.
53
+
54
+ The equivalent CLI command is `notion-custom-blocks upload --uploads '<json>'`. `parseUploadsInput`
55
+ parses and validates that JSON as `UploadsInput`.
@@ -388,7 +388,9 @@ await row.updateByKey({
388
388
  Use `updateByKey` for manifest keys and `updateById` for raw property IDs. The SDK resolves manifest
389
389
  keys before sending the request.
390
390
 
391
- Read a page through `pages.get(pageId)` before calling its instance methods.
391
+ Pages returned by `dataSources.getPage`, `dataSources.query`, and `dataSources.create` support
392
+ property writes through `updateByKey`. Pages returned by `pages.get` and `pages.create` support
393
+ property writes through `updateById`.
392
394
 
393
395
  ### Archiving and unarchiving a row
394
396
 
@@ -1,9 +1,9 @@
1
1
  # Deployment and manifests
2
2
 
3
- A custom block is a static web bundle — an `index.html` plus optional assets — that Notion loads
4
- into a sandboxed `<iframe>`. Custom blocks ship as part of a worker: declare the block source and
5
- data source schema with `worker.customBlock(...)` in the worker's `src/index.ts`, deploy with
6
- `ntn workers deploy`, and Notion serves the built bundle.
3
+ A custom block is a static web bundle containing an `index.html` file and optional assets. Notion
4
+ loads the bundle into a sandboxed `<iframe>`. Custom blocks ship as part of a worker. Declare the
5
+ block source and data source schema with `worker.customBlock(...)` in the worker's `src/index.ts`.
6
+ Deploy with `ntn workers deploy`. Notion then serves the built bundle.
7
7
 
8
8
  A custom block manifest describes the data sources a block requires, including their semantic keys,
9
9
  display metadata, and property schemas. The block's `worker.customBlock(...)` declaration is the
@@ -18,13 +18,18 @@ Notion reconciles custom block definitions by their Worker capability keys durin
18
18
 
19
19
  ## Local development
20
20
 
21
- Run `ntn workers customblocks dev` from a worker. It builds the worker, extracts its custom block
22
- declarations, starts one localhost Vite server per block, and renders them in the mock host at
23
- http://localhost:9873.
21
+ Run `ntn workers customblocks dev` from your worker project. The dev shell builds the worker and
22
+ reads its custom block declarations. It serves the shell and blocks on one port, with a separate
23
+ localhost subdomain for each block. Open the shell URL printed by the command. The default port is
24
+ `9873`; the launcher selects another port when needed.
24
25
 
25
- At startup, the SDK fetches the page-relative `manifest` path only when the bundle's hostname is
26
- exactly `localhost`, then forwards the response in `connect`. On every other hostname, the SDK skips
27
- this fetch and relies on the host-provided manifest from `init`.
26
+ The dev shell supplies the worker's manifest to the host. When Notion previews a local block
27
+ directly, its host fetches `/manifest` from the block server. In both cases, the host sends the
28
+ manifest to the SDK during initialization.
29
+
30
+ The SDK also attempts a legacy page-relative `manifest` fetch on the exact `localhost` hostname. It
31
+ skips that fetch on block subdomains such as `chart.localhost`. Hosts choose the authoritative
32
+ manifest; blocks do not need to fetch or send one themselves.
28
33
 
29
34
  ## Types
30
35
 
@@ -33,27 +38,4 @@ this fetch and relies on the host-provided manifest from `init`.
33
38
  - `ManifestProperty` — a single property declaration inside a `ManifestDataSource`.
34
39
  - `ManifestIcon` — the icon variant accepted on a `ManifestDataSource`.
35
40
 
36
- ## Apps SDK integration
37
-
38
- `notion-custom-blocks build --manifest dist/manifest.json --out <dir>` reads static Apps SDK
39
- capabilities. Paths in the manifest stay relative to the project root (the current directory, or
40
- `--cwd`). Without `--manifest`, the command continues to import the Workers SDK bundle at
41
- `dist/index.js`.
42
-
43
- Node build tools use one entrypoint:
44
-
45
- ```ts
46
- import { build, upload } from "@notionhq/custom-blocks/bundle"
47
- ```
48
-
49
- `build` accepts `BuildArgs` and returns `BuildOutput` containing `BuiltBlock` results. `upload`
50
- accepts `UploadsInput`, a map of block keys to `UploadTarget`, and returns `UploadOutput`.
51
- `printBuildOutput` writes the sentinel-wrapped build result; `parseUploadsInput` validates JSON
52
- upload arguments. The Apps CLI calls these functions from `build-blocks` and `upload-blocks`.
53
-
54
- Relative `--out` paths also resolve from `--cwd`. Build results include `bundleSizeBytes`, the exact
55
- compressed tarball length, for size-bound uploads.
56
-
57
- Upload targets may include a `headers` map containing the headers returned by the server presign,
58
- including `Content-Length` and object tags. The uploader forwards these alongside the tarball
59
- checksum and content type.
41
+ For the Node.js build and upload API, see the [build-tool reference](./build-tools.md).