diff --git a/src/context/directory/handlers/flows.ts b/src/context/directory/handlers/flows.ts index 467dabb10..14b72da57 100644 --- a/src/context/directory/handlers/flows.ts +++ b/src/context/directory/handlers/flows.ts @@ -67,7 +67,14 @@ async function dump(context: DirectoryContext) { const flowFile = path.join(flowsFolder, sanitize(`${flow.name}.json`)); log.info(`Writing ${flowFile}`); - const removeKeysFromOutput = ['id', 'created_at', 'updated_at', 'submitted_at', 'embedded_at']; + const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS); + const removeKeysFromOutput = [ + ...(!includeIdentifiers ? ['id'] : []), + 'created_at', + 'updated_at', + 'submitted_at', + 'embedded_at', + ]; removeKeysFromOutput.forEach((key) => { if (key in flow) { delete flow[key]; diff --git a/src/context/directory/handlers/forms.ts b/src/context/directory/handlers/forms.ts index b6eb7380c..c49ad549d 100644 --- a/src/context/directory/handlers/forms.ts +++ b/src/context/directory/handlers/forms.ts @@ -68,7 +68,12 @@ async function dump(context: DirectoryContext) { const formFile = path.join(formsFolder, sanitize(`${form.name}.json`)); log.info(`Writing ${formFile}`); - const removeKeysFromOutput = ['id', 'created_at', 'updated_at']; + const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS); + const removeKeysFromOutput = [ + ...(!includeIdentifiers ? ['id'] : []), + 'created_at', + 'updated_at', + ]; removeKeysFromOutput.forEach((key) => { if (key in form) { delete form[key]; diff --git a/src/context/yaml/handlers/flows.ts b/src/context/yaml/handlers/flows.ts index 057e37402..92c18dce9 100644 --- a/src/context/yaml/handlers/flows.ts +++ b/src/context/yaml/handlers/flows.ts @@ -78,7 +78,14 @@ async function dump(context: YAMLContext): Promise { const jsonFile = path.join(pagesFolder, `${flowName}.json`); log.info(`Writing ${jsonFile}`); - const removeKeysFromOutput = ['id', 'created_at', 'updated_at', 'submitted_at', 'embedded_at']; + const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS); + const removeKeysFromOutput = [ + ...(!includeIdentifiers ? ['id'] : []), + 'created_at', + 'updated_at', + 'submitted_at', + 'embedded_at', + ]; removeKeysFromOutput.forEach((key) => { if (key in flow) { delete flow[key]; diff --git a/src/context/yaml/handlers/forms.ts b/src/context/yaml/handlers/forms.ts index d59fec64c..7495fa105 100644 --- a/src/context/yaml/handlers/forms.ts +++ b/src/context/yaml/handlers/forms.ts @@ -78,7 +78,12 @@ async function dump(context: YAMLContext): Promise { const jsonFile = path.join(pagesFolder, `${formName}.json`); log.info(`Writing ${jsonFile}`); - const removeKeysFromOutput = ['id', 'created_at', 'updated_at']; + const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS); + const removeKeysFromOutput = [ + ...(!includeIdentifiers ? ['id'] : []), + 'created_at', + 'updated_at', + ]; removeKeysFromOutput.forEach((key) => { if (key in form) { delete form[key]; diff --git a/test/context/directory/flows.test.js b/test/context/directory/flows.test.js index 3ab859faf..9abc9fc5d 100644 --- a/test/context/directory/flows.test.js +++ b/test/context/directory/flows.test.js @@ -63,4 +63,37 @@ describe('#directory context flows', () => { context.assets.flows[1] ); }); + + it('should dump flows with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => { + const dir = path.join(testDataDir, 'directory', 'flowsDumpWithId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: true }, + mockMgmtClient() + ); + + context.assets.flows = [{ id: 'flow-id-1', name: 'someFlow' }]; + + await handler.dump(context); + const flowsFolder = path.join(dir, constants.FLOWS_DIRECTORY); + expect(loadJSON(path.join(flowsFolder, 'someFlow.json'))).to.deep.equal({ + id: 'flow-id-1', + name: 'someFlow', + }); + }); + + it('should dump flows without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => { + const dir = path.join(testDataDir, 'directory', 'flowsDumpNoId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: false }, + mockMgmtClient() + ); + + context.assets.flows = [{ id: 'flow-id-1', name: 'someFlow' }]; + + await handler.dump(context); + const flowsFolder = path.join(dir, constants.FLOWS_DIRECTORY); + expect(loadJSON(path.join(flowsFolder, 'someFlow.json'))).to.deep.equal({ name: 'someFlow' }); + }); }); diff --git a/test/context/directory/forms.test.js b/test/context/directory/forms.test.js index 511111814..3fb9d65da 100644 --- a/test/context/directory/forms.test.js +++ b/test/context/directory/forms.test.js @@ -63,4 +63,37 @@ describe('#directory context forms', () => { context.assets.forms[1] ); }); + + it('should dump forms with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => { + const dir = path.join(testDataDir, 'directory', 'formsDumpWithId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: true }, + mockMgmtClient() + ); + + context.assets.forms = [{ id: 'form-id-1', name: 'someForm' }]; + + await handler.dump(context); + const formsFolder = path.join(dir, constants.FORMS_DIRECTORY); + expect(loadJSON(path.join(formsFolder, 'someForm.json'))).to.deep.equal({ + id: 'form-id-1', + name: 'someForm', + }); + }); + + it('should dump forms without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => { + const dir = path.join(testDataDir, 'directory', 'formsDumpNoId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: false }, + mockMgmtClient() + ); + + context.assets.forms = [{ id: 'form-id-1', name: 'someForm' }]; + + await handler.dump(context); + const formsFolder = path.join(dir, constants.FORMS_DIRECTORY); + expect(loadJSON(path.join(formsFolder, 'someForm.json'))).to.deep.equal({ name: 'someForm' }); + }); }); diff --git a/test/context/yaml/flows.test.js b/test/context/yaml/flows.test.js index ad88afd48..23abb479d 100644 --- a/test/context/yaml/flows.test.js +++ b/test/context/yaml/flows.test.js @@ -67,4 +67,40 @@ describe('#YAML context flows', () => { JSON.parse(fs.readFileSync(path.join(flowsFolder, 'Sample Flow 2.json'), 'utf8')) ).to.deep.equal({ name: 'Sample Flow 2' }); }); + + it('should dump flows with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => { + const dir = path.join(testDataDir, 'yaml', 'flowsWithId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: true }, + mockMgmtClient() + ); + + context.assets.flows = [{ id: 'flow-id-1', name: 'Sample Flow 1' }]; + + await handler.dump(context); + const flowsFolder = path.join(dir, 'flows'); + + expect( + JSON.parse(fs.readFileSync(path.join(flowsFolder, 'Sample Flow 1.json'), 'utf8')) + ).to.deep.equal({ id: 'flow-id-1', name: 'Sample Flow 1' }); + }); + + it('should dump flows without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => { + const dir = path.join(testDataDir, 'yaml', 'flowsNoId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: false }, + mockMgmtClient() + ); + + context.assets.flows = [{ id: 'flow-id-1', name: 'Sample Flow 1' }]; + + await handler.dump(context); + const flowsFolder = path.join(dir, 'flows'); + + expect( + JSON.parse(fs.readFileSync(path.join(flowsFolder, 'Sample Flow 1.json'), 'utf8')) + ).to.deep.equal({ name: 'Sample Flow 1' }); + }); }); diff --git a/test/context/yaml/forms.test.js b/test/context/yaml/forms.test.js index 179f0d0a7..303181060 100644 --- a/test/context/yaml/forms.test.js +++ b/test/context/yaml/forms.test.js @@ -67,4 +67,40 @@ describe('#YAML context forms', () => { JSON.parse(fs.readFileSync(path.join(formsFolder, 'Sample Form 2.json'), 'utf8')) ).to.deep.equal({ name: 'Sample Form 2' }); }); + + it('should dump forms with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => { + const dir = path.join(testDataDir, 'yaml', 'formsWithId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: true }, + mockMgmtClient() + ); + + context.assets.forms = [{ id: 'form-id-1', name: 'Sample Form 1' }]; + + await handler.dump(context); + const formsFolder = path.join(dir, 'forms'); + + expect( + JSON.parse(fs.readFileSync(path.join(formsFolder, 'Sample Form 1.json'), 'utf8')) + ).to.deep.equal({ id: 'form-id-1', name: 'Sample Form 1' }); + }); + + it('should dump forms without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => { + const dir = path.join(testDataDir, 'yaml', 'formsNoId'); + cleanThenMkdir(dir); + const context = new Context( + { AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: false }, + mockMgmtClient() + ); + + context.assets.forms = [{ id: 'form-id-1', name: 'Sample Form 1' }]; + + await handler.dump(context); + const formsFolder = path.join(dir, 'forms'); + + expect( + JSON.parse(fs.readFileSync(path.join(formsFolder, 'Sample Form 1.json'), 'utf8')) + ).to.deep.equal({ name: 'Sample Form 1' }); + }); });