@rockcarver/frodo-lib 0.12.4 → 0.12.5

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.
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findOrphanedNodes = findOrphanedNodes;
7
+ exports.isCloudOnlyNode = isCloudOnlyNode;
8
+ exports.isCustomNode = isCustomNode;
9
+ exports.isPremiumNode = isPremiumNode;
10
+ exports.removeOrphanedNodes = removeOrphanedNodes;
11
+
12
+ var _lodash = _interopRequireDefault(require("lodash"));
13
+
14
+ var _SessionStorage = _interopRequireDefault(require("../storage/SessionStorage"));
15
+
16
+ var _NodeApi = require("../api/NodeApi");
17
+
18
+ var _TreeApi = require("../api/TreeApi");
19
+
20
+ var _Console = require("./utils/Console");
21
+
22
+ var _Saml2Api = require("../api/Saml2Api");
23
+
24
+ var _Base = require("../api/utils/Base64");
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
29
+
30
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
31
+
32
+ var containerNodes = ['PageNode', 'CustomPageNode'];
33
+ var scriptedNodes = ['ConfigProviderNode', 'ScriptedDecisionNode', 'ClientScriptNode', 'SocialProviderHandlerNode', 'CustomScriptNode'];
34
+ var emailTemplateNodes = ['EmailSuspendNode', 'EmailTemplateNode'];
35
+ var emptyScriptPlaceholder = '[Empty]';
36
+ /**
37
+ * Helper to get all SAML2 dependencies for a given node object
38
+ * @param {Object} nodeObject node object
39
+ * @param {[Object]} allProviders array of all saml2 providers objects
40
+ * @param {[Object]} allCirclesOfTrust array of all circle of trust objects
41
+ * @returns {Promise} a promise that resolves to an object containing a saml2 dependencies
42
+ */
43
+
44
+ function getSaml2NodeDependencies(_x, _x2, _x3) {
45
+ return _getSaml2NodeDependencies.apply(this, arguments);
46
+ } // export async function getTreeNodes(treeObject) {
47
+ // const nodeList = Object.entries(treeObject.nodes);
48
+ // const results = await Promise.allSettled(
49
+ // nodeList.map(
50
+ // async ([nodeId, nodeInfo]) => await getNode(nodeId, nodeInfo['nodeType'])
51
+ // )
52
+ // );
53
+ // const nodes = results.filter((r) => r.status === 'fulfilled');
54
+ // nodes.map((f) => {
55
+ // return f.status;
56
+ // });
57
+ // const failedList = results.filter((r) => r.status === 'rejected');
58
+ // return nodes;
59
+ // }
60
+
61
+ /**
62
+ * Find all node configuration objects that are no longer referenced by any tree
63
+ * @returns {Promise<unknown[]>} a promise that resolves to an array of orphaned nodes
64
+ */
65
+
66
+
67
+ function _getSaml2NodeDependencies() {
68
+ _getSaml2NodeDependencies = _asyncToGenerator(function* (nodeObject, allProviders, allCirclesOfTrust) {
69
+ var samlProperties = ['metaAlias', 'idpEntityId'];
70
+ var saml2EntityPromises = [];
71
+
72
+ for (var samlProperty of samlProperties) {
73
+ // In the following line nodeObject[samlProperty] will look like '/alpha/iSPAzure'.
74
+ var entityId = samlProperty === 'metaAlias' ? _lodash.default.last(nodeObject[samlProperty].split('/')) : nodeObject[samlProperty];
75
+
76
+ var entity = _lodash.default.find(allProviders, {
77
+ entityId
78
+ });
79
+
80
+ if (entity) {
81
+ try {
82
+ var providerResponse = yield (0, _Saml2Api.getProviderByLocationAndId)(entity.location, entity._id);
83
+ /**
84
+ * Adding entityLocation here to the entityResponse because the import tool
85
+ * needs to know whether the saml2 entity is remote or not (this will be removed
86
+ * from the config before importing see updateSaml2Entity and createSaml2Entity functions).
87
+ * Importing a remote saml2 entity is a slightly different request (see createSaml2Entity).
88
+ */
89
+
90
+ providerResponse.entityLocation = entity.location;
91
+
92
+ if (entity.location === 'remote') {
93
+ // get the xml representation of this entity and add it to the entityResponse;
94
+ var metaDataResponse = yield (0, _Saml2Api.getProviderMetadata)(providerResponse.entityId);
95
+ providerResponse.base64EntityXML = (0, _Base.encodeBase64Url)(metaDataResponse);
96
+ }
97
+
98
+ saml2EntityPromises.push(providerResponse);
99
+ } catch (error) {
100
+ (0, _Console.printMessage)(error.message, 'error');
101
+ }
102
+ }
103
+ }
104
+
105
+ try {
106
+ var saml2EntitiesPromisesResults = yield Promise.all(saml2EntityPromises);
107
+ var saml2Entities = [];
108
+
109
+ for (var saml2Entity of saml2EntitiesPromisesResults) {
110
+ if (saml2Entity) {
111
+ saml2Entities.push(saml2Entity);
112
+ }
113
+ }
114
+
115
+ var samlEntityIds = _lodash.default.map(saml2Entities, saml2EntityConfig => "".concat(saml2EntityConfig.entityId, "|saml2"));
116
+
117
+ var circlesOfTrust = _lodash.default.filter(allCirclesOfTrust, circleOfTrust => {
118
+ var hasEntityId = false;
119
+
120
+ for (var trustedProvider of circleOfTrust.trustedProviders) {
121
+ if (!hasEntityId && samlEntityIds.includes(trustedProvider)) {
122
+ hasEntityId = true;
123
+ }
124
+ }
125
+
126
+ return hasEntityId;
127
+ });
128
+
129
+ var saml2NodeDependencies = {
130
+ saml2Entities,
131
+ circlesOfTrust
132
+ };
133
+ return saml2NodeDependencies;
134
+ } catch (error) {
135
+ (0, _Console.printMessage)(error.message, 'error');
136
+ var _saml2NodeDependencies = {
137
+ saml2Entities: [],
138
+ circlesOfTrust: []
139
+ };
140
+ return _saml2NodeDependencies;
141
+ }
142
+ });
143
+ return _getSaml2NodeDependencies.apply(this, arguments);
144
+ }
145
+
146
+ function findOrphanedNodes() {
147
+ return _findOrphanedNodes.apply(this, arguments);
148
+ }
149
+ /**
150
+ * Remove orphaned nodes
151
+ * @param {[Object]} orphanedNodes Pass in an array of orphaned node configuration objects to remove
152
+ * @returns {Promise<unknown[]>} a promise that resolves to an array nodes that encountered errors deleting
153
+ */
154
+
155
+
156
+ function _findOrphanedNodes() {
157
+ _findOrphanedNodes = _asyncToGenerator(function* () {
158
+ var allNodes = [];
159
+ var orphanedNodes = [];
160
+ var types = [];
161
+ var allJourneys = (yield (0, _TreeApi.getTrees)()).result;
162
+ var errorMessage = '';
163
+ var errorTypes = [];
164
+ (0, _Console.createProgressIndicator)(undefined, "Counting total nodes...", 'indeterminate');
165
+
166
+ try {
167
+ types = (yield (0, _NodeApi.getNodeTypes)()).result;
168
+ } catch (error) {
169
+ (0, _Console.printMessage)('Error retrieving all available node types:', 'error');
170
+ (0, _Console.printMessage)(error.response.data, 'error');
171
+ return [];
172
+ }
173
+
174
+ for (var type of types) {
175
+ try {
176
+ // eslint-disable-next-line no-await-in-loop, no-loop-func
177
+ var nodes = (yield (0, _NodeApi.getNodesByType)(type._id)).result;
178
+
179
+ for (var node of nodes) {
180
+ allNodes.push(node);
181
+ (0, _Console.updateProgressIndicator)("".concat(allNodes.length, " total nodes").concat(errorMessage));
182
+ }
183
+ } catch (error) {
184
+ errorTypes.push(type._id);
185
+ errorMessage = " (Skipped type(s): ".concat(errorTypes, ")")['yellow'];
186
+ (0, _Console.updateProgressIndicator)("".concat(allNodes.length, " total nodes").concat(errorMessage));
187
+ }
188
+ }
189
+
190
+ if (errorTypes.length > 0) {
191
+ (0, _Console.stopProgressIndicator)("".concat(allNodes.length, " total nodes").concat(errorMessage), 'warn');
192
+ } else {
193
+ (0, _Console.stopProgressIndicator)("".concat(allNodes.length, " total nodes"), 'success');
194
+ }
195
+
196
+ (0, _Console.createProgressIndicator)(undefined, 'Counting active nodes...', 'indeterminate');
197
+ var activeNodes = [];
198
+
199
+ for (var journey of allJourneys) {
200
+ for (var nodeId in journey.nodes) {
201
+ if ({}.hasOwnProperty.call(journey.nodes, nodeId)) {
202
+ activeNodes.push(nodeId);
203
+ (0, _Console.updateProgressIndicator)("".concat(activeNodes.length, " active nodes"));
204
+ var _node = journey.nodes[nodeId];
205
+
206
+ if (containerNodes.includes(_node.nodeType)) {
207
+ var containerNode = yield (0, _NodeApi.getNode)(nodeId, _node.nodeType);
208
+
209
+ for (var innerNode of containerNode.nodes) {
210
+ activeNodes.push(innerNode._id);
211
+ (0, _Console.updateProgressIndicator)("".concat(activeNodes.length, " active nodes"));
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ (0, _Console.stopProgressIndicator)("".concat(activeNodes.length, " active nodes"), 'success');
219
+ (0, _Console.createProgressIndicator)(undefined, 'Calculating orphaned nodes...', 'indeterminate');
220
+ var diff = allNodes.filter(x => !activeNodes.includes(x._id));
221
+
222
+ for (var orphanedNode of diff) {
223
+ orphanedNodes.push(orphanedNode);
224
+ }
225
+
226
+ (0, _Console.stopProgressIndicator)("".concat(orphanedNodes.length, " orphaned nodes"), 'success');
227
+ return orphanedNodes;
228
+ });
229
+ return _findOrphanedNodes.apply(this, arguments);
230
+ }
231
+
232
+ function removeOrphanedNodes(_x4) {
233
+ return _removeOrphanedNodes.apply(this, arguments);
234
+ }
235
+
236
+ function _removeOrphanedNodes() {
237
+ _removeOrphanedNodes = _asyncToGenerator(function* (orphanedNodes) {
238
+ var errorNodes = [];
239
+ (0, _Console.createProgressIndicator)(orphanedNodes.length, 'Removing orphaned nodes...');
240
+
241
+ for (var node of orphanedNodes) {
242
+ (0, _Console.updateProgressIndicator)("Removing ".concat(node['_id'], "..."));
243
+
244
+ try {
245
+ // eslint-disable-next-line no-await-in-loop
246
+ yield (0, _NodeApi.deleteNode)(node['_id'], node['_type']['_id']);
247
+ } catch (deleteError) {
248
+ errorNodes.push(node);
249
+ (0, _Console.printMessage)(" ".concat(deleteError), 'error');
250
+ }
251
+ }
252
+
253
+ (0, _Console.stopProgressIndicator)("Removed ".concat(orphanedNodes.length, " orphaned nodes."));
254
+ return errorNodes;
255
+ });
256
+ return _removeOrphanedNodes.apply(this, arguments);
257
+ }
258
+
259
+ var OOTB_NODE_TYPES_7 = ['AcceptTermsAndConditionsNode', 'AccountActiveDecisionNode', 'AccountLockoutNode', 'AgentDataStoreDecisionNode', 'AnonymousSessionUpgradeNode', 'AnonymousUserNode', 'AttributeCollectorNode', 'AttributePresentDecisionNode', 'AttributeValueDecisionNode', 'AuthLevelDecisionNode', 'ChoiceCollectorNode', 'ConsentNode', 'CookiePresenceDecisionNode', 'CreateObjectNode', 'CreatePasswordNode', 'DataStoreDecisionNode', 'DeviceGeoFencingNode', 'DeviceLocationMatchNode', 'DeviceMatchNode', 'DeviceProfileCollectorNode', 'DeviceSaveNode', 'DeviceTamperingVerificationNode', 'DisplayUserNameNode', 'EmailSuspendNode', 'EmailTemplateNode', 'IdentifyExistingUserNode', 'IncrementLoginCountNode', 'InnerTreeEvaluatorNode', 'IotAuthenticationNode', 'IotRegistrationNode', 'KbaCreateNode', 'KbaDecisionNode', 'KbaVerifyNode', 'LdapDecisionNode', 'LoginCountDecisionNode', 'MessageNode', 'MetadataNode', 'MeterNode', 'ModifyAuthLevelNode', 'OneTimePasswordCollectorDecisionNode', 'OneTimePasswordGeneratorNode', 'OneTimePasswordSmsSenderNode', 'OneTimePasswordSmtpSenderNode', 'PageNode', 'PasswordCollectorNode', 'PatchObjectNode', 'PersistentCookieDecisionNode', 'PollingWaitNode', 'ProfileCompletenessDecisionNode', 'ProvisionDynamicAccountNode', 'ProvisionIdmAccountNode', 'PushAuthenticationSenderNode', 'PushResultVerifierNode', 'QueryFilterDecisionNode', 'RecoveryCodeCollectorDecisionNode', 'RecoveryCodeDisplayNode', 'RegisterLogoutWebhookNode', 'RemoveSessionPropertiesNode', 'RequiredAttributesDecisionNode', 'RetryLimitDecisionNode', 'ScriptedDecisionNode', 'SelectIdPNode', 'SessionDataNode', 'SetFailureUrlNode', 'SetPersistentCookieNode', 'SetSessionPropertiesNode', 'SetSuccessUrlNode', 'SocialFacebookNode', 'SocialGoogleNode', 'SocialNode', 'SocialOAuthIgnoreProfileNode', 'SocialOpenIdConnectNode', 'SocialProviderHandlerNode', 'TermsAndConditionsDecisionNode', 'TimeSinceDecisionNode', 'TimerStartNode', 'TimerStopNode', 'UsernameCollectorNode', 'ValidatedPasswordNode', 'ValidatedUsernameNode', 'WebAuthnAuthenticationNode', 'WebAuthnDeviceStorageNode', 'WebAuthnRegistrationNode', 'ZeroPageLoginNode', 'product-CertificateCollectorNode', 'product-CertificateUserExtractorNode', 'product-CertificateValidationNode', 'product-KerberosNode', 'product-ReCaptchaNode', 'product-Saml2Node', 'product-WriteFederationInformationNode'];
260
+ var OOTB_NODE_TYPES_7_1 = ['PushRegistrationNode', 'GetAuthenticatorAppNode', 'MultiFactorRegistrationOptionsNode', 'OptOutMultiFactorAuthenticationNode'].concat(OOTB_NODE_TYPES_7);
261
+ var OOTB_NODE_TYPES_7_2 = ['OathRegistrationNode', 'OathTokenVerifierNode', 'PassthroughAuthenticationNode', 'ConfigProviderNode', 'DebugNode'].concat(OOTB_NODE_TYPES_7_1);
262
+ var OOTB_NODE_TYPES_7_3 = [].concat(OOTB_NODE_TYPES_7_2);
263
+ var OOTB_NODE_TYPES_6_5 = ['AbstractSocialAuthLoginNode', 'AccountLockoutNode', 'AgentDataStoreDecisionNode', 'AnonymousUserNode', 'AuthLevelDecisionNode', 'ChoiceCollectorNode', 'CookiePresenceDecisionNode', 'CreatePasswordNode', 'DataStoreDecisionNode', 'InnerTreeEvaluatorNode', 'LdapDecisionNode', 'MessageNode', 'MetadataNode', 'MeterNode', 'ModifyAuthLevelNode', 'OneTimePasswordCollectorDecisionNode', 'OneTimePasswordGeneratorNode', 'OneTimePasswordSmsSenderNode', 'OneTimePasswordSmtpSenderNode', 'PageNode', 'PasswordCollectorNode', 'PersistentCookieDecisionNode', 'PollingWaitNode', 'ProvisionDynamicAccountNode', 'ProvisionIdmAccountNode', 'PushAuthenticationSenderNode', 'PushResultVerifierNode', 'RecoveryCodeCollectorDecisionNode', 'RecoveryCodeDisplayNode', 'RegisterLogoutWebhookNode', 'RemoveSessionPropertiesNode', 'RetryLimitDecisionNode', 'ScriptedDecisionNode', 'SessionDataNode', 'SetFailureUrlNode', 'SetPersistentCookieNode', 'SetSessionPropertiesNode', 'SetSuccessUrlNode', 'SocialFacebookNode', 'SocialGoogleNode', 'SocialNode', 'SocialOAuthIgnoreProfileNode', 'SocialOpenIdConnectNode', 'TimerStartNode', 'TimerStopNode', 'UsernameCollectorNode', 'WebAuthnAuthenticationNode', 'WebAuthnRegistrationNode', 'ZeroPageLoginNode'];
264
+ var OOTB_NODE_TYPES_6 = ['AbstractSocialAuthLoginNode', 'AccountLockoutNode', 'AgentDataStoreDecisionNode', 'AnonymousUserNode', 'AuthLevelDecisionNode', 'ChoiceCollectorNode', 'CookiePresenceDecisionNode', 'CreatePasswordNode', 'DataStoreDecisionNode', 'InnerTreeEvaluatorNode', 'LdapDecisionNode', 'MessageNode', 'MetadataNode', 'MeterNode', 'ModifyAuthLevelNode', 'OneTimePasswordCollectorDecisionNode', 'OneTimePasswordGeneratorNode', 'OneTimePasswordSmsSenderNode', 'OneTimePasswordSmtpSenderNode', 'PageNode', 'PasswordCollectorNode', 'PersistentCookieDecisionNode', 'PollingWaitNode', 'ProvisionDynamicAccountNode', 'ProvisionIdmAccountNode', 'PushAuthenticationSenderNode', 'PushResultVerifierNode', 'RecoveryCodeCollectorDecisionNode', 'RecoveryCodeDisplayNode', 'RegisterLogoutWebhookNode', 'RemoveSessionPropertiesNode', 'RetryLimitDecisionNode', 'ScriptedDecisionNode', 'SessionDataNode', 'SetFailureUrlNode', 'SetPersistentCookieNode', 'SetSessionPropertiesNode', 'SetSuccessUrlNode', 'SocialFacebookNode', 'SocialGoogleNode', 'SocialNode', 'SocialOAuthIgnoreProfileNode', 'SocialOpenIdConnectNode', 'TimerStartNode', 'TimerStopNode', 'UsernameCollectorNode', 'WebAuthnAuthenticationNode', 'WebAuthnRegistrationNode', 'ZeroPageLoginNode'];
265
+ var CLOUD_ONLY_NODE_TYPES = ['IdentityStoreDecisionNode'];
266
+ var PREMIUM_NODE_TYPES = ['AutonomousAccessSignalNode', 'AutonomousAccessDecisionNode', 'AutonomousAccessResultNode'];
267
+ /**
268
+ * Analyze if a node is a premium node.
269
+ * @param {string} nodeType Node type
270
+ * @returns {boolean} True if the node type is premium, false otherwise.
271
+ */
272
+
273
+ function isPremiumNode(nodeType) {
274
+ return PREMIUM_NODE_TYPES.includes(nodeType);
275
+ }
276
+ /**
277
+ * Analyze if a node is a cloud-only node.
278
+ * @param {string} nodeType Node type
279
+ * @returns {boolean} True if the node type is cloud-only, false otherwise.
280
+ */
281
+
282
+
283
+ function isCloudOnlyNode(nodeType) {
284
+ return CLOUD_ONLY_NODE_TYPES.includes(nodeType);
285
+ }
286
+ /**
287
+ * Analyze if a node is custom.
288
+ * @param {string} nodeType Node type
289
+ * @returns {boolean} True if the node type is custom, false otherwise.
290
+ */
291
+
292
+
293
+ function isCustomNode(nodeType) {
294
+ var ootbNodeTypes = [];
295
+
296
+ switch (_SessionStorage.default.session.getAmVersion()) {
297
+ case '7.1.0':
298
+ ootbNodeTypes = OOTB_NODE_TYPES_7_1.slice(0);
299
+ break;
300
+
301
+ case '7.2.0':
302
+ ootbNodeTypes = OOTB_NODE_TYPES_7_2.slice(0);
303
+ break;
304
+
305
+ case '7.3.0':
306
+ ootbNodeTypes = OOTB_NODE_TYPES_7_3.slice(0);
307
+ break;
308
+
309
+ case '7.0.0':
310
+ case '7.0.1':
311
+ case '7.0.2':
312
+ ootbNodeTypes = OOTB_NODE_TYPES_7.slice(0);
313
+ break;
314
+
315
+ case '6.5.3':
316
+ case '6.5.2.3':
317
+ case '6.5.2.2':
318
+ case '6.5.2.1':
319
+ case '6.5.2':
320
+ case '6.5.1':
321
+ case '6.5.0.2':
322
+ case '6.5.0.1':
323
+ ootbNodeTypes = OOTB_NODE_TYPES_6_5.slice(0);
324
+ break;
325
+
326
+ case '6.0.0.7':
327
+ case '6.0.0.6':
328
+ case '6.0.0.5':
329
+ case '6.0.0.4':
330
+ case '6.0.0.3':
331
+ case '6.0.0.2':
332
+ case '6.0.0.1':
333
+ case '6.0.0':
334
+ ootbNodeTypes = OOTB_NODE_TYPES_6.slice(0);
335
+ break;
336
+
337
+ default:
338
+ return true;
339
+ }
340
+
341
+ return !ootbNodeTypes.includes(nodeType) && !isPremiumNode(nodeType) && !isCloudOnlyNode(nodeType);
342
+ }
343
+ //# sourceMappingURL=NodeOps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeOps.js","names":["containerNodes","scriptedNodes","emailTemplateNodes","emptyScriptPlaceholder","getSaml2NodeDependencies","nodeObject","allProviders","allCirclesOfTrust","samlProperties","saml2EntityPromises","samlProperty","entityId","_","last","split","entity","find","providerResponse","getProviderByLocationAndId","location","_id","entityLocation","metaDataResponse","getProviderMetadata","base64EntityXML","encodeBase64Url","push","error","printMessage","message","saml2EntitiesPromisesResults","Promise","all","saml2Entities","saml2Entity","samlEntityIds","map","saml2EntityConfig","circlesOfTrust","filter","circleOfTrust","hasEntityId","trustedProvider","trustedProviders","includes","saml2NodeDependencies","findOrphanedNodes","allNodes","orphanedNodes","types","allJourneys","getTrees","result","errorMessage","errorTypes","createProgressIndicator","undefined","getNodeTypes","response","data","type","nodes","getNodesByType","node","updateProgressIndicator","length","stopProgressIndicator","activeNodes","journey","nodeId","hasOwnProperty","call","nodeType","containerNode","getNode","innerNode","diff","x","orphanedNode","removeOrphanedNodes","errorNodes","deleteNode","deleteError","OOTB_NODE_TYPES_7","OOTB_NODE_TYPES_7_1","concat","OOTB_NODE_TYPES_7_2","OOTB_NODE_TYPES_7_3","OOTB_NODE_TYPES_6_5","OOTB_NODE_TYPES_6","CLOUD_ONLY_NODE_TYPES","PREMIUM_NODE_TYPES","isPremiumNode","isCloudOnlyNode","isCustomNode","ootbNodeTypes","storage","session","getAmVersion","slice"],"sources":["ops/NodeOps.ts"],"sourcesContent":["import _ from 'lodash';\nimport storage from '../storage/SessionStorage';\nimport {\n getNode,\n deleteNode,\n getNodeTypes,\n getNodesByType,\n} from '../api/NodeApi';\nimport { getTrees } from '../api/TreeApi';\nimport {\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\nimport {\n getProviderByLocationAndId,\n getProviderMetadata,\n} from '../api/Saml2Api';\nimport { encodeBase64Url } from '../api/utils/Base64';\n\nconst containerNodes = ['PageNode', 'CustomPageNode'];\n\nconst scriptedNodes = [\n 'ConfigProviderNode',\n 'ScriptedDecisionNode',\n 'ClientScriptNode',\n 'SocialProviderHandlerNode',\n 'CustomScriptNode',\n];\n\nconst emailTemplateNodes = ['EmailSuspendNode', 'EmailTemplateNode'];\n\nconst emptyScriptPlaceholder = '[Empty]';\n\n/**\n * Helper to get all SAML2 dependencies for a given node object\n * @param {Object} nodeObject node object\n * @param {[Object]} allProviders array of all saml2 providers objects\n * @param {[Object]} allCirclesOfTrust array of all circle of trust objects\n * @returns {Promise} a promise that resolves to an object containing a saml2 dependencies\n */\nasync function getSaml2NodeDependencies(\n nodeObject,\n allProviders,\n allCirclesOfTrust\n) {\n const samlProperties = ['metaAlias', 'idpEntityId'];\n const saml2EntityPromises = [];\n for (const samlProperty of samlProperties) {\n // In the following line nodeObject[samlProperty] will look like '/alpha/iSPAzure'.\n const entityId =\n samlProperty === 'metaAlias'\n ? _.last(nodeObject[samlProperty].split('/'))\n : nodeObject[samlProperty];\n const entity = _.find(allProviders, { entityId });\n if (entity) {\n try {\n const providerResponse = await getProviderByLocationAndId(\n entity.location,\n entity._id\n );\n /**\n * Adding entityLocation here to the entityResponse because the import tool\n * needs to know whether the saml2 entity is remote or not (this will be removed\n * from the config before importing see updateSaml2Entity and createSaml2Entity functions).\n * Importing a remote saml2 entity is a slightly different request (see createSaml2Entity).\n */\n providerResponse.entityLocation = entity.location;\n\n if (entity.location === 'remote') {\n // get the xml representation of this entity and add it to the entityResponse;\n const metaDataResponse = await getProviderMetadata(\n providerResponse.entityId\n );\n providerResponse.base64EntityXML = encodeBase64Url(metaDataResponse);\n }\n saml2EntityPromises.push(providerResponse);\n } catch (error) {\n printMessage(error.message, 'error');\n }\n }\n }\n try {\n const saml2EntitiesPromisesResults = await Promise.all(saml2EntityPromises);\n const saml2Entities = [];\n for (const saml2Entity of saml2EntitiesPromisesResults) {\n if (saml2Entity) {\n saml2Entities.push(saml2Entity);\n }\n }\n const samlEntityIds = _.map(\n saml2Entities,\n (saml2EntityConfig) => `${saml2EntityConfig.entityId}|saml2`\n );\n const circlesOfTrust = _.filter(allCirclesOfTrust, (circleOfTrust) => {\n let hasEntityId = false;\n for (const trustedProvider of circleOfTrust.trustedProviders) {\n if (!hasEntityId && samlEntityIds.includes(trustedProvider)) {\n hasEntityId = true;\n }\n }\n return hasEntityId;\n });\n const saml2NodeDependencies = {\n saml2Entities,\n circlesOfTrust,\n };\n return saml2NodeDependencies;\n } catch (error) {\n printMessage(error.message, 'error');\n const saml2NodeDependencies = {\n saml2Entities: [],\n circlesOfTrust: [],\n };\n return saml2NodeDependencies;\n }\n}\n\n// export async function getTreeNodes(treeObject) {\n// const nodeList = Object.entries(treeObject.nodes);\n// const results = await Promise.allSettled(\n// nodeList.map(\n// async ([nodeId, nodeInfo]) => await getNode(nodeId, nodeInfo['nodeType'])\n// )\n// );\n// const nodes = results.filter((r) => r.status === 'fulfilled');\n// nodes.map((f) => {\n// return f.status;\n// });\n// const failedList = results.filter((r) => r.status === 'rejected');\n// return nodes;\n// }\n\n/**\n * Find all node configuration objects that are no longer referenced by any tree\n * @returns {Promise<unknown[]>} a promise that resolves to an array of orphaned nodes\n */\nexport async function findOrphanedNodes(): Promise<unknown[]> {\n const allNodes = [];\n const orphanedNodes = [];\n let types = [];\n const allJourneys = (await getTrees()).result;\n let errorMessage = '';\n const errorTypes = [];\n\n createProgressIndicator(\n undefined,\n `Counting total nodes...`,\n 'indeterminate'\n );\n try {\n types = (await getNodeTypes()).result;\n } catch (error) {\n printMessage('Error retrieving all available node types:', 'error');\n printMessage(error.response.data, 'error');\n return [];\n }\n for (const type of types) {\n try {\n // eslint-disable-next-line no-await-in-loop, no-loop-func\n const nodes = (await getNodesByType(type._id)).result;\n for (const node of nodes) {\n allNodes.push(node);\n updateProgressIndicator(\n `${allNodes.length} total nodes${errorMessage}`\n );\n }\n } catch (error) {\n errorTypes.push(type._id);\n errorMessage = ` (Skipped type(s): ${errorTypes})`['yellow'];\n updateProgressIndicator(`${allNodes.length} total nodes${errorMessage}`);\n }\n }\n if (errorTypes.length > 0) {\n stopProgressIndicator(\n `${allNodes.length} total nodes${errorMessage}`,\n 'warn'\n );\n } else {\n stopProgressIndicator(`${allNodes.length} total nodes`, 'success');\n }\n\n createProgressIndicator(\n undefined,\n 'Counting active nodes...',\n 'indeterminate'\n );\n const activeNodes = [];\n for (const journey of allJourneys) {\n for (const nodeId in journey.nodes) {\n if ({}.hasOwnProperty.call(journey.nodes, nodeId)) {\n activeNodes.push(nodeId);\n updateProgressIndicator(`${activeNodes.length} active nodes`);\n const node = journey.nodes[nodeId];\n if (containerNodes.includes(node.nodeType)) {\n const containerNode = await getNode(nodeId, node.nodeType);\n for (const innerNode of containerNode.nodes) {\n activeNodes.push(innerNode._id);\n updateProgressIndicator(`${activeNodes.length} active nodes`);\n }\n }\n }\n }\n }\n stopProgressIndicator(`${activeNodes.length} active nodes`, 'success');\n\n createProgressIndicator(\n undefined,\n 'Calculating orphaned nodes...',\n 'indeterminate'\n );\n const diff = allNodes.filter((x) => !activeNodes.includes(x._id));\n for (const orphanedNode of diff) {\n orphanedNodes.push(orphanedNode);\n }\n stopProgressIndicator(`${orphanedNodes.length} orphaned nodes`, 'success');\n return orphanedNodes;\n}\n\n/**\n * Remove orphaned nodes\n * @param {[Object]} orphanedNodes Pass in an array of orphaned node configuration objects to remove\n * @returns {Promise<unknown[]>} a promise that resolves to an array nodes that encountered errors deleting\n */\nexport async function removeOrphanedNodes(\n orphanedNodes: unknown[]\n): Promise<unknown[]> {\n const errorNodes = [];\n createProgressIndicator(orphanedNodes.length, 'Removing orphaned nodes...');\n for (const node of orphanedNodes) {\n updateProgressIndicator(`Removing ${node['_id']}...`);\n try {\n // eslint-disable-next-line no-await-in-loop\n await deleteNode(node['_id'], node['_type']['_id']);\n } catch (deleteError) {\n errorNodes.push(node);\n printMessage(` ${deleteError}`, 'error');\n }\n }\n stopProgressIndicator(`Removed ${orphanedNodes.length} orphaned nodes.`);\n return errorNodes;\n}\n\nconst OOTB_NODE_TYPES_7 = [\n 'AcceptTermsAndConditionsNode',\n 'AccountActiveDecisionNode',\n 'AccountLockoutNode',\n 'AgentDataStoreDecisionNode',\n 'AnonymousSessionUpgradeNode',\n 'AnonymousUserNode',\n 'AttributeCollectorNode',\n 'AttributePresentDecisionNode',\n 'AttributeValueDecisionNode',\n 'AuthLevelDecisionNode',\n 'ChoiceCollectorNode',\n 'ConsentNode',\n 'CookiePresenceDecisionNode',\n 'CreateObjectNode',\n 'CreatePasswordNode',\n 'DataStoreDecisionNode',\n 'DeviceGeoFencingNode',\n 'DeviceLocationMatchNode',\n 'DeviceMatchNode',\n 'DeviceProfileCollectorNode',\n 'DeviceSaveNode',\n 'DeviceTamperingVerificationNode',\n 'DisplayUserNameNode',\n 'EmailSuspendNode',\n 'EmailTemplateNode',\n 'IdentifyExistingUserNode',\n 'IncrementLoginCountNode',\n 'InnerTreeEvaluatorNode',\n 'IotAuthenticationNode',\n 'IotRegistrationNode',\n 'KbaCreateNode',\n 'KbaDecisionNode',\n 'KbaVerifyNode',\n 'LdapDecisionNode',\n 'LoginCountDecisionNode',\n 'MessageNode',\n 'MetadataNode',\n 'MeterNode',\n 'ModifyAuthLevelNode',\n 'OneTimePasswordCollectorDecisionNode',\n 'OneTimePasswordGeneratorNode',\n 'OneTimePasswordSmsSenderNode',\n 'OneTimePasswordSmtpSenderNode',\n 'PageNode',\n 'PasswordCollectorNode',\n 'PatchObjectNode',\n 'PersistentCookieDecisionNode',\n 'PollingWaitNode',\n 'ProfileCompletenessDecisionNode',\n 'ProvisionDynamicAccountNode',\n 'ProvisionIdmAccountNode',\n 'PushAuthenticationSenderNode',\n 'PushResultVerifierNode',\n 'QueryFilterDecisionNode',\n 'RecoveryCodeCollectorDecisionNode',\n 'RecoveryCodeDisplayNode',\n 'RegisterLogoutWebhookNode',\n 'RemoveSessionPropertiesNode',\n 'RequiredAttributesDecisionNode',\n 'RetryLimitDecisionNode',\n 'ScriptedDecisionNode',\n 'SelectIdPNode',\n 'SessionDataNode',\n 'SetFailureUrlNode',\n 'SetPersistentCookieNode',\n 'SetSessionPropertiesNode',\n 'SetSuccessUrlNode',\n 'SocialFacebookNode',\n 'SocialGoogleNode',\n 'SocialNode',\n 'SocialOAuthIgnoreProfileNode',\n 'SocialOpenIdConnectNode',\n 'SocialProviderHandlerNode',\n 'TermsAndConditionsDecisionNode',\n 'TimeSinceDecisionNode',\n 'TimerStartNode',\n 'TimerStopNode',\n 'UsernameCollectorNode',\n 'ValidatedPasswordNode',\n 'ValidatedUsernameNode',\n 'WebAuthnAuthenticationNode',\n 'WebAuthnDeviceStorageNode',\n 'WebAuthnRegistrationNode',\n 'ZeroPageLoginNode',\n 'product-CertificateCollectorNode',\n 'product-CertificateUserExtractorNode',\n 'product-CertificateValidationNode',\n 'product-KerberosNode',\n 'product-ReCaptchaNode',\n 'product-Saml2Node',\n 'product-WriteFederationInformationNode',\n];\n\nconst OOTB_NODE_TYPES_7_1 = [\n 'PushRegistrationNode',\n 'GetAuthenticatorAppNode',\n 'MultiFactorRegistrationOptionsNode',\n 'OptOutMultiFactorAuthenticationNode',\n].concat(OOTB_NODE_TYPES_7);\n\nconst OOTB_NODE_TYPES_7_2 = [\n 'OathRegistrationNode',\n 'OathTokenVerifierNode',\n 'PassthroughAuthenticationNode',\n 'ConfigProviderNode',\n 'DebugNode',\n].concat(OOTB_NODE_TYPES_7_1);\n\nconst OOTB_NODE_TYPES_7_3 = [].concat(OOTB_NODE_TYPES_7_2);\n\nconst OOTB_NODE_TYPES_6_5 = [\n 'AbstractSocialAuthLoginNode',\n 'AccountLockoutNode',\n 'AgentDataStoreDecisionNode',\n 'AnonymousUserNode',\n 'AuthLevelDecisionNode',\n 'ChoiceCollectorNode',\n 'CookiePresenceDecisionNode',\n 'CreatePasswordNode',\n 'DataStoreDecisionNode',\n 'InnerTreeEvaluatorNode',\n 'LdapDecisionNode',\n 'MessageNode',\n 'MetadataNode',\n 'MeterNode',\n 'ModifyAuthLevelNode',\n 'OneTimePasswordCollectorDecisionNode',\n 'OneTimePasswordGeneratorNode',\n 'OneTimePasswordSmsSenderNode',\n 'OneTimePasswordSmtpSenderNode',\n 'PageNode',\n 'PasswordCollectorNode',\n 'PersistentCookieDecisionNode',\n 'PollingWaitNode',\n 'ProvisionDynamicAccountNode',\n 'ProvisionIdmAccountNode',\n 'PushAuthenticationSenderNode',\n 'PushResultVerifierNode',\n 'RecoveryCodeCollectorDecisionNode',\n 'RecoveryCodeDisplayNode',\n 'RegisterLogoutWebhookNode',\n 'RemoveSessionPropertiesNode',\n 'RetryLimitDecisionNode',\n 'ScriptedDecisionNode',\n 'SessionDataNode',\n 'SetFailureUrlNode',\n 'SetPersistentCookieNode',\n 'SetSessionPropertiesNode',\n 'SetSuccessUrlNode',\n 'SocialFacebookNode',\n 'SocialGoogleNode',\n 'SocialNode',\n 'SocialOAuthIgnoreProfileNode',\n 'SocialOpenIdConnectNode',\n 'TimerStartNode',\n 'TimerStopNode',\n 'UsernameCollectorNode',\n 'WebAuthnAuthenticationNode',\n 'WebAuthnRegistrationNode',\n 'ZeroPageLoginNode',\n];\n\nconst OOTB_NODE_TYPES_6 = [\n 'AbstractSocialAuthLoginNode',\n 'AccountLockoutNode',\n 'AgentDataStoreDecisionNode',\n 'AnonymousUserNode',\n 'AuthLevelDecisionNode',\n 'ChoiceCollectorNode',\n 'CookiePresenceDecisionNode',\n 'CreatePasswordNode',\n 'DataStoreDecisionNode',\n 'InnerTreeEvaluatorNode',\n 'LdapDecisionNode',\n 'MessageNode',\n 'MetadataNode',\n 'MeterNode',\n 'ModifyAuthLevelNode',\n 'OneTimePasswordCollectorDecisionNode',\n 'OneTimePasswordGeneratorNode',\n 'OneTimePasswordSmsSenderNode',\n 'OneTimePasswordSmtpSenderNode',\n 'PageNode',\n 'PasswordCollectorNode',\n 'PersistentCookieDecisionNode',\n 'PollingWaitNode',\n 'ProvisionDynamicAccountNode',\n 'ProvisionIdmAccountNode',\n 'PushAuthenticationSenderNode',\n 'PushResultVerifierNode',\n 'RecoveryCodeCollectorDecisionNode',\n 'RecoveryCodeDisplayNode',\n 'RegisterLogoutWebhookNode',\n 'RemoveSessionPropertiesNode',\n 'RetryLimitDecisionNode',\n 'ScriptedDecisionNode',\n 'SessionDataNode',\n 'SetFailureUrlNode',\n 'SetPersistentCookieNode',\n 'SetSessionPropertiesNode',\n 'SetSuccessUrlNode',\n 'SocialFacebookNode',\n 'SocialGoogleNode',\n 'SocialNode',\n 'SocialOAuthIgnoreProfileNode',\n 'SocialOpenIdConnectNode',\n 'TimerStartNode',\n 'TimerStopNode',\n 'UsernameCollectorNode',\n 'WebAuthnAuthenticationNode',\n 'WebAuthnRegistrationNode',\n 'ZeroPageLoginNode',\n];\n\nconst CLOUD_ONLY_NODE_TYPES = ['IdentityStoreDecisionNode'];\n\nconst PREMIUM_NODE_TYPES = [\n 'AutonomousAccessSignalNode',\n 'AutonomousAccessDecisionNode',\n 'AutonomousAccessResultNode',\n];\n\n/**\n * Analyze if a node is a premium node.\n * @param {string} nodeType Node type\n * @returns {boolean} True if the node type is premium, false otherwise.\n */\nexport function isPremiumNode(nodeType: string): boolean {\n return PREMIUM_NODE_TYPES.includes(nodeType);\n}\n\n/**\n * Analyze if a node is a cloud-only node.\n * @param {string} nodeType Node type\n * @returns {boolean} True if the node type is cloud-only, false otherwise.\n */\nexport function isCloudOnlyNode(nodeType: string): boolean {\n return CLOUD_ONLY_NODE_TYPES.includes(nodeType);\n}\n\n/**\n * Analyze if a node is custom.\n * @param {string} nodeType Node type\n * @returns {boolean} True if the node type is custom, false otherwise.\n */\nexport function isCustomNode(nodeType: string): boolean {\n let ootbNodeTypes = [];\n switch (storage.session.getAmVersion()) {\n case '7.1.0':\n ootbNodeTypes = OOTB_NODE_TYPES_7_1.slice(0);\n break;\n case '7.2.0':\n ootbNodeTypes = OOTB_NODE_TYPES_7_2.slice(0);\n break;\n case '7.3.0':\n ootbNodeTypes = OOTB_NODE_TYPES_7_3.slice(0);\n break;\n case '7.0.0':\n case '7.0.1':\n case '7.0.2':\n ootbNodeTypes = OOTB_NODE_TYPES_7.slice(0);\n break;\n case '6.5.3':\n case '6.5.2.3':\n case '6.5.2.2':\n case '6.5.2.1':\n case '6.5.2':\n case '6.5.1':\n case '6.5.0.2':\n case '6.5.0.1':\n ootbNodeTypes = OOTB_NODE_TYPES_6_5.slice(0);\n break;\n case '6.0.0.7':\n case '6.0.0.6':\n case '6.0.0.5':\n case '6.0.0.4':\n case '6.0.0.3':\n case '6.0.0.2':\n case '6.0.0.1':\n case '6.0.0':\n ootbNodeTypes = OOTB_NODE_TYPES_6.slice(0);\n break;\n default:\n return true;\n }\n return (\n !ootbNodeTypes.includes(nodeType) &&\n !isPremiumNode(nodeType) &&\n !isCloudOnlyNode(nodeType)\n );\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;AAMA;;AAIA;;;;;;;;AAEA,IAAMA,cAAc,GAAG,CAAC,UAAD,EAAa,gBAAb,CAAvB;AAEA,IAAMC,aAAa,GAAG,CACpB,oBADoB,EAEpB,sBAFoB,EAGpB,kBAHoB,EAIpB,2BAJoB,EAKpB,kBALoB,CAAtB;AAQA,IAAMC,kBAAkB,GAAG,CAAC,kBAAD,EAAqB,mBAArB,CAA3B;AAEA,IAAMC,sBAAsB,GAAG,SAA/B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;SACeC,wB;;EA6Ef;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;;;gDA/FA,WACEC,UADF,EAEEC,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;MACA;;IACF,KAAK,OAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,OAAL;IACA,KAAK,OAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;MACEJ,aAAa,GAAGP,mBAAmB,CAACW,KAApB,CAA0B,CAA1B,CAAhB;MACA;;IACF,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,SAAL;IACA,KAAK,OAAL;MACEJ,aAAa,GAAGN,iBAAiB,CAACU,KAAlB,CAAwB,CAAxB,CAAhB;MACA;;IACF;MACE,OAAO,IAAP;EApCJ;;EAsCA,OACE,CAACJ,aAAa,CAACnD,QAAd,CAAuB4B,QAAvB,CAAD,IACA,CAACoB,aAAa,CAACpB,QAAD,CADd,IAEA,CAACqB,eAAe,CAACrB,QAAD,CAHlB;AAKD"}
@@ -61,7 +61,7 @@ function getRealmManagedUser() {
61
61
  var realmManagedUser = 'user';
62
62
 
63
63
  if (_SessionStorage.default.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY) {
64
- realmManagedUser = "".concat(_SessionStorage.default.session.getRealm(), "_user");
64
+ realmManagedUser = "".concat((0, _ApiUtils.getCurrentRealmName)(), "_user");
65
65
  }
66
66
 
67
67
  return realmManagedUser;
@@ -1 +1 @@
1
- {"version":3,"file":"OpsUtils.js","names":["escapeRegExp","str","replace","replaceAll","find","RegExp","applyNameCollisionPolicy","name","capturingRegex","found","match","length","parseInt","getRealmManagedUser","realmManagedUser","storage","session","getDeploymentType","global","CLOUD_DEPLOYMENT_TYPE_KEY","getRealm","isEqualJson","obj1","obj2","ignoreKeys","obj1Keys","Object","keys","filter","key","includes","obj2Keys","objKey","getRealmName","realm","_getRealmName"],"sources":["ops/utils/OpsUtils.ts"],"sourcesContent":["import storage from '../../storage/SessionStorage';\nimport * as global from '../../storage/StaticStorage';\nimport { getRealmName as _getRealmName } from '../../api/utils/ApiUtils';\n\n// TODO: do we really need this? if yes: document\nexport function escapeRegExp(str) {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n}\n\n// TODO: do we really need this? if yes: document\nexport function replaceAll(str, find, replace) {\n return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);\n}\n\n/**\n * Get new name when names collide\n * @param {String} name to apply policy to\n * @returns {String} new name according to policy\n */\nexport function applyNameCollisionPolicy(name) {\n const capturingRegex = /(.* - imported) \\(([0-9]+)\\)/;\n const found = name.match(capturingRegex);\n if (found && found.length > 0 && found.length === 3) {\n // already renamed one or more times\n // return the next number\n return `${found[1]} (${parseInt(found[2], 10) + 1})`;\n }\n // first time\n return `${name} - imported (1)`;\n}\n\n/**\n * Get the name of the managed user object for the current realm\n * @returns {String} the name of the managed user object for the current realm\n */\nexport function getRealmManagedUser() {\n let realmManagedUser = 'user';\n if (\n storage.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY\n ) {\n realmManagedUser = `${storage.session.getRealm()}_user`;\n }\n return realmManagedUser;\n}\n\n/**\n * Compare two json objects\n * @param {Object} obj1 object 1\n * @param {Object} obj2 object 2\n * @param {[String]} ignoreKeys array of keys to ignore in comparison\n * @returns {boolean} true if the two json objects have the same length and all the properties have the same value\n */\nexport function isEqualJson(obj1, obj2, ignoreKeys: string[] = []) {\n const obj1Keys = Object.keys(obj1).filter((key) => !ignoreKeys.includes(key));\n const obj2Keys = Object.keys(obj2).filter((key) => !ignoreKeys.includes(key));\n\n if (obj1Keys.length !== obj2Keys.length) {\n return false;\n }\n\n for (const objKey of obj1Keys) {\n if (obj1[objKey] !== obj2[objKey]) {\n if (\n typeof obj1[objKey] === 'object' &&\n typeof obj2[objKey] === 'object'\n ) {\n if (!isEqualJson(obj1[objKey], obj2[objKey], ignoreKeys)) {\n return false;\n }\n } else {\n return false;\n }\n }\n }\n\n return true;\n}\n\n/**\n * Get current realm name\n * @param {String} realm realm\n * @returns {String} name of the realm. /alpha -> alpha\n */\nexport function getRealmName(realm) {\n return _getRealmName(realm);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;AAEA;AACO,SAASA,YAAT,CAAsBC,GAAtB,EAA2B;EAChC,OAAOA,GAAG,CAACC,OAAJ,CAAY,qBAAZ,EAAmC,MAAnC,CAAP,CADgC,CACmB;AACpD,C,CAED;;;AACO,SAASC,UAAT,CAAoBF,GAApB,EAAyBG,IAAzB,EAA+BF,OAA/B,EAAwC;EAC7C,OAAOD,GAAG,CAACC,OAAJ,CAAY,IAAIG,MAAJ,CAAWL,YAAY,CAACI,IAAD,CAAvB,EAA+B,GAA/B,CAAZ,EAAiDF,OAAjD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASI,wBAAT,CAAkCC,IAAlC,EAAwC;EAC7C,IAAMC,cAAc,GAAG,8BAAvB;EACA,IAAMC,KAAK,GAAGF,IAAI,CAACG,KAAL,CAAWF,cAAX,CAAd;;EACA,IAAIC,KAAK,IAAIA,KAAK,CAACE,MAAN,GAAe,CAAxB,IAA6BF,KAAK,CAACE,MAAN,KAAiB,CAAlD,EAAqD;IACnD;IACA;IACA,iBAAUF,KAAK,CAAC,CAAD,CAAf,eAAuBG,QAAQ,CAACH,KAAK,CAAC,CAAD,CAAN,EAAW,EAAX,CAAR,GAAyB,CAAhD;EACD,CAP4C,CAQ7C;;;EACA,iBAAUF,IAAV;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASM,mBAAT,GAA+B;EACpC,IAAIC,gBAAgB,GAAG,MAAvB;;EACA,IACEC,uBAAA,CAAQC,OAAR,CAAgBC,iBAAhB,OAAwCC,MAAM,CAACC,yBADjD,EAEE;IACAL,gBAAgB,aAAMC,uBAAA,CAAQC,OAAR,CAAgBI,QAAhB,EAAN,UAAhB;EACD;;EACD,OAAON,gBAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,WAAT,CAAqBC,IAArB,EAA2BC,IAA3B,EAA4D;EAAA,IAA3BC,UAA2B,uEAAJ,EAAI;EACjE,IAAMC,QAAQ,GAAGC,MAAM,CAACC,IAAP,CAAYL,IAAZ,EAAkBM,MAAlB,CAA0BC,GAAD,IAAS,CAACL,UAAU,CAACM,QAAX,CAAoBD,GAApB,CAAnC,CAAjB;EACA,IAAME,QAAQ,GAAGL,MAAM,CAACC,IAAP,CAAYJ,IAAZ,EAAkBK,MAAlB,CAA0BC,GAAD,IAAS,CAACL,UAAU,CAACM,QAAX,CAAoBD,GAApB,CAAnC,CAAjB;;EAEA,IAAIJ,QAAQ,CAACd,MAAT,KAAoBoB,QAAQ,CAACpB,MAAjC,EAAyC;IACvC,OAAO,KAAP;EACD;;EAED,KAAK,IAAMqB,MAAX,IAAqBP,QAArB,EAA+B;IAC7B,IAAIH,IAAI,CAACU,MAAD,CAAJ,KAAiBT,IAAI,CAACS,MAAD,CAAzB,EAAmC;MACjC,IACE,OAAOV,IAAI,CAACU,MAAD,CAAX,KAAwB,QAAxB,IACA,OAAOT,IAAI,CAACS,MAAD,CAAX,KAAwB,QAF1B,EAGE;QACA,IAAI,CAACX,WAAW,CAACC,IAAI,CAACU,MAAD,CAAL,EAAeT,IAAI,CAACS,MAAD,CAAnB,EAA6BR,UAA7B,CAAhB,EAA0D;UACxD,OAAO,KAAP;QACD;MACF,CAPD,MAOO;QACL,OAAO,KAAP;MACD;IACF;EACF;;EAED,OAAO,IAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASS,YAAT,CAAsBC,KAAtB,EAA6B;EAClC,OAAO,IAAAC,sBAAA,EAAcD,KAAd,CAAP;AACD"}
1
+ {"version":3,"file":"OpsUtils.js","names":["escapeRegExp","str","replace","replaceAll","find","RegExp","applyNameCollisionPolicy","name","capturingRegex","found","match","length","parseInt","getRealmManagedUser","realmManagedUser","storage","session","getDeploymentType","global","CLOUD_DEPLOYMENT_TYPE_KEY","getCurrentRealmName","isEqualJson","obj1","obj2","ignoreKeys","obj1Keys","Object","keys","filter","key","includes","obj2Keys","objKey","getRealmName","realm","_getRealmName"],"sources":["ops/utils/OpsUtils.ts"],"sourcesContent":["import storage from '../../storage/SessionStorage';\nimport * as global from '../../storage/StaticStorage';\nimport {\n getCurrentRealmName,\n getRealmName as _getRealmName,\n} from '../../api/utils/ApiUtils';\n\n// TODO: do we really need this? if yes: document\nexport function escapeRegExp(str) {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n}\n\n// TODO: do we really need this? if yes: document\nexport function replaceAll(str, find, replace) {\n return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);\n}\n\n/**\n * Get new name when names collide\n * @param {String} name to apply policy to\n * @returns {String} new name according to policy\n */\nexport function applyNameCollisionPolicy(name) {\n const capturingRegex = /(.* - imported) \\(([0-9]+)\\)/;\n const found = name.match(capturingRegex);\n if (found && found.length > 0 && found.length === 3) {\n // already renamed one or more times\n // return the next number\n return `${found[1]} (${parseInt(found[2], 10) + 1})`;\n }\n // first time\n return `${name} - imported (1)`;\n}\n\n/**\n * Get the name of the managed user object for the current realm\n * @returns {String} the name of the managed user object for the current realm\n */\nexport function getRealmManagedUser() {\n let realmManagedUser = 'user';\n if (\n storage.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY\n ) {\n realmManagedUser = `${getCurrentRealmName()}_user`;\n }\n return realmManagedUser;\n}\n\n/**\n * Compare two json objects\n * @param {Object} obj1 object 1\n * @param {Object} obj2 object 2\n * @param {[String]} ignoreKeys array of keys to ignore in comparison\n * @returns {boolean} true if the two json objects have the same length and all the properties have the same value\n */\nexport function isEqualJson(obj1, obj2, ignoreKeys: string[] = []) {\n const obj1Keys = Object.keys(obj1).filter((key) => !ignoreKeys.includes(key));\n const obj2Keys = Object.keys(obj2).filter((key) => !ignoreKeys.includes(key));\n\n if (obj1Keys.length !== obj2Keys.length) {\n return false;\n }\n\n for (const objKey of obj1Keys) {\n if (obj1[objKey] !== obj2[objKey]) {\n if (\n typeof obj1[objKey] === 'object' &&\n typeof obj2[objKey] === 'object'\n ) {\n if (!isEqualJson(obj1[objKey], obj2[objKey], ignoreKeys)) {\n return false;\n }\n } else {\n return false;\n }\n }\n }\n\n return true;\n}\n\n/**\n * Get current realm name\n * @param {String} realm realm\n * @returns {String} name of the realm. /alpha -> alpha\n */\nexport function getRealmName(realm) {\n return _getRealmName(realm);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;AAKA;AACO,SAASA,YAAT,CAAsBC,GAAtB,EAA2B;EAChC,OAAOA,GAAG,CAACC,OAAJ,CAAY,qBAAZ,EAAmC,MAAnC,CAAP,CADgC,CACmB;AACpD,C,CAED;;;AACO,SAASC,UAAT,CAAoBF,GAApB,EAAyBG,IAAzB,EAA+BF,OAA/B,EAAwC;EAC7C,OAAOD,GAAG,CAACC,OAAJ,CAAY,IAAIG,MAAJ,CAAWL,YAAY,CAACI,IAAD,CAAvB,EAA+B,GAA/B,CAAZ,EAAiDF,OAAjD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASI,wBAAT,CAAkCC,IAAlC,EAAwC;EAC7C,IAAMC,cAAc,GAAG,8BAAvB;EACA,IAAMC,KAAK,GAAGF,IAAI,CAACG,KAAL,CAAWF,cAAX,CAAd;;EACA,IAAIC,KAAK,IAAIA,KAAK,CAACE,MAAN,GAAe,CAAxB,IAA6BF,KAAK,CAACE,MAAN,KAAiB,CAAlD,EAAqD;IACnD;IACA;IACA,iBAAUF,KAAK,CAAC,CAAD,CAAf,eAAuBG,QAAQ,CAACH,KAAK,CAAC,CAAD,CAAN,EAAW,EAAX,CAAR,GAAyB,CAAhD;EACD,CAP4C,CAQ7C;;;EACA,iBAAUF,IAAV;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASM,mBAAT,GAA+B;EACpC,IAAIC,gBAAgB,GAAG,MAAvB;;EACA,IACEC,uBAAA,CAAQC,OAAR,CAAgB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 {"version":3,"file":"OpsUtils.test.js","names":["describe","test","REALM","DEPLOYMENT_TYPE","CLOUD_DEPLOYMENT_TYPE_KEY","sessionStorage","session","setRealm","setDeploymentType","testString","getRealmManagedUser","expect","toBe","FORGEOPS_DEPLOYMENT_TYPE_KEY","CLASSIC_DEPLOYMENT_TYPE_KEY"],"sources":["ops/utils/OpsUtils.test.ts"],"sourcesContent":["import { getRealmManagedUser } from './OpsUtils';\nimport sessionStorage from '../../storage/SessionStorage';\nimport {\n CLOUD_DEPLOYMENT_TYPE_KEY,\n FORGEOPS_DEPLOYMENT_TYPE_KEY,\n CLASSIC_DEPLOYMENT_TYPE_KEY,\n} from '../../storage/StaticStorage';\n\ndescribe('OpsUtils', () => {\n test('getRealmManagedUser should prepend realm to managed user type in identity cloud', () => {\n // Arrange\n const REALM = 'alpha';\n const DEPLOYMENT_TYPE = CLOUD_DEPLOYMENT_TYPE_KEY;\n sessionStorage.session.setRealm(REALM);\n sessionStorage.session.setDeploymentType(DEPLOYMENT_TYPE);\n // Act\n const testString = getRealmManagedUser();\n // Assert\n expect(testString).toBe('alpha_user');\n });\n\n test('getCurrentRealmPath should prepend realm without leading slash to managed user type in identity cloud', () => {\n // Arrange\n const REALM = '/alpha';\n const DEPLOYMENT_TYPE = CLOUD_DEPLOYMENT_TYPE_KEY;\n sessionStorage.session.setRealm(REALM);\n sessionStorage.session.setDeploymentType(DEPLOYMENT_TYPE);\n // Act\n const testString = getRealmManagedUser();\n // Assert\n expect(testString).toBe('alpha_user');\n });\n\n test('getRealmManagedUser should not prepend realm to managed user type in forgeops deployments', () => {\n // Arrange\n const REALM = 'alpha';\n const DEPLOYMENT_TYPE = FORGEOPS_DEPLOYMENT_TYPE_KEY;\n sessionStorage.session.setRealm(REALM);\n sessionStorage.session.setDeploymentType(DEPLOYMENT_TYPE);\n // Act\n const testString = getRealmManagedUser();\n // Assert\n expect(testString).toBe('user');\n });\n\n test('getRealmManagedUser should not prepend realm to managed user type in classic deployments', () => {\n // Arrange\n const REALM = 'alpha';\n const DEPLOYMENT_TYPE = CLASSIC_DEPLOYMENT_TYPE_KEY;\n sessionStorage.session.setRealm(REALM);\n sessionStorage.session.setDeploymentType(DEPLOYMENT_TYPE);\n // Act\n const testString = getRealmManagedUser();\n // Assert\n expect(testString).toBe('user');\n });\n});\n"],"mappings":";;AAAA;;AACA;;AACA;;;;AAMAA,QAAQ,CAAC,UAAD,EAAa,MAAM;EACzBC,IAAI,CAAC,iFAAD,EAAoF,MAAM;IAC5F;IACA,IAAMC,KAAK,GAAG,OAAd;IACA,IAAMC,eAAe,GAAGC,wCAAxB;;IACAC,uBAAA,CAAeC,OAAf,CAAuBC,QAAvB,CAAgCL,KAAhC;;IACAG,uBAAA,CAAeC,OAAf,CAAuBE,iBAAvB,CAAyCL,eAAzC,EAL4F,CAM5F;;;IACA,IAAMM,UAAU,GAAG,IAAAC,6BAAA,GAAnB,CAP4F,CAQ5F;;IACAC,MAAM,CAACF,UAAD,CAAN,CAAmBG,IAAnB,CAAwB,YAAxB;EACD,CAVG,CAAJ;EAYAX,IAAI,CAAC,uGAAD,EAA0G,MAAM;IAClH;IACA,IAAMC,KAAK,GAAG,QAAd;IACA,IAAMC,eAAe,GAAGC,wCAAxB;;IACAC,uBAAA,CAAeC,OAAf,CAAuBC,QAAvB,CAAgCL,KAAhC;;IACAG,uBAAA,CAAeC,OAAf,CAAuBE,iBAAvB,CAAyCL,eAAzC,EALkH,CAMlH;;;IACA,IAAMM,UAAU,GAAG,IAAAC,6BAAA,GAAnB,CAPkH,CAQlH;;IACAC,MAAM,CAACF,UAAD,CAAN,CAAmBG,IAAnB,CAAwB,YAAxB;EACD,CAVG,CAAJ;EAYAX,IAAI,CAAC,2FAAD,EAA8F,MAAM;IACtG;IACA,IAAMC,KAAK,GAAG,OAAd;IACA,IAAMC,eAAe,GAAGU,2CAAxB;;IACAR,uBAAA,CAAeC,OAAf,CAAuBC,QAAvB,CAAgCL,KAAhC;;IACAG,uBAAA,CAAeC,OAAf,CAAuBE,iBAAvB,CAAyCL,eAAzC,EALsG,CAMtG;;;IACA,IAAMM,UAAU,GAAG,IAAAC,6BAAA,GAAnB,CAPsG,CAQtG;;IACAC,MAAM,CAACF,UAAD,CAAN,CAAmBG,IAAnB,CAAwB,MAAxB;EACD,CAVG,CAAJ;EAYAX,IAAI,CAAC,0FAAD,EAA6F,MAAM;IACrG;IACA,IAAMC,KAAK,GAAG,OAAd;IACA,IAAMC,eAAe,GAAGW,0CAAxB;;IACAT,uBAAA,CAAeC,OAAf,CAAuBC,QAAvB,CAAgCL,KAAhC;;IACAG,uBAAA,CAAeC,OAAf,CAAuBE,iBAAvB,CAAyCL,eAAzC,EALqG,CAMrG;;;IACA,IAAMM,UAAU,GAAG,IAAAC,6BAAA,GAAnB,CAPqG,CAQrG;;IACAC,MAAM,CAACF,UAAD,CAAN,CAAmBG,IAAnB,CAAwB,MAAxB;EACD,CAVG,CAAJ;AAWD,CAhDO,CAAR"}
@@ -1,6 +1,4 @@
1
- import util from 'util';
2
1
  import storage from '../../storage/SessionStorage';
3
- const realmPathTemplate = '/realms/%s';
4
2
  /**
5
3
  * Get current realm path
6
4
  * @returns {String} a CREST-compliant realm path, e.g. /realms/root/realms/alpha
@@ -9,16 +7,12 @@ const realmPathTemplate = '/realms/%s';
9
7
  export function getCurrentRealmPath() {
10
8
  let realm = storage.session.getRealm();
11
9
 
12
- if (realm.startsWith('/') && realm.length > 1) {
10
+ if (realm.startsWith('/')) {
13
11
  realm = realm.substring(1);
14
12
  }
15
13
 
16
- let realmPath = util.format(realmPathTemplate, 'root');
17
-
18
- if (realm !== '/') {
19
- realmPath += util.format(realmPathTemplate, realm);
20
- }
21
-
14
+ const elements = ['root'].concat(realm.split('/').filter(element => element !== ''));
15
+ const realmPath = `/realms/${elements.join('/realms/')}`;
22
16
  return realmPath;
23
17
  }
24
18
  /**
@@ -33,23 +33,23 @@ test('getCurrentRealmPath "/" should resolve to root', () => {
33
33
 
34
34
  expect(testString).toBe('/realms/root');
35
35
  });
36
- test('getCurrentRealmPath should not handle multiple leading slash', () => {
36
+ test('getCurrentRealmPath should handle multiple leading slashes', () => {
37
37
  // Arrange
38
38
  const REALM_PATH = '//alpha';
39
39
  sessionStorage.session.setItem('realm', REALM_PATH); // Act
40
40
 
41
41
  const testString = getCurrentRealmPath(); // Assert
42
42
 
43
- expect(testString).toBe('/realms/root/realms//alpha');
43
+ expect(testString).toBe('/realms/root/realms/alpha');
44
44
  });
45
- test('getCurrentRealmPath should not handle nested depth realms', () => {
45
+ test('getCurrentRealmPath should handle nested realms', () => {
46
46
  // Arrange
47
- const REALM_PATH = '/alpha/erm';
47
+ const REALM_PATH = '/parent/child';
48
48
  sessionStorage.session.setItem('realm', REALM_PATH); // Act
49
49
 
50
50
  const testString = getCurrentRealmPath(); // Assert
51
51
 
52
- expect(testString).toBe('/realms/root/realms/alpha/erm');
52
+ expect(testString).toBe('/realms/root/realms/parent/realms/child');
53
53
  });
54
54
  test('getTenantURL should parse the https protocol and the hostname', () => {
55
55
  // Arrange
@@ -72,8 +72,13 @@ export async function exportAllRawConfigEntities(directory) {
72
72
  const entityPromises = [];
73
73
  configEntities['configurations'].forEach(x => {
74
74
  entityPromises.push(getConfigEntity(x._id).catch(getConfigEntityError => {
75
- if (!(getConfigEntityError.response.status === 403 && getConfigEntityError.response.data.message === 'This operation is not available in ForgeRock Identity Cloud.')) {
76
- printMessage(getConfigEntityError, 'error');
75
+ var _getConfigEntityError, _getConfigEntityError2, _getConfigEntityError3, _getConfigEntityError4, _getConfigEntityError5, _getConfigEntityError6;
76
+
77
+ if (!(((_getConfigEntityError = getConfigEntityError.response) === null || _getConfigEntityError === void 0 ? void 0 : _getConfigEntityError.status) === 403 && ((_getConfigEntityError2 = getConfigEntityError.response) === null || _getConfigEntityError2 === void 0 ? void 0 : (_getConfigEntityError3 = _getConfigEntityError2.data) === null || _getConfigEntityError3 === void 0 ? void 0 : _getConfigEntityError3.message) === 'This operation is not available in ForgeRock Identity Cloud.') && // https://bugster.forgerock.org/jira/browse/OPENIDM-18270
78
+ !(((_getConfigEntityError4 = getConfigEntityError.response) === null || _getConfigEntityError4 === void 0 ? void 0 : _getConfigEntityError4.status) === 404 && ((_getConfigEntityError5 = getConfigEntityError.response) === null || _getConfigEntityError5 === void 0 ? void 0 : (_getConfigEntityError6 = _getConfigEntityError5.data) === null || _getConfigEntityError6 === void 0 ? void 0 : _getConfigEntityError6.message) === 'No configuration exists for id org.apache.felix.fileinstall/openidm')) {
79
+ var _getConfigEntityError7;
80
+
81
+ printMessage((_getConfigEntityError7 = getConfigEntityError.response) === null || _getConfigEntityError7 === void 0 ? void 0 : _getConfigEntityError7.data, 'error');
77
82
  printMessage(`Error getting config entity: ${getConfigEntityError}`, 'error');
78
83
  }
79
84
  }));
@@ -90,7 +95,7 @@ export async function exportAllRawConfigEntities(directory) {
90
95
  });
91
96
  }
92
97
  });
93
- stopProgressIndicator(null, 'success');
98
+ stopProgressIndicator('Exported config objects.', 'success');
94
99
  });
95
100
  }
96
101
  }