@logto/schemas 1.24.0 → 1.25.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.
@@ -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 email_templates (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ id varchar(21) not null,
14
+ language_tag varchar(16) not null,
15
+ template_type varchar(64) not null,
16
+ details jsonb not null,
17
+ created_at timestamptz not null default now(),
18
+ primary key (tenant_id, id),
19
+ constraint email_templates__tenant_id__language_tag__template_type
20
+ unique (tenant_id, language_tag, template_type)
21
+ );
22
+
23
+ create index email_templates__tenant_id__language_tag
24
+ on email_templates (tenant_id, language_tag);
25
+
26
+ create index email_templates__tenant_id__template_type
27
+ on email_templates (tenant_id, template_type);
28
+ `);
29
+
30
+ await applyTableRls(pool, 'email_templates');
31
+ },
32
+ down: async (pool) => {
33
+ await dropTableRls(pool, 'email_templates');
34
+ await pool.query(sql`
35
+ drop table if exists email_templates;
36
+ `);
37
+ },
38
+ };
39
+
40
+ 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 type users_password_encryption_method add value 'Legacy';
9
+ `);
10
+ },
11
+ down: async (pool) => {
12
+ const { rows } = await pool.query(sql`
13
+ select id from users
14
+ where password_encryption_method = ${'Legacy'}
15
+ `);
16
+ if (rows.length > 0) {
17
+ throw new Error('There are users with password encryption method Legacy.');
18
+ }
19
+
20
+ await pool.query(sql`
21
+ create type users_password_encryption_method_revised as enum (
22
+ 'Argon2i', 'Argon2id', 'Argon2d', 'SHA1', 'SHA256', 'MD5', 'Bcrypt'
23
+ );
24
+
25
+ alter table users
26
+ alter column password_encryption_method type users_password_encryption_method_revised
27
+ using password_encryption_method::text::users_password_encryption_method_revised;
28
+
29
+ drop type users_password_encryption_method;
30
+ alter type users_password_encryption_method_revised rename to users_password_encryption_method;
31
+ `);
32
+ },
33
+ };
34
+
35
+ export default alteration;
@@ -0,0 +1,34 @@
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 email_templates (
7
+ tenant_id varchar(21) not null
8
+ references tenants (id) on update cascade on delete cascade,
9
+ id varchar(21) not null,
10
+ language_tag varchar(16) not null,
11
+ template_type varchar(64) not null,
12
+ details jsonb not null,
13
+ created_at timestamptz not null default now(),
14
+ primary key (tenant_id, id),
15
+ constraint email_templates__tenant_id__language_tag__template_type
16
+ unique (tenant_id, language_tag, template_type)
17
+ );
18
+
19
+ create index email_templates__tenant_id__language_tag
20
+ on email_templates (tenant_id, language_tag);
21
+
22
+ create index email_templates__tenant_id__template_type
23
+ on email_templates (tenant_id, template_type);
24
+ `);
25
+ await applyTableRls(pool, 'email_templates');
26
+ },
27
+ down: async (pool) => {
28
+ await dropTableRls(pool, 'email_templates');
29
+ await pool.query(sql `
30
+ drop table if exists email_templates;
31
+ `);
32
+ },
33
+ };
34
+ export default alteration;
@@ -0,0 +1,30 @@
1
+ import { sql } from '@silverhand/slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter type users_password_encryption_method add value 'Legacy';
6
+ `);
7
+ },
8
+ down: async (pool) => {
9
+ const { rows } = await pool.query(sql `
10
+ select id from users
11
+ where password_encryption_method = ${'Legacy'}
12
+ `);
13
+ if (rows.length > 0) {
14
+ throw new Error('There are users with password encryption method Legacy.');
15
+ }
16
+ await pool.query(sql `
17
+ create type users_password_encryption_method_revised as enum (
18
+ 'Argon2i', 'Argon2id', 'Argon2d', 'SHA1', 'SHA256', 'MD5', 'Bcrypt'
19
+ );
20
+
21
+ alter table users
22
+ alter column password_encryption_method type users_password_encryption_method_revised
23
+ using password_encryption_method::text::users_password_encryption_method_revised;
24
+
25
+ drop type users_password_encryption_method;
26
+ alter type users_password_encryption_method_revised rename to users_password_encryption_method;
27
+ `);
28
+ },
29
+ };
30
+ export default alteration;
@@ -43,5 +43,6 @@ export declare enum UsersPasswordEncryptionMethod {
43
43
  SHA1 = "SHA1",
44
44
  SHA256 = "SHA256",
45
45
  MD5 = "MD5",
46
- Bcrypt = "Bcrypt"
46
+ Bcrypt = "Bcrypt",
47
+ Legacy = "Legacy"
47
48
  }
