@platform-mesh/portal-server-lib 0.6.32 → 0.6.34

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/README.md CHANGED
@@ -31,11 +31,4 @@ Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file in this repository f
31
31
 
32
32
  ## Code of Conduct
33
33
 
34
- Please refer to the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file in this repository for information on the expected Code of Conduct for contributing to platform-mesh.
35
-
36
- ## Licensing
37
-
38
- Copyright 2025 SAP SE or an SAP affiliate company and platform-mesh contributors. Please see our [LICENSES](LICENSES)
39
- for copyright and license information. Detailed information including third-party components and their licensing/copyright information
40
- is available [via the REUSE tool](https://api.reuse.software/info/github.com/platform-mesh/portal-server-lib).
41
-
34
+ Please refer to our [Code of Conduct](https://github.com/platform-mesh/.github/blob/main/CODE_OF_CONDUCT.md) for information on the expected conduct for contributing to Platform Mesh.
@@ -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
- .map((_, i) => `${ACCOUNT_ENTITY_TYPE}:${i + 1}`)
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
- accountChildrenNode.defineEntity.id = `${ACCOUNT_ENTITY_TYPE}:${nextHierarchyLevel}`;
20
- accountChildrenNode.context.accountId = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
21
- accountChildrenNode.context[`${ACCOUNT_ENTITY_TYPE}Id`] =
22
- `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
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":"AAEA,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,MAAM,gBAAgB,GAAG,WAAW;aACjC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,mBAAmB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;aAChD,IAAI,CAAC,GAAG,CAAC,CAAC;QAEb,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CACvC,mBAAmB,EACnB,gBAAgB,CACjB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,oBAA0C,EAC1C,WAAmB,EACG,EAAE;IACxB,MAAM,mBAAmB,GACvB,oBAAoB,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IACxE,MAAM,kBAAkB,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAE7D,IAAI,mBAAmB,EAAE,CAAC;QACxB,mBAAmB,CAAC,YAAY,CAAC,EAAE,GAAG,GAAG,mBAAmB,IAAI,kBAAkB,EAAE,CAAC;QACrF,mBAAmB,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,mBAAmB,MAAM,kBAAkB,EAAE,CAAC;QAC1F,mBAAmB,CAAC,OAAO,CAAC,GAAG,mBAAmB,IAAI,CAAC;YACrD,IAAI,mBAAmB,MAAM,kBAAkB,EAAE,CAAC;QACpD,mBAAmB,CAAC,OAAO,CAAC,UAAU,GAAG,IAAI,mBAAmB,MAAM,kBAAkB,EAAE,CAAC;QAC3F,mBAAmB,CAAC,WAAW,GAAG,IAAI,mBAAmB,MAAM,kBAAkB,EAAE,CAAC;IACtF,CAAC;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,8CAA8C,GAAG,CAC5D,oBAA0C,EAC1C,OAA4B,EACN,EAAE;IACxB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACxE,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,oBAAoB,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7C,yBAAyB,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,+BAA+B,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC,CAAC"}
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,MAAM,gBAAgB,GAAG,WAAW;aACjC,KAAK,CAAC,GAAG,CAAC;aACV,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC;aAC9B,IAAI,CAAC,GAAG,CAAC,CAAC;QAEb,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CACvC,mBAAmB,EACnB,gBAAgB,CACjB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,oBAA0C,EAC1C,WAAmB,EACG,EAAE;IACxB,MAAM,mBAAmB,GACvB,oBAAoB,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IAExE,IAAI,mBAAmB,EAAE,CAAC;QACxB,MAAM,kBAAkB,GACtB,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QACpD,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,WAAW,CAAC;QAC5D,MAAM,eAAe,GAAG,IAAI,mBAAmB,MAAM,kBAAkB,EAAE,CAAC;QAE1E,iBAAiB,CACf,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,CAChB,CAAC;IACJ,CAAC;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,8CAA8C,GAAG,CAC5D,oBAA0C,EAC1C,OAA4B,EACN,EAAE;IACxB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACxE,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,oBAAoB,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7C,yBAAyB,CAAC,oBAAoB,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,KAAK,cAAc,EAAE,CAAC;QACxE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnB,OAAO;IACT,CAAC;IAED,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrD,iBAAiB,CAAC,YAAY,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAe,EACf,aAAqB,EACrB,SAAiB,EACX,EAAE;IACR,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO;IACT,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC7B,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,YAAY,EAAE,EAAE;gBAC5D,MAAM,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC;YAC/B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC9C,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,YAAY,EAAE,EAAE;YAC7D,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platform-mesh/portal-server-lib",
3
- "version": "0.6.32",
3
+ "version": "0.6.34",
4
4
  "author": "Platform Mesh",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -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:1');
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:1.core_platform-mesh_io_account:2.core_platform-mesh_io_account:3',
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('core_platform-mesh_io_account:2');
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:1');
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:1.core_platform-mesh_io_account:2.core_platform-mesh_io_account:3',
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('core_platform-mesh_io_account:2');
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:1',
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:1.core_platform-mesh_io_account:2.core_platform-mesh_io_account:3',
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:1.core_platform-mesh_io_account:2',
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:1.core_platform-mesh_io_account:2',
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('core_platform-mesh_io_account:2');
132
- expect(childNode.context.accountId).toBe(
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.context['core_platform-mesh_io_accountId']).toBe(
174
+ expect(childNode.defineEntity.additionalContextKeys[0]).toBe(
136
175
  ':core_platform-mesh_io_accountId:2',
137
176
  );
138
- expect(childNode.context.resourceId).toBe(
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.pathSegment).toBe(':core_platform-mesh_io_accountId:2');
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('core_platform-mesh_io_account:4');
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('core_platform-mesh_io_account:2');
392
+ expect(childNode.defineEntity.id).toBe('old-id');
270
393
  expect(result.luigiConfigFragment.data.nodes[0].entityType).toBe(
271
- 'core_platform-mesh_io_account:1',
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:1',
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:1.core_platform-mesh_io_account:2',
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
- .map((_, i) => `${ACCOUNT_ENTITY_TYPE}:${i + 1}`)
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
- accountChildrenNode.defineEntity.id = `${ACCOUNT_ENTITY_TYPE}:${nextHierarchyLevel}`;
38
- accountChildrenNode.context.accountId = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
39
- accountChildrenNode.context[`${ACCOUNT_ENTITY_TYPE}Id`] =
40
- `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
41
- accountChildrenNode.context.resourceId = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
42
- accountChildrenNode.pathSegment = `:${ACCOUNT_ENTITY_TYPE}Id:${nextHierarchyLevel}`;
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
+ };
@@ -1,86 +0,0 @@
1
- # SAP Open Source Code of Conduct
2
-
3
- SAP adopts the [Contributor's Covenant 2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)
4
- across our open source projects to ensure a welcoming and open culture for everyone involved.
5
-
6
- ## Our Pledge
7
-
8
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
9
-
10
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to a positive environment for our community include:
15
-
16
- * Demonstrating empathy and kindness toward other people
17
- * Being respectful of differing opinions, viewpoints, and experiences
18
- * Giving and gracefully accepting constructive feedback
19
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
20
- * Focusing on what is best not just for us as individuals, but for the overall community
21
-
22
- Examples of unacceptable behavior include:
23
-
24
- * The use of sexualized language or imagery, and sexual attention or advances of any kind
25
- * Trolling, insulting or derogatory comments, and personal or political attacks
26
- * Public or private harassment
27
- * Publishing others' private information, such as a physical or email address, without their explicit permission
28
- * Other conduct which could reasonably be considered inappropriate in a professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [ospo@sap.com](mailto:ospo@sap.com) (SAP Open Source Program Office). All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
77
-
78
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
79
-
80
- For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
81
-
82
- [homepage]: https://www.contributor-covenant.org
83
- [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
84
- [Mozilla CoC]: https://github.com/mozilla/diversity
85
- [FAQ]: https://www.contributor-covenant.org/faq
86
- [translations]: https://www.contributor-covenant.org/translations