@rockcarver/frodo-cli 2.0.0-37 → 2.0.0-39

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/esm/cli/_template/something-else-export.js +1 -1
  3. package/esm/cli/_template/something-else-export.js.map +1 -1
  4. package/esm/cli/_template/something-export.js +1 -1
  5. package/esm/cli/_template/something-export.js.map +1 -1
  6. package/esm/cli/_template/something-other-export.js +1 -1
  7. package/esm/cli/_template/something-other-export.js.map +1 -1
  8. package/esm/cli/admin/admin-federation-export.js +4 -4
  9. package/esm/cli/admin/admin-federation-export.js.map +1 -1
  10. package/esm/cli/agent/agent-export.js +4 -4
  11. package/esm/cli/agent/agent-export.js.map +1 -1
  12. package/esm/cli/agent/agent-gateway-export.js +4 -4
  13. package/esm/cli/agent/agent-gateway-export.js.map +1 -1
  14. package/esm/cli/agent/agent-java-export.js +4 -4
  15. package/esm/cli/agent/agent-java-export.js.map +1 -1
  16. package/esm/cli/agent/agent-web-export.js +4 -4
  17. package/esm/cli/agent/agent-web-export.js.map +1 -1
  18. package/esm/cli/app/app-export.js +4 -4
  19. package/esm/cli/app/app-export.js.map +1 -1
  20. package/esm/cli/authn/authn-export.js +2 -2
  21. package/esm/cli/authn/authn-export.js.map +1 -1
  22. package/esm/cli/authz/authz-policy-export.js +6 -6
  23. package/esm/cli/authz/authz-policy-export.js.map +1 -1
  24. package/esm/cli/authz/authz-set-export.js +4 -4
  25. package/esm/cli/authz/authz-set-export.js.map +1 -1
  26. package/esm/cli/authz/authz-type-export.js +5 -5
  27. package/esm/cli/authz/authz-type-export.js.map +1 -1
  28. package/esm/cli/config/config-export.js +3 -3
  29. package/esm/cli/config/config-export.js.map +1 -1
  30. package/esm/cli/email/email-template-export.js +4 -4
  31. package/esm/cli/email/email-template-export.js.map +1 -1
  32. package/esm/cli/esv/esv-secret-export.js +4 -4
  33. package/esm/cli/esv/esv-secret-export.js.map +1 -1
  34. package/esm/cli/esv/esv-secret-list.js +2 -2
  35. package/esm/cli/esv/esv-secret-list.js.map +1 -1
  36. package/esm/cli/esv/esv-variable-export.js +4 -4
  37. package/esm/cli/esv/esv-variable-export.js.map +1 -1
  38. package/esm/cli/esv/esv-variable-list.js +2 -2
  39. package/esm/cli/esv/esv-variable-list.js.map +1 -1
  40. package/esm/cli/idp/idp-export.js +4 -4
  41. package/esm/cli/idp/idp-export.js.map +1 -1
  42. package/esm/cli/journey/journey-describe.js +3 -1
  43. package/esm/cli/journey/journey-describe.js.map +1 -1
  44. package/esm/cli/journey/journey-export.js +4 -4
  45. package/esm/cli/journey/journey-export.js.map +1 -1
  46. package/esm/cli/oauth/oauth-client-export.js +4 -4
  47. package/esm/cli/oauth/oauth-client-export.js.map +1 -1
  48. package/esm/cli/saml/saml-cot-export.js +4 -4
  49. package/esm/cli/saml/saml-cot-export.js.map +1 -1
  50. package/esm/cli/saml/saml-export.js +4 -4
  51. package/esm/cli/saml/saml-export.js.map +1 -1
  52. package/esm/cli/script/script-export.js +4 -4
  53. package/esm/cli/script/script-export.js.map +1 -1
  54. package/esm/cli/script/script-list.js +2 -2
  55. package/esm/cli/script/script-list.js.map +1 -1
  56. package/esm/cli/service/service-export.js +4 -4
  57. package/esm/cli/service/service-export.js.map +1 -1
  58. package/esm/cli/theme/theme-export.js +5 -5
  59. package/esm/cli/theme/theme-export.js.map +1 -1
  60. package/esm/ops/AdminFederationOps.js +11 -7
  61. package/esm/ops/AdminFederationOps.js.map +1 -1
  62. package/esm/ops/AgentOps.js +39 -25
  63. package/esm/ops/AgentOps.js.map +1 -1
  64. package/esm/ops/ApplicationOps.js +11 -8
  65. package/esm/ops/ApplicationOps.js.map +1 -1
  66. package/esm/ops/AuthenticationSettingsOps.js +4 -3
  67. package/esm/ops/AuthenticationSettingsOps.js.map +1 -1
  68. package/esm/ops/CirclesOfTrustOps.js +12 -7
  69. package/esm/ops/CirclesOfTrustOps.js.map +1 -1
  70. package/esm/ops/ConfigOps.js +9 -7
  71. package/esm/ops/ConfigOps.js.map +1 -1
  72. package/esm/ops/EmailTemplateOps.js +11 -7
  73. package/esm/ops/EmailTemplateOps.js.map +1 -1
  74. package/esm/ops/IdmOps.js +3 -2
  75. package/esm/ops/IdmOps.js.map +1 -1
  76. package/esm/ops/IdpOps.js +14 -7
  77. package/esm/ops/IdpOps.js.map +1 -1
  78. package/esm/ops/JourneyOps.js +15 -6
  79. package/esm/ops/JourneyOps.js.map +1 -1
  80. package/esm/ops/OAuth2ClientOps.js +10 -7
  81. package/esm/ops/OAuth2ClientOps.js.map +1 -1
  82. package/esm/ops/PolicyOps.js +18 -11
  83. package/esm/ops/PolicyOps.js.map +1 -1
  84. package/esm/ops/PolicySetOps.js +12 -7
  85. package/esm/ops/PolicySetOps.js.map +1 -1
  86. package/esm/ops/ResourceTypeOps.js +15 -9
  87. package/esm/ops/ResourceTypeOps.js.map +1 -1
  88. package/esm/ops/Saml2Ops.js +10 -7
  89. package/esm/ops/Saml2Ops.js.map +1 -1
  90. package/esm/ops/ScriptOps.js +73 -36
  91. package/esm/ops/ScriptOps.js.map +1 -1
  92. package/esm/ops/SecretsOps.js +76 -48
  93. package/esm/ops/SecretsOps.js.map +1 -1
  94. package/esm/ops/ServiceOps.js +10 -9
  95. package/esm/ops/ServiceOps.js.map +1 -1
  96. package/esm/ops/ThemeOps.js +15 -9
  97. package/esm/ops/ThemeOps.js.map +1 -1
  98. package/esm/ops/VariablesOps.js +49 -23
  99. package/esm/ops/VariablesOps.js.map +1 -1
  100. package/esm/utils/Config.js +147 -1
  101. package/esm/utils/Config.js.map +1 -1
  102. package/package.json +2 -2
  103. package/esm/utils/ExportImportUtils.js +0 -48
  104. package/esm/utils/ExportImportUtils.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"VariablesOps.js","names":["frodo","state","createKeyValueTable","createProgressIndicator","createTable","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getTypedFilename","saveJsonToFile","saveToFile","titleCase","wordwrap","decodeBase64","getFilePath","utils","resolvePerpetratorUuid","idm","managed","readVariables","readVariable","exportVariable","exportVariables","deleteVariable","updateVariableDescription","updateVariable","_updateVariable","cloud","variable","listVariables","long","outcome","spinnerId","variables","sort","a","b","_id","localeCompare","length","error","_error$response","response","data","message","table","push","valueBase64","loaded","description","getUseBearerTokenForAmApis","lastChangedBy","Date","lastChangeDate","toUTCString","toString","forEach","createVariable","variableId","value","type","code","setVariableDescription","deleteVariableById","deleteVariables","indicatorId","describeVariable","json","expressionType","toLocaleString","modifierName","exportVariableToFile","file","noDecode","fileName","filePath","fileData","brightCyan","err","exportVariablesToFile","getRealm","variablesExport","_error$response2","status","exportVariablesToFiles","variableList"],"sources":["../../src/ops/VariablesOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport {\n VariableExpressionType,\n VariableSkeleton,\n} from '@rockcarver/frodo-lib/types/api/cloud/VariablesApi';\n\nimport {\n createKeyValueTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n titleCase,\n} from '../utils/ExportImportUtils';\nimport wordwrap from './utils/Wordwrap';\n\nconst { decodeBase64, getFilePath } = frodo.utils;\nconst { resolvePerpetratorUuid } = frodo.idm.managed;\nconst {\n readVariables,\n readVariable,\n exportVariable,\n exportVariables,\n deleteVariable,\n updateVariableDescription,\n updateVariable: _updateVariable,\n} = frodo.cloud.variable;\n\n/**\n * List variables\n * @param {boolean} long Long version, all the fields\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listVariables(long: boolean): Promise<boolean> {\n let outcome = false;\n let spinnerId: string;\n let variables: VariableSkeleton[] = [];\n try {\n spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Reading variables...`\n );\n variables = await readVariables();\n variables.sort((a, b) => a._id.localeCompare(b._id));\n stopProgressIndicator(\n spinnerId,\n `Successfully read ${variables.length} variables.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error reading variables: ${error.response?.data || error.message}`,\n 'fail'\n );\n }\n if (long) {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Value'['brightCyan'],\n 'Status'['brightCyan'],\n 'Description'['brightCyan'],\n 'Modifier'['brightCyan'],\n 'Modified (UTC)'['brightCyan'],\n ]);\n for (const variable of variables) {\n table.push([\n variable._id,\n wordwrap(decodeBase64(variable.valueBase64), 40),\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n wordwrap(variable.description, 40),\n state.getUseBearerTokenForAmApis()\n ? variable.lastChangedBy\n : await resolvePerpetratorUuid(variable.lastChangedBy),\n new Date(variable.lastChangeDate).toUTCString(),\n ]);\n }\n printMessage(table.toString(), 'data');\n outcome = true;\n } else {\n variables.forEach((variable) => {\n printMessage(variable._id, 'data');\n });\n outcome = true;\n }\n return outcome;\n}\n\n/**\n * Create variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n * @param {VariableExpressionType} type variable type\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function createVariable(\n variableId: string,\n value: string,\n description: string,\n type: VariableExpressionType = 'string'\n): Promise<boolean> {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Creating variable ${variableId}...`\n );\n try {\n await _updateVariable(variableId, value, description, type);\n stopProgressIndicator(\n spinnerId,\n `Created variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n error.response\n ? `Error: ${error.response.data.code} - ${error.response.data.message}`\n : error,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Update variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function updateVariable(variableId, value, description) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Updating variable ${variableId}...`\n );\n try {\n await _updateVariable(variableId, value, description);\n stopProgressIndicator(\n spinnerId,\n `Updated variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Set description of variable\n * @param {string} variableId variable id\n * @param {string} description variable description\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function setVariableDescription(variableId, description) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Setting description of variable ${variableId}...`\n );\n try {\n await updateVariableDescription(variableId, description);\n stopProgressIndicator(\n spinnerId,\n `Set description of variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Delete a variable\n * @param {string} variableId variable id\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteVariableById(variableId) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Deleting variable ${variableId}...`\n );\n try {\n await deleteVariable(variableId);\n stopProgressIndicator(\n spinnerId,\n `Deleted variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Delete all variables\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteVariables() {\n let outcome = false;\n let indicatorId: string;\n try {\n const variables = await readVariables();\n indicatorId = createProgressIndicator(\n 'determinate',\n variables.length,\n `Deleting variable...`\n );\n for (const variable of variables) {\n try {\n await deleteVariable(variable._id);\n updateProgressIndicator(\n indicatorId,\n `Deleted variable ${variable._id}`\n );\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n }\n outcome = true;\n stopProgressIndicator(indicatorId, `Variables deleted.`);\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n return outcome;\n}\n\n/**\n * Describe a variable\n * @param {string} variableId variable id\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describeVariable(variableId, json = false) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Describing variable ${variableId}...`\n );\n try {\n const variable = await readVariable(variableId);\n stopProgressIndicator(\n spinnerId,\n `Successfully retrieved variable ${variableId}`,\n 'success'\n );\n if (json) {\n printMessage(variable, 'data');\n } else {\n const table = createKeyValueTable();\n table.push(['Name'['brightCyan'], variable._id]);\n table.push([\n 'Value'['brightCyan'],\n wordwrap(decodeBase64(variable.valueBase64), 40),\n ]);\n table.push(['Type'['brightCyan'], variable.expressionType]);\n table.push([\n 'Status'['brightCyan'],\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n ]);\n table.push([\n 'Description'['brightCyan'],\n wordwrap(variable.description, 60),\n ]);\n table.push([\n 'Modified'['brightCyan'],\n new Date(variable.lastChangeDate).toLocaleString(),\n ]);\n let modifierName: string;\n try {\n modifierName = await resolvePerpetratorUuid(variable.lastChangedBy);\n } catch (error) {\n // ignore\n }\n if (modifierName && modifierName !== variable.lastChangedBy) {\n table.push(['Modifier'['brightCyan'], modifierName]);\n }\n table.push(['Modifier UUID'['brightCyan'], variable.lastChangedBy]);\n printMessage(table.toString(), 'data');\n }\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error describing variable ${variableId}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Export a single variable to file\n * @param {String} variableId Variable id\n * @param {String} file Optional filename\n * @param {boolean} noDecode Do not include decoded variable value in export\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportVariableToFile(\n variableId: string,\n file: string | null,\n noDecode: boolean\n) {\n debugMessage(\n `Cli.VariablesOps.exportVariableToFile: start [variableId=${variableId}, file=${file}]`\n );\n let outcome = false;\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(variableId, 'variable');\n }\n const filePath = getFilePath(fileName, true);\n let indicatorId: string;\n try {\n indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting variable ${variableId}`\n );\n const fileData = await exportVariable(variableId, noDecode);\n saveJsonToFile(fileData, filePath);\n updateProgressIndicator(indicatorId, `Exported variable ${variableId}`);\n stopProgressIndicator(\n indicatorId,\n // @ts-expect-error - brightCyan colors the string, even though it is not a property of string\n `Exported ${variableId.brightCyan} to ${filePath.brightCyan}.`\n );\n outcome = true;\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(err, 'error');\n }\n debugMessage(\n `Cli.VariablesOps.exportVariableToFile: end [variableId=${variableId}, file=${file}]`\n );\n return outcome;\n}\n\n/**\n * Export all variables to single file\n * @param {string} file Optional filename\n * @param {boolean} noDecode Do not include decoded variable value in export\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportVariablesToFile(\n file: string | null,\n noDecode: boolean\n) {\n debugMessage(`Cli.VariablesOps.exportVariablesToFile: start [file=${file}]`);\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Exporting variables...`\n );\n if (!file) {\n file = getTypedFilename(\n `all${titleCase(state.getRealm())}Variables`,\n 'variable'\n );\n }\n try {\n const variablesExport = await exportVariables(noDecode);\n saveJsonToFile(variablesExport, getFilePath(file, true));\n stopProgressIndicator(\n spinnerId,\n `Exported variables to ${file}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error exporting variables: ${error.response?.status || error.message}`,\n 'fail'\n );\n }\n debugMessage(\n `Cli.VariablesOps.exportVariablesToFile: end [outcome=${outcome}, file=${file}]`\n );\n return outcome;\n}\n\n/**\n * Export all variables to seperate files\n * @param {boolean} noDecode Do not include decoded variable value in export\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportVariablesToFiles(noDecode: boolean) {\n let outcome = false;\n let spinnerId: string;\n let indicatorId: string;\n let variableList: VariableSkeleton[] = [];\n try {\n spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Retrieving variables...`\n );\n variableList = await readVariables();\n stopProgressIndicator(\n spinnerId,\n `Successfully retrieved ${variableList.length} variables`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error retrieving variables: ${error.message}`,\n 'fail'\n );\n }\n try {\n const indicatorId = createProgressIndicator(\n 'determinate',\n variableList.length,\n 'Exporting variables'\n );\n for (const variable of variableList) {\n if (!noDecode) {\n variable.value = decodeBase64(variable.valueBase64);\n }\n updateProgressIndicator(indicatorId, `Writing variable ${variable._id}`);\n const fileName = getTypedFilename(variable._id, 'variable');\n saveToFile('variable', variable, '_id', getFilePath(fileName, true));\n }\n stopProgressIndicator(\n indicatorId,\n `${variableList.length} variables exported`\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting variables: ${error.message}`\n );\n }\n return outcome;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAMpD,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,SAAS,QACJ,4BAA4B;AACnC,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC,YAAY;EAAEC;AAAY,CAAC,GAAGf,KAAK,CAACgB,KAAK;AACjD,MAAM;EAAEC;AAAuB,CAAC,GAAGjB,KAAK,CAACkB,GAAG,CAACC,OAAO;A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AI;IACFrD,SAAS,GAAG9B,uBAAuB,CACjC,eAAe,EACf,CAAC,EACA,yBACH,CAAC;IACDmF,YAAY,GAAG,MAAMlE,aAAa,CAAC,CAAC;IACpCb,qBAAqB,CACnB0B,SAAS,EACR,0BAAyBqD,YAAY,CAAC9C,MAAO,YAAW,EACzD,SACF,CAAC;EACH,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdlC,qBAAqB,CACnB0B,SAAS,EACR,+BAA8BQ,KAAK,CAACI,OAAQ,EAAC,EAC9C,MACF,CAAC;EACH;EACA,IAAI;IACF,MAAMqB,WAAW,GAAG/D,uBAAuB,CACzC,aAAa,EACbmF,YAAY,CAAC9C,MAAM,EACnB,qBACF,CAAC;IACD,KAAK,MAAMX,QAAQ,IAAIyD,YAAY,EAAE;MACnC,IAAI,CAACZ,QAAQ,EAAE;QACb7C,QAAQ,CAAC+B,KAAK,GAAG9C,YAAY,CAACe,QAAQ,CAACmB,WAAW,CAAC;MACrD;MACAxC,uBAAuB,CAAC0D,WAAW,EAAG,oBAAmBrC,QAAQ,CAACS,GAAI,EAAC,CAAC;MACxE,MAAMqC,QAAQ,GAAGlE,gBAAgB,CAACoB,QAAQ,CAACS,GAAG,EAAE,UAAU,CAAC;MAC3D3B,UAAU,CAAC,UAAU,EAAEkB,QAAQ,EAAE,KAAK,EAAEd,WAAW,CAAC4D,QAAQ,EAAE,IAAI,CAAC,CAAC;IACtE;IACApE,qBAAqB,CACnB2D,WAAW,EACV,GAAEoB,YAAY,CAAC9C,MAAO,qBACzB,CAAC;IACDR,OAAO,GAAG,IAAI;EAChB,CAAC,CAAC,OAAOS,KAAK,EAAE;IACdlC,qBAAqB,CACnB2D,WAAW,EACV,8BAA6BzB,KAAK,CAACI,OAAQ,EAC9C,CAAC;EACH;EACA,OAAOb,OAAO;AAChB"}
