0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

Merge pull request #642 from logto-io/yemq-extract-connector-types

feat(core): wrap @logto/shared and @logto/connector-types
This commit is contained in:
Darcy Ye 2022-04-24 21:53:08 +08:00 committed by GitHub
commit 2f04d59278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 402 additions and 31 deletions

View file

@ -0,0 +1,44 @@
{
"name": "@logto/connector-types",
"version": "0.1.0",
"main": "lib/index.js",
"author": "Logto Team",
"license": "MPL-2.0",
"files": [
"lib"
],
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
"precommit": "lint-staged",
"build": "rm -rf lib/ && tsc --p tsconfig.build.json",
"lint": "eslint --ext .ts src",
"lint:report": "pnpm lint -- --format json --output-file report.json",
"prepack": "pnpm build"
},
"engines": {
"node": "^16.0.0"
},
"dependencies": {
"@logto/phrases": "^0.1.0"
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@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",
"jest": "^27.5.1",
"jest-matcher-specific-error": "^1.0.0",
"lint-staged": "^11.1.1",
"prettier": "^2.3.2",
"ts-jest": "^27.1.1",
"typescript": "^4.6.2"
},
"eslintConfig": {
"extends": "@silverhand"
},
"prettier": "@silverhand/eslint-config/.prettierrc"
}

View file

@ -0,0 +1,107 @@
import type { Languages } from '@logto/phrases';
export enum ConnectorType {
Email = 'Email',
SMS = 'SMS',
Social = 'Social',
}
export interface ConnectorMetadata {
id: string;
type: ConnectorType;
name: Record<Languages, string>;
logo: string;
description: Record<Languages, string>;
readme: string;
configTemplate: string;
}
export enum ConnectorErrorCodes {
General,
InsufficientRequestParameters,
InvalidConfig,
InvalidResponse,
TemplateNotFound,
SocialAuthCodeInvalid,
SocialAccessTokenInvalid,
}
export class ConnectorError extends Error {
public code: ConnectorErrorCodes;
constructor(code: ConnectorErrorCodes, message?: string) {
super(message);
this.code = code;
}
}
export type EmailMessageTypes = {
SignIn: {
code: string;
};
Register: {
code: string;
};
ForgotPassword: {
code: string;
};
Test: Record<string, unknown>;
};
type SmsMessageTypes = EmailMessageTypes;
export type SendEmailResponse = { EnvId: string; RequestId: string };
export type SendSmsResponse = { BizId: string; Code: string; Message: string; RequestId: string };
export type EmailSendMessageFunction<T = Record<string, unknown>> = (
address: string,
type: keyof EmailMessageTypes,
payload: EmailMessageTypes[typeof type]
) => Promise<T>;
export type SmsSendMessageFunction<T = Record<string, unknown>> = (
phone: string,
type: keyof SmsMessageTypes,
payload: SmsMessageTypes[typeof type]
) => Promise<T>;
export interface BaseConnector {
metadata: ConnectorMetadata;
validateConfig: ValidateConfig;
getConfig: GetConnectorConfig;
}
export interface SmsConnector extends BaseConnector {
sendMessage: SmsSendMessageFunction;
}
export interface EmailConnector extends BaseConnector {
sendMessage: EmailSendMessageFunction;
}
export interface SocialConnector extends BaseConnector {
getAuthorizationUri: GetAuthorizationUri;
getAccessToken: GetAccessToken;
getUserInfo: GetUserInfo;
getRequestTimeout?: GetTimeout;
getTimestamp?: GetTimestamp;
}
export type ValidateConfig<T = Record<string, unknown>> = (config: T) => Promise<void>;
export type GetAuthorizationUri = (redirectUri: string, state: string) => Promise<string>;
export type AccessTokenObject = { accessToken: string } & Record<string, string>;
export type GetAccessToken = (code: string, redirectUri?: string) => Promise<AccessTokenObject>;
export type GetUserInfo = (
accessTokenObject: AccessTokenObject
) => Promise<{ id: string } & Record<string, string | undefined>>;
export type GetConnectorConfig<T = Record<string, unknown>> = (id: string) => Promise<T>;
export type GetTimeout = () => Promise<number>;
export type GetTimestamp = () => string;

