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

feat(core): add README.md for connectors (#362)

* feat(core): add README.md for connectors

* feat(core): add README.md files' existence check

* feat(core): fix path of README.md
This commit is contained in:
Darcy Ye 2022-03-14 11:17:24 +08:00 committed by GitHub
parent 74d7dd6603
commit cde61b77b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,2 @@
### Aliyun DM README
placeholder

View file

@ -1,3 +1,6 @@
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { z } from 'zod';
import assertThat from '@/utils/assert-that';
@ -13,6 +16,9 @@ import {
import { getConnectorConfig } from '../utilities';
import { singleSendMail } from './single-send-mail';
// eslint-disable-next-line unicorn/prefer-module
const pathToReadmeFile = path.join(__dirname, 'README.md');
const readmeContentFallback = 'Please check README.md file directory.';
export const metadata: ConnectorMetadata = {
id: 'aliyun-dm',
type: ConnectorType.Email,
@ -27,6 +33,9 @@ export const metadata: ConnectorMetadata = {
'zh-CN':
'邮件推送DirectMail是款简单高效的电子邮件群发服务构建在阿里云基础之上帮您快速、精准地实现事务邮件、通知邮件和批量邮件的发送。',
},
readme: existsSync(pathToReadmeFile)
? readFileSync(pathToReadmeFile, 'utf8')
: readmeContentFallback,
};
/**

View file

@ -0,0 +1,2 @@
### Aliyun SMS README
placeholder

View file

@ -1,3 +1,6 @@
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { z } from 'zod';
import assertThat from '@/utils/assert-that';
@ -13,6 +16,9 @@ import {
import { getConnectorConfig } from '../utilities';
import { sendSms } from './single-send-text';
// eslint-disable-next-line unicorn/prefer-module
const pathToReadmeFile = path.join(__dirname, 'README.md');
const readmeContentFallback = 'Please check README.md file directory.';
export const metadata: ConnectorMetadata = {
id: 'aliyun-sms',
type: ConnectorType.SMS,
@ -27,6 +33,9 @@ export const metadata: ConnectorMetadata = {
'zh-CN':
'短信服务Short Message Service是指通过调用短信发送API将指定短信内容发送给指定手机用户。',
},
readme: existsSync(pathToReadmeFile)
? readFileSync(pathToReadmeFile, 'utf8')
: readmeContentFallback,
};
/**

View file

@ -0,0 +1,2 @@
### FB Social Connector README
placeholder

View file

@ -2,6 +2,9 @@
* Reference: Manually Build a Login Flow
* https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
*/
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import got, { RequestError as GotRequestError } from 'got';
import { stringify } from 'query-string';
import { z } from 'zod';
@ -25,6 +28,9 @@ import {
import { getConnectorConfig, getConnectorRequestTimeout } from '@/connectors/utilities';
import assertThat from '@/utils/assert-that';
// eslint-disable-next-line unicorn/prefer-module
const pathToReadmeFile = path.join(__dirname, 'README.md');
const readmeContentFallback = 'Please check README.md file directory.';
export const metadata: ConnectorMetadata = {
id: 'facebook',
type: ConnectorType.Social,
@ -38,6 +44,9 @@ export const metadata: ConnectorMetadata = {
en: 'Sign In with Facebook',
'zh-CN': 'Facebook 登录',
},
readme: existsSync(pathToReadmeFile)
? readFileSync(pathToReadmeFile, 'utf8')
: readmeContentFallback,
};
const facebookConfigGuard = z.object({

View file

@ -0,0 +1,2 @@
### Github Social Connector README
placeholder

View file

@ -1,3 +1,6 @@
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import got, { RequestError as GotRequestError } from 'got';
import { stringify } from 'query-string';
import { z } from 'zod';
@ -17,6 +20,9 @@ import {
import { getConnectorConfig, getConnectorRequestTimeout } from '../utilities';
import { authorizationEndpoint, accessTokenEndpoint, scope, userInfoEndpoint } from './constant';
// eslint-disable-next-line unicorn/prefer-module
const pathToReadmeFile = path.join(__dirname, 'README.md');
const readmeContentFallback = 'Please check README.md file directory.';
export const metadata: ConnectorMetadata = {
id: 'github',
type: ConnectorType.Social,
@ -29,6 +35,9 @@ export const metadata: ConnectorMetadata = {
en: 'Sign In with GitHub',
'zh-CN': 'GitHub登录',
},
readme: existsSync(pathToReadmeFile)
? readFileSync(pathToReadmeFile, 'utf8')
: readmeContentFallback,
};
const githubConfigGuard = z.object({

View file

@ -0,0 +1,2 @@
### Google Social Connector README
placeholder

View file

@ -2,6 +2,8 @@
* The Implementation of OpenID Connect of Google Identity Platform.
* https://developers.google.com/identity/protocols/oauth2/openid-connect
*/
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { conditional } from '@silverhand/essentials';
import got, { RequestError as GotRequestError } from 'got';
@ -23,6 +25,9 @@ import {
import { getConnectorConfig, getConnectorRequestTimeout } from '../utilities';
import { accessTokenEndpoint, authorizationEndpoint, scope, userInfoEndpoint } from './constant';
// eslint-disable-next-line unicorn/prefer-module
const pathToReadmeFile = path.join(__dirname, 'README.md');
const readmeContentFallback = 'Please check README.md file directory.';
export const metadata: ConnectorMetadata = {
id: 'google',
type: ConnectorType.Social,
@ -36,6 +41,9 @@ export const metadata: ConnectorMetadata = {
en: 'Sign In with Google',
'zh-CN': 'Google登录',
},
readme: existsSync(pathToReadmeFile)
? readFileSync(pathToReadmeFile, 'utf8')
: readmeContentFallback,
};
const googleConfigGuard = z.object({

View file

@ -134,6 +134,7 @@ describe('sendPasscode', () => {
name: {},
logo: '',
description: {},
readme: '',
},
sendMessage,
validateConfig: jest.fn(),

View file

@ -196,6 +196,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
};
});
@ -235,6 +236,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
};
});
@ -254,6 +256,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
});
expect(response).toHaveProperty('statusCode', 200);
@ -275,6 +278,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
};
});
@ -309,6 +313,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
});
expect(response).toHaveProperty('statusCode', 200);
@ -329,6 +334,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
};
});
@ -348,6 +354,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
});
expect(response).toHaveProperty('statusCode', 200);
@ -406,6 +413,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
validateConfig: async (_config) => {
throw new ConnectorError(ConnectorErrorCodes.InvalidConfig);
@ -433,6 +441,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
validateConfig: async (_config) => {},
@ -454,6 +463,7 @@ describe('connector route', () => {
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
});
expect(response).toHaveProperty('statusCode', 200);

View file

@ -252,6 +252,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
@ -267,6 +268,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
@ -282,6 +284,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
@ -297,6 +300,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
@ -312,6 +316,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
@ -327,6 +332,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
@ -342,6 +348,7 @@ export const mockConnectorInstanceList: Array<{
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
];

View file

@ -13,6 +13,7 @@ export interface ConnectorMetadata {
name: Record<Languages, string>;
logo: string;
description: Record<Languages, string>;
readme: string;
}
export interface ConnectorDTO extends Connector {
metadata: ConnectorMetadata;