@logto/schemas 1.17.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.
Files changed (105) hide show
  1. package/alterations/1.18.0-1717567857-social-sign-in-linking.ts +18 -0
  2. package/alterations/1.18.0-1717597875-add-organization-email-domains-table.ts +31 -0
  3. package/alterations/1.18.0-1717818597-organization-mfa-requirement.ts +18 -0
  4. package/alterations/1.18.0-1718340884-rename-org-email-domains-and-add-jit-roles-table.ts +56 -0
  5. package/alterations/1.18.0-1718594164-add-agree-to-terms-policy.ts +40 -0
  6. package/alterations/1.18.0-1718785576-organization-application-relations.ts +37 -0
  7. package/alterations/1.18.0-1718786576-organization-jit-sso-connectors.ts +31 -0
  8. package/alterations/1.18.0-1718807616-organization-role-application-relations.ts +34 -0
  9. package/alterations/1.18.0-1718865814-add-subject-tokens.ts +36 -0
  10. package/alterations/1.18.0-1719014832-organization-role-types.ts +35 -0
  11. package/alterations/1.18.0-1719221205-fix-functions.ts +25 -0
  12. package/alterations/1.18.0-1719312694-custom-ui-assets.ts +18 -0
  13. package/alterations-js/1.18.0-1717567857-social-sign-in-linking.d.ts +3 -0
  14. package/alterations-js/1.18.0-1717567857-social-sign-in-linking.js +14 -0
  15. package/alterations-js/1.18.0-1717597875-add-organization-email-domains-table.d.ts +3 -0
  16. package/alterations-js/1.18.0-1717597875-add-organization-email-domains-table.js +26 -0
  17. package/alterations-js/1.18.0-1717818597-organization-mfa-requirement.d.ts +3 -0
  18. package/alterations-js/1.18.0-1717818597-organization-mfa-requirement.js +14 -0
  19. package/alterations-js/1.18.0-1718340884-rename-org-email-domains-and-add-jit-roles-table.d.ts +3 -0
  20. package/alterations-js/1.18.0-1718340884-rename-org-email-domains-and-add-jit-roles-table.js +51 -0
  21. package/alterations-js/1.18.0-1718594164-add-agree-to-terms-policy.d.ts +3 -0
  22. package/alterations-js/1.18.0-1718594164-add-agree-to-terms-policy.js +34 -0
  23. package/alterations-js/1.18.0-1718785576-organization-application-relations.d.ts +3 -0
  24. package/alterations-js/1.18.0-1718785576-organization-application-relations.js +32 -0
  25. package/alterations-js/1.18.0-1718786576-organization-jit-sso-connectors.d.ts +3 -0
  26. package/alterations-js/1.18.0-1718786576-organization-jit-sso-connectors.js +26 -0
  27. package/alterations-js/1.18.0-1718807616-organization-role-application-relations.d.ts +3 -0
  28. package/alterations-js/1.18.0-1718807616-organization-role-application-relations.js +29 -0
  29. package/alterations-js/1.18.0-1718865814-add-subject-tokens.d.ts +3 -0
  30. package/alterations-js/1.18.0-1718865814-add-subject-tokens.js +31 -0
  31. package/alterations-js/1.18.0-1719014832-organization-role-types.d.ts +3 -0
  32. package/alterations-js/1.18.0-1719014832-organization-role-types.js +31 -0
  33. package/alterations-js/1.18.0-1719221205-fix-functions.d.ts +7 -0
  34. package/alterations-js/1.18.0-1719221205-fix-functions.js +20 -0
  35. package/alterations-js/1.18.0-1719312694-custom-ui-assets.d.ts +3 -0
  36. package/alterations-js/1.18.0-1719312694-custom-ui-assets.js +14 -0
  37. package/lib/consts/subscriptions.d.ts +9 -6
  38. package/lib/consts/subscriptions.js +8 -5
  39. package/lib/db-entries/custom-types.d.ts +5 -0
  40. package/lib/db-entries/custom-types.js +6 -0
  41. package/lib/db-entries/index.d.ts +6 -0
  42. package/lib/db-entries/index.js +6 -0
  43. package/lib/db-entries/organization-application-relation.d.ts +20 -0
  44. package/lib/db-entries/organization-application-relation.js +29 -0
  45. package/lib/db-entries/organization-jit-email-domain.d.ts +24 -0
  46. package/lib/db-entries/organization-jit-email-domain.js +29 -0
  47. package/lib/db-entries/organization-jit-role.d.ts +24 -0
  48. package/lib/db-entries/organization-jit-role.js +29 -0
  49. package/lib/db-entries/organization-jit-sso-connector.d.ts +22 -0
  50. package/lib/db-entries/organization-jit-sso-connector.js +29 -0
  51. package/lib/db-entries/organization-role-application-relation.d.ts +22 -0
  52. package/lib/db-entries/organization-role-application-relation.js +33 -0
  53. package/lib/db-entries/organization-role.d.ts +6 -1
  54. package/lib/db-entries/organization-role.js +5 -0
  55. package/lib/db-entries/organization.d.ts +5 -1
  56. package/lib/db-entries/organization.js +4 -0
  57. package/lib/db-entries/sign-in-experience.d.ts +11 -3
  58. package/lib/db-entries/sign-in-experience.js +14 -2
  59. package/lib/db-entries/subject-token.d.ts +28 -0
  60. package/lib/db-entries/subject-token.js +50 -0
  61. package/lib/foundations/jsonb-types/hooks.d.ts +0 -4
  62. package/lib/foundations/jsonb-types/hooks.js +1 -4
  63. package/lib/foundations/jsonb-types/oidc-module.d.ts +33 -1
  64. package/lib/foundations/jsonb-types/oidc-module.js +2 -0
  65. package/lib/foundations/jsonb-types/sign-in-experience.d.ts +14 -0
  66. package/lib/foundations/jsonb-types/sign-in-experience.js +3 -0
  67. package/lib/seeds/sign-in-experience.js +1 -0
  68. package/lib/types/application.d.ts +7 -47
  69. package/lib/types/connector.d.ts +724 -190
  70. package/lib/types/consent.d.ts +1 -9
  71. package/lib/types/index.d.ts +2 -0
  72. package/lib/types/index.js +2 -0
  73. package/lib/types/interactions.d.ts +141 -6
  74. package/lib/types/interactions.js +62 -8
  75. package/lib/types/log/token.d.ts +2 -1
  76. package/lib/types/log/token.js +1 -0
  77. package/lib/types/logto-config/index.d.ts +10 -0
  78. package/lib/types/logto-config/jwt-customizer.d.ts +174 -137
  79. package/lib/types/logto-config/jwt-customizer.js +2 -1
  80. package/lib/types/oidc-config.d.ts +2 -1
  81. package/lib/types/oidc-config.js +1 -0
  82. package/lib/types/organization.d.ts +12 -3
  83. package/lib/types/organization.js +4 -1
  84. package/lib/types/role.d.ts +6 -1
  85. package/lib/types/role.js +6 -1
  86. package/lib/types/sign-in-experience.d.ts +1064 -0
  87. package/lib/types/sign-in-experience.js +21 -0
  88. package/lib/types/subject-token.d.ts +12 -0
  89. package/lib/types/subject-token.js +5 -0
  90. package/lib/types/system.d.ts +4 -4
  91. package/lib/types/tenant-organization.d.ts +1 -0
  92. package/lib/types/tenant-organization.js +3 -0
  93. package/lib/utils/zod.d.ts +1 -1
  94. package/package.json +4 -4
  95. package/tables/applications.sql +5 -0
  96. package/tables/organization_application_relations.sql +14 -0
  97. package/tables/organization_jit_email_domains.sql +13 -0
  98. package/tables/organization_jit_roles.sql +14 -0
  99. package/tables/organization_jit_sso_connectors.sql +13 -0
  100. package/tables/organization_role_application_relations.sql +18 -0
  101. package/tables/organization_role_user_relations.sql +3 -1
  102. package/tables/organization_roles.sql +8 -1
  103. package/tables/organizations.sql +2 -0
  104. package/tables/sign_in_experiences.sql +5 -0
  105. 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 social_sign_in jsonb not null default '{}'::jsonb;
