@proteinjs/user 1.2.17 → 1.3.0
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/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +5 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/src/SharedRecord.d.ts +18 -0
- package/dist/src/SharedRecord.d.ts.map +1 -0
- package/dist/src/SharedRecord.js +132 -0
- package/dist/src/SharedRecord.js.map +1 -0
- package/dist/src/services/AccessInviteService.d.ts +25 -0
- package/dist/src/services/AccessInviteService.d.ts.map +1 -0
- package/dist/src/services/AccessInviteService.js +9 -0
- package/dist/src/services/AccessInviteService.js.map +1 -0
- package/dist/src/tables/AccessGrantTable.d.ts +22 -0
- package/dist/src/tables/AccessGrantTable.d.ts.map +1 -0
- package/dist/src/tables/AccessGrantTable.js +105 -0
- package/dist/src/tables/AccessGrantTable.js.map +1 -0
- package/dist/src/tables/AccessInviteTable.d.ts +29 -0
- package/dist/src/tables/AccessInviteTable.d.ts.map +1 -0
- package/dist/src/tables/AccessInviteTable.js +133 -0
- package/dist/src/tables/AccessInviteTable.js.map +1 -0
- package/dist/src/tables/tables.d.ts +4 -0
- package/dist/src/tables/tables.d.ts.map +1 -1
- package/dist/src/tables/tables.js +4 -0
- package/dist/src/tables/tables.js.map +1 -1
- package/dist/test/SharedRecord.test.d.ts +19 -0
- package/dist/test/SharedRecord.test.d.ts.map +1 -0
- package/dist/test/SharedRecord.test.js +324 -0
- package/dist/test/SharedRecord.test.js.map +1 -0
- package/generated/index.ts +11 -10
- package/index.ts +3 -0
- package/package.json +5 -4
- package/src/SharedRecord.ts +106 -0
- package/src/services/AccessInviteService.ts +30 -0
- package/src/tables/AccessGrantTable.ts +57 -0
- package/src/tables/AccessInviteTable.ts +65 -0
- package/src/tables/tables.ts +4 -0
- package/test/SharedRecord.test.ts +212 -0
package/generated/index.ts
CHANGED
|
@@ -7,31 +7,32 @@ import '@proteinjs/service';
|
|
|
7
7
|
import '@proteinjs/user-auth';
|
|
8
8
|
import 'moment';
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
/** Generate Source Graph */
|
|
12
11
|
|
|
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\":\"@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}},{\"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}}],\"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/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\"},{\"v\":\"@proteinjs/user/SignupService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UpdateUserInfoService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"}]}";
|
|
14
|
-
|
|
12
|
+
const sourceGraph =
|
|
13
|
+
'{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/user/ScopedRecord","value":{"packageName":"@proteinjs/user","name":"ScopedRecord","filePath":"/home/runner/work/user/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":"/home/runner/work/user/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":"/home/runner/work/user/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":"@proteinjs/user/AccessInviteService","value":{"packageName":"@proteinjs/user","name":"AccessInviteService","filePath":"/home/runner/work/user/user/packages/user/src/services/AccessInviteService.ts","qualifiedName":"@proteinjs/user/AccessInviteService","properties":[],"methods":[{"name":"createAccessInvite","returnType":{"packageName":"","name":"Promise<CreateAccessInviteResponse>","filePath":null,"qualifiedName":"/Promise<CreateAccessInviteResponse>","typeParameters":null,"directParents":null},"isAsync":false,"isOptional":false,"isAbstract":true,"isStatic":false,"visibility":"public","parameters":[{"name":"params","type":{"packageName":"@proteinjs/user","name":"CreateAccessInviteParams","filePath":null,"qualifiedName":"@proteinjs/user/CreateAccessInviteParams","typeParameters":null,"directParents":null}}]},{"name":"acceptAccessInvite","returnType":{"packageName":"","name":"Promise<T | undefined>","filePath":null,"qualifiedName":"/Promise<T | undefined>","typeParameters":null,"directParents":null},"isAsync":false,"isOptional":false,"isAbstract":true,"isStatic":false,"visibility":"public","parameters":[{"name":"token","type":{"packageName":"","name":"string","filePath":null,"qualifiedName":"/string","typeParameters":null,"directParents":null}}]}],"typeParameters":["/T extends Record"],"directParents":[{"packageName":"@proteinjs/service","name":"Service","filePath":null,"qualifiedName":"@proteinjs/service/Service","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"sourceType":3}},{"v":"@proteinjs/service/Service"},{"v":"/Pick"},{"v":"@proteinjs/user/SignupService","value":{"packageName":"@proteinjs/user","name":"SignupService","filePath":"/home/runner/work/user/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/user/UpdateUserInfoService","value":{"packageName":"@proteinjs/user","name":"UpdateUserInfoService","filePath":"/home/runner/work/user/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":"/home/runner/work/user/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":"/home/runner/work/user/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/AccessInvite","value":{"packageName":"@proteinjs/user","name":"AccessInvite","filePath":"/home/runner/work/user/user/packages/user/src/tables/AccessInviteTable.ts","qualifiedName":"@proteinjs/user/AccessInvite","typeParameters":["/T extends Record = any"],"directParents":[{"packageName":"@proteinjs/db","name":"Record","filePath":null,"qualifiedName":"@proteinjs/db/Record","typeParameters":[],"directParents":null},{"packageName":"@proteinjs/user","name":"{\\n token?: string;\\n tokenExpiresAt: Moment;\\n resource: Reference<T>;\\n resourceTable: string;\\n accepted?: boolean;\\n acceptedBy?: Reference<User>;\\n acceptedAt?: Moment;\\n}","filePath":null,"qualifiedName":"@proteinjs/user/{\\n token?: string;\\n tokenExpiresAt: Moment;\\n resource: Reference<T>;\\n resourceTable: string;\\n accepted?: boolean;\\n acceptedBy?: Reference<User>;\\n acceptedAt?: Moment;\\n}","typeParameters":[],"directParents":null}],"sourceType":1}},{"v":"@proteinjs/user/AccessInviteTable","value":{"packageName":"@proteinjs/user","name":"AccessInviteTable","filePath":"/home/runner/work/user/user/packages/user/src/tables/AccessInviteTable.ts","qualifiedName":"@proteinjs/user/AccessInviteTable","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/AccessInvite"],"directParentInterfaces":[],"directParentClasses":[]}],"sourceType":2}},{"v":"@proteinjs/user/Invite","value":{"packageName":"@proteinjs/user","name":"Invite","filePath":"/home/runner/work/user/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":"/home/runner/work/user/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":"/home/runner/work/user/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":"/home/runner/work/user/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":"/home/runner/work/user/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":"/home/runner/work/user/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/AccessInviteService","w":"@proteinjs/service/Service","value":"extends 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/AccessInvite","w":"@proteinjs/db/Record","value":"extends type"},{"v":"@proteinjs/user/AccessInviteTable","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"}]}';
|
|
15
14
|
|
|
16
15
|
/** Generate Source Links */
|
|
17
16
|
|
|
18
17
|
import { UserRepo } from '../src/UserRepo';
|
|
18
|
+
import { AccessGrantTable } from '../src/tables/AccessGrantTable';
|
|
19
|
+
import { AccessInviteTable } from '../src/tables/AccessInviteTable';
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
'@proteinjs/user/UserRepo': UserRepo,
|
|
26
|
+
'@proteinjs/user/AccessGrantTable': AccessGrantTable,
|
|
27
|
+
'@proteinjs/user/AccessInviteTable': AccessInviteTable,
|
|
28
|
+
'@proteinjs/user/InviteTable': InviteTable,
|
|
29
|
+
'@proteinjs/user/SessionTable': SessionTable,
|
|
30
|
+
'@proteinjs/user/UserTable': UserTable,
|
|
28
31
|
};
|
|
29
32
|
|
|
30
|
-
|
|
31
33
|
/** Load Source Graph and Links */
|
|
32
34
|
|
|
33
35
|
import { SourceRepository } from '@proteinjs/reflection';
|
|
34
36
|
SourceRepository.merge(sourceGraph, sourceLinks);
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
export * from '../index';
|
|
38
|
+
export * from '../index';
|
package/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from './src/services/AccessInviteService';
|
|
1
2
|
export * from './src/services/SignupService';
|
|
2
3
|
export * from './src/services/UpdateUserInfoService';
|
|
3
4
|
|
|
5
|
+
export * from './src/tables/AccessInviteTable';
|
|
4
6
|
export * from './src/tables/InviteTable';
|
|
5
7
|
export * from './src/tables/UserTable';
|
|
6
8
|
export * from './src/tables/SessionTable';
|
|
@@ -9,5 +11,6 @@ export * from './src/routes';
|
|
|
9
11
|
export * from './src/cacheKeys';
|
|
10
12
|
export * from './src/UserRepo';
|
|
11
13
|
export * from './src/ScopedRecord';
|
|
14
|
+
export * from './src/SharedRecord';
|
|
12
15
|
|
|
13
16
|
export * from '@proteinjs/user-auth';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "User management",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "jest"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@proteinjs/db": "1.
|
|
25
|
+
"@proteinjs/db": "1.16.0",
|
|
26
26
|
"@proteinjs/reflection": "1.1.10",
|
|
27
27
|
"@proteinjs/server-api": "2.0.0",
|
|
28
28
|
"@proteinjs/service": "1.2.5",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"moment": "2.29.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@proteinjs/db-driver-knex": "1.4.
|
|
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",
|
|
@@ -44,5 +44,6 @@
|
|
|
44
44
|
"typescript": "5.2.2"
|
|
45
45
|
},
|
|
46
46
|
"main": "./dist/generated/index.js",
|
|
47
|
-
"types": "./dist/generated/index.d.ts"
|
|
47
|
+
"types": "./dist/generated/index.d.ts",
|
|
48
|
+
"gitHead": "4b7cbc05c093d13dc49799906a77d44f05083d59"
|
|
48
49
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Record } from '@proteinjs/db';
|
|
2
|
+
import type { Moment } from 'moment';
|
|
3
|
+
|
|
4
|
+
import { Service, serviceFactory } from '@proteinjs/service';
|
|
5
|
+
|
|
6
|
+
export const getAccessInviteService = <T extends Record>() =>
|
|
7
|
+
serviceFactory<AccessInviteService<T>>('@proteinjs/user/AccessInviteService');
|
|
8
|
+
|
|
9
|
+
export type CreateAccessInviteParams = {
|
|
10
|
+
resourceTable: string;
|
|
11
|
+
resourceId: string;
|
|
12
|
+
expiresInDays?: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type CreateAccessInviteResponse = {
|
|
16
|
+
token: string;
|
|
17
|
+
tokenExpiresAt: Moment;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export interface AccessInviteService<T extends Record> extends Service {
|
|
21
|
+
/**
|
|
22
|
+
* Creates an access invite for a resource. Caller must have admin access to the resource.
|
|
23
|
+
* Returns a token and expiry which can be embedded as a query parameter in a shareable URL.
|
|
24
|
+
*/
|
|
25
|
+
createAccessInvite(params: CreateAccessInviteParams): Promise<CreateAccessInviteResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Accepts an access invite using the provided token. The current authenticated user will be granted access.
|
|
28
|
+
*/
|
|
29
|
+
acceptAccessInvite(token: string): Promise<T | undefined>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DynamicReferenceColumn,
|
|
3
|
+
DynamicReferenceTableNameColumn,
|
|
4
|
+
getDbAsSystem,
|
|
5
|
+
Record,
|
|
6
|
+
Reference,
|
|
7
|
+
ReferenceColumn,
|
|
8
|
+
StringColumn,
|
|
9
|
+
withRecordColumns,
|
|
10
|
+
} from '@proteinjs/db';
|
|
11
|
+
|
|
12
|
+
import { Table } from '@proteinjs/db';
|
|
13
|
+
import { User, UserTable } from './UserTable';
|
|
14
|
+
import { UserRepo } from '../UserRepo';
|
|
15
|
+
|
|
16
|
+
export type AccessGrant = Record & {
|
|
17
|
+
principal: Reference<any>;
|
|
18
|
+
resource: Reference<any>;
|
|
19
|
+
resourceTable?: Table<any>['name'];
|
|
20
|
+
accessLevel: 'read' | 'write' | 'admin';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class AccessGrantTable extends Table<AccessGrant> {
|
|
24
|
+
name = 'access_grant';
|
|
25
|
+
columns = withRecordColumns<AccessGrant>({
|
|
26
|
+
accessLevel: new StringColumn('access_level'),
|
|
27
|
+
principal: new ReferenceColumn<User>('principal', UserTable.name, false),
|
|
28
|
+
resource: new DynamicReferenceColumn<any>('resource', 'resource_table', false),
|
|
29
|
+
resourceTable: new DynamicReferenceTableNameColumn('resource_table', 'resource', {
|
|
30
|
+
onBeforeInsert: async (insertObj: AccessGrant, runAsSystem) => {
|
|
31
|
+
if (runAsSystem) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// if the object doesn't exist yet, we should allow insert
|
|
36
|
+
const resource = await insertObj.resource.get();
|
|
37
|
+
if (!resource) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const hasAdminAccess =
|
|
42
|
+
(
|
|
43
|
+
await getDbAsSystem().query(new AccessGrantTable() as Table<AccessGrant>, {
|
|
44
|
+
accessLevel: 'admin',
|
|
45
|
+
principal: new UserRepo().getUser().id,
|
|
46
|
+
resource: insertObj.resource._id,
|
|
47
|
+
resourceTable: insertObj.resourceTable,
|
|
48
|
+
})
|
|
49
|
+
).length > 0;
|
|
50
|
+
|
|
51
|
+
if (!hasAdminAccess) {
|
|
52
|
+
throw new Error(`User does not have admin access to resource`);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Moment } from 'moment';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BooleanColumn,
|
|
5
|
+
DateTimeColumn,
|
|
6
|
+
DynamicReferenceColumn,
|
|
7
|
+
DynamicReferenceTableNameColumn,
|
|
8
|
+
getDbAsSystem,
|
|
9
|
+
Record,
|
|
10
|
+
Reference,
|
|
11
|
+
ReferenceColumn,
|
|
12
|
+
StringColumn,
|
|
13
|
+
Table,
|
|
14
|
+
withRecordColumns,
|
|
15
|
+
} from '@proteinjs/db';
|
|
16
|
+
import * as crypto from 'crypto';
|
|
17
|
+
import { UserRepo } from '../UserRepo';
|
|
18
|
+
import { AccessGrant, AccessGrantTable } from './AccessGrantTable';
|
|
19
|
+
import { User, UserTable } from './UserTable';
|
|
20
|
+
|
|
21
|
+
export type AccessInvite<T extends Record = any> = Record & {
|
|
22
|
+
token?: string;
|
|
23
|
+
tokenExpiresAt: Moment;
|
|
24
|
+
resource: Reference<T>;
|
|
25
|
+
resourceTable: string;
|
|
26
|
+
accepted?: boolean;
|
|
27
|
+
acceptedBy?: Reference<User>;
|
|
28
|
+
acceptedAt?: Moment;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export class AccessInviteTable extends Table<AccessInvite> {
|
|
32
|
+
name = 'access_invite';
|
|
33
|
+
columns = withRecordColumns<AccessInvite>({
|
|
34
|
+
token: new StringColumn('token', {
|
|
35
|
+
defaultValue: async () => crypto.randomBytes(32).toString('hex'),
|
|
36
|
+
forceDefaultValue: true,
|
|
37
|
+
}),
|
|
38
|
+
tokenExpiresAt: new DateTimeColumn('expires_at'),
|
|
39
|
+
accepted: new BooleanColumn('accepted', { defaultValue: async () => false }),
|
|
40
|
+
acceptedBy: new ReferenceColumn('accepted_by', new UserTable().name, false),
|
|
41
|
+
acceptedAt: new DateTimeColumn('accepted_at'),
|
|
42
|
+
resource: new DynamicReferenceColumn('resource', 'resource_table'),
|
|
43
|
+
resourceTable: new DynamicReferenceTableNameColumn('resource_table', 'resource', {
|
|
44
|
+
onBeforeInsert: async (insertObj: AccessInvite, runAsSystem) => {
|
|
45
|
+
if (runAsSystem) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const hasAdminAccess =
|
|
50
|
+
(
|
|
51
|
+
await getDbAsSystem().query(new AccessGrantTable() as Table<AccessGrant>, {
|
|
52
|
+
accessLevel: 'admin',
|
|
53
|
+
principal: new UserRepo().getUser().id,
|
|
54
|
+
resource: insertObj.resource._id,
|
|
55
|
+
resourceTable: insertObj.resourceTable,
|
|
56
|
+
})
|
|
57
|
+
).length > 0;
|
|
58
|
+
|
|
59
|
+
if (!hasAdminAccess) {
|
|
60
|
+
throw new Error(`User does not have admin access to resource`);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
}
|
package/src/tables/tables.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { AccessGrant, AccessGrantTable } from './AccessGrantTable';
|
|
1
2
|
import { UserTable, User } from './UserTable';
|
|
2
3
|
import { SessionTable, Session } from './SessionTable';
|
|
3
4
|
import { Table } from '@proteinjs/db';
|
|
4
5
|
import { Invite, InviteTable } from './InviteTable';
|
|
6
|
+
import { AccessInvite, AccessInviteTable } from './AccessInviteTable';
|
|
5
7
|
|
|
6
8
|
export const tables = {
|
|
9
|
+
AccessGrant: new AccessGrantTable() as Table<AccessGrant>,
|
|
10
|
+
AccessInvite: new AccessInviteTable() as Table<AccessInvite>,
|
|
7
11
|
Invite: new InviteTable() as Table<Invite>,
|
|
8
12
|
User: new UserTable() as Table<User>,
|
|
9
13
|
Session: new SessionTable() as Table<Session>,
|