@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.
Files changed (46) hide show
  1. package/dist/context/data-context.d.ts +1 -1
  2. package/dist/context/data-context.js +2 -3
  3. package/dist/context/user-context-singleton.js +6 -30
  4. package/dist/context/user-context.d.ts +1 -3
  5. package/dist/context/user-context.js +9 -6
  6. package/dist/data/assistants.d.ts +1 -1
  7. package/dist/data/change-tracking.d.ts +16 -16
  8. package/dist/data/channels.d.ts +1 -1
  9. package/dist/data/data-locks.d.ts +2 -2
  10. package/dist/data/devices.d.ts +4 -4
  11. package/dist/data/embeddings.d.ts +1 -1
  12. package/dist/data/group-members.d.ts +7 -4
  13. package/dist/data/group-members.js +98 -32
  14. package/dist/data/groups.d.ts +7 -3
  15. package/dist/data/groups.js +91 -30
  16. package/dist/data/index.d.ts +1 -0
  17. package/dist/data/index.js +1 -0
  18. package/dist/data/knowledge/knowledge-frames.d.ts +1 -1
  19. package/dist/data/knowledge/knowledge-links.d.ts +1 -1
  20. package/dist/data/knowledge/knowledge-values.d.ts +1 -1
  21. package/dist/data/knowledge/peer-types.d.ts +1 -1
  22. package/dist/data/knowledge/predicates.d.ts +1 -1
  23. package/dist/data/messages.d.ts +4 -4
  24. package/dist/data/orm/client-proxy.data-source.js +8 -18
  25. package/dist/data/orm/decorators.d.ts +1 -1
  26. package/dist/data/orm/decorators.js +7 -7
  27. package/dist/data/packages.d.ts +2 -1
  28. package/dist/data/packages.js +90 -40
  29. package/dist/data/peer-events/peer-event-handlers.d.ts +1 -1
  30. package/dist/data/peer-events/peer-event-types.d.ts +1 -1
  31. package/dist/data/tool-tests.d.ts +1 -1
  32. package/dist/data/tools.d.ts +1 -1
  33. package/dist/data/user-permissions.test.js +7 -10
  34. package/dist/data/user-trust-levels.d.ts +42 -0
  35. package/dist/data/user-trust-levels.js +60 -0
  36. package/dist/data/users.d.ts +7 -7
  37. package/dist/data/users.js +86 -27
  38. package/dist/data/workflow-logs.d.ts +1 -1
  39. package/dist/data/workflow-runs.js +1 -1
  40. package/dist/data/workflows.d.ts +1 -1
  41. package/dist/device/get-trust-level.js +9 -5
  42. package/dist/rpc-types.d.ts +0 -11
  43. package/dist/rpc-types.js +0 -7
  44. package/dist/users.query.d.ts +3 -1
  45. package/dist/users.query.js +39 -11
  46. package/package.json +1 -1
@@ -1,4 +1,38 @@
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.GroupsTable = exports.groupsTableName = exports.groupSchema = void 0;
4
38
  exports.Groups = Groups;
@@ -7,7 +41,8 @@ const user_context_singleton_1 = require("../context/user-context-singleton");
7
41
  const zod_types_1 = require("../types/zod-types");
8
42
  const group_member_roles_1 = require("./group-member-roles");
9
43
  const group_permissions_1 = require("./group-permissions");
10
- const orm_1 = require("./orm");
44
+ const decorators_1 = require("./orm/decorators");
45
+ const table_1 = require("./orm/table");
11
46
  const table_definitions_system_1 = require("./orm/table-definitions.system");
12
47
  const types_1 = require("./orm/types");
