@speedkit/cli 2.27.0 → 2.29.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 +25 -0
- package/README.md +1 -1
- package/dist/helpers/get-parsed-config.d.ts +4 -0
- package/dist/helpers/get-parsed-config.js +4 -0
- package/dist/helpers/is-directory.d.ts +4 -0
- package/dist/helpers/is-directory.js +7 -1
- package/dist/helpers/is-file.d.ts +4 -0
- package/dist/helpers/is-file.js +7 -1
- package/dist/helpers/logging-helper.d.ts +6 -3
- package/dist/helpers/logging-helper.js +3 -0
- package/dist/services/customer-config/customer-config-service.js +0 -3
- package/dist/services/customer-config/templates/config_documentHandler.js.hbs +0 -4
- package/dist/services/deploy/interface/deploy-handler-interface.d.ts +4 -4
- package/dist/services/document-handler-runtime/document-handler-server.d.ts +2 -1
- package/dist/services/document-handler-runtime/document-handler-server.js +9 -8
- package/dist/services/document-handler-runtime/server/document-handler-response.d.ts +10 -0
- package/dist/services/document-handler-runtime/server/document-handler-response.js +19 -0
- package/dist/services/document-handler-runtime/server/request.d.ts +14 -0
- package/dist/services/document-handler-runtime/server/request.js +19 -0
- package/dist/services/onboarding/browser/baqend-response.d.ts +2 -2
- package/dist/services/onboarding/browser/baqend-response.js +10 -1
- package/dist/services/onboarding/dashboard/request-diff-service.js +4 -2
- package/dist/services/onboarding/fetch-events/speed-kit-asset-request.d.ts +4 -18
- package/dist/services/onboarding/fetch-events/speed-kit-asset-request.js +4 -153
- package/dist/services/onboarding/file-events/file-watcher.js +2 -1
- package/dist/services/onboarding/onboarding-model.d.ts +6 -1
- package/dist/services/onboarding/onboarding-model.js +8 -2
- package/dist/services/onboarding/onboarding-service-factory.d.ts +1 -0
- package/dist/services/onboarding/onboarding-service-factory.js +17 -8
- package/dist/services/onboarding/onboarding-service.js +1 -1
- package/dist/services/onboarding/request-cache/cache.js +9 -1
- package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +10 -0
- package/dist/services/onboarding/virtual-orestes-app/crawler.js +58 -0
- package/dist/services/onboarding/virtual-orestes-app/index.d.ts +26 -0
- package/dist/services/onboarding/virtual-orestes-app/index.js +190 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/dist/services/customer-config/templates/deploymentDetection.es6.hbs +0 -303
- package/dist/services/prewarm-service.d.ts +0 -5
- package/dist/services/prewarm-service.js +0 -64
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OnboardingContext = exports.BrowserContext = void 0;
|
|
3
|
+
exports.USER_AGENT = exports.OnboardingContext = exports.BrowserContext = void 0;
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
5
|
const cli_parameters_1 = require("../../models/cli-parameters");
|
|
6
6
|
const DEFAULT_BROWSER_ARGS = [
|
|
@@ -12,13 +12,15 @@ class BrowserContext {
|
|
|
12
12
|
domain;
|
|
13
13
|
chromeFlags;
|
|
14
14
|
userConfig;
|
|
15
|
+
userAgent;
|
|
15
16
|
browserArgs;
|
|
16
17
|
chromePath;
|
|
17
18
|
startParameterDashboard = false;
|
|
18
|
-
constructor(domain, chromeFlags, userConfig) {
|
|
19
|
+
constructor(domain, chromeFlags, userConfig, userAgent) {
|
|
19
20
|
this.domain = domain;
|
|
20
21
|
this.chromeFlags = chromeFlags;
|
|
21
22
|
this.userConfig = userConfig;
|
|
23
|
+
this.userAgent = userAgent;
|
|
22
24
|
this.domain = domain;
|
|
23
25
|
this.chromeFlags = chromeFlags || [];
|
|
24
26
|
this.chromePath = userConfig.chromePath;
|
|
@@ -74,3 +76,7 @@ class OnboardingContext {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
exports.OnboardingContext = OnboardingContext;
|
|
79
|
+
exports.USER_AGENT = {
|
|
80
|
+
DESKTOP: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 (compatible; SpeedKit/1.0)",
|
|
81
|
+
MOBILE: "Mozilla/5.0 (Linux; Android 7.1.1; ONEPLUS A5000 Build/NMF26X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.107 Mobile Safari/537.36 (compatible; SpeedKit/1.0)",
|
|
82
|
+
};
|
|
@@ -11,6 +11,7 @@ const config_api_context_1 = tslib_1.__importDefault(require("../config-api/cont
|
|
|
11
11
|
const config_api_service_factory_1 = tslib_1.__importDefault(require("../config-api/factory/config-api-service-factory"));
|
|
12
12
|
const diff_1 = require("../diff");
|
|
13
13
|
const document_handler_runtime_service_factory_1 = tslib_1.__importDefault(require("../document-handler-runtime/factory/document-handler-runtime-service-factory"));
|
|
14
|
+
const integration_api_1 = require("../integration-api");
|
|
14
15
|
const install_file_recipe_1 = require("./config-renderer/install-file-recipe");
|
|
15
16
|
const speed_kit_install_context_1 = require("./config-renderer/speed-kit-install-context");
|
|
16
17
|
const dashboard_1 = require("./dashboard");
|
|
@@ -32,7 +33,8 @@ const cache_1 = require("./request-cache/cache");
|
|
|
32
33
|
const install_speed_kit_html_template_1 = require("./templates/install-speed-kit-html-template");
|
|
33
34
|
const install_speed_kit_js_template_1 = require("./templates/install-speed-kit-js-template");
|
|
34
35
|
const todo_collector_1 = require("./todo-collector");
|
|
35
|
-
const
|
|
36
|
+
const crawler_1 = require("./virtual-orestes-app/crawler");
|
|
37
|
+
const virtual_orestes_app_1 = require("./virtual-orestes-app");
|
|
36
38
|
class OnboardingServiceFactory {
|
|
37
39
|
context;
|
|
38
40
|
cliConfig;
|
|
@@ -89,6 +91,7 @@ class OnboardingServiceFactory {
|
|
|
89
91
|
}
|
|
90
92
|
async getFetchEventHandler(files, customerConfig, documentHandler, cache, cli, browserContext) {
|
|
91
93
|
const configApi = this.getConfigApi(customerConfig.app);
|
|
94
|
+
const serverConfig = await this.getSpeedKitServerConfig(configApi, cli);
|
|
92
95
|
const parameterQueryBuilder = new parameter_query_builder_1.ParameterQueryBuilder(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CONFIG.SPEED_KIT));
|
|
93
96
|
const DiffService = new diff_1.DiffServiceFactory(new diff_1.DiffContext(this.cliConfig.diffExec, this.cliConfig.diffExecTemplate)).getService();
|
|
94
97
|
const requestDiffService = new request_diff_service_1.RequestDiffService(DiffService, documentHandler);
|
|
@@ -100,20 +103,26 @@ class OnboardingServiceFactory {
|
|
|
100
103
|
new speed_kit_service_worker_js_1.SpeedKitServiceWorkerJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CUSTOM.SW)),
|
|
101
104
|
];
|
|
102
105
|
if (this.context.local) {
|
|
103
|
-
|
|
106
|
+
const crawler = new crawler_1.Crawler(cli, serverConfig);
|
|
107
|
+
const orestesApp = new virtual_orestes_app_1.VirtualOrestesApp(customerConfig, crawler, documentHandler, cache, cli);
|
|
108
|
+
handlers.push(new speed_kit_asset_request_1.SpeedKitAssetRequest(customerConfig, orestesApp), new speed_kit_rum_pi_request_1.SpeedKitRumPiRequest(customerConfig, cache, cli));
|
|
104
109
|
}
|
|
105
110
|
const athenaClient = await this.getAthenaClient();
|
|
106
111
|
if (athenaClient) {
|
|
107
112
|
handlers.push(new dashboard_request_1.DashboardRequest(new dashboard_1.Dashboard(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, cache)));
|
|
108
|
-
/**
|
|
109
|
-
* todo check error `Cannot read properties of undefined (reading 'mainFrame')`
|
|
110
|
-
* until this is fixed, we need to deaktivate the parameter dashboard
|
|
111
|
-
* See ticket: https://www.notion.so/baqend/d3749c5796d647f5892aa5ebfa2fd75f?v=306744f97b924ce29f59a2a3779a045c&p=728aae13a9a94c10807f368143b7dabf&pm=s
|
|
112
|
-
**/
|
|
113
|
-
// browserContext.startParameterDashboard = true;
|
|
114
113
|
}
|
|
115
114
|
return new fetch_event_handler_1.FetchEventHandler(handlers, customerConfig, cli, configApi);
|
|
116
115
|
}
|
|
116
|
+
async getSpeedKitServerConfig(configApi, cli) {
|
|
117
|
+
cli.startAction("get server config from app");
|
|
118
|
+
const serverConfigResult = await (0, safe_1.safe)(configApi.getServerConfig());
|
|
119
|
+
if (serverConfigResult.success !== true) {
|
|
120
|
+
cli.endAction(cli_1.CliActionStatus.FAILED);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
cli.endAction(cli_1.CliActionStatus.COMPLETED);
|
|
124
|
+
return JSON.parse(serverConfigResult.data);
|
|
125
|
+
}
|
|
117
126
|
async getIntegrationFiles() {
|
|
118
127
|
const integrationApiContext = new integration_api_1.IntegrationApiContext(this.context.customerPath, this.context.configName, []);
|
|
119
128
|
const integrationApi = new integration_api_1.IntegrationApiFactory(integrationApiContext, this.cliConfig).buildService();
|
|
@@ -63,8 +63,8 @@ class OnboardingService {
|
|
|
63
63
|
await this.prepareCleanState(page);
|
|
64
64
|
this.registerFileWatcher(page);
|
|
65
65
|
this.registerReinstallSpeedKitOnNavigate(page);
|
|
66
|
-
// inject open Todos from configFiles
|
|
67
66
|
page.on("framenavigated", async (_frame) => {
|
|
67
|
+
// inject open Todos from configFiles
|
|
68
68
|
const tasks = this.taskCollector.getOpenTasks();
|
|
69
69
|
await (0, safe_1.safe)(page.evaluate(`window.skOnboarding = ${JSON.stringify(tasks)}`));
|
|
70
70
|
});
|
|
@@ -22,7 +22,15 @@ class Cache {
|
|
|
22
22
|
this.inMemoryCache.set(requestUri, response);
|
|
23
23
|
}
|
|
24
24
|
removeEntry(requestUri) {
|
|
25
|
-
|
|
25
|
+
const keysToDelete = [];
|
|
26
|
+
for (const key of this.inMemoryCache.keys()) {
|
|
27
|
+
if (key.includes(requestUri)) {
|
|
28
|
+
keysToDelete.push(key);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const key of keysToDelete) {
|
|
32
|
+
this.inMemoryCache.delete(key);
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
clear() {
|
|
28
36
|
this.cli.writeWarning("clear request-caches");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SpeedKitServerConfig } from "../onboarding-model";
|
|
2
|
+
import { CliService } from "../../cli";
|
|
3
|
+
export declare class Crawler {
|
|
4
|
+
private cli;
|
|
5
|
+
private speedKitServerConfig?;
|
|
6
|
+
constructor(cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
|
|
7
|
+
fetchRemote(originUrl: string, variation: string): Promise<Response>;
|
|
8
|
+
private setDefaultUserAgent;
|
|
9
|
+
private prepareOriginRequest;
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Crawler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const onboarding_model_1 = require("../onboarding-model");
|
|
6
|
+
const safe_1 = require("../../../helpers/safe");
|
|
7
|
+
const node_https_1 = require("node:https");
|
|
8
|
+
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
9
|
+
const agent = new node_https_1.Agent({
|
|
10
|
+
rejectUnauthorized: false,
|
|
11
|
+
keepAlive: true,
|
|
12
|
+
secureOptions: node_crypto_1.default.constants.SSL_OP_LEGACY_SERVER_CONNECT,
|
|
13
|
+
});
|
|
14
|
+
class Crawler {
|
|
15
|
+
cli;
|
|
16
|
+
speedKitServerConfig;
|
|
17
|
+
constructor(cli, speedKitServerConfig) {
|
|
18
|
+
this.cli = cli;
|
|
19
|
+
this.speedKitServerConfig = speedKitServerConfig;
|
|
20
|
+
}
|
|
21
|
+
async fetchRemote(originUrl, variation) {
|
|
22
|
+
const userAgent = this.setDefaultUserAgent(variation);
|
|
23
|
+
const headers = { "User-Agent": userAgent };
|
|
24
|
+
const requestInit = {
|
|
25
|
+
...this.prepareOriginRequest(variation, {
|
|
26
|
+
headers,
|
|
27
|
+
}),
|
|
28
|
+
agent,
|
|
29
|
+
};
|
|
30
|
+
const fetchResponse = await (0, safe_1.safe)(fetch(originUrl, requestInit));
|
|
31
|
+
if (fetchResponse.success === true) {
|
|
32
|
+
return fetchResponse.data;
|
|
33
|
+
}
|
|
34
|
+
this.cli.writeError(`error while fetching Asset: ${originUrl}`);
|
|
35
|
+
this.cli.writeError(fetchResponse.error);
|
|
36
|
+
this.cli.writeError(JSON.stringify(fetchResponse.errorObj));
|
|
37
|
+
}
|
|
38
|
+
setDefaultUserAgent(variation) {
|
|
39
|
+
if (variation.includes("MOBILE")) {
|
|
40
|
+
return onboarding_model_1.USER_AGENT.MOBILE;
|
|
41
|
+
}
|
|
42
|
+
return onboarding_model_1.USER_AGENT.DESKTOP;
|
|
43
|
+
}
|
|
44
|
+
prepareOriginRequest(variationParameter, init) {
|
|
45
|
+
if (!this.speedKitServerConfig || !variationParameter) {
|
|
46
|
+
return init;
|
|
47
|
+
}
|
|
48
|
+
for (const variationKey in this.speedKitServerConfig.speedKit.variations) {
|
|
49
|
+
if (variationParameter === variationKey.toUpperCase()) {
|
|
50
|
+
const variationConfig = this.speedKitServerConfig.speedKit.variations[variationKey];
|
|
51
|
+
init.headers = { ...init.headers, ...variationConfig.headers };
|
|
52
|
+
return init;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return init;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Crawler = Crawler;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Protocol from "devtools-protocol";
|
|
2
|
+
import { AbortResponse } from "../browser/abort-response";
|
|
3
|
+
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
|
|
4
|
+
import { Cache } from "../request-cache/cache";
|
|
5
|
+
import { CliService } from "../../cli";
|
|
6
|
+
import { Crawler } from "./crawler";
|
|
7
|
+
import { CustomerConfig } from "../../integration-api";
|
|
8
|
+
export declare class VirtualOrestesApp {
|
|
9
|
+
private customerConfig;
|
|
10
|
+
private crawler;
|
|
11
|
+
private documentHandler;
|
|
12
|
+
private cache;
|
|
13
|
+
private cli;
|
|
14
|
+
constructor(customerConfig: CustomerConfig, crawler: Crawler, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService);
|
|
15
|
+
fetchAssetResponse(event: Protocol.Fetch.RequestPausedEvent): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | AbortResponse>;
|
|
16
|
+
private returnErrorResponse;
|
|
17
|
+
private convertResponseHeadersToOrestesFormat;
|
|
18
|
+
private returnRedirect;
|
|
19
|
+
private handleCdnRedirect;
|
|
20
|
+
private getAssetUrl;
|
|
21
|
+
private getCachedResponse;
|
|
22
|
+
private prepareCustomHeaders;
|
|
23
|
+
private isHtmlContentHeader;
|
|
24
|
+
private isValidHtmlContent;
|
|
25
|
+
private rewriteInstallResource;
|
|
26
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VirtualOrestesApp = void 0;
|
|
4
|
+
const baqend_response_1 = require("../browser/baqend-response");
|
|
5
|
+
const safe_1 = require("../../../helpers/safe");
|
|
6
|
+
class VirtualOrestesApp {
|
|
7
|
+
customerConfig;
|
|
8
|
+
crawler;
|
|
9
|
+
documentHandler;
|
|
10
|
+
cache;
|
|
11
|
+
cli;
|
|
12
|
+
constructor(customerConfig, crawler, documentHandler, cache, cli) {
|
|
13
|
+
this.customerConfig = customerConfig;
|
|
14
|
+
this.crawler = crawler;
|
|
15
|
+
this.documentHandler = documentHandler;
|
|
16
|
+
this.cache = cache;
|
|
17
|
+
this.cli = cli;
|
|
18
|
+
}
|
|
19
|
+
async fetchAssetResponse(event) {
|
|
20
|
+
const originUrl = this.getAssetUrl(event.request.url);
|
|
21
|
+
const UrlObject = new URL(event.request.url);
|
|
22
|
+
const variation = UrlObject.searchParams.has("bqvariation")
|
|
23
|
+
? UrlObject.searchParams.get("bqvariation").trim().toUpperCase()
|
|
24
|
+
: "DEFAULT";
|
|
25
|
+
const cachedResponse = this.getCachedResponse(event.request.url);
|
|
26
|
+
if (cachedResponse instanceof baqend_response_1.BaqendResponse) {
|
|
27
|
+
return cachedResponse;
|
|
28
|
+
}
|
|
29
|
+
const response = await this.crawler.fetchRemote(originUrl, variation);
|
|
30
|
+
// todo check if we can handle more then htmlResponses
|
|
31
|
+
// only handle html responses
|
|
32
|
+
if (!response.headers.get("Content-Type").includes("html")) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const customHeaders = this.prepareCustomHeaders(originUrl);
|
|
36
|
+
// CDN Redirect
|
|
37
|
+
if (originUrl !== response.url) {
|
|
38
|
+
return this.handleCdnRedirect(customHeaders, response, event);
|
|
39
|
+
}
|
|
40
|
+
if (response.status > 300 && response.status < 400) {
|
|
41
|
+
return this.returnRedirect(customHeaders, response, event);
|
|
42
|
+
}
|
|
43
|
+
const responseContent = await response.text();
|
|
44
|
+
if (!this.isHtmlContentHeader(response.headers) ||
|
|
45
|
+
!this.isValidHtmlContent(responseContent)) {
|
|
46
|
+
const customResponse = new baqend_response_1.BaqendResponse(responseContent, response.headers.get("Content-Type") || null, customHeaders);
|
|
47
|
+
this.cache.addEntry(event.request.url, customResponse);
|
|
48
|
+
return customResponse;
|
|
49
|
+
}
|
|
50
|
+
const convertedResponseHeaders = this.convertResponseHeadersToOrestesFormat(response);
|
|
51
|
+
const customResponse = await (0, safe_1.safe)(this.documentHandler.transform(responseContent, variation, originUrl, convertedResponseHeaders));
|
|
52
|
+
if (customResponse.success === false) {
|
|
53
|
+
return this.returnErrorResponse(customResponse, customHeaders);
|
|
54
|
+
}
|
|
55
|
+
const skResponse = customResponse.data;
|
|
56
|
+
if (this.customerConfig.forceInstall) {
|
|
57
|
+
skResponse.body = this.rewriteInstallResource(skResponse.body);
|
|
58
|
+
}
|
|
59
|
+
for (const key in skResponse.headers) {
|
|
60
|
+
customHeaders.push({
|
|
61
|
+
name: `x-debug-${key}`,
|
|
62
|
+
value: skResponse.headers[key],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const originHeaders = [];
|
|
66
|
+
// eslint-disable-next-line unicorn/no-array-for-each
|
|
67
|
+
response.headers.forEach((value, key) => {
|
|
68
|
+
originHeaders.push({ name: `x-origin-${key}`, value: value });
|
|
69
|
+
});
|
|
70
|
+
const baqendResponse = new baqend_response_1.BaqendResponse(skResponse.body, null, [
|
|
71
|
+
...customHeaders,
|
|
72
|
+
...originHeaders,
|
|
73
|
+
]);
|
|
74
|
+
this.cache.addEntry(event.request.url, baqendResponse);
|
|
75
|
+
return baqendResponse;
|
|
76
|
+
}
|
|
77
|
+
returnErrorResponse(customResponse, customHeaders) {
|
|
78
|
+
let message = `could not transform html - ${customResponse.error}`;
|
|
79
|
+
if (customResponse.errorObj) {
|
|
80
|
+
message = customResponse.errorObj.message;
|
|
81
|
+
}
|
|
82
|
+
this.cli.writeError(message);
|
|
83
|
+
this.cli.writeError(JSON.stringify(customResponse.errorObj));
|
|
84
|
+
customHeaders.push({ name: "x-error", value: message });
|
|
85
|
+
return new baqend_response_1.BaqendResponse(message, null, customHeaders, 500);
|
|
86
|
+
}
|
|
87
|
+
convertResponseHeadersToOrestesFormat(response) {
|
|
88
|
+
const convertedResponseHeaders = {};
|
|
89
|
+
// eslint-disable-next-line unicorn/no-array-for-each
|
|
90
|
+
response.headers.forEach((value, key) => {
|
|
91
|
+
convertedResponseHeaders[key] = value;
|
|
92
|
+
});
|
|
93
|
+
return convertedResponseHeaders;
|
|
94
|
+
}
|
|
95
|
+
returnRedirect(customHeaders, response, event) {
|
|
96
|
+
customHeaders.push({
|
|
97
|
+
name: "location",
|
|
98
|
+
value: response.headers.get("location") || "",
|
|
99
|
+
});
|
|
100
|
+
const redirectResponse = new baqend_response_1.BaqendResponse("", null, customHeaders, response.status);
|
|
101
|
+
this.cache.addEntry(event.request.url, redirectResponse);
|
|
102
|
+
return redirectResponse;
|
|
103
|
+
}
|
|
104
|
+
handleCdnRedirect(customHeaders, response, event) {
|
|
105
|
+
customHeaders.push({
|
|
106
|
+
name: "x-debug-response-url",
|
|
107
|
+
value: response.url,
|
|
108
|
+
}, {
|
|
109
|
+
name: "x-debug-redirect",
|
|
110
|
+
value: "response url differs from request url",
|
|
111
|
+
});
|
|
112
|
+
const serverTimingHeader = customHeaders.find((header) => {
|
|
113
|
+
return header.name === "server-timing";
|
|
114
|
+
});
|
|
115
|
+
serverTimingHeader.value += ",error;desc=202";
|
|
116
|
+
const redirectResponse = new baqend_response_1.BaqendResponse("", null, customHeaders, 400);
|
|
117
|
+
this.cache.addEntry(event.request.url, redirectResponse);
|
|
118
|
+
return redirectResponse;
|
|
119
|
+
}
|
|
120
|
+
getAssetUrl(requestUrl) {
|
|
121
|
+
const url = new URL(requestUrl);
|
|
122
|
+
const parametersToDelete = [];
|
|
123
|
+
for (const [name] of url.searchParams.entries()) {
|
|
124
|
+
if (name.startsWith("bq")) {
|
|
125
|
+
parametersToDelete.push(name);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const parameter of parametersToDelete) {
|
|
129
|
+
url.searchParams.delete(parameter);
|
|
130
|
+
}
|
|
131
|
+
const cleanedUrl = url.toString();
|
|
132
|
+
return cleanedUrl.split("app.baqend.com/v1/asset/")[1];
|
|
133
|
+
}
|
|
134
|
+
getCachedResponse(requestUrl) {
|
|
135
|
+
const response = this.cache.getEntry(requestUrl);
|
|
136
|
+
if (!(response instanceof baqend_response_1.BaqendResponse)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
response.setHeader("x-cache", "POP, HIT");
|
|
140
|
+
response.setHeader("x-served-by", "cache-local");
|
|
141
|
+
response.setHeader("server-timing", "pop;desc=LOCAL;dur=1,cache;desc=CACHE,hotness;desc=1,proto;desc=h3");
|
|
142
|
+
return response;
|
|
143
|
+
}
|
|
144
|
+
prepareCustomHeaders(originUrl) {
|
|
145
|
+
const time = new Date().toUTCString();
|
|
146
|
+
const originDomain = new URL(originUrl).origin;
|
|
147
|
+
return [
|
|
148
|
+
{ name: "origin", value: originDomain },
|
|
149
|
+
{ name: "Access-Control-Allow-Credentials", value: "true" },
|
|
150
|
+
{
|
|
151
|
+
name: "strict-transport-security",
|
|
152
|
+
value: "max-age=31536000; includeSubDomains",
|
|
153
|
+
},
|
|
154
|
+
{ name: "timing-allow-origin", value: originDomain },
|
|
155
|
+
{
|
|
156
|
+
name: "Cache-Control",
|
|
157
|
+
value: "public,browser-ttl=0,sw-max-age=31536000,max-age=31469674",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "Alt-Svc",
|
|
161
|
+
value: 'h3=":443";ma=86400,h3-29=":443";ma=86400,h3-27=":443";ma=86400',
|
|
162
|
+
},
|
|
163
|
+
{ name: "x-frame-options", value: "SAMEORIGIN" },
|
|
164
|
+
{ name: "x-cache", value: "STREAM, HIT" },
|
|
165
|
+
{ name: "x-cache-hits", value: "1" },
|
|
166
|
+
{ name: "x-served-by", value: "stream-local" },
|
|
167
|
+
{ name: "last-modified", value: time },
|
|
168
|
+
{ name: "Baqend-Created-At", value: time },
|
|
169
|
+
{ name: "Age", value: "0" },
|
|
170
|
+
{
|
|
171
|
+
name: "server-timing",
|
|
172
|
+
value: "pop;desc=LOCAL;dur=1,cache;desc=STREAM,hotness;desc=1,proto;desc=h3",
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
isHtmlContentHeader(responseHeaders) {
|
|
177
|
+
return (responseHeaders.has("content-type") &&
|
|
178
|
+
responseHeaders.get("content-type").includes("text/html"));
|
|
179
|
+
}
|
|
180
|
+
isValidHtmlContent(text) {
|
|
181
|
+
return text.includes("<html");
|
|
182
|
+
}
|
|
183
|
+
rewriteInstallResource(text) {
|
|
184
|
+
text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
|
|
185
|
+
return text.replace(/<\s*head\b[^>]*>/, (head) => {
|
|
186
|
+
return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.VirtualOrestesApp = VirtualOrestesApp;
|
package/oclif.manifest.json
CHANGED