From 759adf0f1883464858553051025507b77fa9e768 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Tue, 4 Jul 2023 16:24:41 +0800 Subject: [PATCH] refactor(schemas): sync cloud m2m credential to logto config (#4115) --- packages/schemas/src/seeds/logto-config.ts | 23 +++++++++++++++++++++- packages/schemas/src/types/logto-config.ts | 12 +++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/schemas/src/seeds/logto-config.ts b/packages/schemas/src/seeds/logto-config.ts index 4e053ef1b..0088324d0 100644 --- a/packages/schemas/src/seeds/logto-config.ts +++ b/packages/schemas/src/seeds/logto-config.ts @@ -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); diff --git a/packages/schemas/src/types/logto-config.ts b/packages/schemas/src/types/logto-config.ts index 944c162b1..f1500fa71 100644 --- a/packages/schemas/src/types/logto-config.ts +++ b/packages/schemas/src/types/logto-config.ts @@ -34,13 +34,24 @@ export const adminConsoleDataGuard = z.object({ export type AdminConsoleData = z.infer; +/* --- Logto tenant cloud connection config --- */ +export const cloudConnectionDataGuard = z.object({ + appId: z.string(), + appSecret: z.string(), + resource: z.string(), +}); + +export type CloudConnectionData = z.infer; + 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; }> = Object.freeze({ [LogtoTenantConfigKey.AdminConsole]: adminConsoleDataGuard, + [LogtoTenantConfigKey.CloudConnection]: cloudConnectionDataGuard, [LogtoTenantConfigKey.SessionNotFoundRedirectUrl]: z.object({ url: z.string() }), });