@peers-app/peers-sdk 0.14.0 → 0.15.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 (210) hide show
  1. package/dist/context/data-context.d.ts +4 -4
  2. package/dist/context/data-context.js +1 -1
  3. package/dist/context/index.d.ts +3 -3
  4. package/dist/context/index.js +4 -0
  5. package/dist/context/user-context-singleton.js +13 -14
  6. package/dist/context/user-context.d.ts +4 -4
  7. package/dist/context/user-context.js +48 -31
  8. package/dist/data/assistants.d.ts +1 -1
  9. package/dist/data/assistants.js +35 -24
  10. package/dist/data/change-tracking.d.ts +8 -8
  11. package/dist/data/change-tracking.js +45 -39
  12. package/dist/data/channels.js +5 -5
  13. package/dist/data/data-locks.d.ts +2 -2
  14. package/dist/data/data-locks.js +21 -23
  15. package/dist/data/data-locks.test.js +73 -75
  16. package/dist/data/device-sync-info.d.ts +1 -1
  17. package/dist/data/device-sync-info.js +4 -4
  18. package/dist/data/devices.d.ts +1 -1
  19. package/dist/data/devices.js +9 -12
  20. package/dist/data/embeddings.js +14 -11
  21. package/dist/data/files/file-read-stream.d.ts +2 -2
  22. package/dist/data/files/file-read-stream.js +23 -14
  23. package/dist/data/files/file-write-stream.d.ts +2 -2
  24. package/dist/data/files/file-write-stream.js +8 -8
  25. package/dist/data/files/file.types.d.ts +2 -2
  26. package/dist/data/files/file.types.js +17 -11
  27. package/dist/data/files/files.d.ts +6 -6
  28. package/dist/data/files/files.js +17 -19
  29. package/dist/data/files/files.test.js +213 -214
  30. package/dist/data/files/index.d.ts +4 -4
  31. package/dist/data/files/index.js +4 -4
  32. package/dist/data/group-member-roles.js +2 -2
  33. package/dist/data/group-members.d.ts +5 -5
  34. package/dist/data/group-members.js +27 -18
  35. package/dist/data/group-members.test.js +73 -73
  36. package/dist/data/group-permissions.d.ts +3 -3
  37. package/dist/data/group-permissions.js +13 -11
  38. package/dist/data/group-share.d.ts +2 -2
  39. package/dist/data/group-share.js +29 -24
  40. package/dist/data/groups.d.ts +4 -4
  41. package/dist/data/groups.js +27 -19
  42. package/dist/data/groups.test.js +44 -44
  43. package/dist/data/index.d.ts +6 -6
  44. package/dist/data/index.js +6 -6
  45. package/dist/data/knowledge/peer-types.js +9 -9
  46. package/dist/data/messages.d.ts +5 -5
  47. package/dist/data/messages.js +43 -30
  48. package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
  49. package/dist/data/orm/client-proxy.data-source.js +10 -12
  50. package/dist/data/orm/cursor.d.ts +1 -1
  51. package/dist/data/orm/cursor.js +2 -2
  52. package/dist/data/orm/cursor.test.js +92 -93
  53. package/dist/data/orm/data-query.d.ts +3 -3
  54. package/dist/data/orm/data-query.js +24 -18
  55. package/dist/data/orm/data-query.mongo.d.ts +1 -1
  56. package/dist/data/orm/data-query.mongo.js +49 -51
  57. package/dist/data/orm/data-query.mongo.test.js +173 -204
  58. package/dist/data/orm/data-query.sqlite.d.ts +1 -1
  59. package/dist/data/orm/data-query.sqlite.js +84 -73
  60. package/dist/data/orm/data-query.sqlite.test.js +164 -176
  61. package/dist/data/orm/data-query.test.js +216 -224
  62. package/dist/data/orm/decorators.js +3 -3
  63. package/dist/data/orm/dependency-injection.test.js +53 -56
  64. package/dist/data/orm/doc.d.ts +4 -4
  65. package/dist/data/orm/doc.js +17 -21
  66. package/dist/data/orm/event-registry.d.ts +1 -1
  67. package/dist/data/orm/event-registry.test.js +16 -16
  68. package/dist/data/orm/factory.d.ts +2 -2
  69. package/dist/data/orm/factory.js +33 -33
  70. package/dist/data/orm/index.d.ts +10 -10
  71. package/dist/data/orm/index.js +10 -10
  72. package/dist/data/orm/multi-cursors.d.ts +1 -1
  73. package/dist/data/orm/multi-cursors.js +6 -6
  74. package/dist/data/orm/multi-cursors.test.js +152 -144
  75. package/dist/data/orm/sql.data-source.d.ts +7 -7
  76. package/dist/data/orm/sql.data-source.js +88 -93
  77. package/dist/data/orm/sql.data-source.test.js +109 -101
  78. package/dist/data/orm/subscribable.data-source.d.ts +4 -4
  79. package/dist/data/orm/subscribable.data-source.js +5 -5
  80. package/dist/data/orm/table-container-events.test.js +34 -26
  81. package/dist/data/orm/table-container.d.ts +6 -6
  82. package/dist/data/orm/table-container.js +33 -21
  83. package/dist/data/orm/table-container.test.js +64 -53
  84. package/dist/data/orm/table-definitions.system.d.ts +3 -3
  85. package/dist/data/orm/table-definitions.system.js +3 -3
  86. package/dist/data/orm/table-definitions.type.d.ts +5 -5
  87. package/dist/data/orm/table-dependencies.d.ts +2 -2
  88. package/dist/data/orm/table.d.ts +5 -5
  89. package/dist/data/orm/table.event-source.test.js +105 -115
  90. package/dist/data/orm/table.js +35 -34
  91. package/dist/data/orm/types.d.ts +3 -3
  92. package/dist/data/orm/types.js +26 -25
  93. package/dist/data/orm/types.test.js +166 -92
  94. package/dist/data/package-permissions.d.ts +1 -1
  95. package/dist/data/package-permissions.js +2 -2
  96. package/dist/data/package-version-permissions.d.ts +1 -1
  97. package/dist/data/package-version-permissions.js +2 -2
  98. package/dist/data/package-versions.d.ts +9 -9
  99. package/dist/data/package-versions.js +47 -33
  100. package/dist/data/packages.d.ts +2 -2
  101. package/dist/data/packages.js +36 -18
  102. package/dist/data/packages.utils.d.ts +2 -2
  103. package/dist/data/packages.utils.js +4 -4
  104. package/dist/data/persistent-vars.d.ts +15 -15
  105. package/dist/data/persistent-vars.js +165 -154
  106. package/dist/data/table-definitions-table.d.ts +5 -5
  107. package/dist/data/table-definitions-table.js +13 -12
  108. package/dist/data/tool-tests.js +6 -6
  109. package/dist/data/tools.js +29 -19
  110. package/dist/data/user-permissions.d.ts +1 -1
  111. package/dist/data/user-permissions.js +5 -5
  112. package/dist/data/user-permissions.test.js +90 -88
  113. package/dist/data/user-trust-levels.js +10 -10
  114. package/dist/data/users.d.ts +4 -4
  115. package/dist/data/users.js +16 -15
  116. package/dist/data/voice-messages.d.ts +2 -2
  117. package/dist/data/voice-messages.js +13 -13
  118. package/dist/data/welcome-modal.pvar.js +3 -1
  119. package/dist/data/workflow-logs.js +26 -18
  120. package/dist/data/workflow-runs.d.ts +6 -6
  121. package/dist/data/workflow-runs.js +70 -44
  122. package/dist/data/workflows.d.ts +2 -2
  123. package/dist/data/workflows.js +7 -9
  124. package/dist/device/binary-peer-connection-v2.d.ts +7 -7
  125. package/dist/device/binary-peer-connection-v2.js +32 -28
  126. package/dist/device/binary-peer-connection-v2.test.js +80 -67
  127. package/dist/device/binary-peer-connection.d.ts +7 -7
  128. package/dist/device/binary-peer-connection.js +29 -28
  129. package/dist/device/binary-peer-connection.test.js +35 -31
  130. package/dist/device/connection.d.ts +5 -5
  131. package/dist/device/connection.js +59 -48
  132. package/dist/device/connection.test.js +74 -68
  133. package/dist/device/device-election.d.ts +2 -2
  134. package/dist/device/device-election.js +25 -20
  135. package/dist/device/device-election.test.js +35 -36
  136. package/dist/device/device.d.ts +2 -2
  137. package/dist/device/device.js +10 -4
  138. package/dist/device/device.test.js +16 -17
  139. package/dist/device/get-trust-level-fn.d.ts +2 -2
  140. package/dist/device/get-trust-level-fn.js +22 -11
  141. package/dist/device/get-trust-level-fn.test.js +58 -58
  142. package/dist/device/socket-io-binary-peer.d.ts +1 -1
  143. package/dist/device/socket-io-binary-peer.js +16 -13
  144. package/dist/device/socket.type.d.ts +2 -2
  145. package/dist/device/streamed-socket.d.ts +2 -2
  146. package/dist/device/streamed-socket.js +8 -8
  147. package/dist/device/streamed-socket.test.js +40 -40
  148. package/dist/device/tx-encoding.test.js +77 -77
  149. package/dist/events.d.ts +1 -1
  150. package/dist/events.js +5 -2
  151. package/dist/group-invite/group-invite.js +110 -19
  152. package/dist/group-invite/group-invite.pvars.d.ts +2 -2
  153. package/dist/group-invite/group-invite.pvars.js +21 -13
  154. package/dist/group-invite/group-invite.types.d.ts +1 -1
  155. package/dist/group-invite/index.d.ts +3 -3
  156. package/dist/group-invite/index.js +1 -1
  157. package/dist/index.d.ts +25 -24
  158. package/dist/index.js +30 -25
  159. package/dist/keys.d.ts +3 -3
  160. package/dist/keys.js +31 -30
  161. package/dist/keys.test.js +69 -61
  162. package/dist/logging/console-logger.d.ts +1 -1
  163. package/dist/logging/console-logger.js +35 -40
  164. package/dist/logging/console-logger.test.js +115 -115
  165. package/dist/logging/console-logs.table.d.ts +3 -3
  166. package/dist/logging/console-logs.table.js +28 -23
  167. package/dist/mentions.js +16 -12
  168. package/dist/observable.d.ts +2 -2
  169. package/dist/observable.js +15 -9
  170. package/dist/observable.test.js +47 -47
  171. package/dist/package-loader/get-require.js +3 -4
  172. package/dist/package-loader/package-loader.d.ts +2 -2
  173. package/dist/package-loader/package-loader.js +52 -34
  174. package/dist/peers-ui/peers-ui.d.ts +2 -2
  175. package/dist/peers-ui/peers-ui.js +2 -4
  176. package/dist/peers-ui/peers-ui.types.d.ts +3 -3
  177. package/dist/peers-ui/peers-ui.types.js +0 -1
  178. package/dist/rpc-types.d.ts +61 -59
  179. package/dist/rpc-types.js +61 -55
  180. package/dist/serial-json.d.ts +1 -1
  181. package/dist/serial-json.js +50 -43
  182. package/dist/serial-json.test.js +22 -22
  183. package/dist/system-ids.js +8 -8
  184. package/dist/tools/index.d.ts +1 -1
  185. package/dist/tools/tools-factory.d.ts +1 -1
  186. package/dist/tools/tools-factory.js +2 -2
  187. package/dist/types/assistant-runner-args.d.ts +3 -3
  188. package/dist/types/peer-device.d.ts +1 -1
  189. package/dist/types/peers-package.d.ts +3 -3
  190. package/dist/types/workflow-logger.d.ts +1 -1
  191. package/dist/types/workflow-run-context.d.ts +4 -4
  192. package/dist/types/workflow.d.ts +4 -4
  193. package/dist/types/workflow.js +27 -14
  194. package/dist/types/zod-types.d.ts +2 -1
  195. package/dist/types/zod-types.js +9 -3
  196. package/dist/user-connect/connection-code.d.ts +1 -1
  197. package/dist/user-connect/connection-code.js +7 -7
  198. package/dist/user-connect/connection-code.test.js +106 -106
  199. package/dist/user-connect/index.d.ts +3 -3
  200. package/dist/user-connect/index.js +1 -1
  201. package/dist/user-connect/user-connect.pvars.js +13 -11
  202. package/dist/user-connect/user-connect.types.d.ts +3 -3
  203. package/dist/users.query.d.ts +2 -2
  204. package/dist/users.query.js +40 -30
  205. package/dist/utils.d.ts +2 -2
  206. package/dist/utils.js +34 -32
  207. package/dist/utils.test.js +12 -8
  208. package/dist/workflow-log-formatter.d.ts +1 -1
  209. package/dist/workflow-log-formatter.js +17 -18
  210. package/package.json +14 -8