@@ -53,4 +53,5 @@ export var UsersPasswordEncryptionMethod;
53
53
  UsersPasswordEncryptionMethod["SHA256"] = "SHA256";
54
54
  UsersPasswordEncryptionMethod["MD5"] = "MD5";
55
55
  UsersPasswordEncryptionMethod["Bcrypt"] = "Bcrypt";
56
+ UsersPasswordEncryptionMethod["Legacy"] = "Legacy";
56
57
  })(UsersPasswordEncryptionMethod || (UsersPasswordEncryptionMethod = {}));
@@ -0,0 +1,24 @@
1
+ import { TemplateType, EmailTemplateDetails, GeneratedSchema } from './../foundations/index.js';
2
+ /**
3
+ *
4
+ * @remarks This is a type for database creation.
5
+ * @see {@link EmailTemplate} for the original type.
6
+ */
7
+ export type CreateEmailTemplate = {
8
+ tenantId?: string;
9
+ id: string;
10
+ languageTag: string;
11
+ templateType: TemplateType;
12
+ details: EmailTemplateDetails;
13
+ createdAt?: number;
14
+ };
15
+ export type EmailTemplate = {
16
+ tenantId: string;
17
+ id: string;
18
+ languageTag: string;
19
+ templateType: TemplateType;
20
+ details: EmailTemplateDetails;
21
+ createdAt: number;
22
+ };
23
+ export type EmailTemplateKeys = 'tenantId' | 'id' | 'languageTag' | 'templateType' | 'details' | 'createdAt';
24
+ export declare const EmailTemplates: GeneratedSchema<EmailTemplateKeys, CreateEmailTemplate, EmailTemplate, 'email_templates', 'email_template'>;
@@ -0,0 +1,42 @@
1
+ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ import { z } from 'zod';
3
+ import { templateTypeGuard, emailTemplateDetailsGuard } from './../foundations/index.js';
4
+ const createGuard = z.object({
5
+ tenantId: z.string().max(21).optional(),
6
+ id: z.string().min(1).max(21),
7
+ languageTag: z.string().min(1).max(16),
8
+ templateType: templateTypeGuard,
9
+ details: emailTemplateDetailsGuard,
10
+ createdAt: z.number().optional(),
11
+ });
12
+ const guard = z.object({
13
+ tenantId: z.string().max(21),
14
+ id: z.string().min(1).max(21),
15
+ languageTag: z.string().min(1).max(16),
16
+ templateType: templateTypeGuard,
17
+ details: emailTemplateDetailsGuard,
18
+ createdAt: z.number(),
19
+ });
20
+ export const EmailTemplates = Object.freeze({
21
+ table: 'email_templates',
22
+ tableSingular: 'email_template',
23
+ fields: {
24
+ tenantId: 'tenant_id',
25
+ id: 'id',
26
+ languageTag: 'language_tag',
27
+ templateType: 'template_type',
28
+ details: 'details',
29
+ createdAt: 'created_at',
30
+ },
31
+ fieldKeys: [
32
+ 'tenantId',
33
+ 'id',
34
+ 'languageTag',
35
+ 'templateType',
36
+ 'details',
37
+ 'createdAt',
38
+ ],
39
+ createGuard,
40
+ guard,
41
+ updateGuard: guard.partial(),
42
+ });
@@ -18,6 +18,7 @@ export * from './custom-phrase.js';
18
18
  export * from './daily-active-user.js';
