@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
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const keys_1 = require("../keys");
4
4
  const user_permissions_1 = require("./user-permissions");
5
5
  // Test the user permissions logic directly without ORM dependencies
6
- describe('User Permissions Logic', () => {
6
+ describe("User Permissions Logic", () => {
7
7
  let testUser;
8
8
  let userKeys;
9
9
  let otherUserKeys;
@@ -11,264 +11,266 @@ describe('User Permissions Logic', () => {
11
11
  userKeys = (0, keys_1.newKeys)();
12
12
  otherUserKeys = (0, keys_1.newKeys)();
13
13
  testUser = {
14
- userId: 'test-user-1',
15
- name: 'Test User',
14
+ userId: "test-user-1",
15
+ name: "Test User",
16
16
  publicKey: userKeys.publicKey,
17
17
  publicBoxKey: userKeys.publicBoxKey,
18
- signature: ''
18
+ signature: "",
19
19
  };
20
20
  });
21
- describe('basic signature functionality', () => {
22
- it('should add signature to user object', () => {
21
+ describe("basic signature functionality", () => {
22
+ it("should add signature to user object", () => {
23
23
  const signedUser = (0, keys_1.addSignatureToObject)(testUser, userKeys.secretKey);
24
24
  expect(signedUser.signature).toBeTruthy();
25
- expect(signedUser.signature).toContain(':');
25
+ expect(signedUser.signature).toContain(":");
26
26
  expect(signedUser.userId).toBe(testUser.userId);
27
27
  expect(signedUser.name).toBe(testUser.name);
28
28
  expect(signedUser.publicKey).toBe(testUser.publicKey);
29
29
  });
30
- it('should verify valid signature', () => {
30
+ it("should verify valid signature", () => {
31
31
  const signedUser = (0, keys_1.addSignatureToObject)(testUser, userKeys.secretKey);
32
32
  const isValid = (0, keys_1.isObjectSignatureValid)(signedUser);
33
33
  expect(isValid).toBe(true);
34
34
  });
35
- it('should reject invalid signature after modification', () => {
35
+ it("should reject invalid signature after modification", () => {
36
36
  const signedUser = (0, keys_1.addSignatureToObject)(testUser, userKeys.secretKey);
37
37
  // Modify the user after signing
38
- signedUser.name = 'Modified Name';
38
+ signedUser.name = "Modified Name";
39
39
  const isValid = (0, keys_1.isObjectSignatureValid)(signedUser);
40
40
  expect(isValid).toBe(false);
41
41
  });
42
- it('should extract public key from signature', () => {
42
+ it("should extract public key from signature", () => {
43
43
  const signedUser = (0, keys_1.addSignatureToObject)(testUser, userKeys.secretKey);
44
44
  const extractedPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedUser);
45
45
  expect(extractedPublicKey).toBe(userKeys.publicKey);
46
46
  });
47
47
  });
48
- describe('signUserObject helper', () => {
49
- it('should sign user object correctly', () => {
48
+ describe("signUserObject helper", () => {
49
+ it("should sign user object correctly", () => {
50
50
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
51
51
  expect(signedUser.signature).toBeTruthy();
52
52
  expect((0, keys_1.isObjectSignatureValid)(signedUser)).toBe(true);
53
53
  expect((0, keys_1.getPublicKeyFromObjectSignature)(signedUser)).toBe(userKeys.publicKey);
54
54
  });
55
55
  });
56
- describe('verifyUserSignature', () => {
57
- it('should verify valid signature for new user', () => {
56
+ describe("verifyUserSignature", () => {
57
+ it("should verify valid signature for new user", () => {
58
58
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
59
59
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser)).not.toThrow();
60
60
  });
61
- it('should verify valid signature for existing user update', () => {
61
+ it("should verify valid signature for existing user update", () => {
62
62
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
63
63
  const updatedUser = {
64
64
  ...originalUser,
65
- name: 'Updated Name',
66
- signature: ''
65
+ name: "Updated Name",
66
+ signature: "",
67
67
  };
68
68
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
69
69
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).not.toThrow();
70
70
  });
71
- it('should reject signature that does not match user public key for new user', () => {
71
+ it("should reject signature that does not match user public key for new user", () => {
72
72
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, otherUserKeys.secretKey);
73
- expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser)).toThrow('User signature must be signed with their own public key');
73
+ expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser)).toThrow("User signature must be signed with their own public key");
74
74
  });
75
- it('should reject signature that does not match existing user public key', () => {
75
+ it("should reject signature that does not match existing user public key", () => {
76
76
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
77
77
  const updatedUser = {
78
78
  ...originalUser,
79
- name: 'Updated Name',
80
- signature: ''
79
+ name: "Updated Name",
80
+ signature: "",
81
81
  };
82
82
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, otherUserKeys.secretKey);
83
- expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow('User update must be signed by the user themselves');
83
+ expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow("User update must be signed by the user themselves");
84
84
  });
85
- it('should reject public key changes', () => {
85
+ it("should reject public key changes", () => {
86
86
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
87
87
  const updatedUser = {
88
88
  ...originalUser,
89
89
  publicKey: otherUserKeys.publicKey,
90
- signature: ''
90
+ signature: "",
91
91
  };
92
92
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
93
- expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow('Public key changes are not currently supported');
93
+ expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow("Public key changes are not currently supported");
94
94
  });
95
- it('should allow missing signature when no existing record', () => {
95
+ it("should allow missing signature when no existing record", () => {
96
96
  const userWithoutSignature = { ...testUser };
97
97
  expect(() => (0, user_permissions_1.verifyUserSignature)(userWithoutSignature)).not.toThrow();
98
98
  });
99
99
  });
100
- describe('verifyUserSignature - Group Context (With Signature)', () => {
101
- it('should allow valid signature for new user in group context', () => {
100
+ describe("verifyUserSignature - Group Context (With Signature)", () => {
101
+ it("should allow valid signature for new user in group context", () => {
102
102
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
103
103
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).not.toThrow();
104
104
  });
105
- it('should allow valid signature for existing user update in group context', () => {
105
+ it("should allow valid signature for existing user update in group context", () => {
106
106
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
107
107
  const updatedUser = {
108
108
  ...originalUser,
109
- name: 'Updated Name',
110
- signature: ''
109
+ name: "Updated Name",
110
+ signature: "",
111
111
  };
112
112
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
113
113
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).not.toThrow();
114
114
  });
115
- it('should reject invalid signature in group context', () => {
115
+ it("should reject invalid signature in group context", () => {
116
116
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
117
117
  // Tamper with the signature
118
- signedUser.name = 'Tampered Name';
118
+ signedUser.name = "Tampered Name";
119
119
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).toThrow();
120
120
  });
121
- it('should reject signature from wrong user for new user', () => {
121
+ it("should reject signature from wrong user for new user", () => {
122
122
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, otherUserKeys.secretKey);
123
123
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).toThrow();
124
124
  });
125
- it('should reject signature from wrong user for existing user update', () => {
125
+ it("should reject signature from wrong user for existing user update", () => {
126
126
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
127
127
  const updatedUser = {
128
128
  ...originalUser,
129
- name: 'Updated Name',
130
- signature: ''
129
+ name: "Updated Name",
130
+ signature: "",
131
131
  };
132
132
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, otherUserKeys.secretKey);
133
133
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow();
134
134
  });
135
- it('should reject public key changes in group context', () => {
135
+ it("should reject public key changes in group context", () => {
136
136
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
137
137
  const updatedUser = {
138
138
  ...originalUser,
139
139
  publicKey: otherUserKeys.publicKey, // Change public key
140
- signature: ''
140
+ signature: "",
141
141
  };
142
142
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
143
143
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow();
144
144
  });
145
- it('should allow changes with valid signature', () => {
145
+ it("should allow changes with valid signature", () => {
146
146
  const originalUser = (0, user_permissions_1.signUserObject)({ ...testUser }, userKeys.secretKey);
147
147
  const updatedUser = {
148
148
  ...originalUser,
149
- name: 'Updated Name',
150
- signature: ''
149
+ name: "Updated Name",
150
+ signature: "",
151
151
  };
152
152
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
153
153
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).not.toThrow();
154
154
  });
155
155
  });
156
- describe('verifyUserSignature - Signature Requirements', () => {
157
- it('should allow unsigned record when no existing record', () => {
156
+ describe("verifyUserSignature - Signature Requirements", () => {
157
+ it("should allow unsigned record when no existing record", () => {
158
158
  const userWithoutSignature = { ...testUser };
159
159
  expect(() => (0, user_permissions_1.verifyUserSignature)(userWithoutSignature, undefined)).not.toThrow();
160
160
  });
161
- it('should accept valid signature when signature is provided', () => {
161
+ it("should accept valid signature when signature is provided", () => {
162
162
  const signedUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
163
163
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).not.toThrow();
164
164
  });
165
- it('should allow empty signature when no existing record', () => {
166
- const userWithEmptySignature = { ...testUser, signature: '' };
165
+ it("should allow empty signature when no existing record", () => {
166
+ const userWithEmptySignature = { ...testUser, signature: "" };
167
167
  expect(() => (0, user_permissions_1.verifyUserSignature)(userWithEmptySignature, undefined)).not.toThrow();
168
168
  });
169
- it('should reject whitespace-only signature (treated as a bad signature, not a stub)', () => {
170
- const userWithWhitespaceSignature = { ...testUser, signature: ' ' };
169
+ it("should reject whitespace-only signature (treated as a bad signature, not a stub)", () => {
170
+ const userWithWhitespaceSignature = { ...testUser, signature: " " };
171
171
  expect(() => (0, user_permissions_1.verifyUserSignature)(userWithWhitespaceSignature, undefined)).toThrow();
172
172
  });
173
173
  });
174
- describe('verifyUserSignature - Unsigned stubs', () => {
175
- it('should allow unsigned stub when no existing record', () => {
174
+ describe("verifyUserSignature - Unsigned stubs", () => {
175
+ it("should allow unsigned stub when no existing record", () => {
176
176
  const stub = { ...testUser, signature: undefined };
177
177
  expect(() => (0, user_permissions_1.verifyUserSignature)(stub)).not.toThrow();
178
178
  });
179
- it('should allow unsigned stub to overwrite an existing unsigned stub', () => {
179
+ it("should allow unsigned stub to overwrite an existing unsigned stub", () => {
180
180
  const existingStub = { ...testUser, signature: undefined };
181
- const incomingStub = { ...testUser, name: 'Updated Name', signature: undefined };
181
+ const incomingStub = { ...testUser, name: "Updated Name", signature: undefined };
182
182
  expect(() => (0, user_permissions_1.verifyUserSignature)(incomingStub, existingStub)).not.toThrow();
183
183
  });
184
- it('should reject unsigned stub when a signed record already exists', () => {
184
+ it("should reject unsigned stub when a signed record already exists", () => {
185
185
  const signedExisting = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
186
186
  const incomingStub = { ...testUser, signature: undefined };
187
- expect(() => (0, user_permissions_1.verifyUserSignature)(incomingStub, signedExisting))
188
- .toThrow('Cannot overwrite a signed user record with an unsigned one');
187
+ expect(() => (0, user_permissions_1.verifyUserSignature)(incomingStub, signedExisting)).toThrow("Cannot overwrite a signed user record with an unsigned one");
189
188
  });
190
- it('should reject unsigned stub with different keys when signed record exists', () => {
189
+ it("should reject unsigned stub with different keys when signed record exists", () => {
191
190
  const signedExisting = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
192
- const incomingStub = { ...testUser, publicKey: otherUserKeys.publicKey, signature: undefined };
193
- expect(() => (0, user_permissions_1.verifyUserSignature)(incomingStub, signedExisting))
194
- .toThrow('Cannot overwrite a signed user record with an unsigned one');
191
+ const incomingStub = {
192
+ ...testUser,
193
+ publicKey: otherUserKeys.publicKey,
194
+ signature: undefined,
195
+ };
196
+ expect(() => (0, user_permissions_1.verifyUserSignature)(incomingStub, signedExisting)).toThrow("Cannot overwrite a signed user record with an unsigned one");
195
197
  });
196
- it('should allow a signed record to replace an unsigned stub', () => {
198
+ it("should allow a signed record to replace an unsigned stub", () => {
197
199
  const existingStub = { ...testUser, signature: undefined };
198
200
  const signedIncoming = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
199
201
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedIncoming, existingStub)).not.toThrow();
200
202
  });
201
203
  });
202
- describe('edge cases and error handling', () => {
203
- it('should handle undefined user gracefully', () => {
204
- // @ts-ignore - Testing edge case
204
+ describe("edge cases and error handling", () => {
205
+ it("should handle undefined user gracefully", () => {
206
+ // @ts-expect-error - Testing edge case
205
207
  expect(() => (0, user_permissions_1.verifyUserSignature)(undefined, undefined)).toThrow();
206
208
  });
207
- it('should handle malformed signature', () => {
208
- const userWithBadSignature = { ...testUser, signature: 'invalid-signature' };
209
+ it("should handle malformed signature", () => {
210
+ const userWithBadSignature = { ...testUser, signature: "invalid-signature" };
209
211
  expect(() => (0, user_permissions_1.verifyUserSignature)(userWithBadSignature, undefined)).toThrow();
210
212
  });
211
- it('should handle missing public key in user object', () => {
212
- const userWithoutPublicKey = { ...testUser, publicKey: '' };
213
+ it("should handle missing public key in user object", () => {
214
+ const userWithoutPublicKey = { ...testUser, publicKey: "" };
213
215
  const signedUser = (0, user_permissions_1.signUserObject)(userWithoutPublicKey, userKeys.secretKey);
214
216
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).toThrow();
215
217
  });
216
- it('should handle existing user with missing public key', () => {
217
- const originalUser = { ...testUser, publicKey: '' };
218
- const updatedUser = { ...testUser, name: 'Updated' };
218
+ it("should handle existing user with missing public key", () => {
219
+ const originalUser = { ...testUser, publicKey: "" };
220
+ const updatedUser = { ...testUser, name: "Updated" };
219
221
  const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
220
222
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow();
221
223
  });
222
- it('should handle various user values', () => {
224
+ it("should handle various user values", () => {
223
225
  const userWithValues = {
224
226
  ...testUser,
225
- name: 'Complex Name'
227
+ name: "Complex Name",
226
228
  };
227
229
  const signedUser = (0, user_permissions_1.signUserObject)(userWithValues, userKeys.secretKey);
228
230
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).not.toThrow();
229
231
  });
230
232
  });
231
- describe('security scenarios', () => {
232
- it('should prevent impersonation attacks', () => {
233
+ describe("security scenarios", () => {
234
+ it("should prevent impersonation attacks", () => {
233
235
  // Attacker tries to create a user record with victim's public key but signed with attacker's key
234
236
  const victimUser = {
235
- userId: 'victim-user',
236
- name: 'Victim User',
237
+ userId: "victim-user",
238
+ name: "Victim User",
237
239
  publicKey: userKeys.publicKey, // Victim's public key
238
240
  publicBoxKey: userKeys.publicBoxKey,
239
- signature: ''
241
+ signature: "",
240
242
  };
241
243
  const maliciousSignedUser = (0, user_permissions_1.signUserObject)(victimUser, otherUserKeys.secretKey); // Signed with attacker's key
242
244
  expect(() => (0, user_permissions_1.verifyUserSignature)(maliciousSignedUser, undefined)).toThrow();
243
245
  });
244
- it('should prevent profile takeover attacks', () => {
246
+ it("should prevent profile takeover attacks", () => {
245
247
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
246
248
  // Attacker tries to update the user's profile with their own signature
247
249
  const maliciousUpdate = {
248
250
  ...originalUser,
249
- name: 'Attacker Name',
250
- signature: ''
251
+ name: "Attacker Name",
252
+ signature: "",
251
253
  };
252
254
  const maliciousSignedUpdate = (0, user_permissions_1.signUserObject)(maliciousUpdate, otherUserKeys.secretKey);
253
255
  expect(() => (0, user_permissions_1.verifyUserSignature)(maliciousSignedUpdate, originalUser)).toThrow();
254
256
  });
255
- it('should prevent public key rotation attacks', () => {
257
+ it("should prevent public key rotation attacks", () => {
256
258
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
257
259
  // Attacker tries to change the public key to their own
258
260
  const keyRotationAttack = {
259
261
  ...originalUser,
260
262
  publicKey: otherUserKeys.publicKey, // Change to attacker's key
261
- signature: ''
263
+ signature: "",
262
264
  };
263
265
  const signedAttack = (0, user_permissions_1.signUserObject)(keyRotationAttack, userKeys.secretKey);
264
266
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedAttack, originalUser)).toThrow();
265
267
  });
266
- it('should allow legitimate name changes with proper signature', () => {
268
+ it("should allow legitimate name changes with proper signature", () => {
267
269
  const originalUser = (0, user_permissions_1.signUserObject)(testUser, userKeys.secretKey);
268
270
  const legitimateUpdate = {
269
271
  ...originalUser,
270
- name: 'New Legal Name',
271
- signature: ''
272
+ name: "New Legal Name",
273
+ signature: "",
272
274
  };
273
275
  const signedUpdate = (0, user_permissions_1.signUserObject)(legitimateUpdate, userKeys.secretKey);
274
276
  expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdate, originalUser)).not.toThrow();
@@ -18,19 +18,19 @@ const types_1 = require("./orm/types");
18
18
  * Each context can maintain its own trust assessment of other users.
19
19
  */
20
20
  exports.userTrustLevelSchema = zod_1.z.object({
21
- userId: zod_types_1.zodPeerId.describe('The user being assigned a trust level'),
22
- trustLevel: zod_1.z.nativeEnum(socket_type_1.TrustLevel).describe('The trust level assigned to this user in this context'),
23
- assignedAt: zod_1.z.date().optional().describe('When the trust level was assigned'),
24
- notes: zod_1.z.string().optional().describe('Optional notes about why this trust level was assigned'),
21
+ userId: zod_types_1.zodPeerId.describe("The user being assigned a trust level"),
22
+ trustLevel: zod_1.z
23
+ .nativeEnum(socket_type_1.TrustLevel)
24
+ .describe("The trust level assigned to this user in this context"),
25
+ assignedAt: zod_1.z.date().optional().describe("When the trust level was assigned"),
26
+ notes: zod_1.z.string().optional().describe("Optional notes about why this trust level was assigned"),
25
27
  });
26
28
  const metaData = {
27
- name: 'UserTrustLevels',
28
- description: 'Trust levels assigned to users by the current context (user or group)',
29
- primaryKeyName: 'userId',
29
+ name: "UserTrustLevels",
30
+ description: "Trust levels assigned to users by the current context (user or group)",
31
+ primaryKeyName: "userId",
30
32
  fields: (0, types_1.schemaToFields)(exports.userTrustLevelSchema),
31
- indexes: [
32
- { fields: ['trustLevel'] },
33
- ]
33
+ indexes: [{ fields: ["trustLevel"] }],
34
34
  };
35
35
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.userTrustLevelSchema);
36
36
  function UserTrustLevels(dataContext) {
@@ -11,14 +11,14 @@ export declare const userSchema: z.ZodObject<{
11
11
  }, "strip", z.ZodTypeAny, {
12
12
  name: string;
13
13
  publicKey: string;
14
- userId: string;
15
14
  publicBoxKey: string;
15
+ userId: string;
16
16
  signature?: string | undefined;
17
17
  }, {
18
18
  name: string;
19
19
  publicKey: string;
20
- userId: string;
21
20
  publicBoxKey: string;
21
+ userId: string;
22
22
  signature?: string | undefined;
23
23
  }>;
24
24
  export type IUser = z.infer<typeof userSchema>;
@@ -29,9 +29,9 @@ export declare class UsersTable extends Table<IUser> {
29
29
  private static addSignatureToUser;
30
30
  static enableUserSigning(fn: (user: IUser) => IUser): void;
31
31
  /** @deprecated Forbidden on UsersTable; use save() */
32
- insert(..._args: Parameters<Table<IUser>['insert']>): never;
32
+ insert(..._args: Parameters<Table<IUser>["insert"]>): never;
33
33
  /** @deprecated Forbidden on UsersTable; use save() */
34
- update(..._args: Parameters<Table<IUser>['update']>): never;
34
+ update(..._args: Parameters<Table<IUser>["update"]>): never;
35
35
  }
36
36
  export declare function Users(dataContext?: DataContext): UsersTable;
37
37
  export declare function getMe(): Promise<IUser>;
@@ -48,20 +48,21 @@ const user_permissions_1 = require("./user-permissions");
48
48
  exports.userSchema = zod_1.z.object({
49
49
  userId: zod_types_1.zodPeerId,
50
50
  name: zod_1.z.string(),
51
- publicKey: zod_1.z.string().describe('The public key the user uses to sign messages'),
52
- publicBoxKey: zod_1.z.string().describe('The public key to use to encrypt data that only this user can decrypt'),
53
- signature: zod_1.z.string().optional().describe('The signed hash of this user object excluding the signature itself'),
51
+ publicKey: zod_1.z.string().describe("The public key the user uses to sign messages"),
52
+ publicBoxKey: zod_1.z
53
+ .string()
54
+ .describe("The public key to use to encrypt data that only this user can decrypt"),
55
+ signature: zod_1.z
56
+ .string()
57
+ .optional()
58
+ .describe("The signed hash of this user object excluding the signature itself"),
54
59
  });
55
60
  const metaData = {
56
- name: 'Users',
57
- description: 'users',
58
- primaryKeyName: 'userId',
61
+ name: "Users",
62
+ description: "users",
63
+ primaryKeyName: "userId",
59
64
  fields: (0, types_1.schemaToFields)(exports.userSchema),
60
- indexes: [
61
- { fields: ['name'] },
62
- { fields: ['publicKey'] },
63
- { fields: ['publicBoxKey'] },
64
- ]
65
+ indexes: [{ fields: ["name"] }, { fields: ["publicKey"] }, { fields: ["publicBoxKey"] }],
65
66
  };
66
67
  let UsersTable = (() => {
67
68
  let _classSuper = table_1.Table;
@@ -94,7 +95,7 @@ let UsersTable = (() => {
94
95
  }
95
96
  async signAndSave(user, opts) {
96
97
  if (!UsersTable.addSignatureToUser) {
97
- throw new Error('User signing must be enabled to sign and save users. Call UsersTable.enableUserSigning(fn) to enable it.');
98
+ throw new Error("User signing must be enabled to sign and save users. Call UsersTable.enableUserSigning(fn) to enable it.");
98
99
  }
99
100
  user = UsersTable.addSignatureToUser(user);
100
101
  return this.save(user, opts);
@@ -105,11 +106,11 @@ let UsersTable = (() => {
105
106
  }
106
107
  /** @deprecated Forbidden on UsersTable; use save() */
107
108
  insert(..._args) {
108
- throw new Error('UsersTable forbids insert; use save()');
109
+ throw new Error("UsersTable forbids insert; use save()");
109
110
  }
110
111
  /** @deprecated Forbidden on UsersTable; use save() */
111
112
  update(..._args) {
112
- throw new Error('UsersTable forbids update; use save()');
113
+ throw new Error("UsersTable forbids update; use save()");
113
114
  }
114
115
  constructor() {
115
116
  super(...arguments);
@@ -127,7 +128,7 @@ async function getMe() {
127
128
  const userContext = await (0, user_context_singleton_1.getUserContext)();
128
129
  const me = await userContext.getMe();
129
130
  if (!me) {
130
- throw new Error('My user object was not found in the DB. Is the user setup?');
131
+ throw new Error("My user object was not found in the DB. Is the user setup?");
131
132
  }
132
133
  return me;
133
134
  }
@@ -1,5 +1,5 @@
1
- import { z } from 'zod';
2
- import { DataContext } from '../context/data-context';
1
+ import { z } from "zod";
2
+ import type { DataContext } from "../context/data-context";
3
3
  export declare const voiceMessageSchema: z.ZodObject<{
4
4
  voiceMessageId: z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
5
5
  sessionId: z.ZodString;
@@ -2,30 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.voiceMessageSchema = void 0;
4
4
  exports.VoiceMessages = VoiceMessages;
5
- const types_1 = require("./orm/types");
6
- const utils_1 = require("../utils");
7
5
  const zod_1 = require("zod");
8
- const zod_types_1 = require("../types/zod-types");
9
6
  const user_context_singleton_1 = require("../context/user-context-singleton");
7
+ const zod_types_1 = require("../types/zod-types");
8
+ const utils_1 = require("../utils");
10
9
  const table_definitions_system_1 = require("./orm/table-definitions.system");
10
+ const types_1 = require("./orm/types");
11
11
  exports.voiceMessageSchema = zod_1.z.object({
12
12
  voiceMessageId: zod_types_1.zodPeerId.default(() => (0, utils_1.newid)()),
13
- sessionId: zod_1.z.string().describe('Groups messages belonging to one voice session'),
14
- role: zod_1.z.enum(['user', 'assistant']),
13
+ sessionId: zod_1.z.string().describe("Groups messages belonging to one voice session"),
14
+ role: zod_1.z.enum(["user", "assistant"]),
15
15
  content: zod_1.z.string(),
16
- threadId: zod_1.z.string().optional().describe('messageId of the channel thread created when an action was dispatched to the background agent'),
16
+ threadId: zod_1.z
17
+ .string()
18
+ .optional()
19
+ .describe("messageId of the channel thread created when an action was dispatched to the background agent"),
17
20
  createdAt: zod_1.z.date().default(() => new Date()),
18
21
  });
19
22
  const metaData = {
20
- name: 'VoiceMessages',
21
- description: 'Voice conversation history for the self-contained voice assistant',
22
- primaryKeyName: 'voiceMessageId',
23
+ name: "VoiceMessages",
24
+ description: "Voice conversation history for the self-contained voice assistant",
25
+ primaryKeyName: "voiceMessageId",
23
26
  fields: (0, types_1.schemaToFields)(exports.voiceMessageSchema),
24
27
  localOnly: true,
25
- indexes: [
26
- { fields: ['sessionId'] },
27
- { fields: ['sessionId', 'createdAt'] },
28
- ],
28
+ indexes: [{ fields: ["sessionId"] }, { fields: ["sessionId", "createdAt"] }],
29
29
  };
30
30
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.voiceMessageSchema);
31
31
  function VoiceMessages(dataContext) {
@@ -12,4 +12,6 @@ const persistent_vars_1 = require("./persistent-vars");
12
12
  *
13
13
  * Defaults to false, meaning new users will see the modal after account creation.
14
14
  */
15
- exports.hasShownWelcomeModal = (0, persistent_vars_1.deviceVar)('hasShownWelcomeModal', { defaultValue: false });
15
+ exports.hasShownWelcomeModal = (0, persistent_vars_1.deviceVar)("hasShownWelcomeModal", {
16
+ defaultValue: false,
17
+ });
@@ -3,30 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLogger = exports.workflowLogSchema = void 0;
4
4
  exports.WorkflowLogs = WorkflowLogs;
5
5
  const zod_1 = require("zod");
6
+ const user_context_singleton_1 = require("../context/user-context-singleton");
6
7
  const workflow_1 = require("../types/workflow");
7
8
  const zod_types_1 = require("../types/zod-types");
8
9
  const utils_1 = require("../utils");
9
- const types_1 = require("./orm/types");
10
- const user_context_singleton_1 = require("../context/user-context-singleton");
11
10
  const table_definitions_system_1 = require("./orm/table-definitions.system");
11
+ const types_1 = require("./orm/types");
12
12
  exports.workflowLogSchema = zod_1.z.object({
13
13
  workflowLogId: zod_types_1.zodPeerId,
14
- workflowRunId: zod_types_1.zodPeerId.describe('The workflow run that this log entry is associated with'),
15
- contextId: zod_types_1.zodPeerId.describe('The context that this log entry is associated with'),
16
- logDT: zod_1.z.date().default(() => new Date()).describe('The date the log occurred'),
17
- logText: zod_1.z.string().describe('The text of the log entry'),
18
- result: zod_1.z.string().optional().describe('The result of the instructions'),
19
- instruction: workflow_1.workflowInstructionSchema.optional().describe('The instruction that was run'),
20
- toolId: zod_types_1.zodPeerId.optional().describe('The tool that was run'),
21
- toolArgs: zod_types_1.zodAnyObject.optional().describe('The arguments that were passed to the tool'),
22
- toolRunTimeMs: zod_1.z.number().optional().describe('The time it took to run the tool in milliseconds'),
23
- resultObject: zod_types_1.zodAnyObjectOrArray.optional().describe('If the result is structured data it will be stored here'),
24
- isError: zod_1.z.boolean().optional().describe('Whether or not the log entry is the result of an error'),
14
+ workflowRunId: zod_types_1.zodPeerId.describe("The workflow run that this log entry is associated with"),
15
+ contextId: zod_types_1.zodPeerId.describe("The context that this log entry is associated with"),
16
+ logDT: zod_1.z
17
+ .date()
18
+ .default(() => new Date())
19
+ .describe("The date the log occurred"),
20
+ logText: zod_1.z.string().describe("The text of the log entry"),
21
+ result: zod_1.z.string().optional().describe("The result of the instructions"),
22
+ instruction: workflow_1.workflowInstructionSchema.optional().describe("The instruction that was run"),
23
+ toolId: zod_types_1.zodPeerId.optional().describe("The tool that was run"),
24
+ toolArgs: zod_types_1.zodAnyObject.optional().describe("The arguments that were passed to the tool"),
25
+ toolRunTimeMs: zod_1.z.number().optional().describe("The time it took to run the tool in milliseconds"),
26
+ resultObject: zod_types_1.zodAnyObjectOrArray
27
+ .optional()
28
+ .describe("If the result is structured data it will be stored here"),
29
+ isError: zod_1.z
30
+ .boolean()
31
+ .optional()
32
+ .describe("Whether or not the log entry is the result of an error"),
25
33
  });
26
34
  const metaData = {
27
- name: 'WorkflowLogs',
28
- description: 'The log entries for workflow runs.',
29
- primaryKeyName: 'workflowLogId',
35
+ name: "WorkflowLogs",
36
+ description: "The log entries for workflow runs.",
37
+ primaryKeyName: "workflowLogId",
30
38
  fields: (0, types_1.schemaToFields)(exports.workflowLogSchema),
31
39
  };
32
40
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.workflowLogSchema);
@@ -37,7 +45,7 @@ const getLogger = (workflowRunId, contextId) => {
37
45
  return async (logData) => {
38
46
  try {
39
47
  let logRecord;
40
- if (typeof logData === 'string') {
48
+ if (typeof logData === "string") {
41
49
  logRecord = WorkflowLogs().initRecord({
42
50
  workflowRunId,
43
51
  workflowLogId: (0, utils_1.newid)(),
@@ -52,7 +60,7 @@ const getLogger = (workflowRunId, contextId) => {
52
60
  });
53
61
  }
54
62
  logRecord.workflowRunId = workflowRunId;
55
- logRecord.logText = logRecord.logText || '';
63
+ logRecord.logText = logRecord.logText || "";
56
64
  logRecord.contextId = contextId;
57
65
  return await WorkflowLogs().insert(logRecord);
58
66
  }