@botiverse/porthole 0.6.0 → 0.7.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 (145) hide show
  1. package/README.md +16 -0
  2. package/dist/bridge/bridge.d.ts +13 -0
  3. package/dist/bridge/bridge.js +200 -8
  4. package/dist/bridge/refusal.d.ts +5 -1
  5. package/dist/bridge/refusal.js +16 -0
  6. package/dist/bridge/types.d.ts +41 -4
  7. package/dist/check/check.d.ts +7 -0
  8. package/dist/check/check.js +1 -0
  9. package/dist/check/instrument.d.ts +3 -0
  10. package/dist/check/lint.js +4 -2
  11. package/dist/check/page-source.js +1 -1
  12. package/dist/check/page.js +14 -0
  13. package/dist/check/tools.js +2 -3
  14. package/dist/compile/policy.d.ts +19 -0
  15. package/dist/compile/policy.js +42 -0
  16. package/dist/config/capabilities.d.ts +62 -3
  17. package/dist/config/capabilities.js +20 -0
  18. package/dist/config/schema.d.ts +24 -0
  19. package/dist/config/validate.d.ts +1 -1
  20. package/dist/config/validate.js +66 -4
  21. package/dist/conformance/harness-source.js +1 -1
  22. package/dist/conformance/index.d.ts +1 -0
  23. package/dist/conformance/index.js +2 -0
  24. package/dist/conformance/runtime.d.ts +58 -0
  25. package/dist/conformance/runtime.js +314 -0
  26. package/dist/guide/gates.d.ts +3 -0
  27. package/dist/guide/gates.js +19 -0
  28. package/dist/guide/guide.d.ts +2 -0
  29. package/dist/guide/guide.js +34 -32
  30. package/dist/guide/limits.js +4 -4
  31. package/dist/guide/runtime.d.ts +13 -0
  32. package/dist/guide/runtime.js +202 -0
  33. package/dist/host/create-host.js +24 -0
  34. package/dist/host/locate.js +8 -0
  35. package/dist/host/locator.js +7 -0
  36. package/dist/host/types.d.ts +18 -0
  37. package/dist/index.d.ts +8 -2
  38. package/dist/index.js +9 -1
  39. package/dist/isolation/types.d.ts +8 -0
  40. package/dist/presets/presets.d.ts +6 -0
  41. package/dist/presets/presets.js +1 -0
  42. package/dist/protocol/runtime-calls.d.ts +28 -0
  43. package/dist/protocol/runtime-calls.js +113 -0
  44. package/dist/protocol/shell-adapter.js +48 -3
  45. package/dist/react/dialog.js +31 -0
  46. package/dist/react/frame.d.ts +13 -0
  47. package/dist/react/frame.js +6 -0
  48. package/dist/runtime/contract.d.ts +193 -0
  49. package/dist/runtime/contract.js +216 -0
  50. package/dist/runtime/db.d.ts +153 -0
  51. package/dist/runtime/db.js +398 -0
  52. package/dist/runtime/declaration.d.ts +86 -0
  53. package/dist/runtime/declaration.js +266 -0
  54. package/dist/runtime/levels.d.ts +33 -0
  55. package/dist/runtime/levels.js +41 -0
  56. package/dist/runtime/requests.d.ts +125 -0
  57. package/dist/runtime/requests.js +199 -0
  58. package/dist/runtime/segments.d.ts +8 -0
  59. package/dist/runtime/segments.js +14 -0
  60. package/dist/runtime/types.generated.d.ts +1 -0
  61. package/dist/runtime/types.generated.js +19 -0
  62. package/dist/server/files.d.ts +14 -1
  63. package/dist/server/files.js +97 -3
  64. package/dist/server/host.d.ts +6 -1
  65. package/dist/server/host.js +5 -0
  66. package/dist/server/index.d.ts +2 -1
  67. package/dist/server/index.js +1 -0
  68. package/dist/server/pseudonym.d.ts +9 -0
  69. package/dist/server/pseudonym.js +20 -0
  70. package/dist/server/server.d.ts +0 -5
  71. package/dist/server/server.js +214 -35
  72. package/dist/server/types.d.ts +69 -0
  73. package/dist/shell/document.d.ts +8 -0
  74. package/dist/shell/document.js +16 -2
  75. package/dist/shell/legacy.d.ts +21 -0
  76. package/dist/shell/legacy.js +63 -0
  77. package/dist/shell/plan.d.ts +17 -1
  78. package/dist/shell/plan.js +13 -2
  79. package/dist/shell/runtime.js +29 -42
  80. package/dist/shell/use.d.ts +15 -0
  81. package/dist/shell/use.js +235 -0
  82. package/docs/ADOPTING.md +91 -6
  83. package/docs/ARCHITECTURE.md +22 -3
  84. package/docs/DECISIONS.md +415 -6
  85. package/docs/DESIGN.md +66 -0
  86. package/package.json +3 -1
  87. package/src/bridge/bridge.ts +273 -12
  88. package/src/bridge/refusal.ts +16 -0
  89. package/src/bridge/types.ts +46 -4
  90. package/src/check/check.ts +8 -0
  91. package/src/check/instrument.ts +3 -0
  92. package/src/check/lint.ts +4 -2
  93. package/src/check/page.ts +14 -0
  94. package/src/check/tools.ts +2 -3
  95. package/src/compile/policy.ts +54 -0
  96. package/src/config/capabilities.ts +49 -2
  97. package/src/config/schema.ts +24 -0
  98. package/src/config/validate.ts +99 -4
  99. package/src/conformance/index.ts +7 -0
  100. package/src/conformance/runtime.ts +573 -0
  101. package/src/guide/gates.ts +25 -0
  102. package/src/guide/guide.ts +59 -53
  103. package/src/guide/limits.ts +4 -4
  104. package/src/guide/runtime.ts +244 -0
  105. package/src/host/create-host.ts +34 -0
  106. package/src/host/locate.ts +10 -0
  107. package/src/host/locator.ts +11 -0
  108. package/src/host/types.ts +18 -0
  109. package/src/index.ts +89 -0
  110. package/src/isolation/types.ts +8 -0
  111. package/src/presets/presets.ts +7 -0
  112. package/src/protocol/runtime-calls.ts +138 -0
  113. package/src/protocol/shell-adapter.ts +52 -3
  114. package/src/react/dialog.tsx +33 -0
  115. package/src/react/frame.tsx +19 -0
  116. package/src/runtime/contract.ts +305 -0
  117. package/src/runtime/db.ts +530 -0
  118. package/src/runtime/declaration.ts +378 -0
  119. package/src/runtime/levels.ts +69 -0
  120. package/src/runtime/requests.ts +339 -0
  121. package/src/runtime/segments.ts +17 -0
  122. package/src/runtime/types.generated.ts +19 -0
  123. package/src/server/files.ts +117 -4
  124. package/src/server/host.ts +12 -0
  125. package/src/server/index.ts +3 -0
  126. package/src/server/pseudonym.ts +21 -0
  127. package/src/server/server.ts +247 -37
  128. package/src/server/types.ts +68 -0
  129. package/src/shell/document.ts +21 -4
  130. package/src/shell/legacy.ts +64 -0
  131. package/src/shell/plan.ts +37 -3
  132. package/src/shell/runtime.ts +29 -42
  133. package/src/shell/use.ts +235 -0
  134. package/types/runtime/v1/artifact.d.ts +50 -0
  135. package/types/runtime/v1/assets.d.ts +43 -0
  136. package/types/runtime/v1/chat.d.ts +13 -0
  137. package/types/runtime/v1/clipboard.d.ts +14 -0
  138. package/types/runtime/v1/comments.d.ts +24 -0
  139. package/types/runtime/v1/context.d.ts +16 -0
  140. package/types/runtime/v1/data.d.ts +29 -0
  141. package/types/runtime/v1/db.d.ts +110 -0
  142. package/types/runtime/v1/downloads.d.ts +22 -0
  143. package/types/runtime/v1/links.d.ts +13 -0
  144. package/types/runtime/v1/porthole.d.ts +44 -0
  145. package/types/runtime/v1/user.d.ts +19 -0
