Skip to content

Commit b0b21cc

Browse files
authored
feat(schemas): add captcha policy field (#7106)
1 parent 45b58d3 commit b0b21cc

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

packages/core/src/__mocks__/sign-in-experience.ts

+1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ export const mockSignInExperience: SignInExperience = {
103103
supportEmail: null,
104104
supportWebsiteUrl: null,
105105
unknownSessionRedirectUrl: null,
106+
captchaPolicy: {},
106107
};

packages/core/src/queries/sign-in-experience.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ describe('sign-in-experience query', () => {
3636
passwordPolicy: JSON.stringify(mockSignInExperience.passwordPolicy),
3737
mfa: JSON.stringify(mockSignInExperience.mfa),
3838
socialSignIn: JSON.stringify(mockSignInExperience.socialSignIn),
39+
captchaPolicy: JSON.stringify(mockSignInExperience.captchaPolicy),
3940
};
4041

4142
it('findDefaultSignInExperience', async () => {
4243
/* eslint-disable sql/no-unsafe-query */
4344
const expectSql = `
44-
select "tenant_id", "id", "color", "branding", "language_info", "terms_of_use_url", "privacy_policy_url", "agree_to_terms_policy", "sign_in", "sign_up", "social_sign_in", "social_sign_in_connector_targets", "sign_in_mode", "custom_css", "custom_content", "custom_ui_assets", "password_policy", "mfa", "single_sign_on_enabled", "support_email", "support_website_url", "unknown_session_redirect_url"
45+
select "tenant_id", "id", "color", "branding", "language_info", "terms_of_use_url", "privacy_policy_url", "agree_to_terms_policy", "sign_in", "sign_up", "social_sign_in", "social_sign_in_connector_targets", "sign_in_mode", "custom_css", "custom_content", "custom_ui_assets", "password_policy", "mfa", "single_sign_on_enabled", "support_email", "support_website_url", "unknown_session_redirect_url", "captcha_policy"
4546
from "sign_in_experiences"
4647
where "id"=$1
4748
`;

packages/experience-legacy/src/__mocks__/logto.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const mockSignInExperience: SignInExperience = {
117117
supportEmail: null,
118118
supportWebsiteUrl: null,
119119
unknownSessionRedirectUrl: null,
120+
captchaPolicy: {},
120121
};
121122

122123
export const mockSignInExperienceSettings: SignInExperienceResponse = {
@@ -155,6 +156,7 @@ export const mockSignInExperienceSettings: SignInExperienceResponse = {
155156
supportEmail: null,
156157
supportWebsiteUrl: null,
157158
unknownSessionRedirectUrl: null,
159+
captchaPolicy: {},
158160
};
159161

160162
const usernameSettings = {

packages/experience/src/__mocks__/logto.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const mockSignInExperience: SignInExperience = {
117117
supportEmail: null,
118118
supportWebsiteUrl: null,
119119
unknownSessionRedirectUrl: null,
120+
captchaPolicy: {},
120121
};
121122

122123
export const mockSignInExperienceSettings: SignInExperienceResponse = {
@@ -155,6 +156,7 @@ export const mockSignInExperienceSettings: SignInExperienceResponse = {
155156
supportEmail: null,
156157
supportWebsiteUrl: null,
157158
unknownSessionRedirectUrl: null,
159+
captchaPolicy: {},
158160
};
159161

160162
const usernameSettings = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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
9+
add column captcha_policy jsonb not null default '{}'::jsonb;
10+
`);
11+
},
12+
down: async (pool) => {
13+
await pool.query(sql`
14+
alter table sign_in_experiences
15+
drop column captcha_policy;
16+
`);
17+
},
18+
};
19+
20+
export default alteration;

packages/schemas/src/foundations/jsonb-types/sign-in-experience.ts

+8
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,11 @@ export const customUiAssetsGuard = z.object({
160160
});
161161

162162
export type CustomUiAssets = z.infer<typeof customUiAssetsGuard>;
163+
164+
export const captchaPolicyGuard = z.object({
165+
signIn: z.boolean().optional(),
166+
signUp: z.boolean().optional(),
167+
forgotPassword: z.boolean().optional(),
168+
});
169+
170+
export type CaptchaPolicy = z.infer<typeof captchaPolicyGuard>;

packages/schemas/tables/sign_in_experiences.sql

+1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ create table sign_in_experiences (
2626
support_email text,
2727
support_website_url text,
2828
unknown_session_redirect_url text,
29+
captcha_policy jsonb /* @use CaptchaPolicy */ not null default '{}'::jsonb,
2930
primary key (tenant_id, id)
3031
);

0 commit comments

Comments
 (0)