@speedkit/cli 2.9.0 → 2.11.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 +21 -0
- package/README.md +44 -63
- package/dist/commands/build-parameter-query.d.ts +4 -4
- package/dist/commands/build-parameter-query.js +38 -38
- package/dist/commands/build-prewarm-query.d.ts +4 -4
- package/dist/commands/build-prewarm-query.js +33 -34
- package/dist/commands/deploy.d.ts +4 -4
- package/dist/commands/deploy.js +14 -15
- package/dist/commands/find-pops.js +4 -4
- package/dist/commands/generate-pop-config.js +3 -3
- package/dist/commands/login.js +1 -1
- package/dist/commands/pop-prewarm.js +3 -3
- package/dist/commands/prewarm.js +4 -4
- package/dist/commands/wpt-launcher.js +2 -2
- package/dist/helpers/cli-config.d.ts +8 -7
- package/dist/helpers/cli-config.js +50 -44
- package/dist/models/cli-parameters.js +2 -2
- package/dist/services/cli/cli-service.d.ts +4 -4
- package/dist/services/config-api/client.js +1 -1
- package/dist/services/config-api-service.js +1 -1
- package/dist/services/deploy/context/deploy-context.d.ts +1 -4
- package/dist/services/deploy/context/deploy-context.js +6 -7
- package/dist/services/deploy/deploy-service-factory.d.ts +4 -5
- package/dist/services/deploy/deploy-service-factory.js +19 -18
- package/dist/services/integration-api/handler/customer-config-handler.d.ts +3 -3
- package/dist/services/integration-api/handler/customer-config-handler.js +21 -15
- package/dist/services/integration-api/struct/customer-config-file.d.ts +4 -3
- package/dist/services/integration-api/struct/customer-config-file.js +8 -6
- package/dist/services/onboarding/browser/abort-response.js +1 -1
- package/dist/services/onboarding/browser/baqend-response.d.ts +4 -4
- package/dist/services/onboarding/browser/baqend-response.js +33 -25
- package/dist/services/onboarding/browser/origin-response.d.ts +1 -1
- package/dist/services/onboarding/browser/origin-response.js +2 -3
- 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 +44 -32
- package/dist/services/onboarding/dashboard/athena-service.d.ts +2 -2
- package/dist/services/onboarding/dashboard/athena-service.js +28 -23
- package/dist/services/onboarding/dashboard/index.d.ts +3 -3
- package/dist/services/onboarding/dashboard/index.js +48 -36
- package/dist/services/onboarding/dashboard/param-query-builder.d.ts +2 -2
- package/dist/services/onboarding/dashboard/param-query-builder.js +2 -2
- package/dist/services/onboarding/dashboard/request-diff-service.d.ts +1 -1
- package/dist/services/onboarding/dashboard/request-diff-service.js +32 -28
- package/dist/services/onboarding/fetch-event-handler.d.ts +6 -6
- package/dist/services/onboarding/fetch-event-handler.js +72 -62
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +8 -8
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +51 -49
- package/dist/services/onboarding/fetch-events/customer-service-worker-js.d.ts +3 -3
- package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +6 -6
- package/dist/services/onboarding/fetch-events/dashboard-request.d.ts +2 -2
- package/dist/services/onboarding/fetch-events/dashboard-request.js +3 -3
- 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 +76 -59
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +3 -3
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +14 -14
- package/dist/services/onboarding/fetch-events/speed-kit-install-js.d.ts +6 -6
- package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +12 -10
- package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +7 -7
- package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +3 -3
- package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +4 -4
- package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +6 -4
- package/dist/services/onboarding/file-events/{fileWatcher.d.ts → file-watcher.d.ts} +9 -8
- package/dist/services/onboarding/file-events/{fileWatcher.js → file-watcher.js} +74 -56
- package/dist/services/onboarding/index.d.ts +3 -3
- package/dist/services/onboarding/onboarding-model.d.ts +36 -34
- package/dist/services/onboarding/onboarding-model.js +19 -19
- package/dist/services/onboarding/onboarding-service-factory.d.ts +6 -6
- package/dist/services/onboarding/onboarding-service-factory.js +80 -75
- package/dist/services/onboarding/onboarding-service.d.ts +7 -7
- package/dist/services/onboarding/onboarding-service.js +54 -48
- 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 +2 -2
- package/dist/services/onboarding/todo-collector.d.ts +1 -1
- package/dist/services/onboarding/todo-collector.js +8 -6
- package/dist/services/prewarm-service.js +2 -2
- package/oclif.manifest.json +9 -9
- package/package.json +24 -23
|
@@ -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 safe_1 = require("../../helpers/safe");
|
|
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 abort_response_1 = require("./browser/abort-response");
|
|
10
10
|
class FetchEventHandler {
|
|
11
11
|
browserFetchEvents;
|
|
12
12
|
customerConfig;
|
|
@@ -18,23 +18,39 @@ 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
|
+
}
|
|
21
34
|
async handleRequestFetchEvents(target) {
|
|
22
35
|
const browserClient = await target.createCDPSession();
|
|
23
|
-
await browserClient.send(
|
|
36
|
+
await browserClient.send("Fetch.enable", {
|
|
24
37
|
handleAuthRequests: true,
|
|
25
|
-
//see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
|
|
26
|
-
patterns:
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
// see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
|
|
39
|
+
patterns: [
|
|
40
|
+
...this.browserFetchEvents.flatMap((handler) => {
|
|
41
|
+
return handler.patterns;
|
|
42
|
+
}),
|
|
43
|
+
...this.getAuthPattern(),
|
|
44
|
+
],
|
|
29
45
|
});
|
|
30
|
-
browserClient.on(
|
|
46
|
+
browserClient.on("Fetch.authRequired", async (event) => {
|
|
31
47
|
const response = await (0, safe_1.safe)(this.onFetchAuthRequired(event, browserClient));
|
|
32
48
|
if (response.success === true) {
|
|
33
49
|
return response.data;
|
|
34
50
|
}
|
|
35
51
|
this.cli.writeError(response.error);
|
|
36
52
|
});
|
|
37
|
-
browserClient.on(
|
|
53
|
+
browserClient.on("Fetch.requestPaused", async (event) => {
|
|
38
54
|
const response = await (0, safe_1.safe)(this.onFetchRequestPaused(event, browserClient));
|
|
39
55
|
if (response.success === true) {
|
|
40
56
|
return;
|
|
@@ -48,9 +64,17 @@ class FetchEventHandler {
|
|
|
48
64
|
this.cli.writeError(JSON.stringify(response.errorObj));
|
|
49
65
|
});
|
|
50
66
|
}
|
|
67
|
+
async sendDefaultAuthBehaviour(browserClient, requestId) {
|
|
68
|
+
await browserClient.send("Fetch.continueWithAuth", {
|
|
69
|
+
authChallengeResponse: {
|
|
70
|
+
response: "Default",
|
|
71
|
+
},
|
|
72
|
+
requestId,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
51
75
|
canHandlePattern(fetchEventHandler, url, resourceType, requestStage) {
|
|
52
|
-
return fetchEventHandler.patterns.some(pattern => {
|
|
53
|
-
if (!
|
|
76
|
+
return fetchEventHandler.patterns.some((pattern) => {
|
|
77
|
+
if (!new RegExp(pattern.urlPattern).test(url)) {
|
|
54
78
|
return false;
|
|
55
79
|
}
|
|
56
80
|
if (pattern.requestStage !== requestStage) {
|
|
@@ -59,65 +83,30 @@ class FetchEventHandler {
|
|
|
59
83
|
return !pattern.resourceType || pattern.resourceType === resourceType;
|
|
60
84
|
});
|
|
61
85
|
}
|
|
62
|
-
async onFetchRequestPaused(event, browserClient) {
|
|
63
|
-
const requestId = event.requestId;
|
|
64
|
-
for (const fetchEvent of this.browserFetchEvents) {
|
|
65
|
-
// check if current request could be handled
|
|
66
|
-
if (!this.canHandlePattern(fetchEvent, event.request.url, event.resourceType, event.responseHeaders ? 'Response' : 'Request')) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const response = await fetchEvent.handle(event, browserClient);
|
|
70
|
-
if (!response) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (response instanceof abort_response_1.AbortResponse) {
|
|
74
|
-
await browserClient.send('Fetch.failRequest', { requestId: requestId, errorReason: response.errorReason });
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
await browserClient.send('Fetch.fulfillRequest', {
|
|
78
|
-
...response,
|
|
79
|
-
requestId,
|
|
80
|
-
});
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
//see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest
|
|
84
|
-
await browserClient.send('Fetch.continueRequest', {
|
|
85
|
-
requestId: requestId,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
getAuthPattern() {
|
|
89
|
-
let result = [];
|
|
90
|
-
for (const origin of this.customerConfig.origins) {
|
|
91
|
-
const pattern = [
|
|
92
|
-
{
|
|
93
|
-
urlPattern: `${origin}*`,
|
|
94
|
-
requestStage: "Request"
|
|
95
|
-
}
|
|
96
|
-
];
|
|
97
|
-
result.push(...pattern);
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
86
|
async onFetchAuthRequired(event, browserClient) {
|
|
102
87
|
this.cli.writeWarning(`auth requested for ${event.request.url}`);
|
|
103
|
-
if (!this.customerConfig.origins.some((origin) => {
|
|
88
|
+
if (!this.customerConfig.origins.some((origin) => {
|
|
89
|
+
return event.request.url.includes(origin);
|
|
90
|
+
}) ||
|
|
91
|
+
!this.client) {
|
|
104
92
|
this.cli.writeWarning(`incorrect origin for auth request: -> ${this.customerConfig.origins.join("|")}`);
|
|
105
93
|
return { response: "Default" };
|
|
106
94
|
}
|
|
107
|
-
this.cli.startAction(
|
|
95
|
+
this.cli.startAction("wait for credentials from server-config");
|
|
108
96
|
const serverConfigResponse = await (0, safe_1.safe)(this.client.getServerConfig());
|
|
109
97
|
if (serverConfigResponse.success === true) {
|
|
110
98
|
const config = JSON.parse(serverConfigResponse.data);
|
|
111
99
|
const authUrlOrigin = new URL(event.request.url).origin;
|
|
112
100
|
for (const auth of config.speedKit.authentications) {
|
|
113
|
-
if (auth.uri.includes(authUrlOrigin) &&
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
if (auth.uri.includes(authUrlOrigin) &&
|
|
102
|
+
auth.type === event.authChallenge.scheme) {
|
|
103
|
+
await browserClient.send("Fetch.continueWithAuth", {
|
|
116
104
|
authChallengeResponse: {
|
|
105
|
+
password: auth.password,
|
|
117
106
|
response: "ProvideCredentials",
|
|
118
107
|
username: auth.user,
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
},
|
|
109
|
+
requestId: event.requestId,
|
|
121
110
|
});
|
|
122
111
|
this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
|
|
123
112
|
this.cli.writeSuccess(`auth provided for ${event.request.url}`);
|
|
@@ -143,12 +132,33 @@ class FetchEventHandler {
|
|
|
143
132
|
this.cli.writeError(`error providing auth: ${JSON.stringify(serverConfigResponse.errorObj)}`);
|
|
144
133
|
await this.sendDefaultAuthBehaviour(browserClient, event.requestId);
|
|
145
134
|
}
|
|
146
|
-
async
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
135
|
+
async onFetchRequestPaused(event, browserClient) {
|
|
136
|
+
const { request: { url: requestUrl }, requestId, resourceType, responseHeaders, } = event;
|
|
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;
|
|
151
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", {
|
|
161
|
+
requestId,
|
|
152
162
|
});
|
|
153
163
|
}
|
|
154
164
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Protocol from
|
|
2
|
-
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
3
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
1
|
+
import Protocol from "devtools-protocol";
|
|
4
2
|
import { CDPSession } from "puppeteer";
|
|
5
3
|
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
|
-
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
15
14
|
constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
|
|
15
|
+
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
16
16
|
handle(event: Protocol.Fetch.RequestPausedEvent, client: CDPSession): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | void>;
|
|
17
|
-
private isValidHtmlContent;
|
|
18
|
-
private isValidResponse;
|
|
19
|
-
private isHtmlContentHeader;
|
|
20
17
|
private getHtmlContent;
|
|
18
|
+
private isHtmlContentHeader;
|
|
21
19
|
private isSpeedKitResponse;
|
|
22
|
-
private
|
|
20
|
+
private isValidHtmlContent;
|
|
21
|
+
private isValidResponse;
|
|
23
22
|
private rewriteHtmlToLocalConfig;
|
|
23
|
+
private rewriteInstallResource;
|
|
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
|
+
}
|
|
13
18
|
get patterns() {
|
|
14
|
-
|
|
19
|
+
const result = [];
|
|
15
20
|
for (const origin of this.customerConfig.origins) {
|
|
16
21
|
const pattern = [
|
|
17
22
|
{
|
|
23
|
+
requestStage: "Response",
|
|
24
|
+
resourceType: "Document",
|
|
18
25
|
urlPattern: `${origin}*`,
|
|
19
|
-
resourceType: 'Document',
|
|
20
|
-
requestStage: "Response"
|
|
21
26
|
},
|
|
22
27
|
{
|
|
28
|
+
requestStage: "Response",
|
|
29
|
+
resourceType: "Fetch",
|
|
23
30
|
urlPattern: `${origin}*`,
|
|
24
|
-
resourceType: 'Fetch',
|
|
25
|
-
requestStage: "Response"
|
|
26
31
|
},
|
|
27
32
|
{
|
|
33
|
+
requestStage: "Response",
|
|
34
|
+
resourceType: "XHR",
|
|
28
35
|
urlPattern: `${origin}*`,
|
|
29
|
-
resourceType: 'XHR',
|
|
30
|
-
requestStage: "Response"
|
|
31
36
|
},
|
|
32
37
|
{
|
|
38
|
+
requestStage: "Response",
|
|
39
|
+
resourceType: "Fetch",
|
|
33
40
|
urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
|
|
34
|
-
resourceType: 'Fetch',
|
|
35
|
-
requestStage: "Response"
|
|
36
41
|
},
|
|
37
42
|
{
|
|
38
|
-
|
|
43
|
+
requestStage: "Response",
|
|
39
44
|
resourceType: "XHR",
|
|
40
|
-
|
|
41
|
-
}
|
|
45
|
+
urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
|
|
46
|
+
},
|
|
42
47
|
];
|
|
43
48
|
result.push(...pattern);
|
|
44
49
|
}
|
|
45
50
|
return result;
|
|
46
51
|
}
|
|
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,51 +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
|
-
}
|
|
86
71
|
async getHtmlContent(client, event) {
|
|
87
|
-
const contentType = event.responseHeaders.
|
|
88
|
-
return headerRecord.name.toLowerCase() ===
|
|
89
|
-
})?.
|
|
90
|
-
const charset = contentType.split(
|
|
91
|
-
const {
|
|
72
|
+
const contentType = event.responseHeaders.find((headerRecord) => {
|
|
73
|
+
return headerRecord.name.toLowerCase() === "content-type";
|
|
74
|
+
})?.value || "";
|
|
75
|
+
const charset = contentType.split("charset=")?.[1];
|
|
76
|
+
const { base64Encoded, body } = await client.send("Fetch.getResponseBody", {
|
|
77
|
+
requestId: event.requestId,
|
|
78
|
+
});
|
|
92
79
|
if (base64Encoded) {
|
|
93
80
|
// todo get encodingHeader for target encoding
|
|
94
|
-
return Buffer.from(body,
|
|
81
|
+
return Buffer.from(body, "base64").toString(charset || "utf8");
|
|
95
82
|
}
|
|
96
83
|
return body;
|
|
97
84
|
}
|
|
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
|
+
}
|
|
98
91
|
isSpeedKitResponse(text) {
|
|
99
|
-
return text.includes(
|
|
92
|
+
return text.includes("speed-kit-dynamic");
|
|
100
93
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
isValidHtmlContent(text) {
|
|
95
|
+
return text.includes("<html");
|
|
96
|
+
}
|
|
97
|
+
isValidResponse(event) {
|
|
98
|
+
return (event.responseHeaders &&
|
|
99
|
+
event.responseStatusCode &&
|
|
100
|
+
event.responseStatusCode > 199 &&
|
|
101
|
+
event.responseStatusCode < 300);
|
|
106
102
|
}
|
|
107
103
|
rewriteHtmlToLocalConfig(html) {
|
|
108
|
-
const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\s
|
|
109
|
-
const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\s
|
|
110
|
-
html = html.
|
|
111
|
-
const injectedConfig = body.match(/window\.dynamicBlockConfig\.appName\s=.*$/s) ?? [
|
|
104
|
+
const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\S\s]*?)(<\/script>)/g;
|
|
105
|
+
const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\S\s])*(<\/style>)/g;
|
|
106
|
+
html = html.replaceAll(DF_CONFIG_PATTERN, (_, tag, body, end) => {
|
|
107
|
+
const injectedConfig = body.match(/window\.dynamicBlockConfig\.appName\s=.*$/s) ?? [""];
|
|
112
108
|
return `${tag}${this.configDynamicBlock.getContent()}${injectedConfig[0]}${end}`;
|
|
113
109
|
});
|
|
114
|
-
html = html.
|
|
110
|
+
html = html.replaceAll(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
|
|
115
111
|
return html;
|
|
116
112
|
}
|
|
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
|
+
}
|
|
117
119
|
}
|
|
118
120
|
exports.CustomerDomainDocumentResponse = CustomerDomainDocumentResponse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Protocol from
|
|
2
|
-
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
1
|
+
import Protocol from "devtools-protocol";
|
|
3
2
|
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
3
|
+
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
4
4
|
/**
|
|
5
5
|
* Intercepts request to /wrapper-sw.js
|
|
6
6
|
*
|
|
@@ -8,7 +8,7 @@ import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class CustomerServiceWorkerJs implements FetchRequestPausedEventHandler {
|
|
10
10
|
private customerConfig;
|
|
11
|
-
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
12
11
|
constructor(customerConfig: CustomerConfig);
|
|
12
|
+
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
13
13
|
handle(): Promise<Partial<Protocol.Fetch.FulfillRequestRequest>>;
|
|
14
14
|
}
|
|
@@ -9,22 +9,22 @@ 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
|
+
}
|
|
12
15
|
get patterns() {
|
|
13
|
-
|
|
16
|
+
const result = [];
|
|
14
17
|
for (const origin of this.customerConfig.origins) {
|
|
15
18
|
result.push({
|
|
19
|
+
requestStage: "Request",
|
|
16
20
|
urlPattern: `${origin}${this.customerConfig.swPath}*`,
|
|
17
|
-
requestStage: "Request"
|
|
18
21
|
});
|
|
19
22
|
}
|
|
20
23
|
return result;
|
|
21
24
|
}
|
|
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
|
-
return new baqend_response_1.BaqendResponse(wrapperSwCode,
|
|
27
|
+
return new baqend_response_1.BaqendResponse(wrapperSwCode, "text/javascript; charset=utf-8");
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.CustomerServiceWorkerJs = CustomerServiceWorkerJs;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Protocol from
|
|
2
|
-
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
1
|
+
import Protocol from "devtools-protocol";
|
|
3
2
|
import { Dashboard } from "../dashboard";
|
|
3
|
+
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
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,19 +11,19 @@ class DashboardRequest {
|
|
|
11
11
|
dashboard;
|
|
12
12
|
patterns = [
|
|
13
13
|
{
|
|
14
|
+
requestStage: "Request",
|
|
14
15
|
urlPattern: `http://skonboarding.local*`,
|
|
15
|
-
requestStage: "Request"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
+
requestStage: "Request",
|
|
18
19
|
urlPattern: `https://skonboarding.local*`,
|
|
19
|
-
requestStage: "Request"
|
|
20
20
|
},
|
|
21
21
|
];
|
|
22
22
|
constructor(dashboard) {
|
|
23
23
|
this.dashboard = dashboard;
|
|
24
24
|
}
|
|
25
25
|
async handle(event) {
|
|
26
|
-
return
|
|
26
|
+
return this.dashboard.getResponse(event.request);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
exports.DashboardRequest = DashboardRequest;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
-
import {
|
|
3
|
-
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
2
|
+
import { CliService } from "../../cli";
|
|
4
3
|
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
|
|
4
|
+
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
5
5
|
import { AbortResponse } from "../browser/abort-response";
|
|
6
|
+
import { FetchRequestPausedEventHandler, SpeedKitServerConfig } from "../onboarding-model";
|
|
6
7
|
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
|
-
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
18
17
|
constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
19
|
+
handle(event: Protocol.Fetch.RequestPausedEvent): Promise<AbortResponse | Partial<Protocol.Fetch.FulfillRequestRequest>>;
|
|
21
20
|
private buildCustomHeaders;
|
|
22
21
|
private createResponseFromLocalDocumentHandler;
|
|
23
22
|
private getAssetUrl;
|
|
23
|
+
private getCachedResponse;
|
|
24
24
|
private isHtmlContentHeader;
|
|
25
25
|
private isValidHtmlContent;
|
|
26
|
-
private rewriteInstallResource;
|
|
27
26
|
private prepareOriginRequest;
|
|
27
|
+
private rewriteInstallResource;
|
|
28
28
|
}
|