mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor(connector): remove unnecessary ConnectorInstance type check
This commit is contained in:
parent
3b0c569c42
commit
91f8fe8444
7 changed files with 19 additions and 47 deletions
|
@ -1,7 +1,7 @@
|
|||
import { existsSync, readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { GetConnectorConfig } from '@logto/connector-schemas';
|
||||
import { ConnectorType, GetConnectorConfig } from '@logto/connector-schemas';
|
||||
import { Connector } from '@logto/schemas/lib/db-entries';
|
||||
import resolvePackagePath from 'resolve-package-path';
|
||||
|
||||
|
@ -10,7 +10,7 @@ import RequestError from '@/errors/RequestError';
|
|||
import { findAllConnectors, insertConnector } from '@/queries/connector';
|
||||
|
||||
import { defaultConnectorPackages } from './consts';
|
||||
import { ConnectorInstance, SocialConnectorInstance, ConnectorType } from './types';
|
||||
import { ConnectorInstance, SocialConnectorInstance } from './types';
|
||||
import { getConnectorConfig } from './utilities';
|
||||
|
||||
// eslint-disable-next-line @silverhand/fp/no-let
|
||||
|
@ -61,10 +61,7 @@ export const getConnectorInstances = async (): Promise<ConnectorInstance[]> => {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
const instance: ConnectorInstance = new InstanceBuilder(
|
||||
getConnectorConfig,
|
||||
connector
|
||||
) as ConnectorInstance;
|
||||
const instance = new InstanceBuilder(getConnectorConfig, connector) as ConnectorInstance;
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
const packagePath = resolvePackagePath(packageName, __dirname);
|
||||
|
||||
|
@ -136,10 +133,10 @@ export const getConnectorInstanceById = async (id: string): Promise<ConnectorIns
|
|||
return pickedConnectorInstance;
|
||||
};
|
||||
|
||||
const isSocialConnectorInstance = (
|
||||
connector: ConnectorInstance
|
||||
): connector is SocialConnectorInstance => {
|
||||
return connector.metadata.type === ConnectorType.Social;
|
||||
export const isSocialConnectorInstance = (
|
||||
instance: ConnectorInstance
|
||||
): instance is SocialConnectorInstance => {
|
||||
return instance.metadata.type === ConnectorType.Social;
|
||||
};
|
||||
|
||||
export const getSocialConnectorInstanceById = async (
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import {
|
||||
LogtoConnector,
|
||||
ConnectorType,
|
||||
ConnectorError,
|
||||
ConnectorErrorCodes,
|
||||
SendMessageFunction,
|
||||
AuthResponseParser,
|
||||
GetAuthorizationUri,
|
||||
|
@ -11,9 +8,6 @@ import {
|
|||
import { Connector, PasscodeType } from '@logto/schemas';
|
||||
import { z } from 'zod';
|
||||
|
||||
export { ConnectorType } from '@logto/connector-schemas';
|
||||
export type { ConnectorMetadata } from '@logto/connector-schemas';
|
||||
|
||||
export type TemplateType = PasscodeType | 'Test';
|
||||
|
||||
export const socialUserInfoGuard = z.object({
|
||||
|
@ -51,27 +45,3 @@ export class SocialConnectorInstance<T = unknown> extends LogtoConnector<T> {
|
|||
|
||||
protected authResponseParser?: AuthResponseParser;
|
||||
}
|
||||
|
||||
export const isSmsConnectorInstance = (
|
||||
instance: unknown
|
||||
): asserts instance is SmsConnectorInstance => {
|
||||
if (!(instance instanceof ConnectorInstance && instance.metadata.type === ConnectorType.SMS)) {
|
||||
throw new ConnectorError(ConnectorErrorCodes.General);
|
||||
}
|
||||
};
|
||||
|
||||
export const isEmailConnectorInstance = (
|
||||
instance: unknown
|
||||
): asserts instance is EmailConnectorInstance => {
|
||||
if (!(instance instanceof ConnectorInstance && instance.metadata.type === ConnectorType.Email)) {
|
||||
throw new ConnectorError(ConnectorErrorCodes.General);
|
||||
}
|
||||
};
|
||||
|
||||
export const isSocialConnectorInstance = (
|
||||
instance: unknown
|
||||
): asserts instance is SocialConnectorInstance => {
|
||||
if (!(instance instanceof ConnectorInstance && instance.metadata.type === ConnectorType.Social)) {
|
||||
throw new ConnectorError(ConnectorErrorCodes.General);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { ConnectorType } from '@logto/connector-schemas';
|
||||
import { Passcode, PasscodeType } from '@logto/schemas';
|
||||
import { customAlphabet, nanoid } from 'nanoid';
|
||||
|
||||
import { getConnectorInstances } from '@/connectors';
|
||||
import { ConnectorType, EmailConnectorInstance, SmsConnectorInstance } from '@/connectors/types';
|
||||
import { EmailConnectorInstance, SmsConnectorInstance } from '@/connectors/types';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import {
|
||||
consumePasscode,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ConnectorType } from '@logto/connector-schemas';
|
||||
import {
|
||||
Branding,
|
||||
BrandingStyle,
|
||||
|
@ -7,7 +8,7 @@ import {
|
|||
} from '@logto/schemas';
|
||||
import { Optional } from '@silverhand/essentials';
|
||||
|
||||
import { ConnectorInstance, ConnectorType } from '@/connectors/types';
|
||||
import { ConnectorInstance } from '@/connectors/types';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import assertThat from '@/utils/assert-that';
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { ValidateConfig } from '@logto/connector-schemas';
|
||||
import { ConnectorMetadata, ValidateConfig } from '@logto/connector-schemas';
|
||||
import { Connector, ConnectorType } from '@logto/schemas';
|
||||
|
||||
import { mockConnectorInstanceList, mockMetadata, mockConnector } from '@/__mocks__';
|
||||
import { ConnectorMetadata } from '@/connectors/types';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import assertThat from '@/utils/assert-that';
|
||||
import { createRequester } from '@/utils/test-utils';
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { ConnectorError, ConnectorErrorCodes, ValidateConfig } from '@logto/connector-schemas';
|
||||
import {
|
||||
ConnectorError,
|
||||
ConnectorErrorCodes,
|
||||
ConnectorMetadata,
|
||||
ValidateConfig,
|
||||
} from '@logto/connector-schemas';
|
||||
import { Connector, ConnectorType } from '@logto/schemas';
|
||||
|
||||
import { mockConnectorInstanceList, mockMetadata, mockConnector } from '@/__mocks__';
|
||||
import { ConnectorMetadata } from '@/connectors/types';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import { updateConnector } from '@/queries/connector';
|
||||
import assertThat from '@/utils/assert-that';
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { ConnectorType } from '@logto/connector-schemas';
|
||||
import { User } from '@logto/schemas';
|
||||
import { Provider } from 'oidc-provider';
|
||||
|
||||
import { mockUser, mockConnectorInstances } from '@/__mocks__';
|
||||
import { getConnectorInstanceById } from '@/connectors';
|
||||
import { ConnectorType } from '@/connectors/types';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import { createRequester } from '@/utils/test-utils';
|
||||
|
||||
|
|
Loading…
Reference in a new issue