9
+ `);
10
+ },
11
+ down: async (pool) => {
12
+ await pool.query(sql`
13
+ alter table sign_in_experiences drop column social_sign_in;
14
+ `);
15
+ },
16
+ };
17
+
18
+ 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 organization_email_domains (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ /** The ID of the organization. */
14
+ organization_id varchar(21) not null
15
+ references organizations (id) on update cascade on delete cascade,
16
+ /** The email domain that will be automatically provisioned. */
17
+ email_domain varchar(128) not null,
18
+ primary key (tenant_id, organization_id, email_domain)
19
+ );
20
+ `);
21
+ await applyTableRls(pool, 'organization_email_domains');
22
+ },
23
+ down: async (pool) => {
24
+ await dropTableRls(pool, 'organization_email_domains');
25
+ await pool.query(sql`
26
+ drop table organization_email_domains
27
+ `);
28
+ },
29
+ };
30
+
31
+ export default alteration;
@@ -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 organizations add column is_mfa_required boolean not null default false;
9
+ `);
10
+ },
11
+ down: async (pool) => {
12
+ await pool.query(sql`
13
+ alter table organizations drop column is_mfa_required;
14
+ `);
15
+ },
16
+ };
17
+
18
+ export default alteration;
@@ -0,0 +1,56 @@
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
+ alter table organization_email_domains rename to organization_jit_email_domains;
11
+ alter table organization_jit_email_domains
12
+ rename constraint organization_email_domains_organization_id_fkey to organization_jit_email_domains_organization_id_fkey;
13
+ alter table organization_jit_email_domains
14
+ rename constraint organization_email_domains_pkey to organization_jit_email_domains_pkey;
15
+ alter table organization_jit_email_domains
16
+ rename constraint organization_email_domains_tenant_id_fkey to organization_jit_email_domains_tenant_id_fkey;
17
+ alter policy organization_email_domains_modification
18
+ on organization_jit_email_domains rename to organization_jit_email_domains_modification;
19
+ alter policy organization_email_domains_tenant_id
20
+ on organization_jit_email_domains rename to organization_jit_email_domains_tenant_id;
21
+ create table organization_jit_roles (
22
+ tenant_id varchar(21) not null
23
+ references tenants (id) on update cascade on delete cascade,
24
+ /** The ID of the organization. */
25
+ organization_id varchar(21) not null
26
+ references organizations (id) on update cascade on delete cascade,
27
+ /** The organization role ID that will be automatically provisioned. */
28
+ organization_role_id varchar(21) not null
29
+ references organization_roles (id) on update cascade on delete cascade,
30
+ primary key (tenant_id, organization_id, organization_role_id)
31
+ );
32
+ `);
33
+ await applyTableRls(pool, 'organization_jit_roles');
34
+ },
35
+ down: async (pool) => {
36
+ await dropTableRls(pool, 'organization_jit_roles');
37
+ await pool.query(sql`
38
+ drop table organization_jit_roles
39
+ `);
40
+ await pool.query(sql`
41
+ alter table organization_jit_email_domains rename to organization_email_domains;
42
+ alter table organization_email_domains
43
+ rename constraint organization_jit_email_domains_organization_id_fkey to organization_email_domains_organization_id_fkey;
44
+ alter table organization_email_domains
45
+ rename constraint organization_jit_email_domains_pkey to organization_email_domains_pkey;
46
+ alter table organization_email_domains
47
+ rename constraint organization_jit_email_domains_tenant_id_fkey to organization_email_domains_tenant_id_fkey;
48
+ alter policy organization_jit_email_domains_modification
49
+ on organization_email_domains rename to organization_email_domains_modification;
50
+ alter policy organization_jit_email_domains_tenant_id
51
+ on organization_email_domains rename to organization_email_domains_tenant_id;
52
+ `);
53
+ },
54
+ };
55
+
56
+ export default alteration;
@@ -0,0 +1,40 @@
1
+ import { yes } from '@silverhand/essentials';
2
+ import { sql } from '@silverhand/slonik';
3
+
4
+ import type { AlterationScript } from '../lib/types/alteration.js';
5
+
6
+ const isCi = yes(process.env.CI);
7
+
8
+ const alteration: AlterationScript = {
9
+ up: async (pool) => {
10
+ // Create type
11
+ await pool.query(sql`
12
+ create type agree_to_terms_policy as enum ('Automatic', 'ManualRegistrationOnly', 'Manual');
13
+ `);
14
+
15
+ if (isCi) {
16
+ // Direct set default to 'Automatic' to align with the sql table definition when running CI
17
+ await pool.query(sql`
18
+ alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'Automatic';
19
+ `);
20
+ } else {
21
+ // For compatibility with existing data, default to 'ManualRegistrationOnly'
22
+ await pool.query(sql`
23
+ alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'ManualRegistrationOnly';
24
+ `);
25
+
26
+ // For new data, default to 'Automatic'
27
+ await pool.query(sql`
28
+ alter table sign_in_experiences alter column agree_to_terms_policy set default 'Automatic';
29
+ `);
30
+ }
31
+ },
32
+ down: async (pool) => {
33
+ await pool.query(sql`
34
+ alter table sign_in_experiences drop column agree_to_terms_policy;
35
+ drop type agree_to_terms_policy;
36
+ `);
37
+ },
38
+ };
39
+
40
+ export default alteration;
@@ -0,0 +1,37 @@
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 function check_application_type(application_id varchar(21), target_type application_type) returns boolean as
11
+ $$ begin
12
+ return (select type from applications where id = application_id) = target_type;
13
+ end; $$ language plpgsql;
14
+ create table organization_application_relations (
15
+ tenant_id varchar(21) not null
16
+ references tenants (id) on update cascade on delete cascade,
17
+ organization_id varchar(21) not null
18
+ references organizations (id) on update cascade on delete cascade,
19
+ application_id varchar(21) not null
20
+ references applications (id) on update cascade on delete cascade,
21
+ primary key (tenant_id, organization_id, application_id),
22
+ constraint application_type
23
+ check (check_application_type(application_id, 'MachineToMachine'))
24
+ );
25
+ `);
26
+ await applyTableRls(pool, 'organization_application_relations');
27
+ },
28
+ down: async (pool) => {
29
+ await dropTableRls(pool, 'organization_application_relations');
30
+ await pool.query(sql`
31
+ drop table organization_application_relations;
32
+ drop function check_application_type;
33
+ `);
34
+ },
35
+ };
36
+
37
+ 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 organization_jit_sso_connectors (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ /** The ID of the organization. */
14
+ organization_id varchar(21) not null
15
+ references organizations (id) on update cascade on delete cascade,
16
+ sso_connector_id varchar(128) not null
17
+ references sso_connectors (id) on update cascade on delete cascade,
18
+ primary key (tenant_id, organization_id, sso_connector_id)
19
+ );
20
+ `);
21
+ await applyTableRls(pool, 'organization_jit_sso_connectors');
22
+ },
23
+ down: async (pool) => {
24
+ await dropTableRls(pool, 'organization_jit_sso_connectors');
25
+ await pool.query(sql`
26
+ drop table organization_jit_sso_connectors;
27
+ `);
28
+ },
29
+ };
30
+
31
+ export default alteration;
@@ -0,0 +1,34 @@
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 organization_role_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
+ organization_role_id varchar(21) not null
15
+ references organization_roles (id) on update cascade on delete cascade,
16
+ application_id varchar(21) not null,
17
+ primary key (tenant_id, organization_id, organization_role_id, application_id),
18
+ /** Application's roles in an organization should be synchronized with the application's membership in the organization. */
19
+ foreign key (tenant_id, organization_id, application_id)
20
+ references organization_application_relations (tenant_id, organization_id, application_id)
21
+ on update cascade on delete cascade
22
+ );
23
+ `);
24
+ await applyTableRls(pool, 'organization_role_application_relations');
25
+ },
26
+ down: async (pool) => {
27
+ await dropTableRls(pool, 'organization_role_application_relations');
28
+ await pool.query(sql`
29
+ drop table organization_role_application_relations;
30
+ `);
31
+ },
32
+ };
33
+
34
+ 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 subject_tokens (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ id varchar(25) not null,
14
+ context jsonb /* @use JsonObject */ not null default '{}'::jsonb,
15
+ expires_at timestamptz not null,
16
+ consumed_at timestamptz,
17
+ user_id varchar(21) not null
18
+ references users (id) on update cascade on delete cascade,
19
+ created_at timestamptz not null default(now()),
20
+ creator_id varchar(32) not null, /* It is intented to not reference to user or application table */
21
+ primary key (id)
22
+ );
23
+
24
+ create index subject_token__id on subject_tokens (tenant_id, id);
25
+ `);
26
+ await applyTableRls(pool, 'subject_tokens');
27
+ },
28
+ down: async (pool) => {
29
+ await dropTableRls(pool, 'subject_tokens');
30
+ await pool.query(sql`
31
+ drop table subject_tokens
32
+ `);
33
+ },
34
+ };
35
+
36
+ export default alteration;
@@ -0,0 +1,35 @@
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 organization_roles
9
+ add column type role_type not null default 'User';
10
+ create function check_organization_role_type(role_id varchar(21), target_type role_type) returns boolean as
11
+ $$ begin
12
+ return (select type from organization_roles where id = role_id) = target_type;
13
+ end; $$ language plpgsql;
14
+ alter table organization_role_user_relations
15
+ add constraint organization_role_user_relations__role_type
16
+ check (check_organization_role_type(organization_role_id, 'User'));
17
+ alter table organization_role_application_relations
18
+ add constraint organization_role_application_relations__role_type
19
+ check (check_organization_role_type(organization_role_id, 'MachineToMachine'));
20
+ `);
21
+ },
22
+ down: async (pool) => {
23
+ await pool.query(sql`
24
+ alter table organization_role_application_relations
25
+ drop constraint organization_role_application_relations__role_type;
26
+ alter table organization_role_user_relations
27
+ drop constraint organization_role_user_relations__role_type;
28
+ alter table organization_roles
29
+ drop column type;
30
+ drop function check_organization_role_type;
31
+ `);
32
+ },
33
+ };
34
+
35
+ export default alteration;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * In Logto Cloud, we have multiple schemas and the default search behavior will be problematic.
3
+ * This alteration script will fix it by setting the search path to public for the functions.
4
+ */
5
+
6
+ import { sql } from '@silverhand/slonik';
7
+
8
+ import type { AlterationScript } from '../lib/types/alteration.js';
9
+
10
+ const alteration: AlterationScript = {
11
+ up: async (pool) => {
12
+ await pool.query(sql`
13
+ alter function check_application_type set search_path = public;
14
+ alter function check_organization_role_type set search_path = public;
15
+ `);
16
+ },
17
+ down: async (pool) => {
18
+ await pool.query(sql`
19
+ alter function check_application_type reset search_path;
20
+ alter function check_organization_role_type reset search_path;
21
+ `);
22
+ },
23
+ };
24
+
25
+ export default alteration;
@@ -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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ 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,3 @@
1
+ import type { AlterationScript } from '../lib/types/alteration.js';
2
+ declare const alteration: AlterationScript;
3
+ export default alteration;