@@ -0,0 +1,22 @@
1
+ // Porthole capability runtime, contract 1: downloads. Built in: never declare it.
2
+
3
+ /** A file to hand the person: its name, and its text or bytes. */
4
+ interface PortholeDownload {
5
+ /** A file name, no slashes: "report.csv". Its extension gives its type unless `type` says. */
6
+ readonly name: string;
7
+ readonly type?: string;
8
+ readonly text?: string;
9
+ readonly data?: Blob | ArrayBuffer | ArrayBufferView;
10
+ }
11
+
12
+ interface PortholeDownloads {
13
+ /**
14
+ * Hands the person a file to save (<a download> and script-driven saves don't work here).
15
+ * Call it from a click. Resolves true if the download started. Level: view.
16
+ */
17
+ save(file: PortholeDownload): Promise<boolean>;
18
+ }
19
+
20
+ interface PortholeCapabilities {
21
+ downloads: PortholeDownloads;
22
+ }
@@ -0,0 +1,13 @@
1
+ // Porthole capability runtime, contract 1: links. Built in: never declare it.
2
+
3
+ interface PortholeLinks {
4
+ /**
5
+ * Opens an http(s) link outside the page (a click on an <a href> does the same). Call it from
6
+ * a click. Resolves true if it opened. Level: view.
7
+ */
8
+ open(url: string): Promise<boolean>;
9
+ }
10
+
11
+ interface PortholeCapabilities {
12
+ links: PortholeLinks;
13
+ }
@@ -0,0 +1,44 @@
1
+ // Porthole capability runtime, contract 1: the call contract (how a page reaches any capability).
2
+
3
+ /**
4
+ * Why a call was refused: branch on it; show `message` (a sentence for the person) where the
5
+ * result would be. Never retry in a loop.
6
+ * - consent_required: the person hasn't allowed it yet.
7
+ * - denied: the person said no.
8
+ * - rate_limited: too many calls this minute.
9
+ * - not_allowed: not available here (some places show the page without it).
10
+ * - failed: the app tried and couldn't.
11
+ * - forbidden: this person may see the page but not do this (their level).
12
+ * - conflict: what you change moved since you read it: read it again, then write.
13
+ * - too_large: past a limit.
14
+ */
15
+ type PortholeErrorCode =
16
+ | "consent_required"
17
+ | "denied"
18
+ | "rate_limited"
19
+ | "not_allowed"
20
+ | "failed"
21
+ | "forbidden"
22
+ | "conflict"
23
+ | "too_large";
24
+
25
+ /** What every capability method rejects with. */
26
+ interface PortholeError extends Error {
27
+ readonly code: PortholeErrorCode;
28
+ }
29
+
30
+ /** Each capability's namespace, by the name `use` takes (each capability's own file adds its own). */
31
+ interface PortholeCapabilities {}
32
+
33
+ interface PortholeRuntime {
34
+ /**
35
+ * The capability's namespace, frozen; or null when it isn't there for this page: the app
36
+ * doesn't offer it, the page didn't declare it, or no app is showing the page (a tab, a
37
+ * preview). The reasons are indistinguishable: draw the page without it. `use` never rejects;
38
+ * permission problems come when you call a method (a rejected promise, `PortholeError`).
39
+ */
40
+ use<N extends keyof PortholeCapabilities>(name: N): Promise<PortholeCapabilities[N] | null>;
41
+ }
42
+
43
+ /** The page's one global. Nothing else is added to `window`. */
44
+ declare const porthole: PortholeRuntime;
@@ -0,0 +1,19 @@
1
+ // Porthole capability runtime, contract 1: user. Declare it: { user: {} }.
2
+
3
+ /** Who is viewing, as the app says. */
4
+ interface PortholeUserInfo {
5
+ /** The app's id for this person (whose data "data/users/me" is), or null if it gives none. */
6
+ readonly id: string | null;
7
+ readonly name: string | null;
8
+ /** What they may do here: view < interact < admin < owner. */
9
+ readonly level: "view" | "interact" | "admin" | "owner";
10
+ }
11
+
12
+ interface PortholeUser {
13
+ /** Level: view. */
14
+ get(): Promise<PortholeUserInfo>;
15
+ }
16
+
17
+ interface PortholeCapabilities {
18
+ user: PortholeUser;
19
+ }