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

refactor(connector-*): load config template and readme contents while initialization ()

This commit is contained in:
Darcy Ye 2022-06-27 10:00:37 +08:00 committed by GitHub
parent 5fb74537a8
commit 8da9add6b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 70 additions and 167 deletions
packages
connector-alipay-native
connector-alipay
connector-aliyun-dm
connector-aliyun-sms
connector-apple
connector-facebook
connector-github
connector-google
connector-sendgrid-mail
connector-smtp
connector-twilio-sms
connector-wechat-native
connector-wechat
core/src/connectors

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,7 +1,4 @@
import path from 'path';
import { ConnectorType, ConnectorMetadata, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const authorizationEndpoint = 'alipay://'; // This is used to arouse the native Alipay App
export const alipayEndpoint = 'https://openapi.alipay.com/gateway.do';
@ -14,13 +11,6 @@ export const alipaySigningAlgorithmMapping = {
} as const;
export const alipaySigningAlgorithms = ['RSA', 'RSA2'] as const;
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'alipay-native',
target: 'alipay',
@ -36,8 +26,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Allow your users to sign in through their Alipay account.',
'zh-CN': '让用户可以通过支付宝账号登录。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"private": false,
"scripts": {

View file

@ -1,7 +1,4 @@
import path from 'path';
import { ConnectorType, ConnectorMetadata, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const authorizationEndpoint = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm';
export const alipayEndpoint = 'https://openapi.alipay.com/gateway.do';
@ -15,13 +12,6 @@ export const alipaySigningAlgorithmMapping = {
} as const;
export const alipaySigningAlgorithms = ['RSA', 'RSA2'] as const;
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'alipay-web',
target: 'alipay',
@ -37,8 +27,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Allow your users to sign in through their Alipay account.',
'zh-CN': '让用户可以通过支付宝账号登录。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,7 +1,4 @@
import path from 'path';
import { ConnectorType, ConnectorMetadata } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const endpoint = 'https://dm.aliyuncs.com/';
@ -12,13 +9,6 @@ export const staticConfigs = {
Version: '2015-11-23',
};
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'aliyun-direct-mail',
target: 'aliyun-dm',
@ -35,6 +25,6 @@ export const defaultMetadata: ConnectorMetadata = {
'zh-CN':
'邮件推送DirectMail是款简单高效的电子邮件群发服务构建在阿里云基础之上帮您快速、精准地实现事务邮件、通知邮件和批量邮件的发送。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,7 +1,4 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const endpoint = 'https://dysmsapi.aliyuncs.com/';
@ -28,13 +25,6 @@ export enum SmsTemplateType {
PureNumber = 7,
}
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'aliyun-short-message-service',
target: 'aliyun-sms',
@ -51,6 +41,6 @@ export const defaultMetadata: ConnectorMetadata = {
'zh-CN':
'短信服务Short Message Service是指通过调用短信发送API将指定短信内容发送给指定手机用户。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};

View file

@ -10,6 +10,7 @@
"lib",
"docs",
"logo.svg",
"README.md",
"logo-dark.svg"
],
"scripts": {

View file

@ -1,7 +1,4 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
// https://appleid.apple.com/.well-known/openid-configuration
export const issuer = 'https://appleid.apple.com';
@ -12,13 +9,6 @@ export const jwksUri = `${issuer}/auth/keys`;
// Note: only support fixed scope for v1.
export const scope = ''; // Note: `openid` is required when adding more scope(s)
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'apple-universal',
target: 'apple',
@ -34,8 +24,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Enables users to sign in to the Logto app through their Apple account.',
'zh-CN': '让用户能够通过 Apple 账号登录 Logto 应用。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,7 +1,4 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
/**
* Note: If you do not include a version number we will default to the oldest available version, so it's recommended to include the version number in your requests.
@ -17,13 +14,6 @@ export const accessTokenEndpoint = 'https://graph.facebook.com/v13.0/oauth/acces
export const userInfoEndpoint = 'https://graph.facebook.com/v13.0/me';
export const scope = 'email,public_profile';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'facebook-universal',
target: 'facebook',
@ -39,8 +29,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Provide users with the option to sign in with their Facebook account.',
'zh-CN': '为用户提供 Facebook 账号登录的选项。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -10,6 +10,7 @@
"lib",
"docs",
"logo.svg",
"README.md",
"logo-dark.svg"
],
"scripts": {

View file

@ -1,20 +1,10 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const authorizationEndpoint = 'https://github.com/login/oauth/authorize';
export const scope = 'read:user';
export const accessTokenEndpoint = 'https://github.com/login/oauth/access_token';
export const userInfoEndpoint = 'https://api.github.com/user';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'github-universal',
target: 'github',
@ -30,8 +20,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Make signing into Logto seamlessly for GitHub users.',
'zh-CN': '让 GitHub 用户无缝登录 Logto。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,20 +1,10 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const authorizationEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth';
export const accessTokenEndpoint = 'https://oauth2.googleapis.com/token';
export const userInfoEndpoint = 'https://openidconnect.googleapis.com/v1/userinfo';
export const scope = 'openid profile email';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'google-universal',
target: 'google',
@ -30,8 +20,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Gives users the ability to sign in with their Google account.',
'zh-CN': '赋予用户用 Google 账号登录的能力。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,17 +1,7 @@
import path from 'path';
import { ConnectorType, ConnectorMetadata } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const endpoint = 'https://api.sendgrid.com/v3/mail/send';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'sendgrid-email-service',
target: 'sendgrid-mail',
@ -27,6 +17,6 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Leverage the email service that customer-first brands trust for reliable inbox delivery at scale.',
'zh-CN': '客户至上品牌信任的电子邮件服务,实现大规模可靠的收件箱递送。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,14 +1,4 @@
import path from 'path';
import { ConnectorType, ConnectorMetadata } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'simple-mail-transfer-protocol',
@ -25,6 +15,6 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Simple Mail Transfer Protocol.',
'zh-CN': '简单邮件传输协议。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,17 +1,7 @@
import path from 'path';
import { ConnectorType, ConnectorMetadata } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const endpoint = 'https://api.twilio.com/2010-04-01/Accounts/{{accountSID}}/Messages.json';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'twilio-short-message-service',
target: 'twilio-sms',
@ -27,6 +17,6 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Messaging APIs for reliable SMS delivery.',
'zh-CN': '可信赖的短信消息 API。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,20 +1,10 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const authorizationEndpoint = 'wechat://'; // This is used to arouse the native WeChat App
export const accessTokenEndpoint = 'https://api.weixin.qq.com/sns/oauth2/access_token';
export const userInfoEndpoint = 'https://api.weixin.qq.com/sns/userinfo';
export const scope = 'snsapi_userinfo';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'wechat-native',
target: 'wechat',
@ -30,8 +20,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Allow your users to sign in through their WeChat account.',
'zh-CN': '让用户可以通过微信账号登录。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -9,7 +9,8 @@
"files": [
"lib",
"docs",
"logo.svg"
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",

View file

@ -1,20 +1,10 @@
import path from 'path';
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
import { getFileContents } from '@logto/shared';
export const authorizationEndpoint = 'https://open.weixin.qq.com/connect/qrconnect';
export const accessTokenEndpoint = 'https://api.weixin.qq.com/sns/oauth2/access_token';
export const userInfoEndpoint = 'https://api.weixin.qq.com/sns/userinfo';
export const scope = 'snsapi_login';
// eslint-disable-next-line unicorn/prefer-module
const currentPath = __dirname;
const pathToReadmeFile = path.join(currentPath, '..', 'README.md');
const pathToConfigTemplate = path.join(currentPath, '..', 'docs', 'config-template.json');
const readmeContentFallback = 'Please check README.md file directory.';
const configTemplateFallback = 'Please check config-template.json file directory.';
export const defaultMetadata: ConnectorMetadata = {
id: 'wechat-web',
target: 'wechat',
@ -30,8 +20,8 @@ export const defaultMetadata: ConnectorMetadata = {
en: 'Allow your users to sign in through their WeChat account.',
'zh-CN': '让用户可以通过微信账号登录。',
},
readme: getFileContents(pathToReadmeFile, readmeContentFallback),
configTemplate: getFileContents(pathToConfigTemplate, configTemplateFallback),
readme: './README.md',
configTemplate: './docs/config-template.json',
};
export const defaultTimeout = 5000;

View file

@ -50,6 +50,26 @@ const loadConnectors = async () => {
instance.metadata.logoDark = `data:image/svg+xml;base64,${data.toString('base64')}`;
}
if (
packagePath &&
instance.metadata.readme &&
existsSync(path.join(packagePath, '..', instance.metadata.readme))
) {
const data = readFileSync(path.join(packagePath, '..', instance.metadata.readme));
// eslint-disable-next-line @silverhand/fp/no-mutation
instance.metadata.readme = `data:text/plain;base64,${data.toString('base64')}`;
}
if (
packagePath &&
instance.metadata.configTemplate &&
existsSync(path.join(packagePath, '..', instance.metadata.configTemplate))
) {
const data = readFileSync(path.join(packagePath, '..', instance.metadata.configTemplate));
// eslint-disable-next-line @silverhand/fp/no-mutation
instance.metadata.configTemplate = `data:text/plain;base64,${data.toString('base64')}`;
}
return instance;
})
);