@rockcarver/frodo-lib 2.0.0-1 → 2.0.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/cjs/api/ApiTypes.js.map +1 -1
- package/cjs/index.js +1 -105
- package/cjs/index.js.map +1 -1
- package/cjs/lib/FrodoLib.js +20 -20
- package/cjs/lib/FrodoLib.js.map +1 -1
- package/cjs/ops/AgentOps.js +8 -0
- package/cjs/ops/AgentOps.js.map +1 -1
- package/cjs/ops/AuthenticateOps.js +33 -6
- package/cjs/ops/AuthenticateOps.js.map +1 -1
- package/cjs/ops/CirclesOfTrustOps.js +36 -10
- package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
- package/cjs/ops/ConnectionProfileOps.js +13 -126
- package/cjs/ops/ConnectionProfileOps.js.map +1 -1
- package/cjs/ops/IdmOps.js.map +1 -1
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/OAuth2OidcOps.js +84 -0
- package/cjs/ops/OAuth2OidcOps.js.map +1 -0
- package/cjs/ops/ResourceTypeOps.js +65 -49
- package/cjs/ops/ResourceTypeOps.js.map +1 -1
- package/cjs/ops/ServiceOps.js +3 -0
- package/cjs/ops/ServiceOps.js.map +1 -1
- package/cjs/ops/ThemeOps.js +28 -14
- package/cjs/ops/ThemeOps.js.map +1 -1
- package/cjs/ops/cloud/LogOps.js +3 -13
- package/cjs/ops/cloud/LogOps.js.map +1 -1
- package/cjs/ops/utils/Console.js +7 -7
- package/cjs/ops/utils/Console.js.map +1 -1
- package/cjs/ops/utils/ExportImportUtils.js +109 -0
- package/cjs/ops/utils/ExportImportUtils.js.map +1 -1
- package/cjs/ops/utils/ExportImportUtils.test.js.map +1 -1
- package/cjs/ops/utils/Version.js +29 -6
- package/cjs/ops/utils/Version.js.map +1 -1
- package/cjs/ops/utils/Version.test.js.map +1 -1
- package/cjs/shared/State.js +0 -2
- package/cjs/shared/State.js.map +1 -1
- package/esm/index.mjs +1 -59
- package/esm/lib/FrodoLib.mjs +19 -18
- package/esm/ops/AgentOps.mjs +8 -0
- package/esm/ops/AuthenticateOps.mjs +24 -4
- package/esm/ops/CirclesOfTrustOps.mjs +18 -2
- package/esm/ops/ConnectionProfileOps.mjs +1 -105
- package/esm/ops/OAuth2OidcOps.mjs +40 -0
- package/esm/ops/ResourceTypeOps.mjs +14 -4
- package/esm/ops/ServiceOps.mjs +3 -0
- package/esm/ops/ThemeOps.mjs +7 -7
- package/esm/ops/cloud/LogOps.mjs +3 -13
- package/esm/ops/utils/Console.mjs +8 -8
- package/esm/ops/utils/ExportImportUtils.mjs +101 -0
- package/esm/ops/utils/ExportImportUtils.test.mjs +15 -2
- package/esm/ops/utils/Version.mjs +21 -4
- package/esm/ops/utils/Version.test.mjs +4 -1
- package/esm/shared/State.mjs +0 -2
- package/package.json +1 -1
- package/types/api/ApiTypes.d.ts +11 -11
- package/types/api/ApiTypes.d.ts.map +1 -1
- package/types/index.d.ts +1 -48
- package/types/index.d.ts.map +1 -1
- package/types/lib/FrodoLib.d.ts +13 -9
- package/types/lib/FrodoLib.d.ts.map +1 -1
- package/types/ops/AgentOps.d.ts +5 -0
- package/types/ops/AgentOps.d.ts.map +1 -1
- package/types/ops/AuthenticateOps.d.ts +11 -1
- package/types/ops/AuthenticateOps.d.ts.map +1 -1
- package/types/ops/CirclesOfTrustOps.d.ts +16 -2
- package/types/ops/CirclesOfTrustOps.d.ts.map +1 -1
- package/types/ops/ConnectionProfileOps.d.ts +0 -19
- package/types/ops/ConnectionProfileOps.d.ts.map +1 -1
- package/types/ops/IdmOps.d.ts +1 -1
- package/types/ops/IdmOps.d.ts.map +1 -1
- package/types/ops/JourneyOps.d.ts +2 -2
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/OAuth2OidcOps.d.ts +11 -0
- package/types/ops/OAuth2OidcOps.d.ts.map +1 -0
- package/types/ops/ResourceTypeOps.d.ts +3 -3
- package/types/ops/ResourceTypeOps.d.ts.map +1 -1
- package/types/ops/ServiceOps.d.ts +1 -0
- package/types/ops/ServiceOps.d.ts.map +1 -1
- package/types/ops/ThemeOps.d.ts +14 -14
- package/types/ops/ThemeOps.d.ts.map +1 -1
- package/types/ops/cloud/LogOps.d.ts +1 -1
- package/types/ops/cloud/LogOps.d.ts.map +1 -1
- package/types/ops/utils/Console.d.ts.map +1 -1
- package/types/ops/utils/ExportImportUtils.d.ts +43 -0
- package/types/ops/utils/ExportImportUtils.d.ts.map +1 -1
- package/types/ops/utils/Version.d.ts +16 -2
- package/types/ops/utils/Version.d.ts.map +1 -1
- package/types/shared/State.d.ts.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ops/OAuth2OidcOps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAOpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,SAAS,EACT,sBAAsB,EACtB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAGlB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB;IASrE,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,kBAAkB;IAIpE,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB;IAQ1D,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM;CAUhB","file":"OAuth2OidcOps.d.ts","sourcesContent":["import State from '../shared/State';\nimport {\n accessToken,\n authorize,\n clientCredentialsGrant,\n getTokenInfo,\n} from '../api/OAuth2OIDCApi';\nimport { AxiosRequestConfig } from 'axios';\n\nexport {\n accessToken,\n authorize,\n clientCredentialsGrant,\n getTokenInfo,\n} from '../api/OAuth2OIDCApi';\n\nexport default class OAuth2OidcOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n async authorize(amBaseUrl: string, data: string, config: AxiosRequestConfig) {\n return authorize({\n amBaseUrl,\n data,\n config,\n state: this.state,\n });\n }\n\n async accessToken(amBaseUrl: string, data: any, config: AxiosRequestConfig) {\n return accessToken({ amBaseUrl, config, data, state: this.state });\n }\n\n async getTokenInfo(amBaseUrl: string, config: AxiosRequestConfig) {\n return getTokenInfo({\n amBaseUrl,\n config,\n state: this.state,\n });\n }\n\n async clientCredentialsGrant(\n amBaseUrl: string,\n clientId: string,\n clientSecret: string,\n scope: string\n ) {\n return clientCredentialsGrant({\n amBaseUrl,\n clientId,\n clientSecret,\n scope,\n state: this.state,\n });\n }\n}\n"]}
|
|
@@ -5,13 +5,12 @@ import State from '../shared/State';
|
|
|
5
5
|
export default class ResourceTypeOps {
|
|
6
6
|
state: State;
|
|
7
7
|
constructor(state: State);
|
|
8
|
+
getResourceType(resourceTypeUuid: string): Promise<any>;
|
|
8
9
|
/**
|
|
9
10
|
* Get all resource types
|
|
10
11
|
* @returns {Promise} a promise that resolves to an array of resource type objects
|
|
11
12
|
*/
|
|
12
|
-
getResourceTypes(
|
|
13
|
-
state: State;
|
|
14
|
-
}): Promise<ResourceTypeSkeleton[]>;
|
|
13
|
+
getResourceTypes(): Promise<ResourceTypeSkeleton[]>;
|
|
15
14
|
/**
|
|
16
15
|
* Get resource type by name
|
|
17
16
|
* @param {string} resourceTypeName resource type name
|
|
@@ -24,6 +23,7 @@ export default class ResourceTypeOps {
|
|
|
24
23
|
* @returns {Promise<ResourceTypeSkeleton>} a promise that resolves to a resource type object
|
|
25
24
|
*/
|
|
26
25
|
updateResourceType(resourceTypeUuid: string, resourceTypeData: ResourceTypeSkeleton): Promise<ResourceTypeSkeleton>;
|
|
26
|
+
deleteResourceType(resourceTypeUuid: string): Promise<any>;
|
|
27
27
|
/**
|
|
28
28
|
* Delete resource type by name
|
|
29
29
|
* @param {string} resourceTypeName resource type name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/ResourceTypeOps.ts"],"names":[],"mappings":"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","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 /**\n * Get all resource types\n * @returns {Promise} a promise that resolves to an array of resource type objects\n */\n async 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 */\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 /**\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":"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","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"]}
|
|
@@ -5,6 +5,7 @@ import { ServiceExportInterface } from './OpsTypes';
|
|
|
5
5
|
export default class ServiceOps {
|
|
6
6
|
state: State;
|
|
7
7
|
constructor(state: State);
|
|
8
|
+
createServiceExportTemplate(): ServiceExportInterface;
|
|
8
9
|
/**
|
|
9
10
|
* Get list of services
|
|
10
11
|
* @param {boolean} globalConfig true if the list of global services is requested, false otherwise. Default: false.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/ServiceOps.ts"],"names":[],"mappings":"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","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 /**\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":"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","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"]}
|
package/types/ops/ThemeOps.d.ts
CHANGED
|
@@ -16,14 +16,14 @@ export default class ThemeOps {
|
|
|
16
16
|
* @param {string} realm realm name
|
|
17
17
|
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
18
18
|
*/
|
|
19
|
-
getTheme(themeId: string, realm
|
|
19
|
+
getTheme(themeId: string, realm?: string): Promise<ThemeSkeleton>;
|
|
20
20
|
/**
|
|
21
21
|
* Get theme by name
|
|
22
22
|
* @param {string} themeName theme name
|
|
23
23
|
* @param {string} realm realm name
|
|
24
24
|
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
25
25
|
*/
|
|
26
|
-
getThemeByName(themeName: string, realm
|
|
26
|
+
getThemeByName(themeName: string, realm?: string): Promise<ThemeSkeleton>;
|
|
27
27
|
/**
|
|
28
28
|
* Put theme by id
|
|
29
29
|
* @param {string} themeId theme id
|
|
@@ -31,7 +31,7 @@ export default class ThemeOps {
|
|
|
31
31
|
* @param {string} realm realm name
|
|
32
32
|
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
33
33
|
*/
|
|
34
|
-
putTheme(themeId: string, themeData: ThemeSkeleton, realm
|
|
34
|
+
putTheme(themeId: string, themeData: ThemeSkeleton, realm?: string): Promise<ThemeSkeleton>;
|
|
35
35
|
/**
|
|
36
36
|
* Put theme by name
|
|
37
37
|
* @param {String} themeName theme name
|
|
@@ -39,7 +39,7 @@ export default class ThemeOps {
|
|
|
39
39
|
* @param {string} realm realm name
|
|
40
40
|
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
41
41
|
*/
|
|
42
|
-
putThemeByName(themeName: string, themeData: ThemeSkeleton, realm
|
|
42
|
+
putThemeByName(themeName: string, themeData: ThemeSkeleton, realm?: string): Promise<ThemeSkeleton>;
|
|
43
43
|
/**
|
|
44
44
|
* Put all themes
|
|
45
45
|
* @param {Map<string, ThemeSkeleton>} allThemesData themes object containing all themes for all realms
|
|
@@ -53,20 +53,20 @@ export default class ThemeOps {
|
|
|
53
53
|
* @param {string} realm realm name
|
|
54
54
|
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object
|
|
55
55
|
*/
|
|
56
|
-
deleteTheme(themeId: string, realm
|
|
56
|
+
deleteTheme(themeId: string, realm?: string): Promise<ThemeSkeleton>;
|
|
57
57
|
/**
|
|
58
58
|
* Delete theme by name
|
|
59
59
|
* @param {string} themeName theme name
|
|
60
60
|
* @param {string} realm realm name
|
|
61
61
|
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object
|
|
62
62
|
*/
|
|
63
|
-
deleteThemeByName(themeName: string, realm
|
|
63
|
+
deleteThemeByName(themeName: string, realm?: string): Promise<ThemeSkeleton>;
|
|
64
64
|
/**
|
|
65
65
|
* Delete all themes
|
|
66
66
|
* @param {string} realm realm name
|
|
67
67
|
* @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes
|
|
68
68
|
*/
|
|
69
|
-
deleteThemes(realm
|
|
69
|
+
deleteThemes(realm?: string): Promise<ThemeSkeleton[]>;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Get all themes
|
|
@@ -85,7 +85,7 @@ export declare function getThemes({ realm, state, }: {
|
|
|
85
85
|
*/
|
|
86
86
|
export declare function getTheme({ themeId, realm, state, }: {
|
|
87
87
|
themeId: string;
|
|
88
|
-
realm
|
|
88
|
+
realm?: string;
|
|
89
89
|
state: State;
|
|
90
90
|
}): Promise<ThemeSkeleton>;
|
|
91
91
|
/**
|
|
@@ -96,7 +96,7 @@ export declare function getTheme({ themeId, realm, state, }: {
|
|
|
96
96
|
*/
|
|
97
97
|
export declare function getThemeByName({ themeName, realm, state, }: {
|
|
98
98
|
themeName: string;
|
|
99
|
-
realm
|
|
99
|
+
realm?: string;
|
|
100
100
|
state: State;
|
|
101
101
|
}): Promise<ThemeSkeleton>;
|
|
102
102
|
/**
|
|
@@ -109,7 +109,7 @@ export declare function getThemeByName({ themeName, realm, state, }: {
|
|
|
109
109
|
export declare function putTheme({ themeId, themeData, realm, state, }: {
|
|
110
110
|
themeId: string;
|
|
111
111
|
themeData: ThemeSkeleton;
|
|
112
|
-
realm
|
|
112
|
+
realm?: string;
|
|
113
113
|
state: State;
|
|
114
114
|
}): Promise<ThemeSkeleton>;
|
|
115
115
|
/**
|
|
@@ -122,7 +122,7 @@ export declare function putTheme({ themeId, themeData, realm, state, }: {
|
|
|
122
122
|
export declare function putThemeByName({ themeName, themeData, realm, state, }: {
|
|
123
123
|
themeName: string;
|
|
124
124
|
themeData: ThemeSkeleton;
|
|
125
|
-
realm
|
|
125
|
+
realm?: string;
|
|
126
126
|
state: State;
|
|
127
127
|
}): Promise<ThemeSkeleton>;
|
|
128
128
|
/**
|
|
@@ -144,7 +144,7 @@ export declare function putThemes({ themeMap, realm, state, }: {
|
|
|
144
144
|
*/
|
|
145
145
|
export declare function deleteTheme({ themeId, realm, state, }: {
|
|
146
146
|
themeId: string;
|
|
147
|
-
realm
|
|
147
|
+
realm?: string;
|
|
148
148
|
state: State;
|
|
149
149
|
}): Promise<ThemeSkeleton>;
|
|
150
150
|
/**
|
|
@@ -155,7 +155,7 @@ export declare function deleteTheme({ themeId, realm, state, }: {
|
|
|
155
155
|
*/
|
|
156
156
|
export declare function deleteThemeByName({ themeName, realm, state, }: {
|
|
157
157
|
themeName: string;
|
|
158
|
-
realm
|
|
158
|
+
realm?: string;
|
|
159
159
|
state: State;
|
|
160
160
|
}): Promise<ThemeSkeleton>;
|
|
161
161
|
/**
|
|
@@ -164,6 +164,6 @@ export declare function deleteThemeByName({ themeName, realm, state, }: {
|
|
|
164
164
|
* @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes
|
|
165
165
|
*/
|
|
166
166
|
export declare function deleteThemes({ realm, state, }: {
|
|
167
|
-
realm
|
|
167
|
+
realm?: string;
|
|
168
168
|
state: State;
|
|
169
169
|
}): Promise<ThemeSkeleton[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/ThemeOps.ts"],"names":[],"mappings":"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","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(themeId: string, realm: string): 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\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\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\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(themeId: string, realm: string): 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\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(realm: string): 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":"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","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"]}
|
|
@@ -8,7 +8,7 @@ export default class LogOps {
|
|
|
8
8
|
* Get default noise filter
|
|
9
9
|
* @returns {string[]} array of default event types and loggers to be filtered out
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
getDefaultNoiseFilter(): string[];
|
|
12
12
|
/**
|
|
13
13
|
* Resolve log level to an array of effective log levels
|
|
14
14
|
* @param level string or numeric log level: 'FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE', 'ALL', 0, 1, 2, 3, 4
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/cloud/LogOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,gBAAgB,EAChB,2BAA2B,EAC3B,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,EAGrB,IAAI,EACJ,KAAK,EACN,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE;IAO9C;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM;IAalD;;;OAGG;IACG,aAAa;IAInB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAI3C;;;;OAIG;IACG,wBAAwB,CAC5B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,2BAA2B,CAAC;IAIvC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAI5E;;;;;;;OAOG;IACG,KAAK,CACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;CAG1C;AAkOD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAK7D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,CAWjE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,qBAG9D;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,EAClC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAGvB;AAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC","file":"LogOps.d.ts","sourcesContent":["import {\n LogApiKey,\n LogEventPayloadSkeleton,\n LogEventSkeleton,\n NoIdObjectSkeletonInterface,\n PagedResult,\n} from '../../api/ApiTypes';\nimport {\n createAPIKeyAndSecret,\n getAPIKeys,\n getSources,\n tail,\n fetch,\n} from '../../api/cloud/LogApi';\nimport State from '../../shared/State';\n\nexport default class LogOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get default noise filter\n * @returns {string[]} array of default event types and loggers to be filtered out\n */\n getDfaultNoiseFilter(): string[] {\n return getDefaultNoiseFilter();\n }\n\n /**\n * Resolve log level to an array of effective log levels\n * @param level string or numeric log level: 'FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE', 'ALL', 0, 1, 2, 3, 4\n * @returns {string[]} array of effective log levels\n */\n resolveLevel(level: string | number): string[] {\n if (Number.isNaN(parseInt(level as string, 10))) {\n return logLevelMap[level];\n }\n return logLevelMap[numLogLevelMap[level as number][0]];\n }\n\n /**\n * Resolve a log event's level\n * @param {object} log log event\n * @returns {string} log level\n */\n resolvePayloadLevel(log: LogEventSkeleton): string {\n // It seems that the undesirable 'text/plain' logs start with a date, not a LEVEL\n // Therefore, for those, this function returns null, and thus filters out the undesirable\n try {\n return log.type !== 'text/plain'\n ? (log.payload as LogEventPayloadSkeleton).level\n : (log.payload as string).match(/^([^:]*):/)[1];\n } catch (e) {\n // Fail-safe for no group match\n return null;\n }\n }\n\n /**\n * Get available log sources\n * @returns {Promise<string[]>} promise resolving to an array of available log sources\n */\n async getLogSources() {\n return getLogSources({ state: this.state });\n }\n\n /**\n * Get log api keys\n * @returns {Promise<LogApiKey[]>} promise resolving to an array of LogApiKey objects\n */\n async getLogApiKeys(): Promise<LogApiKey[]> {\n return getLogApiKeys({ state: this.state });\n }\n\n /**\n * Create log api key and secret\n * @param {string} keyName key name\n * @returns {Promise<NoIdObjectSkeletonInterface>} a promise resolving to an object containing the log api key and secret\n */\n async createLogApiKeyAndSecret(\n keyName: string\n ): Promise<NoIdObjectSkeletonInterface> {\n return createAPIKeyAndSecret({ keyName, state: this.state });\n }\n\n /**\n * Tail logs\n * @param {string} source log source(s) to tail\n * @param {string} cookie paged results cookie\n * @returns {Promise<PagedResult<LogEventSkeleton>>} promise resolving to paged log event result\n */\n tail(source: string, cookie: string): Promise<PagedResult<LogEventSkeleton>> {\n return tail({ source, cookie, state: this.state });\n }\n\n /**\n * Fetch logs\n * @param {string} source log source(s) to tail\n * @param {string} startTs start timestamp\n * @param {string} endTs end timestamp\n * @param {string} cookie paged results cookie\n * @returns {Promise<PagedResult<LogEventSkeleton>>} promise resolving to paged log event result\n */\n async fetch(\n source: string,\n startTs: string,\n endTs: string,\n cookie: string\n ): Promise<PagedResult<LogEventSkeleton>> {\n return fetch({ source, startTs, endTs, cookie, state: this.state });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst unfilterableNoise = [\n 'text/plain', // Unfortunately, it is impossible to filter out those without excluding IDM script logging as well\n];\n\nconst miscNoise = [\n 'com.iplanet.dpro.session.operations.ServerSessionOperationStrategy',\n 'com.iplanet.dpro.session.SessionIDFactory',\n 'com.iplanet.dpro.session.share.SessionEncodeURL',\n 'com.iplanet.services.naming.WebtopNaming',\n 'com.iplanet.sso.providers.dpro.SSOProviderImpl',\n 'com.sun.identity.authentication.AuthContext',\n 'com.sun.identity.authentication.client.AuthClientUtils',\n 'com.sun.identity.authentication.config.AMAuthConfigType',\n 'com.sun.identity.authentication.config.AMAuthenticationManager',\n 'com.sun.identity.authentication.config.AMAuthLevelManager',\n 'com.sun.identity.authentication.config.AMConfiguration',\n 'com.sun.identity.authentication.jaas.LoginContext',\n 'com.sun.identity.authentication.modules.application.Application',\n 'com.sun.identity.authentication.server.AuthContextLocal',\n 'com.sun.identity.authentication.service.AMLoginContext',\n 'com.sun.identity.authentication.service.AuthContextLookup',\n 'com.sun.identity.authentication.service.AuthD',\n 'com.sun.identity.authentication.service.AuthUtils',\n 'com.sun.identity.authentication.service.DSAMECallbackHandler',\n 'com.sun.identity.authentication.service.LoginState',\n 'com.sun.identity.authentication.spi.AMLoginModule',\n 'com.sun.identity.delegation.DelegationEvaluatorImpl',\n 'com.sun.identity.idm.plugins.internal.AgentsRepo',\n 'com.sun.identity.idm.server.IdCachedServicesImpl',\n 'com.sun.identity.idm.server.IdRepoPluginsCache',\n 'com.sun.identity.idm.server.IdServicesImpl',\n 'com.sun.identity.log.spi.ISDebug',\n 'com.sun.identity.shared.encode.CookieUtils',\n 'com.sun.identity.sm.ldap.SMSLdapObject',\n 'com.sun.identity.sm.CachedSMSEntry',\n 'com.sun.identity.sm.CachedSubEntries',\n 'com.sun.identity.sm.DNMapper',\n 'com.sun.identity.sm.ServiceConfigImpl',\n 'com.sun.identity.sm.ServiceConfigManagerImpl',\n 'com.sun.identity.sm.SMSEntry',\n 'com.sun.identity.sm.SMSUtils',\n 'com.sun.identity.sm.SmsWrapperObject',\n 'oauth2',\n 'org.apache.http.client.protocol.RequestAuthCache',\n 'org.apache.http.impl.conn.PoolingHttpClientConnectionManager',\n 'org.apache.http.impl.nio.client.InternalHttpAsyncClient',\n 'org.apache.http.impl.nio.client.InternalIODispatch',\n 'org.apache.http.impl.nio.client.MainClientExec',\n 'org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl',\n 'org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager',\n 'org.forgerock.audit.AuditServiceImpl',\n 'org.forgerock.oauth2.core.RealmOAuth2ProviderSettings',\n 'org.forgerock.openam.authentication.service.JAASModuleDetector',\n 'org.forgerock.openam.authentication.service.LoginContextFactory',\n 'org.forgerock.openam.blacklist.BloomFilterBlacklist',\n 'org.forgerock.openam.blacklist.CTSBlacklist',\n 'org.forgerock.openam.core.realms.impl.CachingRealmLookup',\n 'org.forgerock.openam.core.rest.authn.RestAuthCallbackHandlerManager',\n 'org.forgerock.openam.core.rest.authn.trees.AuthTrees',\n 'org.forgerock.openam.cors.CorsFilter',\n 'org.forgerock.openam.cts.CTSPersistentStoreImpl',\n 'org.forgerock.openam.cts.impl.CoreTokenAdapter',\n 'org.forgerock.openam.cts.impl.queue.AsyncResultHandler',\n 'org.forgerock.openam.cts.reaper.ReaperDeleteOnQueryResultHandler',\n 'org.forgerock.openam.headers.DisableSameSiteCookiesFilter',\n 'org.forgerock.openam.idrepo.ldap.DJLDAPv3Repo',\n 'org.forgerock.openam.rest.CsrfFilter',\n 'org.forgerock.openam.rest.restAuthenticationFilter',\n 'org.forgerock.openam.rest.fluent.CrestLoggingFilter',\n 'org.forgerock.openam.session.cts.CtsOperations',\n 'org.forgerock.openam.session.stateless.StatelessSessionManager',\n 'org.forgerock.openam.sm.datalayer.impl.ldap.ExternalLdapConfig',\n 'org.forgerock.openam.sm.datalayer.impl.ldap.LdapQueryBuilder',\n 'org.forgerock.openam.sm.datalayer.impl.SeriesTaskExecutor',\n 'org.forgerock.openam.sm.datalayer.impl.SeriesTaskExecutorThread',\n 'org.forgerock.openam.sm.datalayer.providers.LdapConnectionFactoryProvider',\n 'org.forgerock.openam.sm.file.ConfigFileSystemHandler',\n 'org.forgerock.openam.social.idp.SocialIdentityProviders',\n 'org.forgerock.openam.utils.ClientUtils',\n 'org.forgerock.opendj.ldap.CachedConnectionPool',\n 'org.forgerock.opendj.ldap.LoadBalancer',\n 'org.forgerock.secrets.keystore.KeyStoreSecretStore',\n 'org.forgerock.secrets.propertyresolver.PropertyResolverSecretStore',\n 'org.forgerock.secrets.SecretsProvider',\n];\n\nconst journeysNoise = [\n 'org.forgerock.openam.auth.trees.engine.AuthTreeExecutor',\n];\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst journeys = [\n 'org.forgerock.openam.auth.nodes.SelectIdPNode',\n 'org.forgerock.openam.auth.nodes.ValidatedPasswordNode',\n 'org.forgerock.openam.auth.nodes.ValidatedUsernameNode',\n 'org.forgerock.openam.auth.trees.engine.AuthTreeExecutor',\n];\n\nconst samlNoise = [\n 'com.sun.identity.cot.COTCache',\n 'com.sun.identity.plugin.configuration.impl.ConfigurationInstanceImpl',\n 'com.sun.identity.saml2.meta.SAML2MetaCache',\n 'com.sun.identity.saml2.profile.CacheCleanUpRunnable',\n 'org.apache.xml.security.keys.KeyInfo',\n 'org.apache.xml.security.signature.XMLSignature',\n 'org.apache.xml.security.utils.SignerOutputStream',\n 'org.apache.xml.security.utils.resolver.ResourceResolver',\n 'org.apache.xml.security.utils.resolver.implementations.ResolverFragment',\n 'org.apache.xml.security.algorithms.JCEMapper',\n 'org.apache.xml.security.algorithms.implementations.SignatureBaseRSA',\n 'org.apache.xml.security.algorithms.SignatureAlgorithm',\n 'org.apache.xml.security.utils.ElementProxy',\n 'org.apache.xml.security.transforms.Transforms',\n 'org.apache.xml.security.utils.DigesterOutputStream',\n 'org.apache.xml.security.signature.Reference',\n 'org.apache.xml.security.signature.Manifest',\n];\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst saml = [\n 'jsp.saml2.spAssertionConsumer',\n 'com.sun.identity.saml.common.SAMLUtils',\n 'com.sun.identity.saml2.common.SAML2Utils',\n 'com.sun.identity.saml2.meta.SAML2MetaManager',\n 'com.sun.identity.saml2.xmlsig.FMSigProvider',\n];\n\nconst noise = miscNoise.concat(samlNoise).concat(journeysNoise);\n\nconst numLogLevelMap = {\n 0: ['SEVERE', 'ERROR', 'FATAL'],\n 1: ['WARNING', 'WARN', 'CONFIG'],\n 2: ['INFO', 'INFORMATION'],\n 3: ['DEBUG', 'FINE', 'FINER', 'FINEST'],\n 4: ['ALL'],\n};\n\nconst logLevelMap = {\n SEVERE: ['SEVERE', 'ERROR', 'FATAL'],\n ERROR: ['SEVERE', 'ERROR', 'FATAL'],\n FATAL: ['SEVERE', 'ERROR', 'FATAL'],\n WARN: ['SEVERE', 'ERROR', 'FATAL', 'WARNING', 'WARN', 'CONFIG'],\n WARNING: ['SEVERE', 'ERROR', 'FATAL', 'WARNING', 'WARN', 'CONFIG'],\n CONFIG: ['SEVERE', 'ERROR', 'FATAL', 'WARNING', 'WARN', 'CONFIG'],\n INFO: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n ],\n INFORMATION: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n ],\n DEBUG: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n FINE: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n FINER: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n FINEST: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n ALL: ['ALL'],\n};\n\n/**\n * Get default noise filter\n * @returns {string[]} array of default event types and loggers to be filtered out\n */\nexport function getDefaultNoiseFilter(): string[] {\n return noise;\n}\n\n/**\n * Resolve log level to an array of effective log levels\n * @param level string or numeric log level: 'FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE', 'ALL', 0, 1, 2, 3, 4\n * @returns {string[]} array of effective log levels\n */\nexport function resolveLevel(level: string | number): string[] {\n if (Number.isNaN(parseInt(level as string, 10))) {\n return logLevelMap[level];\n }\n return logLevelMap[numLogLevelMap[level as number][0]];\n}\n\n/**\n * Resolve a log event's level\n * @param {object} log log event\n * @returns {string} log level\n */\nexport function resolvePayloadLevel(log: LogEventSkeleton): string {\n // It seems that the undesirable 'text/plain' logs start with a date, not a LEVEL\n // Therefore, for those, this function returns null, and thus filters out the undesirable\n try {\n return log.type !== 'text/plain'\n ? (log.payload as LogEventPayloadSkeleton).level\n : (log.payload as string).match(/^([^:]*):/)[1];\n } catch (e) {\n // Fail-safe for no group match\n return null;\n }\n}\n\n/**\n * Get available log sources\n * @returns {Promise<string[]>} promise resolving to an array of available log sources\n */\nexport async function getLogSources({ state }: { state: State }) {\n const sources = (await getSources({ state })).result;\n return sources;\n}\n\n/**\n * Get log api keys\n * @returns {Promise<LogApiKey[]>} promise resolving to an array of LogApiKey objects\n */\nexport async function getLogApiKeys({\n state,\n}: {\n state: State;\n}): Promise<LogApiKey[]> {\n const keys = (await getAPIKeys({ state })).result;\n return keys;\n}\n\nexport { tail, fetch, createAPIKeyAndSecret };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/cloud/LogOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,gBAAgB,EAChB,2BAA2B,EAC3B,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,EAGrB,IAAI,EACJ,KAAK,EACN,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACH,qBAAqB,IAAI,MAAM,EAAE;IAIjC;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE;IAI9C;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM;IAIlD;;;OAGG;IACG,aAAa;IAInB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAI3C;;;;OAIG;IACG,wBAAwB,CAC5B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,2BAA2B,CAAC;IAIvC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAI5E;;;;;;;OAOG;IACG,KAAK,CACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;CAG1C;AAkOD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAK7D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,CAWjE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,qBAG9D;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,EAClC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAGvB;AAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC","file":"LogOps.d.ts","sourcesContent":["import {\n LogApiKey,\n LogEventPayloadSkeleton,\n LogEventSkeleton,\n NoIdObjectSkeletonInterface,\n PagedResult,\n} from '../../api/ApiTypes';\nimport {\n createAPIKeyAndSecret,\n getAPIKeys,\n getSources,\n tail,\n fetch,\n} from '../../api/cloud/LogApi';\nimport State from '../../shared/State';\n\nexport default class LogOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get default noise filter\n * @returns {string[]} array of default event types and loggers to be filtered out\n */\n getDefaultNoiseFilter(): string[] {\n return getDefaultNoiseFilter();\n }\n\n /**\n * Resolve log level to an array of effective log levels\n * @param level string or numeric log level: 'FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE', 'ALL', 0, 1, 2, 3, 4\n * @returns {string[]} array of effective log levels\n */\n resolveLevel(level: string | number): string[] {\n return resolveLevel(level);\n }\n\n /**\n * Resolve a log event's level\n * @param {object} log log event\n * @returns {string} log level\n */\n resolvePayloadLevel(log: LogEventSkeleton): string {\n return resolvePayloadLevel(log);\n }\n\n /**\n * Get available log sources\n * @returns {Promise<string[]>} promise resolving to an array of available log sources\n */\n async getLogSources() {\n return getLogSources({ state: this.state });\n }\n\n /**\n * Get log api keys\n * @returns {Promise<LogApiKey[]>} promise resolving to an array of LogApiKey objects\n */\n async getLogApiKeys(): Promise<LogApiKey[]> {\n return getLogApiKeys({ state: this.state });\n }\n\n /**\n * Create log api key and secret\n * @param {string} keyName key name\n * @returns {Promise<NoIdObjectSkeletonInterface>} a promise resolving to an object containing the log api key and secret\n */\n async createLogApiKeyAndSecret(\n keyName: string\n ): Promise<NoIdObjectSkeletonInterface> {\n return createAPIKeyAndSecret({ keyName, state: this.state });\n }\n\n /**\n * Tail logs\n * @param {string} source log source(s) to tail\n * @param {string} cookie paged results cookie\n * @returns {Promise<PagedResult<LogEventSkeleton>>} promise resolving to paged log event result\n */\n tail(source: string, cookie: string): Promise<PagedResult<LogEventSkeleton>> {\n return tail({ source, cookie, state: this.state });\n }\n\n /**\n * Fetch logs\n * @param {string} source log source(s) to tail\n * @param {string} startTs start timestamp\n * @param {string} endTs end timestamp\n * @param {string} cookie paged results cookie\n * @returns {Promise<PagedResult<LogEventSkeleton>>} promise resolving to paged log event result\n */\n async fetch(\n source: string,\n startTs: string,\n endTs: string,\n cookie: string\n ): Promise<PagedResult<LogEventSkeleton>> {\n return fetch({ source, startTs, endTs, cookie, state: this.state });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst unfilterableNoise = [\n 'text/plain', // Unfortunately, it is impossible to filter out those without excluding IDM script logging as well\n];\n\nconst miscNoise = [\n 'com.iplanet.dpro.session.operations.ServerSessionOperationStrategy',\n 'com.iplanet.dpro.session.SessionIDFactory',\n 'com.iplanet.dpro.session.share.SessionEncodeURL',\n 'com.iplanet.services.naming.WebtopNaming',\n 'com.iplanet.sso.providers.dpro.SSOProviderImpl',\n 'com.sun.identity.authentication.AuthContext',\n 'com.sun.identity.authentication.client.AuthClientUtils',\n 'com.sun.identity.authentication.config.AMAuthConfigType',\n 'com.sun.identity.authentication.config.AMAuthenticationManager',\n 'com.sun.identity.authentication.config.AMAuthLevelManager',\n 'com.sun.identity.authentication.config.AMConfiguration',\n 'com.sun.identity.authentication.jaas.LoginContext',\n 'com.sun.identity.authentication.modules.application.Application',\n 'com.sun.identity.authentication.server.AuthContextLocal',\n 'com.sun.identity.authentication.service.AMLoginContext',\n 'com.sun.identity.authentication.service.AuthContextLookup',\n 'com.sun.identity.authentication.service.AuthD',\n 'com.sun.identity.authentication.service.AuthUtils',\n 'com.sun.identity.authentication.service.DSAMECallbackHandler',\n 'com.sun.identity.authentication.service.LoginState',\n 'com.sun.identity.authentication.spi.AMLoginModule',\n 'com.sun.identity.delegation.DelegationEvaluatorImpl',\n 'com.sun.identity.idm.plugins.internal.AgentsRepo',\n 'com.sun.identity.idm.server.IdCachedServicesImpl',\n 'com.sun.identity.idm.server.IdRepoPluginsCache',\n 'com.sun.identity.idm.server.IdServicesImpl',\n 'com.sun.identity.log.spi.ISDebug',\n 'com.sun.identity.shared.encode.CookieUtils',\n 'com.sun.identity.sm.ldap.SMSLdapObject',\n 'com.sun.identity.sm.CachedSMSEntry',\n 'com.sun.identity.sm.CachedSubEntries',\n 'com.sun.identity.sm.DNMapper',\n 'com.sun.identity.sm.ServiceConfigImpl',\n 'com.sun.identity.sm.ServiceConfigManagerImpl',\n 'com.sun.identity.sm.SMSEntry',\n 'com.sun.identity.sm.SMSUtils',\n 'com.sun.identity.sm.SmsWrapperObject',\n 'oauth2',\n 'org.apache.http.client.protocol.RequestAuthCache',\n 'org.apache.http.impl.conn.PoolingHttpClientConnectionManager',\n 'org.apache.http.impl.nio.client.InternalHttpAsyncClient',\n 'org.apache.http.impl.nio.client.InternalIODispatch',\n 'org.apache.http.impl.nio.client.MainClientExec',\n 'org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl',\n 'org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager',\n 'org.forgerock.audit.AuditServiceImpl',\n 'org.forgerock.oauth2.core.RealmOAuth2ProviderSettings',\n 'org.forgerock.openam.authentication.service.JAASModuleDetector',\n 'org.forgerock.openam.authentication.service.LoginContextFactory',\n 'org.forgerock.openam.blacklist.BloomFilterBlacklist',\n 'org.forgerock.openam.blacklist.CTSBlacklist',\n 'org.forgerock.openam.core.realms.impl.CachingRealmLookup',\n 'org.forgerock.openam.core.rest.authn.RestAuthCallbackHandlerManager',\n 'org.forgerock.openam.core.rest.authn.trees.AuthTrees',\n 'org.forgerock.openam.cors.CorsFilter',\n 'org.forgerock.openam.cts.CTSPersistentStoreImpl',\n 'org.forgerock.openam.cts.impl.CoreTokenAdapter',\n 'org.forgerock.openam.cts.impl.queue.AsyncResultHandler',\n 'org.forgerock.openam.cts.reaper.ReaperDeleteOnQueryResultHandler',\n 'org.forgerock.openam.headers.DisableSameSiteCookiesFilter',\n 'org.forgerock.openam.idrepo.ldap.DJLDAPv3Repo',\n 'org.forgerock.openam.rest.CsrfFilter',\n 'org.forgerock.openam.rest.restAuthenticationFilter',\n 'org.forgerock.openam.rest.fluent.CrestLoggingFilter',\n 'org.forgerock.openam.session.cts.CtsOperations',\n 'org.forgerock.openam.session.stateless.StatelessSessionManager',\n 'org.forgerock.openam.sm.datalayer.impl.ldap.ExternalLdapConfig',\n 'org.forgerock.openam.sm.datalayer.impl.ldap.LdapQueryBuilder',\n 'org.forgerock.openam.sm.datalayer.impl.SeriesTaskExecutor',\n 'org.forgerock.openam.sm.datalayer.impl.SeriesTaskExecutorThread',\n 'org.forgerock.openam.sm.datalayer.providers.LdapConnectionFactoryProvider',\n 'org.forgerock.openam.sm.file.ConfigFileSystemHandler',\n 'org.forgerock.openam.social.idp.SocialIdentityProviders',\n 'org.forgerock.openam.utils.ClientUtils',\n 'org.forgerock.opendj.ldap.CachedConnectionPool',\n 'org.forgerock.opendj.ldap.LoadBalancer',\n 'org.forgerock.secrets.keystore.KeyStoreSecretStore',\n 'org.forgerock.secrets.propertyresolver.PropertyResolverSecretStore',\n 'org.forgerock.secrets.SecretsProvider',\n];\n\nconst journeysNoise = [\n 'org.forgerock.openam.auth.trees.engine.AuthTreeExecutor',\n];\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst journeys = [\n 'org.forgerock.openam.auth.nodes.SelectIdPNode',\n 'org.forgerock.openam.auth.nodes.ValidatedPasswordNode',\n 'org.forgerock.openam.auth.nodes.ValidatedUsernameNode',\n 'org.forgerock.openam.auth.trees.engine.AuthTreeExecutor',\n];\n\nconst samlNoise = [\n 'com.sun.identity.cot.COTCache',\n 'com.sun.identity.plugin.configuration.impl.ConfigurationInstanceImpl',\n 'com.sun.identity.saml2.meta.SAML2MetaCache',\n 'com.sun.identity.saml2.profile.CacheCleanUpRunnable',\n 'org.apache.xml.security.keys.KeyInfo',\n 'org.apache.xml.security.signature.XMLSignature',\n 'org.apache.xml.security.utils.SignerOutputStream',\n 'org.apache.xml.security.utils.resolver.ResourceResolver',\n 'org.apache.xml.security.utils.resolver.implementations.ResolverFragment',\n 'org.apache.xml.security.algorithms.JCEMapper',\n 'org.apache.xml.security.algorithms.implementations.SignatureBaseRSA',\n 'org.apache.xml.security.algorithms.SignatureAlgorithm',\n 'org.apache.xml.security.utils.ElementProxy',\n 'org.apache.xml.security.transforms.Transforms',\n 'org.apache.xml.security.utils.DigesterOutputStream',\n 'org.apache.xml.security.signature.Reference',\n 'org.apache.xml.security.signature.Manifest',\n];\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst saml = [\n 'jsp.saml2.spAssertionConsumer',\n 'com.sun.identity.saml.common.SAMLUtils',\n 'com.sun.identity.saml2.common.SAML2Utils',\n 'com.sun.identity.saml2.meta.SAML2MetaManager',\n 'com.sun.identity.saml2.xmlsig.FMSigProvider',\n];\n\nconst noise = miscNoise.concat(samlNoise).concat(journeysNoise);\n\nconst numLogLevelMap = {\n 0: ['SEVERE', 'ERROR', 'FATAL'],\n 1: ['WARNING', 'WARN', 'CONFIG'],\n 2: ['INFO', 'INFORMATION'],\n 3: ['DEBUG', 'FINE', 'FINER', 'FINEST'],\n 4: ['ALL'],\n};\n\nconst logLevelMap = {\n SEVERE: ['SEVERE', 'ERROR', 'FATAL'],\n ERROR: ['SEVERE', 'ERROR', 'FATAL'],\n FATAL: ['SEVERE', 'ERROR', 'FATAL'],\n WARN: ['SEVERE', 'ERROR', 'FATAL', 'WARNING', 'WARN', 'CONFIG'],\n WARNING: ['SEVERE', 'ERROR', 'FATAL', 'WARNING', 'WARN', 'CONFIG'],\n CONFIG: ['SEVERE', 'ERROR', 'FATAL', 'WARNING', 'WARN', 'CONFIG'],\n INFO: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n ],\n INFORMATION: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n ],\n DEBUG: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n FINE: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n FINER: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n FINEST: [\n 'SEVERE',\n 'ERROR',\n 'FATAL',\n 'WARNING',\n 'WARN',\n 'CONFIG',\n 'INFO',\n 'INFORMATION',\n 'DEBUG',\n 'FINE',\n 'FINER',\n 'FINEST',\n ],\n ALL: ['ALL'],\n};\n\n/**\n * Get default noise filter\n * @returns {string[]} array of default event types and loggers to be filtered out\n */\nexport function getDefaultNoiseFilter(): string[] {\n return noise;\n}\n\n/**\n * Resolve log level to an array of effective log levels\n * @param level string or numeric log level: 'FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE', 'ALL', 0, 1, 2, 3, 4\n * @returns {string[]} array of effective log levels\n */\nexport function resolveLevel(level: string | number): string[] {\n if (Number.isNaN(parseInt(level as string, 10))) {\n return logLevelMap[level];\n }\n return logLevelMap[numLogLevelMap[level as number][0]];\n}\n\n/**\n * Resolve a log event's level\n * @param {object} log log event\n * @returns {string} log level\n */\nexport function resolvePayloadLevel(log: LogEventSkeleton): string {\n // It seems that the undesirable 'text/plain' logs start with a date, not a LEVEL\n // Therefore, for those, this function returns null, and thus filters out the undesirable\n try {\n return log.type !== 'text/plain'\n ? (log.payload as LogEventPayloadSkeleton).level\n : (log.payload as string).match(/^([^:]*):/)[1];\n } catch (e) {\n // Fail-safe for no group match\n return null;\n }\n}\n\n/**\n * Get available log sources\n * @returns {Promise<string[]>} promise resolving to an array of available log sources\n */\nexport async function getLogSources({ state }: { state: State }) {\n const sources = (await getSources({ state })).result;\n return sources;\n}\n\n/**\n * Get log api keys\n * @returns {Promise<LogApiKey[]>} promise resolving to an array of LogApiKey objects\n */\nexport async function getLogApiKeys({\n state,\n}: {\n state: State;\n}): Promise<LogApiKey[]> {\n const keys = (await getAPIKeys({ state })).result;\n return keys;\n}\n\nexport { tail, fetch, createAPIKeyAndSecret };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/utils/Console.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,IAAI,SAAS,EACb,OAAO,UAAO,QAMf;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,QAKtD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,QAKpD;AAeD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,QAK/C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,KAAA,EACL,OAAO,GAAE,MAAa,EACtB,IAAI,SAAgB,QAMrB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,MAAa,QAK7D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,MAAa,EAAE,MAAM,SAAS,QAK5E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,KAAA,eAqB/B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,gBAqBlC;AA+ED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,KAAA,EAAE,MAAM,KAAK,eA2BpD","file":"Console.d.ts","sourcesContent":["import Table from 'cli-table3';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/ops/utils/Console.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,IAAI,SAAS,EACb,OAAO,UAAO,QAMf;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,QAKtD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,QAKpD;AAeD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,QAK/C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,KAAA,EACL,OAAO,GAAE,MAAa,EACtB,IAAI,SAAgB,QAMrB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,MAAa,QAK7D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,MAAa,EAAE,MAAM,SAAS,QAK5E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,KAAA,eAqB/B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,gBAqBlC;AA+ED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,KAAA,EAAE,MAAM,KAAK,eA2BpD","file":"Console.d.ts","sourcesContent":["import Table from 'cli-table3';\nimport { state } from '../../lib/FrodoLib';\n\n/**\n * Handles data / messages output. The caller decides and implements how\n * the data and messages are handled, by implementing the handler function\n * on its side. `handler` is optional, and if not included by the caller,\n * the data and messages will be lost.\n *\n * @param {string | unknown} message The string message to return\n * @param {string} [type=text] \"text\", \"info\", \"warn\", \"error\" or \"data\". All but\n * type=\"data\" will be written to stderr.\n * @param {boolean} [newline=true] Whether to add a newline at the end of message\n * messages returned\n */\nexport function printMessage(\n message: string | object,\n type = 'text',\n newline = true\n) {\n const handler = state.getPrintHandler();\n if (handler) {\n handler(message, type, newline);\n }\n}\n\n/**\n * Handles verbose output. The caller decides and implements how\n * the messages are handled, by implementing the handler function\n * on its side. Implementing and registering a `handler` is optional.\n *\n * @param {string | unknown} message The verbose output message\n */\nexport function verboseMessage(message: string | object) {\n const handler = state.getVerboseHandler();\n if (handler) {\n handler(message);\n }\n}\n\n/**\n * Handles debug output. The caller decides and implements how\n * the messages are handled, by implementing the handler function\n * on its side. Implementing and registering a `handler` is optional.\n *\n * @param {string | object} message The debug output message\n */\nexport function debugMessage(message: string | object) {\n const handler = state.getDebugHandler();\n if (handler) {\n handler(message);\n }\n}\n\n/**\n * Helper function to mask password header in curl command\n * @param curlCommand curl command to mask\n * @param {State} state library state\n * @returns masked curl command\n */\nfunction maskPasswordHeader(curlCommand: string) {\n const header = 'X-OpenAM-Password:';\n const mask = '<suppressed>';\n const regex = new RegExp('\"' + header + '.+?\"', 'g');\n return curlCommand.replace(regex, '\"' + header + mask + '\"');\n}\n\n/**\n * Handles curlirize output. The caller decides and implements how\n * the messages are handled, by implementing the handler function\n * on its side. Implementing and registering a `handler` is optional.\n *\n * @param {string} message The curlirize output message\n */\nexport function curlirizeMessage(message: string) {\n const handler = state.getCurlirizeHandler();\n if (handler) {\n handler(maskPasswordHeader(message));\n }\n}\n\n/**\n * Calls a callback on client to create a progress indicator.\n * The actual implementation of the indicator is left to the client\n * Two types of indicators are supported:\n * - determinate: should be used when the process completion rate\n * can be detected (example: progress bar showing percentage or count)\n * - indeterminate: used when progress isn’t detectable, or if\n * it’s not necessary to indicate how long an activity will take.\n * (example: spinner showing progress, but not quantifying the progress)\n *\n * Example:\n * [========================================] 100% | 49/49 | Analyzing journey - transactional_auth\n *\n * @param {Number} total The total number of entries to track progress for\n * @param {String} message optional progress bar message\n * @param {String} type optional type of progress indicator. default is 'determinate'\n *\n */\nexport function createProgressIndicator(\n total,\n message: string = null,\n type = 'determinate'\n) {\n const handler = state.getCreateProgressHandler();\n if (handler) {\n handler(type, total, message);\n }\n}\n\n/**\n * Updates the progress indicator with new data/updated status.\n * @param {string} message optional message to show with the indicator\n *\n */\nexport function updateProgressIndicator(message: string = null) {\n const handler = state.getUpdateProgressHandler();\n if (handler) {\n handler(message);\n }\n}\n\n/**\n * Stop and hide the progress indicator\n * @param {string} message optional message to show with the indicator\n * @param {string} status one of 'none', 'success', 'warn', 'fail'\n */\nexport function stopProgressIndicator(message: string = null, status = 'none') {\n const handler = state.getStopProgressHandler();\n if (handler) {\n handler(message, status);\n }\n}\n\n/**\n * Create an empty table\n * @param {[String]} head header row as an array of strings\n * @returns {CliTable3} an empty table\n */\nexport function createTable(head) {\n return new Table({\n head,\n chars: {\n top: '',\n 'top-mid': '',\n 'top-left': '',\n 'top-right': '',\n bottom: '',\n 'bottom-mid': '',\n 'bottom-left': '',\n 'bottom-right': '',\n left: '',\n 'left-mid': '',\n mid: '',\n 'mid-mid': '',\n right: '',\n 'right-mid': '',\n },\n style: { 'padding-left': 0, 'padding-right': 0, head: ['brightCyan'] },\n });\n}\n\n/**\n * Create a new key/value table\n * @returns {CliTable3} an empty key/value table\n */\nexport function createKeyValueTable() {\n return new Table({\n chars: {\n top: '',\n 'top-mid': '',\n 'top-left': '',\n 'top-right': '',\n bottom: '',\n 'bottom-mid': '',\n 'bottom-left': '',\n 'bottom-right': '',\n left: '',\n 'left-mid': '',\n mid: '',\n 'mid-mid': '',\n right: '',\n 'right-mid': '',\n },\n style: { 'padding-left': 0, 'padding-right': 0 },\n wordWrap: true,\n });\n}\n\n/**\n * Helper function to determine the total depth of an object\n * @param {Object} object input object\n * @returns {Number} total depth of the input object\n */\nfunction getObjectDepth(object) {\n return Object(object) === object\n ? 1 + Math.max(-1, ...Object.values(object).map(getObjectDepth))\n : 0;\n}\n\n/**\n * Helper function to determine if an object has values\n * @param {Object} object input object\n * @returns {boolean} true of the object or any of its sub-objects contain values, false otherwise\n */\nfunction hasValues(object) {\n let has = false;\n const keys = Object.keys(object);\n for (const key of keys) {\n if (Object(object[key]) !== object[key]) {\n return true;\n }\n has = has || hasValues(object[key]);\n }\n return has;\n}\n\n/**\n * Helper function (recursive) to add rows to an object table\n * @param {Object} object object to render\n * @param {Number} depth total depth of initial object\n * @param {Number} level current level\n * @param {CliTable3} table the object table to add the rows to\n * @returns the updated object table\n */\nfunction addRows(object, depth, level, table, keyMap) {\n const space = ' ';\n const keys = Object.keys(object);\n for (const key of keys) {\n if (Object(object[key]) !== object[key]) {\n if (level === 1) {\n table.push([\n keyMap[key] ? keyMap[key]['brightCyan'] : key['brightCyan'],\n object[key],\n ]);\n } else {\n table.push([\n {\n hAlign: 'right',\n content: keyMap[key] ? keyMap[key]['gray'] : key['gray'],\n },\n object[key],\n ]);\n }\n }\n }\n for (const key of keys) {\n if (Object(object[key]) === object[key]) {\n // only print header if there are any values below\n if (hasValues(object[key])) {\n let indention = new Array(level).fill(space).join('');\n if (level < 3) indention = `\\n${indention}`;\n table.push([\n indention.concat(\n keyMap[key] ? keyMap[key]['brightCyan'] : key['brightCyan']\n ),\n '',\n ]);\n }\n // eslint-disable-next-line no-param-reassign\n table = addRows(object[key], depth, level + 1, table, keyMap);\n }\n }\n return table;\n}\n\n/**\n * Create and populate an object table from any JSON object. Use for describe commands.\n * @param {Object} object JSON object to create\n * @returns {CliTable3} a table that can be printed to the console\n */\nexport function createObjectTable(object, keyMap = {}) {\n // eslint-disable-next-line no-param-reassign\n const depth = getObjectDepth(object);\n // eslint-disable-next-line no-param-reassign\n const level = 0;\n // eslint-disable-next-line no-param-reassign\n const table = new Table({\n chars: {\n top: '',\n 'top-mid': '',\n 'top-left': '',\n 'top-right': '',\n bottom: '',\n 'bottom-mid': '',\n 'bottom-left': '',\n 'bottom-right': '',\n left: '',\n 'left-mid': '',\n mid: '',\n 'mid-mid': '',\n right: '',\n 'right-mid': '',\n },\n style: { 'padding-left': 0, 'padding-right': 0, head: ['brightCyan'] },\n });\n addRows(object, depth, level + 1, table, keyMap);\n return table;\n}\n"]}
|