@notionhq/custom-blocks 0.0.65 → 0.0.67

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.
Files changed (33) hide show
  1. package/HOST.md +2 -0
  2. package/README.md +1 -0
  3. package/dist/bridge/errors.d.ts +1 -0
  4. package/dist/bridge/errors.d.ts.map +1 -1
  5. package/dist/bridge/messages/createPageResult.d.ts +2 -2
  6. package/dist/bridge/messages/createPageResult.d.ts.map +1 -1
  7. package/dist/bridge/messages/getPage.d.ts +2 -2
  8. package/dist/bridge/messages/getPage.d.ts.map +1 -1
  9. package/dist/bridge/messages/getUser.d.ts +2 -2
  10. package/dist/bridge/messages/getUser.d.ts.map +1 -1
  11. package/dist/bridge/messages/init.d.ts +2 -2
  12. package/dist/bridge/messages/init.d.ts.map +1 -1
  13. package/dist/bridge/messages/listUsers.d.ts +2 -2
  14. package/dist/bridge/messages/listUsers.d.ts.map +1 -1
  15. package/dist/bridge/messages/queryDataSourceResult.d.ts +2 -2
  16. package/dist/bridge/messages/queryDataSourceResult.d.ts.map +1 -1
  17. package/dist/bridge/messages/updatePageResult.d.ts +2 -2
  18. package/dist/bridge/messages/updatePageResult.d.ts.map +1 -1
  19. package/dist/version.js +1 -1
  20. package/docs/data-sources.md +1 -1
  21. package/docs/errors.md +48 -0
  22. package/docs/lifecycle.md +1 -13
  23. package/docs/pages.md +1 -12
  24. package/docs/users.md +1 -12
  25. package/package.json +1 -1
  26. package/src/bridge/errors.ts +8 -0
  27. package/src/bridge/messages/createPageResult.ts +3 -3
  28. package/src/bridge/messages/getPage.ts +4 -5
  29. package/src/bridge/messages/getUser.ts +3 -2
  30. package/src/bridge/messages/init.ts +3 -4
  31. package/src/bridge/messages/listUsers.ts +3 -2
  32. package/src/bridge/messages/queryDataSourceResult.ts +3 -3
  33. package/src/bridge/messages/updatePageResult.ts +3 -3
package/HOST.md CHANGED
@@ -104,6 +104,8 @@ Every bridge error payload uses the same `{ code, message, isRetryable }` shape.
104
104
 
105
105
  `code` is any string on the wire. Schemas validate only the error _shape_ (`code`/`message`/`isRetryable` types); per-API code unions are TypeScript open-enums for autocomplete. Receivers MUST accept well-shaped errors with unknown codes so newer senders can add codes without breaking older receivers.
106
106
 
107
+ Hosts should emit the most specific stable code available. Unexpected or unclassified request failures use the universal `unknown_error` code with `isRetryable: false`. Future hosts and sandboxes may introduce a new error code, so both sides should accept any string, even if it does not match a known code.
108
+
107
109
  Host implementers can use the API-specific aliases and schemas when shaping outbound failures: `CustomBlockCreatePageErrorCode` / `CustomBlockCreatePageErrorInfo` / `customBlockCreatePageErrorCodeSchema` / `customBlockCreatePageErrorInfoSchema`, `CustomBlockGetPageErrorCode` / `CustomBlockGetPageErrorInfo` / `customBlockGetPageErrorCodeSchema` / `customBlockGetPageErrorInfoSchema`, `CustomBlockGetUserErrorCode` / `CustomBlockGetUserErrorInfo` / `customBlockGetUserErrorCodeSchema` / `customBlockGetUserErrorInfoSchema`, `CustomBlockListUsersErrorCode` / `CustomBlockListUsersErrorInfo` / `customBlockListUsersErrorCodeSchema` / `customBlockListUsersErrorInfoSchema`, `CustomBlockQueryDataSourceErrorCode` / `CustomBlockQueryDataSourceErrorInfo` / `customBlockQueryDataSourceErrorCodeSchema` / `customBlockQueryDataSourceErrorInfoSchema`, and `CustomBlockUpdatePageErrorCode` / `CustomBlockUpdatePageErrorInfo` / `customBlockUpdatePageErrorCodeSchema` / `customBlockUpdatePageErrorInfoSchema`. Shared categories are exported as `CustomBlockPropertyErrorCode` / `CustomBlockPropertyErrorInfo` / `customBlockPropertyErrorCodeSchema` and `CustomBlockDataSourceResolutionErrorCode` / `CustomBlockDataSourceResolutionErrorInfo` / `customBlockDataSourceResolutionErrorCodeSchema`. The broad fallback schema remains `customBlockErrorInfoSchema`.
