@notionhq/custom-blocks 0.3.5 → 0.4.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 (124) hide show
  1. package/README.md +2 -2
  2. package/dist/bridge/SandboxBridge.d.ts +4 -23
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +36 -104
  5. package/dist/bridge/requests.d.ts +35 -0
  6. package/dist/bridge/requests.d.ts.map +1 -0
  7. package/dist/bridge/requests.js +97 -0
  8. package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
  9. package/dist/dataSources/bridge/resolveDataSourceQuery.js +15 -1
  10. package/dist/dataSources/createDataSourcePage.d.ts.map +1 -1
  11. package/dist/dataSources/createDataSourcePage.js +5 -1
  12. package/dist/dataSources/types.d.ts +2 -0
  13. package/dist/dataSources/types.d.ts.map +1 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/manifest/types.d.ts +1 -1
  17. package/dist/manifest/types.d.ts.map +1 -1
  18. package/dist/navigation/openExternalUrl.d.ts.map +1 -1
  19. package/dist/navigation/openExternalUrl.js +2 -1
  20. package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
  21. package/dist/pages/bridge/getPageForDataSource.js +2 -1
  22. package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
  23. package/dist/pages/bridge/sendCreatePageRequest.js +2 -1
  24. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +11 -2
  25. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
  26. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +0 -1
  27. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
  28. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -6
  29. package/dist/pages/bridge/updatePage.d.ts.map +1 -1
  30. package/dist/pages/bridge/updatePage.js +19 -4
  31. package/dist/pages/createPage.d.ts.map +1 -1
  32. package/dist/pages/createPage.js +5 -1
  33. package/dist/pages/openPage.d.ts.map +1 -1
  34. package/dist/pages/openPage.js +2 -1
  35. package/dist/pages/types.d.ts +5 -7
  36. package/dist/pages/types.d.ts.map +1 -1
  37. package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +7 -5
  38. package/dist/protocol/context/parent.d.ts +2 -0
  39. package/dist/protocol/dataSources/bridgeArchiveStatus.d.ts +3 -0
  40. package/dist/protocol/dataSources/bridgeArchiveStatus.js +6 -0
  41. package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +0 -4
  42. package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +0 -4
  43. package/dist/protocol/dataSources/collectionSchema.d.ts +0 -4
  44. package/dist/protocol/dataSources/messages/dataSourcesChanged.d.ts +0 -4
  45. package/dist/protocol/dataSources/messages/queryDataSource.d.ts +17 -14
  46. package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
  47. package/dist/protocol/dataSources/notionDataSource.d.ts +0 -8
  48. package/dist/protocol/dataSources/properties/propertySchema.d.ts +3 -7
  49. package/dist/protocol/dataSources/properties/propertySchema.js +1 -3
  50. package/dist/protocol/handshake/connect.d.ts +15 -4
  51. package/dist/protocol/handshake/init.d.ts +15 -8
  52. package/dist/protocol/icons.d.ts +17 -0
  53. package/dist/protocol/icons.js +27 -0
  54. package/dist/protocol/index.d.ts +13 -9
  55. package/dist/protocol/index.js +8 -5
  56. package/dist/protocol/manifest/grants.d.ts +48 -0
  57. package/dist/protocol/manifest/grants.js +19 -0
  58. package/dist/protocol/manifest/manifest.d.ts +33 -10
  59. package/dist/protocol/manifest/manifest.js +11 -5
  60. package/dist/protocol/messages/hostToSandbox.d.ts +109 -87
  61. package/dist/protocol/messages/invalidHostMessage.d.ts +2 -0
  62. package/dist/protocol/messages/invalidHostMessage.js +2 -0
  63. package/dist/protocol/messages/invalidSandboxMessage.d.ts +2 -0
  64. package/dist/protocol/messages/invalidSandboxMessage.js +2 -0
  65. package/dist/protocol/messages/sandboxToHost.d.ts +104 -17
  66. package/dist/protocol/navigation/openExternalUrl.d.ts +2 -2
  67. package/dist/protocol/pages/bridgePage.d.ts +7 -6
  68. package/dist/protocol/pages/bridgePage.js +0 -1
  69. package/dist/protocol/pages/makeBridgePage.d.ts +3 -1
  70. package/dist/protocol/pages/messages/createPage.d.ts +103 -27
  71. package/dist/protocol/pages/messages/createPage.js +3 -1
  72. package/dist/protocol/pages/messages/getPage.d.ts +23 -19
  73. package/dist/protocol/pages/messages/openPage.d.ts +2 -2
  74. package/dist/protocol/pages/messages/updatePage.d.ts +30 -24
  75. package/dist/protocol/pages/pageAppearance.d.ts +36 -1
  76. package/dist/protocol/pages/pageAppearance.js +9 -0
  77. package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +0 -8
  78. package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +0 -4
  79. package/dist/protocol/pages/properties/bridgePagePropertyValue.js +0 -5
  80. package/dist/protocol/users/makeBridgeUser.d.ts +3 -1
  81. package/dist/protocol/users/messages/getUser.d.ts +2 -2
  82. package/dist/protocol/users/messages/listUsers.d.ts +2 -2
  83. package/dist/protocol/utils/errors.d.ts +6 -4
  84. package/dist/protocol/utils/errors.js +3 -3
  85. package/dist/protocol/utils/protocolVersion.d.ts +2 -1
  86. package/dist/protocol/utils/protocolVersion.js +3 -1
  87. package/dist/protocol/utils/readRequestId.d.ts +2 -0
  88. package/dist/protocol/utils/readRequestId.js +7 -0
  89. package/dist/users/getUser.d.ts.map +1 -1
  90. package/dist/users/getUser.js +2 -1
  91. package/dist/users/listUsers.d.ts.map +1 -1
  92. package/dist/users/listUsers.js +4 -2
  93. package/dist/utils/version.js +1 -1
  94. package/docs/data-sources.md +38 -34
  95. package/docs/errors.md +47 -5
  96. package/docs/grants.md +127 -0
  97. package/docs/pages.md +45 -32
  98. package/docs/users.md +2 -2
  99. package/package.json +1 -1
  100. package/src/bridge/SandboxBridge.ts +44 -188
  101. package/src/bridge/requests.ts +138 -0
  102. package/src/dataSources/bridge/resolveDataSourceQuery.ts +21 -1
  103. package/src/dataSources/createDataSourcePage.ts +5 -1
  104. package/src/dataSources/types.ts +3 -0
  105. package/src/index.ts +8 -4
  106. package/src/manifest/types.ts +1 -1
  107. package/src/navigation/openExternalUrl.ts +5 -1
  108. package/src/pages/bridge/getPageForDataSource.ts +5 -1
  109. package/src/pages/bridge/sendCreatePageRequest.ts +5 -1
  110. package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +0 -1
  111. package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -6
  112. package/src/pages/bridge/updatePage.ts +28 -8
  113. package/src/pages/createPage.ts +5 -1
  114. package/src/pages/openPage.ts +5 -1
  115. package/src/pages/types.ts +7 -5
  116. package/src/users/getUser.ts +5 -1
  117. package/src/users/listUsers.ts +9 -4
  118. package/dist/bridge/pendingRequests.d.ts +0 -14
  119. package/dist/bridge/pendingRequests.d.ts.map +0 -1
  120. package/dist/bridge/pendingRequests.js +0 -28
  121. package/dist/protocol/manifest/capabilities.d.ts +0 -37
  122. package/dist/protocol/manifest/capabilities.js +0 -13
  123. package/docs/capabilities.md +0 -111
  124. package/src/bridge/pendingRequests.ts +0 -28