@@ -1,26 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const connection_code_1 = require("./connection-code");
4
- describe('connection-code', () => {
5
- describe('generateConnectionCode', () => {
6
- it('should generate a code with 12 characters', () => {
4
+ describe("connection-code", () => {
5
+ describe("generateConnectionCode", () => {
6
+ it("should generate a code with 12 characters", () => {
7
7
  const result = (0, connection_code_1.generateConnectionCode)();
8
8
  expect(result.code).toHaveLength(12);
9
9
  });
10
- it('should have alias of 4 characters', () => {
10
+ it("should have alias of 4 characters", () => {
11
11
  const result = (0, connection_code_1.generateConnectionCode)();
12
12
  expect(result.alias).toHaveLength(4);
13
13
  });
14
- it('should have secret of 8 characters', () => {
14
+ it("should have secret of 8 characters", () => {
15
15
  const result = (0, connection_code_1.generateConnectionCode)();
16
16
  expect(result.secret).toHaveLength(8);
17
17
  });
18
- it('should have code = alias + secret', () => {
18
+ it("should have code = alias + secret", () => {
19
19
  const result = (0, connection_code_1.generateConnectionCode)();
20
20
  expect(result.code).toBe(result.alias + result.secret);
21
21
  });
22
- it('should only contain valid Crockford Base32 characters', () => {
23
- const validChars = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
22
+ it("should only contain valid Crockford Base32 characters", () => {
23
+ const validChars = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
24
24
  for (let i = 0; i < 10; i++) {
25
25
  const result = (0, connection_code_1.generateConnectionCode)();
26
26
  for (const char of result.code) {
@@ -28,7 +28,7 @@ describe('connection-code', () => {
28
28
  }
29
29
  }
30
30
  });
31
- it('should generate different codes each time', () => {
31
+ it("should generate different codes each time", () => {
32
32
  const codes = new Set();
33
33
  for (let i = 0; i < 100; i++) {
34
34
  codes.add((0, connection_code_1.generateConnectionCode)().code);
@@ -36,51 +36,51 @@ describe('connection-code', () => {
36
36
  expect(codes.size).toBe(100);
37
37
  });
38
38
  });
39
- describe('formatConnectionCode', () => {
40
- it('should format a 12-character code as XXXX-YYYY-ZZZZ', () => {
41
- expect((0, connection_code_1.formatConnectionCode)('ABCD1234EFGH')).toBe('ABCD-1234-EFGH');
39
+ describe("formatConnectionCode", () => {
40
+ it("should format a 12-character code as XXXX-YYYY-ZZZZ", () => {
41
+ expect((0, connection_code_1.formatConnectionCode)("ABCD1234EFGH")).toBe("ABCD-1234-EFGH");
42
42
  });
43
- it('should handle lowercase input', () => {
44
- expect((0, connection_code_1.formatConnectionCode)('abcd1234efgh')).toBe('ABCD-1234-EFGH');
43
+ it("should handle lowercase input", () => {
44
+ expect((0, connection_code_1.formatConnectionCode)("abcd1234efgh")).toBe("ABCD-1234-EFGH");
45
45
  });
46
- it('should handle input with existing dashes', () => {
47
- expect((0, connection_code_1.formatConnectionCode)('ABCD-1234-EFGH')).toBe('ABCD-1234-EFGH');
46
+ it("should handle input with existing dashes", () => {
47
+ expect((0, connection_code_1.formatConnectionCode)("ABCD-1234-EFGH")).toBe("ABCD-1234-EFGH");
48
48
  });
49
- it('should handle input with spaces', () => {
50
- expect((0, connection_code_1.formatConnectionCode)('ABCD 1234 EFGH')).toBe('ABCD-1234-EFGH');
49
+ it("should handle input with spaces", () => {
50
+ expect((0, connection_code_1.formatConnectionCode)("ABCD 1234 EFGH")).toBe("ABCD-1234-EFGH");
51
51
  });
52
- it('should throw for codes that are too short', () => {
53
- expect(() => (0, connection_code_1.formatConnectionCode)('ABCD1234')).toThrow('must be 12 characters');
52
+ it("should throw for codes that are too short", () => {
53
+ expect(() => (0, connection_code_1.formatConnectionCode)("ABCD1234")).toThrow("must be 12 characters");
54
54
  });
55
- it('should throw for codes that are too long', () => {
56
- expect(() => (0, connection_code_1.formatConnectionCode)('ABCD1234EFGH5678')).toThrow('must be 12 characters');
55
+ it("should throw for codes that are too long", () => {
56
+ expect(() => (0, connection_code_1.formatConnectionCode)("ABCD1234EFGH5678")).toThrow("must be 12 characters");
57
57
  });
58
58
  });
59
- describe('parseConnectionCode', () => {
60
- it('should parse a plain 12-character code', () => {
61
- const result = (0, connection_code_1.parseConnectionCode)('ABCD12345678');
62
- expect(result.alias).toBe('ABCD');
63
- expect(result.secret).toBe('12345678');
64
- });
65
- it('should parse a formatted code with dashes', () => {
66
- const result = (0, connection_code_1.parseConnectionCode)('ABCD-1234-5678');
67
- expect(result.alias).toBe('ABCD');
68
- expect(result.secret).toBe('12345678');
69
- });
70
- it('should handle lowercase input', () => {
71
- const result = (0, connection_code_1.parseConnectionCode)('abcd-1234-5678');
72
- expect(result.alias).toBe('ABCD');
73
- expect(result.secret).toBe('12345678');
74
- });
75
- it('should handle mixed case and spaces', () => {
76
- const result = (0, connection_code_1.parseConnectionCode)('AbCd 1234 5678');
77
- expect(result.alias).toBe('ABCD');
78
- expect(result.secret).toBe('12345678');
79
- });
80
- it('should throw for invalid length', () => {
81
- expect(() => (0, connection_code_1.parseConnectionCode)('ABCD1234')).toThrow('must be 12 characters');
82
- });
83
- it('should be the inverse of formatConnectionCode', () => {
59
+ describe("parseConnectionCode", () => {
60
+ it("should parse a plain 12-character code", () => {
61
+ const result = (0, connection_code_1.parseConnectionCode)("ABCD12345678");
62
+ expect(result.alias).toBe("ABCD");
63
+ expect(result.secret).toBe("12345678");
64
+ });
65
+ it("should parse a formatted code with dashes", () => {
66
+ const result = (0, connection_code_1.parseConnectionCode)("ABCD-1234-5678");
67
+ expect(result.alias).toBe("ABCD");
68
+ expect(result.secret).toBe("12345678");
69
+ });
70
+ it("should handle lowercase input", () => {
71
+ const result = (0, connection_code_1.parseConnectionCode)("abcd-1234-5678");
72
+ expect(result.alias).toBe("ABCD");
73
+ expect(result.secret).toBe("12345678");
74
+ });
75
+ it("should handle mixed case and spaces", () => {
76
+ const result = (0, connection_code_1.parseConnectionCode)("AbCd 1234 5678");
77
+ expect(result.alias).toBe("ABCD");
78
+ expect(result.secret).toBe("12345678");
79
+ });
80
+ it("should throw for invalid length", () => {
81
+ expect(() => (0, connection_code_1.parseConnectionCode)("ABCD1234")).toThrow("must be 12 characters");
82
+ });
83
+ it("should be the inverse of formatConnectionCode", () => {
84
84
  const original = (0, connection_code_1.generateConnectionCode)();
85
85
  const formatted = (0, connection_code_1.formatConnectionCode)(original.code);
86
86
  const parsed = (0, connection_code_1.parseConnectionCode)(formatted);
@@ -88,126 +88,126 @@ describe('connection-code', () => {
88
88
  expect(parsed.secret).toBe(original.secret);
89
89
  });
90
90
  });
91
- describe('encryptWithSecret and decryptWithSecret', () => {
92
- it('should round-trip a simple string', () => {
93
- const secret = 'ABCD1234';
94
- const data = 'Hello, World!';
91
+ describe("encryptWithSecret and decryptWithSecret", () => {
92
+ it("should round-trip a simple string", () => {
93
+ const secret = "ABCD1234";
94
+ const data = "Hello, World!";
95
95
  const encrypted = (0, connection_code_1.encryptWithSecret)(data, secret);
96
96
  const decrypted = (0, connection_code_1.decryptWithSecret)(encrypted, secret);
97
97
  expect(decrypted).toBe(data);
98
98
  });
99
- it('should round-trip an object', () => {
100
- const secret = 'ZYXW9876';
101
- const data = { userId: 'user123', name: 'Test User', count: 42 };
99
+ it("should round-trip an object", () => {
100
+ const secret = "ZYXW9876";
101
+ const data = { userId: "user123", name: "Test User", count: 42 };
102
102
  const encrypted = (0, connection_code_1.encryptWithSecret)(data, secret);
103
103
  const decrypted = (0, connection_code_1.decryptWithSecret)(encrypted, secret);
104
104
  expect(decrypted).toEqual(data);
105
105
  });
106
- it('should round-trip user connect info', () => {
107
- const secret = 'TESTCODE';
106
+ it("should round-trip user connect info", () => {
107
+ const secret = "TESTCODE";
108
108
  const userInfo = {
109
- userId: 'user123',
110
- publicKey: 'pk_abc123',
111
- publicBoxKey: 'pbk_xyz789',
112
- deviceId: 'device456',
109
+ userId: "user123",
110
+ publicKey: "pk_abc123",
111
+ publicBoxKey: "pbk_xyz789",
112
+ deviceId: "device456",
113
113
  };
114
114
  const encrypted = (0, connection_code_1.encryptWithSecret)(userInfo, secret);
115
115
  const decrypted = (0, connection_code_1.decryptWithSecret)(encrypted, secret);
116
116
  expect(decrypted).toEqual(userInfo);
117
117
  });
118
- it('should produce different ciphertext for same data (due to random nonce)', () => {
119
- const secret = 'ABCD1234';
120
- const data = 'Same data';
118
+ it("should produce different ciphertext for same data (due to random nonce)", () => {
119
+ const secret = "ABCD1234";
120
+ const data = "Same data";
121
121
  const encrypted1 = (0, connection_code_1.encryptWithSecret)(data, secret);
122
122
  const encrypted2 = (0, connection_code_1.encryptWithSecret)(data, secret);
123
123
  expect(encrypted1).not.toBe(encrypted2);
124
124
  });
125
- it('should fail decryption with wrong secret', () => {
126
- const data = 'Secret message';
127
- const encrypted = (0, connection_code_1.encryptWithSecret)(data, 'CORRECT1');
128
- expect(() => (0, connection_code_1.decryptWithSecret)(encrypted, 'WRONGKEY')).toThrow('Decryption failed');
125
+ it("should fail decryption with wrong secret", () => {
126
+ const data = "Secret message";
127
+ const encrypted = (0, connection_code_1.encryptWithSecret)(data, "CORRECT1");
128
+ expect(() => (0, connection_code_1.decryptWithSecret)(encrypted, "WRONGKEY")).toThrow("Decryption failed");
129
129
  });
130
- it('should fail decryption with corrupted data', () => {
131
- const secret = 'ABCD1234';
132
- const data = 'Hello';
130
+ it("should fail decryption with corrupted data", () => {
131
+ const secret = "ABCD1234";
132
+ const data = "Hello";
133
133
  const encrypted = (0, connection_code_1.encryptWithSecret)(data, secret);
134
- const corrupted = encrypted.slice(0, -5) + 'XXXXX';
134
+ const corrupted = `${encrypted.slice(0, -5)}XXXXX`;
135
135
  expect(() => (0, connection_code_1.decryptWithSecret)(corrupted, secret)).toThrow();
136
136
  });
137
137
  });
138
- describe('generateConfirmationHash', () => {
138
+ describe("generateConfirmationHash", () => {
139
139
  const userA = {
140
- userId: 'userA123',
141
- publicKey: 'pkA',
142
- publicBoxKey: 'pbkA',
143
- deviceId: 'deviceA',
140
+ userId: "userA123",
141
+ publicKey: "pkA",
142
+ publicBoxKey: "pbkA",
143
+ deviceId: "deviceA",
144
144
  };
145
145
  const userB = {
146
- userId: 'userB456',
147
- publicKey: 'pkB',
148
- publicBoxKey: 'pbkB',
149
- deviceId: 'deviceB',
146
+ userId: "userB456",
147
+ publicKey: "pkB",
148
+ publicBoxKey: "pbkB",
149
+ deviceId: "deviceB",
150
150
  };
151
- it('should return a 4-character hash', () => {
151
+ it("should return a 4-character hash", () => {
152
152
  const hash = (0, connection_code_1.generateConfirmationHash)(userA, userB);
153
153
  expect(hash).toHaveLength(4);
154
154
  });
155
- it('should only contain valid Crockford Base32 characters', () => {
156
- const validChars = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
155
+ it("should only contain valid Crockford Base32 characters", () => {
156
+ const validChars = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
157
157
  const hash = (0, connection_code_1.generateConfirmationHash)(userA, userB);
158
158
  for (const char of hash) {
159
159
  expect(validChars).toContain(char);
160
160
  }
161
161
  });
162
- it('should produce same hash regardless of argument order', () => {
162
+ it("should produce same hash regardless of argument order", () => {
163
163
  const hashAB = (0, connection_code_1.generateConfirmationHash)(userA, userB);
164
164
  const hashBA = (0, connection_code_1.generateConfirmationHash)(userB, userA);
165
165
  expect(hashAB).toBe(hashBA);
166
166
  });
167
- it('should produce different hash for different users', () => {
167
+ it("should produce different hash for different users", () => {
168
168
  const userC = {
169
- userId: 'userC789',
170
- publicKey: 'pkC',
171
- publicBoxKey: 'pbkC',
172
- deviceId: 'deviceC',
169
+ userId: "userC789",
170
+ publicKey: "pkC",
171
+ publicBoxKey: "pbkC",
172
+ deviceId: "deviceC",
173
173
  };
174
174
  const hashAB = (0, connection_code_1.generateConfirmationHash)(userA, userB);
175
175
  const hashAC = (0, connection_code_1.generateConfirmationHash)(userA, userC);
176
176
  expect(hashAB).not.toBe(hashAC);
177
177
  });
178
- it('should be deterministic', () => {
178
+ it("should be deterministic", () => {
179
179
  const hash1 = (0, connection_code_1.generateConfirmationHash)(userA, userB);
180
180
  const hash2 = (0, connection_code_1.generateConfirmationHash)(userA, userB);
181
181
  expect(hash1).toBe(hash2);
182
182
  });
183
183
  });
184
- describe('isValidConnectionCode', () => {
185
- it('should return true for valid 12-character codes', () => {
186
- expect((0, connection_code_1.isValidConnectionCode)('ABCD1234EFGH')).toBe(true);
184
+ describe("isValidConnectionCode", () => {
185
+ it("should return true for valid 12-character codes", () => {
186
+ expect((0, connection_code_1.isValidConnectionCode)("ABCD1234EFGH")).toBe(true);
187
187
  });
188
- it('should return true for codes with dashes', () => {
189
- expect((0, connection_code_1.isValidConnectionCode)('ABCD-1234-EFGH')).toBe(true);
188
+ it("should return true for codes with dashes", () => {
189
+ expect((0, connection_code_1.isValidConnectionCode)("ABCD-1234-EFGH")).toBe(true);
190
190
  });
191
- it('should return true for lowercase codes', () => {
192
- expect((0, connection_code_1.isValidConnectionCode)('abcd1234efgh')).toBe(true);
191
+ it("should return true for lowercase codes", () => {
192
+ expect((0, connection_code_1.isValidConnectionCode)("abcd1234efgh")).toBe(true);
193
193
  });
194
- it('should return true for generated codes', () => {
194
+ it("should return true for generated codes", () => {
195
195
  const code = (0, connection_code_1.generateConnectionCode)();
196
196
  expect((0, connection_code_1.isValidConnectionCode)(code.code)).toBe(true);
197
197
  expect((0, connection_code_1.isValidConnectionCode)((0, connection_code_1.formatConnectionCode)(code.code))).toBe(true);
198
198
  });
199
- it('should return false for codes that are too short', () => {
200
- expect((0, connection_code_1.isValidConnectionCode)('ABCD1234')).toBe(false);
199
+ it("should return false for codes that are too short", () => {
200
+ expect((0, connection_code_1.isValidConnectionCode)("ABCD1234")).toBe(false);
201
201
  });
202
- it('should return false for codes that are too long', () => {
203
- expect((0, connection_code_1.isValidConnectionCode)('ABCD1234EFGH5678')).toBe(false);
202
+ it("should return false for codes that are too long", () => {
203
+ expect((0, connection_code_1.isValidConnectionCode)("ABCD1234EFGH5678")).toBe(false);
204
204
  });
205
- it('should return false for codes with invalid characters', () => {
205
+ it("should return false for codes with invalid characters", () => {
206
206
  // I, L, O, U are not in Crockford Base32
207
- expect((0, connection_code_1.isValidConnectionCode)('ABCDILOU1234')).toBe(false);
207
+ expect((0, connection_code_1.isValidConnectionCode)("ABCDILOU1234")).toBe(false);
208
208
  });
209
- it('should return false for empty string', () => {
210
- expect((0, connection_code_1.isValidConnectionCode)('')).toBe(false);
209
+ it("should return false for empty string", () => {
210
+ expect((0, connection_code_1.isValidConnectionCode)("")).toBe(false);
211
211
  });
212
212
  });
213
213
  });
@@ -1,3 +1,3 @@
1
- export * from './connection-code';
2
- export * from './user-connect.types';
3
- export * from './user-connect.pvars';
1
+ export * from "./connection-code";
2
+ export * from "./user-connect.pvars";
3
+ export * from "./user-connect.types";
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./connection-code"), exports);
18
- __exportStar(require("./user-connect.types"), exports);
19
18
  __exportStar(require("./user-connect.pvars"), exports);
19
+ __exportStar(require("./user-connect.types"), exports);
@@ -2,31 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userConnectCodeAnswer = exports.userConnectCodeOffer = exports.userConnectStatus = void 0;
4
4
  const persistent_vars_1 = require("../data/persistent-vars");
5
- exports.userConnectStatus = (0, persistent_vars_1.deviceVar)('userConnectStatus', { defaultValue: undefined });
6
- exports.userConnectCodeOffer = (0, persistent_vars_1.deviceVar)('userConnectCodeOffer', { defaultValue: '' });
5
+ exports.userConnectStatus = (0, persistent_vars_1.deviceVar)("userConnectStatus", { defaultValue: undefined });
6
+ exports.userConnectCodeOffer = (0, persistent_vars_1.deviceVar)("userConnectCodeOffer", { defaultValue: "" });
7
7
  exports.userConnectCodeOffer.loadingPromise.then(() => {
8
- let codeTimeout = undefined;
9
- (0, exports.userConnectStatus)('');
8
+ let codeTimeout;
9
+ (0, exports.userConnectStatus)("");
10
10
  exports.userConnectCodeOffer.subscribe(() => {
11
- (0, exports.userConnectStatus)('');
11
+ (0, exports.userConnectStatus)("");
12
12
  clearTimeout(codeTimeout);
13
13
  if ((0, exports.userConnectCodeOffer)()) {
14
14
  codeTimeout = setTimeout(() => {
15
- (0, exports.userConnectCodeOffer)('');
15
+ (0, exports.userConnectCodeOffer)("");
16
16
  }, 600_000); // 10 minutes
17
17
  }
18
18
  });
19
19
  });
20
- exports.userConnectCodeAnswer = (0, persistent_vars_1.deviceVar)('userConnectCodeAnswer', { defaultValue: '' });
20
+ exports.userConnectCodeAnswer = (0, persistent_vars_1.deviceVar)("userConnectCodeAnswer", {
21
+ defaultValue: "",
22
+ });
21
23
  exports.userConnectCodeAnswer.loadingPromise.then(() => {
22
- let codeTimeout = undefined;
23
- (0, exports.userConnectStatus)('');
24
+ let codeTimeout;
25
+ (0, exports.userConnectStatus)("");
24
26
  exports.userConnectCodeAnswer.subscribe(() => {
25
- (0, exports.userConnectStatus)('');
27
+ (0, exports.userConnectStatus)("");
26
28
  clearTimeout(codeTimeout);
27
29
  if ((0, exports.userConnectCodeAnswer)()) {
28
30
  codeTimeout = setTimeout(() => {
29
- (0, exports.userConnectCodeAnswer)('');
31
+ (0, exports.userConnectCodeAnswer)("");
30
32
  }, 600_000); // 10 minutes
31
33
  }
32
34
  });
@@ -19,7 +19,7 @@ export interface IUserConnectInfo {
19
19
  * The payload is encrypted with the shared secret from the connection code.
20
20
  */
21
21
  export interface IUserConnectRequest {
22
- type: 'user-connect-request';
22
+ type: "user-connect-request";
23
23
  /** User info encrypted with the shared secret */
24
24
  encryptedUserInfo: string;
25
25
  /** The responder's deviceId so the initiator can respond directly */
@@ -30,7 +30,7 @@ export interface IUserConnectRequest {
30
30
  * The payload is encrypted with the shared secret.
31
31
  */
32
32
  export interface IUserConnectResponse {
33
- type: 'user-connect-response';
33
+ type: "user-connect-response";
34
34
  /** User info encrypted with the shared secret */
35
35
  encryptedUserInfo: string;
36
36
  }
@@ -39,7 +39,7 @@ export interface IUserConnectResponse {
39
39
  * Other devices store this mapping for routing purposes.
40
40
  */
41
41
  export interface IDeviceAliasMessage {
42
- type: 'device-alias';
42
+ type: "device-alias";
43
43
  /** The short alias (4 chars Crockford Base32) */
44
44
  alias: string;
45
45
  /** The actual deviceId this alias maps to */
@@ -1,4 +1,4 @@
1
- import { DataContext, DataFilter, ICursorIterable, IUser, TrustLevel, UserContext } from "./index";
1
+ import { type DataContext, type DataFilter, type ICursorIterable, type IUser, TrustLevel, type UserContext } from "./index";
2
2
  export interface IUsersQueryOpts {
3
3
  userContext?: UserContext;
4
4
  currentDataContext?: DataContext;
@@ -7,7 +7,7 @@ export interface IUsersQueryOpts {
7
7
  includeOtherDataContexts?: boolean;
8
8
  includeTrustLevel?: boolean;
9
9
  }
10
- export type IUserSource = 'currentDataContext' | 'userDataContext' | 'otherDataContexts';
10
+ export type IUserSource = "currentDataContext" | "userDataContext" | "otherDataContexts";
11
11
  export interface IUserWithSource extends IUser {
12
12
  source: IUserSource;
13
13
  trustLevel?: TrustLevel;
@@ -11,10 +11,11 @@ async function usersCursor(filter, opts = {}) {
11
11
  // Include current data context
12
12
  if (includeCurrentDataContext) {
13
13
  const primaryTable = (0, index_1.Users)(contextToUse);
14
- const primarySource = (contextToUse === userContext.userDataContext) ? 'userDataContext' : 'currentDataContext';
15
- const primaryCursor = index_1.Cursor.fromDataSource(primaryTable, filter)
16
- .map(async (user) => {
17
- const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(contextToUse, user.userId) : undefined;
14
+ const primarySource = contextToUse === userContext.userDataContext ? "userDataContext" : "currentDataContext";
15
+ const primaryCursor = index_1.Cursor.fromDataSource(primaryTable, filter).map(async (user) => {
16
+ const trustLevel = includeTrustLevel
17
+ ? await (0, index_1.getUserTrustLevel)(contextToUse, user.userId)
18
+ : undefined;
18
19
  const userWithSource = {
19
20
  ...user,
20
21
  source: primarySource,
@@ -27,12 +28,13 @@ async function usersCursor(filter, opts = {}) {
27
28
  // Include user data context (if different from current and requested)
28
29
  if (includeUserDataContext && contextToUse !== userContext.userDataContext) {
29
30
  const userDataContextTable = (0, index_1.Users)(userContext.userDataContext);
30
- const userDataContextCursor = index_1.Cursor.fromDataSource(userDataContextTable, filter)
31
- .map(async (user) => {
32
- const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId) : undefined;
31
+ const userDataContextCursor = index_1.Cursor.fromDataSource(userDataContextTable, filter).map(async (user) => {
32
+ const trustLevel = includeTrustLevel
33
+ ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId)
34
+ : undefined;
33
35
  const userWithSource = {
34
36
  ...user,
35
- source: 'userDataContext',
37
+ source: "userDataContext",
36
38
  trustLevel,
37
39
  };
38
40
  return userWithSource;
@@ -50,14 +52,15 @@ async function usersCursor(filter, opts = {}) {
50
52
  if (otherDataContexts.length > 0) {
51
53
  // For trust levels from multiple contexts, we'll use the first context we find the user in
52
54
  // This is a simplification - in reality, each group might have different trust levels
53
- const otherDataContextTables = otherDataContexts.map(dataContext => (0, index_1.Users)(dataContext));
54
- const otherDataContextsCursor = index_1.Cursor.fromDataSources(otherDataContextTables, filter)
55
- .map(async (user) => {
55
+ const otherDataContextTables = otherDataContexts.map((dataContext) => (0, index_1.Users)(dataContext));
56
+ const otherDataContextsCursor = index_1.Cursor.fromDataSources(otherDataContextTables, filter).map(async (user) => {
56
57
  // Try to get trust level from the first group context that has this user
57
- let trustLevel = undefined;
58
+ let trustLevel;
58
59
  if (includeTrustLevel) {
59
60
  for (const dataContext of otherDataContexts) {
60
- const contextUser = await (0, index_1.Users)(dataContext).get(user.userId).catch(() => null);
61
+ const contextUser = await (0, index_1.Users)(dataContext)
62
+ .get(user.userId)
63
+ .catch(() => null);
61
64
  if (contextUser) {
62
65
  trustLevel = await (0, index_1.getUserTrustLevel)(dataContext, user.userId);
63
66
  break;
@@ -66,20 +69,21 @@ async function usersCursor(filter, opts = {}) {
66
69
  }
67
70
  const userWithSource = {
68
71
  ...user,
69
- source: 'otherDataContexts',
72
+ source: "otherDataContexts",
70
73
  trustLevel,
71
74
  };
72
75
  return userWithSource;
73
76
  });
74
- finalCursor = finalCursor ? finalCursor.union(otherDataContextsCursor) : otherDataContextsCursor;
77
+ finalCursor = finalCursor
78
+ ? finalCursor.union(otherDataContextsCursor)
79
+ : otherDataContextsCursor;
75
80
  }
76
81
  }
77
82
  // If no cursor was created, return empty cursor
78
83
  if (!finalCursor) {
79
- return index_1.Cursor.fromDataSource((0, index_1.Users)(contextToUse), { userId: { $eq: '__non_existent__' } })
80
- .map(async (user) => ({
84
+ return index_1.Cursor.fromDataSource((0, index_1.Users)(contextToUse), { userId: { $eq: "__non_existent__" } }).map(async (user) => ({
81
85
  ...user,
82
- source: 'userDataContext',
86
+ source: "userDataContext",
83
87
  trustLevel: index_1.TrustLevel.Unknown,
84
88
  }));
85
89
  }
@@ -92,7 +96,7 @@ async function usersCursor(filter, opts = {}) {
92
96
  }
93
97
  if (includeTrustLevel) {
94
98
  // use personal trust level if I have one
95
- // TODO: Review this, I think this makes sense but it could create scenarios where I am unintentionally
99
+ // TODO: Review this, I think this makes sense but it could create scenarios where I am unintentionally
96
100
  // trusting another user too much just because a group I'm in has given them a high trust rating
97
101
  // IDEA: Assign a trust level to _groups_ and then user trust levels from that group are capped at that level
98
102
  const personalTrustLevel = await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId);
@@ -105,8 +109,8 @@ async function usersCursor(filter, opts = {}) {
105
109
  });
106
110
  }
107
111
  async function getUserById(userId, opts = {}) {
108
- const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true, includeTrustLevel = true } = opts;
109
- const userContext = opts.userContext || await (0, index_1.getUserContext)();
112
+ const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true, includeTrustLevel = true, } = opts;
113
+ const userContext = opts.userContext || (await (0, index_1.getUserContext)());
110
114
  const contextToUse = currentDataContext || userContext.defaultDataContext();
111
115
  // Try current data context first
112
116
  if (includeCurrentDataContext) {
@@ -114,8 +118,10 @@ async function getUserById(userId, opts = {}) {
114
118
  const primaryTable = (0, index_1.Users)(contextToUse);
115
119
  const user = await primaryTable.get(userId);
116
120
  if (user) {
117
- const source = (contextToUse === userContext.userDataContext) ? 'userDataContext' : 'currentDataContext';
118
- const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(contextToUse, user.userId) : undefined;
121
+ const source = contextToUse === userContext.userDataContext ? "userDataContext" : "currentDataContext";
122
+ const trustLevel = includeTrustLevel
123
+ ? await (0, index_1.getUserTrustLevel)(contextToUse, user.userId)
124
+ : undefined;
119
125
  return {
120
126
  ...user,
121
127
  source,
@@ -123,7 +129,7 @@ async function getUserById(userId, opts = {}) {
123
129
  };
124
130
  }
125
131
  }
126
- catch (error) {
132
+ catch (_error) {
127
133
  // User not found in this context, continue to next
128
134
  }
129
135
  }
@@ -133,15 +139,17 @@ async function getUserById(userId, opts = {}) {
133
139
  const userDataContextTable = (0, index_1.Users)(userContext.userDataContext);
134
140
  const user = await userDataContextTable.get(userId);
135
141
  if (user) {
136
- const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId) : undefined;
142
+ const trustLevel = includeTrustLevel
143
+ ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId)
144
+ : undefined;
137
145
  return {
138
146
  ...user,
139
- source: 'userDataContext',
147
+ source: "userDataContext",
140
148
  trustLevel,
141
149
  };
142
150
  }
143
151
  }
144
- catch (error) {
152
+ catch (_error) {
145
153
  // User not found in this context, continue to next
146
154
  }
147
155
  }
@@ -153,15 +161,17 @@ async function getUserById(userId, opts = {}) {
153
161
  const table = (0, index_1.Users)(dataContext);
154
162
  const user = await table.get(userId);
155
163
  if (user) {
156
- const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(dataContext, user.userId) : undefined;
164
+ const trustLevel = includeTrustLevel
165
+ ? await (0, index_1.getUserTrustLevel)(dataContext, user.userId)
166
+ : undefined;
157
167
  return {
158
168
  ...user,
159
- source: 'otherDataContexts',
169
+ source: "otherDataContexts",
160
170
  trustLevel,
161
171
  };
162
172
  }
163
173
  }
164
- catch (error) {
174
+ catch (_error) {
165
175
  // User not found in this context, continue to next
166
176
  }
167
177
  }
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IDeviceConnection } from './types/peer-device';
2
- import type { ITableMetaData } from './data/orm';
1
+ import type { ITableMetaData } from "./data/orm";
2
+ import { type IDeviceConnection } from "./types/peer-device";
3
3
  export declare function cryptoRandomString(length: number): string;
4
4
  export declare function newid(): string;
5
5
  export declare const MIN_ID: string;