19
19
  export * from './daily-token-usage.js';
20
20
  export * from './domain.js';
21
+ export * from './email-template.js';
21
22
  export * from './hook.js';
22
23
  export * from './idp-initiated-saml-sso-session.js';
23
24
  export * from './log.js';
@@ -19,6 +19,7 @@ export * from './custom-phrase.js';
19
19
  export * from './daily-active-user.js';
20
20
  export * from './daily-token-usage.js';
21
21
  export * from './domain.js';
22
+ export * from './email-template.js';
22
23
  export * from './hook.js';
23
24
  export * from './idp-initiated-saml-sso-session.js';
24
25
  export * from './log.js';
@@ -0,0 +1 @@
1
+ export { TemplateType, templateTypeGuard, type EmailTemplateDetails, emailTemplateDetailsGuard, } from '@logto/connector-kit';
@@ -0,0 +1 @@
1
+ export { TemplateType, templateTypeGuard, emailTemplateDetailsGuard, } from '@logto/connector-kit';
@@ -12,5 +12,6 @@ export * from './verification-records.js';
12
12
  export * from './account-centers.js';
13
13
  export * from './saml-application-configs.js';
14
14
  export * from './saml-application-sessions.js';
15
+ export * from './email-templates.js';
15
16
  export { configurableConnectorMetadataGuard, type ConfigurableConnectorMetadata, jsonGuard, jsonObjectGuard, } from '@logto/connector-kit';
16
17
  export type { Json, JsonObject } from '@withtyped/server';
@@ -12,4 +12,5 @@ export * from './verification-records.js';
12
12
  export * from './account-centers.js';
13
13
  export * from './saml-application-configs.js';
14
14
  export * from './saml-application-sessions.js';
15
+ export * from './email-templates.js';
15
16
  export { configurableConnectorMetadataGuard, jsonGuard, jsonObjectGuard, } from '@logto/connector-kit';
