@notionhq/custom-blocks 0.2.24 → 0.3.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.
Files changed (73) hide show
  1. package/README.md +8 -5
  2. package/dist/bridge/SandboxBridge.d.ts +15 -14
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +117 -35
  5. package/dist/bridge/dataSources/resolve.d.ts +1 -3
  6. package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
  7. package/dist/bridge/dataSources/resolve.js +1 -11
  8. package/dist/bridge/dataSources/subscribe.d.ts +2 -1
  9. package/dist/bridge/dataSources/subscribe.d.ts.map +1 -1
  10. package/dist/bridge/dataSources/subscribe.js +6 -1
  11. package/dist/bridge/hostState.d.ts +11 -39
  12. package/dist/bridge/hostState.d.ts.map +1 -1
  13. package/dist/bridge/hostState.js +5 -50
  14. package/dist/bridge/page.d.ts +14 -0
  15. package/dist/bridge/page.d.ts.map +1 -0
  16. package/dist/bridge/page.js +59 -0
  17. package/dist/bridge/sandboxClient.d.ts +8 -14
  18. package/dist/bridge/sandboxClient.d.ts.map +1 -1
  19. package/dist/bridge/sandboxClient.js +13 -21
  20. package/dist/dataSources.d.ts +8 -0
  21. package/dist/dataSources.d.ts.map +1 -0
  22. package/dist/dataSources.js +103 -0
  23. package/dist/index.d.ts +6 -6
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -2
  26. package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -5
  27. package/dist/protocol/dataSources/dataSourcePage.js +2 -3
  28. package/dist/protocol/dataSources/propertySchema.d.ts +1 -0
  29. package/dist/protocol/index.d.ts +1 -0
  30. package/dist/protocol/index.js +1 -0
  31. package/dist/protocol/messages/createPage.js +2 -2
  32. package/dist/protocol/messages/createPageResult.d.ts +468 -1
  33. package/dist/protocol/messages/createPageResult.js +17 -2
  34. package/dist/protocol/messages/getPage.d.ts +468 -1
  35. package/dist/protocol/messages/getPage.js +18 -3
  36. package/dist/protocol/messages/hostToSandbox.d.ts +2587 -178
  37. package/dist/protocol/messages/hostToSandbox.js +24 -12
  38. package/dist/protocol/messages/openExternalUrl.d.ts +32 -0
  39. package/dist/protocol/messages/openExternalUrl.js +26 -0
  40. package/dist/protocol/messages/queryDataSourceResult.d.ts +468 -1
  41. package/dist/protocol/messages/queryDataSourceResult.js +18 -2
  42. package/dist/protocol/messages/sandboxToHost.d.ts +6 -0
  43. package/dist/protocol/messages/sandboxToHost.js +2 -0
  44. package/dist/protocol/messages/updatePage.d.ts +1 -0
  45. package/dist/protocol/messages/updatePage.js +4 -3
  46. package/dist/protocol/messages/updatePageResult.d.ts +467 -1
  47. package/dist/protocol/messages/updatePageResult.js +16 -2
  48. package/dist/protocol/pages/page.d.ts +386 -6
  49. package/dist/protocol/pages/page.js +23 -2
  50. package/dist/protocol/protocolVersion.d.ts +2 -1
  51. package/dist/protocol/protocolVersion.js +4 -1
  52. package/dist/react/useDataSource.d.ts +1 -1
  53. package/dist/react/useDataSource.d.ts.map +1 -1
  54. package/dist/react/useDataSource.js +1 -3
  55. package/dist/types.d.ts +55 -96
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/version.js +1 -1
  58. package/docs/block-location.md +3 -3
  59. package/docs/data-sources.md +167 -133
  60. package/docs/errors.md +9 -9
  61. package/docs/links.md +44 -0
  62. package/docs/pages.md +113 -182
  63. package/package.json +1 -1
  64. package/src/bridge/SandboxBridge.ts +189 -62
  65. package/src/bridge/dataSources/resolve.ts +1 -20
  66. package/src/bridge/dataSources/subscribe.ts +10 -5
  67. package/src/bridge/hostState.ts +21 -100
  68. package/src/bridge/page.ts +90 -0
  69. package/src/bridge/sandboxClient.ts +15 -25
  70. package/src/dataSources.ts +140 -0
  71. package/src/index.ts +8 -19
  72. package/src/react/useDataSource.ts +1 -3
  73. package/src/types.ts +61 -109