View file

@ -0,0 +1,5 @@
{
"extends": "./tsconfig",
"include": ["src"],
"exclude": ["src/**/*.test.ts"]
}

View file

@ -0,0 +1,11 @@
{
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"]
}

View file

@ -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"
}

View file

@ -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<CreateConnector> = z.object({
id: z.string(),
type: z.nativeEnum(ConnectorType),
type: z.string(),
enabled: z.boolean().optional(),
config: arbitraryObjectGuard.optional(),
createdAt: z.number().optional(),

View file

@ -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',

View file

@ -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<Languages, string>;
logo: string;
description: Record<Languages, string>;
readme: string;
configTemplate: string;
}
export interface ConnectorDTO extends Connector {
metadata: ConnectorMetadata;
}

View file

@ -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()),

View file

@ -0,0 +1,36 @@
{
"name": "@logto/shared",
"version": "0.1.0",
"main": "lib/index.js",
"author": "Logto Team",
"license": "MPL-2.0",
"files": [
"lib"
],
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
"precommit": "lint-staged",
"build": "rm -rf lib/ && tsc --p tsconfig.build.json",
"lint": "eslint --ext .ts src",
"lint:report": "pnpm lint -- --format json --output-file report.json",
"prepack": "pnpm build"
},
"engines": {
"node": "^16.0.0"
},
"devDependencies": {
"@silverhand/eslint-config": "^0.10.2",
"@silverhand/essentials": "^1.1.6",
"@silverhand/ts-config": "^0.10.2",
"@types/node": "^16.3.1",
"eslint": "^8.10.0",
"lint-staged": "^11.1.1",
"prettier": "^2.3.2",
"typescript": "^4.6.2"
},
"eslintConfig": {
"extends": "@silverhand"
},
"prettier": "@silverhand/eslint-config/.prettierrc"
}

View file

@ -0,0 +1,9 @@
import { existsSync, readFileSync } from 'fs';
export const getFileContents = (filePath: string, fallbackContent: string): string => {
if (existsSync(filePath)) {
return readFileSync(filePath, 'utf8');
}
return fallbackContent;
};

View file

@ -0,0 +1,5 @@
{
"extends": "./tsconfig",
"include": ["src"],
"exclude": ["src/**/*.test.ts"]
}

View file

@ -0,0 +1,11 @@
{
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"]
}

View file

