@logto/schemas 1.3.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.
Files changed (79) hide show
  1. package/alterations/1.5.0-1684382842-add-name-tag-created-at-for-tenants-table.ts +22 -0
  2. package/alterations/1.5.0-1684739802-create-hook-id-index-for-logs.ts +18 -0
  3. package/alterations/1.5.0-1684822341-init-domains.ts +66 -0
  4. package/alterations/1.5.0-1684837981-add-manage-tenant-self-scope-to-user-role.ts +56 -0
  5. package/alterations/1.5.0-1685285719-support-default-resource.ts +23 -0
  6. package/alterations/1.6.0-1685691718-domain-unique.ts +20 -0
  7. package/alterations-js/1.5.0-1684382842-add-name-tag-created-at-for-tenants-table.d.ts +3 -0
  8. package/alterations-js/1.5.0-1684382842-add-name-tag-created-at-for-tenants-table.js +19 -0
  9. package/alterations-js/1.5.0-1684739802-create-hook-id-index-for-logs.d.ts +3 -0
  10. package/alterations-js/1.5.0-1684739802-create-hook-id-index-for-logs.js +14 -0
  11. package/alterations-js/1.5.0-1684822341-init-domains.d.ts +3 -0
  12. package/alterations-js/1.5.0-1684822341-init-domains.js +57 -0
  13. package/alterations-js/1.5.0-1684837981-add-manage-tenant-self-scope-to-user-role.d.ts +3 -0
  14. package/alterations-js/1.5.0-1684837981-add-manage-tenant-self-scope-to-user-role.js +50 -0
  15. package/alterations-js/1.5.0-1685285719-support-default-resource.d.ts +3 -0
  16. package/alterations-js/1.5.0-1685285719-support-default-resource.js +19 -0
  17. package/alterations-js/1.6.0-1685691718-domain-unique.d.ts +3 -0
  18. package/alterations-js/1.6.0-1685691718-domain-unique.js +16 -0
  19. package/lib/consts/date.d.ts +5 -0
  20. package/lib/consts/date.js +1 -0
  21. package/lib/consts/index.d.ts +1 -0
  22. package/lib/consts/index.js +1 -0
  23. package/lib/consts/oidc.d.ts +5 -0
  24. package/lib/consts/oidc.js +6 -0
  25. package/lib/db-entries/application.js +3 -3
  26. package/lib/db-entries/applications-role.js +3 -3
  27. package/lib/db-entries/connector.js +2 -2
  28. package/lib/db-entries/custom-phrase.js +2 -2
  29. package/lib/db-entries/domain.d.ts +24 -0
  30. package/lib/db-entries/domain.js +53 -0
  31. package/lib/db-entries/hook.js +3 -3
  32. package/lib/db-entries/index.d.ts +1 -0
  33. package/lib/db-entries/index.js +1 -0
  34. package/lib/db-entries/log.js +2 -2
  35. package/lib/db-entries/logto-config.js +1 -1
  36. package/lib/db-entries/oidc-model-instance.js +2 -2
  37. package/lib/db-entries/passcode.js +3 -3
  38. package/lib/db-entries/resource.d.ts +2 -0
  39. package/lib/db-entries/resource.js +7 -3
  40. package/lib/db-entries/role.js +3 -3
  41. package/lib/db-entries/roles-scope.js +3 -3
  42. package/lib/db-entries/scope.js +4 -4
  43. package/lib/db-entries/service-log.js +2 -2
  44. package/lib/db-entries/sign-in-experience.js +1 -1
  45. package/lib/db-entries/system.js +1 -1
  46. package/lib/db-entries/user.js +1 -1
  47. package/lib/db-entries/users-role.js +3 -3
  48. package/lib/db-entries/verification-status.js +2 -2
  49. package/lib/foundations/jsonb-types.d.ts +127 -5
  50. package/lib/foundations/jsonb-types.js +56 -2
  51. package/lib/models/tenants.d.ts +17 -2
  52. package/lib/models/tenants.js +17 -2
  53. package/lib/seeds/application.js +1 -1
  54. package/lib/seeds/cloud-api.d.ts +4 -0
  55. package/lib/seeds/cloud-api.js +8 -1
  56. package/lib/seeds/management-api.d.ts +3 -3
  57. package/lib/seeds/management-api.js +38 -30
  58. package/lib/seeds/tenant.d.ts +1 -3
  59. package/lib/types/connector.d.ts +7 -4
  60. package/lib/types/connector.js +1 -0
  61. package/lib/types/domain.d.ts +68 -0
  62. package/lib/types/domain.js +15 -0
  63. package/lib/types/hook.d.ts +82 -2
  64. package/lib/types/hook.js +9 -1
  65. package/lib/types/index.d.ts +1 -1
  66. package/lib/types/index.js +1 -1
  67. package/lib/types/interactions.d.ts +6 -6
  68. package/lib/types/log/hook.d.ts +1 -1
  69. package/lib/types/log/hook.js +1 -1
  70. package/lib/types/scope.d.ts +6 -4
  71. package/lib/types/system.d.ts +114 -3
  72. package/lib/types/system.js +55 -0
  73. package/lib/types/user.d.ts +6 -6
  74. package/package.json +6 -4
  75. package/tables/domains.sql +17 -0
  76. package/tables/logs.sql +3 -0
  77. package/tables/resources.sql +5 -0
  78. package/lib/types/tenant.d.ts +0 -4
  79. package/lib/types/tenant.js +0 -1
