Skip to content

Commit 70e14cf

Browse files
authored
fix(connector): use proper template type guard in mock connectors (#8111)
* fix(connector): use proper template type guard in mock connectors Use `templateTypeGuard` from `@logto/connector-kit` instead of `z.string()` for the `usageType` field in mock email and SMS connectors. Also add missing template types to config templates: - OrganizationInvitation - UserPermissionValidation - BindNewIdentifier - BindMfa * fix(test): update mock connector configs to use valid template types Remove deprecated 'Test' and 'Continue' template types from mock connector configurations since they are not valid values in the TemplateType enum used by templateTypeGuard. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent e30bf26 commit 70e14cf

File tree

7 files changed

+89
-25
lines changed

7 files changed

+89
-25
lines changed

packages/connectors/connector-mock-email-alternative/docs/config-template.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,47 @@
1515
"subject": "Logto Register Template",
1616
"content": "This is for registering purposes only. Your verification code is {{code}}."
1717
},
18+
{
19+
"usageType": "ForgotPassword",
20+
"type": "text/plain",
21+
"subject": "Logto Forgot Password Template",
22+
"content": "This is for forgot-password purposes only. Your verification code is {{code}}."
23+
},
24+
{
25+
"usageType": "MfaVerification",
26+
"type": "text/plain",
27+
"subject": "Logto MfaVerification Template",
28+
"content": "This is for MFA verification purposes only. Your verification code is {{code}}."
29+
},
1830
{
1931
"usageType": "Generic",
2032
"type": "text/plain",
2133
"subject": "Logto Generic Template",
2234
"content": "This is for generic purpose through management API only. Your verification code is {{code}}."
2335
},
2436
{
25-
"usageType": "ForgotPassword",
37+
"usageType": "OrganizationInvitation",
2638
"type": "text/plain",
27-
"subject": "Logto Forgot Password Template",
28-
"content": "This is for forgot-password purposes only. Your verification code is {{code}}."
39+
"subject": "Logto Organization Invitation Template",
40+
"content": "You have been invited to join an organization. Please click the link to accept: {{link}}."
41+
},
42+
{
43+
"usageType": "UserPermissionValidation",
44+
"type": "text/plain",
45+
"subject": "Logto User Permission Validation Template",
46+
"content": "This is for validating user permission. Your verification code is {{code}}."
47+
},
48+
{
49+
"usageType": "BindNewIdentifier",
50+
"type": "text/plain",
51+
"subject": "Logto Bind New Identifier Template",
52+
"content": "This is for binding a new identifier to your account. Your verification code is {{code}}."
53+
},
54+
{
55+
"usageType": "BindMfa",
56+
"type": "text/plain",
57+
"subject": "Logto Bind MFA Template",
58+
"content": "This is for binding MFA to your account. Your verification code is {{code}}."
2959
}
3060
]
3161
}

packages/connectors/connector-mock-email-alternative/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { z } from 'zod';
22

3+
import { templateTypeGuard } from '@logto/connector-kit';
4+
35
export enum ContextType {
46
Text = 'text/plain',
57
Html = 'text/html',
68
}
79

810
const templateGuard = z.object({
9-
usageType: z.string(),
11+
usageType: templateTypeGuard,
1012
type: z.nativeEnum(ContextType),
1113
subject: z.string(),
1214
content: z.string(), // With variable {{code}}, support HTML

packages/connectors/connector-mock-email/docs/config-template.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@
3232
"type": "text/plain",
3333
"subject": "Logto Generic Template",
3434
"content": "This is for generic purpose through management API only. Your verification code is {{code}}."
35+
},
36+
{
37+
"usageType": "OrganizationInvitation",
38+
"type": "text/plain",
39+
"subject": "Logto Organization Invitation Template",
40+
"content": "You have been invited to join an organization. Please click the link to accept: {{link}}."
41+
},
42+
{
43+
"usageType": "UserPermissionValidation",
44+
"type": "text/plain",
45+
"subject": "Logto User Permission Validation Template",
46+
"content": "This is for validating user permission. Your verification code is {{code}}."
47+
},
48+
{
49+
"usageType": "BindNewIdentifier",
50+
"type": "text/plain",
51+
"subject": "Logto Bind New Identifier Template",
52+
"content": "This is for binding a new identifier to your account. Your verification code is {{code}}."
53+
},
54+
{
55+
"usageType": "BindMfa",
56+
"type": "text/plain",
57+
"subject": "Logto Bind MFA Template",
58+
"content": "This is for binding MFA to your account. Your verification code is {{code}}."
3559
}
3660
]
3761
}