1
+ {"version":3,"file":"VariablesOps.js","names":["frodo","state","getFullExportConfig","isIdUsed","createKeyValueTable","createProgressIndicator","createTable","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","wordwrap","decodeBase64","getFilePath","getTypedFilename","saveJsonToFile","saveToFile","titleCase","utils","resolvePerpetratorUuid","idm","managed","readVariables","readVariable","exportVariable","exportVariables","deleteVariable","updateVariableDescription","updateVariable","_updateVariable","cloud","variable","listVariables","long","usage","file","spinnerId","variables","sort","a","b","_id","localeCompare","length","error","_error$response","response","data","message","forEach","fullExport","headers","_error$response2","push","table","values","valueBase64","loaded","description","getUseBearerTokenForAmApis","lastChangedBy","Date","lastChangeDate","toUTCString","isEsvUsed","used","location","toString","createVariable","variableId","value","type","outcome","code","setVariableDescription","deleteVariableById","deleteVariables","indicatorId","describeVariable","json","expressionType","toLocaleString","modifierName","exportVariableToFile","noDecode","includeMeta","fileName","filePath","fileData","brightCyan","err","exportVariablesToFile","getRealm","variablesExport","_error$response3","status","exportVariablesToFiles","variableList"],"sources":["../../src/ops/VariablesOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport {\n VariableExpressionType,\n VariableSkeleton,\n} from '@rockcarver/frodo-lib/types/api/cloud/VariablesApi';\n\nimport { getFullExportConfig, isIdUsed } from '../utils/Config';\nimport {\n createKeyValueTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport wordwrap from './utils/Wordwrap';\n\nconst {\n decodeBase64,\n getFilePath,\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n titleCase,\n} = frodo.utils;\nconst { resolvePerpetratorUuid } = frodo.idm.managed;\nconst {\n readVariables,\n readVariable,\n exportVariable,\n exportVariables,\n deleteVariable,\n updateVariableDescription,\n updateVariable: _updateVariable,\n} = frodo.cloud.variable;\n\n/**\n * List variables\n * @param {boolean} long Long version, all the fields besides usage\n * @param {boolean} usage Display usage field\n * @param {String | null} file Optional filename to determine usage\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listVariables(\n long: boolean = false,\n usage: boolean = false,\n file: string | null = null\n): Promise<boolean> {\n let spinnerId: string;\n let variables: VariableSkeleton[] = [];\n try {\n spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Reading variables...`\n );\n variables = await readVariables();\n variables.sort((a, b) => a._id.localeCompare(b._id));\n stopProgressIndicator(\n spinnerId,\n `Successfully read ${variables.length} variables.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error reading variables: ${error.response?.data || error.message}`,\n 'fail'\n );\n return false;\n }\n if (!long && !usage) {\n variables.forEach((variable) => {\n printMessage(variable._id, 'data');\n });\n return true;\n }\n let fullExport = null;\n const headers = long\n ? [\n 'Id'['brightCyan'],\n 'Value'['brightCyan'],\n 'Status'['brightCyan'],\n 'Description'['brightCyan'],\n 'Modifier'['brightCyan'],\n 'Modified (UTC)'['brightCyan'],\n ]\n : ['Id'['brightCyan']];\n if (usage) {\n try {\n fullExport = await getFullExportConfig(file);\n } catch (error) {\n printMessage(\n `Error getting full export: ${error.response?.data || error.message}`,\n 'error'\n );\n return false;\n }\n //Delete variables from full export so they aren't mistakenly used for determining usage\n delete fullExport.variables;\n headers.push('Used'['brightCyan']);\n }\n const table = createTable(headers);\n for (const variable of variables) {\n const values = long\n ? [\n variable._id,\n wordwrap(decodeBase64(variable.valueBase64), 40),\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n wordwrap(variable.description, 40),\n state.getUseBearerTokenForAmApis()\n ? variable.lastChangedBy\n : await resolvePerpetratorUuid(variable.lastChangedBy),\n new Date(variable.lastChangeDate).toUTCString(),\n ]\n : [variable._id];\n if (usage) {\n const isEsvUsed = isIdUsed(fullExport, variable._id, true);\n values.push(\n isEsvUsed.used\n ? `${'yes'['brightGreen']} (at ${isEsvUsed.location})`\n : 'no'['brightRed']\n );\n }\n table.push(values);\n }\n printMessage(table.toString(), 'data');\n return true;\n}\n\n/**\n * Create variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n * @param {VariableExpressionType} type variable type\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function createVariable(\n variableId: string,\n value: string,\n description: string,\n type: VariableExpressionType = 'string'\n): Promise<boolean> {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Creating variable ${variableId}...`\n );\n try {\n await _updateVariable(variableId, value, description, type);\n stopProgressIndicator(\n spinnerId,\n `Created variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n error.response\n ? `Error: ${error.response.data.code} - ${error.response.data.message}`\n : error,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Update variable\n * @param {string} variableId variable id\n * @param {string} value variable value\n * @param {string} description variable description\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function updateVariable(variableId, value, description) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Updating variable ${variableId}...`\n );\n try {\n await _updateVariable(variableId, value, description);\n stopProgressIndicator(\n spinnerId,\n `Updated variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Set description of variable\n * @param {string} variableId variable id\n * @param {string} description variable description\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function setVariableDescription(variableId, description) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Setting description of variable ${variableId}...`\n );\n try {\n await updateVariableDescription(variableId, description);\n stopProgressIndicator(\n spinnerId,\n `Set description of variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Delete a variable\n * @param {string} variableId variable id\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteVariableById(variableId) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Deleting variable ${variableId}...`\n );\n try {\n await deleteVariable(variableId);\n stopProgressIndicator(\n spinnerId,\n `Deleted variable ${variableId}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Delete all variables\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteVariables() {\n let outcome = false;\n let indicatorId: string;\n try {\n const variables = await readVariables();\n indicatorId = createProgressIndicator(\n 'determinate',\n variables.length,\n `Deleting variable...`\n );\n for (const variable of variables) {\n try {\n await deleteVariable(variable._id);\n updateProgressIndicator(\n indicatorId,\n `Deleted variable ${variable._id}`\n );\n } catch (error) {\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n }\n outcome = true;\n stopProgressIndicator(indicatorId, `Variables deleted.`);\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error: ${error.response.data.code} - ${error.response.data.message}`\n );\n printMessage(\n `Error: ${error.response.data.code} - ${error.response.data.message}`,\n 'error'\n );\n }\n return outcome;\n}\n\n/**\n * Describe a variable\n * @param {string} variableId variable id\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describeVariable(variableId, json = false) {\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Describing variable ${variableId}...`\n );\n try {\n const variable = await readVariable(variableId);\n stopProgressIndicator(\n spinnerId,\n `Successfully retrieved variable ${variableId}`,\n 'success'\n );\n if (json) {\n printMessage(variable, 'data');\n } else {\n const table = createKeyValueTable();\n table.push(['Name'['brightCyan'], variable._id]);\n table.push([\n 'Value'['brightCyan'],\n wordwrap(decodeBase64(variable.valueBase64), 40),\n ]);\n table.push(['Type'['brightCyan'], variable.expressionType]);\n table.push([\n 'Status'['brightCyan'],\n variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'],\n ]);\n table.push([\n 'Description'['brightCyan'],\n wordwrap(variable.description, 60),\n ]);\n table.push([\n 'Modified'['brightCyan'],\n new Date(variable.lastChangeDate).toLocaleString(),\n ]);\n let modifierName: string;\n try {\n modifierName = await resolvePerpetratorUuid(variable.lastChangedBy);\n } catch (error) {\n // ignore\n }\n if (modifierName && modifierName !== variable.lastChangedBy) {\n table.push(['Modifier'['brightCyan'], modifierName]);\n }\n table.push(['Modifier UUID'['brightCyan'], variable.lastChangedBy]);\n printMessage(table.toString(), 'data');\n }\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error describing variable ${variableId}`,\n 'fail'\n );\n }\n return outcome;\n}\n\n/**\n * Export a single variable to file\n * @param {String} variableId Variable id\n * @param {String} file Optional filename\n * @param {boolean} noDecode Do not include decoded variable value in export\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportVariableToFile(\n variableId: string,\n file: string | null,\n noDecode: boolean,\n includeMeta: boolean\n) {\n debugMessage(\n `Cli.VariablesOps.exportVariableToFile: start [variableId=${variableId}, file=${file}]`\n );\n let outcome = false;\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(variableId, 'variable');\n }\n const filePath = getFilePath(fileName, true);\n let indicatorId: string;\n try {\n indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting variable ${variableId}`\n );\n const fileData = await exportVariable(variableId, noDecode);\n saveJsonToFile(fileData, filePath, includeMeta);\n updateProgressIndicator(indicatorId, `Exported variable ${variableId}`);\n stopProgressIndicator(\n indicatorId,\n // @ts-expect-error - brightCyan colors the string, even though it is not a property of string\n `Exported ${variableId.brightCyan} to ${filePath.brightCyan}.`\n );\n outcome = true;\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(err, 'error');\n }\n debugMessage(\n `Cli.VariablesOps.exportVariableToFile: end [variableId=${variableId}, file=${file}]`\n );\n return outcome;\n}\n\n/**\n * Export all variables to single file\n * @param {string} file Optional filename\n * @param {boolean} noDecode Do not include decoded variable value in export\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportVariablesToFile(\n file: string | null,\n noDecode: boolean,\n includeMeta: boolean\n) {\n debugMessage(`Cli.VariablesOps.exportVariablesToFile: start [file=${file}]`);\n let outcome = false;\n const spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Exporting variables...`\n );\n if (!file) {\n file = getTypedFilename(\n `all${titleCase(state.getRealm())}Variables`,\n 'variable'\n );\n }\n try {\n const variablesExport = await exportVariables(noDecode);\n saveJsonToFile(variablesExport, getFilePath(file, true), includeMeta);\n stopProgressIndicator(\n spinnerId,\n `Exported variables to ${file}`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error exporting variables: ${error.response?.status || error.message}`,\n 'fail'\n );\n }\n debugMessage(\n `Cli.VariablesOps.exportVariablesToFile: end [outcome=${outcome}, file=${file}]`\n );\n return outcome;\n}\n\n/**\n * Export all variables to seperate files\n * @param {boolean} noDecode Do not include decoded variable value in export\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportVariablesToFiles(\n noDecode: boolean,\n includeMeta: boolean\n) {\n let outcome = false;\n let spinnerId: string;\n let indicatorId: string;\n let variableList: VariableSkeleton[] = [];\n try {\n spinnerId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Retrieving variables...`\n );\n variableList = await readVariables();\n stopProgressIndicator(\n spinnerId,\n `Successfully retrieved ${variableList.length} variables`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n spinnerId,\n `Error retrieving variables: ${error.message}`,\n 'fail'\n );\n }\n try {\n const indicatorId = createProgressIndicator(\n 'determinate',\n variableList.length,\n 'Exporting variables'\n );\n for (const variable of variableList) {\n if (!noDecode) {\n variable.value = decodeBase64(variable.valueBase64);\n }\n updateProgressIndicator(indicatorId, `Writing variable ${variable._id}`);\n const fileName = getTypedFilename(variable._id, 'variable');\n saveToFile(\n 'variable',\n variable,\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n }\n stopProgressIndicator(\n indicatorId,\n `${variableList.length} variables exported`\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting variables: ${error.message}`\n );\n }\n return outcome;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAMpD,SAASC,mBAAmB,EAAEC,QAAQ,QAAQ,iBAAiB;AAC/D,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EACJC,YAAY;EACZC,WAAW;EACXC,gBAAgB;EAChBC,cAAc;EACdC,UAAU;EACVC;AACF,CAAC,GAAGjB,KAAK,CAACkB,KAAK;AACf,MAAM;EAAEC;AAAuB,CAAC,GAAGnB,KAAK,CAACoB,GAAG,CAACC,OAAO;AACpD,MAAM;EACJC,aAAa;EACbC,YAAY;EACZC,cAAc;EACdC,eAAe;EACfC,cAAc;EACdC,yBAAyB;EACzBC,cAAc,EAAEC;AAClB,CAAC,GAAG7B,KAAK,CAAC8B,KAAK,CAACC,QAAQ;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,aAAaA,CACjCC,IAAa,GAAG,KAAK,EACrBC,KAAc,GAAG,KAAK,EACtBC,IAAmB,GAAG,IAAI,EACR;EAClB,IAAIC,SAAiB;EACrB,IAAIC,SAA6B,GAAG,EAAE;EACtC,IAAI;IACFD,SAAS,GAAG/B,uBAAuB,CACjC,eAAe,EACf,CAAC,EACA,sBACH,CAAC;IACDgC,SAAS,GAAG,MA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MACrD;MACA9C,uBAAuB,CAACmE,WAAW,EAAG,oBAAmB9C,QAAQ,CAACU,GAAI,EAAC,CAAC;MACxE,MAAM6C,QAAQ,GAAGxE,gBAAgB,CAACiB,QAAQ,CAACU,GAAG,EAAE,UAAU,CAAC;MAC3DzB,UAAU,CACR,UAAU,EACVe,QAAQ,EACR,KAAK,EACLlB,WAAW,CAACyE,QAAQ,EAAE,IAAI,CAAC,EAC3BD,WACF,CAAC;IACH;IACA5E,qBAAqB,CACnBoE,WAAW,EACV,GAAEoB,YAAY,CAACtD,MAAO,qBACzB,CAAC;IACD6B,OAAO,GAAG,IAAI;EAChB,CAAC,CAAC,OAAO5B,KAAK,EAAE;IACdnC,qBAAqB,CACnBoE,WAAW,EACV,8BAA6BjC,KAAK,CAACI,OAAQ,EAC9C,CAAC;EACH;EACA,OAAOwB,OAAO;AAChB"}
@@ -1,7 +1,15 @@
1
- import { frodo } from '@rockcarver/frodo-lib';
1
+ import { frodo, state } from '@rockcarver/frodo-lib';
2
2
  import fs from 'fs';
3
3
  import os from 'os';
4
+ import slugify from 'slugify';
4
5
  import { printMessage } from './Console';
6
+ const {
7
+ getFilePath,
8
+ readFiles
9
+ } = frodo.utils;
10
+ const {
11
+ exportFullConfiguration
12
+ } = frodo.config;
5
13
  const {
6
14
  getDefaultNoiseFilter
7
15
  } = frodo.cloud.log;
@@ -40,4 +48,142 @@ export function getNoiseFilters(defaults) {
40
48
  }
41
49
  return noiseFilter;
42
50
  }