108
110
 
109
111
  `queryDataSource` carries the resolved raw `dataSourceId` and a sandbox-generated `snapshotId`; semantic data-source keys never cross the bridge for queries. `createPage` arrives with `parent` already resolved to `page_id` or `data_source_id`.
package/README.md CHANGED
@@ -46,6 +46,7 @@ API surface, one page per category. Import framework-neutral APIs from `@notionh
46
46
  - [`docs/data-sources.md`](./docs/data-sources.md) — `useDataSource`, `useManifest`, `customBlock.getManifest`, the row, property, and date-value types, plus a worked example.
47
47
  - [`docs/pages.md`](./docs/pages.md) — `pages.create / get / update / delete`, parent variants (including the recommended `data_source_key`), property input shapes.
48
48
  - [`docs/users.md`](./docs/users.md) — `users.list / get`, the `NotionUser` shape, paging.
49
+ - [`docs/errors.md`](./docs/errors.md) — request results, error format, error codes, retries, and initialization failures.
49
50
  - [`docs/manifest.md`](./docs/manifest.md) — `custom_blocks.json`, the Vite plugin, manifest types.
50
51
 
51
52
  ## Forbidden APIs
@@ -1,4 +1,5 @@
1
1
  import * as v from "valibot";
2
+ export type CustomBlockErrorCode<KnownCode extends string> = KnownCode | "unknown_error" | (string & {});
2
3
  export type CustomBlockErrorInfo<TCode extends string = string> = {
3
4
  code: TCode;
4
5
  message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,MAAM,MAAM,oBAAoB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;IACjE,IAAI,EAAE,KAAK,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,0BAA0B;;;;aAIrC,CAAA"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,MAAM,MAAM,oBAAoB,CAAC,SAAS,SAAS,MAAM,IAEtD,SAAS,GAET,eAAe,GAEf,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,oBAAoB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;IACjE,IAAI,EAAE,KAAK,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,0BAA0B;;;;aAIrC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockCreatePageErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockCreatePageErrorCode = "create_page_failed" | "invalid_page_parent" | "page_access_failed" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value" | (string & {});
4
+ export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "page_access_failed" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
5
5
  export type CustomBlockCreatePageErrorInfo = CustomBlockErrorInfo<CustomBlockCreatePageErrorCode>;
6
6
  export declare const customBlockCreatePageErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"createPageResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/createPageResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAKxD,eAAO,MAAM,oCAAoC,2BAAa,CAAA;AAE9D,MAAM,MAAM,8BAA8B,GACvC,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,GACpB,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,GACxB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,8BAA8B,GACzC,oBAAoB,CAAC,8BAA8B,CAAC,CAAA;AAErD,eAAO,MAAM,oCAAoC;;;;aAI/C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;IAKxC,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAS9B,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,WAAW,CAClD,OAAO,6BAA6B,CACpC,CAAA"}
1
+ {"version":3,"file":"createPageResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/createPageResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAK9E,eAAO,MAAM,oCAAoC,2BAAa,CAAA;AAE9D,MAAM,MAAM,8BAA8B,GAAG,oBAAoB,CAC9D,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,GACpB,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,CAC1B,CAAA;AAED,MAAM,MAAM,8BAA8B,GACzC,oBAAoB,CAAC,8BAA8B,CAAC,CAAA;AAErD,eAAO,MAAM,oCAAoC;;;;aAI/C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;IAKxC,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAS9B,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,WAAW,CAClD,OAAO,6BAA6B,CACpC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockGetPageErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockGetPageErrorCode = "get_page_failed" | "page_access_failed" | (string & {});
4
+ export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "page_access_failed">;
5
5
  export type CustomBlockGetPageErrorInfo = CustomBlockErrorInfo<CustomBlockGetPageErrorCode>;
6
6
  export declare const customBlockGetPageErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"getPage.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/getPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAMxD,eAAO,MAAM,iCAAiC,2BAAa,CAAA;AAE3D,MAAM,MAAM,2BAA2B,GACpC,iBAAiB,GACjB,oBAAoB,GACpB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,2BAA2B,GACtC,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;AAElD,eAAO,MAAM,iCAAiC;;;;aAI5C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;aAI/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEvE,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAarC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAC/C,OAAO,0BAA0B,CACjC,CAAA"}
1
+ {"version":3,"file":"getPage.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/getPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAM9E,eAAO,MAAM,iCAAiC,2BAAa,CAAA;AAE3D,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,CAC7D,iBAAiB,GAAG,oBAAoB,CACxC,CAAA;AAED,MAAM,MAAM,2BAA2B,GACtC,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;AAElD,eAAO,MAAM,iCAAiC;;;;aAI5C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;aAI/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEvE,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAarC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAC/C,OAAO,0BAA0B,CACjC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockGetUserErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockGetUserErrorCode = "get_user_failed" | (string & {});
4
+ export type CustomBlockGetUserErrorCode = CustomBlockErrorCode<"get_user_failed">;
5
5
  export type CustomBlockGetUserErrorInfo = CustomBlockErrorInfo<CustomBlockGetUserErrorCode>;
6
6
  export declare const customBlockGetUserErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"getUser.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/getUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAKxD,eAAO,MAAM,iCAAiC,2BAAa,CAAA;AAE3D,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAE3E,MAAM,MAAM,2BAA2B,GACtC,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;AAElD,eAAO,MAAM,iCAAiC;;;;aAI5C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;aAI/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEvE,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;0BAarC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAC/C,OAAO,0BAA0B,CACjC,CAAA"}
1
+ {"version":3,"file":"getUser.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/getUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAK9E,eAAO,MAAM,iCAAiC,2BAAa,CAAA;AAE3D,MAAM,MAAM,2BAA2B,GACtC,oBAAoB,CAAC,iBAAiB,CAAC,CAAA;AAExC,MAAM,MAAM,2BAA2B,GACtC,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;AAElD,eAAO,MAAM,iCAAiC;;;;aAI5C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;aAI/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEvE,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;0BAarC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAC/C,OAAO,0BAA0B,CACjC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockInitErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockInitErrorCode = "no_ready" | "invalid_ready" | "manifest_unavailable" | "manifest_invalid" | "invalid_protocol_version" | "unsupported_protocol_version" | "context_unavailable" | "current_user_unavailable" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding" | "not_in_iframe" | "init_timeout" | "unknown_error" | (string & {});
4
+ export type CustomBlockInitErrorCode = CustomBlockErrorCode<"no_ready" | "invalid_ready" | "manifest_unavailable" | "manifest_invalid" | "invalid_protocol_version" | "unsupported_protocol_version" | "context_unavailable" | "current_user_unavailable" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding" | "not_in_iframe" | "init_timeout">;
5
5
  export type CustomBlockInitErrorInfo = CustomBlockErrorInfo<CustomBlockInitErrorCode>;
6
6
  export declare const customBlockInitErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AASxD,eAAO,MAAM,8BAA8B,2BAAa,CAAA;AAExD,MAAM,MAAM,wBAAwB,GACjC,UAAU,GACV,eAAe,GACf,sBAAsB,GACtB,kBAAkB,GAClB,0BAA0B,GAC1B,8BAA8B,GAC9B,qBAAqB,GACrB,0BAA0B,GAC1B,6BAA6B,GAC7B,yBAAyB,GACzB,0BAA0B,GAC1B,0BAA0B,GAC1B,eAAe,GACf,cAAc,GACd,eAAe,GACf,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,wBAAwB,GACnC,oBAAoB,CAAC,wBAAwB,CAAC,CAAA;AAE/C,eAAO,MAAM,8BAA8B;;;;aAIzC,CAAA;AAEF,qBAAa,oBACZ,SAAQ,KACR,YAAW,oBAAoB;gBAEnB,KAAK,EAAE,wBAAwB;IAO3C,IAAI,EAAE,wBAAwB,CAAA;IAC9B,WAAW,EAAE,OAAO,CAAA;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAkB5B,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAS9E,eAAO,MAAM,8BAA8B,2BAAa,CAAA;AAExD,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,CACxD,UAAU,GACV,eAAe,GACf,sBAAsB,GACtB,kBAAkB,GAClB,0BAA0B,GAC1B,8BAA8B,GAC9B,qBAAqB,GACrB,0BAA0B,GAC1B,6BAA6B,GAC7B,yBAAyB,GACzB,0BAA0B,GAC1B,0BAA0B,GAC1B,eAAe,GACf,cAAc,CAChB,CAAA;AAED,MAAM,MAAM,wBAAwB,GACnC,oBAAoB,CAAC,wBAAwB,CAAC,CAAA;AAE/C,eAAO,MAAM,8BAA8B;;;;aAIzC,CAAA;AAEF,qBAAa,oBACZ,SAAQ,KACR,YAAW,oBAAoB;gBAEnB,KAAK,EAAE,wBAAwB;IAO3C,IAAI,EAAE,wBAAwB,CAAA;IAC9B,WAAW,EAAE,OAAO,CAAA;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAkB5B,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockListUsersErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockListUsersErrorCode = "list_users_failed" | (string & {});
4
+ export type CustomBlockListUsersErrorCode = CustomBlockErrorCode<"list_users_failed">;
5
5
  export type CustomBlockListUsersErrorInfo = CustomBlockErrorInfo<CustomBlockListUsersErrorCode>;
6
6
  export declare const customBlockListUsersErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"listUsers.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/listUsers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAKxD,eAAO,MAAM,mCAAmC,2BAAa,CAAA;AAE7D,MAAM,MAAM,6BAA6B,GAAG,mBAAmB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAE/E,MAAM,MAAM,6BAA6B,GACxC,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;AAEpD,eAAO,MAAM,mCAAmC;;;;aAI9C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;aAKjC,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE3E,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAavC,CAAA;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,WAAW,CACjD,OAAO,4BAA4B,CACnC,CAAA"}
1
+ {"version":3,"file":"listUsers.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/listUsers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAK9E,eAAO,MAAM,mCAAmC,2BAAa,CAAA;AAE7D,MAAM,MAAM,6BAA6B,GACxC,oBAAoB,CAAC,mBAAmB,CAAC,CAAA;AAE1C,MAAM,MAAM,6BAA6B,GACxC,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;AAEpD,eAAO,MAAM,mCAAmC;;;;aAI9C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;aAKjC,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE3E,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAavC,CAAA;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,WAAW,CACjD,OAAO,4BAA4B,CACnC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockQueryDataSourceErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockQueryDataSourceErrorCode = "query_data_source_failed" | "unknown_data_source_key" | "unmapped_data_source" | (string & {});
4
+ export type CustomBlockQueryDataSourceErrorCode = CustomBlockErrorCode<"query_data_source_failed" | "unknown_data_source_key" | "unmapped_data_source">;
5
5
  export type CustomBlockQueryDataSourceErrorInfo = CustomBlockErrorInfo<CustomBlockQueryDataSourceErrorCode>;
6
6
  export declare const customBlockQueryDataSourceErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"queryDataSourceResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/queryDataSourceResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAIxD,eAAO,MAAM,yCAAyC,2BAAa,CAAA;AAEnE,MAAM,MAAM,mCAAmC,GAC5C,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,mCAAmC,GAC9C,oBAAoB,CAAC,mCAAmC,CAAC,CAAA;AAE1D,eAAO,MAAM,yCAAyC;;;;aAIpD,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAOnD,CAAA;AAEF,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAgBnD,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCAG7C,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CACvD,OAAO,kCAAkC,CACzC,CAAA"}
1
+ {"version":3,"file":"queryDataSourceResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/queryDataSourceResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAI9E,eAAO,MAAM,yCAAyC,2BAAa,CAAA;AAEnE,MAAM,MAAM,mCAAmC,GAAG,oBAAoB,CACnE,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,CACxB,CAAA;AAED,MAAM,MAAM,mCAAmC,GAC9C,oBAAoB,CAAC,mCAAmC,CAAC,CAAA;AAE1D,eAAO,MAAM,yCAAyC;;;;aAIpD,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAOnD,CAAA;AAEF,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAgBnD,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCAG7C,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CACvD,OAAO,kCAAkC,CACzC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
- import type { CustomBlockErrorInfo } from "../errors.js";
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockUpdatePageErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockUpdatePageErrorCode = "update_page_failed" | "invalid_page_update" | "page_access_failed" | "collection_access_failed" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value" | (string & {});
4
+ export type CustomBlockUpdatePageErrorCode = CustomBlockErrorCode<"update_page_failed" | "invalid_page_update" | "page_access_failed" | "collection_access_failed" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
5
5
  export type CustomBlockUpdatePageErrorInfo = CustomBlockErrorInfo<CustomBlockUpdatePageErrorCode>;
6
6
  export declare const customBlockUpdatePageErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"updatePageResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/updatePageResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAKxD,eAAO,MAAM,oCAAoC,2BAAa,CAAA;AAE9D,MAAM,MAAM,8BAA8B,GACvC,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,GACpB,0BAA0B,GAC1B,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,GACxB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,8BAA8B,GACzC,oBAAoB,CAAC,8BAA8B,CAAC,CAAA;AAErD,eAAO,MAAM,oCAAoC;;;;aAI/C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAaxC,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,WAAW,CAClD,OAAO,6BAA6B,CACpC,CAAA"}
1
+ {"version":3,"file":"updatePageResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/updatePageResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAK9E,eAAO,MAAM,oCAAoC,2BAAa,CAAA;AAE9D,MAAM,MAAM,8BAA8B,GAAG,oBAAoB,CAC9D,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,GACpB,0BAA0B,GAC1B,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,CAC1B,CAAA;AAED,MAAM,MAAM,8BAA8B,GACzC,oBAAoB,CAAC,8BAA8B,CAAC,CAAA;AAErD,eAAO,MAAM,oCAAoC;;;;aAI/C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAaxC,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,WAAW,CAClD,OAAO,6BAA6B,CACpC,CAAA"}
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.0.65"
7
+ export const CUSTOM_BLOCKS_SDK_VERSION = "0.0.67"
@@ -50,7 +50,7 @@ type UseDataSourceResult = {
50
50
  };
51
51
  ```