@@ -3,7 +3,7 @@ export type AuthRequestInfo = {
3
3
  issuer: string;
4
4
  request: {
5
5
  id: string;
6
- destination: string;
6
+ destination?: string;
7
7
  issueInstant: string;
8
8
  assertionConsumerServiceUrl: string;
9
9
  };
@@ -12,34 +12,34 @@ export declare const authRequestInfoGuard: z.ZodObject<{
12
12
  issuer: z.ZodString;
13
13
  request: z.ZodObject<{
14
14
  id: z.ZodString;
15
- destination: z.ZodString;
15
+ destination: z.ZodOptional<z.ZodString>;
16
16
  issueInstant: z.ZodString;
17
17
  assertionConsumerServiceUrl: z.ZodString;
18
18
  }, "strip", z.ZodTypeAny, {
19
19
  id: string;
20
- destination: string;
21
20
  issueInstant: string;
22
21
  assertionConsumerServiceUrl: string;
22
+ destination?: string | undefined;
23
23
  }, {
24
24
  id: string;
25
- destination: string;
26
25
  issueInstant: string;
27
26
  assertionConsumerServiceUrl: string;
27
+ destination?: string | undefined;
28
28
  }>;
29
29
  }, "strip", z.ZodTypeAny, {
30
30
  issuer: string;
31
31
  request: {
32
32
  id: string;
33
- destination: string;
34
33
  issueInstant: string;
35
34
  assertionConsumerServiceUrl: string;
35
+ destination?: string | undefined;
36
36
  };
37
37
  }, {
38
38
  issuer: string;
39
39
  request: {
40
40
  id: string;
41
- destination: string;
42
41
  issueInstant: string;
43
42
  assertionConsumerServiceUrl: string;
43
+ destination?: string | undefined;
44
44
  };
45
45
  }>;
@@ -3,7 +3,7 @@ export const authRequestInfoGuard = z.object({
3
3
  issuer: z.string(),
4
4
  request: z.object({
5
5
  id: z.string(),
6
- destination: z.string(),
6
+ destination: z.string().optional(),
7
7
  issueInstant: z.string(),
8
8
  assertionConsumerServiceUrl: z.string(),
9
9
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/schemas",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "author": "Silverhand Inc. <contact@silverhand.io>",
5
5
  "license": "MPL-2.0",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "@types/inquirer": "^9.0.0",
32
32
  "@types/node": "^20.9.5",
33
33
  "@types/pluralize": "^0.0.33",
34
- "@vitest/coverage-v8": "^2.1.8",
34
+ "@vitest/coverage-v8": "^2.1.9",
35
35
  "camelcase": "^8.0.0",
36
36
  "chalk": "^5.3.0",
37
37
  "eslint": "^8.56.0",
@@ -40,7 +40,7 @@
40
40
  "prettier": "^3.0.0",
41
41
  "roarr": "^7.11.0",
42
42
  "typescript": "^5.5.3",
43
- "vitest": "^2.1.8"
43
+ "vitest": "^2.1.9"
44
44
  },
45
45
  "eslintConfig": {
46
46
  "extends": "@silverhand",
@@ -63,12 +63,12 @@
63
63
  },
64
64
  "prettier": "@silverhand/eslint-config/.prettierrc",
65
65
  "dependencies": {
66
- "@logto/connector-kit": "^4.1.0",
67
- "@logto/core-kit": "^2.5.2",
68
- "@logto/language-kit": "^1.1.0",
69
- "@logto/phrases": "^1.17.0",
70
- "@logto/phrases-experience": "^1.9.0",
71
- "@logto/shared": "^3.1.2",
66
+ "@logto/connector-kit": "^4.2.0",
67
+ "@logto/core-kit": "^2.5.4",
68
+ "@logto/language-kit": "^1.1.1",
69
+ "@logto/phrases": "^1.18.0",
70
+ "@logto/phrases-experience": "^1.9.1",
71
+ "@logto/shared": "^3.1.4",
72
72
  "@withtyped/server": "^0.14.0",
73
73
  "nanoid": "^5.0.9"
74
74
  },
@@ -0,0 +1,18 @@
1
+ create table email_templates (
2
+ tenant_id varchar(21) not null
3
+ references tenants (id) on update cascade on delete cascade,
4
+ id varchar(21) not null,
5
+ language_tag varchar(16) not null,
6
+ template_type varchar(64) /* @use TemplateType */ not null,
7
+ details jsonb /* @use EmailTemplateDetails */ not null,
8
+ created_at timestamptz not null default now(),
9
+ primary key (tenant_id, id),
10
+ constraint email_templates__tenant_id__language_tag__template_type
11
+ unique (tenant_id, language_tag, template_type)
12
+ );
13
+
14
+ create index email_templates__tenant_id__language_tag
15
+ on email_templates (tenant_id, language_tag);
16
+
17
+ create index email_templates__tenant_id__template_type
18
+ on email_templates (tenant_id, template_type);
package/tables/users.sql CHANGED
@@ -1,6 +1,6 @@
1
1
  /* init_order = 1 */
2
2
 
3
- create type users_password_encryption_method as enum ('Argon2i', 'Argon2id', 'Argon2d', 'SHA1', 'SHA256', 'MD5', 'Bcrypt');
3
+ create type users_password_encryption_method as enum ('Argon2i', 'Argon2id', 'Argon2d', 'SHA1', 'SHA256', 'MD5', 'Bcrypt', 'Legacy');
4
4
 
5
5
  create table users (
6
6
  tenant_id varchar(21) not null