@rockcarver/frodo-cli 2.0.0-21 → 2.0.0-23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/esm/cli/FrodoCommand.js +3 -1
- package/esm/cli/FrodoCommand.js.map +1 -1
- package/esm/cli/agent/agent-web.js +2 -2
- package/esm/cli/agent/agent-web.js.map +1 -1
- package/esm/cli/app/app-import.js +1 -1
- package/esm/cli/app/app-import.js.map +1 -1
- package/esm/cli/idm/idm-export.js +14 -8
- package/esm/cli/idm/idm-export.js.map +1 -1
- package/esm/cli/idm/idm-import.js +14 -8
- package/esm/cli/idm/idm-import.js.map +1 -1
- package/esm/cli/journey/journey-export.js +2 -3
- package/esm/cli/journey/journey-export.js.map +1 -1
- package/esm/cli/oauth/oauth-client-import.js +1 -1
- package/esm/cli/oauth/oauth-client-import.js.map +1 -1
- package/esm/cli/service/service-import.js +2 -3
- package/esm/cli/service/service-import.js.map +1 -1
- package/esm/ops/AdminFederationOps.js +29 -20
- package/esm/ops/AdminFederationOps.js.map +1 -1
- package/esm/ops/AgentOps.js +41 -34
- package/esm/ops/AgentOps.js.map +1 -1
- package/esm/ops/ApplicationOps.js +23 -17
- package/esm/ops/ApplicationOps.js.map +1 -1
- package/esm/ops/CirclesOfTrustOps.js +27 -20
- package/esm/ops/CirclesOfTrustOps.js.map +1 -1
- package/esm/ops/EmailTemplateOps.js +19 -14
- package/esm/ops/EmailTemplateOps.js.map +1 -1
- package/esm/ops/IdmOps.js +14 -22
- package/esm/ops/IdmOps.js.map +1 -1
- package/esm/ops/IdpOps.js +27 -19
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/JourneyOps.js +18 -51
- package/esm/ops/JourneyOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +23 -17
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/PolicyOps.js +27 -20
- package/esm/ops/PolicyOps.js.map +1 -1
- package/esm/ops/PolicySetOps.js +23 -17
- package/esm/ops/PolicySetOps.js.map +1 -1
- package/esm/ops/ResourceTypeOps.js +27 -20
- package/esm/ops/ResourceTypeOps.js.map +1 -1
- package/esm/ops/Saml2Ops.js +22 -14
- package/esm/ops/Saml2Ops.js.map +1 -1
- package/esm/ops/ScriptOps.js +22 -15
- package/esm/ops/ScriptOps.js.map +1 -1
- package/esm/ops/ServiceOps.js +21 -16
- package/esm/ops/ServiceOps.js.map +1 -1
- package/esm/ops/ThemeOps.js +21 -15
- package/esm/ops/ThemeOps.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CirclesOfTrustOps.js","names":["frodo","state","fs","createProgressBar","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getTypedFilename","saveJsonToFile","titleCase","getRealmName","utils","readCirclesOfTrust","exportCircleOfTrust","exportCirclesOfTrust","importCircleOfTrust","importCirclesOfTrust","importFirstCircleOfTrust","saml2","circlesOfTrust","getOneLineDescription","cotObj","description","_id","getTableHeaderMd","markdown","getTableRowMd","row","status","trustedProviders","map","provider","split","join","listCirclesOfTrust","long","outcome","cotList","error","sort","a","b","localeCompare","forEach","cot","table","push","toString","exportCircleOfTrustToFile","cotId","file","fileName","exportData","message","exportCirclesOfTrustToFile","getRealm","exportCirclesOfTrustToFiles","errors","cots","length","name","importCircleOfTrustFromFile","readFile","err","data","fileData","JSON","parse","_error$response","response","importFirstCircleOfTrustFromFile","_error$response2","importCirclesOfTrustFromFile","_error$response3","importCirclesOfTrustFromFiles","names","readdirSync","files","filter","toLowerCase","endsWith","total","readFileSync","count","Object","keys","saml"],"sources":["../../src/ops/CirclesOfTrustOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type CircleOfTrustSkeleton } from '@rockcarver/frodo-lib/types/api/CirclesOfTrustApi';\nimport { type CirclesOfTrustExportInterface } from '@rockcarver/frodo-lib/types/ops/CirclesOfTrustOps';\nimport fs from 'fs';\n\nimport {\n createProgressBar,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n} from '../utils/ExportImportUtils';\n\nconst { getRealmName } = frodo.utils;\nconst {\n readCirclesOfTrust,\n exportCircleOfTrust,\n exportCirclesOfTrust,\n importCircleOfTrust,\n importCirclesOfTrust,\n importFirstCircleOfTrust,\n} = frodo.saml2.circlesOfTrust;\n\n/**\n * Get a one-line description of the circle of trust object\n * @param {CircleOfTrustSkeleton} cotObj circle of trust object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(cotObj: CircleOfTrustSkeleton): string {\n const description = `[${cotObj._id['brightCyan']}]`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name/Id | Status | Trusted Providers |\\n';\n markdown += '| ------- | ------ | ----------------- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the circle of trust in markdown\n * @param {SocialIdpSkeleton} cotObj circle of trust object to describe\n * @returns {string} a table-row of the circle of trust in markdown\n */\nexport function getTableRowMd(cotObj: CircleOfTrustSkeleton): string {\n const row = `| ${cotObj._id} | ${\n cotObj.status === 'active'\n ? ':white_check_mark: `active`'\n : ':o: `inactive`'\n } | ${cotObj.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('<br>')} |`;\n return row;\n}\n\n/**\n * List entity providers\n * @param {String} long Long list format with details\n */\nexport async function listCirclesOfTrust(long = false): Promise<boolean> {\n let outcome = false;\n let cotList = [];\n try {\n cotList = await readCirclesOfTrust();\n } catch (error) {\n printMessage(`readCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n cotList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n cotList.forEach((cot) => {\n printMessage(`${cot._id}`, 'data');\n });\n outcome = true;\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Description'['brightCyan'],\n 'Status'['brightCyan'],\n 'Trusted Providers'['brightCyan'],\n ]);\n cotList.forEach((cot) => {\n table.push([\n cot._id,\n cot.description,\n cot.status,\n cot.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('\\n'),\n ]);\n });\n printMessage(table.toString());\n outcome = true;\n }\n return outcome;\n}\n\n/**\n * Export a single circle of trust to file\n * @param {String} cotId circle of trust id/name\n * @param {String} file Optional filename\n */\nexport async function exportCircleOfTrustToFile(\n cotId: string,\n file: string = null\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.CirclesOfTrustOps.exportCircleOfTrustToFile: begin`);\n showSpinner(`Exporting ${cotId}...`);\n try {\n let fileName = getTypedFilename(cotId, 'cot.saml');\n if (file) {\n fileName = file;\n }\n const exportData = await exportCircleOfTrust(cotId);\n saveJsonToFile(exportData, fileName);\n succeedSpinner(`Exported ${cotId} to ${fileName}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${cotId}: ${error.message}`);\n }\n debugMessage(`cli.CirclesOfTrustOps.exportCircleOfTrustToFile: end`);\n return outcome;\n}\n\n/**\n * Export all circles of trust to one file\n * @param {String} file Optional filename\n */\nexport async function exportCirclesOfTrustToFile(\n file: string = null\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFile: begin`);\n showSpinner(`Exporting all circles of trust...`);\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}CirclesOfTrust`,\n 'cot.saml'\n );\n if (file) {\n fileName = file;\n }\n const exportData = await exportCirclesOfTrust();\n saveJsonToFile(exportData, fileName);\n succeedSpinner(`Exported all circles of trust to ${fileName}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting circles of trust: ${error.message}`);\n }\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFile: end`);\n return outcome;\n}\n\n/**\n * Export all circles of trust to individual files\n */\nexport async function exportCirclesOfTrustToFiles(): Promise<boolean> {\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFiles: begin`);\n const errors = [];\n try {\n const cots: CircleOfTrustSkeleton[] = await readCirclesOfTrust();\n createProgressBar(cots.length, 'Exporting circles of trust...');\n for (const cot of cots) {\n const file = getTypedFilename(cot._id, 'cot.saml');\n try {\n const exportData: CirclesOfTrustExportInterface =\n await exportCircleOfTrust(cot._id);\n saveJsonToFile(exportData, file);\n updateProgressBar(`Exported ${cot.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error exporting ${cot.name}.`);\n }\n }\n stopProgressBar(`Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressBar(`Error exporting circles of trust to files`);\n }\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {String} file Import file name\n */\nexport async function importCircleOfTrustFromFile(\n cotId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing circle of trust ${cotId} from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importCircleOfTrust(cotId, fileData);\n outcome = true;\n succeedSpinner(`Imported circle of trust ${cotId} from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing circle of trust ${cotId} from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first SAML circle of trust from file\n * @param {String} file Import file name\n */\nexport async function importFirstCircleOfTrustFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing first circle of trust from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importFirstCircleOfTrust(fileData);\n outcome = true;\n succeedSpinner(`Imported first circle of trust from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing first circle of trust from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all SAML circles of trust from file\n * @param {String} file Import file name\n */\nexport async function importCirclesOfTrustFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing circles of trust from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importCirclesOfTrust(fileData);\n outcome = true;\n succeedSpinner(`Imported circles of trust from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing circles of trust from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all SAML circles of trust from all *.cot.saml.json files in the current directory\n */\nexport async function importCirclesOfTrustFromFiles(): Promise<boolean> {\n const errors = [];\n try {\n debugMessage(`cli.CirclesOfTrustOps.importCirclesOfTrustFromFiles: begin`);\n const names = fs.readdirSync('.');\n const files = names.filter((name) =>\n name.toLowerCase().endsWith('.cot.saml.json')\n );\n createProgressBar(files.length, 'Importing circles of trust...');\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: CirclesOfTrustExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.saml.cot).length;\n total += count;\n await importCirclesOfTrust(fileData);\n updateProgressBar(`Imported ${count} circles of trust from ${file}`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error importing circles of trust from ${file}`);\n printMessage(error, 'error');\n }\n }\n stopProgressBar(\n `Imported ${total} circles of trust from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressBar(`Error importing circles of trust from files.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.CirclesOfTrustOps.importCirclesOfTrustFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAGpD,OAAOC,EAAE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AC;EACxE,OAAO,CAAC,KAAKyD,MAAM,CAACE,MAAM;AAC5B"}
|
|
1
|
+
{"version":3,"file":"CirclesOfTrustOps.js","names":["frodo","state","fs","createProgressBar","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getTypedFilename","saveJsonToFile","titleCase","getRealmName","getFilePath","getWorkingDirectory","utils","readCirclesOfTrust","exportCircleOfTrust","exportCirclesOfTrust","importCircleOfTrust","importCirclesOfTrust","importFirstCircleOfTrust","saml2","circlesOfTrust","getOneLineDescription","cotObj","description","_id","getTableHeaderMd","markdown","getTableRowMd","row","status","trustedProviders","map","provider","split","join","listCirclesOfTrust","long","outcome","cotList","error","sort","a","b","localeCompare","forEach","cot","table","push","toString","exportCircleOfTrustToFile","cotId","file","fileName","filePath","exportData","message","exportCirclesOfTrustToFile","getRealm","exportCirclesOfTrustToFiles","errors","cots","length","name","importCircleOfTrustFromFile","readFile","err","data","fileData","JSON","parse","_error$response","response","importFirstCircleOfTrustFromFile","_error$response2","importCirclesOfTrustFromFile","_error$response3","importCirclesOfTrustFromFiles","names","readdirSync","files","filter","toLowerCase","endsWith","total","readFileSync","count","Object","keys","saml"],"sources":["../../src/ops/CirclesOfTrustOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type CircleOfTrustSkeleton } from '@rockcarver/frodo-lib/types/api/CirclesOfTrustApi';\nimport { type CirclesOfTrustExportInterface } from '@rockcarver/frodo-lib/types/ops/CirclesOfTrustOps';\nimport fs from 'fs';\n\nimport {\n createProgressBar,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n} from '../utils/ExportImportUtils';\n\nconst { getRealmName, getFilePath, getWorkingDirectory } = frodo.utils;\nconst {\n readCirclesOfTrust,\n exportCircleOfTrust,\n exportCirclesOfTrust,\n importCircleOfTrust,\n importCirclesOfTrust,\n importFirstCircleOfTrust,\n} = frodo.saml2.circlesOfTrust;\n\n/**\n * Get a one-line description of the circle of trust object\n * @param {CircleOfTrustSkeleton} cotObj circle of trust object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(cotObj: CircleOfTrustSkeleton): string {\n const description = `[${cotObj._id['brightCyan']}]`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name/Id | Status | Trusted Providers |\\n';\n markdown += '| ------- | ------ | ----------------- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the circle of trust in markdown\n * @param {SocialIdpSkeleton} cotObj circle of trust object to describe\n * @returns {string} a table-row of the circle of trust in markdown\n */\nexport function getTableRowMd(cotObj: CircleOfTrustSkeleton): string {\n const row = `| ${cotObj._id} | ${\n cotObj.status === 'active'\n ? ':white_check_mark: `active`'\n : ':o: `inactive`'\n } | ${cotObj.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('<br>')} |`;\n return row;\n}\n\n/**\n * List entity providers\n * @param {String} long Long list format with details\n */\nexport async function listCirclesOfTrust(long = false): Promise<boolean> {\n let outcome = false;\n let cotList = [];\n try {\n cotList = await readCirclesOfTrust();\n } catch (error) {\n printMessage(`readCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n cotList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n cotList.forEach((cot) => {\n printMessage(`${cot._id}`, 'data');\n });\n outcome = true;\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Description'['brightCyan'],\n 'Status'['brightCyan'],\n 'Trusted Providers'['brightCyan'],\n ]);\n cotList.forEach((cot) => {\n table.push([\n cot._id,\n cot.description,\n cot.status,\n cot.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('\\n'),\n ]);\n });\n printMessage(table.toString());\n outcome = true;\n }\n return outcome;\n}\n\n/**\n * Export a single circle of trust to file\n * @param {String} cotId circle of trust id/name\n * @param {String} file Optional filename\n */\nexport async function exportCircleOfTrustToFile(\n cotId: string,\n file: string = null\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.CirclesOfTrustOps.exportCircleOfTrustToFile: begin`);\n showSpinner(`Exporting ${cotId}...`);\n try {\n let fileName = getTypedFilename(cotId, 'cot.saml');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportCircleOfTrust(cotId);\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported ${cotId} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${cotId}: ${error.message}`);\n }\n debugMessage(`cli.CirclesOfTrustOps.exportCircleOfTrustToFile: end`);\n return outcome;\n}\n\n/**\n * Export all circles of trust to one file\n * @param {String} file Optional filename\n */\nexport async function exportCirclesOfTrustToFile(\n file: string = null\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFile: begin`);\n showSpinner(`Exporting all circles of trust...`);\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}CirclesOfTrust`,\n 'cot.saml'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportCirclesOfTrust();\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported all circles of trust to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting circles of trust: ${error.message}`);\n }\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFile: end`);\n return outcome;\n}\n\n/**\n * Export all circles of trust to individual files\n */\nexport async function exportCirclesOfTrustToFiles(): Promise<boolean> {\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFiles: begin`);\n const errors = [];\n try {\n const cots: CircleOfTrustSkeleton[] = await readCirclesOfTrust();\n createProgressBar(cots.length, 'Exporting circles of trust...');\n for (const cot of cots) {\n const file = getTypedFilename(cot._id, 'cot.saml');\n try {\n const exportData: CirclesOfTrustExportInterface =\n await exportCircleOfTrust(cot._id);\n saveJsonToFile(exportData, getFilePath(file, true));\n updateProgressBar(`Exported ${cot.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error exporting ${cot.name}.`);\n }\n }\n stopProgressBar(`Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressBar(`Error exporting circles of trust to files`);\n }\n debugMessage(`cli.CirclesOfTrustOps.exportCirclesOfTrustToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {String} file Import file name\n */\nexport async function importCircleOfTrustFromFile(\n cotId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing circle of trust ${cotId} from ${filePath}...`);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importCircleOfTrust(cotId, fileData);\n outcome = true;\n succeedSpinner(`Imported circle of trust ${cotId} from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing circle of trust ${cotId} from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first SAML circle of trust from file\n * @param {String} file Import file name\n */\nexport async function importFirstCircleOfTrustFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing first circle of trust from ${filePath}...`);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importFirstCircleOfTrust(fileData);\n outcome = true;\n succeedSpinner(`Imported first circle of trust from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing first circle of trust from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all SAML circles of trust from file\n * @param {String} file Import file name\n */\nexport async function importCirclesOfTrustFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing circles of trust from ${filePath}...`);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importCirclesOfTrust(fileData);\n outcome = true;\n succeedSpinner(`Imported circles of trust from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing circles of trust from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all SAML circles of trust from all *.cot.saml.json files in the current directory\n */\nexport async function importCirclesOfTrustFromFiles(): Promise<boolean> {\n const errors = [];\n try {\n debugMessage(`cli.CirclesOfTrustOps.importCirclesOfTrustFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.cot.saml.json'))\n .map((name) => getFilePath(name));\n createProgressBar(files.length, 'Importing circles of trust...');\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: CirclesOfTrustExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.saml.cot).length;\n total += count;\n await importCirclesOfTrust(fileData);\n updateProgressBar(`Imported ${count} circles of trust from ${file}`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error importing circles of trust from ${file}`);\n printMessage(error, 'error');\n }\n }\n stopProgressBar(\n `Imported ${total} circles of trust from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressBar(`Error importing circles of trust from files.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.CirclesOfTrustOps.importCirclesOfTrustFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAGpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,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ElD,YAAY,CAACsC,KAAK,EAAE,OAAO,CAAC;MAC9B;IACF;IACApC,eAAe,CACZ,YAAWgF,KAAM,0BAAyBJ,KAAK,CAAClB,MAAO,SAC1D,CAAC;EACH,CAAC,CAAC,OAAOtB,KAAK,EAAE;IACdoB,MAAM,CAACZ,IAAI,CAACR,KAAK,CAAC;IAClBpC,eAAe,CAAE,8CAA6C,CAAC;IAC/DF,YAAY,CAACsC,KAAK,EAAE,OAAO,CAAC;EAC9B;EACAxC,YAAY,CAAE,0DAAyD,CAAC;EACxE,OAAO,CAAC,KAAK4D,MAAM,CAACE,MAAM;AAC5B"}
|
|
@@ -6,7 +6,9 @@ import { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
|
|
|
6
6
|
import { cloneDeep } from './utils/OpsUtils';
|
|
7
7
|
import wordwrap from './utils/Wordwrap';
|
|
8
8
|
const {
|
|
9
|
-
validateImport
|
|
9
|
+
validateImport,
|
|
10
|
+
getFilePath,
|
|
11
|
+
getWorkingDirectory
|
|
10
12
|
} = frodo.utils;
|
|
11
13
|
const {
|
|
12
14
|
EMAIL_TEMPLATE_TYPE,
|
|
@@ -107,14 +109,15 @@ export async function exportEmailTemplateToFile(templateId, file) {
|
|
|
107
109
|
if (!fileName) {
|
|
108
110
|
fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);
|
|
109
111
|
}
|
|
112
|
+
const filePath = getFilePath(fileName, true);
|
|
110
113
|
createProgressIndicator('determinate', 1, `Exporting ${templateId}`);
|
|
111
114
|
try {
|
|
112
115
|
const templateData = await readEmailTemplate(templateId);
|
|
113
|
-
updateProgressIndicator(`Writing file ${
|
|
116
|
+
updateProgressIndicator(`Writing file ${filePath}`);
|
|
114
117
|
const fileData = getFileDataTemplate();
|
|
115
118
|
fileData.emailTemplate[templateId] = templateData;
|
|
116
|
-
saveJsonToFile(fileData,
|
|
117
|
-
stopProgressIndicator(`Exported ${templateId['brightCyan']} to ${
|
|
119
|
+
saveJsonToFile(fileData, filePath);
|
|
120
|
+
stopProgressIndicator(`Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`);
|
|
118
121
|
} catch (err) {
|
|
119
122
|
stopProgressIndicator(`${err}`);
|
|
120
123
|
printMessage(err, 'error');
|
|
@@ -130,6 +133,7 @@ export async function exportEmailTemplatesToFile(file) {
|
|
|
130
133
|
if (!fileName) {
|
|
131
134
|
fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);
|
|
132
135
|
}
|
|
136
|
+
const filePath = getFilePath(fileName, true);
|
|
133
137
|
try {
|
|
134
138
|
const fileData = getFileDataTemplate();
|
|
135
139
|
const templates = await readEmailTemplates();
|
|
@@ -139,8 +143,8 @@ export async function exportEmailTemplatesToFile(file) {
|
|
|
139
143
|
updateProgressIndicator(`Exporting ${templateId}`);
|
|
140
144
|
fileData.emailTemplate[templateId] = template;
|
|
141
145
|
}
|
|
142
|
-
saveJsonToFile(fileData,
|
|
143
|
-
stopProgressIndicator(`${templates.length} templates exported to ${
|
|
146
|
+
saveJsonToFile(fileData, filePath);
|
|
147
|
+
stopProgressIndicator(`${templates.length} templates exported to ${filePath}.`);
|
|
144
148
|
} catch (err) {
|
|
145
149
|
stopProgressIndicator(`${err}`);
|
|
146
150
|
printMessage(err, 'error');
|
|
@@ -160,7 +164,7 @@ export async function exportEmailTemplatesToFiles() {
|
|
|
160
164
|
const fileData = getFileDataTemplate();
|
|
161
165
|
updateProgressIndicator(`Exporting ${templateId}`);
|
|
162
166
|
fileData.emailTemplate[templateId] = template;
|
|
163
|
-
saveJsonToFile(fileData, fileName);
|
|
167
|
+
saveJsonToFile(fileData, getFilePath(fileName, true));
|
|
164
168
|
}
|
|
165
169
|
stopProgressIndicator(`${templates.length} templates exported.`);
|
|
166
170
|
} catch (err) {
|
|
@@ -178,7 +182,8 @@ export async function exportEmailTemplatesToFiles() {
|
|
|
178
182
|
export async function importEmailTemplateFromFile(templateId, file, raw = false) {
|
|
179
183
|
// eslint-disable-next-line no-param-reassign
|
|
180
184
|
templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');
|
|
181
|
-
|
|
185
|
+
const filePath = getFilePath(file);
|
|
186
|
+
fs.readFile(filePath, 'utf8', async (err, data) => {
|
|
182
187
|
if (err) throw err;
|
|
183
188
|
const fileData = JSON.parse(data);
|
|
184
189
|
if (raw || validateImport(fileData.meta)) {
|
|
@@ -194,8 +199,8 @@ export async function importEmailTemplateFromFile(templateId, file, raw = false)
|
|
|
194
199
|
printMessage(updateEmailTemplateError, 'error');
|
|
195
200
|
}
|
|
196
201
|
} else {
|
|
197
|
-
stopProgressIndicator(`Email template ${templateId} not found in ${
|
|
198
|
-
printMessage(`Email template ${templateId} not found in ${
|
|
202
|
+
stopProgressIndicator(`Email template ${templateId} not found in ${filePath}!`);
|
|
203
|
+
printMessage(`Email template ${templateId} not found in ${filePath}!`, 'error');
|
|
199
204
|
}
|
|
200
205
|
} else {
|
|
201
206
|
printMessage('Import validation failed...', 'error');
|
|
@@ -208,7 +213,7 @@ export async function importEmailTemplateFromFile(templateId, file, raw = false)
|
|
|
208
213
|
* @param {string} file optional filename
|
|
209
214
|
*/
|
|
210
215
|
export async function importEmailTemplatesFromFile(file) {
|
|
211
|
-
fs.readFile(file, 'utf8', async (err, data) => {
|
|
216
|
+
fs.readFile(getFilePath(file), 'utf8', async (err, data) => {
|
|
212
217
|
if (err) throw err;
|
|
213
218
|
const fileData = JSON.parse(data);
|
|
214
219
|
if (validateImport(fileData.meta)) {
|
|
@@ -268,8 +273,8 @@ function s2sConvert(templateData) {
|
|
|
268
273
|
* @param {boolean} raw import raw data file lacking frodo export envelop
|
|
269
274
|
*/
|
|
270
275
|
export async function importEmailTemplatesFromFiles(raw = false) {
|
|
271
|
-
const names = fs.readdirSync(
|
|
272
|
-
const jsonFiles =
|
|
276
|
+
const names = fs.readdirSync(getWorkingDirectory());
|
|
277
|
+
const jsonFiles = names.filter(name => raw ? name.startsWith(`${EMAIL_TEMPLATE_TYPE}-`) && name.endsWith(`.json`) : name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)).map(name => getFilePath(name));
|
|
273
278
|
createProgressIndicator('determinate', jsonFiles.length, 'Importing email templates...');
|
|
274
279
|
let total = 0;
|
|
275
280
|
let totalErrors = 0;
|
|
@@ -320,7 +325,7 @@ export async function importEmailTemplatesFromFiles(raw = false) {
|
|
|
320
325
|
* @param {String} file optional filename
|
|
321
326
|
*/
|
|
322
327
|
export async function importFirstEmailTemplateFromFile(file, raw = false) {
|
|
323
|
-
fs.readFile(file, 'utf8', async (err, data) => {
|
|
328
|
+
fs.readFile(getFilePath(file), 'utf8', async (err, data) => {
|
|
324
329
|
if (err) throw err;
|
|
325
330
|
const fileData = JSON.parse(data);
|
|
326
331
|
if (raw && file.startsWith('emailTemplate-') || validateImport(fileData.meta)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailTemplateOps.js","names":["frodo","fs","path","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getTypedFilename","saveJsonToFile","cloneDeep","wordwrap","validateImport","utils","EMAIL_TEMPLATE_TYPE","readEmailTemplates","readEmailTemplate","updateEmailTemplate","email","template","EMAIL_TEMPLATE_FILE_TYPE","regexEmailTemplateType","RegExp","getFileDataTemplate","meta","emailTemplate","getOneLineDescription","templateObj","description","_id","split","displayName","defaultLocale","subject","Object","values","getTableHeaderMd","markdown","getTableRowMd","templateId","replace","locales","keys","length","filter","locale","join","row","name","listEmailTemplates","long","emailTemplates","error","message","sort","a","b","localeCompare","entries","table","push","enabled","from","toString","exportEmailTemplateToFile","file","fileName","templateData","fileData","err","exportEmailTemplatesToFile","templates","exportEmailTemplatesToFiles","importEmailTemplateFromFile","raw","replaceAll","readFile","data","JSON","parse","emailTemplateData","s2sConvert","updateEmailTemplateError","importEmailTemplatesFromFile","id","hasOwnProperty","call","response","readEmailTemplateIdFromFile","basename","substring","indexOf","html","convertedData","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","startsWith","endsWith","toLowerCase","total","totalErrors","readFileSync","errors","_updateEmailTemplateE","importFirstEmailTemplateFromFile","_updateEmailTemplateE2","_updateEmailTemplateE3"],"sources":["../../src/ops/EmailTemplateOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { EmailTemplateSkeleton } from '@rockcarver/frodo-lib/types/ops/EmailTemplateOps';\nimport fs from 'fs';\nimport path from 'path';\n\nimport {\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';\nimport { cloneDeep } from './utils/OpsUtils';\nimport wordwrap from './utils/Wordwrap';\n\nconst { validateImport } = frodo.utils;\nconst {\n EMAIL_TEMPLATE_TYPE,\n readEmailTemplates,\n readEmailTemplate,\n updateEmailTemplate,\n} = frodo.email.template;\n\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\n\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName ? templateObj.displayName : ''\n } - ${\n templateObj.defaultLocale\n ? templateObj.subject[templateObj.defaultLocale]\n : Object.values(templateObj.subject)[0]\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Display Name | Locale(s) | Subject | Id |\\n';\n markdown += '| ------------ | --------- | ------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the email template in markdown\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a table-row of the email template in markdown\n */\nexport function getTableRowMd(templateObj: EmailTemplateSkeleton): string {\n const templateId = templateObj._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const locales = `${templateObj.defaultLocale}${\n Object.keys(templateObj.subject).length > 1\n ? ` (${Object.keys(templateObj.subject)\n .filter((locale) => locale !== templateObj.defaultLocale)\n .join(',')})`\n : ''\n }`;\n const row = `| ${\n templateObj.name ? templateObj.name : templateId\n } | ${locales} | ${\n templateObj.subject[templateObj.defaultLocale]\n } | \\`${templateId}\\` |`;\n return row;\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = await readEmailTemplates();\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export single email template to a file\n * @param {string} templateId email template id to export\n * @param {string} file filename where to export the template data\n */\nexport async function exportEmailTemplateToFile(\n templateId: string,\n file: string\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n createProgressIndicator('determinate', 1, `Exporting ${templateId}`);\n try {\n const templateData = await readEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${templateId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n try {\n const fileData = getFileDataTemplate();\n const templates = await readEmailTemplates();\n createProgressIndicator(\n 'determinate',\n templates.length,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${templates.length} templates exported to ${fileName}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const templates = await readEmailTemplates();\n createProgressIndicator(\n 'determinate',\n templates.length,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${templates.length} templates exported.`);\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {string} templateId email template id\n * @param {string} file optional filename\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplateFromFile(\n templateId: string,\n file: string,\n raw = false\n) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (raw || validateImport(fileData.meta)) {\n createProgressIndicator('determinate', 1, `Importing ${templateId}`);\n if (\n fileData.emailTemplate[templateId] ||\n (raw && fileData._id === templateId)\n ) {\n try {\n const emailTemplateData = raw\n ? s2sConvert(fileData)\n : fileData.emailTemplate[templateId];\n await updateEmailTemplate(templateId, emailTemplateData);\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(`${updateEmailTemplateError}`);\n printMessage(updateEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId} not found in ${file}!`\n );\n printMessage(\n `Email template ${templateId} not found in ${file}!`,\n 'error'\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from file\n * @param {string} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file: string) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 'determinate',\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Helper function to get email template id from file name\n * @param {string} file file name\n * @returns {string} email template id/name\n */\nfunction readEmailTemplateIdFromFile(file: string) {\n debugMessage(\n `cli.EmailTemplateOps.readEmailTemplateIdFromFile: file=${file}`\n );\n const fileName = path.basename(file);\n const templateId = fileName.substring(14, fileName.indexOf('.'));\n debugMessage(\n `cli.EmailTemplateOps.readEmailTemplateIdFromFile: templateId=${templateId}`\n );\n return templateId;\n}\n\n/**\n * Convert template for s2s purposes (software-to-saas migration)\n * @param {EmailTemplateSkeleton} templateData template object\n * @returns {EmailTemplateSkeleton} converted template object\n */\nfunction s2sConvert(\n templateData: EmailTemplateSkeleton\n): EmailTemplateSkeleton {\n if (templateData.message && !templateData.html) {\n const convertedData = cloneDeep(templateData);\n convertedData.html = cloneDeep(templateData.message);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: templateData:`);\n debugMessage(templateData);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: convertedData:`);\n debugMessage(convertedData);\n return convertedData;\n }\n return templateData;\n}\n\n/**\n * Import all email templates from separate files\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplatesFromFiles(raw = false) {\n const names = fs.readdirSync('.');\n const jsonFiles = raw\n ? names.filter(\n (name) =>\n name.startsWith(`${EMAIL_TEMPLATE_TYPE}-`) && name.endsWith(`.json`)\n )\n : names.filter((name) =>\n name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n );\n createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing email templates...'\n );\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (\n (raw && file.startsWith('emailTemplate-')) ||\n validateImport(fileData.meta)\n ) {\n let errors = 0;\n if (raw) {\n total++;\n const templateId = readEmailTemplateIdFromFile(file);\n try {\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError, 'error');\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n } else {\n total += Object.keys(fileData.emailTemplate).length;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(`Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(\n file: string,\n raw = false\n) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (\n (raw && file.startsWith('emailTemplate-')) ||\n validateImport(fileData.meta)\n ) {\n showSpinner(`Importing first email template`);\n if (raw) {\n const templateId = readEmailTemplateIdFromFile(file);\n try {\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n succeedSpinner(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n failSpinner(`Error importing ${templateId}`);\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n } else {\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await updateEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n succeedSpinner(`Imported ${id}`);\n } catch (updateEmailTemplateError) {\n failSpinner(`Error importing ${id}`);\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n break;\n }\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,cAAc,EACdC,uBAAuB,QAClB,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC7E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC;AAAe,CAAC,GAAGhB,KAAK,CAACiB,KAAK;AACtC,MAAM;EACJC,mBAAmB;EACnBC,kBAAkB;EAClBC,iBAAiB;EACjBC;AACF,CAAC,GAAGrB,KAAK,CAACsB,KAAK,CAACC,QAAQ;AAExB,MAAMC,wBAAwB,GAAG,gBAAgB;AAEjD,MAAMC,sBAAsB,GAAG,IAAIC,MAAM,CAAE,GAAER,mBAAoB,GAAE,EAAE,GAAG,CAAC;;AAEzE;AACA,SAASS,mBAAmBA,CAAA,EAAG;EAC7B,OAAO;IACLC,IAAI,EAAE,CAAC,CAAC;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AE4B,YAAY,CAAC;UACnD7D,cAAc,CAAE,YAAWiC,UAAW,EAAC,CAAC;QAC1C,CAAC,CAAC,OAAO2C,wBAAwB,EAAE;UAAA,IAAAyB,sBAAA;UACjCzG,WAAW,CAAE,mBAAkBqC,UAAW,EAAC,CAAC;UAC5CpC,YAAY,EAAAwG,sBAAA,GAACzB,wBAAwB,CAACK,QAAQ,cAAAoB,sBAAA,uBAAjCA,sBAAA,CAAmC9B,IAAI,EAAE,OAAO,CAAC;QAChE;MACF,CAAC,MAAM;QACL,KAAK,MAAMO,EAAE,IAAIhB,QAAQ,CAAC3C,aAAa,EAAE;UACvC,IAAI,CAAC,CAAC,CAAC4D,cAAc,CAACC,IAAI,CAAClB,QAAQ,CAAC3C,aAAa,EAAE2D,EAAE,CAAC,EAAE;YACtD,IAAI;cACF,MAAMnE,mBAAmB,CACvBmE,EAAE,CAAC5C,OAAO,CAACnB,sBAAsB,EAAE,EAAE,CAAC,EACtC+C,QAAQ,CAAC3C,aAAa,CAAC2D,EAAE,CAC3B,CAAC;cACD9E,cAAc,CAAE,YAAW8E,EAAG,EAAC,CAAC;YAClC,CAAC,CAAC,OAAOF,wBAAwB,EAAE;cAAA,IAAA0B,sBAAA;cACjC1G,WAAW,CAAE,mBAAkBkF,EAAG,EAAC,CAAC;cACpCjF,YAAY,EAAAyG,sBAAA,GAAC1B,wBAAwB,CAACK,QAAQ,cAAAqB,sBAAA,uBAAjCA,sBAAA,CAAmC/B,IAAI,EAAE,OAAO,CAAC;YAChE;YACA;UACF;QACF;MACF;IACF,CAAC,MAAM;MACL1E,YAAY,CAAC,6BAA6B,EAAE,OAAO,CAAC;IACtD;EACF,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"EmailTemplateOps.js","names":["frodo","fs","path","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getTypedFilename","saveJsonToFile","cloneDeep","wordwrap","validateImport","getFilePath","getWorkingDirectory","utils","EMAIL_TEMPLATE_TYPE","readEmailTemplates","readEmailTemplate","updateEmailTemplate","email","template","EMAIL_TEMPLATE_FILE_TYPE","regexEmailTemplateType","RegExp","getFileDataTemplate","meta","emailTemplate","getOneLineDescription","templateObj","description","_id","split","displayName","defaultLocale","subject","Object","values","getTableHeaderMd","markdown","getTableRowMd","templateId","replace","locales","keys","length","filter","locale","join","row","name","listEmailTemplates","long","emailTemplates","error","message","sort","a","b","localeCompare","entries","table","push","enabled","from","toString","exportEmailTemplateToFile","file","fileName","filePath","templateData","fileData","err","exportEmailTemplatesToFile","templates","exportEmailTemplatesToFiles","importEmailTemplateFromFile","raw","replaceAll","readFile","data","JSON","parse","emailTemplateData","s2sConvert","updateEmailTemplateError","importEmailTemplatesFromFile","id","hasOwnProperty","call","response","readEmailTemplateIdFromFile","basename","substring","indexOf","html","convertedData","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","startsWith","endsWith","toLowerCase","map","total","totalErrors","readFileSync","errors","_updateEmailTemplateE","importFirstEmailTemplateFromFile","_updateEmailTemplateE2","_updateEmailTemplateE3"],"sources":["../../src/ops/EmailTemplateOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { EmailTemplateSkeleton } from '@rockcarver/frodo-lib/types/ops/EmailTemplateOps';\nimport fs from 'fs';\nimport path from 'path';\n\nimport {\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';\nimport { cloneDeep } from './utils/OpsUtils';\nimport wordwrap from './utils/Wordwrap';\n\nconst { validateImport, getFilePath, getWorkingDirectory } = frodo.utils;\nconst {\n EMAIL_TEMPLATE_TYPE,\n readEmailTemplates,\n readEmailTemplate,\n updateEmailTemplate,\n} = frodo.email.template;\n\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\n\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName ? templateObj.displayName : ''\n } - ${\n templateObj.defaultLocale\n ? templateObj.subject[templateObj.defaultLocale]\n : Object.values(templateObj.subject)[0]\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Display Name | Locale(s) | Subject | Id |\\n';\n markdown += '| ------------ | --------- | ------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the email template in markdown\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a table-row of the email template in markdown\n */\nexport function getTableRowMd(templateObj: EmailTemplateSkeleton): string {\n const templateId = templateObj._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const locales = `${templateObj.defaultLocale}${\n Object.keys(templateObj.subject).length > 1\n ? ` (${Object.keys(templateObj.subject)\n .filter((locale) => locale !== templateObj.defaultLocale)\n .join(',')})`\n : ''\n }`;\n const row = `| ${\n templateObj.name ? templateObj.name : templateId\n } | ${locales} | ${\n templateObj.subject[templateObj.defaultLocale]\n } | \\`${templateId}\\` |`;\n return row;\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = await readEmailTemplates();\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export single email template to a file\n * @param {string} templateId email template id to export\n * @param {string} file filename where to export the template data\n */\nexport async function exportEmailTemplateToFile(\n templateId: string,\n file: string\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n const filePath = getFilePath(fileName, true);\n createProgressIndicator('determinate', 1, `Exporting ${templateId}`);\n try {\n const templateData = await readEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${filePath}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n `Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n const filePath = getFilePath(fileName, true);\n try {\n const fileData = getFileDataTemplate();\n const templates = await readEmailTemplates();\n createProgressIndicator(\n 'determinate',\n templates.length,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n `${templates.length} templates exported to ${filePath}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const templates = await readEmailTemplates();\n createProgressIndicator(\n 'determinate',\n templates.length,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, getFilePath(fileName, true));\n }\n stopProgressIndicator(`${templates.length} templates exported.`);\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {string} templateId email template id\n * @param {string} file optional filename\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplateFromFile(\n templateId: string,\n file: string,\n raw = false\n) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const filePath = getFilePath(file);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (raw || validateImport(fileData.meta)) {\n createProgressIndicator('determinate', 1, `Importing ${templateId}`);\n if (\n fileData.emailTemplate[templateId] ||\n (raw && fileData._id === templateId)\n ) {\n try {\n const emailTemplateData = raw\n ? s2sConvert(fileData)\n : fileData.emailTemplate[templateId];\n await updateEmailTemplate(templateId, emailTemplateData);\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(`${updateEmailTemplateError}`);\n printMessage(updateEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId} not found in ${filePath}!`\n );\n printMessage(\n `Email template ${templateId} not found in ${filePath}!`,\n 'error'\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from file\n * @param {string} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file: string) {\n fs.readFile(getFilePath(file), 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 'determinate',\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Helper function to get email template id from file name\n * @param {string} file file name\n * @returns {string} email template id/name\n */\nfunction readEmailTemplateIdFromFile(file: string) {\n debugMessage(\n `cli.EmailTemplateOps.readEmailTemplateIdFromFile: file=${file}`\n );\n const fileName = path.basename(file);\n const templateId = fileName.substring(14, fileName.indexOf('.'));\n debugMessage(\n `cli.EmailTemplateOps.readEmailTemplateIdFromFile: templateId=${templateId}`\n );\n return templateId;\n}\n\n/**\n * Convert template for s2s purposes (software-to-saas migration)\n * @param {EmailTemplateSkeleton} templateData template object\n * @returns {EmailTemplateSkeleton} converted template object\n */\nfunction s2sConvert(\n templateData: EmailTemplateSkeleton\n): EmailTemplateSkeleton {\n if (templateData.message && !templateData.html) {\n const convertedData = cloneDeep(templateData);\n convertedData.html = cloneDeep(templateData.message);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: templateData:`);\n debugMessage(templateData);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: convertedData:`);\n debugMessage(convertedData);\n return convertedData;\n }\n return templateData;\n}\n\n/**\n * Import all email templates from separate files\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplatesFromFiles(raw = false) {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) =>\n raw\n ? name.startsWith(`${EMAIL_TEMPLATE_TYPE}-`) && name.endsWith(`.json`)\n : name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n )\n .map((name) => getFilePath(name));\n createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing email templates...'\n );\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (\n (raw && file.startsWith('emailTemplate-')) ||\n validateImport(fileData.meta)\n ) {\n let errors = 0;\n if (raw) {\n total++;\n const templateId = readEmailTemplateIdFromFile(file);\n try {\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError, 'error');\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n } else {\n total += Object.keys(fileData.emailTemplate).length;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(`Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(\n file: string,\n raw = false\n) {\n fs.readFile(getFilePath(file), 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (\n (raw && file.startsWith('emailTemplate-')) ||\n validateImport(fileData.meta)\n ) {\n showSpinner(`Importing first email template`);\n if (raw) {\n const templateId = readEmailTemplateIdFromFile(file);\n try {\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n succeedSpinner(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n failSpinner(`Error importing ${templateId}`);\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n } else {\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await updateEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n succeedSpinner(`Imported ${id}`);\n } catch (updateEmailTemplateError) {\n failSpinner(`Error importing ${id}`);\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n break;\n }\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAEvB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AjCA,sBAAA,CAAmC/B,IAAI,EAAE,OAAO,CAAC;QAChE;MACF,CAAC,MAAM;QACL,KAAK,MAAMO,EAAE,IAAIhB,QAAQ,CAAC5C,aAAa,EAAE;UACvC,IAAI,CAAC,CAAC,CAAC6D,cAAc,CAACC,IAAI,CAAClB,QAAQ,CAAC5C,aAAa,EAAE4D,EAAE,CAAC,EAAE;YACtD,IAAI;cACF,MAAMpE,mBAAmB,CACvBoE,EAAE,CAAC7C,OAAO,CAACnB,sBAAsB,EAAE,EAAE,CAAC,EACtCgD,QAAQ,CAAC5C,aAAa,CAAC4D,EAAE,CAC3B,CAAC;cACDjF,cAAc,CAAE,YAAWiF,EAAG,EAAC,CAAC;YAClC,CAAC,CAAC,OAAOF,wBAAwB,EAAE;cAAA,IAAA2B,sBAAA;cACjC9G,WAAW,CAAE,mBAAkBqF,EAAG,EAAC,CAAC;cACpCpF,YAAY,EAAA6G,sBAAA,GAAC3B,wBAAwB,CAACK,QAAQ,cAAAsB,sBAAA,uBAAjCA,sBAAA,CAAmChC,IAAI,EAAE,OAAO,CAAC;YAChE;YACA;UACF;QACF;MACF;IACF,CAAC,MAAM;MACL7E,YAAY,CAAC,6BAA6B,EAAE,OAAO,CAAC;IACtD;EACF,CAAC,CAAC;AACJ"}
|
package/esm/ops/IdmOps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { frodo } from '@rockcarver/frodo-lib';
|
|
1
|
+
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import fse from 'fs-extra';
|
|
4
4
|
import path from 'path';
|
|
@@ -8,7 +8,8 @@ import { createProgressIndicator, printMessage, stopProgressIndicator } from '..
|
|
|
8
8
|
import { getTypedFilename, readFiles } from '../utils/ExportImportUtils';
|
|
9
9
|
const {
|
|
10
10
|
unSubstituteEnvParams,
|
|
11
|
-
areScriptHooksValid
|
|
11
|
+
areScriptHooksValid,
|
|
12
|
+
getFilePath
|
|
12
13
|
} = frodo.utils;
|
|
13
14
|
const {
|
|
14
15
|
testConnectorServers,
|
|
@@ -62,7 +63,7 @@ export async function exportConfigEntity(id, file) {
|
|
|
62
63
|
fileName = getTypedFilename(`${id}`, 'idm');
|
|
63
64
|
}
|
|
64
65
|
const configEntity = await readConfigEntity(id);
|
|
65
|
-
fs.writeFile(fileName, JSON.stringify(configEntity, null, 2), err => {
|
|
66
|
+
fs.writeFile(getFilePath(fileName, true), JSON.stringify(configEntity, null, 2), err => {
|
|
66
67
|
if (err) {
|
|
67
68
|
return printMessage(`ERROR - can't save ${id} export to file`, 'error');
|
|
68
69
|
}
|
|
@@ -72,14 +73,10 @@ export async function exportConfigEntity(id, file) {
|
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* Export all IDM configuration objects into separate JSON files in a directory specified by <directory>
|
|
75
|
-
* @param {String} directory export directory
|
|
76
76
|
*/
|
|
77
|
-
export async function exportAllRawConfigEntities(
|
|
77
|
+
export async function exportAllRawConfigEntities() {
|
|
78
78
|
try {
|
|
79
79
|
const configurations = await readConfigEntities();
|
|
80
|
-
if (!fs.existsSync(directory)) {
|
|
81
|
-
fs.mkdirSync(directory);
|
|
82
|
-
}
|
|
83
80
|
createProgressIndicator('indeterminate', undefined, 'Exporting config objects...');
|
|
84
81
|
const entityPromises = [];
|
|
85
82
|
for (const configEntity of configurations) {
|
|
@@ -100,7 +97,7 @@ export async function exportAllRawConfigEntities(directory) {
|
|
|
100
97
|
const results = await Promise.all(entityPromises);
|
|
101
98
|
for (const item of results) {
|
|
102
99
|
if (item != null) {
|
|
103
|
-
fse.outputFile(`${
|
|
100
|
+
fse.outputFile(getFilePath(`${item._id}.json`, true), JSON.stringify(item, null, 2), err => {
|
|
104
101
|
if (err) {
|
|
105
102
|
return printMessage(`ERROR - can't save config ${item._id} to file - ${err}`, 'error');
|
|
106
103
|
}
|
|
@@ -116,11 +113,10 @@ export async function exportAllRawConfigEntities(directory) {
|
|
|
116
113
|
|
|
117
114
|
/**
|
|
118
115
|
* Export all IDM configuration objects
|
|
119
|
-
* @param {String} directory export directory
|
|
120
116
|
* @param {String} entitiesFile JSON file that specifies the config entities to export/import
|
|
121
117
|
* @param {String} envFile File that defines environment specific variables for replacement during configuration export/import
|
|
122
118
|
*/
|
|
123
|
-
export async function exportAllConfigEntities(
|
|
119
|
+
export async function exportAllConfigEntities(entitiesFile, envFile) {
|
|
124
120
|
let entriesToExport = [];
|
|
125
121
|
// read list of entities to export
|
|
126
122
|
fs.readFile(entitiesFile, 'utf8', async (err, data) => {
|
|
@@ -133,10 +129,6 @@ export async function exportAllConfigEntities(directory, entitiesFile, envFile)
|
|
|
133
129
|
const envParams = propertiesReader(envFile);
|
|
134
130
|
try {
|
|
135
131
|
const configurations = await readConfigEntities();
|
|
136
|
-
// create export directory if not exist
|
|
137
|
-
if (!fs.existsSync(directory)) {
|
|
138
|
-
fs.mkdirSync(directory);
|
|
139
|
-
}
|
|
140
132
|
createProgressIndicator('indeterminate', undefined, 'Exporting config objects...');
|
|
141
133
|
const entityPromises = [];
|
|
142
134
|
for (const configEntity of configurations) {
|
|
@@ -151,7 +143,7 @@ export async function exportAllConfigEntities(directory, entitiesFile, envFile)
|
|
|
151
143
|
envParams.each((key, value) => {
|
|
152
144
|
configEntityString = replaceall(value, `\${${key}}`, configEntityString);
|
|
153
145
|
});
|
|
154
|
-
fse.outputFile(`${
|
|
146
|
+
fse.outputFile(getFilePath(`${item._id}.json`, true), configEntityString, error => {
|
|
155
147
|
if (err) {
|
|
156
148
|
return printMessage(`ERROR - can't save config ${item._id} to file - ${error}`, 'error');
|
|
157
149
|
}
|
|
@@ -176,7 +168,7 @@ export async function importConfigEntityByIdFromFile(entityId, file, validate) {
|
|
|
176
168
|
if (!file) {
|
|
177
169
|
file = getTypedFilename(entityId, 'idm');
|
|
178
170
|
}
|
|
179
|
-
const fileData = fs.readFileSync(path.resolve(process.cwd(), file), 'utf8');
|
|
171
|
+
const fileData = fs.readFileSync(path.resolve(process.cwd(), getFilePath(file)), 'utf8');
|
|
180
172
|
const entityData = JSON.parse(fileData);
|
|
181
173
|
const isValid = areScriptHooksValid(entityData);
|
|
182
174
|
if (validate && !isValid) {
|
|
@@ -197,7 +189,7 @@ export async function importConfigEntityByIdFromFile(entityId, file, validate) {
|
|
|
197
189
|
* @param validate validate script hooks
|
|
198
190
|
*/
|
|
199
191
|
export async function importConfigEntityFromFile(file, validate) {
|
|
200
|
-
const fileData = fs.readFileSync(path.resolve(process.cwd(), file), 'utf8');
|
|
192
|
+
const fileData = fs.readFileSync(path.resolve(process.cwd(), getFilePath(file)), 'utf8');
|
|
201
193
|
const entityData = JSON.parse(fileData);
|
|
202
194
|
const entityId = entityData._id;
|
|
203
195
|
const isValid = areScriptHooksValid(entityData);
|
|
@@ -215,10 +207,10 @@ export async function importConfigEntityFromFile(file, validate) {
|
|
|
215
207
|
|
|
216
208
|
/**
|
|
217
209
|
* Import all IDM configuration objects from separate JSON files in a directory specified by <directory>
|
|
218
|
-
* @param baseDirectory export directory
|
|
219
210
|
* @param validate validate script hooks
|
|
220
211
|
*/
|
|
221
|
-
export async function importAllRawConfigEntities(
|
|
212
|
+
export async function importAllRawConfigEntities(validate) {
|
|
213
|
+
const baseDirectory = state.getDirectory();
|
|
222
214
|
if (!fs.existsSync(baseDirectory)) {
|
|
223
215
|
return;
|
|
224
216
|
}
|
|
@@ -265,12 +257,12 @@ export async function importAllRawConfigEntities(baseDirectory, validate) {
|
|
|
265
257
|
|
|
266
258
|
/**
|
|
267
259
|
* Import all IDM configuration objects
|
|
268
|
-
* @param baseDirectory import directory
|
|
269
260
|
* @param entitiesFile JSON file that specifies the config entities to export/import
|
|
270
261
|
* @param envFile File that defines environment specific variables for replacement during configuration export/import
|
|
271
262
|
* @param validate validate script hooks
|
|
272
263
|
*/
|
|
273
|
-
export async function importAllConfigEntities(
|
|
264
|
+
export async function importAllConfigEntities(entitiesFile, envFile, validate) {
|
|
265
|
+
const baseDirectory = state.getDirectory();
|
|
274
266
|
if (!fs.existsSync(baseDirectory)) {
|
|
275
267
|
return;
|
|
276
268
|
}
|