From f669f6b657cccf66480e3ee8e416fb11bf8911f4 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Sun, 24 Apr 2022 15:05:38 +0800 Subject: [PATCH] feat(core): fix packages' dependencies --- packages/connector-types/package.json | 4 +-- packages/connector-types/src/index.ts | 30 ++++++++----------- packages/schemas/package.json | 1 + packages/schemas/src/db-entries/connector.ts | 7 ++--- .../schemas/src/db-entries/custom-types.ts | 5 ---- packages/schemas/src/types/connector.ts | 16 ++++------ packages/schemas/tables/connectors.sql | 4 +-- pnpm-lock.yaml | 6 ++-- 8 files changed, 25 insertions(+), 48 deletions(-) diff --git a/packages/connector-types/package.json b/packages/connector-types/package.json index 20e9c38fb..034f36a16 100644 --- a/packages/connector-types/package.json +++ b/packages/connector-types/package.json @@ -20,9 +20,7 @@ "node": "^16.0.0" }, "dependencies": { - "@logto/phrases": "^0.1.0", - "@logto/schemas": "^0.1.0", - "got": "^11.8.2" + "@logto/phrases": "^0.1.0" }, "devDependencies": { "@jest/types": "^27.5.1", diff --git a/packages/connector-types/src/index.ts b/packages/connector-types/src/index.ts index c87cb8ede..1bca14583 100644 --- a/packages/connector-types/src/index.ts +++ b/packages/connector-types/src/index.ts @@ -1,6 +1,10 @@ import { Languages } from '@logto/phrases'; -import { ArbitraryObject, ConnectorType } from '@logto/schemas'; -import { Response } from 'got'; + +export enum ConnectorType { + Email = 'Email', + SMS = 'SMS', + Social = 'Social', +} export interface ConnectorMetadata { id: string; @@ -50,23 +54,17 @@ export type SendEmailResponse = { EnvId: string; RequestId: string }; export type SendSmsResponse = { BizId: string; Code: string; Message: string; RequestId: string }; -export type EmailSendMessageFunction< - ResponseBody extends ArbitraryObject = ArbitraryObject, - ResponseType = Response -> = ( +export type EmailSendMessageFunction> = ( address: string, type: keyof EmailMessageTypes, payload: EmailMessageTypes[typeof type] -) => Promise; +) => Promise; -export type SmsSendMessageFunction< - ResponseBody extends ArbitraryObject = ArbitraryObject, - ResponseType = Response -> = ( +export type SmsSendMessageFunction> = ( phone: string, type: keyof SmsMessageTypes, payload: SmsMessageTypes[typeof type] -) => Promise; +) => Promise; export interface BaseConnector { metadata: ConnectorMetadata; @@ -90,9 +88,7 @@ export interface SocialConnector extends BaseConnector { getTimestamp?: GetTimestamp; } -export type ValidateConfig = ( - config: T -) => Promise; +export type ValidateConfig> = (config: T) => Promise; export type GetAuthorizationUri = (redirectUri: string, state: string) => Promise; @@ -104,9 +100,7 @@ export type GetUserInfo = ( accessTokenObject: AccessTokenObject ) => Promise<{ id: string } & Record>; -export type GetConnectorConfig = ( - id: string -) => Promise; +export type GetConnectorConfig> = (id: string) => Promise; export type GetTimeout = () => Promise; diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 137a6f8e1..1e757d4a6 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -45,6 +45,7 @@ }, "prettier": "@silverhand/eslint-config/.prettierrc", "dependencies": { + "@logto/connector-types": "^0.1.0", "@logto/phrases": "^0.1.0", "zod": "^3.14.3" } diff --git a/packages/schemas/src/db-entries/connector.ts b/packages/schemas/src/db-entries/connector.ts index 1f20df298..aa997f0ff 100644 --- a/packages/schemas/src/db-entries/connector.ts +++ b/packages/schemas/src/db-entries/connector.ts @@ -3,11 +3,10 @@ import { z } from 'zod'; import { ArbitraryObject, arbitraryObjectGuard, GeneratedSchema, Guard } from '../foundations'; -import { ConnectorType } from './custom-types'; export type CreateConnector = { id: string; - type: ConnectorType; + type: string; enabled?: boolean; config?: ArbitraryObject; createdAt?: number; @@ -15,7 +14,7 @@ export type CreateConnector = { export type Connector = { id: string; - type: ConnectorType; + type: string; enabled: boolean; config: ArbitraryObject; createdAt: number; @@ -23,7 +22,7 @@ export type Connector = { const createGuard: Guard = z.object({ id: z.string(), - type: z.nativeEnum(ConnectorType), + type: z.string(), enabled: z.boolean().optional(), config: arbitraryObjectGuard.optional(), createdAt: z.number().optional(), diff --git a/packages/schemas/src/db-entries/custom-types.ts b/packages/schemas/src/db-entries/custom-types.ts index da6a53bfd..80eaebc00 100644 --- a/packages/schemas/src/db-entries/custom-types.ts +++ b/packages/schemas/src/db-entries/custom-types.ts @@ -5,11 +5,6 @@ export enum ApplicationType { SPA = 'SPA', Traditional = 'Traditional', } -export enum ConnectorType { - Email = 'Email', - SMS = 'SMS', - Social = 'Social', -} export enum PasscodeType { SignIn = 'SignIn', Register = 'Register', diff --git a/packages/schemas/src/types/connector.ts b/packages/schemas/src/types/connector.ts index 858c2d39c..599cdafaf 100644 --- a/packages/schemas/src/types/connector.ts +++ b/packages/schemas/src/types/connector.ts @@ -1,16 +1,10 @@ -import { Languages } from '@logto/phrases'; +import { ConnectorMetadata } from '@logto/connector-types'; -import { Connector, ConnectorType } from '../db-entries'; +import { Connector } from '../db-entries'; + +export type { ConnectorMetadata } from '@logto/connector-types'; +export { ConnectorType } from '@logto/connector-types'; -export interface ConnectorMetadata { - id: string; - type: ConnectorType; - name: Record; - logo: string; - description: Record; - readme: string; - configTemplate: string; -} export interface ConnectorDTO extends Connector { metadata: ConnectorMetadata; } diff --git a/packages/schemas/tables/connectors.sql b/packages/schemas/tables/connectors.sql index b8ec238a4..35b5265c5 100644 --- a/packages/schemas/tables/connectors.sql +++ b/packages/schemas/tables/connectors.sql @@ -1,8 +1,6 @@ -create type connector_type as enum ('Email', 'SMS', 'Social'); - create table connectors ( id varchar(128) not null, - type connector_type not null, + type varchar(64) not null, enabled boolean not null default FALSE, config jsonb /* @use ArbitraryObject */ not null default '{}'::jsonb, created_at timestamptz not null default(now()), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5963f7875..2776b9e44 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,14 +61,12 @@ importers: specifiers: '@jest/types': ^27.5.1 '@logto/phrases': ^0.1.0 - '@logto/schemas': ^0.1.0 '@shopify/jest-koa-mocks': ^3.0.8 '@silverhand/eslint-config': ^0.10.2 '@silverhand/essentials': ^1.1.6 '@silverhand/ts-config': ^0.10.2 '@types/jest': ^27.4.1 eslint: ^8.10.0 - got: ^11.8.2 jest: ^27.5.1 jest-matcher-specific-error: ^1.0.0 lint-staged: ^11.1.1 @@ -77,8 +75,6 @@ importers: typescript: ^4.6.2 dependencies: '@logto/phrases': link:../phrases - '@logto/schemas': link:../schemas - got: 11.8.3 devDependencies: '@jest/types': 27.5.1 '@shopify/jest-koa-mocks': 3.0.8 @@ -397,6 +393,7 @@ importers: packages/schemas: specifiers: + '@logto/connector-types': ^0.1.0 '@logto/phrases': ^0.1.0 '@silverhand/eslint-config': ^0.10.2 '@silverhand/essentials': ^1.1.6 @@ -414,6 +411,7 @@ importers: typescript: ^4.6.2 zod: ^3.14.3 dependencies: + '@logto/connector-types': link:../connector-types '@logto/phrases': link:../phrases zod: 3.14.3 devDependencies: