@niscorp/moss 0.9.2 → 0.10.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 (108) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/DESIGN.md +58 -55
  3. package/DOCS.md +280 -170
  4. package/README.md +5 -5
  5. package/dist/{chunk-PVZMCEBX.cjs → chunk-3CKBKTXA.cjs} +2 -2
  6. package/dist/chunk-3CKBKTXA.cjs.map +1 -0
  7. package/dist/{chunk-FUJRIO4N.js → chunk-3PL4AH4I.js} +4 -4
  8. package/dist/{chunk-FUJRIO4N.js.map → chunk-3PL4AH4I.js.map} +1 -1
  9. package/dist/{chunk-QAHDSRPK.js → chunk-4URQHVYG.js} +2 -2
  10. package/dist/chunk-4URQHVYG.js.map +1 -0
  11. package/dist/{chunk-6ZWMC2OV.cjs → chunk-6ACVHHFK.cjs} +33 -30
  12. package/dist/chunk-6ACVHHFK.cjs.map +1 -0
  13. package/dist/{chunk-IUJ2TRNB.cjs → chunk-7MOEKAVC.cjs} +6 -6
  14. package/dist/{chunk-IUJ2TRNB.cjs.map → chunk-7MOEKAVC.cjs.map} +1 -1
  15. package/dist/{chunk-NCQBGK3E.cjs → chunk-BFA76AKR.cjs} +4 -4
  16. package/dist/chunk-BFA76AKR.cjs.map +1 -0
  17. package/dist/{chunk-T5BRTFKP.js → chunk-DSVRFAGX.js} +3 -3
  18. package/dist/{chunk-T5BRTFKP.js.map → chunk-DSVRFAGX.js.map} +1 -1
  19. package/dist/{chunk-IW3A2YIC.js → chunk-EYWD733E.js} +3 -3
  20. package/dist/{chunk-IW3A2YIC.js.map → chunk-EYWD733E.js.map} +1 -1
  21. package/dist/{chunk-IY5BOFLK.cjs → chunk-G4P3XEVM.cjs} +19 -19
  22. package/dist/chunk-G4P3XEVM.cjs.map +1 -0
  23. package/dist/{chunk-6QPTMKRE.cjs → chunk-HUP7CZ7X.cjs} +6 -6
  24. package/dist/{chunk-6QPTMKRE.cjs.map → chunk-HUP7CZ7X.cjs.map} +1 -1
  25. package/dist/{chunk-VKQPOZDJ.cjs → chunk-LTS4AM6T.cjs} +4 -4
  26. package/dist/chunk-LTS4AM6T.cjs.map +1 -0
  27. package/dist/{chunk-UTFOMFCH.js → chunk-MEHCZECW.js} +5 -5
  28. package/dist/chunk-MEHCZECW.js.map +1 -0
  29. package/dist/{chunk-WMIJU6ZZ.js → chunk-MYPK5YZR.js} +297 -206
  30. package/dist/chunk-MYPK5YZR.js.map +1 -0
  31. package/dist/{chunk-TKXYPO2Y.js → chunk-NUX5MH4I.js} +4 -4
  32. package/dist/chunk-NUX5MH4I.js.map +1 -0
  33. package/dist/{chunk-KVXP6OTW.cjs → chunk-UVY5ZPWW.cjs} +373 -282
  34. package/dist/chunk-UVY5ZPWW.cjs.map +1 -0
  35. package/dist/{chunk-5ZB7FZ2J.js → chunk-VYYDLGQ2.js} +29 -26
  36. package/dist/chunk-VYYDLGQ2.js.map +1 -0
  37. package/dist/{chunk-NRZ3Z2FF.js → chunk-WKZWSWOJ.js} +4 -4
  38. package/dist/chunk-WKZWSWOJ.js.map +1 -0
  39. package/dist/{chunk-KMZT6NVL.cjs → chunk-XH6TSWG4.cjs} +7 -7
  40. package/dist/{chunk-KMZT6NVL.cjs.map → chunk-XH6TSWG4.cjs.map} +1 -1
  41. package/dist/client.cjs +5 -5
  42. package/dist/client.js +2 -2
  43. package/dist/{document-deAs7Dre.d.cts → document-DvhT_HaJ.d.cts} +3 -2
  44. package/dist/{document-C3aS9uiW.d.ts → document-iKaRinZE.d.ts} +3 -2
  45. package/dist/{index-CSEo7Tys.d.ts → index-DWj3_0Zg.d.cts} +3 -0
  46. package/dist/{index-CSEo7Tys.d.cts → index-DWj3_0Zg.d.ts} +3 -0
  47. package/dist/index.cjs +16 -16
  48. package/dist/index.d.cts +4 -4
  49. package/dist/index.d.ts +4 -4
  50. package/dist/index.js +4 -4
  51. package/dist/integrations.cjs +27 -18
  52. package/dist/integrations.cjs.map +1 -1
  53. package/dist/integrations.d.cts +1 -1
  54. package/dist/integrations.d.ts +1 -1
  55. package/dist/integrations.js +25 -16
  56. package/dist/integrations.js.map +1 -1
  57. package/dist/node.cjs +9 -9
  58. package/dist/node.d.cts +2 -2
  59. package/dist/node.d.ts +2 -2
  60. package/dist/node.js +5 -5
  61. package/dist/protocol.cjs +5 -5
  62. package/dist/protocol.js +1 -1
  63. package/dist/terminal/dom/index.cjs +3 -3
  64. package/dist/terminal/dom/index.js +1 -1
  65. package/dist/terminal/dom/server.cjs +2 -2
  66. package/dist/terminal/dom/server.js +1 -1
  67. package/dist/terminal/index.cjs +3 -3
  68. package/dist/terminal/index.js +2 -2
  69. package/dist/terminal/ink/index.js.map +1 -1
  70. package/dist/terminal/react/index.cjs +9 -9
  71. package/dist/terminal/react/index.cjs.map +1 -1
  72. package/dist/terminal/react/index.js +4 -4
  73. package/dist/terminal/react/index.js.map +1 -1
  74. package/dist/terminal/react/server.cjs +4 -4
  75. package/dist/terminal/react/server.js +2 -2
  76. package/dist/terminal/tty/index.cjs +12 -12
  77. package/dist/terminal/tty/index.cjs.map +1 -1
  78. package/dist/terminal/tty/index.js +6 -6
  79. package/dist/terminal/tty/index.js.map +1 -1
  80. package/dist/terminal/vue/index.cjs +9 -9
  81. package/dist/terminal/vue/index.cjs.map +1 -1
  82. package/dist/terminal/vue/index.js +4 -4
  83. package/dist/terminal/vue/index.js.map +1 -1
  84. package/dist/terminal/vue/server.cjs +4 -4
  85. package/dist/terminal/vue/server.js +2 -2
  86. package/dist/tide.d.cts +1 -1
  87. package/dist/tide.d.ts +1 -1
  88. package/dist/unverified.cjs +4 -4
  89. package/dist/unverified.js +3 -3
  90. package/dist/vite.cjs +36 -10
  91. package/dist/vite.cjs.map +1 -1
  92. package/dist/vite.d.cts +2 -2
  93. package/dist/vite.d.ts +2 -2
  94. package/dist/vite.js +31 -5
  95. package/dist/vite.js.map +1 -1
  96. package/package.json +13 -13
  97. package/dist/chunk-5ZB7FZ2J.js.map +0 -1
  98. package/dist/chunk-6ZWMC2OV.cjs.map +0 -1
  99. package/dist/chunk-IY5BOFLK.cjs.map +0 -1
  100. package/dist/chunk-KVXP6OTW.cjs.map +0 -1
  101. package/dist/chunk-NCQBGK3E.cjs.map +0 -1
  102. package/dist/chunk-NRZ3Z2FF.js.map +0 -1
  103. package/dist/chunk-PVZMCEBX.cjs.map +0 -1
  104. package/dist/chunk-QAHDSRPK.js.map +0 -1
  105. package/dist/chunk-TKXYPO2Y.js.map +0 -1
  106. package/dist/chunk-UTFOMFCH.js.map +0 -1
  107. package/dist/chunk-VKQPOZDJ.cjs.map +0 -1
  108. package/dist/chunk-WMIJU6ZZ.js.map +0 -1