@@ -0,0 +1,59 @@
1
+ export function toNotionPageFromNotionPageData(args) {
2
+ const { page: bridgePage, dataSource } = args;
3
+ const getPropertyById = (id) => Object.values(sdkPage.properties).find(value => value?.id === id) ?? null;
4
+ let pending;
5
+ const updatePage = (payload, dataSourceId) => {
6
+ const operation = async () => {
7
+ const result = await args.update(payload, dataSourceId);
8
+ if (result.status === "error") {
9
+ return result;
10
+ }
11
+ Object.assign(sdkPage, result.page);
12
+ return { status: "success", page: sdkPage };
13
+ };
14
+ const result = pending ? pending.then(operation) : operation();
15
+ const finished = result.then(() => undefined, () => undefined);
16
+ pending = finished;
17
+ void finished.then(() => {
18
+ if (pending === finished) {
19
+ pending = undefined;
20
+ }
21
+ });
22
+ return result;
23
+ };
24
+ const updateById = (payload) => updatePage(payload, undefined);
25
+ const updateByKey = (payload) => {
26
+ const dataSourceId = dataSource?.collectionPointer?.id;
27
+ if (dataSourceId === undefined) {
28
+ return Promise.resolve({
29
+ status: "error",
30
+ error: {
31
+ code: "unmapped_data_source",
32
+ message: "This page has no bound data source context.",
33
+ isRetryable: false,
34
+ },
35
+ });
36
+ }
37
+ return updatePage(payload, dataSourceId);
38
+ };
39
+ const methods = {
40
+ getPropertyById,
41
+ getPropertyByKey: (key) => {
42
+ const source = args.getDataSource();
43
+ const id = source && Object.hasOwn(source.propertyIdsByKey, key)
44
+ ? source.propertyIdsByKey[key]
45
+ : undefined;
46
+ return id === undefined ? null : getPropertyById(id);
47
+ },
48
+ updateById,
49
+ updateByKey,
50
+ archive: () => updateById({ is_archived: true }),
51
+ unarchive: () => updateById({ is_archived: false }),
52
+ };
53
+ const sdkPage = {
54
+ ...bridgePage,
55
+ dataSourceKey: dataSource?.key ?? null,
56
+ ...methods,
57
+ };
58
+ return sdkPage;
59
+ }
@@ -1,10 +1,11 @@
1
1
  import type { NotionPageId } from "../protocol/ids.js";
2
2
  import type { InitMessage } from "../protocol/messages/init.js";
3
- import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionUserId, OpenPageOptions, OpenPageResult, UpdatePageArgs, UpdatePageResult } from "../types.js";
3
+ import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionUserId, OpenExternalUrlResult, OpenPageOptions, OpenPageResult } from "../types.js";
4
4
  import { type CustomBlockHostState, type DataSourceQueryView } from "./hostState.js";
5
5
  import type { ManifestLoadResult } from "./loadManifest.js";
6
6
  import type { MessageInterceptor } from "./messageInterceptor.js";
