0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(core,connector): use isProduction as email service feature switch (#4135)

* fix(core,connector): use isProduction as email service feature switch

* refactor(core): reorg code

---------

Co-authored-by: Gao Sun <gao@silverhand.io>
This commit is contained in:
Darcy Ye 2023-07-07 23:33:22 +08:00 committed by Gao Sun
parent 04cf242e48
commit c79fda5355
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
2 changed files with 19 additions and 3 deletions

View file

@ -1,3 +1,5 @@
import { getEnv } from '@silverhand/essentials';
import type { ConnectorMetadata } from '@logto/connector-kit'; import type { ConnectorMetadata } from '@logto/connector-kit';
import { ConnectorConfigFormItemType } from '@logto/connector-kit'; import { ConnectorConfigFormItemType } from '@logto/connector-kit';
@ -102,6 +104,9 @@ export const scope = ['send:email'];
export const defaultTimeout = 5000; export const defaultTimeout = 5000;
export const emailEndpoint = '/services/mails'; /** @deprecated Will be replaced by `/services/mails` soon. */
export const demoEmailEndpoint = '/services/send-email';
export const emailEndpoint =
getEnv('NODE_ENV') === 'production' ? demoEmailEndpoint : '/services/mails';
export const usageEndpoint = '/services/mails/usage'; export const usageEndpoint = '/services/mails/usage';

View file

@ -8,6 +8,7 @@ import { connectorDirectory } from '@logto/cli/lib/constants.js';
import { getConnectorPackagesFromDirectory } from '@logto/cli/lib/utils.js'; import { getConnectorPackagesFromDirectory } from '@logto/cli/lib/utils.js';
import { import {
demoConnectorIds, demoConnectorIds,
serviceConnectorIds,
ConnectorType, ConnectorType,
type EmailConnector, type EmailConnector,
type SmsConnector, type SmsConnector,
@ -27,6 +28,14 @@ export const isPasswordlessLogtoConnector = (
): connector is LogtoConnector<EmailConnector | SmsConnector> => ): connector is LogtoConnector<EmailConnector | SmsConnector> =>
connector.type !== ConnectorType.Social; connector.type !== ConnectorType.Social;
/**
* Treat Logto service connectors as demo connectors in production since they are not available
* for public use yet.
*/
const isDemoConnector = (connectorId: string) =>
demoConnectorIds.includes(connectorId) ||
(EnvSet.values.isProduction && serviceConnectorIds.includes(connectorId));
export const transpileLogtoConnector = async ( export const transpileLogtoConnector = async (
connector: LogtoConnector, connector: LogtoConnector,
extraInfo?: ConnectorResponse['extraInfo'] extraInfo?: ConnectorResponse['extraInfo']
@ -40,7 +49,8 @@ export const transpileLogtoConnector = async (
); );
const { dbEntry, metadata, type } = connector; const { dbEntry, metadata, type } = connector;
const { config, connectorId: id } = dbEntry; const { config, connectorId: id } = dbEntry;
const isDemo = demoConnectorIds.includes(id);
const isDemo = isDemoConnector(id);
return { return {
type, type,
@ -61,7 +71,8 @@ export const transpileConnectorFactory = ({
return { return {
type, type,
...metadata, ...metadata,
isDemo: demoConnectorIds.includes(metadata.id), /** Temporarily block entering Logto email connector as well until this feature is ready for prod. */
isDemo: isDemoConnector(metadata.id),
}; };
}; };