@@ -1,111 +0,0 @@
1
- # Capabilities
2
-
3
- The block manifest's `capabilities` lists what a custom block needs to do. Notion asks each viewer
4
- to approve the declared capabilities before it loads the block.
5
-
6
- Hosts do not restrict bridge requests by capability yet. A request that the approved capabilities do
7
- not cover still runs. Declare what the block uses anyway, so viewers see it before approving.
8
-
9
- Each entry pairs a `capability` with a `resource`. The capability names what the block does, and the
10
- resource names what it acts on:
11
-
12
- ```json
13
- {
14
- "version": 1,
15
- "dataSources": {
16
- "tasks": { "name": "Tasks" }
17
- },
18
- "capabilities": [
19
- { "capability": "page", "resource": "data_source" },
20
- { "capability": "user.read", "resource": "workspace" }
21
- ]
22
- }
23
- ```
24
-
25
- `@notionhq/workers` 0.9 does not pass `capabilities` from `worker.customBlock()` into the block
26
- manifest yet.
27
-
28
- ## Vocabulary
29
-
30
- | Capability | Resource | Covers |
31
- | ----------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
32
- | `user.read` | `current_user` | `users.get` for the viewer. |
33
- | `user.read` | `workspace` | `users.get` for any user and `users.list`. |
34
- | `user.read_email` | `current_user` | The viewer's `person.email` in `users.get` results. |
35
- | `user.read_email` | `workspace` | Every user's `person.email` in `users.get` and `users.list` results. Requires `user.read` at `workspace`. |
36
- | `user` | any user resource | Shorthand for `user.read` and `user.read_email` on the same resource. |
37
- | `page.read` | `containing_page` | `pages.get` and `pages.open` for the page that contains the block. |
38
- | `page.read` | `data_source` | Queries of the block's bound data sources, plus `pages.get` and `pages.open` for their rows. |
39
- | `page.read` | `workspace` | Reads of any page or data source that the viewer can access. |
40
- | `page.insert` | `containing_page` | `pages.create` under the containing page. |
41
- | `page.insert` | `data_source` | `pages.create` in the block's bound data sources. |
42
- | `page.insert` | `workspace` | `pages.create` under any page or in any data source that the viewer can edit. |
43
- | `page.update` | `containing_page` | `page.updateById()` and `page.updateByKey()` for the containing page. |
44
- | `page.update` | `data_source` | `row.updateById()`, `row.updateByKey()`, `page.updateById()`, and `page.updateByKey()` for rows of the block's bound data sources. |
45
- | `page.update` | `workspace` | `page.updateById()` and `page.updateByKey()` for any page that the viewer can edit. |
46
- | `page.archive` | `containing_page` | Archiving or unarchiving the containing page. See [Archive](#archive). |
47
- | `page.archive` | `data_source` | Archiving or unarchiving rows of the block's bound data sources. |
48
- | `page.archive` | `workspace` | Archiving or unarchiving any page that the viewer can edit. |
49
- | `page` | any page resource | Shorthand for `page.read`, `page.insert`, `page.update`, and `page.archive` on the same resource. |
50
- | `network.fetch` | an HTTPS origin | Loading content from and connecting to that origin, such as `https://api.example.com`. See [Network access](#network-access). |
51
-
52
- For user capabilities, `workspace` is every member of the workspace. For page capabilities, it's
53
- every page the viewer can access. Either way it covers every narrower resource of the same
54
- capability. A `containing_page` resource applies to the page that the block instance sits on, so
55
- viewers approve it again after the block moves to another page. A `data_source` resource applies to
56
- each data source bound to the block instance, and viewers approve each data source separately. A
57
- bound data source that the viewer hasn't approved stays unbound for them. The `private` page
58
- resource is reserved and not accepted yet.
59
-
60
- Deploys reject unknown capabilities, unknown resources, and pairs that the table does not list.
61
-
62
- A block that declares `dataSources` must also declare a page capability on `data_source`, such as
63
- `{ capability: "page.read", resource: "data_source" }`. Otherwise the deploy fails.
64
-
65
- ## Archive
66
-
67
- `page.update` does not cover archiving or unarchiving a page. Declare `page.archive`, or the `page`
68
- shorthand, on the same resource.
69
-
70
- `page.archive` covers updates that set `is_archived`: `page.archive()`, `page.unarchive()`,
71
- `row.archive()`, `row.unarchive()`, and any update that passes `is_archived`. An update that sets
72
- `is_archived` and other fields needs both `page.archive` and `page.update`.
73
-
74
- `page.trash` is reserved for a future call that moves pages to Trash. Deploys do not accept it yet.
75
-
76
- ## Network access
77
-
78
- `network.fetch` takes a bare HTTPS origin as its resource and lets the block load content from and
79
- connect to that origin, for example
80
- `{ capability: "network.fetch", resource: "https://api.example.com" }`. It covers `fetch` and other
81
- connections, plus images, media, fonts, stylesheets, and frames loaded from the origin. An
82
- `https://*.example.com` resource covers subdomains. Deploys reject resources that are not bare HTTPS
83
- origins. Notion allows an approved origin only while it is also on the workspace's custom block
84
- network allowlist. The dev shell does not limit network access.
85
-
86
- The declared origins, written as a JSON array such as `["https://api.example.com"]`, can use at most
87
- 2,048 characters. Deploys reject longer lists. Combine origins that share a domain into one
88
- wildcard, such as `https://*.example.com`, to stay under the limit. The workspace allowlist has the
89
- same limit.
90
-
91
- ## Blocks without capabilities
92
-
93
- A manifest that omits `capabilities` loads without an approval step. Notion may require
94
- `capabilities` in a future release. An empty `capabilities` array declares nothing.
95
-
96
- ## Capability errors
97
-
98
- The protocol defines the `capability_not_granted` error code for requests that the approved
99
- capabilities do not cover. No host sends it yet. When a host does, the result will resolve with
100
- `status: "error"` and `isRetryable: false`. See [error handling](errors.md).
101
-
102
- ## Dev shell
103
-
104
- The dev shell does not ask for approval. It loads every block as if its capabilities were approved.
105
-
106
- ## Types
107
-
108
- - `CustomBlockCapabilityDeclaration`: one `{ capability, resource }` entry. Both fields are strings
109
- on the wire, so newer names do not break older SDKs.
110
- - `CustomBlockCapabilityName`: the capability names in the vocabulary table.
111
- - `CustomBlockCapabilityResourceName`: the resource names in the vocabulary table.
@@ -1,28 +0,0 @@
1
- /**
2
- * Tracks one-shot request/response pairs over the `postMessage` bridge. Each `allocate` reserves a
3
- * unique `requestId` and stores its resolver. `resolve` finds the pending resolver by `requestId`
4
- * and calls it, then removes the entry so the same `requestId` cannot be resolved twice.
5
- */
6
- export class PendingRequests<T> {
7
- private nextId = 1
8
- private readonly entries = new Map<string, (value: T) => void>()
9
-
10
- constructor(private readonly prefix: string) {}
11
-
12
- allocate(resolver: (value: T) => void): string {
13
- const requestId = `${this.prefix}-${this.nextId}`
14
- this.nextId += 1
15
- this.entries.set(requestId, resolver)
16
- return requestId
17
- }
18
-
19
- resolve(requestId: string, value: T): boolean {
20
- const resolver = this.entries.get(requestId)
21
- if (resolver === undefined) {
22
- return false
23
- }
24
- this.entries.delete(requestId)
25
- resolver(value)
26
- return true
27
- }
28
- }