diff --git a/src/commands/import.ts b/src/commands/import.ts index acde2e2e3..f84c85897 100644 --- a/src/commands/import.ts +++ b/src/commands/import.ts @@ -4,7 +4,6 @@ import { deploy as toolsDeploy } from '../tools'; import log from '../logger'; import { setupContext } from '../context'; import { ImportParams } from '../args'; -import { Assets, Config } from '../types'; export default async function importCMD(params: ImportParams) { const { @@ -49,47 +48,8 @@ export default async function importCMD(params: ImportParams) { const config = configFactory(); config.setProvider((key) => nconf.get(key)); - findUnreplacedKeywords(context.assets); - + //@ts-ignore because context and assets still need to be typed TODO: type assets and type context await toolsDeploy(context.assets, context.mgmtClient, config); log.info('Import Successful'); } - -export const findUnreplacedKeywords = (assets: Assets) => { - const recursiveFindUnreplacedKeywords = (target): string[] => { - let unreplaced: string[] = []; - if (target === undefined || target === null) return []; - if (Array.isArray(target)) { - target.forEach((child) => { - unreplaced.push(...recursiveFindUnreplacedKeywords(child)); - }); - } else if (typeof target === 'object') { - Object.values(target).forEach((child) => { - unreplaced.push(...recursiveFindUnreplacedKeywords(child)); - }); - } - - if (typeof target === 'string') { - const arrayMatches = target.match(/(?<=@@).*(?=@@)/g); - if (arrayMatches !== null) { - return arrayMatches; - } - const keywordMatches = target.match(/(?<=##).*(?=##)/g); - if (keywordMatches !== null) { - return keywordMatches; - } - } - - return unreplaced; - }; - - const unreplacedKeywords = recursiveFindUnreplacedKeywords(assets); - - if (unreplacedKeywords.length > 0) { - throw `Unreplaced keywords found: ${unreplacedKeywords.join( - ', ' - )}. Either correct these values or add to AUTH0_KEYWORD_REPLACE_MAPPINGS configuration.`; - } - return; -}; diff --git a/test/commands/import.test.ts b/test/commands/import.test.ts deleted file mode 100644 index 327b7d699..000000000 --- a/test/commands/import.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { expect } from 'chai'; -import { findUnreplacedKeywords } from '../../src/commands/import'; - -describe('#findUnreplacedKeywords function', () => { - it('should not throw if no unreplaced keywords', () => { - const fn = () => - findUnreplacedKeywords({ - actions: [ - { - foo: 'foo', - bar: 'bar', - }, - { - foo: ['foo1', 'foo2'], - bar: 'bar', - }, - { - foo: 'foo', - bar: 'bar', - }, - ], - tenant: { - foo: 'foo', - bar: { - some: { - nested: { property: 'bar baz' }, - }, - }, - }, - //@ts-ignore because we're detecting this - databases: ' database value ', // - }); - - expect(fn).to.not.throw(); - }); - it('should throw if unreplaced keywords detected', () => { - const fn = () => - findUnreplacedKeywords({ - actions: [ - { - foo: 'foo', - bar: 'bar', - }, - { - foo: ['##KEYWORD1##', '##KEYWORD2##'], - bar: 'bar', - }, - { - foo: 'foo', - bar: 'bar', - }, - ], - tenant: { - foo: 'foo', - bar: { - some: { - nested: { property: 'bar ##KEYWORD3##' }, - }, - }, - }, - //@ts-ignore because we're detecting this - databases: ' @@KEYWORD4@@ ', // - }); - - expect(fn).to.throw( - 'Unreplaced keywords found: KEYWORD1, KEYWORD2, KEYWORD3, KEYWORD4. Either correct these values or add to AUTH0_KEYWORD_REPLACE_MAPPINGS configuration.' - ); - }); -});