@rockcarver/frodo-lib 2.0.0-3 → 2.0.0-4

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 (149) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/cjs/api/AgentApi.js +64 -16
  3. package/cjs/api/AgentApi.js.map +1 -1
  4. package/cjs/api/ApiTypes.js +0 -55
  5. package/cjs/api/ApiTypes.js.map +1 -1
  6. package/cjs/api/BaseApi.js +21 -11
  7. package/cjs/api/BaseApi.js.map +1 -1
  8. package/cjs/api/cloud/SecretsApi.js +7 -14
  9. package/cjs/api/cloud/SecretsApi.js.map +1 -1
  10. package/cjs/api/cloud/SecretsApi.test.js.map +1 -1
  11. package/cjs/ops/AdminOps.js +254 -60
  12. package/cjs/ops/AdminOps.js.map +1 -1
  13. package/cjs/ops/AgentOps.js +352 -108
  14. package/cjs/ops/AgentOps.js.map +1 -1
  15. package/cjs/ops/AuthenticateOps.js +253 -60
  16. package/cjs/ops/AuthenticateOps.js.map +1 -1
  17. package/cjs/ops/CirclesOfTrustOps.js +16 -4
  18. package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
  19. package/cjs/ops/ConnectionProfileOps.js +163 -40
  20. package/cjs/ops/ConnectionProfileOps.js.map +1 -1
  21. package/cjs/ops/EmailTemplateOps.js +7 -1
  22. package/cjs/ops/EmailTemplateOps.js.map +1 -1
  23. package/cjs/ops/IdpOps.js +55 -12
  24. package/cjs/ops/IdpOps.js.map +1 -1
  25. package/cjs/ops/JourneyOps.js +645 -136
  26. package/cjs/ops/JourneyOps.js.map +1 -1
  27. package/cjs/ops/NodeOps.js +96 -24
  28. package/cjs/ops/NodeOps.js.map +1 -1
  29. package/cjs/ops/OAuth2ClientOps.js +45 -11
  30. package/cjs/ops/OAuth2ClientOps.js.map +1 -1
  31. package/cjs/ops/OpsTypes.js +0 -23
  32. package/cjs/ops/OpsTypes.js.map +1 -1
  33. package/cjs/ops/OrganizationOps.js +44 -10
  34. package/cjs/ops/OrganizationOps.js.map +1 -1
  35. package/cjs/ops/PolicyOps.js +86 -24
  36. package/cjs/ops/PolicyOps.js.map +1 -1
  37. package/cjs/ops/PolicySetOps.js +72 -18
  38. package/cjs/ops/PolicySetOps.js.map +1 -1
  39. package/cjs/ops/ResourceTypeOps.js +24 -6
  40. package/cjs/ops/ResourceTypeOps.js.map +1 -1
  41. package/cjs/ops/Saml2Ops.js +120 -33
  42. package/cjs/ops/Saml2Ops.js.map +1 -1
  43. package/cjs/ops/Saml2Ops.test.js.map +1 -1
  44. package/cjs/ops/ScriptOps.js +73 -17
  45. package/cjs/ops/ScriptOps.js.map +1 -1
  46. package/cjs/ops/ServiceOps.js +152 -35
  47. package/cjs/ops/ServiceOps.js.map +1 -1
  48. package/cjs/ops/ThemeOps.js +20 -5
  49. package/cjs/ops/ThemeOps.js.map +1 -1
  50. package/cjs/ops/cloud/FeatureOps.js +4 -1
  51. package/cjs/ops/cloud/FeatureOps.js.map +1 -1
  52. package/cjs/ops/cloud/SecretsOps.js.map +1 -1
  53. package/cjs/ops/cloud/ServiceAccountOps.js +24 -6
  54. package/cjs/ops/cloud/ServiceAccountOps.js.map +1 -1
  55. package/cjs/ops/cloud/StartupOps.js +55 -11
  56. package/cjs/ops/cloud/StartupOps.js.map +1 -1
  57. package/cjs/ops/utils/Console.js +47 -22
  58. package/cjs/ops/utils/Console.js.map +1 -1
  59. package/cjs/ops/utils/DataProtection.js +12 -5
  60. package/cjs/ops/utils/DataProtection.js.map +1 -1
  61. package/cjs/ops/utils/DataProtection.test.js.map +1 -1
  62. package/cjs/ops/utils/ExportImportUtils.js +15 -8
  63. package/cjs/ops/utils/ExportImportUtils.js.map +1 -1
  64. package/cjs/ops/utils/ScriptValidationUtils.js +33 -8
  65. package/cjs/ops/utils/ScriptValidationUtils.js.map +1 -1
  66. package/cjs/ops/utils/ScriptValidationUtils.test.js.map +1 -1
  67. package/cjs/utils/SetupPollyForFrodoLib.js +67 -19
  68. package/cjs/utils/SetupPollyForFrodoLib.js.map +1 -1
  69. package/esm/api/AgentApi.mjs +64 -16
  70. package/esm/api/ApiTypes.mjs +1 -50
  71. package/esm/api/BaseApi.mjs +21 -11
  72. package/esm/api/cloud/SecretsApi.mjs +0 -5
  73. package/esm/api/cloud/SecretsApi.test.mjs +3 -3
  74. package/esm/ops/AdminOps.mjs +254 -60
  75. package/esm/ops/AgentOps.mjs +352 -104
  76. package/esm/ops/AuthenticateOps.mjs +253 -60
  77. package/esm/ops/CirclesOfTrustOps.mjs +16 -4
  78. package/esm/ops/ConnectionProfileOps.mjs +163 -40
  79. package/esm/ops/EmailTemplateOps.mjs +5 -0
  80. package/esm/ops/IdpOps.mjs +55 -12
  81. package/esm/ops/JourneyOps.mjs +639 -132
  82. package/esm/ops/NodeOps.mjs +90 -19
  83. package/esm/ops/OAuth2ClientOps.mjs +45 -11
  84. package/esm/ops/OpsTypes.mjs +1 -22
  85. package/esm/ops/OrganizationOps.mjs +44 -10
  86. package/esm/ops/PolicyOps.mjs +86 -24
  87. package/esm/ops/PolicySetOps.mjs +72 -18
  88. package/esm/ops/ResourceTypeOps.mjs +24 -6
  89. package/esm/ops/Saml2Ops.mjs +120 -33
  90. package/esm/ops/Saml2Ops.test.mjs +10 -11
  91. package/esm/ops/ScriptOps.mjs +73 -17
  92. package/esm/ops/ServiceOps.mjs +152 -35
  93. package/esm/ops/ThemeOps.mjs +20 -5
  94. package/esm/ops/cloud/FeatureOps.mjs +4 -1
  95. package/esm/ops/cloud/ServiceAccountOps.mjs +24 -6
  96. package/esm/ops/cloud/StartupOps.mjs +55 -11
  97. package/esm/ops/utils/Console.mjs +33 -9
  98. package/esm/ops/utils/DataProtection.mjs +9 -2
  99. package/esm/ops/utils/DataProtection.test.mjs +8 -2
  100. package/esm/ops/utils/ExportImportUtils.mjs +15 -8
  101. package/esm/ops/utils/ScriptValidationUtils.mjs +30 -8
  102. package/esm/ops/utils/ScriptValidationUtils.test.mjs +14 -3
  103. package/esm/utils/SetupPollyForFrodoLib.mjs +64 -18
  104. package/package.json +1 -1
  105. package/types/api/AgentApi.d.ts +6 -6
  106. package/types/api/AgentApi.d.ts.map +1 -1
  107. package/types/api/ApiTypes.d.ts +12 -49
  108. package/types/api/ApiTypes.d.ts.map +1 -1
  109. package/types/api/BaseApi.d.ts.map +1 -1
  110. package/types/api/cloud/SecretsApi.d.ts +1 -4
  111. package/types/api/cloud/SecretsApi.d.ts.map +1 -1
  112. package/types/ops/AdminOps.d.ts.map +1 -1
  113. package/types/ops/AgentOps.d.ts +3 -6
  114. package/types/ops/AgentOps.d.ts.map +1 -1
  115. package/types/ops/AuthenticateOps.d.ts.map +1 -1
  116. package/types/ops/CirclesOfTrustOps.d.ts.map +1 -1
  117. package/types/ops/ConnectionProfileOps.d.ts.map +1 -1
  118. package/types/ops/EmailTemplateOps.d.ts +4 -0
  119. package/types/ops/EmailTemplateOps.d.ts.map +1 -1
  120. package/types/ops/IdpOps.d.ts.map +1 -1
  121. package/types/ops/JourneyOps.d.ts +10 -4
  122. package/types/ops/JourneyOps.d.ts.map +1 -1
  123. package/types/ops/NodeOps.d.ts +10 -4
  124. package/types/ops/NodeOps.d.ts.map +1 -1
  125. package/types/ops/OAuth2ClientOps.d.ts.map +1 -1
  126. package/types/ops/OpsTypes.d.ts +2 -12
  127. package/types/ops/OpsTypes.d.ts.map +1 -1
  128. package/types/ops/OrganizationOps.d.ts.map +1 -1
  129. package/types/ops/PolicyOps.d.ts.map +1 -1
  130. package/types/ops/PolicySetOps.d.ts.map +1 -1
  131. package/types/ops/ResourceTypeOps.d.ts.map +1 -1
  132. package/types/ops/Saml2Ops.d.ts.map +1 -1
  133. package/types/ops/ScriptOps.d.ts.map +1 -1
  134. package/types/ops/ServiceOps.d.ts.map +1 -1
  135. package/types/ops/ThemeOps.d.ts.map +1 -1
  136. package/types/ops/cloud/FeatureOps.d.ts.map +1 -1
  137. package/types/ops/cloud/SecretsOps.d.ts +1 -1
  138. package/types/ops/cloud/SecretsOps.d.ts.map +1 -1
  139. package/types/ops/cloud/ServiceAccountOps.d.ts.map +1 -1
  140. package/types/ops/cloud/StartupOps.d.ts.map +1 -1
  141. package/types/ops/utils/Console.d.ts +34 -7
  142. package/types/ops/utils/Console.d.ts.map +1 -1
  143. package/types/ops/utils/DataProtection.d.ts +5 -1
  144. package/types/ops/utils/DataProtection.d.ts.map +1 -1
  145. package/types/ops/utils/ExportImportUtils.d.ts.map +1 -1
  146. package/types/ops/utils/ScriptValidationUtils.d.ts +14 -4
  147. package/types/ops/utils/ScriptValidationUtils.d.ts.map +1 -1
  148. package/types/utils/SetupPollyForFrodoLib.d.ts +5 -1
  149. package/types/utils/SetupPollyForFrodoLib.d.ts.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/ResourceTypeOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,eAAe,EAEf,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIlB,eAAe,CAAC,gBAAgB,EAAE,MAAM;IAI9C;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAKzD;;;;OAIG;IACG,qBAAqB,CACzB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,oBAAoB,CAAC;IAIhC;;;;OAIG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,oBAAoB,CAAC;IAQ1B,kBAAkB,CAAC,gBAAgB,EAAE,MAAM;IAIjD;;;;OAIG;IACG,wBAAwB,CAC5B,gBAAgB,EAAE,M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,KAAK,EAAE,KAAK,CAAC;CACd,gBAoCA;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,2BAA2B,CAAC;IACxC,KAAK,EAAE,KAAK,CAAC;CACd,kBAoCA;AAED,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,CAAC","file":"ResourceTypeOps.d.ts","sourcesContent":["import {\n deleteResourceType,\n getResourceTypes as _getResourceTypes,\n getResourceType,\n getResourceTypeByName as _getResourceTypeByName,\n createResourceType,\n putResourceType,\n} from '../api/ResourceTypesApi';\nimport { ExportMetaData } from './OpsTypes';\nimport { ResourceTypeSkeleton } from '../api/ApiTypes';\nimport { getMetadata } from './utils/ExportImportUtils';\nimport { debugMessage } from './utils/Console';\nimport State from '../shared/State';\n\nexport default class ResourceTypeOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n async getResourceType(resourceTypeUuid: string) {\n return getResourceType({ resourceTypeUuid, state: this.state });\n }\n\n /**\n * Get all resource types\n * @returns {Promise} a promise that resolves to an array of resource type objects\n */\n async getResourceTypes(): Promise<ResourceTypeSkeleton[]> {\n const { result } = await _getResourceTypes({ state: this.state });\n return result;\n }\n\n /**\n * Get resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\n async getResourceTypeByName(\n resourceTypeName: string\n ): Promise<ResourceTypeSkeleton> {\n return getResourceTypeByName({ resourceTypeName, state: this.state });\n }\n\n /**\n * Update resource type\n * @param {string} resourceTypeData resource type id\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\n async updateResourceType(\n resourceTypeUuid: string,\n resourceTypeData: ResourceTypeSkeleton\n ): Promise<ResourceTypeSkeleton> {\n return updateResourceType({\n resourceTypeUuid,\n resourceTypeData,\n state: this.state,\n });\n }\n\n async deleteResourceType(resourceTypeUuid: string) {\n return deleteResourceType({ resourceTypeUuid, state: this.state });\n }\n\n /**\n * Delete resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} Promise resolvig to a resource type object\n */\n async deleteResourceTypeByName(\n resourceTypeName: string\n ): Promise<ResourceTypeSkeleton> {\n return deleteResourceTypeByName({ resourceTypeName, state: this.state });\n }\n\n /**\n * Export resource type\n * @param {string} resourceTypeUuid resource type uuid\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\n async exportResourceType(\n resourceTypeUuid: string\n ): Promise<ResourceTypeExportInterface> {\n return exportResourceType({ resourceTypeUuid, state: this.state });\n }\n\n /**\n * Export resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\n async exportResourceTypeByName(\n resourceTypeName: string\n ): Promise<ResourceTypeExportInterface> {\n return exportResourceTypeByName({ resourceTypeName, state: this.state });\n }\n\n /**\n * Export resource types\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\n async exportResourceTypes(): Promise<ResourceTypeExportInterface> {\n return exportResourceTypes({ state: this.state });\n }\n\n /**\n * Import resource type by uuid\n * @param {string} resourceTypeUuid client uuid\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importResourceType(\n resourceTypeUuid: string,\n importData: ResourceTypeExportInterface\n ) {\n return importResourceType({\n resourceTypeUuid,\n importData,\n state: this.state,\n });\n }\n\n /**\n * Import resource type by name\n * @param {string} resourceTypeName client id\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importResourceTypeByName(\n resourceTypeName: string,\n importData: ResourceTypeExportInterface\n ) {\n return importResourceTypeByName({\n resourceTypeName,\n importData,\n state: this.state,\n });\n }\n\n /**\n * Import first resource type\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importFirstResourceType(importData: ResourceTypeExportInterface) {\n return importFirstResourceType({ importData, state: this.state });\n }\n\n /**\n * Import resource types\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importResourceTypes(importData: ResourceTypeExportInterface) {\n return importResourceTypes({ importData, state: this.state });\n }\n}\n\nexport interface ResourceTypeExportInterface {\n meta?: ExportMetaData;\n resourcetype: Record<string, ResourceTypeSkeleton>;\n}\n\n/**\n * Create an empty export template\n * @returns {ResourceTypeExportInterface} an empty export template\n */\nfunction createResourceTypeExportTemplate({\n state,\n}: {\n state: State;\n}): ResourceTypeExportInterface {\n return {\n meta: getMetadata({ state }),\n script: {},\n policy: {},\n policyset: {},\n resourcetype: {},\n } as ResourceTypeExportInterface;\n}\n\n/**\n * Get all resource types\n * @returns {Promise} a promise that resolves to an array of resource type objects\n */\nexport async function getResourceTypes({\n state,\n}: {\n state: State;\n}): Promise<ResourceTypeSkeleton[]> {\n const { result } = await _getResourceTypes({ state });\n return result;\n}\n\n/**\n * Get resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\nexport async function getResourceTypeByName({\n resourceTypeName,\n state,\n}: {\n resourceTypeName: string;\n state: State;\n}): Promise<ResourceTypeSkeleton> {\n const { result } = await _getResourceTypeByName({ resourceTypeName, state });\n switch (result.length) {\n case 1:\n return result[0];\n case 0:\n throw new Error(\n `Resource Type with name ${resourceTypeName} does not exist in realm ${state.getRealm()}`\n );\n default:\n throw new Error(\n `${result.length} resource types '${resourceTypeName}' found`\n );\n }\n}\n\n/**\n * Update resource type\n * @param {string} resourceTypeData resource type id\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\nexport async function updateResourceType({\n resourceTypeUuid,\n resourceTypeData,\n state,\n}: {\n resourceTypeUuid: string;\n resourceTypeData: ResourceTypeSkeleton;\n state: State;\n}): Promise<ResourceTypeSkeleton> {\n return putResourceType({ resourceTypeUuid, resourceTypeData, state });\n}\n\n/**\n * Delete resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} Promise resolvig to a resource type object\n */\nexport async function deleteResourceTypeByName({\n resourceTypeName,\n state,\n}: {\n resourceTypeName: string;\n state: State;\n}): Promise<ResourceTypeSkeleton> {\n const resourceTypeUuid = (\n await getResourceTypeByName({ resourceTypeName, state })\n ).uuid;\n return deleteResourceType({ resourceTypeUuid, state });\n}\n\n/**\n * Export resource type\n * @param {string} resourceTypeUuid resource type uuid\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\nexport async function exportResourceType({\n resourceTypeUuid,\n state,\n}: {\n resourceTypeUuid: string;\n state: State;\n}): Promise<ResourceTypeExportInterface> {\n debugMessage(`ResourceTypeOps.exportResourceType: start`);\n const exportData = createResourceTypeExportTemplate({ state });\n const errors = [];\n try {\n const resourceTypeData = await getResourceType({\n resourceTypeUuid,\n state,\n });\n exportData.resourcetype[resourceTypeData.uuid] = resourceTypeData;\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => {\n if (error.response?.status === 404) {\n return `Resource Type with uuid ${resourceTypeUuid} does not exist in realm ${state.getRealm()}`;\n } else {\n return error.response?.data?.message || error.message;\n }\n })\n .join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage(`ResourceTypeOps.exportResourceType: end`);\n return exportData;\n}\n\n/**\n * Export resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\nexport async function exportResourceTypeByName({\n resourceTypeName,\n state,\n}: {\n resourceTypeName: string;\n state: State;\n}): Promise<ResourceTypeExportInterface> {\n debugMessage(`ResourceTypeOps.exportResourceTypeByName: start`);\n const exportData = createResourceTypeExportTemplate({ state });\n const errors = [];\n try {\n const resourceTypeData = await getResourceTypeByName({\n resourceTypeName,\n state,\n });\n exportData.resourcetype[resourceTypeData.uuid] = resourceTypeData;\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage(`ResourceTypeOps.exportResourceTypeByName: end`);\n return exportData;\n}\n\n/**\n * Export resource types\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\nexport async function exportResourceTypes({\n state,\n}: {\n state: State;\n}): Promise<ResourceTypeExportInterface> {\n debugMessage(`ResourceTypeOps.exportResourceType: start`);\n const exportData = createResourceTypeExportTemplate({ state });\n const errors = [];\n try {\n const resourceTypes = await getResourceTypes({ state });\n for (const resourceTypeData of resourceTypes) {\n exportData.resourcetype[resourceTypeData.uuid] = resourceTypeData;\n }\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage(`ResourceTypeOps.exportResourceType: end`);\n return exportData;\n}\n\n/**\n * Import resource type by uuid\n * @param {string} resourceTypeUuid client uuid\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importResourceType({\n resourceTypeUuid,\n importData,\n state,\n}: {\n resourceTypeUuid: string;\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n if (id === resourceTypeUuid) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._rev;\n try {\n response = await createResourceType({ resourceTypeData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(\n `Import error:\\n${resourceTypeUuid} not found in import data!`\n );\n }\n return response;\n}\n\n/**\n * Import resource type by name\n * @param {string} resourceTypeName client id\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importResourceTypeByName({\n resourceTypeName,\n importData,\n state,\n}: {\n resourceTypeName: string;\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n if (importData.resourcetype[id].name === resourceTypeName) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._rev;\n try {\n response = await createResourceType({ resourceTypeData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(\n `Import error:\\n${resourceTypeName} not found in import data!`\n );\n }\n return response;\n}\n\n/**\n * Import first resource type\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importFirstResourceType({\n importData,\n state,\n}: {\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._provider;\n delete resourceTypeData._rev;\n try {\n response = await createResourceType({ resourceTypeData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n break;\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo resource types found in import data!`);\n }\n return response;\n}\n\n/**\n * Import resource types\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importResourceTypes({\n importData,\n state,\n}: {\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n const response = [];\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._rev;\n try {\n response.push(await createResourceType({ resourceTypeData, state }));\n } catch (createError) {\n if (createError.response?.status === 409)\n response.push(\n await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n })\n );\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo resource types found in import data!`);\n }\n return response;\n}\n\nexport { getResourceType, createResourceType, deleteResourceType };\n"]}
1
+ {"version":3,"sources":["../src/ops/ResourceTypeOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,eAAe,EAEf,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIlB,eAAe,CAAC,gBAAgB,EAAE,MAAM;IAI9C;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAKzD;;;;OAIG;IACG,qBAAqB,CACzB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,oBAAoB,CAAC;IAIhC;;;;OAIG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,oBAAoB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AGG;AACH,wBAAsB,uBAAuB,CAAC,EAC5C,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,2BAA2B,CAAC;IACxC,KAAK,EAAE,KAAK,CAAC;CACd,gBAoCA;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,2BAA2B,CAAC;IACxC,KAAK,EAAE,KAAK,CAAC;CACd,kBAoCA;AAED,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,CAAC","file":"ResourceTypeOps.d.ts","sourcesContent":["import {\n deleteResourceType,\n getResourceTypes as _getResourceTypes,\n getResourceType,\n getResourceTypeByName as _getResourceTypeByName,\n createResourceType,\n putResourceType,\n} from '../api/ResourceTypesApi';\nimport { ExportMetaData } from './OpsTypes';\nimport { ResourceTypeSkeleton } from '../api/ApiTypes';\nimport { getMetadata } from './utils/ExportImportUtils';\nimport { debugMessage } from './utils/Console';\nimport State from '../shared/State';\n\nexport default class ResourceTypeOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n async getResourceType(resourceTypeUuid: string) {\n return getResourceType({ resourceTypeUuid, state: this.state });\n }\n\n /**\n * Get all resource types\n * @returns {Promise} a promise that resolves to an array of resource type objects\n */\n async getResourceTypes(): Promise<ResourceTypeSkeleton[]> {\n const { result } = await _getResourceTypes({ state: this.state });\n return result;\n }\n\n /**\n * Get resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\n async getResourceTypeByName(\n resourceTypeName: string\n ): Promise<ResourceTypeSkeleton> {\n return getResourceTypeByName({ resourceTypeName, state: this.state });\n }\n\n /**\n * Update resource type\n * @param {string} resourceTypeData resource type id\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\n async updateResourceType(\n resourceTypeUuid: string,\n resourceTypeData: ResourceTypeSkeleton\n ): Promise<ResourceTypeSkeleton> {\n return updateResourceType({\n resourceTypeUuid,\n resourceTypeData,\n state: this.state,\n });\n }\n\n async deleteResourceType(resourceTypeUuid: string) {\n return deleteResourceType({ resourceTypeUuid, state: this.state });\n }\n\n /**\n * Delete resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} Promise resolvig to a resource type object\n */\n async deleteResourceTypeByName(\n resourceTypeName: string\n ): Promise<ResourceTypeSkeleton> {\n return deleteResourceTypeByName({ resourceTypeName, state: this.state });\n }\n\n /**\n * Export resource type\n * @param {string} resourceTypeUuid resource type uuid\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\n async exportResourceType(\n resourceTypeUuid: string\n ): Promise<ResourceTypeExportInterface> {\n return exportResourceType({ resourceTypeUuid, state: this.state });\n }\n\n /**\n * Export resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\n async exportResourceTypeByName(\n resourceTypeName: string\n ): Promise<ResourceTypeExportInterface> {\n return exportResourceTypeByName({ resourceTypeName, state: this.state });\n }\n\n /**\n * Export resource types\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\n async exportResourceTypes(): Promise<ResourceTypeExportInterface> {\n return exportResourceTypes({ state: this.state });\n }\n\n /**\n * Import resource type by uuid\n * @param {string} resourceTypeUuid client uuid\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importResourceType(\n resourceTypeUuid: string,\n importData: ResourceTypeExportInterface\n ) {\n return importResourceType({\n resourceTypeUuid,\n importData,\n state: this.state,\n });\n }\n\n /**\n * Import resource type by name\n * @param {string} resourceTypeName client id\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importResourceTypeByName(\n resourceTypeName: string,\n importData: ResourceTypeExportInterface\n ) {\n return importResourceTypeByName({\n resourceTypeName,\n importData,\n state: this.state,\n });\n }\n\n /**\n * Import first resource type\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importFirstResourceType(importData: ResourceTypeExportInterface) {\n return importFirstResourceType({ importData, state: this.state });\n }\n\n /**\n * Import resource types\n * @param {ResourceTypeExportInterface} importData import data\n */\n async importResourceTypes(importData: ResourceTypeExportInterface) {\n return importResourceTypes({ importData, state: this.state });\n }\n}\n\nexport interface ResourceTypeExportInterface {\n meta?: ExportMetaData;\n resourcetype: Record<string, ResourceTypeSkeleton>;\n}\n\n/**\n * Create an empty export template\n * @returns {ResourceTypeExportInterface} an empty export template\n */\nfunction createResourceTypeExportTemplate({\n state,\n}: {\n state: State;\n}): ResourceTypeExportInterface {\n return {\n meta: getMetadata({ state }),\n script: {},\n policy: {},\n policyset: {},\n resourcetype: {},\n } as ResourceTypeExportInterface;\n}\n\n/**\n * Get all resource types\n * @returns {Promise} a promise that resolves to an array of resource type objects\n */\nexport async function getResourceTypes({\n state,\n}: {\n state: State;\n}): Promise<ResourceTypeSkeleton[]> {\n const { result } = await _getResourceTypes({ state });\n return result;\n}\n\n/**\n * Get resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\nexport async function getResourceTypeByName({\n resourceTypeName,\n state,\n}: {\n resourceTypeName: string;\n state: State;\n}): Promise<ResourceTypeSkeleton> {\n const { result } = await _getResourceTypeByName({ resourceTypeName, state });\n switch (result.length) {\n case 1:\n return result[0];\n case 0:\n throw new Error(\n `Resource Type with name ${resourceTypeName} does not exist in realm ${state.getRealm()}`\n );\n default:\n throw new Error(\n `${result.length} resource types '${resourceTypeName}' found`\n );\n }\n}\n\n/**\n * Update resource type\n * @param {string} resourceTypeData resource type id\n * @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object\n */\nexport async function updateResourceType({\n resourceTypeUuid,\n resourceTypeData,\n state,\n}: {\n resourceTypeUuid: string;\n resourceTypeData: ResourceTypeSkeleton;\n state: State;\n}): Promise<ResourceTypeSkeleton> {\n return putResourceType({ resourceTypeUuid, resourceTypeData, state });\n}\n\n/**\n * Delete resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeSkeleton>} Promise resolvig to a resource type object\n */\nexport async function deleteResourceTypeByName({\n resourceTypeName,\n state,\n}: {\n resourceTypeName: string;\n state: State;\n}): Promise<ResourceTypeSkeleton> {\n const resourceTypeUuid = (\n await getResourceTypeByName({ resourceTypeName, state })\n ).uuid;\n return deleteResourceType({ resourceTypeUuid, state });\n}\n\n/**\n * Export resource type\n * @param {string} resourceTypeUuid resource type uuid\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\nexport async function exportResourceType({\n resourceTypeUuid,\n state,\n}: {\n resourceTypeUuid: string;\n state: State;\n}): Promise<ResourceTypeExportInterface> {\n debugMessage({ message: `ResourceTypeOps.exportResourceType: start`, state });\n const exportData = createResourceTypeExportTemplate({ state });\n const errors = [];\n try {\n const resourceTypeData = await getResourceType({\n resourceTypeUuid,\n state,\n });\n exportData.resourcetype[resourceTypeData.uuid] = resourceTypeData;\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => {\n if (error.response?.status === 404) {\n return `Resource Type with uuid ${resourceTypeUuid} does not exist in realm ${state.getRealm()}`;\n } else {\n return error.response?.data?.message || error.message;\n }\n })\n .join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage({ message: `ResourceTypeOps.exportResourceType: end`, state });\n return exportData;\n}\n\n/**\n * Export resource type by name\n * @param {string} resourceTypeName resource type name\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\nexport async function exportResourceTypeByName({\n resourceTypeName,\n state,\n}: {\n resourceTypeName: string;\n state: State;\n}): Promise<ResourceTypeExportInterface> {\n debugMessage({\n message: `ResourceTypeOps.exportResourceTypeByName: start`,\n state,\n });\n const exportData = createResourceTypeExportTemplate({ state });\n const errors = [];\n try {\n const resourceTypeData = await getResourceTypeByName({\n resourceTypeName,\n state,\n });\n exportData.resourcetype[resourceTypeData.uuid] = resourceTypeData;\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage({\n message: `ResourceTypeOps.exportResourceTypeByName: end`,\n state,\n });\n return exportData;\n}\n\n/**\n * Export resource types\n * @returns {Promise<ResourceTypeExportInterface>} a promise that resolves to an ResourceTypeExportInterface object\n */\nexport async function exportResourceTypes({\n state,\n}: {\n state: State;\n}): Promise<ResourceTypeExportInterface> {\n debugMessage({ message: `ResourceTypeOps.exportResourceType: start`, state });\n const exportData = createResourceTypeExportTemplate({ state });\n const errors = [];\n try {\n const resourceTypes = await getResourceTypes({ state });\n for (const resourceTypeData of resourceTypes) {\n exportData.resourcetype[resourceTypeData.uuid] = resourceTypeData;\n }\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage({ message: `ResourceTypeOps.exportResourceType: end`, state });\n return exportData;\n}\n\n/**\n * Import resource type by uuid\n * @param {string} resourceTypeUuid client uuid\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importResourceType({\n resourceTypeUuid,\n importData,\n state,\n}: {\n resourceTypeUuid: string;\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n if (id === resourceTypeUuid) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._rev;\n try {\n response = await createResourceType({ resourceTypeData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(\n `Import error:\\n${resourceTypeUuid} not found in import data!`\n );\n }\n return response;\n}\n\n/**\n * Import resource type by name\n * @param {string} resourceTypeName client id\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importResourceTypeByName({\n resourceTypeName,\n importData,\n state,\n}: {\n resourceTypeName: string;\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n if (importData.resourcetype[id].name === resourceTypeName) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._rev;\n try {\n response = await createResourceType({ resourceTypeData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(\n `Import error:\\n${resourceTypeName} not found in import data!`\n );\n }\n return response;\n}\n\n/**\n * Import first resource type\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importFirstResourceType({\n importData,\n state,\n}: {\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._provider;\n delete resourceTypeData._rev;\n try {\n response = await createResourceType({ resourceTypeData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n break;\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo resource types found in import data!`);\n }\n return response;\n}\n\n/**\n * Import resource types\n * @param {ResourceTypeExportInterface} importData import data\n */\nexport async function importResourceTypes({\n importData,\n state,\n}: {\n importData: ResourceTypeExportInterface;\n state: State;\n}) {\n const response = [];\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.resourcetype)) {\n try {\n const resourceTypeData = importData.resourcetype[id];\n delete resourceTypeData._rev;\n try {\n response.push(await createResourceType({ resourceTypeData, state }));\n } catch (createError) {\n if (createError.response?.status === 409)\n response.push(\n await putResourceType({\n resourceTypeUuid: id,\n resourceTypeData,\n state,\n })\n );\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo resource types found in import data!`);\n }\n return response;\n}\n\nexport { getResourceType, createResourceType, deleteResourceType };\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/Saml2Ops.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAkBzB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAU1E,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,qBAAqB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAI3D;;;;;OAKG;IACG,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQrE;;;;OAIG;IACH,sBAAsB,CAAC,QAA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ACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAiBhC;AAmED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,QAAQ,EACR,UAAU,EACV,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,oBAAoB,CAAC;IACjC,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BnB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,oBAAoB,CAAC;IACjC,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA+DlC","file":"Saml2Ops.d.ts","sourcesContent":["import _ from 'lodash';\nimport {\n Saml2ProiderLocation,\n Saml2ProviderSkeleton,\n Saml2ProviderStub,\n} from '../api/ApiTypes';\nimport {\n createProvider,\n updateProvider,\n findProviders,\n getProviderByLocationAndId as _getProviderByLocationAndId,\n getProviderMetadata as _getProviderMetadata,\n getProviderMetadataUrl as _getProviderMetadataUrl,\n getProviders,\n deleteProviderByLocationAndId,\n} from '../api/Saml2Api';\nimport { getScript } from '../api/ScriptApi';\nimport {\n decode,\n decodeBase64Url,\n encode,\n encodeBase64Url,\n} from '../api/utils/Base64';\nimport { MultiOpStatusInterface, Saml2ExportInterface } from './OpsTypes';\nimport { putScript } from './ScriptOps';\nimport { debugMessage, printMessage } from './utils/Console';\nimport {\n convertBase64TextToArray,\n convertBase64UrlTextToArray,\n convertTextArrayToBase64,\n convertTextArrayToBase64Url,\n getMetadata,\n} from './utils/ExportImportUtils';\nimport State from '../shared/State';\n\nexport default class Saml2Ops {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\n async getSaml2ProviderStubs(): Promise<Saml2ProviderStub[]> {\n return getSaml2ProviderStubs({ state: this.state });\n }\n\n /**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\n async getProviderByLocationAndId(location: string, entityId64: string) {\n return getProviderByLocationAndId({\n location,\n entityId64,\n state: this.state,\n });\n }\n\n /**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\n getProviderMetadataUrl(entityId: string): string {\n return getProviderMetadataUrl({ entityId, state: this.state });\n }\n\n /**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\n async getProviderMetadata(entityId: string) {\n return getProviderMetadata({ entityId, state: this.state });\n }\n\n /**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\n async getSaml2ProviderStub(entityId: string): Promise<Saml2ProviderStub> {\n return getSaml2ProviderStub({ entityId, state: this.state });\n }\n\n /**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\n async getSaml2Provider(entityId: string): Promise<Saml2ProviderSkeleton> {\n return getSaml2Provider({ entityId, state: this.state });\n }\n\n /**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\n async deleteSaml2Provider(entityId: string): Promise<Saml2ProviderSkeleton> {\n return deleteSaml2Provider({ entityId, state: this.state });\n }\n\n /**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\n async deleteSaml2Providers(): Promise<Saml2ProviderSkeleton[]> {\n return deleteSaml2Providers({ state: this.state });\n }\n\n /**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\n async exportSaml2Provider(entityId: string): Promise<Saml2ExportInterface> {\n return exportSaml2Provider({ entityId, state: this.state });\n }\n\n /**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\n async exportSaml2Providers(): Promise<Saml2ExportInterface> {\n return exportSaml2Providers({ state: this.state });\n }\n\n /**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\n async importSaml2Provider(\n entityId: string,\n importData: Saml2ExportInterface\n ): Promise<boolean> {\n return importSaml2Provider({ entityId, importData, state: this.state });\n }\n\n /**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\n async importSaml2Providers(\n importData: Saml2ExportInterface\n ): Promise<MultiOpStatusInterface> {\n return importSaml2Providers({ importData, state: this.state });\n }\n}\n\n// use a function vs a template variable to avoid problems in loops\nexport function createSaml2ExportTemplate({\n state,\n}: {\n state: State;\n}): Saml2ExportInterface {\n return {\n meta: getMetadata({ state }),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n },\n } as Saml2ExportInterface;\n}\n\n/**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getSaml2ProviderStubs({\n state,\n}: {\n state: State;\n}): Promise<Saml2ProviderStub[]> {\n const { result } = await getProviders({ state });\n return result;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId({\n location,\n entityId64,\n state,\n}: {\n location: string;\n entityId64: string;\n state: State;\n}) {\n return _getProviderByLocationAndId({ location, entityId64, state });\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): string {\n return _getProviderMetadataUrl({ entityId, state });\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}) {\n return _getProviderMetadata({ entityId, state });\n}\n\n/**\n * Include dependencies in the export file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to add dependencies to\n */\nasync function exportDependencies({\n providerData,\n fileData,\n state,\n}: {\n providerData: Saml2ProviderSkeleton;\n fileData: Saml2ExportInterface;\n state: State;\n}) {\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n const scriptData = await getScript({ scriptId: attrMapperScriptId, state });\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[attrMapperScriptId] = scriptData;\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n const scriptData = await getScript({ scriptId: idpAdapterScriptId, state });\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpAdapterScriptId] = scriptData;\n }\n const metaDataResponse = await getProviderMetadata({\n entityId: providerData.entityId,\n state,\n });\n if (!metaDataResponse) {\n throw new Error(\n `Unable to obtain metadata from ${getProviderMetadataUrl({\n entityId: providerData.entityId,\n state,\n })}`\n );\n }\n fileData.saml.metadata[providerData._id] = convertBase64UrlTextToArray(\n encodeBase64Url(metaDataResponse)\n );\n}\n\n/**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2ProviderStub({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ProviderStub> {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: start [entityId=${entityId}]`);\n const found = await findProviders({\n filter: `entityId eq '${entityId}'`,\n state,\n });\n switch (found.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: end [entityId=${entityId}]`);\n return found.result[0];\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2Provider({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.getSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub({ entityId, state });\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId({\n location,\n entityId64: id,\n state,\n });\n debugMessage(`Saml2Ops.getSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteSaml2Provider({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub({ entityId, state });\n const { location } = stub;\n const id = stub._id;\n const providerData = await deleteProviderByLocationAndId({\n location,\n entityId64: id,\n state,\n });\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\nexport async function deleteSaml2Providers({\n state,\n}: {\n state: State;\n}): Promise<Saml2ProviderSkeleton[]> {\n debugMessage(`Saml2Ops.deleteSaml2Providers: start`);\n const providers: Saml2ProviderSkeleton[] = [];\n const stubs = await getSaml2ProviderStubs({ state });\n for (const stub of stubs) {\n const provider = await deleteProviderByLocationAndId({\n location: stub.location,\n entityId64: stub._id,\n state,\n });\n providers.push(provider);\n }\n debugMessage(\n `Saml2Ops.deleteSaml2Providers: end [deleted ${providers.length} providers]`\n );\n return providers;\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Provider({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ExportInterface> {\n debugMessage(`Saml2Ops.exportSaml2Provider: start [entityId=${entityId}]`);\n const exportData = createSaml2ExportTemplate({ state });\n const stub = await getSaml2ProviderStub({ entityId, state });\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId({\n location,\n entityId64: id,\n state,\n });\n exportData.saml[stub.location][providerData._id] = providerData;\n try {\n await exportDependencies({ providerData, fileData: exportData, state });\n } catch (error) {\n printMessage(error.message, 'error');\n }\n debugMessage(`Saml2Ops.exportSaml2Provider: end [entityId=${entityId}]`);\n return exportData;\n}\n\n/**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Providers({\n state,\n}: {\n state: State;\n}): Promise<Saml2ExportInterface> {\n const fileData = createSaml2ExportTemplate({ state });\n const stubs = await getSaml2ProviderStubs({ state });\n for (const stub of stubs) {\n const providerData = await getProviderByLocationAndId({\n location: stub.location,\n entityId64: stub._id,\n state,\n });\n try {\n await exportDependencies({ providerData, fileData, state });\n } catch (error) {\n printMessage(error, 'error');\n }\n fileData.saml[stub.location][providerData._id] = providerData;\n }\n return fileData;\n}\n\n/**\n * Include dependencies from the import file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to read dependencies from\n */\nasync function importDependencies({\n providerData,\n fileData,\n state,\n}: {\n providerData: Saml2ProviderSkeleton;\n fileData: Saml2ExportInterface;\n state: State;\n}) {\n debugMessage(`Saml2Ops.importDependencies: start`);\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: attributeMapperScript=${attrMapperScriptId}`\n );\n const scriptData = _.get(fileData, ['script', attrMapperScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script as string[]);\n await putScript({ scriptId: attrMapperScriptId, scriptData, state });\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: idpAdapterScript=${idpAdapterScriptId}`\n );\n const scriptData = _.get(fileData, ['script', idpAdapterScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script as string[]);\n await putScript({ scriptId: idpAdapterScriptId, scriptData, state });\n }\n debugMessage(`Saml2Ops.importDependencies: end`);\n}\n\n/**\n * Find provider in import file and return its location\n * @param {string} entityId64 Base64-encoded provider entity id\n * @param {Saml2ExportInterface} data Import file json data\n * @returns {string} 'hosted' or 'remote' if found, undefined otherwise\n */\nfunction getLocation(\n entityId64: string,\n data: Saml2ExportInterface\n): Saml2ProiderLocation {\n if (data.saml.hosted[entityId64]) {\n return Saml2ProiderLocation.HOSTED;\n }\n if (data.saml.remote[entityId64]) {\n return Saml2ProiderLocation.REMOTE;\n }\n return undefined;\n}\n\n/**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Provider({\n entityId,\n importData,\n state,\n}: {\n entityId: string;\n importData: Saml2ExportInterface;\n state: State;\n}): Promise<boolean> {\n debugMessage(`Saml2Ops.importSaml2Provider: start`);\n const entityId64 = encode(entityId, false);\n const location = getLocation(entityId64, importData);\n debugMessage(\n `Saml2Ops.importSaml2Provider: entityId=${entityId}, entityId64=${entityId64}, location=${location}`\n );\n if (location) {\n const providerData = importData.saml[location][entityId64];\n await importDependencies({ providerData, fileData: importData, state });\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider({ location, providerData, metaData, state });\n } catch (error) {\n await updateProvider({ location, providerData, state });\n }\n } else {\n throw new Error(`Provider ${entityId} not found in import data!`);\n }\n debugMessage(`Saml2Ops.importSaml2Provider: end`);\n return true;\n}\n\n/**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Providers({\n importData,\n state,\n}: {\n importData: Saml2ExportInterface;\n state: State;\n}): Promise<MultiOpStatusInterface> {\n debugMessage(`Saml2Ops.importSaml2Providers: start`);\n const myStatus: MultiOpStatusInterface = {\n total: 0,\n successes: 0,\n warnings: 0,\n failures: 0,\n };\n try {\n // find providers in hosted and in remote and map locations\n const hostedIds = Object.keys(importData.saml.hosted);\n const remoteIds = Object.keys(importData.saml.remote);\n const providerIds = hostedIds.concat(remoteIds);\n myStatus.total = providerIds.length;\n for (const entityId64 of providerIds) {\n debugMessage(\n `Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(entityId64)}`\n );\n const location = hostedIds.includes(entityId64)\n ? Saml2ProiderLocation.HOSTED\n : Saml2ProiderLocation.REMOTE;\n const entityId = decode(entityId64);\n const providerData = importData.saml[location][entityId64];\n try {\n await importDependencies({ providerData, fileData: importData, state });\n } catch (importDependenciesErr) {\n myStatus.warnings += 1;\n printMessage(\n `\\nWarning importing dependencies for ${entityId}`,\n 'warn'\n );\n printMessage(importDependenciesErr.response.data, 'error');\n }\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider({ location, providerData, metaData, state });\n myStatus.successes += 1;\n } catch (createProviderErr) {\n try {\n await updateProvider({ location, providerData, state });\n myStatus.successes += 1;\n } catch (updateProviderError) {\n myStatus.failures += 1;\n printMessage(\n `\\nError importing provider ${entityId}: ${updateProviderError.message}`,\n 'error'\n );\n printMessage(updateProviderError.response?.data, 'error');\n }\n }\n }\n myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;\n } catch (error) {\n myStatus.failures += 1;\n printMessage(`\\nError importing providers ${error.message}`, 'error');\n }\n debugMessage(`Saml2Ops.importSaml2Providers: end`);\n return myStatus;\n}\n"]}
1
+ {"version":3,"sources":["../src/ops/Saml2Ops.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAkBzB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAU1E,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,qBAAqB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAI3D;;;;;OAKG;IACG,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQrE;;;;OAIG;IACH,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM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AC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAiBhC;AAqED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,QAAQ,EACR,UAAU,EACV,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,oBAAoB,CAAC;IACjC,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA2BnB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,oBAAoB,CAAC;IACjC,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAgFlC","file":"Saml2Ops.d.ts","sourcesContent":["import _ from 'lodash';\nimport {\n Saml2ProiderLocation,\n Saml2ProviderSkeleton,\n Saml2ProviderStub,\n} from '../api/ApiTypes';\nimport {\n createProvider,\n updateProvider,\n findProviders,\n getProviderByLocationAndId as _getProviderByLocationAndId,\n getProviderMetadata as _getProviderMetadata,\n getProviderMetadataUrl as _getProviderMetadataUrl,\n getProviders,\n deleteProviderByLocationAndId,\n} from '../api/Saml2Api';\nimport { getScript } from '../api/ScriptApi';\nimport {\n decode,\n decodeBase64Url,\n encode,\n encodeBase64Url,\n} from '../api/utils/Base64';\nimport { MultiOpStatusInterface, Saml2ExportInterface } from './OpsTypes';\nimport { putScript } from './ScriptOps';\nimport { debugMessage, printMessage } from './utils/Console';\nimport {\n convertBase64TextToArray,\n convertBase64UrlTextToArray,\n convertTextArrayToBase64,\n convertTextArrayToBase64Url,\n getMetadata,\n} from './utils/ExportImportUtils';\nimport State from '../shared/State';\n\nexport default class Saml2Ops {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\n async getSaml2ProviderStubs(): Promise<Saml2ProviderStub[]> {\n return getSaml2ProviderStubs({ state: this.state });\n }\n\n /**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\n async getProviderByLocationAndId(location: string, entityId64: string) {\n return getProviderByLocationAndId({\n location,\n entityId64,\n state: this.state,\n });\n }\n\n /**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\n getProviderMetadataUrl(entityId: string): string {\n return getProviderMetadataUrl({ entityId, state: this.state });\n }\n\n /**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\n async getProviderMetadata(entityId: string) {\n return getProviderMetadata({ entityId, state: this.state });\n }\n\n /**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\n async getSaml2ProviderStub(entityId: string): Promise<Saml2ProviderStub> {\n return getSaml2ProviderStub({ entityId, state: this.state });\n }\n\n /**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\n async getSaml2Provider(entityId: string): Promise<Saml2ProviderSkeleton> {\n return getSaml2Provider({ entityId, state: this.state });\n }\n\n /**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\n async deleteSaml2Provider(entityId: string): Promise<Saml2ProviderSkeleton> {\n return deleteSaml2Provider({ entityId, state: this.state });\n }\n\n /**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\n async deleteSaml2Providers(): Promise<Saml2ProviderSkeleton[]> {\n return deleteSaml2Providers({ state: this.state });\n }\n\n /**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\n async exportSaml2Provider(entityId: string): Promise<Saml2ExportInterface> {\n return exportSaml2Provider({ entityId, state: this.state });\n }\n\n /**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\n async exportSaml2Providers(): Promise<Saml2ExportInterface> {\n return exportSaml2Providers({ state: this.state });\n }\n\n /**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\n async importSaml2Provider(\n entityId: string,\n importData: Saml2ExportInterface\n ): Promise<boolean> {\n return importSaml2Provider({ entityId, importData, state: this.state });\n }\n\n /**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\n async importSaml2Providers(\n importData: Saml2ExportInterface\n ): Promise<MultiOpStatusInterface> {\n return importSaml2Providers({ importData, state: this.state });\n }\n}\n\n// use a function vs a template variable to avoid problems in loops\nexport function createSaml2ExportTemplate({\n state,\n}: {\n state: State;\n}): Saml2ExportInterface {\n return {\n meta: getMetadata({ state }),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n },\n } as Saml2ExportInterface;\n}\n\n/**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getSaml2ProviderStubs({\n state,\n}: {\n state: State;\n}): Promise<Saml2ProviderStub[]> {\n const { result } = await getProviders({ state });\n return result;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId({\n location,\n entityId64,\n state,\n}: {\n location: string;\n entityId64: string;\n state: State;\n}) {\n return _getProviderByLocationAndId({ location, entityId64, state });\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): string {\n return _getProviderMetadataUrl({ entityId, state });\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}) {\n return _getProviderMetadata({ entityId, state });\n}\n\n/**\n * Include dependencies in the export file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to add dependencies to\n */\nasync function exportDependencies({\n providerData,\n fileData,\n state,\n}: {\n providerData: Saml2ProviderSkeleton;\n fileData: Saml2ExportInterface;\n state: State;\n}) {\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n const scriptData = await getScript({ scriptId: attrMapperScriptId, state });\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[attrMapperScriptId] = scriptData;\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n const scriptData = await getScript({ scriptId: idpAdapterScriptId, state });\n scriptData.script = convertBase64TextToArray(scriptData.script);\n fileData.script[idpAdapterScriptId] = scriptData;\n }\n const metaDataResponse = await getProviderMetadata({\n entityId: providerData.entityId,\n state,\n });\n if (!metaDataResponse) {\n throw new Error(\n `Unable to obtain metadata from ${getProviderMetadataUrl({\n entityId: providerData.entityId,\n state,\n })}`\n );\n }\n fileData.saml.metadata[providerData._id] = convertBase64UrlTextToArray(\n encodeBase64Url(metaDataResponse)\n );\n}\n\n/**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2ProviderStub({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ProviderStub> {\n debugMessage({\n message: `Saml2Ops.getSaml2ProviderStub: start [entityId=${entityId}]`,\n state,\n });\n const found = await findProviders({\n filter: `entityId eq '${entityId}'`,\n state,\n });\n switch (found.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n debugMessage({\n message: `Saml2Ops.getSaml2ProviderStub: end [entityId=${entityId}]`,\n state,\n });\n return found.result[0];\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2Provider({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ProviderSkeleton> {\n debugMessage({\n message: `Saml2Ops.getSaml2Provider: start [entityId=${entityId}]`,\n state,\n });\n const stub = await getSaml2ProviderStub({ entityId, state });\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId({\n location,\n entityId64: id,\n state,\n });\n debugMessage({\n message: `Saml2Ops.getSaml2Provider: end [entityId=${entityId}]`,\n state,\n });\n return providerData;\n}\n\n/**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteSaml2Provider({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ProviderSkeleton> {\n debugMessage({\n message: `Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`,\n state,\n });\n const stub = await getSaml2ProviderStub({ entityId, state });\n const { location } = stub;\n const id = stub._id;\n const providerData = await deleteProviderByLocationAndId({\n location,\n entityId64: id,\n state,\n });\n debugMessage({\n message: `Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`,\n state,\n });\n return providerData;\n}\n\n/**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\nexport async function deleteSaml2Providers({\n state,\n}: {\n state: State;\n}): Promise<Saml2ProviderSkeleton[]> {\n debugMessage({ message: `Saml2Ops.deleteSaml2Providers: start`, state });\n const providers: Saml2ProviderSkeleton[] = [];\n const stubs = await getSaml2ProviderStubs({ state });\n for (const stub of stubs) {\n const provider = await deleteProviderByLocationAndId({\n location: stub.location,\n entityId64: stub._id,\n state,\n });\n providers.push(provider);\n }\n debugMessage({\n message: `Saml2Ops.deleteSaml2Providers: end [deleted ${providers.length} providers]`,\n state,\n });\n return providers;\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Provider({\n entityId,\n state,\n}: {\n entityId: string;\n state: State;\n}): Promise<Saml2ExportInterface> {\n debugMessage({\n message: `Saml2Ops.exportSaml2Provider: start [entityId=${entityId}]`,\n state,\n });\n const exportData = createSaml2ExportTemplate({ state });\n const stub = await getSaml2ProviderStub({ entityId, state });\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId({\n location,\n entityId64: id,\n state,\n });\n exportData.saml[stub.location][providerData._id] = providerData;\n try {\n await exportDependencies({ providerData, fileData: exportData, state });\n } catch (error) {\n printMessage({ message: error.message, type: 'error', state });\n }\n debugMessage({\n message: `Saml2Ops.exportSaml2Provider: end [entityId=${entityId}]`,\n state,\n });\n return exportData;\n}\n\n/**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Providers({\n state,\n}: {\n state: State;\n}): Promise<Saml2ExportInterface> {\n const fileData = createSaml2ExportTemplate({ state });\n const stubs = await getSaml2ProviderStubs({ state });\n for (const stub of stubs) {\n const providerData = await getProviderByLocationAndId({\n location: stub.location,\n entityId64: stub._id,\n state,\n });\n try {\n await exportDependencies({ providerData, fileData, state });\n } catch (error) {\n printMessage({ message: error, type: 'error', state });\n }\n fileData.saml[stub.location][providerData._id] = providerData;\n }\n return fileData;\n}\n\n/**\n * Include dependencies from the import file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to read dependencies from\n */\nasync function importDependencies({\n providerData,\n fileData,\n state,\n}: {\n providerData: Saml2ProviderSkeleton;\n fileData: Saml2ExportInterface;\n state: State;\n}) {\n debugMessage({ message: `Saml2Ops.importDependencies: start`, state });\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n debugMessage({\n message: `Saml2Ops.importDependencies: attributeMapperScript=${attrMapperScriptId}`,\n state,\n });\n const scriptData = _.get(fileData, ['script', attrMapperScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script as string[]);\n await putScript({ scriptId: attrMapperScriptId, scriptData, state });\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n debugMessage({\n message: `Saml2Ops.importDependencies: idpAdapterScript=${idpAdapterScriptId}`,\n state,\n });\n const scriptData = _.get(fileData, ['script', idpAdapterScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script as string[]);\n await putScript({ scriptId: idpAdapterScriptId, scriptData, state });\n }\n debugMessage({ message: `Saml2Ops.importDependencies: end`, state });\n}\n\n/**\n * Find provider in import file and return its location\n * @param {string} entityId64 Base64-encoded provider entity id\n * @param {Saml2ExportInterface} data Import file json data\n * @returns {string} 'hosted' or 'remote' if found, undefined otherwise\n */\nfunction getLocation(\n entityId64: string,\n data: Saml2ExportInterface\n): Saml2ProiderLocation {\n if (data.saml.hosted[entityId64]) {\n return 'hosted';\n }\n if (data.saml.remote[entityId64]) {\n return 'remote';\n }\n return undefined;\n}\n\n/**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Provider({\n entityId,\n importData,\n state,\n}: {\n entityId: string;\n importData: Saml2ExportInterface;\n state: State;\n}): Promise<boolean> {\n debugMessage({ message: `Saml2Ops.importSaml2Provider: start`, state });\n const entityId64 = encode(entityId, false);\n const location = getLocation(entityId64, importData);\n debugMessage({\n message: `Saml2Ops.importSaml2Provider: entityId=${entityId}, entityId64=${entityId64}, location=${location}`,\n state,\n });\n if (location) {\n const providerData = importData.saml[location][entityId64];\n await importDependencies({ providerData, fileData: importData, state });\n let metaData = null;\n if (location === 'remote') {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider({ location, providerData, metaData, state });\n } catch (error) {\n await updateProvider({ location, providerData, state });\n }\n } else {\n throw new Error(`Provider ${entityId} not found in import data!`);\n }\n debugMessage({ message: `Saml2Ops.importSaml2Provider: end`, state });\n return true;\n}\n\n/**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Providers({\n importData,\n state,\n}: {\n importData: Saml2ExportInterface;\n state: State;\n}): Promise<MultiOpStatusInterface> {\n debugMessage({ message: `Saml2Ops.importSaml2Providers: start`, state });\n const myStatus: MultiOpStatusInterface = {\n total: 0,\n successes: 0,\n warnings: 0,\n failures: 0,\n };\n try {\n // find providers in hosted and in remote and map locations\n const hostedIds = Object.keys(importData.saml.hosted);\n const remoteIds = Object.keys(importData.saml.remote);\n const providerIds = hostedIds.concat(remoteIds);\n myStatus.total = providerIds.length;\n for (const entityId64 of providerIds) {\n debugMessage({\n message: `Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(\n entityId64\n )}`,\n state,\n });\n const location: Saml2ProiderLocation = hostedIds.includes(entityId64)\n ? 'hosted'\n : 'remote';\n const entityId = decode(entityId64);\n const providerData = importData.saml[location][entityId64];\n try {\n await importDependencies({ providerData, fileData: importData, state });\n } catch (importDependenciesErr) {\n myStatus.warnings += 1;\n printMessage({\n message: `\\nWarning importing dependencies for ${entityId}`,\n state,\n type: 'warn',\n });\n printMessage({\n message: importDependenciesErr.response.data,\n type: 'error',\n state,\n });\n }\n let metaData = null;\n if (location === 'remote') {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider({ location, providerData, metaData, state });\n myStatus.successes += 1;\n } catch (createProviderErr) {\n try {\n await updateProvider({ location, providerData, state });\n myStatus.successes += 1;\n } catch (updateProviderError) {\n myStatus.failures += 1;\n printMessage({\n message: `\\nError importing provider ${entityId}: ${updateProviderError.message}`,\n state,\n type: 'error',\n });\n printMessage({\n message: updateProviderError.response?.data,\n type: 'error',\n state,\n });\n }\n }\n }\n myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;\n } catch (error) {\n myStatus.failures += 1;\n printMessage({\n message: `\\nError importing providers ${error.message}`,\n type: 'error',\n state,\n });\n }\n debugMessage({ message: `Saml2Ops.importSaml2Providers: end`, state });\n return myStatus;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/ScriptOps.ts"],"names":[],"mappings":"AASA,OAAO,EACL,SAAS,EAIT,YAAY,EACb,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EA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AK,CAAC;CACd,GAAG,OAAO,CAAC,cAAc,CAAC,CAU1B;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,EAC9B,QAAQ,EACR,UAAU,EACV,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,cAAc,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CAqBnB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAQjC;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAQjC;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,EAClC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAkBjC;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,UAAU,EACV,MAAc,EACd,QAAgB,EAChB,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA2CnB;AAED,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC","file":"ScriptOps.d.ts","sourcesContent":["import { v4 as uuidv4 } from 'uuid';\nimport { applyNameCollisionPolicy } from './utils/OpsUtils';\nimport {\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n getScript,\n getScriptByName as _getScriptByName,\n getScripts as _getScripts,\n putScript as _putScript,\n deleteScript,\n} from '../api/ScriptApi';\nimport {\n convertBase64TextToArray,\n convertTextArrayToBase64,\n getMetadata,\n} from './utils/ExportImportUtils';\nimport { ScriptSkeleton } from '../api/ApiTypes';\nimport { ExportMetaData } from '../ops/OpsTypes';\nimport { validateScriptDecoded } from './utils/ScriptValidationUtils';\nimport State from '../shared/State';\n\nexport default class ScriptOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all scripts\n * @returns {Promise<ScriptSkeleton[]>} a promise that resolves to an array of script objects\n */\n async getScripts(): Promise<ScriptSkeleton[]> {\n return getScripts({ state: this.state });\n }\n\n /**\n * Get script by name\n * @param {string} name name of the script\n * @returns {Promise<ScriptSkeleton>} promise that resolves to a script object\n */\n async getScriptByName(scriptName: string): Promise<ScriptSkeleton> {\n return getScriptByName({ scriptName, state: this.state });\n }\n\n /**\n * Create or update script\n * @param {string} scriptId script uuid\n * @param {ScriptSkeleton} scriptData script object\n * @returns {Promise<boolean>} a status object\n */\n async putScript(\n scriptId: string,\n scriptData: ScriptSkeleton\n ): Promise<boolean> {\n return putScript({ scriptId, scriptData, state: this.state });\n }\n\n /**\n * Export script by id\n * @param {string} scriptId script uuid\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\n async exportScript(scriptId: string): Promise<ScriptExportInterface> {\n return exportScript({ scriptId, state: this.state });\n }\n\n /**\n * Export script by name\n * @param {string} name script name\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\n async exportScriptByName(scriptName: string): Promise<ScriptExportInterface> {\n return exportScriptByName({ scriptName, state: this.state });\n }\n\n /**\n * Export all scripts\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\n async exportScripts(): Promise<ScriptExportInterface> {\n return exportScripts({ state: this.state });\n }\n\n /**\n * Import scripts\n * @param {string} scriptName Optional name of script. If supplied, only the script of that name is imported\n * @param {ScriptExportInterface} importData Script import data\n * @param {boolean} reUuid true to generate a new uuid for each script on import, false otherwise\n * @returns {Promise<boolean>} true if no errors occurred during import, false otherwise\n */\n async importScripts(\n scriptName: string,\n importData: ScriptExportInterface,\n reUuid = false,\n validate = false\n ): Promise<boolean> {\n return importScripts({\n scriptName,\n importData,\n reUuid,\n validate,\n state: this.state,\n });\n }\n\n getScript(scriptId: string) {\n return getScript({ scriptId, state: this.state });\n }\n\n deleteScript(scriptId: string) {\n return deleteScript({ scriptId, state: this.state });\n }\n}\n\nexport interface ScriptExportInterface {\n meta?: ExportMetaData;\n script: Record<string, ScriptSkeleton>;\n}\n\n/**\n * Create an empty idp export template\n * @returns {ScriptExportInterface} an empty idp export template\n */\nexport function createScriptExportTemplate({\n state,\n}: {\n state: State;\n}): ScriptExportInterface {\n return {\n meta: getMetadata({ state }),\n script: {},\n } as ScriptExportInterface;\n}\n\n/**\n * Get all scripts\n * @returns {Promise<ScriptSkeleton[]>} a promise that resolves to an array of script objects\n */\nexport async function getScripts({\n state,\n}: {\n state: State;\n}): Promise<ScriptSkeleton[]> {\n const { result } = await _getScripts({ state });\n return result;\n}\n\n/**\n * Get script by name\n * @param {string} scriptName name of the script\n * @returns {Promise<ScriptSkeleton>} promise that resolves to a script object\n */\nexport async function getScriptByName({\n scriptName,\n state,\n}: {\n scriptName: string;\n state: State;\n}): Promise<ScriptSkeleton> {\n const { result } = await _getScriptByName({ scriptName, state });\n switch (result.length) {\n case 1:\n return result[0];\n case 0:\n throw new Error(`Script '${scriptName}' not found`);\n default:\n throw new Error(`${result.length} scripts '${scriptName}' found`);\n }\n}\n\n/**\n * Create or update script\n * @param {string} scriptId script uuid\n * @param {ScriptSkeleton} scriptData script object\n * @returns {Promise<boolean>} a status object\n */\nexport async function putScript({\n scriptId,\n scriptData,\n state,\n}: {\n scriptId: string;\n scriptData: ScriptSkeleton;\n state: State;\n}): Promise<boolean> {\n try {\n if (Array.isArray(scriptData.script)) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n }\n const result = await _putScript({ scriptId, scriptData, state });\n return result;\n } catch (error) {\n if (error.response?.status === 409) {\n printMessage(\n `createOrUpdateScript WARNING: script with name ${scriptData.name} already exists, using renaming policy... <name> => <name - imported (n)>`,\n 'warn'\n );\n const newName = applyNameCollisionPolicy(scriptData.name);\n scriptData.name = newName;\n const result = await putScript({ scriptId, scriptData, state });\n printMessage(`Saved script as ${newName}`, 'warn');\n return result;\n }\n throw error;\n }\n}\n\n/**\n * Export script by id\n * @param {string} scriptId script uuid\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\nexport async function exportScript({\n scriptId,\n state,\n}: {\n scriptId: string;\n state: State;\n}): Promise<ScriptExportInterface> {\n debugMessage(`ScriptOps.exportScriptById: start`);\n const scriptData = await getScript({ scriptId, state });\n scriptData.script = convertBase64TextToArray(scriptData.script);\n const exportData = createScriptExportTemplate({ state });\n exportData.script[scriptData._id] = scriptData;\n debugMessage(`ScriptOps.exportScriptById: end`);\n return exportData;\n}\n\n/**\n * Export script by name\n * @param {string} scriptName script name\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\nexport async function exportScriptByName({\n scriptName,\n state,\n}: {\n scriptName: string;\n state: State;\n}): Promise<ScriptExportInterface> {\n debugMessage(`ScriptOps.exportScriptByName: start`);\n const scriptData = await getScriptByName({ scriptName, state });\n scriptData.script = convertBase64TextToArray(scriptData.script as string);\n const exportData = createScriptExportTemplate({ state });\n exportData.script[scriptData._id] = scriptData;\n debugMessage(`ScriptOps.exportScriptByName: end`);\n return exportData;\n}\n\n/**\n * Export all scripts\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\nexport async function exportScripts({\n state,\n}: {\n state: State;\n}): Promise<ScriptExportInterface> {\n const scriptList = await getScripts({ state });\n const exportData = createScriptExportTemplate({ state });\n createProgressIndicator(\n scriptList.length,\n `Exporting ${scriptList.length} scripts...`\n );\n for (const script of scriptList) {\n updateProgressIndicator(`Reading script ${script.name}`);\n const scriptData = await getScriptByName({\n scriptName: script.name,\n state,\n });\n scriptData.script = convertBase64TextToArray(scriptData.script as string);\n exportData.script[scriptData._id] = scriptData;\n }\n stopProgressIndicator(`Exported ${scriptList.length} scripts.`);\n return exportData;\n}\n\n/**\n * Import scripts\n * @param {string} scriptName Optional name of script. If supplied, only the script of that name is imported\n * @param {ScriptExportInterface} importData Script import data\n * @param {boolean} reUuid true to generate a new uuid for each script on import, false otherwise\n * @returns {Promise<boolean>} true if no errors occurred during import, false otherwise\n */\nexport async function importScripts({\n scriptName,\n importData,\n reUuid = false,\n validate = false,\n state,\n}: {\n scriptName: string;\n importData: ScriptExportInterface;\n reUuid?: boolean;\n validate?: boolean;\n state: State;\n}): Promise<boolean> {\n let outcome = true;\n debugMessage(`ScriptOps.importScripts: start`);\n for (const existingId of Object.keys(importData.script)) {\n const scriptSkeleton = importData.script[existingId];\n let newId = existingId;\n if (reUuid) {\n newId = uuidv4();\n debugMessage(\n `ScriptOps.importScripts: Re-uuid-ing script ${scriptSkeleton.name} ${existingId} => ${newId}...`\n );\n scriptSkeleton._id = newId;\n }\n if (scriptName) {\n debugMessage(\n `ScriptOps.importScripts: Renaming script ${scriptSkeleton.name} => ${scriptName}...`\n );\n scriptSkeleton.name = scriptName;\n }\n if (validate) {\n if (!validateScriptDecoded(scriptSkeleton)) {\n outcome = false;\n printMessage(\n `Error importing script '${scriptSkeleton.name}': Script is not valid`,\n 'error'\n );\n continue;\n }\n }\n try {\n await putScript({ scriptId: newId, scriptData: scriptSkeleton, state });\n } catch (error) {\n outcome = false;\n printMessage(\n `Error importing script '${scriptSkeleton.name}': ${error.message}`,\n 'error'\n );\n debugMessage(error);\n }\n if (scriptName) break;\n }\n debugMessage(`ScriptOps.importScripts: end`);\n return outcome;\n}\n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N,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA+CnB;AAED,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC","file":"ScriptOps.d.ts","sourcesContent":["import { v4 as uuidv4 } from 'uuid';\nimport { applyNameCollisionPolicy } from './utils/OpsUtils';\nimport {\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n getScript,\n getScriptByName as _getScriptByName,\n getScripts as _getScripts,\n putScript as _putScript,\n deleteScript,\n} from '../api/ScriptApi';\nimport {\n convertBase64TextToArray,\n convertTextArrayToBase64,\n getMetadata,\n} from './utils/ExportImportUtils';\nimport { ScriptSkeleton } from '../api/ApiTypes';\nimport { ExportMetaData } from '../ops/OpsTypes';\nimport { validateScriptDecoded } from './utils/ScriptValidationUtils';\nimport State from '../shared/State';\n\nexport default class ScriptOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all scripts\n * @returns {Promise<ScriptSkeleton[]>} a promise that resolves to an array of script objects\n */\n async getScripts(): Promise<ScriptSkeleton[]> {\n return getScripts({ state: this.state });\n }\n\n /**\n * Get script by name\n * @param {string} name name of the script\n * @returns {Promise<ScriptSkeleton>} promise that resolves to a script object\n */\n async getScriptByName(scriptName: string): Promise<ScriptSkeleton> {\n return getScriptByName({ scriptName, state: this.state });\n }\n\n /**\n * Create or update script\n * @param {string} scriptId script uuid\n * @param {ScriptSkeleton} scriptData script object\n * @returns {Promise<boolean>} a status object\n */\n async putScript(\n scriptId: string,\n scriptData: ScriptSkeleton\n ): Promise<boolean> {\n return putScript({ scriptId, scriptData, state: this.state });\n }\n\n /**\n * Export script by id\n * @param {string} scriptId script uuid\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\n async exportScript(scriptId: string): Promise<ScriptExportInterface> {\n return exportScript({ scriptId, state: this.state });\n }\n\n /**\n * Export script by name\n * @param {string} name script name\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\n async exportScriptByName(scriptName: string): Promise<ScriptExportInterface> {\n return exportScriptByName({ scriptName, state: this.state });\n }\n\n /**\n * Export all scripts\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\n async exportScripts(): Promise<ScriptExportInterface> {\n return exportScripts({ state: this.state });\n }\n\n /**\n * Import scripts\n * @param {string} scriptName Optional name of script. If supplied, only the script of that name is imported\n * @param {ScriptExportInterface} importData Script import data\n * @param {boolean} reUuid true to generate a new uuid for each script on import, false otherwise\n * @returns {Promise<boolean>} true if no errors occurred during import, false otherwise\n */\n async importScripts(\n scriptName: string,\n importData: ScriptExportInterface,\n reUuid = false,\n validate = false\n ): Promise<boolean> {\n return importScripts({\n scriptName,\n importData,\n reUuid,\n validate,\n state: this.state,\n });\n }\n\n getScript(scriptId: string) {\n return getScript({ scriptId, state: this.state });\n }\n\n deleteScript(scriptId: string) {\n return deleteScript({ scriptId, state: this.state });\n }\n}\n\nexport interface ScriptExportInterface {\n meta?: ExportMetaData;\n script: Record<string, ScriptSkeleton>;\n}\n\n/**\n * Create an empty idp export template\n * @returns {ScriptExportInterface} an empty idp export template\n */\nexport function createScriptExportTemplate({\n state,\n}: {\n state: State;\n}): ScriptExportInterface {\n return {\n meta: getMetadata({ state }),\n script: {},\n } as ScriptExportInterface;\n}\n\n/**\n * Get all scripts\n * @returns {Promise<ScriptSkeleton[]>} a promise that resolves to an array of script objects\n */\nexport async function getScripts({\n state,\n}: {\n state: State;\n}): Promise<ScriptSkeleton[]> {\n const { result } = await _getScripts({ state });\n return result;\n}\n\n/**\n * Get script by name\n * @param {string} scriptName name of the script\n * @returns {Promise<ScriptSkeleton>} promise that resolves to a script object\n */\nexport async function getScriptByName({\n scriptName,\n state,\n}: {\n scriptName: string;\n state: State;\n}): Promise<ScriptSkeleton> {\n const { result } = await _getScriptByName({ scriptName, state });\n switch (result.length) {\n case 1:\n return result[0];\n case 0:\n throw new Error(`Script '${scriptName}' not found`);\n default:\n throw new Error(`${result.length} scripts '${scriptName}' found`);\n }\n}\n\n/**\n * Create or update script\n * @param {string} scriptId script uuid\n * @param {ScriptSkeleton} scriptData script object\n * @returns {Promise<boolean>} a status object\n */\nexport async function putScript({\n scriptId,\n scriptData,\n state,\n}: {\n scriptId: string;\n scriptData: ScriptSkeleton;\n state: State;\n}): Promise<boolean> {\n try {\n if (Array.isArray(scriptData.script)) {\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n }\n const result = await _putScript({ scriptId, scriptData, state });\n return result;\n } catch (error) {\n if (error.response?.status === 409) {\n printMessage({\n message: `createOrUpdateScript WARNING: script with name ${scriptData.name} already exists, using renaming policy... <name> => <name - imported (n)>`,\n type: 'warn',\n state,\n });\n const newName = applyNameCollisionPolicy(scriptData.name);\n scriptData.name = newName;\n const result = await putScript({ scriptId, scriptData, state });\n printMessage({\n message: `Saved script as ${newName}`,\n type: 'warn',\n state,\n });\n return result;\n }\n throw error;\n }\n}\n\n/**\n * Export script by id\n * @param {string} scriptId script uuid\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\nexport async function exportScript({\n scriptId,\n state,\n}: {\n scriptId: string;\n state: State;\n}): Promise<ScriptExportInterface> {\n debugMessage({ message: `ScriptOps.exportScriptById: start`, state });\n const scriptData = await getScript({ scriptId, state });\n scriptData.script = convertBase64TextToArray(scriptData.script);\n const exportData = createScriptExportTemplate({ state });\n exportData.script[scriptData._id] = scriptData;\n debugMessage({ message: `ScriptOps.exportScriptById: end`, state });\n return exportData;\n}\n\n/**\n * Export script by name\n * @param {string} scriptName script name\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\nexport async function exportScriptByName({\n scriptName,\n state,\n}: {\n scriptName: string;\n state: State;\n}): Promise<ScriptExportInterface> {\n debugMessage({ message: `ScriptOps.exportScriptByName: start`, state });\n const scriptData = await getScriptByName({ scriptName, state });\n scriptData.script = convertBase64TextToArray(scriptData.script as string);\n const exportData = createScriptExportTemplate({ state });\n exportData.script[scriptData._id] = scriptData;\n debugMessage({ message: `ScriptOps.exportScriptByName: end`, state });\n return exportData;\n}\n\n/**\n * Export all scripts\n * @returns {Promise<ScriptExportInterface>} a promise that resolved to a ScriptExportInterface object\n */\nexport async function exportScripts({\n state,\n}: {\n state: State;\n}): Promise<ScriptExportInterface> {\n const scriptList = await getScripts({ state });\n const exportData = createScriptExportTemplate({ state });\n createProgressIndicator({\n total: scriptList.length,\n message: `Exporting ${scriptList.length} scripts...`,\n state,\n });\n for (const script of scriptList) {\n updateProgressIndicator({\n message: `Reading script ${script.name}`,\n state,\n });\n const scriptData = await getScriptByName({\n scriptName: script.name,\n state,\n });\n scriptData.script = convertBase64TextToArray(scriptData.script as string);\n exportData.script[scriptData._id] = scriptData;\n }\n stopProgressIndicator({\n message: `Exported ${scriptList.length} scripts.`,\n state,\n });\n return exportData;\n}\n\n/**\n * Import scripts\n * @param {string} scriptName Optional name of script. If supplied, only the script of that name is imported\n * @param {ScriptExportInterface} importData Script import data\n * @param {boolean} reUuid true to generate a new uuid for each script on import, false otherwise\n * @returns {Promise<boolean>} true if no errors occurred during import, false otherwise\n */\nexport async function importScripts({\n scriptName,\n importData,\n reUuid = false,\n validate = false,\n state,\n}: {\n scriptName: string;\n importData: ScriptExportInterface;\n reUuid?: boolean;\n validate?: boolean;\n state: State;\n}): Promise<boolean> {\n let outcome = true;\n debugMessage({ message: `ScriptOps.importScripts: start`, state });\n for (const existingId of Object.keys(importData.script)) {\n const scriptSkeleton = importData.script[existingId];\n let newId = existingId;\n if (reUuid) {\n newId = uuidv4();\n debugMessage({\n message: `ScriptOps.importScripts: Re-uuid-ing script ${scriptSkeleton.name} ${existingId} => ${newId}...`,\n state,\n });\n scriptSkeleton._id = newId;\n }\n if (scriptName) {\n debugMessage({\n message: `ScriptOps.importScripts: Renaming script ${scriptSkeleton.name} => ${scriptName}...`,\n state,\n });\n scriptSkeleton.name = scriptName;\n }\n if (validate) {\n if (!validateScriptDecoded({ scriptSkeleton, state })) {\n outcome = false;\n printMessage({\n message: `Error importing script '${scriptSkeleton.name}': Script is not valid`,\n type: 'error',\n state,\n });\n continue;\n }\n }\n try {\n await putScript({ scriptId: newId, scriptData: scriptSkeleton, state });\n } catch (error) {\n outcome = false;\n printMessage({\n message: `Error importing script '${scriptSkeleton.name}': ${error.message}`,\n type: 'error',\n state,\n });\n debugMessage({ message: error, state });\n }\n if (scriptName) break;\n }\n debugMessage({ message: `ScriptOps.importScripts: end`, state });\n return outcome;\n}\n\nexport { getScript, deleteScript };\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/ServiceOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAQL,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB,2BAA2B,IAAI,sBAAsB;IAIrD;;;OAGG;IACG,iBAAiB,CAAC,YAAY,UAAQ;IAI5C;;;;OAIG;IACG,eAAe,CAAC,YAAY,UAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAInE;;;;OAIG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,UAAQ;IAI/D;;;OAGG;IACG,kBAAkB,CAAC,YAAY,UAAQ;IAI7C;;;;;OAKG;IACG,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,YAAY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AAC,EAClC,SAAS,EACT,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAiBlC;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,EACnC,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAgBlC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,UAAU,EACV,KAAK,EACL,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,sBAAsB,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAY7B;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,EACnC,UAAU,EACV,KAAK,EACL,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,UAAU,EAAE,sBAAsB,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,gCAsBA","file":"ServiceOps.d.ts","sourcesContent":["import { AmServiceSkeleton } from '../api/ApiTypes';\nimport {\n deleteService,\n deleteServiceNextDescendent,\n getService,\n getListOfServices as _getListOfServices,\n getServiceDescendents,\n putService,\n putServiceNextDescendent,\n ServiceNextDescendent,\n} from '../api/ServiceApi';\nimport State from '../shared/State';\nimport { ServiceExportInterface } from './OpsTypes';\nimport { debugMessage, printMessage } from './utils/Console';\n\nexport default class ServiceOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n createServiceExportTemplate(): ServiceExportInterface {\n return createServiceExportTemplate();\n }\n\n /**\n * Get list of services\n * @param {boolean} globalConfig true if the list of global services is requested, false otherwise. Default: false.\n */\n async getListOfServices(globalConfig = false) {\n return getListOfServices({ globalConfig, state: this.state });\n }\n\n /**\n * Get all services including their descendents.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving to an array of services with their descendants\n */\n async getFullServices(globalConfig = false): Promise<FullService[]> {\n return getFullServices({ globalConfig, state: this.state });\n }\n\n /**\n * Deletes the specified service\n * @param {string} serviceId The service to delete\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async deleteFullService(serviceId: string, globalConfig = false) {\n return deleteFullService({ serviceId, globalConfig, state: this.state });\n }\n\n /**\n * Deletes all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async deleteFullServices(globalConfig = false) {\n return deleteFullServices({ globalConfig, state: this.state });\n }\n\n /**\n * Export service. The response can be saved to file as is.\n * @param serviceId service id/name\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\n async exportService(\n serviceId: string,\n globalConfig = false\n ): Promise<ServiceExportInterface> {\n return exportService({ serviceId, globalConfig, state: this.state });\n }\n\n /**\n * Export all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async exportServices(globalConfig = false): Promise<ServiceExportInterface> {\n return exportServices({ globalConfig, state: this.state });\n }\n\n /**\n * Imports a single service using a reference to the service and a file to read the data from. Optionally clean (remove) an existing service first\n * @param {string} serviceId The service id/name to add\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving when the service has been imported\n */\n async importService(\n serviceId: string,\n importData: ServiceExportInterface,\n clean: boolean,\n globalConfig = false\n ): Promise<AmServiceSkeleton> {\n return importService({\n serviceId,\n importData,\n clean,\n globalConfig,\n state: this.state,\n });\n }\n\n /**\n * Imports multiple services from the same file. Optionally clean (remove) existing services first\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove possible existing services first\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async importServices(\n importData: ServiceExportInterface,\n clean: boolean,\n globalConfig = false\n ) {\n return importServices({\n importData,\n clean,\n globalConfig,\n state: this.state,\n });\n }\n}\n\ninterface FullService extends AmServiceSkeleton {\n nextDescendents?: ServiceNextDescendent[];\n}\n\n/**\n * Create an empty service export template\n * @returns {SingleTreeExportInterface} an empty service export template\n */\nexport function createServiceExportTemplate(): ServiceExportInterface {\n return {\n meta: {},\n service: {},\n } as ServiceExportInterface;\n}\n\n/**\n * Get list of services\n * @param {boolean} globalConfig true if the list of global services is requested, false otherwise. Default: false.\n */\nexport async function getListOfServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage(`ServiceOps.getListOfServices: start`);\n const services = (await _getListOfServices({ globalConfig, state })).result;\n debugMessage(`ServiceOps.getListOfServices: end`);\n return services;\n}\n\n/**\n * Get all services including their descendents.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving to an array of services with their descendants\n */\nexport async function getFullServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}): Promise<FullService[]> {\n debugMessage(\n `ServiceOps.getFullServices: start, globalConfig=${globalConfig}`\n );\n const serviceList = (await _getListOfServices({ globalConfig, state }))\n .result;\n\n const fullServiceData = await Promise.all(\n serviceList.map(async (listItem) => {\n try {\n const [service, nextDescendents] = await Promise.all([\n getService({ serviceId: listItem._id, globalConfig, state }),\n getServiceDescendents({\n serviceId: listItem._id,\n globalConfig,\n state,\n }),\n ]);\n\n return {\n ...service,\n nextDescendents,\n };\n } catch (error) {\n if (\n !(\n error.response?.status === 403 &&\n error.response?.data?.message ===\n 'This operation is not available in ForgeRock Identity Cloud.'\n )\n ) {\n const message = error.response?.data?.message;\n printMessage(\n `Unable to retrieve data for ${listItem._id} with error: ${message}`,\n 'error'\n );\n }\n }\n })\n );\n\n debugMessage(`ServiceOps.getFullServices: end`);\n return fullServiceData.filter((data) => !!data); // make sure to filter out any undefined objects\n}\n\n/**\n * Saves a service using the provide id and data, including descendents\n * @param {string} serviceId the service id / name\n * @param {string} fullServiceData service object including descendants\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns promise resolving to a service object\n */\nasync function putFullService({\n serviceId,\n fullServiceData,\n clean,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n fullServiceData: FullService;\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}): Promise<AmServiceSkeleton> {\n debugMessage(\n `ServiceOps.putFullService: start, serviceId=${serviceId}, globalConfig=${globalConfig}`\n );\n const nextDescendents = fullServiceData.nextDescendents;\n\n delete fullServiceData.nextDescendents;\n delete fullServiceData._rev;\n delete fullServiceData.enabled;\n\n if (clean) {\n try {\n debugMessage(`ServiceOps.putFullService: clean`);\n await deleteFullService({ serviceId, globalConfig, state });\n } catch (error) {\n if (\n !(\n error.response?.status === 404 &&\n error.response?.data?.message === 'Not Found'\n )\n ) {\n const message = error.response?.data?.message;\n printMessage(\n `Error deleting service '${serviceId}' before import: ${message}`,\n 'error'\n );\n }\n }\n }\n\n // create service first\n const result = await putService({\n serviceId,\n serviceData: fullServiceData,\n globalConfig,\n state,\n });\n\n // return fast if no next descendents supplied\n if (nextDescendents.length === 0) {\n debugMessage(`ServiceOps.putFullService: end (w/o descendents)`);\n return result;\n }\n\n // now create next descendents\n await Promise.all(\n nextDescendents.map(async (descendent) => {\n const type = descendent._type._id;\n const descendentId = descendent._id;\n debugMessage(`ServiceOps.putFullService: descendentId=${descendentId}`);\n let result = undefined;\n try {\n result = await putServiceNextDescendent({\n serviceId,\n serviceType: type,\n serviceNextDescendentId: descendentId,\n serviceNextDescendentData: descendent,\n globalConfig,\n state,\n });\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(\n `Put descendent '${descendentId}' of service '${serviceId}': ${message}`,\n 'error'\n );\n }\n return result;\n })\n );\n debugMessage(`ServiceOps.putFullService: end (w/ descendents)`);\n}\n\n/**\n * Saves multiple services using the serviceEntries which contain both id and data with descendants\n * @param {[string, FullService][]} serviceEntries The services to add\n * @param {boolean} clean Indicates whether to remove possible existing services first\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns {Promise<AmService[]>} promise resolving to an array of service objects\n */\nasync function putFullServices({\n serviceEntries,\n clean,\n globalConfig = false,\n state,\n}: {\n serviceEntries: [string, FullService][];\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}): Promise<AmServiceSkeleton[]> {\n debugMessage(\n `ServiceOps.putFullServices: start, globalConfig=${globalConfig}`\n );\n const results: AmServiceSkeleton[] = [];\n for (const [id, data] of serviceEntries) {\n try {\n const result = await putFullService({\n serviceId: id,\n fullServiceData: data,\n clean,\n globalConfig,\n state,\n });\n results.push(result);\n printMessage(`Imported: ${id}`, 'info');\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage(`Import service '${id}': ${message}`, 'error');\n if (detail) {\n printMessage(`Details: ${JSON.stringify(detail)}`, 'error');\n }\n }\n }\n debugMessage(`ServiceOps.putFullServices: end`);\n return results;\n}\n\n/**\n * Deletes the specified service\n * @param {string} serviceId The service to delete\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function deleteFullService({\n serviceId,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage(\n `ServiceOps.deleteFullService: start, globalConfig=${globalConfig}`\n );\n const serviceNextDescendentData = await getServiceDescendents({\n serviceId,\n globalConfig,\n state,\n });\n\n await Promise.all(\n serviceNextDescendentData.map((nextDescendent) =>\n deleteServiceNextDescendent({\n serviceId,\n serviceType: nextDescendent._type._id,\n serviceNextDescendentId: nextDescendent._id,\n globalConfig,\n state,\n })\n )\n );\n\n await deleteService({ serviceId, globalConfig, state });\n debugMessage(`ServiceOps.deleteFullService: end`);\n}\n\n/**\n * Deletes all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function deleteFullServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage(\n `ServiceOps.deleteFullServices: start, globalConfig=${globalConfig}`\n );\n try {\n const serviceList = (await _getListOfServices({ globalConfig, state }))\n .result;\n\n await Promise.all(\n serviceList.map(async (serviceListItem) => {\n try {\n await deleteFullService({\n serviceId: serviceListItem._id,\n globalConfig,\n state,\n });\n } catch (error) {\n if (\n !(\n error.response?.status === 403 &&\n error.response?.data?.message ===\n 'This operation is not available in ForgeRock Identity Cloud.'\n )\n ) {\n const message = error.response?.data?.message;\n printMessage(\n `Delete service '${serviceListItem._id}': ${message}`,\n 'error'\n );\n }\n }\n })\n );\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Delete services: ${message}`, 'error');\n }\n debugMessage(`ServiceOps.deleteFullServices: end`);\n}\n\n/**\n * Export service. The response can be saved to file as is.\n * @param serviceId service id/name\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\nexport async function exportService({\n serviceId,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n globalConfig: boolean;\n state: State;\n}): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportService: start, globalConfig=${globalConfig}`);\n const exportData = createServiceExportTemplate();\n try {\n const service = await getService({ serviceId, globalConfig, state });\n service.nextDescendents = await getServiceDescendents({\n serviceId,\n globalConfig,\n state,\n });\n exportData.service[serviceId] = service;\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Export service '${serviceId}': ${message}`, 'error');\n }\n debugMessage(`ServiceOps.exportService: end`);\n return exportData;\n}\n\n/**\n * Export all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function exportServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}): Promise<ServiceExportInterface> {\n debugMessage(\n `ServiceOps.exportServices: start, globalConfig=${globalConfig}`\n );\n const exportData = createServiceExportTemplate();\n try {\n const services = await getFullServices({ globalConfig, state });\n for (const service of services) {\n exportData.service[service._type._id] = service;\n }\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Export servics: ${message}`, 'error');\n }\n debugMessage(`ServiceOps.exportServices: end`);\n return exportData;\n}\n\n/**\n * Imports a single service using a reference to the service and a file to read the data from. Optionally clean (remove) an existing service first\n * @param {string} serviceId The service id/name to add\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving when the service has been imported\n */\nexport async function importService({\n serviceId,\n importData,\n clean,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n importData: ServiceExportInterface;\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.importService: start, globalConfig=${globalConfig}`);\n const serviceData = importData.service[serviceId];\n const result = await putFullService({\n serviceId,\n fullServiceData: serviceData,\n clean,\n globalConfig,\n state,\n });\n debugMessage(`ServiceOps.importService: end`);\n return result;\n}\n\n/**\n * Imports multiple services from the same file. Optionally clean (remove) existing services first\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove possible existing services first\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function importServices({\n importData,\n clean,\n globalConfig = false,\n state,\n}: {\n importData: ServiceExportInterface;\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage(\n `ServiceOps.importServices: start, globalConfig=${globalConfig}`\n );\n try {\n const result = await putFullServices({\n serviceEntries: Object.entries(importData.service),\n clean,\n globalConfig,\n state,\n });\n debugMessage(`ServiceOps.importServices: end`);\n return result;\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage(`Unable to import services: error: ${message}`, 'error');\n if (detail) {\n printMessage(`Details: ${JSON.stringify(detail)}`, 'error');\n }\n throw error;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/ops/ServiceOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAQL,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB,2BAA2B,IAAI,sBAAsB;IAIrD;;;OAGG;IACG,iBAAiB,CAAC,YAAY,UAAQ;IAI5C;;;;OAIG;IACG,eAAe,CAAC,YAAY,UAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAInE;;;;OAIG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,UAAQ;IAI/D;;;OAGG;IACG,kBAAkB,CAAC,YAAY,UAAQ;IAI7C;;;;;OAKG;IACG,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,YAAY,UAAQ,GACnB,OAAO,CAAC,sBAAsB,CAAC;IAIlC;;;OAGG;IACG,cAAc,CAAC,YAAY,UAAQ,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAI3E;;;;;;;OAOG;IACG,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,sBAAsB,EAClC,KAAK,EAAE,OAAO,E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ACnC,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBlC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,UAAU,EACV,KAAK,EACL,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,sBAAsB,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAe7B;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,EACnC,UAAU,EACV,KAAK,EACL,YAAoB,EACpB,KAAK,GACN,EAAE;IACD,UAAU,EAAE,sBAAsB,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,gCA+BA","file":"ServiceOps.d.ts","sourcesContent":["import { AmServiceSkeleton } from '../api/ApiTypes';\nimport {\n deleteService,\n deleteServiceNextDescendent,\n getService,\n getListOfServices as _getListOfServices,\n getServiceDescendents,\n putService,\n putServiceNextDescendent,\n ServiceNextDescendent,\n} from '../api/ServiceApi';\nimport State from '../shared/State';\nimport { ServiceExportInterface } from './OpsTypes';\nimport { debugMessage, printMessage } from './utils/Console';\n\nexport default class ServiceOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n createServiceExportTemplate(): ServiceExportInterface {\n return createServiceExportTemplate();\n }\n\n /**\n * Get list of services\n * @param {boolean} globalConfig true if the list of global services is requested, false otherwise. Default: false.\n */\n async getListOfServices(globalConfig = false) {\n return getListOfServices({ globalConfig, state: this.state });\n }\n\n /**\n * Get all services including their descendents.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving to an array of services with their descendants\n */\n async getFullServices(globalConfig = false): Promise<FullService[]> {\n return getFullServices({ globalConfig, state: this.state });\n }\n\n /**\n * Deletes the specified service\n * @param {string} serviceId The service to delete\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async deleteFullService(serviceId: string, globalConfig = false) {\n return deleteFullService({ serviceId, globalConfig, state: this.state });\n }\n\n /**\n * Deletes all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async deleteFullServices(globalConfig = false) {\n return deleteFullServices({ globalConfig, state: this.state });\n }\n\n /**\n * Export service. The response can be saved to file as is.\n * @param serviceId service id/name\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\n async exportService(\n serviceId: string,\n globalConfig = false\n ): Promise<ServiceExportInterface> {\n return exportService({ serviceId, globalConfig, state: this.state });\n }\n\n /**\n * Export all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async exportServices(globalConfig = false): Promise<ServiceExportInterface> {\n return exportServices({ globalConfig, state: this.state });\n }\n\n /**\n * Imports a single service using a reference to the service and a file to read the data from. Optionally clean (remove) an existing service first\n * @param {string} serviceId The service id/name to add\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving when the service has been imported\n */\n async importService(\n serviceId: string,\n importData: ServiceExportInterface,\n clean: boolean,\n globalConfig = false\n ): Promise<AmServiceSkeleton> {\n return importService({\n serviceId,\n importData,\n clean,\n globalConfig,\n state: this.state,\n });\n }\n\n /**\n * Imports multiple services from the same file. Optionally clean (remove) existing services first\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove possible existing services first\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\n async importServices(\n importData: ServiceExportInterface,\n clean: boolean,\n globalConfig = false\n ) {\n return importServices({\n importData,\n clean,\n globalConfig,\n state: this.state,\n });\n }\n}\n\ninterface FullService extends AmServiceSkeleton {\n nextDescendents?: ServiceNextDescendent[];\n}\n\n/**\n * Create an empty service export template\n * @returns {SingleTreeExportInterface} an empty service export template\n */\nexport function createServiceExportTemplate(): ServiceExportInterface {\n return {\n meta: {},\n service: {},\n } as ServiceExportInterface;\n}\n\n/**\n * Get list of services\n * @param {boolean} globalConfig true if the list of global services is requested, false otherwise. Default: false.\n */\nexport async function getListOfServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage({ message: `ServiceOps.getListOfServices: start`, state });\n const services = (await _getListOfServices({ globalConfig, state })).result;\n debugMessage({ message: `ServiceOps.getListOfServices: end`, state });\n return services;\n}\n\n/**\n * Get all services including their descendents.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving to an array of services with their descendants\n */\nexport async function getFullServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}): Promise<FullService[]> {\n debugMessage({\n message: `ServiceOps.getFullServices: start, globalConfig=${globalConfig}`,\n state,\n });\n const serviceList = (await _getListOfServices({ globalConfig, state }))\n .result;\n\n const fullServiceData = await Promise.all(\n serviceList.map(async (listItem) => {\n try {\n const [service, nextDescendents] = await Promise.all([\n getService({ serviceId: listItem._id, globalConfig, state }),\n getServiceDescendents({\n serviceId: listItem._id,\n globalConfig,\n state,\n }),\n ]);\n\n return {\n ...service,\n nextDescendents,\n };\n } catch (error) {\n if (\n !(\n error.response?.status === 403 &&\n error.response?.data?.message ===\n 'This operation is not available in ForgeRock Identity Cloud.'\n )\n ) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Unable to retrieve data for ${listItem._id} with error: ${message}`,\n type: 'error',\n state,\n });\n }\n }\n })\n );\n\n debugMessage({ message: `ServiceOps.getFullServices: end`, state });\n return fullServiceData.filter((data) => !!data); // make sure to filter out any undefined objects\n}\n\n/**\n * Saves a service using the provide id and data, including descendents\n * @param {string} serviceId the service id / name\n * @param {string} fullServiceData service object including descendants\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns promise resolving to a service object\n */\nasync function putFullService({\n serviceId,\n fullServiceData,\n clean,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n fullServiceData: FullService;\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}): Promise<AmServiceSkeleton> {\n debugMessage({\n message: `ServiceOps.putFullService: start, serviceId=${serviceId}, globalConfig=${globalConfig}`,\n state,\n });\n const nextDescendents = fullServiceData.nextDescendents;\n\n delete fullServiceData.nextDescendents;\n delete fullServiceData._rev;\n delete fullServiceData.enabled;\n\n if (clean) {\n try {\n debugMessage({ message: `ServiceOps.putFullService: clean`, state });\n await deleteFullService({ serviceId, globalConfig, state });\n } catch (error) {\n if (\n !(\n error.response?.status === 404 &&\n error.response?.data?.message === 'Not Found'\n )\n ) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Error deleting service '${serviceId}' before import: ${message}`,\n type: 'error',\n state,\n });\n }\n }\n }\n\n // create service first\n const result = await putService({\n serviceId,\n serviceData: fullServiceData,\n globalConfig,\n state,\n });\n\n // return fast if no next descendents supplied\n if (nextDescendents.length === 0) {\n debugMessage({\n message: `ServiceOps.putFullService: end (w/o descendents)`,\n state,\n });\n return result;\n }\n\n // now create next descendents\n await Promise.all(\n nextDescendents.map(async (descendent) => {\n const type = descendent._type._id;\n const descendentId = descendent._id;\n debugMessage({\n message: `ServiceOps.putFullService: descendentId=${descendentId}`,\n state,\n });\n let result = undefined;\n try {\n result = await putServiceNextDescendent({\n serviceId,\n serviceType: type,\n serviceNextDescendentId: descendentId,\n serviceNextDescendentData: descendent,\n globalConfig,\n state,\n });\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Put descendent '${descendentId}' of service '${serviceId}': ${message}`,\n type: 'error',\n state,\n });\n }\n return result;\n })\n );\n debugMessage({\n message: `ServiceOps.putFullService: end (w/ descendents)`,\n state,\n });\n}\n\n/**\n * Saves multiple services using the serviceEntries which contain both id and data with descendants\n * @param {[string, FullService][]} serviceEntries The services to add\n * @param {boolean} clean Indicates whether to remove possible existing services first\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns {Promise<AmService[]>} promise resolving to an array of service objects\n */\nasync function putFullServices({\n serviceEntries,\n clean,\n globalConfig = false,\n state,\n}: {\n serviceEntries: [string, FullService][];\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}): Promise<AmServiceSkeleton[]> {\n debugMessage({\n message: `ServiceOps.putFullServices: start, globalConfig=${globalConfig}`,\n state,\n });\n const results: AmServiceSkeleton[] = [];\n for (const [id, data] of serviceEntries) {\n try {\n const result = await putFullService({\n serviceId: id,\n fullServiceData: data,\n clean,\n globalConfig,\n state,\n });\n results.push(result);\n printMessage({ message: `Imported: ${id}`, type: 'info', state });\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage({\n message: `Import service '${id}': ${message}`,\n type: 'error',\n state,\n });\n if (detail) {\n printMessage({\n message: `Details: ${JSON.stringify(detail)}`,\n type: 'error',\n state,\n });\n }\n }\n }\n debugMessage({ message: `ServiceOps.putFullServices: end`, state });\n return results;\n}\n\n/**\n * Deletes the specified service\n * @param {string} serviceId The service to delete\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function deleteFullService({\n serviceId,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage({\n message: `ServiceOps.deleteFullService: start, globalConfig=${globalConfig}`,\n state,\n });\n const serviceNextDescendentData = await getServiceDescendents({\n serviceId,\n globalConfig,\n state,\n });\n\n await Promise.all(\n serviceNextDescendentData.map((nextDescendent) =>\n deleteServiceNextDescendent({\n serviceId,\n serviceType: nextDescendent._type._id,\n serviceNextDescendentId: nextDescendent._id,\n globalConfig,\n state,\n })\n )\n );\n\n await deleteService({ serviceId, globalConfig, state });\n debugMessage({ message: `ServiceOps.deleteFullService: end`, state });\n}\n\n/**\n * Deletes all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function deleteFullServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage({\n message: `ServiceOps.deleteFullServices: start, globalConfig=${globalConfig}`,\n state,\n });\n try {\n const serviceList = (await _getListOfServices({ globalConfig, state }))\n .result;\n\n await Promise.all(\n serviceList.map(async (serviceListItem) => {\n try {\n await deleteFullService({\n serviceId: serviceListItem._id,\n globalConfig,\n state,\n });\n } catch (error) {\n if (\n !(\n error.response?.status === 403 &&\n error.response?.data?.message ===\n 'This operation is not available in ForgeRock Identity Cloud.'\n )\n ) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Delete service '${serviceListItem._id}': ${message}`,\n state,\n type: 'error',\n });\n }\n }\n })\n );\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Delete services: ${message}`,\n type: 'error',\n state,\n });\n }\n debugMessage({ message: `ServiceOps.deleteFullServices: end`, state });\n}\n\n/**\n * Export service. The response can be saved to file as is.\n * @param serviceId service id/name\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\nexport async function exportService({\n serviceId,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n globalConfig: boolean;\n state: State;\n}): Promise<ServiceExportInterface> {\n debugMessage({\n message: `ServiceOps.exportService: start, globalConfig=${globalConfig}`,\n state,\n });\n const exportData = createServiceExportTemplate();\n try {\n const service = await getService({ serviceId, globalConfig, state });\n service.nextDescendents = await getServiceDescendents({\n serviceId,\n globalConfig,\n state,\n });\n exportData.service[serviceId] = service;\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Export service '${serviceId}': ${message}`,\n type: 'error',\n state,\n });\n }\n debugMessage({ message: `ServiceOps.exportService: end`, state });\n return exportData;\n}\n\n/**\n * Export all services\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function exportServices({\n globalConfig = false,\n state,\n}: {\n globalConfig: boolean;\n state: State;\n}): Promise<ServiceExportInterface> {\n debugMessage({\n message: `ServiceOps.exportServices: start, globalConfig=${globalConfig}`,\n state,\n });\n const exportData = createServiceExportTemplate();\n try {\n const services = await getFullServices({ globalConfig, state });\n for (const service of services) {\n exportData.service[service._type._id] = service;\n }\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage({\n message: `Export servics: ${message}`,\n type: 'error',\n state,\n });\n }\n debugMessage({ message: `ServiceOps.exportServices: end`, state });\n return exportData;\n}\n\n/**\n * Imports a single service using a reference to the service and a file to read the data from. Optionally clean (remove) an existing service first\n * @param {string} serviceId The service id/name to add\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n * @returns Promise resolving when the service has been imported\n */\nexport async function importService({\n serviceId,\n importData,\n clean,\n globalConfig = false,\n state,\n}: {\n serviceId: string;\n importData: ServiceExportInterface;\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}): Promise<AmServiceSkeleton> {\n debugMessage({\n message: `ServiceOps.importService: start, globalConfig=${globalConfig}`,\n state,\n });\n const serviceData = importData.service[serviceId];\n const result = await putFullService({\n serviceId,\n fullServiceData: serviceData,\n clean,\n globalConfig,\n state,\n });\n debugMessage({ message: `ServiceOps.importService: end`, state });\n return result;\n}\n\n/**\n * Imports multiple services from the same file. Optionally clean (remove) existing services first\n * @param {ServiceExportInterface} importData The service configuration export data to import\n * @param {boolean} clean Indicates whether to remove possible existing services first\n * @param {boolean} globalConfig true if the global service is the target of the operation, false otherwise. Default: false.\n */\nexport async function importServices({\n importData,\n clean,\n globalConfig = false,\n state,\n}: {\n importData: ServiceExportInterface;\n clean: boolean;\n globalConfig: boolean;\n state: State;\n}) {\n debugMessage({\n message: `ServiceOps.importServices: start, globalConfig=${globalConfig}`,\n state,\n });\n try {\n const result = await putFullServices({\n serviceEntries: Object.entries(importData.service),\n clean,\n globalConfig,\n state,\n });\n debugMessage({ message: `ServiceOps.importServices: end`, state });\n return result;\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage({\n message: `Unable to import services: error: ${message}`,\n type: 'error',\n state,\n });\n if (detail) {\n printMessage({\n message: `Details: ${JSON.stringify(detail)}`,\n type: 'error',\n state,\n });\n }\n throw error;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/ThemeOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AAIpE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI3C;;;;;OAKG;IACG,QAAQ,CACZ,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAA8B,GACpC,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;OAKG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,KAAK,GAAE,MAA8B,GACpC,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;OAMG;IACG,QAAQ,CACZ,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,aAAa,EACxB,KAAK,GAAE,MAA8B,GACpC,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;OAMG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAA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KAAK,EACL,KAAK,GACN,EAAE;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAa3B","file":"ThemeOps.d.ts","sourcesContent":["import { ThemeSkeleton, UiThemeRealmObject } from '../api/ApiTypes';\nimport { getConfigEntity, putConfigEntity } from '../api/IdmConfigApi';\nimport { getCurrentRealmName } from '../api/utils/ApiUtils';\nimport { debugMessage } from '../ops/utils/Console';\nimport State from '../shared/State';\n\nexport const THEMEREALM_ID = 'ui/themerealm';\n\nexport default class ThemeOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\n async getThemes(): Promise<ThemeSkeleton[]> {\n return getThemes({ state: this.state });\n }\n\n /**\n * Get theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async getTheme(\n themeId: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return getTheme({ themeId, realm, state: this.state });\n }\n\n /**\n * Get theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async getThemeByName(\n themeName: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return getThemeByName({ themeName, realm, state: this.state });\n }\n\n /**\n * Put theme by id\n * @param {string} themeId theme id\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async putTheme(\n themeId: string,\n themeData: ThemeSkeleton,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return putTheme({ themeId, themeData, realm, state: this.state });\n }\n\n /**\n * Put theme by name\n * @param {String} themeName theme name\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async putThemeByName(\n themeName: string,\n themeData: ThemeSkeleton,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return putThemeByName({ themeName, themeData, realm, state: this.state });\n }\n\n /**\n * Put all themes\n * @param {Map<string, ThemeSkeleton>} allThemesData themes object containing all themes for all realms\n * @param {string} realm realm name\n * @returns {Promise<Map<string, ThemeSkeleton>>} a promise that resolves to a themes object\n */\n async putThemes(\n themeMap: Map<string, ThemeSkeleton>\n ): Promise<Map<string, ThemeSkeleton>> {\n return putThemes({ themeMap, state: this.state });\n }\n\n /**\n * Delete theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\n async deleteTheme(\n themeId: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return deleteTheme({ themeId, realm, state: this.state });\n }\n\n /**\n * Delete theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\n async deleteThemeByName(\n themeName: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return deleteThemeByName({ themeName, realm, state: this.state });\n }\n\n /**\n * Delete all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\n async deleteThemes(\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton[]> {\n return deleteThemes({ realm, state: this.state });\n }\n}\n\n/**\n * Get realm themes\n * @param {UiThemeRealmObject} themes object containing themes\n * @param {string} realm realm name\n * @returns {ThemeSkeleton[]} array of theme pertaining to the current realm\n */\nfunction getRealmThemes({\n themes,\n realm,\n}: {\n themes: UiThemeRealmObject;\n realm: string;\n}): ThemeSkeleton[] {\n if (themes.realm && themes.realm[realm]) {\n return themes.realm[realm];\n }\n return [];\n}\n\n/**\n * Get all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\nexport async function getThemes({\n realm = null,\n state,\n}: {\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton[]> {\n realm = realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n return getRealmThemes({ themes, realm });\n}\n\n/**\n * Get theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function getTheme({\n themeId,\n realm,\n state,\n}: {\n themeId: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const found = getRealmThemes({ themes, realm }).filter(\n (theme) => theme._id === themeId\n );\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes with id '${themeId}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme with id '${themeId}' not found in realm '${realm}'!`);\n}\n\n/**\n * Get theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function getThemeByName({\n themeName,\n realm,\n state,\n}: {\n themeName: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const found = getRealmThemes({ themes, realm }).filter(\n (theme) => theme.name === themeName\n );\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes with the name '${themeName}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme '${themeName}' not found in realm '${realm}'!`);\n}\n\n/**\n * Put theme by id\n * @param {string} themeId theme id\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function putTheme({\n themeId,\n themeData,\n realm,\n state,\n}: {\n themeId: string;\n themeData: ThemeSkeleton;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const data = themeData;\n data._id = themeId;\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n let isNew = true;\n const realmThemes = getRealmThemes({ themes, realm }).map((theme) => {\n if (theme._id === themeId) {\n isNew = false;\n return data;\n }\n if (data.isDefault) theme.isDefault = false;\n return theme;\n });\n if (isNew) {\n realmThemes.push(data);\n }\n themes.realm[realm] = realmThemes;\n const found = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => theme._id === themeId);\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes with id '${themeId}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme with id '${themeId}' not saved in realm '${realm}'!`);\n}\n\n/**\n * Put theme by name\n * @param {String} themeName theme name\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function putThemeByName({\n themeName,\n themeData,\n realm,\n state,\n}: {\n themeName: string;\n themeData: ThemeSkeleton;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const data = themeData;\n data.name = themeName;\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n let isNew = true;\n const realmThemes = getRealmThemes({ themes, realm }).map((theme) => {\n if (theme.name === themeName) {\n isNew = false;\n return data;\n }\n if (data.isDefault) theme.isDefault = false;\n return theme;\n });\n if (isNew) {\n realmThemes.push(data);\n }\n themes['realm'][realm] = realmThemes;\n const found = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => theme.name === themeName);\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes '${themeName}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme '${themeName}' not saved in realm '${realm}'!`);\n}\n\n/**\n * Put all themes\n * @param {Map<string, ThemeSkeleton>} allThemesData themes object containing all themes for all realms\n * @param {string} realm realm name\n * @returns {Promise<Map<string, ThemeSkeleton>>} a promise that resolves to a themes object\n */\nexport async function putThemes({\n themeMap,\n realm = null,\n state,\n}: {\n themeMap: Map<string, ThemeSkeleton>;\n realm?: string;\n state: State;\n}): Promise<Map<string, ThemeSkeleton>> {\n debugMessage(`ThemeApi.putThemes: start`);\n realm = realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const allThemeIDs = Object.keys(themeMap);\n const existingThemeIDs = [];\n let defaultThemeId = null;\n // update existing themes\n let realmThemes = getRealmThemes({ themes, realm }).map((theme) => {\n if (themeMap[theme._id]) {\n debugMessage(`Update theme: ${theme._id} - ${theme.name}`);\n existingThemeIDs.push(theme._id);\n // remember the id of the last default theme\n if (themeMap[theme._id].isDefault) defaultThemeId = theme._id;\n return themeMap[theme._id];\n }\n return theme;\n });\n const newThemeIDs = allThemeIDs.filter(\n (id) => !existingThemeIDs.includes(id)\n );\n // add new themes\n newThemeIDs.forEach((themeId) => {\n debugMessage(\n `Add theme: ${themeMap[themeId]._id} - ${themeMap[themeId].name}`\n );\n // remember the id of the last default theme\n if (themeMap[themeId].isDefault) defaultThemeId = themeId;\n realmThemes.push(themeMap[themeId]);\n });\n // if we imported a default theme, flag all the other themes as not default\n if (defaultThemeId) {\n realmThemes = realmThemes.map((theme) => {\n theme.isDefault = theme._id === defaultThemeId;\n return theme;\n });\n }\n themes.realm[realm] = realmThemes;\n const updatedThemes = new Map(\n getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).map((theme) => [theme._id, theme])\n );\n debugMessage(updatedThemes);\n debugMessage(`ThemeApi.putThemes: finished`);\n return updatedThemes;\n}\n\n/**\n * Delete theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\nexport async function deleteTheme({\n themeId,\n realm,\n state,\n}: {\n themeId: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const realmThemes = getRealmThemes({ themes, realm });\n const deletedThemes: ThemeSkeleton[] = [];\n const finalThemes = realmThemes.filter((theme) => {\n if (theme._id !== themeId) {\n return true;\n }\n deletedThemes.push(theme);\n return false;\n });\n if (realmThemes.length === finalThemes.length)\n throw new Error(`'${themeId}' not found in realm '${realm}'`);\n themes.realm[realm] = realmThemes;\n const undeletedThemes = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => deletedThemes.includes(theme));\n if (deletedThemes.length > 0 && undeletedThemes.length === 0) {\n return deletedThemes[0];\n }\n throw new Error(\n `Theme(s) with id(s) '${undeletedThemes.map(\n (theme) => theme._id\n )}' not deleted from realm '${realm}'!`\n );\n}\n\n/**\n * Delete theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\nexport async function deleteThemeByName({\n themeName,\n realm,\n state,\n}: {\n themeName: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const realmThemes = getRealmThemes({ themes, realm });\n const deletedThemes: ThemeSkeleton[] = [];\n const finalThemes = realmThemes.filter((theme) => {\n if (theme.name !== themeName) {\n return true;\n }\n deletedThemes.push(theme);\n return false;\n });\n if (realmThemes.length === finalThemes.length)\n throw new Error(`'${themeName}' not found in realm '${realm}'`);\n themes.realm[realm] = finalThemes;\n const undeletedThemes = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => deletedThemes.includes(theme));\n if (deletedThemes.length > 0 && undeletedThemes.length === 0) {\n return deletedThemes[0];\n }\n throw new Error(\n `Theme(s) with id(s) '${undeletedThemes.map(\n (theme) => theme._id\n )}' not deleted from realm '${realm}'!`\n );\n}\n\n/**\n * Delete all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\nexport async function deleteThemes({\n realm,\n state,\n}: {\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton[]> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const realmThemes = themes.realm[realm];\n if (!realmThemes)\n throw new Error(`No theme configuration found for realm '${realm}'`);\n const deletedThemes: ThemeSkeleton[] = [];\n for (const theme of realmThemes) {\n deletedThemes.push(theme);\n }\n themes.realm[realm] = [];\n await putConfigEntity({ entityId: THEMEREALM_ID, entityData: themes, state });\n return deletedThemes;\n}\n"]}
1
+ {"version":3,"sources":["../src/ops/ThemeOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AAIpE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI3C;;;;;OAKG;IACG,QAAQ,CACZ,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAA8B,GACpC,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;OAKG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,KAAK,GAAE,MAA8B,GACpC,OAAO,CAAC,aA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T,KAAK,EACL,KAAK,GACN,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,aAAa,CAAC,CA+BzB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,KAAK,GACN,EAAE;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAa3B","file":"ThemeOps.d.ts","sourcesContent":["import { ThemeSkeleton, UiThemeRealmObject } from '../api/ApiTypes';\nimport { getConfigEntity, putConfigEntity } from '../api/IdmConfigApi';\nimport { getCurrentRealmName } from '../api/utils/ApiUtils';\nimport { debugMessage } from '../ops/utils/Console';\nimport State from '../shared/State';\n\nexport const THEMEREALM_ID = 'ui/themerealm';\n\nexport default class ThemeOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\n async getThemes(): Promise<ThemeSkeleton[]> {\n return getThemes({ state: this.state });\n }\n\n /**\n * Get theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async getTheme(\n themeId: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return getTheme({ themeId, realm, state: this.state });\n }\n\n /**\n * Get theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async getThemeByName(\n themeName: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return getThemeByName({ themeName, realm, state: this.state });\n }\n\n /**\n * Put theme by id\n * @param {string} themeId theme id\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async putTheme(\n themeId: string,\n themeData: ThemeSkeleton,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return putTheme({ themeId, themeData, realm, state: this.state });\n }\n\n /**\n * Put theme by name\n * @param {String} themeName theme name\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\n async putThemeByName(\n themeName: string,\n themeData: ThemeSkeleton,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return putThemeByName({ themeName, themeData, realm, state: this.state });\n }\n\n /**\n * Put all themes\n * @param {Map<string, ThemeSkeleton>} allThemesData themes object containing all themes for all realms\n * @param {string} realm realm name\n * @returns {Promise<Map<string, ThemeSkeleton>>} a promise that resolves to a themes object\n */\n async putThemes(\n themeMap: Map<string, ThemeSkeleton>\n ): Promise<Map<string, ThemeSkeleton>> {\n return putThemes({ themeMap, state: this.state });\n }\n\n /**\n * Delete theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\n async deleteTheme(\n themeId: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return deleteTheme({ themeId, realm, state: this.state });\n }\n\n /**\n * Delete theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\n async deleteThemeByName(\n themeName: string,\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton> {\n return deleteThemeByName({ themeName, realm, state: this.state });\n }\n\n /**\n * Delete all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\n async deleteThemes(\n realm: string = this.state.getRealm()\n ): Promise<ThemeSkeleton[]> {\n return deleteThemes({ realm, state: this.state });\n }\n}\n\n/**\n * Get realm themes\n * @param {UiThemeRealmObject} themes object containing themes\n * @param {string} realm realm name\n * @returns {ThemeSkeleton[]} array of theme pertaining to the current realm\n */\nfunction getRealmThemes({\n themes,\n realm,\n}: {\n themes: UiThemeRealmObject;\n realm: string;\n}): ThemeSkeleton[] {\n if (themes.realm && themes.realm[realm]) {\n return themes.realm[realm];\n }\n return [];\n}\n\n/**\n * Get all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\nexport async function getThemes({\n realm = null,\n state,\n}: {\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton[]> {\n realm = realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n return getRealmThemes({ themes, realm });\n}\n\n/**\n * Get theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function getTheme({\n themeId,\n realm,\n state,\n}: {\n themeId: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const found = getRealmThemes({ themes, realm }).filter(\n (theme) => theme._id === themeId\n );\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes with id '${themeId}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme with id '${themeId}' not found in realm '${realm}'!`);\n}\n\n/**\n * Get theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function getThemeByName({\n themeName,\n realm,\n state,\n}: {\n themeName: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const found = getRealmThemes({ themes, realm }).filter(\n (theme) => theme.name === themeName\n );\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes with the name '${themeName}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme '${themeName}' not found in realm '${realm}'!`);\n}\n\n/**\n * Put theme by id\n * @param {string} themeId theme id\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function putTheme({\n themeId,\n themeData,\n realm,\n state,\n}: {\n themeId: string;\n themeData: ThemeSkeleton;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const data = themeData;\n data._id = themeId;\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n let isNew = true;\n const realmThemes = getRealmThemes({ themes, realm }).map((theme) => {\n if (theme._id === themeId) {\n isNew = false;\n return data;\n }\n if (data.isDefault) theme.isDefault = false;\n return theme;\n });\n if (isNew) {\n realmThemes.push(data);\n }\n themes.realm[realm] = realmThemes;\n const found = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => theme._id === themeId);\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes with id '${themeId}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme with id '${themeId}' not saved in realm '${realm}'!`);\n}\n\n/**\n * Put theme by name\n * @param {String} themeName theme name\n * @param {ThemeSkeleton} themeData theme object\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object\n */\nexport async function putThemeByName({\n themeName,\n themeData,\n realm,\n state,\n}: {\n themeName: string;\n themeData: ThemeSkeleton;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const data = themeData;\n data.name = themeName;\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n let isNew = true;\n const realmThemes = getRealmThemes({ themes, realm }).map((theme) => {\n if (theme.name === themeName) {\n isNew = false;\n return data;\n }\n if (data.isDefault) theme.isDefault = false;\n return theme;\n });\n if (isNew) {\n realmThemes.push(data);\n }\n themes['realm'][realm] = realmThemes;\n const found = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => theme.name === themeName);\n if (found.length === 1) {\n return found[0];\n }\n if (found.length > 1) {\n throw new Error(\n `Multiple themes '${themeName}' found in realm '${realm}'!`\n );\n }\n throw new Error(`Theme '${themeName}' not saved in realm '${realm}'!`);\n}\n\n/**\n * Put all themes\n * @param {Map<string, ThemeSkeleton>} allThemesData themes object containing all themes for all realms\n * @param {string} realm realm name\n * @returns {Promise<Map<string, ThemeSkeleton>>} a promise that resolves to a themes object\n */\nexport async function putThemes({\n themeMap,\n realm = null,\n state,\n}: {\n themeMap: Map<string, ThemeSkeleton>;\n realm?: string;\n state: State;\n}): Promise<Map<string, ThemeSkeleton>> {\n debugMessage({ message: `ThemeApi.putThemes: start`, state });\n realm = realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const allThemeIDs = Object.keys(themeMap);\n const existingThemeIDs = [];\n let defaultThemeId = null;\n // update existing themes\n let realmThemes = getRealmThemes({ themes, realm }).map((theme) => {\n if (themeMap[theme._id]) {\n debugMessage({\n message: `Update theme: ${theme._id} - ${theme.name}`,\n state,\n });\n existingThemeIDs.push(theme._id);\n // remember the id of the last default theme\n if (themeMap[theme._id].isDefault) defaultThemeId = theme._id;\n return themeMap[theme._id];\n }\n return theme;\n });\n const newThemeIDs = allThemeIDs.filter(\n (id) => !existingThemeIDs.includes(id)\n );\n // add new themes\n newThemeIDs.forEach((themeId) => {\n debugMessage({\n message: `Add theme: ${themeMap[themeId]._id} - ${themeMap[themeId].name}`,\n state,\n });\n // remember the id of the last default theme\n if (themeMap[themeId].isDefault) defaultThemeId = themeId;\n realmThemes.push(themeMap[themeId]);\n });\n // if we imported a default theme, flag all the other themes as not default\n if (defaultThemeId) {\n realmThemes = realmThemes.map((theme) => {\n theme.isDefault = theme._id === defaultThemeId;\n return theme;\n });\n }\n themes.realm[realm] = realmThemes;\n const updatedThemes = new Map(\n getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).map((theme) => [theme._id, theme])\n );\n debugMessage({ message: updatedThemes, state });\n debugMessage({ message: `ThemeApi.putThemes: finished`, state });\n return updatedThemes;\n}\n\n/**\n * Delete theme by id\n * @param {string} themeId theme id\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\nexport async function deleteTheme({\n themeId,\n realm,\n state,\n}: {\n themeId: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const realmThemes = getRealmThemes({ themes, realm });\n const deletedThemes: ThemeSkeleton[] = [];\n const finalThemes = realmThemes.filter((theme) => {\n if (theme._id !== themeId) {\n return true;\n }\n deletedThemes.push(theme);\n return false;\n });\n if (realmThemes.length === finalThemes.length)\n throw new Error(`'${themeId}' not found in realm '${realm}'`);\n themes.realm[realm] = realmThemes;\n const undeletedThemes = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => deletedThemes.includes(theme));\n if (deletedThemes.length > 0 && undeletedThemes.length === 0) {\n return deletedThemes[0];\n }\n throw new Error(\n `Theme(s) with id(s) '${undeletedThemes.map(\n (theme) => theme._id\n )}' not deleted from realm '${realm}'!`\n );\n}\n\n/**\n * Delete theme by name\n * @param {string} themeName theme name\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object\n */\nexport async function deleteThemeByName({\n themeName,\n realm,\n state,\n}: {\n themeName: string;\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const realmThemes = getRealmThemes({ themes, realm });\n const deletedThemes: ThemeSkeleton[] = [];\n const finalThemes = realmThemes.filter((theme) => {\n if (theme.name !== themeName) {\n return true;\n }\n deletedThemes.push(theme);\n return false;\n });\n if (realmThemes.length === finalThemes.length)\n throw new Error(`'${themeName}' not found in realm '${realm}'`);\n themes.realm[realm] = finalThemes;\n const undeletedThemes = getRealmThemes({\n themes: await putConfigEntity({\n entityId: THEMEREALM_ID,\n entityData: themes,\n state,\n }),\n realm,\n }).filter((theme) => deletedThemes.includes(theme));\n if (deletedThemes.length > 0 && undeletedThemes.length === 0) {\n return deletedThemes[0];\n }\n throw new Error(\n `Theme(s) with id(s) '${undeletedThemes.map(\n (theme) => theme._id\n )}' not deleted from realm '${realm}'!`\n );\n}\n\n/**\n * Delete all themes\n * @param {string} realm realm name\n * @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes\n */\nexport async function deleteThemes({\n realm,\n state,\n}: {\n realm?: string;\n state: State;\n}): Promise<ThemeSkeleton[]> {\n realm ? realm : getCurrentRealmName(state);\n const themes = await getConfigEntity({ entityId: THEMEREALM_ID, state });\n const realmThemes = themes.realm[realm];\n if (!realmThemes)\n throw new Error(`No theme configuration found for realm '${realm}'`);\n const deletedThemes: ThemeSkeleton[] = [];\n for (const theme of realmThemes) {\n deletedThemes.push(theme);\n }\n themes.realm[realm] = [];\n await putConfigEntity({ entityId: THEMEREALM_ID, entityData: themes, state });\n return deletedThemes;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/cloud/FeatureOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAGvC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAIhD;;;;OAIG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAGtD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,EAChC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAU9B;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CAInB","file":"FeatureOps.d.ts","sourcesContent":["import {\n getFeatures as _getFeatures,\n FeatureInterface,\n} from '../../api/cloud/FeatureApi';\nimport State from '../../shared/State';\nimport { debugMessage } from '../utils/Console';\n\nexport default class FeatureOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all features\n * @returns {Promise<FeatureInterface[]>} a promise that resolves to an array of feature objects\n */\n async getFeatures(): Promise<FeatureInterface[]> {\n return getFeatures({ state: this.state });\n }\n\n /**\n * Check if feature is available\n * @param {string} featureId feature id (e.g. 'service-accounts')\n * @returns {Promise<boolean>} a promise that resolves to true if the feature is available and to false otherwise\n */\n async hasFeature(featureId: string): Promise<boolean> {\n return hasFeature({ featureId, state: this.state });\n }\n}\n\n/**\n * Get all features\n * @returns {Promise<FeatureInterface[]>} a promise that resolves to an array of feature objects\n */\nexport async function getFeatures({\n state,\n}: {\n state: State;\n}): Promise<FeatureInterface[]> {\n if (typeof state.getFeatures() !== 'undefined') return state.getFeatures();\n try {\n const { result } = await _getFeatures({ state });\n state.setFeatures(JSON.parse(JSON.stringify(result)));\n } catch (error) {\n debugMessage(error.response?.data);\n state.setFeatures([]);\n }\n return state.getFeatures();\n}\n\n/**\n * Check if feature is available\n * @param {string} featureId feature id (e.g. 'service-accounts')\n * @returns {Promise<boolean>} a promise that resolves to true if the feature is available and to false otherwise\n */\nexport async function hasFeature({\n featureId,\n state,\n}: {\n featureId: string;\n state: State;\n}): Promise<boolean> {\n if (typeof state.getFeatures() === 'undefined') await getFeatures({ state });\n const featureIds = state.getFeatures().map((feature) => feature._id);\n return featureIds.includes(featureId);\n}\n"]}
1
+ {"version":3,"sources":["../src/ops/cloud/FeatureOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAGvC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAIhD;;;;OAIG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAGtD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,EAChC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAU9B;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CAInB","file":"FeatureOps.d.ts","sourcesContent":["import {\n getFeatures as _getFeatures,\n FeatureInterface,\n} from '../../api/cloud/FeatureApi';\nimport State from '../../shared/State';\nimport { debugMessage } from '../utils/Console';\n\nexport default class FeatureOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all features\n * @returns {Promise<FeatureInterface[]>} a promise that resolves to an array of feature objects\n */\n async getFeatures(): Promise<FeatureInterface[]> {\n return getFeatures({ state: this.state });\n }\n\n /**\n * Check if feature is available\n * @param {string} featureId feature id (e.g. 'service-accounts')\n * @returns {Promise<boolean>} a promise that resolves to true if the feature is available and to false otherwise\n */\n async hasFeature(featureId: string): Promise<boolean> {\n return hasFeature({ featureId, state: this.state });\n }\n}\n\n/**\n * Get all features\n * @returns {Promise<FeatureInterface[]>} a promise that resolves to an array of feature objects\n */\nexport async function getFeatures({\n state,\n}: {\n state: State;\n}): Promise<FeatureInterface[]> {\n if (typeof state.getFeatures() !== 'undefined') return state.getFeatures();\n try {\n const { result } = await _getFeatures({ state });\n state.setFeatures(JSON.parse(JSON.stringify(result)));\n } catch (error) {\n debugMessage({ message: error.response?.data, state });\n state.setFeatures([]);\n }\n return state.getFeatures();\n}\n\n/**\n * Check if feature is available\n * @param {string} featureId feature id (e.g. 'service-accounts')\n * @returns {Promise<boolean>} a promise that resolves to true if the feature is available and to false otherwise\n */\nexport async function hasFeature({\n featureId,\n state,\n}: {\n featureId: string;\n state: State;\n}): Promise<boolean> {\n if (typeof state.getFeatures() === 'undefined') await getFeatures({ state });\n const featureIds = state.getFeatures().map((feature) => feature._id);\n return featureIds.includes(featureId);\n}\n"]}
@@ -1,6 +1,6 @@
1
+ import { VersionOfSecretStatus } from '../../api/ApiTypes';
1
2
  import { createNewVersionOfSecret, deleteSecret, deleteVersionOfSecret, getSecret, getSecrets, getSecretVersions, putSecret, setSecretDescription, setStatusOfVersionOfSecret } from '../../api/cloud/SecretsApi';
2
3
  import State from '../../shared/State';
3
- import { VersionOfSecretStatus } from '../../api/cloud/SecretsApi';
4
4
  export default class SecretsOps {
5
5
  state: State;
6
6
  constructor(state: State);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/cloud/SecretsOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,iBAAiB,EAEjB,SAAS,EACT,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,UAAU;IAIhB;;;;OAIG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM;IAIhC;;;;;;;;OAQG;IACG,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,SAAY,EACpB,iBAAiB,UAAO;IAY1B;;;;;OAKG;IACG,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAIhE;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM;IAInC;;;;OAIG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAIxC;;;;;OAKG;IACG,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI9D;;;;;OAKG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAI1D;;;;;;OAMG;IACG,0BAA0B,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,qBAAqB;IAU/B;;;;;OAKG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAG9D;AAED,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,oBAAoB,EACpB,0BAA0B,GAC3B,CAAC","file":"SecretsOps.d.ts","sourcesContent":["import {\n createNewVersionOfSecret,\n deleteSecret,\n deleteVersionOfSecret,\n getSecret,\n getSecrets,\n getSecretVersions,\n getVersionOfSecret,\n putSecret,\n setSecretDescription,\n setStatusOfVersionOfSecret,\n} from '../../api/cloud/SecretsApi';\nimport State from '../../shared/State';\nimport { VersionOfSecretStatus } from '../../api/cloud/SecretsApi';\n\nexport default class SecretsOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all secrets\n * @returns {Promise<unknown[]>} a promise that resolves to an array of secrets\n */\n async getSecrets() {\n return getSecrets({ state: this.state });\n }\n\n /**\n * Get secret\n * @param secretId secret id/name\n * @returns {Promise<unknown>} a promise that resolves to a secret\n */\n async getSecret(secretId: string) {\n return getSecret({ secretId, state: this.state });\n }\n\n /**\n * Create secret\n * @param {string} secretId secret id/name\n * @param {string} value secret value\n * @param {string} description secret description\n * @param {string} encoding secret encoding (only `generic` is supported)\n * @param {boolean} useInPlaceholders flag indicating if the secret can be used in placeholders\n * @returns {Promise<unknown>} a promise that resolves to a secret\n */\n async putSecret(\n secretId: string,\n value: string,\n description: string,\n encoding = 'generic',\n useInPlaceholders = true\n ) {\n return putSecret({\n secretId,\n value,\n description,\n encoding,\n useInPlaceholders,\n state: this.state,\n });\n }\n\n /**\n * Set secret description\n * @param {string} secretId secret id/name\n * @param {string} description secret description\n * @returns {Promise<unknown>} a promise that resolves to a status object\n */\n async setSecretDescription(secretId: string, description: string) {\n return setSecretDescription({ secretId, description, state: this.state });\n }\n\n /**\n * Delete secret\n * @param {string} secretId secret id/name\n * @returns {Promise<unknown>} a promise that resolves to a secret object\n */\n async deleteSecret(secretId: string) {\n return deleteSecret({ secretId, state: this.state });\n }\n\n /**\n * Get secret versions\n * @param {string} secretId secret id/name\n * @returns {Promise<unknown>} a promise that resolves to an array of secret versions\n */\n async getSecretVersions(secretId: string) {\n return getSecretVersions({ secretId, state: this.state });\n }\n\n /**\n * Create new secret version\n * @param {string} secretId secret id/name\n * @param {string} value secret value\n * @returns {Promise<unknown>} a promise that resolves to a version object\n */\n async createNewVersionOfSecret(secretId: string, value: string) {\n return createNewVersionOfSecret({ secretId, value, state: this.state });\n }\n\n /**\n * Get version of secret\n * @param {string} secretId secret id/name\n * @param {string} version secret version\n * @returns {Promise<unknown>} a promise that resolves to a version object\n */\n async getVersionOfSecret(secretId: string, version: string) {\n return getVersionOfSecret({ secretId, version, state: this.state });\n }\n\n /**\n * Update the status of a version of a secret\n * @param {string} secretId secret id/name\n * @param {string} version secret version\n * @param {VersionOfSecretStatus} status status\n * @returns {Promise<unknown>} a promise that resolves to a status object\n */\n async setStatusOfVersionOfSecret(\n secretId: string,\n version: string,\n status: VersionOfSecretStatus\n ) {\n return setStatusOfVersionOfSecret({\n secretId,\n version,\n status,\n state: this.state,\n });\n }\n\n /**\n * Delete version of secret\n * @param {string} secretId secret id/name\n * @param {string} version secret version\n * @returns {Promise<unknown>} a promise that resolves to a version object\n */\n async deleteVersionOfSecret(secretId: string, version: string) {\n return deleteVersionOfSecret({ secretId, version, state: this.state });\n }\n}\n\nexport {\n createNewVersionOfSecret,\n deleteSecret,\n deleteVersionOfSecret,\n getSecret,\n getSecrets,\n getSecretVersions,\n putSecret,\n setSecretDescription,\n setStatusOfVersionOfSecret,\n};\n"]}
1
+ {"version":3,"sources":["../src/ops/cloud/SecretsOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,iBAAiB,EAEjB,SAAS,EACT,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,UAAU;IAIhB;;;;OAIG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM;IAIhC;;;;;;;;OAQG;IACG,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,SAAY,EACpB,iBAAiB,UAAO;IAY1B;;;;;OAKG;IACG,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAIhE;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM;IAInC;;;;OAIG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAIxC;;;;;OAKG;IACG,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI9D;;;;;OAKG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAI1D;;;;;;OAMG;IACG,0BAA0B,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,qBAAqB;IAU/B;;;;;OAKG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAG9D;AAED,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,oBAAoB,EACpB,0BAA0B,GAC3B,CAAC","file":"SecretsOps.d.ts","sourcesContent":["import { VersionOfSecretStatus } from '../../api/ApiTypes';\nimport {\n createNewVersionOfSecret,\n deleteSecret,\n deleteVersionOfSecret,\n getSecret,\n getSecrets,\n getSecretVersions,\n getVersionOfSecret,\n putSecret,\n setSecretDescription,\n setStatusOfVersionOfSecret,\n} from '../../api/cloud/SecretsApi';\nimport State from '../../shared/State';\n\nexport default class SecretsOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all secrets\n * @returns {Promise<unknown[]>} a promise that resolves to an array of secrets\n */\n async getSecrets() {\n return getSecrets({ state: this.state });\n }\n\n /**\n * Get secret\n * @param secretId secret id/name\n * @returns {Promise<unknown>} a promise that resolves to a secret\n */\n async getSecret(secretId: string) {\n return getSecret({ secretId, state: this.state });\n }\n\n /**\n * Create secret\n * @param {string} secretId secret id/name\n * @param {string} value secret value\n * @param {string} description secret description\n * @param {string} encoding secret encoding (only `generic` is supported)\n * @param {boolean} useInPlaceholders flag indicating if the secret can be used in placeholders\n * @returns {Promise<unknown>} a promise that resolves to a secret\n */\n async putSecret(\n secretId: string,\n value: string,\n description: string,\n encoding = 'generic',\n useInPlaceholders = true\n ) {\n return putSecret({\n secretId,\n value,\n description,\n encoding,\n useInPlaceholders,\n state: this.state,\n });\n }\n\n /**\n * Set secret description\n * @param {string} secretId secret id/name\n * @param {string} description secret description\n * @returns {Promise<unknown>} a promise that resolves to a status object\n */\n async setSecretDescription(secretId: string, description: string) {\n return setSecretDescription({ secretId, description, state: this.state });\n }\n\n /**\n * Delete secret\n * @param {string} secretId secret id/name\n * @returns {Promise<unknown>} a promise that resolves to a secret object\n */\n async deleteSecret(secretId: string) {\n return deleteSecret({ secretId, state: this.state });\n }\n\n /**\n * Get secret versions\n * @param {string} secretId secret id/name\n * @returns {Promise<unknown>} a promise that resolves to an array of secret versions\n */\n async getSecretVersions(secretId: string) {\n return getSecretVersions({ secretId, state: this.state });\n }\n\n /**\n * Create new secret version\n * @param {string} secretId secret id/name\n * @param {string} value secret value\n * @returns {Promise<unknown>} a promise that resolves to a version object\n */\n async createNewVersionOfSecret(secretId: string, value: string) {\n return createNewVersionOfSecret({ secretId, value, state: this.state });\n }\n\n /**\n * Get version of secret\n * @param {string} secretId secret id/name\n * @param {string} version secret version\n * @returns {Promise<unknown>} a promise that resolves to a version object\n */\n async getVersionOfSecret(secretId: string, version: string) {\n return getVersionOfSecret({ secretId, version, state: this.state });\n }\n\n /**\n * Update the status of a version of a secret\n * @param {string} secretId secret id/name\n * @param {string} version secret version\n * @param {VersionOfSecretStatus} status status\n * @returns {Promise<unknown>} a promise that resolves to a status object\n */\n async setStatusOfVersionOfSecret(\n secretId: string,\n version: string,\n status: VersionOfSecretStatus\n ) {\n return setStatusOfVersionOfSecret({\n secretId,\n version,\n status,\n state: this.state,\n });\n }\n\n /**\n * Delete version of secret\n * @param {string} secretId secret id/name\n * @param {string} version secret version\n * @returns {Promise<unknown>} a promise that resolves to a version object\n */\n async deleteVersionOfSecret(secretId: string, version: string) {\n return deleteVersionOfSecret({ secretId, version, state: this.state });\n }\n}\n\nexport {\n createNewVersionOfSecret,\n deleteSecret,\n deleteVersionOfSecret,\n getSecret,\n getSecrets,\n getSecretVersions,\n putSecret,\n setSecretDescription,\n setStatusOfVersionOfSecret,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/cloud/ServiceAccountOps.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAI/D,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,iCAAiC,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;;;;OAQG;IACG,oBAAoB,CACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,QAAQ,GAAG,UAAU,EACpC,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,yBAAyB,CAAC;IAWrC;;;;OAIG;IACG,iBAAiB,CAAC,gBAAgB,EAAE,MAAM;CAGjD;AAID,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,cAAc,GAAG,yBAAyB,GACpD,8BAA8B,CAAC;AAEjC;;;GAGG;AACH,wBAAsB,iCAAiC,CAAC,EACtD,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CAUnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,IAAI,EACJ,WAAW,EACX,aAAa,EACb,MAAM,EACN,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAmBrC;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,gBAAgB,EAChB,KAAK,GACN,EAAE;IACD,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,KAAK,CAAC;CACd,2BASA","file":"ServiceAccountOps.d.ts","sourcesContent":["import {\n createManagedObject,\n getManagedObject,\n} from '../../api/ManagedObjectApi';\nimport { JwksInterface } from '../JoseOps';\nimport { IdObjectSkeletonInterface } from '../../api/ApiTypes';\nimport { debugMessage } from '../utils/Console';\nimport { hasFeature } from './FeatureOps';\nimport { getTenantURL } from '../../api/utils/ApiUtils';\nimport State from '../../shared/State';\n\nexport default class ServiceAccountOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Check if service accounts are available\n * @returns {Promise<boolean>} true if service accounts are available, false otherwise\n */\n async isServiceAccountsFeatureAvailable(): Promise<boolean> {\n return isServiceAccountsFeatureAvailable({ state: this.state });\n }\n\n /**\n * Create service account\n * @param {string} name Human-readable name of service account\n * @param {string} description Description of service account\n * @param {'Active' | 'Inactive'} accountStatus Service account status\n * @param {string[]} scopes Scopes.\n * @param {JwksInterface} jwks Java Web Key Set\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\n async createServiceAccount(\n name: string,\n description: string,\n accountStatus: 'Active' | 'Inactive',\n scopes: string[],\n jwks: JwksInterface\n ): Promise<IdObjectSkeletonInterface> {\n return createServiceAccount({\n name,\n description,\n accountStatus,\n scopes,\n jwks,\n state: this.state,\n });\n }\n\n /**\n * Get service account\n * @param {string} serviceAccountId service account id\n * @returns {Promise<ServiceAccount>} a promise resolving to a service account object\n */\n async getServiceAccount(serviceAccountId: string) {\n return getServiceAccount({ serviceAccountId, state: this.state });\n }\n}\n\nconst moType = 'svcacct';\n\nexport interface ServiceAccountPayloadInterface {\n name: string;\n description: string;\n accountStatus: 'Active' | 'Inactive';\n scopes: string[];\n jwks: string;\n}\n\nexport type ServiceAccount = IdObjectSkeletonInterface &\n ServiceAccountPayloadInterface;\n\n/**\n * Check if service accounts are available\n * @returns {Promise<boolean>} true if service accounts are available, false otherwise\n */\nexport async function isServiceAccountsFeatureAvailable({\n state,\n}: {\n state: State;\n}): Promise<boolean> {\n debugMessage(`ServiceAccountOps.isServiceAccountsFeatureAvailable: start`);\n const featureAvailable = await hasFeature({\n featureId: 'service-accounts',\n state,\n });\n debugMessage(\n `ServiceAccountOps.isServiceAccountsFeatureAvailable: end, available=${featureAvailable}`\n );\n return featureAvailable;\n}\n\n/**\n * Create service account\n * @param {string} name Human-readable name of service account\n * @param {string} description Description of service account\n * @param {'Active' | 'Inactive'} accountStatus Service account status\n * @param {string[]} scopes Scopes.\n * @param {JwksInterface} jwks Java Web Key Set\n * @param {State} state library state\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\nexport async function createServiceAccount({\n name,\n description,\n accountStatus,\n scopes,\n jwks,\n state,\n}: {\n name: string;\n description: string;\n accountStatus: 'Active' | 'Inactive';\n scopes: string[];\n jwks: JwksInterface;\n state: State;\n}): Promise<IdObjectSkeletonInterface> {\n debugMessage(`ServiceAccountOps.createServiceAccount: start`);\n const payload: ServiceAccountPayloadInterface = {\n name,\n description,\n accountStatus,\n scopes,\n jwks: JSON.stringify(jwks),\n };\n debugMessage(`ServiceAccountOps: createServiceAccount: payload:`);\n debugMessage(payload);\n const result = await createManagedObject(\n getTenantURL(state.getHost()),\n moType,\n payload,\n state\n );\n debugMessage(`ServiceAccountOps.createServiceAccount: end`);\n return result;\n}\n\n/**\n * Get service account\n * @param {string} serviceAccountId service account id\n * @param {State} state library state\n * @returns {Promise} a promise resolving to a service account object\n */\nexport async function getServiceAccount({\n serviceAccountId,\n state,\n}: {\n serviceAccountId: string;\n state: State;\n}) {\n const serviceAccount = await getManagedObject({\n baseUrl: getTenantURL(state.getHost()),\n type: moType,\n id: serviceAccountId,\n fields: ['*'],\n state,\n });\n return serviceAccount as ServiceAccount;\n}\n"]}
1
+ {"version":3,"sources":["../src/ops/cloud/ServiceAccountOps.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAI/D,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,iCAAiC,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;;;;OAQG;IACG,oBAAoB,CACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,QAAQ,GAAG,UAAU,EACpC,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,yBAAyB,CAAC;IAWrC;;;;OAIG;IACG,iBAAiB,CAAC,gBAAgB,EAAE,MAAM;CAGjD;AAID,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,cAAc,GAAG,yBAAyB,GACpD,8BAA8B,CAAC;AAEjC;;;GAGG;AACH,wBAAsB,iCAAiC,CAAC,EACtD,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CAcnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,IAAI,EACJ,WAAW,EACX,aAAa,EACb,MAAM,EACN,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,yBAAyB,CAAC,CA4BrC;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,gBAAgB,EAChB,KAAK,GACN,EAAE;IACD,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,KAAK,CAAC;CACd,2BASA","file":"ServiceAccountOps.d.ts","sourcesContent":["import {\n createManagedObject,\n getManagedObject,\n} from '../../api/ManagedObjectApi';\nimport { JwksInterface } from '../JoseOps';\nimport { IdObjectSkeletonInterface } from '../../api/ApiTypes';\nimport { debugMessage } from '../utils/Console';\nimport { hasFeature } from './FeatureOps';\nimport { getTenantURL } from '../../api/utils/ApiUtils';\nimport State from '../../shared/State';\n\nexport default class ServiceAccountOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Check if service accounts are available\n * @returns {Promise<boolean>} true if service accounts are available, false otherwise\n */\n async isServiceAccountsFeatureAvailable(): Promise<boolean> {\n return isServiceAccountsFeatureAvailable({ state: this.state });\n }\n\n /**\n * Create service account\n * @param {string} name Human-readable name of service account\n * @param {string} description Description of service account\n * @param {'Active' | 'Inactive'} accountStatus Service account status\n * @param {string[]} scopes Scopes.\n * @param {JwksInterface} jwks Java Web Key Set\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\n async createServiceAccount(\n name: string,\n description: string,\n accountStatus: 'Active' | 'Inactive',\n scopes: string[],\n jwks: JwksInterface\n ): Promise<IdObjectSkeletonInterface> {\n return createServiceAccount({\n name,\n description,\n accountStatus,\n scopes,\n jwks,\n state: this.state,\n });\n }\n\n /**\n * Get service account\n * @param {string} serviceAccountId service account id\n * @returns {Promise<ServiceAccount>} a promise resolving to a service account object\n */\n async getServiceAccount(serviceAccountId: string) {\n return getServiceAccount({ serviceAccountId, state: this.state });\n }\n}\n\nconst moType = 'svcacct';\n\nexport interface ServiceAccountPayloadInterface {\n name: string;\n description: string;\n accountStatus: 'Active' | 'Inactive';\n scopes: string[];\n jwks: string;\n}\n\nexport type ServiceAccount = IdObjectSkeletonInterface &\n ServiceAccountPayloadInterface;\n\n/**\n * Check if service accounts are available\n * @returns {Promise<boolean>} true if service accounts are available, false otherwise\n */\nexport async function isServiceAccountsFeatureAvailable({\n state,\n}: {\n state: State;\n}): Promise<boolean> {\n debugMessage({\n message: `ServiceAccountOps.isServiceAccountsFeatureAvailable: start`,\n state,\n });\n const featureAvailable = await hasFeature({\n featureId: 'service-accounts',\n state,\n });\n debugMessage({\n message: `ServiceAccountOps.isServiceAccountsFeatureAvailable: end, available=${featureAvailable}`,\n state,\n });\n return featureAvailable;\n}\n\n/**\n * Create service account\n * @param {string} name Human-readable name of service account\n * @param {string} description Description of service account\n * @param {'Active' | 'Inactive'} accountStatus Service account status\n * @param {string[]} scopes Scopes.\n * @param {JwksInterface} jwks Java Web Key Set\n * @param {State} state library state\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\nexport async function createServiceAccount({\n name,\n description,\n accountStatus,\n scopes,\n jwks,\n state,\n}: {\n name: string;\n description: string;\n accountStatus: 'Active' | 'Inactive';\n scopes: string[];\n jwks: JwksInterface;\n state: State;\n}): Promise<IdObjectSkeletonInterface> {\n debugMessage({\n message: `ServiceAccountOps.createServiceAccount: start`,\n state,\n });\n const payload: ServiceAccountPayloadInterface = {\n name,\n description,\n accountStatus,\n scopes,\n jwks: JSON.stringify(jwks),\n };\n debugMessage({\n message: `ServiceAccountOps: createServiceAccount: payload:`,\n state,\n });\n debugMessage({ message: payload, state });\n const result = await createManagedObject(\n getTenantURL(state.getHost()),\n moType,\n payload,\n state\n );\n debugMessage({\n message: `ServiceAccountOps.createServiceAccount: end`,\n state,\n });\n return result;\n}\n\n/**\n * Get service account\n * @param {string} serviceAccountId service account id\n * @param {State} state library state\n * @returns {Promise} a promise resolving to a service account object\n */\nexport async function getServiceAccount({\n serviceAccountId,\n state,\n}: {\n serviceAccountId: string;\n state: State;\n}) {\n const serviceAccount = await getManagedObject({\n baseUrl: getTenantURL(state.getHost()),\n type: moType,\n id: serviceAccountId,\n fields: ['*'],\n state,\n });\n return serviceAccount as ServiceAccount;\n}\n"]}