mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(cli,core,shared): install demo connectors only in cloud (#3414)
This commit is contained in:
parent
d8d1cfeeb5
commit
63938d6d4b
6 changed files with 31 additions and 11 deletions
|
@ -25,7 +25,8 @@ packages/**/*.config.js packages/**/*.config.ts packages/**/tsconfig*.json \
|
||||||
-prune -exec rm -rf {} +
|
-prune -exec rm -rf {} +
|
||||||
|
|
||||||
# Add official connectors
|
# Add official connectors
|
||||||
pnpm cli connector add --official -p .
|
cloud_option=$( [[ "$IS_CLOUD" =~ ^(1|true|y|yes|yep|yeah)$ ]] && echo "--cloud" || echo "" )
|
||||||
|
pnpm cli connector add --official $cloud_option -p .
|
||||||
|
|
||||||
echo Tar
|
echo Tar
|
||||||
cd ..
|
cd ..
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { addConnectors, addOfficialConnectors, inquireInstancePath } from './uti
|
||||||
|
|
||||||
const add: CommandModule<
|
const add: CommandModule<
|
||||||
{ path?: string },
|
{ path?: string },
|
||||||
{ packages?: string[]; path?: string; official: boolean }
|
{ packages?: string[]; path?: string; official: boolean; cloud: boolean }
|
||||||
> = {
|
> = {
|
||||||
command: ['add [packages...]', 'a', 'install', 'i'],
|
command: ['add [packages...]', 'a', 'install', 'i'],
|
||||||
describe: 'Add specific Logto connectors',
|
describe: 'Add specific Logto connectors',
|
||||||
|
@ -24,12 +24,23 @@ const add: CommandModule<
|
||||||
describe:
|
describe:
|
||||||
'Add all official connectors.\n' +
|
'Add all official connectors.\n' +
|
||||||
"If it's true, the specified package names will be ignored.",
|
"If it's true, the specified package names will be ignored.",
|
||||||
|
})
|
||||||
|
.option('cloud', {
|
||||||
|
describe: 'Add additional connectors for Logto Cloud',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
hidden: true,
|
||||||
}),
|
}),
|
||||||
handler: async ({ packages: packageNames, path, official }) => {
|
handler: async ({ packages: packageNames, path, official, cloud }) => {
|
||||||
const instancePath = await inquireInstancePath(path);
|
const instancePath = await inquireInstancePath(path);
|
||||||
|
|
||||||
|
if (cloud && !official) {
|
||||||
|
log.error('--cloud option can only be used with --official option');
|
||||||
|
}
|
||||||
|
|
||||||
if (official) {
|
if (official) {
|
||||||
await addOfficialConnectors(instancePath);
|
// Add demo connectors for Logto Cloud only
|
||||||
|
await addOfficialConnectors(instancePath, cloud);
|
||||||
} else {
|
} else {
|
||||||
if (!packageNames?.length) {
|
if (!packageNames?.length) {
|
||||||
log.error('No connector name provided');
|
log.error('No connector name provided');
|
||||||
|
|
|
@ -181,7 +181,7 @@ const officialConnectorPrefix = '@logto/connector-';
|
||||||
|
|
||||||
type PackageMeta = { name: string; scope: string; version: string };
|
type PackageMeta = { name: string; scope: string; version: string };
|
||||||
|
|
||||||
const fetchOfficialConnectorList = async () => {
|
const fetchOfficialConnectorList = async (includingCloudConnectors = false) => {
|
||||||
// See https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search
|
// See https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search
|
||||||
type FetchResult = {
|
type FetchResult = {
|
||||||
objects: Array<{
|
objects: Array<{
|
||||||
|
@ -211,13 +211,15 @@ const fetchOfficialConnectorList = async () => {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const { objects } = await fetchList(page * 20, 20);
|
const { objects } = await fetchList(page * 20, 20);
|
||||||
|
|
||||||
|
const excludeList = ['mock', 'kit', ...(includingCloudConnectors ? [] : ['logto'])];
|
||||||
|
|
||||||
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
|
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
|
||||||
packages.push(
|
packages.push(
|
||||||
...objects
|
...objects
|
||||||
.filter(
|
.filter(
|
||||||
({ package: { name, scope } }) =>
|
({ package: { name, scope } }) =>
|
||||||
scope === 'logto' &&
|
scope === 'logto' &&
|
||||||
['mock', 'kit'].every(
|
excludeList.every(
|
||||||
(excluded) => !name.slice(officialConnectorPrefix.length).startsWith(excluded)
|
(excluded) => !name.slice(officialConnectorPrefix.length).startsWith(excluded)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -232,8 +234,11 @@ const fetchOfficialConnectorList = async () => {
|
||||||
return packages;
|
return packages;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addOfficialConnectors = async (instancePath: string) => {
|
export const addOfficialConnectors = async (
|
||||||
const packages = await oraPromise(fetchOfficialConnectorList(), {
|
instancePath: string,
|
||||||
|
includingCloudConnectors = false
|
||||||
|
) => {
|
||||||
|
const packages = await oraPromise(fetchOfficialConnectorList(includingCloudConnectors), {
|
||||||
text: 'Fetch official connector list',
|
text: 'Fetch official connector list',
|
||||||
prefixText: chalk.blue('[info]'),
|
prefixText: chalk.blue('[info]'),
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { buildRawConnector } from '@logto/cli/lib/connector/index.js';
|
||||||
import { VerificationCodeType, validateConfig } from '@logto/connector-kit';
|
import { VerificationCodeType, validateConfig } from '@logto/connector-kit';
|
||||||
import { emailRegEx, phoneRegEx, buildIdGenerator } from '@logto/core-kit';
|
import { emailRegEx, phoneRegEx, buildIdGenerator } from '@logto/core-kit';
|
||||||
import { arbitraryObjectGuard, Connectors, ConnectorType } from '@logto/schemas';
|
import { arbitraryObjectGuard, Connectors, ConnectorType } from '@logto/schemas';
|
||||||
|
import { demoConnectorIds } from '@logto/shared';
|
||||||
import cleanDeep from 'clean-deep';
|
import cleanDeep from 'clean-deep';
|
||||||
import { string, object } from 'zod';
|
import { string, object } from 'zod';
|
||||||
|
|
||||||
|
@ -69,9 +70,9 @@ export default function connectorRoutes<T extends AuthedRouter>(
|
||||||
|
|
||||||
router.get('/connector-factories', async (ctx, next) => {
|
router.get('/connector-factories', async (ctx, next) => {
|
||||||
const connectorFactories = await loadConnectorFactories();
|
const connectorFactories = await loadConnectorFactories();
|
||||||
ctx.body = connectorFactories.map((connectorFactory) =>
|
ctx.body = connectorFactories
|
||||||
transpileConnectorFactory(connectorFactory)
|
.map((connectorFactory) => transpileConnectorFactory(connectorFactory))
|
||||||
);
|
.filter(({ id }) => !demoConnectorIds.includes(id));
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
1
packages/shared/src/models/connector.ts
Normal file
1
packages/shared/src/models/connector.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const demoConnectorIds = ['logto-email', 'logto-sms'];
|
|
@ -1 +1,2 @@
|
||||||
export * from './tenant.js';
|
export * from './tenant.js';
|
||||||
|
export * from './connector.js';
|
||||||
|
|
Loading…
Reference in a new issue