@botiverse/porthole 0.2.4 → 0.3.1

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 (85) hide show
  1. package/README.md +17 -11
  2. package/dist/check/check.d.ts +100 -0
  3. package/dist/check/check.js +247 -0
  4. package/dist/check/drivers.d.ts +43 -0
  5. package/dist/check/drivers.js +181 -0
  6. package/dist/check/index.d.ts +8 -0
  7. package/dist/check/index.js +8 -0
  8. package/dist/check/instrument.d.ts +71 -0
  9. package/dist/check/instrument.js +84 -0
  10. package/dist/check/lint.d.ts +21 -0
  11. package/dist/check/lint.js +131 -0
  12. package/dist/check/page-source.d.ts +2 -0
  13. package/dist/check/page-source.js +2 -0
  14. package/dist/check/page.d.ts +13 -0
  15. package/dist/check/page.js +170 -0
  16. package/dist/check/tools.d.ts +61 -0
  17. package/dist/check/tools.js +140 -0
  18. package/dist/conformance/host-kit.d.ts +26 -5
  19. package/dist/conformance/host-kit.js +46 -22
  20. package/dist/conformance/index.d.ts +1 -1
  21. package/dist/conformance/reporter.d.ts +14 -0
  22. package/dist/conformance/reporter.js +28 -0
  23. package/dist/displays/displays.d.ts +61 -0
  24. package/dist/displays/displays.js +113 -0
  25. package/dist/host/client.d.ts +110 -0
  26. package/dist/host/client.js +274 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.js +6 -0
  29. package/dist/node/index.d.ts +26 -1
  30. package/dist/node/index.js +91 -1
  31. package/dist/react/frame.d.ts +79 -3
  32. package/dist/react/frame.js +183 -42
  33. package/dist/react/index.d.ts +2 -1
  34. package/dist/react/index.js +1 -0
  35. package/dist/react/view.d.ts +54 -0
  36. package/dist/react/view.js +151 -0
  37. package/dist/server/bootstrap.d.ts +27 -0
  38. package/dist/server/bootstrap.js +63 -0
  39. package/dist/server/host.d.ts +77 -8
  40. package/dist/server/host.js +268 -11
  41. package/dist/server/index.d.ts +4 -2
  42. package/dist/server/index.js +3 -1
  43. package/dist/server/pages.d.ts +19 -0
  44. package/dist/server/pages.js +8 -0
  45. package/dist/server/proxy.d.ts +24 -0
  46. package/dist/server/proxy.js +67 -0
  47. package/dist/server/server.js +14 -1
  48. package/dist/server/types.d.ts +8 -0
  49. package/docs/ADOPTING.md +278 -108
  50. package/docs/DECISIONS.md +280 -0
  51. package/docs/DESIGN.md +84 -2
  52. package/examples/app.mjs +82 -78
  53. package/examples/conformance/page.spec.mjs +23 -0
  54. package/examples/conformance/playwright.config.mjs +3 -2
  55. package/examples/conformance/porthole.spec.mjs +6 -3
  56. package/examples/displays.mjs +21 -0
  57. package/examples/mcp/server.mjs +121 -0
  58. package/examples/node/server.mjs +16 -34
  59. package/examples/workers/worker.mjs +19 -7
  60. package/package.json +13 -1
  61. package/src/check/check.ts +386 -0
  62. package/src/check/drivers.ts +242 -0
  63. package/src/check/index.ts +22 -0
  64. package/src/check/instrument.ts +138 -0
  65. package/src/check/lint.ts +238 -0
  66. package/src/check/page-source.ts +19 -0
  67. package/src/check/page.ts +230 -0
  68. package/src/check/tools.ts +206 -0
  69. package/src/conformance/host-kit.ts +82 -27
  70. package/src/conformance/index.ts +1 -0
  71. package/src/conformance/reporter.ts +38 -0
  72. package/src/displays/displays.ts +191 -0
  73. package/src/host/client.ts +395 -0
  74. package/src/index.ts +25 -0
  75. package/src/node/index.ts +112 -2
  76. package/src/react/frame.tsx +271 -57
  77. package/src/react/index.ts +9 -0
  78. package/src/react/view.tsx +237 -0
  79. package/src/server/bootstrap.ts +97 -0
  80. package/src/server/host.ts +372 -18
  81. package/src/server/index.ts +11 -1
  82. package/src/server/pages.ts +28 -0
  83. package/src/server/proxy.ts +86 -0
  84. package/src/server/server.ts +26 -2
  85. package/src/server/types.ts +5 -0
@@ -251,7 +251,15 @@ export function createServer(options: ServerOptions): PortholeServer {
251
251
  if (!Number.isInteger(authorizeTtl) || authorizeTtl < 0 || authorizeTtl > 300) {
252
252
  throw new TypeError("authorize.ttlSeconds must be an integer from 0 to 300");
253
253
  }
254
- const answers = new Map<string, { readonly answer: AuthorizeAnswer; readonly until: number }>();
254
+ const answers = new Map<
255
+ string,
256
+ {
257
+ readonly answer: AuthorizeAnswer;
258
+ readonly until: number;
259
+ readonly scope: string;
260
+ readonly subject: string | null;
261
+ }
262
+ >();
255
263
 
256
264
  if (options.hostOrigins.length === 0) {
257
265
  throw new TypeError("hostOrigins must name the origins that embed content");
@@ -338,7 +346,12 @@ export function createServer(options: ServerOptions): PortholeServer {
338
346
  } catch {
339
347
  given = { allow: false };
340
348
  }
341
- answer = { answer: given, until: at + authorizeTtl * 1_000 };
349
+ answer = {
350
+ answer: given,
351
+ until: at + authorizeTtl * 1_000,
352
+ scope: access.instance.scope,
353
+ subject: access.subject ?? null,
354
+ };
342
355
  if (authorizeTtl > 0) {
343
356
  if (answers.size > 10_000) {
344
357
  answers.clear();
@@ -1047,6 +1060,17 @@ export function createServer(options: ServerOptions): PortholeServer {
1047
1060
  return { url: `${origin}${path}`, origin, reports: true };
1048
1061
  },
1049
1062
 
1063
+ forget(filter = {}) {
1064
+ for (const [key, each] of answers) {
1065
+ if (
1066
+ (filter.scope === undefined || each.scope === filter.scope) &&
1067
+ (filter.subject === undefined || each.subject === filter.subject)
1068
+ ) {
1069
+ answers.delete(key);
1070
+ }
1071
+ }
1072
+ },
1073
+
1050
1074
  urlOf(scope, path = "/") {
1051
1075
  if (!path.startsWith("/") || path.startsWith("//") || path.startsWith(PREFIX)) {
1052
1076
  throw new TypeError("A clean address's path starts with one / and isn't Porthole's own");
@@ -216,6 +216,11 @@ export interface PortholeServer {
216
216
  access(request: Request): Promise<Access | null>;
217
217
  /** The frame source every content origin matches (`https://*.example-usercontent.com`). */
218
218
  readonly contentSource: string;
219
+ /**
220
+ * Drops cached `authorize.check` answers (`ttlSeconds`): all, or a scope's, or a subject's, so a
221
+ * revocation holds at once (P072).
222
+ */
223
+ forget(filter?: { readonly scope?: string; readonly subject?: string }): void;
219
224
  /** A clean address on a scope's origin (P068): what a tab, a link, a bookmark opens. */
220
225
  urlOf(scope: string, path?: string): string;
221
226
  /** A redirect entry's state, signature checked; null for one this server didn't make. */