@peers-app/peers-sdk 0.7.2 → 0.7.3
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 +1 -1
- package/dist/context/data-context.js +2 -3
- package/dist/context/user-context-singleton.js +6 -30
- package/dist/context/user-context.d.ts +1 -3
- package/dist/context/user-context.js +9 -6
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/change-tracking.d.ts +16 -16
- package/dist/data/channels.d.ts +1 -1
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/devices.d.ts +4 -4
- package/dist/data/embeddings.d.ts +1 -1
- package/dist/data/group-members.d.ts +7 -4
- package/dist/data/group-members.js +98 -32
- package/dist/data/groups.d.ts +7 -3
- package/dist/data/groups.js +91 -30
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.js +1 -0
- package/dist/data/knowledge/knowledge-frames.d.ts +1 -1
- package/dist/data/knowledge/knowledge-links.d.ts +1 -1
- package/dist/data/knowledge/knowledge-values.d.ts +1 -1
- package/dist/data/knowledge/peer-types.d.ts +1 -1
- package/dist/data/knowledge/predicates.d.ts +1 -1
- package/dist/data/messages.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +8 -18
- package/dist/data/orm/decorators.d.ts +1 -1
- package/dist/data/orm/decorators.js +7 -7
- package/dist/data/packages.d.ts +2 -1
- package/dist/data/packages.js +90 -40
- package/dist/data/peer-events/peer-event-handlers.d.ts +1 -1
- package/dist/data/peer-events/peer-event-types.d.ts +1 -1
- package/dist/data/tool-tests.d.ts +1 -1
- package/dist/data/tools.d.ts +1 -1
- package/dist/data/user-permissions.test.js +7 -10
- package/dist/data/user-trust-levels.d.ts +42 -0
- package/dist/data/user-trust-levels.js +60 -0
- package/dist/data/users.d.ts +7 -7
- package/dist/data/users.js +86 -27
- package/dist/data/workflow-logs.d.ts +1 -1
- package/dist/data/workflow-runs.js +1 -1
- package/dist/data/workflows.d.ts +1 -1
- package/dist/device/get-trust-level.js +9 -5
- package/dist/rpc-types.d.ts +0 -11
- package/dist/rpc-types.js +0 -7
- package/dist/users.query.d.ts +3 -1
- package/dist/users.query.js +39 -11
- package/package.json +1 -1
|
@@ -10,8 +10,8 @@ export declare class DataContext {
|
|
|
10
10
|
readonly tableContainer: TableContainer;
|
|
11
11
|
readonly packageLoader: PackageLoader;
|
|
12
12
|
readonly eventRegistry: EventRegistry;
|
|
13
|
+
readonly dataContextId: string;
|
|
13
14
|
constructor(userContext: UserContext, groupId?: string | undefined);
|
|
14
|
-
get dataContextId(): string;
|
|
15
15
|
/**
|
|
16
16
|
* Call this to indicate that this should be the current data context to be used unless otherwise specified
|
|
17
17
|
*/
|
|
@@ -10,9 +10,11 @@ class DataContext {
|
|
|
10
10
|
tableContainer;
|
|
11
11
|
packageLoader;
|
|
12
12
|
eventRegistry;
|
|
13
|
+
dataContextId;
|
|
13
14
|
constructor(userContext, groupId) {
|
|
14
15
|
this.userContext = userContext;
|
|
15
16
|
this.groupId = groupId;
|
|
17
|
+
this.dataContextId = groupId || userContext.userId;
|
|
16
18
|
// Initialize dependencies in the correct order to avoid circular references
|
|
17
19
|
this.eventRegistry = new orm_1.EventRegistry(this.dataContextId);
|
|
18
20
|
this.packageLoader = new package_loader_1.PackageLoader(this);
|
|
@@ -23,9 +25,6 @@ class DataContext {
|
|
|
23
25
|
const tableFactory = (metaData, schema, TableClass) => this.createTable(metaData, schema, TableClass);
|
|
24
26
|
this.tableContainer = new orm_1.TableContainer(tableFactory, groupId);
|
|
25
27
|
}
|
|
26
|
-
get dataContextId() {
|
|
27
|
-
return this.groupId || this.userContext.userId;
|
|
28
|
-
}
|
|
29
28
|
/**
|
|
30
29
|
* Call this to indicate that this should be the current data context to be used unless otherwise specified
|
|
31
30
|
*/
|
|
@@ -86,38 +86,14 @@ if (!rpc_types_1.isClient) {
|
|
|
86
86
|
.getTable(tableName);
|
|
87
87
|
return table;
|
|
88
88
|
}
|
|
89
|
-
// TODO: add check that client has permission to
|
|
90
|
-
rpc_types_1.rpcServerCalls.tableGet = async (dataContextId, tableName, id) => {
|
|
91
|
-
const table = await getTable(dataContextId, tableName);
|
|
92
|
-
return table.get(id);
|
|
93
|
-
};
|
|
94
|
-
rpc_types_1.rpcServerCalls.tableList = async (dataContextId, tableName, filter, opts) => {
|
|
95
|
-
const table = await getTable(dataContextId, tableName);
|
|
96
|
-
return table.list(filter, opts);
|
|
97
|
-
};
|
|
98
|
-
rpc_types_1.rpcServerCalls.tableCount = async (dataContextId, tableName, filter) => {
|
|
99
|
-
const table = await getTable(dataContextId, tableName);
|
|
100
|
-
return table.count(filter);
|
|
101
|
-
};
|
|
102
|
-
rpc_types_1.rpcServerCalls.tableSave = async (dataContextId, tableName, data, opts) => {
|
|
103
|
-
const table = await getTable(dataContextId, tableName);
|
|
104
|
-
return table.save(data, opts);
|
|
105
|
-
};
|
|
106
|
-
rpc_types_1.rpcServerCalls.tableInsert = async (dataContextId, tableName, data) => {
|
|
107
|
-
const table = await getTable(dataContextId, tableName);
|
|
108
|
-
return table.insert(data);
|
|
109
|
-
};
|
|
110
|
-
rpc_types_1.rpcServerCalls.tableUpdate = async (dataContextId, tableName, data) => {
|
|
111
|
-
const table = await getTable(dataContextId, tableName);
|
|
112
|
-
return table.update(data);
|
|
113
|
-
};
|
|
114
|
-
rpc_types_1.rpcServerCalls.tableDelete = async (dataContextId, tableName, idOrRecord) => {
|
|
115
|
-
const table = await getTable(dataContextId, tableName);
|
|
116
|
-
return table.delete(idOrRecord);
|
|
117
|
-
};
|
|
89
|
+
// TODO: add check that client has permission to make this call
|
|
118
90
|
rpc_types_1.rpcServerCalls.tableMethodCall = async (dataContextId, tableName, methodName, ...args) => {
|
|
119
91
|
const table = await getTable(dataContextId, tableName);
|
|
120
|
-
|
|
92
|
+
const method = table[methodName];
|
|
93
|
+
if (typeof method !== 'function') {
|
|
94
|
+
throw new Error(`Method ${methodName} not found on table ${tableName}`);
|
|
95
|
+
}
|
|
96
|
+
// @ts-ignore - call this way to ensure 'this' is correct
|
|
121
97
|
return table[methodName](...args);
|
|
122
98
|
};
|
|
123
99
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DataContext } from "../context/data-context";
|
|
2
2
|
import { IUser } from "../data";
|
|
3
3
|
import type { DataSourceFactory, IDataChangedEvent, Table } from "../data/orm";
|
|
4
|
-
import { TrustLevel } from "../device/socket.type";
|
|
5
4
|
import { IPublicPrivateKeys } from "../keys";
|
|
6
5
|
import { Observable } from "../observable";
|
|
7
6
|
export declare class UserContext {
|
|
@@ -34,10 +33,9 @@ export declare class UserContext {
|
|
|
34
33
|
getMe(): Promise<{
|
|
35
34
|
name: string;
|
|
36
35
|
publicKey: string;
|
|
37
|
-
publicBoxKey: string;
|
|
38
36
|
userId: string;
|
|
37
|
+
publicBoxKey: string;
|
|
39
38
|
signature?: string | undefined;
|
|
40
|
-
trustLevel?: TrustLevel | undefined;
|
|
41
39
|
} | undefined>;
|
|
42
40
|
syncUserAndGroupObjects(userId: string, keys: IPublicPrivateKeys, me?: IUser): Promise<void>;
|
|
43
41
|
subscribeToDataChangedAcrossAllGroups<T extends {
|
|
@@ -4,7 +4,6 @@ exports.UserContext = void 0;
|
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const data_context_1 = require("../context/data-context");
|
|
6
6
|
const data_1 = require("../data");
|
|
7
|
-
const socket_type_1 = require("../device/socket.type");
|
|
8
7
|
const events_1 = require("../events");
|
|
9
8
|
const keys_1 = require("../keys");
|
|
10
9
|
const observable_1 = require("../observable");
|
|
@@ -148,7 +147,6 @@ class UserContext {
|
|
|
148
147
|
name: 'Unnamed_1',
|
|
149
148
|
publicKey: '',
|
|
150
149
|
publicBoxKey: '',
|
|
151
|
-
trustLevel: socket_type_1.TrustLevel.Self,
|
|
152
150
|
};
|
|
153
151
|
}
|
|
154
152
|
me.publicKey = keys.publicKey;
|
|
@@ -162,9 +160,8 @@ class UserContext {
|
|
|
162
160
|
// sync my user to all all my groups
|
|
163
161
|
for (const [, dataContext] of userContext.groupDataContexts) {
|
|
164
162
|
let groupMe = await (0, data_1.Users)(dataContext).get(me.userId);
|
|
165
|
-
if (!
|
|
166
|
-
|
|
167
|
-
await (0, data_1.Users)(dataContext).save(groupMe);
|
|
163
|
+
if (!(0, lodash_1.isEqual)(groupMe, meSigned)) {
|
|
164
|
+
await (0, data_1.Users)(dataContext).save(meSigned);
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
// sync group objects to my personal db
|
|
@@ -176,7 +173,13 @@ class UserContext {
|
|
|
176
173
|
const groupObject = await (0, data_1.Groups)(dataContext).get(dataContext.groupId);
|
|
177
174
|
const myGroupObject = await (0, data_1.Groups)(this.userDataContext).get(dataContext.groupId);
|
|
178
175
|
if (groupObject && !(0, lodash_1.isEqual)(groupObject, myGroupObject)) {
|
|
179
|
-
|
|
176
|
+
try {
|
|
177
|
+
(0, keys_1.verifyObjectSignature)(groupObject);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
console.error(`Error verifying group object from group ${dataContext.groupId}:`, err);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
180
183
|
await (0, data_1.Groups)(this.userDataContext).save(groupObject);
|
|
181
184
|
}
|
|
182
185
|
}
|
|
@@ -39,7 +39,7 @@ export declare const assistantSchema: z.ZodObject<{
|
|
|
39
39
|
toolInclusionStrategy?: ToolInclusionStrategy | undefined;
|
|
40
40
|
}>;
|
|
41
41
|
export type IAssistant = z.infer<typeof assistantSchema>;
|
|
42
|
-
export declare function Assistants(dataContext?: DataContext): import("
|
|
42
|
+
export declare function Assistants(dataContext?: DataContext): import("./orm").Table<{
|
|
43
43
|
name: string;
|
|
44
44
|
createdAt: Date;
|
|
45
45
|
assistantId: string;
|
|
@@ -10,22 +10,22 @@ declare const insertChange: z.ZodObject<{
|
|
|
10
10
|
recordId: z.ZodString;
|
|
11
11
|
newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
|
12
12
|
}, "strip", z.ZodTypeAny, {
|
|
13
|
-
recordId: string;
|
|
14
13
|
changeId: string;
|
|
15
14
|
changeType: "insert" | "snapshot" | "restore";
|
|
16
15
|
timestamp: number;
|
|
17
16
|
timestampApplied: number;
|
|
18
17
|
tableName: string;
|
|
18
|
+
recordId: string;
|
|
19
19
|
newRecord: {} & {
|
|
20
20
|
[k: string]: any;
|
|
21
21
|
};
|
|
22
22
|
}, {
|
|
23
|
-
recordId: string;
|
|
24
23
|
changeId: string;
|
|
25
24
|
changeType: "insert" | "snapshot" | "restore";
|
|
26
25
|
timestamp: number;
|
|
27
26
|
timestampApplied: number;
|
|
28
27
|
tableName: string;
|
|
28
|
+
recordId: string;
|
|
29
29
|
newRecord: {} & {
|
|
30
30
|
[k: string]: any;
|
|
31
31
|
};
|
|
@@ -40,20 +40,20 @@ declare const deleteChange: z.ZodObject<{
|
|
|
40
40
|
recordId: z.ZodString;
|
|
41
41
|
oldRecord: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
|
42
42
|
}, "strip", z.ZodTypeAny, {
|
|
43
|
-
recordId: string;
|
|
44
43
|
changeId: string;
|
|
45
44
|
changeType: "delete";
|
|
46
45
|
timestamp: number;
|
|
47
46
|
timestampApplied: number;
|
|
48
47
|
tableName: string;
|
|
48
|
+
recordId: string;
|
|
49
49
|
oldRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
|
50
50
|
}, {
|
|
51
|
-
recordId: string;
|
|
52
51
|
changeId: string;
|
|
53
52
|
changeType: "delete";
|
|
54
53
|
timestamp: number;
|
|
55
54
|
timestampApplied: number;
|
|
56
55
|
tableName: string;
|
|
56
|
+
recordId: string;
|
|
57
57
|
oldRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
58
58
|
}>;
|
|
59
59
|
export type IChangeDelete = z.infer<typeof deleteChange>;
|
|
@@ -67,23 +67,23 @@ declare const updateChange: z.ZodObject<{
|
|
|
67
67
|
newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
|
68
68
|
jsonDiff: z.ZodArray<z.ZodAny, "many">;
|
|
69
69
|
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
recordId: string;
|
|
71
70
|
changeId: string;
|
|
72
71
|
changeType: "update";
|
|
73
72
|
timestamp: number;
|
|
74
73
|
timestampApplied: number;
|
|
75
74
|
tableName: string;
|
|
75
|
+
recordId: string;
|
|
76
76
|
newRecord: {} & {
|
|
77
77
|
[k: string]: any;
|
|
78
78
|
};
|
|
79
79
|
jsonDiff: any[];
|
|
80
80
|
}, {
|
|
81
|
-
recordId: string;
|
|
82
81
|
changeId: string;
|
|
83
82
|
changeType: "update";
|
|
84
83
|
timestamp: number;
|
|
85
84
|
timestampApplied: number;
|
|
86
85
|
tableName: string;
|
|
86
|
+
recordId: string;
|
|
87
87
|
newRecord: {} & {
|
|
88
88
|
[k: string]: any;
|
|
89
89
|
};
|
|
@@ -99,22 +99,22 @@ declare const changeSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
99
99
|
recordId: z.ZodString;
|
|
100
100
|
newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
|
101
101
|
}, "strip", z.ZodTypeAny, {
|
|
102
|
-
recordId: string;
|
|
103
102
|
changeId: string;
|
|
104
103
|
changeType: "insert" | "snapshot" | "restore";
|
|
105
104
|
timestamp: number;
|
|
106
105
|
timestampApplied: number;
|
|
107
106
|
tableName: string;
|
|
107
|
+
recordId: string;
|
|
108
108
|
newRecord: {} & {
|
|
109
109
|
[k: string]: any;
|
|
110
110
|
};
|
|
111
111
|
}, {
|
|
112
|
-
recordId: string;
|
|
113
112
|
changeId: string;
|
|
114
113
|
changeType: "insert" | "snapshot" | "restore";
|
|
115
114
|
timestamp: number;
|
|
116
115
|
timestampApplied: number;
|
|
117
116
|
tableName: string;
|
|
117
|
+
recordId: string;
|
|
118
118
|
newRecord: {} & {
|
|
119
119
|
[k: string]: any;
|
|
120
120
|
};
|
|
@@ -127,20 +127,20 @@ declare const changeSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
127
127
|
recordId: z.ZodString;
|
|
128
128
|
oldRecord: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
|
129
129
|
}, "strip", z.ZodTypeAny, {
|
|
130
|
-
recordId: string;
|
|
131
130
|
changeId: string;
|
|
132
131
|
changeType: "delete";
|
|
133
132
|
timestamp: number;
|
|
134
133
|
timestampApplied: number;
|
|
135
134
|
tableName: string;
|
|
135
|
+
recordId: string;
|
|
136
136
|
oldRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
|
137
137
|
}, {
|
|
138
|
-
recordId: string;
|
|
139
138
|
changeId: string;
|
|
140
139
|
changeType: "delete";
|
|
141
140
|
timestamp: number;
|
|
142
141
|
timestampApplied: number;
|
|
143
142
|
tableName: string;
|
|
143
|
+
recordId: string;
|
|
144
144
|
oldRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
145
145
|
}>, z.ZodObject<{
|
|
146
146
|
changeId: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -152,23 +152,23 @@ declare const changeSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
152
152
|
newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
|
153
153
|
jsonDiff: z.ZodArray<z.ZodAny, "many">;
|
|
154
154
|
}, "strip", z.ZodTypeAny, {
|
|
155
|
-
recordId: string;
|
|
156
155
|
changeId: string;
|
|
157
156
|
changeType: "update";
|
|
158
157
|
timestamp: number;
|
|
159
158
|
timestampApplied: number;
|
|
160
159
|
tableName: string;
|
|
160
|
+
recordId: string;
|
|
161
161
|
newRecord: {} & {
|
|
162
162
|
[k: string]: any;
|
|
163
163
|
};
|
|
164
164
|
jsonDiff: any[];
|
|
165
165
|
}, {
|
|
166
|
-
recordId: string;
|
|
167
166
|
changeId: string;
|
|
168
167
|
changeType: "update";
|
|
169
168
|
timestamp: number;
|
|
170
169
|
timestampApplied: number;
|
|
171
170
|
tableName: string;
|
|
171
|
+
recordId: string;
|
|
172
172
|
newRecord: {} & {
|
|
173
173
|
[k: string]: any;
|
|
174
174
|
};
|
|
@@ -186,25 +186,25 @@ export declare const changeTrackingSchema: z.ZodObject<{
|
|
|
186
186
|
newRecord: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
|
187
187
|
jsonDiff: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
188
188
|
}, "strip", z.ZodTypeAny, {
|
|
189
|
-
recordId: string;
|
|
190
189
|
changeId: string;
|
|
191
190
|
changeType: "update" | "insert" | "delete" | "snapshot" | "restore";
|
|
192
191
|
timestamp: number;
|
|
193
192
|
timestampApplied: number;
|
|
194
193
|
tableName: string;
|
|
194
|
+
recordId: string;
|
|
195
195
|
newRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
|
196
|
-
jsonDiff?: any[] | undefined;
|
|
197
196
|
oldRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
|
197
|
+
jsonDiff?: any[] | undefined;
|
|
198
198
|
}, {
|
|
199
|
-
recordId: string;
|
|
200
199
|
changeId: string;
|
|
201
200
|
changeType: "update" | "insert" | "delete" | "snapshot" | "restore";
|
|
202
201
|
timestamp: number;
|
|
203
202
|
timestampApplied: number;
|
|
204
203
|
tableName: string;
|
|
204
|
+
recordId: string;
|
|
205
205
|
newRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
206
|
-
jsonDiff?: any[] | undefined;
|
|
207
206
|
oldRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
207
|
+
jsonDiff?: any[] | undefined;
|
|
208
208
|
}>;
|
|
209
209
|
export type IChangeAny = z.infer<typeof changeTrackingSchema>;
|
|
210
210
|
export declare class ChangeTrackingTable extends SQLDataSource<IChange> {
|
package/dist/data/channels.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const channelSchema: z.ZodObject<{
|
|
|
20
20
|
owningGroupId: string;
|
|
21
21
|
}>;
|
|
22
22
|
export type IChannel = z.infer<typeof channelSchema>;
|
|
23
|
-
export declare function Channels(dataContext?: DataContext): import("
|
|
23
|
+
export declare function Channels(dataContext?: DataContext): import("./orm").Table<{
|
|
24
24
|
name: string;
|
|
25
25
|
description: string;
|
|
26
26
|
createdAt: Date;
|
|
@@ -7,13 +7,13 @@ export declare const dataLockSchema: z.ZodObject<{
|
|
|
7
7
|
lockedUntil: z.ZodNumber;
|
|
8
8
|
acknowledged: z.ZodOptional<z.ZodNumber>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
dataLockId: string;
|
|
11
10
|
recordId: string;
|
|
11
|
+
dataLockId: string;
|
|
12
12
|
lockedUntil: number;
|
|
13
13
|
acknowledged?: number | undefined;
|
|
14
14
|
}, {
|
|
15
|
-
dataLockId: string;
|
|
16
15
|
recordId: string;
|
|
16
|
+
dataLockId: string;
|
|
17
17
|
lockedUntil: number;
|
|
18
18
|
acknowledged?: number | undefined;
|
|
19
19
|
}>;
|
package/dist/data/devices.d.ts
CHANGED
|
@@ -11,18 +11,18 @@ export declare const deviceSchema: z.ZodObject<{
|
|
|
11
11
|
trustLevel: z.ZodNativeEnum<typeof TrustLevel>;
|
|
12
12
|
}, "strip", z.ZodTypeAny, {
|
|
13
13
|
userId: string;
|
|
14
|
-
trustLevel: TrustLevel;
|
|
15
14
|
deviceId: string;
|
|
16
15
|
firstSeen: Date;
|
|
17
16
|
lastSeen: Date;
|
|
17
|
+
trustLevel: TrustLevel;
|
|
18
18
|
name?: string | undefined;
|
|
19
19
|
serverUrl?: string | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
userId: string;
|
|
22
|
-
trustLevel: TrustLevel;
|
|
23
22
|
deviceId: string;
|
|
24
23
|
firstSeen: Date;
|
|
25
24
|
lastSeen: Date;
|
|
25
|
+
trustLevel: TrustLevel;
|
|
26
26
|
name?: string | undefined;
|
|
27
27
|
serverUrl?: string | undefined;
|
|
28
28
|
}>;
|
|
@@ -38,12 +38,12 @@ export interface IDeviceHandshake extends IDeviceInfo {
|
|
|
38
38
|
serverAddress: string;
|
|
39
39
|
timestamp: number;
|
|
40
40
|
}
|
|
41
|
-
export declare function Devices(dataContext?: DataContext): import("
|
|
41
|
+
export declare function Devices(dataContext?: DataContext): import("./orm").Table<{
|
|
42
42
|
userId: string;
|
|
43
|
-
trustLevel: TrustLevel;
|
|
44
43
|
deviceId: string;
|
|
45
44
|
firstSeen: Date;
|
|
46
45
|
lastSeen: Date;
|
|
46
|
+
trustLevel: TrustLevel;
|
|
47
47
|
name?: string | undefined;
|
|
48
48
|
serverUrl?: string | undefined;
|
|
49
49
|
}>;
|
|
@@ -34,7 +34,7 @@ export declare const embeddingSchema: z.ZodObject<{
|
|
|
34
34
|
embeddingType: string;
|
|
35
35
|
}>;
|
|
36
36
|
export type IEmbedding = z.infer<typeof embeddingSchema>;
|
|
37
|
-
export declare function Embeddings(dataContext?: DataContext): import("
|
|
37
|
+
export declare function Embeddings(dataContext?: DataContext): import("./orm").Table<{
|
|
38
38
|
metadata: {
|
|
39
39
|
fkId?: string | undefined;
|
|
40
40
|
} & {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
|
-
import { Table } from "./orm";
|
|
4
3
|
import { GroupMemberRole } from './group-member-roles';
|
|
5
|
-
import { ISaveOptions } from "
|
|
4
|
+
import type { ISaveOptions } from "./orm/data-query";
|
|
5
|
+
import { Table } from "./orm/table";
|
|
6
6
|
export declare const groupMemberSchema: z.ZodObject<{
|
|
7
7
|
groupMemberId: z.ZodEffects<z.ZodString, string, string>;
|
|
8
8
|
groupId: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -13,16 +13,16 @@ export declare const groupMemberSchema: z.ZodObject<{
|
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
14
|
role: GroupMemberRole;
|
|
15
15
|
signature: string;
|
|
16
|
-
groupId: string;
|
|
17
16
|
userId: string;
|
|
18
17
|
groupMemberId: string;
|
|
18
|
+
groupId: string;
|
|
19
19
|
deleted?: boolean | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
role: GroupMemberRole;
|
|
22
22
|
signature: string;
|
|
23
|
-
groupId: string;
|
|
24
23
|
userId: string;
|
|
25
24
|
groupMemberId: string;
|
|
25
|
+
groupId: string;
|
|
26
26
|
deleted?: boolean | undefined;
|
|
27
27
|
}>;
|
|
28
28
|
export type IGroupMember = z.infer<typeof groupMemberSchema>;
|
|
@@ -30,7 +30,10 @@ export declare const groupMembersTableName = "GroupMembers";
|
|
|
30
30
|
export declare class GroupMembersTable extends Table<IGroupMember> {
|
|
31
31
|
static isPassthrough: boolean;
|
|
32
32
|
save(groupMember: IGroupMember, opts?: ISaveOptions): Promise<IGroupMember>;
|
|
33
|
+
signAndSave(groupMember: IGroupMember, opts?: ISaveOptions): Promise<IGroupMember>;
|
|
33
34
|
delete(groupMemberId: string): Promise<void>;
|
|
35
|
+
private static addSignatureToGroupMember;
|
|
36
|
+
static enableGroupMemberSigning(fn: (groupMember: IGroupMember) => IGroupMember): void;
|
|
34
37
|
/** @deprecated Forbidden on GroupsTable; use save() */
|
|
35
38
|
insert(..._args: Parameters<Table<IGroupMember>['insert']>): never;
|
|
36
39
|
/** @deprecated Forbidden on GroupsTable; use save() */
|
|
@@ -1,16 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
2
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
37
|
exports.GroupMembersTable = exports.groupMembersTableName = exports.groupMemberSchema = void 0;
|
|
4
38
|
exports.GroupMembers = GroupMembers;
|
|
5
39
|
const zod_1 = require("zod");
|
|
6
40
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
41
|
+
const decorators_1 = require("../data/orm/decorators");
|
|
7
42
|
const zod_types_1 = require("../types/zod-types");
|
|
8
|
-
const orm_1 = require("./orm");
|
|
9
|
-
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
10
|
-
const types_1 = require("./orm/types");
|
|
11
43
|
const group_member_roles_1 = require("./group-member-roles");
|
|
12
44
|
const group_permissions_1 = require("./group-permissions");
|
|
13
|
-
const
|
|
45
|
+
const table_1 = require("./orm/table");
|
|
46
|
+
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
47
|
+
const types_1 = require("./orm/types");
|
|
48
|
+
const users_1 = require("./users");
|
|
14
49
|
exports.groupMemberSchema = zod_1.z.object({
|
|
15
50
|
groupMemberId: zod_types_1.zodPeerId,
|
|
16
51
|
groupId: zod_types_1.zodPeerId.describe('The id of the group'),
|
|
@@ -29,38 +64,69 @@ const metaData = {
|
|
|
29
64
|
{ fields: ['groupId', 'userId'], unique: true },
|
|
30
65
|
]
|
|
31
66
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
67
|
+
let GroupMembersTable = (() => {
|
|
68
|
+
let _classSuper = table_1.Table;
|
|
69
|
+
let _instanceExtraInitializers = [];
|
|
70
|
+
let _signAndSave_decorators;
|
|
71
|
+
return class GroupMembersTable extends _classSuper {
|
|
72
|
+
static {
|
|
73
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
74
|
+
_signAndSave_decorators = [(0, decorators_1.ProxyClientTableMethodCalls)()];
|
|
75
|
+
__esDecorate(this, null, _signAndSave_decorators, { kind: "method", name: "signAndSave", static: false, private: false, access: { has: obj => "signAndSave" in obj, get: obj => obj.signAndSave }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
76
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
37
77
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
78
|
+
static isPassthrough = false;
|
|
79
|
+
async save(groupMember, opts) {
|
|
80
|
+
if (GroupMembersTable.isPassthrough) {
|
|
81
|
+
return super.save(groupMember, opts);
|
|
82
|
+
}
|
|
83
|
+
const me = await (0, users_1.getMe)();
|
|
84
|
+
if (groupMember.groupId === me.userId) {
|
|
85
|
+
throw new Error('Group members cannot be added to personal user contexts');
|
|
86
|
+
}
|
|
87
|
+
const oldGroupMember = groupMember.groupMemberId ? await this.get(groupMember.groupMemberId) : undefined;
|
|
88
|
+
if (await (0, group_permissions_1.isGroupMemberSignatureValid)(groupMember.groupId, groupMember, oldGroupMember)) {
|
|
89
|
+
return super.save(groupMember, opts);
|
|
90
|
+
}
|
|
91
|
+
throw new Error('Group member signature is not valid');
|
|
41
92
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
async signAndSave(groupMember, opts) {
|
|
94
|
+
if (!GroupMembersTable.addSignatureToGroupMember) {
|
|
95
|
+
throw new Error('Group member signing must be enabled to sign and save group members. Call GroupMembersTable.enableGroupMemberSigning(fn) to enable it.');
|
|
96
|
+
}
|
|
97
|
+
groupMember = GroupMembersTable.addSignatureToGroupMember(groupMember);
|
|
98
|
+
return this.save(groupMember, opts);
|
|
47
99
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await
|
|
100
|
+
async delete(groupMemberId) {
|
|
101
|
+
if (GroupMembersTable.isPassthrough) {
|
|
102
|
+
return super.delete(groupMemberId);
|
|
103
|
+
}
|
|
104
|
+
const groupMember = await this.get(groupMemberId);
|
|
105
|
+
if (groupMember) {
|
|
106
|
+
groupMember.deleted = true;
|
|
107
|
+
groupMember.role = group_member_roles_1.GroupMemberRole.None;
|
|
108
|
+
// we do a soft delete by saving the object with deleted=true and
|
|
109
|
+
await this.signAndSave(groupMember);
|
|
110
|
+
}
|
|
53
111
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
112
|
+
static addSignatureToGroupMember = undefined;
|
|
113
|
+
static enableGroupMemberSigning(fn) {
|
|
114
|
+
GroupMembersTable.addSignatureToGroupMember = fn;
|
|
115
|
+
}
|
|
116
|
+
/** @deprecated Forbidden on GroupsTable; use save() */
|
|
117
|
+
insert(..._args) {
|
|
118
|
+
throw new Error('GroupsTable forbids insert; use save()');
|
|
119
|
+
}
|
|
120
|
+
/** @deprecated Forbidden on GroupsTable; use save() */
|
|
121
|
+
update(..._args) {
|
|
122
|
+
throw new Error('GroupsTable forbids update; use save()');
|
|
123
|
+
}
|
|
124
|
+
constructor() {
|
|
125
|
+
super(...arguments);
|
|
126
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
})();
|
|
64
130
|
exports.GroupMembersTable = GroupMembersTable;
|
|
65
131
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.groupMemberSchema, GroupMembersTable);
|
|
66
132
|
function GroupMembers(dataContext) {
|
package/dist/data/groups.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
3
|
import { GroupMemberRole } from "./group-member-roles";
|
|
4
|
-
import { ISaveOptions
|
|
4
|
+
import type { ISaveOptions } from "./orm/data-query";
|
|
5
|
+
import { Table } from "./orm/table";
|
|
5
6
|
export declare const groupSchema: z.ZodObject<{
|
|
6
7
|
groupId: z.ZodEffects<z.ZodString, string, string>;
|
|
7
8
|
name: z.ZodString;
|
|
@@ -18,9 +19,9 @@ export declare const groupSchema: z.ZodObject<{
|
|
|
18
19
|
description: string;
|
|
19
20
|
signature: string;
|
|
20
21
|
publicKey: string;
|
|
22
|
+
publicBoxKey: string;
|
|
21
23
|
groupId: string;
|
|
22
24
|
founderUserId: string;
|
|
23
|
-
publicBoxKey: string;
|
|
24
25
|
disabled?: boolean | undefined;
|
|
25
26
|
iconClassName?: string | undefined;
|
|
26
27
|
publicRole?: GroupMemberRole | undefined;
|
|
@@ -29,9 +30,9 @@ export declare const groupSchema: z.ZodObject<{
|
|
|
29
30
|
description: string;
|
|
30
31
|
signature: string;
|
|
31
32
|
publicKey: string;
|
|
33
|
+
publicBoxKey: string;
|
|
32
34
|
groupId: string;
|
|
33
35
|
founderUserId: string;
|
|
34
|
-
publicBoxKey: string;
|
|
35
36
|
disabled?: boolean | undefined;
|
|
36
37
|
iconClassName?: string | undefined;
|
|
37
38
|
publicRole?: GroupMemberRole | undefined;
|
|
@@ -41,7 +42,10 @@ export declare const groupsTableName = "Groups";
|
|
|
41
42
|
export declare class GroupsTable extends Table<IGroup> {
|
|
42
43
|
static isPassthrough: boolean;
|
|
43
44
|
save(group: IGroup, opts?: ISaveOptions): Promise<IGroup>;
|
|
45
|
+
signAndSave(group: IGroup, opts?: ISaveOptions): Promise<IGroup>;
|
|
44
46
|
delete(groupId: string): Promise<void>;
|
|
47
|
+
private static addSignatureToGroup;
|
|
48
|
+
static enableGroupSigning(fn: (group: IGroup) => IGroup): void;
|
|
45
49
|
/** @deprecated Direct inserts forbidden; use save() */
|
|
46
50
|
insert(..._args: Parameters<Table<IGroup>['insert']>): never;
|
|
47
51
|
/** @deprecated Direct updates forbidden; use save() */
|