@fairfox/polly 0.23.0 → 0.25.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 (116) hide show
  1. package/README.md +55 -1
  2. package/dist/cli/polly.js +21 -1
  3. package/dist/cli/polly.js.map +3 -3
  4. package/dist/src/actions/error.d.ts +26 -0
  5. package/dist/src/actions/event-delegation.d.ts +48 -0
  6. package/dist/src/actions/form.d.ts +72 -0
  7. package/dist/src/actions/index.d.ts +13 -0
  8. package/dist/src/actions/index.js +525 -0
  9. package/dist/src/actions/index.js.map +15 -0
  10. package/dist/src/actions/overlay.d.ts +26 -0
  11. package/dist/src/actions/registry.d.ts +25 -0
  12. package/dist/src/actions/store.d.ts +26 -0
  13. package/dist/src/actions/testing.d.ts +26 -0
  14. package/dist/src/background/index.js +26 -1
  15. package/dist/src/background/index.js.map +2 -2
  16. package/dist/src/background/message-router.js +26 -1
  17. package/dist/src/background/message-router.js.map +2 -2
  18. package/dist/src/client/index.js +27 -2
  19. package/dist/src/client/index.js.map +3 -3
  20. package/dist/src/elysia/index.js +27 -2
  21. package/dist/src/elysia/index.js.map +3 -3
  22. package/dist/src/elysia/peer-repo-plugin.d.ts +1 -1
  23. package/dist/src/index.js +26 -1
  24. package/dist/src/index.js.map +2 -2
  25. package/dist/src/mesh-node.d.ts +89 -0
  26. package/dist/src/mesh-node.js +619 -0
  27. package/dist/src/mesh-node.js.map +14 -0
  28. package/dist/src/mesh.d.ts +10 -0
  29. package/dist/src/mesh.js +951 -24
  30. package/dist/src/mesh.js.map +17 -9
  31. package/dist/src/peer.d.ts +1 -0
  32. package/dist/src/peer.js +130 -84
  33. package/dist/src/peer.js.map +11 -10
  34. package/dist/src/polly-ui/ActionForm.d.ts +21 -0
  35. package/dist/src/polly-ui/ActionInput.d.ts +41 -0
  36. package/dist/src/polly-ui/ConfirmDialog.d.ts +24 -0
  37. package/dist/src/polly-ui/Layout.d.ts +51 -0
  38. package/dist/src/polly-ui/Modal.d.ts +52 -0
  39. package/dist/src/polly-ui/OverlayRoot.d.ts +10 -0
  40. package/dist/src/polly-ui/TextInput.d.ts +31 -0
  41. package/dist/src/polly-ui/Toast.d.ts +19 -0
  42. package/dist/src/polly-ui/index.css +319 -0
  43. package/dist/src/polly-ui/index.d.ts +17 -0
  44. package/dist/src/polly-ui/index.js +953 -0
  45. package/dist/src/polly-ui/index.js.map +22 -0
  46. package/dist/src/polly-ui/internal/focus-trap.d.ts +10 -0
  47. package/dist/src/polly-ui/internal/input-base.d.ts +18 -0
  48. package/dist/src/polly-ui/internal/scroll-lock.d.ts +9 -0
  49. package/dist/src/polly-ui/styles.css +70 -0
  50. package/dist/src/polly-ui/theme.css +163 -0
  51. package/dist/src/shared/adapters/index.js +26 -1
  52. package/dist/src/shared/adapters/index.js.map +2 -2
  53. package/dist/src/shared/lib/blob-cache.d.ts +58 -0
  54. package/dist/src/shared/lib/blob-store-impl.d.ts +33 -0
  55. package/dist/src/shared/lib/blob-store.d.ts +87 -0
  56. package/dist/src/shared/lib/blob-transfer.d.ts +58 -0
  57. package/dist/src/shared/lib/context-helpers.js +26 -1
  58. package/dist/src/shared/lib/context-helpers.js.map +2 -2
  59. package/dist/src/shared/lib/crdt-specialised.d.ts +1 -1
  60. package/dist/src/shared/lib/crdt-state.d.ts +1 -1
  61. package/dist/src/shared/lib/errors.js +26 -1
  62. package/dist/src/shared/lib/errors.js.map +2 -2
  63. package/dist/src/shared/lib/keyring-storage.d.ts +57 -0
  64. package/dist/src/shared/lib/mesh-client.d.ts +91 -0
  65. package/dist/src/shared/lib/mesh-network-adapter.d.ts +1 -1
  66. package/dist/src/shared/lib/mesh-signaling-client.d.ts +6 -0
  67. package/dist/src/shared/lib/mesh-state.d.ts +1 -1
  68. package/dist/src/shared/lib/mesh-webrtc-adapter.d.ts +20 -1
  69. package/dist/src/shared/lib/message-bus.js +26 -1
  70. package/dist/src/shared/lib/message-bus.js.map +2 -2
  71. package/dist/src/shared/lib/peer-relay-adapter.d.ts +1 -1
  72. package/dist/src/shared/lib/peer-repo-server.d.ts +1 -1
  73. package/dist/src/shared/lib/peer-state.d.ts +1 -1
  74. package/dist/src/shared/lib/resource.js +26 -1
  75. package/dist/src/shared/lib/resource.js.map +2 -2
  76. package/dist/src/shared/lib/state.js +26 -1
  77. package/dist/src/shared/lib/state.js.map +2 -2
  78. package/dist/src/shared/lib/test-helpers.js +26 -1
  79. package/dist/src/shared/lib/test-helpers.js.map +2 -2
  80. package/dist/src/shared/lib/wasm-init.d.ts +17 -0
  81. package/dist/src/shared/state/app-state.js +26 -1
  82. package/dist/src/shared/state/app-state.js.map +2 -2
  83. package/dist/src/shared/types/messages.js +26 -1
  84. package/dist/src/shared/types/messages.js.map +2 -2
  85. package/dist/tools/quality/src/cli.js +647 -28
  86. package/dist/tools/quality/src/cli.js.map +11 -5
  87. package/dist/tools/quality/src/css/check-layout.d.ts +19 -0
  88. package/dist/tools/quality/src/css/check-quality.d.ts +24 -0
  89. package/dist/tools/quality/src/css/check-unused.d.ts +20 -0
  90. package/dist/tools/quality/src/css/check-vars.d.ts +22 -0
  91. package/dist/tools/quality/src/css/shared.d.ts +33 -0
  92. package/dist/tools/quality/src/index.d.ts +37 -0
  93. package/dist/tools/quality/src/index.js +735 -0
  94. package/dist/tools/quality/src/index.js.map +16 -0
  95. package/dist/tools/quality/src/logger.d.ts +26 -0
  96. package/dist/tools/quality/src/no-as-casting.d.ts +44 -0
  97. package/dist/tools/test/src/adapters/index.js +26 -1
  98. package/dist/tools/test/src/adapters/index.js.map +2 -2
  99. package/dist/tools/test/src/browser/index.js +26 -1
  100. package/dist/tools/test/src/browser/index.js.map +2 -2
  101. package/dist/tools/test/src/browser/run.js +238 -0
  102. package/dist/tools/test/src/browser/run.js.map +11 -0
  103. package/dist/tools/test/src/index.js +26 -1
  104. package/dist/tools/test/src/index.js.map +2 -2
  105. package/dist/tools/test/src/test-utils.js +26 -1
  106. package/dist/tools/test/src/test-utils.js.map +2 -2
  107. package/dist/tools/test/src/visual/compare.d.ts +23 -0
  108. package/dist/tools/test/src/visual/harness.d.ts +53 -0
  109. package/dist/tools/test/src/visual/index.d.ts +12 -0
  110. package/dist/tools/test/src/visual/index.js +13968 -0
  111. package/dist/tools/test/src/visual/index.js.map +41 -0
  112. package/dist/tools/verify/src/cli.js +3 -3
  113. package/dist/tools/verify/src/cli.js.map +1 -1
  114. package/dist/tools/verify/src/config.js +26 -1
  115. package/dist/tools/verify/src/config.js.map +2 -2
  116. package/package.json +42 -3