52
52
 
53
- Reads the data source mapped to `key`. `limit` defaults to 20 and is capped at 999. To show more rows, keep the desired limit in your own component state and pass the larger value back into `useDataSource(key, { limit })`. `propertySchemasByKey` is `undefined` for declared-but-unbound slots. When the host reports a query failure, `error` is `{ code, message, isRetryable }` with `code` narrowed to `CustomBlockQueryDataSourceErrorCode`.
53
+ Reads the data source mapped to `key`. `limit` defaults to 20 and is capped at 999. To show more rows, keep the desired limit in your own component state and pass the larger value back into `useDataSource(key, { limit })`. `propertySchemasByKey` is `undefined` for declared-but-unbound slots. Query failures follow the SDK's [error-handling contract](./errors.md).
54
54
 
55
55
  ### `useManifest()`
56
56
 
package/docs/errors.md ADDED
@@ -0,0 +1,48 @@
1
+ # Error handling
2
+
3
+ Request-style SDK APIs resolve to a result with `status: "success"` or `status: "error"`. Conceptually, success payloads vary by API while error results contain an `error` object with a consistent structure:
4
+
5
+ ```ts
6
+ type Result<T> =
7
+ | { status: "success"; value: T }
8
+ | { status: "error"; error: CustomBlockErrorInfo };
9
+ ```
10
+
11
+ ## Error format
12
+
13
+ SDK errors use `CustomBlockErrorInfo`:
14
+
15
+ ```ts
16
+ type CustomBlockErrorInfo<TCode extends string = string> = {
17
+ code: TCode;
18
+ message: string;
19
+ isRetryable: boolean;
20
+ };
21
+ ```
22
+
23
+ - `code` is a stable identifier intended for application logic.
24
+ - `message` provides developer-facing details and is not a stable identifier.
25
+ - `isRetryable` indicates whether retrying the operation could plausibly succeed.
26
+
27
+ Each API narrows `code` to its own open string union. The known literals provide autocomplete, but newer hosts may send codes that an older SDK does not list.
28
+
29
+ ## API-specific error types
30
+
31
+ - Pages: `CustomBlockCreatePageErrorCode` / `CustomBlockCreatePageErrorInfo`, `CustomBlockGetPageErrorCode` / `CustomBlockGetPageErrorInfo`, and `CustomBlockUpdatePageErrorCode` / `CustomBlockUpdatePageErrorInfo`.
32
+ - Users: `CustomBlockGetUserErrorCode` / `CustomBlockGetUserErrorInfo` and `CustomBlockListUsersErrorCode` / `CustomBlockListUsersErrorInfo`.
33
+ - Data sources: `CustomBlockQueryDataSourceErrorCode` / `CustomBlockQueryDataSourceErrorInfo`.
34
+ - Shared resolution failures: `CustomBlockPropertyErrorCode` / `CustomBlockPropertyErrorInfo` and `CustomBlockDataSourceResolutionErrorCode` / `CustomBlockDataSourceResolutionErrorInfo`.
35
+
36
+ ## Initialization errors
37
+
38
+ Unlike request helpers, `initCustomBlock` rejects with `CustomBlockInitError` when the host rejects initialization. Use `error instanceof CustomBlockInitError`, then inspect its `code` and `isRetryable` fields. Its structured payload is available as `CustomBlockInitErrorInfo`, with `code` narrowed to `CustomBlockInitErrorCode`.
39
+
40
+ See [Lifecycle and initialization](./lifecycle.md) for initialization-specific error codes.
41
+
42
+ ## Handling errors
43
+
44
+ - Branch on `code` and `isRetryable`, never on `message`.
45
+ - Keep a default branch when switching on `code`. The known literals provide autocomplete, but newer hosts may send codes that an older SDK does not list.
46
+ - Treat `isRetryable` as advisory when deciding whether to offer or schedule a retry.
47
+ - Use `message` for developer-facing details, not as a stable identifier.
48
+ - `"unknown_error"` means the host encountered an unexpected or unclassified failure.
package/docs/lifecycle.md CHANGED
@@ -79,14 +79,6 @@ class CustomBlockInitError extends Error {
79
79
  isRetryable: boolean;
80
80
  }
