0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

refactor(schemas): sync cloud m2m credential to logto config (#4115)

This commit is contained in:
Darcy Ye 2023-07-04 16:24:41 +08:00 committed by GitHub
parent 3c14d046c6
commit 759adf0f18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View file

@ -1,7 +1,9 @@
import { type CreateLogtoConfig } from '../db-entries/index.js';
import type { AdminConsoleData } from '../types/index.js';
import type { AdminConsoleData, CloudConnectionData } from '../types/index.js';
import { LogtoTenantConfigKey } from '../types/index.js';
import { cloudApiIndicator } from './cloud-api.js';
export const createDefaultAdminConsoleConfig = (
forTenantId: string
): Readonly<{
@ -23,3 +25,22 @@ export const createDefaultAdminConsoleConfig = (
m2mApplicationCreated: false,
},
} satisfies CreateLogtoConfig);
export const createDefaultCloudConnectionConfig = (
forTenantId: string,
appId: string,
appSecret: string
): Readonly<{
tenantId: string;
key: LogtoTenantConfigKey;
value: CloudConnectionData;
}> =>
Object.freeze({
tenantId: forTenantId,
key: LogtoTenantConfigKey.CloudConnection,
value: {
appId,
appSecret,
resource: cloudApiIndicator,
},
} satisfies CreateLogtoConfig);

View file

@ -34,13 +34,24 @@ export const adminConsoleDataGuard = z.object({
export type AdminConsoleData = z.infer<typeof adminConsoleDataGuard>;
/* --- Logto tenant cloud connection config --- */
export const cloudConnectionDataGuard = z.object({
appId: z.string(),
appSecret: z.string(),
resource: z.string(),
});
export type CloudConnectionData = z.infer<typeof cloudConnectionDataGuard>;
export enum LogtoTenantConfigKey {
AdminConsole = 'adminConsole',
CloudConnection = 'cloudConnection',
/** The URL to redirect when session not found in Sign-in Experience. */
SessionNotFoundRedirectUrl = 'sessionNotFoundRedirectUrl',
}
export type LogtoTenantConfigType = {
[LogtoTenantConfigKey.AdminConsole]: AdminConsoleData;
[LogtoTenantConfigKey.CloudConnection]: CloudConnectionData;
[LogtoTenantConfigKey.SessionNotFoundRedirectUrl]: { url: string };
};
@ -48,6 +59,7 @@ export const logtoTenantConfigGuard: Readonly<{
[key in LogtoTenantConfigKey]: ZodType<LogtoTenantConfigType[key]>;
}> = Object.freeze({
[LogtoTenantConfigKey.AdminConsole]: adminConsoleDataGuard,
[LogtoTenantConfigKey.CloudConnection]: cloudConnectionDataGuard,
[LogtoTenantConfigKey.SessionNotFoundRedirectUrl]: z.object({ url: z.string() }),
});