@lwrjs/shared-utils 0.5.7 → 0.5.11-236-1

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.
@@ -30,4 +30,5 @@ __exportStar(exports, __toModule(require("./import-metadata.cjs")));
30
30
  __exportStar(exports, __toModule(require("./graph.cjs")));
31
31
  __exportStar(exports, __toModule(require("./mappings.cjs")));
32
32
  __exportStar(exports, __toModule(require("./metrics.cjs")));
33
+ __exportStar(exports, __toModule(require("./urls.cjs")));
33
34
  __exportStar(exports, __toModule(require("./env.cjs")));
@@ -0,0 +1,83 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/shared-utils/src/urls.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ extractRequestParams: () => extractRequestParams,
28
+ getClientBootstrapConfigurationRoutes: () => getClientBootstrapConfigurationRoutes,
29
+ getClientBootstrapConfigurationUri: () => getClientBootstrapConfigurationUri,
30
+ getClientBootstrapConfigurationUriPrefix: () => getClientBootstrapConfigurationUriPrefix,
31
+ removeClientBootstrapConfigurationSuffix: () => removeClientBootstrapConfigurationSuffix
32
+ });
33
+ var import_path_to_regexp = __toModule(require("path-to-regexp"));
34
+ var CONFIG_SUFFIX = "/config.js";
35
+ function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams) {
36
+ const encodeUrl = encodeURIComponent(routeInfo.url);
37
+ const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
38
+ return `${configUrlPrefix}/${encodeUrl}${CONFIG_SUFFIX}`;
39
+ }
40
+ function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
41
+ const {apiVersion, format} = runtimeEnvironment;
42
+ const {id} = routeInfo;
43
+ const locale = runtimeParams?.locale;
44
+ const environment = runtimeParams?.environment;
45
+ if (locale && environment) {
46
+ return `/${apiVersion}/application/${format}/l/${locale}/e/${environment}/ai/${id}/configuration/ci`;
47
+ } else if (locale) {
48
+ return `/${apiVersion}/application/${format}/l/${locale}/ai/${id}/configuration/ci`;
49
+ } else if (environment) {
50
+ return `/${apiVersion}/application/${format}/e/${environment}/ai/${id}/configuration/ci`;
51
+ } else {
52
+ return `/${apiVersion}/application/${format}/ai/${id}/configuration/ci`;
53
+ }
54
+ }
55
+ function removeClientBootstrapConfigurationSuffix(url) {
56
+ let ret = url;
57
+ if (url.endsWith(CONFIG_SUFFIX)) {
58
+ ret = url.slice(0, -CONFIG_SUFFIX.length);
59
+ }
60
+ return ret;
61
+ }
62
+ function getClientBootstrapConfigurationRoutes() {
63
+ return [
64
+ `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
65
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
66
+ `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
67
+ `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`
68
+ ];
69
+ }
70
+ function extractRequestParams(parameterizedRoute, resolvedUrl, existingParams) {
71
+ const keys = [];
72
+ const re = (0, import_path_to_regexp.pathToRegexp)(parameterizedRoute, keys);
73
+ const params = existingParams || {};
74
+ if (keys.length > 0) {
75
+ const result = re.exec(resolvedUrl) || new Array(keys.length);
76
+ for (let i = 0; i < keys.length; i++) {
77
+ const key = keys[i].name;
78
+ const value = result[i + 1];
79
+ params[key] = value;
80
+ }
81
+ }
82
+ return params;
83
+ }
@@ -9,5 +9,6 @@ export * from './import-metadata.js';
9
9
  export * from './graph.js';
10
10
  export * from './mappings.js';
11
11
  export * from './metrics.js';
12
+ export * from './urls.js';
12
13
  export * from './env.js';
13
14
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -9,5 +9,6 @@ export * from './import-metadata.js';
9
9
  export * from './graph.js';
10
10
  export * from './mappings.js';
11
11
  export * from './metrics.js';
12
+ export * from './urls.js';
12
13
  export * from './env.js';