@@ -11,6 +11,7 @@
11
11
  * import { $peerState, configurePeerState } from "@fairfox/polly/peer";
12
12
  * ```
13
13
  */
14
+ import "./shared/lib/wasm-init";
14
15
  export type { CounterDoc, CrdtCounterOptions, CrdtListOptions, CrdtTextOptions, ListDoc, SpecialisedPrimitive, TextDoc, } from "./shared/lib/crdt-specialised";
15
16
  export { $crdtCounter, $crdtList, $crdtText } from "./shared/lib/crdt-specialised";
16
17
  export type { CrdtPrimitive, CrdtStateOptions } from "./shared/lib/crdt-state";
package/dist/src/peer.js CHANGED
@@ -1,3 +1,5 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
1
3
  var __defProp = Object.defineProperty;
2
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
3
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,6 +7,28 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  function __accessProp(key) {
6
8
  return this[key];
7
9
  }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
8
32
  var __toCommonJS = (from) => {
9
33
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
34
  if (entry)
@@ -22,6 +46,7 @@ var __toCommonJS = (from) => {
22
46
  return entry;
23
47
  };
24
48
  var __moduleCache;
49
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
25
50
  var __returnValue = (v) => v;
26
51
  function __exportSetter(name, newValue) {
27
52
  this[name] = __returnValue.bind(null, newValue);
@@ -44,8 +69,107 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
44
69
  throw Error('Dynamic require of "' + x + '" is not supported');
45
70
  });
46
71
 
72
+ // src/shared/lib/encryption.ts
73
+ var exports_encryption = {};
74
+ __export(exports_encryption, {
75
+ sealEnvelope: () => sealEnvelope,
76
+ openEnvelope: () => openEnvelope,
77
+ generateDocumentKey: () => generateDocumentKey,
78
+ encrypt: () => encrypt,
79
+ encodeEncryptedEnvelope: () => encodeEncryptedEnvelope,
80
+ decryptOrThrow: () => decryptOrThrow,
81
+ decrypt: () => decrypt,
82
+ decodeEncryptedEnvelope: () => decodeEncryptedEnvelope,
83
+ TAG_BYTES: () => TAG_BYTES,
84
+ NONCE_BYTES: () => NONCE_BYTES,
85
+ KEY_BYTES: () => KEY_BYTES,
86
+ EncryptionError: () => EncryptionError
87
+ });
88
+ import nacl from "tweetnacl";
89
+ function generateDocumentKey() {
90
+ return nacl.randomBytes(KEY_BYTES);
91
+ }
92
+ function encrypt(payload, key) {
93
+ if (key.length !== KEY_BYTES) {
94
+ throw new EncryptionError(`secretbox key must be ${KEY_BYTES} bytes, got ${key.length}.`, "invalid-key-length");
95
+ }
96
+ const nonce = nacl.randomBytes(NONCE_BYTES);
97
+ const ciphertext = nacl.secretbox(payload, nonce, key);
98
+ const out = new Uint8Array(NONCE_BYTES + ciphertext.length);
99
+ out.set(nonce, 0);
100
+ out.set(ciphertext, NONCE_BYTES);
101
+ return out;
102
+ }
103
+ function decrypt(sealed, key) {
104
+ if (key.length !== KEY_BYTES) {
105
+ throw new EncryptionError(`secretbox key must be ${KEY_BYTES} bytes, got ${key.length}.`, "invalid-key-length");
106
+ }
107
+ if (sealed.length < NONCE_BYTES + TAG_BYTES) {
108
+ return;
109
+ }
110
+ const nonce = sealed.subarray(0, NONCE_BYTES);
111
+ const ciphertext = sealed.subarray(NONCE_BYTES);
112
+ const opened = nacl.secretbox.open(ciphertext, nonce, key);
113
+ return opened ?? undefined;
114
+ }
115
+ function decryptOrThrow(sealed, key) {
116
+ const opened = decrypt(sealed, key);
117
+ if (!opened) {
118
+ throw new EncryptionError(`Failed to decrypt sealed blob: wrong key, malformed input, or tampered ciphertext.`, "decrypt-failed");
119
+ }
120
+ return opened;
121
+ }
122
+ function sealEnvelope(payload, documentId, key) {
123
+ return {
124
+ documentId,
125
+ sealed: encrypt(payload, key)
126
+ };
127
+ }
128
+ function openEnvelope(envelope, key) {
129
+ return decryptOrThrow(envelope.sealed, key);
130
+ }
131
+ function encodeEncryptedEnvelope(envelope) {
132
+ const idBytes = new TextEncoder().encode(envelope.documentId);
133
+ const out = new Uint8Array(4 + idBytes.length + envelope.sealed.length);
134
+ const view = new DataView(out.buffer);
135
+ view.setUint32(0, idBytes.length, false);
136
+ out.set(idBytes, 4);
137
+ out.set(envelope.sealed, 4 + idBytes.length);
138
+ return out;
139
+ }
140
+ function decodeEncryptedEnvelope(bytes) {
141
+ if (bytes.length < 4) {
142
+ throw new EncryptionError(`Encrypted envelope too short: ${bytes.length} bytes.`, "envelope-malformed");
143
+ }
144
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
145
+ const idLen = view.getUint32(0, false);
146
+ if (bytes.length < 4 + idLen) {
147
+ throw new EncryptionError(`Encrypted envelope truncated: declared id length ${idLen}, total ${bytes.length}.`, "envelope-malformed");
148
+ }
149
+ const documentId = new TextDecoder().decode(bytes.subarray(4, 4 + idLen));
150
+ const sealed = bytes.slice(4 + idLen);
151
+ return { documentId, sealed };
152
+ }
153
+ var KEY_BYTES = 32, NONCE_BYTES = 24, TAG_BYTES = 16, EncryptionError;
154
+ var init_encryption = __esm(() => {
155
+ EncryptionError = class EncryptionError extends Error {
156
+ code;
157
+ constructor(message, code) {
158
+ super(message);
159
+ this.name = "EncryptionError";
160
+ this.code = code;
161
+ }
162
+ };
163
+ });
164
+
165
+ // src/shared/lib/wasm-init.ts
166
+ import wasmPath from "@automerge/automerge/automerge.wasm";
167
+ import { initializeWasm } from "@automerge/automerge-repo/slim";
168
+ var wasmUrl = new URL(wasmPath, import.meta.url).href;
169
+ await initializeWasm(wasmUrl);
170
+
47
171
  // src/shared/lib/crdt-specialised.ts
48
- import { Counter, updateText } from "@automerge/automerge-repo";
172
+ import { Counter, updateText } from "@automerge/automerge-repo/slim";
49
173
  import { effect, signal } from "@preact/signals";
50
174
 
51
175
  // src/shared/lib/migrate-primitive.ts
@@ -418,93 +542,15 @@ function applyTopLevel(doc, value) {
418
542
  }
419
543
  }
420
544
  // src/shared/lib/peer-relay-adapter.ts
421
- import { Repo } from "@automerge/automerge-repo";
545
+ import { Repo } from "@automerge/automerge-repo/slim";
422
546
  import { WebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket";
423
547
  import { signal as signal3 } from "@preact/signals";
424
548
 
425
549
  // src/shared/lib/mesh-network-adapter.ts
550
+ init_encryption();
426
551
  import {
427
552
  NetworkAdapter
428
- } from "@automerge/automerge-repo";
429
-
430
- // src/shared/lib/encryption.ts
431
- import nacl from "tweetnacl";
432
- var KEY_BYTES = 32;
433
- var NONCE_BYTES = 24;
434
- var TAG_BYTES = 16;
435
-
436
- class EncryptionError extends Error {
437
- code;
438
- constructor(message, code) {
439
- super(message);
440
- this.name = "EncryptionError";
441
- this.code = code;
442
- }
443
- }
444
- function generateDocumentKey() {
445
- return nacl.randomBytes(KEY_BYTES);
446
- }
447
- function encrypt(payload, key) {
448
- if (key.length !== KEY_BYTES) {
449
- throw new EncryptionError(`secretbox key must be ${KEY_BYTES} bytes, got ${key.length}.`, "invalid-key-length");
450
- }
451
- const nonce = nacl.randomBytes(NONCE_BYTES);
452
- const ciphertext = nacl.secretbox(payload, nonce, key);
453
- const out = new Uint8Array(NONCE_BYTES + ciphertext.length);
454
- out.set(nonce, 0);
455
- out.set(ciphertext, NONCE_BYTES);
456
- return out;
457
- }
458
- function decrypt(sealed, key) {
459
- if (key.length !== KEY_BYTES) {
460
- throw new EncryptionError(`secretbox key must be ${KEY_BYTES} bytes, got ${key.length}.`, "invalid-key-length");
461
- }
462
- if (sealed.length < NONCE_BYTES + TAG_BYTES) {
463
- return;
464
- }
465
- const nonce = sealed.subarray(0, NONCE_BYTES);
466
- const ciphertext = sealed.subarray(NONCE_BYTES);
467
- const opened = nacl.secretbox.open(ciphertext, nonce, key);
468
- return opened ?? undefined;
469
- }
470
- function decryptOrThrow(sealed, key) {
471
- const opened = decrypt(sealed, key);
472
- if (!opened) {
473
- throw new EncryptionError(`Failed to decrypt sealed blob: wrong key, malformed input, or tampered ciphertext.`, "decrypt-failed");
474
- }
475
- return opened;
476
- }
477
- function sealEnvelope(payload, documentId, key) {
478
- return {
479
- documentId,
480
- sealed: encrypt(payload, key)
481
- };
482
- }
483
- function openEnvelope(envelope, key) {
484
- return decryptOrThrow(envelope.sealed, key);
485
- }
486
- function encodeEncryptedEnvelope(envelope) {
487
- const idBytes = new TextEncoder().encode(envelope.documentId);
488
- const out = new Uint8Array(4 + idBytes.length + envelope.sealed.length);
489
- const view = new DataView(out.buffer);
490
- view.setUint32(0, idBytes.length, false);
491
- out.set(idBytes, 4);
492
- out.set(envelope.sealed, 4 + idBytes.length);
493
- return out;
494
- }
495
- function decodeEncryptedEnvelope(bytes) {
496
- if (bytes.length < 4) {
497
- throw new EncryptionError(`Encrypted envelope too short: ${bytes.length} bytes.`, "envelope-malformed");
498
- }
499
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
500
- const idLen = view.getUint32(0, false);
501
- if (bytes.length < 4 + idLen) {
502
- throw new EncryptionError(`Encrypted envelope truncated: declared id length ${idLen}, total ${bytes.length}.`, "envelope-malformed");
503
- }
504
- const documentId = new TextDecoder().decode(bytes.subarray(4, 4 + idLen));
505
- const sealed = bytes.slice(4 + idLen);
506
- return { documentId, sealed };
507
- }
553
+ } from "@automerge/automerge-repo/slim";
508
554
 
509
555
  // src/shared/lib/signing.ts
510
556
  import nacl2 from "tweetnacl";
@@ -771,7 +817,7 @@ function createPeerStateClient(options) {
771
817
  };
772
818
  }
773
819
  // src/shared/lib/peer-repo-server.ts
774
- import { Repo as Repo2 } from "@automerge/automerge-repo";
820
+ import { Repo as Repo2 } from "@automerge/automerge-repo/slim";
775
821
  import { WebSocketServerAdapter } from "@automerge/automerge-repo-network-websocket";
776
822
  import { NodeFSStorageAdapter } from "@automerge/automerge-repo-storage-nodefs";
777
823
  import * as ws from "ws";
@@ -927,4 +973,4 @@ export {
927
973
  $crdtCounter
928
974
  };
929
975
 
930
- //# debugId=5E1D406403AE952E64756E2164756E21
976
+ //# debugId=76261FFA861B865364756E2164756E21