@speedkit/cli 2.14.2 → 2.15.0
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/CHANGELOG.md +16 -0
- package/README.md +5 -2
- package/dist/commands/generate-pop-config.js +6 -5
- package/dist/dummy.spec.js +4 -4
- package/dist/helpers/build-query-helper.js +49 -35
- package/dist/helpers/file-helper.d.ts +2 -8
- package/dist/helpers/file-helper.js +6 -41
- package/dist/helpers/get-parsed-config.js +7 -7
- package/dist/helpers/getChromePath.js +11 -7
- package/dist/helpers/isDirectory.js +1 -1
- package/dist/helpers/isFile.js +1 -1
- package/dist/helpers/normalize.d.ts +2 -0
- package/dist/helpers/normalize.js +14 -12
- package/dist/helpers/race.js +3 -1
- package/dist/helpers/scrape.js +3 -2
- package/dist/helpers/speedKitRuleToRegExp.js +2 -2
- package/dist/models/cli-parameters.d.ts +2 -2
- package/dist/models/cli-parameters.js +8 -2
- package/dist/models/files.js +13 -13
- package/dist/services/athena/athena-service-factory.d.ts +13 -0
- package/dist/services/athena/athena-service-factory.js +40 -0
- package/dist/services/athena/athena-service-model.d.ts +4 -0
- package/dist/services/athena/athena-service-model.js +7 -0
- package/dist/services/{athena-service.d.ts → athena/athena-service.d.ts} +4 -8
- package/dist/services/{athena-service.js → athena/athena-service.js} +12 -36
- package/dist/services/athena/error/fetch-credentials-error.d.ts +2 -0
- package/dist/services/athena/error/fetch-credentials-error.js +6 -0
- package/dist/services/athena/index.d.ts +4 -0
- package/dist/services/athena/index.js +7 -0
- package/dist/services/bundler/bundle-service-factory.d.ts +1 -1
- package/dist/services/bundler/bundle-service.d.ts +2 -2
- package/dist/services/bundler/bundle-service.js +29 -23
- package/dist/services/bundler/index.d.ts +2 -2
- package/dist/services/cli/cli-service.js +5 -5
- package/dist/services/cli/hooks.js +2 -2
- package/dist/services/cli/index.d.ts +3 -3
- package/dist/services/config-api/client.d.ts +1 -1
- package/dist/services/config-api/client.js +9 -7
- package/dist/services/config-api/config-api-service.js +20 -8
- package/dist/services/config-api/factory/config-api-service-factory.js +1 -1
- package/dist/services/config-api/interface/request-extension-interface.d.ts +2 -2
- package/dist/services/customer-config/customer-config-service-context.js +1 -1
- package/dist/services/customer-config/customer-config-service.d.ts +1 -0
- package/dist/services/customer-config/customer-config-service.js +68 -57
- package/dist/services/customer-config/index.d.ts +4 -4
- package/dist/services/deploy/builder/install-resource-builder.js +9 -7
- package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +2 -2
- package/dist/services/deploy/checks/post-deploy/save-files-check.js +2 -2
- package/dist/services/deploy/deploy-service.js +7 -7
- package/dist/services/deploy/handler/customer-config-handler.js +12 -11
- package/dist/services/deploy/handler/install-resource-handler.js +14 -12
- package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.js +10 -10
- package/dist/services/deploy/handler/module-handler.js +9 -9
- package/dist/services/deploy/handler/module-modifier/deployment-detection-modifier.js +2 -2
- package/dist/services/deploy/handler/server-config-handler.js +4 -4
- package/dist/services/deploy/interface/install.d.ts +1 -1
- package/dist/services/document-handler-runtime/context/document-handler-runtime-context.js +37 -18
- package/dist/services/document-handler-runtime/document-handler-runtime-service.js +45 -35
- package/dist/services/document-handler-runtime/document-handler-server.js +56 -33
- package/dist/services/document-handler-runtime/error/handler/required-file-not-found-handler.js +1 -1
- package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +20 -16
- package/dist/services/document-handler-runtime/templates/abstract-template.d.ts +1 -1
- package/dist/services/document-handler-runtime/templates/abstract-template.js +1 -1
- package/dist/services/error-handling/abstract/abstract-async-error-handling-factory.js +1 -1
- package/dist/services/error-handling/abstract/abstract-async-error-handling-service.js +1 -1
- package/dist/services/error-handling/abstract/abstract-error-handling-factory.js +1 -1
- package/dist/services/error-handling/abstract/abstract-error-handling-service.js +1 -1
- package/dist/services/error-handling/error/handler/default-error-handler.d.ts +1 -1
- package/dist/services/error-handling/error/handler/default-error-handler.js +1 -1
- package/dist/services/error-handling/error-handling-service.js +2 -2
- package/dist/services/integration-api/context/integration-api-context.js +1 -1
- package/dist/services/integration-api/external/external-file-reader.js +1 -1
- package/dist/services/integration-api/factory/integration-api-service-factory.js +3 -3
- package/dist/services/integration-api/file-list.js +6 -4
- package/dist/services/integration-api/file-reader.js +17 -12
- package/dist/services/integration-api/handler/file-handler.d.ts +1 -1
- package/dist/services/integration-api/handler/file-handler.js +8 -4
- package/dist/services/integration-api/handler/install-resource-handler.js +21 -20
- package/dist/services/integration-api/handler/server-config-handler.js +1 -3
- package/dist/services/integration-api/integration-api-model.d.ts +2 -2
- package/dist/services/integration-api/integration-api-service.js +10 -7
- package/dist/services/integration-api/struct/customer-config.js +3 -2
- package/dist/services/integration-api/struct/file.js +4 -4
- package/dist/services/integration-api/struct/module-file.d.ts +1 -1
- package/dist/services/integration-api/struct/module-file.js +3 -1
- package/dist/services/integration-api/struct/server-config-file.d.ts +1 -1
- package/dist/services/integration-api/validator/customer-config-validator.js +13 -4
- package/dist/services/integration-api/validator/mandatory-files-validator.js +9 -5
- package/dist/services/integration-api/virtual/virtual-file-handler.js +1 -1
- package/dist/services/onboarding/dashboard/frontend-dist/assets/{index-87b53ed4.css → index-e3bd4f6e.css} +1 -1
- package/dist/services/onboarding/dashboard/frontend-dist/assets/{main-274b5625.js → main-215271c2.js} +3 -3
- package/dist/services/onboarding/dashboard/frontend-dist/index.html +2 -2
- package/dist/services/onboarding/dashboard/index.d.ts +2 -1
- package/dist/services/onboarding/dashboard/index.js +6 -5
- package/dist/services/onboarding/dashboard/request-diff-service.d.ts +4 -2
- package/dist/services/onboarding/dashboard/request-diff-service.js +23 -14
- package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
- package/dist/services/onboarding/onboarding-service-factory.js +9 -34
- package/dist/services/pop-config/index.d.ts +3 -0
- package/dist/services/pop-config/index.js +6 -0
- package/dist/services/pop-config/pop-config-factory.d.ts +4 -0
- package/dist/services/pop-config/pop-config-factory.js +12 -0
- package/dist/services/pop-config/pop-config-model.d.ts +6 -0
- package/dist/services/pop-config/pop-config-model.js +2 -0
- package/dist/services/pop-config/pop-config-service.d.ts +7 -0
- package/dist/services/pop-config/pop-config-service.js +39 -0
- package/dist/services/prewarm-service.js +22 -16
- package/oclif.manifest.json +1 -1
- package/package.json +4 -6
- package/dist/services/onboarding/dashboard/athena-service.d.ts +0 -11
- package/dist/services/onboarding/dashboard/athena-service.js +0 -75
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [2.15.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.14.3...v2.15.0) (2024-03-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **origins:** merge main ([afc9abf](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/afc9abf9a3a921687acc256a37ec88b07001390e))
|
|
7
|
+
* **paramDiff:** remove meta:baqendAssetUrl for easier diff ([6886f81](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/6886f81d631b8f81708dbbab08ad29278296a5e6))
|
|
8
|
+
* **paramStripping:** remove customAWSLogin ([5beb6a1](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/5beb6a140a6479f6bc4f1be616cd36ca159867c0))
|
|
9
|
+
|
|
10
|
+
## [2.14.3](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.14.2...v2.14.3) (2024-03-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **onboarding:** add esBuild to productionDependency ([4e7deba](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/4e7deba5aba4ea65d08a2ec6119bd9c039f1aa6c))
|
|
16
|
+
|
|
1
17
|
## [2.14.2](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.14.1...v2.14.2) (2024-03-20)
|
|
2
18
|
|
|
3
19
|
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @speedkit/cli
|
|
|
21
21
|
$ sk COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ sk (--version)
|
|
24
|
-
@speedkit/cli/2.
|
|
24
|
+
@speedkit/cli/2.15.0 linux-x64 node-v20.11.1
|
|
25
25
|
$ sk --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ sk COMMAND
|
|
@@ -29,7 +29,10 @@ USAGE
|
|
|
29
29
|
```
|
|
30
30
|
<!-- usagestop -->
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
> **💡 NOTE:**
|
|
33
|
+
Set up auto-completion for the CLI by executing [`sk autocomplete [SHELL]`](#sk-autocomplete-shell) once.
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
33
36
|
|
|
34
37
|
There are two different ways of configuring the CLI:
|
|
35
38
|
- [Using Config File (recommended)](#using-config-file-recommended)
|
|
@@ -6,10 +6,10 @@ const cli_1 = require("baqend/cli");
|
|
|
6
6
|
const promises_1 = require("node:fs/promises");
|
|
7
7
|
const file_helper_1 = require("../helpers/file-helper");
|
|
8
8
|
const cli_parameters_1 = require("../models/cli-parameters");
|
|
9
|
-
const athena_service_1 = require("../services/athena-service");
|
|
10
9
|
const cli_2 = require("../services/cli");
|
|
11
10
|
const config_api_service_1 = tslib_1.__importDefault(require("../services/config-api-service"));
|
|
12
11
|
const diff_service_1 = require("../services/diff-service");
|
|
12
|
+
const pop_config_1 = require("../services/pop-config");
|
|
13
13
|
const POP_REMAPPING = {
|
|
14
14
|
HHN: "FRA",
|
|
15
15
|
};
|
|
@@ -137,8 +137,9 @@ class GeneratePopConfig extends core_1.Command {
|
|
|
137
137
|
}
|
|
138
138
|
async run() {
|
|
139
139
|
const { args: { app }, flags: { coverage, deploy, "pop-limit": popLimit, "traffic-share": minimalShare, "use-rum": useRum, }, } = await this.parse(GeneratePopConfig);
|
|
140
|
-
|
|
141
|
-
const
|
|
140
|
+
// @todo refactor businessCode from this command to src/pop-config/pop-config-service
|
|
141
|
+
const popConfigService = await new pop_config_1.PopConfigFactory().getService();
|
|
142
|
+
const result = await popConfigService.getUsedPopsPerOrigin(app, useRum);
|
|
142
143
|
const originStats = this.generateOriginStats(result).filter((stats) => stats.hits > 1000);
|
|
143
144
|
this.printStats(originStats, coverage / 100, minimalShare / 100, popLimit);
|
|
144
145
|
const popConfig = this.generatePopConfig(originStats, coverage / 100, minimalShare / 100, popLimit);
|
|
@@ -161,8 +162,8 @@ class GeneratePopConfig extends core_1.Command {
|
|
|
161
162
|
}
|
|
162
163
|
generateOriginStats(result) {
|
|
163
164
|
const originStats = {};
|
|
164
|
-
for (
|
|
165
|
-
pop = POP_REMAPPING[
|
|
165
|
+
for (const { hits, origin, pop: givenPop, region } of result) {
|
|
166
|
+
const pop = POP_REMAPPING[givenPop] ?? givenPop;
|
|
166
167
|
const shieldInfo = this.getShieldInfo(region, pop);
|
|
167
168
|
// eslint-disable-next-line no-multi-assign
|
|
168
169
|
const stats = (originStats[origin] = originStats[origin] ?? {
|
package/dist/dummy.spec.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// Require the assert module from Chai
|
|
4
|
-
const { expect } = require(
|
|
4
|
+
const { expect } = require("chai");
|
|
5
5
|
// Dummy function to test
|
|
6
6
|
function add(a, b) {
|
|
7
7
|
return a + b;
|
|
8
8
|
}
|
|
9
9
|
// Describe your test suite
|
|
10
|
-
describe(
|
|
11
|
-
// It block
|
|
12
|
-
it(
|
|
10
|
+
describe("(dummy) add function test", () => {
|
|
11
|
+
// It block-describes a single test
|
|
12
|
+
it("should add two numbers", () => {
|
|
13
13
|
// Call our function with some test inputs
|
|
14
14
|
const result = add(2, 3);
|
|
15
15
|
// Assert that our function returned the correct value
|
|
@@ -20,18 +20,18 @@ function getStringBetween(input, leftBound, rightBound) {
|
|
|
20
20
|
* @param type - Whether type of property is a pathname or url.
|
|
21
21
|
*/
|
|
22
22
|
function getFilterForProperty(property, sqlField, shouldEqual, type) {
|
|
23
|
-
if (typeof property ===
|
|
24
|
-
if (type ===
|
|
25
|
-
return `url_extract_path(${sqlField}) ${shouldEqual ?
|
|
23
|
+
if (typeof property === "string") {
|
|
24
|
+
if (type === "pathname") {
|
|
25
|
+
return `url_extract_path(${sqlField}) ${shouldEqual ? "" : "not "}like '${property}%'`;
|
|
26
26
|
}
|
|
27
|
-
return `${sqlField} ${shouldEqual ?
|
|
27
|
+
return `${sqlField} ${shouldEqual ? "" : "not "}like 'https://${property}%'`;
|
|
28
28
|
}
|
|
29
29
|
const ignoreCase = isRegExpIgnoringCase(property);
|
|
30
|
-
const sqlRegExp = getStringBetween(String(property),
|
|
31
|
-
if (type ===
|
|
32
|
-
return `${shouldEqual ?
|
|
30
|
+
const sqlRegExp = getStringBetween(String(property), "/", "/");
|
|
31
|
+
if (type === "pathname") {
|
|
32
|
+
return `${shouldEqual ? "" : "not "}regexp_like(url_extract_path(${sqlField}), '${ignoreCase ? "(?i)" : ""}${sqlRegExp}')`;
|
|
33
33
|
}
|
|
34
|
-
return `${shouldEqual ?
|
|
34
|
+
return `${shouldEqual ? "" : "not "}regexp_like(${sqlField}, '${ignoreCase ? "(?i)" : ""}${sqlRegExp}')`;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Returns all properties of a speed kit rule with the given keys.
|
|
@@ -46,8 +46,8 @@ function getRuleProp(speedKitRuleValues, key) {
|
|
|
46
46
|
}
|
|
47
47
|
for (const ruleValue of speedKitRuleValues) {
|
|
48
48
|
Object.keys(ruleValue)
|
|
49
|
-
.filter(ruleKey => key === ruleKey)
|
|
50
|
-
.forEach(ruleKey => properties.push(...ruleValue[ruleKey]));
|
|
49
|
+
.filter((ruleKey) => key === ruleKey)
|
|
50
|
+
.forEach((ruleKey) => properties.push(...ruleValue[ruleKey]));
|
|
51
51
|
}
|
|
52
52
|
return properties;
|
|
53
53
|
}
|
|
@@ -59,9 +59,12 @@ function getRuleProp(speedKitRuleValues, key) {
|
|
|
59
59
|
function getWhitelistedFilter(parsedConfig) {
|
|
60
60
|
const { whitelist, enabledSites } = parsedConfig;
|
|
61
61
|
// TODO: use origins instead here
|
|
62
|
-
const whitelistedFilter = `(\n ${(whitelist[0].host || whitelist[0].url)
|
|
63
|
-
|
|
64
|
-
.
|
|
62
|
+
const whitelistedFilter = `(\n ${(whitelist[0].host || whitelist[0].url)
|
|
63
|
+
.map((hostname) => getFilterForProperty(hostname, "url", true, "url"))
|
|
64
|
+
.join("\n or ")}\n )`;
|
|
65
|
+
const enabledFilter = getRuleProp(enabledSites, "pathname")
|
|
66
|
+
.map((pathname) => getFilterForProperty(pathname, "url", true, "pathname"))
|
|
67
|
+
.join("\nor ");
|
|
65
68
|
if (!enabledFilter) {
|
|
66
69
|
return `${whitelistedFilter}`;
|
|
67
70
|
}
|
|
@@ -75,13 +78,16 @@ exports.getWhitelistedFilter = getWhitelistedFilter;
|
|
|
75
78
|
*/
|
|
76
79
|
function getBlacklistedFilter(parsedConfig) {
|
|
77
80
|
const { blacklist, disabledSites } = parsedConfig;
|
|
78
|
-
const blacklistedPathnamesFilter = getRuleProp(blacklist,
|
|
79
|
-
.map(pathname => getFilterForProperty(pathname,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
81
|
+
const blacklistedPathnamesFilter = getRuleProp(blacklist, "pathname")
|
|
82
|
+
.map((pathname) => getFilterForProperty(pathname, "url", false, "pathname"))
|
|
83
|
+
.join("\n and ");
|
|
84
|
+
const blacklistedUrlsFilter = getRuleProp(blacklist, "url")
|
|
85
|
+
.map((url) => getFilterForProperty(url, "url", false, "url"))
|
|
86
|
+
.join("\n and ");
|
|
87
|
+
const disabledFilter = getRuleProp(disabledSites, "pathname")
|
|
88
|
+
.map((pathname) => getFilterForProperty(pathname, "url", false, "pathname"))
|
|
89
|
+
.join("\n and ");
|
|
90
|
+
let blacklistedFilter = "";
|
|
85
91
|
if (blacklistedPathnamesFilter) {
|
|
86
92
|
blacklistedFilter += blacklistedPathnamesFilter;
|
|
87
93
|
}
|
|
@@ -101,9 +107,10 @@ exports.getBlacklistedFilter = getBlacklistedFilter;
|
|
|
101
107
|
* @param skConfigVersion - The Speed Kit config ruleset version.
|
|
102
108
|
*/
|
|
103
109
|
function getParameterFilter(params, skConfigVersion = 1) {
|
|
104
|
-
return params
|
|
110
|
+
return params
|
|
111
|
+
.map((param) => {
|
|
105
112
|
// Prefix comparison for strings
|
|
106
|
-
if (typeof param ===
|
|
113
|
+
if (typeof param === "string") {
|
|
107
114
|
if (skConfigVersion === 1) {
|
|
108
115
|
return `not regexp_like(key, '^${param}')`;
|
|
109
116
|
}
|
|
@@ -113,8 +120,9 @@ function getParameterFilter(params, skConfigVersion = 1) {
|
|
|
113
120
|
}
|
|
114
121
|
// Regexp like for complex regular expressions
|
|
115
122
|
const ignoreCase = isRegExpIgnoringCase(param);
|
|
116
|
-
return `not regexp_like(key, '${ignoreCase ?
|
|
117
|
-
})
|
|
123
|
+
return `not regexp_like(key, '${ignoreCase ? "(?i)" : ""}${getStringBetween(String(param), "/", "/")}')`;
|
|
124
|
+
})
|
|
125
|
+
.join("\nand ");
|
|
118
126
|
}
|
|
119
127
|
exports.getParameterFilter = getParameterFilter;
|
|
120
128
|
/**
|
|
@@ -130,9 +138,9 @@ function getParameterReplaceFilter(params, skConfigVersion = 1) {
|
|
|
130
138
|
const prefixIgnoreCaseParams = [];
|
|
131
139
|
const suffixIgnoreCaseParams = [];
|
|
132
140
|
const fullMatchIgnoreCaseParams = [];
|
|
133
|
-
params.forEach(param => {
|
|
141
|
+
params.forEach((param) => {
|
|
134
142
|
// String params or regex params with start marker but no end marker
|
|
135
|
-
if (typeof param ===
|
|
143
|
+
if (typeof param === "string") {
|
|
136
144
|
if (skConfigVersion === 1) {
|
|
137
145
|
return prefixParams.push(param);
|
|
138
146
|
}
|
|
@@ -143,18 +151,18 @@ function getParameterReplaceFilter(params, skConfigVersion = 1) {
|
|
|
143
151
|
const ignoreCase = isRegExpIgnoringCase(param);
|
|
144
152
|
// Regex params with start marker but no end marker
|
|
145
153
|
if (/\/\^[^$]+$/.test(String(param))) {
|
|
146
|
-
return (ignoreCase ? prefixIgnoreCaseParams : prefixParams).push(getStringBetween(String(param),
|
|
154
|
+
return (ignoreCase ? prefixIgnoreCaseParams : prefixParams).push(getStringBetween(String(param), "^", "/"));
|
|
147
155
|
}
|
|
148
156
|
// Regex params with end marker but no start marker
|
|
149
157
|
if (/\/[^^$]+\$/.test(String(param))) {
|
|
150
|
-
return (ignoreCase ? suffixIgnoreCaseParams : suffixParams).push(getStringBetween(String(param),
|
|
158
|
+
return (ignoreCase ? suffixIgnoreCaseParams : suffixParams).push(getStringBetween(String(param), "/", "$"));
|
|
151
159
|
}
|
|
152
160
|
// Regex params with start marker and end marker
|
|
153
161
|
if (/\/\^[^$]+\$\//.test(String(param))) {
|
|
154
|
-
return (ignoreCase ? fullMatchIgnoreCaseParams : fullMatchParams).push(getStringBetween(String(param),
|
|
162
|
+
return (ignoreCase ? fullMatchIgnoreCaseParams : fullMatchParams).push(getStringBetween(String(param), "^", "$"));
|
|
155
163
|
}
|
|
156
164
|
// Regex params with no start marker and no end marker are being considered full matches
|
|
157
|
-
(ignoreCase ? fullMatchIgnoreCaseParams : fullMatchParams).push(getStringBetween(String(param),
|
|
165
|
+
(ignoreCase ? fullMatchIgnoreCaseParams : fullMatchParams).push(getStringBetween(String(param), "/", "/"));
|
|
158
166
|
});
|
|
159
167
|
let regExpQuery = "regexp_replace(url, '#.*' )";
|
|
160
168
|
const regExps = [
|
|
@@ -166,7 +174,7 @@ function getParameterReplaceFilter(params, skConfigVersion = 1) {
|
|
|
166
174
|
getParamFullMatchRegExp(fullMatchIgnoreCaseParams, true),
|
|
167
175
|
];
|
|
168
176
|
// Nest all regexes inside each other:
|
|
169
|
-
regExps.forEach(regExp => {
|
|
177
|
+
regExps.forEach((regExp) => {
|
|
170
178
|
if (regExp) {
|
|
171
179
|
regExpQuery = `regexp_replace(${regExpQuery}, '${regExp}', '')`;
|
|
172
180
|
}
|
|
@@ -178,13 +186,19 @@ function isRegExpIgnoringCase(regExp) {
|
|
|
178
186
|
return /\/i$/.test(String(regExp));
|
|
179
187
|
}
|
|
180
188
|
function getParamPrefixRegExp(params, ignoreCase) {
|
|
181
|
-
return params.length > 0
|
|
189
|
+
return params.length > 0
|
|
190
|
+
? `${ignoreCase ? "(?i)" : ""}[?&](${params.join("|")})[^&]*`
|
|
191
|
+
: null;
|
|
182
192
|
}
|
|
183
193
|
function getParamSuffixRegExp(params, ignoreCase) {
|
|
184
|
-
return params.length > 0
|
|
194
|
+
return params.length > 0
|
|
195
|
+
? `${ignoreCase ? "(?i)" : ""}[?&][^&]*(${params.join("|")})(=[^&]*)?(?=&|$)`
|
|
196
|
+
: null;
|
|
185
197
|
}
|
|
186
198
|
function getParamFullMatchRegExp(params, ignoreCase) {
|
|
187
|
-
return params.length > 0
|
|
199
|
+
return params.length > 0
|
|
200
|
+
? `${ignoreCase ? "(?i)" : ""}[?&](${params.join("|")})(=[^&]*)?(?=&|$)`
|
|
201
|
+
: null;
|
|
188
202
|
}
|
|
189
203
|
/**
|
|
190
204
|
* Returns the stripped parameters that are named within the speed kit config.
|
|
@@ -196,7 +210,7 @@ function getStrippedParams(parsedConfig) {
|
|
|
196
210
|
if (!paramArray) {
|
|
197
211
|
return [];
|
|
198
212
|
}
|
|
199
|
-
const isSimpleArray = paramArray.every((param) => typeof param ===
|
|
213
|
+
const isSimpleArray = paramArray.every((param) => typeof param === "string" || param instanceof RegExp);
|
|
200
214
|
if (isSimpleArray) {
|
|
201
215
|
return paramArray;
|
|
202
216
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export declare function createTemporalDir(): Promise<
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function trimFileExtension(str: string): string;
|
|
4
|
-
export declare function readLocalFile(basePath: string, fileName: string): Promise<string | null>;
|
|
5
|
-
/**
|
|
6
|
-
* Returns the local path to the sk-onboarding project.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getLocalPath(path: string): string;
|
|
1
|
+
export declare function createTemporalDir(): Promise<null | string>;
|
|
2
|
+
export declare function readLocalFile(basePath: string, fileName: string): Promise<null | string>;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.readLocalFile = exports.createTemporalDir = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const os = tslib_1.__importStar(require("os"));
|
|
9
|
-
const core_1 = require("@oclif/core");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const os = tslib_1.__importStar(require("node:os"));
|
|
7
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
10
8
|
const CustomerConfig_1 = require("./CustomerConfig");
|
|
11
|
-
const logging_helper_1 = require("./logging-helper");
|
|
12
9
|
async function createTemporalDir() {
|
|
13
10
|
try {
|
|
14
|
-
return
|
|
11
|
+
return (0, node_fs_1.mkdtempSync)(path.join(os.tmpdir(), "speed-kit-cli-"));
|
|
15
12
|
}
|
|
16
13
|
catch (error) {
|
|
17
14
|
console.error("Error creating temp folder", error);
|
|
@@ -19,45 +16,13 @@ async function createTemporalDir() {
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
exports.createTemporalDir = createTemporalDir;
|
|
22
|
-
async function createEmptyFile() {
|
|
23
|
-
const tempDir = await createTemporalDir();
|
|
24
|
-
const filePath = path.join(tempDir, "/empty_FilePath.js");
|
|
25
|
-
const writeFilePromise = new Promise((resolve, reject) => {
|
|
26
|
-
fs.writeFile(filePath, "No file was found", (err) => {
|
|
27
|
-
if (err) {
|
|
28
|
-
return reject(err);
|
|
29
|
-
}
|
|
30
|
-
resolve(null);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
await writeFilePromise;
|
|
34
|
-
return path.resolve(filePath);
|
|
35
|
-
}
|
|
36
|
-
exports.createEmptyFile = createEmptyFile;
|
|
37
|
-
function trimFileExtension(str) {
|
|
38
|
-
return str.replace(".js", "").replace(".es6", "");
|
|
39
|
-
}
|
|
40
|
-
exports.trimFileExtension = trimFileExtension;
|
|
41
19
|
async function readLocalFile(basePath, fileName) {
|
|
42
20
|
try {
|
|
43
21
|
const file = await CustomerConfig_1.ConfigFile.loadFile(basePath, fileName);
|
|
44
22
|
return await file.readContent();
|
|
45
23
|
}
|
|
46
|
-
catch
|
|
24
|
+
catch {
|
|
47
25
|
return null;
|
|
48
26
|
}
|
|
49
27
|
}
|
|
50
28
|
exports.readLocalFile = readLocalFile;
|
|
51
|
-
/**
|
|
52
|
-
* Returns the local path to the sk-onboarding project.
|
|
53
|
-
*/
|
|
54
|
-
function getLocalPath(path) {
|
|
55
|
-
const fullCustomerPath = path_1.default.resolve(path, "");
|
|
56
|
-
// Check if path is a valid path or not
|
|
57
|
-
if (!fs.existsSync(fullCustomerPath)) {
|
|
58
|
-
(0, logging_helper_1.logError)(`The given path: ${fullCustomerPath} is not a valid path`);
|
|
59
|
-
core_1.ux.exit(1);
|
|
60
|
-
}
|
|
61
|
-
return fullCustomerPath;
|
|
62
|
-
}
|
|
63
|
-
exports.getLocalPath = getLocalPath;
|
|
@@ -18,20 +18,20 @@ function parseSpeedKitConfig(config) {
|
|
|
18
18
|
const node = {
|
|
19
19
|
querySelector: () => node,
|
|
20
20
|
querySelectorAll: () => [],
|
|
21
|
-
classList: { contains: () => false }
|
|
21
|
+
classList: { contains: () => false },
|
|
22
22
|
};
|
|
23
23
|
const context = {
|
|
24
24
|
window,
|
|
25
|
-
APP:
|
|
25
|
+
APP: "",
|
|
26
26
|
document: Object.assign(Object.create(node), {
|
|
27
|
-
cookie:
|
|
27
|
+
cookie: "",
|
|
28
28
|
documentElement: Object.create(node),
|
|
29
29
|
head: Object.create(node),
|
|
30
30
|
body: Object.create(node),
|
|
31
31
|
}),
|
|
32
32
|
speedKit: window.speedKit,
|
|
33
|
-
navigator: { userAgent:
|
|
34
|
-
location: new URL(
|
|
33
|
+
navigator: { userAgent: "test-agent" },
|
|
34
|
+
location: new URL("https://www.example.com"),
|
|
35
35
|
localStorage: storage,
|
|
36
36
|
sessionStorage: storage,
|
|
37
37
|
};
|
|
@@ -42,7 +42,7 @@ exports.parseSpeedKitConfig = parseSpeedKitConfig;
|
|
|
42
42
|
async function getParsedConfig(configFile) {
|
|
43
43
|
const configString = configFile ? await configFile.readContent() : undefined;
|
|
44
44
|
if (!configString) {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error("Speed Kit config could not be found in directory");
|
|
46
46
|
}
|
|
47
47
|
let parsedConfig;
|
|
48
48
|
try {
|
|
@@ -52,7 +52,7 @@ async function getParsedConfig(configFile) {
|
|
|
52
52
|
throw new Error(`Speed Kit config string could not be parsed.\n${e.stack}`);
|
|
53
53
|
}
|
|
54
54
|
if (!parsedConfig) {
|
|
55
|
-
throw new Error(
|
|
55
|
+
throw new Error("Speed Kit config was not correctly exposed on the global speedKit variable.");
|
|
56
56
|
}
|
|
57
57
|
return parsedConfig;
|
|
58
58
|
}
|
|
@@ -4,11 +4,11 @@ exports.getChromePath = void 0;
|
|
|
4
4
|
const CustomerConfig_1 = require("./CustomerConfig");
|
|
5
5
|
const isFile_1 = require("./isFile");
|
|
6
6
|
const CHROME_PATHS = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
darwin: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
8
|
+
win32: "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
|
|
9
|
+
linux: "/usr/bin/google-chrome",
|
|
10
10
|
};
|
|
11
|
-
const ENV_CHROME_REGEX = new RegExp(/^\s*CHROME_PATH=(.*)$/
|
|
11
|
+
const ENV_CHROME_REGEX = new RegExp(/^\s*CHROME_PATH=(.*)$/mu);
|
|
12
12
|
/**
|
|
13
13
|
* Gets chrome-path of .env file in skonboarding project.
|
|
14
14
|
* If path is not set or falsy, uses default chrome-path.
|
|
@@ -16,12 +16,16 @@ const ENV_CHROME_REGEX = new RegExp(/^\s*CHROME_PATH=(.*)$/um);
|
|
|
16
16
|
* @param customerPath - Path to customer in skonboarding-project.
|
|
17
17
|
*/
|
|
18
18
|
async function getChromePath(customerPath) {
|
|
19
|
-
const envFile = await CustomerConfig_1.ConfigFile.loadFile(customerPath,
|
|
19
|
+
const envFile = await CustomerConfig_1.ConfigFile.loadFile(customerPath, "../../.env");
|
|
20
20
|
if (!envFile) {
|
|
21
21
|
return CHROME_PATHS[process.platform];
|
|
22
22
|
}
|
|
23
23
|
const envContent = await envFile.readContent();
|
|
24
|
-
const chromePath = ENV_CHROME_REGEX.test(envContent)
|
|
25
|
-
|
|
24
|
+
const chromePath = ENV_CHROME_REGEX.test(envContent)
|
|
25
|
+
? envContent.match(ENV_CHROME_REGEX)[1]
|
|
26
|
+
: "";
|
|
27
|
+
return (await (0, isFile_1.isFile)(chromePath))
|
|
28
|
+
? chromePath
|
|
29
|
+
: CHROME_PATHS[process.platform];
|
|
26
30
|
}
|
|
27
31
|
exports.getChromePath = getChromePath;
|
package/dist/helpers/isFile.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalize = exports.transformNoValueParams = exports.convertNotEncodedParameters = exports.sortParams = void 0;
|
|
4
|
-
const
|
|
4
|
+
const url_1 = require("url");
|
|
5
5
|
/**
|
|
6
6
|
* Sorts all urls params manually.
|
|
7
7
|
*
|
|
@@ -15,9 +15,9 @@ function sortParams(searchParams) {
|
|
|
15
15
|
return a[0] < b[0] ? -1 : 1;
|
|
16
16
|
});
|
|
17
17
|
// Clear search params before appending sorted params
|
|
18
|
-
entries.forEach(key => searchParams.delete(key[0]));
|
|
18
|
+
entries.forEach((key) => searchParams.delete(key[0]));
|
|
19
19
|
// Append sorted params without overwriting keys
|
|
20
|
-
entries.forEach(key => searchParams.append(key[0], key[1]));
|
|
20
|
+
entries.forEach((key) => searchParams.append(key[0], key[1]));
|
|
21
21
|
}
|
|
22
22
|
exports.sortParams = sortParams;
|
|
23
23
|
/**
|
|
@@ -28,9 +28,9 @@ exports.sortParams = sortParams;
|
|
|
28
28
|
* @return The encoded parameter key and value without ?.
|
|
29
29
|
*/
|
|
30
30
|
function encodeUrlComponent(parameterKey, parameterValue) {
|
|
31
|
-
const url = new URL(
|
|
31
|
+
const url = new url_1.URL("https://www.baqend.com/");
|
|
32
32
|
url.searchParams.append(parameterKey, parameterValue);
|
|
33
|
-
return url.search.replace(/\?/,
|
|
33
|
+
return url.search.replace(/\?/, "");
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Converts parameters back to origin form.
|
|
@@ -52,7 +52,7 @@ function convertNotEncodedParameters(url, manipulatedUrl) {
|
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
const originalParamsMap = new Map();
|
|
55
|
-
const originalParams = url.search.substring(1).split(
|
|
55
|
+
const originalParams = url.search.substring(1).split("&");
|
|
56
56
|
let index = 0;
|
|
57
57
|
url.searchParams.forEach((value, param) => {
|
|
58
58
|
const paramWithValue = originalParams[index];
|
|
@@ -69,7 +69,7 @@ function convertNotEncodedParameters(url, manipulatedUrl) {
|
|
|
69
69
|
}
|
|
70
70
|
return `${key}=${value}`;
|
|
71
71
|
});
|
|
72
|
-
manipulatedUrl.search = `?${search.join(
|
|
72
|
+
manipulatedUrl.search = `?${search.join("&")}`;
|
|
73
73
|
}
|
|
74
74
|
exports.convertNotEncodedParameters = convertNotEncodedParameters;
|
|
75
75
|
/**
|
|
@@ -82,7 +82,9 @@ exports.convertNotEncodedParameters = convertNotEncodedParameters;
|
|
|
82
82
|
* @param manipulatedUrl - The manipulated URL to remove the "=" from.
|
|
83
83
|
*/
|
|
84
84
|
function transformNoValueParams(url, manipulatedUrl) {
|
|
85
|
-
const paramsWithoutValue = url.search
|
|
85
|
+
const paramsWithoutValue = url.search
|
|
86
|
+
.split(/[?&]/)
|
|
87
|
+
.filter((e) => e && !e.includes("="));
|
|
86
88
|
for (const param of paramsWithoutValue) {
|
|
87
89
|
manipulatedUrl.search = manipulatedUrl.search.replace(`${param}=`, param);
|
|
88
90
|
}
|
|
@@ -96,17 +98,17 @@ exports.transformNoValueParams = transformNoValueParams;
|
|
|
96
98
|
* @returns The normalized URL.
|
|
97
99
|
*/
|
|
98
100
|
function normalize(urlString, sortParameters) {
|
|
99
|
-
const url = new URL(urlString);
|
|
101
|
+
const url = new url_1.URL(urlString);
|
|
100
102
|
// Remove the hash part of the URL if exists
|
|
101
103
|
if (url.hash) {
|
|
102
|
-
url.hash =
|
|
104
|
+
url.hash = "";
|
|
103
105
|
}
|
|
104
106
|
if (!sortParameters) {
|
|
105
107
|
// Sort search params to normalize encoding and order of params
|
|
106
108
|
sortParams(url.searchParams);
|
|
107
109
|
}
|
|
108
|
-
convertNotEncodedParameters(new URL(urlString), url);
|
|
109
|
-
transformNoValueParams(new URL(urlString), url);
|
|
110
|
+
convertNotEncodedParameters(new url_1.URL(urlString), url);
|
|
111
|
+
transformNoValueParams(new url_1.URL(urlString), url);
|
|
110
112
|
return url.toString();
|
|
111
113
|
}
|
|
112
114
|
exports.normalize = normalize;
|
package/dist/helpers/race.js
CHANGED
|
@@ -5,7 +5,9 @@ const safe_1 = require("./safe");
|
|
|
5
5
|
const DEFAULT_TIMEOUT = 5000;
|
|
6
6
|
async function race(promise) {
|
|
7
7
|
const timeOut = new Promise((resolve, reject) => {
|
|
8
|
-
setTimeout(() => {
|
|
8
|
+
setTimeout(() => {
|
|
9
|
+
reject("timeout");
|
|
10
|
+
}, DEFAULT_TIMEOUT);
|
|
9
11
|
});
|
|
10
12
|
const result = await (0, safe_1.safe)(Promise.race([promise, timeOut]));
|
|
11
13
|
if (result.success === true) {
|
package/dist/helpers/scrape.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
4
5
|
async function scrape(url) {
|
|
5
|
-
const response = await
|
|
6
|
+
const response = await (0, node_fetch_1.default)(url);
|
|
6
7
|
if (response.status !== 200) {
|
|
7
8
|
return null;
|
|
8
9
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.speedKitRuleToRegExp = void 0;
|
|
4
4
|
function escapeRegExp(str) {
|
|
5
|
-
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,
|
|
5
|
+
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
6
6
|
}
|
|
7
7
|
function speedKitRuleToRegExp(url) {
|
|
8
|
-
return new RegExp(`^${escapeRegExp(url).replace(/\\\*/g,
|
|
8
|
+
return new RegExp(`^${escapeRegExp(url).replace(/\\\*/g, ".*")}$`);
|
|
9
9
|
}
|
|
10
10
|
exports.speedKitRuleToRegExp = speedKitRuleToRegExp;
|
|
@@ -64,10 +64,10 @@ export declare enum CLIParametersExample {
|
|
|
64
64
|
VariationPath = "C:\\Users\\testUser\\variations.csv"
|
|
65
65
|
}
|
|
66
66
|
export declare const CLI_CONFIG_NAME: {
|
|
67
|
-
configName: import("@oclif/core/lib/interfaces
|
|
67
|
+
configName: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
68
68
|
};
|
|
69
69
|
export declare const CLI_CUSTOMER_CONFIG: {
|
|
70
|
-
customerPath: import("@oclif/core/lib/interfaces
|
|
70
|
+
customerPath: import("@oclif/core/lib/interfaces").Arg<string, {
|
|
71
71
|
exists?: boolean;
|
|
72
72
|
}>;
|
|
73
73
|
};
|
|
@@ -27,6 +27,7 @@ var CLIParameters;
|
|
|
27
27
|
CLIParameters["Variation"] = "variation";
|
|
28
28
|
CLIParameters["VariationPath"] = "variationPath";
|
|
29
29
|
})(CLIParameters || (exports.CLIParameters = CLIParameters = {}));
|
|
30
|
+
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
|
|
30
31
|
var CLIParametersChar;
|
|
31
32
|
(function (CLIParametersChar) {
|
|
32
33
|
CLIParametersChar["AppName"] = "a";
|
|
@@ -49,6 +50,7 @@ var CLIParametersChar;
|
|
|
49
50
|
CLIParametersChar["Variation"] = "v";
|
|
50
51
|
CLIParametersChar["VariationPath"] = "p";
|
|
51
52
|
})(CLIParametersChar || (exports.CLIParametersChar = CLIParametersChar = {}));
|
|
53
|
+
/* eslint-enable @typescript-eslint/no-duplicate-enum-values */
|
|
52
54
|
var CLIParametersExample;
|
|
53
55
|
(function (CLIParametersExample) {
|
|
54
56
|
CLIParametersExample["AppName"] = "decathlon";
|
|
@@ -71,12 +73,16 @@ var CLIParametersExample;
|
|
|
71
73
|
CLIParametersExample["VariationPath"] = "C:\\Users\\testUser\\variations.csv";
|
|
72
74
|
})(CLIParametersExample || (exports.CLIParametersExample = CLIParametersExample = {}));
|
|
73
75
|
exports.CLI_CONFIG_NAME = {
|
|
74
|
-
[CLIParameters.ConfigName]: core_1.Flags.string({
|
|
76
|
+
[CLIParameters.ConfigName]: core_1.Flags.string({
|
|
77
|
+
char: CLIParametersChar.ConfigName,
|
|
78
|
+
default: "production",
|
|
79
|
+
description: "The costumer config name",
|
|
80
|
+
}),
|
|
75
81
|
};
|
|
76
82
|
exports.CLI_CUSTOMER_CONFIG = {
|
|
77
83
|
[CLIParameters.CustomerPath]: core_1.Args.directory({
|
|
78
84
|
name: CLIParameters.CustomerPath, // name of arg to show in help and reference with args[name]
|
|
79
85
|
required: true, // make the arg required with `required: true`
|
|
80
|
-
description:
|
|
86
|
+
description: "The customer config path", // help description
|
|
81
87
|
}),
|
|
82
88
|
};
|