@logto/schemas 1.16.0 → 1.18.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.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/1.18.0-1717567857-social-sign-in-linking.ts +18 -0
- package/alterations/1.18.0-1717597875-add-organization-email-domains-table.ts +31 -0
- package/alterations/1.18.0-1717818597-organization-mfa-requirement.ts +18 -0
- package/alterations/1.18.0-1718340884-rename-org-email-domains-and-add-jit-roles-table.ts +56 -0
- package/alterations/1.18.0-1718594164-add-agree-to-terms-policy.ts +40 -0
- package/alterations/1.18.0-1718785576-organization-application-relations.ts +37 -0
- package/alterations/1.18.0-1718786576-organization-jit-sso-connectors.ts +31 -0
- package/alterations/1.18.0-1718807616-organization-role-application-relations.ts +34 -0
- package/alterations/1.18.0-1718865814-add-subject-tokens.ts +36 -0
- package/alterations/1.18.0-1719014832-organization-role-types.ts +35 -0
- package/alterations/1.18.0-1719221205-fix-functions.ts +25 -0
- package/alterations/1.18.0-1719312694-custom-ui-assets.ts +18 -0
- package/alterations/utils/1716643968-id-generation.ts +46 -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/1.18.0-1717567857-social-sign-in-linking.d.ts +3 -0
- package/alterations-js/1.18.0-1717567857-social-sign-in-linking.js +14 -0
- package/alterations-js/1.18.0-1717597875-add-organization-email-domains-table.d.ts +3 -0
- package/alterations-js/1.18.0-1717597875-add-organization-email-domains-table.js +26 -0
- package/alterations-js/1.18.0-1717818597-organization-mfa-requirement.d.ts +3 -0
- package/alterations-js/1.18.0-1717818597-organization-mfa-requirement.js +14 -0
- package/alterations-js/1.18.0-1718340884-rename-org-email-domains-and-add-jit-roles-table.d.ts +3 -0
- package/alterations-js/1.18.0-1718340884-rename-org-email-domains-and-add-jit-roles-table.js +51 -0
- package/alterations-js/1.18.0-1718594164-add-agree-to-terms-policy.d.ts +3 -0
- package/alterations-js/1.18.0-1718594164-add-agree-to-terms-policy.js +34 -0
- package/alterations-js/1.18.0-1718785576-organization-application-relations.d.ts +3 -0
- package/alterations-js/1.18.0-1718785576-organization-application-relations.js +32 -0
- package/alterations-js/1.18.0-1718786576-organization-jit-sso-connectors.d.ts +3 -0
- package/alterations-js/1.18.0-1718786576-organization-jit-sso-connectors.js +26 -0
- package/alterations-js/1.18.0-1718807616-organization-role-application-relations.d.ts +3 -0
- package/alterations-js/1.18.0-1718807616-organization-role-application-relations.js +29 -0
- package/alterations-js/1.18.0-1718865814-add-subject-tokens.d.ts +3 -0
- package/alterations-js/1.18.0-1718865814-add-subject-tokens.js +31 -0
- package/alterations-js/1.18.0-1719014832-organization-role-types.d.ts +3 -0
- package/alterations-js/1.18.0-1719014832-organization-role-types.js +31 -0
- package/alterations-js/1.18.0-1719221205-fix-functions.d.ts +7 -0
- package/alterations-js/1.18.0-1719221205-fix-functions.js +20 -0
- package/alterations-js/1.18.0-1719312694-custom-ui-assets.d.ts +3 -0
- package/alterations-js/1.18.0-1719312694-custom-ui-assets.js +14 -0
- package/alterations-js/utils/1716643968-id-generation.d.ts +19 -0
- package/alterations-js/utils/1716643968-id-generation.js +26 -0
- package/lib/consts/subscriptions.d.ts +9 -6
- package/lib/consts/subscriptions.js +8 -5
- package/lib/db-entries/custom-types.d.ts +5 -0
- package/lib/db-entries/custom-types.js +6 -0
- package/lib/db-entries/index.d.ts +6 -0
- package/lib/db-entries/index.js +6 -0
- package/lib/db-entries/organization-application-relation.d.ts +20 -0
- package/lib/db-entries/organization-application-relation.js +29 -0
- package/lib/db-entries/organization-jit-email-domain.d.ts +24 -0
- package/lib/db-entries/organization-jit-email-domain.js +29 -0
- package/lib/db-entries/organization-jit-role.d.ts +24 -0
- package/lib/db-entries/organization-jit-role.js +29 -0
- package/lib/db-entries/organization-jit-sso-connector.d.ts +22 -0
- package/lib/db-entries/organization-jit-sso-connector.js +29 -0
- package/lib/db-entries/organization-role-application-relation.d.ts +22 -0
- package/lib/db-entries/organization-role-application-relation.js +33 -0
- package/lib/db-entries/organization-role.d.ts +6 -1
- package/lib/db-entries/organization-role.js +5 -0
- package/lib/db-entries/organization.d.ts +5 -1
- package/lib/db-entries/organization.js +4 -0
- package/lib/db-entries/role.d.ts +5 -1
- package/lib/db-entries/role.js +4 -0
- package/lib/db-entries/sign-in-experience.d.ts +11 -3
- package/lib/db-entries/sign-in-experience.js +14 -2
- package/lib/db-entries/subject-token.d.ts +28 -0
- package/lib/db-entries/subject-token.js +50 -0
- package/lib/foundations/jsonb-types/hooks.d.ts +18 -20
- package/lib/foundations/jsonb-types/hooks.js +21 -21
- package/lib/foundations/jsonb-types/oidc-module.d.ts +33 -1
- package/lib/foundations/jsonb-types/oidc-module.js +2 -0
- package/lib/foundations/jsonb-types/sign-in-experience.d.ts +14 -0
- package/lib/foundations/jsonb-types/sign-in-experience.js +3 -0
- 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/seeds/sign-in-experience.js +1 -0
- package/lib/types/application.d.ts +7 -47
- package/lib/types/connector.d.ts +724 -190
- package/lib/types/consent.d.ts +1 -9
- package/lib/types/hook.d.ts +67 -6
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/types/interactions.d.ts +141 -6
- package/lib/types/interactions.js +62 -8
- package/lib/types/log/token.d.ts +2 -1
- package/lib/types/log/token.js +1 -0
- package/lib/types/logto-config/index.d.ts +10 -0
- package/lib/types/logto-config/jwt-customizer.d.ts +174 -137
- package/lib/types/logto-config/jwt-customizer.js +2 -1
- package/lib/types/mapi-proxy.js +1 -0
- package/lib/types/oidc-config.d.ts +2 -1
- package/lib/types/oidc-config.js +1 -0
- package/lib/types/organization.d.ts +12 -3
- package/lib/types/organization.js +4 -1
- package/lib/types/role.d.ts +6 -1
- package/lib/types/role.js +6 -1
- package/lib/types/sign-in-experience.d.ts +1064 -0
- package/lib/types/sign-in-experience.js +21 -0
- package/lib/types/subject-token.d.ts +12 -0
- package/lib/types/subject-token.js +5 -0
- package/lib/types/system.d.ts +4 -4
- package/lib/types/tenant-organization.d.ts +1 -0
- package/lib/types/tenant-organization.js +3 -0
- package/lib/types/user.d.ts +5 -1
- package/lib/types/user.js +5 -1
- package/lib/utils/role.d.ts +2 -0
- package/lib/utils/role.js +2 -0
- package/lib/utils/zod.d.ts +1 -1
- package/package.json +8 -7
- package/tables/_after_all.sql +0 -27
- package/tables/applications.sql +5 -0
- package/tables/organization_application_relations.sql +14 -0
- package/tables/organization_jit_email_domains.sql +13 -0
- package/tables/organization_jit_roles.sql +14 -0
- package/tables/organization_jit_sso_connectors.sql +13 -0
- package/tables/organization_role_application_relations.sql +18 -0
- package/tables/organization_role_user_relations.sql +3 -1
- package/tables/organization_roles.sql +8 -1
- package/tables/organizations.sql +2 -0
- package/tables/roles.sql +2 -0
- package/tables/service_logs.sql +1 -2
- package/tables/sign_in_experiences.sql +5 -0
- package/tables/subject_tokens.sql +16 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
|
|
3
|
+
import type { AlterationScript } from '../lib/types/alteration.js';
|
|
4
|
+
|
|
5
|
+
const alteration: AlterationScript = {
|
|
6
|
+
up: async (pool) => {
|
|
7
|
+
await pool.query(sql`
|
|
8
|
+
alter table sign_in_experiences add column custom_ui_asset_id varchar(21);
|
|
9
|
+
`);
|
|
10
|
+
},
|
|
11
|
+
down: async (pool) => {
|
|
12
|
+
await pool.query(sql`
|
|
13
|
+
alter table sign_in_experiences drop column custom_ui_asset_id;
|
|
14
|
+
`);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default alteration;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
|
|
6
|
+
const lowercaseAlphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
7
|
+
const alphabet = `${lowercaseAlphabet}ABCDEFGHIJKLMNOPQRSTUVWXYZ` as const;
|
|
8
|
+
|
|
9
|
+
type BuildIdGenerator = {
|
|
10
|
+
/**
|
|
11
|
+
* Build a nanoid generator function uses numbers (0-9), lowercase letters (a-z), and uppercase letters (A-Z) as the alphabet.
|
|
12
|
+
* @param size The default id length for the generator.
|
|
13
|
+
*/
|
|
14
|
+
(size: number): ReturnType<typeof customAlphabet>;
|
|
15
|
+
/**
|
|
16
|
+
* Build a nanoid generator function uses numbers (0-9) and lowercase letters (a-z) as the alphabet.
|
|
17
|
+
* @param size The default id length for the generator.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
|
20
|
+
(size: number, includingUppercase: false): ReturnType<typeof customAlphabet>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const buildIdGenerator: BuildIdGenerator = (size: number, includingUppercase = true) =>
|
|
24
|
+
customAlphabet(includingUppercase ? alphabet : lowercaseAlphabet, size);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate a standard id with 21 characters, including lowercase letters and numbers.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link lowercaseAlphabet}
|
|
30
|
+
*/
|
|
31
|
+
export const generateStandardId = buildIdGenerator(21, false);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Generate a standard short id with 12 characters, including lowercase letters and numbers.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link lowercaseAlphabet}
|
|
37
|
+
*/
|
|
38
|
+
export const generateStandardShortId = buildIdGenerator(12, false);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generate a standard secret with 32 characters, including uppercase letters, lowercase
|
|
42
|
+
* letters, and numbers.
|
|
43
|
+
*
|
|
44
|
+
* @see {@link alphabet}
|
|
45
|
+
*/
|
|
46
|
+
export const generateStandardSecret = buildIdGenerator(32);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
const alteration = {
|
|
3
|
+
up: async (pool) => {
|
|
4
|
+
await pool.query(sql `
|
|
5
|
+
alter table roles add column is_default boolean not null default false;
|
|
6
|
+
`);
|
|
7
|
+
},
|
|
8
|
+
down: async (pool) => {
|
|
9
|
+
await pool.query(sql `
|
|
10
|
+
alter table roles drop column is_default;
|
|
11
|
+
`);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default alteration;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
var DataHookSchema;
|
|
3
|
+
(function (DataHookSchema) {
|
|
4
|
+
DataHookSchema["User"] = "User";
|
|
5
|
+
DataHookSchema["Role"] = "Role";
|
|
6
|
+
DataHookSchema["Scope"] = "Scope";
|
|
7
|
+
DataHookSchema["Organization"] = "Organization";
|
|
8
|
+
DataHookSchema["OrganizationRole"] = "OrganizationRole";
|
|
9
|
+
DataHookSchema["OrganizationScope"] = "OrganizationScope";
|
|
10
|
+
})(DataHookSchema || (DataHookSchema = {}));
|
|
11
|
+
const oldSchemaUpdateEvents = Object.freeze([
|
|
12
|
+
'User.Updated',
|
|
13
|
+
'Role.Updated',
|
|
14
|
+
'Scope.Updated',
|
|
15
|
+
'Organization.Updated',
|
|
16
|
+
'OrganizationRole.Updated',
|
|
17
|
+
'OrganizationScope.Updated',
|
|
18
|
+
]);
|
|
19
|
+
const newSchemaUpdateEvents = Object.freeze([
|
|
20
|
+
'User.Data.Updated',
|
|
21
|
+
'Role.Data.Updated',
|
|
22
|
+
'Scope.Data.Updated',
|
|
23
|
+
'Organization.Data.Updated',
|
|
24
|
+
'OrganizationRole.Data.Updated',
|
|
25
|
+
'OrganizationScope.Data.Updated',
|
|
26
|
+
]);
|
|
27
|
+
const updateMap = {
|
|
28
|
+
'User.Updated': 'User.Data.Updated',
|
|
29
|
+
'Role.Updated': 'Role.Data.Updated',
|
|
30
|
+
'Scope.Updated': 'Scope.Data.Updated',
|
|
31
|
+
'Organization.Updated': 'Organization.Data.Updated',
|
|
32
|
+
'OrganizationRole.Updated': 'OrganizationRole.Data.Updated',
|
|
33
|
+
'OrganizationScope.Updated': 'OrganizationScope.Data.Updated',
|
|
34
|
+
};
|
|
35
|
+
const reverseMap = {
|
|
36
|
+
'User.Data.Updated': 'User.Updated',
|
|
37
|
+
'Role.Data.Updated': 'Role.Updated',
|
|
38
|
+
'Scope.Data.Updated': 'Scope.Updated',
|
|
39
|
+
'Organization.Data.Updated': 'Organization.Updated',
|
|
40
|
+
'OrganizationRole.Data.Updated': 'OrganizationRole.Updated',
|
|
41
|
+
'OrganizationScope.Data.Updated': 'OrganizationScope.Updated',
|
|
42
|
+
};
|
|
43
|
+
// This alteration script filters all the hook's events jsonb column to replace all the old schema update events with the new schema update events.
|
|
44
|
+
const isOldSchemaUpdateEvent = (event) =>
|
|
45
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
46
|
+
oldSchemaUpdateEvents.includes(event);
|
|
47
|
+
const isNewSchemaUpdateEvent = (event) =>
|
|
48
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
49
|
+
newSchemaUpdateEvents.includes(event);
|
|
50
|
+
const alteration = {
|
|
51
|
+
up: async (pool) => {
|
|
52
|
+
const { rows: hooks } = await pool.query(sql `
|
|
53
|
+
select id, events
|
|
54
|
+
from hooks
|
|
55
|
+
`);
|
|
56
|
+
const hooksToBeUpdate = hooks.filter(({ events }) => {
|
|
57
|
+
return oldSchemaUpdateEvents.some((oldEvent) => events.includes(oldEvent));
|
|
58
|
+
});
|
|
59
|
+
await Promise.all(hooksToBeUpdate.map(async ({ id, events }) => {
|
|
60
|
+
const updateEvents = events.reduce((accumulator, event) => {
|
|
61
|
+
if (isOldSchemaUpdateEvent(event)) {
|
|
62
|
+
return [...accumulator, updateMap[event]];
|
|
63
|
+
}
|
|
64
|
+
return [...accumulator, event];
|
|
65
|
+
}, []);
|
|
66
|
+
await pool.query(sql `
|
|
67
|
+
update hooks
|
|
68
|
+
set events = ${JSON.stringify(updateEvents)}
|
|
69
|
+
where id = ${id};
|
|
70
|
+
`);
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
down: async (pool) => {
|
|
74
|
+
const { rows: hooks } = await pool.query(sql `
|
|
75
|
+
select id, events
|
|
76
|
+
from hooks
|
|
77
|
+
`);
|
|
78
|
+
const hooksToBeUpdate = hooks.filter(({ events }) => {
|
|
79
|
+
return newSchemaUpdateEvents.some((newEvent) => events.includes(newEvent));
|
|
80
|
+
});
|
|
81
|
+
await Promise.all(hooksToBeUpdate.map(async ({ id, events }) => {
|
|
82
|
+
const updateEvents = events.reduce((accumulator, event) => {
|
|
83
|
+
if (isNewSchemaUpdateEvent(event)) {
|
|
84
|
+
return [...accumulator, reverseMap[event]];
|
|
85
|
+
}
|
|
86
|
+
return [...accumulator, event];
|
|
87
|
+
}, []);
|
|
88
|
+
await pool.query(sql `
|
|
89
|
+
update hooks
|
|
90
|
+
set events = ${JSON.stringify(updateEvents)}
|
|
91
|
+
where id = ${id};
|
|
92
|
+
`);
|
|
93
|
+
}));
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
export default alteration;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
const alteration = {
|
|
3
|
+
up: async (pool) => {
|
|
4
|
+
await pool.query(sql `
|
|
5
|
+
drop policy if exists roles_select on roles;
|
|
6
|
+
drop policy if exists roles_modification on roles;
|
|
7
|
+
create policy roles_modification on roles using (true);
|
|
8
|
+
|
|
9
|
+
drop policy if exists roles_scopes_select on roles_scopes;
|
|
10
|
+
drop policy if exists roles_scopes_modification on roles_scopes;
|
|
11
|
+
create policy roles_scopes_modification on roles_scopes using (true);
|
|
12
|
+
`);
|
|
13
|
+
},
|
|
14
|
+
down: async (pool) => {
|
|
15
|
+
await pool.query(sql `
|
|
16
|
+
create policy roles_select on roles
|
|
17
|
+
for select using (true);
|
|
18
|
+
|
|
19
|
+
drop policy roles_modification on roles;
|
|
20
|
+
create policy roles_modification on roles
|
|
21
|
+
using (not starts_with(name, '#internal:'));
|
|
22
|
+
|
|
23
|
+
-- Restrict role - scope modification
|
|
24
|
+
create policy roles_scopes_select on roles_scopes
|
|
25
|
+
for select using (true);
|
|
26
|
+
|
|
27
|
+
drop policy roles_scopes_modification on roles_scopes;
|
|
28
|
+
create policy roles_scopes_modification on roles_scopes
|
|
29
|
+
using (not starts_with((select roles.name from roles where roles.id = role_id), '#internal:'));
|
|
30
|
+
`);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export default alteration;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AlterationScript } from '../lib/types/alteration.js';
|
|
2
|
+
/**
|
|
3
|
+
* This script is to create a pre-configured Management API M2M role for new users.
|
|
4
|
+
* 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.
|
|
5
|
+
*/
|
|
6
|
+
declare const alteration: AlterationScript;
|
|
7
|
+
export default alteration;
|
|
@@ -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,14 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
const alteration = {
|
|
3
|
+
up: async (pool) => {
|
|
4
|
+
await pool.query(sql `
|
|
5
|
+
alter table sign_in_experiences add column social_sign_in jsonb not null default '{}'::jsonb;
|
|
6
|
+
`);
|
|
7
|
+
},
|
|
8
|
+
down: async (pool) => {
|
|
9
|
+
await pool.query(sql `
|
|
10
|
+
alter table sign_in_experiences drop column social_sign_in;
|
|
11
|
+
`);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default alteration;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|
3
|
+
const alteration = {
|
|
4
|
+
up: async (pool) => {
|
|
5
|
+
await pool.query(sql `
|
|
6
|
+
create table organization_email_domains (
|
|
7
|
+
tenant_id varchar(21) not null
|
|
8
|
+
references tenants (id) on update cascade on delete cascade,
|
|
9
|
+
/** The ID of the organization. */
|
|
10
|
+
organization_id varchar(21) not null
|
|
11
|
+
references organizations (id) on update cascade on delete cascade,
|
|
12
|
+
/** The email domain that will be automatically provisioned. */
|
|
13
|
+
email_domain varchar(128) not null,
|
|
14
|
+
primary key (tenant_id, organization_id, email_domain)
|
|
15
|
+
);
|
|
16
|
+
`);
|
|
17
|
+
await applyTableRls(pool, 'organization_email_domains');
|
|
18
|
+
},
|
|
19
|
+
down: async (pool) => {
|
|
20
|
+
await dropTableRls(pool, 'organization_email_domains');
|
|
21
|
+
await pool.query(sql `
|
|
22
|
+
drop table organization_email_domains
|
|
23
|
+
`);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export default alteration;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
const alteration = {
|
|
3
|
+
up: async (pool) => {
|
|
4
|
+
await pool.query(sql `
|
|
5
|
+
alter table organizations add column is_mfa_required boolean not null default false;
|
|
6
|
+
`);
|
|
7
|
+
},
|
|
8
|
+
down: async (pool) => {
|
|
9
|
+
await pool.query(sql `
|
|
10
|
+
alter table organizations drop column is_mfa_required;
|
|
11
|
+
`);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default alteration;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|
3
|
+
const alteration = {
|
|
4
|
+
up: async (pool) => {
|
|
5
|
+
await pool.query(sql `
|
|
6
|
+
alter table organization_email_domains rename to organization_jit_email_domains;
|
|
7
|
+
alter table organization_jit_email_domains
|
|
8
|
+
rename constraint organization_email_domains_organization_id_fkey to organization_jit_email_domains_organization_id_fkey;
|
|
9
|
+
alter table organization_jit_email_domains
|
|
10
|
+
rename constraint organization_email_domains_pkey to organization_jit_email_domains_pkey;
|
|
11
|
+
alter table organization_jit_email_domains
|
|
12
|
+
rename constraint organization_email_domains_tenant_id_fkey to organization_jit_email_domains_tenant_id_fkey;
|
|
13
|
+
alter policy organization_email_domains_modification
|
|
14
|
+
on organization_jit_email_domains rename to organization_jit_email_domains_modification;
|
|
15
|
+
alter policy organization_email_domains_tenant_id
|
|
16
|
+
on organization_jit_email_domains rename to organization_jit_email_domains_tenant_id;
|
|
17
|
+
create table organization_jit_roles (
|
|
18
|
+
tenant_id varchar(21) not null
|
|
19
|
+
references tenants (id) on update cascade on delete cascade,
|
|
20
|
+
/** The ID of the organization. */
|
|
21
|
+
organization_id varchar(21) not null
|
|
22
|
+
references organizations (id) on update cascade on delete cascade,
|
|
23
|
+
/** The organization role ID that will be automatically provisioned. */
|
|
24
|
+
organization_role_id varchar(21) not null
|
|
25
|
+
references organization_roles (id) on update cascade on delete cascade,
|
|
26
|
+
primary key (tenant_id, organization_id, organization_role_id)
|
|
27
|
+
);
|
|
28
|
+
`);
|
|
29
|
+
await applyTableRls(pool, 'organization_jit_roles');
|
|
30
|
+
},
|
|
31
|
+
down: async (pool) => {
|
|
32
|
+
await dropTableRls(pool, 'organization_jit_roles');
|
|
33
|
+
await pool.query(sql `
|
|
34
|
+
drop table organization_jit_roles
|
|
35
|
+
`);
|
|
36
|
+
await pool.query(sql `
|
|
37
|
+
alter table organization_jit_email_domains rename to organization_email_domains;
|
|
38
|
+
alter table organization_email_domains
|
|
39
|
+
rename constraint organization_jit_email_domains_organization_id_fkey to organization_email_domains_organization_id_fkey;
|
|
40
|
+
alter table organization_email_domains
|
|
41
|
+
rename constraint organization_jit_email_domains_pkey to organization_email_domains_pkey;
|
|
42
|
+
alter table organization_email_domains
|
|
43
|
+
rename constraint organization_jit_email_domains_tenant_id_fkey to organization_email_domains_tenant_id_fkey;
|
|
44
|
+
alter policy organization_jit_email_domains_modification
|
|
45
|
+
on organization_email_domains rename to organization_email_domains_modification;
|
|
46
|
+
alter policy organization_jit_email_domains_tenant_id
|
|
47
|
+
on organization_email_domains rename to organization_email_domains_tenant_id;
|
|
48
|
+
`);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export default alteration;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { yes } from '@silverhand/essentials';
|
|
2
|
+
import { sql } from '@silverhand/slonik';
|
|
3
|
+
const isCi = yes(process.env.CI);
|
|
4
|
+
const alteration = {
|
|
5
|
+
up: async (pool) => {
|
|
6
|
+
// Create type
|
|
7
|
+
await pool.query(sql `
|
|
8
|
+
create type agree_to_terms_policy as enum ('Automatic', 'ManualRegistrationOnly', 'Manual');
|
|
9
|
+
`);
|
|
10
|
+
if (isCi) {
|
|
11
|
+
// Direct set default to 'Automatic' to align with the sql table definition when running CI
|
|
12
|
+
await pool.query(sql `
|
|
13
|
+
alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'Automatic';
|
|
14
|
+
`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// For compatibility with existing data, default to 'ManualRegistrationOnly'
|
|
18
|
+
await pool.query(sql `
|
|
19
|
+
alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'ManualRegistrationOnly';
|
|
20
|
+
`);
|
|
21
|
+
// For new data, default to 'Automatic'
|
|
22
|
+
await pool.query(sql `
|
|
23
|
+
alter table sign_in_experiences alter column agree_to_terms_policy set default 'Automatic';
|
|
24
|
+
`);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
down: async (pool) => {
|
|
28
|
+
await pool.query(sql `
|
|
29
|
+
alter table sign_in_experiences drop column agree_to_terms_policy;
|
|
30
|
+
drop type agree_to_terms_policy;
|
|
31
|
+
`);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export default alteration;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|
3
|
+
const alteration = {
|
|
4
|
+
up: async (pool) => {
|
|
5
|
+
await pool.query(sql `
|
|
6
|
+
create function check_application_type(application_id varchar(21), target_type application_type) returns boolean as
|
|
7
|
+
$$ begin
|
|
8
|
+
return (select type from applications where id = application_id) = target_type;
|
|
9
|
+
end; $$ language plpgsql;
|
|
10
|
+
create table organization_application_relations (
|
|
11
|
+
tenant_id varchar(21) not null
|
|
12
|
+
references tenants (id) on update cascade on delete cascade,
|
|
13
|
+
organization_id varchar(21) not null
|
|
14
|
+
references organizations (id) on update cascade on delete cascade,
|
|
15
|
+
application_id varchar(21) not null
|
|
16
|
+
references applications (id) on update cascade on delete cascade,
|
|
17
|
+
primary key (tenant_id, organization_id, application_id),
|
|
18
|
+
constraint application_type
|
|
19
|
+
check (check_application_type(application_id, 'MachineToMachine'))
|
|
20
|
+
);
|
|
21
|
+
`);
|
|
22
|
+
await applyTableRls(pool, 'organization_application_relations');
|
|
23
|
+
},
|
|
24
|
+
down: async (pool) => {
|
|
25
|
+
await dropTableRls(pool, 'organization_application_relations');
|
|
26
|
+
await pool.query(sql `
|
|
27
|
+
drop table organization_application_relations;
|
|
28
|
+
drop function check_application_type;
|
|
29
|
+
`);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export default alteration;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|
3
|
+
const alteration = {
|
|
4
|
+
up: async (pool) => {
|
|
5
|
+
await pool.query(sql `
|
|
6
|
+
create table organization_jit_sso_connectors (
|
|
7
|
+
tenant_id varchar(21) not null
|
|
8
|
+
references tenants (id) on update cascade on delete cascade,
|
|
9
|
+
/** The ID of the organization. */
|
|
10
|
+
organization_id varchar(21) not null
|
|
11
|
+
references organizations (id) on update cascade on delete cascade,
|
|
12
|
+
sso_connector_id varchar(128) not null
|
|
13
|
+
references sso_connectors (id) on update cascade on delete cascade,
|
|
14
|
+
primary key (tenant_id, organization_id, sso_connector_id)
|
|
15
|
+
);
|
|
16
|
+
`);
|
|
17
|
+
await applyTableRls(pool, 'organization_jit_sso_connectors');
|
|
18
|
+
},
|
|
19
|
+
down: async (pool) => {
|
|
20
|
+
await dropTableRls(pool, 'organization_jit_sso_connectors');
|
|
21
|
+
await pool.query(sql `
|
|
22
|
+
drop table organization_jit_sso_connectors;
|
|
23
|
+
`);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export default alteration;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|
3
|
+
const alteration = {
|
|
4
|
+
up: async (pool) => {
|
|
5
|
+
await pool.query(sql `
|
|
6
|
+
create table organization_role_application_relations (
|
|
7
|
+
tenant_id varchar(21) not null
|
|
8
|
+
references tenants (id) on update cascade on delete cascade,
|
|
9
|
+
organization_id varchar(21) not null,
|
|
10
|
+
organization_role_id varchar(21) not null
|
|
11
|
+
references organization_roles (id) on update cascade on delete cascade,
|
|
12
|
+
application_id varchar(21) not null,
|
|
13
|
+
primary key (tenant_id, organization_id, organization_role_id, application_id),
|
|
14
|
+
/** Application's roles in an organization should be synchronized with the application's membership in the organization. */
|
|
15
|
+
foreign key (tenant_id, organization_id, application_id)
|
|
16
|
+
references organization_application_relations (tenant_id, organization_id, application_id)
|
|
17
|
+
on update cascade on delete cascade
|
|
18
|
+
);
|
|
19
|
+
`);
|
|
20
|
+
await applyTableRls(pool, 'organization_role_application_relations');
|
|
21
|
+
},
|
|
22
|
+
down: async (pool) => {
|
|
23
|
+
await dropTableRls(pool, 'organization_role_application_relations');
|
|
24
|
+
await pool.query(sql `
|
|
25
|
+
drop table organization_role_application_relations;
|
|
26
|
+
`);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export default alteration;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { sql } from '@silverhand/slonik';
|
|
2
|
+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|
3
|
+
const alteration = {
|
|
4
|
+
up: async (pool) => {
|
|
5
|
+
await pool.query(sql `
|
|
6
|
+
create table subject_tokens (
|
|
7
|
+
tenant_id varchar(21) not null
|
|
8
|
+
references tenants (id) on update cascade on delete cascade,
|
|
9
|
+
id varchar(25) not null,
|
|
10
|
+
context jsonb /* @use JsonObject */ not null default '{}'::jsonb,
|
|
11
|
+
expires_at timestamptz not null,
|
|
12
|
+
consumed_at timestamptz,
|
|
13
|
+
user_id varchar(21) not null
|
|
14
|
+
references users (id) on update cascade on delete cascade,
|
|
15
|
+
created_at timestamptz not null default(now()),
|
|
16
|
+
creator_id varchar(32) not null, /* It is intented to not reference to user or application table */
|
|
17
|
+
primary key (id)
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
create index subject_token__id on subject_tokens (tenant_id, id);
|
|
21
|
+
`);
|
|
22
|
+
await applyTableRls(pool, 'subject_tokens');
|
|
23
|
+
},
|
|
24
|
+
down: async (pool) => {
|
|
25
|
+
await dropTableRls(pool, 'subject_tokens');
|
|
26
|
+
await pool.query(sql `
|
|
27
|
+
drop table subject_tokens
|
|
28
|
+
`);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
export default alteration;
|