@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.
- package/dist/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- 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(
|
|
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:
|
|
15
|
-
name:
|
|
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(
|
|
22
|
-
it(
|
|
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(
|
|
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(
|
|
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 =
|
|
38
|
+
signedUser.name = "Modified Name";
|
|
39
39
|
const isValid = (0, keys_1.isObjectSignatureValid)(signedUser);
|
|
40
40
|
expect(isValid).toBe(false);
|
|
41
41
|
});
|
|
42
|
-
it(
|
|
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(
|
|
49
|
-
it(
|
|
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(
|
|
57
|
-
it(
|
|
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(
|
|
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:
|
|
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(
|
|
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(
|
|
73
|
+
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser)).toThrow("User signature must be signed with their own public key");
|
|
74
74
|
});
|
|
75
|
-
it(
|
|
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:
|
|
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(
|
|
83
|
+
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow("User update must be signed by the user themselves");
|
|
84
84
|
});
|
|
85
|
-
it(
|
|
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(
|
|
93
|
+
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow("Public key changes are not currently supported");
|
|
94
94
|
});
|
|
95
|
-
it(
|
|
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(
|
|
101
|
-
it(
|
|
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(
|
|
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:
|
|
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(
|
|
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 =
|
|
118
|
+
signedUser.name = "Tampered Name";
|
|
119
119
|
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).toThrow();
|
|
120
120
|
});
|
|
121
|
-
it(
|
|
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(
|
|
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:
|
|
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(
|
|
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(
|
|
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:
|
|
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(
|
|
157
|
-
it(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
175
|
-
it(
|
|
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(
|
|
179
|
+
it("should allow unsigned stub to overwrite an existing unsigned stub", () => {
|
|
180
180
|
const existingStub = { ...testUser, signature: undefined };
|
|
181
|
-
const incomingStub = { ...testUser, name:
|
|
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(
|
|
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(
|
|
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 = {
|
|
193
|
-
|
|
194
|
-
.
|
|
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(
|
|
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(
|
|
203
|
-
it(
|
|
204
|
-
// @ts-
|
|
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(
|
|
208
|
-
const userWithBadSignature = { ...testUser, 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(
|
|
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(
|
|
217
|
-
const originalUser = { ...testUser, publicKey:
|
|
218
|
-
const updatedUser = { ...testUser, name:
|
|
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(
|
|
224
|
+
it("should handle various user values", () => {
|
|
223
225
|
const userWithValues = {
|
|
224
226
|
...testUser,
|
|
225
|
-
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(
|
|
232
|
-
it(
|
|
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:
|
|
236
|
-
name:
|
|
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(
|
|
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:
|
|
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(
|
|
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(
|
|
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:
|
|
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(
|
|
22
|
-
trustLevel: zod_1.z
|
|
23
|
-
|
|
24
|
-
|
|
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:
|
|
28
|
-
description:
|
|
29
|
-
primaryKeyName:
|
|
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) {
|
package/dist/data/users.d.ts
CHANGED
|
@@ -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>[
|
|
32
|
+
insert(..._args: Parameters<Table<IUser>["insert"]>): never;
|
|
33
33
|
/** @deprecated Forbidden on UsersTable; use save() */
|
|
34
|
-
update(..._args: Parameters<Table<IUser>[
|
|
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>;
|
package/dist/data/users.js
CHANGED
|
@@ -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(
|
|
52
|
-
publicBoxKey: zod_1.z
|
|
53
|
-
|
|
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:
|
|
57
|
-
description:
|
|
58
|
-
primaryKeyName:
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
2
|
-
import { DataContext } from
|
|
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(
|
|
14
|
-
role: zod_1.z.enum([
|
|
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
|
|
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:
|
|
21
|
-
description:
|
|
22
|
-
primaryKeyName:
|
|
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)(
|
|
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(
|
|
15
|
-
contextId: zod_types_1.zodPeerId.describe(
|
|
16
|
-
logDT: zod_1.z
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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:
|
|
28
|
-
description:
|
|
29
|
-
primaryKeyName:
|
|
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 ===
|
|
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
|
}
|