@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.
- package/CHANGELOG.md +9 -1
- package/esm/cli/_template/something-else-export.js +1 -1
- package/esm/cli/_template/something-else-export.js.map +1 -1
- package/esm/cli/_template/something-export.js +1 -1
- package/esm/cli/_template/something-export.js.map +1 -1
- package/esm/cli/_template/something-other-export.js +1 -1
- package/esm/cli/_template/something-other-export.js.map +1 -1
- package/esm/cli/admin/admin-federation-export.js +4 -4
- package/esm/cli/admin/admin-federation-export.js.map +1 -1
- package/esm/cli/agent/agent-export.js +4 -4
- package/esm/cli/agent/agent-export.js.map +1 -1
- package/esm/cli/agent/agent-gateway-export.js +4 -4
- package/esm/cli/agent/agent-gateway-export.js.map +1 -1
- package/esm/cli/agent/agent-java-export.js +4 -4
- package/esm/cli/agent/agent-java-export.js.map +1 -1
- package/esm/cli/agent/agent-web-export.js +4 -4
- package/esm/cli/agent/agent-web-export.js.map +1 -1
- package/esm/cli/app/app-export.js +4 -4
- package/esm/cli/app/app-export.js.map +1 -1
- package/esm/cli/authn/authn-export.js +2 -2
- package/esm/cli/authn/authn-export.js.map +1 -1
- package/esm/cli/authz/authz-policy-export.js +6 -6
- package/esm/cli/authz/authz-policy-export.js.map +1 -1
- package/esm/cli/authz/authz-set-export.js +4 -4
- package/esm/cli/authz/authz-set-export.js.map +1 -1
- package/esm/cli/authz/authz-type-export.js +5 -5
- package/esm/cli/authz/authz-type-export.js.map +1 -1
- package/esm/cli/config/config-export.js +3 -3
- package/esm/cli/config/config-export.js.map +1 -1
- package/esm/cli/email/email-template-export.js +4 -4
- package/esm/cli/email/email-template-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-export.js +4 -4
- package/esm/cli/esv/esv-secret-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-list.js +2 -2
- package/esm/cli/esv/esv-secret-list.js.map +1 -1
- package/esm/cli/esv/esv-variable-export.js +4 -4
- package/esm/cli/esv/esv-variable-export.js.map +1 -1
- package/esm/cli/esv/esv-variable-list.js +2 -2
- package/esm/cli/esv/esv-variable-list.js.map +1 -1
- package/esm/cli/idp/idp-export.js +4 -4
- package/esm/cli/idp/idp-export.js.map +1 -1
- package/esm/cli/journey/journey-describe.js +3 -1
- package/esm/cli/journey/journey-describe.js.map +1 -1
- package/esm/cli/journey/journey-export.js +4 -4
- package/esm/cli/journey/journey-export.js.map +1 -1
- package/esm/cli/oauth/oauth-client-export.js +4 -4
- package/esm/cli/oauth/oauth-client-export.js.map +1 -1
- package/esm/cli/saml/saml-cot-export.js +4 -4
- package/esm/cli/saml/saml-cot-export.js.map +1 -1
- package/esm/cli/saml/saml-export.js +4 -4
- package/esm/cli/saml/saml-export.js.map +1 -1
- package/esm/cli/script/script-export.js +4 -4
- package/esm/cli/script/script-export.js.map +1 -1
- package/esm/cli/script/script-list.js +2 -2
- package/esm/cli/script/script-list.js.map +1 -1
- package/esm/cli/service/service-export.js +4 -4
- package/esm/cli/service/service-export.js.map +1 -1
- package/esm/cli/theme/theme-export.js +5 -5
- package/esm/cli/theme/theme-export.js.map +1 -1
- package/esm/ops/AdminFederationOps.js +11 -7
- package/esm/ops/AdminFederationOps.js.map +1 -1
- package/esm/ops/AgentOps.js +39 -25
- package/esm/ops/AgentOps.js.map +1 -1
- package/esm/ops/ApplicationOps.js +11 -8
- package/esm/ops/ApplicationOps.js.map +1 -1
- package/esm/ops/AuthenticationSettingsOps.js +4 -3
- package/esm/ops/AuthenticationSettingsOps.js.map +1 -1
- package/esm/ops/CirclesOfTrustOps.js +12 -7
- package/esm/ops/CirclesOfTrustOps.js.map +1 -1
- package/esm/ops/ConfigOps.js +9 -7
- package/esm/ops/ConfigOps.js.map +1 -1
- package/esm/ops/EmailTemplateOps.js +11 -7
- package/esm/ops/EmailTemplateOps.js.map +1 -1
- package/esm/ops/IdmOps.js +3 -2
- package/esm/ops/IdmOps.js.map +1 -1
- package/esm/ops/IdpOps.js +14 -7
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/JourneyOps.js +15 -6
- package/esm/ops/JourneyOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +10 -7
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/PolicyOps.js +18 -11
- package/esm/ops/PolicyOps.js.map +1 -1
- package/esm/ops/PolicySetOps.js +12 -7
- package/esm/ops/PolicySetOps.js.map +1 -1
- package/esm/ops/ResourceTypeOps.js +15 -9
- package/esm/ops/ResourceTypeOps.js.map +1 -1
- package/esm/ops/Saml2Ops.js +10 -7
- package/esm/ops/Saml2Ops.js.map +1 -1
- package/esm/ops/ScriptOps.js +73 -36
- package/esm/ops/ScriptOps.js.map +1 -1
- package/esm/ops/SecretsOps.js +76 -48
- package/esm/ops/SecretsOps.js.map +1 -1
- package/esm/ops/ServiceOps.js +10 -9
- package/esm/ops/ServiceOps.js.map +1 -1
- package/esm/ops/ThemeOps.js +15 -9
- package/esm/ops/ThemeOps.js.map +1 -1
- package/esm/ops/VariablesOps.js +49 -23
- package/esm/ops/VariablesOps.js.map +1 -1
- package/esm/utils/Config.js +147 -1
- package/esm/utils/Config.js.map +1 -1
- package/package.json +2 -2
- package/esm/utils/ExportImportUtils.js +0 -48
- package/esm/utils/ExportImportUtils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceTypeOps.js","names":["frodo","state","fs","createObjectTable","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getTypedFilename","saveJsonToFile","titleCase","getRealmName","getFilePath","getWorkingDirectory","utils","readResourceTypes","readResourceType","readResourceTypeByName","exportResourceType","exportResourceTypeByName","exportResourceTypes","importResourceType","importResourceTypeByName","importFirstResourceType","importResourceTypes","deleteResourceType","deleteResourceTypeByName","authz","resourceType","listResourceTypes","long","outcome","resourceTypes","sort","a","b","name","localeCompare","table","push","description","uuid","toString","err","message","describeResourceType","resourceTypeUuid","json","error","_error$response","response","status","getRealm","_error$response2","data","describeResourceTypeByName","resourceTypeName","_error$response3","_error$response4","deleteResourceTypeById","_error$response5","deleteResourceTypeUsingName","_error$response6","deleteResourceTypes","errors","indicatorId","length","resourceTypeId","errorMessages","map","join","exportResourceTypeToFile","file","fileName","filePath","exportData","exportResourceTypeByNameToFile","exportResourceTypesToFile","exportResourceTypesToFiles","importResourceTypeFromFile","readFileSync","fileData","JSON","parse","importResourceTypeByNameFromFile","importFirstResourceTypeFromFile","importResourceTypesFromFile","importResourceTypesFromFiles","names","readdirSync","files","filter","toLowerCase","endsWith","total","count","Object","keys","resourcetype"],"sources":["../../src/ops/ResourceTypeOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type ResourceTypeSkeleton } from '@rockcarver/frodo-lib/types/api/ResourceTypesApi';\nimport { type ResourceTypeExportInterface } from '@rockcarver/frodo-lib/types/ops/ResourceTypeOps';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n} from '../utils/ExportImportUtils';\n\nconst { getRealmName, getFilePath, getWorkingDirectory } = frodo.utils;\nconst {\n readResourceTypes,\n readResourceType,\n readResourceTypeByName,\n exportResourceType,\n exportResourceTypeByName,\n exportResourceTypes,\n importResourceType,\n importResourceTypeByName,\n importFirstResourceType,\n importResourceTypes,\n deleteResourceType,\n deleteResourceTypeByName,\n} = frodo.authz.resourceType;\n\n/**\n * List resource types\n * @param {boolean} long more fields\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listResourceTypes(long = false): Promise<boolean> {\n let outcome = false;\n try {\n const resourceTypes = await readResourceTypes();\n resourceTypes.sort((a, b) => a.name.localeCompare(b.name));\n if (long) {\n const table = createTable(['Name', 'Description', 'Uuid']);\n for (const resourceType of resourceTypes) {\n table.push([\n `${resourceType.name}`,\n `${resourceType.description}`,\n `${resourceType.uuid}`,\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const resourceType of resourceTypes) {\n printMessage(`${resourceType.name}`, 'data');\n }\n }\n outcome = true;\n } catch (err) {\n printMessage(`listResourceTypes ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Describe resource type by uuid\n * @param {string} resourceTypeUuid resource type uuid\n * @param {boolean} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describeResourceType(\n resourceTypeUuid: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n try {\n const resourceType = await readResourceType(resourceTypeUuid);\n if (json) {\n printMessage(resourceType, 'data');\n } else {\n const table = createObjectTable(resourceType);\n printMessage(table.toString(), 'data');\n }\n outcome = true;\n } catch (error) {\n if (error.response?.status === 404) {\n printMessage(\n `Resource Type with uuid ${resourceTypeUuid} does not exist in realm ${state.getRealm()}`,\n 'error'\n );\n } else {\n printMessage(error.response?.data?.message || error.message, 'error');\n }\n }\n return outcome;\n}\n\n/**\n * Describe resource type by name\n * @param {string} resourceTypeName resource type name\n * @param {boolean} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describeResourceTypeByName(\n resourceTypeName: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n try {\n const resourceType = await readResourceTypeByName(resourceTypeName);\n if (json) {\n printMessage(resourceType, 'data');\n } else {\n const table = createObjectTable(resourceType);\n printMessage(table.toString(), 'data');\n }\n outcome = true;\n } catch (error) {\n if (error.response?.status === 404) {\n printMessage(\n `Resource Type with name ${resourceTypeName} does not exist in realm ${state.getRealm()}`,\n 'error'\n );\n } else {\n printMessage(error.response?.data?.message || error.message, 'error');\n }\n }\n return outcome;\n}\n\n/**\n * Delete resource type by uuid\n * @param {string} resourceTypeUuid resource type uuid\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteResourceTypeById(\n resourceTypeUuid: string\n): Promise<boolean | ResourceTypeSkeleton> {\n debugMessage(`cli.ResourceTypeOps.deleteResourceType: begin`);\n showSpinner(`Deleting ${resourceTypeUuid}...`);\n let outcome = false;\n try {\n debugMessage(`Deleting resource type ${resourceTypeUuid}`);\n await deleteResourceType(resourceTypeUuid);\n succeedSpinner(`Deleted ${resourceTypeUuid}.`);\n outcome = true;\n } catch (error) {\n failSpinner(\n `Error deleting ${resourceTypeUuid}: ${\n error.response?.data?.message || error.message\n }`\n );\n }\n debugMessage(\n `cli.ResourceTypeOps.deleteResourceType: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Delete resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteResourceTypeUsingName(\n resourceTypeName: string\n): Promise<boolean | ResourceTypeSkeleton> {\n debugMessage(`cli.ResourceTypeOps.deleteResourceTypeByName: begin`);\n showSpinner(`Deleting ${resourceTypeName}...`);\n let outcome = false;\n try {\n debugMessage(`Deleting resource type ${resourceTypeName}`);\n await deleteResourceTypeByName(resourceTypeName);\n succeedSpinner(`Deleted ${resourceTypeName}.`);\n outcome = true;\n } catch (error) {\n failSpinner(\n `Error deleting ${resourceTypeName}: ${\n error.response?.data?.message || error.message\n }`\n );\n }\n debugMessage(\n `cli.ResourceTypeOps.deleteResourceTypeByName: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Delete all resource types\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteResourceTypes(): Promise<\n boolean | ResourceTypeSkeleton\n> {\n debugMessage(`cli.ResourceTypeOps.deleteResourceTypes: begin`);\n let outcome = false;\n const errors = [];\n let resourceTypes: ResourceTypeSkeleton[] = [];\n let indicatorId: string;\n try {\n showSpinner(`Retrieving all resource types...`);\n try {\n resourceTypes = await readResourceTypes();\n succeedSpinner(`Found ${resourceTypes.length} resource types.`);\n } catch (error) {\n error.message = `Error retrieving all resource types: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (resourceTypes.length)\n indicatorId = createProgressIndicator(\n 'determinate',\n resourceTypes.length,\n `Deleting ${resourceTypes.length} resource types...`\n );\n for (const resourceType of resourceTypes) {\n const resourceTypeId = resourceType.uuid;\n try {\n debugMessage(`Deleting resource type ${resourceTypeId}`);\n await deleteResourceType(resourceTypeId);\n updateProgressIndicator(indicatorId, `Deleted ${resourceTypeId}`);\n } catch (error) {\n error.message = `Error deleting resource type ${resourceTypeId}: ${error}`;\n updateProgressIndicator(indicatorId, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting resource types: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (resourceTypes.length)\n stopProgressIndicator(\n indicatorId,\n `Error deleting all resource types: ${errorMessages}`\n );\n } else {\n if (resourceTypes.length)\n stopProgressIndicator(\n indicatorId,\n `Deleted ${resourceTypes.length} resource types.`\n );\n outcome = true;\n }\n }\n debugMessage(\n `cli.ResourceTypeOps.deleteResourceTypes: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Export resource type to file\n * @param {string} resourceTypeUuid resource type uuid\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportResourceTypeToFile(\n resourceTypeUuid: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeToFile: begin`);\n showSpinner(`Exporting ${resourceTypeUuid}...`);\n try {\n let fileName = getTypedFilename(resourceTypeUuid, 'resourcetype.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportResourceType(resourceTypeUuid);\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported ${resourceTypeUuid} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${resourceTypeUuid}: ${error.message}`);\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeToFile: end`);\n return outcome;\n}\n\n/**\n * Export resource type by name to file\n * @param {string} resourceTypeName resource type name\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportResourceTypeByNameToFile(\n resourceTypeName: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeByNameToFile: begin`);\n showSpinner(`Exporting ${resourceTypeName}...`);\n try {\n let fileName = getTypedFilename(resourceTypeName, 'resourcetype.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportResourceTypeByName(resourceTypeName);\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported ${resourceTypeName} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${resourceTypeName}: ${error.message}`);\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeByNameToFile: end`);\n return outcome;\n}\n\n/**\n * Export resource types to file\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportResourceTypesToFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFile: begin`);\n showSpinner(`Exporting all resource types...`);\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}ResourceTypes`,\n 'resourcetype.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportResourceTypes();\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported all resource types to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting resource types: ${error.message}`);\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFile: end`);\n return outcome;\n}\n\n/**\n * Export all resource types to separate files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportResourceTypesToFiles(): Promise<boolean> {\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const resourceTypes: ResourceTypeSkeleton[] = await readResourceTypes();\n indicatorId = createProgressIndicator(\n 'determinate',\n resourceTypes.length,\n 'Exporting resource types...'\n );\n for (const resourceType of resourceTypes) {\n const file = getTypedFilename(resourceType.name, 'resourcetype.authz');\n try {\n const exportData: ResourceTypeExportInterface =\n await exportResourceType(resourceType.uuid);\n saveJsonToFile(exportData, getFilePath(file, true));\n updateProgressIndicator(indicatorId, `Exported ${resourceType.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error exporting ${resourceType.name}.`\n );\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(\n indicatorId,\n `Error exporting resource types to files`\n );\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import resource type from file\n * @param {string} resourceTypeId resource type id\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypeFromFile(\n resourceTypeId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importResourceTypeFromFile: begin`);\n showSpinner(`Importing ${resourceTypeId}...`);\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importResourceType(resourceTypeId, fileData);\n outcome = true;\n succeedSpinner(`Imported ${resourceTypeId}.`);\n } catch (error) {\n failSpinner(`Error importing ${resourceTypeId}: ${error.message}`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypeFromFile: end`);\n return outcome;\n}\n\n/**\n * Import resource type by name from file\n * @param {string} resourceTypeName resource type name\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypeByNameFromFile(\n resourceTypeName: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importResourceTypeByNameFromFile: begin`);\n showSpinner(`Importing ${resourceTypeName}...`);\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importResourceTypeByName(resourceTypeName, fileData);\n outcome = true;\n succeedSpinner(`Imported ${resourceTypeName}.`);\n } catch (error) {\n failSpinner(`Error importing ${resourceTypeName}: ${error.message}`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypeByNameFromFile: end`);\n return outcome;\n}\n\n/**\n * Import first resource type from file\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstResourceTypeFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importFirstResourceTypeFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importFirstResourceType(fileData);\n outcome = true;\n succeedSpinner(`Imported ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing ${filePath}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importFirstResourceTypeFromFile: end`);\n return outcome;\n}\n\n/**\n * Import resource types from file\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypesFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importResourceTypes(fileData);\n outcome = true;\n succeedSpinner(`Imported ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing ${filePath}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFile: end`);\n return outcome;\n}\n\n/**\n * Import resource types from files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypesFromFiles(): Promise<boolean> {\n const errors = [];\n let indicatorId: string;\n try {\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.resourcetype.authz.json'))\n .map((name) => getFilePath(name));\n indicatorId = createProgressIndicator(\n 'determinate',\n files.length,\n 'Importing resource types...'\n );\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: ResourceTypeExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.resourcetype).length;\n total += count;\n await importResourceTypes(fileData);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} resource types from ${file}`\n );\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error importing resource types from ${file}`\n );\n printMessage(error, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} resource types from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(\n indicatorId,\n `Error importing resource types from files.`\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAGpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,cAAc,EACdC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,gBAAgB,EAChBC,cAAc,EACdC,SAAS,QACJ,4BAA4B;AAEnC,MAAM;EAAEC,YAAY;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGlB,KAAK,CAACmB,KAAK;AACtE,MAAM;EACJC,iBAAiB;EACjBC,gBAAgB;EA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AC;IACnC6B,WAAW,GAAGlE,uBAAuB,CACnC,aAAa,EACb2F,KAAK,CAACxB,MAAM,EACZ,6BACF,CAAC;IACD,IAAI4B,KAAK,GAAG,CAAC;IACb,KAAK,MAAMtB,IAAI,IAAIkB,KAAK,EAAE;MACxB,IAAI;QACF,MAAMpC,IAAI,GAAGzD,EAAE,CAACmF,YAAY,CAACR,IAAI,EAAE,MAAM,CAAC;QAC1C,MAAMS,QAAqC,GAAGC,IAAI,CAACC,KAAK,CAAC7B,IAAI,CAAC;QAC9D,MAAMyC,KAAK,GAAGC,MAAM,CAACC,IAAI,CAAChB,QAAQ,CAACiB,YAAY,CAAC,CAAChC,MAAM;QACvD4B,KAAK,IAAIC,KAAK;QACd,MAAMvE,mBAAmB,CAACyD,QAAQ,CAAC;QACnC1E,uBAAuB,CACrB0D,WAAW,EACV,YAAW8B,KAAM,wBAAuBvB,IAAK,EAChD,CAAC;MACH,CAAC,CAAC,OAAOxB,KAAK,EAAE;QACdgB,MAAM,CAACzB,IAAI,CAACS,KAAK,CAAC;QAClBzC,uBAAuB,CACrB0D,WAAW,EACV,uCAAsCO,IAAK,EAC9C,CAAC;QACDrE,YAAY,CAAC6C,KAAK,EAAE,OAAO,CAAC;MAC9B;IACF;IACA3C,qBAAqB,CACnB4D,WAAW,EACV,sBAAqB6B,KAAM,wBAAuBJ,KAAK,CAACxB,MAAO,SAClE,CAAC;EACH,CAAC,CAAC,OAAOlB,KAAK,EAAE;IACdgB,MAAM,CAACzB,IAAI,CAACS,KAAK,CAAC;IAClB3C,qBAAqB,CACnB4D,WAAW,EACV,4CACH,CAAC;IACD9D,YAAY,CAAC6C,KAAK,EAAE,OAAO,CAAC;EAC9B;EACA/C,YAAY,CAAE,uDAAsD,CAAC;EACrE,OAAO,CAAC,KAAK+D,MAAM,CAACE,MAAM;AAC5B"}
|
|
1
|
+
{"version":3,"file":"ResourceTypeOps.js","names":["frodo","state","fs","createObjectTable","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getRealmName","getTypedFilename","saveJsonToFile","titleCase","getFilePath","getWorkingDirectory","utils","readResourceTypes","readResourceType","readResourceTypeByName","exportResourceType","exportResourceTypeByName","exportResourceTypes","importResourceType","importResourceTypeByName","importFirstResourceType","importResourceTypes","deleteResourceType","deleteResourceTypeByName","authz","resourceType","listResourceTypes","long","outcome","resourceTypes","sort","a","b","name","localeCompare","table","push","description","uuid","toString","err","message","describeResourceType","resourceTypeUuid","json","error","_error$response","response","status","getRealm","_error$response2","data","describeResourceTypeByName","resourceTypeName","_error$response3","_error$response4","deleteResourceTypeById","_error$response5","deleteResourceTypeUsingName","_error$response6","deleteResourceTypes","errors","indicatorId","length","resourceTypeId","errorMessages","map","join","exportResourceTypeToFile","file","includeMeta","fileName","filePath","exportData","exportResourceTypeByNameToFile","exportResourceTypesToFile","exportResourceTypesToFiles","importResourceTypeFromFile","readFileSync","fileData","JSON","parse","importResourceTypeByNameFromFile","importFirstResourceTypeFromFile","importResourceTypesFromFile","importResourceTypesFromFiles","names","readdirSync","files","filter","toLowerCase","endsWith","total","count","Object","keys","resourcetype"],"sources":["../../src/ops/ResourceTypeOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type ResourceTypeSkeleton } from '@rockcarver/frodo-lib/types/api/ResourceTypesApi';\nimport { type ResourceTypeExportInterface } from '@rockcarver/frodo-lib/types/ops/ResourceTypeOps';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n getRealmName,\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\nconst {\n readResourceTypes,\n readResourceType,\n readResourceTypeByName,\n exportResourceType,\n exportResourceTypeByName,\n exportResourceTypes,\n importResourceType,\n importResourceTypeByName,\n importFirstResourceType,\n importResourceTypes,\n deleteResourceType,\n deleteResourceTypeByName,\n} = frodo.authz.resourceType;\n\n/**\n * List resource types\n * @param {boolean} long more fields\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listResourceTypes(long = false): Promise<boolean> {\n let outcome = false;\n try {\n const resourceTypes = await readResourceTypes();\n resourceTypes.sort((a, b) => a.name.localeCompare(b.name));\n if (long) {\n const table = createTable(['Name', 'Description', 'Uuid']);\n for (const resourceType of resourceTypes) {\n table.push([\n `${resourceType.name}`,\n `${resourceType.description}`,\n `${resourceType.uuid}`,\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const resourceType of resourceTypes) {\n printMessage(`${resourceType.name}`, 'data');\n }\n }\n outcome = true;\n } catch (err) {\n printMessage(`listResourceTypes ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Describe resource type by uuid\n * @param {string} resourceTypeUuid resource type uuid\n * @param {boolean} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describeResourceType(\n resourceTypeUuid: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n try {\n const resourceType = await readResourceType(resourceTypeUuid);\n if (json) {\n printMessage(resourceType, 'data');\n } else {\n const table = createObjectTable(resourceType);\n printMessage(table.toString(), 'data');\n }\n outcome = true;\n } catch (error) {\n if (error.response?.status === 404) {\n printMessage(\n `Resource Type with uuid ${resourceTypeUuid} does not exist in realm ${state.getRealm()}`,\n 'error'\n );\n } else {\n printMessage(error.response?.data?.message || error.message, 'error');\n }\n }\n return outcome;\n}\n\n/**\n * Describe resource type by name\n * @param {string} resourceTypeName resource type name\n * @param {boolean} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describeResourceTypeByName(\n resourceTypeName: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n try {\n const resourceType = await readResourceTypeByName(resourceTypeName);\n if (json) {\n printMessage(resourceType, 'data');\n } else {\n const table = createObjectTable(resourceType);\n printMessage(table.toString(), 'data');\n }\n outcome = true;\n } catch (error) {\n if (error.response?.status === 404) {\n printMessage(\n `Resource Type with name ${resourceTypeName} does not exist in realm ${state.getRealm()}`,\n 'error'\n );\n } else {\n printMessage(error.response?.data?.message || error.message, 'error');\n }\n }\n return outcome;\n}\n\n/**\n * Delete resource type by uuid\n * @param {string} resourceTypeUuid resource type uuid\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteResourceTypeById(\n resourceTypeUuid: string\n): Promise<boolean | ResourceTypeSkeleton> {\n debugMessage(`cli.ResourceTypeOps.deleteResourceType: begin`);\n showSpinner(`Deleting ${resourceTypeUuid}...`);\n let outcome = false;\n try {\n debugMessage(`Deleting resource type ${resourceTypeUuid}`);\n await deleteResourceType(resourceTypeUuid);\n succeedSpinner(`Deleted ${resourceTypeUuid}.`);\n outcome = true;\n } catch (error) {\n failSpinner(\n `Error deleting ${resourceTypeUuid}: ${\n error.response?.data?.message || error.message\n }`\n );\n }\n debugMessage(\n `cli.ResourceTypeOps.deleteResourceType: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Delete resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteResourceTypeUsingName(\n resourceTypeName: string\n): Promise<boolean | ResourceTypeSkeleton> {\n debugMessage(`cli.ResourceTypeOps.deleteResourceTypeByName: begin`);\n showSpinner(`Deleting ${resourceTypeName}...`);\n let outcome = false;\n try {\n debugMessage(`Deleting resource type ${resourceTypeName}`);\n await deleteResourceTypeByName(resourceTypeName);\n succeedSpinner(`Deleted ${resourceTypeName}.`);\n outcome = true;\n } catch (error) {\n failSpinner(\n `Error deleting ${resourceTypeName}: ${\n error.response?.data?.message || error.message\n }`\n );\n }\n debugMessage(\n `cli.ResourceTypeOps.deleteResourceTypeByName: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Delete all resource types\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deleteResourceTypes(): Promise<\n boolean | ResourceTypeSkeleton\n> {\n debugMessage(`cli.ResourceTypeOps.deleteResourceTypes: begin`);\n let outcome = false;\n const errors = [];\n let resourceTypes: ResourceTypeSkeleton[] = [];\n let indicatorId: string;\n try {\n showSpinner(`Retrieving all resource types...`);\n try {\n resourceTypes = await readResourceTypes();\n succeedSpinner(`Found ${resourceTypes.length} resource types.`);\n } catch (error) {\n error.message = `Error retrieving all resource types: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (resourceTypes.length)\n indicatorId = createProgressIndicator(\n 'determinate',\n resourceTypes.length,\n `Deleting ${resourceTypes.length} resource types...`\n );\n for (const resourceType of resourceTypes) {\n const resourceTypeId = resourceType.uuid;\n try {\n debugMessage(`Deleting resource type ${resourceTypeId}`);\n await deleteResourceType(resourceTypeId);\n updateProgressIndicator(indicatorId, `Deleted ${resourceTypeId}`);\n } catch (error) {\n error.message = `Error deleting resource type ${resourceTypeId}: ${error}`;\n updateProgressIndicator(indicatorId, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting resource types: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (resourceTypes.length)\n stopProgressIndicator(\n indicatorId,\n `Error deleting all resource types: ${errorMessages}`\n );\n } else {\n if (resourceTypes.length)\n stopProgressIndicator(\n indicatorId,\n `Deleted ${resourceTypes.length} resource types.`\n );\n outcome = true;\n }\n }\n debugMessage(\n `cli.ResourceTypeOps.deleteResourceTypes: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Export resource type to file\n * @param {string} resourceTypeUuid resource type uuid\n * @param {string} file file name\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 exportResourceTypeToFile(\n resourceTypeUuid: string,\n file: string,\n includeMeta = true\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeToFile: begin`);\n showSpinner(`Exporting ${resourceTypeUuid}...`);\n try {\n let fileName = getTypedFilename(resourceTypeUuid, 'resourcetype.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportResourceType(resourceTypeUuid);\n saveJsonToFile(exportData, filePath, includeMeta);\n succeedSpinner(`Exported ${resourceTypeUuid} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${resourceTypeUuid}: ${error.message}`);\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeToFile: end`);\n return outcome;\n}\n\n/**\n * Export resource type by name to file\n * @param {string} resourceTypeName resource type name\n * @param {string} file file name\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 exportResourceTypeByNameToFile(\n resourceTypeName: string,\n file: string,\n includeMeta = true\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeByNameToFile: begin`);\n showSpinner(`Exporting ${resourceTypeName}...`);\n try {\n let fileName = getTypedFilename(resourceTypeName, 'resourcetype.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportResourceTypeByName(resourceTypeName);\n saveJsonToFile(exportData, filePath, includeMeta);\n succeedSpinner(`Exported ${resourceTypeName} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${resourceTypeName}: ${error.message}`);\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypeByNameToFile: end`);\n return outcome;\n}\n\n/**\n * Export resource types to file\n * @param {string} file file name\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 exportResourceTypesToFile(\n file: string,\n includeMeta = true\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFile: begin`);\n showSpinner(`Exporting all resource types...`);\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}ResourceTypes`,\n 'resourcetype.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportResourceTypes();\n saveJsonToFile(exportData, filePath, includeMeta);\n succeedSpinner(`Exported all resource types to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting resource types: ${error.message}`);\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFile: end`);\n return outcome;\n}\n\n/**\n * Export all resource types to separate files\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 exportResourceTypesToFiles(\n includeMeta = true\n): Promise<boolean> {\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const resourceTypes: ResourceTypeSkeleton[] = await readResourceTypes();\n indicatorId = createProgressIndicator(\n 'determinate',\n resourceTypes.length,\n 'Exporting resource types...'\n );\n for (const resourceType of resourceTypes) {\n const file = getTypedFilename(resourceType.name, 'resourcetype.authz');\n try {\n const exportData: ResourceTypeExportInterface =\n await exportResourceType(resourceType.uuid);\n saveJsonToFile(exportData, getFilePath(file, true), includeMeta);\n updateProgressIndicator(indicatorId, `Exported ${resourceType.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error exporting ${resourceType.name}.`\n );\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(\n indicatorId,\n `Error exporting resource types to files`\n );\n }\n debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import resource type from file\n * @param {string} resourceTypeId resource type id\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypeFromFile(\n resourceTypeId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importResourceTypeFromFile: begin`);\n showSpinner(`Importing ${resourceTypeId}...`);\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importResourceType(resourceTypeId, fileData);\n outcome = true;\n succeedSpinner(`Imported ${resourceTypeId}.`);\n } catch (error) {\n failSpinner(`Error importing ${resourceTypeId}: ${error.message}`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypeFromFile: end`);\n return outcome;\n}\n\n/**\n * Import resource type by name from file\n * @param {string} resourceTypeName resource type name\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypeByNameFromFile(\n resourceTypeName: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importResourceTypeByNameFromFile: begin`);\n showSpinner(`Importing ${resourceTypeName}...`);\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importResourceTypeByName(resourceTypeName, fileData);\n outcome = true;\n succeedSpinner(`Imported ${resourceTypeName}.`);\n } catch (error) {\n failSpinner(`Error importing ${resourceTypeName}: ${error.message}`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypeByNameFromFile: end`);\n return outcome;\n}\n\n/**\n * Import first resource type from file\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstResourceTypeFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importFirstResourceTypeFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importFirstResourceType(fileData);\n outcome = true;\n succeedSpinner(`Imported ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing ${filePath}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importFirstResourceTypeFromFile: end`);\n return outcome;\n}\n\n/**\n * Import resource types from file\n * @param {string} file file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypesFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importResourceTypes(fileData);\n outcome = true;\n succeedSpinner(`Imported ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing ${filePath}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFile: end`);\n return outcome;\n}\n\n/**\n * Import resource types from files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importResourceTypesFromFiles(): Promise<boolean> {\n const errors = [];\n let indicatorId: string;\n try {\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.resourcetype.authz.json'))\n .map((name) => getFilePath(name));\n indicatorId = createProgressIndicator(\n 'determinate',\n files.length,\n 'Importing resource types...'\n );\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: ResourceTypeExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.resourcetype).length;\n total += count;\n await importResourceTypes(fileData);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} resource types from ${file}`\n );\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error importing resource types from ${file}`\n );\n printMessage(error, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} resource types from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(\n indicatorId,\n `Error importing resource types from files.`\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAGpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,cAAc,EACdC,uBAAuB,QAClB,kBAAkB;AAEzB,MAAM;EACJC,YAAY;EACZC,gBAAgB;EAChBC,cAAc;EACdC,SAAS;EACTC,WAAW;EACXC;AACF,CAAC,GAAGlB,KAAK,CAACmB,KAAK;AACf,MAAM;EACJC,iBAAiB;EACjBC,gBAAgB;EAChBC,sBAAsB;EACtBC,kBAAkB;EAClBC,wBAAwB;EACxBC,mBAAmB;EACnBC,kBAAkB;EAClBC,wBAAwB;EACxBC,uBAAuB;EACvBC,mBAAmB;EACnBC,kBAAkB;EAClBC;AACF,CAAC,GAAG/B,KAAK,CAACgC,KAAK,CAACC,YAAY;;AAE5B;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,iBAAiBA,CAACC,IAAI,GAAG,KAAK,EAAoB;EACtE,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAI;IACF,MAAMC,aAAa,GAAG,MAAMjB,iBAAiB,CAAC,CAAC;IAC/CiB,aAAa,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,IAAI,CAACC,aAAa,CAACF,CAAC,CAACC,IAAI,CAAC,CAAC;IAC1D,IAAIN,IAAI,EAAE;MACR,MAAMQ,KAAK,GAAGtC,WAAW,CAAC,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;MAC1D,KAAK,MAAM4B,YAAY,IAAII,aAAa,EAAE;QACxCM,KAAK,CAACC,IAAI,CAAC,CACR,GAAEX,YAAY,CAACQ,IAAK,EAAC,EACrB,GA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AC,OAAOxB,KAAK,EAAE;QACdgB,MAAM,CAACzB,IAAI,CAACS,KAAK,CAAC;QAClBzC,uBAAuB,CACrB0D,WAAW,EACV,uCAAsCO,IAAK,EAC9C,CAAC;QACDrE,YAAY,CAAC6C,KAAK,EAAE,OAAO,CAAC;MAC9B;IACF;IACA3C,qBAAqB,CACnB4D,WAAW,EACV,sBAAqB8B,KAAM,wBAAuBJ,KAAK,CAACzB,MAAO,SAClE,CAAC;EACH,CAAC,CAAC,OAAOlB,KAAK,EAAE;IACdgB,MAAM,CAACzB,IAAI,CAACS,KAAK,CAAC;IAClB3C,qBAAqB,CACnB4D,WAAW,EACV,4CACH,CAAC;IACD9D,YAAY,CAAC6C,KAAK,EAAE,OAAO,CAAC;EAC9B;EACA/C,YAAY,CAAE,uDAAsD,CAAC;EACrE,OAAO,CAAC,KAAK+D,MAAM,CAACE,MAAM;AAC5B"}
|
package/esm/ops/Saml2Ops.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { frodo } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { createObjectTable, createProgressIndicator, createTable, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
4
|
-
import { saveTextToFile } from '../utils/ExportImportUtils';
|
|
5
4
|
const {
|
|
6
5
|
decodeBase64,
|
|
6
|
+
saveTextToFile,
|
|
7
7
|
getFilePath,
|
|
8
8
|
getWorkingDirectory
|
|
9
9
|
} = frodo.utils;
|
|
@@ -147,8 +147,9 @@ export async function exportSaml2MetadataToFile(entityId, file = null) {
|
|
|
147
147
|
* Export a single entity provider to file
|
|
148
148
|
* @param {String} entityId Provider entity id
|
|
149
149
|
* @param {String} file Optional filename
|
|
150
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
150
151
|
*/
|
|
151
|
-
export async function exportSaml2ProviderToFile(entityId, file = null) {
|
|
152
|
+
export async function exportSaml2ProviderToFile(entityId, file = null, includeMeta = true) {
|
|
152
153
|
debugMessage(`cli.Saml2Ops.exportSaml2ProviderToFile: start [entityId=${entityId}, file=${file}]`);
|
|
153
154
|
if (!file) {
|
|
154
155
|
file = getTypedFilename(entityId, 'saml');
|
|
@@ -158,7 +159,7 @@ export async function exportSaml2ProviderToFile(entityId, file = null) {
|
|
|
158
159
|
try {
|
|
159
160
|
indicatorId = createProgressIndicator('determinate', 1, `Exporting provider ${entityId}`);
|
|
160
161
|
const fileData = await exportSaml2Provider(entityId);
|
|
161
|
-
saveJsonToFile(fileData, filePath);
|
|
162
|
+
saveJsonToFile(fileData, filePath, includeMeta);
|
|
162
163
|
updateProgressIndicator(indicatorId, `Exported provider ${entityId}`);
|
|
163
164
|
stopProgressIndicator(indicatorId,
|
|
164
165
|
// @ts-expect-error - brightCyan colors the string, even though it is not a property of string
|
|
@@ -173,15 +174,16 @@ export async function exportSaml2ProviderToFile(entityId, file = null) {
|
|
|
173
174
|
/**
|
|
174
175
|
* Export all entity providers to one file
|
|
175
176
|
* @param {String} file Optional filename
|
|
177
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
176
178
|
*/
|
|
177
|
-
export async function exportSaml2ProvidersToFile(file = null) {
|
|
179
|
+
export async function exportSaml2ProvidersToFile(file = null, includeMeta = true) {
|
|
178
180
|
debugMessage(`cli.Saml2Ops.exportSaml2ProviderToFile: start [file=${file}]`);
|
|
179
181
|
if (!file) {
|
|
180
182
|
file = getTypedFilename(`all${getRealmString()}Providers`, 'saml');
|
|
181
183
|
}
|
|
182
184
|
try {
|
|
183
185
|
const exportData = await exportSaml2Providers();
|
|
184
|
-
saveJsonToFile(exportData, getFilePath(file, true));
|
|
186
|
+
saveJsonToFile(exportData, getFilePath(file, true), includeMeta);
|
|
185
187
|
} catch (error) {
|
|
186
188
|
var _error$response;
|
|
187
189
|
printMessage(error.message, 'error');
|
|
@@ -192,15 +194,16 @@ export async function exportSaml2ProvidersToFile(file = null) {
|
|
|
192
194
|
|
|
193
195
|
/**
|
|
194
196
|
* Export all entity providers to individual files
|
|
197
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
195
198
|
*/
|
|
196
|
-
export async function exportSaml2ProvidersToFiles() {
|
|
199
|
+
export async function exportSaml2ProvidersToFiles(includeMeta = true) {
|
|
197
200
|
const stubs = await readSaml2ProviderStubs();
|
|
198
201
|
if (stubs.length > 0) {
|
|
199
202
|
const indicatorId = createProgressIndicator('determinate', stubs.length, 'Exporting providers');
|
|
200
203
|
for (const stub of stubs) {
|
|
201
204
|
const file = getFilePath(getTypedFilename(stub.entityId, 'saml'), true);
|
|
202
205
|
const fileData = await exportSaml2Provider(stub.entityId);
|
|
203
|
-
saveJsonToFile(fileData, file);
|
|
206
|
+
saveJsonToFile(fileData, file, includeMeta);
|
|
204
207
|
updateProgressIndicator(indicatorId, `Exported provider ${stub.entityId}`);
|
|
205
208
|
}
|
|
206
209
|
stopProgressIndicator(indicatorId, `${stubs.length} providers exported.`);
|
package/esm/ops/Saml2Ops.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Saml2Ops.js","names":["frodo","fs","createObjectTable","createProgressIndicator","createTable","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","saveTextToFile","decodeBase64","getFilePath","getWorkingDirectory","utils","getTypedFilename","saveJsonToFile","getRealmString","validateImport","readSaml2ProviderStubs","readSaml2Provider","readSaml2ProviderStub","getSaml2ProviderMetadataUrl","getSaml2ProviderMetadata","exportSaml2Provider","exportSaml2Providers","importSaml2Provider","importSaml2Providers","saml2","entityProvider","roleMap","identityProvider","serviceProvider","attributeQueryProvider","xacmlPolicyEnforcementPoint","getOneLineDescription","saml2ProviderObj","roles","key","value","Object","entries","push","description","entityId","entityLocation","length","join","getTableHeaderMd","markdown","getTableRowMd","row","listSaml2Providers","long","providerList","sort","a","b","_id","localeCompare","provider","table","location","map","role","toString","describeSaml2Provider","stub","rawProviderData","_rev","metadataUrl","error","message","exportSaml2MetadataToFile","file","filePath","indicatorId","metaData","brightCyan","exportSaml2ProviderToFile","fileData","err","exportSaml2ProvidersToFile","exportData","_error$response","response","status","exportSaml2ProvidersToFiles","stubs","importSaml2ProviderFromFile","data","readFileSync","JSON","parse","importFirstSaml2ProviderFromFile","entityId64","keys","saml","remote","hosted","importSaml2ProvidersFromFile","meta","importSaml2ProvidersFromFiles","names","readdirSync","jsonFiles","filter","name","toLowerCase","endsWith","total","result"],"sources":["../../src/ops/Saml2Ops.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { type Saml2ProviderSkeleton } from '@rockcarver/frodo-lib/types/api/Saml2Api';\nimport { type Saml2ExportInterface } from '@rockcarver/frodo-lib/types/ops/Saml2Ops';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport { saveTextToFile } from '../utils/ExportImportUtils';\n\nconst { decodeBase64, getFilePath, getWorkingDirectory } = frodo.utils;\nconst { getTypedFilename, saveJsonToFile, getRealmString, validateImport } =\n frodo.utils;\nconst {\n readSaml2ProviderStubs,\n readSaml2Provider,\n readSaml2ProviderStub,\n getSaml2ProviderMetadataUrl,\n getSaml2ProviderMetadata,\n exportSaml2Provider,\n exportSaml2Providers,\n importSaml2Provider,\n importSaml2Providers,\n} = frodo.saml2.entityProvider;\n\nconst roleMap = {\n identityProvider: 'IDP',\n serviceProvider: 'SP',\n attributeQueryProvider: 'AttrQuery',\n xacmlPolicyEnforcementPoint: 'XACML PEP',\n};\n\n/**\n * Get a one-line description of the saml2 provider object\n * @param {Saml2ProviderSkeleton} saml2ProviderObj saml2 provider object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n saml2ProviderObj: Saml2ProviderSkeleton\n): string {\n const roles: string[] = [];\n for (const [key, value] of Object.entries(roleMap)) {\n if (saml2ProviderObj[key]) {\n roles.push(value);\n }\n }\n const description = `[${saml2ProviderObj.entityId['brightCyan']}]${\n ' (' + saml2ProviderObj.entityLocation\n }${roles.length ? ' ' + roles.join(', ') + ')' : ')'}`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Entity Id | Location | Role(s) |\\n';\n markdown += '| --------- | -------- | ------- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the saml2 provider in markdown\n * @param {Saml2ProviderSkeleton} saml2ProviderObj saml2 provider object to describe\n * @returns {string} a table-row of the saml2 provider in markdown\n */\nexport function getTableRowMd(saml2ProviderObj: Saml2ProviderSkeleton): string {\n const roles: string[] = [];\n for (const [key, value] of Object.entries(roleMap)) {\n if (saml2ProviderObj[key]) {\n roles.push(value);\n }\n }\n const row = `| ${saml2ProviderObj.entityId} | ${\n saml2ProviderObj.entityLocation\n } | ${roles.length ? roles.join(', ') : ''} |`;\n return row;\n}\n\n/**\n * List entity providers\n * @param {boolean} long Long list format with details\n */\nexport async function listSaml2Providers(long = false) {\n const providerList = await readSaml2ProviderStubs();\n providerList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const provider of providerList) {\n printMessage(`${provider.entityId}`, 'data');\n }\n } else {\n const table = createTable([\n 'Entity Id'['brightCyan'],\n 'Location'['brightCyan'],\n 'Role(s)'['brightCyan'],\n ]);\n for (const provider of providerList) {\n table.push([\n provider.entityId,\n provider.location,\n provider.roles.map((role) => roleMap[role]).join(', '),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n}\n\n/**\n * Describe an entity provider's configuration\n * @param {String} entityId Provider entity id\n */\nexport async function describeSaml2Provider(entityId) {\n try {\n const stub = await readSaml2ProviderStub(entityId);\n const { location } = stub;\n const roles = stub.roles.map((role: string) => roleMap[role]).join(', ');\n const rawProviderData = await readSaml2Provider(entityId);\n delete rawProviderData._id;\n delete rawProviderData._rev;\n rawProviderData.location = location;\n rawProviderData.roles = roles;\n rawProviderData.metadataUrl = getSaml2ProviderMetadataUrl(entityId);\n const table = createObjectTable(rawProviderData);\n printMessage(table.toString(), 'data');\n } catch (error) {\n printMessage(error.message, 'error');\n }\n}\n\n/**\n * Export provider metadata to file\n * @param {String} entityId Provider entity id\n * @param {String} file Optional filename\n */\nexport async function exportSaml2MetadataToFile(entityId, file = null) {\n if (!file) {\n file = getTypedFilename(entityId, 'metadata', 'xml');\n }\n const filePath = getFilePath(file, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting metadata for: ${entityId}`\n );\n try {\n updateProgressIndicator(indicatorId, `Writing file ${filePath}`);\n const metaData = await getSaml2ProviderMetadata(entityId);\n saveTextToFile(metaData, filePath);\n updateProgressIndicator(indicatorId, `Exported provider ${entityId}`);\n stopProgressIndicator(\n indicatorId,\n // @ts-expect-error - brightCyan colors the string, even though it is not a property of string\n `Exported ${entityId.brightCyan} metadata to ${filePath.brightCyan}.`\n );\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error}`);\n printMessage(error, 'error');\n }\n}\n\n/**\n * Export a single entity provider to file\n * @param {String} entityId Provider entity id\n * @param {String} file Optional filename\n */\nexport async function exportSaml2ProviderToFile(entityId, file = null) {\n debugMessage(\n `cli.Saml2Ops.exportSaml2ProviderToFile: start [entityId=${entityId}, file=${file}]`\n );\n if (!file) {\n file = getTypedFilename(entityId, 'saml');\n }\n const filePath = getFilePath(file, true);\n let indicatorId: string;\n try {\n indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting provider ${entityId}`\n );\n const fileData = await exportSaml2Provider(entityId);\n saveJsonToFile(fileData, filePath);\n updateProgressIndicator(indicatorId, `Exported provider ${entityId}`);\n stopProgressIndicator(\n indicatorId,\n // @ts-expect-error - brightCyan colors the string, even though it is not a property of string\n `Exported ${entityId.brightCyan} to ${filePath.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(err, 'error');\n }\n debugMessage(\n `cli.Saml2Ops.exportSaml2ProviderToFile: end [entityId=${entityId}, file=${filePath}]`\n );\n}\n\n/**\n * Export all entity providers to one file\n * @param {String} file Optional filename\n */\nexport async function exportSaml2ProvidersToFile(file = null) {\n debugMessage(`cli.Saml2Ops.exportSaml2ProviderToFile: start [file=${file}]`);\n if (!file) {\n file = getTypedFilename(`all${getRealmString()}Providers`, 'saml');\n }\n try {\n const exportData = await exportSaml2Providers();\n saveJsonToFile(exportData, getFilePath(file, true));\n } catch (error) {\n printMessage(error.message, 'error');\n printMessage(\n `exportSaml2ProvidersToFile: ${error.response?.status}`,\n 'error'\n );\n }\n debugMessage(`cli.Saml2Ops.exportSaml2ProviderToFile: end [file=${file}]`);\n}\n\n/**\n * Export all entity providers to individual files\n */\nexport async function exportSaml2ProvidersToFiles() {\n const stubs = await readSaml2ProviderStubs();\n if (stubs.length > 0) {\n const indicatorId = createProgressIndicator(\n 'determinate',\n stubs.length,\n 'Exporting providers'\n );\n for (const stub of stubs) {\n const file = getFilePath(getTypedFilename(stub.entityId, 'saml'), true);\n const fileData = await exportSaml2Provider(stub.entityId);\n saveJsonToFile(fileData, file);\n updateProgressIndicator(\n indicatorId,\n `Exported provider ${stub.entityId}`\n );\n }\n stopProgressIndicator(indicatorId, `${stubs.length} providers exported.`);\n } else {\n printMessage('No entity providers found.', 'info');\n }\n}\n\n/**\n * Import a SAML entity provider by entity id from file\n * @param {String} entityId Provider entity id\n * @param {String} file Import file name\n */\nexport async function importSaml2ProviderFromFile(\n entityId: string,\n file: string\n) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${entityId}...`\n );\n try {\n await importSaml2Provider(entityId, fileData);\n stopProgressIndicator(indicatorId, `Imported ${entityId}.`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${entityId}: ${error.message}`,\n 'fail'\n );\n }\n } catch (error) {\n printMessage(\n `Error importing saml2 provider ${entityId}: ${error}`,\n 'error'\n );\n }\n}\n\n/**\n * Import a SAML entity provider by entity id from file\n * @param {String} file Import file name\n */\nexport async function importFirstSaml2ProviderFromFile(file: string) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data) as Saml2ExportInterface;\n // pick the first provider and run with it\n const entityId64 =\n Object.keys(fileData.saml.remote)[0] ||\n Object.keys(fileData.saml.hosted)[0];\n const entityId = decodeBase64(entityId64);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${entityId}...`\n );\n try {\n await importSaml2Provider(entityId, fileData);\n stopProgressIndicator(indicatorId, `Imported ${entityId}.`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${entityId}: ${error.message}`,\n 'fail'\n );\n }\n } catch (error) {\n printMessage(`Error importing first saml2 provider: ${error}`, 'error');\n }\n}\n\n/**\n * Import all SAML entity providers from file\n * @param {String} file Import file name\n */\nexport async function importSaml2ProvidersFromFile(file: string) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n await importSaml2Providers(fileData);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n } catch (error) {\n printMessage(`Error importing saml2 providers: ${error}`, 'error');\n }\n}\n\n/**\n * Import all SAML entity providers from all *.saml.json files in the current directory\n */\nexport async function importSaml2ProvidersFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.saml.json'))\n .map((name) => getFilePath(name));\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing providers...'\n );\n let total = 0;\n for (const file of jsonFiles) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n const result = await importSaml2Providers(fileData);\n total += result.length;\n updateProgressIndicator(\n indicatorId,\n `Imported ${result.length} provider(s) from ${file}.`\n );\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n } catch (error) {\n printMessage(\n `Error importing providers from ${file}: ${error.message}`,\n 'error'\n );\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Imported ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAG7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SAASC,cAAc,QAAQ,4BAA4B;AAE3D,MAAM;EAAEC,YAAY;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGZ,KAAK,CAACa,KAAK;AACtE,MAAM;EAAEC,gBAAgB;EAAEC,cAAc;EAAEC,cAAc;EAAEC;AAAe,CAAC,GACxEjB,KAAK,CAACa,KAAK;AACb,MAAM;EACJK,sBAAsB;EACtBC,iBAAiB;EACjBC,qBAAqB;EACrBC,2BAA2B;EAC3BC,wBAAwB;EACxBC,mBAAmB;EACnBC,oBAAoB;EACpBC,mBAAmB;EACnBC;AACF,CAAC,GAAG1B,KAAK,CAAC2B,KAAK,CAACC,cAAc;AAE9B,MAAMC,OAAO,GAAG;EACdC,gBAAgB,EAAE,KAAK;EACvBC,eAAe,EAAE,IAAI;EACrBC,sBAAsB,EAAE,WAAW;EACnCC,2BAA2B,EAAE;AAC/B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,gBAAuC,EAC/B;EACR,MAAMC,KAAe,GAAG,EAAE;EAC1B,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACX,OAAO,CAAC,EAAE;IAClD,IAAIM,gBAAgB,CAACE,GAAG,CAAC,EAAE;MACzBD,KAAK,CAACK,IAAI,CAACH,KAAK,CAAC;IACnB;EACF;EACA,MAAMI,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AW,CAAC+F,IAAI,CAAC,CAAC;EACnC,MAAM/B,WAAW,GAAGxE,uBAAuB,CACzC,aAAa,EACbqG,SAAS,CAAC3D,MAAM,EAChB,wBACF,CAAC;EACD,IAAIgE,KAAK,GAAG,CAAC;EACb,KAAK,MAAMpC,IAAI,IAAI+B,SAAS,EAAE;IAC5B,IAAI;MACF,MAAMf,IAAI,GAAGxF,EAAE,CAACyF,YAAY,CAACjB,IAAI,EAAE,MAAM,CAAC;MAC1C,MAAMM,QAAQ,GAAGY,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;MACjC,IAAIxE,cAAc,CAAC8D,QAAQ,CAACqB,IAAI,CAAC,EAAE;QACjC,MAAMU,MAAM,GAAG,MAAMpF,oBAAoB,CAACqD,QAAQ,CAAC;QACnD8B,KAAK,IAAIC,MAAM,CAACjE,MAAM;QACtBrC,uBAAuB,CACrBmE,WAAW,EACV,YAAWmC,MAAM,CAACjE,MAAO,qBAAoB4B,IAAK,GACrD,CAAC;MACH,CAAC,MAAM;QACLnE,YAAY,CAAE,iBAAgBmE,IAAK,UAAS,EAAE,OAAO,CAAC;MACxD;IACF,CAAC,CAAC,OAAOH,KAAK,EAAE;MACdhE,YAAY,CACT,kCAAiCmE,IAAK,KAAIH,KAAK,CAACC,OAAQ,EAAC,EAC1D,OACF,CAAC;IACH;EACF;EACAhE,qBAAqB,CACnBoE,WAAW,EACV,YAAWkC,KAAM,qBAAoBL,SAAS,CAAC3D,MAAO,WACzD,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"Saml2Ops.js","names":["frodo","fs","createObjectTable","createProgressIndicator","createTable","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","decodeBase64","saveTextToFile","getFilePath","getWorkingDirectory","utils","getTypedFilename","saveJsonToFile","getRealmString","validateImport","readSaml2ProviderStubs","readSaml2Provider","readSaml2ProviderStub","getSaml2ProviderMetadataUrl","getSaml2ProviderMetadata","exportSaml2Provider","exportSaml2Providers","importSaml2Provider","importSaml2Providers","saml2","entityProvider","roleMap","identityProvider","serviceProvider","attributeQueryProvider","xacmlPolicyEnforcementPoint","getOneLineDescription","saml2ProviderObj","roles","key","value","Object","entries","push","description","entityId","entityLocation","length","join","getTableHeaderMd","markdown","getTableRowMd","row","listSaml2Providers","long","providerList","sort","a","b","_id","localeCompare","provider","table","location","map","role","toString","describeSaml2Provider","stub","rawProviderData","_rev","metadataUrl","error","message","exportSaml2MetadataToFile","file","filePath","indicatorId","metaData","brightCyan","exportSaml2ProviderToFile","includeMeta","fileData","err","exportSaml2ProvidersToFile","exportData","_error$response","response","status","exportSaml2ProvidersToFiles","stubs","importSaml2ProviderFromFile","data","readFileSync","JSON","parse","importFirstSaml2ProviderFromFile","entityId64","keys","saml","remote","hosted","importSaml2ProvidersFromFile","meta","importSaml2ProvidersFromFiles","names","readdirSync","jsonFiles","filter","name","toLowerCase","endsWith","total","result"],"sources":["../../src/ops/Saml2Ops.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { type Saml2ProviderSkeleton } from '@rockcarver/frodo-lib/types/api/Saml2Api';\nimport { type Saml2ExportInterface } from '@rockcarver/frodo-lib/types/ops/Saml2Ops';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst { decodeBase64, saveTextToFile, getFilePath, getWorkingDirectory } =\n frodo.utils;\nconst { getTypedFilename, saveJsonToFile, getRealmString, validateImport } =\n frodo.utils;\nconst {\n readSaml2ProviderStubs,\n readSaml2Provider,\n readSaml2ProviderStub,\n getSaml2ProviderMetadataUrl,\n getSaml2ProviderMetadata,\n exportSaml2Provider,\n exportSaml2Providers,\n importSaml2Provider,\n importSaml2Providers,\n} = frodo.saml2.entityProvider;\n\nconst roleMap = {\n identityProvider: 'IDP',\n serviceProvider: 'SP',\n attributeQueryProvider: 'AttrQuery',\n xacmlPolicyEnforcementPoint: 'XACML PEP',\n};\n\n/**\n * Get a one-line description of the saml2 provider object\n * @param {Saml2ProviderSkeleton} saml2ProviderObj saml2 provider object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n saml2ProviderObj: Saml2ProviderSkeleton\n): string {\n const roles: string[] = [];\n for (const [key, value] of Object.entries(roleMap)) {\n if (saml2ProviderObj[key]) {\n roles.push(value);\n }\n }\n const description = `[${saml2ProviderObj.entityId['brightCyan']}]${\n ' (' + saml2ProviderObj.entityLocation\n }${roles.length ? ' ' + roles.join(', ') + ')' : ')'}`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Entity Id | Location | Role(s) |\\n';\n markdown += '| --------- | -------- | ------- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the saml2 provider in markdown\n * @param {Saml2ProviderSkeleton} saml2ProviderObj saml2 provider object to describe\n * @returns {string} a table-row of the saml2 provider in markdown\n */\nexport function getTableRowMd(saml2ProviderObj: Saml2ProviderSkeleton): string {\n const roles: string[] = [];\n for (const [key, value] of Object.entries(roleMap)) {\n if (saml2ProviderObj[key]) {\n roles.push(value);\n }\n }\n const row = `| ${saml2ProviderObj.entityId} | ${\n saml2ProviderObj.entityLocation\n } | ${roles.length ? roles.join(', ') : ''} |`;\n return row;\n}\n\n/**\n * List entity providers\n * @param {boolean} long Long list format with details\n */\nexport async function listSaml2Providers(long = false) {\n const providerList = await readSaml2ProviderStubs();\n providerList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const provider of providerList) {\n printMessage(`${provider.entityId}`, 'data');\n }\n } else {\n const table = createTable([\n 'Entity Id'['brightCyan'],\n 'Location'['brightCyan'],\n 'Role(s)'['brightCyan'],\n ]);\n for (const provider of providerList) {\n table.push([\n provider.entityId,\n provider.location,\n provider.roles.map((role) => roleMap[role]).join(', '),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n}\n\n/**\n * Describe an entity provider's configuration\n * @param {String} entityId Provider entity id\n */\nexport async function describeSaml2Provider(entityId) {\n try {\n const stub = await readSaml2ProviderStub(entityId);\n const { location } = stub;\n const roles = stub.roles.map((role: string) => roleMap[role]).join(', ');\n const rawProviderData = await readSaml2Provider(entityId);\n delete rawProviderData._id;\n delete rawProviderData._rev;\n rawProviderData.location = location;\n rawProviderData.roles = roles;\n rawProviderData.metadataUrl = getSaml2ProviderMetadataUrl(entityId);\n const table = createObjectTable(rawProviderData);\n printMessage(table.toString(), 'data');\n } catch (error) {\n printMessage(error.message, 'error');\n }\n}\n\n/**\n * Export provider metadata to file\n * @param {String} entityId Provider entity id\n * @param {String} file Optional filename\n */\nexport async function exportSaml2MetadataToFile(entityId, file = null) {\n if (!file) {\n file = getTypedFilename(entityId, 'metadata', 'xml');\n }\n const filePath = getFilePath(file, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting metadata for: ${entityId}`\n );\n try {\n updateProgressIndicator(indicatorId, `Writing file ${filePath}`);\n const metaData = await getSaml2ProviderMetadata(entityId);\n saveTextToFile(metaData, filePath);\n updateProgressIndicator(indicatorId, `Exported provider ${entityId}`);\n stopProgressIndicator(\n indicatorId,\n // @ts-expect-error - brightCyan colors the string, even though it is not a property of string\n `Exported ${entityId.brightCyan} metadata to ${filePath.brightCyan}.`\n );\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error}`);\n printMessage(error, 'error');\n }\n}\n\n/**\n * Export a single entity provider to file\n * @param {String} entityId Provider entity id\n * @param {String} file Optional filename\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportSaml2ProviderToFile(\n entityId,\n file = null,\n includeMeta = true\n) {\n debugMessage(\n `cli.Saml2Ops.exportSaml2ProviderToFile: start [entityId=${entityId}, file=${file}]`\n );\n if (!file) {\n file = getTypedFilename(entityId, 'saml');\n }\n const filePath = getFilePath(file, true);\n let indicatorId: string;\n try {\n indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting provider ${entityId}`\n );\n const fileData = await exportSaml2Provider(entityId);\n saveJsonToFile(fileData, filePath, includeMeta);\n updateProgressIndicator(indicatorId, `Exported provider ${entityId}`);\n stopProgressIndicator(\n indicatorId,\n // @ts-expect-error - brightCyan colors the string, even though it is not a property of string\n `Exported ${entityId.brightCyan} to ${filePath.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(err, 'error');\n }\n debugMessage(\n `cli.Saml2Ops.exportSaml2ProviderToFile: end [entityId=${entityId}, file=${filePath}]`\n );\n}\n\n/**\n * Export all entity providers to one file\n * @param {String} file Optional filename\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportSaml2ProvidersToFile(\n file = null,\n includeMeta = true\n) {\n debugMessage(`cli.Saml2Ops.exportSaml2ProviderToFile: start [file=${file}]`);\n if (!file) {\n file = getTypedFilename(`all${getRealmString()}Providers`, 'saml');\n }\n try {\n const exportData = await exportSaml2Providers();\n saveJsonToFile(exportData, getFilePath(file, true), includeMeta);\n } catch (error) {\n printMessage(error.message, 'error');\n printMessage(\n `exportSaml2ProvidersToFile: ${error.response?.status}`,\n 'error'\n );\n }\n debugMessage(`cli.Saml2Ops.exportSaml2ProviderToFile: end [file=${file}]`);\n}\n\n/**\n * Export all entity providers to individual files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportSaml2ProvidersToFiles(includeMeta = true) {\n const stubs = await readSaml2ProviderStubs();\n if (stubs.length > 0) {\n const indicatorId = createProgressIndicator(\n 'determinate',\n stubs.length,\n 'Exporting providers'\n );\n for (const stub of stubs) {\n const file = getFilePath(getTypedFilename(stub.entityId, 'saml'), true);\n const fileData = await exportSaml2Provider(stub.entityId);\n saveJsonToFile(fileData, file, includeMeta);\n updateProgressIndicator(\n indicatorId,\n `Exported provider ${stub.entityId}`\n );\n }\n stopProgressIndicator(indicatorId, `${stubs.length} providers exported.`);\n } else {\n printMessage('No entity providers found.', 'info');\n }\n}\n\n/**\n * Import a SAML entity provider by entity id from file\n * @param {String} entityId Provider entity id\n * @param {String} file Import file name\n */\nexport async function importSaml2ProviderFromFile(\n entityId: string,\n file: string\n) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${entityId}...`\n );\n try {\n await importSaml2Provider(entityId, fileData);\n stopProgressIndicator(indicatorId, `Imported ${entityId}.`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${entityId}: ${error.message}`,\n 'fail'\n );\n }\n } catch (error) {\n printMessage(\n `Error importing saml2 provider ${entityId}: ${error}`,\n 'error'\n );\n }\n}\n\n/**\n * Import a SAML entity provider by entity id from file\n * @param {String} file Import file name\n */\nexport async function importFirstSaml2ProviderFromFile(file: string) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data) as Saml2ExportInterface;\n // pick the first provider and run with it\n const entityId64 =\n Object.keys(fileData.saml.remote)[0] ||\n Object.keys(fileData.saml.hosted)[0];\n const entityId = decodeBase64(entityId64);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${entityId}...`\n );\n try {\n await importSaml2Provider(entityId, fileData);\n stopProgressIndicator(indicatorId, `Imported ${entityId}.`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${entityId}: ${error.message}`,\n 'fail'\n );\n }\n } catch (error) {\n printMessage(`Error importing first saml2 provider: ${error}`, 'error');\n }\n}\n\n/**\n * Import all SAML entity providers from file\n * @param {String} file Import file name\n */\nexport async function importSaml2ProvidersFromFile(file: string) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n await importSaml2Providers(fileData);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n } catch (error) {\n printMessage(`Error importing saml2 providers: ${error}`, 'error');\n }\n}\n\n/**\n * Import all SAML entity providers from all *.saml.json files in the current directory\n */\nexport async function importSaml2ProvidersFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.saml.json'))\n .map((name) => getFilePath(name));\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing providers...'\n );\n let total = 0;\n for (const file of jsonFiles) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n const result = await importSaml2Providers(fileData);\n total += result.length;\n updateProgressIndicator(\n indicatorId,\n `Imported ${result.length} provider(s) from ${file}.`\n );\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n } catch (error) {\n printMessage(\n `Error importing providers from ${file}: ${error.message}`,\n 'error'\n );\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Imported ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAG7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AAEzB,MAAM;EAAEC,YAAY;EAAEC,cAAc;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GACtEZ,KAAK,CAACa,KAAK;AACb,MAAM;EAAEC,gBAAgB;EAAEC,cAAc;EAAEC,cAAc;EAAEC;AAAe,CAAC,GACxEjB,KAAK,CAACa,KAAK;AACb,MAAM;EACJK,sBAAsB;EACtBC,iBAAiB;EACjBC,qBAAqB;EACrBC,2BAA2B;EAC3BC,wBAAwB;EACxBC,mBAAmB;EACnBC,oBAAoB;EACpBC,mBAAmB;EACnBC;AACF,CAAC,GAAG1B,KAAK,CAAC2B,KAAK,CAACC,cAAc;AAE9B,MAAMC,OAAO,GAAG;EACdC,gBAAgB,EAAE,K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F,CAAC,CAAC,OAAOH,KAAK,EAAE;MACdhE,YAAY,CACT,kCAAiCmE,IAAK,KAAIH,KAAK,CAACC,OAAQ,EAAC,EAC1D,OACF,CAAC;IACH;EACF;EACAhE,qBAAqB,CACnBoE,WAAW,EACV,YAAWmC,KAAM,qBAAoBL,SAAS,CAAC5D,MAAO,WACzD,CAAC;AACH"}
|
package/esm/ops/ScriptOps.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import chokidar from 'chokidar';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import { getFullExportConfig, isIdUsed } from '../utils/Config';
|
|
4
5
|
import { createProgressIndicator, createTable, debugMessage, failSpinner, printMessage, showSpinner, spinSpinner, stopProgressIndicator, succeedSpinner, updateProgressIndicator } from '../utils/Console';
|
|
5
|
-
import { getTypedFilename, isValidUrl, saveJsonToFile, saveTextToFile, titleCase } from '../utils/ExportImportUtils';
|
|
6
6
|
import wordwrap from './utils/Wordwrap';
|
|
7
|
+
const {
|
|
8
|
+
getTypedFilename,
|
|
9
|
+
isValidUrl,
|
|
10
|
+
saveJsonToFile,
|
|
11
|
+
saveTextToFile,
|
|
12
|
+
titleCase,
|
|
13
|
+
isBase64Encoded,
|
|
14
|
+
getFilePath,
|
|
15
|
+
getWorkingDirectory
|
|
16
|
+
} = frodo.utils;
|
|
7
17
|
const {
|
|
8
18
|
readScripts,
|
|
9
19
|
exportScript,
|
|
@@ -14,11 +24,6 @@ const {
|
|
|
14
24
|
deleteScriptByName,
|
|
15
25
|
deleteScripts
|
|
16
26
|
} = frodo.script;
|
|
17
|
-
const {
|
|
18
|
-
isBase64Encoded,
|
|
19
|
-
getFilePath,
|
|
20
|
-
getWorkingDirectory
|
|
21
|
-
} = frodo.utils;
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* Get a one-line description of the script object
|
|
@@ -58,45 +63,74 @@ export function getTableRowMd(scriptObj) {
|
|
|
58
63
|
/**
|
|
59
64
|
* List scripts
|
|
60
65
|
* @param {boolean} long detail list
|
|
66
|
+
* @param {boolean} usage display usage field
|
|
67
|
+
* @param {String | null} file Optional filename to determine usage
|
|
61
68
|
* @returns {Promise<boolean>} true if no errors occurred during export, false otherwise
|
|
62
69
|
*/
|
|
63
|
-
export async function listScripts(long = false) {
|
|
64
|
-
let
|
|
70
|
+
export async function listScripts(long = false, usage = false, file = null) {
|
|
71
|
+
let spinnerId;
|
|
72
|
+
let scripts = [];
|
|
65
73
|
debugMessage(`Cli.ScriptOps.listScripts: start`);
|
|
66
74
|
try {
|
|
67
|
-
|
|
75
|
+
spinnerId = createProgressIndicator('indeterminate', 0, `Reading scripts...`);
|
|
76
|
+
scripts = await readScripts();
|
|
68
77
|
scripts.sort((a, b) => a.name.localeCompare(b.name));
|
|
69
|
-
|
|
70
|
-
const table = createTable(['Name', 'UUID', 'Language', 'Context', 'Description']);
|
|
71
|
-
const langMap = {
|
|
72
|
-
JAVASCRIPT: 'JS',
|
|
73
|
-
GROOVY: 'Groovy'
|
|
74
|
-
};
|
|
75
|
-
scripts.forEach(script => {
|
|
76
|
-
table.push([wordwrap(script.name, 25, ' '), script._id, langMap[script.language], wordwrap(titleCase(script.context.split('_').join(' ')), 25), wordwrap(script.description, 30)]);
|
|
77
|
-
});
|
|
78
|
-
printMessage(table.toString(), 'data');
|
|
79
|
-
} else {
|
|
80
|
-
scripts.forEach(script => {
|
|
81
|
-
printMessage(`${script.name}`, 'data');
|
|
82
|
-
});
|
|
83
|
-
}
|
|
78
|
+
stopProgressIndicator(spinnerId, `Successfully read ${scripts.length} scripts.`, 'success');
|
|
84
79
|
} catch (error) {
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
var _error$response;
|
|
81
|
+
stopProgressIndicator(spinnerId, `Error reading scripts: ${((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || error.message}`, 'fail');
|
|
87
82
|
debugMessage(error);
|
|
83
|
+
debugMessage(`Cli.ScriptOps.listScripts: end [false]`);
|
|
84
|
+
return false;
|
|
88
85
|
}
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
if (!long && !usage) {
|
|
87
|
+
scripts.forEach(script => {
|
|
88
|
+
printMessage(`${script.name}`, 'data');
|
|
89
|
+
});
|
|
90
|
+
debugMessage(`Cli.ScriptOps.listScripts: end [true]`);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
let fullExport = null;
|
|
94
|
+
const headers = long ? ['Name', 'UUID', 'Language', 'Context', 'Description'] : ['Name'];
|
|
95
|
+
if (usage) {
|
|
96
|
+
try {
|
|
97
|
+
fullExport = await getFullExportConfig(file);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
var _error$response2;
|
|
100
|
+
printMessage(`Error getting full export: ${((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) || error.message}`, 'error');
|
|
101
|
+
debugMessage(`Cli.ScriptOps.listScripts: end [false]`);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//Delete scripts from full export so they aren't mistakenly used for determining usage
|
|
105
|
+
delete fullExport.script;
|
|
106
|
+
headers.push('Used');
|
|
107
|
+
}
|
|
108
|
+
const table = createTable(headers);
|
|
109
|
+
const langMap = {
|
|
110
|
+
JAVASCRIPT: 'JS',
|
|
111
|
+
GROOVY: 'Groovy'
|
|
112
|
+
};
|
|
113
|
+
scripts.forEach(script => {
|
|
114
|
+
const values = long ? [wordwrap(script.name, 25, ' '), script._id, langMap[script.language], wordwrap(titleCase(script.context.split('_').join(' ')), 25), wordwrap(script.description, 30)] : [wordwrap(script.name, 25, ' ')];
|
|
115
|
+
if (usage) {
|
|
116
|
+
const isScriptUsed = isIdUsed(fullExport, script._id, false);
|
|
117
|
+
values.push(isScriptUsed.used ? `${'yes'['brightGreen']} (at ${isScriptUsed.location})` : 'no'['brightRed']);
|
|
118
|
+
}
|
|
119
|
+
table.push(values);
|
|
120
|
+
});
|
|
121
|
+
printMessage(table.toString(), 'data');
|
|
122
|
+
debugMessage(`Cli.ScriptOps.listScripts: end [true]`);
|
|
123
|
+
return true;
|
|
91
124
|
}
|
|
92
125
|
|
|
93
126
|
/**
|
|
94
127
|
* Export script by id to file
|
|
95
128
|
* @param {string} scriptId script uuid
|
|
96
129
|
* @param {string} file file name
|
|
130
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
97
131
|
* @returns {Promise<boolean>} true if no errors occurred during export, false otherwise
|
|
98
132
|
*/
|
|
99
|
-
export async function exportScriptToFile(scriptId, file) {
|
|
133
|
+
export async function exportScriptToFile(scriptId, file, includeMeta = true) {
|
|
100
134
|
debugMessage(`Cli.ScriptOps.exportScriptToFile: start`);
|
|
101
135
|
try {
|
|
102
136
|
showSpinner(`Exporting script '${scriptId}'...`);
|
|
@@ -107,7 +141,7 @@ export async function exportScriptToFile(scriptId, file) {
|
|
|
107
141
|
const filePath = getFilePath(fileName, true);
|
|
108
142
|
spinSpinner(`Exporting script '${scriptId}' to '${filePath}'...`);
|
|
109
143
|
const scriptExport = await exportScript(scriptId);
|
|
110
|
-
saveJsonToFile(scriptExport, filePath);
|
|
144
|
+
saveJsonToFile(scriptExport, filePath, includeMeta);
|
|
111
145
|
succeedSpinner(`Exported script '${scriptId}' to '${filePath}'.`);
|
|
112
146
|
debugMessage(`Cli.ScriptOps.exportScriptToFile: end [true]`);
|
|
113
147
|
return true;
|
|
@@ -123,9 +157,10 @@ export async function exportScriptToFile(scriptId, file) {
|
|
|
123
157
|
* Export script by name to file
|
|
124
158
|
* @param {string} name script name
|
|
125
159
|
* @param {string} file file name
|
|
160
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
126
161
|
* @returns {Promise<boolean>} true if no errors occurred during export, false otherwise
|
|
127
162
|
*/
|
|
128
|
-
export async function exportScriptByNameToFile(name, file) {
|
|
163
|
+
export async function exportScriptByNameToFile(name, file, includeMeta = true) {
|
|
129
164
|
debugMessage(`Cli.ScriptOps.exportScriptByNameToFile: start`);
|
|
130
165
|
try {
|
|
131
166
|
showSpinner(`Exporting script '${name}'...`);
|
|
@@ -136,7 +171,7 @@ export async function exportScriptByNameToFile(name, file) {
|
|
|
136
171
|
const filePath = getFilePath(fileName, true);
|
|
137
172
|
spinSpinner(`Exporting script '${name}' to '${filePath}'...`);
|
|
138
173
|
const scriptExport = await exportScriptByName(name);
|
|
139
|
-
saveJsonToFile(scriptExport, filePath);
|
|
174
|
+
saveJsonToFile(scriptExport, filePath, includeMeta);
|
|
140
175
|
succeedSpinner(`Exported script '${name}' to '${filePath}'.`);
|
|
141
176
|
debugMessage(`Cli.ScriptOps.exportScriptByNameToFile: end [true]`);
|
|
142
177
|
return true;
|
|
@@ -151,9 +186,10 @@ export async function exportScriptByNameToFile(name, file) {
|
|
|
151
186
|
/**
|
|
152
187
|
* Export all scripts to single file
|
|
153
188
|
* @param {string} file file name
|
|
189
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
154
190
|
* @returns {Promise<boolean>} true if no errors occurred during export, false otherwise
|
|
155
191
|
*/
|
|
156
|
-
export async function exportScriptsToFile(file) {
|
|
192
|
+
export async function exportScriptsToFile(file, includeMeta = true) {
|
|
157
193
|
debugMessage(`Cli.ScriptOps.exportScriptsToFile: start`);
|
|
158
194
|
try {
|
|
159
195
|
let fileName = getTypedFilename(`all${titleCase(state.getRealm())}Scripts`, 'script');
|
|
@@ -161,7 +197,7 @@ export async function exportScriptsToFile(file) {
|
|
|
161
197
|
fileName = file;
|
|
162
198
|
}
|
|
163
199
|
const scriptExport = await exportScripts();
|
|
164
|
-
saveJsonToFile(scriptExport, getFilePath(fileName, true));
|
|
200
|
+
saveJsonToFile(scriptExport, getFilePath(fileName, true), includeMeta);
|
|
165
201
|
debugMessage(`Cli.ScriptOps.exportScriptsToFile: end [true]`);
|
|
166
202
|
return true;
|
|
167
203
|
} catch (error) {
|
|
@@ -175,9 +211,10 @@ export async function exportScriptsToFile(file) {
|
|
|
175
211
|
/**
|
|
176
212
|
* Export all scripts to individual files
|
|
177
213
|
* @param extract Extracts the scripts from the exports into separate files if true
|
|
214
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
178
215
|
* @returns {Promise<boolean>} true if no errors occurred during export, false otherwise
|
|
179
216
|
*/
|
|
180
|
-
export async function exportScriptsToFiles(extract = false) {
|
|
217
|
+
export async function exportScriptsToFiles(extract = false, includeMeta = true) {
|
|
181
218
|
let outcome = true;
|
|
182
219
|
debugMessage(`Cli.ScriptOps.exportScriptsToFiles: start`);
|
|
183
220
|
const scriptList = await readScripts();
|
|
@@ -189,7 +226,7 @@ export async function exportScriptsToFiles(extract = false) {
|
|
|
189
226
|
try {
|
|
190
227
|
const scriptExport = await exportScriptByName(script.name);
|
|
191
228
|
if (extract) extractScriptToFile(scriptExport);
|
|
192
|
-
saveJsonToFile(scriptExport, file);
|
|
229
|
+
saveJsonToFile(scriptExport, file, includeMeta);
|
|
193
230
|
updateProgressIndicator(fileBarId, `Saving ${script.name} to ${file}.`);
|
|
194
231
|
stopProgressIndicator(fileBarId, `${script.name} saved to ${file}.`);
|
|
195
232
|
} catch (error) {
|