0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-10 22:22:45 -05:00

feat(core): add sign-in-experiences table (#191)

* feat(core): add sign-in-experience-setting table

add sign-in-experience-setting table

* fix(core): fix typo

fix typo

* refactor: rename sign-in-experience table name

rename sign-in-experience table name

* fix(core): cr fix update sign_in_method schema

update sign_in_method schema

* fix(schema): cr fix

remove signinMethodsMetadata jsonb field
This commit is contained in:
simeng-li 2022-01-25 11:48:47 +08:00 committed by GitHub
parent 7d182e2b46
commit f85b922836
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 203 additions and 1 deletions

View file

@ -7,5 +7,7 @@ export * from './oidc-model-instance';
export * from './resource-scope';
export * from './resource';
export * from './setting';
export * from './sign-in-experience';
export * from './sign-in-method';
export * from './user-log';
export * from './user';

View file

@ -0,0 +1,72 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import { z } from 'zod';
import {
CompanyInfo,
companyInfoGuard,
Branding,
brandingGuard,
TermsOfUse,
termsOfUseGuard,
Localization,
localizationGuard,
SignInMethodSettings,
signInMethodSettingsGuard,
GeneratedSchema,
Guard,
} from '../foundations';
export type CreateSignInExperience = {
id: string;
companyInfo: CompanyInfo;
branding: Branding;
termsOfUse: TermsOfUse;
forgetPasswordEnabled?: boolean;
localization: Localization;
signInMethods: SignInMethodSettings;
};
export type SignInExperience = {
id: string;
companyInfo: CompanyInfo;
branding: Branding;
termsOfUse: TermsOfUse;
forgetPasswordEnabled: boolean;
localization: Localization;
signInMethods: SignInMethodSettings;
};
const createGuard: Guard<CreateSignInExperience> = z.object({
id: z.string(),
companyInfo: companyInfoGuard,
branding: brandingGuard,
termsOfUse: termsOfUseGuard,
forgetPasswordEnabled: z.boolean().optional(),
localization: localizationGuard,
signInMethods: signInMethodSettingsGuard,
});
export const SignInExperiences: GeneratedSchema<CreateSignInExperience> = Object.freeze({
table: 'sign_in_experiences',
tableSingular: 'sign_in_experience',
fields: {
id: 'id',
companyInfo: 'company_info',
branding: 'branding',
termsOfUse: 'terms_of_use',
forgetPasswordEnabled: 'forget_password_enabled',
localization: 'localization',
signInMethods: 'sign_in_methods',
},
fieldKeys: [
'id',
'companyInfo',
'branding',
'termsOfUse',
'forgetPasswordEnabled',
'localization',
'signInMethods',
],
createGuard,
});

View file

@ -0,0 +1,35 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import { z } from 'zod';
import { GeneratedSchema, Guard } from '../foundations';
export type CreateSignInMethod = {
id: string;
name: string;
connectorId?: string | null;
};
export type SignInMethod = {
id: string;
name: string;
connectorId: string | null;
};
const createGuard: Guard<CreateSignInMethod> = z.object({
id: z.string(),
name: z.string(),
connectorId: z.string().nullable().optional(),
});
export const SignInMethods: GeneratedSchema<CreateSignInMethod> = Object.freeze({
table: 'sign_in_methods',
tableSingular: 'sign_in_method',
fields: {
id: 'id',
name: 'name',
connectorId: 'connector_id',
},
fieldKeys: ['id', 'name', 'connectorId'],
createGuard,
});

View file

@ -1,5 +1,9 @@
import { z } from 'zod';
/**
* OIDC Model Instances
*/
export const oidcModelInstancePayloadGuard = z
.object({
userCode: z.string().optional(),
@ -34,6 +38,10 @@ export const customClientMetadataGuard = z.object({
export type CustomClientMetadata = z.infer<typeof customClientMetadataGuard>;
/**
* User Logs
*/
export const userLogPayloadGuard = z.object({
ip: z.string().optional(),
userAgent: z.string().optional(),
@ -44,13 +52,78 @@ export const userLogPayloadGuard = z.object({
export type UserLogPayload = z.infer<typeof userLogPayloadGuard>;
/**
* Connectors
*/
// TODO: support empty shape of object
export const connectorConfigGuard = z.object({}).catchall(z.unknown());
export type ConnectorConfig = z.infer<typeof connectorConfigGuard>;
/**
* Settings
*/
export const adminConsoleConfigGuard = z.object({
applicationSkipGetStarted: z.boolean(),
});
export type AdminConsoleConfig = z.infer<typeof adminConsoleConfigGuard>;
/**
* SignIn Experience
*/
export const companyInfoGuard = z.object({
name: z.string(),
logo: z.string(),
});
export type CompanyInfo = z.infer<typeof companyInfoGuard>;
export enum BrandingStyle {
CompanyLogo_CompanyName_AppName = 'CompanyLogo_CompanyName_AppName',
CompanyLogo_AppLogo_CompanyName_AppName = 'CompanyLogo_AppLogo_CompanyName_AppName',
AppLogo_CompanyName_AppName = 'AppLogo_CompanyName_AppName',
}
export const brandingGuard = z.object({
primaryColor: z.string(),
backgroundColor: z.string(),
darkMode: z.boolean(),
darkPrimaryColor: z.string(),
darkBackgroundColor: z.string(),
style: z.nativeEnum(BrandingStyle),
});
export type Branding = z.infer<typeof brandingGuard>;
export const termsOfUseGuard = z.object({
enabled: z.boolean(),
content: z.string().optional(),
contentUrl: z.string().optional(),
});
export type TermsOfUse = z.infer<typeof termsOfUseGuard>;
export enum Language {
english = 'en',
chinese = 'zh-cn',
}
export const localizationGuard = z.object({
autoDetect: z.boolean(),
primaryLanguage: z.nativeEnum(Language),
fallbackLanguage: z.nativeEnum(Language),
});
export type Localization = z.infer<typeof localizationGuard>;
export const signInMethodSettingsGuard = z.object({
primary: z.string().array().nonempty().max(3),
secondary: z.string().array(),
disabled: z.string().array(),
});
export type SignInMethodSettings = z.infer<typeof signInMethodSettingsGuard>;

View file

@ -4,7 +4,7 @@ create table resource_scopes (
description text not null,
resource_id varchar(24) not null,
primary key (id),
constraint fk_resource
constraint fk__resource_scopes__resource_id
foreign key (resource_id)
references resources(id)
on delete cascade

View file

@ -0,0 +1,10 @@
create table sign_in_experiences (
id varchar(128) not null,
company_info jsonb /* @use CompanyInfo */ not null,
branding jsonb /* @use Branding */ not null,
terms_of_use jsonb /* @use TermsOfUse */ not null,
forget_password_enabled boolean not null default(true),
localization jsonb /* @use Localization */ not null,
sign_in_methods jsonb /* @use SignInMethodSettings */ not null,
primary key (id)
)

View file

@ -0,0 +1,10 @@
create table sign_in_methods (
id varchar(128) not null,
name varchar(128) not null,
connector_id varchar(128),
primary key (id),
constraint fk__sign_in_methods__connector_id
foreign key (connector_id)
references connectors(id)
on delete cascade
)