@proteinjs/user 1.2.16 → 1.2.18

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.
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.SharedItemTable = void 0;
58
+ var UserRepo_1 = require("../src/UserRepo");
59
+ var moment_1 = __importDefault(require("moment"));
60
+ var db_1 = require("@proteinjs/db");
61
+ var db_driver_knex_1 = require("@proteinjs/db-driver-knex");
62
+ var SharedRecord_1 = require("../src/SharedRecord");
63
+ var AccessGrantTable_1 = require("../src/tables/AccessGrantTable");
64
+ var server_api_1 = require("@proteinjs/server-api");
65
+ var reflection_1 = require("@proteinjs/reflection");
66
+ var tables_1 = require("../src/tables/tables");
67
+ var DbDriverFactory = /** @class */ (function () {
68
+ function DbDriverFactory(dbDriver) {
69
+ this.dbDriver = dbDriver;
70
+ }
71
+ DbDriverFactory.prototype.getDbDriver = function () {
72
+ return this.dbDriver;
73
+ };
74
+ return DbDriverFactory;
75
+ }());
76
+ var TestSessionDataStorage = /** @class */ (function () {
77
+ function TestSessionDataStorage() {
78
+ this.environment = 'node';
79
+ }
80
+ TestSessionDataStorage.prototype.setData = function (data) {
81
+ TestSessionDataStorage.SESSION_DATA['sessionData'] = data;
82
+ };
83
+ TestSessionDataStorage.prototype.getData = function () {
84
+ return TestSessionDataStorage.SESSION_DATA['sessionData'];
85
+ };
86
+ TestSessionDataStorage.SESSION_DATA = {};
87
+ return TestSessionDataStorage;
88
+ }());
89
+ var users = [
90
+ {
91
+ name: 'Test user0',
92
+ email: 'test.user0',
93
+ password: 'test',
94
+ emailVerified: false,
95
+ roles: '',
96
+ created: (0, moment_1.default)(),
97
+ updated: (0, moment_1.default)(),
98
+ id: 'user0',
99
+ },
100
+ {
101
+ name: 'Test user1',
102
+ email: 'test.user1',
103
+ password: 'test',
104
+ emailVerified: false,
105
+ roles: '',
106
+ created: (0, moment_1.default)(),
107
+ updated: (0, moment_1.default)(),
108
+ id: 'user1',
109
+ },
110
+ ];
111
+ var SharedItemTable = /** @class */ (function (_super) {
112
+ __extends(SharedItemTable, _super);
113
+ function SharedItemTable() {
114
+ var _this = _super !== null && _super.apply(this, arguments) || this;
115
+ _this.name = 'user_test_shared_item';
116
+ _this.columns = (0, SharedRecord_1.withSharedRecordColumns)({
117
+ name: new db_1.StringColumn('name'),
118
+ });
119
+ return _this;
120
+ }
121
+ return SharedItemTable;
122
+ }(db_1.Table));
123
+ exports.SharedItemTable = SharedItemTable;
124
+ var dbDriver = new db_driver_knex_1.KnexDriver({
125
+ host: 'localhost',
126
+ user: 'root',
127
+ password: '',
128
+ dbName: 'test',
129
+ });
130
+ var userRepo = new UserRepo_1.UserRepo();
131
+ var dropTable = function (table) { return __awaiter(void 0, void 0, void 0, function () {
132
+ return __generator(this, function (_a) {
133
+ switch (_a.label) {
134
+ case 0: return [4 /*yield*/, dbDriver.getKnex().schema.withSchema(dbDriver.getDbName()).hasTable(table.name)];
135
+ case 1:
136
+ if (!_a.sent()) return [3 /*break*/, 3];
137
+ return [4 /*yield*/, dbDriver.getKnex().schema.withSchema(dbDriver.getDbName()).dropTable(table.name)];
138
+ case 2:
139
+ _a.sent();
140
+ _a.label = 3;
141
+ case 3: return [2 /*return*/];
142
+ }
143
+ });
144
+ }); };
145
+ // TODO use TestEnvironment
146
+ describe('Shared Record', function () {
147
+ beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
148
+ return __generator(this, function (_a) {
149
+ switch (_a.label) {
150
+ case 0:
151
+ reflection_1.SourceRepository.get().objectCache['@proteinjs/db/DefaultDbDriverFactory'] = [
152
+ new DbDriverFactory(dbDriver),
153
+ ];
154
+ reflection_1.SourceRepository.get().objectCache['@proteinjs/server-api/SessionDataStorage'] = [
155
+ new TestSessionDataStorage(),
156
+ ];
157
+ reflection_1.SourceRepository.get().objectCache['@proteinjs/db/Table'] = [
158
+ tables_1.tables.AccessGrant,
159
+ new SharedItemTable(),
160
+ ];
161
+ server_api_1.Session.setData({
162
+ sessionId: 'test-session',
163
+ user: 'guest',
164
+ data: {},
165
+ });
166
+ userRepo.setUser(users[0]);
167
+ if (!dbDriver.start) return [3 /*break*/, 2];
168
+ return [4 /*yield*/, dbDriver.start()];
169
+ case 1:
170
+ _a.sent();
171
+ _a.label = 2;
172
+ case 2:
173
+ jest.spyOn(db_1.Db, 'getDefaultDbDriver').mockImplementation(function () { return dbDriver; });
174
+ return [2 /*return*/];
175
+ }
176
+ });
177
+ }); });
178
+ beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0: return [4 /*yield*/, dbDriver.getTableManager().loadTable(new SharedItemTable())];
182
+ case 1:
183
+ _a.sent();
184
+ return [4 /*yield*/, dbDriver.getTableManager().loadTable(new AccessGrantTable_1.AccessGrantTable())];
185
+ case 2:
186
+ _a.sent();
187
+ return [2 /*return*/];
188
+ }
189
+ });
190
+ }); });
191
+ afterEach(function () { return __awaiter(void 0, void 0, void 0, function () {
192
+ return __generator(this, function (_a) {
193
+ switch (_a.label) {
194
+ case 0: return [4 /*yield*/, dropTable(new SharedItemTable())];
195
+ case 1:
196
+ _a.sent();
197
+ return [4 /*yield*/, dropTable(new AccessGrantTable_1.AccessGrantTable())];
198
+ case 2:
199
+ _a.sent();
200
+ return [2 /*return*/];
201
+ }
202
+ });
203
+ }); });
204
+ afterAll(function () {
205
+ if (dbDriver.stop) {
206
+ dbDriver.stop();
207
+ }
208
+ });
209
+ test('Query shared records with access grants', function () { return __awaiter(void 0, void 0, void 0, function () {
210
+ var sharedItemTable, user0, user1, user0Item1, user0Item2, user1Item1, items, itemNames;
211
+ return __generator(this, function (_a) {
212
+ switch (_a.label) {
213
+ case 0:
214
+ sharedItemTable = new SharedItemTable();
215
+ user0 = users[0], user1 = users[1];
216
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDbAsSystem)().insert(sharedItemTable, {
217
+ name: "".concat(user0.name, "_item1"),
218
+ })];
219
+ case 1:
220
+ user0Item1 = _a.sent();
221
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDbAsSystem)().insert(sharedItemTable, {
222
+ name: "".concat(user0.name, "_item2"),
223
+ })];
224
+ case 2:
225
+ user0Item2 = _a.sent();
226
+ userRepo.setUser(user1);
227
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDbAsSystem)().insert(sharedItemTable, {
228
+ name: "".concat(user1.name, "_item1"),
229
+ })];
230
+ case 3:
231
+ user1Item1 = _a.sent();
232
+ userRepo.setUser(user0);
233
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDb)().query(sharedItemTable, {})];
234
+ case 4:
235
+ items = _a.sent();
236
+ // Should only return items that user0 has access to
237
+ expect(items.length).toBe(2);
238
+ itemNames = items.map(function (item) { return item.name; });
239
+ expect(itemNames).toContain(user0Item1.name);
240
+ expect(itemNames).toContain(user0Item2.name);
241
+ expect(itemNames).not.toContain(user1Item1.name);
242
+ return [2 /*return*/];
243
+ }
244
+ });
245
+ }); });
246
+ test('System DB can access all shared records', function () { return __awaiter(void 0, void 0, void 0, function () {
247
+ var sharedItemTable, user0, user1, items;
248
+ return __generator(this, function (_a) {
249
+ switch (_a.label) {
250
+ case 0:
251
+ sharedItemTable = new SharedItemTable();
252
+ user0 = users[0], user1 = users[1];
253
+ userRepo.setUser(user0);
254
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDb)().insert(sharedItemTable, {
255
+ name: "".concat(user0.name, "_item1"),
256
+ })];
257
+ case 1:
258
+ _a.sent();
259
+ userRepo.setUser(user1);
260
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDb)().insert(sharedItemTable, {
261
+ name: "".concat(user1.name, "_item1"),
262
+ })];
263
+ case 2:
264
+ _a.sent();
265
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDbAsSystem)().query(sharedItemTable, {})];
266
+ case 3:
267
+ items = _a.sent();
268
+ expect(items.length).toBe(2);
269
+ return [2 /*return*/];
270
+ }
271
+ });
272
+ }); });
273
+ test('Only Admin can create AccessGrants', function () { return __awaiter(void 0, void 0, void 0, function () {
274
+ var sharedItemTable, accessGrantTable, user0, user1, sharedItem, error_1, grantForUser1;
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0:
278
+ sharedItemTable = new SharedItemTable();
279
+ accessGrantTable = new AccessGrantTable_1.AccessGrantTable();
280
+ user0 = users[0], user1 = users[1];
281
+ userRepo.setUser(user0);
282
+ return [4 /*yield*/, (0, SharedRecord_1.getSharedDbAsSystem)().insert(sharedItemTable, {
283
+ name: 'Shared item for access grant test',
284
+ })];
285
+ case 1:
286
+ sharedItem = _a.sent();
287
+ _a.label = 2;
288
+ case 2:
289
+ _a.trys.push([2, 4, , 5]);
290
+ userRepo.setUser(user1);
291
+ return [4 /*yield*/, (0, db_1.getDb)().insert(accessGrantTable, {
292
+ principal: new db_1.Reference('user', user1.id),
293
+ resource: new db_1.Reference(sharedItemTable.name, sharedItem.id),
294
+ resourceTable: sharedItemTable.name,
295
+ accessLevel: 'read',
296
+ })];
297
+ case 3:
298
+ _a.sent();
299
+ // If we reach here, the test should fail because the insert should have thrown an error
300
+ fail('User without admin access was able to create an access grant');
301
+ return [3 /*break*/, 5];
302
+ case 4:
303
+ error_1 = _a.sent();
304
+ expect(error_1).toBeInstanceOf(Error);
305
+ return [3 /*break*/, 5];
306
+ case 5:
307
+ userRepo.setUser(user0);
308
+ return [4 /*yield*/, (0, db_1.getDb)().insert(accessGrantTable, {
309
+ principal: new db_1.Reference('user', user1.id),
310
+ resource: new db_1.Reference(sharedItemTable.name, sharedItem.id),
311
+ resourceTable: sharedItemTable.name,
312
+ accessLevel: 'read',
313
+ })];
314
+ case 6:
315
+ grantForUser1 = _a.sent();
316
+ expect(grantForUser1.id).toBeDefined();
317
+ expect(grantForUser1.principal._id).toBe(user1.id);
318
+ expect(grantForUser1.accessLevel).toBe('read');
319
+ return [2 /*return*/];
320
+ }
321
+ });
322
+ }); });
323
+ });
324
+ //# sourceMappingURL=SharedRecord.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedRecord.test.js","sourceRoot":"","sources":["../../test/SharedRecord.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,kDAA4B;AAC5B,oCAAoF;AACpF,4DAAuD;AACvD,oDAA8G;AAC9G,mEAAkE;AAClE,oDAAiF;AACjF,oDAAyD;AACzD,+CAA8C;AAM9C;IACE,yBAAoB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;IAAG,CAAC;IAE1C,qCAAW,GAAX;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACH,sBAAC;AAAD,CAAC,AAND,IAMC;AAED;IAAA;QACE,gBAAW,GAAG,MAAgB,CAAC;IAUjC,CAAC;I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O,CAAC,KAAK,CAAC,CAAC;oBACF,qBAAM,IAAA,UAAK,GAAE,CAAC,MAAM,CAAC,gBAAgB,EAAE;4BAC3D,SAAS,EAAE,IAAI,cAAS,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;4BAC1C,QAAQ,EAAE,IAAI,cAAS,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC;4BAC5D,aAAa,EAAE,eAAe,CAAC,IAAI;4BACnC,WAAW,EAAE,MAAM;yBACpB,CAAC,EAAA;;oBALI,aAAa,GAAG,SAKpB;oBAEF,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;oBACvC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;oBACnD,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;SAChD,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -10,18 +10,20 @@ import 'moment';
10
10
 