packages/connectors/connector-mock-email/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { z } from 'zod';
22

3+
import { templateTypeGuard } from '@logto/connector-kit';
4+
35
export enum ContextType {
46
Text = 'text/plain',
57
Html = 'text/html',
68
}
79

810
const templateGuard = z.object({
9-
usageType: z.string(),
11+
usageType: templateTypeGuard,
1012
type: z.nativeEnum(ContextType),
1113
subject: z.string(),
1214
content: z.string(), // With variable {{code}}, support HTML

packages/connectors/connector-mock-sms/docs/config-template.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@
2222
{
2323
"usageType": "Generic",
2424
"content": "This is for generic purpose through management API only. Your verification code is {{code}}."
25+
},
26+
{
27+
"usageType": "OrganizationInvitation",
28+
"content": "You have been invited to join an organization. Please click the link to accept: {{link}}."
29+
},
30+
{
31+
"usageType": "UserPermissionValidation",
32+
"content": "This is for validating user permission. Your verification code is {{code}}."
33+
},
34+
{
35+
"usageType": "BindNewIdentifier",
36+
"content": "This is for binding a new identifier to your account. Your verification code is {{code}}."
37+
},
38+
{
39+
"usageType": "BindMfa",
40+
"content": "This is for binding MFA to your account. Your verification code is {{code}}."
2541
}
2642
]
2743
}

packages/connectors/connector-mock-sms/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { z } from 'zod';
22

3+
import { templateTypeGuard } from '@logto/connector-kit';
4+
35
const templateGuard = z.object({
4-
usageType: z.string(),
6+
usageType: templateTypeGuard,
57
content: z.string(),
68
});
79

packages/integration-tests/src/__mocks__/connectors-mock.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ export const mockSmsConnectorConfig = {
114114
usageType: 'Generic',
115115
content: 'This is for Management API call only. Your passcode is {{code}}.',
116116
},
117-
{
118-
usageType: 'Test',
119-
content: 'This is for testing purposes only. Your passcode is {{code}}.',
120-
},
121117
{
122118
usageType: 'UserPermissionValidation',
123119
content: 'This is for user permission validation purposes only. Your passcode is {{code}}.',
@@ -134,6 +130,10 @@ export const mockSmsConnectorConfig = {
134130
usageType: 'BindMfa',
135131
content: 'This is for binding MFA purposes only. Your passcode is {{code}}.',
136132
},
133+
{
134+
usageType: 'OrganizationInvitation',
135+
content: 'This is for organization invitation purposes only. Your link is {{link}}.',
136+
},
137137
],
138138
};
139139

@@ -167,12 +167,6 @@ export const mockEmailConnectorConfig = {
167167
subject: 'Logto Generic Template',
168168
content: 'This is for Management API call only. Your passcode is {{code}}.',
169169
},
170-
{
171-
usageType: 'Test',
172-
type: 'text/plain',
173-
subject: 'Logto Test Template',
174-
content: 'This is for testing purposes only. Your passcode is {{code}}.',
175-
},
176170
{
177171
usageType: 'OrganizationInvitation',
178172
type: 'text/plain',
@@ -231,16 +225,10 @@ export const mockAlternativeEmailConnectorConfig = {
231225
content: 'This is for forgot-password purposes only. Your passcode is {{code}}.',
232226
},
233227
{
234-
usageType: 'Continue',
235-
type: 'text/plain',
236-
subject: 'Logto Continue Template',
237-
content: 'This is for completing user profile purposes only. Your passcode is {{code}}.',
238-
},
239-
{
240-
usageType: 'Test',
228+
usageType: 'Generic',
241229
type: 'text/plain',
242-
subject: 'Logto Test Template',
243-
content: 'This is for testing purposes only. Your passcode is {{code}}.',
230+
subject: 'Logto Generic Template',
231+
content: 'This is for generic purposes only. Your passcode is {{code}}.',
244232
},
245233
],
246234
};

0 commit comments

Comments
 (0)