@@ -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) {
@@ -65,13 +104,29 @@ export var DemoSocialKey;
65
104
  export const demoSocialGuard = Object.freeze({
66
105
  [DemoSocialKey.DemoSocial]: demoSocialDataGuard,
67
106
  });
107
+ // Cloudflare Hostnames
108
+ export const hostnameProviderDataGuard = z.object({
109
+ zoneId: z.string(),
110
+ apiToken: z.string(), // Requires zone permission for "SSL and Certificates Edit"
111
+ });
112
+ export var CloudflareKey;
113
+ (function (CloudflareKey) {
114
+ CloudflareKey["HostnameProvider"] = "cloudflareHostnameProvider";
115
+ })(CloudflareKey || (CloudflareKey = {}));
116
+ export const cloudflareGuard = Object.freeze({
117
+ [CloudflareKey.HostnameProvider]: hostnameProviderDataGuard,
118
+ });
68
119
  export const systemKeys = Object.freeze([
69
120
  ...Object.values(AlterationStateKey),
70
121
  ...Object.values(StorageProviderKey),
71
122
  ...Object.values(DemoSocialKey),
123
+ ...Object.values(CloudflareKey),
124
+ ...Object.values(EmailServiceProviderKey),
72
125
  ]);
73
126
  export const systemGuards = Object.freeze({
74
127
  ...alterationStateGuard,
75
128
  ...storageProviderGuard,
76
129
  ...demoSocialGuard,
130
+ ...cloudflareGuard,
131
+ ...emailServiceProviderGuard,
77
132
  });
@@ -22,12 +22,12 @@ export declare const userInfoGuard: z.ZodObject<Pick<{
22
22
  isSuspended: z.ZodType<boolean, z.ZodTypeDef, boolean>;
23
23
  lastSignInAt: z.ZodType<number | null, z.ZodTypeDef, number | null>;
24
24
  createdAt: z.ZodType<number, z.ZodTypeDef, number>;
25
- }, "tenantId" | "username" | "applicationId" | "id" | "name" | "createdAt" | "primaryEmail" | "primaryPhone" | "passwordEncrypted" | "passwordEncryptionMethod" | "avatar" | "identities" | "customData" | "isSuspended" | "lastSignInAt">, "strip", z.ZodTypeAny, {
25
+ }, "tenantId" | "username" | "applicationId" | "name" | "id" | "createdAt" | "primaryEmail" | "primaryPhone" | "passwordEncrypted" | "passwordEncryptionMethod" | "avatar" | "identities" | "customData" | "isSuspended" | "lastSignInAt">, "strip", z.ZodTypeAny, {
26
26
  tenantId: string;
27
27
  username: string | null;
28
28
  applicationId: string | null;
29
- id: string;
30
29
  name: string | null;
30
+ id: string;
31
31
  createdAt: number;
32
32
  primaryEmail: string | null;
33
33
  primaryPhone: string | null;
@@ -45,8 +45,8 @@ export declare const userInfoGuard: z.ZodObject<Pick<{
45
45
  tenantId: string;
46
46
  username: string | null;
47
47
  applicationId: string | null;
48
- id: string;
49
48
  name: string | null;
49
+ id: string;
50
50
  createdAt: number;
51
51
  primaryEmail: string | null;
52
52
  primaryPhone: string | null;
@@ -84,15 +84,15 @@ export declare const userProfileResponseGuard: z.ZodObject<z.extendShape<Pick<{
84
84
  isSuspended: z.ZodType<boolean, z.ZodTypeDef, boolean>;
85
85
  lastSignInAt: z.ZodType<number | null, z.ZodTypeDef, number | null>;
86
86
  createdAt: z.ZodType<number, z.ZodTypeDef, number>;
87
- }, "tenantId" | "username" | "applicationId" | "id" | "name" | "createdAt" | "primaryEmail" | "primaryPhone" | "passwordEncrypted" | "passwordEncryptionMethod" | "avatar" | "identities" | "customData" | "isSuspended" | "lastSignInAt">, {
87
+ }, "tenantId" | "username" | "applicationId" | "name" | "id" | "createdAt" | "primaryEmail" | "primaryPhone" | "passwordEncrypted" | "passwordEncryptionMethod" | "avatar" | "identities" | "customData" | "isSuspended" | "lastSignInAt">, {
88
88
  hasPassword: z.ZodOptional<z.ZodBoolean>;
89
89
  }>, "strip", z.ZodTypeAny, {
90
90
  hasPassword?: boolean | undefined;
91
91
  tenantId: string;
92
92
  username: string | null;
93
93
  applicationId: string | null;
94
- id: string;
95
94
  name: string | null;
95
+ id: string;
96
96
  createdAt: number;
97
97
  primaryEmail: string | null;
98
98
  primaryPhone: string | null;
@@ -111,8 +111,8 @@ export declare const userProfileResponseGuard: z.ZodObject<z.extendShape<Pick<{
111
111
  tenantId: string;
112
112
  username: string | null;
113
113
  applicationId: string | null;
114
- id: string;
115
114
  name: string | null;
115
+ id: string;
116
116
  createdAt: number;
117
117
  primaryEmail: string | null;
118
118
  primaryPhone: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/schemas",
3
- "version": "1.3.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.2.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": {
@@ -0,0 +1,17 @@
1
+ create table domains (
2
+ tenant_id varchar(21) not null
3
+ references tenants (id) on update cascade on delete cascade,
4
+ id varchar(21) not null,
5
+ domain varchar(256) not null,
6
+ status varchar(32) /* @use DomainStatus */ not null default('PendingVerification'),
7
+ error_message varchar(1024),
8
+ dns_records jsonb /* @use DomainDnsRecords */ not null default '[]'::jsonb,
9
+ cloudflare_data jsonb /* @use CloudflareData */,
10
+ updated_at timestamptz not null default(now()),
11
+ created_at timestamptz not null default(now()),
12
+ primary key (id),
13
+ constraint domains__domain
14
+ unique (tenant_id, domain)
15
+ );
16
+
17
+ create index domains__id on domains (tenant_id, id);
package/tables/logs.sql CHANGED
@@ -19,3 +19,6 @@ create index logs__user_id
19
19
 
20
20
  create index logs__application_id
21
21
  on logs (tenant_id, (payload->>'applicationId'));
22
+
23
+ create index logs__hook_id
24
+ on logs (tenant_id, (payload->>'hookId'));
@@ -6,6 +6,7 @@ create table resources (
6
6
  id varchar(21) not null,
7
7
  name text not null,
8
8
  indicator text not null, /* resource indicator also used as audience */
9
+ is_default boolean not null default (false),
9
10
  access_token_ttl bigint not null default(3600), /* expiration value in seconds, default is 1h */
10
11
  primary key (id),
11
12
  constraint resources__indicator
@@ -14,3 +15,7 @@ create table resources (
14
15
 
15
16
  create index resources__id
16
17
  on resources (tenant_id, id);
18
+
19
+ create unique index resources__is_default_true
20
+ on resources (tenant_id)
21
+ where is_default = true;
@@ -1,4 +0,0 @@
1
- export type TenantInfo = {
2
- id: string;
3
- indicator: string;
4
- };
@@ -1 +0,0 @@
1
- export {};