mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor: validate config generic (#4286)
This commit is contained in:
parent
5b34338484
commit
3752b86797
33 changed files with 62 additions and 85 deletions
|
@ -52,7 +52,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state }) => {
|
async ({ state }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<AlipayNativeConfig>(config, alipayNativeConfigGuard);
|
validateConfig(config, alipayNativeConfigGuard);
|
||||||
|
|
||||||
const { appId } = config;
|
const { appId } = config;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ const getUserInfo =
|
||||||
const { auth_code } = await authorizationCallbackHandler(data);
|
const { auth_code } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
|
|
||||||
validateConfig<AlipayNativeConfig>(config, alipayNativeConfigGuard);
|
validateConfig(config, alipayNativeConfigGuard);
|
||||||
|
|
||||||
const { accessToken } = await getAccessToken(auth_code, config);
|
const { accessToken } = await getAccessToken(auth_code, config);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<AlipayConfig>(config, alipayConfigGuard);
|
validateConfig(config, alipayConfigGuard);
|
||||||
|
|
||||||
const { appId: app_id, scope } = config;
|
const { appId: app_id, scope } = config;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { auth_code } = await authorizationCallbackHandler(data);
|
const { auth_code } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<AlipayConfig>(config, alipayConfigGuard);
|
validateConfig(config, alipayConfigGuard);
|
||||||
|
|
||||||
const { accessToken } = await getAccessToken(auth_code, config);
|
const { accessToken } = await getAccessToken(auth_code, config);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ import {
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import { singleSendMail } from './single-send-mail.js';
|
import { singleSendMail } from './single-send-mail.js';
|
||||||
import type { AliyunDmConfig } from './types.js';
|
|
||||||
import {
|
import {
|
||||||
aliyunDmConfigGuard,
|
aliyunDmConfigGuard,
|
||||||
sendEmailResponseGuard,
|
sendEmailResponseGuard,
|
||||||
|
@ -29,7 +28,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<AliyunDmConfig>(config, aliyunDmConfigGuard);
|
validateConfig(config, aliyunDmConfigGuard);
|
||||||
const { accessKeyId, accessKeySecret, accountName, fromAlias, templates } = config;
|
const { accessKeyId, accessKeySecret, accountName, fromAlias, templates } = config;
|
||||||
const template = templates.find((template) => template.usageType === type);
|
const template = templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import { sendSms } from './single-send-text.js';
|
import { sendSms } from './single-send-text.js';
|
||||||
import type { AliyunSmsConfig, Template } from './types.js';
|
import type { Template } from './types.js';
|
||||||
import { aliyunSmsConfigGuard, sendSmsResponseGuard } from './types.js';
|
import { aliyunSmsConfigGuard, sendSmsResponseGuard } from './types.js';
|
||||||
|
|
||||||
const isChinaNumber = (to: string) => /^(\+86|0086|86)?\d{11}$/.test(to);
|
const isChinaNumber = (to: string) => /^(\+86|0086|86)?\d{11}$/.test(to);
|
||||||
|
@ -35,7 +35,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<AliyunSmsConfig>(config, aliyunSmsConfigGuard);
|
validateConfig(config, aliyunSmsConfigGuard);
|
||||||
const { accessKeyId, accessKeySecret, signName, templates } = config;
|
const { accessKeyId, accessKeySecret, signName, templates } = config;
|
||||||
const template = templates.find(({ usageType }) => usageType === type);
|
const template = templates.find(({ usageType }) => usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ import { generateStandardId } from '@logto/shared/universal';
|
||||||
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
||||||
|
|
||||||
import { scope, defaultMetadata, jwksUri, issuer, authorizationEndpoint } from './constant.js';
|
import { scope, defaultMetadata, jwksUri, issuer, authorizationEndpoint } from './constant.js';
|
||||||
import type { AppleConfig } from './types.js';
|
|
||||||
import { appleConfigGuard, dataGuard } from './types.js';
|
import { appleConfigGuard, dataGuard } from './types.js';
|
||||||
|
|
||||||
const generateNonce = () => generateStandardId();
|
const generateNonce = () => generateStandardId();
|
||||||
|
@ -27,7 +26,7 @@ const getAuthorizationUri =
|
||||||
async ({ state, redirectUri }, setSession) => {
|
async ({ state, redirectUri }, setSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
|
|
||||||
validateConfig<AppleConfig>(config, appleConfigGuard);
|
validateConfig(config, appleConfigGuard);
|
||||||
|
|
||||||
const nonce = generateNonce();
|
const nonce = generateNonce();
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ const getUserInfo =
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<AppleConfig>(config, appleConfigGuard);
|
validateConfig(config, appleConfigGuard);
|
||||||
|
|
||||||
const { clientId } = config;
|
const { clientId } = config;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import type { AwsSesConfig } from './types.js';
|
|
||||||
import { awsSesConfigGuard } from './types.js';
|
import { awsSesConfigGuard } from './types.js';
|
||||||
import { makeClient, makeCommand, makeEmailContent } from './utils.js';
|
import { makeClient, makeCommand, makeEmailContent } from './utils.js';
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<AwsSesConfig>(config, awsSesConfigGuard);
|
validateConfig(config, awsSesConfigGuard);
|
||||||
const { accessKeyId, accessKeySecret, region, templates } = config;
|
const { accessKeyId, accessKeySecret, region, templates } = config;
|
||||||
const template = templates.find((template) => template.usageType === type);
|
const template = templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ const getAuthorizationUri =
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
|
|
||||||
validateConfig<AzureADConfig>(config, azureADConfigGuard);
|
validateConfig(config, azureADConfigGuard);
|
||||||
const { clientId, clientSecret, cloudInstance, tenantId } = config;
|
const { clientId, clientSecret, cloudInstance, tenantId } = config;
|
||||||
|
|
||||||
const defaultAuthCodeUrlParameters: AuthorizationUrlRequest = {
|
const defaultAuthCodeUrlParameters: AuthorizationUrlRequest = {
|
||||||
|
@ -106,7 +106,7 @@ const getUserInfo =
|
||||||
|
|
||||||
// Temporarily keep this as this is a refactor, which should not change the logics.
|
// Temporarily keep this as this is a refactor, which should not change the logics.
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<AzureADConfig>(config, azureADConfigGuard);
|
validateConfig(config, azureADConfigGuard);
|
||||||
|
|
||||||
const { accessToken } = await getAccessToken(config, code, redirectUri);
|
const { accessToken } = await getAccessToken(config, code, redirectUri);
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<DiscordConfig>(config, discordConfigGuard);
|
validateConfig(config, discordConfigGuard);
|
||||||
|
|
||||||
const queryParameters = new URLSearchParams({
|
const queryParameters = new URLSearchParams({
|
||||||
client_id: config.clientId,
|
client_id: config.clientId,
|
||||||
|
@ -92,7 +92,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<DiscordConfig>(config, discordConfigGuard);
|
validateConfig(config, discordConfigGuard);
|
||||||
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -42,7 +42,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<FacebookConfig>(config, facebookConfigGuard);
|
validateConfig(config, facebookConfigGuard);
|
||||||
|
|
||||||
const queryParameters = new URLSearchParams({
|
const queryParameters = new URLSearchParams({
|
||||||
client_id: config.clientId,
|
client_id: config.clientId,
|
||||||
|
@ -60,7 +60,7 @@ export const getAccessToken = async (
|
||||||
codeObject: { code: string; redirectUri: string }
|
codeObject: { code: string; redirectUri: string }
|
||||||
) => {
|
) => {
|
||||||
const { code, redirectUri } = codeObject;
|
const { code, redirectUri } = codeObject;
|
||||||
validateConfig<FacebookConfig>(config, facebookConfigGuard);
|
validateConfig(config, facebookConfigGuard);
|
||||||
|
|
||||||
const { clientId: client_id, clientSecret: client_secret } = config;
|
const { clientId: client_id, clientSecret: client_secret } = config;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<FacebookConfig>(config, facebookConfigGuard);
|
validateConfig(config, facebookConfigGuard);
|
||||||
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -22,7 +22,6 @@ import {
|
||||||
defaultMetadata,
|
defaultMetadata,
|
||||||
userInfoEndpoint,
|
userInfoEndpoint,
|
||||||
} from './constant.js';
|
} from './constant.js';
|
||||||
import type { FeishuConfig } from './types.js';
|
|
||||||
import {
|
import {
|
||||||
feishuAccessTokenResponse,
|
feishuAccessTokenResponse,
|
||||||
feishuAuthCodeGuard,
|
feishuAuthCodeGuard,
|
||||||
|
@ -49,7 +48,7 @@ export function buildAuthorizationUri(
|
||||||
export function getAuthorizationUri(getConfig: GetConnectorConfig): GetAuthorizationUri {
|
export function getAuthorizationUri(getConfig: GetConnectorConfig): GetAuthorizationUri {
|
||||||
return async function ({ state, redirectUri }) {
|
return async function ({ state, redirectUri }) {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<FeishuConfig>(config, feishuConfigGuard);
|
validateConfig(config, feishuConfigGuard);
|
||||||
|
|
||||||
const { appId } = config;
|
const { appId } = config;
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ export function getUserInfo(getConfig: GetConnectorConfig): GetUserInfo {
|
||||||
return async function (data) {
|
return async function (data) {
|
||||||
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<FeishuConfig>(config, feishuConfigGuard);
|
validateConfig(config, feishuConfigGuard);
|
||||||
|
|
||||||
const { accessToken } = await getAccessToken(code, config.appId, config.appSecret, redirectUri);
|
const { accessToken } = await getAccessToken(code, config.appId, config.appSecret, redirectUri);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<GithubConfig>(config, githubConfigGuard);
|
validateConfig(config, githubConfigGuard);
|
||||||
const queryParameters = new URLSearchParams({
|
const queryParameters = new URLSearchParams({
|
||||||
client_id: config.clientId,
|
client_id: config.clientId,
|
||||||
redirect_uri: redirectUri,
|
redirect_uri: redirectUri,
|
||||||
|
@ -107,7 +107,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code } = await authorizationCallbackHandler(data);
|
const { code } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<GithubConfig>(config, githubConfigGuard);
|
validateConfig(config, githubConfigGuard);
|
||||||
const { accessToken } = await getAccessToken(config, { code });
|
const { accessToken } = await getAccessToken(config, { code });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -40,7 +40,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<GoogleConfig>(config, googleConfigGuard);
|
validateConfig(config, googleConfigGuard);
|
||||||
|
|
||||||
const queryParameters = new URLSearchParams({
|
const queryParameters = new URLSearchParams({
|
||||||
client_id: config.clientId,
|
client_id: config.clientId,
|
||||||
|
@ -91,7 +91,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<GoogleConfig>(config, googleConfigGuard);
|
validateConfig(config, googleConfigGuard);
|
||||||
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -39,7 +39,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<KakaoConfig>(config, kakaoConfigGuard);
|
validateConfig(config, kakaoConfigGuard);
|
||||||
|
|
||||||
const queryParameters = new URLSearchParams({
|
const queryParameters = new URLSearchParams({
|
||||||
client_id: config.clientId,
|
client_id: config.clientId,
|
||||||
|
@ -89,7 +89,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<KakaoConfig>(config, kakaoConfigGuard);
|
validateConfig(config, kakaoConfigGuard);
|
||||||
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -19,14 +19,13 @@ import {
|
||||||
|
|
||||||
import { defaultMetadata, defaultTimeout, emailEndpoint, usageEndpoint } from './constant.js';
|
import { defaultMetadata, defaultTimeout, emailEndpoint, usageEndpoint } from './constant.js';
|
||||||
import { grantAccessToken } from './grant-access-token.js';
|
import { grantAccessToken } from './grant-access-token.js';
|
||||||
import type { LogtoEmailConfig } from './types.js';
|
|
||||||
import { logtoEmailConfigGuard } from './types.js';
|
import { logtoEmailConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
(getConfig: GetConnectorConfig): SendMessageFunction =>
|
(getConfig: GetConnectorConfig): SendMessageFunction =>
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<LogtoEmailConfig>(config, logtoEmailConfigGuard);
|
validateConfig(config, logtoEmailConfigGuard);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
endpoint,
|
endpoint,
|
||||||
|
@ -76,7 +75,7 @@ const getUsage =
|
||||||
(getConfig: GetConnectorConfig): GetUsageFunction =>
|
(getConfig: GetConnectorConfig): GetUsageFunction =>
|
||||||
async (startFrom?: Date) => {
|
async (startFrom?: Date) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<LogtoEmailConfig>(config, logtoEmailConfigGuard);
|
validateConfig(config, logtoEmailConfigGuard);
|
||||||
|
|
||||||
const { endpoint, tokenEndpoint, appId, appSecret, resource } = config;
|
const { endpoint, tokenEndpoint, appId, appSecret, resource } = config;
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,13 @@ import { ConnectorType, validateConfig } from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata, defaultTimeout, smsEndpoint } from './constant.js';
|
import { defaultMetadata, defaultTimeout, smsEndpoint } from './constant.js';
|
||||||
import { grantAccessToken } from './grant-access-token.js';
|
import { grantAccessToken } from './grant-access-token.js';
|
||||||
import type { LogtoSmsConfig } from './types.js';
|
|
||||||
import { logtoSmsConfigGuard } from './types.js';
|
import { logtoSmsConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
(getConfig: GetConnectorConfig): SendMessageFunction =>
|
(getConfig: GetConnectorConfig): SendMessageFunction =>
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<LogtoSmsConfig>(config, logtoSmsConfigGuard);
|
validateConfig(config, logtoSmsConfigGuard);
|
||||||
|
|
||||||
const { endpoint, tokenEndpoint, appId, appSecret, resource } = config;
|
const { endpoint, tokenEndpoint, appId, appSecret, resource } = config;
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,13 @@ import type {
|
||||||
import { validateConfig, ConnectorType } from '@logto/connector-kit';
|
import { validateConfig, ConnectorType } from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata, getProviderConfigs } from './constant.js';
|
import { defaultMetadata, getProviderConfigs } from './constant.js';
|
||||||
import type { SocialDemoConfig } from './types.js';
|
|
||||||
import { socialDemoConfigGuard } from './types.js';
|
import { socialDemoConfigGuard } from './types.js';
|
||||||
|
|
||||||
const getAuthorizationUri =
|
const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state }) => {
|
async ({ state }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<SocialDemoConfig>(config, socialDemoConfigGuard);
|
validateConfig(config, socialDemoConfigGuard);
|
||||||
|
|
||||||
const { provider, clientId, redirectUri } = config;
|
const { provider, clientId, redirectUri } = config;
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,7 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import {
|
import { type DeliveryConfig, mailgunConfigGuard, supportTemplateGuard } from './types.js';
|
||||||
type DeliveryConfig,
|
|
||||||
mailgunConfigGuard,
|
|
||||||
supportTemplateGuard,
|
|
||||||
type MailgunConfig,
|
|
||||||
} from './types.js';
|
|
||||||
|
|
||||||
const removeUndefinedKeys = (object: Record<string, unknown>) =>
|
const removeUndefinedKeys = (object: Record<string, unknown>) =>
|
||||||
Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined));
|
Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined));
|
||||||
|
@ -52,7 +47,7 @@ const getDataFromDeliveryConfig = (
|
||||||
const sendMessage = (getConfig: GetConnectorConfig): SendMessageFunction => {
|
const sendMessage = (getConfig: GetConnectorConfig): SendMessageFunction => {
|
||||||
return async ({ to, type: typeInput, payload: { code } }, inputConfig) => {
|
return async ({ to, type: typeInput, payload: { code } }, inputConfig) => {
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<MailgunConfig>(config, mailgunConfigGuard);
|
validateConfig(config, mailgunConfigGuard);
|
||||||
|
|
||||||
const { domain, apiKey, from, deliveries } = config;
|
const { domain, apiKey, from, deliveries } = config;
|
||||||
const type = supportTemplateGuard.safeParse(typeInput);
|
const type = supportTemplateGuard.safeParse(typeInput);
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import type { MockMailConfig } from './types.js';
|
|
||||||
import { mockMailConfigGuard } from './types.js';
|
import { mockMailConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
|
@ -24,7 +23,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<MockMailConfig>(config, mockMailConfigGuard);
|
validateConfig(config, mockMailConfigGuard);
|
||||||
const { templates } = config;
|
const { templates } = config;
|
||||||
const template = templates?.find((template) => template.usageType === type);
|
const template = templates?.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import type { MockMailConfig } from './types.js';
|
|
||||||
import { mockMailConfigGuard } from './types.js';
|
import { mockMailConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
|
@ -24,7 +23,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<MockMailConfig>(config, mockMailConfigGuard);
|
validateConfig(config, mockMailConfigGuard);
|
||||||
const { templates } = config;
|
const { templates } = config;
|
||||||
const template = templates.find((template) => template.usageType === type);
|
const template = templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import type { MockSmsConfig } from './types.js';
|
|
||||||
import { mockSmsConfigGuard } from './types.js';
|
import { mockSmsConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
|
@ -24,7 +23,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<MockSmsConfig>(config, mockSmsConfigGuard);
|
validateConfig(config, mockSmsConfigGuard);
|
||||||
const { templates } = config;
|
const { templates } = config;
|
||||||
const template = templates.find((template) => template.usageType === type);
|
const template = templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<NaverConfig>(config, naverConfigGuard);
|
validateConfig(config, naverConfigGuard);
|
||||||
|
|
||||||
const queryParameters = new URLSearchParams({
|
const queryParameters = new URLSearchParams({
|
||||||
client_id: config.clientId,
|
client_id: config.clientId,
|
||||||
|
@ -89,7 +89,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
const { code, redirectUri } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<NaverConfig>(config, naverConfigGuard);
|
validateConfig(config, naverConfigGuard);
|
||||||
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
const { accessToken } = await getAccessToken(config, { code, redirectUri });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata, defaultTimeout } from './constant.js';
|
import { defaultMetadata, defaultTimeout } from './constant.js';
|
||||||
import type { OauthConfig } from './types.js';
|
|
||||||
import { oauthConfigGuard } from './types.js';
|
import { oauthConfigGuard } from './types.js';
|
||||||
import { userProfileMapping, getAccessToken } from './utils.js';
|
import { userProfileMapping, getAccessToken } from './utils.js';
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }, setSession) => {
|
async ({ state, redirectUri }, setSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<OauthConfig>(config, oauthConfigGuard);
|
validateConfig(config, oauthConfigGuard);
|
||||||
const parsedConfig = oauthConfigGuard.parse(config);
|
const parsedConfig = oauthConfigGuard.parse(config);
|
||||||
|
|
||||||
const { customConfig, ...rest } = parsedConfig;
|
const { customConfig, ...rest } = parsedConfig;
|
||||||
|
@ -52,7 +51,7 @@ const getUserInfo =
|
||||||
(getConfig: GetConnectorConfig): GetUserInfo =>
|
(getConfig: GetConnectorConfig): GetUserInfo =>
|
||||||
async (data, getSession) => {
|
async (data, getSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<OauthConfig>(config, oauthConfigGuard);
|
validateConfig(config, oauthConfigGuard);
|
||||||
const parsedConfig = oauthConfigGuard.parse(config);
|
const parsedConfig = oauthConfigGuard.parse(config);
|
||||||
|
|
||||||
const { redirectUri } = await getSession();
|
const { redirectUri } = await getSession();
|
||||||
|
|
|
@ -19,7 +19,6 @@ import { generateStandardId } from '@logto/shared/universal';
|
||||||
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import type { OidcConfig } from './types.js';
|
|
||||||
import { idTokenProfileStandardClaimsGuard, oidcConfigGuard } from './types.js';
|
import { idTokenProfileStandardClaimsGuard, oidcConfigGuard } from './types.js';
|
||||||
import { getIdToken } from './utils.js';
|
import { getIdToken } from './utils.js';
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }, setSession) => {
|
async ({ state, redirectUri }, setSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<OidcConfig>(config, oidcConfigGuard);
|
validateConfig(config, oidcConfigGuard);
|
||||||
const parsedConfig = oidcConfigGuard.parse(config);
|
const parsedConfig = oidcConfigGuard.parse(config);
|
||||||
|
|
||||||
const nonce = generateNonce();
|
const nonce = generateNonce();
|
||||||
|
@ -62,7 +61,7 @@ const getUserInfo =
|
||||||
(getConfig: GetConnectorConfig): GetUserInfo =>
|
(getConfig: GetConnectorConfig): GetUserInfo =>
|
||||||
async (data, getSession) => {
|
async (data, getSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<OidcConfig>(config, oidcConfigGuard);
|
validateConfig(config, oidcConfigGuard);
|
||||||
const parsedConfig = oidcConfigGuard.parse(config);
|
const parsedConfig = oidcConfigGuard.parse(config);
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
|
|
|
@ -19,14 +19,13 @@ import * as saml from 'samlify';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import { samlConfigGuard } from './types.js';
|
import { samlConfigGuard } from './types.js';
|
||||||
import type { SamlConfig } from './types.js';
|
|
||||||
import { samlAssertionHandler, getUserInfoFromRawUserProfile } from './utils.js';
|
import { samlAssertionHandler, getUserInfoFromRawUserProfile } from './utils.js';
|
||||||
|
|
||||||
const getAuthorizationUri =
|
const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri, connectorId, connectorFactoryId, jti }, setSession) => {
|
async ({ state, redirectUri, connectorId, connectorFactoryId, jti }, setSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<SamlConfig>(config, samlConfigGuard);
|
validateConfig(config, samlConfigGuard);
|
||||||
const {
|
const {
|
||||||
entityID,
|
entityID,
|
||||||
x509Certificate,
|
x509Certificate,
|
||||||
|
@ -99,7 +98,7 @@ export const validateSamlAssertion =
|
||||||
(getConfig: GetConnectorConfig): ValidateSamlAssertion =>
|
(getConfig: GetConnectorConfig): ValidateSamlAssertion =>
|
||||||
async (assertion, getSession, setSession) => {
|
async (assertion, getSession, setSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<SamlConfig>(config, samlConfigGuard);
|
validateConfig(config, samlConfigGuard);
|
||||||
const parsedConfig = samlConfigGuard.parse(config);
|
const parsedConfig = samlConfigGuard.parse(config);
|
||||||
|
|
||||||
const connectorSession = await getSession();
|
const connectorSession = await getSession();
|
||||||
|
@ -137,7 +136,7 @@ const getUserInfo =
|
||||||
(getConfig: GetConnectorConfig): GetUserInfo =>
|
(getConfig: GetConnectorConfig): GetUserInfo =>
|
||||||
async (_data, getSession) => {
|
async (_data, getSession) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<SamlConfig>(config, samlConfigGuard);
|
validateConfig(config, samlConfigGuard);
|
||||||
const parsedConfig = samlConfigGuard.parse(config);
|
const parsedConfig = samlConfigGuard.parse(config);
|
||||||
const { profileMap } = parsedConfig;
|
const { profileMap } = parsedConfig;
|
||||||
|
|
||||||
|
|
|
@ -16,20 +16,14 @@ import {
|
||||||
|
|
||||||
import { defaultMetadata, endpoint } from './constant.js';
|
import { defaultMetadata, endpoint } from './constant.js';
|
||||||
import { sendGridMailConfigGuard } from './types.js';
|
import { sendGridMailConfigGuard } from './types.js';
|
||||||
import type {
|
import type { EmailData, Personalization, Content, PublicParameters } from './types.js';
|
||||||
EmailData,
|
|
||||||
Personalization,
|
|
||||||
Content,
|
|
||||||
PublicParameters,
|
|
||||||
SendGridMailConfig,
|
|
||||||
} from './types.js';
|
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
(getConfig: GetConnectorConfig): SendMessageFunction =>
|
(getConfig: GetConnectorConfig): SendMessageFunction =>
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<SendGridMailConfig>(config, sendGridMailConfigGuard);
|
validateConfig(config, sendGridMailConfigGuard);
|
||||||
const { apiKey, fromEmail, fromName, templates } = config;
|
const { apiKey, fromEmail, fromName, templates } = config;
|
||||||
const template = templates.find((template) => template.usageType === type);
|
const template = templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata, endpoint } from './constant.js';
|
import { defaultMetadata, endpoint } from './constant.js';
|
||||||
import type { PublicParameters, SmsAeroConfig } from './types.js';
|
import type { PublicParameters } from './types.js';
|
||||||
import { smsAeroConfigGuard } from './types.js';
|
import { smsAeroConfigGuard } from './types.js';
|
||||||
|
|
||||||
function sendMessage(getConfig: GetConnectorConfig): SendMessageFunction {
|
function sendMessage(getConfig: GetConnectorConfig): SendMessageFunction {
|
||||||
|
@ -23,7 +23,7 @@ function sendMessage(getConfig: GetConnectorConfig): SendMessageFunction {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
|
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<SmsAeroConfig>(config, smsAeroConfigGuard);
|
validateConfig(config, smsAeroConfigGuard);
|
||||||
|
|
||||||
const { email, apiKey, senderName, templates } = config;
|
const { email, apiKey, senderName, templates } = config;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import nodemailer from 'nodemailer';
|
||||||
import type SMTPTransport from 'nodemailer/lib/smtp-transport';
|
import type SMTPTransport from 'nodemailer/lib/smtp-transport';
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import type { SmtpConfig } from './types.js';
|
|
||||||
import { ContextType, smtpConfigGuard } from './types.js';
|
import { ContextType, smtpConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
|
@ -24,7 +23,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<SmtpConfig>(config, smtpConfigGuard);
|
validateConfig(config, smtpConfigGuard);
|
||||||
const template = config.templates.find((template) => template.usageType === type);
|
const template = config.templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
|
|
||||||
import { defaultMetadata } from './constant.js';
|
import { defaultMetadata } from './constant.js';
|
||||||
import { isSmsErrorResponse, sendSmsRequest } from './http.js';
|
import { isSmsErrorResponse, sendSmsRequest } from './http.js';
|
||||||
import type { TencentSmsConfig } from './schema.js';
|
|
||||||
import { SmsConfigGuard, tencentErrorResponse } from './schema.js';
|
import { SmsConfigGuard, tencentErrorResponse } from './schema.js';
|
||||||
|
|
||||||
function safeGetArray<T>(value: Array<T | undefined>, index: number): T {
|
function safeGetArray<T>(value: Array<T | undefined>, index: number): T {
|
||||||
|
@ -34,7 +33,7 @@ function sendMessage(getConfig: GetConnectorConfig): SendMessageFunction {
|
||||||
return async (data, inputConfig) => {
|
return async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<TencentSmsConfig>(config, SmsConfigGuard);
|
validateConfig(config, SmsConfigGuard);
|
||||||
const { accessKeyId, accessKeySecret, signName, templates, sdkAppId, region } = config;
|
const { accessKeyId, accessKeySecret, signName, templates, sdkAppId, region } = config;
|
||||||
const template = templates.find(({ usageType }) => usageType === type);
|
const template = templates.find(({ usageType }) => usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
} from '@logto/connector-kit';
|
} from '@logto/connector-kit';
|
||||||
|
|
||||||
import { defaultMetadata, endpoint } from './constant.js';
|
import { defaultMetadata, endpoint } from './constant.js';
|
||||||
import type { TwilioSmsConfig, PublicParameters } from './types.js';
|
import type { PublicParameters } from './types.js';
|
||||||
import { twilioSmsConfigGuard } from './types.js';
|
import { twilioSmsConfigGuard } from './types.js';
|
||||||
|
|
||||||
const sendMessage =
|
const sendMessage =
|
||||||
|
@ -23,7 +23,7 @@ const sendMessage =
|
||||||
async (data, inputConfig) => {
|
async (data, inputConfig) => {
|
||||||
const { to, type, payload } = data;
|
const { to, type, payload } = data;
|
||||||
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
const config = inputConfig ?? (await getConfig(defaultMetadata.id));
|
||||||
validateConfig<TwilioSmsConfig>(config, twilioSmsConfigGuard);
|
validateConfig(config, twilioSmsConfigGuard);
|
||||||
const { accountSID, authToken, fromMessagingServiceSID, templates } = config;
|
const { accountSID, authToken, fromMessagingServiceSID, templates } = config;
|
||||||
const template = templates.find((template) => template.usageType === type);
|
const template = templates.find((template) => template.usageType === type);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ const getAuthorizationUri =
|
||||||
async ({ state }) => {
|
async ({ state }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
|
|
||||||
validateConfig<WechatNativeConfig>(config, wechatNativeConfigGuard);
|
validateConfig(config, wechatNativeConfigGuard);
|
||||||
|
|
||||||
const { appId, universalLinks } = config;
|
const { appId, universalLinks } = config;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code } = await authorizationCallbackHandler(data);
|
const { code } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<WechatNativeConfig>(config, wechatNativeConfigGuard);
|
validateConfig(config, wechatNativeConfigGuard);
|
||||||
const { accessToken, openid } = await getAccessToken(code, config);
|
const { accessToken, openid } = await getAccessToken(code, config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -47,7 +47,7 @@ const getAuthorizationUri =
|
||||||
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
(getConfig: GetConnectorConfig): GetAuthorizationUri =>
|
||||||
async ({ state, redirectUri }) => {
|
async ({ state, redirectUri }) => {
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<WechatConfig>(config, wechatConfigGuard);
|
validateConfig(config, wechatConfigGuard);
|
||||||
|
|
||||||
const { appId, scope } = config;
|
const { appId, scope } = config;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ const getUserInfo =
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const { code } = await authorizationCallbackHandler(data);
|
const { code } = await authorizationCallbackHandler(data);
|
||||||
const config = await getConfig(defaultMetadata.id);
|
const config = await getConfig(defaultMetadata.id);
|
||||||
validateConfig<WechatConfig>(config, wechatConfigGuard);
|
validateConfig(config, wechatConfigGuard);
|
||||||
const { accessToken, openid } = await getAccessToken(code, config);
|
const { accessToken, openid } = await getAccessToken(code, config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe('connector-kit', () => {
|
||||||
type TestingType = z.infer<typeof testingTypeGuard>;
|
type TestingType = z.infer<typeof testingTypeGuard>;
|
||||||
const testingConfig = { foo: 'foo', bar: 1, baz: true };
|
const testingConfig = { foo: 'foo', bar: 1, baz: true };
|
||||||
expect(() => {
|
expect(() => {
|
||||||
validateConfig<TestingType>(testingConfig, testingTypeGuard);
|
validateConfig(testingConfig, testingTypeGuard);
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ describe('connector-kit', () => {
|
||||||
type TestingType = z.infer<typeof testingTypeGuard>;
|
type TestingType = z.infer<typeof testingTypeGuard>;
|
||||||
const testingConfig = { foo: 'foo', bar: 1 };
|
const testingConfig = { foo: 'foo', bar: 1 };
|
||||||
expect(() => {
|
expect(() => {
|
||||||
validateConfig<TestingType>(testingConfig, testingTypeGuard);
|
validateConfig(testingConfig, testingTypeGuard);
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import type { ZodType } from 'zod';
|
import type { ZodType, ZodTypeDef } from 'zod';
|
||||||
|
|
||||||
import { ConnectorError, ConnectorErrorCodes } from './types.js';
|
import { ConnectorError, ConnectorErrorCodes } from './types.js';
|
||||||
|
|
||||||
export * from './types.js';
|
export * from './types.js';
|
||||||
|
|
||||||
export function validateConfig<T>(config: unknown, guard: ZodType): asserts config is T {
|
export function validateConfig<Output, Input = Output>(
|
||||||
|
config: unknown,
|
||||||
|
guard: ZodType<Output, ZodTypeDef, Input>
|
||||||
|
): asserts config is Output {
|
||||||
const result = guard.safeParse(config);
|
const result = guard.safeParse(config);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
|
Loading…
Reference in a new issue