@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
package/dist/data/group-share.js
CHANGED
|
@@ -21,15 +21,15 @@ async function generateGroupShare(groupId) {
|
|
|
21
21
|
// Get the group from user's context
|
|
22
22
|
const group = await (0, groups_1.Groups)(userContext.userDataContext).get(groupId);
|
|
23
23
|
if (!group) {
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error("Group not found");
|
|
25
25
|
}
|
|
26
26
|
// Get group data context and members
|
|
27
27
|
const groupDataContext = userContext.getDataContext(groupId);
|
|
28
28
|
const groupMembersTable = (0, group_members_1.GroupMembers)(groupDataContext);
|
|
29
29
|
// Get the 5 newest admins to seed the members table with for the initial connection
|
|
30
|
-
const adminMembers = await groupMembersTable.list({ deleted: { $ne: true }, role: { $gte: group_member_roles_1.GroupMemberRole.Admin } }, { pageSize: 5, sortBy: [
|
|
30
|
+
const adminMembers = await groupMembersTable.list({ deleted: { $ne: true }, role: { $gte: group_member_roles_1.GroupMemberRole.Admin } }, { pageSize: 5, sortBy: ["-groupMemberId"] });
|
|
31
31
|
if (adminMembers.length === 0) {
|
|
32
|
-
console.warn(
|
|
32
|
+
console.warn("No admin members, first connection will rely exclusively on founder");
|
|
33
33
|
}
|
|
34
34
|
const groupShare = {
|
|
35
35
|
group,
|
|
@@ -49,12 +49,12 @@ async function importGroupShare(groupShareJson) {
|
|
|
49
49
|
try {
|
|
50
50
|
groupShare = JSON.parse(groupShareJson);
|
|
51
51
|
}
|
|
52
|
-
catch (
|
|
53
|
-
throw new Error(
|
|
52
|
+
catch (_error) {
|
|
53
|
+
throw new Error("Invalid JSON format");
|
|
54
54
|
}
|
|
55
55
|
// Validate structure - maybe redo this with a zod schema
|
|
56
56
|
if (!validateGroupShare(groupShare)) {
|
|
57
|
-
throw new Error(
|
|
57
|
+
throw new Error("Invalid GroupShare structure");
|
|
58
58
|
}
|
|
59
59
|
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
60
60
|
const { group, groupMembers } = groupShare;
|
|
@@ -85,15 +85,18 @@ async function importGroupShare(groupShareJson) {
|
|
|
85
85
|
* @returns boolean True if valid GroupShare structure
|
|
86
86
|
*/
|
|
87
87
|
function validateGroupShare(obj) {
|
|
88
|
-
if (!obj || typeof obj !==
|
|
88
|
+
if (!obj || typeof obj !== "object") {
|
|
89
89
|
return false;
|
|
90
90
|
}
|
|
91
91
|
// Check group structure
|
|
92
|
-
if (!obj.group || typeof obj.group !==
|
|
92
|
+
if (!obj.group || typeof obj.group !== "object") {
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
95
|
const group = obj.group;
|
|
96
|
-
if (!group.groupId ||
|
|
96
|
+
if (!group.groupId ||
|
|
97
|
+
!group.name ||
|
|
98
|
+
typeof group.groupId !== "string" ||
|
|
99
|
+
typeof group.name !== "string") {
|
|
97
100
|
return false;
|
|
98
101
|
}
|
|
99
102
|
// Check groupMembers structure
|
|
@@ -101,14 +104,16 @@ function validateGroupShare(obj) {
|
|
|
101
104
|
return false;
|
|
102
105
|
}
|
|
103
106
|
for (const member of obj.groupMembers) {
|
|
104
|
-
if (!member || typeof member !==
|
|
107
|
+
if (!member || typeof member !== "object") {
|
|
105
108
|
return false;
|
|
106
109
|
}
|
|
107
|
-
if (!member.groupMemberId ||
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
typeof member.
|
|
111
|
-
typeof member.
|
|
110
|
+
if (!member.groupMemberId ||
|
|
111
|
+
!member.groupId ||
|
|
112
|
+
!member.userId ||
|
|
113
|
+
typeof member.groupMemberId !== "string" ||
|
|
114
|
+
typeof member.groupId !== "string" ||
|
|
115
|
+
typeof member.userId !== "string" ||
|
|
116
|
+
typeof member.role !== "number" ||
|
|
112
117
|
member.role < group_member_roles_1.GroupMemberRole.Admin) {
|
|
113
118
|
return false;
|
|
114
119
|
}
|
|
@@ -133,8 +138,8 @@ function checkQRCodeCompatibility(groupShare, qrVersion = 20) {
|
|
|
133
138
|
const size = estimateGroupShareSize(groupShare);
|
|
134
139
|
const limits = {
|
|
135
140
|
10: 1273, // Version 10 limit
|
|
136
|
-
20: 3057, // Version 20 limit
|
|
137
|
-
40: 7089 // Version 40 limit
|
|
141
|
+
20: 3057, // Version 20 limit
|
|
142
|
+
40: 7089, // Version 40 limit
|
|
138
143
|
};
|
|
139
144
|
const maxSize = limits[qrVersion];
|
|
140
145
|
const fits = size <= maxSize;
|
|
@@ -145,7 +150,7 @@ function checkQRCodeCompatibility(groupShare, qrVersion = 20) {
|
|
|
145
150
|
fits,
|
|
146
151
|
usagePercent,
|
|
147
152
|
qrVersion,
|
|
148
|
-
memberCount: groupShare.groupMembers.length
|
|
153
|
+
memberCount: groupShare.groupMembers.length,
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
@@ -155,26 +160,26 @@ function checkQRCodeCompatibility(groupShare, qrVersion = 20) {
|
|
|
155
160
|
*/
|
|
156
161
|
async function copyToClipboard(text) {
|
|
157
162
|
try {
|
|
158
|
-
if (navigator.clipboard
|
|
163
|
+
if (navigator.clipboard?.writeText) {
|
|
159
164
|
await navigator.clipboard.writeText(text);
|
|
160
165
|
return true;
|
|
161
166
|
}
|
|
162
167
|
else {
|
|
163
168
|
// Fallback for older browsers
|
|
164
|
-
const textArea = document.createElement(
|
|
169
|
+
const textArea = document.createElement("textarea");
|
|
165
170
|
textArea.value = text;
|
|
166
|
-
textArea.style.position =
|
|
167
|
-
textArea.style.opacity =
|
|
171
|
+
textArea.style.position = "fixed";
|
|
172
|
+
textArea.style.opacity = "0";
|
|
168
173
|
document.body.appendChild(textArea);
|
|
169
174
|
textArea.focus();
|
|
170
175
|
textArea.select();
|
|
171
|
-
const success = document.execCommand(
|
|
176
|
+
const success = document.execCommand("copy");
|
|
172
177
|
document.body.removeChild(textArea);
|
|
173
178
|
return success;
|
|
174
179
|
}
|
|
175
180
|
}
|
|
176
181
|
catch (error) {
|
|
177
|
-
console.error(
|
|
182
|
+
console.error("Failed to copy to clipboard:", error);
|
|
178
183
|
return false;
|
|
179
184
|
}
|
|
180
185
|
}
|
package/dist/data/groups.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ export declare const groupSchema: z.ZodObject<{
|
|
|
19
19
|
description: string;
|
|
20
20
|
publicKey: string;
|
|
21
21
|
signature: string;
|
|
22
|
-
publicBoxKey: string;
|
|
23
22
|
groupId: string;
|
|
24
23
|
founderUserId: string;
|
|
24
|
+
publicBoxKey: string;
|
|
25
25
|
disabled?: boolean | undefined;
|
|
26
26
|
iconClassName?: string | undefined;
|
|
27
27
|
publicRole?: GroupMemberRole | undefined;
|
|
@@ -30,9 +30,9 @@ export declare const groupSchema: z.ZodObject<{
|
|
|
30
30
|
description: string;
|
|
31
31
|
publicKey: string;
|
|
32
32
|
signature: string;
|
|
33
|
-
publicBoxKey: string;
|
|
34
33
|
groupId: string;
|
|
35
34
|
founderUserId: string;
|
|
35
|
+
publicBoxKey: string;
|
|
36
36
|
disabled?: boolean | undefined;
|
|
37
37
|
iconClassName?: string | undefined;
|
|
38
38
|
publicRole?: GroupMemberRole | undefined;
|
|
@@ -47,8 +47,8 @@ export declare class GroupsTable extends Table<IGroup> {
|
|
|
47
47
|
private static addSignatureToGroup;
|
|
48
48
|
static enableGroupSigning(fn: (group: IGroup) => IGroup): void;
|
|
49
49
|
/** @deprecated Direct inserts forbidden; use save() */
|
|
50
|
-
insert(..._args: Parameters<Table<IGroup>[
|
|
50
|
+
insert(..._args: Parameters<Table<IGroup>["insert"]>): never;
|
|
51
51
|
/** @deprecated Direct updates forbidden; use save() */
|
|
52
|
-
update(..._args: Parameters<Table<IGroup>[
|
|
52
|
+
update(..._args: Parameters<Table<IGroup>["update"]>): never;
|
|
53
53
|
}
|
|
54
54
|
export declare function Groups(dataContext?: DataContext): GroupsTable;
|
package/dist/data/groups.js
CHANGED
|
@@ -49,24 +49,32 @@ exports.groupSchema = zod_1.z.object({
|
|
|
49
49
|
groupId: zod_types_1.zodPeerId,
|
|
50
50
|
name: zod_1.z.string(),
|
|
51
51
|
description: zod_1.z.string(),
|
|
52
|
-
iconClassName: zod_1.z
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
iconClassName: zod_1.z
|
|
53
|
+
.string()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe("Icon class name for the group (e.g., bi-people-fill)"),
|
|
56
|
+
publicRole: zod_1.z
|
|
57
|
+
.nativeEnum(group_member_roles_1.GroupMemberRole)
|
|
58
|
+
.optional()
|
|
59
|
+
.describe("Whether the group is publicly readable"),
|
|
60
|
+
disabled: zod_1.z.boolean().optional().describe("Whether the group is currently disabled"),
|
|
61
|
+
founderUserId: zod_types_1.zodPeerId.describe("The user ID of the group founder"),
|
|
62
|
+
signature: zod_1.z.string().describe("The signed hash of this data excluding the signature itself"),
|
|
63
|
+
publicKey: zod_1.z
|
|
64
|
+
.string()
|
|
65
|
+
.describe("The public key of the group used to verify a data has come from a group member with write permissions or higher"),
|
|
66
|
+
publicBoxKey: zod_1.z
|
|
67
|
+
.string()
|
|
68
|
+
.describe("The public key used to encrypt data that only group members with writer permissions or higher can decrypt"),
|
|
59
69
|
});
|
|
60
|
-
exports.groupsTableName =
|
|
70
|
+
exports.groupsTableName = "Groups";
|
|
61
71
|
const metaData = {
|
|
62
72
|
name: exports.groupsTableName,
|
|
63
|
-
description:
|
|
64
|
-
primaryKeyName:
|
|
73
|
+
description: "groups",
|
|
74
|
+
primaryKeyName: "groupId",
|
|
65
75
|
fields: (0, types_1.schemaToFields)(exports.groupSchema),
|
|
66
|
-
iconClassName:
|
|
67
|
-
indexes: [
|
|
68
|
-
{ fields: ['name'] },
|
|
69
|
-
]
|
|
76
|
+
iconClassName: "bi bi-people-fill",
|
|
77
|
+
indexes: [{ fields: ["name"] }],
|
|
70
78
|
};
|
|
71
79
|
let GroupsTable = (() => {
|
|
72
80
|
let _classSuper = table_1.Table;
|
|
@@ -96,7 +104,7 @@ let GroupsTable = (() => {
|
|
|
96
104
|
}
|
|
97
105
|
async signAndSave(group, opts) {
|
|
98
106
|
if (!GroupsTable.addSignatureToGroup) {
|
|
99
|
-
throw new Error(
|
|
107
|
+
throw new Error("Group signing must be enabled to sign and save groups. Call GroupsTable.enableGroupSigning(fn) to enable it.");
|
|
100
108
|
}
|
|
101
109
|
group = GroupsTable.addSignatureToGroup(group);
|
|
102
110
|
return this.save(group, opts);
|
|
@@ -107,19 +115,19 @@ let GroupsTable = (() => {
|
|
|
107
115
|
if (userContextGroups === this) {
|
|
108
116
|
return super.delete(groupId);
|
|
109
117
|
}
|
|
110
|
-
throw new Error(
|
|
118
|
+
throw new Error("Only deleting groups from the user context Groups table is allowed");
|
|
111
119
|
}
|
|
112
120
|
static addSignatureToGroup = undefined;
|
|
113
121
|
static enableGroupSigning(fn) {
|
|
114
|
-
|
|
122
|
+
GroupsTable.addSignatureToGroup = fn;
|
|
115
123
|
}
|
|
116
124
|
/** @deprecated Direct inserts forbidden; use save() */
|
|
117
125
|
insert(..._args) {
|
|
118
|
-
throw new Error(
|
|
126
|
+
throw new Error("Direct inserts forbidden; use save()");
|
|
119
127
|
}
|
|
120
128
|
/** @deprecated Direct updates forbidden; use save() */
|
|
121
129
|
update(..._args) {
|
|
122
|
-
throw new Error(
|
|
130
|
+
throw new Error("Direct updates forbidden; use save()");
|
|
123
131
|
}
|
|
124
132
|
constructor() {
|
|
125
133
|
super(...arguments);
|
package/dist/data/groups.test.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const keys_1 = require("../keys");
|
|
4
4
|
const group_member_roles_1 = require("./group-member-roles");
|
|
5
5
|
// Test the signature logic directly without full ORM dependencies
|
|
6
|
-
describe(
|
|
6
|
+
describe("Groups Signature Logic", () => {
|
|
7
7
|
let testGroup;
|
|
8
8
|
let ownerKeys;
|
|
9
9
|
let adminKeys;
|
|
@@ -13,86 +13,86 @@ describe('Groups Signature Logic', () => {
|
|
|
13
13
|
adminKeys = (0, keys_1.newKeys)();
|
|
14
14
|
unauthorizedKeys = (0, keys_1.newKeys)();
|
|
15
15
|
testGroup = {
|
|
16
|
-
groupId:
|
|
17
|
-
name:
|
|
18
|
-
description:
|
|
16
|
+
groupId: "test-group-1",
|
|
17
|
+
name: "Test Group",
|
|
18
|
+
description: "A test group",
|
|
19
19
|
publicRole: group_member_roles_1.GroupMemberRole.Reader,
|
|
20
20
|
disabled: false,
|
|
21
|
-
signature:
|
|
22
|
-
founderUserId:
|
|
21
|
+
signature: "",
|
|
22
|
+
founderUserId: "",
|
|
23
23
|
publicKey: ownerKeys.publicKey,
|
|
24
|
-
publicBoxKey: ownerKeys.publicKey
|
|
24
|
+
publicBoxKey: ownerKeys.publicKey,
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
|
-
describe(
|
|
28
|
-
it(
|
|
27
|
+
describe("basic signature functionality", () => {
|
|
28
|
+
it("should add signature to group object", () => {
|
|
29
29
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
30
30
|
expect(signedGroup.signature).toBeTruthy();
|
|
31
|
-
expect(signedGroup.signature).toContain(
|
|
31
|
+
expect(signedGroup.signature).toContain(":");
|
|
32
32
|
expect(signedGroup.name).toBe(testGroup.name);
|
|
33
33
|
expect(signedGroup.groupId).toBe(testGroup.groupId);
|
|
34
34
|
});
|
|
35
|
-
it(
|
|
35
|
+
it("should verify valid signature", () => {
|
|
36
36
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
37
37
|
const isValid = (0, keys_1.isObjectSignatureValid)(signedGroup);
|
|
38
38
|
expect(isValid).toBe(true);
|
|
39
39
|
});
|
|
40
|
-
it(
|
|
40
|
+
it("should reject invalid signature after modification", () => {
|
|
41
41
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
42
42
|
// Modify the group after signing
|
|
43
|
-
signedGroup.name =
|
|
43
|
+
signedGroup.name = "Modified Name";
|
|
44
44
|
const isValid = (0, keys_1.isObjectSignatureValid)(signedGroup);
|
|
45
45
|
expect(isValid).toBe(false);
|
|
46
46
|
});
|
|
47
|
-
it(
|
|
47
|
+
it("should extract correct public key from signature", () => {
|
|
48
48
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
49
49
|
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
50
50
|
expect(extractedKey).toBe(ownerKeys.publicKey);
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
|
-
describe(
|
|
54
|
-
it(
|
|
53
|
+
describe("basic signing with different keys", () => {
|
|
54
|
+
it("should create valid signature with owner key", () => {
|
|
55
55
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
56
56
|
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
57
57
|
expect(extractedKey).toBe(ownerKeys.publicKey);
|
|
58
58
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
59
59
|
});
|
|
60
|
-
it(
|
|
60
|
+
it("should create valid signature with admin key", () => {
|
|
61
61
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, adminKeys.secretKey);
|
|
62
62
|
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
63
63
|
expect(extractedKey).toBe(adminKeys.publicKey);
|
|
64
64
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
65
65
|
});
|
|
66
|
-
it(
|
|
66
|
+
it("should create valid signature with any key", () => {
|
|
67
67
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, unauthorizedKeys.secretKey);
|
|
68
68
|
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
69
69
|
expect(extractedKey).toBe(unauthorizedKeys.publicKey);
|
|
70
70
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true); // Signature is cryptographically valid
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
|
-
describe(
|
|
74
|
-
it(
|
|
73
|
+
describe("signature tampering detection", () => {
|
|
74
|
+
it("should detect tampered signature", () => {
|
|
75
75
|
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
76
76
|
// Tamper with signature by adding extra characters
|
|
77
|
-
signedGroup.signature = signedGroup.signature
|
|
77
|
+
signedGroup.signature = `${signedGroup.signature}tampered`;
|
|
78
78
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(false);
|
|
79
79
|
});
|
|
80
|
-
it(
|
|
81
|
-
testGroup.signature =
|
|
80
|
+
it("should detect empty signature", () => {
|
|
81
|
+
testGroup.signature = "";
|
|
82
82
|
expect((0, keys_1.isObjectSignatureValid)(testGroup)).toBe(false);
|
|
83
83
|
});
|
|
84
|
-
it(
|
|
85
|
-
testGroup.signature =
|
|
84
|
+
it("should detect malformed signature", () => {
|
|
85
|
+
testGroup.signature = "malformed-signature";
|
|
86
86
|
expect((0, keys_1.isObjectSignatureValid)(testGroup)).toBe(false);
|
|
87
87
|
});
|
|
88
|
-
it(
|
|
89
|
-
testGroup.signature =
|
|
88
|
+
it("should handle signature without colon separator", () => {
|
|
89
|
+
testGroup.signature = "noseparator";
|
|
90
90
|
expect((0, keys_1.isObjectSignatureValid)(testGroup)).toBe(false);
|
|
91
91
|
expect((0, keys_1.getPublicKeyFromObjectSignature)(testGroup)).toBeUndefined();
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
-
describe(
|
|
95
|
-
it(
|
|
94
|
+
describe("complex group objects", () => {
|
|
95
|
+
it("should handle groups with all optional fields", () => {
|
|
96
96
|
const complexGroup = {
|
|
97
97
|
...testGroup,
|
|
98
98
|
publicRole: group_member_roles_1.GroupMemberRole.Writer,
|
|
@@ -103,15 +103,15 @@ describe('Groups Signature Logic', () => {
|
|
|
103
103
|
expect(signedGroup.publicRole).toBe(group_member_roles_1.GroupMemberRole.Writer);
|
|
104
104
|
expect(signedGroup.disabled).toBe(true);
|
|
105
105
|
});
|
|
106
|
-
it(
|
|
106
|
+
it("should handle groups without optional fields", () => {
|
|
107
107
|
const simpleGroup = {
|
|
108
108
|
groupId: testGroup.groupId,
|
|
109
109
|
name: testGroup.name,
|
|
110
110
|
description: testGroup.description,
|
|
111
|
-
signature:
|
|
112
|
-
founderUserId:
|
|
111
|
+
signature: "",
|
|
112
|
+
founderUserId: "",
|
|
113
113
|
publicKey: ownerKeys.publicKey,
|
|
114
|
-
publicBoxKey: ownerKeys.publicKey
|
|
114
|
+
publicBoxKey: ownerKeys.publicKey,
|
|
115
115
|
};
|
|
116
116
|
const signedGroup = (0, keys_1.addSignatureToObject)(simpleGroup, ownerKeys.secretKey);
|
|
117
117
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
@@ -119,32 +119,32 @@ describe('Groups Signature Logic', () => {
|
|
|
119
119
|
expect(signedGroup.disabled).toBeUndefined();
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
-
describe(
|
|
123
|
-
it(
|
|
122
|
+
describe("edge cases", () => {
|
|
123
|
+
it("should handle long group names and descriptions", () => {
|
|
124
124
|
const longGroup = {
|
|
125
125
|
...testGroup,
|
|
126
|
-
name:
|
|
127
|
-
description:
|
|
126
|
+
name: "A".repeat(1000),
|
|
127
|
+
description: "B".repeat(5000),
|
|
128
128
|
};
|
|
129
129
|
const signedGroup = (0, keys_1.addSignatureToObject)(longGroup, ownerKeys.secretKey);
|
|
130
130
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
131
131
|
});
|
|
132
|
-
it(
|
|
132
|
+
it("should handle special characters in group data", () => {
|
|
133
133
|
const specialGroup = {
|
|
134
134
|
...testGroup,
|
|
135
135
|
name: 'Group with 🚀 emojis and "quotes" & <html>',
|
|
136
|
-
description:
|
|
136
|
+
description: "Contains\nnewlines\tand\ttabs",
|
|
137
137
|
};
|
|
138
138
|
const signedGroup = (0, keys_1.addSignatureToObject)(specialGroup, ownerKeys.secretKey);
|
|
139
139
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
140
|
-
expect(signedGroup.name).toContain(
|
|
141
|
-
expect(signedGroup.description).toContain(
|
|
140
|
+
expect(signedGroup.name).toContain("🚀");
|
|
141
|
+
expect(signedGroup.description).toContain("\n");
|
|
142
142
|
});
|
|
143
|
-
it(
|
|
143
|
+
it("should handle empty strings", () => {
|
|
144
144
|
const emptyGroup = {
|
|
145
145
|
...testGroup,
|
|
146
|
-
name:
|
|
147
|
-
description:
|
|
146
|
+
name: "",
|
|
147
|
+
description: "",
|
|
148
148
|
};
|
|
149
149
|
const signedGroup = (0, keys_1.addSignatureToObject)(emptyGroup, ownerKeys.secretKey);
|
|
150
150
|
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
export * from "./assistants";
|
|
2
|
-
export * from "./channels";
|
|
3
2
|
export * from "./change-tracking";
|
|
3
|
+
export * from "./channels";
|
|
4
4
|
export * from "./data-locks";
|
|
5
5
|
export * from "./device-sync-info";
|
|
6
6
|
export * from "./devices";
|
|
7
7
|
export * from "./embeddings";
|
|
8
8
|
export * from "./files";
|
|
9
|
-
export * from "./group-permissions";
|
|
10
|
-
export * from "./groups";
|
|
11
|
-
export * from "./group-members";
|
|
12
9
|
export * from "./group-member-roles";
|
|
10
|
+
export * from "./group-members";
|
|
11
|
+
export * from "./group-permissions";
|
|
13
12
|
export * from "./group-share";
|
|
13
|
+
export * from "./groups";
|
|
14
14
|
export * from "./knowledge/peer-types";
|
|
15
15
|
export * from "./messages";
|
|
16
16
|
export * from "./package-versions";
|
|
17
17
|
export * from "./packages";
|
|
18
18
|
export * from "./packages.utils";
|
|
19
|
-
export * from "./table-definitions-table";
|
|
20
19
|
export * from "./persistent-vars";
|
|
20
|
+
export * from "./table-definitions-table";
|
|
21
21
|
export * from "./tool-tests";
|
|
22
22
|
export * from "./tools";
|
|
23
|
-
export * from "./users";
|
|
24
23
|
export * from "./user-permissions";
|
|
25
24
|
export * from "./user-trust-levels";
|
|
25
|
+
export * from "./users";
|
|
26
26
|
export * from "./voice-messages";
|
|
27
27
|
export * from "./welcome-modal.pvar";
|
|
28
28
|
export * from "./workflow-logs";
|
package/dist/data/index.js
CHANGED
|
@@ -15,30 +15,30 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./assistants"), exports);
|
|
18
|
-
__exportStar(require("./channels"), exports);
|
|
19
18
|
__exportStar(require("./change-tracking"), exports);
|
|
19
|
+
__exportStar(require("./channels"), exports);
|
|
20
20
|
__exportStar(require("./data-locks"), exports);
|
|
21
21
|
__exportStar(require("./device-sync-info"), exports);
|
|
22
22
|
__exportStar(require("./devices"), exports);
|
|
23
23
|
__exportStar(require("./embeddings"), exports);
|
|
24
24
|
__exportStar(require("./files"), exports);
|
|
25
|
-
__exportStar(require("./group-permissions"), exports);
|
|
26
|
-
__exportStar(require("./groups"), exports);
|
|
27
|
-
__exportStar(require("./group-members"), exports);
|
|
28
25
|
__exportStar(require("./group-member-roles"), exports);
|
|
26
|
+
__exportStar(require("./group-members"), exports);
|
|
27
|
+
__exportStar(require("./group-permissions"), exports);
|
|
29
28
|
__exportStar(require("./group-share"), exports);
|
|
29
|
+
__exportStar(require("./groups"), exports);
|
|
30
30
|
__exportStar(require("./knowledge/peer-types"), exports);
|
|
31
31
|
__exportStar(require("./messages"), exports);
|
|
32
32
|
__exportStar(require("./package-versions"), exports);
|
|
33
33
|
__exportStar(require("./packages"), exports);
|
|
34
34
|
__exportStar(require("./packages.utils"), exports);
|
|
35
|
-
__exportStar(require("./table-definitions-table"), exports);
|
|
36
35
|
__exportStar(require("./persistent-vars"), exports);
|
|
36
|
+
__exportStar(require("./table-definitions-table"), exports);
|
|
37
37
|
__exportStar(require("./tool-tests"), exports);
|
|
38
38
|
__exportStar(require("./tools"), exports);
|
|
39
|
-
__exportStar(require("./users"), exports);
|
|
40
39
|
__exportStar(require("./user-permissions"), exports);
|
|
41
40
|
__exportStar(require("./user-trust-levels"), exports);
|
|
41
|
+
__exportStar(require("./users"), exports);
|
|
42
42
|
__exportStar(require("./voice-messages"), exports);
|
|
43
43
|
__exportStar(require("./welcome-modal.pvar"), exports);
|
|
44
44
|
__exportStar(require("./workflow-logs"), exports);
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PeerTypes = PeerTypes;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const types_1 = require("../orm/types");
|
|
6
5
|
const user_context_singleton_1 = require("../../context/user-context-singleton");
|
|
7
|
-
const table_definitions_system_1 = require("../orm/table-definitions.system");
|
|
8
6
|
const zod_types_1 = require("../../types/zod-types");
|
|
7
|
+
const table_definitions_system_1 = require("../orm/table-definitions.system");
|
|
8
|
+
const types_1 = require("../orm/types");
|
|
9
9
|
const tools_1 = require("../tools");
|
|
10
10
|
const valueTypeSchema = zod_1.z.object({
|
|
11
11
|
peerTypeId: zod_types_1.zodPeerId,
|
|
12
|
-
name: zod_1.z.string().describe(
|
|
13
|
-
description: zod_1.z.string().optional().describe(
|
|
14
|
-
schema: tools_1.ioSchema.describe(
|
|
15
|
-
iconClass: zod_1.z.string().optional().describe(
|
|
12
|
+
name: zod_1.z.string().describe("The name of the peer type"),
|
|
13
|
+
description: zod_1.z.string().optional().describe("The description of the peer type"),
|
|
14
|
+
schema: tools_1.ioSchema.describe("The schema of the peer type"),
|
|
15
|
+
iconClass: zod_1.z.string().optional().describe("The icon class for the peer type"),
|
|
16
16
|
});
|
|
17
17
|
const metaData = {
|
|
18
|
-
name:
|
|
18
|
+
name: "PeerTypes",
|
|
19
19
|
description: "The peer types in the system",
|
|
20
|
-
primaryKeyName:
|
|
21
|
-
iconClassName:
|
|
20
|
+
primaryKeyName: "peerTypeId",
|
|
21
|
+
iconClassName: "bi bi-code-square",
|
|
22
22
|
fields: (0, types_1.schemaToFields)(valueTypeSchema),
|
|
23
23
|
};
|
|
24
24
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, valueTypeSchema);
|
package/dist/data/messages.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from
|
|
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 messageSchema: z.ZodObject<{
|
|
4
4
|
messageId: z.ZodEffects<z.ZodString, string, string>;
|
|
5
5
|
channelId: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -13,8 +13,8 @@ export declare const messageSchema: z.ZodObject<{
|
|
|
13
13
|
vars: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
|
14
14
|
}, "strip", z.ZodTypeAny, {
|
|
15
15
|
message: string;
|
|
16
|
-
createdAt: Date;
|
|
17
16
|
userId: string;
|
|
17
|
+
createdAt: Date;
|
|
18
18
|
channelId: string;
|
|
19
19
|
messageId: string;
|
|
20
20
|
assistantId?: string | undefined;
|
|
@@ -24,8 +24,8 @@ export declare const messageSchema: z.ZodObject<{
|
|
|
24
24
|
fileIds?: string[] | undefined;
|
|
25
25
|
}, {
|
|
26
26
|
message: string;
|
|
27
|
-
createdAt: Date;
|
|
28
27
|
userId: string;
|
|
28
|
+
createdAt: Date;
|
|
29
29
|
channelId: string;
|
|
30
30
|
messageId: string;
|
|
31
31
|
assistantId?: string | undefined;
|
|
@@ -37,8 +37,8 @@ export declare const messageSchema: z.ZodObject<{
|
|
|
37
37
|
export type IMessage = z.infer<typeof messageSchema>;
|
|
38
38
|
export declare function Messages(dataContext?: DataContext): import("./orm").Table<{
|
|
39
39
|
message: string;
|
|
40
|
-
createdAt: Date;
|
|
41
40
|
userId: string;
|
|
41
|
+
createdAt: Date;
|
|
42
42
|
channelId: string;
|
|
43
43
|
messageId: string;
|
|
44
44
|
assistantId?: string | undefined;
|