@logto/schemas 1.20.0 → 1.22.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.
Files changed (75) hide show
  1. package/alterations/1.21.0-1728357690-add-sso-connector-idp-initated-auth-configs-table.ts +40 -0
  2. package/alterations/1.21.0-1728526649-add-idp-initiated-saml-sso-sessions-table.ts +36 -0
  3. package/alterations/1.21.0-1728887713-add-client-idp-initiated-auth-callback-uri-columns.ts +40 -0
  4. package/alterations/1.22.0-1730689363-add-account-center.ts +31 -0
  5. package/alterations/1.22.0-1731054001-init-account-center.ts +43 -0
  6. package/alterations/1.22.0-1731304920-add-support-email-and-website-to-sie-table.ts +22 -0
  7. package/alterations/1.22.0-1731377260-add-unknown-session-redirect-url-to-sie.ts +20 -0
  8. package/alterations/1.22.0-1731900596-add-saml-application-type.ts +50 -0
  9. package/alterations/1.22.0-1731900631-add-saml-app-third-party-consistency-check.ts +20 -0
  10. package/alterations/1.22.0-1731901231-add-saml-application-secrets-table.ts +40 -0
  11. package/alterations/1.22.0-1731904029-add-saml-application-configs-table.ts +33 -0
  12. package/alterations-js/1.21.0-1728357690-add-sso-connector-idp-initated-auth-configs-table.js +35 -0
  13. package/alterations-js/1.21.0-1728526649-add-idp-initiated-saml-sso-sessions-table.js +31 -0
  14. package/alterations-js/1.21.0-1728887713-add-client-idp-initiated-auth-callback-uri-columns.js +36 -0
  15. package/alterations-js/1.22.0-1730689363-add-account-center.js +26 -0
  16. package/alterations-js/1.22.0-1731054001-init-account-center.js +35 -0
  17. package/alterations-js/1.22.0-1731304920-add-support-email-and-website-to-sie-table.js +18 -0
  18. package/alterations-js/1.22.0-1731377260-add-unknown-session-redirect-url-to-sie.js +16 -0
  19. package/alterations-js/1.22.0-1731900596-add-saml-application-type.js +46 -0
  20. package/alterations-js/1.22.0-1731900631-add-saml-app-third-party-consistency-check.js +16 -0
  21. package/alterations-js/1.22.0-1731901231-add-saml-application-secrets-table.js +35 -0
  22. package/alterations-js/1.22.0-1731904029-add-saml-application-configs-table.js +28 -0
  23. package/lib/db-entries/account-center.d.ts +24 -0
  24. package/lib/db-entries/account-center.js +34 -0
  25. package/lib/db-entries/custom-types.d.ts +2 -1
  26. package/lib/db-entries/custom-types.js +1 -0
  27. package/lib/db-entries/idp-initiated-saml-sso-session.d.ts +32 -0
  28. package/lib/db-entries/idp-initiated-saml-sso-session.js +42 -0
  29. package/lib/db-entries/index.d.ts +5 -0
  30. package/lib/db-entries/index.js +5 -0
  31. package/lib/db-entries/saml-application-config.d.ts +1 -0
  32. package/lib/db-entries/saml-application-config.js +2 -0
  33. package/lib/db-entries/saml-application-secret.d.ts +28 -0
  34. package/lib/db-entries/saml-application-secret.js +49 -0
  35. package/lib/db-entries/sign-in-experience.d.ts +7 -1
  36. package/lib/db-entries/sign-in-experience.js +12 -0
  37. package/lib/db-entries/sso-connector-idp-initiated-auth-config.d.ts +42 -0
  38. package/lib/db-entries/sso-connector-idp-initiated-auth-config.js +50 -0
  39. package/lib/foundations/jsonb-types/account-centers.d.ts +43 -0
  40. package/lib/foundations/jsonb-types/account-centers.js +25 -0
  41. package/lib/foundations/jsonb-types/index.d.ts +2 -0
  42. package/lib/foundations/jsonb-types/index.js +2 -0
  43. package/lib/foundations/jsonb-types/saml-application-configs.d.ts +21 -0
  44. package/lib/foundations/jsonb-types/saml-application-configs.js +11 -0
  45. package/lib/foundations/jsonb-types/sign-in-experience.d.ts +3 -0
  46. package/lib/foundations/jsonb-types/sign-in-experience.js +4 -0
  47. package/lib/foundations/jsonb-types/sso-connector.d.ts +49 -0
  48. package/lib/foundations/jsonb-types/sso-connector.js +17 -0
  49. package/lib/seeds/account-center.d.ts +2 -0
  50. package/lib/seeds/account-center.js +6 -0
  51. package/lib/seeds/index.d.ts +1 -0
  52. package/lib/seeds/index.js +1 -0
  53. package/lib/types/application.d.ts +6 -6
  54. package/lib/types/consent.d.ts +10 -10
  55. package/lib/types/hook.d.ts +2 -2
  56. package/lib/types/interactions.d.ts +17 -3
  57. package/lib/types/interactions.js +5 -1
  58. package/lib/types/log/interaction.d.ts +1 -1
  59. package/lib/types/logto-config/index.d.ts +9 -9
  60. package/lib/types/logto-config/jwt-customizer.d.ts +17 -17
  61. package/lib/types/sign-in-experience.d.ts +10 -1
  62. package/lib/types/sso-connector.d.ts +3 -0
  63. package/lib/types/sso-connector.js +4 -0
  64. package/lib/types/system.d.ts +20 -3
  65. package/lib/types/system.js +13 -0
  66. package/lib/types/user.d.ts +7 -7
  67. package/lib/utils/application.js +2 -0
  68. package/package.json +5 -5
  69. package/tables/account_centers.sql +10 -0
  70. package/tables/applications.sql +5 -2
  71. package/tables/idp_initiated_saml_sso_sessions.sql +16 -0
  72. package/tables/saml_application_configs.sql +19 -0
  73. package/tables/saml_application_secrets.sql +22 -0
  74. package/tables/sign_in_experiences.sql +3 -0
  75. package/tables/sso_connector_idp_initiated_auth_configs.sql +24 -0
