@speedkit/cli 4.44.0-beta.4 → 4.44.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 +35 -13
- package/README.md +68 -42
- package/dist/base/sk-command.d.ts +7 -0
- package/dist/base/sk-command.js +19 -0
- package/dist/commands/deploy.d.ts +1 -0
- package/dist/commands/deploy.js +5 -1
- package/dist/commands/diff.d.ts +47 -0
- package/dist/commands/diff.js +67 -0
- package/dist/commands/generate-pop-config.js +3 -7
- package/dist/helpers/race.js +4 -2
- package/dist/helpers/spec/race.spec.js +31 -0
- package/dist/models/files.d.ts +0 -1
- package/dist/models/files.js +0 -1
- package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
- package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +1 -7
- package/dist/services/browser-fetch/browser-origin-fetcher.js +3 -26
- package/dist/services/bundler/bundle-service-factory.d.ts +0 -3
- package/dist/services/bundler/bundle-service-factory.js +1 -5
- package/dist/services/bundler/bundle-service.d.ts +1 -10
- package/dist/services/bundler/bundle-service.js +1 -16
- package/dist/services/bundler/index.d.ts +0 -1
- package/dist/services/bundler/index.js +0 -1
- package/dist/services/cli/cli-environment.d.ts +11 -0
- package/dist/services/cli/cli-environment.js +37 -0
- package/dist/services/cli/cli-service-model.d.ts +3 -1
- package/dist/services/cli/cli-service.d.ts +1 -1
- package/dist/services/cli/cli-service.js +4 -1
- package/dist/services/cli/spec/cli-environment.spec.js +30 -1
- package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
- package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
- package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
- package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
- package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
- package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
- package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
- package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
- package/dist/services/deploy/deploy-service-build-context.d.ts +2 -0
- package/dist/services/deploy/deploy-service-build-context.js +13 -2
- package/dist/services/deploy/deploy-service-factory.js +2 -9
- package/dist/services/deploy/deploy-service-model.d.ts +11 -1
- package/dist/services/deploy/deploy-service.d.ts +2 -0
- package/dist/services/deploy/deploy-service.js +26 -1
- package/dist/services/deploy/handler/customer-config-handler.d.ts +2 -2
- package/dist/services/deploy/handler/install-resource-handler.d.ts +2 -2
- package/dist/services/deploy/handler/install-resource-handler.js +6 -3
- package/dist/services/deploy/handler/module-handler.d.ts +2 -2
- package/dist/services/deploy/handler/module-handler.js +2 -2
- package/dist/services/deploy/handler/server-config-handler.d.ts +2 -2
- package/dist/services/deploy/handler/server-config-handler.js +2 -2
- package/dist/services/deploy/mr/live-state-check.d.ts +2 -2
- package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +2 -7
- package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
- package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
- package/dist/services/deploy/policy/index.d.ts +1 -0
- package/dist/services/deploy/policy/index.js +1 -0
- package/dist/services/deploy/policy/testing-deploy-policy.d.ts +16 -0
- package/dist/services/deploy/policy/testing-deploy-policy.js +42 -0
- package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
- package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
- package/dist/services/deploy/spec/handler/install-resource-handler.spec.js +58 -0
- package/dist/services/deploy/spec/mr/live-state-check.spec.js +2 -2
- package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
- package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.d.ts +1 -0
- package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +46 -0
- package/dist/services/diff/create-diff-engine.d.ts +14 -0
- package/dist/services/diff/create-diff-engine.js +42 -0
- package/dist/services/diff/customer-origin.d.ts +9 -0
- package/dist/services/diff/customer-origin.js +19 -0
- package/dist/services/diff/diff-engine.d.ts +30 -0
- package/dist/services/diff/diff-engine.js +49 -0
- package/dist/services/diff/diff-log.d.ts +9 -0
- package/dist/services/diff/diff-log.js +18 -0
- package/dist/services/diff/diff-model.d.ts +68 -0
- package/dist/services/diff/diff-model.js +1 -0
- package/dist/services/diff/diff-service-build-context.d.ts +99 -9
- package/dist/services/diff/diff-service-build-context.js +299 -1
- package/dist/services/diff/diff-service-factory.d.ts +24 -2
- package/dist/services/diff/diff-service-factory.js +165 -3
- package/dist/services/diff/diff-service.d.ts +93 -33
- package/dist/services/diff/diff-service.js +274 -140
- package/dist/services/diff/index.d.ts +12 -1
- package/dist/services/diff/index.js +12 -1
- package/dist/services/diff/noise-baseline.d.ts +28 -0
- package/dist/services/diff/noise-baseline.js +105 -0
- package/dist/services/diff/page-source.d.ts +42 -0
- package/dist/services/diff/page-source.js +93 -0
- package/dist/services/diff/side-failure.d.ts +28 -0
- package/dist/services/diff/side-failure.js +100 -0
- package/dist/services/diff/sinks/json-diff-sink.d.ts +32 -0
- package/dist/services/diff/sinks/json-diff-sink.js +44 -0
- package/dist/services/diff/sinks/no-diff-sink.d.ts +5 -0
- package/dist/services/diff/sinks/no-diff-sink.js +6 -0
- package/dist/services/diff/sinks/patch-diff-sink.d.ts +19 -0
- package/dist/services/diff/sinks/patch-diff-sink.js +29 -0
- package/dist/services/diff/sinks/tool-diff-sink.d.ts +26 -0
- package/dist/services/diff/sinks/tool-diff-sink.js +88 -0
- package/dist/services/diff/sinks/unified-patch.d.ts +7 -0
- package/dist/services/diff/sinks/unified-patch.js +12 -0
- package/dist/services/diff/spec/customer-origin.spec.d.ts +1 -0
- package/dist/services/diff/spec/customer-origin.spec.js +27 -0
- package/dist/services/diff/spec/diff-engine.spec.d.ts +1 -0
- package/dist/services/diff/spec/diff-engine.spec.js +47 -0
- package/dist/services/diff/spec/diff-service-build-context.spec.d.ts +1 -0
- package/dist/services/diff/spec/diff-service-build-context.spec.js +185 -0
- package/dist/services/diff/spec/diff-service.spec.d.ts +1 -0
- package/dist/services/diff/spec/diff-service.spec.js +393 -0
- package/dist/services/diff/spec/noise-baseline.spec.d.ts +1 -0
- package/dist/services/diff/spec/noise-baseline.spec.js +95 -0
- package/dist/services/diff/spec/page-source.spec.d.ts +1 -0
- package/dist/services/diff/spec/page-source.spec.js +140 -0
- package/dist/services/diff/spec/sinks/json-diff-sink.spec.d.ts +1 -0
- package/dist/services/diff/spec/sinks/json-diff-sink.spec.js +72 -0
- package/dist/services/diff/spec/sinks/patch-diff-sink.spec.d.ts +1 -0
- package/dist/services/diff/spec/sinks/patch-diff-sink.spec.js +47 -0
- package/dist/services/diff/spec/sinks/tool-diff-sink.spec.d.ts +1 -0
- package/dist/services/diff/spec/sinks/tool-diff-sink.spec.js +61 -0
- package/dist/services/document-handler-runtime/document-handler-abort.d.ts +2 -0
- package/dist/services/document-handler-runtime/document-handler-abort.js +2 -0
- package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
- package/dist/services/document-handler-runtime/document-handler-server.js +19 -81
- package/dist/services/document-handler-runtime/runtime-files.d.ts +9 -0
- package/dist/services/document-handler-runtime/runtime-files.js +17 -0
- package/dist/services/integration-api/integration-api-model.d.ts +1 -2
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -68
- package/dist/services/integration-api/struct/customer-config.d.ts +1 -32
- package/dist/services/integration-api/struct/customer-config.js +3 -33
- package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
- package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -27
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -25
- package/dist/services/onboarding/dashboard/diff-against-current-page.d.ts +29 -7
- package/dist/services/onboarding/dashboard/diff-against-current-page.js +24 -37
- package/dist/services/onboarding/dashboard/index.js +13 -6
- package/dist/services/onboarding/dashboard/request-diff-service.d.ts +21 -8
- package/dist/services/onboarding/dashboard/request-diff-service.js +21 -49
- package/dist/services/onboarding/onboarding-model.d.ts +0 -1
- package/dist/services/onboarding/onboarding-model.js +0 -1
- package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
- package/dist/services/onboarding/onboarding-service-factory.js +24 -30
- package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.js +57 -0
- package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
- package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -3
- package/dist/services/onboarding/virtual-orestes-app/index.js +5 -5
- package/dist/services/origin-request/index.d.ts +3 -0
- package/dist/services/origin-request/index.js +3 -0
- package/dist/services/origin-request/origin-fetcher.d.ts +52 -0
- package/dist/services/origin-request/origin-fetcher.js +93 -0
- package/dist/services/origin-request/origin-request-service-factory.js +19 -1
- package/dist/services/origin-request/origin-request-service.d.ts +6 -10
- package/dist/services/origin-request/origin-request-service.js +28 -70
- package/dist/services/origin-request/runtime-config-source.d.ts +36 -0
- package/dist/services/origin-request/runtime-config-source.js +59 -0
- package/dist/services/origin-request/spec/origin-error-cause.spec.d.ts +1 -0
- package/dist/services/{onboarding/spec/virtual-orestes-app → origin-request/spec}/origin-error-cause.spec.js +1 -1
- package/dist/services/origin-request/spec/origin-fetcher.spec.d.ts +1 -0
- package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.js → origin-request/spec/origin-fetcher.spec.js} +46 -15
- package/dist/services/prewarm/assets/asset-api-client.d.ts +6 -0
- package/dist/services/prewarm/assets/asset-api-client.js +6 -1
- package/dist/services/prewarm/pre-warm-service.d.ts +10 -0
- package/dist/services/prewarm/pre-warm-service.js +17 -0
- package/dist/services/prewarm/spec/pre-warm-service.spec.d.ts +1 -0
- package/dist/services/prewarm/spec/pre-warm-service.spec.js +72 -0
- package/dist/services/query-builder/query-builder-factory.js +3 -3
- package/dist/services/setup/os/tool-registry.d.ts +1 -1
- package/oclif.manifest.json +151 -19
- package/package.json +1 -2
- package/dist/commands/diff-url-parameters.d.ts +0 -19
- package/dist/commands/diff-url-parameters.js +0 -121
- package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
- package/dist/services/bundler/error/packjockel-error.js +0 -3
- package/dist/services/bundler/packjockel-service.d.ts +0 -72
- package/dist/services/bundler/packjockel-service.js +0 -156
- package/dist/services/bundler/spec/packjockel-service.spec.js +0 -143
- package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
- package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
- package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
- package/dist/services/deploy/error/check-module-file-error.js +0 -4
- package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
- package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
- package/dist/services/onboarding/server-config/index.d.ts +0 -10
- package/dist/services/onboarding/server-config/index.js +0 -27
- package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +0 -31
- package/dist/services/onboarding/virtual-orestes-app/crawler.js +0 -98
- /package/dist/{services/bundler/spec/packjockel-service.spec.d.ts → helpers/spec/race.spec.d.ts} +0 -0
- /package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
- /package/dist/services/{onboarding/spec/virtual-orestes-app/origin-error-cause.spec.d.ts → deploy/spec/handler/install-resource-handler.spec.d.ts} +0 -0
- /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.d.ts +0 -0
- /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.js +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ExternalFileReader, ExternalRecipe, } from "../integration-api/index.js";
|
|
2
|
+
import { LOCAL_DOCUMENT_HANDLER } from "./document-handler-runtime-model.js";
|
|
3
|
+
/** The released document handler, run when the customer directory brings none of its own. */
|
|
4
|
+
export const LATEST_DOCUMENT_HANDLER_URL = "https://www.baqend.com/speed-kit-handler/latest/DocumentHandler.js";
|
|
5
|
+
/**
|
|
6
|
+
* The virtual files a local document handler run needs beside the customer's
|
|
7
|
+
* config: the document handler itself. Hand them to `integrationApi.run()`
|
|
8
|
+
* before the files reach `DocumentHandlerRuntimeServiceFactory`.
|
|
9
|
+
*/
|
|
10
|
+
export function documentHandlerRuntimeFiles() {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
name: LOCAL_DOCUMENT_HANDLER,
|
|
14
|
+
recipe: new ExternalRecipe(LATEST_DOCUMENT_HANDLER_URL, new ExternalFileReader()),
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
}
|
|
@@ -13,7 +13,6 @@ export * from "./virtual/external-recipe.js";
|
|
|
13
13
|
export * from "./virtual/static-recipe.js";
|
|
14
14
|
export * from "./external/external-file-reader.js";
|
|
15
15
|
import type { SpeedKitConfig } from "./struct/speed-kit-config.js";
|
|
16
|
-
import type { SpeedKitConfigCustomer } from "./struct/speed-kit-config-file.js";
|
|
17
16
|
import { CustomerConfig } from "./struct/customer-config.js";
|
|
18
17
|
import { RoFile } from "./struct/ro-file.js";
|
|
19
18
|
import { VirtualFile } from "./struct/virtual-file.js";
|
|
@@ -90,7 +89,7 @@ export interface InstallResourceInterface extends ConfigFileInterface, FileInter
|
|
|
90
89
|
readonly remoteKey: string;
|
|
91
90
|
}
|
|
92
91
|
export interface SpeedKitConfigInterface extends InstallResourceInterface {
|
|
93
|
-
evaluate(
|
|
92
|
+
evaluate(app: string, origin: string): Promise<SpeedKitConfig>;
|
|
94
93
|
}
|
|
95
94
|
export interface CustomerConfigInterface extends ConfigFileInterface {
|
|
96
95
|
config: CustomerConfig;
|
|
@@ -2,21 +2,8 @@ import { expect } from "chai";
|
|
|
2
2
|
import { describe, it } from "mocha";
|
|
3
3
|
import { SpeedKitConfigFile, VirtualSpeedKitConfigFile } from "../index.js";
|
|
4
4
|
import { INTEGRATION_FILES } from "../../../models/files.js";
|
|
5
|
-
import {
|
|
5
|
+
import { BundleServiceFactory } from "../../bundler/index.js";
|
|
6
6
|
const bundler = new BundleServiceFactory("./").buildService();
|
|
7
|
-
const SHOP_DE = { app: "shop-de" };
|
|
8
|
-
/** Answers every bundle request with one bundle and keeps the requests. */
|
|
9
|
-
class FakePackjockel {
|
|
10
|
-
bundled;
|
|
11
|
-
requests = [];
|
|
12
|
-
constructor(bundled) {
|
|
13
|
-
this.bundled = bundled;
|
|
14
|
-
}
|
|
15
|
-
async bundle(request) {
|
|
16
|
-
this.requests.push(request);
|
|
17
|
-
return this.bundled;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
7
|
function configFile(source) {
|
|
21
8
|
return new SpeedKitConfigFile({
|
|
22
9
|
name: INTEGRATION_FILES.CONFIG.SPEED_KIT,
|
|
@@ -26,7 +13,7 @@ function configFile(source) {
|
|
|
26
13
|
}, bundler);
|
|
27
14
|
}
|
|
28
15
|
function evaluate(source) {
|
|
29
|
-
return configFile(source).evaluate(
|
|
16
|
+
return configFile(source).evaluate("shop-de", "https://www.shop.de");
|
|
30
17
|
}
|
|
31
18
|
/** What the config assigned, for the tests about the browser mock itself. */
|
|
32
19
|
async function evaluateRaw(source) {
|
|
@@ -102,19 +89,19 @@ describe("SpeedKitConfigFile", () => {
|
|
|
102
89
|
// builder and the pre-deploy checks both go through here.
|
|
103
90
|
const file = configFile(`window.speedKit = { host: window.location.host };`);
|
|
104
91
|
const [first, second] = await Promise.all([
|
|
105
|
-
file.evaluate(
|
|
106
|
-
file.evaluate(
|
|
92
|
+
file.evaluate("shop-de", "https://www.shop.de"),
|
|
93
|
+
file.evaluate("shop-de", "https://www.shop.de"),
|
|
107
94
|
]);
|
|
108
|
-
const otherOrigin = await file.evaluate(
|
|
95
|
+
const otherOrigin = await file.evaluate("shop-de", "https://m.shop.de");
|
|
109
96
|
expect(first).to.equal(second);
|
|
110
97
|
expect(otherOrigin).to.not.equal(first);
|
|
111
98
|
expect(otherOrigin.raw.host).to.equal("m.shop.de");
|
|
112
99
|
});
|
|
113
100
|
it("should forget what it read when the file changes", async () => {
|
|
114
101
|
const file = configFile(`window.speedKit = { split: 0.1 };`);
|
|
115
|
-
const before = await file.evaluate(
|
|
102
|
+
const before = await file.evaluate("shop-de", "https://www.shop.de");
|
|
116
103
|
file.setContent(`window.speedKit = { split: 0.5 };`);
|
|
117
|
-
const after = await file.evaluate(
|
|
104
|
+
const after = await file.evaluate("shop-de", "https://www.shop.de");
|
|
118
105
|
expect(before.split).to.equal(0.1);
|
|
119
106
|
expect(after.split).to.equal(0.5);
|
|
120
107
|
});
|
|
@@ -122,55 +109,8 @@ describe("SpeedKitConfigFile", () => {
|
|
|
122
109
|
const source = `window.speedKit = { split: 0.5, appName: APP };`;
|
|
123
110
|
const remote = await VirtualSpeedKitConfigFile.createRemote(source, bundler);
|
|
124
111
|
const local = await evaluate(source);
|
|
125
|
-
const deployed = await remote.evaluate(
|
|
112
|
+
const deployed = await remote.evaluate("shop-de", "https://www.shop.de");
|
|
126
113
|
expect(deployed).to.deep.equal(local);
|
|
127
114
|
expect(remote.getContent()).to.equal(source);
|
|
128
115
|
});
|
|
129
|
-
describe("with the enableSpeedKitConfigPlugins feature", () => {
|
|
130
|
-
const SOURCE = "window.speedKit = { split: 0.1 };";
|
|
131
|
-
const EMBEDDED = {
|
|
132
|
-
app: "shop-de",
|
|
133
|
-
features: { enableSpeedKitConfigPlugins: true },
|
|
134
|
-
configPluginsVersion: "@release",
|
|
135
|
-
};
|
|
136
|
-
function embeddedFile(bundled) {
|
|
137
|
-
const packjockel = new FakePackjockel(bundled);
|
|
138
|
-
const file = new SpeedKitConfigFile({
|
|
139
|
-
name: INTEGRATION_FILES.CONFIG.SPEED_KIT,
|
|
140
|
-
path: "config_SpeedKit.js",
|
|
141
|
-
content: SOURCE,
|
|
142
|
-
remoteKey: "config",
|
|
143
|
-
}, new BundleService("./", packjockel));
|
|
144
|
-
return { file, packjockel };
|
|
145
|
-
}
|
|
146
|
-
it("should bundle with packjockel and the tags of the customer", async () => {
|
|
147
|
-
const { file, packjockel } = embeddedFile(`SpeedKit.config = {};`);
|
|
148
|
-
await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
149
|
-
expect(packjockel.requests).to.have.length(1);
|
|
150
|
-
expect(packjockel.requests[0]).to.deep.equal({
|
|
151
|
-
entryPoints: { "config.js": SOURCE },
|
|
152
|
-
versions: EMBEDDED,
|
|
153
|
-
define: { APP: '"shop-de"' },
|
|
154
|
-
platform: "browser",
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
it("should read SpeedKit.config and the plugins pushed without a guard", async () => {
|
|
158
|
-
const { file } = embeddedFile(`SpeedKit.configPlugins.push({ name: "StripQueryParamPlugin" });
|
|
159
|
-
SpeedKit.config = { split: 0.3, appName: "shop-de" };`);
|
|
160
|
-
const config = await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
161
|
-
expect(config.split).to.equal(0.3);
|
|
162
|
-
expect(config.raw.appName).to.equal("shop-de");
|
|
163
|
-
});
|
|
164
|
-
it("should still read a config that assigns window.speedKit", async () => {
|
|
165
|
-
const { file } = embeddedFile(`window.speedKit = { split: 0.7 };`);
|
|
166
|
-
const config = await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
167
|
-
expect(config.split).to.equal(0.7);
|
|
168
|
-
});
|
|
169
|
-
it("should not reuse a reading of the other bundler", async () => {
|
|
170
|
-
const { file, packjockel } = embeddedFile(`SpeedKit.config = {};`);
|
|
171
|
-
await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
172
|
-
await file.evaluate({ app: "shop-de" }, "https://www.shop.de");
|
|
173
|
-
expect(packjockel.requests).to.have.length(1);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
116
|
});
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { AssetVersions } from "../../bundler/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* The installation features of a config. `null` leaves a feature at its default.
|
|
4
|
-
*/
|
|
5
|
-
export interface CustomerFeatures {
|
|
6
|
-
/**
|
|
7
|
-
* packjockel bundles the config with the config plugins of its target and
|
|
8
|
-
* embeds it into the document handler and the install script. The config
|
|
9
|
-
* writes `SpeedKit.config`.
|
|
10
|
-
*/
|
|
11
|
-
enableSpeedKitConfigPlugins?: boolean | null;
|
|
12
|
-
[feature: string]: unknown;
|
|
13
|
-
}
|
|
14
1
|
export interface CustomerConfigs {
|
|
15
2
|
production: CustomerConfig;
|
|
16
3
|
[configName: string]: CustomerConfig;
|
|
@@ -34,24 +21,6 @@ export declare class CustomerConfig {
|
|
|
34
21
|
* installation whose split is greater than 0 for any origin.
|
|
35
22
|
*/
|
|
36
23
|
readonly needsCustomerApproval?: boolean;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The tag of Speed Kit (snippet, service worker, dynamic fetcher) for the `enableSpeedKitConfigPlugins` feature: a
|
|
40
|
-
* version such as `2.22.4`, or a channel such as `@release`; `latest` when not set. This and the other
|
|
41
|
-
* tags are named like the client config keys of packjockel.
|
|
42
|
-
*/
|
|
43
|
-
readonly speedKitVersion?: string;
|
|
44
|
-
/** The tag of RUM for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
45
|
-
readonly rumPluginVersion?: string;
|
|
46
|
-
/** The tag of predictive preloading for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
47
|
-
readonly ppVersion?: string;
|
|
48
|
-
/** The tag of the speed-kit-config plugins for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
49
|
-
readonly configPluginsVersion?: string;
|
|
50
|
-
/**
|
|
51
|
-
* The tag of the published document handler for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}.
|
|
52
|
-
* A `custom_documentHandler.js` replaces it.
|
|
53
|
-
*/
|
|
54
|
-
readonly documentHandlerVersion?: string;
|
|
55
|
-
constructor(app: string, origins: string[], domain: string, swPath: string, scope: string, appDomain?: string, installPath?: string, installParameters?: string, name?: string, forceInstall?: boolean, chromeFlags?: string[], dependencies?: Record<string, string>, needsCustomerApproval?: boolean, features?: CustomerFeatures, versions?: AssetVersions);
|
|
24
|
+
constructor(app: string, origins: string[], domain: string, swPath: string, scope: string, appDomain?: string, installPath?: string, installParameters?: string, name?: string, forceInstall?: boolean, chromeFlags?: string[], dependencies?: Record<string, string>, needsCustomerApproval?: boolean);
|
|
56
25
|
static createFrom(configFile: Partial<CustomerConfig>, configName?: string): CustomerConfig;
|
|
57
26
|
}
|
|
@@ -18,25 +18,7 @@ export class CustomerConfig {
|
|
|
18
18
|
* installation whose split is greater than 0 for any origin.
|
|
19
19
|
*/
|
|
20
20
|
needsCustomerApproval;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The tag of Speed Kit (snippet, service worker, dynamic fetcher) for the `enableSpeedKitConfigPlugins` feature: a
|
|
24
|
-
* version such as `2.22.4`, or a channel such as `@release`; `latest` when not set. This and the other
|
|
25
|
-
* tags are named like the client config keys of packjockel.
|
|
26
|
-
*/
|
|
27
|
-
speedKitVersion;
|
|
28
|
-
/** The tag of RUM for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
29
|
-
rumPluginVersion;
|
|
30
|
-
/** The tag of predictive preloading for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
31
|
-
ppVersion;
|
|
32
|
-
/** The tag of the speed-kit-config plugins for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
33
|
-
configPluginsVersion;
|
|
34
|
-
/**
|
|
35
|
-
* The tag of the published document handler for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}.
|
|
36
|
-
* A `custom_documentHandler.js` replaces it.
|
|
37
|
-
*/
|
|
38
|
-
documentHandlerVersion;
|
|
39
|
-
constructor(app, origins, domain, swPath, scope, appDomain, installPath, installParameters, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, versions = {}) {
|
|
21
|
+
constructor(app, origins, domain, swPath, scope, appDomain, installPath, installParameters, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval) {
|
|
40
22
|
this.app = app;
|
|
41
23
|
this.origins = origins;
|
|
42
24
|
this.domain = domain;
|
|
@@ -50,23 +32,11 @@ export class CustomerConfig {
|
|
|
50
32
|
this.chromeFlags = chromeFlags;
|
|
51
33
|
this.dependencies = dependencies;
|
|
52
34
|
this.needsCustomerApproval = needsCustomerApproval;
|
|
53
|
-
this.features = features;
|
|
54
|
-
this.speedKitVersion = versions.speedKitVersion;
|
|
55
|
-
this.rumPluginVersion = versions.rumPluginVersion;
|
|
56
|
-
this.ppVersion = versions.ppVersion;
|
|
57
|
-
this.configPluginsVersion = versions.configPluginsVersion;
|
|
58
|
-
this.documentHandlerVersion = versions.documentHandlerVersion;
|
|
59
35
|
}
|
|
60
36
|
static createFrom(configFile, configName) {
|
|
61
|
-
const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval,
|
|
37
|
+
const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, } = configFile;
|
|
62
38
|
return new CustomerConfig(new RequiredParameter("app", app).isString().getValue(), new RequiredParameter("origins", origins).isArray().getValue(), domain, new RequiredParameter("swPath", swPath).isString().getValue(), new RequiredParameter("scope", scope).isString().getValue(), appDomain || `${app}.app.baqend.com`, installPath ||
|
|
63
|
-
`https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false
|
|
64
|
-
speedKitVersion,
|
|
65
|
-
rumPluginVersion,
|
|
66
|
-
ppVersion,
|
|
67
|
-
configPluginsVersion,
|
|
68
|
-
documentHandlerVersion,
|
|
69
|
-
});
|
|
39
|
+
`https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false);
|
|
70
40
|
}
|
|
71
41
|
}
|
|
72
42
|
class RequiredParameter {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BundleService } from "../../bundler/index.js";
|
|
2
2
|
import type { SpeedKitConfigInterface, VirtualFileInterface, VirtualFileRecipe } from "../integration-api-model.js";
|
|
3
3
|
import { InstallResourceFile } from "./install-resource-file.js";
|
|
4
4
|
import { SpeedKitConfig } from "./speed-kit-config.js";
|
|
5
|
-
import type { CustomerConfig } from "./customer-config.js";
|
|
6
|
-
/** What of the customer config decides how a Speed Kit config is bundled and read. */
|
|
7
|
-
export type SpeedKitConfigCustomer = Pick<CustomerConfig, "app" | "features"> & AssetVersions;
|
|
8
5
|
/** The name the config deployed to the app is read back under. */
|
|
9
6
|
export declare const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
|
|
10
7
|
/** The file a {@link SpeedKitConfigFile} stands for. */
|
|
@@ -26,7 +23,7 @@ export interface SpeedKitConfigFileInit {
|
|
|
26
23
|
export declare class SpeedKitConfigFile extends InstallResourceFile implements SpeedKitConfigInterface {
|
|
27
24
|
private readonly bundler;
|
|
28
25
|
/**
|
|
29
|
-
* One evaluation per app
|
|
26
|
+
* One evaluation per app and origin. A config branches on
|
|
30
27
|
* `window.location`, so the same file read for two origins is two different
|
|
31
28
|
* configs — and bundling one is expensive enough not to repeat per caller.
|
|
32
29
|
*/
|
|
@@ -37,8 +34,8 @@ export declare class SpeedKitConfigFile extends InstallResourceFile implements S
|
|
|
37
34
|
*/
|
|
38
35
|
constructor(file: SpeedKitConfigFileInit, bundler: BundleService);
|
|
39
36
|
setContent(content: string): void;
|
|
40
|
-
/** The config this file describes for one
|
|
41
|
-
evaluate(
|
|
37
|
+
/** The config this file describes for one app and origin. */
|
|
38
|
+
evaluate(app: string, origin: string): Promise<SpeedKitConfig>;
|
|
42
39
|
}
|
|
43
40
|
/**
|
|
44
41
|
* A SpeedKit config that has no file on disk behind it — the one deployed to
|
|
@@ -63,5 +60,3 @@ export declare class VirtualSpeedKitConfigFile extends SpeedKitConfigFile implem
|
|
|
63
60
|
delete(): Promise<void>;
|
|
64
61
|
onChange(): void;
|
|
65
62
|
}
|
|
66
|
-
/** The customer has the `enableSpeedKitConfigPlugins` feature: packjockel bundles its config. */
|
|
67
|
-
export declare function usesConfigPlugins(customer: SpeedKitConfigCustomer): boolean;
|
|
@@ -3,7 +3,7 @@ import { EvaluateSkConfigError } from "../error/evaluate-sk-config-error.js";
|
|
|
3
3
|
import ApplicationError from "../../error-handling/error/application-error.js";
|
|
4
4
|
import { StaticRecipe } from "../virtual/static-recipe.js";
|
|
5
5
|
import { InstallResourceFile } from "./install-resource-file.js";
|
|
6
|
-
import { SpeedKitConfig
|
|
6
|
+
import { SpeedKitConfig } from "./speed-kit-config.js";
|
|
7
7
|
/** The name the config deployed to the app is read back under. */
|
|
8
8
|
export const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
|
|
9
9
|
/**
|
|
@@ -17,7 +17,7 @@ export const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
|
|
|
17
17
|
export class SpeedKitConfigFile extends InstallResourceFile {
|
|
18
18
|
bundler;
|
|
19
19
|
/**
|
|
20
|
-
* One evaluation per app
|
|
20
|
+
* One evaluation per app and origin. A config branches on
|
|
21
21
|
* `window.location`, so the same file read for two origins is two different
|
|
22
22
|
* configs — and bundling one is expensive enough not to repeat per caller.
|
|
23
23
|
*/
|
|
@@ -34,15 +34,14 @@ export class SpeedKitConfigFile extends InstallResourceFile {
|
|
|
34
34
|
super.setContent(content);
|
|
35
35
|
this.evaluations.clear();
|
|
36
36
|
}
|
|
37
|
-
/** The config this file describes for one
|
|
38
|
-
evaluate(
|
|
39
|
-
const {
|
|
40
|
-
const key = `${app}|${origin}|${usesConfigPlugins(customer) ? "packjockel" : "esbuild"}`;
|
|
37
|
+
/** The config this file describes for one app and origin. */
|
|
38
|
+
evaluate(app, origin) {
|
|
39
|
+
const key = `${app}|${origin}`;
|
|
41
40
|
const cached = this.evaluations.get(key);
|
|
42
41
|
if (cached) {
|
|
43
42
|
return cached;
|
|
44
43
|
}
|
|
45
|
-
const evaluation = bundle(this.bundler, this.getContent(),
|
|
44
|
+
const evaluation = bundle(this.bundler, this.getContent(), app)
|
|
46
45
|
.then((code) => evaluateSpeedKitConfig(app, origin, code, this.path))
|
|
47
46
|
.catch((error) => {
|
|
48
47
|
// A failure is not an answer: forget it, so the next caller — or the
|
|
@@ -96,8 +95,7 @@ export class VirtualSpeedKitConfigFile extends SpeedKitConfigFile {
|
|
|
96
95
|
}
|
|
97
96
|
/**
|
|
98
97
|
* Run a bundled config against a browser mock and hand back what it assigned to
|
|
99
|
-
* `
|
|
100
|
-
* plugins it registered.
|
|
98
|
+
* `window.speedKit`, together with the config plugins it registered.
|
|
101
99
|
*
|
|
102
100
|
* @param app the app the config is evaluated for, exposed to it as `APP`
|
|
103
101
|
* @param origin the origin the config is evaluated for, its `window.location`
|
|
@@ -115,7 +113,7 @@ function evaluateSpeedKitConfig(app, origin, code, filename) {
|
|
|
115
113
|
if (browserContext.vmError !== null) {
|
|
116
114
|
throw new EvaluateSkConfigError(`[${filename}] ${browserContext.vmError?.message}`);
|
|
117
115
|
}
|
|
118
|
-
return SpeedKitConfig.createFrom(browserContext.window.
|
|
116
|
+
return SpeedKitConfig.createFrom(browserContext.window.speedKit, registeredPlugins(browserContext));
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
121
119
|
* The plugins a config registered, read the way `ConfigController.getPlugins`
|
|
@@ -138,9 +136,7 @@ function buildBrowserMock(origin, app) {
|
|
|
138
136
|
},
|
|
139
137
|
customVariation: [],
|
|
140
138
|
},
|
|
141
|
-
|
|
142
|
-
// way packjockel hands it over.
|
|
143
|
-
SpeedKit: { configPlugins: [] },
|
|
139
|
+
SpeedKit: {},
|
|
144
140
|
serviceWorkerUrl: "",
|
|
145
141
|
screen: { width: 0, height: 0 },
|
|
146
142
|
devicePixelRatio: 1,
|
|
@@ -218,23 +214,10 @@ function safeFileContentWrapper(fileContent) {
|
|
|
218
214
|
}
|
|
219
215
|
`;
|
|
220
216
|
}
|
|
221
|
-
|
|
222
|
-
export function usesConfigPlugins(customer) {
|
|
223
|
-
return customer.features?.enableSpeedKitConfigPlugins === true;
|
|
224
|
-
}
|
|
225
|
-
async function bundle(bundler, content, customer) {
|
|
217
|
+
async function bundle(bundler, content, app) {
|
|
226
218
|
if (!content) {
|
|
227
219
|
throw new ApplicationError("Content is empty");
|
|
228
220
|
}
|
|
229
|
-
const app = customer.app;
|
|
230
|
-
if (usesConfigPlugins(customer)) {
|
|
231
|
-
return bundler.packjockel.bundle({
|
|
232
|
-
entryPoints: { "config.js": content },
|
|
233
|
-
versions: customer,
|
|
234
|
-
define: { APP: JSON.stringify(app) },
|
|
235
|
-
platform: "browser",
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
221
|
return bundler.bundle({
|
|
239
222
|
basePaths: {
|
|
240
223
|
"speed-kit-config": "https://www.baqend.com/speed-kit-config/latest/",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { usesConfigPlugins, } from "../../integration-api/index.js";
|
|
2
1
|
import { INTEGRATION_FILES } from "../../../models/files.js";
|
|
3
2
|
const IMPORT_PATHS = {
|
|
4
3
|
rum: "https://www.baqend.com/rum/latest/",
|
|
@@ -20,10 +19,8 @@ export class SpeedKitInstallContext {
|
|
|
20
19
|
this.skTemplate = skTemplate;
|
|
21
20
|
}
|
|
22
21
|
async getSpeedKitInstallJs() {
|
|
23
|
-
const configPlugins = usesConfigPlugins(this.customerConfig);
|
|
24
22
|
const configJs = this.skTemplate.render({
|
|
25
23
|
config: this.getConfigSpeedKit(),
|
|
26
|
-
configPlugins,
|
|
27
24
|
forceInstall: this.customerConfig.forceInstall,
|
|
28
25
|
installPath: this.customerConfig.installPath,
|
|
29
26
|
installParams: this.customerConfig.installParams,
|
|
@@ -32,29 +29,15 @@ export class SpeedKitInstallContext {
|
|
|
32
29
|
.getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
33
30
|
.getContent(),
|
|
34
31
|
});
|
|
35
|
-
const entryPoints = {
|
|
36
|
-
"rum.js": this.prepareConfigLoadHandler(),
|
|
37
|
-
"config.js": configJs,
|
|
38
|
-
// Like the install script of the server (packjockel!121), without skVersion and installationId:
|
|
39
|
-
// a local run has no installation.
|
|
40
|
-
...(configPlugins && {
|
|
41
|
-
"installation.js": "Object.assign(SpeedKit.config, { app: APP });",
|
|
42
|
-
}),
|
|
43
|
-
"loader.js": this.files
|
|
44
|
-
.getByName(INTEGRATION_FILES.CUSTOM.LOADER)
|
|
45
|
-
.getContent(),
|
|
46
|
-
};
|
|
47
|
-
if (configPlugins) {
|
|
48
|
-
return this.bundler.packjockel.bundle({
|
|
49
|
-
entryPoints,
|
|
50
|
-
versions: this.customerConfig,
|
|
51
|
-
define: { APP: JSON.stringify(this.customerConfig.app) },
|
|
52
|
-
platform: "browser",
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
32
|
return this.bundler.bundle({
|
|
56
33
|
basePaths: IMPORT_PATHS,
|
|
57
|
-
entryPoints
|
|
34
|
+
entryPoints: {
|
|
35
|
+
"rum.js": this.prepareConfigLoadHandler(),
|
|
36
|
+
"config.js": configJs,
|
|
37
|
+
"loader.js": this.files
|
|
38
|
+
.getByName(INTEGRATION_FILES.CUSTOM.LOADER)
|
|
39
|
+
.getContent(),
|
|
40
|
+
},
|
|
58
41
|
logLevel: "error",
|
|
59
42
|
minify: false,
|
|
60
43
|
platform: "browser",
|
|
@@ -89,7 +72,7 @@ export class SpeedKitInstallContext {
|
|
|
89
72
|
return config.replace(value, "100");
|
|
90
73
|
});
|
|
91
74
|
}
|
|
92
|
-
return configString.replace(/
|
|
75
|
+
return configString.replace(/window\.speedKit[^{]*=[^{]*{/, (configOpenTag) => {
|
|
93
76
|
return configOpenTag + `\n delayRacedOrigin: 100,\n`;
|
|
94
77
|
});
|
|
95
78
|
}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server.js";
|
|
3
|
-
import { Crawler } from "../virtual-orestes-app/crawler.js";
|
|
1
|
+
import { DiffEngine, PageSource } from "../../diff/index.js";
|
|
4
2
|
import { CliServiceInterface } from "../../cli/index.js";
|
|
3
|
+
/** The body of a `/variant-diff` request. */
|
|
4
|
+
export interface VariantDiffRequest {
|
|
5
|
+
/** The page the browser shows. */
|
|
6
|
+
readonly currentHtml: string;
|
|
7
|
+
readonly currentUrl: string;
|
|
8
|
+
readonly variant?: string;
|
|
9
|
+
/** Run both through the documentHandler before comparing. */
|
|
10
|
+
readonly transform?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Fetch the remote page twice and ignore what differs between the two, as
|
|
13
|
+
* `sk diff --baseline` does. Off by default: it doubles the requests.
|
|
14
|
+
*/
|
|
15
|
+
readonly baseline?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The dashboard's `/variant-diff`: the page the browser shows against the same
|
|
19
|
+
* page fetched from origin for a variation, built the way `sk diff` builds a
|
|
20
|
+
* side.
|
|
21
|
+
*/
|
|
5
22
|
export declare class DiffAgainstCurrentPage {
|
|
6
23
|
private diffService;
|
|
7
|
-
private
|
|
8
|
-
private crawler;
|
|
24
|
+
private pages;
|
|
9
25
|
private cli;
|
|
10
|
-
constructor(diffService:
|
|
11
|
-
|
|
26
|
+
constructor(diffService: DiffEngine, pages: PageSource, cli: CliServiceInterface);
|
|
27
|
+
/**
|
|
28
|
+
* Resolves to whether the two are equal. With `transform`, both run
|
|
29
|
+
* through the documentHandler first; without, both are compared as they
|
|
30
|
+
* are. With `baseline`, the remote page is fetched twice, and what differs
|
|
31
|
+
* between the two is ignored; the current page has one response only.
|
|
32
|
+
*/
|
|
33
|
+
postDiff({ currentHtml, currentUrl, variant, transform, baseline, }: VariantDiffRequest): Promise<boolean>;
|
|
12
34
|
}
|
|
@@ -1,46 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withoutNoise } from "../../diff/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The dashboard's `/variant-diff`: the page the browser shows against the same
|
|
4
|
+
* page fetched from origin for a variation, built the way `sk diff` builds a
|
|
5
|
+
* side.
|
|
6
|
+
*/
|
|
2
7
|
export class DiffAgainstCurrentPage {
|
|
3
8
|
diffService;
|
|
4
|
-
|
|
5
|
-
crawler;
|
|
9
|
+
pages;
|
|
6
10
|
cli;
|
|
7
|
-
constructor(diffService,
|
|
11
|
+
constructor(diffService, pages, cli) {
|
|
8
12
|
this.diffService = diffService;
|
|
9
|
-
this.
|
|
10
|
-
this.crawler = crawler;
|
|
13
|
+
this.pages = pages;
|
|
11
14
|
this.cli = cli;
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Resolves to whether the two are equal. With `transform`, both run
|
|
18
|
+
* through the documentHandler first; without, both are compared as they
|
|
19
|
+
* are. With `baseline`, the remote page is fetched twice, and what differs
|
|
20
|
+
* between the two is ignored; the current page has one response only.
|
|
21
|
+
*/
|
|
22
|
+
async postDiff({ currentHtml, currentUrl, variant = "default", transform = false, baseline = false, }) {
|
|
14
23
|
this.cli.writeWarning(`received diff for url: ${currentUrl}`);
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.cli.startAction(`DIFF:TRANSFORM:FILE:${currentUrl}`, `transform documents`);
|
|
24
|
-
if (transform) {
|
|
25
|
-
// todo check if the currentHTML is already transformed
|
|
26
|
-
// TODO: we may need to forward the correct content type from the origin response
|
|
27
|
-
const contentType = "text/html; charset=utf-8";
|
|
28
|
-
const currentDocumentHandlerResponse = await this.documentHandlerRuntime.transform(contentType, currentHtml, variant, currentUrl, {});
|
|
29
|
-
const currentResponse = currentDocumentHandlerResponse.body;
|
|
30
|
-
if (Buffer.isBuffer(currentResponse)) {
|
|
31
|
-
throw new TypeError("cant diff body as buffer");
|
|
32
|
-
}
|
|
33
|
-
currentHtml = currentResponse;
|
|
34
|
-
const originDocumentHandlerResponse = await this.documentHandlerRuntime.transform(contentType, originHtml, variant, currentUrl, {});
|
|
35
|
-
const originResponse = originDocumentHandlerResponse.body;
|
|
36
|
-
if (Buffer.isBuffer(originResponse)) {
|
|
37
|
-
throw new TypeError("cant diff body as buffer");
|
|
38
|
-
}
|
|
39
|
-
originHtml = originResponse;
|
|
40
|
-
}
|
|
41
|
-
this.cli.successAction(`DIFF:TRANSFORM:FILE:${currentUrl}`);
|
|
42
|
-
const remoteFilePath = await this.diffService.writeContentToTemporalFile(`remote-${variant}.html`, formatHtml(originHtml));
|
|
43
|
-
const localFilePath = await this.diffService.writeContentToTemporalFile("current.html", formatHtml(currentHtml));
|
|
44
|
-
return await this.diffService.executeDiff(remoteFilePath, localFilePath);
|
|
24
|
+
const raw = !transform;
|
|
25
|
+
const remote = await this.pages.fetch(currentUrl, variant, `remote-${variant}.html`, { raw, baseline });
|
|
26
|
+
const current = await this.pages.fromHtml(currentHtml, currentUrl, variant, {
|
|
27
|
+
raw,
|
|
28
|
+
label: "current.html",
|
|
29
|
+
});
|
|
30
|
+
const { equal } = await this.diffService.compare(remote, withoutNoise(remote, current));
|
|
31
|
+
return equal;
|
|
45
32
|
}
|
|
46
33
|
}
|
|
@@ -105,16 +105,23 @@ export class Dashboard {
|
|
|
105
105
|
if (url.pathname.startsWith("/diff")) {
|
|
106
106
|
const postData = request.postData;
|
|
107
107
|
const data = JSON.parse(postData);
|
|
108
|
-
return this.requestDiffService.postDiff(requestOrigin,
|
|
108
|
+
return this.requestDiffService.postDiff(requestOrigin, {
|
|
109
|
+
url: data.url,
|
|
110
|
+
paramKeys: data.paramKeys,
|
|
111
|
+
autoDiff: data.autoDiff,
|
|
112
|
+
baseline: data.baseline === true,
|
|
113
|
+
});
|
|
109
114
|
}
|
|
110
115
|
if (url.pathname.startsWith("/variant-diff")) {
|
|
111
116
|
const postData = request.postData;
|
|
112
117
|
const data = JSON.parse(postData);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
const diffResult = await safe(this.currentPageDiff.postDiff({
|
|
119
|
+
currentHtml: data.currentHtml,
|
|
120
|
+
currentUrl: data.currentUrl,
|
|
121
|
+
variant: data.variant || "DEFAULT",
|
|
122
|
+
transform: Boolean(data.transform),
|
|
123
|
+
baseline: data.baseline === true,
|
|
124
|
+
}));
|
|
118
125
|
if (diffResult.success === true) {
|
|
119
126
|
return this.createBaqendResponse(requestOrigin, JSON.stringify({ success: diffResult.data }), "application/json; charset=UTF-8", [], 200);
|
|
120
127
|
}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DiffEngine, PageSource } from "../../diff/index.js";
|
|
2
2
|
import { BaqendResponse } from "../browser/baqend-response.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/** The body of a `/diff` request. */
|
|
4
|
+
export interface ParameterDiffRequest {
|
|
5
|
+
readonly url: string;
|
|
6
|
+
/** The parameters to remove, as `[a, b]`. */
|
|
7
|
+
readonly paramKeys: string;
|
|
8
|
+
/** Only tell whether the pages are equal; open no diff tool. */
|
|
9
|
+
readonly autoDiff?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Fetch each page twice and ignore what differs between the two, as
|
|
12
|
+
* `sk diff --baseline` does. Off by default: it doubles the requests.
|
|
13
|
+
*/
|
|
14
|
+
readonly baseline?: boolean;
|
|
15
|
+
}
|
|
5
16
|
export declare class RequestDiffService {
|
|
6
17
|
private diffService;
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
private pages;
|
|
19
|
+
constructor(diffService: DiffEngine, pages: PageSource);
|
|
20
|
+
postDiff(requestOrigin: string, request: ParameterDiffRequest): Promise<BaqendResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Compares the page with and without the parameters, both fetched and
|
|
23
|
+
* rendered the way `sk diff` builds a side.
|
|
24
|
+
*/
|
|
11
25
|
private diffLocal;
|
|
12
|
-
private fetchHtml;
|
|
13
26
|
private createUrlsForDiff;
|
|
14
27
|
private createBaqendResponse;
|
|
15
28
|
}
|