@@ -1,7 +1,8 @@
1
- import { emitterOf, spanClock } from './chunk-QAHDSRPK.js';
1
+ import { emitterOf, spanClock } from './chunk-4URQHVYG.js';
2
2
  import { generateKeyPairSync, sign, createPrivateKey, createPublicKey, createHash, randomBytes } from 'crypto';
3
3
  import { z } from 'zod';
4
4
  import { Hono } from 'hono';
5
+ import { normalizeRole } from '@niscorp/charter';
5
6
  import { ActionDefinitionSchema, paletteEntryOf } from '@niscorp/nova';
6
7
  import { isRecord } from '@niscorp/nova/reflect';
7
8
  import { StrataError, exceedsDepth, depthRefusal } from '@niscorp/strata';
@@ -222,8 +223,8 @@ var reachOf = (bundle, integrationId) => {
222
223
  const admit = (url, actionId) => {
223
224
  if (!url.startsWith(own)) return;
224
225
  const key = normalizePath(url);
225
- const held = reach[key] ??= [];
226
- if (!held.includes(actionId)) held.push(actionId);
226
+ const declaring = reach[key] ??= [];
227
+ if (!declaring.includes(actionId)) declaring.push(actionId);
227
228
  };
228
229
  for (const [actionId, action] of Object.entries(bundle.actions)) {
229
230
  for (const endpoint of Object.values(action.endpoints ?? {})) {
@@ -232,7 +233,7 @@ var reachOf = (bundle, integrationId) => {
232
233
  }
233
234
  return Object.fromEntries(Object.entries(reach).sort(([a], [b]) => a.localeCompare(b)));
234
235
  };
235
- var reachAdmits = (reach, path, held) => (reach[normalizePath(path)] ?? []).some((actionId) => held.has(actionId));
236
+ var reachAdmits = (reach, path, granted) => (reach[normalizePath(path)] ?? []).some((actionId) => granted.has(actionId));
236
237
  var reachDeclares = (reach, path) => reach[normalizePath(path)] !== void 0;
237
238
 
238
239
  // src/integrations/forward.ts
@@ -263,7 +264,16 @@ var createForwarder = (deps) => {
263
264
  return sent(url, () => call.request(assertion));
264
265
  };
265
266
  };
266
- var relayed = (response, otherwise, more = {}) => new Response(response.body, { status: response.status, headers: { "content-type": response.headers.get("content-type") ?? otherwise, ...more } });
267
+ var SANDBOX = "sandbox allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals allow-downloads allow-top-navigation";
268
+ var relayed = (response, otherwise, more = {}) => new Response(response.body, {
269
+ status: response.status,
270
+ headers: {
271
+ "content-type": response.headers.get("content-type") ?? otherwise,
272
+ "content-security-policy": SANDBOX,
273
+ "x-content-type-options": "nosniff",
274
+ ...more
275
+ }
276
+ });
267
277
  var HOOK_LIMIT = 240;
268
278
  var HOOK_WINDOW_MS = 6e4;
269
279
  var createHookLimit = () => {
@@ -284,8 +294,9 @@ var webhook = (deps, routes) => {
284
294
  const id = c.req.param("id");
285
295
  const here = new URL(c.req.url);
286
296
  const headers = new Headers(c.req.raw.headers);
287
- headers.delete("authorization");
297
+ for (const name of ["authorization", "cookie", "proxy-authorization", "x-operator-key"]) headers.delete(name);
288
298
  headers.delete("host");
299
+ for (const name of ["transfer-encoding", "keep-alive", "expect", "upgrade"]) headers.delete(name);
289
300
  const ended = await deps.forward({
290
301
  integration: id,
291
302
  admits: () => hookAllows(id, Date.now()),
@@ -314,7 +325,7 @@ var proxy = (deps, routes) => {
314
325
  request: async (assertion) => ({
315
326
  method: c.req.method,
316
327
  headers: { "content-type": "application/json", authorization: `Bearer ${assertion}` },
317
- ...c.req.method === "GET" ? {} : { body: await c.req.text() }
328
+ ...c.req.method === "GET" || c.req.method === "HEAD" ? {} : { body: await c.req.text() }
318
329
  })
319
330
  });
320
331
  if (ended.kind === "refused") return c.json({ message: ended.why === "uninstalled" ? "Not installed here." : "No such integration." }, 404);
@@ -520,7 +531,7 @@ var RegistrationRowSchema = z.object({ status: z.string(), key_hash: z.string().
520
531
  var WrittenRowSchema = z.looseObject({ key_hash: z.string().nullish() });
521
532
  var WrittenSchema = z.union([z.array(WrittenRowSchema), WrittenRowSchema.transform((row) => [row]), z.undefined().transform(() => [])]);
522
533
  var RequestedRowSchema = z.object({ requested_data: strings });
523
- var KeyHolderRowSchema = z.object({ id: z.string() });
534
+ var KeyOwnerRowSchema = z.object({ id: z.string() });
524
535
  var actionKey = { integration_id: z.string(), action_id: z.string() };
525
536
  var afterAction2 = (last) => ({
526
537
  after_integration: last?.integration_id ?? "",
@@ -556,7 +567,7 @@ var recordFailedImport2 = async (replay, id, url, error) => {
556
567
  };
557
568
  var registrationOf = async (replay, id) => {
558
569
  const row = RegistrationRowSchema.optional().parse(rowsOf(await replay("integrations/registration", { id }))[0]);
559
- return { approved: row?.status === "approved", holdsKey: typeof row?.key_hash === "string" && row.key_hash !== "" };
570
+ return { approved: row?.status === "approved", hasKey: typeof row?.key_hash === "string" && row.key_hash !== "" };
560
571
  };
561
572
  var importedRow = ({ id, url, bundle, extension }) => ({
562
573
  id,
@@ -592,7 +603,7 @@ var setBackToPending2 = async (replay, id, why) => {
592
603
  var removeIntegration = async (replay, id) => {
593
604
  await replay("integrations/remove", { id });
594
605
  };
595
- var integrationByKey = async (replay, key) => KeyHolderRowSchema.optional().parse(rowsOf(await replay("integrations/by-key", { key_hash: hashIntegrationKey(key) }))[0])?.id;
606
+ var integrationByKey = async (replay, key) => KeyOwnerRowSchema.optional().parse(rowsOf(await replay("integrations/by-key", { key_hash: hashIntegrationKey(key) }))[0])?.id;
596
607
  var listIntegrations = async (replay) => {
597
608
  const listed = await everyRow(ListedRowSchema, (after) => replay("integrations/list", { after: after?.id ?? "" }));
598
609
  const counted = await everyRow(ActionCountRowSchema, (after) => replay("integrations/action-counts", { after: after?.integration_id ?? "" }));
@@ -708,12 +719,12 @@ var register = (deps, routes) => {
708
719
  await recordFailedImport2(deps.replay, id, url, taken.error);
709
720
  return c.json(taken.answer, taken.status);
710
721
  }
711
- const { approved: wasApproved, holdsKey } = await registrationOf(deps.replay, id);
722
+ const { approved: wasApproved, hasKey } = await registrationOf(deps.replay, id);
712
723
  if (wasApproved) {
713
724
  const refusal = deps.refusalOf({ ...deps.actions(), ...taken.bundle.actions });
714
725
  if (refusal !== void 0) return c.json({ message: "Refused \u2014 the app would not serve this.", reasons: [`Error: ${refusal}`] }, 422);
715
726
  }
716
- const key = holdsKey ? void 0 : mintIntegrationKey();
727
+ const key = hasKey ? void 0 : mintIntegrationKey();
717
728
  const { keptKey } = await writeBundle2(deps.replay, {
718
729
  id,
719
730
  url,
@@ -798,10 +809,8 @@ var buildContract = (host, integrationId) => {
798
809
  const components = Object.keys(registered).sort().map((name) => paletteEntryOf(name, componentMetaOf(registered[name]?.meta)));
799
810
  const audiences = /* @__PURE__ */ new Set();
800
811
  for (const def of Object.values(host.charter)) {
801
- if (def === void 0 || Array.isArray(def)) continue;
802
- const selection = def.actions;
803
- const list2 = Array.isArray(selection) ? selection : selection?.allow ?? [];
804
- for (const entry of list2) {
812
+ if (Array.isArray(def) || def?.actions === void 0) continue;
813
+ for (const entry of normalizeRole(def, "actions").allow) {
805
814
  const parts = entry.split(".");
806
815
  if (parts[0] === "ext" && parts[1] !== void 0 && parts[1] !== "*") audiences.add(parts[1]);
807
816
  }