@@ -0,0 +1,40 @@
1
+ import { sql } from '@silverhand/slonik';
2
+
3
+ import type { AlterationScript } from '../lib/types/alteration.js';
4
+
5
+ import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
6
+
7
+ const alteration: AlterationScript = {
8
+ up: async (pool) => {
9
+ await pool.query(sql`
10
+ create table sso_connector_idp_initiated_auth_configs (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ /** The globally unique identifier of the SSO connector. */
14
+ connector_id varchar(128) not null
15
+ references sso_connectors (id) on update cascade on delete cascade,
16
+ /** The default Logto application id. */
17
+ default_application_id varchar(21) not null
18
+ references applications (id) on update cascade on delete cascade,
19
+ /** OIDC sign-in redirect URI. */
20
+ redirect_uri text,
21
+ /** Additional OIDC auth parameters. */
22
+ auth_parameters jsonb /* @use IdpInitiatedAuthParams */ not null default '{}'::jsonb,
23
+ created_at timestamptz not null default(now()),
24
+ primary key (tenant_id, connector_id),
25
+ /** Insure the application type is Traditional. */
26
+ constraint application_type
27
+ check (check_application_type(default_application_id, 'Traditional'))
28
+ );
29
+ `);
30
+ await applyTableRls(pool, 'sso_connector_idp_initiated_auth_configs');
31
+ },
32
+ down: async (pool) => {
33
+ await dropTableRls(pool, 'sso_connector_idp_initiated_auth_configs');
34
+ await pool.query(sql`
35
+ drop table sso_connector_idp_initiated_auth_configs;
36
+ `);
37
+ },
38
+ };
39
+
40
+ export default alteration;
@@ -0,0 +1,36 @@
1
+ import { sql } from '@silverhand/slonik';
2
+
3
+ import type { AlterationScript } from '../lib/types/alteration.js';
4
+
5
+ import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
6
+
7
+ const alteration: AlterationScript = {
8
+ up: async (pool) => {
9
+ await pool.query(sql`
10
+ create table idp_initiated_saml_sso_sessions (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ /** The globally unique identifier of the assertion record. */
14
+ id varchar(21) not null,
15
+ /** The identifier of the SAML SSO connector. */
16
+ connector_id varchar(128) not null
17
+ references sso_connectors (id) on update cascade on delete cascade,
18
+ /** The SAML assertion. */
19
+ assertion_content jsonb /* @use SsoSamlAssertionContent */ not null default '{}'::jsonb,
20
+ created_at timestamptz not null default(now()),
21
+ /** The expiration time of the assertion. */
22
+ expires_at timestamptz not null,
23
+ primary key (tenant_id, id)
24
+ );
25
+ `);
26
+ await applyTableRls(pool, 'idp_initiated_saml_sso_sessions');
27
+ },
28
+ down: async (pool) => {
29
+ await dropTableRls(pool, 'idp_initiated_saml_sso_sessions');
30
+ await pool.query(sql`
31
+ drop table idp_initiated_saml_sso_sessions;
32
+ `);
33
+ },
34
+ };
35
+
36
+ export default alteration;
@@ -0,0 +1,40 @@
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 sso_connector_idp_initiated_auth_configs
9
+ add column client_idp_initiated_auth_callback_uri text;
10
+
11
+ alter table sso_connector_idp_initiated_auth_configs
12
+ add column auto_send_authorization_request boolean not null default false;
13
+
14
+ alter table sso_connector_idp_initiated_auth_configs
15
+ drop constraint application_type;
16
+
17
+ alter table sso_connector_idp_initiated_auth_configs
18
+ add constraint application_type
19
+ check (check_application_type(default_application_id, 'Traditional', 'SPA'));
20
+ `);
21
+ },
22
+ down: async (pool) => {
23
+ await pool.query(sql`
24
+ alter table sso_connector_idp_initiated_auth_configs
25
+ drop constraint application_type;
26
+
27
+ alter table sso_connector_idp_initiated_auth_configs
28
+ drop column client_idp_initiated_auth_callback_uri;
29
+
30
+ alter table sso_connector_idp_initiated_auth_configs
31
+ drop column auto_send_authorization_request;
32
+
33
+ alter table sso_connector_idp_initiated_auth_configs
34
+ add constraint application_type
35
+ check (check_application_type(default_application_id, 'Traditional'));
36
+ `);
37
+ },
38
+ };
39
+
40
+ export default alteration;
@@ -0,0 +1,31 @@
1
+ import { sql } from '@silverhand/slonik';
2
+
3
+ import type { AlterationScript } from '../lib/types/alteration.js';
4
+
5
+ import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
6
+
7
+ const alteration: AlterationScript = {
8
+ up: async (pool) => {
9
+ await pool.query(sql`
10
+ create table account_centers (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ id varchar(21) not null,
14
+ /** The whole feature can be disabled */
15
+ enabled boolean not null default false,
16
+ /** Control each fields */
17
+ fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb,
18
+ primary key (tenant_id, id)
19
+ );
20
+ `);
21
+ await applyTableRls(pool, 'account_centers');
22
+ },
23
+ down: async (pool) => {
24
+ await dropTableRls(pool, 'account_centers');
25
+ await pool.query(sql`
26
+ drop table account_centers;
27
+ `);
28
+ },
29
+ };
30
+
31
+ export default alteration;
@@ -0,0 +1,43 @@
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
+ // Process in chunks of 1000 tenants
8
+ const batchSize = 1000;
9
+ // eslint-disable-next-line @silverhand/fp/no-let
10
+ let offset = 0;
11
+
12
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
13
+ while (true) {
14
+ // eslint-disable-next-line no-await-in-loop
15
+ const tenants = await pool.any<{ id: string }>(sql`
16
+ select id from tenants
17
+ order by created_at asc, id asc
18
+ limit ${batchSize} offset ${offset};
19
+ `);
20
+
21
+ if (tenants.length === 0) {
22
+ break;
23
+ }
24
+
25
+ const values = tenants.map((tenant) => sql`(${tenant.id}, 'default')`);
26
+ // eslint-disable-next-line no-await-in-loop
27
+ await pool.query(sql`
28
+ insert into account_centers (tenant_id, id)
29
+ values ${sql.join(values, sql`, `)}
30
+ `);
31
+
32
+ // eslint-disable-next-line @silverhand/fp/no-mutation
33
+ offset += batchSize;
34
+ }
35
+ },
36
+ down: async (pool) => {
37
+ await pool.query(sql`
38
+ delete from account_centers where id = 'default';
39
+ `);
40
+ },
41
+ };
42
+
43
+ export default alteration;
@@ -0,0 +1,22 @@
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
9
+ add column support_email text,
10
+ add column support_website_url text;
11
+ `);
12
+ },
13
+ down: async (pool) => {
14
+ await pool.query(sql`
15
+ alter table sign_in_experiences
16
+ drop column support_email,
17
+ drop column support_website_url;
18
+ `);
19
+ },
20
+ };
21
+
22
+ export default alteration;
@@ -0,0 +1,20 @@
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
9
+ add column unknown_session_redirect_url text;
10
+ `);
11
+ },
12
+ down: async (pool) => {
13
+ await pool.query(sql`
14
+ alter table sign_in_experiences
15
+ drop column unknown_session_redirect_url;
16
+ `);
17
+ },
18
+ };
19
+
20
+ export default alteration;
@@ -0,0 +1,50 @@
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 type application_type add value 'SAML';
9
+ `);
10
+ },
11
+ down: async (pool) => {
12
+ await pool.query(sql`
13
+ alter table organization_application_relations drop constraint application_type;
14
+ alter table application_secrets drop constraint application_type;
15
+ alter table sso_connector_idp_initiated_auth_configs drop constraint application_type;
16
+
17
+ drop function check_application_type;
18
+
19
+ create type application_type_new as enum ('Native', 'SPA', 'Traditional', 'MachineToMachine', 'Protected');
20
+ delete from applications where "type"='SAML';
21
+ alter table applications
22
+ alter column "type" type application_type_new
23
+ using ("type"::text::application_type_new);
24
+ drop type application_type;
25
+ alter type application_type_new rename to application_type;
26
+
27
+ create function check_application_type(
28
+ application_id varchar(21),
29
+ variadic target_type application_type[]
30
+ ) returns boolean as
31
+ $$ begin
32
+ return (select type from applications where id = application_id) = any(target_type);
33
+ end; $$ language plpgsql set search_path = public;
34
+
35
+ alter table organization_application_relations
36
+ add constraint application_type
37
+ check (check_application_type(application_id, 'MachineToMachine'));
38
+
39
+ alter table application_secrets
40
+ add constraint application_type
41
+ check (check_application_type(application_id, 'MachineToMachine', 'Traditional', 'Protected'));
42
+
43
+ alter table sso_connector_idp_initiated_auth_configs
44
+ add constraint application_type
45
+ check (check_application_type(default_application_id, 'Traditional', 'SPA'));
46
+ `);
47
+ },
48
+ };
49
+
50
+ export default alteration;
@@ -0,0 +1,20 @@
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 applications
9
+ add constraint check_saml_app_third_party_consistency
10
+ check (type != 'SAML' OR (type = 'SAML' AND is_third_party = true));
11
+ `);
12
+ },
13
+ down: async (pool) => {
14
+ await pool.query(sql`
15
+ alter table applications drop constraint check_saml_app_third_party_consistency;
16
+ `);
17
+ },
18
+ };
19
+
20
+ export default alteration;
@@ -0,0 +1,40 @@
1
+ import { sql } from '@silverhand/slonik';
2
+
3
+ import type { AlterationScript } from '../lib/types/alteration.js';
4
+
5
+ import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
6
+
7
+ const alteration: AlterationScript = {
8
+ up: async (pool) => {
9
+ await pool.query(sql`
10
+ create table saml_application_secrets (
11
+ id varchar(21) not null,
12
+ tenant_id varchar(21) not null
13
+ references tenants (id) on update cascade on delete cascade,
14
+ application_id varchar(21) not null
15
+ references applications (id) on update cascade on delete cascade,
16
+ private_key text not null,
17
+ certificate text not null,
18
+ created_at timestamptz not null default now(),
19
+ expires_at timestamptz not null,
20
+ active boolean not null,
21
+ primary key (tenant_id, application_id, id),
22
+ constraint application_type
23
+ check (check_application_type(application_id, 'SAML'))
24
+ );
25
+
26
+ create unique index saml_application_secrets__unique_active_secret
27
+ on saml_application_secrets (tenant_id, application_id, active)
28
+ where active;
29
+ `);
30
+ await applyTableRls(pool, 'saml_application_secrets');
31
+ },
32
+ down: async (pool) => {
33
+ await dropTableRls(pool, 'saml_application_secrets');
34
+ await pool.query(sql`
35
+ drop table saml_application_secrets;
36
+ `);
37
+ },
38
+ };
39
+
40
+ export default alteration;
@@ -0,0 +1,33 @@
1
+ import { sql } from '@silverhand/slonik';
2
+
3
+ import type { AlterationScript } from '../lib/types/alteration.js';
4
+
5
+ import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
6
+
7
+ const alteration: AlterationScript = {
8
+ up: async (pool) => {
9
+ await pool.query(sql`
10
+ create table saml_application_configs (
11
+ application_id varchar(21) not null
12
+ references applications (id) on update cascade on delete cascade,
13
+ tenant_id varchar(21) not null
14
+ references tenants (id) on update cascade on delete cascade,
15
+ attribute_mapping jsonb /* @use SamlAttributeMapping */ not null default '{}'::jsonb,
16
+ entity_id varchar(128),
17
+ acs_url jsonb /* @use SamlAcsUrl */,
18
+ primary key (tenant_id, application_id),
19
+ constraint application_type
20
+ check (check_application_type(application_id, 'SAML'))
21
+ );
22
+ `);
23
+ await applyTableRls(pool, 'saml_application_configs');
24
+ },
25
+ down: async (pool) => {
26
+ await dropTableRls(pool, 'saml_application_configs');
27
+ await pool.query(sql`
28
+ drop table saml_application_configs;
29
+ `);
30
+ },
31
+ };
32
+
33
+ export default alteration;
@@ -0,0 +1,35 @@
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 sso_connector_idp_initiated_auth_configs (
7
+ tenant_id varchar(21) not null
8
+ references tenants (id) on update cascade on delete cascade,
9
+ /** The globally unique identifier of the SSO connector. */
10
+ connector_id varchar(128) not null
11
+ references sso_connectors (id) on update cascade on delete cascade,
12
+ /** The default Logto application id. */
13
+ default_application_id varchar(21) not null
14
+ references applications (id) on update cascade on delete cascade,
15
+ /** OIDC sign-in redirect URI. */
16
+ redirect_uri text,
17
+ /** Additional OIDC auth parameters. */
18
+ auth_parameters jsonb /* @use IdpInitiatedAuthParams */ not null default '{}'::jsonb,
19
+ created_at timestamptz not null default(now()),
20
+ primary key (tenant_id, connector_id),
21
+ /** Insure the application type is Traditional. */
22
+ constraint application_type
23
+ check (check_application_type(default_application_id, 'Traditional'))
24
+ );
25
+ `);
26
+ await applyTableRls(pool, 'sso_connector_idp_initiated_auth_configs');
27
+ },
28
+ down: async (pool) => {
29
+ await dropTableRls(pool, 'sso_connector_idp_initiated_auth_configs');
30
+ await pool.query(sql `
31
+ drop table sso_connector_idp_initiated_auth_configs;
32
+ `);
33
+ },
34
+ };
35
+ 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 idp_initiated_saml_sso_sessions (
7
+ tenant_id varchar(21) not null
8
+ references tenants (id) on update cascade on delete cascade,
9
+ /** The globally unique identifier of the assertion record. */
10
+ id varchar(21) not null,
11
+ /** The identifier of the SAML SSO connector. */
12
+ connector_id varchar(128) not null
13
+ references sso_connectors (id) on update cascade on delete cascade,
14
+ /** The SAML assertion. */
15
+ assertion_content jsonb /* @use SsoSamlAssertionContent */ not null default '{}'::jsonb,
16
+ created_at timestamptz not null default(now()),
17
+ /** The expiration time of the assertion. */
18
+ expires_at timestamptz not null,
19
+ primary key (tenant_id, id)
20
+ );
21
+ `);
22
+ await applyTableRls(pool, 'idp_initiated_saml_sso_sessions');
23
+ },
24
+ down: async (pool) => {
25
+ await dropTableRls(pool, 'idp_initiated_saml_sso_sessions');
26
+ await pool.query(sql `
27
+ drop table idp_initiated_saml_sso_sessions;
28
+ `);
29
+ },
30
+ };
31
+ export default alteration;
@@ -0,0 +1,36 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter table sso_connector_idp_initiated_auth_configs
6
+ add column client_idp_initiated_auth_callback_uri text;
7
+
8
+ alter table sso_connector_idp_initiated_auth_configs
9
+ add column auto_send_authorization_request boolean not null default false;
10
+
11
+ alter table sso_connector_idp_initiated_auth_configs
12
+ drop constraint application_type;
13
+
14
+ alter table sso_connector_idp_initiated_auth_configs
15
+ add constraint application_type
16
+ check (check_application_type(default_application_id, 'Traditional', 'SPA'));
17
+ `);
18
+ },
19
+ down: async (pool) => {
20
+ await pool.query(sql `
21
+ alter table sso_connector_idp_initiated_auth_configs
22
+ drop constraint application_type;
23
+
24
+ alter table sso_connector_idp_initiated_auth_configs
25
+ drop column client_idp_initiated_auth_callback_uri;
26
+
27
+ alter table sso_connector_idp_initiated_auth_configs
28
+ drop column auto_send_authorization_request;
29
+
30
+ alter table sso_connector_idp_initiated_auth_configs
31
+ add constraint application_type
32
+ check (check_application_type(default_application_id, 'Traditional'));
33
+ `);
34
+ },
35
+ };
36
+ 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 account_centers (
7
+ tenant_id varchar(21) not null
8
+ references tenants (id) on update cascade on delete cascade,
9
+ id varchar(21) not null,
10
+ /** The whole feature can be disabled */
11
+ enabled boolean not null default false,
12
+ /** Control each fields */
13
+ fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb,
14
+ primary key (tenant_id, id)
15
+ );
16
+ `);
17
+ await applyTableRls(pool, 'account_centers');
18
+ },
19
+ down: async (pool) => {
20
+ await dropTableRls(pool, 'account_centers');
21
+ await pool.query(sql `
22
+ drop table account_centers;
23
+ `);
24
+ },
25
+ };
26
+ export default alteration;
@@ -0,0 +1,35 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ // Process in chunks of 1000 tenants
5
+ const batchSize = 1000;
6
+ // eslint-disable-next-line @silverhand/fp/no-let
7
+ let offset = 0;
8
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
9
+ while (true) {
10
+ // eslint-disable-next-line no-await-in-loop
11
+ const tenants = await pool.any(sql `
12
+ select id from tenants
13
+ order by created_at asc, id asc
14
+ limit ${batchSize} offset ${offset};
15
+ `);
16
+ if (tenants.length === 0) {
17
+ break;
18
+ }
19
+ const values = tenants.map((tenant) => sql `(${tenant.id}, 'default')`);
20
+ // eslint-disable-next-line no-await-in-loop
21
+ await pool.query(sql `
22
+ insert into account_centers (tenant_id, id)
23
+ values ${sql.join(values, sql `, `)}
24
+ `);
25
+ // eslint-disable-next-line @silverhand/fp/no-mutation
26
+ offset += batchSize;
27
+ }
28
+ },
29
+ down: async (pool) => {
30
+ await pool.query(sql `
31
+ delete from account_centers where id = 'default';
32
+ `);
33
+ },
34
+ };
35
+ export default alteration;
@@ -0,0 +1,18 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter table sign_in_experiences
6
+ add column support_email text,
7
+ add column support_website_url text;
8
+ `);
9
+ },
10
+ down: async (pool) => {
11
+ await pool.query(sql `
12
+ alter table sign_in_experiences
13
+ drop column support_email,
14
+ drop column support_website_url;
15
+ `);
16
+ },
17
+ };
18
+ export default alteration;
@@ -0,0 +1,16 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter table sign_in_experiences
6
+ add column unknown_session_redirect_url text;
7
+ `);
8
+ },
9
+ down: async (pool) => {
10
+ await pool.query(sql `
11
+ alter table sign_in_experiences
12
+ drop column unknown_session_redirect_url;
13
+ `);
14
+ },
15
+ };
16
+ export default alteration;
@@ -0,0 +1,46 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter type application_type add value 'SAML';
6
+ `);
7
+ },
8
+ down: async (pool) => {
9
+ await pool.query(sql `
10
+ alter table organization_application_relations drop constraint application_type;
11
+ alter table application_secrets drop constraint application_type;
12
+ alter table sso_connector_idp_initiated_auth_configs drop constraint application_type;
13
+
14
+ drop function check_application_type;
15
+
16
+ create type application_type_new as enum ('Native', 'SPA', 'Traditional', 'MachineToMachine', 'Protected');
17
+ delete from applications where "type"='SAML';
18
+ alter table applications
19
+ alter column "type" type application_type_new
20
+ using ("type"::text::application_type_new);
21
+ drop type application_type;
22
+ alter type application_type_new rename to application_type;
23
+
24
+ create function check_application_type(
25
+ application_id varchar(21),
26
+ variadic target_type application_type[]
27
+ ) returns boolean as
28
+ $$ begin
29
+ return (select type from applications where id = application_id) = any(target_type);
30
+ end; $$ language plpgsql set search_path = public;
31
+
32
+ alter table organization_application_relations
33
+ add constraint application_type
34
+ check (check_application_type(application_id, 'MachineToMachine'));
35
+
36
+ alter table application_secrets
37
+ add constraint application_type
38
+ check (check_application_type(application_id, 'MachineToMachine', 'Traditional', 'Protected'));
39
+
40
+ alter table sso_connector_idp_initiated_auth_configs
41
+ add constraint application_type
42
+ check (check_application_type(default_application_id, 'Traditional', 'SPA'));
43
+ `);
44
+ },
45
+ };
46
+ export default alteration;
@@ -0,0 +1,16 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter table applications
6
+ add constraint check_saml_app_third_party_consistency
7
+ check (type != 'SAML' OR (type = 'SAML' AND is_third_party = true));
8
+ `);
9
+ },
10
+ down: async (pool) => {
11
+ await pool.query(sql `
12
+ alter table applications drop constraint check_saml_app_third_party_consistency;
13
+ `);
14
+ },
15
+ };
16
+ export default alteration;