@speedkit/cli 2.14.0 → 2.14.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.
- package/CHANGELOG.md +7 -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 -38
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
+
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
3
|
+
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
2
4
|
import { CDPSession } from "puppeteer";
|
|
3
5
|
import { ConfigFileInterface } from "../../integration-api/integration-api-model";
|
|
4
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
5
|
-
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
6
6
|
/**
|
|
7
7
|
* Intercepts any request to the customersOrigin and equivalent requests to baqendAssetApi
|
|
8
8
|
* @implements {FetchRequestPausedEventHandler}
|
|
@@ -11,14 +11,14 @@ export declare class CustomerDomainDocumentResponse implements FetchRequestPause
|
|
|
11
11
|
private customerConfig;
|
|
12
12
|
private configDynamicBlock;
|
|
13
13
|
private configDynamicStyles;
|
|
14
|
-
constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
|
|
15
14
|
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
15
|
+
constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
|
|
16
16
|
handle(event: Protocol.Fetch.RequestPausedEvent, client: CDPSession): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | void>;
|
|
17
|
-
private getHtmlContent;
|
|
18
|
-
private isHtmlContentHeader;
|
|
19
|
-
private isSpeedKitResponse;
|
|
20
17
|
private isValidHtmlContent;
|
|
21
18
|
private isValidResponse;
|
|
22
|
-
private
|
|
19
|
+
private isHtmlContentHeader;
|
|
20
|
+
private getHtmlContent;
|
|
21
|
+
private isSpeedKitResponse;
|
|
23
22
|
private rewriteInstallResource;
|
|
23
|
+
private rewriteHtmlToLocalConfig;
|
|
24
24
|
}
|
|
@@ -10,45 +10,45 @@ class CustomerDomainDocumentResponse {
|
|
|
10
10
|
customerConfig;
|
|
11
11
|
configDynamicBlock;
|
|
12
12
|
configDynamicStyles;
|
|
13
|
-
constructor(customerConfig, configDynamicBlock, configDynamicStyles) {
|
|
14
|
-
this.customerConfig = customerConfig;
|
|
15
|
-
this.configDynamicBlock = configDynamicBlock;
|
|
16
|
-
this.configDynamicStyles = configDynamicStyles;
|
|
17
|
-
}
|
|
18
13
|
get patterns() {
|
|
19
14
|
const result = [];
|
|
20
15
|
for (const origin of this.customerConfig.origins) {
|
|
21
16
|
const pattern = [
|
|
22
17
|
{
|
|
23
|
-
requestStage: "Response",
|
|
24
|
-
resourceType: "Document",
|
|
25
18
|
urlPattern: `${origin}*`,
|
|
19
|
+
resourceType: "Document",
|
|
20
|
+
requestStage: "Response",
|
|
26
21
|
},
|
|
27
22
|
{
|
|
28
|
-
requestStage: "Response",
|
|
29
|
-
resourceType: "Fetch",
|
|
30
23
|
urlPattern: `${origin}*`,
|
|
24
|
+
resourceType: "Fetch",
|
|
25
|
+
requestStage: "Response",
|
|
31
26
|
},
|
|
32
27
|
{
|
|
33
|
-
requestStage: "Response",
|
|
34
|
-
resourceType: "XHR",
|
|
35
28
|
urlPattern: `${origin}*`,
|
|
29
|
+
resourceType: "XHR",
|
|
30
|
+
requestStage: "Response",
|
|
36
31
|
},
|
|
37
32
|
{
|
|
38
|
-
requestStage: "Response",
|
|
39
|
-
resourceType: "Fetch",
|
|
40
33
|
urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
|
|
34
|
+
resourceType: "Fetch",
|
|
35
|
+
requestStage: "Response",
|
|
41
36
|
},
|
|
42
37
|
{
|
|
43
|
-
requestStage: "Response",
|
|
44
|
-
resourceType: "XHR",
|
|
45
38
|
urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
|
|
39
|
+
resourceType: "XHR",
|
|
40
|
+
requestStage: "Response",
|
|
46
41
|
},
|
|
47
42
|
];
|
|
48
43
|
result.push(...pattern);
|
|
49
44
|
}
|
|
50
45
|
return result;
|
|
51
46
|
}
|
|
47
|
+
constructor(customerConfig, configDynamicBlock, configDynamicStyles) {
|
|
48
|
+
this.customerConfig = customerConfig;
|
|
49
|
+
this.configDynamicBlock = configDynamicBlock;
|
|
50
|
+
this.configDynamicStyles = configDynamicStyles;
|
|
51
|
+
}
|
|
52
52
|
async handle(event, client) {
|
|
53
53
|
if (!this.isValidResponse(event)) {
|
|
54
54
|
return;
|
|
@@ -68,53 +68,53 @@ class CustomerDomainDocumentResponse {
|
|
|
68
68
|
}
|
|
69
69
|
return new origin_response_1.OriginResponse(text, event.responseHeaders, event.responseStatusCode);
|
|
70
70
|
}
|
|
71
|
+
isValidHtmlContent(text) {
|
|
72
|
+
return text.includes("<html");
|
|
73
|
+
}
|
|
74
|
+
isValidResponse(event) {
|
|
75
|
+
return (event.responseHeaders &&
|
|
76
|
+
event.responseStatusCode &&
|
|
77
|
+
event.responseStatusCode > 199 &&
|
|
78
|
+
event.responseStatusCode < 300);
|
|
79
|
+
}
|
|
80
|
+
isHtmlContentHeader(responseHeaders) {
|
|
81
|
+
const contentType = responseHeaders.filter((headerRecord) => {
|
|
82
|
+
return headerRecord.name.toLowerCase() === "content-type";
|
|
83
|
+
})?.[0]?.["value"];
|
|
84
|
+
return contentType && contentType.includes("text/html");
|
|
85
|
+
}
|
|
71
86
|
async getHtmlContent(client, event) {
|
|
72
|
-
const contentType = event.responseHeaders.
|
|
87
|
+
const contentType = event.responseHeaders.filter((headerRecord) => {
|
|
73
88
|
return headerRecord.name.toLowerCase() === "content-type";
|
|
74
|
-
})?.value || "";
|
|
89
|
+
})?.[0]?.["value"] || "";
|
|
75
90
|
const charset = contentType.split("charset=")?.[1];
|
|
76
|
-
const {
|
|
91
|
+
const { body, base64Encoded } = await client.send("Fetch.getResponseBody", {
|
|
77
92
|
requestId: event.requestId,
|
|
78
93
|
});
|
|
79
94
|
if (base64Encoded) {
|
|
80
95
|
// todo get encodingHeader for target encoding
|
|
81
|
-
return Buffer.from(body, "base64").toString(charset || "
|
|
96
|
+
return Buffer.from(body, "base64").toString(charset || "utf-8");
|
|
82
97
|
}
|
|
83
98
|
return body;
|
|
84
99
|
}
|
|
85
|
-
isHtmlContentHeader(responseHeaders) {
|
|
86
|
-
const contentType = responseHeaders.find((headerRecord) => {
|
|
87
|
-
return headerRecord.name.toLowerCase() === "content-type";
|
|
88
|
-
})?.value;
|
|
89
|
-
return contentType && contentType.includes("text/html");
|
|
90
|
-
}
|
|
91
100
|
isSpeedKitResponse(text) {
|
|
92
101
|
return text.includes("speed-kit-dynamic");
|
|
93
102
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
event.responseStatusCode &&
|
|
100
|
-
event.responseStatusCode > 199 &&
|
|
101
|
-
event.responseStatusCode < 300);
|
|
103
|
+
rewriteInstallResource(text) {
|
|
104
|
+
text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
|
|
105
|
+
return text.replace(/<\s*head\b[^>]*>/, (head) => {
|
|
106
|
+
return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
|
|
107
|
+
});
|
|
102
108
|
}
|
|
103
109
|
rewriteHtmlToLocalConfig(html) {
|
|
104
|
-
const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\S
|
|
105
|
-
const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\S
|
|
106
|
-
html = html.
|
|
110
|
+
const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\s\S]*?)(<\/script>)/g;
|
|
111
|
+
const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\s\S])*(<\/style>)/g;
|
|
112
|
+
html = html.replace(DF_CONFIG_PATTERN, (_, tag, body, end) => {
|
|
107
113
|
const injectedConfig = body.match(/window\.dynamicBlockConfig\.appName\s=.*$/s) ?? [""];
|
|
108
114
|
return `${tag}${this.configDynamicBlock.getContent()}${injectedConfig[0]}${end}`;
|
|
109
115
|
});
|
|
110
|
-
html = html.
|
|
116
|
+
html = html.replace(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
|
|
111
117
|
return html;
|
|
112
118
|
}
|
|
113
|
-
rewriteInstallResource(text) {
|
|
114
|
-
text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
|
|
115
|
-
return text.replace(/<\s*head\b[^>]*>/, (head) => {
|
|
116
|
-
return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
119
|
}
|
|
120
120
|
exports.CustomerDomainDocumentResponse = CustomerDomainDocumentResponse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
3
2
|
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
3
|
+
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
4
4
|
/**
|
|
5
5
|
* Intercepts request to /wrapper-sw.js
|
|
6
6
|
*
|
|
@@ -8,7 +8,7 @@ import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class CustomerServiceWorkerJs implements FetchRequestPausedEventHandler {
|
|
10
10
|
private customerConfig;
|
|
11
|
-
constructor(customerConfig: CustomerConfig);
|
|
12
11
|
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
12
|
+
constructor(customerConfig: CustomerConfig);
|
|
13
13
|
handle(): Promise<Partial<Protocol.Fetch.FulfillRequestRequest>>;
|
|
14
14
|
}
|
|
@@ -9,19 +9,19 @@ const baqend_response_1 = require("../browser/baqend-response");
|
|
|
9
9
|
*/
|
|
10
10
|
class CustomerServiceWorkerJs {
|
|
11
11
|
customerConfig;
|
|
12
|
-
constructor(customerConfig) {
|
|
13
|
-
this.customerConfig = customerConfig;
|
|
14
|
-
}
|
|
15
12
|
get patterns() {
|
|
16
13
|
const result = [];
|
|
17
14
|
for (const origin of this.customerConfig.origins) {
|
|
18
15
|
result.push({
|
|
19
|
-
requestStage: "Request",
|
|
20
16
|
urlPattern: `${origin}${this.customerConfig.swPath}*`,
|
|
17
|
+
requestStage: "Request",
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
20
|
return result;
|
|
24
21
|
}
|
|
22
|
+
constructor(customerConfig) {
|
|
23
|
+
this.customerConfig = customerConfig;
|
|
24
|
+
}
|
|
25
25
|
async handle() {
|
|
26
26
|
const wrapperSwCode = `importScripts(\`https://${this.customerConfig.appDomain}/v1/speedkit/sw.js\${location.search}\`); // skonboarding`;
|
|
27
27
|
return new baqend_response_1.BaqendResponse(wrapperSwCode, "text/javascript; charset=utf-8");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
-
import { Dashboard } from "../dashboard";
|
|
3
2
|
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
3
|
+
import { Dashboard } from "../dashboard";
|
|
4
4
|
/**
|
|
5
5
|
* The DashboardRequest class represents a request handler for the dashboard.
|
|
6
6
|
* Handle all the requests on the secondTab(http://skonboarding.local)
|
|
@@ -11,12 +11,12 @@ class DashboardRequest {
|
|
|
11
11
|
dashboard;
|
|
12
12
|
patterns = [
|
|
13
13
|
{
|
|
14
|
-
requestStage: "Request",
|
|
15
14
|
urlPattern: `http://skonboarding.local*`,
|
|
15
|
+
requestStage: "Request",
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
requestStage: "Request",
|
|
19
18
|
urlPattern: `https://skonboarding.local*`,
|
|
19
|
+
requestStage: "Request",
|
|
20
20
|
},
|
|
21
21
|
];
|
|
22
22
|
constructor(dashboard) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
-
import {
|
|
3
|
-
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
|
|
2
|
+
import { FetchRequestPausedEventHandler, SpeedKitServerConfig } from "../onboarding-model";
|
|
4
3
|
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
4
|
+
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
|
|
5
5
|
import { AbortResponse } from "../browser/abort-response";
|
|
6
|
-
import { FetchRequestPausedEventHandler, SpeedKitServerConfig } from "../onboarding-model";
|
|
7
6
|
import { Cache } from "../request-cache/cache";
|
|
7
|
+
import { CliService } from "../../cli";
|
|
8
8
|
/**
|
|
9
9
|
* Handles fetch requests for Speed Kit assets and returns customized responses.
|
|
10
10
|
*/
|
|
@@ -14,15 +14,15 @@ export declare class SpeedKitAssetRequest implements FetchRequestPausedEventHand
|
|
|
14
14
|
private cache;
|
|
15
15
|
private cli;
|
|
16
16
|
private speedKitServerConfig?;
|
|
17
|
-
constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
|
|
18
17
|
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
19
|
-
|
|
18
|
+
constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
|
|
19
|
+
handle(event: Protocol.Fetch.RequestPausedEvent): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | AbortResponse>;
|
|
20
|
+
private getCachedResponse;
|
|
20
21
|
private buildCustomHeaders;
|
|
21
22
|
private createResponseFromLocalDocumentHandler;
|
|
22
23
|
private getAssetUrl;
|
|
23
|
-
private getCachedResponse;
|
|
24
24
|
private isHtmlContentHeader;
|
|
25
25
|
private isValidHtmlContent;
|
|
26
|
-
private prepareOriginRequest;
|
|
27
26
|
private rewriteInstallResource;
|
|
27
|
+
private prepareOriginRequest;
|
|
28
28
|
}
|
|
@@ -11,32 +11,32 @@ class SpeedKitAssetRequest {
|
|
|
11
11
|
cache;
|
|
12
12
|
cli;
|
|
13
13
|
speedKitServerConfig;
|
|
14
|
-
constructor(customerConfig, documentHandler, cache, cli, speedKitServerConfig) {
|
|
15
|
-
this.customerConfig = customerConfig;
|
|
16
|
-
this.documentHandler = documentHandler;
|
|
17
|
-
this.cache = cache;
|
|
18
|
-
this.cli = cli;
|
|
19
|
-
this.speedKitServerConfig = speedKitServerConfig;
|
|
20
|
-
}
|
|
21
14
|
get patterns() {
|
|
22
15
|
const result = [];
|
|
23
16
|
for (const origin of this.customerConfig.origins) {
|
|
24
17
|
const pattern = [
|
|
25
18
|
{
|
|
26
|
-
requestStage: "Request",
|
|
27
|
-
resourceType: "Fetch",
|
|
28
19
|
urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
|
|
20
|
+
resourceType: "Fetch",
|
|
21
|
+
requestStage: "Request",
|
|
29
22
|
},
|
|
30
23
|
{
|
|
31
|
-
requestStage: "Request",
|
|
32
|
-
resourceType: "XHR",
|
|
33
24
|
urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
|
|
25
|
+
resourceType: "XHR",
|
|
26
|
+
requestStage: "Request",
|
|
34
27
|
},
|
|
35
28
|
];
|
|
36
29
|
result.push(...pattern);
|
|
37
30
|
}
|
|
38
31
|
return result;
|
|
39
32
|
}
|
|
33
|
+
constructor(customerConfig, documentHandler, cache, cli, speedKitServerConfig) {
|
|
34
|
+
this.customerConfig = customerConfig;
|
|
35
|
+
this.documentHandler = documentHandler;
|
|
36
|
+
this.cache = cache;
|
|
37
|
+
this.cli = cli;
|
|
38
|
+
this.speedKitServerConfig = speedKitServerConfig;
|
|
39
|
+
}
|
|
40
40
|
async handle(event) {
|
|
41
41
|
const originUrl = this.getAssetUrl(event.request.url);
|
|
42
42
|
const UrlObject = new URL(event.request.url);
|
|
@@ -80,6 +80,16 @@ class SpeedKitAssetRequest {
|
|
|
80
80
|
return new baqend_response_1.BaqendResponse(message, null, customHeaders, 500);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
getCachedResponse(requestUrl) {
|
|
84
|
+
const response = this.cache.getEntry(requestUrl);
|
|
85
|
+
if (!(response instanceof baqend_response_1.BaqendResponse)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
response.setHeader("x-cache", "POP, HIT");
|
|
89
|
+
response.setHeader("x-served-by", "cache-local");
|
|
90
|
+
response.setHeader("server-timing", "pop;desc=LOCAL;dur=1,cache;desc=CACHE,hotness;desc=1,proto;desc=h3");
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
83
93
|
buildCustomHeaders(originUrl) {
|
|
84
94
|
const time = new Date().toUTCString();
|
|
85
95
|
const originDomain = new URL(originUrl).origin;
|
|
@@ -130,16 +140,6 @@ class SpeedKitAssetRequest {
|
|
|
130
140
|
const cleanedUrl = url.toString();
|
|
131
141
|
return cleanedUrl.split("app.baqend.com/v1/asset/")[1];
|
|
132
142
|
}
|
|
133
|
-
getCachedResponse(requestUrl) {
|
|
134
|
-
const response = this.cache.getEntry(requestUrl);
|
|
135
|
-
if (!(response instanceof baqend_response_1.BaqendResponse)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
response.setHeader("x-cache", "POP, HIT");
|
|
139
|
-
response.setHeader("x-served-by", "cache-local");
|
|
140
|
-
response.setHeader("server-timing", "pop;desc=LOCAL;dur=1,cache;desc=CACHE,hotness;desc=1,proto;desc=h3");
|
|
141
|
-
return response;
|
|
142
|
-
}
|
|
143
143
|
isHtmlContentHeader(responseHeaders) {
|
|
144
144
|
return (responseHeaders.has("content-type") &&
|
|
145
145
|
responseHeaders.get("content-type").includes("text/html"));
|
|
@@ -147,6 +147,12 @@ class SpeedKitAssetRequest {
|
|
|
147
147
|
isValidHtmlContent(text) {
|
|
148
148
|
return text.includes("<html");
|
|
149
149
|
}
|
|
150
|
+
rewriteInstallResource(text) {
|
|
151
|
+
text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
|
|
152
|
+
return text.replace(/<\s*head\b[^>]*>/, (head) => {
|
|
153
|
+
return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
150
156
|
prepareOriginRequest(variationParam, init) {
|
|
151
157
|
if (!this.speedKitServerConfig || !variationParam) {
|
|
152
158
|
return init;
|
|
@@ -159,11 +165,5 @@ class SpeedKitAssetRequest {
|
|
|
159
165
|
init.headers = { ...init.headers, ...variationConfig.headers };
|
|
160
166
|
return init;
|
|
161
167
|
}
|
|
162
|
-
rewriteInstallResource(text) {
|
|
163
|
-
text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
|
|
164
|
-
return text.replace(/<\s*head\b[^>]*>/, (head) => {
|
|
165
|
-
return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
168
|
}
|
|
169
169
|
exports.SpeedKitAssetRequest = SpeedKitAssetRequest;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
3
2
|
import { BrowserContext, FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
3
|
+
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
4
4
|
import { InstallSpeedKitHtmlTemplate } from "../templates/install-speed-kit-html-template";
|
|
5
5
|
/**
|
|
6
6
|
* Represents a class that handles the installation of Speed Kit HTML.
|
|
@@ -9,7 +9,7 @@ export declare class SpeedKitInstallHtml implements FetchRequestPausedEventHandl
|
|
|
9
9
|
private customerConfig;
|
|
10
10
|
private browserContext;
|
|
11
11
|
private speedKitInstallHtmlTemplate;
|
|
12
|
-
constructor(customerConfig: CustomerConfig, browserContext: BrowserContext, speedKitInstallHtmlTemplate: InstallSpeedKitHtmlTemplate);
|
|
13
12
|
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
13
|
+
constructor(customerConfig: CustomerConfig, browserContext: BrowserContext, speedKitInstallHtmlTemplate: InstallSpeedKitHtmlTemplate);
|
|
14
14
|
handle(): Promise<Partial<Protocol.Fetch.FulfillRequestRequest>>;
|
|
15
15
|
}
|
|
@@ -9,39 +9,39 @@ class SpeedKitInstallHtml {
|
|
|
9
9
|
customerConfig;
|
|
10
10
|
browserContext;
|
|
11
11
|
speedKitInstallHtmlTemplate;
|
|
12
|
-
constructor(customerConfig, browserContext, speedKitInstallHtmlTemplate) {
|
|
13
|
-
this.customerConfig = customerConfig;
|
|
14
|
-
this.browserContext = browserContext;
|
|
15
|
-
this.speedKitInstallHtmlTemplate = speedKitInstallHtmlTemplate;
|
|
16
|
-
}
|
|
17
12
|
get patterns() {
|
|
18
13
|
const result = [];
|
|
19
14
|
for (const origin of this.customerConfig.origins) {
|
|
20
15
|
const pattern = [
|
|
21
16
|
{
|
|
22
|
-
requestStage: "Request",
|
|
23
|
-
resourceType: "Document",
|
|
24
17
|
urlPattern: `${origin}${this.customerConfig.scope}speed-kit-install.html*`,
|
|
18
|
+
resourceType: "Document",
|
|
19
|
+
requestStage: "Request",
|
|
25
20
|
},
|
|
26
21
|
{
|
|
27
|
-
requestStage: "Request",
|
|
28
|
-
resourceType: "XHR",
|
|
29
22
|
urlPattern: `${origin}${this.customerConfig.scope}speed-kit-install.html*`,
|
|
23
|
+
resourceType: "XHR",
|
|
24
|
+
requestStage: "Request",
|
|
30
25
|
},
|
|
31
26
|
{
|
|
32
|
-
requestStage: "Request",
|
|
33
|
-
resourceType: "Fetch",
|
|
34
27
|
urlPattern: `${origin}${this.customerConfig.scope}speed-kit-install.html*`,
|
|
28
|
+
resourceType: "Fetch",
|
|
29
|
+
requestStage: "Request",
|
|
35
30
|
},
|
|
36
31
|
];
|
|
37
32
|
result.push(...pattern);
|
|
38
33
|
}
|
|
39
34
|
return result;
|
|
40
35
|
}
|
|
36
|
+
constructor(customerConfig, browserContext, speedKitInstallHtmlTemplate) {
|
|
37
|
+
this.customerConfig = customerConfig;
|
|
38
|
+
this.browserContext = browserContext;
|
|
39
|
+
this.speedKitInstallHtmlTemplate = speedKitInstallHtmlTemplate;
|
|
40
|
+
}
|
|
41
41
|
async handle() {
|
|
42
42
|
return new baqend_response_1.BaqendResponse(this.speedKitInstallHtmlTemplate.render({
|
|
43
|
-
domain: this.browserContext.domain,
|
|
44
43
|
installPath: this.customerConfig.installPath,
|
|
44
|
+
domain: this.browserContext.domain,
|
|
45
45
|
swPath: this.customerConfig.swPath,
|
|
46
46
|
}));
|
|
47
47
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Page } from "puppeteer";
|
|
2
1
|
import { CliService } from "../../cli";
|
|
2
|
+
import { Page } from "puppeteer";
|
|
3
|
+
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
3
4
|
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
|
|
5
|
+
import { Cache } from "../request-cache/cache";
|
|
4
6
|
import { ConfigFileInterface, FileListInterface } from "../../integration-api/integration-api-model";
|
|
5
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
6
7
|
import { BrowserContext } from "../onboarding-model";
|
|
7
|
-
import { Cache } from "../request-cache/cache";
|
|
8
8
|
/**
|
|
9
9
|
* Add different callbacks that will be executed if a local file is changed.
|
|
10
10
|
*/
|
|
@@ -17,13 +17,13 @@ export declare class FileWatcher {
|
|
|
17
17
|
private cache;
|
|
18
18
|
constructor(cli: CliService, customerConfig: CustomerConfig, files: FileListInterface, documentHandler: DocumentHandlerServer, browserContext: BrowserContext, cache: Cache);
|
|
19
19
|
addCallbackOnFileChange(page: Page, serviceWorkerReinstallCallback: (file: ConfigFileInterface) => Promise<void>): void;
|
|
20
|
-
private clearPageFunction;
|
|
21
|
-
private clearServiceWorker;
|
|
22
|
-
private handleDynamicStyles;
|
|
23
|
-
private handleGenericConfigFiles;
|
|
24
20
|
private handleServiceWorkerDependencies;
|
|
25
|
-
private
|
|
26
|
-
private
|
|
21
|
+
private handleGenericConfigFiles;
|
|
22
|
+
private handleDynamicStyles;
|
|
27
23
|
private onChangeServiceWorkerCallback;
|
|
28
24
|
private updateStyles;
|
|
25
|
+
private onChangeConfigFileCallback;
|
|
26
|
+
private onChangeDynamicStyleCallback;
|
|
27
|
+
private clearPageFunction;
|
|
28
|
+
private clearServiceWorker;
|
|
29
29
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FileWatcher = void 0;
|
|
4
4
|
const safe_1 = require("../../../helpers/safe");
|
|
5
|
-
const files_1 = require("../../../models/files");
|
|
6
5
|
const virtual_file_1 = require("../../integration-api/struct/virtual-file");
|
|
6
|
+
const files_1 = require("../../../models/files");
|
|
7
7
|
/**
|
|
8
8
|
* Add different callbacks that will be executed if a local file is changed.
|
|
9
9
|
*/
|
|
@@ -28,39 +28,29 @@ class FileWatcher {
|
|
|
28
28
|
this.handleGenericConfigFiles(page, installResource);
|
|
29
29
|
this.handleDynamicStyles(page);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
handleServiceWorkerDependencies(page, installResource, serviceWorkerReinstallCallback) {
|
|
32
|
+
// add watcher to serviceWorker related files
|
|
33
|
+
const serviceWorkerDependencies = [
|
|
34
|
+
files_1.INTEGRATION_FILES.CONFIG.SPEED_KIT,
|
|
35
|
+
files_1.INTEGRATION_FILES.CONFIG.LOAD_HANDLER,
|
|
36
|
+
files_1.INTEGRATION_FILES.CUSTOM.LOADER,
|
|
37
|
+
files_1.INTEGRATION_FILES.CUSTOM.SW,
|
|
38
|
+
];
|
|
39
|
+
for (const dependency of serviceWorkerDependencies) {
|
|
40
|
+
if (!this.files.hasFile(dependency)) {
|
|
41
|
+
continue;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const client = await page.target().createCDPSession();
|
|
46
|
-
await client.send("ServiceWorker.enable");
|
|
47
|
-
await client.send("ServiceWorker.unregister", {
|
|
48
|
-
scopeURL: `https://${this.customerConfig.domain}`,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
handleDynamicStyles(page) {
|
|
52
|
-
if (!this.files.hasFile(files_1.INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// add watcher that will instantly add changes to current page
|
|
56
|
-
this.files
|
|
57
|
-
.getByName(files_1.INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES)
|
|
58
|
-
.onChange(async (file) => {
|
|
59
|
-
const result = await (0, safe_1.safe)(this.onChangeDynamicStyleCallback(file, page));
|
|
60
|
-
if (result.success === false) {
|
|
61
|
-
this.cli.writeError(`error after fileChange: ${file.name}: ${result.error}`);
|
|
43
|
+
const file = this.files.getByName(dependency);
|
|
44
|
+
if (file.type === virtual_file_1.VirtualFile) {
|
|
45
|
+
continue;
|
|
62
46
|
}
|
|
63
|
-
|
|
47
|
+
file.onChange(async (file) => {
|
|
48
|
+
const result = await (0, safe_1.safe)(this.onChangeServiceWorkerCallback(file, page, installResource, serviceWorkerReinstallCallback));
|
|
49
|
+
if (result.success === false) {
|
|
50
|
+
this.cli.writeError(`error after fileChange: ${file.name}: ${result.error}`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
64
54
|
}
|
|
65
55
|
handleGenericConfigFiles(page, installResource) {
|
|
66
56
|
// add watcher to configFiles
|
|
@@ -86,28 +76,34 @@ class FileWatcher {
|
|
|
86
76
|
});
|
|
87
77
|
}
|
|
88
78
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
files_1.INTEGRATION_FILES.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
const file = this.files.getByName(dependency);
|
|
102
|
-
if (file.type === virtual_file_1.VirtualFile) {
|
|
103
|
-
continue;
|
|
79
|
+
handleDynamicStyles(page) {
|
|
80
|
+
if (!this.files.hasFile(files_1.INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// add watcher that will instantly add changes to current page
|
|
84
|
+
this.files
|
|
85
|
+
.getByName(files_1.INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES)
|
|
86
|
+
.onChange(async (file) => {
|
|
87
|
+
const result = await (0, safe_1.safe)(this.onChangeDynamicStyleCallback(file, page));
|
|
88
|
+
if (result.success === false) {
|
|
89
|
+
this.cli.writeError(`error after fileChange: ${file.name}: ${result.error}`);
|
|
104
90
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async onChangeServiceWorkerCallback(file, page, installResource, serviceWorkerReinstallCallback) {
|
|
94
|
+
this.cli.writeWarning(`changed file: ${file.name} (reinstall serviceWorker)`);
|
|
95
|
+
// clear speed-kit-service-worker-caches and uninstall serviceWorker
|
|
96
|
+
await this.clearPageFunction(page);
|
|
97
|
+
await this.clearServiceWorker(page);
|
|
98
|
+
// rebuild installResource
|
|
99
|
+
await installResource.buildContent();
|
|
100
|
+
// tell puppeteer to reinstall serviceworker on next navigate
|
|
101
|
+
await serviceWorkerReinstallCallback(file);
|
|
102
|
+
}
|
|
103
|
+
updateStyles(styles) {
|
|
104
|
+
const styleElement = document.querySelector("#speed-kit-df-styles");
|
|
105
|
+
if (styleElement) {
|
|
106
|
+
styleElement.textContent = decodeURI(styles);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
109
|
async onChangeConfigFileCallback(page, installResource, file) {
|
|
@@ -131,21 +127,25 @@ class FileWatcher {
|
|
|
131
127
|
await this.documentHandler.buildDocumentHandler();
|
|
132
128
|
this.cache.clear();
|
|
133
129
|
}
|
|
134
|
-
async
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const styleElement = document.querySelector("#speed-kit-df-styles");
|
|
146
|
-
if (styleElement) {
|
|
147
|
-
styleElement.textContent = decodeURI(styles);
|
|
130
|
+
async clearPageFunction(page) {
|
|
131
|
+
const client = await page.target().createCDPSession();
|
|
132
|
+
const cacheResponse = await client.send("CacheStorage.requestCacheNames", {
|
|
133
|
+
securityOrigin: this.browserContext.domain,
|
|
134
|
+
});
|
|
135
|
+
for (const cache of cacheResponse.caches) {
|
|
136
|
+
if (cache.cacheName.includes("baqend")) {
|
|
137
|
+
await client.send("CacheStorage.deleteCache", {
|
|
138
|
+
cacheId: cache.cacheId,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
148
141
|
}
|
|
149
142
|
}
|
|
143
|
+
async clearServiceWorker(page) {
|
|
144
|
+
const client = await page.target().createCDPSession();
|
|
145
|
+
await client.send("ServiceWorker.enable");
|
|
146
|
+
await client.send("ServiceWorker.unregister", {
|
|
147
|
+
scopeURL: `https://${this.customerConfig.domain}`,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
150
|
}
|
|
151
151
|
exports.FileWatcher = FileWatcher;
|