51
+
52
+ /**
53
+ * Gets the full export config from one of three locations:
54
+ * 1. The file passed into the function if one is provided.
55
+ * 2. The working directory if it exists (provided by the user)
56
+ * 3. The cloud tenant if the exports are not locally provided
57
+ * @param file The optional file path
58
+ * @returns The full export config
59
+ */
60
+ export async function getFullExportConfig(file = null) {
61
+ // Get export from file if it exists
62
+ if (file) {
63
+ return JSON.parse(fs.readFileSync(getFilePath(file), 'utf8'));
64
+ }
65
+ // If working directory doesn't exist, export from the cloud
66
+ const workingDirectory = state.getDirectory();
67
+ if (!workingDirectory) {
68
+ return await exportFullConfiguration({
69
+ useStringArrays: true,
70
+ noDecode: false
71
+ });
72
+ }
73
+ // Go through files in directory and reconstruct the full export
74
+ const fullExportConfig = {
75
+ meta: {},
76
+ agents: {},
77
+ application: {},
78
+ authentication: {},
79
+ config: {},
80
+ emailTemplate: {},
81
+ idp: {},
82
+ managedApplication: {},
83
+ policy: {},
84
+ policyset: {},
85
+ resourcetype: {},
86
+ saml: {
87
+ hosted: {},
88
+ remote: {},
89
+ metadata: {},
90
+ cot: {}
91
+ },
92
+ script: {},
93
+ secrets: {},
94
+ service: {},
95
+ theme: {},
96
+ trees: {},
97
+ variables: {}
98
+ };
99
+ const files = await readFiles(workingDirectory);
100
+ const jsonFiles = files.filter(f => f.path.endsWith('.json'));
101
+ const idmConfigFiles = jsonFiles.filter(f => f.path.startsWith('config/'));
102
+ const samlFiles = jsonFiles.filter(f => f.path.startsWith('saml/') || f.path.startsWith('cot/'));
103
+ const otherFiles = jsonFiles.filter(f => !f.path.startsWith('config/') && !f.path.startsWith('saml/') && !f.path.startsWith('cot/'));
104
+ const scriptFiles = files.filter(f => f.path.endsWith('.js') || f.path.endsWith('.groovy'));
105
+ // Handle json files
106
+ for (const f of otherFiles) {
107
+ for (const [id, value] of Object.entries(JSON.parse(f.content))) {
108
+ if (value == null || fullExportConfig[id] == null) {
109
+ continue;
110
+ }
111
+ Object.assign(fullExportConfig[id], value);
112
+ }
113
+ }
114
+ // Handle saml files
115
+ for (const f of samlFiles) {
116
+ let content = JSON.parse(f.content);
117
+ content = content.saml;
118
+ for (const [id, value] of Object.entries(content)) {
119
+ Object.assign(fullExportConfig.saml[id], value);
120
+ }
121
+ }
122
+ // Handle idm config files
123
+ for (const f of idmConfigFiles) {
124
+ const content = JSON.parse(f.content);
125
+ fullExportConfig.config[content._id] = content;
126
+ }
127
+ // Handle extracted scripts, adding them to their corresponding script objects in the export
128
+ if (scriptFiles.length > 0 && fullExportConfig.script != null) {
129
+ const scriptExports = Object.values(fullExportConfig.script);
130
+ for (const f of scriptFiles) {
131
+ const name = f.path.substring(f.path.lastIndexOf('/') + 1, f.path.indexOf('.', f.path.lastIndexOf('/')));
132
+ const scriptLines = f.content.split('\n');
133
+ const script = scriptExports.find(s => slugify(s.name.replace(/^http(s?):\/\//, ''), {
134
+ remove: /[^\w\s$*_+~.()'"!\-@]+/g
135
+ }) === name);
136
+ if (!script) {
137
+ throw Error(`Can't find the script corresponding to the file '${f.path}' in the export files`);
138
+ }
139
+ script.script = scriptLines;
140
+ }
141
+ }
142
+ return fullExportConfig;
143
+ }
144
+
145
+ /**
146
+ * Determines if a string id is being used anywhere within the given configuration object
147
+ * @param configuration The configuration object
148
+ * @param id The id being search for
149
+ * @param isEsv Whether the id corresponds to an ESV or not
150
+ */
151
+ export function isIdUsed(
152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
+ configuration, id, isEsv) {
154
+ return isIdUsedRecurse(configuration, isEsv ?
155
+ // For ESV ids, they contain either letters, numbers, dashes, or underscores. The dashes get replaced with periods (escaped with a \ for the regex)
156
+ // since anywhere they are being used they will be used with periods, not dashes. Note that the (?:[^a-z0-9._]|$) expressions at the beginning and
157
+ // end are meant to ensure that the id found is not a substring of some other id (i.e. the id found must either be at the beginning or end of the
158
+ // string, or if in the middle of a string, is not preceded or followed by a character that would be part of another id).
159
+ new RegExp(`(?:[^a-z0-9._]|^)${id.replaceAll('-', '\\.')}(?:[^a-z0-9._]|$)`) :
160
+ // For normal ids, they contain only letters, numbers, or dashes.
161
+ new RegExp(`(?:[^a-z0-9-]|^)${id}(?:[^a-z0-9-]|$)`));
162
+ }
163
+
164
+ /**
165
+ * Recursive helper for isIdUsed that finds any strings contained in the configuration that pass the regex
166
+ * @param configuration The configuration (could be anything)
167
+ * @param regex The regex test
168
+ */
169
+ function isIdUsedRecurse(
170
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
+ configuration, regex) {
172
+ const type = typeof configuration;
173
+ if (type === 'object' && configuration !== null) {
174
+ for (const [id, value] of Object.entries(
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+ configuration)) {
177
+ const isIdUsed = isIdUsedRecurse(value, regex);
178
+ if (isIdUsed.used) {
179
+ isIdUsed.location = id + (value.name ? `(name: '${value.name}')` : '') + (isIdUsed.location === '' ? '' : '.') + isIdUsed.location;
180
+ return isIdUsed;
181
+ }
182
+ }
183
+ }
184
+ return {
185
+ used: type === 'string' && regex.test(configuration),
186
+ location: ''
187
+ };
188
+ }
43
189
  //# sourceMappingURL=Config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Config.js","names":["frodo","fs","os","printMessage","getDefaultNoiseFilter","cloud","log","FRODO_CONFIG_PATH_KEY","FRODO_LOG_NOISEFILTER_FILENAME","getConfigPath","process","env","homedir","getCustomNoiseFilters","filename","noiseFilter","data","readFileSync","JSON","parse","e","message","getNoiseFilters","defaults","length","writeFileSync","stringify"],"sources":["../../src/utils/Config.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport os from 'os';\n\nimport { printMessage } from './Console';\n\nconst { getDefaultNoiseFilter } = frodo.cloud.log;\n\nexport const FRODO_CONFIG_PATH_KEY = 'FRODO_CONFIG_PATH';\nexport const FRODO_LOG_NOISEFILTER_FILENAME = 'LoggingNoiseFilter.json';\n\nexport function getConfigPath(): string {\n return process.env[FRODO_CONFIG_PATH_KEY] || `${os.homedir()}/.frodo`;\n}\n\nfunction getCustomNoiseFilters(): Array<string> {\n const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;\n let noiseFilter = [];\n try {\n const data = fs.readFileSync(filename, 'utf8');\n noiseFilter = JSON.parse(data);\n } catch (e) {\n printMessage(`Error reading ${filename} (${e.message})`, 'error');\n }\n return noiseFilter;\n}\n\nexport function getNoiseFilters(defaults: boolean): Array<string> {\n const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;\n if (defaults) {\n printMessage(`Using default logging noise filters.`, 'info');\n return getDefaultNoiseFilter();\n }\n let noiseFilter = getCustomNoiseFilters();\n if (noiseFilter.length == 0) {\n printMessage(`No custom noise filters defined. Using defaults.`, 'info');\n noiseFilter = getDefaultNoiseFilter();\n try {\n fs.writeFileSync(filename, JSON.stringify(noiseFilter, null, 2));\n printMessage(\n `The default filters were saved in ${filename}. You can change the filters as needed.`,\n 'info'\n );\n } catch (e) {\n printMessage(\n `Error creating noise filter configuration with default values.`,\n 'error'\n );\n }\n }\n return noiseFilter;\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,EAAE,MAAM,IAAI;AAEnB,SAASC,YAAY,QAAQ,WAAW;AAExC,MAAM;EAAEC;AAAsB,CAAC,GAAGJ,KAAK,CAACK,KAAK,CAACC,GAAG;AAEjD,OAAO,MAAMC,qBAAqB,GAAG,mBAAmB;AACxD,OAAO,MAAMC,8BAA8B,GAAG,yBAAyB;AAEvE,OAAO,SAASC,aAAaA,CAAA,EAAW;EACtC,OAAOC,OAAO,CAACC,GAAG,CAACJ,qBAAqB,CAAC,IAAK,GAAEL,EAAE,CAACU,OAAO,CAAC,CAAE,SAAQ;AACvE;AAEA,SAASC,qBAAqBA,CAAA,EAAkB;EAC9C,MAAMC,QAAQ,GAAI,GAAEL,aAAa,CAAC,CAAE,IAAGD,8BAA+B,EAAC;EACvE,IAAIO,WAAW,GAAG,EAAE;EACpB,IAAI;IACF,MAAMC,IAAI,GAAGf,EAAE,CAACgB,YAAY,CAACH,QAAQ,EAAE,MAAM,CAAC;IAC9CC,WAAW,GAAGG,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;EAChC,CAAC,CAAC,OAAOI,CAAC,EAAE;IACVjB,YAAY,CAAE,iBAAgBW,QAAS,KAAIM,CAAC,CAACC,OAAQ,GAAE,EAAE,OAAO,CAAC;EACnE;EACA,OAAON,WAAW;AACpB;AAEA,OAAO,SAASO,eAAeA,CAACC,QAAiB,EAAiB;EAChE,MAAMT,QAAQ,GAAI,GAAEL,aAAa,CAAC,CAAE,IAAGD,8BAA+B,EAAC;EACvE,IAAIe,QAAQ,EAAE;IACZpB,YAAY,CAAE,sCAAqC,EAAE,MAAM,CAAC;IAC5D,OAAOC,qBAAqB,CAAC,CAAC;EAChC;EACA,IAAIW,WAAW,GAAGF,qBAAqB,CAAC,CAAC;EACzC,IAAIE,WAAW,CAACS,MAAM,IAAI,CAAC,EAAE;IAC3BrB,YAAY,CAAE,kDAAiD,EAAE,MAAM,CAAC;IACxEY,WAAW,GAAGX,qBAAqB,CAAC,CAAC;IACrC,IAAI;MACFH,EAAE,CAACwB,aAAa,CAACX,QAAQ,EAAEI,IAAI,CAACQ,SAAS,CAACX,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;MAChEZ,YAAY,CACT,qCAAoCW,QAAS,yCAAwC,EACtF,MACF,CAAC;IACH,CAAC,CAAC,OAAOM,CAAC,EAAE;MACVjB,YAAY,CACT,gEAA+D,EAChE,OACF,CAAC;IACH;EACF;EACA,OAAOY,WAAW;AACpB"}
1
+ {"version":3,"file":"Config.js","names":["frodo","state","fs","os","slugify","printMessage","getFilePath","readFiles","utils","exportFullConfiguration","config","getDefaultNoiseFilter","cloud","log","FRODO_CONFIG_PATH_KEY","FRODO_LOG_NOISEFILTER_FILENAME","getConfigPath","process","env","homedir","getCustomNoiseFilters","filename","noiseFilter","data","readFileSync","JSON","parse","e","message","getNoiseFilters","defaults","length","writeFileSync","stringify","getFullExportConfig","file","workingDirectory","getDirectory","useStringArrays","noDecode","fullExportConfig","meta","agents","application","authentication","emailTemplate","idp","managedApplication","policy","policyset","resourcetype","saml","hosted","remote","metadata","cot","script","secrets","service","theme","trees","variables","files","jsonFiles","filter","f","path","endsWith","idmConfigFiles","startsWith","samlFiles","otherFiles","scriptFiles","id","value","Object","entries","content","assign","_id","scriptExports","values","name","substring","lastIndexOf","indexOf","scriptLines","split","find","s","replace","remove","Error","isIdUsed","configuration","isEsv","isIdUsedRecurse","RegExp","replaceAll","regex","type","used","location","test"],"sources":["../../src/utils/Config.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { FullExportInterface } from '@rockcarver/frodo-lib/types/ops/ConfigOps';\nimport fs from 'fs';\nimport os from 'os';\nimport slugify from 'slugify';\n\nimport { printMessage } from './Console';\n\nconst { getFilePath, readFiles } = frodo.utils;\n\nconst { exportFullConfiguration } = frodo.config;\n\nconst { getDefaultNoiseFilter } = frodo.cloud.log;\n\nexport const FRODO_CONFIG_PATH_KEY = 'FRODO_CONFIG_PATH';\nexport const FRODO_LOG_NOISEFILTER_FILENAME = 'LoggingNoiseFilter.json';\n\nexport function getConfigPath(): string {\n return process.env[FRODO_CONFIG_PATH_KEY] || `${os.homedir()}/.frodo`;\n}\n\nfunction getCustomNoiseFilters(): Array<string> {\n const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;\n let noiseFilter = [];\n try {\n const data = fs.readFileSync(filename, 'utf8');\n noiseFilter = JSON.parse(data);\n } catch (e) {\n printMessage(`Error reading ${filename} (${e.message})`, 'error');\n }\n return noiseFilter;\n}\n\nexport function getNoiseFilters(defaults: boolean): Array<string> {\n const filename = `${getConfigPath()}/${FRODO_LOG_NOISEFILTER_FILENAME}`;\n if (defaults) {\n printMessage(`Using default logging noise filters.`, 'info');\n return getDefaultNoiseFilter();\n }\n let noiseFilter = getCustomNoiseFilters();\n if (noiseFilter.length == 0) {\n printMessage(`No custom noise filters defined. Using defaults.`, 'info');\n noiseFilter = getDefaultNoiseFilter();\n try {\n fs.writeFileSync(filename, JSON.stringify(noiseFilter, null, 2));\n printMessage(\n `The default filters were saved in ${filename}. You can change the filters as needed.`,\n 'info'\n );\n } catch (e) {\n printMessage(\n `Error creating noise filter configuration with default values.`,\n 'error'\n );\n }\n }\n return noiseFilter;\n}\n\n/**\n * Gets the full export config from one of three locations:\n * 1. The file passed into the function if one is provided.\n * 2. The working directory if it exists (provided by the user)\n * 3. The cloud tenant if the exports are not locally provided\n * @param file The optional file path\n * @returns The full export config\n */\nexport async function getFullExportConfig(\n file: string | null = null\n): Promise<FullExportInterface> {\n // Get export from file if it exists\n if (file) {\n return JSON.parse(fs.readFileSync(getFilePath(file), 'utf8'));\n }\n // If working directory doesn't exist, export from the cloud\n const workingDirectory = state.getDirectory();\n if (!workingDirectory) {\n return await exportFullConfiguration({\n useStringArrays: true,\n noDecode: false,\n });\n }\n // Go through files in directory and reconstruct the full export\n const fullExportConfig = {\n meta: {},\n agents: {},\n application: {},\n authentication: {},\n config: {},\n emailTemplate: {},\n idp: {},\n managedApplication: {},\n policy: {},\n policyset: {},\n resourcetype: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n script: {},\n secrets: {},\n service: {},\n theme: {},\n trees: {},\n variables: {},\n } as FullExportInterface;\n const files = await readFiles(workingDirectory);\n const jsonFiles = files.filter((f) => f.path.endsWith('.json'));\n const idmConfigFiles = jsonFiles.filter((f) => f.path.startsWith('config/'));\n const samlFiles = jsonFiles.filter(\n (f) => f.path.startsWith('saml/') || f.path.startsWith('cot/')\n );\n const otherFiles = jsonFiles.filter(\n (f) =>\n !f.path.startsWith('config/') &&\n !f.path.startsWith('saml/') &&\n !f.path.startsWith('cot/')\n );\n const scriptFiles = files.filter(\n (f) => f.path.endsWith('.js') || f.path.endsWith('.groovy')\n );\n // Handle json files\n for (const f of otherFiles) {\n for (const [id, value] of Object.entries(JSON.parse(f.content))) {\n if (value == null || fullExportConfig[id] == null) {\n continue;\n }\n Object.assign(fullExportConfig[id], value);\n }\n }\n // Handle saml files\n for (const f of samlFiles) {\n let content = JSON.parse(f.content);\n content = content.saml;\n for (const [id, value] of Object.entries(content)) {\n Object.assign(fullExportConfig.saml[id], value);\n }\n }\n // Handle idm config files\n for (const f of idmConfigFiles) {\n const content = JSON.parse(f.content);\n fullExportConfig.config[content._id] = content;\n }\n // Handle extracted scripts, adding them to their corresponding script objects in the export\n if (scriptFiles.length > 0 && fullExportConfig.script != null) {\n const scriptExports = Object.values(fullExportConfig.script);\n for (const f of scriptFiles) {\n const name = f.path.substring(\n f.path.lastIndexOf('/') + 1,\n f.path.indexOf('.', f.path.lastIndexOf('/'))\n );\n const scriptLines = f.content.split('\\n');\n const script = scriptExports.find(\n (s) =>\n slugify(s.name.replace(/^http(s?):\\/\\//, ''), {\n remove: /[^\\w\\s$*_+~.()'\"!\\-@]+/g,\n }) === name\n );\n if (!script) {\n throw Error(\n `Can't find the script corresponding to the file '${f.path}' in the export files`\n );\n }\n script.script = scriptLines;\n }\n }\n return fullExportConfig;\n}\n\n/**\n * Determines if a string id is being used anywhere within the given configuration object\n * @param configuration The configuration object\n * @param id The id being search for\n * @param isEsv Whether the id corresponds to an ESV or not\n */\nexport function isIdUsed(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n configuration: any,\n id: string,\n isEsv: boolean\n): {\n used: boolean;\n location: string;\n} {\n return isIdUsedRecurse(\n configuration,\n isEsv\n ? // For ESV ids, they contain either letters, numbers, dashes, or underscores. The dashes get replaced with periods (escaped with a \\ for the regex)\n // since anywhere they are being used they will be used with periods, not dashes. Note that the (?:[^a-z0-9._]|$) expressions at the beginning and\n // end are meant to ensure that the id found is not a substring of some other id (i.e. the id found must either be at the beginning or end of the\n // string, or if in the middle of a string, is not preceded or followed by a character that would be part of another id).\n new RegExp(\n `(?:[^a-z0-9._]|^)${id.replaceAll('-', '\\\\.')}(?:[^a-z0-9._]|$)`\n )\n : // For normal ids, they contain only letters, numbers, or dashes.\n new RegExp(`(?:[^a-z0-9-]|^)${id}(?:[^a-z0-9-]|$)`)\n );\n}\n\n/**\n * Recursive helper for isIdUsed that finds any strings contained in the configuration that pass the regex\n * @param configuration The configuration (could be anything)\n * @param regex The regex test\n */\nfunction isIdUsedRecurse(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n configuration: any,\n regex: RegExp\n): {\n used: boolean;\n location: string;\n} {\n const type = typeof configuration;\n if (type === 'object' && configuration !== null) {\n for (const [id, value] of Object.entries(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n configuration as Record<string, any>\n )) {\n const isIdUsed = isIdUsedRecurse(value, regex);\n if (isIdUsed.used) {\n isIdUsed.location =\n id +\n (value.name ? `(name: '${value.name}')` : '') +\n (isIdUsed.location === '' ? '' : '.') +\n isIdUsed.location;\n return isIdUsed;\n }\n }\n }\n return {\n used: type === 'string' && regex.test(configuration),\n location: '',\n };\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAEpD,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,OAAO,MAAM,SAAS;AAE7B,SAASC,YAAY,QAAQ,WAAW;AAExC,MAAM;EAAEC,WAAW;EAAEC;AAAU,CAAC,GAAGP,KAAK,CAACQ,KAAK;AAE9C,MAAM;EAAEC;AAAwB,CAAC,GAAGT,KAAK,CAACU,MAAM;AAEhD,MAAM;EAAEC;AAAsB,CAAC,GAAGX,KAAK,CAACY,KAAK,CAACC,GAAG;AAEjD,OAAO,MAAMC,qBAAqB,GAAG,mBAAmB;AACxD,OAAO,MAAMC,8BAA8B,GAAG,yBAAyB;AAEvE,OAAO,SAASC,aAAaA,CAAA,EAAW;EACtC,OAAOC,OAAO,CAACC,GAAG,CAACJ,qBAAqB,CAAC,IAAK,GAAEX,EAAE,CAACgB,OAAO,CAAC,CAAE,SAAQ;AACvE;AAEA,SAASC,qBAAqBA,CAAA,EAAkB;EAC9C,MAAMC,QAAQ,GAAI,GAAEL,aAAa,CAAC,CAAE,IAAGD,8BAA+B,EAAC;EACvE,IAAIO,WAAW,GAAG,EAAE;EACpB,IAAI;IACF,MAAMC,IAAI,GAAGrB,EAAE,CAACsB,YAAY,CAACH,QAAQ,EAAE,MAAM,CAAC;IAC9CC,WAAW,GAAGG,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;EAChC,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B,KAAc,EAId;EACA,OAAOC,eAAe,CACpBF,aAAa,EACbC,KAAK;EACD;EACA;EACA;EACA;EACA,IAAIE,MAAM,CACP,oBAAmBxB,EAAE,CAACyB,UAAU,CAAC,GAAG,EAAE,KAAK,CAAE,mBAChD,CAAC;EACD;EACA,IAAID,MAAM,CAAE,mBAAkBxB,EAAG,kBAAiB,CACxD,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASuB,eAAeA;AACtB;AACAF,aAAkB,EAClBK,KAAa,EAIb;EACA,MAAMC,IAAI,GAAG,OAAON,aAAa;EACjC,IAAIM,IAAI,KAAK,QAAQ,IAAIN,aAAa,KAAK,IAAI,EAAE;IAC/C,KAAK,MAAM,CAACrB,EAAE,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO;IACtC;IACAkB,aACF,CAAC,EAAE;MACD,MAAMD,QAAQ,GAAGG,eAAe,CAACtB,KAAK,EAAEyB,KAAK,CAAC;MAC9C,IAAIN,QAAQ,CAACQ,IAAI,EAAE;QACjBR,QAAQ,CAACS,QAAQ,GACf7B,EAAE,IACDC,KAAK,CAACQ,IAAI,GAAI,WAAUR,KAAK,CAACQ,IAAK,IAAG,GAAG,EAAE,CAAC,IAC5CW,QAAQ,CAACS,QAAQ,KAAK,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,GACrCT,QAAQ,CAACS,QAAQ;QACnB,OAAOT,QAAQ;MACjB;IACF;EACF;EACA,OAAO;IACLQ,IAAI,EAAED,IAAI,KAAK,QAAQ,IAAID,KAAK,CAACI,IAAI,CAACT,aAAa,CAAC;IACpDQ,QAAQ,EAAE;EACZ,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rockcarver/frodo-cli",
3
- "version": "2.0.0-37",
3
+ "version": "2.0.0-39",
4
4
  "type": "module",
5
5
  "description": "A command line interface to manage ForgeRock Identity Cloud tenants, ForgeOps deployments, and classic deployments.",
6
6
  "keywords": [
@@ -116,7 +116,7 @@
116
116
  ]
117
117
  },
118
118
  "dependencies": {
119
- "@rockcarver/frodo-lib": "2.0.0-54",
119
+ "@rockcarver/frodo-lib": "2.0.0-55",
120
120
  "chokidar": "^3.5.3",
121
121
  "cli-progress": "^3.11.2",
122
122
  "cli-table3": "^0.6.3",
@@ -1,48 +0,0 @@
1
- import { frodo } from '@rockcarver/frodo-lib';
2
- import fs from 'fs';
3
- import { lstat, readdir, readFile } from 'fs/promises';
4
- import { join } from 'path';
5
-
6
- /**
7
- * find all (nested) files in a directory
8
- *
9
- * @param baseDirectory directory to search
10
- * @param childDirectory subdirectory to search
11
- * @returns list of files
12
- */
13
- export async function readFiles(baseDirectory, childDirectory = '') {
14
- const targetDirectory = join(baseDirectory, childDirectory);
15
- const directoryItems = await readdir(targetDirectory);
16
- const childPaths = directoryItems.map(item => join(childDirectory, item));
17
- const filePathsNested = await Promise.all(childPaths.map(async childPath => {
18
- const path = join(baseDirectory, childPath);
19
- const isDirectory = (await lstat(path)).isDirectory();
20
- if (isDirectory) {
21
- return readFiles(baseDirectory, childPath);
22
- }
23
- return {
24
- path: childPath,
25
- content: await readFile(path, 'utf8')
26
- };
27
- }));
28
- return filePathsNested.flat();
29
- }
30
- const {
31
- getTypedFilename,
32
- saveJsonToFile,
33
- saveToFile,
34
- titleCase,
35
- getRealmString,
36
- isValidUrl
37
- } = frodo.utils;
38
- export { getRealmString, getTypedFilename, isValidUrl, saveJsonToFile, saveToFile, titleCase };
39
-
40
- /**
41
- * Save text data to file
42
- * @param data text data
43
- * @param filename file name
44
- */
45
- export function saveTextToFile(data, filename) {
46
- fs.writeFileSync(filename, data);
47
- }
48
- //# sourceMappingURL=ExportImportUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExportImportUtils.js","names":["frodo","fs","lstat","readdir","readFile","join","readFiles","baseDirectory","childDirectory","targetDirectory","directoryItems","childPaths","map","item","filePathsNested","Promise","all","childPath","path","isDirectory","content","flat","getTypedFilename","saveJsonToFile","saveToFile","titleCase","getRealmString","isValidUrl","utils","saveTextToFile","data","filename","writeFileSync"],"sources":["../../src/utils/ExportImportUtils.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport { lstat, readdir, readFile } from 'fs/promises';\nimport { join } from 'path';\n\n/**\n * find all (nested) files in a directory\n *\n * @param baseDirectory directory to search\n * @param childDirectory subdirectory to search\n * @returns list of files\n */\nexport async function readFiles(\n baseDirectory: string,\n childDirectory = ''\n): Promise<\n {\n path: string;\n content: string;\n }[]\n> {\n const targetDirectory = join(baseDirectory, childDirectory);\n const directoryItems = await readdir(targetDirectory);\n const childPaths = directoryItems.map((item) => join(childDirectory, item));\n\n const filePathsNested = await Promise.all(\n childPaths.map(async (childPath) => {\n const path = join(baseDirectory, childPath);\n const isDirectory = (await lstat(path)).isDirectory();\n\n if (isDirectory) {\n return readFiles(baseDirectory, childPath);\n }\n\n return {\n path: childPath,\n content: await readFile(path, 'utf8'),\n };\n })\n );\n\n return filePathsNested.flat();\n}\n\nconst {\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n titleCase,\n getRealmString,\n isValidUrl,\n} = frodo.utils;\n\nexport {\n getRealmString,\n getTypedFilename,\n isValidUrl,\n saveJsonToFile,\n saveToFile,\n titleCase,\n};\n\n/**\n * Save text data to file\n * @param data text data\n * @param filename file name\n */\nexport function saveTextToFile(data: string, filename: string): void {\n fs.writeFileSync(filename, data);\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,aAAa;AACtD,SAASC,IAAI,QAAQ,MAAM;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,SAASA,CAC7BC,aAAqB,EACrBC,cAAc,GAAG,EAAE,EAMnB;EACA,MAAMC,eAAe,GAAGJ,IAAI,CAACE,aAAa,EAAEC,c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