@sap-ux/project-access 1.35.16 → 1.35.18

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.
@@ -95,6 +95,21 @@ export declare function getCdsServices(projectRoot: string, ignoreErrors?: boole
95
95
  * @returns - string containing the edmx
96
96
  */
97
97
  export declare function readCapServiceMetadataEdmx(root: string, uri: string, version?: 'v2' | 'v4'): Promise<string>;
98
+ /**
99
+ * Checks whether a given URL path matches one of the supported service prefix patterns
100
+ * and ends with the expected service suffix path.
101
+ *
102
+ * Currently method validates against DwC service patterns, supported patterns:
103
+ * - `/ui/<inbound-service-name>/v<version>/<suffix>`
104
+ * - `/<string>.<string>/external-ui/<inbound-service-name>/v<version>/<suffix>`
105
+ *
106
+ * The `<suffix>` (e.g. `odata/v4/myService`) must match exactly.
107
+ *
108
+ * @param path - The full request path to validate.
109
+ * @param expectedSuffixPath - The expected service path (e.g. `odata/v4/myService`).
110
+ * @returns `true` if the path matches one of the supported patterns and ends with the expected suffix.
111
+ */
112
+ export declare function isMatchingServiceUri(path: string, expectedSuffixPath: string): boolean;
98
113
  /**
99
114
  * Get CAP CDS project environment config for project root.
100
115
  *
@@ -12,6 +12,7 @@ exports.getCdsFiles = getCdsFiles;
12
12
  exports.getCdsRoots = getCdsRoots;
13
13
  exports.getCdsServices = getCdsServices;
14
14
  exports.readCapServiceMetadataEdmx = readCapServiceMetadataEdmx;
15
+ exports.isMatchingServiceUri = isMatchingServiceUri;
15
16
  exports.getCapEnvironment = getCapEnvironment;
16
17
  exports.clearCdsModuleCache = clearCdsModuleCache;
17
18
  exports.clearGlobalCdsModulePromiseCache = clearGlobalCdsModulePromiseCache;
@@ -333,6 +334,9 @@ function extractCdsFilesFromMessage(sources) {
333
334
  * @returns - uniform url
334
335
  */
335
336
  function uniformUrl(url) {
337
+ if (!url) {
338
+ return '';
339
+ }
336
340
  return url
337
341
  .replace(/\\/g, '/')
338
342
  .replace(/\/\//g, '/')
@@ -361,6 +365,41 @@ async function readCapServiceMetadataEdmx(root, uri, version = 'v4') {
361
365
  throw Error(`Error while reading CAP service metadata. Path: '${root}', service uri: '${uri}', error: '${error.toString()}'}`);
362
366
  }
363
367
  }
368
+ /**
369
+ * Normalizes a service URL path by removing a leading and/or trailing slash.
370
+ *
371
+ * @param urlPath - The URL path to normalize.
372
+ * @returns The normalized path without leading or trailing slashes.
373
+ */
374
+ function normalizeServiceUrlPath(urlPath) {
375
+ return urlPath.replaceAll(/(?:^\/)|(?:\/$)/g, '');
376
+ }
377
+ /**
378
+ * Checks whether a given URL path matches one of the supported service prefix patterns
379
+ * and ends with the expected service suffix path.
380
+ *
381
+ * Currently method validates against DwC service patterns, supported patterns:
382
+ * - `/ui/<inbound-service-name>/v<version>/<suffix>`
383
+ * - `/<string>.<string>/external-ui/<inbound-service-name>/v<version>/<suffix>`
384
+ *
385
+ * The `<suffix>` (e.g. `odata/v4/myService`) must match exactly.
386
+ *
387
+ * @param path - The full request path to validate.
388
+ * @param expectedSuffixPath - The expected service path (e.g. `odata/v4/myService`).
389
+ * @returns `true` if the path matches one of the supported patterns and ends with the expected suffix.
390
+ */
391
+ function isMatchingServiceUri(path, expectedSuffixPath) {
392
+ const normalizedPath = path.startsWith('/') ? path : `/${path}`;
393
+ // Escapes special regex characters in a string so it can be embedded into regular expression
394
+ const escapedSuffix = expectedSuffixPath.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
395
+ const patterns = [
396
+ // regex for pattern -> /ui/<inbound-service-name>/v<version>/...
397
+ String.raw `^/ui/[^/]+/v\d+/${escapedSuffix}$`,
398
+ // regex for pattern -> /<string>.<string>/external-ui/<inbound-service-name>/v<version>/...
399
+ String.raw `^/[^/]+\.[^/]+/external-ui/[^/]+/v\d+/${escapedSuffix}$`
400
+ ];
401
+ return patterns.some((pattern) => new RegExp(pattern).test(normalizedPath));
402
+ }
364
403
  /**
365
404
  * Find a service in a list of services ignoring leading and trailing slashes.
366
405
  *
@@ -369,8 +408,15 @@ async function readCapServiceMetadataEdmx(root, uri, version = 'v4') {
369
408
  * @returns - name and uri of the service, undefined if service not found
370
409
  */
371
410
  function findServiceByUri(services, uri) {
372
- const searchUri = uniformUrl(uri).replace(/(?:^\/)|(?:\/$)/g, '');
373
- return services.find((srv) => srv.urlPath.replace(/(?:^\/)|(?:\/$)/g, '') === searchUri);
411
+ const searchUri = normalizeServiceUrlPath(uniformUrl(uri));
412
+ // Try to find a service by exact path match
413
+ let service = services.find((srv) => normalizeServiceUrlPath(srv.urlPath) === searchUri);
414
+ // If no exact match is found, try matching while ignoring the service prefix
415
+ service ??= services.find((srv) => {
416
+ const normalizedServiceUrlPath = normalizeServiceUrlPath(srv.urlPath);
417
+ return isMatchingServiceUri(searchUri, normalizedServiceUrlPath);
418
+ });
419
+ return service;
374
420
  }
375
421
  /**
376
422
  * Get CAP CDS project environment config for project root.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-access",
3
- "version": "1.35.16",
3
+ "version": "1.35.18",
4
4
  "description": "Library to access SAP Fiori tools projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,7 +39,7 @@
39
39
  "@types/semver": "7.7.1",
40
40
  "@ui5/manifest": "1.84.0",
41
41
  "vscode-uri": "3.1.0",
42
- "@sap-ux/logger": "0.8.3"
42
+ "@sap-ux/logger": "0.8.4"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsc --build",