@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
|
@@ -23,43 +23,33 @@ class ClientProxyDataSource {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
async get(id, opts = {}) {
|
|
26
|
-
return rpc_types_1.rpcServerCalls.
|
|
26
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'get', id, opts);
|
|
27
27
|
}
|
|
28
28
|
async list(filter = {}, opts = {}) {
|
|
29
|
-
return rpc_types_1.rpcServerCalls.
|
|
29
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'list', filter, opts);
|
|
30
30
|
}
|
|
31
31
|
;
|
|
32
32
|
async count(filter = {}) {
|
|
33
|
-
return rpc_types_1.rpcServerCalls.
|
|
33
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'count', filter);
|
|
34
34
|
}
|
|
35
35
|
;
|
|
36
36
|
cursor(filter = {}, opts = {}) {
|
|
37
37
|
return (0, data_query_1.dataSourceCursor)(this, filter, opts);
|
|
38
38
|
}
|
|
39
39
|
async findOne(filter = {}, opts) {
|
|
40
|
-
|
|
41
|
-
const records = await this.list(filter, { pageSize: 1 });
|
|
42
|
-
return records[0];
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const records = await this.list(filter, { pageSize: 2 });
|
|
46
|
-
if (records.length > 1) {
|
|
47
|
-
throw new Error(`Matched more than one record for ${this.tableName} with query ${JSON.stringify(filter)}`);
|
|
48
|
-
}
|
|
49
|
-
return records[0];
|
|
50
|
-
}
|
|
40
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'findOne', filter, opts);
|
|
51
41
|
}
|
|
52
42
|
async save(record, opts) {
|
|
53
|
-
return rpc_types_1.rpcServerCalls.
|
|
43
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'save', record, opts);
|
|
54
44
|
}
|
|
55
45
|
async insert(record) {
|
|
56
|
-
return rpc_types_1.rpcServerCalls.
|
|
46
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'insert', record);
|
|
57
47
|
}
|
|
58
48
|
async update(record) {
|
|
59
|
-
return rpc_types_1.rpcServerCalls.
|
|
49
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'update', record);
|
|
60
50
|
}
|
|
61
51
|
async delete(idOrRecord) {
|
|
62
|
-
return rpc_types_1.rpcServerCalls.
|
|
52
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'delete', idOrRecord);
|
|
63
53
|
}
|
|
64
54
|
}
|
|
65
55
|
exports.ClientProxyDataSource = ClientProxyDataSource;
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* When used on the client side, these methods will be automatically proxied
|
|
4
4
|
* to the server via rpcServerCalls.tableMethodCall.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function ProxyClientTableMethodCalls(): (target: any, context: any) => any;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ProxyClientTableMethodCalls = ProxyClientTableMethodCalls;
|
|
4
|
+
const rpc_types_1 = require("../../rpc-types");
|
|
4
5
|
/**
|
|
5
6
|
* Decorator that marks a table method as server-side only.
|
|
6
7
|
* When used on the client side, these methods will be automatically proxied
|
|
7
8
|
* to the server via rpcServerCalls.tableMethodCall.
|
|
8
9
|
*/
|
|
9
|
-
function
|
|
10
|
+
function ProxyClientTableMethodCalls() {
|
|
10
11
|
return function (target, context) {
|
|
11
|
-
if (context.kind === 'method' &&
|
|
12
|
+
if (context.kind === 'method' && rpc_types_1.isClient) {
|
|
12
13
|
const methodName = context.name;
|
|
13
|
-
return function (...args) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, methodName, ...args);
|
|
14
|
+
return function (table, ...args) {
|
|
15
|
+
const dataContextId = table.groupId || '';
|
|
16
|
+
return rpc_types_1.rpcServerCalls.tableMethodCall(dataContextId, table.tableName, methodName, ...args);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
return target;
|
package/dist/data/orm/table.js
CHANGED
|
@@ -144,11 +144,9 @@ class Table {
|
|
|
144
144
|
this.setLocalOperation(recordId, operation);
|
|
145
145
|
let result;
|
|
146
146
|
try {
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
// result = await this.dataSource.update(record);
|
|
151
|
-
// }
|
|
147
|
+
// NOTE: done this way to allow individual tables to have custom logic in `save`, `insert`, and `update`
|
|
148
|
+
// but this results in a double-read (this method and the data-source method).
|
|
149
|
+
// TODO: try to avoid the double-read, probably by passing the just-read result as `opts.dbData`
|
|
152
150
|
result = await this.dataSource.save(record, opts);
|
|
153
151
|
}
|
|
154
152
|
finally {
|
package/dist/data/packages.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
|
-
import { ISaveOptions
|
|
3
|
+
import type { ISaveOptions } from "./orm/data-query";
|
|
4
|
+
import { Table } from "./orm/table";
|
|
4
5
|
declare const schema: z.ZodObject<{
|
|
5
6
|
packageId: z.ZodString;
|
|
6
7
|
name: z.ZodString;
|
package/dist/data/packages.js
CHANGED
|
@@ -1,15 +1,50 @@
|
|
|
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.reloadPackagesOnPageRefresh = exports.packagesRootDir = exports.PackagesTable = void 0;
|
|
4
38
|
exports.Packages = Packages;
|
|
5
39
|
const zod_1 = require("zod");
|
|
40
|
+
const context_1 = require("../context");
|
|
6
41
|
const app_nav_1 = require("../types/app-nav");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
42
|
+
const decorators_1 = require("./orm/decorators");
|
|
43
|
+
const table_1 = require("./orm/table");
|
|
9
44
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
10
|
-
const
|
|
11
|
-
const orm_1 = require("./orm");
|
|
45
|
+
const types_1 = require("./orm/types");
|
|
12
46
|
const package_permissions_1 = require("./package-permissions");
|
|
47
|
+
const persistent_vars_1 = require("./persistent-vars");
|
|
13
48
|
const schema = zod_1.z.object({
|
|
14
49
|
packageId: zod_1.z.string(),
|
|
15
50
|
name: zod_1.z.string(),
|
|
@@ -34,52 +69,67 @@ const metaData = {
|
|
|
34
69
|
iconClassName: 'bi bi-box-fill',
|
|
35
70
|
fields: (0, types_1.schemaToFields)(schema),
|
|
36
71
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
72
|
+
let PackagesTable = (() => {
|
|
73
|
+
let _classSuper = table_1.Table;
|
|
74
|
+
let _instanceExtraInitializers = [];
|
|
75
|
+
let _signAndSave_decorators;
|
|
76
|
+
return class PackagesTable extends _classSuper {
|
|
77
|
+
static {
|
|
78
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
79
|
+
_signAndSave_decorators = [(0, decorators_1.ProxyClientTableMethodCalls)()];
|
|
80
|
+
__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);
|
|
81
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
82
|
+
}
|
|
83
|
+
static isPassthrough = false;
|
|
84
|
+
async insert(packageObj, opts) {
|
|
85
|
+
return this.save(packageObj, opts);
|
|
86
|
+
}
|
|
87
|
+
async update(packageObj, opts) {
|
|
88
|
+
return this.save(packageObj, opts);
|
|
89
|
+
}
|
|
90
|
+
async save(packageObj, opts) {
|
|
91
|
+
if (PackagesTable.isPassthrough) {
|
|
92
|
+
return super.save(packageObj, opts);
|
|
93
|
+
}
|
|
94
|
+
if (!this.groupId) {
|
|
95
|
+
// users can do whatever they want to packages in their personal space
|
|
96
|
+
return super.save(packageObj, opts);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
await (0, package_permissions_1.verifyPackageSignature)(packageObj, this.groupId);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
throw new Error('Package verification failed. Did you mean to call `signAndSave`?', { cause: err });
|
|
103
|
+
}
|
|
47
104
|
return super.save(packageObj, opts);
|
|
48
105
|
}
|
|
49
|
-
|
|
50
|
-
|
|
106
|
+
async signAndSave(packageObj, opts) {
|
|
107
|
+
if (!PackagesTable.addSignatureToPackage) {
|
|
108
|
+
throw new Error('Package signing is not enabled. Call PackagesTable.enablePackageSigning(fn) to enable it.');
|
|
109
|
+
}
|
|
110
|
+
packageObj = await PackagesTable.addSignatureToPackage(packageObj);
|
|
51
111
|
return super.save(packageObj, opts);
|
|
52
112
|
}
|
|
53
|
-
|
|
54
|
-
|
|
113
|
+
static addSignatureToPackage = undefined;
|
|
114
|
+
static enablePackageSigning(fn) {
|
|
115
|
+
this.addSignatureToPackage = fn;
|
|
55
116
|
}
|
|
56
|
-
|
|
57
|
-
|
|
117
|
+
async delete(packageId) {
|
|
118
|
+
// anyone (with write permissions) can delete packages since that isn't a security risk (unless something else is relying on a package to be present?)
|
|
119
|
+
return super.delete(packageId);
|
|
120
|
+
// const userContext = await getUserContext();
|
|
121
|
+
// const userContextPackages = Packages(userContext.userDataContext);
|
|
122
|
+
// if (userContextPackages === this) {
|
|
123
|
+
// return super.delete(packageId);
|
|
124
|
+
// }
|
|
125
|
+
// throw new Error('Only deleting packages from the user context Packages table is allowed');
|
|
58
126
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!PackagesTable.addSignatureToPackage) {
|
|
63
|
-
throw new Error('Package signing is not enabled. Call PackagesTable.enablePackageSigning(fn) to enable it.');
|
|
127
|
+
constructor() {
|
|
128
|
+
super(...arguments);
|
|
129
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
64
130
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
static addSignatureToPackage = undefined;
|
|
69
|
-
static enablePackageSigning(fn) {
|
|
70
|
-
this.addSignatureToPackage = fn;
|
|
71
|
-
}
|
|
72
|
-
async delete(packageId) {
|
|
73
|
-
// anyone (with write permissions) can delete packages since that isn't a security risk (unless something else is relying on a package to be present?)
|
|
74
|
-
return super.delete(packageId);
|
|
75
|
-
// const userContext = await getUserContext();
|
|
76
|
-
// const userContextPackages = Packages(userContext.userDataContext);
|
|
77
|
-
// if (userContextPackages === this) {
|
|
78
|
-
// return super.delete(packageId);
|
|
79
|
-
// }
|
|
80
|
-
// throw new Error('Only deleting packages from the user context Packages table is allowed');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
131
|
+
};
|
|
132
|
+
})();
|
|
83
133
|
exports.PackagesTable = PackagesTable;
|
|
84
134
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, schema, PackagesTable);
|
|
85
135
|
function Packages(dataContext) {
|
|
@@ -87,4 +137,3 @@ function Packages(dataContext) {
|
|
|
87
137
|
}
|
|
88
138
|
exports.packagesRootDir = (0, persistent_vars_1.deviceVar)('packagesRootDir', { defaultValue: '~/peers-packages' });
|
|
89
139
|
exports.reloadPackagesOnPageRefresh = (0, persistent_vars_1.deviceVar)('reloadPackagesOnPageRefresh', { defaultValue: true, });
|
|
90
|
-
// export const packageLocalPathsResolved = persistentVar<{ [packageId: string]: string}>('packageLocalPathsResolved', { defaultValue: {}, scope: 'device' });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyPackageToAnotherDataContext = copyPackageToAnotherDataContext;
|
|
4
|
+
const packages_1 = require("./packages");
|
|
5
|
+
const files_1 = require("./files");
|
|
6
|
+
async function copyPackageToAnotherDataContext(packageId, fromDataContext, toDataContext) {
|
|
7
|
+
const fromPackages = (0, packages_1.Packages)(fromDataContext);
|
|
8
|
+
const toPackages = (0, packages_1.Packages)(toDataContext);
|
|
9
|
+
const pkg = await fromPackages.get(packageId);
|
|
10
|
+
if (!pkg) {
|
|
11
|
+
throw new Error(`Package ${packageId} not found in fromDataContext`);
|
|
12
|
+
}
|
|
13
|
+
const fromFiles = (0, files_1.Files)(fromDataContext);
|
|
14
|
+
const toFiles = (0, files_1.Files)(toDataContext);
|
|
15
|
+
const bundleFile = await fromFiles.get(pkg.packageBundleFileId);
|
|
16
|
+
if (bundleFile) {
|
|
17
|
+
await toFiles.saveFileRecord(bundleFile);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
throw new Error(`Package bundle file ${pkg.packageBundleFileId} not found in fromDataContext`);
|
|
21
|
+
}
|
|
22
|
+
if (pkg.routesBundleFileId) {
|
|
23
|
+
const routesBundleFile = await fromFiles.get(pkg.routesBundleFileId);
|
|
24
|
+
if (routesBundleFile) {
|
|
25
|
+
await toFiles.saveFileRecord(routesBundleFile);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`Routes bundle file ${pkg.routesBundleFileId} not found in fromDataContext`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (pkg.uiBundleFileId) {
|
|
32
|
+
const uiBundleFile = await fromFiles.get(pkg.uiBundleFileId);
|
|
33
|
+
if (uiBundleFile) {
|
|
34
|
+
await toFiles.saveFileRecord(uiBundleFile);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error(`UI bundle file ${pkg.uiBundleFileId} not found in fromDataContext`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return toPackages.signAndSave(pkg);
|
|
41
|
+
}
|
|
@@ -14,7 +14,7 @@ export declare const peerEventHandlerSchema: z.ZodObject<{
|
|
|
14
14
|
handlerWorkflowId: string;
|
|
15
15
|
}>;
|
|
16
16
|
export type IPeerEventHandler = z.infer<typeof peerEventHandlerSchema>;
|
|
17
|
-
export declare function PeerEventHandlers(dataContext?: DataContext): import("
|
|
17
|
+
export declare function PeerEventHandlers(dataContext?: DataContext): import("../orm").Table<{
|
|
18
18
|
peerEventTypeId: string;
|
|
19
19
|
peerEventHandlerId: string;
|
|
20
20
|
handlerWorkflowId: string;
|
|
@@ -97,7 +97,7 @@ export declare const peerEventTypeSchema: z.ZodObject<{
|
|
|
97
97
|
nextScheduledTime?: number | undefined;
|
|
98
98
|
}>;
|
|
99
99
|
export type IPeerEventType = z.infer<typeof peerEventTypeSchema>;
|
|
100
|
-
export declare function PeerEventTypes(dataContext?: DataContext): import("
|
|
100
|
+
export declare function PeerEventTypes(dataContext?: DataContext): import("../orm").Table<{
|
|
101
101
|
name: string;
|
|
102
102
|
description: string;
|
|
103
103
|
schema: {
|
|
@@ -26,7 +26,7 @@ export declare const toolTestSchema: z.ZodObject<{
|
|
|
26
26
|
mocks?: any;
|
|
27
27
|
}>;
|
|
28
28
|
export type IToolTest = z.infer<typeof toolTestSchema>;
|
|
29
|
-
export declare function ToolTests(dataContext?: DataContext): import("
|
|
29
|
+
export declare function ToolTests(dataContext?: DataContext): import("./orm").Table<{
|
|
30
30
|
code: string;
|
|
31
31
|
description: string;
|
|
32
32
|
toolId: string;
|
package/dist/data/tools.d.ts
CHANGED
|
@@ -311,7 +311,7 @@ export interface IToolInstance {
|
|
|
311
311
|
inputSchema?: z.ZodObject<any>;
|
|
312
312
|
outputSchema?: z.ZodObject<any>;
|
|
313
313
|
}
|
|
314
|
-
export declare function Tools(dataContext?: DataContext): import("
|
|
314
|
+
export declare function Tools(dataContext?: DataContext): import("./orm").Table<{
|
|
315
315
|
code: string;
|
|
316
316
|
name: string;
|
|
317
317
|
toolId: string;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const keys_1 = require("../keys");
|
|
4
4
|
const user_permissions_1 = require("./user-permissions");
|
|
5
|
-
const socket_type_1 = require("../device/socket.type");
|
|
6
5
|
// Test the user permissions logic directly without ORM dependencies
|
|
7
6
|
describe('User Permissions Logic', () => {
|
|
8
7
|
let testUser;
|
|
@@ -16,7 +15,6 @@ describe('User Permissions Logic', () => {
|
|
|
16
15
|
name: 'Test User',
|
|
17
16
|
publicKey: userKeys.publicKey,
|
|
18
17
|
publicBoxKey: userKeys.publicBoxKey,
|
|
19
|
-
trustLevel: socket_type_1.TrustLevel.Trusted,
|
|
20
18
|
signature: ''
|
|
21
19
|
};
|
|
22
20
|
});
|
|
@@ -144,11 +142,11 @@ describe('User Permissions Logic', () => {
|
|
|
144
142
|
const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
|
|
145
143
|
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow();
|
|
146
144
|
});
|
|
147
|
-
it('should allow
|
|
148
|
-
const originalUser = (0, user_permissions_1.signUserObject)({ ...testUser
|
|
145
|
+
it('should allow changes with valid signature', () => {
|
|
146
|
+
const originalUser = (0, user_permissions_1.signUserObject)({ ...testUser }, userKeys.secretKey);
|
|
149
147
|
const updatedUser = {
|
|
150
148
|
...originalUser,
|
|
151
|
-
|
|
149
|
+
name: 'Updated Name',
|
|
152
150
|
signature: ''
|
|
153
151
|
};
|
|
154
152
|
const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
|
|
@@ -193,12 +191,12 @@ describe('User Permissions Logic', () => {
|
|
|
193
191
|
const signedUpdatedUser = (0, user_permissions_1.signUserObject)(updatedUser, userKeys.secretKey);
|
|
194
192
|
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUpdatedUser, originalUser)).toThrow();
|
|
195
193
|
});
|
|
196
|
-
it('should handle
|
|
197
|
-
const
|
|
194
|
+
it('should handle various user values', () => {
|
|
195
|
+
const userWithValues = {
|
|
198
196
|
...testUser,
|
|
199
|
-
|
|
197
|
+
name: 'Complex Name'
|
|
200
198
|
};
|
|
201
|
-
const signedUser = (0, user_permissions_1.signUserObject)(
|
|
199
|
+
const signedUser = (0, user_permissions_1.signUserObject)(userWithValues, userKeys.secretKey);
|
|
202
200
|
expect(() => (0, user_permissions_1.verifyUserSignature)(signedUser, undefined)).not.toThrow();
|
|
203
201
|
});
|
|
204
202
|
});
|
|
@@ -210,7 +208,6 @@ describe('User Permissions Logic', () => {
|
|
|
210
208
|
name: 'Victim User',
|
|
211
209
|
publicKey: userKeys.publicKey, // Victim's public key
|
|
212
210
|
publicBoxKey: userKeys.publicBoxKey,
|
|
213
|
-
trustLevel: socket_type_1.TrustLevel.Trusted,
|
|
214
211
|
signature: ''
|
|
215
212
|
};
|
|
216
213
|
const maliciousSignedUser = (0, user_permissions_1.signUserObject)(victimUser, otherUserKeys.secretKey); // Signed with attacker's key
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { DataContext } from "../context/data-context";
|
|
3
|
+
import { TrustLevel } from "../device/socket.type";
|
|
4
|
+
/**
|
|
5
|
+
* UserTrustLevels table allows different users/groups to assign their own trust levels
|
|
6
|
+
* to users without modifying the user's signed record.
|
|
7
|
+
*
|
|
8
|
+
* The trustLevel is scoped to the current DataContext (either user or group).
|
|
9
|
+
* Each context can maintain its own trust assessment of other users.
|
|
10
|
+
*/
|
|
11
|
+
export declare const userTrustLevelSchema: z.ZodObject<{
|
|
12
|
+
userId: z.ZodString;
|
|
13
|
+
trustLevel: z.ZodNativeEnum<typeof TrustLevel>;
|
|
14
|
+
assignedAt: z.ZodOptional<z.ZodDate>;
|
|
15
|
+
notes: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
userId: string;
|
|
18
|
+
trustLevel: TrustLevel;
|
|
19
|
+
assignedAt?: Date | undefined;
|
|
20
|
+
notes?: string | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
userId: string;
|
|
23
|
+
trustLevel: TrustLevel;
|
|
24
|
+
assignedAt?: Date | undefined;
|
|
25
|
+
notes?: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export type IUserTrustLevel = z.infer<typeof userTrustLevelSchema>;
|
|
28
|
+
export declare function UserTrustLevels(dataContext?: DataContext): import("./orm").Table<{
|
|
29
|
+
userId: string;
|
|
30
|
+
trustLevel: TrustLevel;
|
|
31
|
+
assignedAt?: Date | undefined;
|
|
32
|
+
notes?: string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the trust level for a specific user in the given context.
|
|
36
|
+
* Returns TrustLevel.Unknown if no trust level has been assigned.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getUserTrustLevel(dataContext: DataContext, userId: string): Promise<TrustLevel>;
|
|
39
|
+
/**
|
|
40
|
+
* Set the trust level for a specific user in the given context.
|
|
41
|
+
*/
|
|
42
|
+
export declare function setUserTrustLevel(userId: string, trustLevel: TrustLevel, dataContext?: DataContext, notes?: string): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.userTrustLevelSchema = void 0;
|
|
4
|
+
exports.UserTrustLevels = UserTrustLevels;
|
|
5
|
+
exports.getUserTrustLevel = getUserTrustLevel;
|
|
6
|
+
exports.setUserTrustLevel = setUserTrustLevel;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
9
|
+
const socket_type_1 = require("../device/socket.type");
|
|
10
|
+
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
11
|
+
const types_1 = require("./orm/types");
|
|
12
|
+
/**
|
|
13
|
+
* UserTrustLevels table allows different users/groups to assign their own trust levels
|
|
14
|
+
* to users without modifying the user's signed record.
|
|
15
|
+
*
|
|
16
|
+
* The trustLevel is scoped to the current DataContext (either user or group).
|
|
17
|
+
* Each context can maintain its own trust assessment of other users.
|
|
18
|
+
*/
|
|
19
|
+
exports.userTrustLevelSchema = zod_1.z.object({
|
|
20
|
+
userId: zod_1.z.string().describe('The user being assigned a trust level'),
|
|
21
|
+
trustLevel: zod_1.z.nativeEnum(socket_type_1.TrustLevel).describe('The trust level assigned to this user in this context'),
|
|
22
|
+
assignedAt: zod_1.z.date().optional().describe('When the trust level was assigned'),
|
|
23
|
+
notes: zod_1.z.string().optional().describe('Optional notes about why this trust level was assigned'),
|
|
24
|
+
});
|
|
25
|
+
const metaData = {
|
|
26
|
+
name: 'UserTrustLevels',
|
|
27
|
+
description: 'Trust levels assigned to users by the current context (user or group)',
|
|
28
|
+
primaryKeyName: 'userId',
|
|
29
|
+
fields: (0, types_1.schemaToFields)(exports.userTrustLevelSchema),
|
|
30
|
+
indexes: [
|
|
31
|
+
{ fields: ['trustLevel'] },
|
|
32
|
+
]
|
|
33
|
+
};
|
|
34
|
+
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.userTrustLevelSchema);
|
|
35
|
+
function UserTrustLevels(dataContext) {
|
|
36
|
+
return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.userTrustLevelSchema);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the trust level for a specific user in the given context.
|
|
40
|
+
* Returns TrustLevel.Unknown if no trust level has been assigned.
|
|
41
|
+
*/
|
|
42
|
+
async function getUserTrustLevel(dataContext, userId) {
|
|
43
|
+
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
44
|
+
if (dataContext === userContext.userDataContext && userContext.userId === userId) {
|
|
45
|
+
return socket_type_1.TrustLevel.Self;
|
|
46
|
+
}
|
|
47
|
+
const trustLevelRecord = await UserTrustLevels(dataContext).get(userId);
|
|
48
|
+
return trustLevelRecord?.trustLevel ?? socket_type_1.TrustLevel.Unknown;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Set the trust level for a specific user in the given context.
|
|
52
|
+
*/
|
|
53
|
+
async function setUserTrustLevel(userId, trustLevel, dataContext, notes) {
|
|
54
|
+
await UserTrustLevels(dataContext).save({
|
|
55
|
+
userId,
|
|
56
|
+
trustLevel,
|
|
57
|
+
assignedAt: new Date(),
|
|
58
|
+
notes,
|
|
59
|
+
});
|
|
60
|
+
}
|
package/dist/data/users.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { ISaveOptions } from "./orm/data-query";
|
|
4
|
+
import { Table } from "./orm/table";
|
|
5
5
|
export declare const userSchema: z.ZodObject<{
|
|
6
6
|
userId: z.ZodString;
|
|
7
7
|
name: z.ZodString;
|
|
8
8
|
publicKey: z.ZodString;
|
|
9
9
|
publicBoxKey: z.ZodString;
|
|
10
|
-
trustLevel: z.ZodOptional<z.ZodNativeEnum<typeof TrustLevel>>;
|
|
11
10
|
signature: z.ZodOptional<z.ZodString>;
|
|
12
11
|
}, "strip", z.ZodTypeAny, {
|
|
13
12
|
name: string;
|
|
14
13
|
publicKey: string;
|
|
15
|
-
publicBoxKey: string;
|
|
16
14
|
userId: string;
|
|
15
|
+
publicBoxKey: string;
|
|
17
16
|
signature?: string | undefined;
|
|
18
|
-
trustLevel?: TrustLevel | undefined;
|
|
19
17
|
}, {
|
|
20
18
|
name: string;
|
|
21
19
|
publicKey: string;
|
|
22
|
-
publicBoxKey: string;
|
|
23
20
|
userId: string;
|
|
21
|
+
publicBoxKey: string;
|
|
24
22
|
signature?: string | undefined;
|
|
25
|
-
trustLevel?: TrustLevel | undefined;
|
|
26
23
|
}>;
|
|
27
24
|
export type IUser = z.infer<typeof userSchema>;
|
|
28
25
|
export declare class UsersTable extends Table<IUser> {
|
|
29
26
|
static isPassthrough: boolean;
|
|
30
27
|
save(user: IUser, opts?: ISaveOptions): Promise<IUser>;
|
|
28
|
+
signAndSave(user: IUser, opts?: ISaveOptions): Promise<IUser>;
|
|
29
|
+
private static addSignatureToUser;
|
|
30
|
+
static enableUserSigning(fn: (user: IUser) => IUser): void;
|
|
31
31
|
/** @deprecated Forbidden on UsersTable; use save() */
|
|
32
32
|
insert(..._args: Parameters<Table<IUser>['insert']>): never;
|
|
33
33
|
/** @deprecated Forbidden on UsersTable; use save() */
|