@peers-app/peers-sdk 0.7.0 → 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 -6
- package/dist/context/user-context.js +10 -12
- 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/files/files.d.ts +8 -6
- package/dist/data/files/files.js +16 -12
- package/dist/data/files/files.test.js +17 -17
- 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 +2 -0
- package/dist/data/index.js +2 -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/orm/table.js +3 -5
- package/dist/data/packages.d.ts +2 -1
- package/dist/data/packages.js +93 -44
- package/dist/data/packages.utils.d.ts +3 -0
- package/dist/data/packages.utils.js +41 -0
- 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/keys.d.ts +1 -1
- package/dist/keys.js +2 -2
- package/dist/keys.test.js +1 -1
- package/dist/package-loader/package-loader.d.ts +1 -1
- package/dist/package-loader/package-loader.js +4 -4
- package/dist/rpc-types.d.ts +6 -20
- package/dist/rpc-types.js +5 -12
- package/dist/system-ids.d.ts +2 -0
- package/dist/system-ids.js +3 -1
- package/dist/users.query.d.ts +3 -1
- package/dist/users.query.js +39 -11
- package/package.json +1 -1
package/dist/data/users.js
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
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.myUserId = exports.UsersTable = exports.userSchema = void 0;
|
|
4
38
|
exports.Users = Users;
|
|
5
39
|
exports.getMe = getMe;
|
|
6
40
|
const zod_1 = require("zod");
|
|
7
41
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
42
|
+
const decorators_1 = require("./orm/decorators");
|
|
43
|
+
const table_1 = require("./orm/table");
|
|
10
44
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
11
45
|
const types_1 = require("./orm/types");
|
|
12
|
-
const user_permissions_1 = require("./user-permissions");
|
|
13
46
|
const persistent_vars_1 = require("./persistent-vars");
|
|
47
|
+
const user_permissions_1 = require("./user-permissions");
|
|
14
48
|
exports.userSchema = zod_1.z.object({
|
|
15
49
|
userId: zod_1.z.string(),
|
|
16
50
|
name: zod_1.z.string(),
|
|
17
51
|
publicKey: zod_1.z.string().describe('The public key the user uses to sign messages'),
|
|
18
52
|
publicBoxKey: zod_1.z.string().describe('The public key to use to encrypt data that only this user can decrypt'),
|
|
19
|
-
trustLevel: zod_1.z.nativeEnum(socket_type_1.TrustLevel).optional().describe('The trust level of the user'),
|
|
20
53
|
signature: zod_1.z.string().optional().describe('The signed hash of this user object excluding the signature itself'),
|
|
21
54
|
});
|
|
22
55
|
const metaData = {
|
|
@@ -30,32 +63,58 @@ const metaData = {
|
|
|
30
63
|
{ fields: ['publicBoxKey'] },
|
|
31
64
|
]
|
|
32
65
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
66
|
+
let UsersTable = (() => {
|
|
67
|
+
let _classSuper = table_1.Table;
|
|
68
|
+
let _instanceExtraInitializers = [];
|
|
69
|
+
let _signAndSave_decorators;
|
|
70
|
+
return class UsersTable extends _classSuper {
|
|
71
|
+
static {
|
|
72
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
73
|
+
_signAndSave_decorators = [(0, decorators_1.ProxyClientTableMethodCalls)()];
|
|
74
|
+
__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);
|
|
75
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
38
76
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
77
|
+
static isPassthrough = false;
|
|
78
|
+
async save(user, opts) {
|
|
79
|
+
if (UsersTable.isPassthrough) {
|
|
80
|
+
return super.save(user, opts);
|
|
81
|
+
}
|
|
82
|
+
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
83
|
+
const userContextUserTable = Users(userContext.userDataContext);
|
|
84
|
+
if (this === userContextUserTable) {
|
|
85
|
+
// user is allowed to make any changes they want to their own user table
|
|
86
|
+
return super.save(user, opts);
|
|
87
|
+
}
|
|
88
|
+
// Get the old user record if it exists
|
|
89
|
+
const oldUser = await this.get(user.userId);
|
|
90
|
+
await (0, user_permissions_1.verifyUserSignature)(user, oldUser);
|
|
43
91
|
return super.save(user, opts);
|
|
44
92
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
93
|
+
async signAndSave(user, opts) {
|
|
94
|
+
if (!UsersTable.addSignatureToUser) {
|
|
95
|
+
throw new Error('User signing must be enabled to sign and save users. Call UsersTable.enableUserSigning(fn) to enable it.');
|
|
96
|
+
}
|
|
97
|
+
user = UsersTable.addSignatureToUser(user);
|
|
98
|
+
return this.save(user, opts);
|
|
99
|
+
}
|
|
100
|
+
static addSignatureToUser = undefined;
|
|
101
|
+
static enableUserSigning(fn) {
|
|
102
|
+
UsersTable.addSignatureToUser = fn;
|
|
103
|
+
}
|
|
104
|
+
/** @deprecated Forbidden on UsersTable; use save() */
|
|
105
|
+
insert(..._args) {
|
|
106
|
+
throw new Error('UsersTable forbids insert; use save()');
|
|
107
|
+
}
|
|
108
|
+
/** @deprecated Forbidden on UsersTable; use save() */
|
|
109
|
+
update(..._args) {
|
|
110
|
+
throw new Error('UsersTable forbids update; use save()');
|
|
111
|
+
}
|
|
112
|
+
constructor() {
|
|
113
|
+
super(...arguments);
|
|
114
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
})();
|
|
59
118
|
exports.UsersTable = UsersTable;
|
|
60
119
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.userSchema, UsersTable);
|
|
61
120
|
function Users(dataContext) {
|
|
@@ -66,7 +66,7 @@ export declare const workflowLogSchema: z.ZodObject<{
|
|
|
66
66
|
isError?: boolean | undefined;
|
|
67
67
|
}>;
|
|
68
68
|
export type IWorkflowLog = z.infer<typeof workflowLogSchema>;
|
|
69
|
-
export declare function WorkflowLogs(dataContext?: DataContext): import("
|
|
69
|
+
export declare function WorkflowLogs(dataContext?: DataContext): import("./orm").Table<{
|
|
70
70
|
workflowLogId: string;
|
|
71
71
|
workflowRunId: string;
|
|
72
72
|
contextId: string;
|
|
@@ -93,7 +93,7 @@ let WorkflowRunTable = (() => {
|
|
|
93
93
|
return class WorkflowRunTable extends _classSuper {
|
|
94
94
|
static {
|
|
95
95
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
96
|
-
_haltRun_decorators = [(0, orm_1.
|
|
96
|
+
_haltRun_decorators = [(0, orm_1.ProxyClientTableMethodCalls)()];
|
|
97
97
|
__esDecorate(this, null, _haltRun_decorators, { kind: "method", name: "haltRun", static: false, private: false, access: { has: obj => "haltRun" in obj, get: obj => obj.haltRun }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
98
98
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
99
99
|
}
|
package/dist/data/workflows.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DataContext } from "../context/data-context";
|
|
2
|
-
export declare function Workflows(dataContext?: DataContext): import("
|
|
2
|
+
export declare function Workflows(dataContext?: DataContext): import("./orm").Table<{
|
|
3
3
|
name: string;
|
|
4
4
|
description: string;
|
|
5
5
|
createdAt: Date;
|
|
@@ -15,16 +15,17 @@ function getTrustLevelFn(me, serverUrl) {
|
|
|
15
15
|
return socket_type_1.TrustLevel.Trusted;
|
|
16
16
|
}
|
|
17
17
|
// await Devices().delete(deviceInfo.deviceId);
|
|
18
|
-
let [user, device] = await Promise.all([
|
|
18
|
+
let [user, device, userTrustLevel] = await Promise.all([
|
|
19
19
|
(0, data_1.Users)(userDataContext).get(deviceInfo.userId),
|
|
20
20
|
(0, data_1.Devices)(userDataContext).get(deviceInfo.deviceId),
|
|
21
|
+
(0, data_1.UserTrustLevels)(userDataContext).get(deviceInfo.userId),
|
|
21
22
|
]);
|
|
22
23
|
if (user && device && !(deviceInfo.userId === device.userId && deviceInfo.userId === user.userId && deviceInfo.publicKey === user.publicKey && deviceInfo.publicBoxKey === user.publicBoxKey)) {
|
|
23
24
|
console.error(new Date().toISOString(), 'deviceInfo does not align with local info about user and device', { deviceInfo, user, device });
|
|
24
25
|
// TODO check if user has changed their public keys
|
|
25
26
|
return socket_type_1.TrustLevel.Untrusted;
|
|
26
27
|
}
|
|
27
|
-
if (
|
|
28
|
+
if (userTrustLevel?.trustLevel && userTrustLevel.trustLevel >= socket_type_1.TrustLevel.Trusted && device?.trustLevel && device.trustLevel >= socket_type_1.TrustLevel.Trusted) {
|
|
28
29
|
device.lastSeen = new Date();
|
|
29
30
|
await (0, data_1.Devices)(userDataContext).update(device);
|
|
30
31
|
return socket_type_1.TrustLevel.Trusted;
|
|
@@ -76,9 +77,12 @@ function getTrustLevelFn(me, serverUrl) {
|
|
|
76
77
|
// }
|
|
77
78
|
// }
|
|
78
79
|
// }
|
|
79
|
-
if (remoteTrustLevel > socket_type_1.TrustLevel.Unknown && !
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (remoteTrustLevel > socket_type_1.TrustLevel.Unknown && !userTrustLevel) {
|
|
81
|
+
await (0, data_1.UserTrustLevels)(userDataContext).save({
|
|
82
|
+
userId: deviceInfo.userId,
|
|
83
|
+
trustLevel: socket_type_1.TrustLevel.Known,
|
|
84
|
+
assignedAt: new Date(),
|
|
85
|
+
});
|
|
82
86
|
}
|
|
83
87
|
else if (newUser) {
|
|
84
88
|
await (0, data_1.Users)(userDataContext).save(user);
|
package/dist/keys.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface IDataBox {
|
|
|
26
26
|
fromPublicKey: string;
|
|
27
27
|
}
|
|
28
28
|
export declare function newKeys(): IPublicPrivateKeys;
|
|
29
|
-
export declare function
|
|
29
|
+
export declare function hydrateKeys(secretKey: string): IPublicPrivateKeys;
|
|
30
30
|
export declare function signMessageWithSecretKey(msg: string, secretKey: string): string;
|
|
31
31
|
export declare function openMessageWithPublicKey(msg: string, publicKey: string): string;
|
|
32
32
|
export declare function signObjectWithSecretKey<T>(obj: T, secretKey: string): ISignedObject<T>;
|
package/dist/keys.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.encodeBase64 = encodeBase64;
|
|
|
9
9
|
exports.decodeBase64 = decodeBase64;
|
|
10
10
|
exports.newToken = newToken;
|
|
11
11
|
exports.newKeys = newKeys;
|
|
12
|
-
exports.
|
|
12
|
+
exports.hydrateKeys = hydrateKeys;
|
|
13
13
|
exports.signMessageWithSecretKey = signMessageWithSecretKey;
|
|
14
14
|
exports.openMessageWithPublicKey = openMessageWithPublicKey;
|
|
15
15
|
exports.signObjectWithSecretKey = signObjectWithSecretKey;
|
|
@@ -80,7 +80,7 @@ function newKeys() {
|
|
|
80
80
|
publicBoxKey: encodeBase64(boxKeyPair.publicKey),
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function hydrateKeys(secretKey) {
|
|
84
84
|
let _secretKey = decodeBase64(secretKey);
|
|
85
85
|
const boxKeyPair = nacl.box.keyPair.fromSecretKey(_secretKey.slice(0, 32));
|
|
86
86
|
return {
|
package/dist/keys.test.js
CHANGED
|
@@ -97,7 +97,7 @@ describe('keys', () => {
|
|
|
97
97
|
describe('loading keys', () => {
|
|
98
98
|
it('should allow loading keys from a secret key', () => {
|
|
99
99
|
const keys = (0, keys_1.newKeys)();
|
|
100
|
-
const loadedKeys = (0, keys_1.
|
|
100
|
+
const loadedKeys = (0, keys_1.hydrateKeys)(keys.secretKey);
|
|
101
101
|
expect(loadedKeys.secretKey).toEqual(keys.secretKey);
|
|
102
102
|
expect(loadedKeys.publicKey).toEqual(keys.publicKey);
|
|
103
103
|
expect(loadedKeys.publicBoxKey).toEqual(keys.publicBoxKey);
|
|
@@ -11,6 +11,6 @@ export declare class PackageLoader {
|
|
|
11
11
|
}): Promise<void>;
|
|
12
12
|
loadPackage(pkg: IPackage, opts?: {
|
|
13
13
|
force?: boolean;
|
|
14
|
-
}): Promise<IPeersPackage |
|
|
14
|
+
}): Promise<IPeersPackage | undefined>;
|
|
15
15
|
}
|
|
16
16
|
export declare function setDefaultRequire(require: (<T>(module: string) => T)): void;
|
|
@@ -31,13 +31,13 @@ class PackageLoader {
|
|
|
31
31
|
let bundleCode = '';
|
|
32
32
|
if (pkg.packageBundleFileId) {
|
|
33
33
|
const filesTable = (0, files_1.Files)(this.dataContext);
|
|
34
|
-
const bundleBuffer = await filesTable.
|
|
34
|
+
const bundleBuffer = await filesTable.getFileContents(pkg.packageBundleFileId);
|
|
35
35
|
if (bundleBuffer) {
|
|
36
36
|
bundleCode = Buffer.from(bundleBuffer).toString('utf8');
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
console.warn(`Package bundle file not found for ${pkg.name} (fileId: ${pkg.packageBundleFileId})`);
|
|
40
|
-
return
|
|
40
|
+
return;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
@@ -87,11 +87,11 @@ class PackageLoader {
|
|
|
87
87
|
});
|
|
88
88
|
return packageInstance;
|
|
89
89
|
}
|
|
90
|
-
return
|
|
90
|
+
return;
|
|
91
91
|
}
|
|
92
92
|
catch (err) {
|
|
93
93
|
console.debug(`Could not load package bundle for ${pkg.name}`, err);
|
|
94
|
-
return
|
|
94
|
+
return;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
package/dist/rpc-types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { DataFilter, IDataQueryParams, ISaveOptions } from "./data/orm";
|
|
2
1
|
export interface IEventData<T = any> {
|
|
3
2
|
name: string;
|
|
4
3
|
data: T;
|
|
@@ -8,28 +7,15 @@ export declare const rpcServerCalls: {
|
|
|
8
7
|
openLinkInBrowser: ((url: string) => Promise<void>);
|
|
9
8
|
openPath: ((path: string) => Promise<void>);
|
|
10
9
|
openPackage: ((path: string) => Promise<void>);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
addOrUpdatePackage: ((input: string, options?: {
|
|
11
|
+
dataContextId?: string;
|
|
12
|
+
packageLocation?: string;
|
|
13
|
+
update?: boolean;
|
|
14
|
+
linkRemote?: boolean;
|
|
15
|
+
}) => Promise<string>);
|
|
15
16
|
setUserIdAndSecretKey: ((userId: string, secretKey: string) => Promise<void>);
|
|
16
17
|
getUserId: () => Promise<string | undefined>;
|
|
17
|
-
updateUserSettings: ((settings: {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
value: any;
|
|
21
|
-
}) => Promise<void>);
|
|
22
18
|
encryptData: ((value: string, groupId?: string) => Promise<string>);
|
|
23
|
-
tableGet: (dataContextId: string, tableName: string, id: string, opts?: {
|
|
24
|
-
useCache?: boolean;
|
|
25
|
-
cacheTtlMs?: number;
|
|
26
|
-
}) => Promise<any>;
|
|
27
|
-
tableList: ((dataContextId: string, tableName: string, filter?: DataFilter<any>, opts?: IDataQueryParams<any>) => Promise<any[]>);
|
|
28
|
-
tableCount: ((dataContextId: string, tableName: string, filter?: DataFilter<any>) => Promise<number>);
|
|
29
|
-
tableSave: ((dataContextId: string, tableName: string, record: any, opts?: ISaveOptions) => Promise<any>);
|
|
30
|
-
tableInsert: ((dataContextId: string, tableName: string, record: any) => Promise<any>);
|
|
31
|
-
tableUpdate: ((dataContextId: string, tableName: string, record: any) => Promise<any>);
|
|
32
|
-
tableDelete: ((dataContextId: string, tableName: string, recordOrId: any) => Promise<any>);
|
|
33
19
|
tableMethodCall: ((dataContextId: string, tableName: string, methodName: string, ...args: any[]) => Promise<any>);
|
|
34
20
|
getFileContents: ((fileId: string, encoding?: BufferEncoding) => Promise<string>);
|
|
35
21
|
resetAllDeviceSyncInfo: (() => Promise<void>);
|
package/dist/rpc-types.js
CHANGED
|
@@ -8,30 +8,23 @@ function rpcStub(rpcName) {
|
|
|
8
8
|
}
|
|
9
9
|
exports.rpcServerCalls = {
|
|
10
10
|
ping: async (msg) => `pong: ${msg}`,
|
|
11
|
+
// TODO collapse these two down to just openPath
|
|
11
12
|
openLinkInBrowser: rpcStub('openLinkInBrowser'),
|
|
12
13
|
openPath: rpcStub('openPath'),
|
|
13
14
|
openPackage: rpcStub('OpenPackage'),
|
|
14
|
-
|
|
15
|
-
addRemotePackage: rpcStub('addRemotePackage'),
|
|
16
|
-
linkRemoteRepo: rpcStub('linkRemoteRepo'),
|
|
17
|
-
installOrUpdatePackage: rpcStub('installOrUpdatePackage'),
|
|
15
|
+
addOrUpdatePackage: rpcStub('addOrUpdatePackage'),
|
|
18
16
|
setUserIdAndSecretKey: rpcStub('setUserIdAndSecretKey'),
|
|
19
17
|
getUserId: rpcStub('getUserId'),
|
|
20
|
-
updateUserSettings: rpcStub('updateUserSettings'),
|
|
21
18
|
encryptData: rpcStub('encryptData'),
|
|
22
|
-
|
|
23
|
-
tableList: rpcStub('tableList'),
|
|
24
|
-
tableCount: rpcStub('tableCount'),
|
|
25
|
-
tableSave: rpcStub('tableSave'),
|
|
26
|
-
tableInsert: rpcStub('tableInsert'),
|
|
27
|
-
tableUpdate: rpcStub('tableUpdate'),
|
|
28
|
-
tableDelete: rpcStub('tableDelete'),
|
|
19
|
+
// TODO collapse these all down to just tableMethodCall
|
|
29
20
|
tableMethodCall: rpcStub('tableMethodCall'),
|
|
30
21
|
// TODO lock this down so not all code can get any file contents
|
|
31
22
|
getFileContents: rpcStub('getFileContents'),
|
|
32
23
|
resetAllDeviceSyncInfo: rpcStub('resetAllDeviceSyncInfo'),
|
|
33
24
|
importGroupShare: rpcStub('importGroupShare'),
|
|
34
25
|
// TODO try to get rid of this and rely on the client-side table and server-side table individually emitting events
|
|
26
|
+
// TODO TODO before deleting this, check if we can stop client-side tables from emitting events and rely solely on server-side tables
|
|
27
|
+
// propagating events with rpcClientCalls.emitEvent. It's very likely we're currently seeing two events for every one write originating from the UI
|
|
35
28
|
// emitEvent: _na as ((event: IEventData) => Promise<boolean>),
|
|
36
29
|
};
|
|
37
30
|
exports.rpcClientCalls = {
|
package/dist/system-ids.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export declare const defaultAssistantRunnerToolId = "000peers0tool00000runner1";
|
|
|
4
4
|
export declare const defaultSendMessageToolId = "000peers0tool00000sendmsg";
|
|
5
5
|
export declare const runWorkflowToolId = "000peers0tool0runworkflow";
|
|
6
6
|
export declare const emitEventToolId = "000peers0tool000emitevent";
|
|
7
|
+
export declare const peersCorePackageId = "00mh0wlipjixk2gqmurbwee0o";
|
|
8
|
+
export declare const peersCorePackageRepoUrl = "https://github.com/peers-app/peers-core";
|
package/dist/system-ids.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.emitEventToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
3
|
+
exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.emitEventToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
4
4
|
exports.peersRootUserId = '000peers0user000000000001';
|
|
5
5
|
exports.defaultAssistantId = '000peers0bot00000000shell';
|
|
6
6
|
// export const defaultAssistantId = '000peers0bot000000000bot1';
|
|
@@ -8,3 +8,5 @@ exports.defaultAssistantRunnerToolId = '000peers0tool00000runner1';
|
|
|
8
8
|
exports.defaultSendMessageToolId = '000peers0tool00000sendmsg';
|
|
9
9
|
exports.runWorkflowToolId = '000peers0tool0runworkflow';
|
|
10
10
|
exports.emitEventToolId = '000peers0tool000emitevent';
|
|
11
|
+
exports.peersCorePackageId = '00mh0wlipjixk2gqmurbwee0o';
|
|
12
|
+
exports.peersCorePackageRepoUrl = 'https://github.com/peers-app/peers-core';
|
package/dist/users.query.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { DataContext, DataFilter, ICursorIterable, IUser } from "./index";
|
|
1
|
+
import { DataContext, DataFilter, ICursorIterable, IUser, TrustLevel } from "./index";
|
|
2
2
|
export interface IUsersQueryOpts {
|
|
3
3
|
currentDataContext?: DataContext;
|
|
4
4
|
includeCurrentDataContext?: boolean;
|
|
5
5
|
includeUserDataContext?: boolean;
|
|
6
6
|
includeOtherDataContexts?: boolean;
|
|
7
|
+
includeTrustLevel?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export type IUserSource = 'currentDataContext' | 'userDataContext' | 'otherDataContexts';
|
|
9
10
|
export interface IUserWithSource extends IUser {
|
|
10
11
|
source: IUserSource;
|
|
12
|
+
trustLevel?: TrustLevel;
|
|
11
13
|
}
|
|
12
14
|
export declare function usersCursor(filter: DataFilter<IUser>, opts?: IUsersQueryOpts): Promise<ICursorIterable<IUserWithSource>>;
|
|
13
15
|
export declare function getUserById(userId: string, opts?: IUsersQueryOpts): Promise<IUserWithSource | undefined>;
|
package/dist/users.query.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.usersCursor = usersCursor;
|
|
|
4
4
|
exports.getUserById = getUserById;
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
async function usersCursor(filter, opts = {}) {
|
|
7
|
-
const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true } = opts;
|
|
7
|
+
const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true, includeTrustLevel = true, } = opts;
|
|
8
8
|
const userContext = await (0, index_1.getUserContext)();
|
|
9
9
|
const contextToUse = currentDataContext || userContext.defaultDataContext();
|
|
10
10
|
let finalCursor = null;
|
|
@@ -13,10 +13,12 @@ async function usersCursor(filter, opts = {}) {
|
|
|
13
13
|
const primaryTable = (0, index_1.Users)(contextToUse);
|
|
14
14
|
const primarySource = (contextToUse === userContext.userDataContext) ? 'userDataContext' : 'currentDataContext';
|
|
15
15
|
const primaryCursor = index_1.Cursor.fromDataSource(primaryTable, filter)
|
|
16
|
-
.map(user => {
|
|
16
|
+
.map(async (user) => {
|
|
17
|
+
const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(contextToUse, user.userId) : undefined;
|
|
17
18
|
const userWithSource = {
|
|
18
19
|
...user,
|
|
19
20
|
source: primarySource,
|
|
21
|
+
trustLevel,
|
|
20
22
|
};
|
|
21
23
|
return userWithSource;
|
|
22
24
|
});
|
|
@@ -26,10 +28,12 @@ async function usersCursor(filter, opts = {}) {
|
|
|
26
28
|
if (includeUserDataContext && contextToUse !== userContext.userDataContext) {
|
|
27
29
|
const userDataContextTable = (0, index_1.Users)(userContext.userDataContext);
|
|
28
30
|
const userDataContextCursor = index_1.Cursor.fromDataSource(userDataContextTable, filter)
|
|
29
|
-
.map(user => {
|
|
31
|
+
.map(async (user) => {
|
|
32
|
+
const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId) : undefined;
|
|
30
33
|
const userWithSource = {
|
|
31
34
|
...user,
|
|
32
|
-
source: 'userDataContext'
|
|
35
|
+
source: 'userDataContext',
|
|
36
|
+
trustLevel,
|
|
33
37
|
};
|
|
34
38
|
return userWithSource;
|
|
35
39
|
});
|
|
@@ -44,12 +48,26 @@ async function usersCursor(filter, opts = {}) {
|
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
if (otherDataContexts.length > 0) {
|
|
51
|
+
// For trust levels from multiple contexts, we'll use the first context we find the user in
|
|
52
|
+
// This is a simplification - in reality, each group might have different trust levels
|
|
47
53
|
const otherDataContextTables = otherDataContexts.map(dataContext => (0, index_1.Users)(dataContext));
|
|
48
54
|
const otherDataContextsCursor = index_1.Cursor.fromDataSources(otherDataContextTables, filter)
|
|
49
|
-
.map(user => {
|
|
55
|
+
.map(async (user) => {
|
|
56
|
+
// Try to get trust level from the first group context that has this user
|
|
57
|
+
let trustLevel = undefined;
|
|
58
|
+
if (includeTrustLevel) {
|
|
59
|
+
for (const dataContext of otherDataContexts) {
|
|
60
|
+
const contextUser = await (0, index_1.Users)(dataContext).get(user.userId).catch(() => null);
|
|
61
|
+
if (contextUser) {
|
|
62
|
+
trustLevel = await (0, index_1.getUserTrustLevel)(dataContext, user.userId);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
50
67
|
const userWithSource = {
|
|
51
68
|
...user,
|
|
52
|
-
source: 'otherDataContexts'
|
|
69
|
+
source: 'otherDataContexts',
|
|
70
|
+
trustLevel,
|
|
53
71
|
};
|
|
54
72
|
return userWithSource;
|
|
55
73
|
});
|
|
@@ -59,7 +77,11 @@ async function usersCursor(filter, opts = {}) {
|
|
|
59
77
|
// If no cursor was created, return empty cursor
|
|
60
78
|
if (!finalCursor) {
|
|
61
79
|
return index_1.Cursor.fromDataSource((0, index_1.Users)(contextToUse), { userId: { $eq: '__non_existent__' } })
|
|
62
|
-
.map(user => ({
|
|
80
|
+
.map(async (user) => ({
|
|
81
|
+
...user,
|
|
82
|
+
source: 'userDataContext',
|
|
83
|
+
trustLevel: includeTrustLevel ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId) : undefined
|
|
84
|
+
}));
|
|
63
85
|
}
|
|
64
86
|
// Deduplication by userId
|
|
65
87
|
// TODO: Push deduplication logic down into the queries for better performance
|
|
@@ -73,7 +95,7 @@ async function usersCursor(filter, opts = {}) {
|
|
|
73
95
|
});
|
|
74
96
|
}
|
|
75
97
|
async function getUserById(userId, opts = {}) {
|
|
76
|
-
const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true } = opts;
|
|
98
|
+
const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true, includeTrustLevel = true } = opts;
|
|
77
99
|
const userContext = await (0, index_1.getUserContext)();
|
|
78
100
|
const contextToUse = currentDataContext || userContext.defaultDataContext();
|
|
79
101
|
// Try current data context first
|
|
@@ -83,9 +105,11 @@ async function getUserById(userId, opts = {}) {
|
|
|
83
105
|
const user = await primaryTable.get(userId);
|
|
84
106
|
if (user) {
|
|
85
107
|
const source = (contextToUse === userContext.userDataContext) ? 'userDataContext' : 'currentDataContext';
|
|
108
|
+
const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(contextToUse, user.userId) : undefined;
|
|
86
109
|
return {
|
|
87
110
|
...user,
|
|
88
|
-
source
|
|
111
|
+
source,
|
|
112
|
+
trustLevel,
|
|
89
113
|
};
|
|
90
114
|
}
|
|
91
115
|
}
|
|
@@ -99,9 +123,11 @@ async function getUserById(userId, opts = {}) {
|
|
|
99
123
|
const userDataContextTable = (0, index_1.Users)(userContext.userDataContext);
|
|
100
124
|
const user = await userDataContextTable.get(userId);
|
|
101
125
|
if (user) {
|
|
126
|
+
const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(userContext.userDataContext, user.userId) : undefined;
|
|
102
127
|
return {
|
|
103
128
|
...user,
|
|
104
|
-
source: 'userDataContext'
|
|
129
|
+
source: 'userDataContext',
|
|
130
|
+
trustLevel,
|
|
105
131
|
};
|
|
106
132
|
}
|
|
107
133
|
}
|
|
@@ -117,9 +143,11 @@ async function getUserById(userId, opts = {}) {
|
|
|
117
143
|
const table = (0, index_1.Users)(dataContext);
|
|
118
144
|
const user = await table.get(userId);
|
|
119
145
|
if (user) {
|
|
146
|
+
const trustLevel = includeTrustLevel ? await (0, index_1.getUserTrustLevel)(dataContext, user.userId) : undefined;
|
|
120
147
|
return {
|
|
121
148
|
...user,
|
|
122
|
-
source: 'otherDataContexts'
|
|
149
|
+
source: 'otherDataContexts',
|
|
150
|
+
trustLevel,
|
|
123
151
|
};
|
|
124
152
|
}
|
|
125
153
|
}
|