@devxcrew/platform 0.1.2 → 0.1.6
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/README.md +7 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -2
- package/dist/modules/identity/audit/audit.controller.d.ts +17 -0
- package/dist/modules/identity/audit/audit.controller.js +12 -0
- package/dist/modules/identity/audit/audit.migration.d.ts +1 -0
- package/dist/modules/identity/audit/audit.migration.js +1 -0
- package/dist/modules/identity/audit/audit.provider.d.ts +24 -0
- package/dist/modules/identity/audit/audit.provider.js +14 -0
- package/dist/modules/identity/audit/audit.repository.d.ts +26 -0
- package/dist/modules/identity/audit/audit.repository.js +46 -0
- package/dist/modules/identity/audit/audit.routes.d.ts +5 -0
- package/dist/modules/identity/audit/audit.routes.js +2 -0
- package/dist/modules/identity/audit/audit.schema.d.ts +1 -0
- package/dist/modules/identity/audit/audit.schema.js +1 -0
- package/dist/modules/identity/audit/audit.seed.d.ts +1 -0
- package/dist/modules/identity/audit/audit.seed.js +1 -0
- package/dist/modules/identity/audit/audit.service.d.ts +23 -0
- package/dist/modules/identity/audit/audit.service.js +46 -0
- package/dist/modules/identity/audit/audit.types.d.ts +12 -0
- package/dist/modules/identity/audit/audit.types.js +1 -0
- package/dist/modules/identity/audit/index.d.ts +4 -0
- package/dist/modules/identity/audit/index.js +3 -0
- package/dist/modules/identity/{identity.administration-service.d.ts → composition/identity.composition.d.ts} +59 -27
- package/dist/modules/identity/composition/identity.composition.js +171 -0
- package/dist/modules/identity/composition/identity.seed.d.ts +3 -0
- package/dist/modules/identity/composition/identity.seed.js +16 -0
- package/dist/modules/identity/identity.controller.d.ts +8 -6
- package/dist/modules/identity/identity.controller.js +90 -70
- package/dist/modules/identity/identity.migration.d.ts +1 -2
- package/dist/modules/identity/identity.migration.js +1 -79
- package/dist/modules/identity/identity.provider.d.ts +39 -13
- package/dist/modules/identity/identity.provider.js +19 -73
- package/dist/modules/identity/identity.public-schemas.d.ts +9 -3
- package/dist/modules/identity/identity.public-schemas.js +9 -3
- package/dist/modules/identity/identity.repository.d.ts +1 -40
- package/dist/modules/identity/identity.repository.js +1 -196
- package/dist/modules/identity/identity.routes.d.ts +2 -5
- package/dist/modules/identity/identity.routes.js +3 -11
- package/dist/modules/identity/identity.schema.d.ts +1 -27
- package/dist/modules/identity/identity.schema.js +1 -34
- package/dist/modules/identity/identity.seed.d.ts +1 -3
- package/dist/modules/identity/identity.seed.js +1 -81
- package/dist/modules/identity/identity.service.d.ts +1 -32
- package/dist/modules/identity/identity.service.js +1 -83
- package/dist/modules/identity/identity.types.d.ts +13 -106
- package/dist/modules/identity/index.d.ts +18 -11
- package/dist/modules/identity/index.js +14 -8
- package/dist/modules/identity/{identity.administration-migration.js → legacy/identity.administration-migration.js} +3 -11
- package/dist/modules/identity/legacy/identity.migration.d.ts +2 -0
- package/dist/modules/identity/legacy/identity.migration.js +72 -0
- package/dist/modules/identity/organization/index.d.ts +6 -0
- package/dist/modules/identity/organization/index.js +5 -0
- package/dist/modules/identity/organization/organization.controller.d.ts +35 -0
- package/dist/modules/identity/organization/organization.controller.js +18 -0
- package/dist/modules/identity/organization/organization.migration.d.ts +1 -0
- package/dist/modules/identity/organization/organization.migration.js +1 -0
- package/dist/modules/identity/organization/organization.provider.d.ts +46 -0
- package/dist/modules/identity/organization/organization.provider.js +33 -0
- package/dist/modules/identity/organization/organization.repository.d.ts +58 -0
- package/dist/modules/identity/organization/organization.repository.js +101 -0
- package/dist/modules/identity/organization/organization.routes.d.ts +5 -0
- package/dist/modules/identity/organization/organization.routes.js +2 -0
- package/dist/modules/identity/organization/organization.schema.d.ts +11 -0
- package/dist/modules/identity/organization/organization.schema.js +18 -0
- package/dist/modules/identity/organization/organization.seed.d.ts +3 -0
- package/dist/modules/identity/organization/organization.seed.js +11 -0
- package/dist/modules/identity/organization/organization.service.d.ts +39 -0
- package/dist/modules/identity/organization/organization.service.js +55 -0
- package/dist/modules/identity/organization/organization.types.d.ts +19 -0
- package/dist/modules/identity/organization/organization.types.js +1 -0
- package/dist/modules/identity/permission/index.d.ts +9 -0
- package/dist/modules/identity/permission/index.js +6 -0
- package/dist/modules/identity/permission/permission.controller.d.ts +21 -0
- package/dist/modules/identity/permission/permission.controller.js +12 -0
- package/dist/modules/identity/{identity.permission-declarations-migration.js → permission/permission.declarations.migration.js} +9 -4
- package/dist/modules/identity/{identity.permission-labels-migration.js → permission/permission.labels.migration.js} +5 -2
- package/dist/modules/identity/permission/permission.migration.d.ts +2 -0
- package/dist/modules/identity/permission/permission.migration.js +2 -0
- package/dist/modules/identity/permission/permission.provider.d.ts +19 -0
- package/dist/modules/identity/permission/permission.provider.js +14 -0
- package/dist/modules/identity/permission/permission.repository.d.ts +51 -0
- package/dist/modules/identity/permission/permission.repository.js +84 -0
- package/dist/modules/identity/permission/permission.routes.d.ts +5 -0
- package/dist/modules/identity/permission/permission.routes.js +2 -0
- package/dist/modules/identity/permission/permission.schema.d.ts +14 -0
- package/dist/modules/identity/permission/permission.schema.js +29 -0
- package/dist/modules/identity/permission/permission.seed.d.ts +4 -0
- package/dist/modules/identity/permission/permission.seed.js +17 -0
- package/dist/modules/identity/permission/permission.service.d.ts +31 -0
- package/dist/modules/identity/permission/permission.service.js +77 -0
- package/dist/modules/identity/permission/permission.types.d.ts +15 -0
- package/dist/modules/identity/permission/permission.types.js +1 -0
- package/dist/modules/identity/role/index.d.ts +10 -0
- package/dist/modules/identity/role/index.js +6 -0
- package/dist/modules/identity/role/role.controller.d.ts +42 -0
- package/dist/modules/identity/role/role.controller.js +25 -0
- package/dist/modules/identity/{identity.roles-migration.js → role/role.migration.js} +5 -18
- package/dist/modules/identity/role/role.provider.d.ts +14 -0
- package/dist/modules/identity/role/role.provider.js +30 -0
- package/dist/modules/identity/role/role.repository.d.ts +38 -0
- package/dist/modules/identity/role/role.repository.js +46 -0
- package/dist/modules/identity/role/role.routes.d.ts +5 -0
- package/dist/modules/identity/role/role.routes.js +2 -0
- package/dist/modules/identity/role/role.schema.d.ts +16 -0
- package/dist/modules/identity/role/role.schema.js +27 -0
- package/dist/modules/identity/role/role.seed.d.ts +3 -0
- package/dist/modules/identity/role/role.seed.js +8 -0
- package/dist/modules/identity/role/role.service.d.ts +69 -0
- package/dist/modules/identity/role/role.service.js +192 -0
- package/dist/modules/identity/role/role.types.d.ts +17 -0
- package/dist/modules/identity/role/role.types.js +1 -0
- package/dist/modules/identity/role-permission/index.d.ts +6 -0
- package/dist/modules/identity/role-permission/index.js +4 -0
- package/dist/modules/identity/role-permission/role-permission.controller.d.ts +1 -0
- package/dist/modules/identity/role-permission/role-permission.controller.js +1 -0
- package/dist/modules/identity/role-permission/role-permission.migration.d.ts +1 -0
- package/dist/modules/identity/role-permission/role-permission.migration.js +1 -0
- package/dist/modules/identity/role-permission/role-permission.provider.d.ts +14 -0
- package/dist/modules/identity/role-permission/role-permission.provider.js +15 -0
- package/dist/modules/identity/role-permission/role-permission.repository.d.ts +12 -0
- package/dist/modules/identity/role-permission/role-permission.repository.js +51 -0
- package/dist/modules/identity/role-permission/role-permission.routes.d.ts +1 -0
- package/dist/modules/identity/role-permission/role-permission.routes.js +2 -0
- package/dist/modules/identity/role-permission/role-permission.schema.d.ts +2 -0
- package/dist/modules/identity/role-permission/role-permission.schema.js +3 -0
- package/dist/modules/identity/role-permission/role-permission.seed.d.ts +3 -0
- package/dist/modules/identity/role-permission/role-permission.seed.js +10 -0
- package/dist/modules/identity/role-permission/role-permission.service.d.ts +13 -0
- package/dist/modules/identity/role-permission/role-permission.service.js +35 -0
- package/dist/modules/identity/role-permission/role-permission.types.d.ts +12 -0
- package/dist/modules/identity/role-permission/role-permission.types.js +1 -0
- package/dist/modules/identity/session/index.d.ts +6 -0
- package/dist/modules/identity/session/index.js +5 -0
- package/dist/modules/identity/session/session.authentication.controller.d.ts +30 -0
- package/dist/modules/identity/session/session.authentication.controller.js +37 -0
- package/dist/modules/identity/session/session.controller.d.ts +18 -0
- package/dist/modules/identity/session/session.controller.js +15 -0
- package/dist/modules/identity/session/session.migration.d.ts +1 -0
- package/dist/modules/identity/session/session.migration.js +1 -0
- package/dist/modules/identity/session/session.provider.d.ts +34 -0
- package/dist/modules/identity/session/session.provider.js +23 -0
- package/dist/modules/identity/session/session.repository.d.ts +36 -0
- package/dist/modules/identity/session/session.repository.js +128 -0
- package/dist/modules/identity/session/session.routes.d.ts +27 -0
- package/dist/modules/identity/session/session.routes.js +13 -0
- package/dist/modules/identity/session/session.schema.d.ts +6 -0
- package/dist/modules/identity/session/session.schema.js +12 -0
- package/dist/modules/identity/session/session.seed.d.ts +1 -0
- package/dist/modules/identity/session/session.seed.js +1 -0
- package/dist/modules/identity/session/session.service.d.ts +20 -0
- package/dist/modules/identity/session/session.service.js +27 -0
- package/dist/modules/identity/session/session.types.d.ts +17 -0
- package/dist/modules/identity/session/session.types.js +1 -0
- package/dist/modules/identity/settings/index.d.ts +5 -0
- package/dist/modules/identity/settings/index.js +4 -0
- package/dist/modules/identity/settings/settings.controller.d.ts +35 -0
- package/dist/modules/identity/settings/settings.controller.js +18 -0
- package/dist/modules/identity/settings/settings.migration.d.ts +1 -0
- package/dist/modules/identity/settings/settings.migration.js +1 -0
- package/dist/modules/identity/settings/settings.provider.d.ts +35 -0
- package/dist/modules/identity/settings/settings.provider.js +14 -0
- package/dist/modules/identity/settings/settings.repository.d.ts +49 -0
- package/dist/modules/identity/settings/settings.repository.js +75 -0
- package/dist/modules/identity/settings/settings.routes.d.ts +1 -0
- package/dist/modules/identity/settings/settings.routes.js +7 -0
- package/dist/modules/identity/settings/settings.schema.d.ts +15 -0
- package/dist/modules/identity/settings/settings.schema.js +27 -0
- package/dist/modules/identity/settings/settings.seed.d.ts +1 -0
- package/dist/modules/identity/settings/settings.seed.js +1 -0
- package/dist/modules/identity/settings/settings.service.d.ts +40 -0
- package/dist/modules/identity/settings/settings.service.js +101 -0
- package/dist/modules/identity/settings/settings.types.d.ts +20 -0
- package/dist/modules/identity/settings/settings.types.js +1 -0
- package/dist/modules/identity/support/identity.schema.d.ts +8 -0
- package/dist/modules/identity/support/identity.schema.js +10 -0
- package/dist/modules/identity/support/pagination.d.ts +13 -0
- package/dist/modules/identity/support/pagination.js +27 -0
- package/dist/modules/identity/support/pagination.schema.d.ts +43 -0
- package/dist/modules/identity/support/pagination.schema.js +15 -0
- package/dist/modules/identity/support/resource-controller.d.ts +14 -0
- package/dist/modules/identity/support/resource-controller.js +1 -0
- package/dist/modules/identity/user/index.d.ts +13 -0
- package/dist/modules/identity/user/index.js +11 -0
- package/dist/modules/identity/user/user.administration.service.d.ts +59 -0
- package/dist/modules/identity/user/user.administration.service.js +159 -0
- package/dist/modules/identity/user/user.controller.d.ts +44 -0
- package/dist/modules/identity/user/user.controller.js +21 -0
- package/dist/modules/identity/user/user.lifecycle.controller.d.ts +58 -0
- package/dist/modules/identity/user/user.lifecycle.controller.js +27 -0
- package/dist/modules/identity/{identity.lifecycle-schema.js → user/user.lifecycle.schema.js} +5 -5
- package/dist/modules/identity/{identity.lifecycle-service.d.ts → user/user.lifecycle.service.d.ts} +8 -4
- package/dist/modules/identity/{identity.lifecycle-service.js → user/user.lifecycle.service.js} +66 -118
- package/dist/modules/identity/user/user.migration.d.ts +1 -0
- package/dist/modules/identity/user/user.migration.js +1 -0
- package/dist/modules/identity/{identity.password.js → user/user.password.js} +1 -1
- package/dist/modules/identity/user/user.provider.d.ts +80 -0
- package/dist/modules/identity/user/user.provider.js +22 -0
- package/dist/modules/identity/user/user.repository.d.ts +64 -0
- package/dist/modules/identity/user/user.repository.js +129 -0
- package/dist/modules/identity/user/user.routes.d.ts +12 -0
- package/dist/modules/identity/user/user.routes.js +9 -0
- package/dist/modules/identity/user/user.schema.d.ts +34 -0
- package/dist/modules/identity/user/user.schema.js +46 -0
- package/dist/modules/identity/user/user.seed.d.ts +14 -0
- package/dist/modules/identity/user/user.seed.js +47 -0
- package/dist/modules/identity/user/user.service.d.ts +33 -0
- package/dist/modules/identity/user/user.service.js +76 -0
- package/dist/modules/identity/user/user.types.d.ts +27 -0
- package/dist/modules/identity/user/user.types.js +1 -0
- package/dist/modules/identity/user-role/index.d.ts +8 -0
- package/dist/modules/identity/user-role/index.js +6 -0
- package/dist/modules/identity/user-role/user-role.controller.d.ts +42 -0
- package/dist/modules/identity/user-role/user-role.controller.js +21 -0
- package/dist/modules/identity/user-role/user-role.migration.d.ts +1 -0
- package/dist/modules/identity/user-role/user-role.migration.js +1 -0
- package/dist/modules/identity/user-role/user-role.policy.d.ts +3 -0
- package/dist/modules/identity/user-role/user-role.policy.js +25 -0
- package/dist/modules/identity/user-role/user-role.provider.d.ts +18 -0
- package/dist/modules/identity/user-role/user-role.provider.js +23 -0
- package/dist/modules/identity/user-role/user-role.repository.d.ts +34 -0
- package/dist/modules/identity/user-role/user-role.repository.js +87 -0
- package/dist/modules/identity/user-role/user-role.routes.d.ts +5 -0
- package/dist/modules/identity/user-role/user-role.routes.js +2 -0
- package/dist/modules/identity/user-role/user-role.schema.d.ts +14 -0
- package/dist/modules/identity/user-role/user-role.schema.js +25 -0
- package/dist/modules/identity/user-role/user-role.seed.d.ts +7 -0
- package/dist/modules/identity/user-role/user-role.seed.js +11 -0
- package/dist/modules/identity/user-role/user-role.service.d.ts +60 -0
- package/dist/modules/identity/user-role/user-role.service.js +216 -0
- package/dist/modules/identity/user-role/user-role.types.d.ts +12 -0
- package/dist/modules/identity/user-role/user-role.types.js +1 -0
- package/dist/modules/tenant/index.d.ts +6 -0
- package/dist/modules/tenant/index.js +5 -0
- package/dist/modules/tenant/tenant.command.d.ts +3 -0
- package/dist/modules/tenant/tenant.command.js +43 -0
- package/dist/modules/tenant/tenant.controller.d.ts +4 -0
- package/dist/modules/tenant/tenant.controller.js +12 -0
- package/dist/modules/tenant/tenant.migration.d.ts +5 -0
- package/dist/modules/tenant/tenant.migration.js +46 -0
- package/dist/modules/tenant/tenant.provider.d.ts +3 -0
- package/dist/modules/tenant/tenant.provider.js +44 -0
- package/dist/modules/tenant/tenant.readiness.d.ts +6 -0
- package/dist/modules/tenant/tenant.readiness.js +45 -0
- package/dist/modules/tenant/tenant.repository.d.ts +15 -0
- package/dist/modules/tenant/tenant.repository.js +23 -0
- package/dist/modules/tenant/tenant.routes.d.ts +4 -0
- package/dist/modules/tenant/tenant.routes.js +7 -0
- package/dist/modules/tenant/tenant.schema.d.ts +20 -0
- package/dist/modules/tenant/tenant.schema.js +31 -0
- package/dist/modules/tenant/tenant.seed.d.ts +8 -0
- package/dist/modules/tenant/tenant.seed.js +40 -0
- package/dist/modules/tenant/tenant.service.d.ts +16 -0
- package/dist/modules/tenant/tenant.service.js +72 -0
- package/dist/modules/tenant/tenant.types.d.ts +39 -0
- package/dist/modules/tenant/tenant.types.js +1 -0
- package/package.json +9 -5
- package/dist/modules/identity/identity.administration-repository.d.ts +0 -19
- package/dist/modules/identity/identity.administration-repository.js +0 -102
- package/dist/modules/identity/identity.administration-schema.d.ts +0 -113
- package/dist/modules/identity/identity.administration-schema.js +0 -121
- package/dist/modules/identity/identity.administration-service.js +0 -517
- package/dist/modules/identity/identity.membership-policy.d.ts +0 -3
- package/dist/modules/identity/identity.membership-policy.js +0 -27
- package/dist/modules/identity/identity.permission-declarations.d.ts +0 -23
- package/dist/modules/identity/identity.permission-declarations.js +0 -57
- package/dist/modules/identity/identity.presentation-service.d.ts +0 -23
- package/dist/modules/identity/identity.presentation-service.js +0 -51
- package/dist/modules/identity/identity.roles-service.d.ts +0 -49
- package/dist/modules/identity/identity.roles-service.js +0 -327
- /package/dist/modules/identity/{identity.administration-migration.d.ts → legacy/identity.administration-migration.d.ts} +0 -0
- /package/dist/modules/identity/{identity.permission-declarations-migration.d.ts → permission/permission.declarations.migration.d.ts} +0 -0
- /package/dist/modules/identity/{identity.permission-labels-migration.d.ts → permission/permission.labels.migration.d.ts} +0 -0
- /package/dist/modules/identity/{identity.roles-migration.d.ts → role/role.migration.d.ts} +0 -0
- /package/dist/modules/identity/{identity.error.d.ts → support/identity.error.d.ts} +0 -0
- /package/dist/modules/identity/{identity.error.js → support/identity.error.js} +0 -0
- /package/dist/modules/identity/{identity.request-context.d.ts → support/identity.request-context.d.ts} +0 -0
- /package/dist/modules/identity/{identity.request-context.js → support/identity.request-context.js} +0 -0
- /package/dist/modules/identity/{identity.lifecycle-schema.d.ts → user/user.lifecycle.schema.d.ts} +0 -0
- /package/dist/modules/identity/{identity.password.d.ts → user/user.password.d.ts} +0 -0
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
1
|
+
export * from "./support/pagination.schema.js";
|
|
2
|
+
export { userCreateSchema, userUpdateSchema, profileSchema, passwordSchema, accountSchema } from "./user/user.schema.js";
|
|
3
|
+
export { invitationSchema, recoverySchema, tokenCompletionSchema } from "./user/user.lifecycle.schema.js";
|
|
4
|
+
export { customRoleCreateSchema, customRoleUpdateSchema, roleUpdateSchema } from "./role/role.schema.js";
|
|
5
|
+
export { membershipDeleteQuerySchema, membershipSchema, membershipUpdateSchema } from "./user-role/user-role.schema.js";
|
|
6
|
+
export { loginSchema } from "./session/session.schema.js";
|
|
7
|
+
export { settingsSchema, securitySettingsSchema } from "./settings/settings.schema.js";
|
|
8
|
+
export { organizationCreateSchema, organizationUpdateSchema } from "./organization/organization.schema.js";
|
|
9
|
+
export { identityKeySchema, portalSchema, resourceIdSchema } from "./support/identity.schema.js";
|
|
4
10
|
export type { IdentityPermissionCatalogEntry } from "./identity.types.js";
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
1
|
+
export * from "./support/pagination.schema.js";
|
|
2
|
+
export { userCreateSchema, userUpdateSchema, profileSchema, passwordSchema, accountSchema } from "./user/user.schema.js";
|
|
3
|
+
export { invitationSchema, recoverySchema, tokenCompletionSchema } from "./user/user.lifecycle.schema.js";
|
|
4
|
+
export { customRoleCreateSchema, customRoleUpdateSchema, roleUpdateSchema } from "./role/role.schema.js";
|
|
5
|
+
export { membershipDeleteQuerySchema, membershipSchema, membershipUpdateSchema } from "./user-role/user-role.schema.js";
|
|
6
|
+
export { loginSchema } from "./session/session.schema.js";
|
|
7
|
+
export { settingsSchema, securitySettingsSchema } from "./settings/settings.schema.js";
|
|
8
|
+
export { organizationCreateSchema, organizationUpdateSchema } from "./organization/organization.schema.js";
|
|
9
|
+
export { identityKeySchema, portalSchema, resourceIdSchema } from "./support/identity.schema.js";
|
|
@@ -1,40 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IdentitySchema, Portal } from "./identity.types.js";
|
|
3
|
-
export declare class IdentityRepository {
|
|
4
|
-
private readonly db;
|
|
5
|
-
constructor(db: Kysely<IdentitySchema>);
|
|
6
|
-
user(email: string): Promise<{
|
|
7
|
-
active: number;
|
|
8
|
-
email: string;
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
password_hash: string;
|
|
12
|
-
version: number;
|
|
13
|
-
} | undefined>;
|
|
14
|
-
sessionSeconds(appId: string, fallback: number): Promise<number>;
|
|
15
|
-
principal(userId: string, tenantId: string, portal: Portal, appId: string): Promise<{
|
|
16
|
-
user: {
|
|
17
|
-
id: string;
|
|
18
|
-
email: string;
|
|
19
|
-
name: string;
|
|
20
|
-
};
|
|
21
|
-
tenant: {
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
};
|
|
25
|
-
permissions: string[];
|
|
26
|
-
} | null>;
|
|
27
|
-
session(tokenHash: string, appId: string, portal: Portal, now: string): Promise<{
|
|
28
|
-
app_id: string;
|
|
29
|
-
expires_at: string;
|
|
30
|
-
portal: Portal;
|
|
31
|
-
tenant_id: string;
|
|
32
|
-
token_hash: string;
|
|
33
|
-
user_id: string;
|
|
34
|
-
} | undefined>;
|
|
35
|
-
createSession(session: IdentitySchema["identity_sessions"], expectedHash: string, previous?: string): Promise<boolean>;
|
|
36
|
-
revoke(tokenHash: string, appId: string, portal: Portal): Promise<void>;
|
|
37
|
-
throttle(key: string): Promise<number>;
|
|
38
|
-
clearThrottle(key: string): Promise<void>;
|
|
39
|
-
changePassword(userId: string, expectedHash: string, passwordHash: string): Promise<boolean>;
|
|
40
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,196 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { sql } from "kysely";
|
|
3
|
-
import { checkIdentityRequest } from "./identity.request-context.js";
|
|
4
|
-
export class IdentityRepository {
|
|
5
|
-
db;
|
|
6
|
-
constructor(db) {
|
|
7
|
-
this.db = db;
|
|
8
|
-
}
|
|
9
|
-
user(email) {
|
|
10
|
-
return this.db
|
|
11
|
-
.selectFrom("identity_users")
|
|
12
|
-
.selectAll()
|
|
13
|
-
.where("email", "=", email)
|
|
14
|
-
.executeTakeFirst();
|
|
15
|
-
}
|
|
16
|
-
async sessionSeconds(appId, fallback) {
|
|
17
|
-
const row = await this.db
|
|
18
|
-
.selectFrom("identity_app_settings")
|
|
19
|
-
.select("session_seconds")
|
|
20
|
-
.where("app_id", "=", appId)
|
|
21
|
-
.executeTakeFirst();
|
|
22
|
-
return Number(row?.session_seconds ?? fallback);
|
|
23
|
-
}
|
|
24
|
-
async principal(userId, tenantId, portal, appId) {
|
|
25
|
-
const member = await this.db
|
|
26
|
-
.selectFrom("identity_memberships as m")
|
|
27
|
-
.innerJoin("identity_users as u", "u.id", "m.user_id")
|
|
28
|
-
.innerJoin("identity_tenants as t", "t.id", "m.tenant_id")
|
|
29
|
-
.select([
|
|
30
|
-
"u.id",
|
|
31
|
-
"u.email",
|
|
32
|
-
"u.name",
|
|
33
|
-
"t.id as tenantId",
|
|
34
|
-
"t.name as tenantName",
|
|
35
|
-
"m.custom_role_id as customRoleId",
|
|
36
|
-
])
|
|
37
|
-
.where("u.id", "=", userId)
|
|
38
|
-
.where("m.tenant_id", "=", tenantId)
|
|
39
|
-
.where("m.role_id", "=", portal)
|
|
40
|
-
.where("m.active", "=", 1)
|
|
41
|
-
.where("u.active", "=", 1)
|
|
42
|
-
.where("t.active", "=", 1)
|
|
43
|
-
.executeTakeFirst();
|
|
44
|
-
if (!member)
|
|
45
|
-
return null;
|
|
46
|
-
if (member.customRoleId) {
|
|
47
|
-
const role = await this.db
|
|
48
|
-
.selectFrom("identity_custom_roles")
|
|
49
|
-
.select("id")
|
|
50
|
-
.where("id", "=", member.customRoleId)
|
|
51
|
-
.where("app_id", "=", appId)
|
|
52
|
-
.where("tenant_id", "=", tenantId)
|
|
53
|
-
.where("active", "=", 1)
|
|
54
|
-
.executeTakeFirst();
|
|
55
|
-
if (!role || portal !== "user")
|
|
56
|
-
return null;
|
|
57
|
-
const permissions = await this.db
|
|
58
|
-
.selectFrom("identity_custom_role_permissions")
|
|
59
|
-
.select("permission_id")
|
|
60
|
-
.where("role_id", "=", role.id)
|
|
61
|
-
.execute();
|
|
62
|
-
return {
|
|
63
|
-
user: { id: member.id, email: member.email, name: member.name },
|
|
64
|
-
tenant: { id: member.tenantId, name: member.tenantName },
|
|
65
|
-
permissions: await filterDeclaredPermissions(this.db, appId, portal, permissions.map((row) => row.permission_id)),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const permissions = await this.db
|
|
69
|
-
.selectFrom("identity_role_permissions")
|
|
70
|
-
.select("permission_id")
|
|
71
|
-
.where("role_id", "=", portal)
|
|
72
|
-
.execute();
|
|
73
|
-
return {
|
|
74
|
-
user: { id: member.id, email: member.email, name: member.name },
|
|
75
|
-
tenant: { id: member.tenantId, name: member.tenantName },
|
|
76
|
-
permissions: await filterDeclaredPermissions(this.db, appId, portal, permissions.map((p) => p.permission_id)),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
async session(tokenHash, appId, portal, now) {
|
|
80
|
-
return this.db
|
|
81
|
-
.selectFrom("identity_sessions")
|
|
82
|
-
.selectAll()
|
|
83
|
-
.where("token_hash", "=", tokenHash)
|
|
84
|
-
.where("app_id", "=", appId)
|
|
85
|
-
.where("portal", "=", portal)
|
|
86
|
-
.where("expires_at", ">", now)
|
|
87
|
-
.executeTakeFirst();
|
|
88
|
-
}
|
|
89
|
-
async createSession(session, expectedHash, previous) {
|
|
90
|
-
return this.db.transaction().execute(async (trx) => {
|
|
91
|
-
checkIdentityRequest();
|
|
92
|
-
const current = await trx
|
|
93
|
-
.selectFrom("identity_users")
|
|
94
|
-
.select("id")
|
|
95
|
-
.where("id", "=", session.user_id)
|
|
96
|
-
.where("password_hash", "=", expectedHash)
|
|
97
|
-
.where("active", "=", 1)
|
|
98
|
-
.executeTakeFirst();
|
|
99
|
-
if (!current)
|
|
100
|
-
return false;
|
|
101
|
-
const membership = await trx
|
|
102
|
-
.selectFrom("identity_memberships")
|
|
103
|
-
.select("custom_role_id")
|
|
104
|
-
.where("user_id", "=", session.user_id)
|
|
105
|
-
.where("tenant_id", "=", session.tenant_id)
|
|
106
|
-
.where("role_id", "=", session.portal)
|
|
107
|
-
.where("active", "=", 1)
|
|
108
|
-
.executeTakeFirst();
|
|
109
|
-
if (!membership)
|
|
110
|
-
return false;
|
|
111
|
-
if (membership.custom_role_id) {
|
|
112
|
-
const role = await trx
|
|
113
|
-
.selectFrom("identity_custom_roles")
|
|
114
|
-
.select("id")
|
|
115
|
-
.where("id", "=", membership.custom_role_id)
|
|
116
|
-
.where("app_id", "=", session.app_id)
|
|
117
|
-
.where("tenant_id", "=", session.tenant_id)
|
|
118
|
-
.where("active", "=", 1)
|
|
119
|
-
.executeTakeFirst();
|
|
120
|
-
if (!role)
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
await trx
|
|
124
|
-
.deleteFrom("identity_sessions")
|
|
125
|
-
.where("expires_at", "<=", new Date().toISOString())
|
|
126
|
-
.execute();
|
|
127
|
-
if (previous)
|
|
128
|
-
await trx
|
|
129
|
-
.deleteFrom("identity_sessions")
|
|
130
|
-
.where("token_hash", "=", previous)
|
|
131
|
-
.where("app_id", "=", session.app_id)
|
|
132
|
-
.where("portal", "=", session.portal)
|
|
133
|
-
.execute();
|
|
134
|
-
await trx.insertInto("identity_sessions").values(session).execute();
|
|
135
|
-
checkIdentityRequest();
|
|
136
|
-
return true;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async revoke(tokenHash, appId, portal) {
|
|
140
|
-
checkIdentityRequest();
|
|
141
|
-
await this.db
|
|
142
|
-
.deleteFrom("identity_sessions")
|
|
143
|
-
.where("token_hash", "=", tokenHash)
|
|
144
|
-
.where("app_id", "=", appId)
|
|
145
|
-
.where("portal", "=", portal)
|
|
146
|
-
.execute();
|
|
147
|
-
}
|
|
148
|
-
async throttle(key) {
|
|
149
|
-
const now = new Date();
|
|
150
|
-
return this.db.transaction().execute(async (trx) => {
|
|
151
|
-
await trx
|
|
152
|
-
.deleteFrom("identity_throttles")
|
|
153
|
-
.where("expires_at", "<=", now.toISOString())
|
|
154
|
-
.execute();
|
|
155
|
-
await trx
|
|
156
|
-
.insertInto("identity_throttles")
|
|
157
|
-
.values({
|
|
158
|
-
key,
|
|
159
|
-
attempts: 1,
|
|
160
|
-
expires_at: new Date(now.getTime() + 15 * 60 * 1000).toISOString(),
|
|
161
|
-
})
|
|
162
|
-
.onConflict((c) => c.column("key").doUpdateSet({ attempts: sql `attempts + 1` }))
|
|
163
|
-
.execute();
|
|
164
|
-
const row = await trx
|
|
165
|
-
.selectFrom("identity_throttles")
|
|
166
|
-
.select("attempts")
|
|
167
|
-
.where("key", "=", key)
|
|
168
|
-
.executeTakeFirstOrThrow();
|
|
169
|
-
return Number(row.attempts);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
async clearThrottle(key) {
|
|
173
|
-
await this.db
|
|
174
|
-
.deleteFrom("identity_throttles")
|
|
175
|
-
.where("key", "=", key)
|
|
176
|
-
.execute();
|
|
177
|
-
}
|
|
178
|
-
async changePassword(userId, expectedHash, passwordHash) {
|
|
179
|
-
return this.db.transaction().execute(async (trx) => {
|
|
180
|
-
checkIdentityRequest();
|
|
181
|
-
const result = await trx
|
|
182
|
-
.updateTable("identity_users")
|
|
183
|
-
.set({ password_hash: passwordHash })
|
|
184
|
-
.where("id", "=", userId)
|
|
185
|
-
.where("password_hash", "=", expectedHash)
|
|
186
|
-
.executeTakeFirst();
|
|
187
|
-
if (result.numUpdatedRows !== 1n)
|
|
188
|
-
return false;
|
|
189
|
-
await trx
|
|
190
|
-
.deleteFrom("identity_sessions")
|
|
191
|
-
.where("user_id", "=", userId)
|
|
192
|
-
.execute();
|
|
193
|
-
return true;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { portalRoutes } from "./session/index.js";
|
|
2
2
|
export declare const identityRoutes: readonly [{
|
|
3
3
|
readonly method: "POST";
|
|
4
4
|
readonly path: "sessions";
|
|
@@ -16,7 +16,4 @@ export declare const identityRoutes: readonly [{
|
|
|
16
16
|
readonly path: "password";
|
|
17
17
|
readonly action: "password";
|
|
18
18
|
}];
|
|
19
|
-
export
|
|
20
|
-
login: string;
|
|
21
|
-
desk: string;
|
|
22
|
-
}>;
|
|
19
|
+
export { portalRoutes };
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
{ method: "DELETE", path: "sessions/current", action: "logout" },
|
|
5
|
-
{ method: "PATCH", path: "password", action: "password" },
|
|
6
|
-
];
|
|
7
|
-
export const portalRoutes = {
|
|
8
|
-
user: { login: "/login", desk: "/desk" },
|
|
9
|
-
admin: { login: "/admin/login", desk: "/admin/desk" },
|
|
10
|
-
"super-admin": { login: "/sa/login", desk: "/sa/desk" },
|
|
11
|
-
};
|
|
1
|
+
import { sessionRoutes, portalRoutes } from "./session/index.js";
|
|
2
|
+
export const identityRoutes = sessionRoutes;
|
|
3
|
+
export { portalRoutes };
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const portalSchema: z.ZodEnum<{
|
|
3
|
-
admin: "admin";
|
|
4
|
-
"super-admin": "super-admin";
|
|
5
|
-
user: "user";
|
|
6
|
-
}>;
|
|
7
|
-
export declare const identityKeySchema: z.ZodString;
|
|
8
|
-
export declare const loginSchema: z.ZodObject<{
|
|
9
|
-
email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
|
|
10
|
-
password: z.ZodString;
|
|
11
|
-
tenantId: z.ZodOptional<z.ZodString>;
|
|
12
|
-
}, z.core.$strict>;
|
|
13
|
-
export declare const passwordSchema: z.ZodObject<{
|
|
14
|
-
currentPassword: z.ZodString;
|
|
15
|
-
password: z.ZodString;
|
|
16
|
-
}, z.core.$strict>;
|
|
17
|
-
export declare const accountSchema: z.ZodObject<{
|
|
18
|
-
email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
|
|
19
|
-
name: z.ZodString;
|
|
20
|
-
password: z.ZodString;
|
|
21
|
-
portal: z.ZodEnum<{
|
|
22
|
-
admin: "admin";
|
|
23
|
-
"super-admin": "super-admin";
|
|
24
|
-
user: "user";
|
|
25
|
-
}>;
|
|
26
|
-
tenantId: z.ZodString;
|
|
27
|
-
}, z.core.$strict>;
|
|
1
|
+
export {};
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const portalSchema = z.enum(["user", "admin", "super-admin"]);
|
|
3
|
-
export const identityKeySchema = z
|
|
4
|
-
.string()
|
|
5
|
-
.regex(/^[a-zA-Z0-9._-]{1,100}$/)
|
|
6
|
-
.refine((value) => !/^\.+$/.test(value), "Use an identifier with a letter or number.");
|
|
7
|
-
export const loginSchema = z
|
|
8
|
-
.object({
|
|
9
|
-
email: z
|
|
10
|
-
.email()
|
|
11
|
-
.max(254)
|
|
12
|
-
.transform((value) => value.trim().toLowerCase()),
|
|
13
|
-
password: z.string().min(1).max(256),
|
|
14
|
-
tenantId: identityKeySchema.optional(),
|
|
15
|
-
})
|
|
16
|
-
.strict();
|
|
17
|
-
export const passwordSchema = z
|
|
18
|
-
.object({
|
|
19
|
-
currentPassword: z.string().min(1).max(256),
|
|
20
|
-
password: z.string().min(12).max(256),
|
|
21
|
-
})
|
|
22
|
-
.strict();
|
|
23
|
-
export const accountSchema = z
|
|
24
|
-
.object({
|
|
25
|
-
email: z
|
|
26
|
-
.email()
|
|
27
|
-
.max(254)
|
|
28
|
-
.transform((value) => value.toLowerCase()),
|
|
29
|
-
name: z.string().trim().min(1).max(100),
|
|
30
|
-
password: z.string().min(12).max(256),
|
|
31
|
-
portal: portalSchema,
|
|
32
|
-
tenantId: identityKeySchema,
|
|
33
|
-
})
|
|
34
|
-
.strict();
|
|
1
|
+
export {};
|
|
@@ -1,81 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { accountSchema } from "./identity.schema.js";
|
|
3
|
-
import { hashPassword } from "./identity.password.js";
|
|
4
|
-
export async function seedIdentity(db, env) {
|
|
5
|
-
const tenantId = env.IDENTITY_TENANT_ID ?? "default";
|
|
6
|
-
const accounts = ["user", "admin", "super-admin"].flatMap((portal) => {
|
|
7
|
-
const prefix = `IDENTITY_SEED_${portal.toUpperCase().replace("-", "_")}`;
|
|
8
|
-
const email = env[`${prefix}_EMAIL`];
|
|
9
|
-
const password = env[`${prefix}_PASSWORD`];
|
|
10
|
-
if (!email && !password)
|
|
11
|
-
return [];
|
|
12
|
-
return [
|
|
13
|
-
accountSchema.parse({
|
|
14
|
-
email,
|
|
15
|
-
password,
|
|
16
|
-
name: env[`${prefix}_NAME`]?.trim() || portal,
|
|
17
|
-
portal,
|
|
18
|
-
tenantId,
|
|
19
|
-
}),
|
|
20
|
-
];
|
|
21
|
-
});
|
|
22
|
-
await db.transaction().execute(async (trx) => {
|
|
23
|
-
await trx
|
|
24
|
-
.insertInto("identity_tenants")
|
|
25
|
-
.values({
|
|
26
|
-
id: tenantId,
|
|
27
|
-
name: env.IDENTITY_TENANT_NAME ?? "Default organization",
|
|
28
|
-
active: 1,
|
|
29
|
-
})
|
|
30
|
-
.onConflict((c) => c.column("id").doNothing())
|
|
31
|
-
.execute();
|
|
32
|
-
for (const portal of ["user", "admin", "super-admin"]) {
|
|
33
|
-
await trx
|
|
34
|
-
.insertInto("identity_roles")
|
|
35
|
-
.values({ id: portal })
|
|
36
|
-
.onConflict((c) => c.column("id").doNothing())
|
|
37
|
-
.execute();
|
|
38
|
-
for (const permission of [
|
|
39
|
-
`desk.${portal}`,
|
|
40
|
-
"identity.self",
|
|
41
|
-
"identity.password",
|
|
42
|
-
...(portal === "user" ? [] : ["identity.manage"]),
|
|
43
|
-
]) {
|
|
44
|
-
await trx
|
|
45
|
-
.insertInto("identity_permissions")
|
|
46
|
-
.values({ id: permission })
|
|
47
|
-
.onConflict((c) => c.column("id").doNothing())
|
|
48
|
-
.execute();
|
|
49
|
-
await trx
|
|
50
|
-
.insertInto("identity_role_permissions")
|
|
51
|
-
.values({ role_id: portal, permission_id: permission })
|
|
52
|
-
.onConflict((c) => c.columns(["role_id", "permission_id"]).doNothing())
|
|
53
|
-
.execute();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
for (const account of accounts) {
|
|
57
|
-
const existing = await trx
|
|
58
|
-
.selectFrom("identity_users")
|
|
59
|
-
.select("id")
|
|
60
|
-
.where("email", "=", account.email)
|
|
61
|
-
.executeTakeFirst();
|
|
62
|
-
if (existing)
|
|
63
|
-
continue;
|
|
64
|
-
const id = randomUUID();
|
|
65
|
-
await trx
|
|
66
|
-
.insertInto("identity_users")
|
|
67
|
-
.values({
|
|
68
|
-
id,
|
|
69
|
-
email: account.email,
|
|
70
|
-
name: account.name,
|
|
71
|
-
password_hash: await hashPassword(account.password),
|
|
72
|
-
active: 1,
|
|
73
|
-
})
|
|
74
|
-
.execute();
|
|
75
|
-
await trx
|
|
76
|
-
.insertInto("identity_memberships")
|
|
77
|
-
.values({ user_id: id, tenant_id: tenantId, role_id: account.portal })
|
|
78
|
-
.execute();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IdentityConfig, Portal, Principal } from "./identity.types.js";
|
|
3
|
-
import type { z } from "zod";
|
|
4
|
-
import type { loginSchema, passwordSchema } from "./identity.schema.js";
|
|
5
|
-
export declare class IdentityService {
|
|
6
|
-
private readonly repository;
|
|
7
|
-
private readonly config;
|
|
8
|
-
private readonly dummyHash;
|
|
9
|
-
constructor(repository: IdentityRepository, config: IdentityConfig);
|
|
10
|
-
login(portal: Portal, input: z.infer<typeof loginSchema>, address: string, previous?: string): Promise<{
|
|
11
|
-
token: string;
|
|
12
|
-
sessionSeconds: number;
|
|
13
|
-
principal: {
|
|
14
|
-
user: {
|
|
15
|
-
id: string;
|
|
16
|
-
email: string;
|
|
17
|
-
name: string;
|
|
18
|
-
};
|
|
19
|
-
tenant: {
|
|
20
|
-
id: string;
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
permissions: string[];
|
|
24
|
-
appId: string;
|
|
25
|
-
portal: Portal;
|
|
26
|
-
};
|
|
27
|
-
}>;
|
|
28
|
-
authenticate(portal: Portal, token?: string): Promise<Principal>;
|
|
29
|
-
requirePermission(principal: Principal, permission: string): void;
|
|
30
|
-
logout(portal: Portal, token?: string): Promise<void>;
|
|
31
|
-
changePassword(principal: Principal, input: z.infer<typeof passwordSchema>): Promise<void>;
|
|
32
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,83 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { digest, hashPassword, verifyPassword } from "./identity.password.js";
|
|
3
|
-
import { IdentityError } from "./identity.error.js";
|
|
4
|
-
export class IdentityService {
|
|
5
|
-
repository;
|
|
6
|
-
config;
|
|
7
|
-
dummyHash = hashPassword(randomBytes(32).toString("hex"));
|
|
8
|
-
constructor(repository, config) {
|
|
9
|
-
this.repository = repository;
|
|
10
|
-
this.config = config;
|
|
11
|
-
}
|
|
12
|
-
async login(portal, input, address, previous) {
|
|
13
|
-
const key = digest(`${this.config.appId}:${portal}:${address}:${input.email}`);
|
|
14
|
-
const ipKey = digest(`${this.config.appId}:ip:${address}`);
|
|
15
|
-
if ((await this.repository.throttle(ipKey)) > 100 ||
|
|
16
|
-
(await this.repository.throttle(key)) > 10)
|
|
17
|
-
throw new IdentityError(429, "Too many sign-in attempts. Try again later.");
|
|
18
|
-
const user = await this.repository.user(input.email);
|
|
19
|
-
const valid = await verifyPassword(input.password, user?.password_hash ?? (await this.dummyHash));
|
|
20
|
-
const tenantId = this.config.mode === "single-client"
|
|
21
|
-
? this.config.tenantId
|
|
22
|
-
: input.tenantId;
|
|
23
|
-
if (!valid ||
|
|
24
|
-
!user ||
|
|
25
|
-
!Number(user.active) ||
|
|
26
|
-
!tenantId ||
|
|
27
|
-
(this.config.mode === "single-client" &&
|
|
28
|
-
input.tenantId &&
|
|
29
|
-
input.tenantId !== tenantId))
|
|
30
|
-
throw new IdentityError(401, "Invalid credentials or portal access.");
|
|
31
|
-
const principal = await this.repository.principal(user.id, tenantId, portal, this.config.appId);
|
|
32
|
-
if (!principal?.permissions.includes(`desk.${portal}`))
|
|
33
|
-
throw new IdentityError(401, "Invalid credentials or portal access.");
|
|
34
|
-
const token = randomBytes(32).toString("base64url");
|
|
35
|
-
const sessionSeconds = await this.repository.sessionSeconds(this.config.appId, this.config.sessionSeconds);
|
|
36
|
-
const created = await this.repository.createSession({
|
|
37
|
-
token_hash: digest(token),
|
|
38
|
-
user_id: user.id,
|
|
39
|
-
tenant_id: tenantId,
|
|
40
|
-
app_id: this.config.appId,
|
|
41
|
-
portal,
|
|
42
|
-
expires_at: new Date(Date.now() + sessionSeconds * 1000).toISOString(),
|
|
43
|
-
}, user.password_hash, previous ? digest(previous) : undefined);
|
|
44
|
-
if (!created)
|
|
45
|
-
throw new IdentityError(401, "Invalid credentials or portal access.");
|
|
46
|
-
await this.repository.clearThrottle(key);
|
|
47
|
-
return {
|
|
48
|
-
token,
|
|
49
|
-
sessionSeconds,
|
|
50
|
-
principal: { ...principal, appId: this.config.appId, portal },
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
async authenticate(portal, token) {
|
|
54
|
-
if (!token || !/^[A-Za-z0-9_-]{43}$/.test(token))
|
|
55
|
-
throw new IdentityError(401, "Sign in to continue.");
|
|
56
|
-
const session = await this.repository.session(digest(token), this.config.appId, portal, new Date().toISOString());
|
|
57
|
-
if (!session ||
|
|
58
|
-
(this.config.mode === "single-client" &&
|
|
59
|
-
session.tenant_id !== this.config.tenantId))
|
|
60
|
-
throw new IdentityError(401, "Sign in to continue.");
|
|
61
|
-
const principal = await this.repository.principal(session.user_id, session.tenant_id, portal, this.config.appId);
|
|
62
|
-
if (!principal)
|
|
63
|
-
throw new IdentityError(401, "Sign in to continue.");
|
|
64
|
-
return { ...principal, appId: this.config.appId, portal };
|
|
65
|
-
}
|
|
66
|
-
requirePermission(principal, permission) {
|
|
67
|
-
if (!principal.permissions.includes(permission))
|
|
68
|
-
throw new IdentityError(403, "Access denied.");
|
|
69
|
-
}
|
|
70
|
-
async logout(portal, token) {
|
|
71
|
-
if (token)
|
|
72
|
-
await this.repository.revoke(digest(token), this.config.appId, portal);
|
|
73
|
-
}
|
|
74
|
-
async changePassword(principal, input) {
|
|
75
|
-
this.requirePermission(principal, "identity.password");
|
|
76
|
-
const user = await this.repository.user(principal.user.email);
|
|
77
|
-
if (!user ||
|
|
78
|
-
!(await verifyPassword(input.currentPassword, user.password_hash)))
|
|
79
|
-
throw new IdentityError(422, "Current password is incorrect.");
|
|
80
|
-
if (!(await this.repository.changePassword(user.id, user.password_hash, await hashPassword(input.password))))
|
|
81
|
-
throw new IdentityError(409, "Account changed. Sign in again.");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
export {};
|