@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,5 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { IdentityPermissionDeclaration } from "./
|
|
1
|
+
import type { Transaction } from "kysely";
|
|
2
|
+
import type { IdentityPermissionDeclaration } from "./permission/index.js";
|
|
3
|
+
import type { IdentityUserTables } from "./user/user.types.js";
|
|
4
|
+
import type { IdentityOrganizationTables } from "./organization/organization.types.js";
|
|
5
|
+
import type { IdentityRoleTables } from "./role/role.types.js";
|
|
6
|
+
import type { IdentityPermissionTables } from "./permission/permission.types.js";
|
|
7
|
+
import type { IdentityRolePermissionTables } from "./role-permission/role-permission.types.js";
|
|
8
|
+
import type { IdentityUserRoleTables } from "./user-role/user-role.types.js";
|
|
9
|
+
import type { IdentitySessionTables } from "./session/session.types.js";
|
|
10
|
+
import type { IdentitySettingsTables } from "./settings/settings.types.js";
|
|
11
|
+
import type { IdentityAuditTables } from "./audit/audit.types.js";
|
|
3
12
|
export type Portal = "user" | "admin" | "super-admin";
|
|
4
13
|
export interface IdentityPermissionCatalogEntry {
|
|
5
14
|
id: string;
|
|
@@ -29,110 +38,8 @@ export interface Principal {
|
|
|
29
38
|
};
|
|
30
39
|
permissions: string[];
|
|
31
40
|
}
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
permission_id: string;
|
|
35
|
-
app_id: string;
|
|
36
|
-
owner: string;
|
|
37
|
-
portals: string;
|
|
38
|
-
label: Generated<string | null>;
|
|
39
|
-
};
|
|
40
|
-
identity_app_settings: {
|
|
41
|
-
app_id: string;
|
|
42
|
-
display_name: string;
|
|
43
|
-
locale: string;
|
|
44
|
-
time_zone: string;
|
|
45
|
-
session_seconds: number;
|
|
46
|
-
version: Generated<number>;
|
|
47
|
-
};
|
|
48
|
-
identity_tokens: {
|
|
49
|
-
id: string;
|
|
50
|
-
token_hash: string;
|
|
51
|
-
app_id: string;
|
|
52
|
-
tenant_id: string;
|
|
53
|
-
kind: "invitation" | "recovery";
|
|
54
|
-
email: string;
|
|
55
|
-
name: string;
|
|
56
|
-
role_id: Portal;
|
|
57
|
-
user_id: string | null;
|
|
58
|
-
expires_at: string;
|
|
59
|
-
consumed_at: string | null;
|
|
60
|
-
delivered: number;
|
|
61
|
-
};
|
|
62
|
-
identity_users: {
|
|
63
|
-
id: string;
|
|
64
|
-
email: string;
|
|
65
|
-
name: string;
|
|
66
|
-
password_hash: string;
|
|
67
|
-
active: number;
|
|
68
|
-
version: Generated<number>;
|
|
69
|
-
};
|
|
70
|
-
identity_tenants: {
|
|
71
|
-
id: string;
|
|
72
|
-
name: string;
|
|
73
|
-
active: number;
|
|
74
|
-
version: Generated<number>;
|
|
75
|
-
};
|
|
76
|
-
identity_roles: {
|
|
77
|
-
id: string;
|
|
78
|
-
version: Generated<number>;
|
|
79
|
-
};
|
|
80
|
-
identity_permissions: {
|
|
81
|
-
id: string;
|
|
82
|
-
};
|
|
83
|
-
identity_role_permissions: {
|
|
84
|
-
role_id: string;
|
|
85
|
-
permission_id: string;
|
|
86
|
-
};
|
|
87
|
-
identity_memberships: {
|
|
88
|
-
user_id: string;
|
|
89
|
-
tenant_id: string;
|
|
90
|
-
role_id: string;
|
|
91
|
-
custom_role_id: Generated<string | null>;
|
|
92
|
-
active: Generated<number>;
|
|
93
|
-
version: Generated<number>;
|
|
94
|
-
};
|
|
95
|
-
identity_custom_roles: {
|
|
96
|
-
id: string;
|
|
97
|
-
app_id: string;
|
|
98
|
-
tenant_id: string;
|
|
99
|
-
name: string;
|
|
100
|
-
active: Generated<number>;
|
|
101
|
-
version: Generated<number>;
|
|
102
|
-
};
|
|
103
|
-
identity_custom_role_permissions: {
|
|
104
|
-
role_id: string;
|
|
105
|
-
permission_id: string;
|
|
106
|
-
};
|
|
107
|
-
identity_sessions: {
|
|
108
|
-
token_hash: string;
|
|
109
|
-
user_id: string;
|
|
110
|
-
tenant_id: string;
|
|
111
|
-
app_id: string;
|
|
112
|
-
portal: Portal;
|
|
113
|
-
expires_at: string;
|
|
114
|
-
};
|
|
115
|
-
identity_throttles: {
|
|
116
|
-
key: string;
|
|
117
|
-
attempts: number;
|
|
118
|
-
expires_at: string;
|
|
119
|
-
};
|
|
120
|
-
identity_settings: {
|
|
121
|
-
tenant_id: string;
|
|
122
|
-
display_name: string;
|
|
123
|
-
locale: string;
|
|
124
|
-
time_zone: string;
|
|
125
|
-
version: Generated<number>;
|
|
126
|
-
};
|
|
127
|
-
identity_audit_events: {
|
|
128
|
-
id: string;
|
|
129
|
-
app_id: string;
|
|
130
|
-
actor_id: string;
|
|
131
|
-
tenant_id: string;
|
|
132
|
-
action: string;
|
|
133
|
-
resource_id: string;
|
|
134
|
-
created_at: string;
|
|
135
|
-
};
|
|
41
|
+
export type IdentityMutation = <T>(actor: Principal, resource: string, id: string, action: (trx: Transaction<IdentitySchema>, id: string) => Promise<T>, affectedTenant?: string) => Promise<T>;
|
|
42
|
+
export interface IdentitySchema extends IdentityUserTables, IdentityOrganizationTables, IdentityRoleTables, IdentityPermissionTables, IdentityRolePermissionTables, IdentityUserRoleTables, IdentitySessionTables, IdentitySettingsTables, IdentityAuditTables {
|
|
136
43
|
}
|
|
137
44
|
export interface IdentityDeliveryProvider {
|
|
138
45
|
send(input: {
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
export { createIdentityProvider } from "./identity.provider.js";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
10
|
-
export type {
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
2
|
+
export { createIdentityTenantDirectory } from "./organization/index.js";
|
|
3
|
+
export type { IdentityTenantDirectory } from "./organization/index.js";
|
|
4
|
+
export { IdentityError } from "./support/identity.error.js";
|
|
5
|
+
export { identityMigration } from "./legacy/identity.migration.js";
|
|
6
|
+
export { identityAdministrationMigration } from "./legacy/identity.administration-migration.js";
|
|
7
|
+
export { identityRolesMigration } from "./role/index.js";
|
|
8
|
+
export { identityPermissionDeclarationsMigration } from "./permission/index.js";
|
|
9
|
+
export { identityPermissionLabelsMigration } from "./permission/index.js";
|
|
10
|
+
export type { IdentityPermissionDeclaration } from "./permission/index.js";
|
|
11
|
+
export { listSchema } from "./support/pagination.schema.js";
|
|
12
|
+
export { organizationCreateSchema, organizationUpdateSchema } from "./organization/index.js";
|
|
13
|
+
export { settingsSchema } from "./settings/index.js";
|
|
14
|
+
export { userCreateSchema, userUpdateSchema, profileSchema } from "./user/index.js";
|
|
15
|
+
export { membershipSchema, membershipUpdateSchema, membershipDeleteQuerySchema } from "./user-role/index.js";
|
|
16
|
+
export { customRoleCreateSchema, customRoleUpdateSchema, roleUpdateSchema } from "./role/index.js";
|
|
17
|
+
export type { IdentityListQuery, IdentityResource } from "./support/pagination.schema.js";
|
|
18
|
+
export { seedIdentity } from "./composition/identity.seed.js";
|
|
19
|
+
export type { IdentitySchema, IdentityConfig, Principal, Portal, IdentityDeliveryProvider, IdentityProviderOptions, IdentityPermissionCatalogEntry } from "./identity.types.js";
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export { createIdentityProvider } from "./identity.provider.js";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
2
|
+
export { createIdentityTenantDirectory } from "./organization/index.js";
|
|
3
|
+
export { IdentityError } from "./support/identity.error.js";
|
|
4
|
+
export { identityMigration } from "./legacy/identity.migration.js";
|
|
5
|
+
export { identityAdministrationMigration } from "./legacy/identity.administration-migration.js";
|
|
6
|
+
export { identityRolesMigration } from "./role/index.js";
|
|
7
|
+
export { identityPermissionDeclarationsMigration } from "./permission/index.js";
|
|
8
|
+
export { identityPermissionLabelsMigration } from "./permission/index.js";
|
|
9
|
+
export { listSchema } from "./support/pagination.schema.js";
|
|
10
|
+
export { organizationCreateSchema, organizationUpdateSchema } from "./organization/index.js";
|
|
11
|
+
export { settingsSchema } from "./settings/index.js";
|
|
12
|
+
export { userCreateSchema, userUpdateSchema, profileSchema } from "./user/index.js";
|
|
13
|
+
export { membershipSchema, membershipUpdateSchema, membershipDeleteQuerySchema } from "./user-role/index.js";
|
|
14
|
+
export { customRoleCreateSchema, customRoleUpdateSchema, roleUpdateSchema } from "./role/index.js";
|
|
15
|
+
export { seedIdentity } from "./composition/identity.seed.js";
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export const identityAdministrationMigration = {
|
|
2
2
|
async up(db) {
|
|
3
|
-
for (const table of [
|
|
4
|
-
"identity_users",
|
|
5
|
-
"identity_tenants",
|
|
6
|
-
"identity_roles",
|
|
7
|
-
])
|
|
3
|
+
for (const table of ["identity_users", "identity_tenants", "identity_roles"])
|
|
8
4
|
await db.schema
|
|
9
5
|
.alterTable(table)
|
|
10
6
|
.addColumn("version", "integer", (c) => c.notNull().defaultTo(0))
|
|
@@ -61,15 +57,11 @@ export const identityAdministrationMigration = {
|
|
|
61
57
|
.execute();
|
|
62
58
|
},
|
|
63
59
|
async down(db) {
|
|
64
|
-
for (const table of [
|
|
65
|
-
"identity_users",
|
|
66
|
-
"identity_tenants",
|
|
67
|
-
"identity_roles",
|
|
68
|
-
])
|
|
60
|
+
for (const table of ["identity_users", "identity_tenants", "identity_roles"])
|
|
69
61
|
await db.schema.alterTable(table).dropColumn("version").execute();
|
|
70
62
|
await db.schema.dropTable("identity_app_settings").execute();
|
|
71
63
|
await db.schema.dropTable("identity_tokens").execute();
|
|
72
64
|
await db.schema.dropTable("identity_audit_events").execute();
|
|
73
65
|
await db.schema.dropTable("identity_settings").execute();
|
|
74
|
-
}
|
|
66
|
+
}
|
|
75
67
|
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const identityMigration = {
|
|
2
|
+
async up(db) {
|
|
3
|
+
await db.schema
|
|
4
|
+
.createTable("identity_users")
|
|
5
|
+
.addColumn("id", "text", (c) => c.primaryKey())
|
|
6
|
+
.addColumn("email", "text", (c) => c.notNull().unique())
|
|
7
|
+
.addColumn("name", "text", (c) => c.notNull())
|
|
8
|
+
.addColumn("password_hash", "text", (c) => c.notNull())
|
|
9
|
+
.addColumn("active", "integer", (c) => c.notNull().defaultTo(1))
|
|
10
|
+
.execute();
|
|
11
|
+
await db.schema
|
|
12
|
+
.createTable("identity_tenants")
|
|
13
|
+
.addColumn("id", "text", (c) => c.primaryKey())
|
|
14
|
+
.addColumn("name", "text", (c) => c.notNull())
|
|
15
|
+
.addColumn("active", "integer", (c) => c.notNull().defaultTo(1))
|
|
16
|
+
.execute();
|
|
17
|
+
await db.schema
|
|
18
|
+
.createTable("identity_roles")
|
|
19
|
+
.addColumn("id", "text", (c) => c.primaryKey())
|
|
20
|
+
.execute();
|
|
21
|
+
await db.schema
|
|
22
|
+
.createTable("identity_permissions")
|
|
23
|
+
.addColumn("id", "text", (c) => c.primaryKey())
|
|
24
|
+
.execute();
|
|
25
|
+
await db.schema
|
|
26
|
+
.createTable("identity_role_permissions")
|
|
27
|
+
.addColumn("role_id", "text", (c) => c.notNull().references("identity_roles.id"))
|
|
28
|
+
.addColumn("permission_id", "text", (c) => c.notNull().references("identity_permissions.id"))
|
|
29
|
+
.addPrimaryKeyConstraint("identity_role_permission_pk", ["role_id", "permission_id"])
|
|
30
|
+
.execute();
|
|
31
|
+
await db.schema
|
|
32
|
+
.createTable("identity_memberships")
|
|
33
|
+
.addColumn("user_id", "text", (c) => c.notNull().references("identity_users.id").onDelete("cascade"))
|
|
34
|
+
.addColumn("tenant_id", "text", (c) => c.notNull().references("identity_tenants.id").onDelete("cascade"))
|
|
35
|
+
.addColumn("role_id", "text", (c) => c.notNull().references("identity_roles.id"))
|
|
36
|
+
.addPrimaryKeyConstraint("identity_membership_pk", ["user_id", "tenant_id", "role_id"])
|
|
37
|
+
.execute();
|
|
38
|
+
await db.schema
|
|
39
|
+
.createTable("identity_sessions")
|
|
40
|
+
.addColumn("token_hash", "text", (c) => c.primaryKey())
|
|
41
|
+
.addColumn("user_id", "text", (c) => c.notNull().references("identity_users.id").onDelete("cascade"))
|
|
42
|
+
.addColumn("tenant_id", "text", (c) => c.notNull().references("identity_tenants.id").onDelete("cascade"))
|
|
43
|
+
.addColumn("app_id", "text", (c) => c.notNull())
|
|
44
|
+
.addColumn("portal", "text", (c) => c.notNull())
|
|
45
|
+
.addColumn("expires_at", "text", (c) => c.notNull())
|
|
46
|
+
.execute();
|
|
47
|
+
await db.schema
|
|
48
|
+
.createIndex("identity_sessions_expiry")
|
|
49
|
+
.on("identity_sessions")
|
|
50
|
+
.column("expires_at")
|
|
51
|
+
.execute();
|
|
52
|
+
await db.schema
|
|
53
|
+
.createTable("identity_throttles")
|
|
54
|
+
.addColumn("key", "text", (c) => c.primaryKey())
|
|
55
|
+
.addColumn("attempts", "integer", (c) => c.notNull())
|
|
56
|
+
.addColumn("expires_at", "text", (c) => c.notNull())
|
|
57
|
+
.execute();
|
|
58
|
+
},
|
|
59
|
+
async down(db) {
|
|
60
|
+
for (const table of [
|
|
61
|
+
"identity_throttles",
|
|
62
|
+
"identity_sessions",
|
|
63
|
+
"identity_memberships",
|
|
64
|
+
"identity_role_permissions",
|
|
65
|
+
"identity_permissions",
|
|
66
|
+
"identity_roles",
|
|
67
|
+
"identity_tenants",
|
|
68
|
+
"identity_users"
|
|
69
|
+
])
|
|
70
|
+
await db.schema.dropTable(table).execute();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createIdentityOrganizationProvider, createIdentityTenantDirectory } from "./organization.provider.js";
|
|
2
|
+
export { organizationCreateSchema, organizationUpdateSchema } from "./organization.schema.js";
|
|
3
|
+
export { seedOrganization } from "./organization.seed.js";
|
|
4
|
+
export { organizationResource, organizationResourceRoute } from "./organization.routes.js";
|
|
5
|
+
export type { IdentityOrganizationRow, IdentityTenantDirectory } from "./organization.types.js";
|
|
6
|
+
export { IdentityOrganizationController } from "./organization.controller.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createIdentityOrganizationProvider, createIdentityTenantDirectory } from "./organization.provider.js";
|
|
2
|
+
export { organizationCreateSchema, organizationUpdateSchema } from "./organization.schema.js";
|
|
3
|
+
export { seedOrganization } from "./organization.seed.js";
|
|
4
|
+
export { organizationResource, organizationResourceRoute } from "./organization.routes.js";
|
|
5
|
+
export { IdentityOrganizationController } from "./organization.controller.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Principal } from "../identity.types.js";
|
|
2
|
+
import type { IdentityListQuery } from "../support/pagination.schema.js";
|
|
3
|
+
import type { createIdentityOrganizationProvider } from "./organization.provider.js";
|
|
4
|
+
export declare class IdentityOrganizationController {
|
|
5
|
+
private readonly service;
|
|
6
|
+
constructor(service: ReturnType<typeof createIdentityOrganizationProvider>);
|
|
7
|
+
index(actor: Principal, query: IdentityListQuery): Promise<{
|
|
8
|
+
data: {
|
|
9
|
+
active: boolean;
|
|
10
|
+
version: number;
|
|
11
|
+
}[];
|
|
12
|
+
meta: {
|
|
13
|
+
page: number;
|
|
14
|
+
perPage: number;
|
|
15
|
+
total: number;
|
|
16
|
+
lastPage: number;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
show(actor: Principal, id: string): Promise<{
|
|
20
|
+
active: boolean;
|
|
21
|
+
version: number;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
store(actor: Principal, raw: unknown): Promise<{
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
active: boolean;
|
|
27
|
+
version: number;
|
|
28
|
+
}>;
|
|
29
|
+
update(actor: Principal, id: string, raw: unknown): Promise<{
|
|
30
|
+
active: boolean;
|
|
31
|
+
version: number;
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class IdentityOrganizationController {
|
|
2
|
+
service;
|
|
3
|
+
constructor(service) {
|
|
4
|
+
this.service = service;
|
|
5
|
+
}
|
|
6
|
+
index(actor, query) {
|
|
7
|
+
return this.service.list(actor, query);
|
|
8
|
+
}
|
|
9
|
+
show(actor, id) {
|
|
10
|
+
return this.service.show(actor, id);
|
|
11
|
+
}
|
|
12
|
+
store(actor, raw) {
|
|
13
|
+
return this.service.create(actor, raw);
|
|
14
|
+
}
|
|
15
|
+
update(actor, id, raw) {
|
|
16
|
+
return this.service.update(actor, id, raw);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Kysely, Transaction } from "kysely";
|
|
2
|
+
import type { IdentityMutation, IdentitySchema } from "../identity.types.js";
|
|
3
|
+
import { organizationNameSource } from "./organization.repository.js";
|
|
4
|
+
import type { IdentityTenantDirectory } from "./organization.types.js";
|
|
5
|
+
/** Read-only server contract for modules that depend on active tenant identity. */
|
|
6
|
+
export declare function createIdentityTenantDirectory(database: Kysely<IdentitySchema>): IdentityTenantDirectory;
|
|
7
|
+
export declare function createIdentityOrganizationProvider(database: Kysely<IdentitySchema>, mutate: IdentityMutation, revokeTenantSessions: (trx: Transaction<IdentitySchema>, tenantId: string) => Promise<void>): Readonly<{
|
|
8
|
+
verify: () => Promise<void>;
|
|
9
|
+
tenantIds: (trx: Transaction<IdentitySchema>) => Promise<string[]>;
|
|
10
|
+
active: (trx: Transaction<IdentitySchema>, id: string) => Promise<{
|
|
11
|
+
id: string;
|
|
12
|
+
} | undefined>;
|
|
13
|
+
activeDetail: (db: Kysely<IdentitySchema>, id: string) => Promise<{
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
} | undefined>;
|
|
17
|
+
nameSource: typeof organizationNameSource;
|
|
18
|
+
list: (actor: import("../identity.types.js").Principal, query: import("../index.js").IdentityListQuery) => Promise<{
|
|
19
|
+
data: {
|
|
20
|
+
active: boolean;
|
|
21
|
+
version: number;
|
|
22
|
+
}[];
|
|
23
|
+
meta: {
|
|
24
|
+
page: number;
|
|
25
|
+
perPage: number;
|
|
26
|
+
total: number;
|
|
27
|
+
lastPage: number;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
show: (actor: import("../identity.types.js").Principal, id: string) => Promise<{
|
|
31
|
+
active: boolean;
|
|
32
|
+
version: number;
|
|
33
|
+
} | undefined>;
|
|
34
|
+
create: (actor: import("../identity.types.js").Principal, raw: unknown) => Promise<{
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
active: boolean;
|
|
38
|
+
version: number;
|
|
39
|
+
}>;
|
|
40
|
+
update: (actor: import("../identity.types.js").Principal, id: string, raw: unknown) => Promise<{
|
|
41
|
+
active: boolean;
|
|
42
|
+
version: number;
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
}>;
|
|
46
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IdentityOrganizationRepository, organizationNameSource } from "./organization.repository.js";
|
|
2
|
+
import { IdentityOrganizationService } from "./organization.service.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/** Read-only server contract for modules that depend on active tenant identity. */
|
|
5
|
+
export function createIdentityTenantDirectory(database) {
|
|
6
|
+
const repository = new IdentityOrganizationRepository(database);
|
|
7
|
+
return {
|
|
8
|
+
active(id) {
|
|
9
|
+
z.string().min(1).max(255).parse(id);
|
|
10
|
+
return repository.activeDetail(database, id);
|
|
11
|
+
},
|
|
12
|
+
listActive(after, pageSize) {
|
|
13
|
+
z.string().max(255).parse(after);
|
|
14
|
+
z.number().int().min(1).max(500).parse(pageSize);
|
|
15
|
+
return repository.listActive(after, pageSize);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function createIdentityOrganizationProvider(database, mutate, revokeTenantSessions) {
|
|
20
|
+
const repository = new IdentityOrganizationRepository(database);
|
|
21
|
+
const service = new IdentityOrganizationService(repository, mutate, revokeTenantSessions);
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
verify: repository.verifySchema.bind(repository),
|
|
24
|
+
tenantIds: repository.tenantIds.bind(repository),
|
|
25
|
+
active: repository.active.bind(repository),
|
|
26
|
+
activeDetail: repository.activeDetail.bind(repository),
|
|
27
|
+
nameSource: organizationNameSource,
|
|
28
|
+
list: service.list.bind(service),
|
|
29
|
+
show: service.show.bind(service),
|
|
30
|
+
create: service.create.bind(service),
|
|
31
|
+
update: service.update.bind(service)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Kysely, type Transaction } from "kysely";
|
|
2
|
+
import type { IdentitySchema, Principal } from "../identity.types.js";
|
|
3
|
+
import type { IdentityListQuery } from "../support/pagination.schema.js";
|
|
4
|
+
export declare const organizationNameSource: () => import("kysely").RawBuilder<unknown>;
|
|
5
|
+
export declare class IdentityOrganizationRepository {
|
|
6
|
+
private readonly db;
|
|
7
|
+
constructor(db: Kysely<IdentitySchema>);
|
|
8
|
+
verifySchema(): Promise<void>;
|
|
9
|
+
tenantIds(trx: Transaction<IdentitySchema>): Promise<string[]>;
|
|
10
|
+
active(trx: Transaction<IdentitySchema>, id: string): Promise<{
|
|
11
|
+
id: string;
|
|
12
|
+
} | undefined>;
|
|
13
|
+
activeDetail(db: Kysely<IdentitySchema>, id: string): Promise<{
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
} | undefined>;
|
|
17
|
+
listActive(after: string, pageSize: number): Promise<{
|
|
18
|
+
id: string;
|
|
19
|
+
}[]>;
|
|
20
|
+
list(actor: Principal, query: IdentityListQuery): Promise<{
|
|
21
|
+
data: {
|
|
22
|
+
active: boolean;
|
|
23
|
+
version: number;
|
|
24
|
+
}[];
|
|
25
|
+
meta: {
|
|
26
|
+
page: number;
|
|
27
|
+
perPage: number;
|
|
28
|
+
total: number;
|
|
29
|
+
lastPage: number;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
32
|
+
show(actor: Principal, id: string): Promise<{
|
|
33
|
+
active: boolean;
|
|
34
|
+
version: number;
|
|
35
|
+
} | undefined>;
|
|
36
|
+
exists(trx: Transaction<IdentitySchema>, id: string): Promise<{
|
|
37
|
+
id: string;
|
|
38
|
+
} | undefined>;
|
|
39
|
+
version(trx: Transaction<IdentitySchema>, id: string): Promise<{
|
|
40
|
+
version: number;
|
|
41
|
+
}>;
|
|
42
|
+
create(trx: Transaction<IdentitySchema>, input: {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
active: boolean;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
update(trx: Transaction<IdentitySchema>, id: string, input: {
|
|
48
|
+
name?: string;
|
|
49
|
+
active?: boolean;
|
|
50
|
+
expectedVersion: number;
|
|
51
|
+
}): Promise<boolean>;
|
|
52
|
+
get(trx: Transaction<IdentitySchema>, id: string): Promise<{
|
|
53
|
+
active: number;
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
version: number;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { listRows, showRow } from "../support/pagination.js";
|
|
3
|
+
function organizationListSource(actor) {
|
|
4
|
+
return sql `select id,name,active,version from identity_tenants ${actor.portal === "super-admin" ? sql `` : sql `where id=${actor.tenant.id}`}`;
|
|
5
|
+
}
|
|
6
|
+
export const organizationNameSource = () => sql `select id,name from identity_tenants`;
|
|
7
|
+
export class IdentityOrganizationRepository {
|
|
8
|
+
db;
|
|
9
|
+
constructor(db) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
}
|
|
12
|
+
async verifySchema() {
|
|
13
|
+
await this.db.selectFrom("identity_tenants").select("version").limit(1).execute();
|
|
14
|
+
}
|
|
15
|
+
async tenantIds(trx) {
|
|
16
|
+
const rows = await trx.selectFrom("identity_tenants").select("id").execute();
|
|
17
|
+
return rows.map((row) => row.id);
|
|
18
|
+
}
|
|
19
|
+
active(trx, id) {
|
|
20
|
+
return trx
|
|
21
|
+
.selectFrom("identity_tenants")
|
|
22
|
+
.select("id")
|
|
23
|
+
.where("id", "=", id)
|
|
24
|
+
.where("active", "=", 1)
|
|
25
|
+
.executeTakeFirst();
|
|
26
|
+
}
|
|
27
|
+
activeDetail(db, id) {
|
|
28
|
+
return db
|
|
29
|
+
.selectFrom("identity_tenants")
|
|
30
|
+
.select(["id", "name"])
|
|
31
|
+
.where("id", "=", id)
|
|
32
|
+
.where("active", "=", 1)
|
|
33
|
+
.executeTakeFirst();
|
|
34
|
+
}
|
|
35
|
+
listActive(after, pageSize) {
|
|
36
|
+
return this.db
|
|
37
|
+
.selectFrom("identity_tenants")
|
|
38
|
+
.select("id")
|
|
39
|
+
.where("active", "=", 1)
|
|
40
|
+
.where("id", ">", after)
|
|
41
|
+
.orderBy("id")
|
|
42
|
+
.limit(pageSize)
|
|
43
|
+
.execute();
|
|
44
|
+
}
|
|
45
|
+
list(actor, query) {
|
|
46
|
+
const present = (row) => ({
|
|
47
|
+
...row,
|
|
48
|
+
active: Boolean(row.active),
|
|
49
|
+
version: Number(row.version)
|
|
50
|
+
});
|
|
51
|
+
return listRows(this.db, organizationListSource(actor), ["id", "name"], query, present);
|
|
52
|
+
}
|
|
53
|
+
show(actor, id) {
|
|
54
|
+
const present = (row) => ({
|
|
55
|
+
...row,
|
|
56
|
+
active: Boolean(row.active),
|
|
57
|
+
version: Number(row.version)
|
|
58
|
+
});
|
|
59
|
+
return showRow(this.db, organizationListSource(actor), id, present);
|
|
60
|
+
}
|
|
61
|
+
exists(trx, id) {
|
|
62
|
+
return trx.selectFrom("identity_tenants").select("id").where("id", "=", id).executeTakeFirst();
|
|
63
|
+
}
|
|
64
|
+
version(trx, id) {
|
|
65
|
+
return trx
|
|
66
|
+
.selectFrom("identity_tenants")
|
|
67
|
+
.select("version")
|
|
68
|
+
.where("id", "=", id)
|
|
69
|
+
.executeTakeFirstOrThrow();
|
|
70
|
+
}
|
|
71
|
+
async create(trx, input) {
|
|
72
|
+
await trx
|
|
73
|
+
.insertInto("identity_tenants")
|
|
74
|
+
.values({
|
|
75
|
+
id: input.id,
|
|
76
|
+
name: input.name,
|
|
77
|
+
active: Number(input.active)
|
|
78
|
+
})
|
|
79
|
+
.execute();
|
|
80
|
+
}
|
|
81
|
+
async update(trx, id, input) {
|
|
82
|
+
const updated = await trx
|
|
83
|
+
.updateTable("identity_tenants")
|
|
84
|
+
.set({
|
|
85
|
+
name: input.name,
|
|
86
|
+
active: input.active === undefined ? undefined : Number(input.active),
|
|
87
|
+
version: sql `version + 1`
|
|
88
|
+
})
|
|
89
|
+
.where("id", "=", id)
|
|
90
|
+
.where("version", "=", input.expectedVersion)
|
|
91
|
+
.executeTakeFirst();
|
|
92
|
+
return updated.numUpdatedRows === 1n;
|
|
93
|
+
}
|
|
94
|
+
async get(trx, id) {
|
|
95
|
+
return trx
|
|
96
|
+
.selectFrom("identity_tenants")
|
|
97
|
+
.selectAll()
|
|
98
|
+
.where("id", "=", id)
|
|
99
|
+
.executeTakeFirstOrThrow();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const organizationResource: "organizations";
|
|
2
|
+
export declare const organizationResourceRoute: (controller: import("./organization.controller.js").IdentityOrganizationController) => {
|
|
3
|
+
resource: "organizations";
|
|
4
|
+
controller: import("./organization.controller.js").IdentityOrganizationController;
|
|
5
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const organizationCreateSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
active: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export declare const organizationUpdateSchema: z.ZodObject<{
|
|
8
|
+
name: z.ZodOptional<z.ZodString>;
|
|
9
|
+
active: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
expectedVersion: z.ZodNumber;
|
|
11
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { identityKeySchema } from "../support/identity.schema.js";
|
|
3
|
+
const name = z.string().trim().min(1).max(100);
|
|
4
|
+
export const organizationCreateSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
id: identityKeySchema,
|
|
7
|
+
name,
|
|
8
|
+
active: z.boolean().default(true)
|
|
9
|
+
})
|
|
10
|
+
.strict();
|
|
11
|
+
export const organizationUpdateSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
name: name.optional(),
|
|
14
|
+
active: z.boolean().optional(),
|
|
15
|
+
expectedVersion: z.number().int().min(0)
|
|
16
|
+
})
|
|
17
|
+
.strict()
|
|
18
|
+
.refine((value) => Object.keys(value).length > 1, "Provide a changed field.");
|