From 5b44b7194ed4f98c6c2e77aae828a39b477b6010 Mon Sep 17 00:00:00 2001 From: Wang Sijie Date: Tue, 24 May 2022 13:54:37 +0800 Subject: [PATCH] feat(core): serve connector logo (#931) --- packages/connector-alipay-native/logo.svg | 4 ++ packages/connector-alipay-native/package.json | 3 +- .../connector-alipay-native/src/constant.ts | 2 +- .../connector-alipay-native/src/index.test.ts | 2 +- packages/connector-alipay-native/src/index.ts | 2 +- packages/connector-alipay/logo.svg | 4 ++ packages/connector-alipay/package.json | 3 +- packages/connector-alipay/src/constant.ts | 2 +- packages/connector-alipay/src/index.test.ts | 2 +- packages/connector-alipay/src/index.ts | 2 +- packages/connector-aliyun-dm/logo.svg | 3 + packages/connector-aliyun-dm/package.json | 3 +- packages/connector-aliyun-dm/src/constant.ts | 2 +- .../connector-aliyun-dm/src/index.test.ts | 2 +- packages/connector-aliyun-dm/src/index.ts | 2 +- packages/connector-aliyun-sms/logo.svg | 3 + packages/connector-aliyun-sms/package.json | 3 +- packages/connector-aliyun-sms/src/constant.ts | 2 +- .../connector-aliyun-sms/src/index.test.ts | 2 +- packages/connector-aliyun-sms/src/index.ts | 2 +- packages/connector-facebook/logo.svg | 4 ++ packages/connector-facebook/package.json | 3 +- packages/connector-facebook/src/constant.ts | 2 +- packages/connector-facebook/src/index.test.ts | 2 +- packages/connector-facebook/src/index.ts | 2 +- packages/connector-github/logo.svg | 3 + packages/connector-github/package.json | 3 +- packages/connector-github/src/constant.ts | 2 +- packages/connector-github/src/index.test.ts | 2 +- packages/connector-github/src/index.ts | 2 +- packages/connector-google/logo.svg | 6 ++ packages/connector-google/package.json | 3 +- packages/connector-google/src/constant.ts | 2 +- packages/connector-google/src/index.test.ts | 2 +- packages/connector-google/src/index.ts | 2 +- packages/connector-sendgrid-mail/logo.svg | 9 +++ packages/connector-sendgrid-mail/package.json | 3 +- .../connector-sendgrid-mail/src/constant.ts | 2 +- .../connector-sendgrid-mail/src/index.test.ts | 2 +- packages/connector-sendgrid-mail/src/index.ts | 2 +- packages/connector-twilio-sms/logo.svg | 3 + packages/connector-twilio-sms/package.json | 3 +- packages/connector-twilio-sms/src/constant.ts | 2 +- .../connector-twilio-sms/src/index.test.ts | 2 +- packages/connector-twilio-sms/src/index.ts | 2 +- packages/connector-wechat-native/logo.svg | 4 ++ packages/connector-wechat-native/package.json | 3 +- .../connector-wechat-native/src/constant.ts | 2 +- .../connector-wechat-native/src/index.test.ts | 2 +- packages/connector-wechat-native/src/index.ts | 2 +- packages/connector-wechat/logo.svg | 4 ++ packages/connector-wechat/package.json | 3 +- packages/connector-wechat/src/constant.ts | 2 +- packages/connector-wechat/src/index.test.ts | 2 +- packages/connector-wechat/src/index.ts | 2 +- .../src/pages/ConnectorDetails/index.tsx | 7 +- .../components/ConnectorName/index.tsx | 8 +-- packages/core/package.json | 5 +- packages/core/src/connectors/consts.ts | 14 ++++ packages/core/src/connectors/index.ts | 67 ++++++++++++------- pnpm-lock.yaml | 21 ++++++ 61 files changed, 185 insertions(+), 83 deletions(-) create mode 100644 packages/connector-alipay-native/logo.svg create mode 100644 packages/connector-alipay/logo.svg create mode 100644 packages/connector-aliyun-dm/logo.svg create mode 100644 packages/connector-aliyun-sms/logo.svg create mode 100644 packages/connector-facebook/logo.svg create mode 100644 packages/connector-github/logo.svg create mode 100644 packages/connector-google/logo.svg create mode 100644 packages/connector-sendgrid-mail/logo.svg create mode 100644 packages/connector-twilio-sms/logo.svg create mode 100644 packages/connector-wechat-native/logo.svg create mode 100644 packages/connector-wechat/logo.svg create mode 100644 packages/core/src/connectors/consts.ts diff --git a/packages/connector-alipay-native/logo.svg b/packages/connector-alipay-native/logo.svg new file mode 100644 index 000000000..0be4575af --- /dev/null +++ b/packages/connector-alipay-native/logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/connector-alipay-native/package.json b/packages/connector-alipay-native/package.json index eea16ed64..6c3f92066 100644 --- a/packages/connector-alipay-native/package.json +++ b/packages/connector-alipay-native/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-alipay-native/src/constant.ts b/packages/connector-alipay-native/src/constant.ts index 1d94757ee..a266f0da0 100644 --- a/packages/connector-alipay-native/src/constant.ts +++ b/packages/connector-alipay-native/src/constant.ts @@ -30,7 +30,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Alipay', 'zh-CN': '支付宝', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/alipay.svg', + logo: './logo.svg', description: { en: 'Sign In with Alipay', 'zh-CN': '支付宝登录', diff --git a/packages/connector-alipay-native/src/index.test.ts b/packages/connector-alipay-native/src/index.test.ts index 16477b9f1..794ddf10c 100644 --- a/packages/connector-alipay-native/src/index.test.ts +++ b/packages/connector-alipay-native/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { AlipayNativeConnector } from '.'; +import AlipayNativeConnector from '.'; import { alipayEndpoint } from './constant'; import { mockedAlipayNativeConfig, mockedAlipayNativeConfigWithValidPrivateKey } from './mock'; import { AlipayNativeConfig } from './types'; diff --git a/packages/connector-alipay-native/src/index.ts b/packages/connector-alipay-native/src/index.ts index 4202a6e3e..caa8477a8 100644 --- a/packages/connector-alipay-native/src/index.ts +++ b/packages/connector-alipay-native/src/index.ts @@ -41,7 +41,7 @@ import { signingParameters } from './utils'; export type { AlipayNativeConfig } from './types'; -export class AlipayNativeConnector implements SocialConnector { +export default class AlipayNativeConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; private readonly signingParameters = signingParameters; diff --git a/packages/connector-alipay/logo.svg b/packages/connector-alipay/logo.svg new file mode 100644 index 000000000..0be4575af --- /dev/null +++ b/packages/connector-alipay/logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/connector-alipay/package.json b/packages/connector-alipay/package.json index 1faeaabc2..8d2f5120d 100644 --- a/packages/connector-alipay/package.json +++ b/packages/connector-alipay/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-alipay/src/constant.ts b/packages/connector-alipay/src/constant.ts index 79909bd69..239714681 100644 --- a/packages/connector-alipay/src/constant.ts +++ b/packages/connector-alipay/src/constant.ts @@ -31,7 +31,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Alipay', 'zh-CN': '支付宝', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/alipay.svg', + logo: './logo.svg', description: { en: 'Sign In with Alipay', 'zh-CN': '支付宝登录', diff --git a/packages/connector-alipay/src/index.test.ts b/packages/connector-alipay/src/index.test.ts index 841631d2d..601670275 100644 --- a/packages/connector-alipay/src/index.test.ts +++ b/packages/connector-alipay/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { AlipayConnector } from '.'; +import AlipayConnector from '.'; import { alipayEndpoint, authorizationEndpoint } from './constant'; import { mockedAlipayConfig, mockedAlipayConfigWithValidPrivateKey } from './mock'; import { AlipayConfig } from './types'; diff --git a/packages/connector-alipay/src/index.ts b/packages/connector-alipay/src/index.ts index 58445a2e6..63e9477ce 100644 --- a/packages/connector-alipay/src/index.ts +++ b/packages/connector-alipay/src/index.ts @@ -35,7 +35,7 @@ import { signingParameters } from './utils'; export type { AlipayConfig } from './types'; -export class AlipayConnector implements SocialConnector { +export default class AlipayConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; private readonly signingParameters = signingParameters; diff --git a/packages/connector-aliyun-dm/logo.svg b/packages/connector-aliyun-dm/logo.svg new file mode 100644 index 000000000..3cff2b4f1 --- /dev/null +++ b/packages/connector-aliyun-dm/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/connector-aliyun-dm/package.json b/packages/connector-aliyun-dm/package.json index e0163369c..f5e707bd7 100644 --- a/packages/connector-aliyun-dm/package.json +++ b/packages/connector-aliyun-dm/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-aliyun-dm/src/constant.ts b/packages/connector-aliyun-dm/src/constant.ts index 86f993618..c563fb94f 100644 --- a/packages/connector-aliyun-dm/src/constant.ts +++ b/packages/connector-aliyun-dm/src/constant.ts @@ -28,7 +28,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Aliyun Direct Mail', 'zh-CN': '阿里云邮件推送', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/alibabacloud.svg', + logo: './logo.svg', description: { en: 'A simple and efficient email service to help you send transactional notifications and batch email.', 'zh-CN': diff --git a/packages/connector-aliyun-dm/src/index.test.ts b/packages/connector-aliyun-dm/src/index.test.ts index 48f5de4b1..814c23eab 100644 --- a/packages/connector-aliyun-dm/src/index.test.ts +++ b/packages/connector-aliyun-dm/src/index.test.ts @@ -1,6 +1,6 @@ import { GetConnectorConfig } from '@logto/connector-types'; -import { AliyunDmConnector } from '.'; +import AliyunDmConnector from '.'; import { mockedConfig } from './mock'; import { singleSendMail } from './single-send-mail'; import { AliyunDmConfig } from './types'; diff --git a/packages/connector-aliyun-dm/src/index.ts b/packages/connector-aliyun-dm/src/index.ts index ccaee0beb..c46c1ddab 100644 --- a/packages/connector-aliyun-dm/src/index.ts +++ b/packages/connector-aliyun-dm/src/index.ts @@ -14,7 +14,7 @@ import { defaultMetadata } from './constant'; import { singleSendMail } from './single-send-mail'; import { SendEmailResponse, AliyunDmConfig, aliyunDmConfigGuard } from './types'; -export class AliyunDmConnector implements EmailConnector { +export default class AliyunDmConnector implements EmailConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-aliyun-sms/logo.svg b/packages/connector-aliyun-sms/logo.svg new file mode 100644 index 000000000..3cff2b4f1 --- /dev/null +++ b/packages/connector-aliyun-sms/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/connector-aliyun-sms/package.json b/packages/connector-aliyun-sms/package.json index 9b3e1920b..2c0071ba5 100644 --- a/packages/connector-aliyun-sms/package.json +++ b/packages/connector-aliyun-sms/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-aliyun-sms/src/constant.ts b/packages/connector-aliyun-sms/src/constant.ts index 5ecce3c8a..9a343d02f 100644 --- a/packages/connector-aliyun-sms/src/constant.ts +++ b/packages/connector-aliyun-sms/src/constant.ts @@ -44,7 +44,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Aliyun Short Message Service', 'zh-CN': '阿里云短信服务', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/alibabacloud.svg', + logo: './logo.svg', description: { en: 'Short Message Service (SMS) has a batch sending feature and various API operations to send one-time password (OTP) messages, notification messages, and promotional messages to customers.', 'zh-CN': diff --git a/packages/connector-aliyun-sms/src/index.test.ts b/packages/connector-aliyun-sms/src/index.test.ts index e97d83423..bd4ba2c50 100644 --- a/packages/connector-aliyun-sms/src/index.test.ts +++ b/packages/connector-aliyun-sms/src/index.test.ts @@ -1,6 +1,6 @@ import { GetConnectorConfig } from '@logto/connector-types'; -import { AliyunSmsConnector } from '.'; +import AliyunSmsConnector from '.'; import { mockedConnectorConfig, mockedValidConnectorConfig, phoneTest, codeTest } from './mock'; import { sendSms } from './single-send-text'; import { AliyunSmsConfig } from './types'; diff --git a/packages/connector-aliyun-sms/src/index.ts b/packages/connector-aliyun-sms/src/index.ts index d4460f5b4..6f4a10fbc 100644 --- a/packages/connector-aliyun-sms/src/index.ts +++ b/packages/connector-aliyun-sms/src/index.ts @@ -14,7 +14,7 @@ import { defaultMetadata } from './constant'; import { sendSms } from './single-send-text'; import { aliyunSmsConfigGuard, AliyunSmsConfig, SendSmsResponse } from './types'; -export class AliyunSmsConnector implements SmsConnector { +export default class AliyunSmsConnector implements SmsConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-facebook/logo.svg b/packages/connector-facebook/logo.svg new file mode 100644 index 000000000..5b9b4b8b2 --- /dev/null +++ b/packages/connector-facebook/logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/connector-facebook/package.json b/packages/connector-facebook/package.json index 3092347ae..8a5ef2cd9 100644 --- a/packages/connector-facebook/package.json +++ b/packages/connector-facebook/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-facebook/src/constant.ts b/packages/connector-facebook/src/constant.ts index 43d07c7d9..1d3d94b1a 100644 --- a/packages/connector-facebook/src/constant.ts +++ b/packages/connector-facebook/src/constant.ts @@ -33,7 +33,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Facebook', 'zh-CN': 'Facebook', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/facebook.svg', + logo: './logo.svg', description: { en: 'Sign In with Facebook', 'zh-CN': 'Facebook 登录', diff --git a/packages/connector-facebook/src/index.test.ts b/packages/connector-facebook/src/index.test.ts index 778824431..c4e98615f 100644 --- a/packages/connector-facebook/src/index.test.ts +++ b/packages/connector-facebook/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { FacebookConnector } from '.'; +import FacebookConnector from '.'; import { accessTokenEndpoint, authorizationEndpoint, userInfoEndpoint } from './constant'; import { clientId, clientSecret, code, dummyRedirectUri, fields, mockedConfig } from './mock'; import { FacebookConfig } from './types'; diff --git a/packages/connector-facebook/src/index.ts b/packages/connector-facebook/src/index.ts index 0545a177e..46e444fb8 100644 --- a/packages/connector-facebook/src/index.ts +++ b/packages/connector-facebook/src/index.ts @@ -32,7 +32,7 @@ import { UserInfoResponse, } from './types'; -export class FacebookConnector implements SocialConnector { +export default class FacebookConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-github/logo.svg b/packages/connector-github/logo.svg new file mode 100644 index 000000000..9e55f1616 --- /dev/null +++ b/packages/connector-github/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/connector-github/package.json b/packages/connector-github/package.json index be6c5cd73..5960bdaa3 100644 --- a/packages/connector-github/package.json +++ b/packages/connector-github/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-github/src/constant.ts b/packages/connector-github/src/constant.ts index bf92a4894..2bccb45e0 100644 --- a/packages/connector-github/src/constant.ts +++ b/packages/connector-github/src/constant.ts @@ -24,7 +24,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'GitHub', 'zh-CN': 'GitHub', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/github.svg', + logo: './logo.svg', description: { en: 'Sign In with GitHub', 'zh-CN': 'GitHub登录', diff --git a/packages/connector-github/src/index.test.ts b/packages/connector-github/src/index.test.ts index 5993a2746..e9ed869e1 100644 --- a/packages/connector-github/src/index.test.ts +++ b/packages/connector-github/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { GithubConnector } from '.'; +import GithubConnector from '.'; import { accessTokenEndpoint, authorizationEndpoint, userInfoEndpoint } from './constant'; import { mockedConfig } from './mock'; import { GithubConfig } from './types'; diff --git a/packages/connector-github/src/index.ts b/packages/connector-github/src/index.ts index 31766138d..b7ae4aedc 100644 --- a/packages/connector-github/src/index.ts +++ b/packages/connector-github/src/index.ts @@ -22,7 +22,7 @@ import { } from './constant'; import { githubConfigGuard, AccessTokenResponse, GithubConfig, UserInfoResponse } from './types'; -export class GithubConnector implements SocialConnector { +export default class GithubConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-google/logo.svg b/packages/connector-google/logo.svg new file mode 100644 index 000000000..142b86244 --- /dev/null +++ b/packages/connector-google/logo.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/packages/connector-google/package.json b/packages/connector-google/package.json index fd5875a1c..ba73312cc 100644 --- a/packages/connector-google/package.json +++ b/packages/connector-google/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-google/src/constant.ts b/packages/connector-google/src/constant.ts index 084105ebc..4ed878009 100644 --- a/packages/connector-google/src/constant.ts +++ b/packages/connector-google/src/constant.ts @@ -24,7 +24,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Google', 'zh-CN': 'Google', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/google.svg', + logo: './logo.svg', description: { en: 'Sign In with Google', 'zh-CN': 'Google登录', diff --git a/packages/connector-google/src/index.test.ts b/packages/connector-google/src/index.test.ts index 1ad54efbf..b79813966 100644 --- a/packages/connector-google/src/index.test.ts +++ b/packages/connector-google/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { GoogleConnector } from '.'; +import GoogleConnector from '.'; import { accessTokenEndpoint, authorizationEndpoint, userInfoEndpoint } from './constant'; import { mockedConfig } from './mock'; import { GoogleConfig } from './types'; diff --git a/packages/connector-google/src/index.ts b/packages/connector-google/src/index.ts index b99c8d387..e49536fd7 100644 --- a/packages/connector-google/src/index.ts +++ b/packages/connector-google/src/index.ts @@ -26,7 +26,7 @@ import { } from './constant'; import { googleConfigGuard, AccessTokenResponse, GoogleConfig, UserInfoResponse } from './types'; -export class GoogleConnector implements SocialConnector { +export default class GoogleConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-sendgrid-mail/logo.svg b/packages/connector-sendgrid-mail/logo.svg new file mode 100644 index 000000000..83810368d --- /dev/null +++ b/packages/connector-sendgrid-mail/logo.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/packages/connector-sendgrid-mail/package.json b/packages/connector-sendgrid-mail/package.json index 194b12f8f..2c98a59c5 100644 --- a/packages/connector-sendgrid-mail/package.json +++ b/packages/connector-sendgrid-mail/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-sendgrid-mail/src/constant.ts b/packages/connector-sendgrid-mail/src/constant.ts index d775b3bb0..b442799c7 100644 --- a/packages/connector-sendgrid-mail/src/constant.ts +++ b/packages/connector-sendgrid-mail/src/constant.ts @@ -21,7 +21,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'SendGrid Mail Service', 'zh-CN': 'SendGrid 邮件服务', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/sendgrid.svg', + logo: './logo.svg', description: { en: 'Leverage the email service that customer-first brands trust for reliable inbox delivery at scale.', 'zh-CN': '客户至上品牌信任的电子邮件服务,实现大规模可靠的收件箱递送。', diff --git a/packages/connector-sendgrid-mail/src/index.test.ts b/packages/connector-sendgrid-mail/src/index.test.ts index eb4132555..354458130 100644 --- a/packages/connector-sendgrid-mail/src/index.test.ts +++ b/packages/connector-sendgrid-mail/src/index.test.ts @@ -1,6 +1,6 @@ import { GetConnectorConfig } from '@logto/connector-types'; -import { SendGridMailConnector } from '.'; +import SendGridMailConnector from '.'; import { mockedConfig } from './mock'; import { ContextType, SendGridMailConfig } from './types'; diff --git a/packages/connector-sendgrid-mail/src/index.ts b/packages/connector-sendgrid-mail/src/index.ts index e15019cd9..63ac9d343 100644 --- a/packages/connector-sendgrid-mail/src/index.ts +++ b/packages/connector-sendgrid-mail/src/index.ts @@ -21,7 +21,7 @@ import { PublicParameters, } from './types'; -export class SendGridMailConnector implements EmailConnector { +export default class SendGridMailConnector implements EmailConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-twilio-sms/logo.svg b/packages/connector-twilio-sms/logo.svg new file mode 100644 index 000000000..5e53aff23 --- /dev/null +++ b/packages/connector-twilio-sms/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/connector-twilio-sms/package.json b/packages/connector-twilio-sms/package.json index c3244b15f..26ab59199 100644 --- a/packages/connector-twilio-sms/package.json +++ b/packages/connector-twilio-sms/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-twilio-sms/src/constant.ts b/packages/connector-twilio-sms/src/constant.ts index 1b7aefa69..655b39a93 100644 --- a/packages/connector-twilio-sms/src/constant.ts +++ b/packages/connector-twilio-sms/src/constant.ts @@ -21,7 +21,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'Twilio SMS Service', 'zh-CN': 'Twilio 短信服务', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/twilio.svg', + logo: './logo.svg', description: { en: 'Messaging APIs for reliable SMS delivery.', 'zh-CN': '可信赖的短信消息 API。', diff --git a/packages/connector-twilio-sms/src/index.test.ts b/packages/connector-twilio-sms/src/index.test.ts index 807b4133c..d6afc7c30 100644 --- a/packages/connector-twilio-sms/src/index.test.ts +++ b/packages/connector-twilio-sms/src/index.test.ts @@ -1,6 +1,6 @@ import { GetConnectorConfig } from '@logto/connector-types'; -import { TwilioSmsConnector } from '.'; +import TwilioSmsConnector from '.'; import { mockedConfig } from './mock'; import { TwilioSmsConfig } from './types'; diff --git a/packages/connector-twilio-sms/src/index.ts b/packages/connector-twilio-sms/src/index.ts index 989103a08..bc5d0507e 100644 --- a/packages/connector-twilio-sms/src/index.ts +++ b/packages/connector-twilio-sms/src/index.ts @@ -13,7 +13,7 @@ import got from 'got'; import { defaultMetadata, endpoint } from './constant'; import { twilioSmsConfigGuard, SendSmsResponse, TwilioSmsConfig, PublicParameters } from './types'; -export class TwilioSmsConnector implements SmsConnector { +export default class TwilioSmsConnector implements SmsConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-wechat-native/logo.svg b/packages/connector-wechat-native/logo.svg new file mode 100644 index 000000000..1c050fe49 --- /dev/null +++ b/packages/connector-wechat-native/logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/connector-wechat-native/package.json b/packages/connector-wechat-native/package.json index d6323d75d..f98a5d14f 100644 --- a/packages/connector-wechat-native/package.json +++ b/packages/connector-wechat-native/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-wechat-native/src/constant.ts b/packages/connector-wechat-native/src/constant.ts index b275d41e6..bdcefd00a 100644 --- a/packages/connector-wechat-native/src/constant.ts +++ b/packages/connector-wechat-native/src/constant.ts @@ -24,7 +24,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'WeChat', 'zh-CN': '微信', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/wechat.svg', + logo: './logo.svg', description: { en: 'Sign In with WeChat', 'zh-CN': '微信登录', diff --git a/packages/connector-wechat-native/src/index.test.ts b/packages/connector-wechat-native/src/index.test.ts index 7ff7be0d3..0443796ba 100644 --- a/packages/connector-wechat-native/src/index.test.ts +++ b/packages/connector-wechat-native/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { WeChatNativeConnector } from '.'; +import WeChatNativeConnector from '.'; import { accessTokenEndpoint, authorizationEndpoint, userInfoEndpoint } from './constant'; import { mockedConfig } from './mock'; import { WeChatNativeConfig } from './types'; diff --git a/packages/connector-wechat-native/src/index.ts b/packages/connector-wechat-native/src/index.ts index b75d47340..998a792db 100644 --- a/packages/connector-wechat-native/src/index.ts +++ b/packages/connector-wechat-native/src/index.ts @@ -34,7 +34,7 @@ import { // As creating a WeChat Web/Mobile application needs a real App or Website record, the real test is temporarily not finished. // TODO: test with our own wechat mobile/web application (LOG-1910), already tested with other verified wechat web application -export class WeChatNativeConnector implements SocialConnector { +export default class WeChatNativeConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/connector-wechat/logo.svg b/packages/connector-wechat/logo.svg new file mode 100644 index 000000000..1c050fe49 --- /dev/null +++ b/packages/connector-wechat/logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/connector-wechat/package.json b/packages/connector-wechat/package.json index 5cf86eb88..112cbb1d0 100644 --- a/packages/connector-wechat/package.json +++ b/packages/connector-wechat/package.json @@ -8,7 +8,8 @@ "license": "MPL-2.0", "files": [ "lib", - "docs" + "docs", + "logo.svg" ], "private": false, "scripts": { diff --git a/packages/connector-wechat/src/constant.ts b/packages/connector-wechat/src/constant.ts index ecef2c1f3..b5932c953 100644 --- a/packages/connector-wechat/src/constant.ts +++ b/packages/connector-wechat/src/constant.ts @@ -24,7 +24,7 @@ export const defaultMetadata: ConnectorMetadata = { en: 'WeChat', 'zh-CN': '微信', }, - logo: 'https://gist.githubusercontent.com/darcyYe/31bc893a0a305dc43cf831bf0b14f0fc/raw/faf985d3fbeed88180b8f3cb709892320d66ae45/wechat.svg', + logo: './logo.svg', description: { en: 'Sign In with WeChat', 'zh-CN': '微信登录', diff --git a/packages/connector-wechat/src/index.test.ts b/packages/connector-wechat/src/index.test.ts index 4d8ca3095..5d897749c 100644 --- a/packages/connector-wechat/src/index.test.ts +++ b/packages/connector-wechat/src/index.test.ts @@ -1,7 +1,7 @@ import { ConnectorError, ConnectorErrorCodes, GetConnectorConfig } from '@logto/connector-types'; import nock from 'nock'; -import { WeChatConnector } from '.'; +import WeChatConnector from '.'; import { accessTokenEndpoint, authorizationEndpoint, userInfoEndpoint } from './constant'; import { mockedConfig } from './mock'; import { WeChatConfig } from './types'; diff --git a/packages/connector-wechat/src/index.ts b/packages/connector-wechat/src/index.ts index 68bf3fd02..8fe6fd9f4 100644 --- a/packages/connector-wechat/src/index.ts +++ b/packages/connector-wechat/src/index.ts @@ -30,7 +30,7 @@ import { weChatConfigGuard, AccessTokenResponse, UserInfoResponse, WeChatConfig // As creating a WeChat Web/Mobile application needs a real App or Website record, the real test is temporarily not finished. // TODO: test with our own wechat mobile/web application (LOG-1910), already tested with other verified wechat web application -export class WeChatConnector implements SocialConnector { +export default class WeChatConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; constructor(public readonly getConfig: GetConnectorConfig) {} diff --git a/packages/console/src/pages/ConnectorDetails/index.tsx b/packages/console/src/pages/ConnectorDetails/index.tsx index 834f6e160..c5971c66e 100644 --- a/packages/console/src/pages/ConnectorDetails/index.tsx +++ b/packages/console/src/pages/ConnectorDetails/index.tsx @@ -12,7 +12,6 @@ import Card from '@/components/Card'; import CodeEditor from '@/components/CodeEditor'; import DetailsSkeleton from '@/components/DetailsSkeleton'; import Drawer from '@/components/Drawer'; -import ImagePlaceholder from '@/components/ImagePlaceholder'; import LinkButton from '@/components/LinkButton'; import Markdown from '@/components/Markdown'; import Status from '@/components/Status'; @@ -115,11 +114,7 @@ const ConnectorDetails = () => { {data && (
- {data.logo.startsWith('http') ? ( - - ) : ( - - )} +
diff --git a/packages/console/src/pages/Connectors/components/ConnectorName/index.tsx b/packages/console/src/pages/Connectors/components/ConnectorName/index.tsx index 4e6d5bfc7..fca5c09ed 100644 --- a/packages/console/src/pages/Connectors/components/ConnectorName/index.tsx +++ b/packages/console/src/pages/Connectors/components/ConnectorName/index.tsx @@ -23,13 +23,7 @@ const ConnectorName = ({ connector, titlePlaceholder = '' }: Props) => { } subtitle={connector.id} - icon={ - connector.logo.startsWith('http') ? ( - - ) : ( - - ) - } + icon={} /> ); diff --git a/packages/core/package.json b/packages/core/package.json index 01853aced..be7ae907d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -33,8 +33,8 @@ "@logto/connector-wechat": "^0.1.0", "@logto/connector-wechat-native": "^0.1.0", "@logto/phrases": "^0.1.0", - "@logto/shared": "^0.1.0", "@logto/schemas": "^0.1.0", + "@logto/shared": "^0.1.0", "@silverhand/essentials": "^1.1.6", "argon2": "^0.28.5", "chalk": "^4", @@ -60,6 +60,7 @@ "oidc-provider": "^7.10.0", "p-retry": "^4.6.1", "query-string": "^7.0.1", + "resolve-package-path": "^4.0.3", "roarr": "^7.11.0", "slonik": "^28.0.0", "slonik-interceptor-preset": "^1.2.10", @@ -68,9 +69,9 @@ "zod": "^3.14.3" }, "devDependencies": { - "@silverhand/jest-config": "^0.14.0", "@shopify/jest-koa-mocks": "^4.0.0", "@silverhand/eslint-config": "^0.14.0", + "@silverhand/jest-config": "^0.14.0", "@silverhand/ts-config": "^0.14.0", "@types/inquirer": "^8.2.1", "@types/jest": "^27.4.1", diff --git a/packages/core/src/connectors/consts.ts b/packages/core/src/connectors/consts.ts new file mode 100644 index 000000000..bacefe2db --- /dev/null +++ b/packages/core/src/connectors/consts.ts @@ -0,0 +1,14 @@ +// TODO: move to environment variable +export const connectorPackages = [ + '@logto/connector-alipay', + '@logto/connector-alipay-native', + '@logto/connector-aliyun-dm', + '@logto/connector-aliyun-sms', + '@logto/connector-facebook', + '@logto/connector-github', + '@logto/connector-google', + '@logto/connector-sendgrid-email', + '@logto/connector-twilio-sms', + '@logto/connector-wechat', + '@logto/connector-wechat-native', +]; diff --git a/packages/core/src/connectors/index.ts b/packages/core/src/connectors/index.ts index 65abe9e0c..ff48c197c 100644 --- a/packages/core/src/connectors/index.ts +++ b/packages/core/src/connectors/index.ts @@ -1,39 +1,57 @@ -import { AlipayConnector } from '@logto/connector-alipay'; -import { AlipayNativeConnector } from '@logto/connector-alipay-native'; -import { AliyunDmConnector } from '@logto/connector-aliyun-dm'; -import { AliyunSmsConnector } from '@logto/connector-aliyun-sms'; -import { FacebookConnector } from '@logto/connector-facebook'; -import { GithubConnector } from '@logto/connector-github'; -import { GoogleConnector } from '@logto/connector-google'; -import { SendGridMailConnector } from '@logto/connector-sendgrid-email'; -import { TwilioSmsConnector } from '@logto/connector-twilio-sms'; -import { WeChatConnector } from '@logto/connector-wechat'; -import { WeChatNativeConnector } from '@logto/connector-wechat-native'; +import { existsSync, readFileSync } from 'fs'; +import path from 'path'; + +import resolvePackagePath from 'resolve-package-path'; import RequestError from '@/errors/RequestError'; import { findAllConnectors, insertConnector } from '@/queries/connector'; +import { connectorPackages } from './consts'; import { ConnectorInstance, ConnectorType, IConnector, SocialConnectorInstance } from './types'; import { getConnectorConfig } from './utilities'; -const allConnectors: IConnector[] = [ - new AlipayConnector(getConnectorConfig), - new AlipayNativeConnector(getConnectorConfig), - new AliyunDmConnector(getConnectorConfig), - new AliyunSmsConnector(getConnectorConfig), - new FacebookConnector(getConnectorConfig), - new GithubConnector(getConnectorConfig), - new GoogleConnector(getConnectorConfig), - new SendGridMailConnector(getConnectorConfig), - new TwilioSmsConnector(getConnectorConfig), - new WeChatConnector(getConnectorConfig), - new WeChatNativeConnector(getConnectorConfig), -]; +// eslint-disable-next-line @silverhand/fp/no-let +let cachedConnectors: IConnector[] | undefined; + +const loadConnectors = async () => { + if (cachedConnectors) { + return cachedConnectors; + } + + // eslint-disable-next-line @silverhand/fp/no-mutation + cachedConnectors = await Promise.all( + connectorPackages.map(async (packageName) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const { default: Builder } = await import(packageName); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + const instance = new Builder(getConnectorConfig) as IConnector; + // eslint-disable-next-line unicorn/prefer-module + const packagePath = resolvePackagePath(packageName, __dirname); + + // For relative path logo url, try to read local asset. + if ( + packagePath && + !instance.metadata.logo.startsWith('http') && + existsSync(path.join(packagePath, '..', instance.metadata.logo)) + ) { + const data = readFileSync(path.join(packagePath, '..', instance.metadata.logo)); + // eslint-disable-next-line @silverhand/fp/no-mutation + instance.metadata.logo = `data:image/svg+xml;base64,${data.toString('base64')}`; + } + + return instance; + }) + ); + + return cachedConnectors; +}; export const getConnectorInstances = async (): Promise => { const connectors = await findAllConnectors(); const connectorMap = new Map(connectors.map((connector) => [connector.id, connector])); + const allConnectors = await loadConnectors(); + return allConnectors.map((element) => { const { id } = element.metadata; const connector = connectorMap.get(id); @@ -99,6 +117,7 @@ export const getEnabledSocialConnectorIds = async ( export const initConnectors = async () => { const connectors = await findAllConnectors(); const existingConnectors = new Map(connectors.map((connector) => [connector.id, connector])); + const allConnectors = await loadConnectors(); const newConnectors = allConnectors.filter(({ metadata: { id } }) => { const connector = existingConnectors.get(id); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f2936345..a056ef3f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -756,6 +756,7 @@ importers: p-retry: ^4.6.1 prettier: ^2.3.2 query-string: ^7.0.1 + resolve-package-path: ^4.0.3 roarr: ^7.11.0 slonik: ^28.0.0 slonik-interceptor-preset: ^1.2.10 @@ -808,6 +809,7 @@ importers: oidc-provider: 7.10.4 p-retry: 4.6.1 query-string: 7.0.1 + resolve-package-path: 4.0.3 roarr: 7.11.0 slonik: 28.1.0 slonik-interceptor-preset: 1.2.10 @@ -15327,6 +15329,18 @@ packages: /path-parse/1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} + /path-root-regex/0.1.2: + resolution: {integrity: sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0=} + engines: {node: '>=0.10.0'} + dev: false + + /path-root/0.1.1: + resolution: {integrity: sha1-mkpoFMrBwM1zNgqV8yCDyOpHRbc=} + engines: {node: '>=0.10.0'} + dependencies: + path-root-regex: 0.1.2 + dev: false + /path-to-regexp/0.1.7: resolution: {integrity: sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=} dev: true @@ -17305,6 +17319,13 @@ packages: global-dirs: 0.1.1 dev: true + /resolve-package-path/4.0.3: + resolution: {integrity: sha512-SRpNAPW4kewOaNUt8VPqhJ0UMxawMwzJD8V7m1cJfdSTK9ieZwS6K7Dabsm4bmLFM96Z5Y/UznrpG5kt1im8yA==} + engines: {node: '>= 12'} + dependencies: + path-root: 0.1.1 + dev: false + /resolve-path/1.4.0: resolution: {integrity: sha1-xL2p9e+y/OZSR4c6s2u02DT+Fvc=} engines: {node: '>= 0.8'}