13
14
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ import { RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
+ export declare function getClientBootstrapConfigurationUri(routeInfo: {
3
+ id: string;
4
+ url: string;
5
+ }, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams): string;
6
+ export declare function getClientBootstrapConfigurationUriPrefix(routeInfo: {
7
+ id: string;
8
+ }, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams): string;
9
+ /**
10
+ * Remove the suffix from config
11
+ */
12
+ export declare function removeClientBootstrapConfigurationSuffix(url: string): string;
13
+ /**
14
+ * Get the parameterized client bootstrap app configuration routes
15
+ */
16
+ export declare function getClientBootstrapConfigurationRoutes(): string[];
17
+ /**
18
+ * Extract param values from a resolved URL based on a parameterized route. Keep existing param values.
19
+ * Uses path-to-regexp to match -> https://www.npmjs.com/package/path-to-regexp
20
+ *
21
+ * extractRequestParams('/:p1/:p2*', '/foo/bar/barz', {e1:'v1'}) => {e1:'v1', p1:'foo', p2:'bar/barz'}
22
+ *
23
+ * @param parameterizedRoute - A Url with parameter tokens
24
+ * @param resolvedUrl - A url with tokens filled in to match against
25
+ * @param existingParams - optional existing request parameters to match against
26
+ * @returns A parameter maps with existing parameters plus token value pairs from route and url
27
+ */
28
+ export declare function extractRequestParams(parameterizedRoute: string, resolvedUrl: string, existingParams?: Record<string, string>): Record<string, string>;
29
+ //# sourceMappingURL=urls.d.ts.map
@@ -0,0 +1,73 @@
1
+ import { pathToRegexp } from 'path-to-regexp';
2
+ const CONFIG_SUFFIX = '/config.js';
3
+ export function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams) {
4
+ const encodeUrl = encodeURIComponent(routeInfo.url);
5
+ const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
6
+ return `${configUrlPrefix}/${encodeUrl}${CONFIG_SUFFIX}`;
7
+ }
8
+ export function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
9
+ const { apiVersion, format } = runtimeEnvironment;
10
+ const { id } = routeInfo;
11
+ const locale = runtimeParams?.locale;
12
+ const environment = runtimeParams?.environment;
13
+ if (locale && environment) {
14
+ return `/${apiVersion}/application/${format}/l/${locale}/e/${environment}/ai/${id}/configuration/ci`;
15
+ }
16
+ else if (locale) {
17
+ return `/${apiVersion}/application/${format}/l/${locale}/ai/${id}/configuration/ci`;
18
+ }
19
+ else if (environment) {
20
+ return `/${apiVersion}/application/${format}/e/${environment}/ai/${id}/configuration/ci`;
21
+ }
22
+ else {
23
+ return `/${apiVersion}/application/${format}/ai/${id}/configuration/ci`;
24
+ }
25
+ }
26
+ /**
27
+ * Remove the suffix from config
28
+ */
29
+ export function removeClientBootstrapConfigurationSuffix(url) {
30
+ let ret = url;
31
+ if (url.endsWith(CONFIG_SUFFIX)) {
32
+ ret = url.slice(0, -CONFIG_SUFFIX.length);
33
+ }
34
+ return ret;
35
+ }
36
+ /**
37
+ * Get the parameterized client bootstrap app configuration routes
38
+ */
39
+ export function getClientBootstrapConfigurationRoutes() {
40
+ return [
41
+ `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
42
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
43
+ `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
44
+ `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
45
+ ];
46
+ }
47
+ /**
48
+ * Extract param values from a resolved URL based on a parameterized route. Keep existing param values.
49
+ * Uses path-to-regexp to match -> https://www.npmjs.com/package/path-to-regexp
50
+ *
51
+ * extractRequestParams('/:p1/:p2*', '/foo/bar/barz', {e1:'v1'}) => {e1:'v1', p1:'foo', p2:'bar/barz'}
52
+ *
53
+ * @param parameterizedRoute - A Url with parameter tokens
54
+ * @param resolvedUrl - A url with tokens filled in to match against
55
+ * @param existingParams - optional existing request parameters to match against
56
+ * @returns A parameter maps with existing parameters plus token value pairs from route and url
57
+ */
58
+ export function extractRequestParams(parameterizedRoute, resolvedUrl, existingParams) {
59
+ const keys = [];
60
+ const re = pathToRegexp(parameterizedRoute, keys);
61
+ const params = existingParams || {};
62
+ if (keys.length > 0) {
63
+ const result = re.exec(resolvedUrl) || new Array(keys.length);
64
+ for (let i = 0; i < keys.length; i++) {
65
+ const key = keys[i].name;
66
+ // result array if [url, value, value] so add 1 to count to get matching value
67
+ const value = result[i + 1];
68
+ params[key] = value;
69
+ }
70
+ }
71
+ return params;
72
+ }
73
+ //# sourceMappingURL=urls.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.5.7",
7
+ "version": "0.5.11-236-1",
8
8
  "homepage": "https://lwr.dev/",
9
9
  "repository": {
10
10
  "type": "git",
@@ -41,11 +41,11 @@
41
41
  "slugify": "^1.4.5"
42
42
  },
43
43
  "devDependencies": {
44
- "@lwrjs/diagnostics": "0.5.7",
45
- "@lwrjs/types": "0.5.7"
44
+ "@lwrjs/diagnostics": "0.5.11-236-1",
45
+ "@lwrjs/types": "0.5.11-236-1",
46
+ "@types/path-to-regexp": "^1.7.0"
46
47
  },
47
48
  "engines": {
48
49
  "node": ">=14.15.4 <17"
49
- },
50
- "gitHead": "406dbaa1c1f7a08b067e47c1c01d0b5295df3e5b"
50
+ }
51
51
  }
package/LICENSE DELETED
@@ -1,10 +0,0 @@
1
- MIT LICENSE
2
-
3
- Copyright (c) 2020, Salesforce.com, Inc.
4
- All rights reserved.
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
-
8
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
-
10
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.