@rockcarver/frodo-cli 2.0.0-32 → 2.0.0-34
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 +8 -1
- package/esm/cli/FrodoCommand.js.map +1 -1
- package/esm/cli/admin/admin-execute-rfc7523-authz-grant-flow.js +41 -0
- package/esm/cli/admin/admin-execute-rfc7523-authz-grant-flow.js.map +1 -0
- package/esm/cli/admin/admin-export-full-cloud-config.js +44 -0
- package/esm/cli/admin/admin-export-full-cloud-config.js.map +1 -0
- package/esm/cli/admin/admin-generate-rfc7523-authz-grant-artifacts.js +43 -0
- package/esm/cli/admin/admin-generate-rfc7523-authz-grant-artifacts.js.map +1 -0
- package/esm/cli/admin/admin.js +3 -0
- package/esm/cli/admin/admin.js.map +1 -1
- package/esm/cli/authz/authz-policy-export.js +1 -1
- package/esm/cli/authz/authz-policy-export.js.map +1 -1
- package/esm/cli/authz/authz-policy-import.js +1 -1
- package/esm/cli/authz/authz-policy-import.js.map +1 -1
- package/esm/cli/authz/authz-policy-list.js +2 -2
- package/esm/cli/authz/authz-policy-list.js.map +1 -1
- package/esm/cli/authz/authz-set-delete.js +2 -2
- package/esm/cli/authz/authz-set-delete.js.map +1 -1
- package/esm/cli/authz/authz-set-export.js +1 -1
- package/esm/cli/authz/authz-set-export.js.map +1 -1
- package/esm/cli/authz/authz-set-import.js +1 -1
- package/esm/cli/authz/authz-set-import.js.map +1 -1
- package/esm/cli/authz/authz-set-list.js +1 -1
- package/esm/cli/authz/authz-set-list.js.map +1 -1
- package/esm/cli/authz/authz-type-delete.js +3 -3
- package/esm/cli/authz/authz-type-delete.js.map +1 -1
- package/esm/cli/authz/authz-type-export.js +2 -2
- package/esm/cli/authz/authz-type-export.js.map +1 -1
- package/esm/cli/authz/authz-type-import.js +2 -2
- package/esm/cli/authz/authz-type-import.js.map +1 -1
- package/esm/cli/authz/authz-type-list.js +1 -1
- package/esm/cli/authz/authz-type-list.js.map +1 -1
- package/esm/cli/email/email-template-export.js +3 -3
- package/esm/cli/email/email-template-export.js.map +1 -1
- package/esm/cli/email/email-template-import.js +4 -4
- package/esm/cli/email/email-template-import.js.map +1 -1
- package/esm/cli/email/email-template-list.js +1 -1
- package/esm/cli/email/email-template-list.js.map +1 -1
- package/esm/cli/esv/esv-secret-create.js +2 -1
- package/esm/cli/esv/esv-secret-create.js.map +1 -1
- package/esm/cli/esv/esv-secret-delete.js +4 -3
- package/esm/cli/esv/esv-secret-delete.js.map +1 -1
- package/esm/cli/esv/esv-secret-describe.js +2 -1
- package/esm/cli/esv/esv-secret-describe.js.map +1 -1
- package/esm/cli/esv/esv-secret-export.js +6 -4
- package/esm/cli/esv/esv-secret-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-list.js +2 -1
- package/esm/cli/esv/esv-secret-list.js.map +1 -1
- package/esm/cli/esv/esv-secret-set.js +2 -1
- package/esm/cli/esv/esv-secret-set.js.map +1 -1
- package/esm/cli/esv/esv-secret-version-activate.js +2 -2
- package/esm/cli/esv/esv-secret-version-activate.js.map +1 -1
- package/esm/cli/esv/esv-secret-version-create.js +2 -1
- package/esm/cli/esv/esv-secret-version-create.js.map +1 -1
- package/esm/cli/esv/esv-secret-version-deactivate.js +2 -2
- package/esm/cli/esv/esv-secret-version-deactivate.js.map +1 -1
- package/esm/cli/esv/esv-secret-version-delete.js +4 -3
- package/esm/cli/esv/esv-secret-version-delete.js.map +1 -1
- package/esm/cli/esv/esv-secret-version-list.js +2 -1
- package/esm/cli/esv/esv-secret-version-list.js.map +1 -1
- package/esm/cli/esv/esv-variable-create.js +2 -1
- package/esm/cli/esv/esv-variable-create.js.map +1 -1
- package/esm/cli/esv/esv-variable-delete.js +4 -2
- package/esm/cli/esv/esv-variable-delete.js.map +1 -1
- package/esm/cli/esv/esv-variable-describe.js +2 -1
- package/esm/cli/esv/esv-variable-describe.js.map +1 -1
- package/esm/cli/esv/esv-variable-export.js +6 -3
- package/esm/cli/esv/esv-variable-export.js.map +1 -1
- package/esm/cli/esv/esv-variable-list.js +2 -1
- package/esm/cli/esv/esv-variable-list.js.map +1 -1
- package/esm/cli/esv/esv-variable-set.js +4 -2
- package/esm/cli/esv/esv-variable-set.js.map +1 -1
- package/esm/cli/idm/idm-count.js +1 -1
- package/esm/cli/idm/idm-count.js.map +1 -1
- package/esm/cli/idm/idm-export.js +3 -3
- package/esm/cli/idm/idm-export.js.map +1 -1
- package/esm/cli/idm/idm-list.js +2 -2
- package/esm/cli/idm/idm-list.js.map +1 -1
- package/esm/cli/idp/idp-export.js +3 -3
- package/esm/cli/idp/idp-export.js.map +1 -1
- package/esm/cli/idp/idp-import.js +4 -4
- package/esm/cli/idp/idp-import.js.map +1 -1
- package/esm/cli/idp/idp-list.js +1 -1
- package/esm/cli/idp/idp-list.js.map +1 -1
- package/esm/cli/journey/journey-delete.js +6 -2
- package/esm/cli/journey/journey-delete.js.map +1 -1
- package/esm/cli/journey/journey-disable.js +4 -10
- package/esm/cli/journey/journey-disable.js.map +1 -1
- package/esm/cli/journey/journey-enable.js +4 -10
- package/esm/cli/journey/journey-enable.js.map +1 -1
- package/esm/cli/journey/journey-import.js +4 -4
- package/esm/cli/journey/journey-import.js.map +1 -1
- package/esm/cli/journey/journey-list.js +1 -1
- package/esm/cli/journey/journey-list.js.map +1 -1
- package/esm/cli/saml/saml-cot-export.js +3 -3
- package/esm/cli/saml/saml-cot-export.js.map +1 -1
- package/esm/cli/saml/saml-cot-list.js +1 -1
- package/esm/cli/saml/saml-cot-list.js.map +1 -1
- package/esm/cli/saml/saml-describe.js +1 -1
- package/esm/cli/saml/saml-describe.js.map +1 -1
- package/esm/cli/saml/saml-import.js +4 -4
- package/esm/cli/saml/saml-import.js.map +1 -1
- package/esm/cli/saml/saml-list.js +1 -1
- package/esm/cli/saml/saml-list.js.map +1 -1
- package/esm/cli/saml/saml-metadata-export.js +1 -1
- package/esm/cli/saml/saml-metadata-export.js.map +1 -1
- package/esm/cli/script/script-export.js +2 -6
- package/esm/cli/script/script-export.js.map +1 -1
- package/esm/cli/theme/theme-delete.js +3 -3
- package/esm/cli/theme/theme-delete.js.map +1 -1
- package/esm/cli/theme/theme-export.js +4 -4
- package/esm/cli/theme/theme-export.js.map +1 -1
- package/esm/cli/theme/theme-import.js +4 -4
- package/esm/cli/theme/theme-import.js.map +1 -1
- package/esm/cli/theme/theme-list.js +1 -1
- package/esm/cli/theme/theme-list.js.map +1 -1
- package/esm/ops/AdminFederationOps.js +28 -26
- package/esm/ops/AdminFederationOps.js.map +1 -1
- package/esm/ops/AdminOps.js +241 -0
- package/esm/ops/AdminOps.js.map +1 -0
- package/esm/ops/AgentOps.js +59 -51
- package/esm/ops/AgentOps.js.map +1 -1
- package/esm/ops/ApplicationOps.js +19 -13
- package/esm/ops/ApplicationOps.js.map +1 -1
- package/esm/ops/CirclesOfTrustOps.js +28 -26
- package/esm/ops/CirclesOfTrustOps.js.map +1 -1
- package/esm/ops/EmailTemplateOps.js +78 -94
- package/esm/ops/EmailTemplateOps.js.map +1 -1
- package/esm/ops/IdmOps.js +8 -31
- package/esm/ops/IdmOps.js.map +1 -1
- package/esm/ops/IdpOps.js +49 -54
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/JourneyOps.js +91 -70
- package/esm/ops/JourneyOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +13 -11
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/PolicyOps.js +31 -26
- package/esm/ops/PolicyOps.js.map +1 -1
- package/esm/ops/PolicySetOps.js +42 -39
- package/esm/ops/PolicySetOps.js.map +1 -1
- package/esm/ops/ResourceTypeOps.js +19 -16
- package/esm/ops/ResourceTypeOps.js.map +1 -1
- package/esm/ops/Saml2Ops.js +49 -45
- package/esm/ops/Saml2Ops.js.map +1 -1
- package/esm/ops/ScriptOps.js +36 -55
- package/esm/ops/ScriptOps.js.map +1 -1
- package/esm/ops/SecretsOps.js +159 -60
- package/esm/ops/SecretsOps.js.map +1 -1
- package/esm/ops/ThemeOps.js +111 -130
- package/esm/ops/ThemeOps.js.map +1 -1
- package/esm/ops/VariablesOps.js +126 -56
- package/esm/ops/VariablesOps.js.map +1 -1
- package/esm/utils/Console.js +69 -30
- package/esm/utils/Console.js.map +1 -1
- package/esm/utils/ExportImportUtils.js +4 -12
- package/esm/utils/ExportImportUtils.js.map +1 -1
- package/package.json +10 -2
|
@@ -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","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","getTemplateIdFromFileName","emailTemplateData","s2sConvert","updateEmailTemplateError","importEmailTemplatesFromFile","id","hasOwnProperty","call","response","basename","Error","html","convertedData","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","startsWith","endsWith","toLowerCase","map","total","totalErrors","readFileSync","errors","_updateEmailTemplateE","importFirstEmailTemplateFromFile","_error$response","_updateEmailTemplateE2"],"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 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 && fileData.emailTemplate[templateId]) ||\n (raw && getTemplateIdFromFileName(file) === 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 getTemplateIdFromFileName(file: string) {\n debugMessage(`cli.EmailTemplateOps.getTemplateIdFromFileName: file=${file}`);\n const basename = path.basename(file);\n const keys = basename.split('-');\n if (keys[0] !== EMAIL_TEMPLATE_TYPE || keys.length <= 1)\n throw new Error(`Filename does not indicate a raw email template: ${file}`);\n const templateId = keys[1].split('.')[0];\n debugMessage(\n `cli.EmailTemplateOps.getTemplateIdFromFileName: 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 = getTemplateIdFromFileName(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 (raw || validateImport(fileData.meta)) {\n showSpinner(`Importing first email template`);\n if (raw) {\n try {\n const templateId = getTemplateIdFromFileName(file);\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n succeedSpinner(`Imported ${templateId}`);\n } catch (error) {\n failSpinner(`Error importing email template: ${error}`);\n printMessage(error.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,cAAc;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGlB,KAAK,CAACmB,KAAK;AACxE,MAAM;EACJC,mBAAmB;EACnBC,kBAAkB;EAClBC,iBAAiB;EACjBC;AACF,CAAC,GAAGvB,KAAK,CAACwB,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;IACRC,aAAa,EAAE,CAAC;EAClB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,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AA4G,sBAAA,GAACzB,wBAAwB,CAACK,QAAQ,cAAAoB,sBAAA,uBAAjCA,sBAAA,CAAmC/B,IAAI,EAAE,OAAO,CAAC;YAChE;YACA;UACF;QACF;MACF;IACF,CAAC,MAAM;MACL7E,YAAY,CAAC,6BAA6B,EAAE,OAAO,CAAC;IACtD;EACF,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"EmailTemplateOps.js","names":["frodo","fs","path","createProgressIndicator","createTable","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getTypedFilename","saveJsonToFile","cloneDeep","wordwrap","validateImport","getFilePath","getWorkingDirectory","utils","EMAIL_TEMPLATE_TYPE","readEmailTemplates","readEmailTemplate","exportEmailTemplates","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","indicatorId","templateData","fileData","err","exportEmailTemplatesToFile","exportData","exportEmailTemplatesToFiles","importEmailTemplateFromFile","raw","replaceAll","data","readFileSync","JSON","parse","getTemplateIdFromFileName","emailTemplateData","s2sConvert","updateEmailTemplateError","importEmailTemplatesFromFile","id","response","basename","Error","html","convertedData","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","startsWith","endsWith","toLowerCase","map","total","totalErrors","errors","_updateEmailTemplateE","hasOwnProperty","call","importFirstEmailTemplateFromFile","_error$response","_updateEmailTemplateE2"],"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 printMessage,\n stopProgressIndicator,\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 exportEmailTemplates,\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 const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${templateId}`\n );\n try {\n const templateData = await readEmailTemplate(templateId);\n updateProgressIndicator(indicatorId, `Writing file ${filePath}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n indicatorId,\n `Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${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 exportData = await exportEmailTemplates();\n saveJsonToFile(exportData, filePath);\n } catch (err) {\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n let indicatorId: string;\n try {\n const exportData = Object.entries(\n (await exportEmailTemplates()).emailTemplate\n );\n indicatorId = createProgressIndicator(\n 'determinate',\n exportData.length,\n 'Writing email templates'\n );\n for (const [templateId, template] of exportData) {\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(indicatorId, `Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, getFilePath(fileName, true));\n }\n stopProgressIndicator(\n indicatorId,\n `${exportData.length} templates written.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${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 templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const filePath = getFilePath(file);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Importing ${templateId}`\n );\n if (\n (fileData.emailTemplate && fileData.emailTemplate[templateId]) ||\n (raw && getTemplateIdFromFileName(file) === templateId)\n ) {\n try {\n const emailTemplateData = raw\n ? s2sConvert(fileData)\n : fileData.emailTemplate[templateId];\n await updateEmailTemplate(templateId, emailTemplateData);\n updateProgressIndicator(indicatorId, `Importing ${templateId}`);\n stopProgressIndicator(indicatorId, `Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(indicatorId, `${updateEmailTemplateError}`);\n printMessage(updateEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n indicatorId,\n `Email template ${templateId} not found in ${filePath}!`\n );\n printMessage(\n `Email template ${templateId} not found in ${filePath}!`,\n 'error'\n );\n }\n } catch (error) {\n printMessage(\n `Error importing email template ${templateId}: ${error}`,\n '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 try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id of Object.keys(fileData.emailTemplate)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(indicatorId, `Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n stopProgressIndicator(indicatorId, `Done.`);\n } catch (error) {\n printMessage(`Error importing email templates: ${error}`, 'error');\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 getTemplateIdFromFileName(file: string) {\n debugMessage(`cli.EmailTemplateOps.getTemplateIdFromFileName: file=${file}`);\n const basename = path.basename(file);\n const keys = basename.split('-');\n if (keys[0] !== EMAIL_TEMPLATE_TYPE || keys.length <= 1)\n throw new Error(`Filename does not indicate a raw email template: ${file}`);\n const templateId = keys[1].split('.')[0];\n debugMessage(\n `cli.EmailTemplateOps.getTemplateIdFromFileName: 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 const indicatorId = 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 = getTemplateIdFromFileName(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(indicatorId, `Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\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 let indicatorId: string;\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing first email template`\n );\n if (raw) {\n try {\n const templateId = getTemplateIdFromFileName(file);\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n stopProgressIndicator(indicatorId, `Imported ${templateId}`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing email template: ${error}`,\n 'fail'\n );\n printMessage(error.response?.data, 'error');\n }\n } else {\n for (const id of Object.keys(fileData.emailTemplate)) {\n try {\n await updateEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n stopProgressIndicator(indicatorId, `Imported ${id}`, 'success');\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(indicatorId, `Error importing ${id}`, 'fail');\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n break;\n }\n }\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing first email template`,\n 'fail'\n );\n printMessage(`Error importing first email template: ${error}`, 'error');\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,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC7E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC,cAAc;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGf,KAAK,CAACgB,KAAK;AACxE,MAAM;EACJC,mBAAmB;EACnBC,kBAAkB;EAClBC,iBAAiB;EACjBC,oBAAoB;EACpBC;AACF,CAAC,GAAGrB,KAAK,CAACsB,KAAK,CAACC,QAAQ;AAExB,MAAMC,wBAAwB,GAAG,gBAAgB;AAEjD,MAAMC,sBAAsB,GAAG,IAAIC,MAAM,CAAE,GAAET,mBAAoB,GAAE,EAAE,GAAG,CAAC;;AAEzE;AACA,SAASU,mBAAmBA,CAAA,EAAG;EAC7B,OAAO;IACLC,IAAI,EAAE,CAAC,CAAC;IACRC,aAAa,EAAE,CAAC;EAClB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,WAAkC,EAC1B;EACR,MAAMC,WAAW,GAAI,IAAGD,WAAW,CAACE,GAAG,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAE,K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B,IAAI,EAAE,OAAO,CAAC;MAC7C;IACF,CAAC,MAAM;MACL,KAAK,MAAMS,EAAE,IAAIrD,MAAM,CAACQ,IAAI,CAAC4B,QAAQ,CAAC7C,aAAa,CAAC,EAAE;QACpD,IAAI;UACF,MAAMR,mBAAmB,CACvBsE,EAAE,CAAC/C,OAAO,CAACnB,sBAAsB,EAAE,EAAE,CAAC,EACtCiD,QAAQ,CAAC7C,aAAa,CAAC8D,EAAE,CAC3B,CAAC;UACDpF,qBAAqB,CAACiE,WAAW,EAAG,YAAWmB,EAAG,EAAC,EAAE,SAAS,CAAC;QACjE,CAAC,CAAC,OAAOF,wBAAwB,EAAE;UAAA,IAAAwB,sBAAA;UACjC1G,qBAAqB,CAACiE,WAAW,EAAG,mBAAkBmB,EAAG,EAAC,EAAE,MAAM,CAAC;UACnErF,YAAY,EAAA2G,sBAAA,GAACxB,wBAAwB,CAACG,QAAQ,cAAAqB,sBAAA,uBAAjCA,sBAAA,CAAmC/B,IAAI,EAAE,OAAO,CAAC;QAChE;QACA;MACF;IACF;EACF,CAAC,CAAC,OAAO1B,KAAK,EAAE;IACdjD,qBAAqB,CACnBiE,WAAW,EACV,sCAAqC,EACtC,MACF,CAAC;IACDlE,YAAY,CAAE,yCAAwCkD,KAAM,EAAC,EAAE,OAAO,CAAC;EACzE;AACF"}
|
package/esm/ops/IdmOps.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
testConnectorServers,
|
|
16
16
|
readConfigEntities,
|
|
17
17
|
readConfigEntity,
|
|
18
|
+
exportConfigEntities,
|
|
18
19
|
updateConfigEntity
|
|
19
20
|
} = frodo.idm.config;
|
|
20
21
|
const {
|
|
@@ -75,39 +76,15 @@ export async function exportConfigEntity(id, file) {
|
|
|
75
76
|
* Export all IDM configuration objects into separate JSON files in a directory specified by <directory>
|
|
76
77
|
*/
|
|
77
78
|
export async function exportAllRawConfigEntities() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var _readConfigEntityErro, _readConfigEntityErro2, _readConfigEntityErro3, _readConfigEntityErro4, _readConfigEntityErro5, _readConfigEntityErro6;
|
|
85
|
-
if (!(((_readConfigEntityErro = readConfigEntityError.response) === null || _readConfigEntityErro === void 0 ? void 0 : _readConfigEntityErro.status) === 403 && ((_readConfigEntityErro2 = readConfigEntityError.response) === null || _readConfigEntityErro2 === void 0 || (_readConfigEntityErro2 = _readConfigEntityErro2.data) === null || _readConfigEntityErro2 === void 0 ? void 0 : _readConfigEntityErro2.message) === 'This operation is not available in ForgeRock Identity Cloud.') && !(
|
|
86
|
-
// list of config entities, which do not exist by default or ever.
|
|
87
|
-
|
|
88
|
-
['script', 'notificationFactory', 'apiVersion', 'metrics', 'repo.init', 'endpoint/validateQueryFilter', 'endpoint/oauthproxy', 'external.rest', 'scheduler', 'org.apache.felix.fileinstall/openidm', 'cluster', 'endpoint/mappingDetails', 'fieldPolicy/teammember'].includes(configEntity._id) && ((_readConfigEntityErro3 = readConfigEntityError.response) === null || _readConfigEntityErro3 === void 0 ? void 0 : _readConfigEntityErro3.status) === 404 && ((_readConfigEntityErro4 = readConfigEntityError.response) === null || _readConfigEntityErro4 === void 0 || (_readConfigEntityErro4 = _readConfigEntityErro4.data) === null || _readConfigEntityErro4 === void 0 ? void 0 : _readConfigEntityErro4.reason) === 'Not Found') &&
|
|
89
|
-
// https://bugster.forgerock.org/jira/browse/OPENIDM-18270
|
|
90
|
-
!(((_readConfigEntityErro5 = readConfigEntityError.response) === null || _readConfigEntityErro5 === void 0 ? void 0 : _readConfigEntityErro5.status) === 404 && ((_readConfigEntityErro6 = readConfigEntityError.response) === null || _readConfigEntityErro6 === void 0 || (_readConfigEntityErro6 = _readConfigEntityErro6.data) === null || _readConfigEntityErro6 === void 0 ? void 0 : _readConfigEntityErro6.message) === 'No configuration exists for id org.apache.felix.fileinstall/openidm')) {
|
|
91
|
-
var _readConfigEntityErro7;
|
|
92
|
-
printMessage((_readConfigEntityErro7 = readConfigEntityError.response) === null || _readConfigEntityErro7 === void 0 ? void 0 : _readConfigEntityErro7.data, 'error');
|
|
93
|
-
printMessage(`Error getting config entity ${configEntity._id}: ${readConfigEntityError}`, 'error');
|
|
79
|
+
const exportedConfigurations = await exportConfigEntities();
|
|
80
|
+
for (const [id, value] of Object.entries(exportedConfigurations.config)) {
|
|
81
|
+
if (value != null) {
|
|
82
|
+
fse.outputFile(getFilePath(`${id}.json`, true), JSON.stringify(value, null, 2), err => {
|
|
83
|
+
if (err) {
|
|
84
|
+
return printMessage(`ERROR - can't save config ${id} to file - ${err}`, 'error');
|
|
94
85
|
}
|
|
95
|
-
})
|
|
86
|
+
});
|
|
96
87
|
}
|
|
97
|
-
const results = await Promise.all(entityPromises);
|
|
98
|
-
for (const item of results) {
|
|
99
|
-
if (item != null) {
|
|
100
|
-
fse.outputFile(getFilePath(`${item._id}.json`, true), JSON.stringify(item, null, 2), err => {
|
|
101
|
-
if (err) {
|
|
102
|
-
return printMessage(`ERROR - can't save config ${item._id} to file - ${err}`, 'error');
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
stopProgressIndicator('Exported config objects.', 'success');
|
|
108
|
-
} catch (readConfigEntitiesError) {
|
|
109
|
-
printMessage(readConfigEntitiesError, 'error');
|
|
110
|
-
printMessage(`Error getting config entities: ${readConfigEntitiesError}`, 'error');
|
|
111
88
|
}
|
|
112
89
|
}
|
|
113
90
|
|
package/esm/ops/IdmOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdmOps.js","names":["frodo","state","fs","fse","path","propertiesReader","replaceall","createProgressIndicator","printMessage","stopProgressIndicator","getTypedFilename","readFiles","unSubstituteEnvParams","areScriptHooksValid","getFilePath","utils","testConnectorServers","readConfigEntities","readConfigEntity","updateConfigEntity","idm","config","queryManagedObjects","managed","warnAboutOfflineConnectorServers","all","offline","filter","status","ok","map","name","length","join","error","message","listAllConfigEntities","configurations","configEntity","_id","readConfigEntitiesError","exportConfigEntity","id","file","fileName","writeFile","JSON","stringify","err","exportAllRawConfigEntities","undefined","entityPromises","push","catch","readConfigEntityError","_readConfigEntityErro","_readConfigEntityErro2","_readConfigEntityErro3","_readConfigEntityErro4","_readConfigEntityErro5","_readConfigEntityErro6","response","data","includes","reason","_readConfigEntityErro7","results","Promise","item","outputFile","exportAllConfigEntities","entitiesFile","envFile","entriesToExport","readFile","entriesData","parse","envParams","configEntityString","each","key","value","importConfigEntityByIdFromFile","entityId","validate","fileData","readFileSync","resolve","process","cwd","entityData","isValid","updateConfigEntityError","importConfigEntityFromFile","importAllRawConfigEntities","baseDirectory","getDirectory","existsSync","files","jsonFiles","toLowerCase","endsWith","content","substring","everyScriptValid","jsObject","isScriptValid","allSettled","errors","result","importAllConfigEntities","entriesToImport","envReader","unsubstituted","countManagedObjects","type"],"sources":["../../src/ops/IdmOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport fse from 'fs-extra';\nimport path from 'path';\nimport propertiesReader from 'properties-reader';\nimport replaceall from 'replaceall';\n\nimport {\n createProgressIndicator,\n printMessage,\n stopProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, readFiles } from '../utils/ExportImportUtils';\n\nconst { unSubstituteEnvParams, areScriptHooksValid, getFilePath } = frodo.utils;\nconst {\n testConnectorServers,\n readConfigEntities,\n readConfigEntity,\n updateConfigEntity,\n} = frodo.idm.config;\nconst { queryManagedObjects } = frodo.idm.managed;\n\n/**\n * Warn about and list offline remote connector servers\n */\nexport async function warnAboutOfflineConnectorServers() {\n try {\n const all = await testConnectorServers();\n const offline = all\n .filter((status) => !status.ok)\n .map((status) => status.name);\n if (offline.length) {\n printMessage(\n `\\nThe following connector server(s) are offline and their connectors and configuration unavailable:\\n${offline.join(\n '\\n'\n )}`,\n 'warn'\n );\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(\n `Error getting offline connector servers: ${error.message}`,\n 'error'\n );\n }\n}\n\n/**\n * List all IDM configuration objects\n */\nexport async function listAllConfigEntities() {\n try {\n const configurations = await readConfigEntities();\n for (const configEntity of configurations) {\n printMessage(`${configEntity._id}`, 'data');\n }\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n}\n\n/**\n * Export an IDM configuration object.\n * @param {String} id the desired configuration object\n * @param {String} file optional export file\n */\nexport async function exportConfigEntity(id, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`${id}`, 'idm');\n }\n const configEntity = await readConfigEntity(id);\n fs.writeFile(\n getFilePath(fileName, true),\n JSON.stringify(configEntity, null, 2),\n (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${id} export to file`, 'error');\n }\n return '';\n }\n );\n}\n\n/**\n * Export all IDM configuration objects into separate JSON files in a directory specified by <directory>\n */\nexport async function exportAllRawConfigEntities() {\n try {\n const configurations = await readConfigEntities();\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Exporting config objects...'\n );\n const entityPromises = [];\n for (const configEntity of configurations) {\n entityPromises.push(\n readConfigEntity(configEntity._id).catch((readConfigEntityError) => {\n if (\n !(\n readConfigEntityError.response?.status === 403 &&\n readConfigEntityError.response?.data?.message ===\n 'This operation is not available in ForgeRock Identity Cloud.'\n ) &&\n !(\n // list of config entities, which do not exist by default or ever.\n (\n [\n 'script',\n 'notificationFactory',\n 'apiVersion',\n 'metrics',\n 'repo.init',\n 'endpoint/validateQueryFilter',\n 'endpoint/oauthproxy',\n 'external.rest',\n 'scheduler',\n 'org.apache.felix.fileinstall/openidm',\n 'cluster',\n 'endpoint/mappingDetails',\n 'fieldPolicy/teammember',\n ].includes(configEntity._id) &&\n readConfigEntityError.response?.status === 404 &&\n readConfigEntityError.response?.data?.reason === 'Not Found'\n )\n ) &&\n // https://bugster.forgerock.org/jira/browse/OPENIDM-18270\n !(\n readConfigEntityError.response?.status === 404 &&\n readConfigEntityError.response?.data?.message ===\n 'No configuration exists for id org.apache.felix.fileinstall/openidm'\n )\n ) {\n printMessage(readConfigEntityError.response?.data, 'error');\n printMessage(\n `Error getting config entity ${configEntity._id}: ${readConfigEntityError}`,\n 'error'\n );\n }\n })\n );\n }\n const results = await Promise.all(entityPromises);\n for (const item of results) {\n if (item != null) {\n fse.outputFile(\n getFilePath(`${item._id}.json`, true),\n JSON.stringify(item, null, 2),\n (err) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${item._id} to file - ${err}`,\n 'error'\n );\n }\n }\n );\n }\n }\n stopProgressIndicator('Exported config objects.', 'success');\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n}\n\n/**\n * Export all IDM configuration objects\n * @param {String} entitiesFile JSON file that specifies the config entities to export/import\n * @param {String} envFile File that defines environment specific variables for replacement during configuration export/import\n */\nexport async function exportAllConfigEntities(entitiesFile, envFile) {\n let entriesToExport = [];\n // read list of entities to export\n fs.readFile(entitiesFile, 'utf8', async (err, data) => {\n if (err) throw err;\n const entriesData = JSON.parse(data);\n entriesToExport = entriesData.idm;\n // console.log(`entriesToExport ${entriesToExport}`);\n\n // read list of configs to parameterize for environment specific values\n const envParams = propertiesReader(envFile);\n\n try {\n const configurations = await readConfigEntities();\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Exporting config objects...'\n );\n const entityPromises = [];\n for (const configEntity of configurations) {\n if (entriesToExport.includes(configEntity._id)) {\n entityPromises.push(readConfigEntity(configEntity._id));\n }\n }\n const results = await Promise.all(entityPromises);\n for (const item of results) {\n if (item != null) {\n let configEntityString = JSON.stringify(item, null, 2);\n envParams.each((key, value) => {\n configEntityString = replaceall(\n value,\n `\\${${key}}`,\n configEntityString\n );\n });\n fse.outputFile(\n getFilePath(`${item._id}.json`, true),\n configEntityString,\n (error) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${item._id} to file - ${error}`,\n 'error'\n );\n }\n }\n );\n }\n }\n stopProgressIndicator(null, 'success');\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n });\n}\n\n/**\n * Import an IDM configuration object by id from file.\n * @param entityId the configuration object to import\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityByIdFromFile(\n entityId: string,\n file?: string,\n validate?: boolean\n) {\n if (!file) {\n file = getTypedFilename(entityId, 'idm');\n }\n\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n\n const entityData = JSON.parse(fileData);\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import IDM configuration object from file.\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityFromFile(\n file: string,\n validate?: boolean\n) {\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n const entityData = JSON.parse(fileData);\n const entityId = entityData._id;\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import all IDM configuration objects from separate JSON files in a directory specified by <directory>\n * @param validate validate script hooks\n */\nexport async function importAllRawConfigEntities(validate?: boolean) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ path, content }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles.map((file) => {\n return updateConfigEntity(file.entityId, JSON.parse(file.content));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Import all IDM configuration objects\n * @param entitiesFile JSON file that specifies the config entities to export/import\n * @param envFile File that defines environment specific variables for replacement during configuration export/import\n * @param validate validate script hooks\n */\nexport async function importAllConfigEntities(\n entitiesFile: string,\n envFile: string,\n validate?: boolean\n) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const entriesToImport = JSON.parse(fs.readFileSync(entitiesFile, 'utf8')).idm;\n\n const envReader = propertiesReader(envFile);\n\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ content, path }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles\n .filter(({ entityId }) => {\n return entriesToImport.includes(entityId);\n })\n .map(({ entityId, content }) => {\n const unsubstituted = unSubstituteEnvParams(content, envReader);\n return updateConfigEntity(entityId, JSON.parse(unsubstituted));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Count number of managed objects of a given type\n * @param {String} type managed object type, e.g. alpha_user\n */\nexport async function countManagedObjects(type: string) {\n try {\n const result = await queryManagedObjects(type);\n printMessage(`${type}: ${result.length}`, 'data');\n } catch (error) {\n printMessage(error.response.data, 'error');\n printMessage(`Error querying managed objects by type: ${error}`, 'error');\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,GAAG,MAAM,UAAU;AAC1B,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,gBAAgB,MAAM,mBAAmB;AAChD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,uBAAuB,EACvBC,YAAY,EACZC,qBAAqB,QAChB,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,4BAA4B;AAExE,MAAM;EAAEC,qBAAqB;EAAEC,mBAAmB;EAAEC;AAAY,CAAC,GAAGd,KAAK,CAACe,KAAK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AM,EAAC,EAAE,OAAO,CAAC;EAC3E;AACF"}
|
|
1
|
+
{"version":3,"file":"IdmOps.js","names":["frodo","state","fs","fse","path","propertiesReader","replaceall","createProgressIndicator","printMessage","stopProgressIndicator","getTypedFilename","readFiles","unSubstituteEnvParams","areScriptHooksValid","getFilePath","utils","testConnectorServers","readConfigEntities","readConfigEntity","exportConfigEntities","updateConfigEntity","idm","config","queryManagedObjects","managed","warnAboutOfflineConnectorServers","all","offline","filter","status","ok","map","name","length","join","error","message","listAllConfigEntities","configurations","configEntity","_id","readConfigEntitiesError","exportConfigEntity","id","file","fileName","writeFile","JSON","stringify","err","exportAllRawConfigEntities","exportedConfigurations","value","Object","entries","outputFile","exportAllConfigEntities","entitiesFile","envFile","entriesToExport","readFile","data","entriesData","parse","envParams","undefined","entityPromises","includes","push","results","Promise","item","configEntityString","each","key","importConfigEntityByIdFromFile","entityId","validate","fileData","readFileSync","resolve","process","cwd","entityData","isValid","updateConfigEntityError","importConfigEntityFromFile","importAllRawConfigEntities","baseDirectory","getDirectory","existsSync","files","jsonFiles","toLowerCase","endsWith","content","substring","everyScriptValid","jsObject","isScriptValid","allSettled","errors","result","reason","importAllConfigEntities","entriesToImport","envReader","unsubstituted","countManagedObjects","type","response"],"sources":["../../src/ops/IdmOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport fse from 'fs-extra';\nimport path from 'path';\nimport propertiesReader from 'properties-reader';\nimport replaceall from 'replaceall';\n\nimport {\n createProgressIndicator,\n printMessage,\n stopProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, readFiles } from '../utils/ExportImportUtils';\n\nconst { unSubstituteEnvParams, areScriptHooksValid, getFilePath } = frodo.utils;\nconst {\n testConnectorServers,\n readConfigEntities,\n readConfigEntity,\n exportConfigEntities,\n updateConfigEntity,\n} = frodo.idm.config;\nconst { queryManagedObjects } = frodo.idm.managed;\n\n/**\n * Warn about and list offline remote connector servers\n */\nexport async function warnAboutOfflineConnectorServers() {\n try {\n const all = await testConnectorServers();\n const offline = all\n .filter((status) => !status.ok)\n .map((status) => status.name);\n if (offline.length) {\n printMessage(\n `\\nThe following connector server(s) are offline and their connectors and configuration unavailable:\\n${offline.join(\n '\\n'\n )}`,\n 'warn'\n );\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(\n `Error getting offline connector servers: ${error.message}`,\n 'error'\n );\n }\n}\n\n/**\n * List all IDM configuration objects\n */\nexport async function listAllConfigEntities() {\n try {\n const configurations = await readConfigEntities();\n for (const configEntity of configurations) {\n printMessage(`${configEntity._id}`, 'data');\n }\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n}\n\n/**\n * Export an IDM configuration object.\n * @param {String} id the desired configuration object\n * @param {String} file optional export file\n */\nexport async function exportConfigEntity(id, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`${id}`, 'idm');\n }\n const configEntity = await readConfigEntity(id);\n fs.writeFile(\n getFilePath(fileName, true),\n JSON.stringify(configEntity, null, 2),\n (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${id} export to file`, 'error');\n }\n return '';\n }\n );\n}\n\n/**\n * Export all IDM configuration objects into separate JSON files in a directory specified by <directory>\n */\nexport async function exportAllRawConfigEntities() {\n const exportedConfigurations = await exportConfigEntities();\n for (const [id, value] of Object.entries(exportedConfigurations.config)) {\n if (value != null) {\n fse.outputFile(\n getFilePath(`${id}.json`, true),\n JSON.stringify(value, null, 2),\n (err) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${id} to file - ${err}`,\n 'error'\n );\n }\n }\n );\n }\n }\n}\n\n/**\n * Export all IDM configuration objects\n * @param {String} entitiesFile JSON file that specifies the config entities to export/import\n * @param {String} envFile File that defines environment specific variables for replacement during configuration export/import\n */\nexport async function exportAllConfigEntities(entitiesFile, envFile) {\n let entriesToExport = [];\n // read list of entities to export\n fs.readFile(entitiesFile, 'utf8', async (err, data) => {\n if (err) throw err;\n const entriesData = JSON.parse(data);\n entriesToExport = entriesData.idm;\n // console.log(`entriesToExport ${entriesToExport}`);\n\n // read list of configs to parameterize for environment specific values\n const envParams = propertiesReader(envFile);\n\n try {\n const configurations = await readConfigEntities();\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Exporting config objects...'\n );\n const entityPromises = [];\n for (const configEntity of configurations) {\n if (entriesToExport.includes(configEntity._id)) {\n entityPromises.push(readConfigEntity(configEntity._id));\n }\n }\n const results = await Promise.all(entityPromises);\n for (const item of results) {\n if (item != null) {\n let configEntityString = JSON.stringify(item, null, 2);\n envParams.each((key, value) => {\n configEntityString = replaceall(\n value,\n `\\${${key}}`,\n configEntityString\n );\n });\n fse.outputFile(\n getFilePath(`${item._id}.json`, true),\n configEntityString,\n (error) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${item._id} to file - ${error}`,\n 'error'\n );\n }\n }\n );\n }\n }\n stopProgressIndicator(null, 'success');\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n });\n}\n\n/**\n * Import an IDM configuration object by id from file.\n * @param entityId the configuration object to import\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityByIdFromFile(\n entityId: string,\n file?: string,\n validate?: boolean\n) {\n if (!file) {\n file = getTypedFilename(entityId, 'idm');\n }\n\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n\n const entityData = JSON.parse(fileData);\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import IDM configuration object from file.\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityFromFile(\n file: string,\n validate?: boolean\n) {\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n const entityData = JSON.parse(fileData);\n const entityId = entityData._id;\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import all IDM configuration objects from separate JSON files in a directory specified by <directory>\n * @param validate validate script hooks\n */\nexport async function importAllRawConfigEntities(validate?: boolean) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ path, content }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles.map((file) => {\n return updateConfigEntity(file.entityId, JSON.parse(file.content));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Import all IDM configuration objects\n * @param entitiesFile JSON file that specifies the config entities to export/import\n * @param envFile File that defines environment specific variables for replacement during configuration export/import\n * @param validate validate script hooks\n */\nexport async function importAllConfigEntities(\n entitiesFile: string,\n envFile: string,\n validate?: boolean\n) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const entriesToImport = JSON.parse(fs.readFileSync(entitiesFile, 'utf8')).idm;\n\n const envReader = propertiesReader(envFile);\n\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ content, path }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles\n .filter(({ entityId }) => {\n return entriesToImport.includes(entityId);\n })\n .map(({ entityId, content }) => {\n const unsubstituted = unSubstituteEnvParams(content, envReader);\n return updateConfigEntity(entityId, JSON.parse(unsubstituted));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Count number of managed objects of a given type\n * @param {String} type managed object type, e.g. alpha_user\n */\nexport async function countManagedObjects(type: string) {\n try {\n const result = await queryManagedObjects(type);\n printMessage(`${type}: ${result.length}`, 'data');\n } catch (error) {\n printMessage(error.response.data, 'error');\n printMessage(`Error querying managed objects by type: ${error}`, 'error');\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,GAAG,MAAM,UAAU;AAC1B,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,gBAAgB,MAAM,mBAAmB;AAChD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,uBAAuB,EACvBC,YAAY,EACZC,qBAAqB,QAChB,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,4BAA4B;AAExE,MAAM;EAAEC,qBAAqB;EAAEC,mBAAmB;EAAEC;AAAY,CAAC,GAAGd,KAAK,CAACe,KAAK;AAC/E,MAAM;EACJC,oBAAoB;EACpBC,kBAAkB;EAClBC,gBAAgB;EAChBC,oBAAoB;EACpBC;AACF,CAAC,GAAGpB,KAAK,CAACqB,GAAG,CAACC,MAAM;AACpB,MAAM;EAAEC;AAAoB,CAAC,GAAGvB,KAAK,CAACqB,GAAG,CAACG,OAAO;;AAEjD;AACA;AACA;AACA,OAAO,eAAeC,gCAAgCA,CAAA,EAAG;EACvD,IAAI;IACF,MAAMC,GAAG,GAAG,MAAMV,oBAAoB,CAAC,CAAC;IACxC,MAAMW,OAAO,GAAGD,GAAG,CAChBE,MAAM,CAAEC,MAAM,IAAK,CAACA,MAAM,CAACC,EAAE,CAAC,CAC9BC,GAAG,CAAEF,MAAM,IAAKA,MAAM,CAACG,IAAI,CAAC;IAC/B,IAAIL,OAAO,CAACM,MAAM,EAAE;MAClBzB,YAAY,CACT,wGAAuGmB,OAAO,CAACO,IAAI,CAClH,IACF,CAAE,EAAC,EACH,MACF,CAAC;IACH;EACF,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd3B,YAAY,CAAC2B,KAAK,EAAE,OAAO,CAAC;IAC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{ createProgressIndicator, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
4
4
|
import { getRealmString, getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
|
|
5
5
|
const {
|
|
6
6
|
readSocialIdentityProviders,
|
|
@@ -74,14 +74,14 @@ export async function exportSocialIdentityProviderToFile(providerId, file = '')
|
|
|
74
74
|
fileName = getTypedFilename(providerId, 'idp');
|
|
75
75
|
}
|
|
76
76
|
const filePath = getFilePath(fileName, true);
|
|
77
|
-
|
|
77
|
+
const indicatorId = createProgressIndicator('determinate', 1, `Exporting ${providerId}`);
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
updateProgressIndicator(indicatorId, `Writing file ${filePath}`);
|
|
80
80
|
const fileData = await exportSocialIdentityProvider(providerId);
|
|
81
81
|
saveJsonToFile(fileData, filePath);
|
|
82
|
-
|
|
82
|
+
stopProgressIndicator(indicatorId, `Exported ${providerId['brightCyan']} to ${filePath['brightCyan']}.`);
|
|
83
83
|
} catch (err) {
|
|
84
|
-
|
|
84
|
+
stopProgressIndicator(indicatorId, `${err}`);
|
|
85
85
|
printMessage(`${err}`, 'error');
|
|
86
86
|
}
|
|
87
87
|
debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: end`);
|
|
@@ -105,22 +105,23 @@ export async function exportSocialIdentityProvidersToFile(file = '') {
|
|
|
105
105
|
*/
|
|
106
106
|
export async function exportSocialIdentityProvidersToFiles() {
|
|
107
107
|
debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: start`);
|
|
108
|
+
let indicatorId;
|
|
108
109
|
try {
|
|
109
110
|
const allIdpsData = await readSocialIdentityProviders();
|
|
110
|
-
|
|
111
|
+
indicatorId = createProgressIndicator('determinate', allIdpsData.length, 'Exporting providers');
|
|
111
112
|
for (const idpData of allIdpsData) {
|
|
112
113
|
try {
|
|
113
114
|
const fileName = getTypedFilename(idpData._id, 'idp');
|
|
114
115
|
const fileData = await exportSocialIdentityProvider(idpData._id);
|
|
115
116
|
saveJsonToFile(fileData, getFilePath(fileName, true));
|
|
116
|
-
|
|
117
|
+
updateProgressIndicator(indicatorId, `Exported provider ${idpData._id}`);
|
|
117
118
|
} catch (error) {
|
|
118
119
|
printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
+
stopProgressIndicator(indicatorId, `${allIdpsData.length} providers exported.`);
|
|
122
123
|
} catch (error) {
|
|
123
|
-
|
|
124
|
+
stopProgressIndicator(indicatorId, `${error}`);
|
|
124
125
|
printMessage(`${error}`, 'error');
|
|
125
126
|
}
|
|
126
127
|
debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: end`);
|
|
@@ -135,20 +136,18 @@ export async function exportSocialIdentityProvidersToFiles() {
|
|
|
135
136
|
export async function importSocialIdentityProviderFromFile(providerId, file) {
|
|
136
137
|
let outcome = false;
|
|
137
138
|
const filePath = getFilePath(file);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
});
|
|
139
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Importing provider ${providerId} from ${filePath}...`);
|
|
140
|
+
try {
|
|
141
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
142
|
+
const fileData = JSON.parse(data);
|
|
143
|
+
await importSocialIdentityProvider(providerId, fileData);
|
|
144
|
+
outcome = true;
|
|
145
|
+
stopProgressIndicator(indicatorId, `Successfully imported provider ${providerId} from ${filePath}.`, 'success');
|
|
146
|
+
} catch (error) {
|
|
147
|
+
var _error$response;
|
|
148
|
+
stopProgressIndicator(indicatorId, `Error importing provider ${providerId} from ${filePath}.`, 'fail');
|
|
149
|
+
printMessage(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || error, 'error');
|
|
150
|
+
}
|
|
152
151
|
return outcome;
|
|
153
152
|
}
|
|
154
153
|
|
|
@@ -160,20 +159,18 @@ export async function importSocialIdentityProviderFromFile(providerId, file) {
|
|
|
160
159
|
export async function importFirstSocialIdentityProviderFromFile(file) {
|
|
161
160
|
let outcome = false;
|
|
162
161
|
const filePath = getFilePath(file);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
});
|
|
162
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Importing first provider from ${filePath}...`);
|
|
163
|
+
try {
|
|
164
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
165
|
+
const fileData = JSON.parse(data);
|
|
166
|
+
await importFirstSocialIdentityProvider(fileData);
|
|
167
|
+
outcome = true;
|
|
168
|
+
stopProgressIndicator(indicatorId, `Successfully imported first provider from ${filePath}.`, 'success');
|
|
169
|
+
} catch (error) {
|
|
170
|
+
var _error$response2;
|
|
171
|
+
stopProgressIndicator(indicatorId, `Error importing first provider from ${filePath}.`, 'fail');
|
|
172
|
+
printMessage(((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) || error, 'error');
|
|
173
|
+
}
|
|
177
174
|
return outcome;
|
|
178
175
|
}
|
|
179
176
|
|
|
@@ -185,20 +182,18 @@ export async function importFirstSocialIdentityProviderFromFile(file) {
|
|
|
185
182
|
export async function importSocialIdentityProvidersFromFile(file) {
|
|
186
183
|
let outcome = false;
|
|
187
184
|
const filePath = getFilePath(file);
|
|
188
|
-
|
|
189
|
-
fs.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
});
|
|
185
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Importing providers from ${filePath}...`);
|
|
186
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
187
|
+
try {
|
|
188
|
+
const fileData = JSON.parse(data);
|
|
189
|
+
await importSocialIdentityProviders(fileData);
|
|
190
|
+
outcome = true;
|
|
191
|
+
stopProgressIndicator(indicatorId, `Successfully imported providers from ${filePath}.`, 'success');
|
|
192
|
+
} catch (error) {
|
|
193
|
+
var _error$response3;
|
|
194
|
+
stopProgressIndicator(indicatorId, `Error importing providers from ${filePath}.`, 'fail');
|
|
195
|
+
printMessage(((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data) || error, 'error');
|
|
196
|
+
}
|
|
202
197
|
return outcome;
|
|
203
198
|
}
|
|
204
199
|
|
|
@@ -208,7 +203,7 @@ export async function importSocialIdentityProvidersFromFile(file) {
|
|
|
208
203
|
export async function importSocialIdentityProvidersFromFiles() {
|
|
209
204
|
const names = fs.readdirSync(getWorkingDirectory());
|
|
210
205
|
const jsonFiles = names.filter(name => name.toLowerCase().endsWith('.idp.json')).map(name => getFilePath(name));
|
|
211
|
-
|
|
206
|
+
const indicatorId = createProgressIndicator('determinate', jsonFiles.length, 'Importing providers...');
|
|
212
207
|
let total = 0;
|
|
213
208
|
for (const file of jsonFiles) {
|
|
214
209
|
const data = fs.readFileSync(file, 'utf8');
|
|
@@ -216,8 +211,8 @@ export async function importSocialIdentityProvidersFromFiles() {
|
|
|
216
211
|
const count = Object.keys(fileData.idp).length;
|
|
217
212
|
total += count;
|
|
218
213
|
await importSocialIdentityProviders(fileData);
|
|
219
|
-
|
|
214
|
+
updateProgressIndicator(indicatorId, `Imported ${count} provider(s) from ${file}`);
|
|
220
215
|
}
|
|
221
|
-
|
|
216
|
+
stopProgressIndicator(indicatorId, `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`);
|
|
222
217
|
}
|
|
223
218
|
//# sourceMappingURL=IdpOps.js.map
|
package/esm/ops/IdpOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdpOps.js","names":["frodo","fs","createProgressBar","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getRealmString","getTypedFilename","saveJsonToFile","readSocialIdentityProviders","exportSocialIdentityProvider","exportSocialIdentityProviders","importFirstSocialIdentityProvider","importSocialIdentityProvider","importSocialIdentityProviders","oauth2oidc","external","getFilePath","getWorkingDirectory","utils","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialIdentityProviderToFile","providerId","file","fileName","filePath","fileData","exportSocialIdentityProvidersToFile","exportSocialIdentityProvidersToFiles","allIdpsData","length","idpData","error","importSocialIdentityProviderFromFile","outcome","readFile","data","JSON","parse","_error$response","response","importFirstSocialIdentityProviderFromFile","_error$response2","importSocialIdentityProvidersFromFile","_error$response3","importSocialIdentityProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","map","total","readFileSync","count","Object","keys","idp"],"sources":["../../src/ops/IdpOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/SocialIdentityProvidersApi';\nimport fs from 'fs';\n\nimport {\n createProgressBar,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\nconst {\n readSocialIdentityProviders,\n exportSocialIdentityProvider,\n exportSocialIdentityProviders,\n importFirstSocialIdentityProvider,\n importSocialIdentityProvider,\n importSocialIdentityProviders,\n} = frodo.oauth2oidc.external;\n\nconst { getFilePath, getWorkingDirectory } = frodo.utils;\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\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 | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await readSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProviderToFile(\n providerId: string,\n file = ''\n) {\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: start`);\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n const filePath = getFilePath(fileName, true);\n createProgressBar(1, `Exporting ${providerId}`);\n try {\n updateProgressBar(`Writing file ${filePath}`);\n const fileData = await exportSocialIdentityProvider(providerId);\n saveJsonToFile(fileData, filePath);\n stopProgressBar(\n `Exported ${providerId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressBar(`${err}`);\n printMessage(`${err}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: end`);\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await exportSocialIdentityProviders();\n saveJsonToFile(fileData, getFilePath(fileName, true));\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialIdentityProvidersToFiles() {\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: start`);\n try {\n const allIdpsData = await readSocialIdentityProviders();\n createProgressBar(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n try {\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await exportSocialIdentityProvider(idpData._id);\n saveJsonToFile(fileData, getFilePath(fileName, true));\n updateProgressBar(`Exported provider ${idpData._id}`);\n } catch (error) {\n printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');\n }\n }\n stopProgressBar(`${allIdpsData.length} providers exported.`);\n } catch (error) {\n stopProgressBar(`${error}`);\n printMessage(`${error}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: end`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialIdentityProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing provider ${providerId} 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 importSocialIdentityProvider(providerId, fileData);\n outcome = true;\n succeedSpinner(\n `Successfully imported provider ${providerId} from ${filePath}.`\n );\n } catch (error) {\n failSpinner(`Error importing provider ${providerId} from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialIdentityProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing first provider 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 importFirstSocialIdentityProvider(fileData);\n outcome = true;\n succeedSpinner(`Successfully imported first provider from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing first provider from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialIdentityProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing providers 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 importSocialIdentityProviders(fileData);\n outcome = true;\n succeedSpinner(`Successfully imported providers from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing providers from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialIdentityProvidersFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.idp.json'))\n .map((name) => getFilePath(name));\n\n createProgressBar(jsonFiles.length, 'Importing providers...');\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await importSocialIdentityProviders(fileData);\n updateProgressBar(`Imported ${count} provider(s) from ${file}`);\n }\n stopProgressBar(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\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S,CAAClB,MAAO,WACnE,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"IdpOps.js","names":["frodo","fs","createProgressIndicator","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getRealmString","getTypedFilename","saveJsonToFile","readSocialIdentityProviders","exportSocialIdentityProvider","exportSocialIdentityProviders","importFirstSocialIdentityProvider","importSocialIdentityProvider","importSocialIdentityProviders","oauth2oidc","external","getFilePath","getWorkingDirectory","utils","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialIdentityProviderToFile","providerId","file","fileName","filePath","indicatorId","fileData","exportSocialIdentityProvidersToFile","exportSocialIdentityProvidersToFiles","allIdpsData","length","idpData","error","importSocialIdentityProviderFromFile","outcome","data","readFileSync","JSON","parse","_error$response","response","importFirstSocialIdentityProviderFromFile","_error$response2","importSocialIdentityProvidersFromFile","_error$response3","importSocialIdentityProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","map","total","count","Object","keys","idp"],"sources":["../../src/ops/IdpOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/SocialIdentityProvidersApi';\nimport fs from 'fs';\n\nimport {\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\nconst {\n readSocialIdentityProviders,\n exportSocialIdentityProvider,\n exportSocialIdentityProviders,\n importFirstSocialIdentityProvider,\n importSocialIdentityProvider,\n importSocialIdentityProviders,\n} = frodo.oauth2oidc.external;\n\nconst { getFilePath, getWorkingDirectory } = frodo.utils;\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\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 | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await readSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProviderToFile(\n providerId: string,\n file = ''\n) {\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: start`);\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${providerId}`\n );\n try {\n updateProgressIndicator(indicatorId, `Writing file ${filePath}`);\n const fileData = await exportSocialIdentityProvider(providerId);\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n indicatorId,\n `Exported ${providerId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(`${err}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: end`);\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await exportSocialIdentityProviders();\n saveJsonToFile(fileData, getFilePath(fileName, true));\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialIdentityProvidersToFiles() {\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: start`);\n let indicatorId: string;\n try {\n const allIdpsData = await readSocialIdentityProviders();\n indicatorId = createProgressIndicator(\n 'determinate',\n allIdpsData.length,\n 'Exporting providers'\n );\n for (const idpData of allIdpsData) {\n try {\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await exportSocialIdentityProvider(idpData._id);\n saveJsonToFile(fileData, getFilePath(fileName, true));\n updateProgressIndicator(\n indicatorId,\n `Exported provider ${idpData._id}`\n );\n } catch (error) {\n printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `${allIdpsData.length} providers exported.`\n );\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error}`);\n printMessage(`${error}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: end`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialIdentityProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing provider ${providerId} from ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importSocialIdentityProvider(providerId, fileData);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Successfully imported provider ${providerId} from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing provider ${providerId} from ${filePath}.`,\n 'fail'\n );\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialIdentityProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing first provider from ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importFirstSocialIdentityProvider(fileData);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Successfully imported first provider from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing first provider from ${filePath}.`,\n 'fail'\n );\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialIdentityProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing providers from ${filePath}...`\n );\n const data = fs.readFileSync(filePath, 'utf8');\n try {\n const fileData = JSON.parse(data);\n await importSocialIdentityProviders(fileData);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Successfully imported providers from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing providers from ${filePath}.`,\n 'fail'\n );\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialIdentityProvidersFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.idp.json'))\n .map((name) => getFilePath(name));\n\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing providers...'\n );\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await importSocialIdentityProviders(fileData);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} provider(s) from ${file}`\n );\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,uBAAuB,EACvBC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,cAAc,EACdC,gBAAgB,EAChBC,cAAc,QACT,4BAA4B;AAEnC,MAAM;EACJC,2BAA2B;EAC3BC,4BAA4B;EAC5BC,6BAA6B;EAC7BC,iCAAiC;EACjCC,4BAA4B;EAC5BC;AACF,CAAC,GAAGf,KAAK,CAACgB,UAAU,CAACC,QAAQ;AAE7B,MAAM;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGnB,KAAK,CAACoB,KAAK;;AAExD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG,KAAK,CAACD,GAAI,EAAC;EACnF,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,gBAAgBA,CAAA,EAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,+BAA+B;EAC3CA,QAAQ,IAAI,6BAA6B;EACzC,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;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