@rockcarver/frodo-lib 0.16.2-7 → 0.16.2-8
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/ServiceApi.js +2 -6
- package/cjs/api/ServiceApi.js.map +1 -1
- package/cjs/ops/ServiceOps.js +125 -69
- package/cjs/ops/ServiceOps.js.map +1 -1
- package/esm/api/ServiceApi.mjs +2 -4
- package/esm/ops/ServiceOps.mjs +110 -63
- package/package.json +1 -1
- package/types/api/ServiceApi.d.ts.map +1 -1
- package/types/ops/ServiceOps.d.ts +4 -0
- package/types/ops/ServiceOps.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.16.2-8] - 2022-11-16
|
|
11
|
+
|
|
10
12
|
## [0.16.2-7] - 2022-11-16
|
|
11
13
|
|
|
12
14
|
## [0.16.2-6] - 2022-11-11
|
|
@@ -696,7 +698,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
696
698
|
- Fixed problem with adding connection profiles
|
|
697
699
|
- Miscellaneous bug fixes
|
|
698
700
|
|
|
699
|
-
[Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.16.2-
|
|
701
|
+
[Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.16.2-8...HEAD
|
|
702
|
+
|
|
703
|
+
[0.16.2-8]: https://github.com/rockcarver/frodo-lib/compare/v0.16.2-7...v0.16.2-8
|
|
700
704
|
|
|
701
705
|
[0.16.2-7]: https://github.com/rockcarver/frodo-lib/compare/v0.16.2-6...v0.16.2-7
|
|
702
706
|
|
package/cjs/api/ServiceApi.js
CHANGED
|
@@ -131,9 +131,7 @@ function putService(_x3, _x4) {
|
|
|
131
131
|
|
|
132
132
|
function _putService() {
|
|
133
133
|
_putService = _asyncToGenerator(function* (serviceId, serviceData) {
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
var urlString = _util.default.format(serviceURLTemplate, _SessionStorage.default.session.getTenant(), realm, serviceId);
|
|
134
|
+
var urlString = _util.default.format(serviceURLTemplate, _SessionStorage.default.session.getTenant(), (0, _ApiUtils.getCurrentRealmPath)(), serviceId);
|
|
137
135
|
|
|
138
136
|
var {
|
|
139
137
|
data
|
|
@@ -157,9 +155,7 @@ function putServiceNextDescendent(_x5, _x6, _x7, _x8) {
|
|
|
157
155
|
|
|
158
156
|
function _putServiceNextDescendent() {
|
|
159
157
|
_putServiceNextDescendent = _asyncToGenerator(function* (serviceId, serviceType, serviceNextDescendentId, serviceNextDescendentData) {
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
var urlString = _util.default.format(serviceURLNextDescendentTemplate, _SessionStorage.default.session.getTenant(), realm, serviceId, serviceType, serviceNextDescendentId);
|
|
158
|
+
var urlString = _util.default.format(serviceURLNextDescendentTemplate, _SessionStorage.default.session.getTenant(), (0, _ApiUtils.getCurrentRealmPath)(), serviceId, serviceType, serviceNextDescendentId);
|
|
163
159
|
|
|
164
160
|
var {
|
|
165
161
|
data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceApi.js","names":["serviceURLTemplate","serviceURLNextDescendentsTemplate","serviceURLNextDescendentTemplate","serviceListURLTemplate","apiVersion","getApiConfig","configPath","getCurrentRealmPath","path","getListOfServices","urlString","util","format","storage","session","getTenant","data","generateAmApi","get","withCredentials","getService","serviceId","getServiceDescendents","post","result","putService","serviceData","realm","getRealm","put","putServiceNextDescendent","serviceType","serviceNextDescendentId","serviceNextDescendentData","deleteService","delete","deleteServiceNextDescendent"],"sources":["api/ServiceApi.ts"],"sourcesContent":["import util from 'util';\nimport storage from '../storage/SessionStorage';\nimport { AmServiceSkeleton, PagedResult } from './ApiTypes';\nimport { generateAmApi } from './BaseApi';\nimport { getCurrentRealmPath } from './utils/ApiUtils';\n\nconst serviceURLTemplate = '%s/json%s/realm-config/services/%s';\nconst serviceURLNextDescendentsTemplate =\n '%s/json%s/realm-config/services/%s?_action=nextdescendents';\nconst serviceURLNextDescendentTemplate =\n '%s/json%s/realm-config/services/%s/%s/%s';\nconst serviceListURLTemplate =\n '%s/json%s/realm-config/services?_queryFilter=true';\nconst apiVersion = 'protocol=2.0,resource=1.0';\n\nfunction getApiConfig() {\n const configPath = getCurrentRealmPath();\n return {\n path: `${configPath}/realm-config/services`,\n apiVersion,\n };\n}\n\nexport interface ServiceListItem {\n /**\n * The identifier for the service - used to construct the subpath for the service\n */\n _id: string;\n /**\n * The user-facing name of the service\n */\n name: string;\n /**\n * The revision number of the service\n */\n _rev: string;\n}\n\n// export interface AmService {\n// _id: '';\n// _rev: string;\n// _type: {\n// _id: string;\n// name: string;\n// collection: boolean;\n// };\n// [key: string]: any;\n// }\n\nexport interface ServiceNextDescendentResponse {\n result: ServiceNextDescendent;\n}\n\nexport interface ServiceNextDescendent {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any;\n}\n\n/**\n * Get a list of services\n * @returns {Promise<ServiceListItem[]>} a promise resolving to an array of service list items.\n */\nexport async function getListOfServices(): Promise<\n PagedResult<ServiceListItem>\n> {\n const urlString = util.format(\n serviceListURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n const { data } = await generateAmApi(getApiConfig()).get<\n PagedResult<ServiceListItem>\n >(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Get service\n * @param {string} serviceId servide id\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function getService(\n serviceId: string\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).get<AmServiceSkeleton>(\n urlString,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Get a service's decendents (applicable for structured services only, e.g. SocialIdentityProviders)\n * @param {string} serviceId service id\n * @returns {Promise<ServiceNextDescendent[]>} a promise resolving to an array of the service's next decendents\n */\nexport async function getServiceDescendents(\n serviceId: string\n): Promise<ServiceNextDescendent[]> {\n const urlString = util.format(\n serviceURLNextDescendentsTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(\n getApiConfig()\n ).post<ServiceNextDescendentResponse>(urlString, {\n withCredentials: true,\n });\n return data.result as ServiceNextDescendent[];\n}\n\n/**\n * Create or update a service\n * @param {string} serviceId service id\n * @param {AmService} serviceData service configuration\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function putService(\n serviceId: string,\n serviceData: AmServiceSkeleton\n): Promise<AmServiceSkeleton> {\n const realm =\n storage.session.getRealm() === '/' ? '' : storage.session.getRealm();\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n realm,\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n serviceData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Create or update a service next descendent instance\n * @param {string} serviceId service id\n * @param {string} serviceType service type\n * @param {string} serviceNextDescendentId service instance id\n * @param {ServiceNextDescendent} serviceNextDescendentData service next descendent configuration\n * @returns {Promise<ServiceNextDescendent>} a promise resolving to a service next descendent\n */\nexport async function putServiceNextDescendent(\n serviceId: string,\n serviceType: string,\n serviceNextDescendentId: string,\n serviceNextDescendentData: ServiceNextDescendent\n): Promise<ServiceNextDescendent> {\n const realm =\n storage.session.getRealm() === '/' ? '' : storage.session.getRealm();\n const urlString = util.format(\n serviceURLNextDescendentTemplate,\n storage.session.getTenant(),\n realm,\n serviceId,\n serviceType,\n serviceNextDescendentId\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n serviceNextDescendentData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Delete service\n * @param {string} serviceId service id\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function deleteService(\n serviceId: string\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).delete(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Delete service next descendent\n * @param {string} serviceId service id\n * @param {string} serviceType service type\n * @param {string} serviceNextDescendentId service instance id\n * @returns {Promise<ServiceNextDescendent>} a promise resolving to a service next descendent\n */\nexport async function deleteServiceNextDescendent(\n serviceId: string,\n serviceType: string,\n serviceNextDescendentId: string\n): Promise<ServiceNextDescendent> {\n const urlString = util.format(\n serviceURLNextDescendentTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId,\n serviceType,\n serviceNextDescendentId\n );\n const { data } = await generateAmApi(getApiConfig()).delete(urlString, {\n withCredentials: true,\n });\n return data;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;;;;;;;AAEA,IAAMA,kBAAkB,GAAG,oCAA3B;AACA,IAAMC,iCAAiC,GACrC,4DADF;AAEA,IAAMC,gCAAgC,GACpC,0CADF;AAEA,IAAMC,sBAAsB,GAC1B,mDADF;AAEA,IAAMC,UAAU,GAAG,2BAAnB;;AAEA,SAASC,YAAT,GAAwB;EACtB,IAAMC,UAAU,GAAG,IAAAC,6BAAA,GAAnB;EACA,OAAO;IACLC,IAAI,YAAKF,UAAL,2BADC;IAELF;EAFK,CAAP;AAID;;AAqCD;AACA;AACA;AACA;SACsBK,iB;;;AAgBtB;AACA;AACA;AACA;AACA;;;;yCApBO,aAEL;IACA,IAAMC,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBT,sBADgB,EAEhBU,uBAAA,CAAQC,OAAR,CAAgBC,SAAhB,EAFgB,EAGhB,IAAAR,6BAAA,GAHgB,CAAlB;;IAKA,IAAM;MAAES;IAAF,UAAiB,IAAAC,sBAAA,EAAcZ,YAA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A,EAAcZ,YAAY,EAA1B,EAA8B8B,MAA9B,CAAqCzB,SAArC,EAAgD;MACrES,eAAe,EAAE;IADoD,CAAhD,CAAvB;IAGA,OAAOH,IAAP;EACD,C;;;;SASqBoB,2B;;;;;mDAAf,WACLf,SADK,EAELU,WAFK,EAGLC,uBAHK,EAI2B;IAChC,IAAMtB,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBV,gCADgB,EAEhBW,uBAAA,CAAQC,OAAR,CAAgBC,SAAhB,EAFgB,EAGhB,IAAAR,6BAAA,GAHgB,EAIhBc,SAJgB,EAKhBU,WALgB,EAMhBC,uBANgB,CAAlB;;IAQA,IAAM;MAAEhB;IAAF,UAAiB,IAAAC,sBAAA,EAAcZ,YAAY,EAA1B,EAA8B8B,MAA9B,CAAqCzB,SAArC,EAAgD;MACrES,eAAe,EAAE;IADoD,CAAhD,CAAvB;IAGA,OAAOH,IAAP;EACD,C"}
|
|
1
|
+
{"version":3,"file":"ServiceApi.js","names":["serviceURLTemplate","serviceURLNextDescendentsTemplate","serviceURLNextDescendentTemplate","serviceListURLTemplate","apiVersion","getApiConfig","configPath","getCurrentRealmPath","path","getListOfServices","urlString","util","format","storage","session","getTenant","data","generateAmApi","get","withCredentials","getService","serviceId","getServiceDescendents","post","result","putService","serviceData","put","putServiceNextDescendent","serviceType","serviceNextDescendentId","serviceNextDescendentData","deleteService","delete","deleteServiceNextDescendent"],"sources":["api/ServiceApi.ts"],"sourcesContent":["import util from 'util';\nimport storage from '../storage/SessionStorage';\nimport { AmServiceSkeleton, PagedResult } from './ApiTypes';\nimport { generateAmApi } from './BaseApi';\nimport { getCurrentRealmPath } from './utils/ApiUtils';\n\nconst serviceURLTemplate = '%s/json%s/realm-config/services/%s';\nconst serviceURLNextDescendentsTemplate =\n '%s/json%s/realm-config/services/%s?_action=nextdescendents';\nconst serviceURLNextDescendentTemplate =\n '%s/json%s/realm-config/services/%s/%s/%s';\nconst serviceListURLTemplate =\n '%s/json%s/realm-config/services?_queryFilter=true';\nconst apiVersion = 'protocol=2.0,resource=1.0';\n\nfunction getApiConfig() {\n const configPath = getCurrentRealmPath();\n return {\n path: `${configPath}/realm-config/services`,\n apiVersion,\n };\n}\n\nexport interface ServiceListItem {\n /**\n * The identifier for the service - used to construct the subpath for the service\n */\n _id: string;\n /**\n * The user-facing name of the service\n */\n name: string;\n /**\n * The revision number of the service\n */\n _rev: string;\n}\n\n// export interface AmService {\n// _id: '';\n// _rev: string;\n// _type: {\n// _id: string;\n// name: string;\n// collection: boolean;\n// };\n// [key: string]: any;\n// }\n\nexport interface ServiceNextDescendentResponse {\n result: ServiceNextDescendent;\n}\n\nexport interface ServiceNextDescendent {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any;\n}\n\n/**\n * Get a list of services\n * @returns {Promise<ServiceListItem[]>} a promise resolving to an array of service list items.\n */\nexport async function getListOfServices(): Promise<\n PagedResult<ServiceListItem>\n> {\n const urlString = util.format(\n serviceListURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n const { data } = await generateAmApi(getApiConfig()).get<\n PagedResult<ServiceListItem>\n >(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Get service\n * @param {string} serviceId servide id\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function getService(\n serviceId: string\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).get<AmServiceSkeleton>(\n urlString,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Get a service's decendents (applicable for structured services only, e.g. SocialIdentityProviders)\n * @param {string} serviceId service id\n * @returns {Promise<ServiceNextDescendent[]>} a promise resolving to an array of the service's next decendents\n */\nexport async function getServiceDescendents(\n serviceId: string\n): Promise<ServiceNextDescendent[]> {\n const urlString = util.format(\n serviceURLNextDescendentsTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(\n getApiConfig()\n ).post<ServiceNextDescendentResponse>(urlString, {\n withCredentials: true,\n });\n return data.result as ServiceNextDescendent[];\n}\n\n/**\n * Create or update a service\n * @param {string} serviceId service id\n * @param {AmService} serviceData service configuration\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function putService(\n serviceId: string,\n serviceData: AmServiceSkeleton\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n serviceData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Create or update a service next descendent instance\n * @param {string} serviceId service id\n * @param {string} serviceType service type\n * @param {string} serviceNextDescendentId service instance id\n * @param {ServiceNextDescendent} serviceNextDescendentData service next descendent configuration\n * @returns {Promise<ServiceNextDescendent>} a promise resolving to a service next descendent\n */\nexport async function putServiceNextDescendent(\n serviceId: string,\n serviceType: string,\n serviceNextDescendentId: string,\n serviceNextDescendentData: ServiceNextDescendent\n): Promise<ServiceNextDescendent> {\n const urlString = util.format(\n serviceURLNextDescendentTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId,\n serviceType,\n serviceNextDescendentId\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n serviceNextDescendentData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Delete service\n * @param {string} serviceId service id\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function deleteService(\n serviceId: string\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).delete(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Delete service next descendent\n * @param {string} serviceId service id\n * @param {string} serviceType service type\n * @param {string} serviceNextDescendentId service instance id\n * @returns {Promise<ServiceNextDescendent>} a promise resolving to a service next descendent\n */\nexport async function deleteServiceNextDescendent(\n serviceId: string,\n serviceType: string,\n serviceNextDescendentId: string\n): Promise<ServiceNextDescendent> {\n const urlString = util.format(\n serviceURLNextDescendentTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId,\n serviceType,\n serviceNextDescendentId\n );\n const { data } = await generateAmApi(getApiConfig()).delete(urlString, {\n withCredentials: true,\n });\n return data;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;;;;;;;AAEA,IAAMA,kBAAkB,GAAG,oCAA3B;AACA,IAAMC,iCAAiC,GACrC,4DADF;AAEA,IAAMC,gCAAgC,GACpC,0CADF;AAEA,IAAMC,sBAAsB,GAC1B,mDADF;AAEA,IAAMC,UAAU,GAAG,2BAAnB;;AAEA,SAASC,YAAT,GAAwB;EACtB,IAAMC,UAAU,GAAG,IAAAC,6BAAA,GAAnB;EACA,OAAO;IACLC,IAAI,YAAKF,UAAL,2BADC;IAELF;EAFK,CAAP;AAID;;AAqCD;AACA;AACA;AACA;SACsBK,iB;;;AAgBtB;AACA;AACA;AACA;AACA;;;;yCApBO,aAEL;IACA,IAAMC,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBT,sBADgB,EAEhBU,uBAAA,CAAQC,OAAR,CAAgBC,SAAhB,EAFgB,EAGhB,IAAAR,6BAAA,GAHgB,CAAlB;;IAKA,IAAM;MAAES;IAAF,UAAiB,IAAAC,sBAAA,EAAcZ,YAAY,EAA1B,EAA8Ba,GAA9B,CAErBR,SAFqB,EAEV;MACXS,eAAe,EAAE;IADN,CAFU,CAAvB;IAKA,OAAOH,IAAP;EACD,C;;;;SAOqBI,U;;;AAkBtB;AACA;AACA;AACA;AACA;;;;kCAtBO,WACLC,SADK,EAEuB;IAC5B,IAAMX,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBZ,kBADgB,EAEhBa,uBAAA,CAAQC,OAAR,CAAgBC,SAAh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IAGA,OAAOH,IAAP;EACD,C"}
|
package/cjs/ops/ServiceOps.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createServiceExportTemplate = createServiceExportTemplate;
|
|
7
7
|
exports.deleteFullService = deleteFullService;
|
|
8
|
+
exports.deleteFullServices = deleteFullServices;
|
|
8
9
|
exports.exportService = exportService;
|
|
9
10
|
exports.exportServices = exportServices;
|
|
10
11
|
exports.getFullServices = getFullServices;
|
|
@@ -65,8 +66,8 @@ function getFullServices() {
|
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Saves a service using the provide id and data, including descendents
|
|
68
|
-
* @param {string}
|
|
69
|
-
* @param {string}
|
|
69
|
+
* @param {string} serviceId the service id / name
|
|
70
|
+
* @param {string} fullServiceData service object including descendants
|
|
70
71
|
* @returns promise resolving to a service object
|
|
71
72
|
*/
|
|
72
73
|
|
|
@@ -83,14 +84,18 @@ function _getFullServices() {
|
|
|
83
84
|
nextDescendents
|
|
84
85
|
});
|
|
85
86
|
} catch (error) {
|
|
86
|
-
var _error$response, _error$
|
|
87
|
+
var _error$response, _error$response2, _error$response2$data;
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
if (!(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 403 && ((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$data = _error$response2.data) === null || _error$response2$data === void 0 ? void 0 : _error$response2$data.message) === 'This operation is not available in ForgeRock Identity Cloud.')) {
|
|
90
|
+
var _error$response3, _error$response3$data;
|
|
91
|
+
|
|
92
|
+
var message = (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : (_error$response3$data = _error$response3.data) === null || _error$response3$data === void 0 ? void 0 : _error$response3$data.message;
|
|
93
|
+
(0, _Console.printMessage)("Unable to retrieve data for ".concat(listItem._id, " with error: ").concat(message), 'error');
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
});
|
|
92
97
|
|
|
93
|
-
return function (
|
|
98
|
+
return function (_x13) {
|
|
94
99
|
return _ref.apply(this, arguments);
|
|
95
100
|
};
|
|
96
101
|
}()));
|
|
@@ -100,27 +105,45 @@ function _getFullServices() {
|
|
|
100
105
|
return _getFullServices.apply(this, arguments);
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
function putFullService(_x, _x2) {
|
|
108
|
+
function putFullService(_x, _x2, _x3) {
|
|
104
109
|
return _putFullService.apply(this, arguments);
|
|
105
110
|
}
|
|
106
111
|
/**
|
|
107
112
|
* Saves multiple services using the serviceEntries which contain both id and data with descendants
|
|
108
113
|
* @param {[string, FullService][]} serviceEntries The services to add
|
|
114
|
+
* @param {boolean} clean Indicates whether to remove possible existing services first
|
|
109
115
|
* @returns {Promise<AmService[]>} promise resolving to an array of service objects
|
|
110
116
|
*/
|
|
111
117
|
|
|
112
118
|
|
|
113
119
|
function _putFullService() {
|
|
114
|
-
_putFullService = _asyncToGenerator(function* (
|
|
115
|
-
(0, _Console.debugMessage)("ServiceOps.putFullService: start");
|
|
116
|
-
var nextDescendents =
|
|
117
|
-
delete
|
|
118
|
-
delete
|
|
119
|
-
delete
|
|
120
|
+
_putFullService = _asyncToGenerator(function* (serviceId, fullServiceData, clean) {
|
|
121
|
+
(0, _Console.debugMessage)("ServiceOps.putFullService: start, serviceId=".concat(serviceId));
|
|
122
|
+
var nextDescendents = fullServiceData.nextDescendents;
|
|
123
|
+
delete fullServiceData.nextDescendents;
|
|
124
|
+
delete fullServiceData._rev;
|
|
125
|
+
delete fullServiceData.enabled;
|
|
126
|
+
|
|
127
|
+
if (clean) {
|
|
128
|
+
try {
|
|
129
|
+
(0, _Console.debugMessage)("ServiceOps.putFullService: clean");
|
|
130
|
+
yield deleteFullService(serviceId);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
var _error$response4, _error$response5, _error$response5$data;
|
|
133
|
+
|
|
134
|
+
if (!(((_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.status) === 404 && ((_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : _error$response5$data.message) === 'Not Found')) {
|
|
135
|
+
var _error$response6, _error$response6$data;
|
|
120
136
|
|
|
121
|
-
|
|
137
|
+
var message = (_error$response6 = error.response) === null || _error$response6 === void 0 ? void 0 : (_error$response6$data = _error$response6.data) === null || _error$response6$data === void 0 ? void 0 : _error$response6$data.message;
|
|
138
|
+
(0, _Console.printMessage)("Error deleting service '".concat(serviceId, "' before import: ").concat(message), 'error');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} // create service first
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
var result = yield (0, _ServiceApi.putService)(serviceId, fullServiceData); // return fast if no next descendents supplied
|
|
122
145
|
|
|
123
|
-
if (
|
|
146
|
+
if (nextDescendents.length === 0) {
|
|
124
147
|
(0, _Console.debugMessage)("ServiceOps.putFullService: end (w/o descendents)");
|
|
125
148
|
return result;
|
|
126
149
|
} // now create next descendents
|
|
@@ -130,20 +153,32 @@ function _putFullService() {
|
|
|
130
153
|
var _ref2 = _asyncToGenerator(function* (descendent) {
|
|
131
154
|
var type = descendent._type._id;
|
|
132
155
|
var descendentId = descendent._id;
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
(0, _Console.debugMessage)("ServiceOps.putFullService: descendentId=".concat(descendentId));
|
|
157
|
+
var result = undefined;
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
result = yield (0, _ServiceApi.putServiceNextDescendent)(serviceId, type, descendentId, descendent);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
var _error$response7, _error$response7$data;
|
|
163
|
+
|
|
164
|
+
var _message = (_error$response7 = error.response) === null || _error$response7 === void 0 ? void 0 : (_error$response7$data = _error$response7.data) === null || _error$response7$data === void 0 ? void 0 : _error$response7$data.message;
|
|
165
|
+
|
|
166
|
+
(0, _Console.printMessage)("Put descendent '".concat(descendentId, "' of service '").concat(serviceId, "': ").concat(_message), 'error');
|
|
167
|
+
}
|
|
168
|
+
|
|
135
169
|
return result;
|
|
136
170
|
});
|
|
137
171
|
|
|
138
|
-
return function (
|
|
172
|
+
return function (_x14) {
|
|
139
173
|
return _ref2.apply(this, arguments);
|
|
140
174
|
};
|
|
141
175
|
}()));
|
|
176
|
+
(0, _Console.debugMessage)("ServiceOps.putFullService: end (w/ descendents)");
|
|
142
177
|
});
|
|
143
178
|
return _putFullService.apply(this, arguments);
|
|
144
179
|
}
|
|
145
180
|
|
|
146
|
-
function putFullServices(
|
|
181
|
+
function putFullServices(_x4, _x5) {
|
|
147
182
|
return _putFullServices.apply(this, arguments);
|
|
148
183
|
}
|
|
149
184
|
/**
|
|
@@ -153,21 +188,21 @@ function putFullServices(_x3) {
|
|
|
153
188
|
|
|
154
189
|
|
|
155
190
|
function _putFullServices() {
|
|
156
|
-
_putFullServices = _asyncToGenerator(function* (serviceEntries) {
|
|
191
|
+
_putFullServices = _asyncToGenerator(function* (serviceEntries, clean) {
|
|
157
192
|
(0, _Console.debugMessage)("ServiceOps.putFullServices: start");
|
|
158
193
|
var results = [];
|
|
159
194
|
|
|
160
195
|
for (var [id, data] of serviceEntries) {
|
|
161
196
|
try {
|
|
162
|
-
var result = yield putFullService(id, data);
|
|
197
|
+
var result = yield putFullService(id, data, clean);
|
|
163
198
|
results.push(result);
|
|
164
199
|
(0, _Console.printMessage)("Imported: ".concat(id), 'info');
|
|
165
200
|
} catch (error) {
|
|
166
|
-
var _error$
|
|
201
|
+
var _error$response8, _error$response8$data, _error$response9, _error$response9$data;
|
|
167
202
|
|
|
168
|
-
var message = (_error$
|
|
169
|
-
var detail = (_error$
|
|
170
|
-
(0, _Console.printMessage)("
|
|
203
|
+
var message = (_error$response8 = error.response) === null || _error$response8 === void 0 ? void 0 : (_error$response8$data = _error$response8.data) === null || _error$response8$data === void 0 ? void 0 : _error$response8$data.message;
|
|
204
|
+
var detail = (_error$response9 = error.response) === null || _error$response9 === void 0 ? void 0 : (_error$response9$data = _error$response9.data) === null || _error$response9$data === void 0 ? void 0 : _error$response9$data.detail;
|
|
205
|
+
(0, _Console.printMessage)("Import service '".concat(id, "': ").concat(message), 'error');
|
|
171
206
|
|
|
172
207
|
if (detail) {
|
|
173
208
|
(0, _Console.printMessage)("Details: ".concat(JSON.stringify(detail)), 'error');
|
|
@@ -181,7 +216,7 @@ function _putFullServices() {
|
|
|
181
216
|
return _putFullServices.apply(this, arguments);
|
|
182
217
|
}
|
|
183
218
|
|
|
184
|
-
function deleteFullService(
|
|
219
|
+
function deleteFullService(_x6) {
|
|
185
220
|
return _deleteFullService.apply(this, arguments);
|
|
186
221
|
}
|
|
187
222
|
/**
|
|
@@ -210,13 +245,43 @@ function deleteFullServices() {
|
|
|
210
245
|
|
|
211
246
|
function _deleteFullServices() {
|
|
212
247
|
_deleteFullServices = _asyncToGenerator(function* () {
|
|
213
|
-
|
|
214
|
-
|
|
248
|
+
(0, _Console.debugMessage)("ServiceOps.deleteFullServices: start");
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
var serviceList = (yield (0, _ServiceApi.getListOfServices)()).result;
|
|
252
|
+
yield Promise.all(serviceList.map( /*#__PURE__*/function () {
|
|
253
|
+
var _ref3 = _asyncToGenerator(function* (serviceListItem) {
|
|
254
|
+
try {
|
|
255
|
+
yield deleteFullService(serviceListItem._id);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
var _error$response10, _error$response11, _error$response11$dat;
|
|
258
|
+
|
|
259
|
+
if (!(((_error$response10 = error.response) === null || _error$response10 === void 0 ? void 0 : _error$response10.status) === 403 && ((_error$response11 = error.response) === null || _error$response11 === void 0 ? void 0 : (_error$response11$dat = _error$response11.data) === null || _error$response11$dat === void 0 ? void 0 : _error$response11$dat.message) === 'This operation is not available in ForgeRock Identity Cloud.')) {
|
|
260
|
+
var _error$response12, _error$response12$dat;
|
|
261
|
+
|
|
262
|
+
var message = (_error$response12 = error.response) === null || _error$response12 === void 0 ? void 0 : (_error$response12$dat = _error$response12.data) === null || _error$response12$dat === void 0 ? void 0 : _error$response12$dat.message;
|
|
263
|
+
(0, _Console.printMessage)("Delete service '".concat(serviceListItem._id, "': ").concat(message), 'error');
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
return function (_x15) {
|
|
269
|
+
return _ref3.apply(this, arguments);
|
|
270
|
+
};
|
|
271
|
+
}()));
|
|
272
|
+
} catch (error) {
|
|
273
|
+
var _error$response13, _error$response13$dat;
|
|
274
|
+
|
|
275
|
+
var message = (_error$response13 = error.response) === null || _error$response13 === void 0 ? void 0 : (_error$response13$dat = _error$response13.data) === null || _error$response13$dat === void 0 ? void 0 : _error$response13$dat.message;
|
|
276
|
+
(0, _Console.printMessage)("Delete services: ".concat(message), 'error');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
(0, _Console.debugMessage)("ServiceOps.deleteFullServices: end");
|
|
215
280
|
});
|
|
216
281
|
return _deleteFullServices.apply(this, arguments);
|
|
217
282
|
}
|
|
218
283
|
|
|
219
|
-
function exportService(
|
|
284
|
+
function exportService(_x7) {
|
|
220
285
|
return _exportService.apply(this, arguments);
|
|
221
286
|
}
|
|
222
287
|
/**
|
|
@@ -229,9 +294,18 @@ function _exportService() {
|
|
|
229
294
|
_exportService = _asyncToGenerator(function* (serviceId) {
|
|
230
295
|
(0, _Console.debugMessage)("ServiceOps.exportService: start");
|
|
231
296
|
var exportData = createServiceExportTemplate();
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
var service = yield (0, _ServiceApi.getService)(serviceId);
|
|
300
|
+
service.nextDescendents = yield (0, _ServiceApi.getServiceDescendents)(serviceId);
|
|
301
|
+
exportData.service[serviceId] = service;
|
|
302
|
+
} catch (error) {
|
|
303
|
+
var _error$response14, _error$response14$dat;
|
|
304
|
+
|
|
305
|
+
var message = (_error$response14 = error.response) === null || _error$response14 === void 0 ? void 0 : (_error$response14$dat = _error$response14.data) === null || _error$response14$dat === void 0 ? void 0 : _error$response14$dat.message;
|
|
306
|
+
(0, _Console.printMessage)("Export service '".concat(serviceId, "': ").concat(message), 'error');
|
|
307
|
+
}
|
|
308
|
+
|
|
235
309
|
(0, _Console.debugMessage)("ServiceOps.exportService: end");
|
|
236
310
|
return exportData;
|
|
237
311
|
});
|
|
@@ -254,10 +328,18 @@ function _exportServices() {
|
|
|
254
328
|
_exportServices = _asyncToGenerator(function* () {
|
|
255
329
|
(0, _Console.debugMessage)("ServiceOps.exportServices: start");
|
|
256
330
|
var exportData = createServiceExportTemplate();
|
|
257
|
-
var services = yield getFullServices();
|
|
258
331
|
|
|
259
|
-
|
|
260
|
-
|
|
332
|
+
try {
|
|
333
|
+
var services = yield getFullServices();
|
|
334
|
+
|
|
335
|
+
for (var service of services) {
|
|
336
|
+
exportData.service[service._type._id] = service;
|
|
337
|
+
}
|
|
338
|
+
} catch (error) {
|
|
339
|
+
var _error$response15, _error$response15$dat;
|
|
340
|
+
|
|
341
|
+
var message = (_error$response15 = error.response) === null || _error$response15 === void 0 ? void 0 : (_error$response15$dat = _error$response15.data) === null || _error$response15$dat === void 0 ? void 0 : _error$response15$dat.message;
|
|
342
|
+
(0, _Console.printMessage)("Export servics: ".concat(message), 'error');
|
|
261
343
|
}
|
|
262
344
|
|
|
263
345
|
(0, _Console.debugMessage)("ServiceOps.exportServices: end");
|
|
@@ -266,7 +348,7 @@ function _exportServices() {
|
|
|
266
348
|
return _exportServices.apply(this, arguments);
|
|
267
349
|
}
|
|
268
350
|
|
|
269
|
-
function importService(
|
|
351
|
+
function importService(_x8, _x9, _x10) {
|
|
270
352
|
return _importService.apply(this, arguments);
|
|
271
353
|
}
|
|
272
354
|
/**
|
|
@@ -279,35 +361,14 @@ function _importService() {
|
|
|
279
361
|
_importService = _asyncToGenerator(function* (serviceId, importData, clean) {
|
|
280
362
|
(0, _Console.debugMessage)("ServiceOps.importService: start");
|
|
281
363
|
var serviceData = importData.service[serviceId];
|
|
282
|
-
|
|
283
|
-
if (clean) {
|
|
284
|
-
(0, _Console.debugMessage)("ServiceOps.importService: clean");
|
|
285
|
-
yield (0, _ServiceApi.deleteService)(serviceId);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
var result = yield putFullService(serviceId, serviceData);
|
|
290
|
-
(0, _Console.debugMessage)("ServiceOps.importService: end");
|
|
291
|
-
return result;
|
|
292
|
-
} catch (error) {
|
|
293
|
-
var _error$response4, _error$response4$data, _error$response5, _error$response5$data;
|
|
294
|
-
|
|
295
|
-
var message = (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : (_error$response4$data = _error$response4.data) === null || _error$response4$data === void 0 ? void 0 : _error$response4$data.message;
|
|
296
|
-
var detail = (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : _error$response5$data.detail;
|
|
297
|
-
(0, _Console.printMessage)("Unable to import service: ".concat(serviceId, " with error: ").concat(message), 'error');
|
|
298
|
-
|
|
299
|
-
if (detail) {
|
|
300
|
-
(0, _Console.printMessage)("Details: ".concat(JSON.stringify(detail)), 'error');
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
364
|
+
var result = yield putFullService(serviceId, serviceData, clean);
|
|
304
365
|
(0, _Console.debugMessage)("ServiceOps.importService: end");
|
|
305
|
-
return
|
|
366
|
+
return result;
|
|
306
367
|
});
|
|
307
368
|
return _importService.apply(this, arguments);
|
|
308
369
|
}
|
|
309
370
|
|
|
310
|
-
function importServices(
|
|
371
|
+
function importServices(_x11, _x12) {
|
|
311
372
|
return _importServices.apply(this, arguments);
|
|
312
373
|
}
|
|
313
374
|
|
|
@@ -315,20 +376,15 @@ function _importServices() {
|
|
|
315
376
|
_importServices = _asyncToGenerator(function* (importData, clean) {
|
|
316
377
|
(0, _Console.debugMessage)("ServiceOps.importServices: start");
|
|
317
378
|
|
|
318
|
-
if (clean) {
|
|
319
|
-
(0, _Console.debugMessage)("ServiceOps.importServices: clean");
|
|
320
|
-
yield deleteFullServices();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
379
|
try {
|
|
324
|
-
var result = yield putFullServices(Object.entries(importData.service));
|
|
380
|
+
var result = yield putFullServices(Object.entries(importData.service), clean);
|
|
325
381
|
(0, _Console.debugMessage)("ServiceOps.importServices: end");
|
|
326
382
|
return result;
|
|
327
383
|
} catch (error) {
|
|
328
|
-
var _error$
|
|
384
|
+
var _error$response16, _error$response16$dat, _error$response17, _error$response17$dat;
|
|
329
385
|
|
|
330
|
-
var message = (_error$
|
|
331
|
-
var detail = (_error$
|
|
386
|
+
var message = (_error$response16 = error.response) === null || _error$response16 === void 0 ? void 0 : (_error$response16$dat = _error$response16.data) === null || _error$response16$dat === void 0 ? void 0 : _error$response16$dat.message;
|
|
387
|
+
var detail = (_error$response17 = error.response) === null || _error$response17 === void 0 ? void 0 : (_error$response17$dat = _error$response17.data) === null || _error$response17$dat === void 0 ? void 0 : _error$response17$dat.detail;
|
|
332
388
|
(0, _Console.printMessage)("Unable to import services: error: ".concat(message), 'error');
|
|
333
389
|
|
|
334
390
|
if (detail) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceOps.js","names":["createServiceExportTemplate","meta","service","getListOfServices","debugMessage","services","_getListOfServices","result","getFullServices","serviceList","fullServiceData","Promise","all","map","listItem","nextDescendents","getService","_id","getServiceDescendents","error","message","response","data","printMessage","filter","putFullService","id","_rev","enabled","putService","descendent","type","_type","descendentId","putServiceNextDescendent","putFullServices","serviceEntries","results","push","detail","JSON","stringify","deleteFullService","serviceId","serviceNextDescendentData","nextDescendent","deleteServiceNextDescendent","deleteService","deleteFullServices","serviceListItem","exportService","exportData","exportServices","importService","importData","clean","serviceData","importServices","Object","entries"],"sources":["ops/ServiceOps.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 { ServiceExportInterface } from './OpsTypes';\nimport { debugMessage, printMessage } from './utils/Console';\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 */\nexport async function getListOfServices() {\n debugMessage(`ServiceOps.getListOfServices: start`);\n const services = (await _getListOfServices()).result;\n debugMessage(`ServiceOps.getListOfServices: end`);\n return services;\n}\n\n/**\n * Get all services including their descendents.\n * @returns Promise resolving to an array of services with their descendants\n */\nexport async function getFullServices(): Promise<FullService[]> {\n debugMessage(`ServiceOps.getFullServices: start`);\n const serviceList = (await _getListOfServices()).result;\n\n const fullServiceData = await Promise.all(\n serviceList.map(async (listItem) => {\n try {\n const [service, nextDescendents] = await Promise.all([\n getService(listItem._id),\n getServiceDescendents(listItem._id),\n ]);\n\n return {\n ...service,\n nextDescendents,\n };\n } catch (error) {\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 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} id the service id / name\n * @param {string} data service object including descendants\n * @returns promise resolving to a service object\n */\nasync function putFullService(\n id: string,\n data: FullService\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.putFullService: start`);\n const nextDescendents = data.nextDescendents;\n\n delete data.nextDescendents;\n delete data._rev;\n delete data.enabled;\n\n // create service first\n const result = await putService(id, data);\n\n // return fast if no next descendents supplied\n if (!nextDescendents) {\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 const result = await putServiceNextDescendent(\n id,\n type,\n descendentId,\n descendent\n );\n debugMessage(`ServiceOps.putFullService: end (w/ descendents)`);\n return result;\n })\n );\n}\n\n/**\n * Saves multiple services using the serviceEntries which contain both id and data with descendants\n * @param {[string, FullService][]} serviceEntries The services to add\n * @returns {Promise<AmService[]>} promise resolving to an array of service objects\n */\nasync function putFullServices(\n serviceEntries: [string, FullService][]\n): Promise<AmServiceSkeleton[]> {\n debugMessage(`ServiceOps.putFullServices: start`);\n const results: AmServiceSkeleton[] = [];\n for (const [id, data] of serviceEntries) {\n try {\n const result = await putFullService(id, data);\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(\n `Unable to import service: ${id} with error: ${message}`,\n 'error'\n );\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 */\nexport async function deleteFullService(serviceId: string) {\n const serviceNextDescendentData = await getServiceDescendents(serviceId);\n\n await Promise.all(\n serviceNextDescendentData.map((nextDescendent) =>\n deleteServiceNextDescendent(\n serviceId,\n nextDescendent._type._id,\n nextDescendent._id\n )\n )\n );\n\n await deleteService(serviceId);\n}\n\n/**\n * Deletes all services\n */\nasync function deleteFullServices() {\n const serviceList = (await _getListOfServices()).result;\n\n await Promise.all(\n serviceList.map((serviceListItem) => deleteFullService(serviceListItem._id))\n );\n}\n\n/**\n * Export service. The response can be saved to file as is.\n * @param serviceId service id/name\n * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\nexport async function exportService(\n serviceId: string\n): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportService: start`);\n const exportData = createServiceExportTemplate();\n const service = await getService(serviceId);\n service.nextDescendents = await getServiceDescendents(serviceId);\n exportData.service[serviceId] = service;\n debugMessage(`ServiceOps.exportService: end`);\n return exportData;\n}\n\n/**\n * Export all services\n * @param {string} file Options filename for the file, otherwise all{realm}Services.service.json will be the name\n */\nexport async function exportServices(): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportServices: start`);\n const exportData = createServiceExportTemplate();\n const services = await getFullServices();\n for (const service of services) {\n exportData.service[service._id] = service;\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 {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {string} file Reference to the filename with the data for the service\n * @returns Promise resolving when the service has been imported\n */\nexport async function importService(\n serviceId: string,\n importData: ServiceExportInterface,\n clean: boolean\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.importService: start`);\n\n const serviceData = importData.service[serviceId];\n\n if (clean) {\n debugMessage(`ServiceOps.importService: clean`);\n await deleteService(serviceId);\n }\n\n try {\n const result = await putFullService(serviceId, serviceData);\n debugMessage(`ServiceOps.importService: end`);\n return result;\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage(\n `Unable to import service: ${serviceId} with error: ${message}`,\n 'error'\n );\n if (detail) {\n printMessage(`Details: ${JSON.stringify(detail)}`, 'error');\n }\n }\n\n debugMessage(`ServiceOps.importService: end`);\n return null;\n}\n\n/**\n * Imports multiple services from the same file. Optionally clean (remove) existing services first\n * @param {boolean} clean Indicates whether to remove possible existing services first\n */\nexport async function importServices(\n importData: ServiceExportInterface,\n clean: boolean\n) {\n debugMessage(`ServiceOps.importServices: start`);\n\n if (clean) {\n debugMessage(`ServiceOps.importServices: clean`);\n await deleteFullServices();\n }\n\n try {\n const result = await putFullServices(Object.entries(importData.service));\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"],"mappings":";;;;;;;;;;;;;;AACA;;AAWA;;;;;;;;;;;;AAMA;AACA;AACA;AACA;AACO,SAASA,2BAAT,GAA+D;EACpE,OAAO;IACLC,IAAI,EAAE,EADD;IAELC,OAAO,EAAE;EAFJ,CAAP;AAID;AAED;AACA;AACA;;;SACsBC,iB;;;AAOtB;AACA;AACA;AACA;;;;0CAVO,aAAmC;IACxC,IAAAC,qBAAA;IACA,IAAMC,QAAQ,GAAG,OAAO,IAAAC,6BAAA,GAAP,EAA6BC,MAA9C;IACA,IAAAH,qBAAA;IACA,OAAOC,QAAP;EACD,C;;;;SAMqBG,e;;;AA8BtB;AACA;AACA;AACA;AACA;AACA;;;;uCAnCO,aAAyD;IAC9D,IAAAJ,qBAAA;IACA,IAAMK,WAAW,GAAG,OAAO,IAAAH,6BAAA,GAAP,EAA6BC,MAAjD;IAEA,IAAMG,eAAe,SAASC,OAAO,CAACC,GAAR,CAC5BH,WAAW,CAACI,GAAZ;MAAA,6BAAgB,WAAOC,QAAP,EAAoB;QAClC,IAAI;UACF,IAAM,CAACZ,OAAD,EAAUa,eAAV,UAAmCJ,OAAO,CAACC,GAAR,CAAY,CACnD,IAAAI,sBAAA,EAAWF,QAAQ,CAACG,GAApB,CADmD,EAEnD,IAAAC,iCAAA,EAAsBJ,QAAQ,CAACG,GAA/B,CAFmD,CAAZ,CAAzC;UAKA,uCACKf,OADL;YAEEa;UAFF;QAID,CAVD,CAUE,OAAOI,KAAP,EAAc;UAAA;;UACd,IAAMC,OAAO,sBAAGD,KAAK,CAACE,QAAT,4EAAG,gBAAgBC,IAAnB,yDAAG,qBAAsBF,OAAtC;UACA,IA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version":3,"file":"ServiceOps.js","names":["createServiceExportTemplate","meta","service","getListOfServices","debugMessage","services","_getListOfServices","result","getFullServices","serviceList","fullServiceData","Promise","all","map","listItem","nextDescendents","getService","_id","getServiceDescendents","error","response","status","data","message","printMessage","filter","putFullService","serviceId","clean","_rev","enabled","deleteFullService","putService","length","descendent","type","_type","descendentId","undefined","putServiceNextDescendent","putFullServices","serviceEntries","results","id","push","detail","JSON","stringify","serviceNextDescendentData","nextDescendent","deleteServiceNextDescendent","deleteService","deleteFullServices","serviceListItem","exportService","exportData","exportServices","importService","importData","serviceData","importServices","Object","entries"],"sources":["ops/ServiceOps.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 { ServiceExportInterface } from './OpsTypes';\nimport { debugMessage, printMessage } from './utils/Console';\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 */\nexport async function getListOfServices() {\n debugMessage(`ServiceOps.getListOfServices: start`);\n const services = (await _getListOfServices()).result;\n debugMessage(`ServiceOps.getListOfServices: end`);\n return services;\n}\n\n/**\n * Get all services including their descendents.\n * @returns Promise resolving to an array of services with their descendants\n */\nexport async function getFullServices(): Promise<FullService[]> {\n debugMessage(`ServiceOps.getFullServices: start`);\n const serviceList = (await _getListOfServices()).result;\n\n const fullServiceData = await Promise.all(\n serviceList.map(async (listItem) => {\n try {\n const [service, nextDescendents] = await Promise.all([\n getService(listItem._id),\n getServiceDescendents(listItem._id),\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 * @returns promise resolving to a service object\n */\nasync function putFullService(\n serviceId: string,\n fullServiceData: FullService,\n clean: boolean\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.putFullService: start, serviceId=${serviceId}`);\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);\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(serviceId, fullServiceData);\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 type,\n descendentId,\n descendent\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 * @returns {Promise<AmService[]>} promise resolving to an array of service objects\n */\nasync function putFullServices(\n serviceEntries: [string, FullService][],\n clean: boolean\n): Promise<AmServiceSkeleton[]> {\n debugMessage(`ServiceOps.putFullServices: start`);\n const results: AmServiceSkeleton[] = [];\n for (const [id, data] of serviceEntries) {\n try {\n const result = await putFullService(id, data, clean);\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 */\nexport async function deleteFullService(serviceId: string) {\n const serviceNextDescendentData = await getServiceDescendents(serviceId);\n\n await Promise.all(\n serviceNextDescendentData.map((nextDescendent) =>\n deleteServiceNextDescendent(\n serviceId,\n nextDescendent._type._id,\n nextDescendent._id\n )\n )\n );\n\n await deleteService(serviceId);\n}\n\n/**\n * Deletes all services\n */\nexport async function deleteFullServices() {\n debugMessage(`ServiceOps.deleteFullServices: start`);\n try {\n const serviceList = (await _getListOfServices()).result;\n\n await Promise.all(\n serviceList.map(async (serviceListItem) => {\n try {\n await deleteFullService(serviceListItem._id);\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 * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\nexport async function exportService(\n serviceId: string\n): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportService: start`);\n const exportData = createServiceExportTemplate();\n try {\n const service = await getService(serviceId);\n service.nextDescendents = await getServiceDescendents(serviceId);\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 {string} file Options filename for the file, otherwise all{realm}Services.service.json will be the name\n */\nexport async function exportServices(): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportServices: start`);\n const exportData = createServiceExportTemplate();\n try {\n const services = await getFullServices();\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 {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {string} file Reference to the filename with the data for the service\n * @returns Promise resolving when the service has been imported\n */\nexport async function importService(\n serviceId: string,\n importData: ServiceExportInterface,\n clean: boolean\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.importService: start`);\n const serviceData = importData.service[serviceId];\n const result = await putFullService(serviceId, serviceData, clean);\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 {boolean} clean Indicates whether to remove possible existing services first\n */\nexport async function importServices(\n importData: ServiceExportInterface,\n clean: boolean\n) {\n debugMessage(`ServiceOps.importServices: start`);\n try {\n const result = await putFullServices(\n Object.entries(importData.service),\n clean\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"],"mappings":";;;;;;;;;;;;;;;AACA;;AAWA;;;;;;;;;;;;AAMA;AACA;AACA;AACA;AACO,SAASA,2BAAT,GAA+D;EACpE,OAAO;IACLC,IAAI,EAAE,EADD;IAELC,OAAO,EAAE;EAFJ,CAAP;AAID;AAED;AACA;AACA;;;SACsBC,iB;;;AAOtB;AACA;AACA;AACA;;;;0CAVO,aAAmC;IACxC,IAAAC,qBAAA;IACA,IAAMC,QAAQ,GAAG,OAAO,IAAAC,6BAAA,GAAP,EAA6BC,MAA9C;IACA,IAAAH,qBAAA;IACA,OAAOC,QAAP;EACD,C;;;;SAMqBG,e;;;AAsCtB;AACA;AACA;AACA;AACA;AACA;;;;uCA3CO,aAAyD;IAC9D,IAAAJ,qBAAA;IACA,IAAMK,WAAW,GAAG,OAAO,IAAAH,6BAAA,GAAP,EAA6BC,MAAjD;IAEA,IAAMG,eAAe,SAASC,OAAO,CAACC,GAAR,CAC5BH,WAAW,CAACI,GAAZ;MAAA,6BAAgB,WAAOC,QAAP,EAAoB;QAClC,IAAI;UACF,IAAM,CAACZ,OAAD,EAAUa,eAAV,UAAmCJ,OAAO,CAACC,GAAR,CAAY,CACnD,IAAAI,sBAAA,EAAWF,QAAQ,CAACG,GAApB,CADmD,EAEnD,IAAAC,iCAAA,EAAsBJ,QAAQ,CAACG,GAA/B,CAFmD,CAAZ,CAAzC;UAKA,uCACKf,OADL;YAEEa;UAFF;QAID,CAVD,CAUE,OAAOI,KAAP,EAAc;UAAA;;UACd,IACE,EACE,oBAAAA,KAAK,CAACC,QAAN,oEAAgBC,MAAhB,MAA2B,GAA3B,IACA,qBAAAF,KAAK,CAACC,QAAN,+FAAgBE,IAAhB,gFAAsBC,OAAtB,MACE,8DAHJ,CADF,EAME;YAAA;;YACA,IAAMA,OAAO,uBAA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A,IAAMsB,MAAM,wBAAG1B,KAAK,CAACC,QAAT,+EAAG,kBAAgBE,IAAnB,0DAAG,sBAAsBuB,MAArC;MACA,IAAArB,qBAAA,8CAAkDD,OAAlD,GAA6D,OAA7D;;MACA,IAAIsB,MAAJ,EAAY;QACV,IAAArB,qBAAA,qBAAyBsB,IAAI,CAACC,SAAL,CAAeF,MAAf,CAAzB,GAAmD,OAAnD;MACD;;MACD,MAAM1B,KAAN;IACD;EACF,C"}
|
package/esm/api/ServiceApi.mjs
CHANGED
|
@@ -67,8 +67,7 @@ export async function getServiceDescendents(serviceId) {
|
|
|
67
67
|
*/
|
|
68
68
|
|
|
69
69
|
export async function putService(serviceId, serviceData) {
|
|
70
|
-
const
|
|
71
|
-
const urlString = util.format(serviceURLTemplate, storage.session.getTenant(), realm, serviceId);
|
|
70
|
+
const urlString = util.format(serviceURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), serviceId);
|
|
72
71
|
const {
|
|
73
72
|
data
|
|
74
73
|
} = await generateAmApi(getApiConfig()).put(urlString, serviceData, {
|
|
@@ -86,8 +85,7 @@ export async function putService(serviceId, serviceData) {
|
|
|
86
85
|
*/
|
|
87
86
|
|
|
88
87
|
export async function putServiceNextDescendent(serviceId, serviceType, serviceNextDescendentId, serviceNextDescendentData) {
|
|
89
|
-
const
|
|
90
|
-
const urlString = util.format(serviceURLNextDescendentTemplate, storage.session.getTenant(), realm, serviceId, serviceType, serviceNextDescendentId);
|
|
88
|
+
const urlString = util.format(serviceURLNextDescendentTemplate, storage.session.getTenant(), getCurrentRealmPath(), serviceId, serviceType, serviceNextDescendentId);
|
|
91
89
|
const {
|
|
92
90
|
data
|
|
93
91
|
} = await generateAmApi(getApiConfig()).put(urlString, serviceNextDescendentData, {
|
package/esm/ops/ServiceOps.mjs
CHANGED
|
@@ -36,10 +36,14 @@ export async function getFullServices() {
|
|
|
36
36
|
nextDescendents
|
|
37
37
|
};
|
|
38
38
|
} catch (error) {
|
|
39
|
-
var _error$response, _error$
|
|
39
|
+
var _error$response, _error$response2, _error$response2$data;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (!(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 403 && ((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$data = _error$response2.data) === null || _error$response2$data === void 0 ? void 0 : _error$response2$data.message) === 'This operation is not available in ForgeRock Identity Cloud.')) {
|
|
42
|
+
var _error$response3, _error$response3$data;
|
|
43
|
+
|
|
44
|
+
const message = (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : (_error$response3$data = _error$response3.data) === null || _error$response3$data === void 0 ? void 0 : _error$response3$data.message;
|
|
45
|
+
printMessage(`Unable to retrieve data for ${listItem._id} with error: ${message}`, 'error');
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
}));
|
|
45
49
|
debugMessage(`ServiceOps.getFullServices: end`);
|
|
@@ -47,21 +51,38 @@ export async function getFullServices() {
|
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* Saves a service using the provide id and data, including descendents
|
|
50
|
-
* @param {string}
|
|
51
|
-
* @param {string}
|
|
54
|
+
* @param {string} serviceId the service id / name
|
|
55
|
+
* @param {string} fullServiceData service object including descendants
|
|
52
56
|
* @returns promise resolving to a service object
|
|
53
57
|
*/
|
|
54
58
|
|
|
55
|
-
async function putFullService(
|
|
56
|
-
debugMessage(`ServiceOps.putFullService: start`);
|
|
57
|
-
const nextDescendents =
|
|
58
|
-
delete
|
|
59
|
-
delete
|
|
60
|
-
delete
|
|
59
|
+
async function putFullService(serviceId, fullServiceData, clean) {
|
|
60
|
+
debugMessage(`ServiceOps.putFullService: start, serviceId=${serviceId}`);
|
|
61
|
+
const nextDescendents = fullServiceData.nextDescendents;
|
|
62
|
+
delete fullServiceData.nextDescendents;
|
|
63
|
+
delete fullServiceData._rev;
|
|
64
|
+
delete fullServiceData.enabled;
|
|
65
|
+
|
|
66
|
+
if (clean) {
|
|
67
|
+
try {
|
|
68
|
+
debugMessage(`ServiceOps.putFullService: clean`);
|
|
69
|
+
await deleteFullService(serviceId);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
var _error$response4, _error$response5, _error$response5$data;
|
|
72
|
+
|
|
73
|
+
if (!(((_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.status) === 404 && ((_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : _error$response5$data.message) === 'Not Found')) {
|
|
74
|
+
var _error$response6, _error$response6$data;
|
|
61
75
|
|
|
62
|
-
|
|
76
|
+
const message = (_error$response6 = error.response) === null || _error$response6 === void 0 ? void 0 : (_error$response6$data = _error$response6.data) === null || _error$response6$data === void 0 ? void 0 : _error$response6$data.message;
|
|
77
|
+
printMessage(`Error deleting service '${serviceId}' before import: ${message}`, 'error');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} // create service first
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const result = await putService(serviceId, fullServiceData); // return fast if no next descendents supplied
|
|
63
84
|
|
|
64
|
-
if (
|
|
85
|
+
if (nextDescendents.length === 0) {
|
|
65
86
|
debugMessage(`ServiceOps.putFullService: end (w/o descendents)`);
|
|
66
87
|
return result;
|
|
67
88
|
} // now create next descendents
|
|
@@ -70,33 +91,45 @@ async function putFullService(id, data) {
|
|
|
70
91
|
await Promise.all(nextDescendents.map(async descendent => {
|
|
71
92
|
const type = descendent._type._id;
|
|
72
93
|
const descendentId = descendent._id;
|
|
73
|
-
|
|
74
|
-
|
|
94
|
+
debugMessage(`ServiceOps.putFullService: descendentId=${descendentId}`);
|
|
95
|
+
let result = undefined;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
result = await putServiceNextDescendent(serviceId, type, descendentId, descendent);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
var _error$response7, _error$response7$data;
|
|
101
|
+
|
|
102
|
+
const message = (_error$response7 = error.response) === null || _error$response7 === void 0 ? void 0 : (_error$response7$data = _error$response7.data) === null || _error$response7$data === void 0 ? void 0 : _error$response7$data.message;
|
|
103
|
+
printMessage(`Put descendent '${descendentId}' of service '${serviceId}': ${message}`, 'error');
|
|
104
|
+
}
|
|
105
|
+
|
|
75
106
|
return result;
|
|
76
107
|
}));
|
|
108
|
+
debugMessage(`ServiceOps.putFullService: end (w/ descendents)`);
|
|
77
109
|
}
|
|
78
110
|
/**
|
|
79
111
|
* Saves multiple services using the serviceEntries which contain both id and data with descendants
|
|
80
112
|
* @param {[string, FullService][]} serviceEntries The services to add
|
|
113
|
+
* @param {boolean} clean Indicates whether to remove possible existing services first
|
|
81
114
|
* @returns {Promise<AmService[]>} promise resolving to an array of service objects
|
|
82
115
|
*/
|
|
83
116
|
|
|
84
117
|
|
|
85
|
-
async function putFullServices(serviceEntries) {
|
|
118
|
+
async function putFullServices(serviceEntries, clean) {
|
|
86
119
|
debugMessage(`ServiceOps.putFullServices: start`);
|
|
87
120
|
const results = [];
|
|
88
121
|
|
|
89
122
|
for (const [id, data] of serviceEntries) {
|
|
90
123
|
try {
|
|
91
|
-
const result = await putFullService(id, data);
|
|
124
|
+
const result = await putFullService(id, data, clean);
|
|
92
125
|
results.push(result);
|
|
93
126
|
printMessage(`Imported: ${id}`, 'info');
|
|
94
127
|
} catch (error) {
|
|
95
|
-
var _error$
|
|
128
|
+
var _error$response8, _error$response8$data, _error$response9, _error$response9$data;
|
|
96
129
|
|
|
97
|
-
const message = (_error$
|
|
98
|
-
const detail = (_error$
|
|
99
|
-
printMessage(`
|
|
130
|
+
const message = (_error$response8 = error.response) === null || _error$response8 === void 0 ? void 0 : (_error$response8$data = _error$response8.data) === null || _error$response8$data === void 0 ? void 0 : _error$response8$data.message;
|
|
131
|
+
const detail = (_error$response9 = error.response) === null || _error$response9 === void 0 ? void 0 : (_error$response9$data = _error$response9.data) === null || _error$response9$data === void 0 ? void 0 : _error$response9$data.detail;
|
|
132
|
+
printMessage(`Import service '${id}': ${message}`, 'error');
|
|
100
133
|
|
|
101
134
|
if (detail) {
|
|
102
135
|
printMessage(`Details: ${JSON.stringify(detail)}`, 'error');
|
|
@@ -122,9 +155,33 @@ export async function deleteFullService(serviceId) {
|
|
|
122
155
|
* Deletes all services
|
|
123
156
|
*/
|
|
124
157
|
|
|
125
|
-
async function deleteFullServices() {
|
|
126
|
-
|
|
127
|
-
|
|
158
|
+
export async function deleteFullServices() {
|
|
159
|
+
debugMessage(`ServiceOps.deleteFullServices: start`);
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const serviceList = (await _getListOfServices()).result;
|
|
163
|
+
await Promise.all(serviceList.map(async serviceListItem => {
|
|
164
|
+
try {
|
|
165
|
+
await deleteFullService(serviceListItem._id);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
var _error$response10, _error$response11, _error$response11$dat;
|
|
168
|
+
|
|
169
|
+
if (!(((_error$response10 = error.response) === null || _error$response10 === void 0 ? void 0 : _error$response10.status) === 403 && ((_error$response11 = error.response) === null || _error$response11 === void 0 ? void 0 : (_error$response11$dat = _error$response11.data) === null || _error$response11$dat === void 0 ? void 0 : _error$response11$dat.message) === 'This operation is not available in ForgeRock Identity Cloud.')) {
|
|
170
|
+
var _error$response12, _error$response12$dat;
|
|
171
|
+
|
|
172
|
+
const message = (_error$response12 = error.response) === null || _error$response12 === void 0 ? void 0 : (_error$response12$dat = _error$response12.data) === null || _error$response12$dat === void 0 ? void 0 : _error$response12$dat.message;
|
|
173
|
+
printMessage(`Delete service '${serviceListItem._id}': ${message}`, 'error');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
} catch (error) {
|
|
178
|
+
var _error$response13, _error$response13$dat;
|
|
179
|
+
|
|
180
|
+
const message = (_error$response13 = error.response) === null || _error$response13 === void 0 ? void 0 : (_error$response13$dat = _error$response13.data) === null || _error$response13$dat === void 0 ? void 0 : _error$response13$dat.message;
|
|
181
|
+
printMessage(`Delete services: ${message}`, 'error');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
debugMessage(`ServiceOps.deleteFullServices: end`);
|
|
128
185
|
}
|
|
129
186
|
/**
|
|
130
187
|
* Export service. The response can be saved to file as is.
|
|
@@ -132,13 +189,21 @@ async function deleteFullServices() {
|
|
|
132
189
|
* @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.
|
|
133
190
|
*/
|
|
134
191
|
|
|
135
|
-
|
|
136
192
|
export async function exportService(serviceId) {
|
|
137
193
|
debugMessage(`ServiceOps.exportService: start`);
|
|
138
194
|
const exportData = createServiceExportTemplate();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
const service = await getService(serviceId);
|
|
198
|
+
service.nextDescendents = await getServiceDescendents(serviceId);
|
|
199
|
+
exportData.service[serviceId] = service;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
var _error$response14, _error$response14$dat;
|
|
202
|
+
|
|
203
|
+
const message = (_error$response14 = error.response) === null || _error$response14 === void 0 ? void 0 : (_error$response14$dat = _error$response14.data) === null || _error$response14$dat === void 0 ? void 0 : _error$response14$dat.message;
|
|
204
|
+
printMessage(`Export service '${serviceId}': ${message}`, 'error');
|
|
205
|
+
}
|
|
206
|
+
|
|
142
207
|
debugMessage(`ServiceOps.exportService: end`);
|
|
143
208
|
return exportData;
|
|
144
209
|
}
|
|
@@ -150,10 +215,18 @@ export async function exportService(serviceId) {
|
|
|
150
215
|
export async function exportServices() {
|
|
151
216
|
debugMessage(`ServiceOps.exportServices: start`);
|
|
152
217
|
const exportData = createServiceExportTemplate();
|
|
153
|
-
const services = await getFullServices();
|
|
154
218
|
|
|
155
|
-
|
|
156
|
-
|
|
219
|
+
try {
|
|
220
|
+
const services = await getFullServices();
|
|
221
|
+
|
|
222
|
+
for (const service of services) {
|
|
223
|
+
exportData.service[service._type._id] = service;
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
var _error$response15, _error$response15$dat;
|
|
227
|
+
|
|
228
|
+
const message = (_error$response15 = error.response) === null || _error$response15 === void 0 ? void 0 : (_error$response15$dat = _error$response15.data) === null || _error$response15$dat === void 0 ? void 0 : _error$response15$dat.message;
|
|
229
|
+
printMessage(`Export servics: ${message}`, 'error');
|
|
157
230
|
}
|
|
158
231
|
|
|
159
232
|
debugMessage(`ServiceOps.exportServices: end`);
|
|
@@ -170,30 +243,9 @@ export async function exportServices() {
|
|
|
170
243
|
export async function importService(serviceId, importData, clean) {
|
|
171
244
|
debugMessage(`ServiceOps.importService: start`);
|
|
172
245
|
const serviceData = importData.service[serviceId];
|
|
173
|
-
|
|
174
|
-
if (clean) {
|
|
175
|
-
debugMessage(`ServiceOps.importService: clean`);
|
|
176
|
-
await deleteService(serviceId);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
const result = await putFullService(serviceId, serviceData);
|
|
181
|
-
debugMessage(`ServiceOps.importService: end`);
|
|
182
|
-
return result;
|
|
183
|
-
} catch (error) {
|
|
184
|
-
var _error$response4, _error$response4$data, _error$response5, _error$response5$data;
|
|
185
|
-
|
|
186
|
-
const message = (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : (_error$response4$data = _error$response4.data) === null || _error$response4$data === void 0 ? void 0 : _error$response4$data.message;
|
|
187
|
-
const detail = (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : _error$response5$data.detail;
|
|
188
|
-
printMessage(`Unable to import service: ${serviceId} with error: ${message}`, 'error');
|
|
189
|
-
|
|
190
|
-
if (detail) {
|
|
191
|
-
printMessage(`Details: ${JSON.stringify(detail)}`, 'error');
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
246
|
+
const result = await putFullService(serviceId, serviceData, clean);
|
|
195
247
|
debugMessage(`ServiceOps.importService: end`);
|
|
196
|
-
return
|
|
248
|
+
return result;
|
|
197
249
|
}
|
|
198
250
|
/**
|
|
199
251
|
* Imports multiple services from the same file. Optionally clean (remove) existing services first
|
|
@@ -203,20 +255,15 @@ export async function importService(serviceId, importData, clean) {
|
|
|
203
255
|
export async function importServices(importData, clean) {
|
|
204
256
|
debugMessage(`ServiceOps.importServices: start`);
|
|
205
257
|
|
|
206
|
-
if (clean) {
|
|
207
|
-
debugMessage(`ServiceOps.importServices: clean`);
|
|
208
|
-
await deleteFullServices();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
258
|
try {
|
|
212
|
-
const result = await putFullServices(Object.entries(importData.service));
|
|
259
|
+
const result = await putFullServices(Object.entries(importData.service), clean);
|
|
213
260
|
debugMessage(`ServiceOps.importServices: end`);
|
|
214
261
|
return result;
|
|
215
262
|
} catch (error) {
|
|
216
|
-
var _error$
|
|
263
|
+
var _error$response16, _error$response16$dat, _error$response17, _error$response17$dat;
|
|
217
264
|
|
|
218
|
-
const message = (_error$
|
|
219
|
-
const detail = (_error$
|
|
265
|
+
const message = (_error$response16 = error.response) === null || _error$response16 === void 0 ? void 0 : (_error$response16$dat = _error$response16.data) === null || _error$response16$dat === void 0 ? void 0 : _error$response16$dat.message;
|
|
266
|
+
const detail = (_error$response17 = error.response) === null || _error$response17 === void 0 ? void 0 : (_error$response17$dat = _error$response17.data) === null || _error$response17$dat === void 0 ? void 0 : _error$response17$dat.detail;
|
|
220
267
|
printMessage(`Unable to import services: error: ${message}`, 'error');
|
|
221
268
|
|
|
222
269
|
if (detail) {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/ServiceApi.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAqB5D,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,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ACzC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAalC;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,CAe5B;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,uBAAuB,EAAE,MAAM,EAC/B,yBAAyB,EAAE,qBAAqB,GAC/C,OAAO,CAAC,qBAAqB,CAAC,CAiBhC;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,CAAC,CAW5B;AAED;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,uBAAuB,EAAE,MAAM,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAahC","file":"ServiceApi.d.ts","sourcesContent":["import util from 'util';\nimport storage from '../storage/SessionStorage';\nimport { AmServiceSkeleton, PagedResult } from './ApiTypes';\nimport { generateAmApi } from './BaseApi';\nimport { getCurrentRealmPath } from './utils/ApiUtils';\n\nconst serviceURLTemplate = '%s/json%s/realm-config/services/%s';\nconst serviceURLNextDescendentsTemplate =\n '%s/json%s/realm-config/services/%s?_action=nextdescendents';\nconst serviceURLNextDescendentTemplate =\n '%s/json%s/realm-config/services/%s/%s/%s';\nconst serviceListURLTemplate =\n '%s/json%s/realm-config/services?_queryFilter=true';\nconst apiVersion = 'protocol=2.0,resource=1.0';\n\nfunction getApiConfig() {\n const configPath = getCurrentRealmPath();\n return {\n path: `${configPath}/realm-config/services`,\n apiVersion,\n };\n}\n\nexport interface ServiceListItem {\n /**\n * The identifier for the service - used to construct the subpath for the service\n */\n _id: string;\n /**\n * The user-facing name of the service\n */\n name: string;\n /**\n * The revision number of the service\n */\n _rev: string;\n}\n\n// export interface AmService {\n// _id: '';\n// _rev: string;\n// _type: {\n// _id: string;\n// name: string;\n// collection: boolean;\n// };\n// [key: string]: any;\n// }\n\nexport interface ServiceNextDescendentResponse {\n result: ServiceNextDescendent;\n}\n\nexport interface ServiceNextDescendent {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any;\n}\n\n/**\n * Get a list of services\n * @returns {Promise<ServiceListItem[]>} a promise resolving to an array of service list items.\n */\nexport async function getListOfServices(): Promise<\n PagedResult<ServiceListItem>\n> {\n const urlString = util.format(\n serviceListURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n const { data } = await generateAmApi(getApiConfig()).get<\n PagedResult<ServiceListItem>\n >(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Get service\n * @param {string} serviceId servide id\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function getService(\n serviceId: string\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).get<AmServiceSkeleton>(\n urlString,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Get a service's decendents (applicable for structured services only, e.g. SocialIdentityProviders)\n * @param {string} serviceId service id\n * @returns {Promise<ServiceNextDescendent[]>} a promise resolving to an array of the service's next decendents\n */\nexport async function getServiceDescendents(\n serviceId: string\n): Promise<ServiceNextDescendent[]> {\n const urlString = util.format(\n serviceURLNextDescendentsTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(\n getApiConfig()\n ).post<ServiceNextDescendentResponse>(urlString, {\n withCredentials: true,\n });\n return data.result as ServiceNextDescendent[];\n}\n\n/**\n * Create or update a service\n * @param {string} serviceId service id\n * @param {AmService} serviceData service configuration\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function putService(\n serviceId: string,\n serviceData: AmServiceSkeleton\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n serviceData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Create or update a service next descendent instance\n * @param {string} serviceId service id\n * @param {string} serviceType service type\n * @param {string} serviceNextDescendentId service instance id\n * @param {ServiceNextDescendent} serviceNextDescendentData service next descendent configuration\n * @returns {Promise<ServiceNextDescendent>} a promise resolving to a service next descendent\n */\nexport async function putServiceNextDescendent(\n serviceId: string,\n serviceType: string,\n serviceNextDescendentId: string,\n serviceNextDescendentData: ServiceNextDescendent\n): Promise<ServiceNextDescendent> {\n const urlString = util.format(\n serviceURLNextDescendentTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId,\n serviceType,\n serviceNextDescendentId\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n serviceNextDescendentData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Delete service\n * @param {string} serviceId service id\n * @returns {Promise<AmService>} a promise resolving to a service object\n */\nexport async function deleteService(\n serviceId: string\n): Promise<AmServiceSkeleton> {\n const urlString = util.format(\n serviceURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId\n );\n const { data } = await generateAmApi(getApiConfig()).delete(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Delete service next descendent\n * @param {string} serviceId service id\n * @param {string} serviceType service type\n * @param {string} serviceNextDescendentId service instance id\n * @returns {Promise<ServiceNextDescendent>} a promise resolving to a service next descendent\n */\nexport async function deleteServiceNextDescendent(\n serviceId: string,\n serviceType: string,\n serviceNextDescendentId: string\n): Promise<ServiceNextDescendent> {\n const urlString = util.format(\n serviceURLNextDescendentTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n serviceId,\n serviceType,\n serviceNextDescendentId\n );\n const { data } = await generateAmApi(getApiConfig()).delete(urlString, {\n withCredentials: true,\n });\n return data;\n}\n"]}
|
|
@@ -23,6 +23,10 @@ export declare function getFullServices(): Promise<FullService[]>;
|
|
|
23
23
|
* @param {string} serviceId The service to delete
|
|
24
24
|
*/
|
|
25
25
|
export declare function deleteFullService(serviceId: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Deletes all services
|
|
28
|
+
*/
|
|
29
|
+
export declare function deleteFullServices(): Promise<void>;
|
|
26
30
|
/**
|
|
27
31
|
* Export service. The response can be saved to file as is.
|
|
28
32
|
* @param serviceId service id/name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/ServiceOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAQL,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,UAAU,WAAY,SAAQ,iBAAiB;IAC7C,eAAe,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,sBAAsB,CAKpE;AAED;;GAEG;AACH,wBAAsB,iBAAiB,2DAKtC;AAED;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CA4B9D;AA4ED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,iBAcxD;AAaD;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAQjC;AAED;;;GAGG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAStE;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,sBAAsB,EAClC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,iBAAiB,CAAC,CA4B5B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,sBAAsB,EAClC,KAAK,EAAE,OAAO,gCAsBf","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 { ServiceExportInterface } from './OpsTypes';\nimport { debugMessage, printMessage } from './utils/Console';\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 */\nexport async function getListOfServices() {\n debugMessage(`ServiceOps.getListOfServices: start`);\n const services = (await _getListOfServices()).result;\n debugMessage(`ServiceOps.getListOfServices: end`);\n return services;\n}\n\n/**\n * Get all services including their descendents.\n * @returns Promise resolving to an array of services with their descendants\n */\nexport async function getFullServices(): Promise<FullService[]> {\n debugMessage(`ServiceOps.getFullServices: start`);\n const serviceList = (await _getListOfServices()).result;\n\n const fullServiceData = await Promise.all(\n serviceList.map(async (listItem) => {\n try {\n const [service, nextDescendents] = await Promise.all([\n getService(listItem._id),\n getServiceDescendents(listItem._id),\n ]);\n\n return {\n ...service,\n nextDescendents,\n };\n } catch (error) {\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 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} id the service id / name\n * @param {string} data service object including descendants\n * @returns promise resolving to a service object\n */\nasync function putFullService(\n id: string,\n data: FullService\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.putFullService: start`);\n const nextDescendents = data.nextDescendents;\n\n delete data.nextDescendents;\n delete data._rev;\n delete data.enabled;\n\n // create service first\n const result = await putService(id, data);\n\n // return fast if no next descendents supplied\n if (!nextDescendents) {\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 const result = await putServiceNextDescendent(\n id,\n type,\n descendentId,\n descendent\n );\n debugMessage(`ServiceOps.putFullService: end (w/ descendents)`);\n return result;\n })\n );\n}\n\n/**\n * Saves multiple services using the serviceEntries which contain both id and data with descendants\n * @param {[string, FullService][]} serviceEntries The services to add\n * @returns {Promise<AmService[]>} promise resolving to an array of service objects\n */\nasync function putFullServices(\n serviceEntries: [string, FullService][]\n): Promise<AmServiceSkeleton[]> {\n debugMessage(`ServiceOps.putFullServices: start`);\n const results: AmServiceSkeleton[] = [];\n for (const [id, data] of serviceEntries) {\n try {\n const result = await putFullService(id, data);\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(\n `Unable to import service: ${id} with error: ${message}`,\n 'error'\n );\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 */\nexport async function deleteFullService(serviceId: string) {\n const serviceNextDescendentData = await getServiceDescendents(serviceId);\n\n await Promise.all(\n serviceNextDescendentData.map((nextDescendent) =>\n deleteServiceNextDescendent(\n serviceId,\n nextDescendent._type._id,\n nextDescendent._id\n )\n )\n );\n\n await deleteService(serviceId);\n}\n\n/**\n * Deletes all services\n */\nasync function deleteFullServices() {\n const serviceList = (await _getListOfServices()).result;\n\n await Promise.all(\n serviceList.map((serviceListItem) => deleteFullService(serviceListItem._id))\n );\n}\n\n/**\n * Export service. The response can be saved to file as is.\n * @param serviceId service id/name\n * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\nexport async function exportService(\n serviceId: string\n): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportService: start`);\n const exportData = createServiceExportTemplate();\n const service = await getService(serviceId);\n service.nextDescendents = await getServiceDescendents(serviceId);\n exportData.service[serviceId] = service;\n debugMessage(`ServiceOps.exportService: end`);\n return exportData;\n}\n\n/**\n * Export all services\n * @param {string} file Options filename for the file, otherwise all{realm}Services.service.json will be the name\n */\nexport async function exportServices(): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportServices: start`);\n const exportData = createServiceExportTemplate();\n const services = await getFullServices();\n for (const service of services) {\n exportData.service[service._id] = service;\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 {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {string} file Reference to the filename with the data for the service\n * @returns Promise resolving when the service has been imported\n */\nexport async function importService(\n serviceId: string,\n importData: ServiceExportInterface,\n clean: boolean\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.importService: start`);\n\n const serviceData = importData.service[serviceId];\n\n if (clean) {\n debugMessage(`ServiceOps.importService: clean`);\n await deleteService(serviceId);\n }\n\n try {\n const result = await putFullService(serviceId, serviceData);\n debugMessage(`ServiceOps.importService: end`);\n return result;\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage(\n `Unable to import service: ${serviceId} with error: ${message}`,\n 'error'\n );\n if (detail) {\n printMessage(`Details: ${JSON.stringify(detail)}`, 'error');\n }\n }\n\n debugMessage(`ServiceOps.importService: end`);\n return null;\n}\n\n/**\n * Imports multiple services from the same file. Optionally clean (remove) existing services first\n * @param {boolean} clean Indicates whether to remove possible existing services first\n */\nexport async function importServices(\n importData: ServiceExportInterface,\n clean: boolean\n) {\n debugMessage(`ServiceOps.importServices: start`);\n\n if (clean) {\n debugMessage(`ServiceOps.importServices: clean`);\n await deleteFullServices();\n }\n\n try {\n const result = await putFullServices(Object.entries(importData.service));\n debugMessage(`ServiceOps.importServices: end`);\n return result;\n } catch (error) {\n const message = error.response?.data?.message;\n const detail = error.response?.data?.detail;\n printMessage(`Unable to import services: error: ${message}`, 'error');\n if (detail) {\n printMessage(`Details: ${JSON.stringify(detail)}`, 'error');\n }\n throw error;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/ServiceOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAQL,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,UAAU,WAAY,SAAQ,iBAAiB;IAC7C,eAAe,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,sBAAsB,CAKpE;AAED;;GAEG;AACH,wBAAsB,iBAAiB,2DAKtC;AAED;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAoC9D;AA0GD;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,iBAcxD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,kBA+BvC;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAajC;AAED;;;GAGG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,sBAAsB,CAAC,CActE;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,sBAAsB,EAClC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,iBAAiB,CAAC,CAM5B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,sBAAsB,EAClC,KAAK,EAAE,OAAO,gCAmBf","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 { ServiceExportInterface } from './OpsTypes';\nimport { debugMessage, printMessage } from './utils/Console';\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 */\nexport async function getListOfServices() {\n debugMessage(`ServiceOps.getListOfServices: start`);\n const services = (await _getListOfServices()).result;\n debugMessage(`ServiceOps.getListOfServices: end`);\n return services;\n}\n\n/**\n * Get all services including their descendents.\n * @returns Promise resolving to an array of services with their descendants\n */\nexport async function getFullServices(): Promise<FullService[]> {\n debugMessage(`ServiceOps.getFullServices: start`);\n const serviceList = (await _getListOfServices()).result;\n\n const fullServiceData = await Promise.all(\n serviceList.map(async (listItem) => {\n try {\n const [service, nextDescendents] = await Promise.all([\n getService(listItem._id),\n getServiceDescendents(listItem._id),\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 * @returns promise resolving to a service object\n */\nasync function putFullService(\n serviceId: string,\n fullServiceData: FullService,\n clean: boolean\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.putFullService: start, serviceId=${serviceId}`);\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);\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(serviceId, fullServiceData);\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 type,\n descendentId,\n descendent\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 * @returns {Promise<AmService[]>} promise resolving to an array of service objects\n */\nasync function putFullServices(\n serviceEntries: [string, FullService][],\n clean: boolean\n): Promise<AmServiceSkeleton[]> {\n debugMessage(`ServiceOps.putFullServices: start`);\n const results: AmServiceSkeleton[] = [];\n for (const [id, data] of serviceEntries) {\n try {\n const result = await putFullService(id, data, clean);\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 */\nexport async function deleteFullService(serviceId: string) {\n const serviceNextDescendentData = await getServiceDescendents(serviceId);\n\n await Promise.all(\n serviceNextDescendentData.map((nextDescendent) =>\n deleteServiceNextDescendent(\n serviceId,\n nextDescendent._type._id,\n nextDescendent._id\n )\n )\n );\n\n await deleteService(serviceId);\n}\n\n/**\n * Deletes all services\n */\nexport async function deleteFullServices() {\n debugMessage(`ServiceOps.deleteFullServices: start`);\n try {\n const serviceList = (await _getListOfServices()).result;\n\n await Promise.all(\n serviceList.map(async (serviceListItem) => {\n try {\n await deleteFullService(serviceListItem._id);\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 * @returns {Promise<ServiceExportInterface>} Promise resolving to a ServiceExportInterface object.\n */\nexport async function exportService(\n serviceId: string\n): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportService: start`);\n const exportData = createServiceExportTemplate();\n try {\n const service = await getService(serviceId);\n service.nextDescendents = await getServiceDescendents(serviceId);\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 {string} file Options filename for the file, otherwise all{realm}Services.service.json will be the name\n */\nexport async function exportServices(): Promise<ServiceExportInterface> {\n debugMessage(`ServiceOps.exportServices: start`);\n const exportData = createServiceExportTemplate();\n try {\n const services = await getFullServices();\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 {boolean} clean Indicates whether to remove a possible existing service with the same id first.\n * @param {string} file Reference to the filename with the data for the service\n * @returns Promise resolving when the service has been imported\n */\nexport async function importService(\n serviceId: string,\n importData: ServiceExportInterface,\n clean: boolean\n): Promise<AmServiceSkeleton> {\n debugMessage(`ServiceOps.importService: start`);\n const serviceData = importData.service[serviceId];\n const result = await putFullService(serviceId, serviceData, clean);\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 {boolean} clean Indicates whether to remove possible existing services first\n */\nexport async function importServices(\n importData: ServiceExportInterface,\n clean: boolean\n) {\n debugMessage(`ServiceOps.importServices: start`);\n try {\n const result = await putFullServices(\n Object.entries(importData.service),\n clean\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"]}
|