@platform-mesh/portal-server-lib 0.6.33 → 0.6.35
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/dist/portal-options/utils/account-hierarchy-resolver.js +7 -8
- package/dist/portal-options/utils/account-hierarchy-resolver.js.map +1 -1
- package/dist/portal-options/utils/replace-string-deep.d.ts +1 -0
- package/dist/portal-options/utils/replace-string-deep.js +28 -0
- package/dist/portal-options/utils/replace-string-deep.js.map +1 -0
- package/package.json +2 -2
- package/src/portal-options/service-providers/content-configuration-service-providers.service.spec.ts +3 -3
- package/src/portal-options/service-providers/kubernetes-service-providers.service.spec.ts +3 -3
- package/src/portal-options/utils/account-hierarchy-resolver.spec.ts +140 -17
- package/src/portal-options/utils/account-hierarchy-resolver.ts +13 -8
- package/src/portal-options/utils/replace-string-deep.spec.ts +41 -0
- package/src/portal-options/utils/replace-string-deep.ts +40 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { replaceStringDeep } from './replace-string-deep.js';
|
|
1
2
|
const ACCOUNT_ENTITY_TYPE = 'core_platform-mesh_io_account';
|
|
2
3
|
export const updateEntityTypeFromAccountPath = (contentConfiguration, accountPath) => {
|
|
3
4
|
contentConfiguration.luigiConfigFragment.data.nodes.forEach((node) => {
|
|
@@ -6,7 +7,8 @@ export const updateEntityTypeFromAccountPath = (contentConfiguration, accountPat
|
|
|
6
7
|
}
|
|
7
8
|
const accountPathParts = accountPath
|
|
8
9
|
.split(':')
|
|
9
|
-
.
|
|
10
|
+
.filter(Boolean)
|
|
11
|
+
.map(() => ACCOUNT_ENTITY_TYPE)
|
|
10
12
|
.join('.');
|
|
11
13
|
node.entityType = node.entityType.replace(ACCOUNT_ENTITY_TYPE, accountPathParts);
|
|
12
14
|
});
|
|
@@ -14,14 +16,11 @@ export const updateEntityTypeFromAccountPath = (contentConfiguration, accountPat
|
|
|
14
16
|
};
|
|
15
17
|
export const updateAccountNodeChildren = (contentConfiguration, accountPath) => {
|
|
16
18
|
const accountChildrenNode = contentConfiguration.luigiConfigFragment.data.nodes[0]?.children?.[0];
|
|
17
|
-
const nextHierarchyLevel = accountPath.split(':').length + 1;
|
|
18
19
|
if (accountChildrenNode) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
accountChildrenNode.context.resourceId = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
|
|
24
|
-
accountChildrenNode.pathSegment = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
|
|
20
|
+
const nextHierarchyLevel = accountPath.split(':').filter(Boolean).length + 1;
|
|
21
|
+
const previousPathSegment = accountChildrenNode.pathSegment;
|
|
22
|
+
const nextPathSegment = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
|
|
23
|
+
replaceStringDeep(accountChildrenNode, previousPathSegment, nextPathSegment);
|
|
25
24
|
}
|
|
26
25
|
return contentConfiguration;
|
|
27
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-hierarchy-resolver.js","sourceRoot":"","sources":["../../../src/portal-options/utils/account-hierarchy-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account-hierarchy-resolver.js","sourceRoot":"","sources":["../../../src/portal-options/utils/account-hierarchy-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAE5D,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,oBAA0C,EAC1C,WAAmB,EACG,EAAE;IACxB,oBAAoB,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACnD,OAAO;QACT,CAAC;QAED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EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,+BAA+B,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const replaceStringDeep: (target: unknown, previousValue: string, nextValue: string) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const processValue = (currentValue, valueToReplace, newValue, setValue) => {
|
|
2
|
+
if (typeof currentValue === 'string' && currentValue === valueToReplace) {
|
|
3
|
+
setValue(newValue);
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (currentValue && typeof currentValue === 'object') {
|
|
7
|
+
replaceStringDeep(currentValue, valueToReplace, newValue);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export const replaceStringDeep = (target, previousValue, nextValue) => {
|
|
11
|
+
if (target === null || typeof target !== 'object') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(target)) {
|
|
15
|
+
target.forEach((item, index) => {
|
|
16
|
+
processValue(item, previousValue, nextValue, (updatedValue) => {
|
|
17
|
+
target[index] = updatedValue;
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
Object.entries(target).forEach(([key, value]) => {
|
|
23
|
+
processValue(value, previousValue, nextValue, (updatedValue) => {
|
|
24
|
+
target[key] = updatedValue;
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=replace-string-deep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-string-deep.js","sourceRoot":"","sources":["../../../src/portal-options/utils/replace-string-deep.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CACnB,YAAqB,EACrB,cAAsB,EACtB,QAAgB,EAChB,QAAiC,EAC3B,EAAE;IACR,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY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
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@nestjs/testing": "11.1.14",
|
|
58
58
|
"@openmfp/config-prettier": "0.9.2",
|
|
59
59
|
"@types/jest": "30.0.0",
|
|
60
|
-
"@types/node": "24.10.
|
|
60
|
+
"@types/node": "24.10.15",
|
|
61
61
|
"@types/supertest": "7.2.0",
|
|
62
62
|
"eslint": "10.0.2",
|
|
63
63
|
"eslint-config-prettier": "10.1.8",
|
package/src/portal-options/service-providers/content-configuration-service-providers.service.spec.ts
CHANGED
|
@@ -208,7 +208,7 @@ describe('ContentConfigurationServiceProvidersService', () => {
|
|
|
208
208
|
expect(
|
|
209
209
|
result.rawServiceProviders[0].contentConfiguration[0].luigiConfigFragment
|
|
210
210
|
.data.nodes[0].entityType,
|
|
211
|
-
).toBe('core_platform-mesh_io_account
|
|
211
|
+
).toBe('core_platform-mesh_io_account');
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
it('applies processContentConfigurationForAccountHierarchy with multi-level accountPath', async () => {
|
|
@@ -253,7 +253,7 @@ describe('ContentConfigurationServiceProvidersService', () => {
|
|
|
253
253
|
result.rawServiceProviders[0].contentConfiguration[0].luigiConfigFragment
|
|
254
254
|
.data.nodes[0].entityType,
|
|
255
255
|
).toBe(
|
|
256
|
-
'core_platform-mesh_io_account
|
|
256
|
+
'core_platform-mesh_io_account.core_platform-mesh_io_account.core_platform-mesh_io_account',
|
|
257
257
|
);
|
|
258
258
|
});
|
|
259
259
|
|
|
@@ -308,7 +308,7 @@ describe('ContentConfigurationServiceProvidersService', () => {
|
|
|
308
308
|
result.rawServiceProviders[0].contentConfiguration[0].luigiConfigFragment
|
|
309
309
|
.data.nodes[0].children[0];
|
|
310
310
|
|
|
311
|
-
expect(childNode.defineEntity.id).toBe('
|
|
311
|
+
expect(childNode.defineEntity.id).toBe('old-id');
|
|
312
312
|
expect(childNode.pathSegment).toBe(':core_platform-mesh_io_accountId:2');
|
|
313
313
|
});
|
|
314
314
|
|
|
@@ -453,7 +453,7 @@ describe('KubernetesServiceProvidersService', () => {
|
|
|
453
453
|
expect(
|
|
454
454
|
res.rawServiceProviders[0].contentConfiguration[0].luigiConfigFragment
|
|
455
455
|
.data.nodes[0].entityType,
|
|
456
|
-
).toBe('core_platform-mesh_io_account
|
|
456
|
+
).toBe('core_platform-mesh_io_account');
|
|
457
457
|
});
|
|
458
458
|
|
|
459
459
|
it('should apply processContentConfigurationForAccountHierarchy with multi-level accountPath', async () => {
|
|
@@ -488,7 +488,7 @@ describe('KubernetesServiceProvidersService', () => {
|
|
|
488
488
|
res.rawServiceProviders[0].contentConfiguration[0].luigiConfigFragment
|
|
489
489
|
.data.nodes[0].entityType,
|
|
490
490
|
).toBe(
|
|
491
|
-
'core_platform-mesh_io_account
|
|
491
|
+
'core_platform-mesh_io_account.core_platform-mesh_io_account.core_platform-mesh_io_account',
|
|
492
492
|
);
|
|
493
493
|
});
|
|
494
494
|
|
|
@@ -535,7 +535,7 @@ describe('KubernetesServiceProvidersService', () => {
|
|
|
535
535
|
res.rawServiceProviders[0].contentConfiguration[0].luigiConfigFragment
|
|
536
536
|
.data.nodes[0].children[0];
|
|
537
537
|
|
|
538
|
-
expect(childNode.defineEntity.id).toBe('
|
|
538
|
+
expect(childNode.defineEntity.id).toBe('old-id');
|
|
539
539
|
expect(childNode.pathSegment).toBe(':core_platform-mesh_io_accountId:2');
|
|
540
540
|
});
|
|
541
541
|
|
|
@@ -31,7 +31,7 @@ describe('updateEntityTypeFromAccountPath', () => {
|
|
|
31
31
|
const result = updateEntityTypeFromAccountPath(config, 'acc1');
|
|
32
32
|
|
|
33
33
|
expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
|
|
34
|
-
'core_platform-mesh_io_account
|
|
34
|
+
'core_platform-mesh_io_account',
|
|
35
35
|
);
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -47,7 +47,7 @@ describe('updateEntityTypeFromAccountPath', () => {
|
|
|
47
47
|
const result = updateEntityTypeFromAccountPath(config, 'acc1:acc2:acc3');
|
|
48
48
|
|
|
49
49
|
expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
|
|
50
|
-
'core_platform-mesh_io_account
|
|
50
|
+
'core_platform-mesh_io_account.core_platform-mesh_io_account.core_platform-mesh_io_account',
|
|
51
51
|
);
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -66,10 +66,10 @@ describe('updateEntityTypeFromAccountPath', () => {
|
|
|
66
66
|
const result = updateEntityTypeFromAccountPath(config, 'acc1:acc2');
|
|
67
67
|
|
|
68
68
|
expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
|
|
69
|
-
'core_platform-mesh_io_account
|
|
69
|
+
'core_platform-mesh_io_account.core_platform-mesh_io_account',
|
|
70
70
|
);
|
|
71
71
|
expect(result.luigiConfigFragment.data.nodes[1].entityType).toBe(
|
|
72
|
-
'core_platform-mesh_io_account
|
|
72
|
+
'core_platform-mesh_io_account.core_platform-mesh_io_account',
|
|
73
73
|
);
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -128,17 +128,143 @@ describe('updateAccountNodeChildren', () => {
|
|
|
128
128
|
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
129
129
|
.children?.[0] as any;
|
|
130
130
|
|
|
131
|
-
expect(childNode.defineEntity.id).toBe('
|
|
132
|
-
expect(childNode.
|
|
131
|
+
expect(childNode.defineEntity.id).toBe('old-id');
|
|
132
|
+
expect(childNode.pathSegment).toBe(':core_platform-mesh_io_accountId:2');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should replace all additional fields equal to previous pathSegment', () => {
|
|
136
|
+
const oldPathSegment = ':core_platform-mesh_io_accountId';
|
|
137
|
+
const config = createMockContentConfiguration({
|
|
138
|
+
luigiConfigFragment: {
|
|
139
|
+
data: {
|
|
140
|
+
nodes: [
|
|
141
|
+
{
|
|
142
|
+
children: [
|
|
143
|
+
{
|
|
144
|
+
defineEntity: {
|
|
145
|
+
id: 'old-id',
|
|
146
|
+
contextKey: oldPathSegment,
|
|
147
|
+
additionalContextKeys: [oldPathSegment],
|
|
148
|
+
} as any,
|
|
149
|
+
context: {
|
|
150
|
+
accountId: oldPathSegment,
|
|
151
|
+
customPath: oldPathSegment,
|
|
152
|
+
nested: [{ deepPath: oldPathSegment }],
|
|
153
|
+
},
|
|
154
|
+
pathSegment: oldPathSegment,
|
|
155
|
+
navHeader: {
|
|
156
|
+
label: oldPathSegment,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const result = updateAccountNodeChildren(config, 'acc1');
|
|
167
|
+
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
168
|
+
.children?.[0] as any;
|
|
169
|
+
|
|
170
|
+
expect(childNode.pathSegment).toBe(':core_platform-mesh_io_accountId:2');
|
|
171
|
+
expect(childNode.defineEntity.contextKey).toBe(
|
|
133
172
|
':core_platform-mesh_io_accountId:2',
|
|
134
173
|
);
|
|
135
|
-
expect(childNode.
|
|
174
|
+
expect(childNode.defineEntity.additionalContextKeys[0]).toBe(
|
|
136
175
|
':core_platform-mesh_io_accountId:2',
|
|
137
176
|
);
|
|
138
|
-
expect(childNode.context.
|
|
177
|
+
expect(childNode.context.customPath).toBe(':core_platform-mesh_io_accountId:2');
|
|
178
|
+
expect(childNode.context.nested[0].deepPath).toBe(
|
|
139
179
|
':core_platform-mesh_io_accountId:2',
|
|
140
180
|
);
|
|
141
|
-
expect(childNode.
|
|
181
|
+
expect(childNode.navHeader.label).toBe(':core_platform-mesh_io_accountId:2');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should keep defineEntity.id controlled only by explicit assignment', () => {
|
|
185
|
+
const oldPathSegment = ':core_platform-mesh_io_accountId';
|
|
186
|
+
const config = createMockContentConfiguration({
|
|
187
|
+
luigiConfigFragment: {
|
|
188
|
+
data: {
|
|
189
|
+
nodes: [
|
|
190
|
+
{
|
|
191
|
+
children: [
|
|
192
|
+
{
|
|
193
|
+
defineEntity: {
|
|
194
|
+
id: oldPathSegment,
|
|
195
|
+
},
|
|
196
|
+
context: {},
|
|
197
|
+
pathSegment: oldPathSegment,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const result = updateAccountNodeChildren(config, 'acc1');
|
|
207
|
+
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
208
|
+
.children?.[0] as any;
|
|
209
|
+
|
|
210
|
+
expect(childNode.defineEntity.id).toBe(':core_platform-mesh_io_accountId:2');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should not replace strings that only partially match previous pathSegment', () => {
|
|
214
|
+
const oldPathSegment = ':core_platform-mesh_io_accountId';
|
|
215
|
+
const config = createMockContentConfiguration({
|
|
216
|
+
luigiConfigFragment: {
|
|
217
|
+
data: {
|
|
218
|
+
nodes: [
|
|
219
|
+
{
|
|
220
|
+
children: [
|
|
221
|
+
{
|
|
222
|
+
defineEntity: { id: 'old-id' },
|
|
223
|
+
context: {
|
|
224
|
+
exact: oldPathSegment,
|
|
225
|
+
partial: `${oldPathSegment}:suffix`,
|
|
226
|
+
},
|
|
227
|
+
pathSegment: oldPathSegment,
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const result = updateAccountNodeChildren(config, 'acc1');
|
|
237
|
+
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
238
|
+
.children?.[0] as any;
|
|
239
|
+
|
|
240
|
+
expect(childNode.context.exact).toBe(':core_platform-mesh_io_accountId:2');
|
|
241
|
+
expect(childNode.context.partial).toBe(':core_platform-mesh_io_accountId:suffix');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should not set pathSegment when previous pathSegment is missing', () => {
|
|
245
|
+
const config = createMockContentConfiguration({
|
|
246
|
+
luigiConfigFragment: {
|
|
247
|
+
data: {
|
|
248
|
+
nodes: [
|
|
249
|
+
{
|
|
250
|
+
children: [
|
|
251
|
+
{
|
|
252
|
+
defineEntity: { id: 'old-id' },
|
|
253
|
+
context: {},
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const result = updateAccountNodeChildren(config, 'acc1');
|
|
263
|
+
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
264
|
+
.children?.[0] as any;
|
|
265
|
+
|
|
266
|
+
expect(childNode.pathSegment).toBeUndefined();
|
|
267
|
+
expect(childNode.defineEntity.id).toBe('old-id');
|
|
142
268
|
});
|
|
143
269
|
|
|
144
270
|
it('should update children node for multi-level account path', () => {
|
|
@@ -164,10 +290,7 @@ describe('updateAccountNodeChildren', () => {
|
|
|
164
290
|
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
165
291
|
.children?.[0] as any;
|
|
166
292
|
|
|
167
|
-
expect(childNode.defineEntity.id).toBe('
|
|
168
|
-
expect(childNode.context.accountId).toBe(
|
|
169
|
-
':core_platform-mesh_io_accountId:4',
|
|
170
|
-
);
|
|
293
|
+
expect(childNode.defineEntity.id).toBe('old-id');
|
|
171
294
|
expect(childNode.pathSegment).toBe(':core_platform-mesh_io_accountId:4');
|
|
172
295
|
});
|
|
173
296
|
|
|
@@ -266,9 +389,9 @@ describe('processContentConfigurationForAccountHierarchy', () => {
|
|
|
266
389
|
const childNode = result.luigiConfigFragment.data.nodes[0]
|
|
267
390
|
.children?.[0] as any;
|
|
268
391
|
|
|
269
|
-
expect(childNode.defineEntity.id).toBe('
|
|
392
|
+
expect(childNode.defineEntity.id).toBe('old-id');
|
|
270
393
|
expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
|
|
271
|
-
'core_platform-mesh_io_account
|
|
394
|
+
'core_platform-mesh_io_account',
|
|
272
395
|
);
|
|
273
396
|
});
|
|
274
397
|
|
|
@@ -301,7 +424,7 @@ describe('processContentConfigurationForAccountHierarchy', () => {
|
|
|
301
424
|
|
|
302
425
|
expect(childNode.defineEntity.id).toBe('old-id');
|
|
303
426
|
expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
|
|
304
|
-
'core_platform-mesh_io_account
|
|
427
|
+
'core_platform-mesh_io_account',
|
|
305
428
|
);
|
|
306
429
|
});
|
|
307
430
|
|
|
@@ -320,7 +443,7 @@ describe('processContentConfigurationForAccountHierarchy', () => {
|
|
|
320
443
|
});
|
|
321
444
|
|
|
322
445
|
expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
|
|
323
|
-
'core_platform-mesh_io_account
|
|
446
|
+
'core_platform-mesh_io_account.core_platform-mesh_io_account',
|
|
324
447
|
);
|
|
325
448
|
});
|
|
326
449
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { replaceStringDeep } from './replace-string-deep.js';
|
|
1
2
|
import { ContentConfiguration } from '@openmfp/portal-server-lib';
|
|
2
3
|
|
|
3
4
|
const ACCOUNT_ENTITY_TYPE = 'core_platform-mesh_io_account';
|
|
@@ -13,7 +14,8 @@ export const updateEntityTypeFromAccountPath = (
|
|
|
13
14
|
|
|
14
15
|
const accountPathParts = accountPath
|
|
15
16
|
.split(':')
|
|
16
|
-
.
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.map(() => ACCOUNT_ENTITY_TYPE)
|
|
17
19
|
.join('.');
|
|
18
20
|
|
|
19
21
|
node.entityType = node.entityType.replace(
|
|
@@ -31,15 +33,18 @@ export const updateAccountNodeChildren = (
|
|
|
31
33
|
): ContentConfiguration => {
|
|
32
34
|
const accountChildrenNode =
|
|
33
35
|
contentConfiguration.luigiConfigFragment.data.nodes[0]?.children?.[0];
|
|
34
|
-
const nextHierarchyLevel = accountPath.split(':').length + 1;
|
|
35
36
|
|
|
36
37
|
if (accountChildrenNode) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
accountChildrenNode.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const nextHierarchyLevel =
|
|
39
|
+
accountPath.split(':').filter(Boolean).length + 1;
|
|
40
|
+
const previousPathSegment = accountChildrenNode.pathSegment;
|
|
41
|
+
const nextPathSegment = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
|
|
42
|
+
|
|
43
|
+
replaceStringDeep(
|
|
44
|
+
accountChildrenNode,
|
|
45
|
+
previousPathSegment,
|
|
46
|
+
nextPathSegment,
|
|
47
|
+
);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
return contentConfiguration;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { replaceStringDeep } from './replace-string-deep.js';
|
|
2
|
+
|
|
3
|
+
describe('replaceStringDeep', () => {
|
|
4
|
+
it('replaces matching strings in nested objects and arrays', () => {
|
|
5
|
+
const target = {
|
|
6
|
+
direct: ':accountId',
|
|
7
|
+
nested: {
|
|
8
|
+
list: [':accountId', { deep: ':accountId' }],
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
replaceStringDeep(target, ':accountId', ':accountId:2');
|
|
13
|
+
|
|
14
|
+
expect(target).toEqual({
|
|
15
|
+
direct: ':accountId:2',
|
|
16
|
+
nested: {
|
|
17
|
+
list: [':accountId:2', { deep: ':accountId:2' }],
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('does not replace partial string matches', () => {
|
|
23
|
+
const target = {
|
|
24
|
+
exact: ':accountId',
|
|
25
|
+
partial: ':accountId:suffix',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
replaceStringDeep(target, ':accountId', ':accountId:2');
|
|
29
|
+
|
|
30
|
+
expect(target.exact).toBe(':accountId:2');
|
|
31
|
+
expect(target.partial).toBe(':accountId:suffix');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('supports root arrays', () => {
|
|
35
|
+
const target = [':accountId', { value: ':accountId' }, ['other']];
|
|
36
|
+
|
|
37
|
+
replaceStringDeep(target, ':accountId', ':accountId:2');
|
|
38
|
+
|
|
39
|
+
expect(target).toEqual([':accountId:2', { value: ':accountId:2' }, ['other']]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const processValue = (
|
|
2
|
+
currentValue: unknown,
|
|
3
|
+
valueToReplace: string,
|
|
4
|
+
newValue: string,
|
|
5
|
+
setValue: (value: string) => void,
|
|
6
|
+
): void => {
|
|
7
|
+
if (typeof currentValue === 'string' && currentValue === valueToReplace) {
|
|
8
|
+
setValue(newValue);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (currentValue && typeof currentValue === 'object') {
|
|
13
|
+
replaceStringDeep(currentValue, valueToReplace, newValue);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const replaceStringDeep = (
|
|
18
|
+
target: unknown,
|
|
19
|
+
previousValue: string,
|
|
20
|
+
nextValue: string,
|
|
21
|
+
): void => {
|
|
22
|
+
if (target === null || typeof target !== 'object') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (Array.isArray(target)) {
|
|
27
|
+
target.forEach((item, index) => {
|
|
28
|
+
processValue(item, previousValue, nextValue, (updatedValue) => {
|
|
29
|
+
target[index] = updatedValue;
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Object.entries(target).forEach(([key, value]) => {
|
|
36
|
+
processValue(value, previousValue, nextValue, (updatedValue) => {
|
|
37
|
+
target[key] = updatedValue;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
};
|