@logto/schemas 1.5.0 → 1.6.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,20 @@
1
+ import { sql } from '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 domains drop constraint domains__domain;
9
+ alter table domains add constraint domains__domain unique (tenant_id, domain);
10
+ `);
11
+ },
12
+ down: async (pool) => {
13
+ await pool.query(sql`
14
+ alter table domains drop constraint domains__domain;
15
+ alter table domains add constraint domains__domain unique (domain);
16
+ `);
17
+ },
18
+ };
19
+
20
+ 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,16 @@
1
+ import { sql } from 'slonik';
2
+ const alteration = {
3
+ up: async (pool) => {
4
+ await pool.query(sql `
5
+ alter table domains drop constraint domains__domain;
6
+ alter table domains add constraint domains__domain unique (tenant_id, domain);
7
+ `);
8
+ },
9
+ down: async (pool) => {
10
+ await pool.query(sql `
11
+ alter table domains drop constraint domains__domain;
12
+ alter table domains add constraint domains__domain unique (domain);
13
+ `);
14
+ },
15
+ };
16
+ export default alteration;
@@ -0,0 +1,5 @@
1
+ export declare const inSeconds: Readonly<{
2
+ oneMinute: 60;
3
+ oneHour: number;
4
+ oneDay: number;
5
+ }>;
@@ -0,0 +1 @@
1
+ export const inSeconds = Object.freeze({ oneMinute: 60, oneHour: 60 * 60, oneDay: 24 * 60 * 60 });
@@ -1,3 +1,4 @@
1
1
  export * from './cookie.js';
2
2
  export * from './system.js';
3
3
  export * from './oidc.js';
4
+ export * from './date.js';
@@ -1,3 +1,4 @@
1
1
  export * from './cookie.js';
2
2
  export * from './system.js';
3
3
  export * from './oidc.js';
4
+ export * from './date.js';
@@ -1 +1,6 @@
1
1
  export declare const tenantIdKey = "tenant_id";
2
+ export declare const customClientMetadataDefault: Readonly<{
3
+ readonly idTokenTtl: number;
4
+ readonly refreshTokenTtlInDays: 14;
5
+ readonly rotateRefreshToken: true;
6
+ }>;
@@ -1 +1,7 @@
1
+ import { inSeconds } from './date.js';
1
2
  export const tenantIdKey = 'tenant_id';
3
+ export const customClientMetadataDefault = Object.freeze({
4
+ idTokenTtl: inSeconds.oneHour,
5
+ refreshTokenTtlInDays: 14,
6
+ rotateRefreshToken: true,
7
+ });
@@ -1,9 +1,9 @@
1
- import { DomainDnsRecords, CloudflareData, GeneratedSchema } from './../foundations/index.js';
1
+ import { DomainStatus, DomainDnsRecords, CloudflareData, GeneratedSchema } from './../foundations/index.js';
2
2
  export type CreateDomain = {
3
3
  tenantId?: string;
4
4
  id: string;
5
5
  domain: string;
6
- status?: string;
6
+ status?: DomainStatus;
7
7
  errorMessage?: string | null;
8
8
  dnsRecords?: DomainDnsRecords;
9
9
  cloudflareData?: CloudflareData | null;
@@ -14,7 +14,7 @@ export type Domain = {
14
14
  tenantId: string;
15
15
  id: string;
16
16
  domain: string;
17
- status: string;
17
+ status: DomainStatus;
18
18
  errorMessage: string | null;
19
19
  dnsRecords: DomainDnsRecords;
20
20
  cloudflareData: CloudflareData | null;
@@ -1,11 +1,11 @@
1
1
  // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
2
  import { z } from 'zod';
3
- import { domainDnsRecordsGuard, cloudflareDataGuard } from './../foundations/index.js';
3
+ import { domainStatusGuard, domainDnsRecordsGuard, cloudflareDataGuard } from './../foundations/index.js';
4
4
  const createGuard = z.object({
5
5
  tenantId: z.string().max(21).optional(),
6
6
  id: z.string().min(1).max(21),
7
7
  domain: z.string().min(1).max(256),
8
- status: z.string().min(1).max(32).optional(),
8
+ status: domainStatusGuard.optional(),
9
9
  errorMessage: z.string().max(1024).nullable().optional(),
10
10
  dnsRecords: domainDnsRecordsGuard.optional(),
11
11
  cloudflareData: cloudflareDataGuard.nullable().optional(),
@@ -16,7 +16,7 @@ const guard = z.object({
16
16
  tenantId: z.string().max(21),
17
17
  id: z.string().min(1).max(21),
18
18
  domain: z.string().min(1).max(256),
19
- status: z.string().max(32),
19
+ status: domainStatusGuard,
20
20
  errorMessage: z.string().max(1024).nullable(),
21
21
  dnsRecords: domainDnsRecordsGuard,
22
22
  cloudflareData: cloudflareDataGuard.nullable(),
@@ -40,7 +40,9 @@ export type OidcClientMetadata = z.infer<typeof oidcClientMetadataGuard>;
40
40
  export declare enum CustomClientMetadataKey {
41
41
  CorsAllowedOrigins = "corsAllowedOrigins",
42
42
  IdTokenTtl = "idTokenTtl",
43
+ /** @deprecated Use {@link RefreshTokenTtlInDays} instead. */
43
44
  RefreshTokenTtl = "refreshTokenTtl",
45
+ RefreshTokenTtlInDays = "refreshTokenTtlInDays",
44
46
  TenantId = "tenantId",
45
47
  /**
46
48
  * Enabling this configuration will allow Logto to always issue Refresh Tokens, regardless of whether `prompt=consent` is presented in the authentication request.
@@ -49,26 +51,38 @@ export declare enum CustomClientMetadataKey {
49
51
  *
50
52
  * This config is for the third-party integrations that do not strictly follow OpenID Connect standards due to some reasons (e.g. they only know OAuth, but requires a Refresh Token to be returned anyway).
51
53
  */
52
- AlwaysIssueRefreshToken = "alwaysIssueRefreshToken"
54
+ AlwaysIssueRefreshToken = "alwaysIssueRefreshToken",
55
+ /**
56
+ * When enabled (default), Logto will issue a new Refresh Token for token requests when 70% of the original Time to Live (TTL) has passed.
57
+ *
58
+ * It can be turned off for only traditional web apps for enhanced security.
59
+ */
60
+ RotateRefreshToken = "rotateRefreshToken"
53
61
  }
54
62
  export declare const customClientMetadataGuard: z.ZodObject<{
55
63
  corsAllowedOrigins: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
56
64
  idTokenTtl: z.ZodOptional<z.ZodNumber>;
57
65
  refreshTokenTtl: z.ZodOptional<z.ZodNumber>;
66
+ refreshTokenTtlInDays: z.ZodOptional<z.ZodNumber>;
58
67
  tenantId: z.ZodOptional<z.ZodString>;
59
68
  alwaysIssueRefreshToken: z.ZodOptional<z.ZodBoolean>;
69
+ rotateRefreshToken: z.ZodOptional<z.ZodBoolean>;
60
70
  }, "strip", z.ZodTypeAny, {
61
71
  corsAllowedOrigins?: string[] | undefined;
62
72
  idTokenTtl?: number | undefined;
63
73
  refreshTokenTtl?: number | undefined;
74
+ refreshTokenTtlInDays?: number | undefined;
64
75
  tenantId?: string | undefined;
65
76
  alwaysIssueRefreshToken?: boolean | undefined;
77
+ rotateRefreshToken?: boolean | undefined;
66
78
  }, {
67
79
  corsAllowedOrigins?: string[] | undefined;
68
80
  idTokenTtl?: number | undefined;
69
81
  refreshTokenTtl?: number | undefined;
82
+ refreshTokenTtlInDays?: number | undefined;
70
83
  tenantId?: string | undefined;
71
84
  alwaysIssueRefreshToken?: boolean | undefined;
85
+ rotateRefreshToken?: boolean | undefined;
72
86
  }>;
73
87
  /**
74
88
  * @see {@link CustomClientMetadataKey} for key descriptions.
@@ -301,8 +315,6 @@ export declare const cloudflareDataGuard: z.ZodObject<{
301
315
  status: z.ZodString;
302
316
  ssl: z.ZodObject<{
303
317
  status: z.ZodString;
304
- txt_name: z.ZodOptional<z.ZodString>;
305
- txt_value: z.ZodOptional<z.ZodString>;
306
318
  validation_errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
307
319
  message: z.ZodString;
308
320
  }, "strip", z.ZodUnknown, {
@@ -314,8 +326,6 @@ export declare const cloudflareDataGuard: z.ZodObject<{
314
326
  }>, "many">>;
315
327
  }, "strip", z.ZodUnknown, {
316
328
  [x: string]: unknown;
317
- txt_name?: string | undefined;
318
- txt_value?: string | undefined;
319
329
  validation_errors?: {
320
330
  [x: string]: unknown;
321
331
  message: string;
@@ -323,45 +333,20 @@ export declare const cloudflareDataGuard: z.ZodObject<{
323
333
  status: string;
324
334
  }, {
325
335
  [x: string]: unknown;
326
- txt_name?: string | undefined;
327
- txt_value?: string | undefined;
328
336
  validation_errors?: {
329
337
  [x: string]: unknown;
330
338
  message: string;
331
339
  }[] | undefined;
332
340
  status: string;
333
341
  }>;
334
- ownership_verification: z.ZodOptional<z.ZodObject<{
335
- name: z.ZodString;
336
- type: z.ZodString;
337
- value: z.ZodString;
338
- }, "strip", z.ZodUnknown, {
339
- [x: string]: unknown;
340
- type: string;
341
- value: string;
342
- name: string;
343
- }, {
344
- [x: string]: unknown;
345
- type: string;
346
- value: string;
347
- name: string;
348
- }>>;
349
342
  verification_errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
350
343
  }, "strip", z.ZodUnknown, {
351
344
  [x: string]: unknown;
352
- ownership_verification?: {
353
- [x: string]: unknown;
354
- type: string;
355
- value: string;
356
- name: string;
357
- } | undefined;
358
345
  verification_errors?: string[] | undefined;
359
346
  status: string;
360
347
  id: string;
361
348
  ssl: {
362
349
  [x: string]: unknown;
363
- txt_name?: string | undefined;
364
- txt_value?: string | undefined;
365
350
  validation_errors?: {
366
351
  [x: string]: unknown;
367
352
  message: string;
@@ -370,19 +355,11 @@ export declare const cloudflareDataGuard: z.ZodObject<{
370
355
  };
371
356
  }, {
372
357
  [x: string]: unknown;
373
- ownership_verification?: {
374
- [x: string]: unknown;
375
- type: string;
376
- value: string;
377
- name: string;
378
- } | undefined;
379
358
  verification_errors?: string[] | undefined;
380
359
  status: string;
381
360
  id: string;
382
361
  ssl: {
383
362
  [x: string]: unknown;
384
- txt_name?: string | undefined;
385
- txt_value?: string | undefined;
386
363
  validation_errors?: {
387
364
  [x: string]: unknown;
388
365
  message: string;
@@ -391,3 +368,10 @@ export declare const cloudflareDataGuard: z.ZodObject<{
391
368
  };
392
369
  }>;
393
370
  export type CloudflareData = z.infer<typeof cloudflareDataGuard>;
371
+ export declare enum DomainStatus {
372
+ PendingVerification = "PendingVerification",
373
+ PendingSsl = "PendingSsl",
374
+ Active = "Active",
375
+ Error = "Error"
376
+ }
377
+ export declare const domainStatusGuard: z.ZodNativeEnum<typeof DomainStatus>;
@@ -45,7 +45,9 @@ export var CustomClientMetadataKey;
45
45
  (function (CustomClientMetadataKey) {
46
46
  CustomClientMetadataKey["CorsAllowedOrigins"] = "corsAllowedOrigins";
47
47
  CustomClientMetadataKey["IdTokenTtl"] = "idTokenTtl";
48
+ /** @deprecated Use {@link RefreshTokenTtlInDays} instead. */
48
49
  CustomClientMetadataKey["RefreshTokenTtl"] = "refreshTokenTtl";
50
+ CustomClientMetadataKey["RefreshTokenTtlInDays"] = "refreshTokenTtlInDays";
49
51
  CustomClientMetadataKey["TenantId"] = "tenantId";
50
52
  /**
51
53
  * Enabling this configuration will allow Logto to always issue Refresh Tokens, regardless of whether `prompt=consent` is presented in the authentication request.
@@ -55,13 +57,21 @@ export var CustomClientMetadataKey;
55
57
  * This config is for the third-party integrations that do not strictly follow OpenID Connect standards due to some reasons (e.g. they only know OAuth, but requires a Refresh Token to be returned anyway).
56
58
  */
57
59
  CustomClientMetadataKey["AlwaysIssueRefreshToken"] = "alwaysIssueRefreshToken";
60
+ /**
61
+ * When enabled (default), Logto will issue a new Refresh Token for token requests when 70% of the original Time to Live (TTL) has passed.
62
+ *
63
+ * It can be turned off for only traditional web apps for enhanced security.
64
+ */
65
+ CustomClientMetadataKey["RotateRefreshToken"] = "rotateRefreshToken";
58
66
  })(CustomClientMetadataKey || (CustomClientMetadataKey = {}));
59
67
  export const customClientMetadataGuard = z.object({
60
68
  [CustomClientMetadataKey.CorsAllowedOrigins]: z.string().url().array().optional(),
61
69
  [CustomClientMetadataKey.IdTokenTtl]: z.number().optional(),
62
70
  [CustomClientMetadataKey.RefreshTokenTtl]: z.number().optional(),
71
+ [CustomClientMetadataKey.RefreshTokenTtlInDays]: z.number().int().min(1).max(90).optional(),
63
72
  [CustomClientMetadataKey.TenantId]: z.string().optional(),
64
73
  [CustomClientMetadataKey.AlwaysIssueRefreshToken]: z.boolean().optional(),
74
+ [CustomClientMetadataKey.RotateRefreshToken]: z.boolean().optional(),
65
75
  });
66
76
  /* === Users === */
67
77
  export const roleNamesGuard = z.string().array();
@@ -166,8 +176,6 @@ export const cloudflareDataGuard = z
166
176
  ssl: z
167
177
  .object({
168
178
  status: z.string(),
169
- txt_name: z.string().optional(),
170
- txt_value: z.string().optional(),
171
179
  validation_errors: z
172
180
  .object({
173
181
  message: z.string(),
@@ -177,7 +185,14 @@ export const cloudflareDataGuard = z
177
185
  .optional(),
178
186
  })
179
187
  .catchall(z.unknown()),
180
- ownership_verification: domainDnsRecordGuard.catchall(z.unknown()).optional(),
181
188
  verification_errors: z.string().array().optional(),
182
189
  })
183
190
  .catchall(z.unknown());
191
+ export var DomainStatus;
192
+ (function (DomainStatus) {
193
+ DomainStatus["PendingVerification"] = "PendingVerification";
194
+ DomainStatus["PendingSsl"] = "PendingSsl";
195
+ DomainStatus["Active"] = "Active";
196
+ DomainStatus["Error"] = "Error";
197
+ })(DomainStatus || (DomainStatus = {}));
198
+ export const domainStatusGuard = z.nativeEnum(DomainStatus);
@@ -1,8 +1,20 @@
1
- export declare const Tenants: import("@withtyped/server").Model<"tenants", {
1
+ import type { InferModelType } from '@withtyped/server/model';
2
+ import { z } from 'zod';
3
+ export declare enum TenantTag {
4
+ Development = "development",
5
+ Staging = "staging",
6
+ Production = "production"
7
+ }
8
+ export declare const Tenants: import("@withtyped/server/model").default<"tenants", {
2
9
  id: string;
3
10
  dbUser: string | null;
4
11
  dbUserPassword: string | null;
5
12
  name: string;
6
- tag: string;
13
+ tag: TenantTag;
7
14
  createdAt: Date;
8
- }, "name" | "createdAt" | "tag", never>;
15
+ }, "name" | "createdAt" | "tag", "createdAt">;
16
+ export type TenantModel = InferModelType<typeof Tenants>;
17
+ export type TenantInfo = Pick<TenantModel, 'id' | 'name' | 'tag'> & {
18
+ indicator: string;
19
+ };
20
+ export declare const tenantInfoGuard: z.ZodType<TenantInfo>;
@@ -1,5 +1,11 @@
1
- import { createModel } from '@withtyped/server';
2
- import { TenantTag } from '../index.js';
1
+ import { createModel } from '@withtyped/server/model';
2
+ import { z } from 'zod';
3
+ export var TenantTag;
4
+ (function (TenantTag) {
5
+ TenantTag["Development"] = "development";
6
+ TenantTag["Staging"] = "staging";
7
+ TenantTag["Production"] = "production";
8
+ })(TenantTag || (TenantTag = {}));
3
9
  export const Tenants = createModel(/* sql */ `