@ -57,6 +57,39 @@ importers:
ts-node: 10.4.0_e6a8a9b497f380f485f6d23f5cd591ca
typescript: 4.6.3
packages/connector-types:
specifiers:
'@jest/types': ^27.5.1
'@logto/phrases': ^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
jest: ^27.5.1
jest-matcher-specific-error: ^1.0.0
lint-staged: ^11.1.1
prettier: ^2.3.2
ts-jest: ^27.1.1
typescript: ^4.6.2
dependencies:
'@logto/phrases': link:../phrases
devDependencies:
'@jest/types': 27.5.1
'@shopify/jest-koa-mocks': 3.0.8
'@silverhand/eslint-config': 0.10.2_bbe1a6794670f389df81805f22999709
'@silverhand/essentials': 1.1.7
'@silverhand/ts-config': 0.10.2_typescript@4.6.3
'@types/jest': 27.4.1
eslint: 8.10.0
jest: 27.5.1
jest-matcher-specific-error: 1.0.0
lint-staged: 11.2.6
prettier: 2.5.1
ts-jest: 27.1.1_9985e1834e803358b7be1e6ce5ca0eea
typescript: 4.6.3
packages/console:
specifiers:
'@logto/phrases': ^0.1.0
@ -360,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
@ -377,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:
@ -395,6 +430,26 @@ importers:
ts-node: 10.4.0_64c593b7451d264b48ef412e6cb0ba64
typescript: 4.6.2
packages/shared:
specifiers:
'@silverhand/eslint-config': ^0.10.2
'@silverhand/essentials': ^1.1.6
'@silverhand/ts-config': ^0.10.2
'@types/node': ^16.3.1
eslint: ^8.10.0
lint-staged: ^11.1.1
prettier: ^2.3.2
typescript: ^4.6.2
devDependencies:
'@silverhand/eslint-config': 0.10.2_bbe1a6794670f389df81805f22999709
'@silverhand/essentials': 1.1.7
'@silverhand/ts-config': 0.10.2_typescript@4.6.3
'@types/node': 16.11.12
eslint: 8.10.0
lint-staged: 11.2.6
prettier: 2.5.1
typescript: 4.6.3
packages/ui:
specifiers:
'@logto/jest-config': ^0.1.0
@ -6655,6 +6710,11 @@ packages:
string-width: 4.2.3
dev: true
/ansi-colors/4.1.1:
resolution: {integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==}
engines: {node: '>=6'}
dev: true
/ansi-escapes/4.3.2:
resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==}
engines: {node: '>=8'}
@ -6822,7 +6882,6 @@ packages:
/asap/2.0.6:
resolution: {integrity: sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=}
dev: true
/asn1/0.2.6:
resolution: {integrity: sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==}
@ -7771,6 +7830,10 @@ packages:
resolution: {integrity: sha512-Uqbg+J445nc1TKn4FoDPS6ZZqAvEDnwrH42yo8B40JSOgSLxMZ/gt3h4nmCtPLQeXhjJJkqBx7SCY35WnIixaQ==}
dev: true
/colorette/1.4.0:
resolution: {integrity: sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==}
dev: true
/colorette/2.0.16:
resolution: {integrity: sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==}
dev: true
@ -8520,6 +8583,19 @@ packages:
dependencies:
ms: 2.1.2
/debug/4.3.3_supports-color@8.1.1:
resolution: {integrity: sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.2
supports-color: 8.1.1
dev: true
/debug/4.3.3_supports-color@9.2.2:
resolution: {integrity: sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==}
engines: {node: '>=6.0'}
@ -9006,6 +9082,13 @@ packages:
tapable: 2.2.1
dev: true
/enquirer/2.3.6:
resolution: {integrity: sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==}
engines: {node: '>=8.6'}
dependencies:
ansi-colors: 4.1.1
dev: true
/entities/1.1.2:
resolution: {integrity: sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==}
dev: true
@ -11274,12 +11357,6 @@ packages:
ci-info: 2.0.0
dev: true
/is-core-module/2.8.0:
resolution: {integrity: sha512-vd15qHsaqrRL7dtH6QNuy0ndJmRDrS9HAM1CAiSifNUFv4x1a0CCVsj18hJ1mShxIG6T2i1sO78MkP56r0nYRw==}
dependencies:
has: 1.0.3
dev: true
/is-core-module/2.8.1:
resolution: {integrity: sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==}
dependencies:
@ -12661,6 +12738,26 @@ packages:
/lines-and-columns/1.2.4:
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
/lint-staged/11.2.6:
resolution: {integrity: sha512-Vti55pUnpvPE0J9936lKl0ngVeTdSZpEdTNhASbkaWX7J5R9OEifo1INBGQuGW4zmy6OG+TcWPJ3m5yuy5Q8Tg==}
hasBin: true
dependencies:
cli-truncate: 2.1.0
colorette: 1.4.0
commander: 8.3.0
cosmiconfig: 7.0.1
debug: 4.3.3_supports-color@8.1.1
enquirer: 2.3.6
execa: 5.1.1
listr2: 3.14.0_enquirer@2.3.6
micromatch: 4.0.5
normalize-path: 3.0.0
please-upgrade-node: 3.2.0
string-argv: 0.3.1
stringify-object: 3.3.0
supports-color: 8.1.1
dev: true
/lint-staged/12.4.0:
resolution: {integrity: sha512-3X7MR0h9b7qf4iXf/1n7RlVAx+EzpAZXoCEMhVSpaBlgKDfH2ewf+QUm7BddFyq29v4dgPP+8+uYpWuSWx035A==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@ -12684,6 +12781,26 @@ packages:
- enquirer
dev: true
/listr2/3.14.0_enquirer@2.3.6:
resolution: {integrity: sha512-TyWI8G99GX9GjE54cJ+RrNMcIFBfwMPxc3XTFiAYGN4s10hWROGtOg7+O6u6LE3mNkyld7RSLE6nrKBvTfcs3g==}
engines: {node: '>=10.0.0'}
peerDependencies:
enquirer: '>= 2.3.0 < 3'
peerDependenciesMeta:
enquirer:
optional: true
dependencies:
cli-truncate: 2.1.0
colorette: 2.0.16
enquirer: 2.3.6
log-update: 4.0.0
p-map: 4.0.0
rfdc: 1.3.0
rxjs: 7.5.5
through: 2.3.8
wrap-ansi: 7.0.0
dev: true
/listr2/4.0.5:
resolution: {integrity: sha512-juGHV1doQdpNT3GSTs9IUN43QJb7KHdF9uqg7Vufs/tG9VTzpFphqF4pm/ICdAABGQxsyNn9CiYA3StkI6jpwA==}
engines: {node: '>=12'}
@ -14985,6 +15102,12 @@ packages:
find-up: 3.0.0
dev: true
/please-upgrade-node/3.2.0:
resolution: {integrity: sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==}
dependencies:
semver-compare: 1.0.0
dev: true
/pluralize/8.0.0:
resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==}
engines: {node: '>=4'}
@ -17325,7 +17448,6 @@ packages:
/semver-compare/1.0.0:
resolution: {integrity: sha1-De4hahyUGrN+nvsXiPavxf9VN/w=}
dev: false
/semver-diff/3.1.1:
resolution: {integrity: sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==}
@ -18699,6 +18821,40 @@ packages:
yargs-parser: 20.2.9
dev: true
/ts-jest/27.1.1_9985e1834e803358b7be1e6ce5ca0eea:
resolution: {integrity: sha512-Ds0VkB+cB+8g2JUmP/GKWndeZcCKrbe6jzolGrVWdqVUFByY/2KDHqxJ7yBSon7hDB1TA4PXxjfZ+JjzJisvgA==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
hasBin: true
peerDependencies:
'@babel/core': '>=7.0.0-beta.0 <8'
'@types/jest': ^27.0.0
babel-jest: '>=27.0.0 <28'
esbuild: ~0.14.0
jest: ^27.0.0
typescript: '>=3.8 <5.0'
peerDependenciesMeta:
'@babel/core':
optional: true
'@types/jest':
optional: true
babel-jest:
optional: true
esbuild:
optional: true
dependencies:
'@types/jest': 27.4.1
bs-logger: 0.2.6
fast-json-stable-stringify: 2.1.0
jest: 27.5.1
jest-util: 27.5.1
json5: 2.2.1
lodash.memoize: 4.1.2
make-error: 1.3.6
semver: 7.3.5
typescript: 4.6.3
yargs-parser: 20.2.9
dev: true
/ts-jest/27.1.1_jest@27.5.1+typescript@4.6.3:
resolution: {integrity: sha512-Ds0VkB+cB+8g2JUmP/GKWndeZcCKrbe6jzolGrVWdqVUFByY/2KDHqxJ7yBSon7hDB1TA4PXxjfZ+JjzJisvgA==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}