@rockcarver/frodo-lib 0.12.6 → 0.13.0
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 +22 -1
- package/cjs/api/ApiTypes.js.map +1 -1
- package/cjs/index.js +9 -1
- package/cjs/index.js.map +1 -1
- package/cjs/ops/CirclesOfTrustOps.js +1 -12
- package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
- package/cjs/ops/EmailTemplateOps.js +0 -12
- package/cjs/ops/EmailTemplateOps.js.map +1 -1
- package/cjs/ops/IdpOps.js +1 -12
- package/cjs/ops/IdpOps.js.map +1 -1
- package/cjs/ops/JourneyOps.js +127 -193
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/JourneyOps.test.js.map +1 -1
- package/cjs/ops/NodeOps.js +32 -29
- package/cjs/ops/NodeOps.js.map +1 -1
- package/cjs/ops/OpsTypes.js +28 -0
- package/cjs/ops/OpsTypes.js.map +1 -1
- package/cjs/ops/Saml2Ops.js +1 -21
- package/cjs/ops/Saml2Ops.js.map +1 -1
- package/cjs/ops/ScriptOps.js +0 -12
- package/cjs/ops/ScriptOps.js.map +1 -1
- package/cjs/ops/ThemeOps.js +0 -12
- package/cjs/ops/ThemeOps.js.map +1 -1
- package/cjs/test/mocks/TreeApi/getTree/Disabled.json +26 -0
- package/esm/index.mjs +3 -0
- package/esm/ops/CirclesOfTrustOps.mjs +1 -11
- package/esm/ops/EmailTemplateOps.mjs +1 -11
- package/esm/ops/IdpOps.mjs +1 -11
- package/esm/ops/JourneyOps.mjs +83 -148
- package/esm/ops/JourneyOps.test.mjs +54 -0
- package/esm/ops/NodeOps.mjs +29 -27
- package/esm/ops/OpsTypes.mjs +24 -1
- package/esm/ops/Saml2Ops.mjs +1 -19
- package/esm/ops/ScriptOps.mjs +0 -10
- package/esm/ops/ThemeOps.mjs +0 -10
- package/esm/test/mocks/TreeApi/getTree/Disabled.json +26 -0
- package/package.json +3 -2
- package/types/api/ApiTypes.d.ts +1 -1
- package/types/api/ApiTypes.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/ops/CirclesOfTrustOps.d.ts +0 -7
- package/types/ops/CirclesOfTrustOps.d.ts.map +1 -1
- package/types/ops/EmailTemplateOps.d.ts +0 -7
- package/types/ops/EmailTemplateOps.d.ts.map +1 -1
- package/types/ops/IdpOps.d.ts +0 -7
- package/types/ops/IdpOps.d.ts.map +1 -1
- package/types/ops/JourneyOps.d.ts +17 -26
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/NodeOps.d.ts +10 -8
- package/types/ops/NodeOps.d.ts.map +1 -1
- package/types/ops/OpsTypes.d.ts +12 -0
- package/types/ops/OpsTypes.d.ts.map +1 -1
- package/types/ops/Saml2Ops.d.ts +0 -7
- package/types/ops/Saml2Ops.d.ts.map +1 -1
- package/types/ops/ScriptOps.d.ts +0 -7
- package/types/ops/ScriptOps.d.ts.map +1 -1
- package/types/ops/ThemeOps.d.ts +0 -7
- package/types/ops/ThemeOps.d.ts.map +1 -1
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAaA,wBAAgB,UAAU,WAEzB;AAGD,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,YAAY,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,cAAc,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,iBAAiB,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,YAAY,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,YAAY,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAG9C,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAIlD,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC","file":"index.d.ts","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport Color from 'colors';\n\nColor.enable();\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst pkg = JSON.parse(\n fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')\n);\n\nexport function getVersion() {\n return `v${pkg.version}`;\n}\n\n// Api Layer\nexport * as TypesRaw from './api/ApiTypes';\nexport * as NodeRaw from './api/NodeApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as StartupRaw from './api/StartupApi';\nexport * as SecretsRaw from './api/SecretsApi';\nexport * as VariablesRaw from './api/VariablesApi';\n\n// Ops Layer\nexport * as Types from './ops/OpsTypes';\nexport * as Admin from './ops/AdminOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Log from './ops/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Node from './ops/NodeOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Secrets from './ops/SecretsOps';\nexport * as Startup from './ops/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Variables from './ops/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './storage/SessionStorage';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\n"]}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { CircleOfTrustSkeleton } from '../api/ApiTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Get a one-line description of the circle of trust object
|
|
4
|
-
* @param {CircleOfTrustSkeleton} cotObj circle of trust object to describe
|
|
5
|
-
* @returns {string} a one-line description
|
|
6
|
-
*/
|
|
7
|
-
export declare function getOneLineDescription(cotObj: CircleOfTrustSkeleton): string;
|
|
8
1
|
/**
|
|
9
2
|
* List entity providers
|
|
10
3
|
* @param {String} long Long list format with details
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/CirclesOfTrustOps.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAG3E;AAgBD;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,UAAQ,iBAgCpD;AAYD;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,KAAA,EAAE,IAAI,MAAO,iBAqB3D;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,MAAO,iBA4B3D;AAED;;GAEG;AACH,wBAAsB,2BAA2B,kBAoBhD;AAYD;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,KAAA,EAAE,IAAI,KAAA,iBA2BpD;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,IAAI,KAAA,iBA2BlD;AAED;;;GAGG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,KAAA,iBA6BtD;AAED;;GAEG;AACH,wBAAsB,6BAA6B,kBA6ClD","file":"CirclesOfTrustOps.d.ts","sourcesContent":["import fs from 'fs';\nimport _ from 'lodash';\nimport {\n createTable,\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\nimport {\n getCirclesOfTrust,\n getCircleOfTrust,\n createCircleOfTrust,\n} from '../api/CirclesOfTrustApi';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport { CircleOfTrustSkeleton } from '../api/ApiTypes';\n\n/**\n * Get a one-line description of the circle of trust object\n * @param {CircleOfTrustSkeleton} cotObj circle of trust object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(cotObj: CircleOfTrustSkeleton): string {\n const description = `[${cotObj._id['brightCyan']}]`;\n return description;\n}\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n };\n}\n\n/**\n * List entity providers\n * @param {String} long Long list format with details\n */\nexport async function listCirclesOfTrust(long = false) {\n let cotList = [];\n try {\n cotList = (await getCirclesOfTrust()).result;\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n cotList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n cotList.forEach((cot) => {\n printMessage(`${cot._id}`, 'data');\n });\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Description'['brightCyan'],\n 'Status'['brightCyan'],\n 'Trusted Providers'['brightCyan'],\n ]);\n cotList.forEach((cot) => {\n table.push([\n cot._id,\n cot.description,\n cot.status,\n cot.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('\\n'),\n ]);\n });\n printMessage(table.toString());\n }\n}\n\n/**\n * Include dependencies in the export file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(cotData, fileData) {\n // TODO: Export dependencies\n return [cotData, fileData];\n}\n\n/**\n * Export a single circle of trust to file\n * @param {String} cotId circle of trust id/name\n * @param {String} file Optional filename\n */\nexport async function exportCircleOfTrust(cotId, file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(cotId, 'cot.saml');\n }\n createProgressIndicator(1, `Exporting circle of trust ${cotId}`);\n try {\n const cotData = _.cloneDeep(getCircleOfTrust(cotId));\n delete cotData['_rev'];\n updateProgressIndicator(`Exporting ${cotId}`);\n const fileData = getFileDataTemplate();\n fileData.saml.cot[cotId] = cotData;\n await exportDependencies(cotData, fileData);\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${cotId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all circles of trust to one file\n * @param {String} file Optional filename\n */\nexport async function exportCirclesOfTrustToFile(file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(\n `all${getRealmString()}CirclesOfTrust`,\n 'cot.saml'\n );\n }\n const fileData = getFileDataTemplate();\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${allCotData.length} circle(s) of trust exported to ${fileName}.`\n );\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Export all circles of trust to individual files\n */\nexport async function exportCirclesOfTrustToFiles() {\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n const fileName = getTypedFilename(cotData._id, 'cot.saml');\n const fileData = getFileDataTemplate();\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${allCotData.length} providers exported.`);\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Include dependencies from the import file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to read dependencies from\n */\nasync function importDependencies(cotData, fileData) {\n // TODO: Import dependencies\n return [cotData, fileData];\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {String} file Import file name\n */\nexport async function importCircleOfTrust(cotId, file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n const cotData = _.get(fileData, ['saml', 'cot', cotId]);\n if (cotData) {\n updateProgressIndicator(`Importing ${cotId}`);\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createProviderErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createProviderErr.response.data, 'error');\n }\n } else {\n stopProgressIndicator(\n `Circle of trust ${cotId.brightCyan} not found in ${file.brightCyan}!`\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import first SAML circle of trust from file\n * @param {String} file Import file name\n */\nexport async function importFirstCircleOfTrust(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n updateProgressIndicator(`Importing ${cotId}`);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createCircleOfTrustErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from file\n * @param {String} file Import file name\n */\nexport async function importCirclesOfTrustFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.saml.cot).length,\n 'Importing circles of trust...'\n );\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Circles of trust imported.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from all *.cot.saml.json files in the current directory\n */\nexport async function importCirclesOfTrustFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.cot.saml.json')\n );\n createProgressIndicator(jsonFiles.length, 'Importing circles or trust...');\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 (validateImport(fileData.meta)) {\n total += _.keys(fileData.saml.cot).length;\n let errors = 0;\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n // updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n errors += 1;\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(\n `Imported ${\n _.keys(fileData.saml.cot).length - errors\n } circle(s) of trust from ${file}`\n );\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} circle(s) of trust from ${\n jsonFiles.length\n } file(s).`\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/CirclesOfTrustOps.ts"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,UAAQ,iBAgCpD;AAYD;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,KAAA,EAAE,IAAI,MAAO,iBAqB3D;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,MAAO,iBA4B3D;AAED;;GAEG;AACH,wBAAsB,2BAA2B,kBAoBhD;AAYD;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,KAAA,EAAE,IAAI,KAAA,iBA2BpD;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,IAAI,KAAA,iBA2BlD;AAED;;;GAGG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,KAAA,iBA6BtD;AAED;;GAEG;AACH,wBAAsB,6BAA6B,kBA6ClD","file":"CirclesOfTrustOps.d.ts","sourcesContent":["import fs from 'fs';\nimport _ from 'lodash';\nimport {\n createTable,\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\nimport {\n getCirclesOfTrust,\n getCircleOfTrust,\n createCircleOfTrust,\n} from '../api/CirclesOfTrustApi';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n };\n}\n\n/**\n * List entity providers\n * @param {String} long Long list format with details\n */\nexport async function listCirclesOfTrust(long = false) {\n let cotList = [];\n try {\n cotList = (await getCirclesOfTrust()).result;\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n cotList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n cotList.forEach((cot) => {\n printMessage(`${cot._id}`, 'data');\n });\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Description'['brightCyan'],\n 'Status'['brightCyan'],\n 'Trusted Providers'['brightCyan'],\n ]);\n cotList.forEach((cot) => {\n table.push([\n cot._id,\n cot.description,\n cot.status,\n cot.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('\\n'),\n ]);\n });\n printMessage(table.toString());\n }\n}\n\n/**\n * Include dependencies in the export file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(cotData, fileData) {\n // TODO: Export dependencies\n return [cotData, fileData];\n}\n\n/**\n * Export a single circle of trust to file\n * @param {String} cotId circle of trust id/name\n * @param {String} file Optional filename\n */\nexport async function exportCircleOfTrust(cotId, file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(cotId, 'cot.saml');\n }\n createProgressIndicator(1, `Exporting circle of trust ${cotId}`);\n try {\n const cotData = _.cloneDeep(getCircleOfTrust(cotId));\n delete cotData['_rev'];\n updateProgressIndicator(`Exporting ${cotId}`);\n const fileData = getFileDataTemplate();\n fileData.saml.cot[cotId] = cotData;\n await exportDependencies(cotData, fileData);\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${cotId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all circles of trust to one file\n * @param {String} file Optional filename\n */\nexport async function exportCirclesOfTrustToFile(file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(\n `all${getRealmString()}CirclesOfTrust`,\n 'cot.saml'\n );\n }\n const fileData = getFileDataTemplate();\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${allCotData.length} circle(s) of trust exported to ${fileName}.`\n );\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Export all circles of trust to individual files\n */\nexport async function exportCirclesOfTrustToFiles() {\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n const fileName = getTypedFilename(cotData._id, 'cot.saml');\n const fileData = getFileDataTemplate();\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${allCotData.length} providers exported.`);\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Include dependencies from the import file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to read dependencies from\n */\nasync function importDependencies(cotData, fileData) {\n // TODO: Import dependencies\n return [cotData, fileData];\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {String} file Import file name\n */\nexport async function importCircleOfTrust(cotId, file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n const cotData = _.get(fileData, ['saml', 'cot', cotId]);\n if (cotData) {\n updateProgressIndicator(`Importing ${cotId}`);\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createProviderErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createProviderErr.response.data, 'error');\n }\n } else {\n stopProgressIndicator(\n `Circle of trust ${cotId.brightCyan} not found in ${file.brightCyan}!`\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import first SAML circle of trust from file\n * @param {String} file Import file name\n */\nexport async function importFirstCircleOfTrust(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n updateProgressIndicator(`Importing ${cotId}`);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createCircleOfTrustErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from file\n * @param {String} file Import file name\n */\nexport async function importCirclesOfTrustFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.saml.cot).length,\n 'Importing circles of trust...'\n );\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Circles of trust imported.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from all *.cot.saml.json files in the current directory\n */\nexport async function importCirclesOfTrustFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.cot.saml.json')\n );\n createProgressIndicator(jsonFiles.length, 'Importing circles or trust...');\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 (validateImport(fileData.meta)) {\n total += _.keys(fileData.saml.cot).length;\n let errors = 0;\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n // updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n errors += 1;\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(\n `Imported ${\n _.keys(fileData.saml.cot).length - errors\n } circle(s) of trust from ${file}`\n );\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} circle(s) of trust from ${\n jsonFiles.length\n } file(s).`\n );\n}\n"]}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { EmailTemplateSkeleton } from '../api/ApiTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Get a one-line description of the email template
|
|
4
|
-
* @param {EmailTemplateSkeleton} templateObj email template object to describe
|
|
5
|
-
* @returns {string} a one-line description
|
|
6
|
-
*/
|
|
7
|
-
export declare function getOneLineDescription(templateObj: EmailTemplateSkeleton): string;
|
|
8
1
|
/**
|
|
9
2
|
* List email templates
|
|
10
3
|
* @param {boolean} long Long list format with details
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/EmailTemplateOps.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAuCxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,qBAAqB,GACjC,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,UAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAmDzE;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,iBAmB/D;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,KAAA,iBAuBpD;AAED;;GAEG;AACH,wBAAsB,2BAA2B,kBAkBhD;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,iBAiCjE;AAED;;;GAGG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,KAAA,iBA8BtD;AAED;;GAEG;AACH,wBAAsB,6BAA6B,kBAyClD;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CAAC,IAAI,KAAA,iBA2B1D","file":"EmailTemplateOps.d.ts","sourcesContent":["import fs from 'fs';\nimport { EmailTemplateSkeleton } from '../api/ApiTypes';\nimport {\n EMAIL_TEMPLATE_TYPE,\n getEmailTemplate,\n getEmailTemplates,\n putEmailTemplate,\n} from '../api/EmailTemplateApi';\nimport {\n createProgressIndicator,\n createTable,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport wordwrap from './utils/Wordwrap';\n\n/**\n * Regex to remove email template type from id\n */\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n/**\n * Maintain the file type centrally\n */\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\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['brightYellow']\n } - ${templateObj.subject[templateObj.defaultLocale]['brightYellow']}`;\n return description;\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 getEmailTemplates()).result;\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 a single email template to file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplateToFile(templateId, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n createProgressIndicator(1, `Exporting ${templateId}`);\n try {\n const templateData = await getEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${templateId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n try {\n const fileData = getFileDataTemplate();\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${response.resultCount} templates exported to ${fileName}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${response.resultCount} 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 */\nexport async function importEmailTemplateFromFile(templateId, file) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing ${templateId}`);\n if (fileData.emailTemplate[templateId]) {\n try {\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`${putEmailTemplateError}`);\n printMessage(putEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`\n );\n printMessage(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`,\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) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 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 // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from separate files\n */\nexport async function importEmailTemplatesFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n );\n createProgressIndicator(jsonFiles.length, 'Importing email templates...');\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 (validateImport(fileData.meta)) {\n total += Object.keys(fileData.emailTemplate).length;\n let errors = 0;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (putEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\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(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing first email template`);\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await putEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n updateProgressIndicator(`Imported ${id}`);\n stopProgressIndicator(`Imported ${id}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`Error importing email template ${id}`);\n printMessage(`\\nError importing email template ${id}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/EmailTemplateOps.ts"],"names":[],"mappings":"AAuCA;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,UAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAmDzE;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,iBAmB/D;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,KAAA,iBAuBpD;AAED;;GAEG;AACH,wBAAsB,2BAA2B,kBAkBhD;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,iBAiCjE;AAED;;;GAGG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,KAAA,iBA8BtD;AAED;;GAEG;AACH,wBAAsB,6BAA6B,kBAyClD;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CAAC,IAAI,KAAA,iBA2B1D","file":"EmailTemplateOps.d.ts","sourcesContent":["import fs from 'fs';\nimport {\n EMAIL_TEMPLATE_TYPE,\n getEmailTemplate,\n getEmailTemplates,\n putEmailTemplate,\n} from '../api/EmailTemplateApi';\nimport {\n createProgressIndicator,\n createTable,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport wordwrap from './utils/Wordwrap';\n\n/**\n * Regex to remove email template type from id\n */\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n/**\n * Maintain the file type centrally\n */\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\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 * 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 getEmailTemplates()).result;\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 a single email template to file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplateToFile(templateId, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n createProgressIndicator(1, `Exporting ${templateId}`);\n try {\n const templateData = await getEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${templateId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n try {\n const fileData = getFileDataTemplate();\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${response.resultCount} templates exported to ${fileName}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${response.resultCount} 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 */\nexport async function importEmailTemplateFromFile(templateId, file) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing ${templateId}`);\n if (fileData.emailTemplate[templateId]) {\n try {\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`${putEmailTemplateError}`);\n printMessage(putEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`\n );\n printMessage(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`,\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) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 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 // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from separate files\n */\nexport async function importEmailTemplatesFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n );\n createProgressIndicator(jsonFiles.length, 'Importing email templates...');\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 (validateImport(fileData.meta)) {\n total += Object.keys(fileData.emailTemplate).length;\n let errors = 0;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (putEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\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(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing first email template`);\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await putEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n updateProgressIndicator(`Imported ${id}`);\n stopProgressIndicator(`Imported ${id}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`Error importing email template ${id}`);\n printMessage(`\\nError importing email template ${id}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"]}
|
package/types/ops/IdpOps.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { SocialIdpSkeleton } from '../api/ApiTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Get a one-line description of the social idp object
|
|
4
|
-
* @param {SocialIdpSkeleton} socialIdpObj social idp object to describe
|
|
5
|
-
* @returns {string} a one-line description
|
|
6
|
-
*/
|
|
7
|
-
export declare function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string;
|
|
8
1
|
/**
|
|
9
2
|
* List providers
|
|
10
3
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/IdpOps.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,iBAAiB,GAAG,MAAM,CAG7E;AAWD;;GAEG;AACH,wBAAsB,mBAAmB,kBAWxC;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,KAAA,gBAgBjD;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,UAAU,KAAA,EAAE,IAAI,SAAK,iBAwBrE;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,KAAA,iBAsBrD;AAED;;GAEG;AACH,wBAAsB,4BAA4B,kBAkBjD;AAED;;;;GAIG;AACH,wBAAsB,4BAA4B,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,iBAuDlE;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,CAAC,IAAI,KAAA,iBA6C3D;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CAAC,IAAI,KAAA,iBAuCvD;AAED;;GAEG;AACH,wBAAsB,8BAA8B,kBAsCnD","file":"IdpOps.d.ts","sourcesContent":["import fs from 'fs';\nimport {\n getSocialIdentityProviders,\n putProviderByTypeAndId,\n} from '../api/SocialIdentityProvidersApi';\nimport { getScript } from '../api/ScriptApi';\nimport { createOrUpdateScript } from './ScriptOps';\nimport {\n convertBase64TextToArray,\n convertTextArrayToBase64,\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport {\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\nimport { SocialIdpSkeleton } from '../api/ApiTypes';\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// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n script: {},\n idp: {},\n };\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await getSocialIdentityProviders();\n providers.result.sort((a, b) => a._id.localeCompare(b._id));\n providers.result.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 * Get social identity provider by id\n * @param {String} providerId social identity provider id/name\n * @returns {Promise} a promise that resolves a social identity provider object\n */\nexport async function getSocialProvider(providerId) {\n return getSocialIdentityProviders().then((response) => {\n const foundProviders = response.result.filter(\n (provider) => provider._id === providerId\n );\n switch (foundProviders.length) {\n case 1:\n return foundProviders[0];\n case 0:\n throw new Error(`Provider '${providerId}' not found`);\n default:\n throw new Error(\n `${foundProviders.length} providers '${providerId}' found`\n );\n }\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 exportSocialProviderToFile(providerId, file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n createProgressIndicator(1, `Exporting ${providerId}`);\n try {\n const idpData = await getSocialProvider(providerId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.idp[idpData._id] = idpData;\n if (idpData.transform) {\n const scriptData = await getScript(idpData.transform);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpData.transform] = scriptData;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(`${err}`, 'error');\n }\n}\n\n/**\n * Export all providers\n * @param {String} file optional export file name\n */\nexport async function exportSocialProvidersToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = getFileDataTemplate();\n const allIdpsData = (await getSocialIdentityProviders()).result;\n createProgressIndicator(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressIndicator(`Exporting provider ${idpData._id}`);\n fileData.idp[idpData._id] = idpData;\n if (idpData.transform) {\n // eslint-disable-next-line no-await-in-loop\n const scriptData = await getScript(idpData.transform);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpData.transform] = scriptData;\n }\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${allIdpsData.length} providers exported to ${fileName}.`\n );\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialProvidersToFiles() {\n const allIdpsData = await (await getSocialIdentityProviders()).result;\n // printMessage(allIdpsData, 'data');\n createProgressIndicator(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressIndicator(`Writing provider ${idpData._id}`);\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = getFileDataTemplate();\n fileData.idp[idpData._id] = idpData;\n if (idpData.transform) {\n // eslint-disable-next-line no-await-in-loop\n const scriptData = await getScript(idpData.transform);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpData.transform] = scriptData;\n }\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${allIdpsData.length} providers exported.`);\n}\n\n/**\n * Import provider by id/name\n * @param {String} providerId provider id/name\n * @param {String} file import file name\n */\nexport async function importSocialProviderFromFile(providerId, file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing provider...');\n let found = false;\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n if (idpId === providerId) {\n found = true;\n updateProgressIndicator(`Importing ${fileData.idp[idpId]._id}`);\n const scriptId = fileData.idp[idpId].transform;\n const scriptData = fileData.script[scriptId];\n if (scriptId && scriptData) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n // eslint-disable-next-line no-await-in-loop\n await createOrUpdateScript(\n fileData.idp[idpId].transform,\n fileData.script[fileData.idp[idpId].transform]\n );\n }\n putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n )\n .then(() => {\n stopProgressIndicator(\n `Successfully imported provider ${providerId}.`\n );\n })\n .catch((importProviderErr) => {\n stopProgressIndicator(\n `Error importing provider ${fileData.idp[idpId]._id}`\n );\n printMessage(\n `\\nError importing provider ${providerId}`,\n 'error'\n );\n printMessage(importProviderErr.response.data, 'error');\n });\n break;\n }\n }\n }\n if (!found) {\n stopProgressIndicator(\n `Provider ${providerId.brightCyan} not found in ${file.brightCyan}!`\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n */\nexport async function importFirstSocialProviderFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing provider...');\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n updateProgressIndicator(`Importing ${fileData.idp[idpId]._id}`);\n const scriptId = fileData.idp[idpId].transform;\n const scriptData = fileData.script[scriptId];\n if (scriptId && scriptData) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n // eslint-disable-next-line no-await-in-loop\n await createOrUpdateScript(\n fileData.idp[idpId].transform,\n fileData.script[fileData.idp[idpId].transform]\n );\n }\n putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n ).then((result) => {\n if (result == null) {\n stopProgressIndicator(\n `Error importing provider ${fileData.idp[idpId]._id}`\n );\n printMessage(\n `Error importing provider ${fileData.idp[idpId]._id}`,\n 'error'\n );\n } else {\n stopProgressIndicator(\n `Successfully imported provider ${fileData.idp[idpId]._id}.`\n );\n }\n });\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all providers from file\n * @param {String} file import file name\n */\nexport async function importSocialProvidersFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.idp).length,\n 'Importing providers...'\n );\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n const scriptId = fileData.idp[idpId].transform;\n const scriptData = fileData.script[scriptId];\n if (scriptId && scriptData) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n // eslint-disable-next-line no-await-in-loop\n await createOrUpdateScript(\n fileData.idp[idpId].transform,\n fileData.script[fileData.idp[idpId].transform]\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const result = await putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n );\n if (!result) {\n updateProgressIndicator(\n `Successfully imported ${fileData.idp[idpId].name}`\n );\n }\n }\n }\n stopProgressIndicator(`Providers imported.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialProvidersFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.idp.json')\n );\n\n createProgressIndicator(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 if (validateImport(fileData.meta)) {\n const count = Object.keys(fileData.idp).length;\n total += count;\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n // eslint-disable-next-line no-await-in-loop\n const result = await putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n );\n if (result == null) {\n printMessage(\n `Error importing ${count} providers from ${file}`,\n 'error'\n );\n }\n }\n }\n updateProgressIndicator(`Imported ${count} provider(s) from ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/IdpOps.ts"],"names":[],"mappings":"AA+BA;;GAEG;AACH,wBAAsB,mBAAmB,kBAWxC;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,KAAA,gBAgBjD;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,UAAU,KAAA,EAAE,IAAI,SAAK,iBAwBrE;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,KAAA,iBAsBrD;AAED;;GAEG;AACH,wBAAsB,4BAA4B,kBAkBjD;AAED;;;;GAIG;AACH,wBAAsB,4BAA4B,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,iBAuDlE;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,CAAC,IAAI,KAAA,iBA6C3D;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CAAC,IAAI,KAAA,iBAuCvD;AAED;;GAEG;AACH,wBAAsB,8BAA8B,kBAsCnD","file":"IdpOps.d.ts","sourcesContent":["import fs from 'fs';\nimport {\n getSocialIdentityProviders,\n putProviderByTypeAndId,\n} from '../api/SocialIdentityProvidersApi';\nimport { getScript } from '../api/ScriptApi';\nimport { createOrUpdateScript } from './ScriptOps';\nimport {\n convertBase64TextToArray,\n convertTextArrayToBase64,\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport {\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n script: {},\n idp: {},\n };\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await getSocialIdentityProviders();\n providers.result.sort((a, b) => a._id.localeCompare(b._id));\n providers.result.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 * Get social identity provider by id\n * @param {String} providerId social identity provider id/name\n * @returns {Promise} a promise that resolves a social identity provider object\n */\nexport async function getSocialProvider(providerId) {\n return getSocialIdentityProviders().then((response) => {\n const foundProviders = response.result.filter(\n (provider) => provider._id === providerId\n );\n switch (foundProviders.length) {\n case 1:\n return foundProviders[0];\n case 0:\n throw new Error(`Provider '${providerId}' not found`);\n default:\n throw new Error(\n `${foundProviders.length} providers '${providerId}' found`\n );\n }\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 exportSocialProviderToFile(providerId, file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n createProgressIndicator(1, `Exporting ${providerId}`);\n try {\n const idpData = await getSocialProvider(providerId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.idp[idpData._id] = idpData;\n if (idpData.transform) {\n const scriptData = await getScript(idpData.transform);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpData.transform] = scriptData;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(`${err}`, 'error');\n }\n}\n\n/**\n * Export all providers\n * @param {String} file optional export file name\n */\nexport async function exportSocialProvidersToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = getFileDataTemplate();\n const allIdpsData = (await getSocialIdentityProviders()).result;\n createProgressIndicator(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressIndicator(`Exporting provider ${idpData._id}`);\n fileData.idp[idpData._id] = idpData;\n if (idpData.transform) {\n // eslint-disable-next-line no-await-in-loop\n const scriptData = await getScript(idpData.transform);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpData.transform] = scriptData;\n }\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${allIdpsData.length} providers exported to ${fileName}.`\n );\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialProvidersToFiles() {\n const allIdpsData = await (await getSocialIdentityProviders()).result;\n // printMessage(allIdpsData, 'data');\n createProgressIndicator(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressIndicator(`Writing provider ${idpData._id}`);\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = getFileDataTemplate();\n fileData.idp[idpData._id] = idpData;\n if (idpData.transform) {\n // eslint-disable-next-line no-await-in-loop\n const scriptData = await getScript(idpData.transform);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpData.transform] = scriptData;\n }\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${allIdpsData.length} providers exported.`);\n}\n\n/**\n * Import provider by id/name\n * @param {String} providerId provider id/name\n * @param {String} file import file name\n */\nexport async function importSocialProviderFromFile(providerId, file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing provider...');\n let found = false;\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n if (idpId === providerId) {\n found = true;\n updateProgressIndicator(`Importing ${fileData.idp[idpId]._id}`);\n const scriptId = fileData.idp[idpId].transform;\n const scriptData = fileData.script[scriptId];\n if (scriptId && scriptData) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n // eslint-disable-next-line no-await-in-loop\n await createOrUpdateScript(\n fileData.idp[idpId].transform,\n fileData.script[fileData.idp[idpId].transform]\n );\n }\n putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n )\n .then(() => {\n stopProgressIndicator(\n `Successfully imported provider ${providerId}.`\n );\n })\n .catch((importProviderErr) => {\n stopProgressIndicator(\n `Error importing provider ${fileData.idp[idpId]._id}`\n );\n printMessage(\n `\\nError importing provider ${providerId}`,\n 'error'\n );\n printMessage(importProviderErr.response.data, 'error');\n });\n break;\n }\n }\n }\n if (!found) {\n stopProgressIndicator(\n `Provider ${providerId.brightCyan} not found in ${file.brightCyan}!`\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n */\nexport async function importFirstSocialProviderFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing provider...');\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n updateProgressIndicator(`Importing ${fileData.idp[idpId]._id}`);\n const scriptId = fileData.idp[idpId].transform;\n const scriptData = fileData.script[scriptId];\n if (scriptId && scriptData) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n // eslint-disable-next-line no-await-in-loop\n await createOrUpdateScript(\n fileData.idp[idpId].transform,\n fileData.script[fileData.idp[idpId].transform]\n );\n }\n putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n ).then((result) => {\n if (result == null) {\n stopProgressIndicator(\n `Error importing provider ${fileData.idp[idpId]._id}`\n );\n printMessage(\n `Error importing provider ${fileData.idp[idpId]._id}`,\n 'error'\n );\n } else {\n stopProgressIndicator(\n `Successfully imported provider ${fileData.idp[idpId]._id}.`\n );\n }\n });\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all providers from file\n * @param {String} file import file name\n */\nexport async function importSocialProvidersFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.idp).length,\n 'Importing providers...'\n );\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n const scriptId = fileData.idp[idpId].transform;\n const scriptData = fileData.script[scriptId];\n if (scriptId && scriptData) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n // eslint-disable-next-line no-await-in-loop\n await createOrUpdateScript(\n fileData.idp[idpId].transform,\n fileData.script[fileData.idp[idpId].transform]\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const result = await putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n );\n if (!result) {\n updateProgressIndicator(\n `Successfully imported ${fileData.idp[idpId].name}`\n );\n }\n }\n }\n stopProgressIndicator(`Providers imported.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialProvidersFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.idp.json')\n );\n\n createProgressIndicator(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 if (validateImport(fileData.meta)) {\n const count = Object.keys(fileData.idp).length;\n total += count;\n for (const idpId in fileData.idp) {\n if ({}.hasOwnProperty.call(fileData.idp, idpId)) {\n // eslint-disable-next-line no-await-in-loop\n const result = await putProviderByTypeAndId(\n fileData.idp[idpId]._type._id,\n idpId,\n fileData.idp[idpId]\n );\n if (result == null) {\n printMessage(\n `Error importing ${count} providers from ${file}`,\n 'error'\n );\n }\n }\n }\n updateProgressIndicator(`Imported ${count} provider(s) from ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"]}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { TreeExportResolverInterface } from './OpsTypes';
|
|
2
|
-
import { InnerNodeRefSkeletonInterface, NodeRefSkeletonInterface, NodeSkeleton
|
|
1
|
+
import { JourneyClassification, TreeExportResolverInterface } from './OpsTypes';
|
|
2
|
+
import { InnerNodeRefSkeletonInterface, NodeRefSkeletonInterface, NodeSkeleton } from '../api/ApiTypes';
|
|
3
3
|
import { SingleTreeExportInterface, MultiTreeExportInterface, TreeDependencyMapInterface, TreeExportOptions, TreeImportOptions } from './OpsTypes';
|
|
4
|
-
/**
|
|
5
|
-
* Get a one-line description of the tree object
|
|
6
|
-
* @param {TreeSkeleton} treeObj circle of trust object to describe
|
|
7
|
-
* @returns {string} a one-line description
|
|
8
|
-
*/
|
|
9
|
-
export declare function getOneLineDescription(treeObj: TreeSkeleton): string;
|
|
10
4
|
/**
|
|
11
5
|
* Create an empty single tree export template
|
|
12
6
|
* @returns {SingleTreeExportInterface} an empty single tree export template
|
|
@@ -119,22 +113,6 @@ export declare function createFileParamTreeExportResolver(file: string): TreeExp
|
|
|
119
113
|
* @returns {Promise<TreeDependencyMapInterface>} a promise that resolves to a tree dependency map
|
|
120
114
|
*/
|
|
121
115
|
export declare function getTreeDescendents(treeExport: SingleTreeExportInterface, resolveTreeExport?: TreeExportResolverInterface, resolvedTreeIds?: string[]): Promise<TreeDependencyMapInterface>;
|
|
122
|
-
/**
|
|
123
|
-
* Describe a journey:
|
|
124
|
-
* - Properties, tags, description, name, metadata
|
|
125
|
-
* - Inner tree dependency tree
|
|
126
|
-
* - Node type summary
|
|
127
|
-
* - Nodes
|
|
128
|
-
* - Themes
|
|
129
|
-
* - Scripts
|
|
130
|
-
* - Email templates
|
|
131
|
-
* - Social identity providers
|
|
132
|
-
* - SAML2 entity providers
|
|
133
|
-
* - SAML2 circles of trust
|
|
134
|
-
* @param {SingleTreeExportInterface} journeyData journey export object
|
|
135
|
-
* @param {TreeExportResolverInterface} resolveTreeExport tree export resolver callback function
|
|
136
|
-
*/
|
|
137
|
-
export declare function describeJourney(journeyData: SingleTreeExportInterface, resolveTreeExport?: TreeExportResolverInterface): Promise<void>;
|
|
138
116
|
/**
|
|
139
117
|
* Find all node configuration objects that are no longer referenced by any tree
|
|
140
118
|
* @returns {Promise<unknown[]>} a promise that resolves to an array of orphaned nodes
|
|
@@ -169,10 +147,11 @@ export declare function isCloudOnlyJourney(journey: SingleTreeExportInterface):
|
|
|
169
147
|
* - standard: can run on any instance of a ForgeRock platform
|
|
170
148
|
* - cloud: utilize nodes, which are exclusively available in the ForgeRock Identity Cloud
|
|
171
149
|
* - premium: utilizes nodes, which come at a premium
|
|
150
|
+
* - custom: utilizes nodes not included in the ForgeRock platform release
|
|
172
151
|
* @param {SingleTreeExportInterface} journey journey export data
|
|
173
|
-
* @returns {
|
|
152
|
+
* @returns {JourneyClassification[]} an array of one or multiple classifications
|
|
174
153
|
*/
|
|
175
|
-
export declare function getJourneyClassification(journey: SingleTreeExportInterface):
|
|
154
|
+
export declare function getJourneyClassification(journey: SingleTreeExportInterface): JourneyClassification[];
|
|
176
155
|
/**
|
|
177
156
|
* List all the journeys/trees
|
|
178
157
|
* @param {boolean} long Long version, all the fields
|
|
@@ -193,3 +172,15 @@ export declare function deleteJourney(journeyId: string, options: any, progress?
|
|
|
193
172
|
* @param {Object} options deep=true also delete all the nodes and inner nodes, verbose=true print verbose info
|
|
194
173
|
*/
|
|
195
174
|
export declare function deleteJourneys(options: any): Promise<{}>;
|
|
175
|
+
/**
|
|
176
|
+
* Enable a journey
|
|
177
|
+
* @param journeyId journey id/name
|
|
178
|
+
* @returns {Promise<boolean>} true if the operation was successful, false otherwise
|
|
179
|
+
*/
|
|
180
|
+
export declare function enableJourney(journeyId: string): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Disable a journey
|
|
183
|
+
* @param journeyId journey id/name
|
|
184
|
+
* @returns {Promise<boolean>} true if the operation was successful, false otherwise
|
|
185
|
+
*/
|
|
186
|
+
export declare function disableJourney(journeyId: string): Promise<boolean>;
|