4
10
  /* init_order = 0 */
5
11
  create table tenants (
@@ -14,4 +20,9 @@ export const Tenants = createModel(/* sql */ `
14
20
  unique (db_user)
15
21
  );
16
22
  /* no_after_each */
17
- `);
23
+ `)
24
+ .extend('tag', z.nativeEnum(TenantTag))
25
+ .extend('createdAt', { readonly: true });
26
+ export const tenantInfoGuard = Tenants.guard('model')
27
+ .pick({ id: true, name: true, tag: true })
28
+ .extend({ indicator: z.string() });
@@ -1,5 +1,3 @@
1
- import type { InferModelType } from '@withtyped/server';
2
- import type { Tenants } from '../models/tenants.js';
1
+ export type { TenantModel } from '../models/tenants.js';
3
2
  export declare const defaultTenantId = "default";
4
3
  export declare const adminTenantId = "admin";
5
- export type TenantModel = InferModelType<typeof Tenants>;
@@ -899,6 +899,7 @@ export declare const connectorResponseGuard: z.ZodObject<z.extendShape<z.extendS
899
899
  }>, {
900
900
  type: z.ZodNativeEnum<typeof ConnectorType>;
901
901
  isDemo: z.ZodOptional<z.ZodBoolean>;
902
+ extraInfo: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
902
903
  }>, "strip", z.ZodTypeAny, {
903
904
  isStandard?: boolean | undefined;
904
905
  configTemplate?: string | undefined;
@@ -936,6 +937,7 @@ export declare const connectorResponseGuard: z.ZodObject<z.extendShape<z.extendS
936
937
  label: string;
937
938
  })[] | undefined;
938
939
  isDemo?: boolean | undefined;
940
+ extraInfo?: Record<string, unknown> | undefined;
939
941
  type: ConnectorType;
940
942
  name: {
941
943
  en: string;
@@ -1366,6 +1368,7 @@ export declare const connectorResponseGuard: z.ZodObject<z.extendShape<z.extendS
1366
1368
  label: string;
1367
1369
  })[] | undefined;
1368
1370
  isDemo?: boolean | undefined;
1371
+ extraInfo?: Record<string, unknown> | undefined;
1369
1372
  type: ConnectorType;
1370
1373
  name: {
1371
1374
  en: string;
@@ -14,6 +14,7 @@ export const connectorResponseGuard = Connectors.guard
14
14
  .merge(z.object({
15
15
  type: z.nativeEnum(ConnectorType),
16
16
  isDemo: z.boolean().optional(),
17
+ extraInfo: z.record(z.unknown()).optional(),
17
18
  }));
18
19
  export const connectorFactoryResponseGuard = z
19
20
  .object({
@@ -4,7 +4,7 @@ export declare const domainResponseGuard: z.ZodObject<Pick<{
4
4
  tenantId: z.ZodType<string, z.ZodTypeDef, string>;
5
5
  id: z.ZodType<string, z.ZodTypeDef, string>;
6
6
  domain: z.ZodType<string, z.ZodTypeDef, string>;
7
- status: z.ZodType<string, z.ZodTypeDef, string>;
7
+ status: z.ZodType<import("../index.js").DomainStatus, z.ZodTypeDef, import("../index.js").DomainStatus>;
8
8
  errorMessage: z.ZodType<string | null, z.ZodTypeDef, string | null>;
9
9
  dnsRecords: z.ZodType<{
10
10
  type: string;
@@ -17,19 +17,11 @@ export declare const domainResponseGuard: z.ZodObject<Pick<{
17
17
  }[]>;
18
18
  cloudflareData: z.ZodType<{
19
19
  [x: string]: unknown;
20
- ownership_verification?: {
21
- [x: string]: unknown;
22
- type: string;
23
- value: string;
24
- name: string;
25
- } | undefined;
26
20
  verification_errors?: string[] | undefined;
27
21
  status: string;
28
22
  id: string;
29
23
  ssl: {
30
24
  [x: string]: unknown;
31
- txt_name?: string | undefined;
32
- txt_value?: string | undefined;
33
25
  validation_errors?: {
34
26
  [x: string]: unknown;
35
27
  message: string;
@@ -38,19 +30,11 @@ export declare const domainResponseGuard: z.ZodObject<Pick<{
38
30
  };
39
31
  } | null, z.ZodTypeDef, {
40
32
  [x: string]: unknown;
41
- ownership_verification?: {
42
- [x: string]: unknown;
43
- type: string;
44
- value: string;
45
- name: string;
46
- } | undefined;
47
33
  verification_errors?: string[] | undefined;
48
34
  status: string;
49
35
  id: string;
50
36
  ssl: {
51
37
  [x: string]: unknown;
52
- txt_name?: string | undefined;
53
- txt_value?: string | undefined;
54
38
  validation_errors?: {
55
39
  [x: string]: unknown;
56
40
  message: string;
@@ -61,7 +45,7 @@ export declare const domainResponseGuard: z.ZodObject<Pick<{
61
45
  updatedAt: z.ZodType<number, z.ZodTypeDef, number>;
62
46
  createdAt: z.ZodType<number, z.ZodTypeDef, number>;
63
47
  }, "status" | "id" | "domain" | "errorMessage" | "dnsRecords">, "strip", z.ZodTypeAny, {
64
- status: string;
48
+ status: import("../index.js").DomainStatus;
65
49
  id: string;
66
50
  domain: string;
67
51
  errorMessage: string | null;
@@ -71,7 +55,7 @@ export declare const domainResponseGuard: z.ZodObject<Pick<{
71
55
  name: string;
72
56
  }[];
73
57
  }, {
74
- status: string;
58
+ status: import("../index.js").DomainStatus;
75
59
  id: string;
76
60
  domain: string;
77
61
  errorMessage: string | null;
@@ -82,9 +66,3 @@ export declare const domainResponseGuard: z.ZodObject<Pick<{
82
66
  }[];
83
67
  }>;
84
68
  export type DomainResponse = z.infer<typeof domainResponseGuard>;
85
- export declare enum DomainStatus {
86
- PendingVerification = "PendingVerification",
87
- PendingSsl = "PendingSsl",
88
- Active = "Active",
89
- Error = "Error"
90
- }
@@ -13,10 +13,3 @@ export const domainResponseGuard = Domains.guard.pick({
13
13
  errorMessage: true,
14
14
  dnsRecords: true,
15
15
  });
16
- export var DomainStatus;
17
- (function (DomainStatus) {
18
- DomainStatus["PendingVerification"] = "PendingVerification";
19
- DomainStatus["PendingSsl"] = "PendingSsl";
20
- DomainStatus["Active"] = "Active";
21
- DomainStatus["Error"] = "Error";
22
- })(DomainStatus || (DomainStatus = {}));
@@ -11,7 +11,6 @@ export * from './role.js';
11
11
  export * from './verification-code.js';
12
12
  export * from './application.js';
13
13
  export * from './system.js';
14
- export * from './tenant.js';
15
14
  export * from './user-assets.js';
16
15
  export * from './hook.js';
17
16
  export * from './service-log.js';
@@ -11,7 +11,6 @@ export * from './role.js';
11
11
  export * from './verification-code.js';
12
12
  export * from './application.js';
13
13
  export * from './system.js';
14
- export * from './tenant.js';
15
14
  export * from './user-assets.js';
16
15
  export * from './hook.js';
17
16
  export * from './service-log.js';
@@ -64,6 +64,97 @@ export type StorageProviderType = {
64
64
  export declare const storageProviderGuard: Readonly<{
65
65
  [key in StorageProviderKey]: ZodType<StorageProviderType[key]>;
66
66
  }>;
67
+ export declare enum EmailServiceProvider {
68
+ SendGrid = "SendGrid"
69
+ }
70
+ /**
71
+ * `General` is now used as a fallback scenario.
72
+ * This will be extended in the future since we will send different emails for
73
+ * different purposes (such as webhook that inform users of suspicious account activities).
74
+ */
75
+ export declare enum OtherEmailTemplate {
76
+ General = "General"
77
+ }
78
+ export declare const otherEmailTemplateGuard: z.ZodNativeEnum<typeof OtherEmailTemplate>;
79
+ export declare const sendgridEmailServiceDataGuard: z.ZodObject<{
80
+ fromName: z.ZodString;
81
+ fromEmail: z.ZodString;
82
+ templates: z.ZodRecord<z.ZodUnion<[z.ZodNativeEnum<typeof import("@logto/connector-kit").VerificationCodeType>, z.ZodNativeEnum<typeof OtherEmailTemplate>]>, z.ZodObject<{
83
+ subject: z.ZodString;
84
+ content: z.ZodString;
85
+ }, "strip", z.ZodTypeAny, {
86
+ subject: string;
87
+ content: string;
88
+ }, {
89
+ subject: string;
90
+ content: string;
91
+ }>>;
92
+ provider: z.ZodLiteral<EmailServiceProvider>;
93
+ apiKey: z.ZodString;
94
+ }, "strip", z.ZodTypeAny, {
95
+ provider: EmailServiceProvider;
96
+ apiKey: string;
97
+ fromName: string;
98
+ fromEmail: string;
99
+ templates: Partial<Record<OtherEmailTemplate.General | import("@logto/connector-kit").VerificationCodeType, {
100
+ subject: string;
101
+ content: string;
102
+ }>>;
103
+ }, {
104
+ provider: EmailServiceProvider;
105
+ apiKey: string;
106
+ fromName: string;
107
+ fromEmail: string;
108
+ templates: Partial<Record<OtherEmailTemplate.General | import("@logto/connector-kit").VerificationCodeType, {
109
+ subject: string;
110
+ content: string;
111
+ }>>;
112
+ }>;
113
+ export type SendgridEmailServiceData = z.infer<typeof sendgridEmailServiceDataGuard>;
114
+ export declare const emailServiceDataGuard: z.ZodDiscriminatedUnion<"provider", [z.ZodObject<{
115
+ fromName: z.ZodString;
116
+ fromEmail: z.ZodString;
117
+ templates: z.ZodRecord<z.ZodUnion<[z.ZodNativeEnum<typeof import("@logto/connector-kit").VerificationCodeType>, z.ZodNativeEnum<typeof OtherEmailTemplate>]>, z.ZodObject<{
118
+ subject: z.ZodString;
119
+ content: z.ZodString;
120
+ }, "strip", z.ZodTypeAny, {
121
+ subject: string;
122
+ content: string;
123
+ }, {
124
+ subject: string;
125
+ content: string;
126
+ }>>;
127
+ provider: z.ZodLiteral<EmailServiceProvider>;
128
+ apiKey: z.ZodString;
129
+ }, "strip", z.ZodTypeAny, {
130
+ provider: EmailServiceProvider;
131
+ apiKey: string;
132
+ fromName: string;
133
+ fromEmail: string;
134
+ templates: Partial<Record<OtherEmailTemplate.General | import("@logto/connector-kit").VerificationCodeType, {
135
+ subject: string;
136
+ content: string;
137
+ }>>;
138
+ }, {
139
+ provider: EmailServiceProvider;
140
+ apiKey: string;
141
+ fromName: string;
142
+ fromEmail: string;
143
+ templates: Partial<Record<OtherEmailTemplate.General | import("@logto/connector-kit").VerificationCodeType, {
144
+ subject: string;
145
+ content: string;
146
+ }>>;
147
+ }>]>;
148
+ export type EmailServiceData = z.infer<typeof emailServiceDataGuard>;
149
+ export declare enum EmailServiceProviderKey {
150
+ EmailServiceProvider = "EmailServiceProvider"
151
+ }
152
+ export type EmailServiceProviderType = {
153
+ [EmailServiceProviderKey.EmailServiceProvider]: EmailServiceData;
154
+ };
155
+ export declare const emailServiceProviderGuard: Readonly<{
156
+ [key in EmailServiceProviderKey]: ZodType<EmailServiceProviderType[key]>;
157
+ }>;
67
158
  export declare enum DemoSocialProvider {
68
159
  Google = "google",
69
160
  GitHub = "github",
@@ -101,15 +192,12 @@ export declare const demoSocialGuard: Readonly<{
101
192
  export declare const hostnameProviderDataGuard: z.ZodObject<{
102
193
  zoneId: z.ZodString;
103
194
  apiToken: z.ZodString;
104
- fallbackOrigin: z.ZodString;
105
195
  }, "strip", z.ZodTypeAny, {
106
196
  zoneId: string;
107
197
  apiToken: string;
108
- fallbackOrigin: string;
109
198
  }, {
110
199
  zoneId: string;
111
200
  apiToken: string;
112
- fallbackOrigin: string;
113
201
  }>;
114
202
  export type HostnameProviderData = z.infer<typeof hostnameProviderDataGuard>;
115
203
  export declare enum CloudflareKey {
@@ -121,8 +209,8 @@ export type CloudflareType = {
121
209
  export declare const cloudflareGuard: Readonly<{
122
210
  [key in CloudflareKey]: ZodType<CloudflareType[key]>;
123
211
  }>;
124
- export type SystemKey = AlterationStateKey | StorageProviderKey | DemoSocialKey | CloudflareKey;
125
- export type SystemType = AlterationStateType | StorageProviderType | DemoSocialType | CloudflareType;
126
- export type SystemGuard = typeof alterationStateGuard & typeof storageProviderGuard & typeof demoSocialGuard & typeof cloudflareGuard;
212
+ export type SystemKey = AlterationStateKey | StorageProviderKey | DemoSocialKey | CloudflareKey | EmailServiceProviderKey;
213
+ export type SystemType = AlterationStateType | StorageProviderType | DemoSocialType | CloudflareType | EmailServiceProviderType;
214
+ export type SystemGuard = typeof alterationStateGuard & typeof storageProviderGuard & typeof demoSocialGuard & typeof cloudflareGuard & typeof emailServiceProviderGuard;
127
215
  export declare const systemKeys: readonly SystemKey[];
128
216
  export declare const systemGuards: SystemGuard;
@@ -1,3 +1,4 @@
1
+ import { verificationCodeTypeGuard } from '@logto/connector-kit';
1
2
  import { z } from 'zod';
2
3
  // Alteration state
3
4
  export var AlterationStateKey;
@@ -42,6 +43,44 @@ export var StorageProviderKey;
42
43
  export const storageProviderGuard = Object.freeze({
43
44
  [StorageProviderKey.StorageProvider]: storageProviderDataGuard,
44
45
  });
46
+ // Email service provider
47
+ export var EmailServiceProvider;
48
+ (function (EmailServiceProvider) {
49
+ EmailServiceProvider["SendGrid"] = "SendGrid";
50
+ })(EmailServiceProvider || (EmailServiceProvider = {}));
51
+ /**
52
+ * `General` is now used as a fallback scenario.
53
+ * This will be extended in the future since we will send different emails for
54
+ * different purposes (such as webhook that inform users of suspicious account activities).
55
+ */
56
+ export var OtherEmailTemplate;
57
+ (function (OtherEmailTemplate) {
58
+ OtherEmailTemplate["General"] = "General";
59
+ })(OtherEmailTemplate || (OtherEmailTemplate = {}));
60
+ export const otherEmailTemplateGuard = z.nativeEnum(OtherEmailTemplate);
61
+ const emailServiceBasicConfig = {
62
+ fromName: z.string(),
63
+ fromEmail: z.string(),
64
+ templates: z.record(verificationCodeTypeGuard.or(otherEmailTemplateGuard), z.object({
65
+ subject: z.string(),
66
+ content: z.string(),
67
+ })),
68
+ };
69
+ export const sendgridEmailServiceDataGuard = z.object({
70
+ provider: z.literal(EmailServiceProvider.SendGrid),
71
+ apiKey: z.string(),
72
+ ...emailServiceBasicConfig,
73
+ });
74
+ export const emailServiceDataGuard = z.discriminatedUnion('provider', [
75
+ sendgridEmailServiceDataGuard,
76
+ ]);
77
+ export var EmailServiceProviderKey;
78
+ (function (EmailServiceProviderKey) {
79
+ EmailServiceProviderKey["EmailServiceProvider"] = "EmailServiceProvider";
80
+ })(EmailServiceProviderKey || (EmailServiceProviderKey = {}));
81
+ export const emailServiceProviderGuard = Object.freeze({
82
+ [EmailServiceProviderKey.EmailServiceProvider]: emailServiceDataGuard,
83
+ });
45
84
  // Demo social connectors
46
85
  export var DemoSocialProvider;
47
86
  (function (DemoSocialProvider) {
@@ -68,8 +107,7 @@ export const demoSocialGuard = Object.freeze({
68
107
  // Cloudflare Hostnames
69
108
  export const hostnameProviderDataGuard = z.object({
70
109
  zoneId: z.string(),
71
- apiToken: z.string(),
72
- fallbackOrigin: z.string(), // A domain name
110
+ apiToken: z.string(), // Requires zone permission for "SSL and Certificates Edit"
73
111
  });
74
112
  export var CloudflareKey;
75
113
  (function (CloudflareKey) {
@@ -83,10 +121,12 @@ export const systemKeys = Object.freeze([
83
121
  ...Object.values(StorageProviderKey),
84
122
  ...Object.values(DemoSocialKey),
85
123
  ...Object.values(CloudflareKey),
124
+ ...Object.values(EmailServiceProviderKey),
86
125
  ]);
87
126
  export const systemGuards = Object.freeze({
88
127
  ...alterationStateGuard,
89
128
  ...storageProviderGuard,
90
129
  ...demoSocialGuard,
91
130
  ...cloudflareGuard,
131
+ ...emailServiceProviderGuard,
92
132
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/schemas",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "author": "Silverhand Inc. <contact@silverhand.io>",
5
5
  "license": "MPL-2.0",
6
6
  "type": "module",
@@ -65,12 +65,14 @@
65
65
  "prettier": "@silverhand/eslint-config/.prettierrc",
66
66
  "dependencies": {
67
67
  "@logto/connector-kit": "^1.1.1",
68
- "@logto/core-kit": "^2.0.0",
68
+ "@logto/core-kit": "^2.0.1",
69
69
  "@logto/language-kit": "^1.0.0",
70
- "@logto/phrases": "^1.4.0",
70
+ "@logto/phrases": "^1.4.1",
71
71
  "@logto/phrases-ui": "^1.2.0",
72
72
  "@logto/shared": "^2.0.0",
73
- "@withtyped/server": "^0.9.0",
73
+ "@withtyped/server": "^0.11.1"
74
+ },
75
+ "peerDependencies": {
74
76
  "zod": "^3.20.2"
75
77
  },
76
78
  "scripts": {
@@ -3,7 +3,7 @@ create table domains (
3
3
  references tenants (id) on update cascade on delete cascade,
4
4
  id varchar(21) not null,
5
5
  domain varchar(256) not null,
6
- status varchar(32) not null default('PendingVerification'),
6
+ status varchar(32) /* @use DomainStatus */ not null default('PendingVerification'),
7
7
  error_message varchar(1024),
8
8
  dns_records jsonb /* @use DomainDnsRecords */ not null default '[]'::jsonb,
9
9
  cloudflare_data jsonb /* @use CloudflareData */,
@@ -11,7 +11,7 @@ create table domains (
11
11
  created_at timestamptz not null default(now()),
12
12
  primary key (id),
13
13
  constraint domains__domain
14
- unique (domain)
14
+ unique (tenant_id, domain)
15
15
  );
16
16
 
17
17
  create index domains__id on domains (tenant_id, id);
@@ -1,37 +0,0 @@
1
- import { z } from 'zod';
2
- import { type TenantModel } from '../seeds/tenant.js';
3
- export declare enum TenantTag {
4
- Development = "development",
5
- Staging = "staging",
6
- Production = "production"
7
- }
8
- export type PatchTenant = Partial<Pick<TenantModel, 'name' | 'tag'>>;
9
- export type CreateTenant = Pick<TenantModel, 'id' | 'dbUser' | 'dbUserPassword'> & PatchTenant & {
10
- createdAt?: number;
11
- };
12
- export declare const createTenantGuard: z.ZodObject<{
13
- id: z.ZodString;
14
- dbUser: z.ZodString;
15
- dbUserPassword: z.ZodString;
16
- name: z.ZodOptional<z.ZodString>;
17
- tag: z.ZodOptional<z.ZodNativeEnum<typeof TenantTag>>;
18
- createdAt: z.ZodOptional<z.ZodNumber>;
19
- }, "strip", z.ZodTypeAny, {
20
- name?: string | undefined;
21
- createdAt?: number | undefined;
22
- tag?: TenantTag | undefined;
23
- id: string;
24
- dbUser: string;
25
- dbUserPassword: string;
26
- }, {
27
- name?: string | undefined;
28
- createdAt?: number | undefined;
29
- tag?: TenantTag | undefined;
30
- id: string;
31
- dbUser: string;
32
- dbUserPassword: string;
33
- }>;
34
- export type TenantInfo = Pick<TenantModel, 'id' | 'name' | 'tag'> & {
35
- indicator: string;
36
- };
37
- export declare const tenantInfoGuard: z.ZodType<TenantInfo>;
@@ -1,19 +0,0 @@
1
- import { z } from 'zod';
2
- export var TenantTag;
3
- (function (TenantTag) {
4
- TenantTag["Development"] = "development";
5
- TenantTag["Staging"] = "staging";
6
- TenantTag["Production"] = "production";
7
- })(TenantTag || (TenantTag = {}));
8
- export const createTenantGuard = z.object({
9
- id: z.string(),
10
- dbUser: z.string(),
11
- dbUserPassword: z.string(),
12
- name: z.string().optional(),
13
- tag: z.nativeEnum(TenantTag).optional(),
14
- createdAt: z.number().optional(),
15
- });
16
- export const tenantInfoGuard = createTenantGuard
17
- .pick({ id: true, name: true, tag: true })
18
- .extend({ indicator: z.string() })
19
- .required();