7
- import { type MessageLogEntry, type QueryDataSourceArgs } from "./SandboxBridge.js";
7
+ import { type MessageLogEntry, type QueryDataSourceArgs, SandboxBridge } from "./SandboxBridge.js";
8
+ export declare function getBridge(): SandboxBridge;
8
9
  export declare const customBlockHost: {
9
10
  registerMessageInterceptor: (interceptor: MessageInterceptor) => (() => void);
10
11
  sendConnect: (manifestResult: ManifestLoadResult) => void;
@@ -45,18 +46,11 @@ export declare const pages: {
45
46
  * Requests that the Notion host open a page.
46
47
  */
47
48
  open: (pageId: NotionPageId, options: OpenPageOptions) => Promise<OpenPageResult>;
48
- /**
49
- * Updates an existing page.
50
- */
51
- update: (input: UpdatePageArgs) => Promise<UpdatePageResult>;
52
- /**
53
- * Archives a page.
54
- */
55
- archive: (pageId: NotionPageId) => Promise<UpdatePageResult>;
56
- /**
57
- * Unarchives a page.
58
- */
59
- unarchive: (pageId: NotionPageId) => Promise<UpdatePageResult>;
49
+ };
50
+ /** External-link APIs exposed under `sdk.links.*`. */
51
+ export declare const links: {
52
+ /** Requests host-owned approval before opening an HTTPS URL. */
53
+ open: (url: string) => Promise<OpenExternalUrlResult>;
60
54
  };
61
55
  /**
62
56
  * User-related SDK APIs exposed under `sdk.users.*`.
@@ -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,K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MAAM,IAAI;IAIhC,QAAQ,QAAM,oBAAoB;IAIlC;;;OAGG;IACH,YAAY,YAAY,WAAW;IAInC,sBAAsB;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;CAYtB,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;IAI1D;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;IAInD;;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,7 +1,7 @@
1
1
  import { getDataSourceQueryView as getDataSourceQueryViewWithBridge, } from "./hostState.js";
2
2
  import { SandboxBridge, } from "./SandboxBridge.js";
3
3
  let bridge;
4
- function getBridge() {
4
+ export function getBridge() {
5
5
  if (!bridge) {
6
6
  bridge = new SandboxBridge();
7
7
  }
@@ -46,7 +46,10 @@ export const customBlockDataSources = {
46
46
  getBridge().releaseDataSourceSubscription(subscriptionId);
47
47
  },
48
48
  getView: (hostState, key, subscriptionId) => {
49
- return getDataSourceQueryViewWithBridge(hostState, key, subscriptionId, args => getBridge().updateDataSourcePage(args));
49
+ return getDataSourceQueryViewWithBridge(hostState, key, subscriptionId, ({ page, dataSource }) => getBridge().buildNotionPage({
50
+ page,
51
+ dataSourceId: dataSource?.collectionPointer?.id,
52
+ }));
50
53
  },
51
54
  };
52
55
  export const messageLog = {
@@ -65,13 +68,13 @@ export const pages = {
65
68
  * Creates a new Notion page.
66
69
  */
67
70
  create: (input) => {
68
- return getBridge().createPage(input);
71
+ return getBridge().createPage(input, undefined);
69
72
  },
70
73
  /**
71
74
  * Fetches a page by id.
72
75
  */
73
76
  get: (pageId) => {
74
- return getBridge().getPage(pageId);
77
+ return getBridge().getPage(pageId, undefined);
75
78
  },
76
79
  /**
77
80
  * Requests that the Notion host open a page.
@@ -79,23 +82,12 @@ export const pages = {
79
82
  open: (pageId, options) => {
80
83
  return getBridge().openPage(pageId, options);
81
84
  },
82
- /**
83
- * Updates an existing page.
84
- */
85
- update: (input) => {
86
- return getBridge().updatePage(input);
87
- },
88
- /**
89
- * Archives a page.
90
- */
91
- archive: (pageId) => {
92
- return getBridge().updatePage({ pageId, is_archived: true });
93
- },
94
- /**
95
- * Unarchives a page.
96
- */
97
- unarchive: (pageId) => {
98
- return getBridge().updatePage({ pageId, is_archived: false });
85
+ };
86
+ /** External-link APIs exposed under `sdk.links.*`. */
87
+ export const links = {
88
+ /** Requests host-owned approval before opening an HTTPS URL. */
89
+ open: (url) => {
90
+ return getBridge().openExternalUrl(url);
99
91
  },
100
92
  };
101
93
  /**
@@ -0,0 +1,8 @@
1
+ import type { NotionPageId } from "./protocol/ids.js";
2
+ import type { CreatePageArgs, DataSourceQueryOptions, DataSourcesPageResult, DataSourcesQueryResult } from "./types.js";
3
+ export declare const dataSources: {
4
+ getPage(key: string, pageId: NotionPageId): Promise<DataSourcesPageResult>;
5
+ create(key: string, payload: Omit<CreatePageArgs, "parent" | "position">): Promise<DataSourcesPageResult>;
6
+ query(key: string, options?: DataSourceQueryOptions): Promise<DataSourcesQueryResult>;
7
+ };
8
+ //# sourceMappingURL=dataSources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataSources.d.ts","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAIhD,OAAO,KAAK,EACX,cAAc,EAEd,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,WAAW;IACjB,OAAO,MACP,MAAM,UACH,YAAY,GAClB,OAAO,CAAC,qBAAqB,CAAC;IAW3B,MAAM,MACN,MAAM,WACF,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,UAAU,CAAC,GAClD,OAAO,CAAC,qBAAqB,CAAC;IAiB3B,KAAK,MACL,MAAM,YACD,sBAAsB,GAC9B,OAAO,CAAC,sBAAsB,CAAC;CAwDlC,CAAA"}
@@ -0,0 +1,103 @@
1
+ import { CustomBlockInitializationError } from "./protocol/messages/init.js";
2
+ import { subscribeToDataSource } from "./bridge/dataSources/subscribe.js";
3
+ import { getBridge } from "./bridge/sandboxClient.js";
4
+ export const dataSources = {
5
+ async getPage(key, pageId) {
6
+ const resolved = resolvePageDataSource(key);
7
+ if (resolved.status === "error") {
8
+ return resolved;
9
+ }
10
+ const { dataSource, dataSourceId } = resolved;
11
+ const result = await getBridge().getPage(pageId, dataSourceId);
12
+ return result.status === "error"
13
+ ? result
14
+ : { ...result, propertyIdsByKey: dataSource.propertyIdsByKey };
15
+ },
16
+ async create(key, payload) {
17
+ const resolved = resolvePageDataSource(key);
18
+ if (resolved.status === "error") {
19
+ return resolved;
20
+ }
21
+ const { dataSource, dataSourceId } = resolved;
22
+ const result = await getBridge().createPage({
23
+ ...payload,
24
+ parent: { type: "data_source_id", data_source_id: dataSourceId },
25
+ }, dataSourceId);
26
+ return result.status === "error"
27
+ ? result
28
+ : { ...result, propertyIdsByKey: dataSource.propertyIdsByKey };
29
+ },
30
+ async query(key, options) {
31
+ const bridge = getBridge();
32
+ if (bridge.getHostState().status !== "initialized") {
33
+ try {
34
+ await bridge.initialize();
35
+ }
36
+ catch (error) {
37
+ if (bridge.getHostState().status !== "initialized") {
38
+ return {
39
+ status: "error",
40
+ error: error instanceof CustomBlockInitializationError
41
+ ? {
42
+ code: error.code,
43
+ message: error.message,
44
+ isRetryable: error.isRetryable,
45
+ }
46
+ : {
47
+ code: "unknown_error",
48
+ message: error instanceof Error ? error.message : String(error),
49
+ isRetryable: false,
50
+ },
51
+ };
52
+ }
53
+ }
54
+ }
55
+ return new Promise(resolve => {
56
+ let completed = false;
57
+ let unsubscribe = () => { };
58
+ unsubscribe = subscribeToDataSource({
59
+ key,
60
+ options,
61
+ onSnapshot: snapshot => {
62
+ if (snapshot.isLoading || completed) {
63
+ return;
64
+ }
65
+ completed = true;
66
+ unsubscribe();
67
+ resolve({ status: "success", ...snapshot });
68
+ },
69
+ }, error => {
70
+ if (completed) {
71
+ return;
72
+ }
73
+ completed = true;
74
+ unsubscribe();
75
+ resolve({ status: "error", error });
76
+ });
77
+ if (completed) {
78
+ unsubscribe();
79
+ }
80
+ });
81
+ },
82
+ };
83
+ function resolvePageDataSource(key) {
84
+ const hostState = getBridge().getHostState();
85
+ const dataSource = hostState.status === "initialized"
86
+ ? hostState.dataSources.find(source => source.key === key)
87
+ : undefined;
88
+ if (!dataSource?.collectionPointer) {
89
+ return {
90
+ status: "error",
91
+ error: {
92
+ code: dataSource ? "unmapped_data_source" : "unknown_data_source_key",
93
+ message: `No bound data source for "${key}".`,
94
+ isRetryable: false,
95
+ },
96
+ };
97
+ }
98
+ return {
99
+ status: "success",
100
+ dataSource,
101
+ dataSourceId: dataSource.collectionPointer.id,
102
+ };
103
+ }
package/dist/index.d.ts CHANGED
@@ -8,11 +8,9 @@
8
8
  */
9
9
  export type { NotionContrastMode } from "./protocol/contrast.js";
10
10
  export type { NotionCollectionSchema, NotionDataSource, } from "./protocol/dataSources/dataSource.js";
11
- export type { NotionDataSourceValue } from "./protocol/dataSources/dataSourceValue.js";
12
- export type { NotionDate, NotionDateRange, NotionDateReminder, NotionDateTime, NotionDateTimeRange, NotionDateTimeReminder, NotionDateValue, NotionNoReminder, NotionTimeReminder, } from "./protocol/dataSources/dateValue.js";
13
11
  export type { CustomBlockDataSourceResolutionErrorCode, CustomBlockDataSourceResolutionErrorInfo, CustomBlockPropertyErrorCode, CustomBlockPropertyErrorInfo, } from "./protocol/dataSources/errors.js";
14
- export type { NotionBuiltinPropertyId, NotionDualProperty, NotionPropertyColor, NotionPropertyOption, NotionPropertySchema, NotionPropertyType, NotionStatusGroup, } from "./protocol/dataSources/propertySchema.js";
15
- export { NOTION_BUILTIN_PROPERTY_IDS, NOTION_PROPERTY_TYPES, } from "./protocol/dataSources/propertySchema.js";
12
+ export type { NotionDualProperty, NotionPropertyColor, NotionPropertyOption, NotionPropertySchema, NotionPropertyType, NotionStatusGroup, } from "./protocol/dataSources/propertySchema.js";
13
+ export { NOTION_PROPERTY_TYPES } from "./protocol/dataSources/propertySchema.js";
16
14
  export type { NotionRecordPointer } from "./protocol/dataSources/recordPointer.js";
17
15
  export type { NotionSortDirection } from "./protocol/dataSources/sortDirection.js";
18
16
  export type { CustomBlockErrorInfo } from "./protocol/errors.js";
@@ -25,14 +23,16 @@ export type { CustomBlockGetUserErrorCode, CustomBlockGetUserErrorInfo, } from "
25
23
  export type { CustomBlockInitializationErrorCode, CustomBlockInitializationErrorInfo, } from "./protocol/messages/init.js";
26
24
  export { CustomBlockInitializationError } from "./protocol/messages/init.js";
27
25
  export type { CustomBlockListUsersErrorCode, CustomBlockListUsersErrorInfo, } from "./protocol/messages/listUsers.js";
26
+ export type { CustomBlockOpenExternalUrlErrorCode, CustomBlockOpenExternalUrlErrorInfo, } from "./protocol/messages/openExternalUrl.js";
28
27
  export type { CustomBlockOpenPageErrorCode, CustomBlockOpenPageErrorInfo, OpenPageMode, } from "./protocol/messages/openPage.js";
29
28
  export type { CustomBlockQueryDataSourceErrorCode, CustomBlockQueryDataSourceErrorInfo, } from "./protocol/messages/queryDataSourceResult.js";
30
29
  export type { CustomBlockUpdatePageErrorCode, CustomBlockUpdatePageErrorInfo, } from "./protocol/messages/updatePageResult.js";
31
- export type { CustomBlockPage, NotionPage, NotionPageCover, NotionPageIcon, NotionPagePropertyReadMap, NotionPagePropertyValue, NotionPagePropertyWriteMap, } from "./protocol/pages/page.js";
30
+ export type { CustomBlockPage, NotionDateInput, NotionPageCover, NotionPageIcon, NotionPagePropertyReadMap, NotionPagePropertyValue, NotionPagePropertyWriteMap, } from "./protocol/pages/page.js";
32
31
  export type { NotionParent } from "./protocol/parent.js";
33
32
  export type { NotionTheme } from "./protocol/theme.js";
34
- export { pages, users } from "./bridge/sandboxClient.js";
33
+ export { links, pages, users } from "./bridge/sandboxClient.js";
35
34
  export { customBlock } from "./customBlock.js";
35
+ export { dataSources } from "./dataSources.js";
36
36
  export { type CustomBlockInitPayload, initCustomBlock, NotInIframeError, } from "./init.js";
37
37
  export * from "./types.js";
38
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,YAAY,EACX,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,4DAA4D,CAAA;AACnE,YAAY,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,YAAY,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GAClB,MAAM,2DAA2D,CAAA;AAClE,YAAY,EACX,wCAAwC,EACxC,wCAAwC,EACxC,4BAA4B,EA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,EACN,KAAK,sBAAsB,EAC3B,eAAe,EACf,gBAAgB,GAChB,MAAM,WAAW,CAAA;AAClB,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@
6
6
  * consumers should import from `@notionhq/custom-blocks`; React consumers
7
7
  * should import hooks and components from `@notionhq/custom-blocks/react`.
8
8
  */
9
- export { NOTION_BUILTIN_PROPERTY_IDS, NOTION_PROPERTY_TYPES, } from "./protocol/dataSources/propertySchema.js";
9
+ export { NOTION_PROPERTY_TYPES } from "./protocol/dataSources/propertySchema.js";
10
10
  export { CustomBlockInitializationError } from "./protocol/messages/init.js";
11
- export { pages, users } from "./bridge/sandboxClient.js";
11
+ export { links, pages, users } from "./bridge/sandboxClient.js";
12
12
  export { customBlock } from "./customBlock.js";
13
+ export { dataSources } from "./dataSources.js";
13
14
  export { initCustomBlock, NotInIframeError, } from "./init.js";
14
15
  export * from "./types.js";
@@ -1,10 +1,9 @@
1
1
  import * as v from "valibot";
2
2
  /**
3
3
  * Bridge shape for a data source page, as parsed from inbound host messages. The host keys
4
- * properties by raw property ID. The four built-ins (`created_time`, `last_edited_time`,
5
- * `created_by`, `last_edited_by`) are normally present, possibly with `undefined` values.
4
+ * properties by raw property ID. Only actual schema properties are included.
6
5
  */
7
- export declare const notionDataSourcePageBridgeSchema: v.ObjectSchema<{
6
+ export declare const legacyNotionDataSourcePageBridgeSchema: v.ObjectSchema<{
8
7
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
9
8
  /** Whether the page or an ancestor is archived. */
10
9
  readonly is_archived: v.BooleanSchema<undefined>;
@@ -72,5 +71,4 @@ export declare const notionDataSourcePageBridgeSchema: v.ObjectSchema<{
72
71
  readonly table: v.StringSchema<undefined>;
73
72
  }, undefined>, undefined>], undefined>, undefined>, undefined>;
74
73
  }, undefined>;
75
- /** Internal SDK type for a parsed bridge page. */
76
- export type NotionDataSourcePageBridge = v.InferOutput<typeof notionDataSourcePageBridgeSchema>;
74
+ export type LegacyNotionDataSourcePageBridge = v.InferOutput<typeof legacyNotionDataSourcePageBridgeSchema>;
@@ -3,10 +3,9 @@ import { notionPageIdSchema } from "../ids.js";
3
3
  import { notionDataSourceValueSchema } from "./dataSourceValue.js";
4
4
  /**
5
5
  * Bridge shape for a data source page, as parsed from inbound host messages. The host keys
6
- * properties by raw property ID. The four built-ins (`created_time`, `last_edited_time`,
7
- * `created_by`, `last_edited_by`) are normally present, possibly with `undefined` values.
6
+ * properties by raw property ID. Only actual schema properties are included.
8
7
  */
9
- export const notionDataSourcePageBridgeSchema = v.object({
8
+ export const legacyNotionDataSourcePageBridgeSchema = v.object({
10
9
  id: notionPageIdSchema,
11
10
  /** Whether the page or an ancestor is archived. */
12
11
  is_archived: v.boolean(),
@@ -189,6 +189,7 @@ export declare const notionPropertySchemaSchema: v.VariantSchema<"type", [v.Obje
189
189
  readonly type: v.LiteralSchema<"last_edited_by", undefined>;
190
190
  }, undefined>], undefined>;
191
191
  export type NotionPropertySchema = v.InferOutput<typeof notionPropertySchemaSchema>;
192
+ export type NotionPropertySchemasById = Record<string, NotionPropertySchema>;
192
193
  /**
193
194
  * The four synthetic built-in property IDs the host always includes in every
194
195
  * data source's `propertySchemasById` and every row's `propertiesById`.
@@ -34,6 +34,7 @@ export * from "./messages/invalidSandboxMessage.js";
34
34
  export * from "./messages/isInitHandshakeMessage.js";
35
35
  export * from "./messages/listUsers.js";
36
36
  export * from "./messages/messagePayload.js";
37
+ export * from "./messages/openExternalUrl.js";
37
38
  export * from "./messages/openPage.js";
38
39
  export * from "./messages/pageChanged.js";
39
40
  export * from "./messages/parentChanged.js";
@@ -34,6 +34,7 @@ export * from "./messages/invalidSandboxMessage.js";
34
34
  export * from "./messages/isInitHandshakeMessage.js";
35
35
  export * from "./messages/listUsers.js";
36
36
  export * from "./messages/messagePayload.js";
37
+ export * from "./messages/openExternalUrl.js";
37
38
  export * from "./messages/openPage.js";
38
39
  export * from "./messages/pageChanged.js";
39
40
  export * from "./messages/parentChanged.js";
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { notionBlockIdSchema, notionDataSourceIdSchema, notionPageIdSchema, } from "../ids.js";
3
- import { notionPagePropertyReadMapSchema } from "../pages/page.js";
3
+ import { notionPagePropertyWriteMapSchema } from "../pages/page.js";
4
4
  /**
5
5
  * Describes where the newly created page should be inserted.
6
6
  * - `start` / `end` (default): prepend / append to the request's `parent`
@@ -46,6 +46,6 @@ export const createPageMessageSchema = v.object({
46
46
  * To create a page with manifest-defined property keys, call `pages.create`. The SDK resolves
47
47
  * those keys before it sends this message.
48
48
  */
49
- properties: notionPagePropertyReadMapSchema,
49
+ properties: notionPagePropertyWriteMapSchema,
50
50
  position: v.optional(notionCreatePagePositionSchema),
51
51
  });