@speedkit/cli 2.14.0 → 2.14.2
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 +14 -0
- package/README.md +1 -1
- package/dist/services/onboarding/browser/baqend-response.d.ts +3 -3
- package/dist/services/onboarding/browser/baqend-response.js +13 -12
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +4 -4
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +38 -37
- package/dist/services/onboarding/dashboard/athena-service.d.ts +1 -1
- package/dist/services/onboarding/dashboard/athena-service.js +12 -12
- package/dist/services/onboarding/dashboard/index.d.ts +3 -3
- package/dist/services/onboarding/dashboard/index.js +14 -14
- package/dist/services/onboarding/dashboard/request-diff-service.d.ts +1 -1
- package/dist/services/onboarding/dashboard/request-diff-service.js +23 -23
- package/dist/services/onboarding/fetch-event-handler.d.ts +6 -6
- package/dist/services/onboarding/fetch-event-handler.js +52 -52
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +7 -7
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +43 -43
- package/dist/services/onboarding/fetch-events/customer-service-worker-js.d.ts +2 -2
- package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +4 -4
- package/dist/services/onboarding/fetch-events/dashboard-request.d.ts +1 -1
- package/dist/services/onboarding/fetch-events/dashboard-request.js +2 -2
- package/dist/services/onboarding/fetch-events/speed-kit-asset-request.d.ts +7 -7
- package/dist/services/onboarding/fetch-events/speed-kit-asset-request.js +27 -27
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +2 -2
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +12 -12
- package/dist/services/onboarding/file-events/file-watcher.d.ts +9 -9
- package/dist/services/onboarding/file-events/file-watcher.js +67 -67
- package/dist/services/onboarding/onboarding-service.d.ts +6 -6
- package/dist/services/onboarding/onboarding-service.js +38 -39
- package/dist/services/onboarding/request-cache/cache.d.ts +3 -3
- package/dist/services/onboarding/request-cache/cache.js +7 -7
- package/dist/services/onboarding/server-config/index.js +1 -1
- package/dist/services/onboarding/todo-collector.d.ts +1 -1
- package/dist/services/onboarding/todo-collector.js +3 -4
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.14.2](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.14.1...v2.14.2) (2024-03-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **onboarding:** do not minify installResource ([c426acd](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/c426acd27347b2ea349a73e530e1ea6070d80e77))
|
|
7
|
+
|
|
8
|
+
## [2.14.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.14.0...v2.14.1) (2024-03-20)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **onboarding:** undo perfectionist sorting ([db3ba2e](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/db3ba2ec7395ab84a7e795e5c10f3f463148a97c))
|
|
14
|
+
|
|
1
15
|
# [2.14.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.13.0...v2.14.0) (2024-03-18)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
2
|
export declare class BaqendResponse implements Partial<Protocol.Fetch.FulfillRequestRequest> {
|
|
3
|
-
readonly body: string;
|
|
4
3
|
readonly requestId?: string;
|
|
5
4
|
readonly responseCode: number;
|
|
5
|
+
readonly body: string;
|
|
6
6
|
responseHeaders: Protocol.Fetch.HeaderEntry[];
|
|
7
|
-
private contentLength;
|
|
8
7
|
private contentType;
|
|
8
|
+
private contentLength;
|
|
9
9
|
constructor(body: string, contentType?: string, headers?: Protocol.Fetch.HeaderEntry[], status?: number);
|
|
10
|
-
protected addCustomHeaders(headers?: Protocol.Fetch.HeaderEntry[]): Protocol.Fetch.HeaderEntry[];
|
|
11
10
|
setHeader(name: string, value: string): void;
|
|
11
|
+
protected addCustomHeaders(headers?: Protocol.Fetch.HeaderEntry[]): Protocol.Fetch.HeaderEntry[];
|
|
12
12
|
}
|
|
@@ -8,12 +8,12 @@ const DEFAULT_HEADERS = [
|
|
|
8
8
|
const DEFAULT_CONTENT_TYPE = "text/html; charset=utf-8";
|
|
9
9
|
const DEFAULT_STATUS = 200;
|
|
10
10
|
class BaqendResponse {
|
|
11
|
-
body;
|
|
12
11
|
requestId;
|
|
13
12
|
responseCode;
|
|
13
|
+
body;
|
|
14
14
|
responseHeaders;
|
|
15
|
-
contentLength;
|
|
16
15
|
contentType;
|
|
16
|
+
contentLength;
|
|
17
17
|
constructor(body, contentType, headers, status) {
|
|
18
18
|
this.responseCode = status || DEFAULT_STATUS;
|
|
19
19
|
this.contentType = contentType || DEFAULT_CONTENT_TYPE;
|
|
@@ -24,6 +24,15 @@ class BaqendResponse {
|
|
|
24
24
|
this.contentLength = body.length;
|
|
25
25
|
this.body = Buffer.from(body).toString("base64");
|
|
26
26
|
}
|
|
27
|
+
setHeader(name, value) {
|
|
28
|
+
for (const header of this.responseHeaders) {
|
|
29
|
+
if (header.name === name) {
|
|
30
|
+
header.value = value;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.responseHeaders.push({ name, value });
|
|
35
|
+
}
|
|
27
36
|
addCustomHeaders(headers) {
|
|
28
37
|
if (!headers?.find((o) => o.name === "Cache-Control")) {
|
|
29
38
|
headers.push({
|
|
@@ -44,17 +53,9 @@ class BaqendResponse {
|
|
|
44
53
|
if (!headers?.find((o) => o.name === "Content-Type")) {
|
|
45
54
|
headers.push({ name: "Content-Type", value: String(this.contentType) });
|
|
46
55
|
}
|
|
47
|
-
headers.push({ name: "via", value: "sk-onboarding" }
|
|
56
|
+
headers.push({ name: "via", value: "sk-onboarding" });
|
|
57
|
+
headers.push({ name: "Service-Worker-Allowed", value: "/" });
|
|
48
58
|
return headers;
|
|
49
59
|
}
|
|
50
|
-
setHeader(name, value) {
|
|
51
|
-
for (const header of this.responseHeaders) {
|
|
52
|
-
if (header.name === name) {
|
|
53
|
-
header.value = value;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
this.responseHeaders.push({ name, value });
|
|
58
|
-
}
|
|
59
60
|
}
|
|
60
61
|
exports.BaqendResponse = BaqendResponse;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { InstallSpeedKitJsTemplate } from "../templates/install-speed-kit-js-template";
|
|
2
|
+
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
1
3
|
import { BundleService } from "../../bundler";
|
|
2
4
|
import { FileListInterface } from "../../integration-api/integration-api-model";
|
|
3
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
4
|
-
import { InstallSpeedKitJsTemplate } from "../templates/install-speed-kit-js-template";
|
|
5
5
|
export declare class SpeedKitInstallContext {
|
|
6
6
|
private customerConfig;
|
|
7
7
|
private configName;
|
|
@@ -10,6 +10,8 @@ export declare class SpeedKitInstallContext {
|
|
|
10
10
|
private skTemplate;
|
|
11
11
|
private isLocalRuntime;
|
|
12
12
|
constructor(customerConfig: CustomerConfig, configName: string, files: FileListInterface, bundler: BundleService, skTemplate: InstallSpeedKitJsTemplate, isLocalRuntime?: boolean);
|
|
13
|
+
getSpeedKitInstallJs(): Promise<string>;
|
|
14
|
+
private getConfigSpeedKit;
|
|
13
15
|
/**
|
|
14
16
|
* Fetches and returns the latest dynamic fetcher from the code repository. If a new version is available online it is
|
|
15
17
|
* downloaded and cached, otherwise the fetcher id returned from cache. The resulting module gets minified afterwards.
|
|
@@ -17,6 +19,4 @@ export declare class SpeedKitInstallContext {
|
|
|
17
19
|
* @returns {Promise<string>} a Promise which resolves to the latest dynamic fetcher
|
|
18
20
|
*/
|
|
19
21
|
bundleDynamicFetcher(): Promise<string>;
|
|
20
|
-
private getConfigSpeedKit;
|
|
21
|
-
getSpeedKitInstallJs(): Promise<string>;
|
|
22
22
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SpeedKitInstallContext = void 0;
|
|
4
4
|
const files_1 = require("../../../models/files");
|
|
5
5
|
const IMPORT_PATHS = {
|
|
6
|
-
"predictive-preloading": "https://www.baqend.com/speed-kit-predictive-preloading/latest/",
|
|
7
6
|
rum: "https://www.baqend.com/rum/latest/",
|
|
8
7
|
"speed-kit": "https://www.baqend.com/speed-kit/latest/",
|
|
8
|
+
"predictive-preloading": "https://www.baqend.com/speed-kit-predictive-preloading/latest/",
|
|
9
9
|
};
|
|
10
10
|
class SpeedKitInstallContext {
|
|
11
11
|
customerConfig;
|
|
@@ -22,24 +22,33 @@ class SpeedKitInstallContext {
|
|
|
22
22
|
this.skTemplate = skTemplate;
|
|
23
23
|
this.isLocalRuntime = isLocalRuntime;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
async getSpeedKitInstallJs() {
|
|
26
|
+
const configJs = this.skTemplate.render({
|
|
27
|
+
config: this.getConfigSpeedKit(),
|
|
28
|
+
forceInstall: this.customerConfig.forceInstall,
|
|
29
|
+
installPath: this.customerConfig.installPath,
|
|
30
|
+
installParams: this.customerConfig.installParams,
|
|
31
|
+
domain: this.customerConfig.domain,
|
|
32
|
+
df: this.files
|
|
33
|
+
.getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
34
|
+
.getContent(),
|
|
35
|
+
});
|
|
32
36
|
return this.bundler.bundle({
|
|
33
|
-
basePaths:
|
|
37
|
+
basePaths: IMPORT_PATHS,
|
|
34
38
|
entryPoints: {
|
|
35
|
-
"
|
|
36
|
-
.getByName(files_1.INTEGRATION_FILES.
|
|
39
|
+
"rum.js": this.files
|
|
40
|
+
.getByName(files_1.INTEGRATION_FILES.CONFIG.LOAD_HANDLER)
|
|
41
|
+
.getContent(),
|
|
42
|
+
"config.js": configJs,
|
|
43
|
+
"loader.js": this.files
|
|
44
|
+
.getByName(files_1.INTEGRATION_FILES.CUSTOM.LOADER)
|
|
37
45
|
.getContent(),
|
|
38
46
|
},
|
|
39
|
-
logLevel: "
|
|
47
|
+
logLevel: "error",
|
|
40
48
|
minify: false,
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
define: {
|
|
50
|
+
APP: JSON.stringify(this.customerConfig.app),
|
|
51
|
+
},
|
|
43
52
|
});
|
|
44
53
|
}
|
|
45
54
|
getConfigSpeedKit() {
|
|
@@ -50,7 +59,7 @@ class SpeedKitInstallContext {
|
|
|
50
59
|
return configString;
|
|
51
60
|
}
|
|
52
61
|
if (configString.includes("delayRacedOrigin")) {
|
|
53
|
-
return configString.replace(/delayRacedOrigin:[
|
|
62
|
+
return configString.replace(/delayRacedOrigin:[^,|\d](\d*)[^,]*,/, (config, value) => {
|
|
54
63
|
return config.replace(value, "100");
|
|
55
64
|
});
|
|
56
65
|
}
|
|
@@ -58,32 +67,24 @@ class SpeedKitInstallContext {
|
|
|
58
67
|
return configOpenTag + `\n delayRacedOrigin: 100,\n`;
|
|
59
68
|
});
|
|
60
69
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
df: this.files
|
|
69
|
-
.getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
70
|
-
.getContent(),
|
|
71
|
-
});
|
|
70
|
+
/**
|
|
71
|
+
* Fetches and returns the latest dynamic fetcher from the code repository. If a new version is available online it is
|
|
72
|
+
* downloaded and cached, otherwise the fetcher id returned from cache. The resulting module gets minified afterwards.
|
|
73
|
+
*
|
|
74
|
+
* @returns {Promise<string>} a Promise which resolves to the latest dynamic fetcher
|
|
75
|
+
*/
|
|
76
|
+
async bundleDynamicFetcher() {
|
|
72
77
|
return this.bundler.bundle({
|
|
73
|
-
basePaths:
|
|
74
|
-
define: {
|
|
75
|
-
APP: JSON.stringify(this.customerConfig.app),
|
|
76
|
-
},
|
|
78
|
+
basePaths: {},
|
|
77
79
|
entryPoints: {
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
.getByName(files_1.INTEGRATION_FILES.CUSTOM.LOADER)
|
|
81
|
-
.getContent(),
|
|
82
|
-
"rum.js": this.files
|
|
83
|
-
.getByName(files_1.INTEGRATION_FILES.CONFIG.LOAD_HANDLER)
|
|
80
|
+
"dynamicFetcher.js": this.files
|
|
81
|
+
.getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
84
82
|
.getContent(),
|
|
85
83
|
},
|
|
86
|
-
|
|
84
|
+
target: "es6",
|
|
85
|
+
logLevel: "verbose",
|
|
86
|
+
minify: false,
|
|
87
|
+
platform: "browser",
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AthenaService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const safe_1 = require("../../../helpers/safe");
|
|
5
|
+
const util_1 = tslib_1.__importDefault(require("util"));
|
|
7
6
|
const cli_1 = require("../../cli");
|
|
8
|
-
const
|
|
7
|
+
const safe_1 = require("../../../helpers/safe");
|
|
8
|
+
const sleep = util_1.default.promisify(setTimeout);
|
|
9
9
|
class AthenaService {
|
|
10
10
|
athena;
|
|
11
11
|
cli;
|
|
@@ -19,10 +19,10 @@ class AthenaService {
|
|
|
19
19
|
return this.lastQueryResult;
|
|
20
20
|
}
|
|
21
21
|
const params = {
|
|
22
|
+
QueryString: queryString,
|
|
22
23
|
QueryExecutionContext: {
|
|
23
24
|
Database: "rum.pi",
|
|
24
25
|
},
|
|
25
|
-
QueryString: queryString,
|
|
26
26
|
};
|
|
27
27
|
this.cli.startAction("[athena-query]: fetch result");
|
|
28
28
|
const result = await (0, safe_1.safe)(this.fetchResult(params));
|
|
@@ -34,9 +34,6 @@ class AthenaService {
|
|
|
34
34
|
this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
|
|
35
35
|
this.cli.writeError(result.error);
|
|
36
36
|
}
|
|
37
|
-
getLastQueryResult() {
|
|
38
|
-
return this.lastQueryResult;
|
|
39
|
-
}
|
|
40
37
|
async fetchResult(params) {
|
|
41
38
|
const request = await this.athena.startQueryExecution(params);
|
|
42
39
|
let queryStatus = await this.athena.getQueryExecution({
|
|
@@ -56,20 +53,23 @@ class AthenaService {
|
|
|
56
53
|
const queryResult = await this.athena.getQueryResults(queryParams);
|
|
57
54
|
// transform result and return it
|
|
58
55
|
const dataArray = [];
|
|
59
|
-
|
|
56
|
+
queryResult.ResultSet.Rows.forEach((recordRow) => {
|
|
60
57
|
const object = {
|
|
61
|
-
|
|
58
|
+
params: recordRow.Data[0].VarCharValue,
|
|
59
|
+
potentialGain: recordRow.Data[1].VarCharValue,
|
|
62
60
|
cachedUrls: recordRow.Data[2].VarCharValue,
|
|
61
|
+
PIs: recordRow.Data[3].VarCharValue,
|
|
63
62
|
example1: recordRow.Data[4].VarCharValue,
|
|
64
63
|
example2: recordRow.Data[5].VarCharValue,
|
|
65
64
|
example3: recordRow.Data[6].VarCharValue,
|
|
66
|
-
params: recordRow.Data[0].VarCharValue,
|
|
67
|
-
potentialGain: recordRow.Data[1].VarCharValue,
|
|
68
65
|
};
|
|
69
66
|
// into an array....
|
|
70
67
|
dataArray.push(object);
|
|
71
|
-
}
|
|
68
|
+
});
|
|
72
69
|
return dataArray;
|
|
73
70
|
}
|
|
71
|
+
getLastQueryResult() {
|
|
72
|
+
return this.lastQueryResult;
|
|
73
|
+
}
|
|
74
74
|
}
|
|
75
75
|
exports.AthenaService = AthenaService;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { BaqendResponse } from "../browser/baqend-response";
|
|
1
2
|
import { Protocol } from "devtools-protocol";
|
|
3
|
+
import { ParamQueryBuilder } from "./param-query-builder";
|
|
2
4
|
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
3
|
-
import { BaqendResponse } from "../browser/baqend-response";
|
|
4
|
-
import { Cache } from "../request-cache/cache";
|
|
5
5
|
import { AthenaService } from "./athena-service";
|
|
6
|
-
import { ParamQueryBuilder } from "./param-query-builder";
|
|
7
6
|
import { RequestDiffService } from "./request-diff-service";
|
|
7
|
+
import { Cache } from "../request-cache/cache";
|
|
8
8
|
export declare class Dashboard {
|
|
9
9
|
private customerConfig;
|
|
10
10
|
private paramQueryBuilder;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Dashboard = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const json2csv_1 = tslib_1.__importDefault(require("json2csv"));
|
|
6
|
-
const node_fs_1 = require("node:fs");
|
|
7
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
|
-
const safe_1 = require("../../../helpers/safe");
|
|
9
5
|
const baqend_response_1 = require("../browser/baqend-response");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const safe_1 = require("../../../helpers/safe");
|
|
9
|
+
const json2csv_1 = tslib_1.__importDefault(require("json2csv"));
|
|
10
10
|
class Dashboard {
|
|
11
11
|
customerConfig;
|
|
12
12
|
paramQueryBuilder;
|
|
@@ -23,13 +23,13 @@ class Dashboard {
|
|
|
23
23
|
async getResponse(request) {
|
|
24
24
|
const url = new URL(request.url);
|
|
25
25
|
if (url.pathname === "/") {
|
|
26
|
-
const filePath =
|
|
27
|
-
const content = (0,
|
|
26
|
+
const filePath = path_1.default.join(__dirname, "./frontend-dist", "index.html");
|
|
27
|
+
const content = (0, fs_1.readFileSync)(filePath, { encoding: "utf-8" });
|
|
28
28
|
return new baqend_response_1.BaqendResponse(content);
|
|
29
29
|
}
|
|
30
30
|
if (url.pathname.startsWith("/assets/")) {
|
|
31
|
-
const filePath =
|
|
32
|
-
const content = (0,
|
|
31
|
+
const filePath = path_1.default.join(__dirname, "./frontend-dist", url.pathname);
|
|
32
|
+
const content = (0, fs_1.readFileSync)(filePath, { encoding: "utf-8" });
|
|
33
33
|
let contentType = "application/javascript; charset=UTF-8";
|
|
34
34
|
if (url.pathname.includes(".css")) {
|
|
35
35
|
contentType = "text/css";
|
|
@@ -40,7 +40,7 @@ class Dashboard {
|
|
|
40
40
|
return new baqend_response_1.BaqendResponse(JSON.stringify({ query: this.paramQueryBuilder.getQuery() }), "application/json; charset=UTF-8");
|
|
41
41
|
}
|
|
42
42
|
if (url.pathname.startsWith("/query/execute")) {
|
|
43
|
-
const
|
|
43
|
+
const postData = request.postData;
|
|
44
44
|
const data = JSON.parse(postData);
|
|
45
45
|
const response = await (0, safe_1.safe)(this.athenaClient.executeQuery(data.query));
|
|
46
46
|
if (response.success === true) {
|
|
@@ -73,15 +73,15 @@ class Dashboard {
|
|
|
73
73
|
return new baqend_response_1.BaqendResponse(JSON.stringify(this.customerConfig), "application/json; charset=UTF-8");
|
|
74
74
|
}
|
|
75
75
|
if (url.pathname.startsWith("/diff")) {
|
|
76
|
-
const
|
|
76
|
+
const postData = request.postData;
|
|
77
77
|
const data = JSON.parse(postData);
|
|
78
|
-
return this.requestDiffService.postDiff(data.url, data.params);
|
|
78
|
+
return await this.requestDiffService.postDiff(data.url, data.params);
|
|
79
79
|
}
|
|
80
80
|
if (url.pathname.startsWith("/cache/get")) {
|
|
81
81
|
const response = [];
|
|
82
|
-
|
|
83
|
-
response.push({ response: baqendResponse
|
|
84
|
-
}
|
|
82
|
+
Array.from(this.cache.getAll()).forEach(([url, baqendResponse]) => {
|
|
83
|
+
response.push({ url, response: baqendResponse });
|
|
84
|
+
});
|
|
85
85
|
return new baqend_response_1.BaqendResponse(JSON.stringify(response), "application/json; charset=UTF-8");
|
|
86
86
|
}
|
|
87
87
|
return new baqend_response_1.BaqendResponse("Not implemented");
|
|
@@ -4,8 +4,8 @@ export declare class RequestDiffService {
|
|
|
4
4
|
private diffService;
|
|
5
5
|
constructor(diffService: DiffService);
|
|
6
6
|
postDiff(url: string, parametersString: string): Promise<BaqendResponse>;
|
|
7
|
-
private createUrlsForDiff;
|
|
8
7
|
private diffLocal;
|
|
9
8
|
private doOriginVsContentDiff;
|
|
10
9
|
private fetchHtml;
|
|
10
|
+
private createUrlsForDiff;
|
|
11
11
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequestDiffService = void 0;
|
|
4
|
-
const safe_1 = require("../../../helpers/safe");
|
|
5
4
|
const baqend_response_1 = require("../browser/baqend-response");
|
|
5
|
+
const safe_1 = require("../../../helpers/safe");
|
|
6
6
|
class RequestDiffService {
|
|
7
7
|
diffService;
|
|
8
8
|
constructor(diffService) {
|
|
@@ -19,17 +19,34 @@ class RequestDiffService {
|
|
|
19
19
|
const { urlWithParam, urlWithoutParam } = this.createUrlsForDiff(url, params);
|
|
20
20
|
const result = await (0, safe_1.safe)(this.diffLocal(urlWithParam, urlWithoutParam));
|
|
21
21
|
if (result.success === true) {
|
|
22
|
-
return new baqend_response_1.BaqendResponse(JSON.stringify({ isIdentical: result.data
|
|
22
|
+
return new baqend_response_1.BaqendResponse(JSON.stringify({ status: "success", isIdentical: result.data }), "application/json; charset=UTF-8");
|
|
23
23
|
}
|
|
24
|
-
return new baqend_response_1.BaqendResponse(JSON.stringify({
|
|
24
|
+
return new baqend_response_1.BaqendResponse(JSON.stringify({ status: "error", error: result.error }), "application/json; charset=UTF-8", null, 500);
|
|
25
|
+
}
|
|
26
|
+
async diffLocal(urlWithParam, urlWithoutParam) {
|
|
27
|
+
const htmlWithParam = await this.fetchHtml(urlWithParam);
|
|
28
|
+
const htmlWithoutParam = await this.fetchHtml(urlWithoutParam);
|
|
29
|
+
const paramsFilePath = await this.diffService.writeContentToTemporalFile("params", htmlWithParam);
|
|
30
|
+
const pureFilePath = await this.diffService.writeContentToTemporalFile("pure", htmlWithoutParam);
|
|
31
|
+
return await this.diffService.executeDiff(paramsFilePath, pureFilePath);
|
|
32
|
+
}
|
|
33
|
+
async doOriginVsContentDiff(url, content) {
|
|
34
|
+
const html = await this.fetchHtml(url);
|
|
35
|
+
const origin = await this.diffService.writeContentToTemporalFile("origin", html);
|
|
36
|
+
const local = await this.diffService.writeContentToTemporalFile("content", content);
|
|
37
|
+
return await this.diffService.executeDiff(local, origin);
|
|
38
|
+
}
|
|
39
|
+
async fetchHtml(url) {
|
|
40
|
+
const response = await fetch(url);
|
|
41
|
+
return await response.text();
|
|
25
42
|
}
|
|
26
43
|
createUrlsForDiff(urlWithParam, params) {
|
|
27
44
|
const url = new URL(urlWithParam);
|
|
28
|
-
const
|
|
45
|
+
const search_params = url.searchParams;
|
|
29
46
|
for (const param of params) {
|
|
30
|
-
|
|
47
|
+
search_params.delete(param);
|
|
31
48
|
}
|
|
32
|
-
url.search =
|
|
49
|
+
url.search = search_params.toString();
|
|
33
50
|
const urlWithoutParam = url.toString();
|
|
34
51
|
console.log("With-----");
|
|
35
52
|
console.log(urlWithParam);
|
|
@@ -42,22 +59,5 @@ class RequestDiffService {
|
|
|
42
59
|
urlWithoutParam,
|
|
43
60
|
};
|
|
44
61
|
}
|
|
45
|
-
async diffLocal(urlWithParam, urlWithoutParam) {
|
|
46
|
-
const htmlWithParam = await this.fetchHtml(urlWithParam);
|
|
47
|
-
const htmlWithoutParam = await this.fetchHtml(urlWithoutParam);
|
|
48
|
-
const paramsFilePath = await this.diffService.writeContentToTemporalFile("params", htmlWithParam);
|
|
49
|
-
const pureFilePath = await this.diffService.writeContentToTemporalFile("pure", htmlWithoutParam);
|
|
50
|
-
return this.diffService.executeDiff(paramsFilePath, pureFilePath);
|
|
51
|
-
}
|
|
52
|
-
async doOriginVsContentDiff(url, content) {
|
|
53
|
-
const html = await this.fetchHtml(url);
|
|
54
|
-
const origin = await this.diffService.writeContentToTemporalFile("origin", html);
|
|
55
|
-
const local = await this.diffService.writeContentToTemporalFile("content", content);
|
|
56
|
-
return this.diffService.executeDiff(local, origin);
|
|
57
|
-
}
|
|
58
|
-
async fetchHtml(url) {
|
|
59
|
-
const response = await fetch(url);
|
|
60
|
-
return response.text();
|
|
61
|
-
}
|
|
62
62
|
}
|
|
63
63
|
exports.RequestDiffService = RequestDiffService;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FetchRequestPausedEventHandler } from "./onboarding-model";
|
|
2
2
|
import { Protocol } from "puppeteer-core";
|
|
3
|
+
import { CDPSession, Target } from "puppeteer";
|
|
3
4
|
import { CliService } from "../cli";
|
|
4
|
-
import ConfigApiService from "../config-api/config-api-service";
|
|
5
5
|
import CustomerConfig from "../integration-api/struct/customer-config";
|
|
6
|
-
import
|
|
6
|
+
import ConfigApiService from "../config-api/config-api-service";
|
|
7
7
|
export declare class FetchEventHandler {
|
|
8
8
|
private browserFetchEvents;
|
|
9
9
|
private customerConfig;
|
|
10
10
|
private cli;
|
|
11
11
|
private client?;
|
|
12
12
|
constructor(browserFetchEvents: FetchRequestPausedEventHandler[], customerConfig: CustomerConfig, cli: CliService, client?: ConfigApiService);
|
|
13
|
-
getAuthPattern(): Protocol.Fetch.RequestPattern[];
|
|
14
13
|
handleRequestFetchEvents(target: Target): Promise<void>;
|
|
15
|
-
sendDefaultAuthBehaviour(browserClient: CDPSession, requestId: string): Promise<void>;
|
|
16
14
|
private canHandlePattern;
|
|
17
|
-
private onFetchAuthRequired;
|
|
18
15
|
private onFetchRequestPaused;
|
|
16
|
+
getAuthPattern(): Protocol.Fetch.RequestPattern[];
|
|
17
|
+
private onFetchAuthRequired;
|
|
18
|
+
sendDefaultAuthBehaviour(browserClient: CDPSession, requestId: string): Promise<void>;
|
|
19
19
|
}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FetchEventHandler = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const puppeteer_core_1 = require("puppeteer-core");
|
|
6
|
-
const
|
|
6
|
+
const abort_response_1 = require("./browser/abort-response");
|
|
7
7
|
const cli_1 = require("../cli");
|
|
8
8
|
const login_error_1 = tslib_1.__importDefault(require("../config-api/error/login-error"));
|
|
9
|
-
const
|
|
9
|
+
const safe_1 = require("../../helpers/safe");
|
|
10
10
|
class FetchEventHandler {
|
|
11
11
|
browserFetchEvents;
|
|
12
12
|
customerConfig;
|
|
@@ -18,24 +18,11 @@ class FetchEventHandler {
|
|
|
18
18
|
this.cli = cli;
|
|
19
19
|
this.client = client;
|
|
20
20
|
}
|
|
21
|
-
getAuthPattern() {
|
|
22
|
-
const result = [];
|
|
23
|
-
for (const origin of this.customerConfig.origins) {
|
|
24
|
-
const pattern = [
|
|
25
|
-
{
|
|
26
|
-
requestStage: "Request",
|
|
27
|
-
urlPattern: `${origin}*`,
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
result.push(...pattern);
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
21
|
async handleRequestFetchEvents(target) {
|
|
35
22
|
const browserClient = await target.createCDPSession();
|
|
36
23
|
await browserClient.send("Fetch.enable", {
|
|
37
24
|
handleAuthRequests: true,
|
|
38
|
-
//
|
|
25
|
+
//see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
|
|
39
26
|
patterns: [
|
|
40
27
|
...this.browserFetchEvents.flatMap((handler) => {
|
|
41
28
|
return handler.patterns;
|
|
@@ -64,14 +51,6 @@ class FetchEventHandler {
|
|
|
64
51
|
this.cli.writeError(JSON.stringify(response.errorObj));
|
|
65
52
|
});
|
|
66
53
|
}
|
|
67
|
-
async sendDefaultAuthBehaviour(browserClient, requestId) {
|
|
68
|
-
await browserClient.send("Fetch.continueWithAuth", {
|
|
69
|
-
authChallengeResponse: {
|
|
70
|
-
response: "Default",
|
|
71
|
-
},
|
|
72
|
-
requestId,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
54
|
canHandlePattern(fetchEventHandler, url, resourceType, requestStage) {
|
|
76
55
|
return fetchEventHandler.patterns.some((pattern) => {
|
|
77
56
|
if (!new RegExp(pattern.urlPattern).test(url)) {
|
|
@@ -83,6 +62,48 @@ class FetchEventHandler {
|
|
|
83
62
|
return !pattern.resourceType || pattern.resourceType === resourceType;
|
|
84
63
|
});
|
|
85
64
|
}
|
|
65
|
+
async onFetchRequestPaused(event, browserClient) {
|
|
66
|
+
const requestId = event.requestId;
|
|
67
|
+
for (const fetchEvent of this.browserFetchEvents) {
|
|
68
|
+
// check if current request could be handled
|
|
69
|
+
if (!this.canHandlePattern(fetchEvent, event.request.url, event.resourceType, event.responseHeaders ? "Response" : "Request")) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const response = await fetchEvent.handle(event, browserClient);
|
|
73
|
+
if (!response) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (response instanceof abort_response_1.AbortResponse) {
|
|
77
|
+
await browserClient.send("Fetch.failRequest", {
|
|
78
|
+
requestId: requestId,
|
|
79
|
+
errorReason: response.errorReason,
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await browserClient.send("Fetch.fulfillRequest", {
|
|
84
|
+
...response,
|
|
85
|
+
requestId,
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
//see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest
|
|
90
|
+
await browserClient.send("Fetch.continueRequest", {
|
|
91
|
+
requestId: requestId,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getAuthPattern() {
|
|
95
|
+
const result = [];
|
|
96
|
+
for (const origin of this.customerConfig.origins) {
|
|
97
|
+
const pattern = [
|
|
98
|
+
{
|
|
99
|
+
urlPattern: `${origin}*`,
|
|
100
|
+
requestStage: "Request",
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
result.push(...pattern);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
86
107
|
async onFetchAuthRequired(event, browserClient) {
|
|
87
108
|
this.cli.writeWarning(`auth requested for ${event.request.url}`);
|
|
88
109
|
if (!this.customerConfig.origins.some((origin) => {
|
|
@@ -101,12 +122,12 @@ class FetchEventHandler {
|
|
|
101
122
|
if (auth.uri.includes(authUrlOrigin) &&
|
|
102
123
|
auth.type === event.authChallenge.scheme) {
|
|
103
124
|
await browserClient.send("Fetch.continueWithAuth", {
|
|
125
|
+
requestId: event.requestId,
|
|
104
126
|
authChallengeResponse: {
|
|
105
|
-
password: auth.password,
|
|
106
127
|
response: "ProvideCredentials",
|
|
107
128
|
username: auth.user,
|
|
129
|
+
password: auth.password,
|
|
108
130
|
},
|
|
109
|
-
requestId: event.requestId,
|
|
110
131
|
});
|
|
111
132
|
this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
|
|
112
133
|
this.cli.writeSuccess(`auth provided for ${event.request.url}`);
|
|
@@ -132,33 +153,12 @@ class FetchEventHandler {
|
|
|
132
153
|
this.cli.writeError(`error providing auth: ${JSON.stringify(serverConfigResponse.errorObj)}`);
|
|
133
154
|
await this.sendDefaultAuthBehaviour(browserClient, event.requestId);
|
|
134
155
|
}
|
|
135
|
-
async
|
|
136
|
-
|
|
137
|
-
for (const fetchEvent of this.browserFetchEvents) {
|
|
138
|
-
// check if current request could be handled
|
|
139
|
-
if (!this.canHandlePattern(fetchEvent, requestUrl, resourceType, responseHeaders ? "Response" : "Request")) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
const response = await fetchEvent.handle(event, browserClient);
|
|
143
|
-
if (!response) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
if (response instanceof abort_response_1.AbortResponse) {
|
|
147
|
-
await browserClient.send("Fetch.failRequest", {
|
|
148
|
-
errorReason: response.errorReason,
|
|
149
|
-
requestId,
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
await browserClient.send("Fetch.fulfillRequest", {
|
|
154
|
-
...response,
|
|
155
|
-
requestId,
|
|
156
|
-
});
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
// see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest
|
|
160
|
-
await browserClient.send("Fetch.continueRequest", {
|
|
156
|
+
async sendDefaultAuthBehaviour(browserClient, requestId) {
|
|
157
|
+
await browserClient.send("Fetch.continueWithAuth", {
|
|
161
158
|
requestId,
|
|
159
|
+
authChallengeResponse: {
|
|
160
|
+
response: "Default",
|
|
161
|
+
},
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
}
|