11
11
  /** Generate Source Graph */
12
12
 
13
- const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"ScopedRecord\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/ScopedRecord.ts\",\"qualifiedName\":\"@proteinjs/user/ScopedRecord\",\"properties\":[{\"name\":\"scope\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/db/Record\"},{\"v\":\"@proteinjs/user/UserRepo\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserRepo\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/UserRepo.ts\",\"qualifiedName\":\"@proteinjs/user/UserRepo\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"\",\"name\":\"Omit<User, 'roles'> & AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"/Omit<User, 'roles'> & AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]},{\"name\":\"setUser\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"user\",\"type\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\"},{\"v\":\"/Pick\"},{\"v\":\"@proteinjs/user/SignupService\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SignupService\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/services/SignupService.ts\",\"qualifiedName\":\"@proteinjs/user/SignupService\",\"properties\":[],\"methods\":[{\"name\":\"createUser\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"user\",\"type\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserSignup\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/UserSignup\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"token\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"sendInvite\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<SendInviteResponse>\",\"filePath\":null,\"qualifiedName\":\"/Promise<SendInviteResponse>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"email\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"revokeInvite\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"email\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"initializeSignup\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<InitializeSignupResponse>\",\"filePath\":null,\"qualifiedName\":\"/Promise<InitializeSignupResponse>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"inviteToken\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/service/Service\"},{\"v\":\"@proteinjs/user/UpdateUserInfoService\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UpdateUserInfoService\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/services/UpdateUserInfoService.ts\",\"qualifiedName\":\"@proteinjs/user/UpdateUserInfoService\",\"properties\":[],\"methods\":[{\"name\":\"updateName\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"updatePassword\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<UpdatePasswordResponse>\",\"filePath\":null,\"qualifiedName\":\"/Promise<UpdatePasswordResponse>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"currentPassword\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"newPassword\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/user/Invite\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"Invite\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/InviteTable.ts\",\"qualifiedName\":\"@proteinjs/user/Invite\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n email: string;\\n token: string | null;\\n tokenExpiresAt: Moment | null;\\n invitedBy: string;\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n email: string;\\n token: string | null;\\n tokenExpiresAt: Moment | null;\\n invitedBy: string;\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/InviteTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"InviteTable\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/InviteTable.ts\",\"qualifiedName\":\"@proteinjs/user/InviteTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/Invite\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"},{\"v\":\"@proteinjs/user/Session\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"Session\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/Session\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n sessionId: string;\\n session: string;\\n expires: Date;\\n userEmail: string;\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n sessionId: string;\\n session: string;\\n expires: Date;\\n userEmail: string;\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/SessionTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SessionTable\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/SessionTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/Session\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/user/User\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n name: string;\\n email: string;\\n password: string;\\n passwordResetToken?: string | null;\\n passwordResetTokenExpiration?: Moment | null;\\n emailVerified: boolean;\\n roles: string;\\n invitedBy?: string | null;\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n name: string;\\n email: string;\\n password: string;\\n passwordResetToken?: string | null;\\n passwordResetTokenExpiration?: Moment | null;\\n emailVerified: boolean;\\n roles: string;\\n invitedBy?: string | null;\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/UserTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserTable\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/UserTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/User\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}}],\"edges\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UserRepo\",\"w\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/user/SignupService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UpdateUserInfoService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/Invite\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/InviteTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/Session\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/SessionTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/User\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/UserTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
13
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"ScopedRecord\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/ScopedRecord.ts\",\"qualifiedName\":\"@proteinjs/user/ScopedRecord\",\"properties\":[{\"name\":\"scope\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/db/Record\"},{\"v\":\"@proteinjs/user/SharedRecord\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SharedRecord\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/SharedRecord.ts\",\"qualifiedName\":\"@proteinjs/user/SharedRecord\",\"properties\":[{\"name\":\"permissionSource\",\"type\":{\"packageName\":\"\",\"name\":\"Reference<T>\",\"filePath\":null,\"qualifiedName\":\"/Reference<T>\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"permissionSourceTable\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[\"/T extends SharedRecord = any\"],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/user/UserRepo\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserRepo\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/UserRepo.ts\",\"qualifiedName\":\"@proteinjs/user/UserRepo\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"\",\"name\":\"Omit<User, 'roles'> & AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"/Omit<User, 'roles'> & AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]},{\"name\":\"setUser\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"user\",\"type\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\"},{\"v\":\"/Pick\"},{\"v\":\"@proteinjs/user/SignupService\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SignupService\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/services/SignupService.ts\",\"qualifiedName\":\"@proteinjs/user/SignupService\",\"properties\":[],\"methods\":[{\"name\":\"createUser\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"user\",\"type\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserSignup\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/UserSignup\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"token\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"sendInvite\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<SendInviteResponse>\",\"filePath\":null,\"qualifiedName\":\"/Promise<SendInviteResponse>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"email\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"revokeInvite\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"email\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"initializeSignup\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<InitializeSignupResponse>\",\"filePath\":null,\"qualifiedName\":\"/Promise<InitializeSignupResponse>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"inviteToken\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/service/Service\"},{\"v\":\"@proteinjs/user/UpdateUserInfoService\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UpdateUserInfoService\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/services/UpdateUserInfoService.ts\",\"qualifiedName\":\"@proteinjs/user/UpdateUserInfoService\",\"properties\":[],\"methods\":[{\"name\":\"updateName\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"updatePassword\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<UpdatePasswordResponse>\",\"filePath\":null,\"qualifiedName\":\"/Promise<UpdatePasswordResponse>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"currentPassword\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"newPassword\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/user/AccessGrant\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"AccessGrant\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/AccessGrantTable.ts\",\"qualifiedName\":\"@proteinjs/user/AccessGrant\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n principal: Reference<any>;\\n resource: Reference<any>;\\n resourceTable?: Table<any>['name'];\\n accessLevel: 'read' | 'write' | 'admin';\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n principal: Reference<any>;\\n resource: Reference<any>;\\n resourceTable?: Table<any>['name'];\\n accessLevel: 'read' | 'write' | 'admin';\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/AccessGrantTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"AccessGrantTable\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/AccessGrantTable.ts\",\"qualifiedName\":\"@proteinjs/user/AccessGrantTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/AccessGrant\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"},{\"v\":\"@proteinjs/user/Invite\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"Invite\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/InviteTable.ts\",\"qualifiedName\":\"@proteinjs/user/Invite\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n email: string;\\n token: string | null;\\n tokenExpiresAt: Moment | null;\\n invitedBy: string;\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n email: string;\\n token: string | null;\\n tokenExpiresAt: Moment | null;\\n invitedBy: string;\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/InviteTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"InviteTable\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/InviteTable.ts\",\"qualifiedName\":\"@proteinjs/user/InviteTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/Invite\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/user/Session\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"Session\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/Session\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n sessionId: string;\\n session: string;\\n expires: Date;\\n userEmail: string;\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n sessionId: string;\\n session: string;\\n expires: Date;\\n userEmail: string;\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/SessionTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SessionTable\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/SessionTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/Session\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/user/User\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n name: string;\\n email: string;\\n password: string;\\n passwordResetToken?: string | null;\\n passwordResetTokenExpiration?: Moment | null;\\n emailVerified: boolean;\\n roles: string;\\n invitedBy?: string | null;\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n name: string;\\n email: string;\\n password: string;\\n passwordResetToken?: string | null;\\n passwordResetTokenExpiration?: Moment | null;\\n emailVerified: boolean;\\n roles: string;\\n invitedBy?: string | null;\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/UserTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserTable\",\"filePath\":\"/Users/mauricio/dev/n3xa-dev/n3xa/packages/proteinjs/packages/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/UserTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/User\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}}],\"edges\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/SharedRecord\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UserRepo\",\"w\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/user/SignupService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UpdateUserInfoService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/AccessGrant\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/AccessGrantTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/Invite\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/InviteTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/Session\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/SessionTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/User\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/UserTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
14
14
 
15
15
 
16
16
  /** Generate Source Links */
17
17
 
18
18
  import { UserRepo } from '../src/UserRepo';
19
+ import { AccessGrantTable } from '../src/tables/AccessGrantTable';
19
20
  import { InviteTable } from '../src/tables/InviteTable';
20
21
  import { SessionTable } from '../src/tables/SessionTable';
21
22
  import { UserTable } from '../src/tables/UserTable';
22
23
 
23
24
  const sourceLinks = {
24
25
  '@proteinjs/user/UserRepo': UserRepo,
26
+ '@proteinjs/user/AccessGrantTable': AccessGrantTable,
25
27
  '@proteinjs/user/InviteTable': InviteTable,
26
28
  '@proteinjs/user/SessionTable': SessionTable,
27
29
  '@proteinjs/user/UserTable': UserTable,
package/index.ts CHANGED
@@ -9,5 +9,6 @@ export * from './src/routes';
9
9
  export * from './src/cacheKeys';
10
10
  export * from './src/UserRepo';
11
11
  export * from './src/ScopedRecord';
12
+ export * from './src/SharedRecord';
12
13
 
13
14
  export * from '@proteinjs/user-auth';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/user",
3
- "version": "1.2.16",
3
+ "version": "1.2.18",
4
4
  "description": "User management",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,15 +22,15 @@
22
22
  "test": "jest"
23
23
  },
24
24
  "dependencies": {
25
- "@proteinjs/db": "1.15.2",
25
+ "@proteinjs/db": "1.16.0",
26
26
  "@proteinjs/reflection": "1.1.10",
27
- "@proteinjs/server-api": "1.5.4",
28
- "@proteinjs/service": "1.2.4",
27
+ "@proteinjs/server-api": "2.0.0",
28
+ "@proteinjs/service": "1.2.5",
29
29
  "@proteinjs/user-auth": "^1.1.5",
30
30
  "moment": "2.29.4"
31
31
  },
32
32
  "devDependencies": {
33
- "@proteinjs/db-driver-knex": "1.4.8",
33
+ "@proteinjs/db-driver-knex": "1.4.10",
34
34
  "@proteinjs/reflection-build": "1.2.0",
35
35
  "@types/jest": "29.5.5",
36
36
  "@types/node": "14.0.13",
@@ -0,0 +1,106 @@
1
+ import {
2
+ Columns,
3
+ Db,
4
+ QueryBuilder,
5
+ Record,
6
+ Table,
7
+ getColumnByName,
8
+ getDb,
9
+ getTables,
10
+ withRecordColumns,
11
+ Reference,
12
+ DynamicReferenceColumn,
13
+ DynamicReferenceTableNameColumn,
14
+ } from '@proteinjs/db';
15
+
16
+ import { AccessGrant, AccessGrantTable } from './tables/AccessGrantTable';
17
+ import { UserRepo } from './UserRepo';
18
+ import { UserTable } from './tables/UserTable';
19
+
20
+ export interface SharedRecord<T extends SharedRecord = any> extends Record {
21
+ permissionSource: Reference<T>;
22
+ permissionSourceTable: string;
23
+ }
24
+
25
+ export const getSharedDb = getDb<SharedRecord>;
26
+ export const getSharedDbWithOverride = getDb<Omit<SharedRecord, 'permissionSource'>>;
27
+
28
+ export const getSharedDbAsSystem = <R extends SharedRecord = SharedRecord>() =>
29
+ new Db<R>(undefined, undefined, undefined, true);
30
+
31
+ const getSharedRecordColumns = () => {
32
+ return {
33
+ permissionSource: new DynamicReferenceColumn('permission_source', 'permission_source_table', true, {
34
+ defaultValue: async (table, insertObj) => {
35
+ const user = new UserRepo().getUser();
36
+ const db = getDb<AccessGrant>();
37
+
38
+ await db.insert(new AccessGrantTable() as Table<AccessGrant>, {
39
+ principal: new Reference(new UserTable().name, user.id),
40
+ resource: new Reference(table.name, insertObj.id),
41
+ resourceTable: table.name,
42
+ accessLevel: 'admin',
43
+ });
44
+
45
+ return new Reference(table.name, insertObj.id);
46
+ },
47
+ addToQuery: async (qb, runAsSystem) => {
48
+ if (runAsSystem) {
49
+ return;
50
+ }
51
+ const subQuery = new QueryBuilder(new AccessGrantTable().name);
52
+ subQuery.select({
53
+ fields: ['resource'],
54
+ });
55
+
56
+ subQuery.condition({
57
+ field: 'principal',
58
+ operator: '=',
59
+ value: new UserRepo().getUser().id,
60
+ });
61
+
62
+ subQuery.condition({
63
+ field: 'accessLevel',
64
+ operator: 'IN',
65
+ value: ['read', 'write', 'admin'],
66
+ });
67
+
68
+ subQuery.condition({
69
+ field: 'resourceTable',
70
+ operator: '=',
71
+ value: qb.tableName,
72
+ });
73
+
74
+ qb.condition({
75
+ field: 'permissionSource',
76
+ operator: 'IN',
77
+ value: subQuery,
78
+ });
79
+ },
80
+ }),
81
+ permissionSourceTable: new DynamicReferenceTableNameColumn('permission_source_table', 'permission_source', {
82
+ defaultValue: async (table) => table.name,
83
+ forceDefaultValue: true,
84
+ }),
85
+ };
86
+ };
87
+
88
+ export function getSharedTables() {
89
+ return getTables<SharedRecord>().filter((table) => isSharedTable(table));
90
+ }
91
+
92
+ export function isSharedTable(table: Table<any>): table is Table<SharedRecord> {
93
+ return !!getColumnByName(table, getSharedRecordColumns().permissionSource.name);
94
+ }
95
+
96
+ /**
97
+ * Wrapper function to add default Shared columns to your table's columns.
98
+ *
99
+ * @param columns your columns
100
+ * @returns recordColumns & sourceRecordColumns & your columns
101
+ */
102
+ export function withSharedRecordColumns<T extends SharedRecord>(
103
+ columns: Columns<Omit<T, keyof SharedRecord>>
104
+ ): Columns<SharedRecord> & Columns<Omit<T, keyof SharedRecord>> {
105
+ return Object.assign(Object.assign({}, getSharedRecordColumns()), withRecordColumns<Record>(columns) as any);
106
+ }