81
81
 
82
- type CustomBlockErrorInfo<TCode extends string = string> = {
83
- code: TCode;
84
- message: string;
85
- isRetryable: boolean;
86
- };
87
-
88
- type CustomBlockInitErrorInfo = CustomBlockErrorInfo<CustomBlockInitErrorCode>;
89
-
90
82
  type CustomBlockInitErrorCode =
91
83
  | "no_ready"
92
84
  | "invalid_ready"
@@ -105,11 +97,7 @@ type CustomBlockInitErrorCode =
105
97
  | "unknown_error";
106
98
  ```
107
99
 
108
- Thrown when the host rejects initialization instead of returning the initial theme, block location, current user, and data sources. `CustomBlockInitErrorInfo` uses the same structured error payload as every other API, with `code` narrowed to `CustomBlockInitErrorCode`. Use `error instanceof CustomBlockInitError`, `error.code`, and `error.isRetryable` to branch on host-reported setup failures.
109
-
110
- Runtime APIs use the same `CustomBlockErrorInfo<TCode>` envelope with their own code unions, such as `CustomBlockCreatePageErrorCode`, `CustomBlockUpdatePageErrorCode`, and `CustomBlockQueryDataSourceErrorCode`.
111
-
112
- The public API-specific runtime aliases are `CustomBlockCreatePageErrorInfo`, `CustomBlockGetPageErrorInfo`, `CustomBlockGetUserErrorInfo`, `CustomBlockListUsersErrorInfo`, `CustomBlockQueryDataSourceErrorInfo`, and `CustomBlockUpdatePageErrorInfo`. Their `code` fields are narrowed by `CustomBlockCreatePageErrorCode`, `CustomBlockGetPageErrorCode`, `CustomBlockGetUserErrorCode`, `CustomBlockListUsersErrorCode`, `CustomBlockQueryDataSourceErrorCode`, and `CustomBlockUpdatePageErrorCode`. Shared categories include `CustomBlockPropertyErrorCode` / `CustomBlockPropertyErrorInfo` and `CustomBlockDataSourceResolutionErrorCode` / `CustomBlockDataSourceResolutionErrorInfo`.
100
+ Thrown when the host rejects initialization instead of returning the initial theme, block location, current user, and data sources. Use `error instanceof CustomBlockInitError`, `error.code`, and `error.isRetryable` to branch on host-reported setup failures. See [Error handling](./errors.md) for the shared structured error contract.
113
101
 
114
102
  ### `customBlock`
115
103
 
package/docs/pages.md CHANGED
@@ -6,18 +6,7 @@ Helpers for creating, reading, updating, and archiving Notion pages from inside
6
6
  import { pages } from "@notionhq/custom-blocks";
7
7
  ```
