@logto/schemas 1.15.0 → 1.17.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/alterations/1.16.0-1712912361-delete-jwt-customier-with-empty-script.ts +23 -0
- package/alterations/1.16.0-1713942039-add-organization-custom-data.ts +25 -0
- package/alterations/1.16.0-1714270244-application-org-resource-scope.ts +32 -0
- package/alterations/1.17.0-1715826336-add-default-user-role-config.ts +18 -0
- package/alterations/1.17.0-1715829731-rename-data-hook-schema-update-event.ts +120 -0
- package/alterations/1.17.0-1716278409-remove-internal-role-database-policies.ts +37 -0
- package/alterations/1.17.0-1716291265-create-pre-configured-m-api-role.ts +92 -0
- package/alterations/1.17.0-1717148078-remove-service-log-reference.ts +19 -0
- package/alterations/utils/1716643968-id-generation.ts +46 -0
- package/alterations-js/1.16.0-1712912361-delete-jwt-customier-with-empty-script.d.ts +3 -0
- package/alterations-js/1.16.0-1712912361-delete-jwt-customier-with-empty-script.js +17 -0
- package/alterations-js/1.16.0-1713942039-add-organization-custom-data.d.ts +4 -0
- package/alterations-js/1.16.0-1713942039-add-organization-custom-data.js +17 -0
- package/alterations-js/1.16.0-1714270244-application-org-resource-scope.d.ts +3 -0
- package/alterations-js/1.16.0-1714270244-application-org-resource-scope.js +27 -0
- package/alterations-js/1.17.0-1715826336-add-default-user-role-config.d.ts +3 -0
- package/alterations-js/1.17.0-1715826336-add-default-user-role-config.js +14 -0
- package/alterations-js/1.17.0-1715829731-rename-data-hook-schema-update-event.d.ts +3 -0
- package/alterations-js/1.17.0-1715829731-rename-data-hook-schema-update-event.js +96 -0
- package/alterations-js/1.17.0-1716278409-remove-internal-role-database-policies.d.ts +3 -0
- package/alterations-js/1.17.0-1716278409-remove-internal-role-database-policies.js +33 -0
- package/alterations-js/1.17.0-1716291265-create-pre-configured-m-api-role.d.ts +7 -0
- package/alterations-js/1.17.0-1716291265-create-pre-configured-m-api-role.js +77 -0
- package/alterations-js/1.17.0-1717148078-remove-service-log-reference.d.ts +3 -0
- package/alterations-js/1.17.0-1717148078-remove-service-log-reference.js +15 -0
- package/alterations-js/utils/1716643968-id-generation.d.ts +19 -0
- package/alterations-js/utils/1716643968-id-generation.js +26 -0
- package/lib/db-entries/application-user-consent-organization-resource-scope.d.ts +24 -0
- package/lib/db-entries/application-user-consent-organization-resource-scope.js +29 -0
- package/lib/db-entries/index.d.ts +1 -0
- package/lib/db-entries/index.js +1 -0
- package/lib/db-entries/organization.d.ts +6 -2
- package/lib/db-entries/organization.js +5 -0
- package/lib/db-entries/role.d.ts +5 -1
- package/lib/db-entries/role.js +4 -0
- package/lib/foundations/jsonb-types/hooks.d.ts +73 -3
- package/lib/foundations/jsonb-types/hooks.js +101 -7
- package/lib/models/tenants.d.ts +0 -21
- package/lib/models/tenants.js +0 -3
- package/lib/seeds/cloud-api.js +1 -0
- package/lib/seeds/management-api.d.ts +4 -0
- package/lib/seeds/management-api.js +10 -0
- package/lib/types/application.d.ts +81 -0
- package/lib/types/application.js +7 -4
- package/lib/types/consent.d.ts +207 -22
- package/lib/types/consent.js +11 -7
- package/lib/types/hook.d.ts +66 -19
- package/lib/types/logto-config/index.d.ts +20 -19
- package/lib/types/logto-config/jwt-customizer.d.ts +47 -40
- package/lib/types/logto-config/jwt-customizer.js +19 -24
- package/lib/types/logto-config/jwt-customizer.test.js +10 -2
- package/lib/types/mapi-proxy.js +1 -0
- package/lib/types/organization.d.ts +0 -1
- package/lib/types/organization.js +0 -9
- package/lib/types/system.d.ts +28 -1
- package/lib/types/system.js +16 -0
- package/lib/types/user.d.ts +12 -8
- package/lib/types/user.js +5 -1
- package/lib/utils/role.d.ts +2 -0
- package/lib/utils/role.js +2 -0
- package/package.json +10 -9
- package/tables/_after_all.sql +0 -27
- package/tables/application_user_consent_organization_resource_scopes.sql +18 -0
- package/tables/organizations.sql +2 -0
- package/tables/roles.sql +2 -0
- package/tables/service_logs.sql +1 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { yes } from '@silverhand/essentials';
|
|
2
|
+
import { sql } from '@silverhand/slonik';
|
|
3
|
+
import { generateStandardId } from './utils/1716643968-id-generation.js';
|
|
4
|
+
const isCi = yes(process.env.CI);
|
|
5
|
+
const defaultTenantId = 'default';
|
|
6
|
+
const defaultTenantManagementApiIndicator = `https://${defaultTenantId}.logto.app/api`;
|
|
7
|
+
const roleName = 'Logto Management API access';
|
|
8
|
+
const roleDescription = 'This default role grants access to the Logto management API.';
|
|
9
|
+
var RoleType;
|
|
10
|
+
(function (RoleType) {
|
|
11
|
+
RoleType["MachineToMachine"] = "MachineToMachine";
|
|
12
|
+
})(RoleType || (RoleType = {}));
|
|
13
|
+
var PredefinedScope;
|
|
14
|
+
(function (PredefinedScope) {
|
|
15
|
+
PredefinedScope["All"] = "all";
|
|
16
|
+
})(PredefinedScope || (PredefinedScope = {}));
|
|
17
|
+
/**
|
|
18
|
+
* This script is to create a pre-configured Management API M2M role for new users.
|
|
19
|
+
* This script is **only for CI**, since we won't create this role for existing users, so this script is not applicable for existing db data.
|
|
20
|
+
*/
|
|
21
|
+
const alteration = {
|
|
22
|
+
up: async (pool) => {
|
|
23
|
+
if (!isCi) {
|
|
24
|
+
console.info("Skipping the alteration script `next-1716291265-create-pre-configured-m-api-role.ts` since it's should not be applied to existing db data.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Only affect the `default` tenant, since this is the only tenant in the OSS version and the initial tenant in the cloud version.
|
|
29
|
+
* So we only need to care about this role for the `default` tenant.
|
|
30
|
+
*/
|
|
31
|
+
const roleId = generateStandardId();
|
|
32
|
+
await pool.query(sql `
|
|
33
|
+
insert into roles (id, tenant_id, name, description, type)
|
|
34
|
+
values (
|
|
35
|
+
${roleId},
|
|
36
|
+
${defaultTenantId},
|
|
37
|
+
${roleName},
|
|
38
|
+
${roleDescription},
|
|
39
|
+
${RoleType.MachineToMachine}
|
|
40
|
+
);
|
|
41
|
+
`);
|
|
42
|
+
// Assign Logto Management API permission `all` to the Logto Management API M2M role
|
|
43
|
+
await pool.query(sql `
|
|
44
|
+
insert into roles_scopes (id, role_id, scope_id, tenant_id)
|
|
45
|
+
values (
|
|
46
|
+
${generateStandardId()},
|
|
47
|
+
${roleId},
|
|
48
|
+
(
|
|
49
|
+
select scopes.id
|
|
50
|
+
from scopes
|
|
51
|
+
join resources on
|
|
52
|
+
scopes.tenant_id = resources.tenant_id and
|
|
53
|
+
scopes.resource_id = resources.id
|
|
54
|
+
where resources.indicator = ${defaultTenantManagementApiIndicator}
|
|
55
|
+
and scopes.name = ${PredefinedScope.All}
|
|
56
|
+
and scopes.tenant_id = ${defaultTenantId}
|
|
57
|
+
),
|
|
58
|
+
${defaultTenantId}
|
|
59
|
+
)
|
|
60
|
+
`);
|
|
61
|
+
},
|
|
62
|
+
down: async (pool) => {
|
|
63
|
+
if (!isCi) {
|
|
64
|
+
console.info("Skipping the down script `next-1716291265-create-pre-configured-m-api-role.ts` since it's should not be applied to production db.");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// Delete the created role
|
|
68
|
+
await pool.query(sql `
|
|
69
|
+
delete from roles
|
|
70
|
+
where tenant_id = ${defaultTenantId}
|
|
71
|
+
and name = ${roleName}
|
|
72
|
+
and description = ${roleDescription}
|
|
73
|
+
and type = ${RoleType.MachineToMachine}
|
|
74
|
+
`);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
export default alteration;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
const alteration = {
|
|
3
|
+
up: async (pool) => {
|
|
4
|
+
await pool.query(sql `
|
|
5
|
+
alter table service_logs drop constraint service_logs_tenant_id_fkey;
|
|
6
|
+
`);
|
|
7
|
+
},
|
|
8
|
+
down: async (pool) => {
|
|
9
|
+
await pool.query(sql `
|
|
10
|
+
alter table service_logs add constraint service_logs_tenant_id_fkey
|
|
11
|
+
foreign key (tenant_id) references tenants(id) on update cascade on delete cascade;
|
|
12
|
+
`);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
export default alteration;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a standard id with 21 characters, including lowercase letters and numbers.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link lowercaseAlphabet}
|
|
5
|
+
*/
|
|
6
|
+
export declare const generateStandardId: (size?: number | undefined) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Generate a standard short id with 12 characters, including lowercase letters and numbers.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link lowercaseAlphabet}
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateStandardShortId: (size?: number | undefined) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a standard secret with 32 characters, including uppercase letters, lowercase
|
|
15
|
+
* letters, and numbers.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link alphabet}
|
|
18
|
+
*/
|
|
19
|
+
export declare const generateStandardSecret: (size?: number | undefined) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is forked from `@logto/shared` 3.1.0 to avoid alteration scripts to depend on outer packages.
|
|
3
|
+
*/
|
|
4
|
+
import { customAlphabet } from 'nanoid';
|
|
5
|
+
const lowercaseAlphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
6
|
+
const alphabet = `${lowercaseAlphabet}ABCDEFGHIJKLMNOPQRSTUVWXYZ`;
|
|
7
|
+
const buildIdGenerator = (size, includingUppercase = true) => customAlphabet(includingUppercase ? alphabet : lowercaseAlphabet, size);
|
|
8
|
+
/**
|
|
9
|
+
* Generate a standard id with 21 characters, including lowercase letters and numbers.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link lowercaseAlphabet}
|
|
12
|
+
*/
|
|
13
|
+
export const generateStandardId = buildIdGenerator(21, false);
|
|
14
|
+
/**
|
|
15
|
+
* Generate a standard short id with 12 characters, including lowercase letters and numbers.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link lowercaseAlphabet}
|
|
18
|
+
*/
|
|
19
|
+
export const generateStandardShortId = buildIdGenerator(12, false);
|
|
20
|
+
/**
|
|
21
|
+
* Generate a standard secret with 32 characters, including uppercase letters, lowercase
|
|
22
|
+
* letters, and numbers.
|
|
23
|
+
*
|
|
24
|
+
* @see {@link alphabet}
|
|
25
|
+
*/
|
|
26
|
+
export const generateStandardSecret = buildIdGenerator(32);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GeneratedSchema } from './../foundations/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The organization resource scopes (permissions) assigned to an application's consent request. This is different from the application_user_consent_resource_scopes table, scopes in this table is granted by the organization roles.
|
|
4
|
+
*
|
|
5
|
+
* @remarks This is a type for database creation.
|
|
6
|
+
* @see {@link ApplicationUserConsentOrganizationResourceScope} for the original type.
|
|
7
|
+
*/
|
|
8
|
+
export type CreateApplicationUserConsentOrganizationResourceScope = {
|
|
9
|
+
tenantId?: string;
|
|
10
|
+
/** The globally unique identifier of the application. */
|
|
11
|
+
applicationId: string;
|
|
12
|
+
/** The globally unique identifier of the resource scope. */
|
|
13
|
+
scopeId: string;
|
|
14
|
+
};
|
|
15
|
+
/** The organization resource scopes (permissions) assigned to an application's consent request. This is different from the application_user_consent_resource_scopes table, scopes in this table is granted by the organization roles. */
|
|
16
|
+
export type ApplicationUserConsentOrganizationResourceScope = {
|
|
17
|
+
tenantId: string;
|
|
18
|
+
/** The globally unique identifier of the application. */
|
|
19
|
+
applicationId: string;
|
|
20
|
+
/** The globally unique identifier of the resource scope. */
|
|
21
|
+
scopeId: string;
|
|
22
|
+
};
|
|
23
|
+
export type ApplicationUserConsentOrganizationResourceScopeKeys = 'tenantId' | 'applicationId' | 'scopeId';
|
|
24
|
+
export declare const ApplicationUserConsentOrganizationResourceScopes: GeneratedSchema<ApplicationUserConsentOrganizationResourceScopeKeys, CreateApplicationUserConsentOrganizationResourceScope, ApplicationUserConsentOrganizationResourceScope, 'application_user_consent_organization_resource_scopes', 'application_user_consent_organization_resource_scope'>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const createGuard = z.object({
|
|
4
|
+
tenantId: z.string().max(21).optional(),
|
|
5
|
+
applicationId: z.string().min(1).max(21),
|
|
6
|
+
scopeId: z.string().min(1).max(21),
|
|
7
|
+
});
|
|
8
|
+
const guard = z.object({
|
|
9
|
+
tenantId: z.string().max(21),
|
|
10
|
+
applicationId: z.string().min(1).max(21),
|
|
11
|
+
scopeId: z.string().min(1).max(21),
|
|
12
|
+
});
|
|
13
|
+
export const ApplicationUserConsentOrganizationResourceScopes = Object.freeze({
|
|
14
|
+
table: 'application_user_consent_organization_resource_scopes',
|
|
15
|
+
tableSingular: 'application_user_consent_organization_resource_scope',
|
|
16
|
+
fields: {
|
|
17
|
+
tenantId: 'tenant_id',
|
|
18
|
+
applicationId: 'application_id',
|
|
19
|
+
scopeId: 'scope_id',
|
|
20
|
+
},
|
|
21
|
+
fieldKeys: [
|
|
22
|
+
'tenantId',
|
|
23
|
+
'applicationId',
|
|
24
|
+
'scopeId',
|
|
25
|
+
],
|
|
26
|
+
createGuard,
|
|
27
|
+
guard,
|
|
28
|
+
updateGuard: guard.partial(),
|
|
29
|
+
});
|
|
@@ -4,6 +4,7 @@ export * from './-after-each.js';
|
|
|
4
4
|
export * from './-before-all.js';
|
|
5
5
|
export * from './-function.js';
|
|
6
6
|
export * from './application-sign-in-experience.js';
|
|
7
|
+
export * from './application-user-consent-organization-resource-scope.js';
|
|
7
8
|
export * from './application-user-consent-organization-scope.js';
|
|
8
9
|
export * from './application-user-consent-organization.js';
|
|
9
10
|
export * from './application-user-consent-resource-scope.js';
|
package/lib/db-entries/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './-after-each.js';
|
|
|
5
5
|
export * from './-before-all.js';
|
|
6
6
|
export * from './-function.js';
|
|
7
7
|
export * from './application-sign-in-experience.js';
|
|
8
|
+
export * from './application-user-consent-organization-resource-scope.js';
|
|
8
9
|
export * from './application-user-consent-organization-scope.js';
|
|
9
10
|
export * from './application-user-consent-organization.js';
|
|
10
11
|
export * from './application-user-consent-resource-scope.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneratedSchema } from './../foundations/index.js';
|
|
1
|
+
import { JsonObject, GeneratedSchema } from './../foundations/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Organizations defined by [RFC 0001](https://github.com/logto-io/rfcs/blob/HEAD/active/0001-organization.md).
|
|
4
4
|
*
|
|
@@ -13,6 +13,8 @@ export type CreateOrganization = {
|
|
|
13
13
|
name: string;
|
|
14
14
|
/** A brief description of the organization. */
|
|
15
15
|
description?: string | null;
|
|
16
|
+
/** Additional data associated with the organization. */
|
|
17
|
+
customData?: JsonObject;
|
|
16
18
|
/** When the organization was created. */
|
|
17
19
|
createdAt?: number;
|
|
18
20
|
};
|
|
@@ -25,8 +27,10 @@ export type Organization = {
|
|
|
25
27
|
name: string;
|
|
26
28
|
/** A brief description of the organization. */
|
|
27
29
|
description: string | null;
|
|
30
|
+
/** Additional data associated with the organization. */
|
|
31
|
+
customData: JsonObject;
|
|
28
32
|
/** When the organization was created. */
|
|
29
33
|
createdAt: number;
|
|
30
34
|
};
|
|
31
|
-
export type OrganizationKeys = 'tenantId' | 'id' | 'name' | 'description' | 'createdAt';
|
|
35
|
+
export type OrganizationKeys = 'tenantId' | 'id' | 'name' | 'description' | 'customData' | 'createdAt';
|
|
32
36
|
export declare const Organizations: GeneratedSchema<OrganizationKeys, CreateOrganization, Organization, 'organizations', 'organization'>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { jsonObjectGuard } from './../foundations/index.js';
|
|
3
4
|
const createGuard = z.object({
|
|
4
5
|
tenantId: z.string().max(21).optional(),
|
|
5
6
|
id: z.string().min(1).max(21),
|
|
6
7
|
name: z.string().min(1).max(128),
|
|
7
8
|
description: z.string().max(256).nullable().optional(),
|
|
9
|
+
customData: jsonObjectGuard.optional(),
|
|
8
10
|
createdAt: z.number().optional(),
|
|
9
11
|
});
|
|
10
12
|
const guard = z.object({
|
|
@@ -12,6 +14,7 @@ const guard = z.object({
|
|
|
12
14
|
id: z.string().min(1).max(21),
|
|
13
15
|
name: z.string().min(1).max(128),
|
|
14
16
|
description: z.string().max(256).nullable(),
|
|
17
|
+
customData: jsonObjectGuard,
|
|
15
18
|
createdAt: z.number(),
|
|
16
19
|
});
|
|
17
20
|
export const Organizations = Object.freeze({
|
|
@@ -22,6 +25,7 @@ export const Organizations = Object.freeze({
|
|
|
22
25
|
id: 'id',
|
|
23
26
|
name: 'name',
|
|
24
27
|
description: 'description',
|
|
28
|
+
customData: 'custom_data',
|
|
25
29
|
createdAt: 'created_at',
|
|
26
30
|
},
|
|
27
31
|
fieldKeys: [
|
|
@@ -29,6 +33,7 @@ export const Organizations = Object.freeze({
|
|
|
29
33
|
'id',
|
|
30
34
|
'name',
|
|
31
35
|
'description',
|
|
36
|
+
'customData',
|
|
32
37
|
'createdAt',
|
|
33
38
|
],
|
|
34
39
|
createGuard,
|
package/lib/db-entries/role.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export type CreateRole = {
|
|
|
11
11
|
name: string;
|
|
12
12
|
description: string;
|
|
13
13
|
type?: RoleType;
|
|
14
|
+
/** If the role is the default role for a new user. Should be ignored for `MachineToMachine` roles. */
|
|
15
|
+
isDefault?: boolean;
|
|
14
16
|
};
|
|
15
17
|
export type Role = {
|
|
16
18
|
tenantId: string;
|
|
@@ -18,6 +20,8 @@ export type Role = {
|
|
|
18
20
|
name: string;
|
|
19
21
|
description: string;
|
|
20
22
|
type: RoleType;
|
|
23
|
+
/** If the role is the default role for a new user. Should be ignored for `MachineToMachine` roles. */
|
|
24
|
+
isDefault: boolean;
|
|
21
25
|
};
|
|
22
|
-
export type RoleKeys = 'tenantId' | 'id' | 'name' | 'description' | 'type';
|
|
26
|
+
export type RoleKeys = 'tenantId' | 'id' | 'name' | 'description' | 'type' | 'isDefault';
|
|
23
27
|
export declare const Roles: GeneratedSchema<RoleKeys, CreateRole, Role, 'roles', 'role'>;
|
package/lib/db-entries/role.js
CHANGED
|
@@ -7,6 +7,7 @@ const createGuard = z.object({
|
|
|
7
7
|
name: z.string().min(1).max(128),
|
|
8
8
|
description: z.string().min(1).max(128),
|
|
9
9
|
type: z.nativeEnum(RoleType).optional(),
|
|
10
|
+
isDefault: z.boolean().optional(),
|
|
10
11
|
});
|
|
11
12
|
const guard = z.object({
|
|
12
13
|
tenantId: z.string().max(21),
|
|
@@ -14,6 +15,7 @@ const guard = z.object({
|
|
|
14
15
|
name: z.string().min(1).max(128),
|
|
15
16
|
description: z.string().min(1).max(128),
|
|
16
17
|
type: z.nativeEnum(RoleType),
|
|
18
|
+
isDefault: z.boolean(),
|
|
17
19
|
});
|
|
18
20
|
export const Roles = Object.freeze({
|
|
19
21
|
table: 'roles',
|
|
@@ -24,6 +26,7 @@ export const Roles = Object.freeze({
|
|
|
24
26
|
name: 'name',
|
|
25
27
|
description: 'description',
|
|
26
28
|
type: 'type',
|
|
29
|
+
isDefault: 'is_default',
|
|
27
30
|
},
|
|
28
31
|
fieldKeys: [
|
|
29
32
|
'tenantId',
|
|
@@ -31,6 +34,7 @@ export const Roles = Object.freeze({
|
|
|
31
34
|
'name',
|
|
32
35
|
'description',
|
|
33
36
|
'type',
|
|
37
|
+
'isDefault',
|
|
34
38
|
],
|
|
35
39
|
createGuard,
|
|
36
40
|
guard,
|
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* We categorize the hook events into two types:
|
|
4
|
+
*
|
|
5
|
+
* InteractionHookEvent: The hook events that are triggered by user interactions.
|
|
6
|
+
* DataHookEvent: The hook events that are triggered by Logto data mutations.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum InteractionHookEvent {
|
|
3
9
|
PostRegister = "PostRegister",
|
|
4
10
|
PostSignIn = "PostSignIn",
|
|
5
11
|
PostResetPassword = "PostResetPassword"
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
13
|
+
export declare enum DataHookSchema {
|
|
14
|
+
User = "User",
|
|
15
|
+
Role = "Role",
|
|
16
|
+
Scope = "Scope",
|
|
17
|
+
Organization = "Organization",
|
|
18
|
+
OrganizationRole = "OrganizationRole",
|
|
19
|
+
OrganizationScope = "OrganizationScope"
|
|
20
|
+
}
|
|
21
|
+
declare enum DataHookBasicMutationType {
|
|
22
|
+
Created = "Created",
|
|
23
|
+
Deleted = "Deleted"
|
|
24
|
+
}
|
|
25
|
+
declare enum DataHookDetailMutationType {
|
|
26
|
+
Updated = "Updated"
|
|
27
|
+
}
|
|
28
|
+
type BasicDataHookEvent = `${DataHookSchema}.${DataHookBasicMutationType}`;
|
|
29
|
+
type CustomDataHookMutableSchema = `${DataHookSchema}.Data` | `${DataHookSchema.User}.SuspensionStatus` | `${DataHookSchema.Role}.Scopes` | `${DataHookSchema.Organization}.Membership` | `${DataHookSchema.OrganizationRole}.Scopes`;
|
|
30
|
+
type DataHookPropertyUpdateEvent = `${CustomDataHookMutableSchema}.${DataHookDetailMutationType.Updated}`;
|
|
31
|
+
export type DataHookEvent = BasicDataHookEvent | DataHookPropertyUpdateEvent;
|
|
32
|
+
/** The hook event values that can be registered. */
|
|
33
|
+
export declare const hookEvents: readonly [InteractionHookEvent.PostRegister, InteractionHookEvent.PostSignIn, InteractionHookEvent.PostResetPassword, "User.Created", "User.Deleted", "User.Data.Updated", "User.SuspensionStatus.Updated", "Role.Created", "Role.Deleted", "Role.Data.Updated", "Role.Scopes.Updated", "Scope.Created", "Scope.Deleted", "Scope.Data.Updated", "Organization.Created", "Organization.Deleted", "Organization.Data.Updated", "Organization.Membership.Updated", "OrganizationRole.Created", "OrganizationRole.Deleted", "OrganizationRole.Data.Updated", "OrganizationRole.Scopes.Updated", "OrganizationScope.Created", "OrganizationScope.Deleted", "OrganizationScope.Data.Updated"];
|
|
34
|
+
/** The type of hook event values that can be registered. */
|
|
35
|
+
export type HookEvent = (typeof hookEvents)[number];
|
|
36
|
+
export declare const hookEventGuard: z.ZodEnum<[InteractionHookEvent.PostRegister, InteractionHookEvent.PostSignIn, InteractionHookEvent.PostResetPassword, "User.Created", "User.Deleted", "User.Data.Updated", "User.SuspensionStatus.Updated", "Role.Created", "Role.Deleted", "Role.Data.Updated", "Role.Scopes.Updated", "Scope.Created", "Scope.Deleted", "Scope.Data.Updated", "Organization.Created", "Organization.Deleted", "Organization.Data.Updated", "Organization.Membership.Updated", "OrganizationRole.Created", "OrganizationRole.Deleted", "OrganizationRole.Data.Updated", "OrganizationRole.Scopes.Updated", "OrganizationScope.Created", "OrganizationScope.Deleted", "OrganizationScope.Data.Updated"]>;
|
|
37
|
+
export declare const hookEventsGuard: z.ZodArray<z.ZodEnum<[InteractionHookEvent.PostRegister, InteractionHookEvent.PostSignIn, InteractionHookEvent.PostResetPassword, "User.Created", "User.Deleted", "User.Data.Updated", "User.SuspensionStatus.Updated", "Role.Created", "Role.Deleted", "Role.Data.Updated", "Role.Scopes.Updated", "Scope.Created", "Scope.Deleted", "Scope.Data.Updated", "Organization.Created", "Organization.Deleted", "Organization.Data.Updated", "Organization.Membership.Updated", "OrganizationRole.Created", "OrganizationRole.Deleted", "OrganizationRole.Data.Updated", "OrganizationRole.Scopes.Updated", "OrganizationScope.Created", "OrganizationScope.Deleted", "OrganizationScope.Data.Updated"]>, "many">;
|
|
9
38
|
export type HookEvents = z.infer<typeof hookEventsGuard>;
|
|
39
|
+
export declare const interactionHookEventGuard: z.ZodNativeEnum<typeof InteractionHookEvent>;
|
|
40
|
+
/**
|
|
41
|
+
* Hook configuration for web hook.
|
|
42
|
+
*/
|
|
10
43
|
export declare const hookConfigGuard: z.ZodObject<{
|
|
11
44
|
/** We don't need `type` since v1 only has web hook */
|
|
12
45
|
/** Method fixed to `POST` */
|
|
@@ -30,3 +63,40 @@ export declare const hookConfigGuard: z.ZodObject<{
|
|
|
30
63
|
retries?: number | undefined;
|
|
31
64
|
}>;
|
|
32
65
|
export type HookConfig = z.infer<typeof hookConfigGuard>;
|
|
66
|
+
/**
|
|
67
|
+
* Management API hooks registration.
|
|
68
|
+
* Define the hook event that should be triggered when the management API is called.
|
|
69
|
+
*/
|
|
70
|
+
export declare const managementApiHooksRegistration: Readonly<{
|
|
71
|
+
'POST /users': "User.Created";
|
|
72
|
+
'DELETE /users/:userId': "User.Deleted";
|
|
73
|
+
'PATCH /users/:userId': "User.Data.Updated";
|
|
74
|
+
'PATCH /users/:userId/custom-data': "User.Data.Updated";
|
|
75
|
+
'PATCH /users/:userId/profile': "User.Data.Updated";
|
|
76
|
+
'PATCH /users/:userId/password': "User.Data.Updated";
|
|
77
|
+
'PATCH /users/:userId/is-suspended': "User.SuspensionStatus.Updated";
|
|
78
|
+
'POST /roles': "Role.Created";
|
|
79
|
+
'DELETE /roles/:id': "Role.Deleted";
|
|
80
|
+
'PATCH /roles/:id': "Role.Data.Updated";
|
|
81
|
+
'POST /roles/:id/scopes': "Role.Scopes.Updated";
|
|
82
|
+
'DELETE /roles/:id/scopes/:scopeId': "Role.Scopes.Updated";
|
|
83
|
+
'POST /resources/:resourceId/scopes': "Scope.Created";
|
|
84
|
+
'DELETE /resources/:resourceId/scopes/:scopeId': "Scope.Deleted";
|
|
85
|
+
'PATCH /resources/:resourceId/scopes/:scopeId': "Scope.Data.Updated";
|
|
86
|
+
'POST /organizations': "Organization.Created";
|
|
87
|
+
'DELETE /organizations/:id': "Organization.Deleted";
|
|
88
|
+
'PATCH /organizations/:id': "Organization.Data.Updated";
|
|
89
|
+
'PUT /organizations/:id/users': "Organization.Membership.Updated";
|
|
90
|
+
'POST /organizations/:id/users': "Organization.Membership.Updated";
|
|
91
|
+
'DELETE /organizations/:id/users/:userId': "Organization.Membership.Updated";
|
|
92
|
+
'POST /organization-roles': "OrganizationRole.Created";
|
|
93
|
+
'DELETE /organization-roles/:id': "OrganizationRole.Deleted";
|
|
94
|
+
'PATCH /organization-roles/:id': "OrganizationRole.Data.Updated";
|
|
95
|
+
'POST /organization-scopes': "OrganizationScope.Created";
|
|
96
|
+
'DELETE /organization-scopes/:id': "OrganizationScope.Deleted";
|
|
97
|
+
'PATCH /organization-scopes/:id': "OrganizationScope.Data.Updated";
|
|
98
|
+
'PUT /organization-roles/:id/scopes': "OrganizationRole.Scopes.Updated";
|
|
99
|
+
'POST /organization-roles/:id/scopes': "OrganizationRole.Scopes.Updated";
|
|
100
|
+
'DELETE /organization-roles/:id/scopes/:organizationScopeId': "OrganizationRole.Scopes.Updated";
|
|
101
|
+
}>;
|
|
102
|
+
export {};
|
|
@@ -1,12 +1,70 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
/**
|
|
3
|
+
* We categorize the hook events into two types:
|
|
4
|
+
*
|
|
5
|
+
* InteractionHookEvent: The hook events that are triggered by user interactions.
|
|
6
|
+
* DataHookEvent: The hook events that are triggered by Logto data mutations.
|
|
7
|
+
*/
|
|
8
|
+
// InteractionHookEvent
|
|
9
|
+
export var InteractionHookEvent;
|
|
10
|
+
(function (InteractionHookEvent) {
|
|
11
|
+
InteractionHookEvent["PostRegister"] = "PostRegister";
|
|
12
|
+
InteractionHookEvent["PostSignIn"] = "PostSignIn";
|
|
13
|
+
InteractionHookEvent["PostResetPassword"] = "PostResetPassword";
|
|
14
|
+
})(InteractionHookEvent || (InteractionHookEvent = {}));
|
|
15
|
+
// DataHookEvent
|
|
16
|
+
export var DataHookSchema;
|
|
17
|
+
(function (DataHookSchema) {
|
|
18
|
+
DataHookSchema["User"] = "User";
|
|
19
|
+
DataHookSchema["Role"] = "Role";
|
|
20
|
+
DataHookSchema["Scope"] = "Scope";
|
|
21
|
+
DataHookSchema["Organization"] = "Organization";
|
|
22
|
+
DataHookSchema["OrganizationRole"] = "OrganizationRole";
|
|
23
|
+
DataHookSchema["OrganizationScope"] = "OrganizationScope";
|
|
24
|
+
})(DataHookSchema || (DataHookSchema = {}));
|
|
25
|
+
var DataHookBasicMutationType;
|
|
26
|
+
(function (DataHookBasicMutationType) {
|
|
27
|
+
DataHookBasicMutationType["Created"] = "Created";
|
|
28
|
+
DataHookBasicMutationType["Deleted"] = "Deleted";
|
|
29
|
+
})(DataHookBasicMutationType || (DataHookBasicMutationType = {}));
|
|
30
|
+
var DataHookDetailMutationType;
|
|
31
|
+
(function (DataHookDetailMutationType) {
|
|
32
|
+
DataHookDetailMutationType["Updated"] = "Updated";
|
|
33
|
+
})(DataHookDetailMutationType || (DataHookDetailMutationType = {}));
|
|
34
|
+
/** The hook event values that can be registered. */
|
|
35
|
+
export const hookEvents = Object.freeze([
|
|
36
|
+
InteractionHookEvent.PostRegister,
|
|
37
|
+
InteractionHookEvent.PostSignIn,
|
|
38
|
+
InteractionHookEvent.PostResetPassword,
|
|
39
|
+
'User.Created',
|
|
40
|
+
'User.Deleted',
|
|
41
|
+
'User.Data.Updated',
|
|
42
|
+
'User.SuspensionStatus.Updated',
|
|
43
|
+
'Role.Created',
|
|
44
|
+
'Role.Deleted',
|
|
45
|
+
'Role.Data.Updated',
|
|
46
|
+
'Role.Scopes.Updated',
|
|
47
|
+
'Scope.Created',
|
|
48
|
+
'Scope.Deleted',
|
|
49
|
+
'Scope.Data.Updated',
|
|
50
|
+
'Organization.Created',
|
|
51
|
+
'Organization.Deleted',
|
|
52
|
+
'Organization.Data.Updated',
|
|
53
|
+
'Organization.Membership.Updated',
|
|
54
|
+
'OrganizationRole.Created',
|
|
55
|
+
'OrganizationRole.Deleted',
|
|
56
|
+
'OrganizationRole.Data.Updated',
|
|
57
|
+
'OrganizationRole.Scopes.Updated',
|
|
58
|
+
'OrganizationScope.Created',
|
|
59
|
+
'OrganizationScope.Deleted',
|
|
60
|
+
'OrganizationScope.Data.Updated',
|
|
61
|
+
]);
|
|
62
|
+
export const hookEventGuard = z.enum(hookEvents);
|
|
9
63
|
export const hookEventsGuard = hookEventGuard.array();
|
|
64
|
+
export const interactionHookEventGuard = z.nativeEnum(InteractionHookEvent);
|
|
65
|
+
/**
|
|
66
|
+
* Hook configuration for web hook.
|
|
67
|
+
*/
|
|
10
68
|
export const hookConfigGuard = z.object({
|
|
11
69
|
/** We don't need `type` since v1 only has web hook */
|
|
12
70
|
// type: 'web';
|
|
@@ -22,3 +80,39 @@ export const hookConfigGuard = z.object({
|
|
|
22
80
|
*/
|
|
23
81
|
retries: z.number().gte(0).lte(3).optional(),
|
|
24
82
|
});
|
|
83
|
+
/**
|
|
84
|
+
* Management API hooks registration.
|
|
85
|
+
* Define the hook event that should be triggered when the management API is called.
|
|
86
|
+
*/
|
|
87
|
+
export const managementApiHooksRegistration = Object.freeze({
|
|
88
|
+
'POST /users': 'User.Created',
|
|
89
|
+
'DELETE /users/:userId': 'User.Deleted',
|
|
90
|
+
'PATCH /users/:userId': 'User.Data.Updated',
|
|
91
|
+
'PATCH /users/:userId/custom-data': 'User.Data.Updated',
|
|
92
|
+
'PATCH /users/:userId/profile': 'User.Data.Updated',
|
|
93
|
+
'PATCH /users/:userId/password': 'User.Data.Updated',
|
|
94
|
+
'PATCH /users/:userId/is-suspended': 'User.SuspensionStatus.Updated',
|
|
95
|
+
'POST /roles': 'Role.Created',
|
|
96
|
+
'DELETE /roles/:id': 'Role.Deleted',
|
|
97
|
+
'PATCH /roles/:id': 'Role.Data.Updated',
|
|
98
|
+
'POST /roles/:id/scopes': 'Role.Scopes.Updated',
|
|
99
|
+
'DELETE /roles/:id/scopes/:scopeId': 'Role.Scopes.Updated',
|
|
100
|
+
'POST /resources/:resourceId/scopes': 'Scope.Created',
|
|
101
|
+
'DELETE /resources/:resourceId/scopes/:scopeId': 'Scope.Deleted',
|
|
102
|
+
'PATCH /resources/:resourceId/scopes/:scopeId': 'Scope.Data.Updated',
|
|
103
|
+
'POST /organizations': 'Organization.Created',
|
|
104
|
+
'DELETE /organizations/:id': 'Organization.Deleted',
|
|
105
|
+
'PATCH /organizations/:id': 'Organization.Data.Updated',
|
|
106
|
+
'PUT /organizations/:id/users': 'Organization.Membership.Updated',
|
|
107
|
+
'POST /organizations/:id/users': 'Organization.Membership.Updated',
|
|
108
|
+
'DELETE /organizations/:id/users/:userId': 'Organization.Membership.Updated',
|
|
109
|
+
'POST /organization-roles': 'OrganizationRole.Created',
|
|
110
|
+
'DELETE /organization-roles/:id': 'OrganizationRole.Deleted',
|
|
111
|
+
'PATCH /organization-roles/:id': 'OrganizationRole.Data.Updated',
|
|
112
|
+
'POST /organization-scopes': 'OrganizationScope.Created',
|
|
113
|
+
'DELETE /organization-scopes/:id': 'OrganizationScope.Deleted',
|
|
114
|
+
'PATCH /organization-scopes/:id': 'OrganizationScope.Data.Updated',
|
|
115
|
+
'PUT /organization-roles/:id/scopes': 'OrganizationRole.Scopes.Updated',
|
|
116
|
+
'POST /organization-roles/:id/scopes': 'OrganizationRole.Scopes.Updated',
|
|
117
|
+
'DELETE /organization-roles/:id/scopes/:organizationScopeId': 'OrganizationRole.Scopes.Updated',
|
|
118
|
+
});
|
package/lib/models/tenants.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { InferModelType } from '@withtyped/server/model';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import { TenantTag } from '../types/tenant.js';
|
|
4
3
|
export declare const Tenants: import("@withtyped/server/lib/model/index.js").default<"tenants", {
|
|
5
4
|
id: string;
|
|
@@ -11,23 +10,3 @@ export declare const Tenants: import("@withtyped/server/lib/model/index.js").def
|
|
|
11
10
|
isSuspended: boolean;
|
|
12
11
|
}, "name" | "createdAt" | "isSuspended" | "tag", "createdAt">;
|
|
13
12
|
export type TenantModel = InferModelType<typeof Tenants>;
|
|
14
|
-
export declare const tenantInfoGuard: z.ZodObject<{
|
|
15
|
-
name: z.ZodType<string, z.ZodTypeDef, string>;
|
|
16
|
-
id: z.ZodType<string, z.ZodTypeDef, string>;
|
|
17
|
-
isSuspended: z.ZodType<boolean, z.ZodTypeDef, boolean>;
|
|
18
|
-
tag: z.ZodType<TenantTag, z.ZodTypeDef, TenantTag>;
|
|
19
|
-
indicator: z.ZodString;
|
|
20
|
-
}, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
21
|
-
name: string;
|
|
22
|
-
id: string;
|
|
23
|
-
indicator: string;
|
|
24
|
-
isSuspended: boolean;
|
|
25
|
-
tag: TenantTag;
|
|
26
|
-
}, {
|
|
27
|
-
name: string;
|
|
28
|
-
id: string;
|
|
29
|
-
indicator: string;
|
|
30
|
-
isSuspended: boolean;
|
|
31
|
-
tag: TenantTag;
|
|
32
|
-
}>;
|
|
33
|
-
export type TenantInfo = z.infer<typeof tenantInfoGuard>;
|
package/lib/models/tenants.js
CHANGED
|
@@ -20,6 +20,3 @@ export const Tenants = createModel(
|
|
|
20
20
|
`, 'public')
|
|
21
21
|
.extend('tag', z.nativeEnum(TenantTag))
|
|
22
22
|
.extend('createdAt', { readonly: true });
|
|
23
|
-
export const tenantInfoGuard = Tenants.guard('model')
|
|
24
|
-
.pick({ id: true, name: true, tag: true, isSuspended: true })
|
|
25
|
-
.extend({ indicator: z.string() });
|
package/lib/seeds/cloud-api.js
CHANGED
|
@@ -61,4 +61,5 @@ export const createTenantApplicationRole = () => ({
|
|
|
61
61
|
name: AdminTenantRole.TenantApplication,
|
|
62
62
|
description: 'The role for M2M applications that represent a user tenant and send requests to Logto Cloud.',
|
|
63
63
|
type: RoleType.MachineToMachine,
|
|
64
|
+
isDefault: false,
|
|
64
65
|
});
|
|
@@ -120,3 +120,7 @@ export declare const createMeApiInAdminTenant: () => Readonly<{
|
|
|
120
120
|
type: RoleType.User;
|
|
121
121
|
};
|
|
122
122
|
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Create a pre-configured M2M role for Management API access.
|
|
125
|
+
*/
|
|
126
|
+
export declare const createPreConfiguredManagementApiAccessRole: (tenantId: string) => CreateRole;
|
|
@@ -131,3 +131,13 @@ export const createMeApiInAdminTenant = () => {
|
|
|
131
131
|
},
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* Create a pre-configured M2M role for Management API access.
|
|
136
|
+
*/
|
|
137
|
+
export const createPreConfiguredManagementApiAccessRole = (tenantId) => ({
|
|
138
|
+
tenantId,
|
|
139
|
+
id: generateStandardId(),
|
|
140
|
+
description: 'This default role grants access to the Logto management API.',
|
|
141
|
+
name: 'Logto Management API access',
|
|
142
|
+
type: RoleType.MachineToMachine,
|
|
143
|
+
});
|