@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
|
@@ -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(
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
23
|
-
const validChars =
|
|
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(
|
|
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(
|
|
40
|
-
it(
|
|
41
|
-
expect((0, connection_code_1.formatConnectionCode)(
|
|
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(
|
|
44
|
-
expect((0, connection_code_1.formatConnectionCode)(
|
|
43
|
+
it("should handle lowercase input", () => {
|
|
44
|
+
expect((0, connection_code_1.formatConnectionCode)("abcd1234efgh")).toBe("ABCD-1234-EFGH");
|
|
45
45
|
});
|
|
46
|
-
it(
|
|
47
|
-
expect((0, connection_code_1.formatConnectionCode)(
|
|
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(
|
|
50
|
-
expect((0, connection_code_1.formatConnectionCode)(
|
|
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(
|
|
53
|
-
expect(() => (0, connection_code_1.formatConnectionCode)(
|
|
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(
|
|
56
|
-
expect(() => (0, connection_code_1.formatConnectionCode)(
|
|
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(
|
|
60
|
-
it(
|
|
61
|
-
const result = (0, connection_code_1.parseConnectionCode)(
|
|
62
|
-
expect(result.alias).toBe(
|
|
63
|
-
expect(result.secret).toBe(
|
|
64
|
-
});
|
|
65
|
-
it(
|
|
66
|
-
const result = (0, connection_code_1.parseConnectionCode)(
|
|
67
|
-
expect(result.alias).toBe(
|
|
68
|
-
expect(result.secret).toBe(
|
|
69
|
-
});
|
|
70
|
-
it(
|
|
71
|
-
const result = (0, connection_code_1.parseConnectionCode)(
|
|
72
|
-
expect(result.alias).toBe(
|
|
73
|
-
expect(result.secret).toBe(
|
|
74
|
-
});
|
|
75
|
-
it(
|
|
76
|
-
const result = (0, connection_code_1.parseConnectionCode)(
|
|
77
|
-
expect(result.alias).toBe(
|
|
78
|
-
expect(result.secret).toBe(
|
|
79
|
-
});
|
|
80
|
-
it(
|
|
81
|
-
expect(() => (0, connection_code_1.parseConnectionCode)(
|
|
82
|
-
});
|
|
83
|
-
it(
|
|
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(
|
|
92
|
-
it(
|
|
93
|
-
const secret =
|
|
94
|
-
const data =
|
|
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(
|
|
100
|
-
const secret =
|
|
101
|
-
const data = { userId:
|
|
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(
|
|
107
|
-
const secret =
|
|
106
|
+
it("should round-trip user connect info", () => {
|
|
107
|
+
const secret = "TESTCODE";
|
|
108
108
|
const userInfo = {
|
|
109
|
-
userId:
|
|
110
|
-
publicKey:
|
|
111
|
-
publicBoxKey:
|
|
112
|
-
deviceId:
|
|
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(
|
|
119
|
-
const secret =
|
|
120
|
-
const 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(
|
|
126
|
-
const data =
|
|
127
|
-
const encrypted = (0, connection_code_1.encryptWithSecret)(data,
|
|
128
|
-
expect(() => (0, connection_code_1.decryptWithSecret)(encrypted,
|
|
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(
|
|
131
|
-
const secret =
|
|
132
|
-
const data =
|
|
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)
|
|
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(
|
|
138
|
+
describe("generateConfirmationHash", () => {
|
|
139
139
|
const userA = {
|
|
140
|
-
userId:
|
|
141
|
-
publicKey:
|
|
142
|
-
publicBoxKey:
|
|
143
|
-
deviceId:
|
|
140
|
+
userId: "userA123",
|
|
141
|
+
publicKey: "pkA",
|
|
142
|
+
publicBoxKey: "pbkA",
|
|
143
|
+
deviceId: "deviceA",
|
|
144
144
|
};
|
|
145
145
|
const userB = {
|
|
146
|
-
userId:
|
|
147
|
-
publicKey:
|
|
148
|
-
publicBoxKey:
|
|
149
|
-
deviceId:
|
|
146
|
+
userId: "userB456",
|
|
147
|
+
publicKey: "pkB",
|
|
148
|
+
publicBoxKey: "pbkB",
|
|
149
|
+
deviceId: "deviceB",
|
|
150
150
|
};
|
|
151
|
-
it(
|
|
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(
|
|
156
|
-
const validChars =
|
|
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(
|
|
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(
|
|
167
|
+
it("should produce different hash for different users", () => {
|
|
168
168
|
const userC = {
|
|
169
|
-
userId:
|
|
170
|
-
publicKey:
|
|
171
|
-
publicBoxKey:
|
|
172
|
-
deviceId:
|
|
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(
|
|
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(
|
|
185
|
-
it(
|
|
186
|
-
expect((0, connection_code_1.isValidConnectionCode)(
|
|
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(
|
|
189
|
-
expect((0, connection_code_1.isValidConnectionCode)(
|
|
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(
|
|
192
|
-
expect((0, connection_code_1.isValidConnectionCode)(
|
|
191
|
+
it("should return true for lowercase codes", () => {
|
|
192
|
+
expect((0, connection_code_1.isValidConnectionCode)("abcd1234efgh")).toBe(true);
|
|
193
193
|
});
|
|
194
|
-
it(
|
|
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(
|
|
200
|
-
expect((0, connection_code_1.isValidConnectionCode)(
|
|
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(
|
|
203
|
-
expect((0, connection_code_1.isValidConnectionCode)(
|
|
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(
|
|
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)(
|
|
207
|
+
expect((0, connection_code_1.isValidConnectionCode)("ABCDILOU1234")).toBe(false);
|
|
208
208
|
});
|
|
209
|
-
it(
|
|
210
|
-
expect((0, connection_code_1.isValidConnectionCode)(
|
|
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
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
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)(
|
|
6
|
-
exports.userConnectCodeOffer = (0, persistent_vars_1.deviceVar)(
|
|
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
|
|
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)(
|
|
20
|
+
exports.userConnectCodeAnswer = (0, persistent_vars_1.deviceVar)("userConnectCodeAnswer", {
|
|
21
|
+
defaultValue: "",
|
|
22
|
+
});
|
|
21
23
|
exports.userConnectCodeAnswer.loadingPromise.then(() => {
|
|
22
|
-
let codeTimeout
|
|
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:
|
|
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:
|
|
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:
|
|
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 */
|
package/dist/users.query.d.ts
CHANGED
|
@@ -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 =
|
|
10
|
+
export type IUserSource = "currentDataContext" | "userDataContext" | "otherDataContexts";
|
|
11
11
|
export interface IUserWithSource extends IUser {
|
|
12
12
|
source: IUserSource;
|
|
13
13
|
trustLevel?: TrustLevel;
|
package/dist/users.query.js
CHANGED
|
@@ -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 =
|
|
15
|
-
const primaryCursor = index_1.Cursor.fromDataSource(primaryTable, filter)
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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:
|
|
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
|
|
58
|
+
let trustLevel;
|
|
58
59
|
if (includeTrustLevel) {
|
|
59
60
|
for (const dataContext of otherDataContexts) {
|
|
60
|
-
const contextUser = await (0, index_1.Users)(dataContext)
|
|
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:
|
|
72
|
+
source: "otherDataContexts",
|
|
70
73
|
trustLevel,
|
|
71
74
|
};
|
|
72
75
|
return userWithSource;
|
|
73
76
|
});
|
|
74
|
-
finalCursor = finalCursor
|
|
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:
|
|
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:
|
|
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 =
|
|
118
|
-
const trustLevel = includeTrustLevel
|
|
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 (
|
|
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
|
|
142
|
+
const trustLevel = includeTrustLevel
|
|
143
|
+
? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId)
|
|
144
|
+
: undefined;
|
|
137
145
|
return {
|
|
138
146
|
...user,
|
|
139
|
-
source:
|
|
147
|
+
source: "userDataContext",
|
|
140
148
|
trustLevel,
|
|
141
149
|
};
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
|
-
catch (
|
|
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
|
|
164
|
+
const trustLevel = includeTrustLevel
|
|
165
|
+
? await (0, index_1.getUserTrustLevel)(dataContext, user.userId)
|
|
166
|
+
: undefined;
|
|
157
167
|
return {
|
|
158
168
|
...user,
|
|
159
|
-
source:
|
|
169
|
+
source: "otherDataContexts",
|
|
160
170
|
trustLevel,
|
|
161
171
|
};
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
|
-
catch (
|
|
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 {
|
|
2
|
-
import type
|
|
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;
|