8
8
 
9
- Every helper returns a discriminated result instead of throwing:
10
-
11
- ```ts
12
- const result = await pages.get(pageId);
13
- if (result.status === "success") {
14
- // result.page is a NotionPage
15
- } else {
16
- // result.error is a human-readable string
17
- }
18
- ```
19
-
20
- Always check `result.status` before reading `result.page`.
9
+ Every helper follows the SDK's [error-handling contract](./errors.md). Check `result.status` before reading the success payload.
21
10
 
22
11
  ## Creating pages
23
12
 
package/docs/users.md CHANGED
@@ -12,18 +12,7 @@ import {
12
12
  import { useCurrentUser } from "@notionhq/custom-blocks/react";
13
13
  ```
14
14
 
15
- Every helper returns a discriminated result instead of throwing:
16
-
17
- ```ts
18
- const result = await users.get(userId);
19
- if (result.status === "success") {
20
- // result.user is a NotionUser
21
- } else {
22
- // result.error is a human-readable string
23
- }
24
- ```
25
-
26
- Always check `result.status` before reading `result.user` / `result.list`.
15
+ Every helper follows the SDK's [error-handling contract](./errors.md). Check `result.status` before reading `result.user` or `result.list`.
27
16
 
28
17
  ## Reading the current user
29
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,5 +1,13 @@
1
1
  import * as v from "valibot"
2
2
 
3
+ export type CustomBlockErrorCode<KnownCode extends string> =
4
+ // Accept a list of known codes for auto-completion.
5
+ | KnownCode
6
+ // Hosts send this for any errors that are not covered by an error code known by that host.
7
+ | "unknown_error"
8
+ // Hosts may introduce new codes in the future, so allow any string as a catch-all.
9
+ | (string & {})
10
+
3
11
  export type CustomBlockErrorInfo<TCode extends string = string> = {
4
12
  code: TCode
5
13
  message: string
@@ -1,12 +1,12 @@
1
1
  import * as v from "valibot"
2
- import type { CustomBlockErrorInfo } from "../errors.js"
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
3
  import { notionPageSchema } from "../pages/page.js"
4
4
 
5
5
  // The schema accepts any string code. The type lists known codes for
6
6
  // autocomplete, with an open string fallback for newer senders.
7
7
  export const customBlockCreatePageErrorCodeSchema = v.string()
8
8
 
9
- export type CustomBlockCreatePageErrorCode =
9
+ export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<
10
10
  | "create_page_failed"
11
11
  | "invalid_page_parent"
12
12
  | "page_access_failed"
@@ -17,7 +17,7 @@ export type CustomBlockCreatePageErrorCode =
17
17
  | "property_id_mismatch"
18
18
  | "duplicate_property"
19
19
  | "invalid_property_value"
20
- | (string & {})
20
+ >
21
21
 
22
22
  export type CustomBlockCreatePageErrorInfo =
23
23
  CustomBlockErrorInfo<CustomBlockCreatePageErrorCode>
@@ -1,5 +1,5 @@
1
1
  import * as v from "valibot"
2
- import type { CustomBlockErrorInfo } from "../errors.js"
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
3
  import { notionPageIdSchema } from "../ids.js"
4
4
  import { notionPageSchema } from "../pages/page.js"
5
5
 
@@ -7,10 +7,9 @@ import { notionPageSchema } from "../pages/page.js"
7
7
  // autocomplete, with an open string fallback for newer senders.
8
8
  export const customBlockGetPageErrorCodeSchema = v.string()
9
9
 
10
- export type CustomBlockGetPageErrorCode =
11
- | "get_page_failed"
12
- | "page_access_failed"
13
- | (string & {})
10
+ export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<
11
+ "get_page_failed" | "page_access_failed"
12
+ >
14
13
 
15
14
  export type CustomBlockGetPageErrorInfo =
16
15
  CustomBlockErrorInfo<CustomBlockGetPageErrorCode>
@@ -1,12 +1,13 @@
1
1
  import * as v from "valibot"
2
- import type { CustomBlockErrorInfo } from "../errors.js"
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
3
  import { notionUserSchema } from "../users/user.js"
4
4
 
5
5
  // The schema accepts any string code. The type lists known codes for
6
6
  // autocomplete, with an open string fallback for newer senders.
7
7
  export const customBlockGetUserErrorCodeSchema = v.string()
8
8
 
9
- export type CustomBlockGetUserErrorCode = "get_user_failed" | (string & {})
9
+ export type CustomBlockGetUserErrorCode =
10
+ CustomBlockErrorCode<"get_user_failed">
10
11
 
11
12
  export type CustomBlockGetUserErrorInfo =
12
13
  CustomBlockErrorInfo<CustomBlockGetUserErrorCode>
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot"
2
2
  import { notionDataSourceBindingsSchema } from "../dataSources/dataSource.js"
3
- import type { CustomBlockErrorInfo } from "../errors.js"
3
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
4
4
  import { notionBlockIdSchema } from "../ids.js"
5
5
  import { customBlockPageSchema } from "../pages/page.js"
6
6
  import { notionParentSchema } from "../parent.js"
@@ -11,7 +11,7 @@ import { notionUserSchema } from "../users/user.js"
11
11
  // autocomplete, with an open string fallback for newer senders.
12
12
  export const customBlockInitErrorCodeSchema = v.string()
13
13
 
14
- export type CustomBlockInitErrorCode =
14
+ export type CustomBlockInitErrorCode = CustomBlockErrorCode<
15
15
  | "no_ready"
16
16
  | "invalid_ready"
17
17
  | "manifest_unavailable"
@@ -26,8 +26,7 @@ export type CustomBlockInitErrorCode =
26
26
  | "invalid_property_binding"
27
27
  | "not_in_iframe"
28
28
  | "init_timeout"
29
- | "unknown_error"
30
- | (string & {})
29
+ >
31
30
 
32
31
  export type CustomBlockInitErrorInfo =
33
32
  CustomBlockErrorInfo<CustomBlockInitErrorCode>
@@ -1,12 +1,13 @@
1
1
  import * as v from "valibot"
2
- import type { CustomBlockErrorInfo } from "../errors.js"
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
3
  import { notionUserListSchema } from "../users/user.js"
4
4
 
5
5
  // The schema accepts any string code. The type lists known codes for
6
6
  // autocomplete, with an open string fallback for newer senders.
7
7
  export const customBlockListUsersErrorCodeSchema = v.string()
8
8
 
9
- export type CustomBlockListUsersErrorCode = "list_users_failed" | (string & {})
9
+ export type CustomBlockListUsersErrorCode =
10
+ CustomBlockErrorCode<"list_users_failed">
10
11
 
11
12
  export type CustomBlockListUsersErrorInfo =
12
13
  CustomBlockErrorInfo<CustomBlockListUsersErrorCode>
@@ -1,16 +1,16 @@
1
1
  import * as v from "valibot"
2
2
  import { notionDataSourcePageBridgeSchema } from "../dataSources/dataSourcePage.js"
3
- import type { CustomBlockErrorInfo } from "../errors.js"
3
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
4
4
 
5
5
  // The schema accepts any string code. The type lists known codes for
6
6
  // autocomplete, with an open string fallback for newer senders.
7
7
  export const customBlockQueryDataSourceErrorCodeSchema = v.string()
8
8
 
9
- export type CustomBlockQueryDataSourceErrorCode =
9
+ export type CustomBlockQueryDataSourceErrorCode = CustomBlockErrorCode<
10
10
  | "query_data_source_failed"
11
11
  | "unknown_data_source_key"
12
12
  | "unmapped_data_source"
13
- | (string & {})
13
+ >
14
14
 
15
15
  export type CustomBlockQueryDataSourceErrorInfo =
16
16
  CustomBlockErrorInfo<CustomBlockQueryDataSourceErrorCode>
@@ -1,12 +1,12 @@
1
1
  import * as v from "valibot"
2
- import type { CustomBlockErrorInfo } from "../errors.js"
2
+ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
3
  import { notionPageSchema } from "../pages/page.js"
4
4
 
5
5
  // The schema accepts any string code. The type lists known codes for
6
6
  // autocomplete, with an open string fallback for newer senders.
7
7
  export const customBlockUpdatePageErrorCodeSchema = v.string()
8
8
 
9
- export type CustomBlockUpdatePageErrorCode =
9
+ export type CustomBlockUpdatePageErrorCode = CustomBlockErrorCode<
10
10
  | "update_page_failed"
11
11
  | "invalid_page_update"
12
12
  | "page_access_failed"
@@ -15,7 +15,7 @@ export type CustomBlockUpdatePageErrorCode =
15
15
  | "property_id_mismatch"
16
16
  | "duplicate_property"
17
17
  | "invalid_property_value"
18
- | (string & {})
18
+ >
19
19
 
20
20
  export type CustomBlockUpdatePageErrorInfo =
21
21
  CustomBlockErrorInfo<CustomBlockUpdatePageErrorCode>