From a710ec6ba500be600890c56356ac6a1428b57dda Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Tue, 12 Apr 2022 16:59:19 +0800 Subject: [PATCH] feat(core): add connector config json templates --- packages/core/src/__mocks__/connector.ts | 7 +++++++ .../core/src/connectors/aliyun-dm/config-template.md | 3 +++ packages/core/src/connectors/aliyun-dm/index.ts | 9 ++++++++- .../core/src/connectors/aliyun-sms/config-template.md | 3 +++ packages/core/src/connectors/aliyun-sms/index.ts | 9 ++++++++- .../core/src/connectors/facebook/config-template.md | 3 +++ packages/core/src/connectors/facebook/index.ts | 9 ++++++++- .../core/src/connectors/github/config-template.md | 3 +++ packages/core/src/connectors/github/index.ts | 9 ++++++++- .../core/src/connectors/google/config-template.md | 3 +++ packages/core/src/connectors/google/index.ts | 9 ++++++++- .../core/src/connectors/wechat/config-template.md | 3 +++ packages/core/src/connectors/wechat/index.ts | 9 ++++++++- packages/core/src/lib/passcode.test.ts | 3 ++- packages/core/src/routes/connector.test.ts | 11 +++++++++++ packages/schemas/src/types/connector.ts | 1 + 16 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 packages/core/src/connectors/aliyun-dm/config-template.md create mode 100644 packages/core/src/connectors/aliyun-sms/config-template.md create mode 100644 packages/core/src/connectors/facebook/config-template.md create mode 100644 packages/core/src/connectors/github/config-template.md create mode 100644 packages/core/src/connectors/google/config-template.md create mode 100644 packages/core/src/connectors/wechat/config-template.md diff --git a/packages/core/src/__mocks__/connector.ts b/packages/core/src/__mocks__/connector.ts index f05ef1c2e..6982f3d18 100644 --- a/packages/core/src/__mocks__/connector.ts +++ b/packages/core/src/__mocks__/connector.ts @@ -71,6 +71,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, { @@ -88,6 +89,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, { @@ -105,6 +107,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, { @@ -122,6 +125,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, { @@ -139,6 +143,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, { @@ -156,6 +161,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, { @@ -173,6 +179,7 @@ export const mockConnectorInstanceList: Array<{ logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }, ]; diff --git a/packages/core/src/connectors/aliyun-dm/config-template.md b/packages/core/src/connectors/aliyun-dm/config-template.md new file mode 100644 index 000000000..52ea1f659 --- /dev/null +++ b/packages/core/src/connectors/aliyun-dm/config-template.md @@ -0,0 +1,3 @@ +{ + // placeholder +} diff --git a/packages/core/src/connectors/aliyun-dm/index.ts b/packages/core/src/connectors/aliyun-dm/index.ts index ac593ea37..3fbdcecd9 100644 --- a/packages/core/src/connectors/aliyun-dm/index.ts +++ b/packages/core/src/connectors/aliyun-dm/index.ts @@ -17,8 +17,12 @@ 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 currentPath = __dirname; +const pathToReadmeFile = path.join(currentPath, 'README.md'); +const pathToConfigTemplate = path.join(currentPath, 'config-template.md'); const readmeContentFallback = 'Please check README.md file directory.'; +const configTemplateFallback = 'Please check config-template.md file directory.'; + export const metadata: ConnectorMetadata = { id: 'aliyun-dm', type: ConnectorType.Email, @@ -36,6 +40,9 @@ export const metadata: ConnectorMetadata = { readme: existsSync(pathToReadmeFile) ? readFileSync(pathToReadmeFile, 'utf8') : readmeContentFallback, + configTemplate: existsSync(pathToConfigTemplate) + ? readFileSync(pathToConfigTemplate, 'utf-8') + : configTemplateFallback, }; /** diff --git a/packages/core/src/connectors/aliyun-sms/config-template.md b/packages/core/src/connectors/aliyun-sms/config-template.md new file mode 100644 index 000000000..52ea1f659 --- /dev/null +++ b/packages/core/src/connectors/aliyun-sms/config-template.md @@ -0,0 +1,3 @@ +{ + // placeholder +} diff --git a/packages/core/src/connectors/aliyun-sms/index.ts b/packages/core/src/connectors/aliyun-sms/index.ts index dbb747c9e..95b2a16bf 100644 --- a/packages/core/src/connectors/aliyun-sms/index.ts +++ b/packages/core/src/connectors/aliyun-sms/index.ts @@ -17,8 +17,12 @@ 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 currentPath = __dirname; +const pathToReadmeFile = path.join(currentPath, 'README.md'); +const pathToConfigTemplate = path.join(currentPath, 'config-template.md'); const readmeContentFallback = 'Please check README.md file directory.'; +const configTemplateFallback = 'Please check config-template.md file directory.'; + export const metadata: ConnectorMetadata = { id: 'aliyun-sms', type: ConnectorType.SMS, @@ -36,6 +40,9 @@ export const metadata: ConnectorMetadata = { readme: existsSync(pathToReadmeFile) ? readFileSync(pathToReadmeFile, 'utf8') : readmeContentFallback, + configTemplate: existsSync(pathToConfigTemplate) + ? readFileSync(pathToConfigTemplate, 'utf-8') + : configTemplateFallback, }; /** diff --git a/packages/core/src/connectors/facebook/config-template.md b/packages/core/src/connectors/facebook/config-template.md new file mode 100644 index 000000000..52ea1f659 --- /dev/null +++ b/packages/core/src/connectors/facebook/config-template.md @@ -0,0 +1,3 @@ +{ + // placeholder +} diff --git a/packages/core/src/connectors/facebook/index.ts b/packages/core/src/connectors/facebook/index.ts index 057b9fb0e..640d413a7 100644 --- a/packages/core/src/connectors/facebook/index.ts +++ b/packages/core/src/connectors/facebook/index.ts @@ -29,8 +29,12 @@ import { getConnectorConfig, getConnectorRequestTimeout } from '@/connectors/uti import assertThat from '@/utils/assert-that'; // eslint-disable-next-line unicorn/prefer-module -const pathToReadmeFile = path.join(__dirname, 'README.md'); +const currentPath = __dirname; +const pathToReadmeFile = path.join(currentPath, 'README.md'); +const pathToConfigTemplate = path.join(currentPath, 'config-template.md'); const readmeContentFallback = 'Please check README.md file directory.'; +const configTemplateFallback = 'Please check config-template.md file directory.'; + export const metadata: ConnectorMetadata = { id: 'facebook', type: ConnectorType.Social, @@ -47,6 +51,9 @@ export const metadata: ConnectorMetadata = { readme: existsSync(pathToReadmeFile) ? readFileSync(pathToReadmeFile, 'utf8') : readmeContentFallback, + configTemplate: existsSync(pathToConfigTemplate) + ? readFileSync(pathToConfigTemplate, 'utf-8') + : configTemplateFallback, }; const facebookConfigGuard = z.object({ diff --git a/packages/core/src/connectors/github/config-template.md b/packages/core/src/connectors/github/config-template.md new file mode 100644 index 000000000..52ea1f659 --- /dev/null +++ b/packages/core/src/connectors/github/config-template.md @@ -0,0 +1,3 @@ +{ + // placeholder +} diff --git a/packages/core/src/connectors/github/index.ts b/packages/core/src/connectors/github/index.ts index 37d068aca..824d36daf 100644 --- a/packages/core/src/connectors/github/index.ts +++ b/packages/core/src/connectors/github/index.ts @@ -21,8 +21,12 @@ 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 currentPath = __dirname; +const pathToReadmeFile = path.join(currentPath, 'README.md'); +const pathToConfigTemplate = path.join(currentPath, 'config-template.md'); const readmeContentFallback = 'Please check README.md file directory.'; +const configTemplateFallback = 'Please check config-template.md file directory.'; + export const metadata: ConnectorMetadata = { id: 'github', type: ConnectorType.Social, @@ -38,6 +42,9 @@ export const metadata: ConnectorMetadata = { readme: existsSync(pathToReadmeFile) ? readFileSync(pathToReadmeFile, 'utf8') : readmeContentFallback, + configTemplate: existsSync(pathToConfigTemplate) + ? readFileSync(pathToConfigTemplate, 'utf-8') + : configTemplateFallback, }; const githubConfigGuard = z.object({ diff --git a/packages/core/src/connectors/google/config-template.md b/packages/core/src/connectors/google/config-template.md new file mode 100644 index 000000000..52ea1f659 --- /dev/null +++ b/packages/core/src/connectors/google/config-template.md @@ -0,0 +1,3 @@ +{ + // placeholder +} diff --git a/packages/core/src/connectors/google/index.ts b/packages/core/src/connectors/google/index.ts index c7ec0cf6a..5a16b07fb 100644 --- a/packages/core/src/connectors/google/index.ts +++ b/packages/core/src/connectors/google/index.ts @@ -26,8 +26,12 @@ 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 currentPath = __dirname; +const pathToReadmeFile = path.join(currentPath, 'README.md'); +const pathToConfigTemplate = path.join(currentPath, 'config-template.md'); const readmeContentFallback = 'Please check README.md file directory.'; +const configTemplateFallback = 'Please check config-template.md file directory.'; + export const metadata: ConnectorMetadata = { id: 'google', type: ConnectorType.Social, @@ -44,6 +48,9 @@ export const metadata: ConnectorMetadata = { readme: existsSync(pathToReadmeFile) ? readFileSync(pathToReadmeFile, 'utf8') : readmeContentFallback, + configTemplate: existsSync(pathToConfigTemplate) + ? readFileSync(pathToConfigTemplate, 'utf-8') + : configTemplateFallback, }; const googleConfigGuard = z.object({ diff --git a/packages/core/src/connectors/wechat/config-template.md b/packages/core/src/connectors/wechat/config-template.md new file mode 100644 index 000000000..52ea1f659 --- /dev/null +++ b/packages/core/src/connectors/wechat/config-template.md @@ -0,0 +1,3 @@ +{ + // placeholder +} diff --git a/packages/core/src/connectors/wechat/index.ts b/packages/core/src/connectors/wechat/index.ts index 44f7c7ef4..e2812e68c 100644 --- a/packages/core/src/connectors/wechat/index.ts +++ b/packages/core/src/connectors/wechat/index.ts @@ -25,8 +25,12 @@ import { getConnectorConfig, getConnectorRequestTimeout } from '../utilities'; import { authorizationEndpoint, accessTokenEndpoint, userInfoEndpoint, scope } from './constant'; // eslint-disable-next-line unicorn/prefer-module -const pathToReadmeFile = path.join(__dirname, 'README.md'); +const currentPath = __dirname; +const pathToReadmeFile = path.join(currentPath, 'README.md'); +const pathToConfigTemplate = path.join(currentPath, 'config-template.md'); const readmeContentFallback = 'Please check README.md file directory.'; +const configTemplateFallback = 'Please check config-template.md file directory.'; + export const metadata: ConnectorMetadata = { id: 'wechat', type: ConnectorType.Social, @@ -43,6 +47,9 @@ export const metadata: ConnectorMetadata = { readme: existsSync(pathToReadmeFile) ? readFileSync(pathToReadmeFile, 'utf8') : readmeContentFallback, + configTemplate: existsSync(pathToConfigTemplate) + ? readFileSync(pathToConfigTemplate, 'utf-8') + : configTemplateFallback, }; // As creating a WeChat Web/Mobile application needs a real App or Website record, the real test is temporarily not finished. diff --git a/packages/core/src/lib/passcode.test.ts b/packages/core/src/lib/passcode.test.ts index 240bd3437..be7fd2a5e 100644 --- a/packages/core/src/lib/passcode.test.ts +++ b/packages/core/src/lib/passcode.test.ts @@ -135,7 +135,8 @@ describe('sendPasscode', () => { name: {}, logo: '', description: {}, - readme: '', + readme: 'README.md', + configTemplate: 'config-template.md', }, sendMessage, validateConfig: jest.fn(), diff --git a/packages/core/src/routes/connector.test.ts b/packages/core/src/routes/connector.test.ts index 327ce8a92..46e2f01d6 100644 --- a/packages/core/src/routes/connector.test.ts +++ b/packages/core/src/routes/connector.test.ts @@ -200,6 +200,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: jest.fn(), }; @@ -221,6 +222,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }); expect(response).toHaveProperty('statusCode', 200); @@ -243,6 +245,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: async () => { throw new ConnectorError(ConnectorErrorCodes.InvalidConfig); @@ -272,6 +275,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }; }); @@ -315,6 +319,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: jest.fn(), }; @@ -374,6 +379,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: async () => { throw new ConnectorError(ConnectorErrorCodes.InvalidConfig); @@ -403,6 +409,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, }; }); @@ -483,6 +490,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: async () => { throw new ConnectorError(ConnectorErrorCodes.InvalidConfig); @@ -512,6 +520,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: jest.fn(), }; @@ -560,6 +569,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: jest.fn(), sendMessage: async ( @@ -605,6 +615,7 @@ describe('connector route', () => { logo: './logo.png', description: {}, readme: 'README.md', + configTemplate: 'config-template.md', }, validateConfig: jest.fn(), sendMessage: async ( diff --git a/packages/schemas/src/types/connector.ts b/packages/schemas/src/types/connector.ts index b78c2865c..858c2d39c 100644 --- a/packages/schemas/src/types/connector.ts +++ b/packages/schemas/src/types/connector.ts @@ -9,6 +9,7 @@ export interface ConnectorMetadata { logo: string; description: Record; readme: string; + configTemplate: string; } export interface ConnectorDTO extends Connector { metadata: ConnectorMetadata;