13
48
  exports.groupSchema = zod_1.z.object({
@@ -33,39 +68,65 @@ const metaData = {
33
68
  { fields: ['name'] },
34
69
  ]
35
70
  };
36
- class GroupsTable extends orm_1.Table {
37
- static isPassthrough = false;
38
- async save(group, opts) {
39
- if (GroupsTable.isPassthrough) {
40
- return super.save(group, opts);
71
+ let GroupsTable = (() => {
72
+ let _classSuper = table_1.Table;
73
+ let _instanceExtraInitializers = [];
74
+ let _signAndSave_decorators;
75
+ return class GroupsTable extends _classSuper {
76
+ static {
77
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
78
+ _signAndSave_decorators = [(0, decorators_1.ProxyClientTableMethodCalls)()];
79
+ __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);
80
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
41
81
  }
42
- const userContext = await (0, user_context_singleton_1.getUserContext)();
43
- const userContextGroups = Groups(userContext.userDataContext);
44
- if (userContextGroups === this) {
45
- // users can do whatever they want to groups in their personal space
82
+ static isPassthrough = false;
83
+ async save(group, opts) {
84
+ if (GroupsTable.isPassthrough) {
85
+ return super.save(group, opts);
86
+ }
87
+ const userContext = await (0, user_context_singleton_1.getUserContext)();
88
+ const userContextGroups = Groups(userContext.userDataContext);
89
+ if (userContextGroups === this) {
90
+ // users can do whatever they want to groups in their personal space
91
+ return super.save(group, opts);
92
+ }
93
+ const oldGroup = await this.get(group.groupId);
94
+ await (0, group_permissions_1.verifyGroupSignature)(group, oldGroup);
46
95
  return super.save(group, opts);
47
96
  }
48
- const oldGroup = await this.get(group.groupId);
49
- await (0, group_permissions_1.verifyGroupSignature)(group, oldGroup);
50
- return super.save(group, opts);
51
- }
52
- async delete(groupId) {
53
- const userContext = await (0, user_context_singleton_1.getUserContext)();
54
- const userContextGroups = Groups(userContext.userDataContext);
55
- if (userContextGroups === this) {
56
- return super.delete(groupId);
97
+ async signAndSave(group, opts) {
98
+ if (!GroupsTable.addSignatureToGroup) {
99
+ throw new Error('Group signing must be enabled to sign and save groups. Call GroupsTable.enableGroupSigning(fn) to enable it.');
100
+ }
101
+ group = GroupsTable.addSignatureToGroup(group);
102
+ return this.save(group, opts);
57
103
  }
58
- throw new Error('Only deleting groups from the user context Groups table is allowed');
59
- }
60
- /** @deprecated Direct inserts forbidden; use save() */
61
- insert(..._args) {
62
- throw new Error('Direct inserts forbidden; use save()');
63
- }
64
- /** @deprecated Direct updates forbidden; use save() */
65
- update(..._args) {
66
- throw new Error('Direct updates forbidden; use save()');
67
- }
68
- }
104
+ async delete(groupId) {
105
+ const userContext = await (0, user_context_singleton_1.getUserContext)();
106
+ const userContextGroups = Groups(userContext.userDataContext);
107
+ if (userContextGroups === this) {
108
+ return super.delete(groupId);
109
+ }
110
+ throw new Error('Only deleting groups from the user context Groups table is allowed');
111
+ }
112
+ static addSignatureToGroup = undefined;
113
+ static enableGroupSigning(fn) {
114
+ this.addSignatureToGroup = fn;
115
+ }
116
+ /** @deprecated Direct inserts forbidden; use save() */
117
+ insert(..._args) {
118
+ throw new Error('Direct inserts forbidden; use save()');
119
+ }
120
+ /** @deprecated Direct updates forbidden; use save() */
121
+ update(..._args) {
122
+ throw new Error('Direct updates forbidden; use save()');
123
+ }
124
+ constructor() {
125
+ super(...arguments);
126
+ __runInitializers(this, _instanceExtraInitializers);
127
+ }
128
+ };
129
+ })();
69
130
  exports.GroupsTable = GroupsTable;
70
131
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.groupSchema, GroupsTable);
71
132
  function Groups(dataContext) {
@@ -27,6 +27,7 @@ export * from "./tool-tests";
27
27
  export * from "./tools";
28
28
  export * from "./users";
29
29
  export * from "./user-permissions";
30
+ export * from "./user-trust-levels";
30
31
  export * from "./workflow-logs";
31
32
  export * from "./workflow-runs";
32
33
  export * from "./workflows";
@@ -43,6 +43,7 @@ __exportStar(require("./tool-tests"), exports);
43
43
  __exportStar(require("./tools"), exports);
44
44
  __exportStar(require("./users"), exports);
45
45
  __exportStar(require("./user-permissions"), exports);
46
+ __exportStar(require("./user-trust-levels"), exports);
46
47
  __exportStar(require("./workflow-logs"), exports);
47
48
  __exportStar(require("./workflow-runs"), exports);
48
49
  __exportStar(require("./workflows"), exports);
@@ -23,7 +23,7 @@ declare const knowledgeFrameSchema: z.ZodObject<{
23
23
  conclusion?: string | undefined;
24
24
  }>;
25
25
  export type IKnowledgeFrame = z.infer<typeof knowledgeFrameSchema>;
26
- export declare function KnowledgeFrames(dataContext?: DataContext): import("../..").Table<{
26
+ export declare function KnowledgeFrames(dataContext?: DataContext): import("../orm").Table<{
27
27
  name: string;
28
28
  body: string;
29
29
  knowledgeFrameId: string;
@@ -20,7 +20,7 @@ declare const knowledgeLinkSchema: z.ZodObject<{
20
20
  objectValueId?: string | undefined;
21
21
  }>;
22
22
  export type IKnowledgeLink = z.infer<typeof knowledgeLinkSchema>;
23
- export declare function KnowledgeLinks(dataContext?: DataContext): import("../..").Table<{
23
+ export declare function KnowledgeLinks(dataContext?: DataContext): import("../orm").Table<{
24
24
  knowledgeLinkId: string;
25
25
  subjectValueId: string;
26
26
  predicateId: string;
@@ -24,7 +24,7 @@ export declare const knowledgeValueSchema: z.ZodObject<{
24
24
  lastModified?: Date | undefined;
25
25
  }>;
26
26
  export type IKnowledgeValue = z.infer<typeof knowledgeValueSchema>;
27
- export declare function KnowledgeValues(dataContext?: DataContext): import("../..").Table<{
27
+ export declare function KnowledgeValues(dataContext?: DataContext): import("../orm").Table<{
28
28
  name: string;
29
29
  value: {} & {
30
30
  [k: string]: any;
@@ -91,7 +91,7 @@ declare const valueTypeSchema: z.ZodObject<{
91
91
  iconClass?: string | undefined;
92
92
  }>;
93
93
  export type IPeerType = z.infer<typeof valueTypeSchema>;
94
- export declare function PeerTypes(dataContext?: DataContext): import("../..").Table<{
94
+ export declare function PeerTypes(dataContext?: DataContext): import("../orm").Table<{
95
95
  name: string;
96
96
  schema: {
97
97
  type: import("../tools").IOSchemaType;
@@ -23,7 +23,7 @@ declare const predicateSchema: z.ZodObject<{
23
23
  allowedObjectValueTypes?: string[] | undefined;
24
24
  }>;
25
25
  export type IPredicate = z.infer<typeof predicateSchema>;
26
- export declare function Predicates(dataContext?: DataContext): import("../..").Table<{
26
+ export declare function Predicates(dataContext?: DataContext): import("../orm").Table<{
27
27
  name: string;
28
28
  predicateId: string;
29
29
  description?: string | undefined;
@@ -13,8 +13,8 @@ export declare const messageSchema: z.ZodObject<{
13
13
  vars: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
14
14
  }, "strip", z.ZodTypeAny, {
15
15
  message: string;
16
- userId: string;
17
16
  createdAt: Date;
17
+ userId: string;
18
18
  channelId: string;
19
19
  messageId: string;
20
20
  assistantId?: string | undefined;
@@ -24,8 +24,8 @@ export declare const messageSchema: z.ZodObject<{
24
24
  fileIds?: string[] | undefined;
25
25
  }, {
26
26
  message: string;
27
- userId: string;
28
27
  createdAt: Date;
28
+ userId: string;
29
29
  channelId: string;
30
30
  messageId: string;
31
31
  assistantId?: string | undefined;
@@ -35,10 +35,10 @@ export declare const messageSchema: z.ZodObject<{
35
35
  fileIds?: string[] | undefined;
36
36
  }>;
37
37
  export type IMessage = z.infer<typeof messageSchema>;
38
- export declare function Messages(dataContext?: DataContext): import("..").Table<{
38
+ export declare function Messages(dataContext?: DataContext): import("./orm").Table<{
39
39
  message: string;
40
- userId: string;
41
40
  createdAt: Date;
41
+ userId: string;
42
42
  channelId: string;
43
43
  messageId: string;
44
44
  assistantId?: string | undefined;
@@ -23,43 +23,33 @@ class ClientProxyDataSource {
23
23
  }
24
24
  }
25
25
  async get(id, opts = {}) {
26
- return rpc_types_1.rpcServerCalls.tableGet(this.dataContextId, this.tableName, id, opts);
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.tableList(this.dataContextId, this.tableName, filter, opts);
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.tableCount(this.dataContextId, this.tableName, filter);
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
- if (!opts?.enforceUnique) {
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.tableSave(this.dataContextId, this.tableName, record, opts);
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.tableInsert(this.dataContextId, this.tableName, record);
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.tableUpdate(this.dataContextId, this.tableName, record);
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.tableDelete(this.dataContextId, this.tableName, idOrRecord);
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 ProxyClientCalls(): (target: any, context: any) => any;
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.ProxyClientCalls = ProxyClientCalls;
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 ProxyClientCalls() {
10
+ function ProxyClientTableMethodCalls() {
10
11
  return function (target, context) {
11
- if (context.kind === 'method' && typeof window !== 'undefined') {
12
+ if (context.kind === 'method' && rpc_types_1.isClient) {
12
13
  const methodName = context.name;
13
- return function (...args) {
14
- // Lazy import to avoid circular dependencies
15
- const { rpcServerCalls } = require("../..");
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;
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import type { DataContext } from "../context/data-context";
3
- import { ISaveOptions, Table } from "./orm";
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;
@@ -1,11 +1,46 @@
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");
6
40
  const context_1 = require("../context");
7
41
  const app_nav_1 = require("../types/app-nav");
8
- const orm_1 = require("./orm");
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
45
  const types_1 = require("./orm/types");
11
46
  const package_permissions_1 = require("./package-permissions");
@@ -34,52 +69,67 @@ const metaData = {
34
69
  iconClassName: 'bi bi-box-fill',
35
70
  fields: (0, types_1.schemaToFields)(schema),
36
71
  };
37
- class PackagesTable extends orm_1.Table {
38
- static isPassthrough = false;
39
- async insert(packageObj, opts) {
40
- return this.save(packageObj, opts);
41
- }
42
- async update(packageObj, opts) {
43
- return this.save(packageObj, opts);
44
- }
45
- async save(packageObj, opts) {
46
- if (PackagesTable.isPassthrough) {
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
- if (!this.groupId) {
50
- // users can do whatever they want to packages in their personal space
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
- try {
54
- await (0, package_permissions_1.verifyPackageSignature)(packageObj, this.groupId);
113
+ static addSignatureToPackage = undefined;
114
+ static enablePackageSigning(fn) {
115
+ this.addSignatureToPackage = fn;
55
116
  }
56
- catch (err) {
57
- throw new Error('Package verification failed. Did you mean to call `signAndSave`?', { cause: err });
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
- return super.save(packageObj, opts);
60
- }
61
- async signAndSave(packageObj, opts) {
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
- packageObj = await PackagesTable.addSignatureToPackage(packageObj);
66
- return super.save(packageObj, opts);
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) {
@@ -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("../..").Table<{
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("../..").Table<{
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("..").Table<{
29
+ export declare function ToolTests(dataContext?: DataContext): import("./orm").Table<{
30
30
  code: string;
31
31
  description: string;
32
32
  toolId: string;
@@ -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("..").Table<{
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 trust level changes with valid signature in group context', () => {
148
- const originalUser = (0, user_permissions_1.signUserObject)({ ...testUser, trustLevel: socket_type_1.TrustLevel.Unknown }, userKeys.secretKey);
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
- trustLevel: socket_type_1.TrustLevel.Trusted,
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 complex trust level enum values', () => {
197
- const userWithComplexTrust = {
194
+ it('should handle various user values', () => {
195
+ const userWithValues = {
198
196
  ...testUser,
199
- trustLevel: socket_type_1.TrustLevel.Malicious
197
+ name: 'Complex Name'
200
198
  };
201
- const signedUser = (0, user_permissions_1.signUserObject)(userWithComplexTrust, userKeys.secretKey);
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>;