@speedkit/cli 4.44.0-beta.3 → 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 +38 -8
- 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 -20
- 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 +294 -162
- 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,95 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { baselineOf, withoutNoise } from "../noise-baseline.js";
|
|
4
|
+
const lines = (...content) => content.join("\n");
|
|
5
|
+
describe("noise baseline", () => {
|
|
6
|
+
it("finds the lines that differ between two identical requests", () => {
|
|
7
|
+
const baseline = baselineOf(lines("<a>", '<script nonce="111">', "<b>"), lines("<a>", '<script nonce="222">', "<b>"));
|
|
8
|
+
expect([...baseline.lines]).to.deep.equal(['<script nonce="0">']);
|
|
9
|
+
expect(baseline.reorders).to.equal(false);
|
|
10
|
+
});
|
|
11
|
+
it("recognises a line whose random hex id changes on every request", () => {
|
|
12
|
+
const baseline = baselineOf('<article item-data-ref="6abfae220721d">', '<article item-data-ref="6abfae2207653">');
|
|
13
|
+
const left = {
|
|
14
|
+
label: "with",
|
|
15
|
+
content: '<article item-data-ref="6abfae220721d">',
|
|
16
|
+
baseline,
|
|
17
|
+
};
|
|
18
|
+
const right = {
|
|
19
|
+
label: "without",
|
|
20
|
+
content: '<article item-data-ref="6abfae249582c">',
|
|
21
|
+
};
|
|
22
|
+
expect(withoutNoise(left, right).content).to.equal(left.content);
|
|
23
|
+
});
|
|
24
|
+
it("takes a change of a volatile line back to the left side", () => {
|
|
25
|
+
const left = {
|
|
26
|
+
label: "desktop",
|
|
27
|
+
content: lines("<a>", '<x data="10">', "<b>"),
|
|
28
|
+
baseline: { lines: new Set(['<x data="0">']), reorders: false },
|
|
29
|
+
};
|
|
30
|
+
const right = {
|
|
31
|
+
label: "mobile",
|
|
32
|
+
content: lines("<a>", '<x data="37">', "<b>"),
|
|
33
|
+
};
|
|
34
|
+
const reduced = withoutNoise(left, right);
|
|
35
|
+
expect(reduced.content).to.equal(left.content);
|
|
36
|
+
expect(reduced.details).to.include({ ignoredLines: 2 });
|
|
37
|
+
});
|
|
38
|
+
it("keeps a real difference next to the noise", () => {
|
|
39
|
+
const left = {
|
|
40
|
+
label: "desktop",
|
|
41
|
+
content: lines('<x data="10">', "<nav>desktop</nav>"),
|
|
42
|
+
baseline: { lines: new Set(['<x data="0">']), reorders: false },
|
|
43
|
+
};
|
|
44
|
+
const right = {
|
|
45
|
+
label: "mobile",
|
|
46
|
+
content: lines('<x data="99">', "<nav>mobile</nav>"),
|
|
47
|
+
baseline: { lines: new Set(), reorders: false },
|
|
48
|
+
};
|
|
49
|
+
const reduced = withoutNoise(left, right);
|
|
50
|
+
// One hunk: its real line makes the noise next to it part of the change.
|
|
51
|
+
expect(reduced.content).to.equal(right.content);
|
|
52
|
+
});
|
|
53
|
+
it("keeps a real change of a line the baseline saw change", () => {
|
|
54
|
+
const left = {
|
|
55
|
+
label: "desktop",
|
|
56
|
+
content: lines("<a>", '<x state="1" keys="a,b">', "<b>"),
|
|
57
|
+
baseline: {
|
|
58
|
+
lines: new Set(['<x state="0" keys="a,b">']),
|
|
59
|
+
reorders: false,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const right = {
|
|
63
|
+
label: "mobile",
|
|
64
|
+
content: lines("<a>", '<x state="2" keys="b,a">', "<b>"),
|
|
65
|
+
};
|
|
66
|
+
expect(withoutNoise(left, right).content).to.equal(right.content);
|
|
67
|
+
});
|
|
68
|
+
it("counts a reordered line as noise when the baseline saw it move", () => {
|
|
69
|
+
const first = lines("<link a>", "<link b>", "<link c>");
|
|
70
|
+
const second = lines("<link b>", "<link a>", "<link c>");
|
|
71
|
+
const left = {
|
|
72
|
+
label: "desktop",
|
|
73
|
+
content: first,
|
|
74
|
+
baseline: baselineOf(first, second),
|
|
75
|
+
};
|
|
76
|
+
const right = {
|
|
77
|
+
label: "mobile",
|
|
78
|
+
content: lines("<link a>", "<link c>", "<link b>"),
|
|
79
|
+
};
|
|
80
|
+
expect(withoutNoise(left, right).content).to.equal(first);
|
|
81
|
+
});
|
|
82
|
+
it("keeps a reordered line the baseline never saw move", () => {
|
|
83
|
+
const left = {
|
|
84
|
+
label: "desktop",
|
|
85
|
+
content: lines("<link a>", "<link b>"),
|
|
86
|
+
baseline: { lines: new Set(["<other>"]), reorders: false },
|
|
87
|
+
};
|
|
88
|
+
const right = { label: "mobile", content: lines("<link b>", "<link a>") };
|
|
89
|
+
expect(withoutNoise(left, right).content).to.not.equal(left.content);
|
|
90
|
+
});
|
|
91
|
+
it("leaves the right side alone without a baseline", () => {
|
|
92
|
+
const right = { label: "b", content: "<p>2</p>" };
|
|
93
|
+
expect(withoutNoise({ label: "a", content: "<p>1</p>" }, right)).to.equal(right);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { afterEach, describe, it } from "mocha";
|
|
3
|
+
import { setOriginFetchTransport } from "../../../helpers/origin-proxy.js";
|
|
4
|
+
import ApplicationError from "../../error-handling/error/application-error.js";
|
|
5
|
+
import { MOBILE_USER_AGENT, OriginFetcher, } from "../../origin-request/index.js";
|
|
6
|
+
import { PageSource } from "../page-source.js";
|
|
7
|
+
import { PageSideFailure } from "../side-failure.js";
|
|
8
|
+
import { DocumentHandlerAbort } from "../../document-handler-runtime/document-handler-abort.js";
|
|
9
|
+
import { DocumentHandlerTransformError } from "../../onboarding/error/document-handler-transform-error.js";
|
|
10
|
+
/** Answers every request with `body`, and records what was requested. */
|
|
11
|
+
function origin(body, status = 200) {
|
|
12
|
+
const seen = [];
|
|
13
|
+
setOriginFetchTransport(async (url, init) => {
|
|
14
|
+
seen.push({ url, headers: init?.headers });
|
|
15
|
+
return new Response(body, {
|
|
16
|
+
status,
|
|
17
|
+
headers: { "content-type": "text/html" },
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
return seen;
|
|
21
|
+
}
|
|
22
|
+
/** A strict fetcher over a runtime config without variations, as `sk diff` builds it. */
|
|
23
|
+
function fetcher() {
|
|
24
|
+
return new OriginFetcher({
|
|
25
|
+
cli: {
|
|
26
|
+
startAction: () => undefined,
|
|
27
|
+
successAction: () => undefined,
|
|
28
|
+
failAction: () => undefined,
|
|
29
|
+
writeWarning: () => undefined,
|
|
30
|
+
writeError: () => undefined,
|
|
31
|
+
},
|
|
32
|
+
config: { variations: {}, authentications: [] },
|
|
33
|
+
strict: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
describe("PageSource", () => {
|
|
37
|
+
afterEach(() => setOriginFetchTransport());
|
|
38
|
+
it("requests a variation with the headers Speed Kit's server sends", async () => {
|
|
39
|
+
const seen = origin("<p>x</p>");
|
|
40
|
+
const pages = new PageSource({ fetcher: fetcher(), ignore: [] });
|
|
41
|
+
const side = await pages.fetch("https://shop.test/?a=1", "mobile", "m");
|
|
42
|
+
expect(seen[0].headers["user-agent"]).to.equal(MOBILE_USER_AGENT);
|
|
43
|
+
expect(side.details).to.include({ variation: "mobile", status: 200 });
|
|
44
|
+
});
|
|
45
|
+
it("renders the page through the documentHandler for its variation", async () => {
|
|
46
|
+
origin("<p>origin</p>");
|
|
47
|
+
const calls = [];
|
|
48
|
+
const documentHandler = {
|
|
49
|
+
async transform(_type, html, variation) {
|
|
50
|
+
calls.push(variation);
|
|
51
|
+
return { body: html.replace("origin", "rendered") };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const pages = new PageSource({
|
|
55
|
+
fetcher: fetcher(),
|
|
56
|
+
ignore: [],
|
|
57
|
+
documentHandler,
|
|
58
|
+
});
|
|
59
|
+
const side = await pages.fetch("https://shop.test/", "tablet", "t");
|
|
60
|
+
expect(calls).to.deep.equal(["tablet"]);
|
|
61
|
+
expect(side.content).to.contain("rendered");
|
|
62
|
+
});
|
|
63
|
+
it("drops the asset url meta and what an ignore pattern matches", async () => {
|
|
64
|
+
origin('<head><meta name="baqend:asset_url" content="https://shop.test/?a=1"><script nonce="abc"></script></head>');
|
|
65
|
+
const pages = new PageSource({
|
|
66
|
+
fetcher: fetcher(),
|
|
67
|
+
ignore: [/ nonce="[^"]*"/g],
|
|
68
|
+
});
|
|
69
|
+
const side = await pages.fetch("https://shop.test/?a=1", "default", "d");
|
|
70
|
+
expect(side.content).to.not.contain("asset_url");
|
|
71
|
+
expect(side.content).to.not.contain("nonce");
|
|
72
|
+
});
|
|
73
|
+
it("refuses a page the origin does not answer with 200, classified as Speed Kit does", async () => {
|
|
74
|
+
origin("challenge", 403);
|
|
75
|
+
const pages = new PageSource({ fetcher: fetcher(), ignore: [] });
|
|
76
|
+
const error = (await pages
|
|
77
|
+
.fetch("https://shop.test/", "default", "d")
|
|
78
|
+
.catch((error_) => error_));
|
|
79
|
+
expect(error).to.be.instanceOf(PageSideFailure);
|
|
80
|
+
expect(error.failure).to.include({
|
|
81
|
+
kind: "origin",
|
|
82
|
+
code: "109",
|
|
83
|
+
cause: "OriginBlockedStatus",
|
|
84
|
+
status: 403,
|
|
85
|
+
});
|
|
86
|
+
expect(error.suggestions.join(" ")).to.contain("bot protection");
|
|
87
|
+
});
|
|
88
|
+
it("names a missing page as one, not as a bot protection", async () => {
|
|
89
|
+
origin("gone", 404);
|
|
90
|
+
const pages = new PageSource({ fetcher: fetcher(), ignore: [] });
|
|
91
|
+
const error = (await pages
|
|
92
|
+
.fetch("https://shop.test/?page=2", "default", "d")
|
|
93
|
+
.catch((error_) => error_));
|
|
94
|
+
expect(error.failure).to.include({
|
|
95
|
+
code: "105",
|
|
96
|
+
cause: "OriginStatusNotFound",
|
|
97
|
+
});
|
|
98
|
+
expect(error.suggestions.join(" "))
|
|
99
|
+
.to.contain("does not exist")
|
|
100
|
+
.and.not.contain("bot protection");
|
|
101
|
+
});
|
|
102
|
+
it("tells a documentHandler abort from a documentHandler error", async () => {
|
|
103
|
+
origin("<p>x</p>");
|
|
104
|
+
const throwing = (error) => ({
|
|
105
|
+
async transform() {
|
|
106
|
+
throw new DocumentHandlerTransformError(error);
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
const failureOf = async (error) => {
|
|
110
|
+
const pages = new PageSource({
|
|
111
|
+
fetcher: fetcher(),
|
|
112
|
+
ignore: [],
|
|
113
|
+
documentHandler: throwing(error),
|
|
114
|
+
});
|
|
115
|
+
const thrown = (await pages
|
|
116
|
+
.fetch("https://shop.test/", "default", "d")
|
|
117
|
+
.catch((error_) => error_));
|
|
118
|
+
return thrown.failure;
|
|
119
|
+
};
|
|
120
|
+
expect(await failureOf(new DocumentHandlerAbort("old-engine PLP"))).to.deep.equal({
|
|
121
|
+
kind: "documentHandlerAbort",
|
|
122
|
+
code: "303",
|
|
123
|
+
cause: "ServerDocumentHandlerAbort",
|
|
124
|
+
reason: "old-engine PLP",
|
|
125
|
+
});
|
|
126
|
+
expect(await failureOf(new TypeError("x is undefined"))).to.deep.include({
|
|
127
|
+
kind: "documentHandlerError",
|
|
128
|
+
code: "314",
|
|
129
|
+
cause: "ServerDocumentHandlerError",
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
it("refuses a variation the runtime config does not define", async () => {
|
|
133
|
+
origin("<p>x</p>");
|
|
134
|
+
const pages = new PageSource({ fetcher: fetcher(), ignore: [] });
|
|
135
|
+
const error = await pages
|
|
136
|
+
.fetch("https://shop.test/", "b2b", "d")
|
|
137
|
+
.catch((error_) => error_);
|
|
138
|
+
expect(error).to.be.instanceOf(ApplicationError);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { JsonDiffSink } from "../../sinks/json-diff-sink.js";
|
|
4
|
+
/** A CLI whose data channel is a string. */
|
|
5
|
+
function pipeCli() {
|
|
6
|
+
const cli = {
|
|
7
|
+
piped: "",
|
|
8
|
+
pipe(data) {
|
|
9
|
+
cli.piped += data;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
return cli;
|
|
13
|
+
}
|
|
14
|
+
function result(left, right, equal = false) {
|
|
15
|
+
return {
|
|
16
|
+
equal,
|
|
17
|
+
left: { label: "with", content: left, details: { status: 200 } },
|
|
18
|
+
right: { label: "without", content: right },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
describe("JsonDiffSink", () => {
|
|
22
|
+
it("prints every result as one array when finished", async () => {
|
|
23
|
+
const cli = pipeCli();
|
|
24
|
+
const sink = new JsonDiffSink(cli);
|
|
25
|
+
await sink.show(result("a\n", "b\n"));
|
|
26
|
+
await sink.show(result("a", "a", true));
|
|
27
|
+
expect(cli.piped).to.equal("");
|
|
28
|
+
sink.finish();
|
|
29
|
+
const entries = JSON.parse(cli.piped);
|
|
30
|
+
expect(entries).to.have.length(2);
|
|
31
|
+
expect(entries[0].left).to.deep.equal({
|
|
32
|
+
status: 200,
|
|
33
|
+
label: "with",
|
|
34
|
+
bytes: 2,
|
|
35
|
+
});
|
|
36
|
+
expect(entries[0].patch).to.contain("+b");
|
|
37
|
+
expect(entries[0].outcome).to.equal("differs");
|
|
38
|
+
expect(entries[1]).to.include({
|
|
39
|
+
outcome: "equal",
|
|
40
|
+
equal: true,
|
|
41
|
+
patch: null,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it("lists a comparison a side failed, with the failure", () => {
|
|
45
|
+
const cli = pipeCli();
|
|
46
|
+
const sink = new JsonDiffSink(cli);
|
|
47
|
+
const failure = {
|
|
48
|
+
kind: "documentHandlerAbort",
|
|
49
|
+
code: "303",
|
|
50
|
+
cause: "ServerDocumentHandlerAbort",
|
|
51
|
+
reason: "old-engine PLP",
|
|
52
|
+
};
|
|
53
|
+
sink.fail({
|
|
54
|
+
outcome: "uncacheable",
|
|
55
|
+
left: { label: "with", failure, details: { url: "https://shop.test/" } },
|
|
56
|
+
right: { label: "without", content: "ab" },
|
|
57
|
+
});
|
|
58
|
+
sink.finish();
|
|
59
|
+
const [entry] = JSON.parse(cli.piped);
|
|
60
|
+
expect(entry).to.include({
|
|
61
|
+
outcome: "uncacheable",
|
|
62
|
+
equal: false,
|
|
63
|
+
patch: null,
|
|
64
|
+
});
|
|
65
|
+
expect(entry.left).to.deep.equal({
|
|
66
|
+
url: "https://shop.test/",
|
|
67
|
+
label: "with",
|
|
68
|
+
failure,
|
|
69
|
+
});
|
|
70
|
+
expect(entry.right).to.deep.equal({ label: "without", bytes: 2 });
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { PatchDiffSink } from "../../sinks/patch-diff-sink.js";
|
|
4
|
+
/** A CLI whose data channel is a string. */
|
|
5
|
+
function pipeCli() {
|
|
6
|
+
const cli = {
|
|
7
|
+
piped: "",
|
|
8
|
+
pipe(data) {
|
|
9
|
+
cli.piped += data;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
return cli;
|
|
13
|
+
}
|
|
14
|
+
function result(left, right, equal = false) {
|
|
15
|
+
return {
|
|
16
|
+
equal,
|
|
17
|
+
left: { label: "with", content: left, details: { status: 200 } },
|
|
18
|
+
right: { label: "without", content: right },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
describe("PatchDiffSink", () => {
|
|
22
|
+
it("prints a differing result as a unified diff", async () => {
|
|
23
|
+
const cli = pipeCli();
|
|
24
|
+
await new PatchDiffSink({ cli }).show(result("a\nb\nc\n", "a\nx\nc\n"));
|
|
25
|
+
expect(cli.piped).to.contain("--- with\n+++ without\n");
|
|
26
|
+
expect(cli.piped).to.contain("-b\n+x\n");
|
|
27
|
+
});
|
|
28
|
+
it("prints nothing for an equal result", async () => {
|
|
29
|
+
const cli = pipeCli();
|
|
30
|
+
await new PatchDiffSink({ cli }).show(result("a", "a", true));
|
|
31
|
+
expect(cli.piped).to.equal("");
|
|
32
|
+
});
|
|
33
|
+
it("leaves out a change of whitespace alone", async () => {
|
|
34
|
+
const cli = pipeCli();
|
|
35
|
+
await new PatchDiffSink({ cli }).show(result("a\n b\nc\n", "a\nb\nd\n"));
|
|
36
|
+
expect(cli.piped).to.not.contain("+b");
|
|
37
|
+
expect(cli.piped).to.contain("+d");
|
|
38
|
+
});
|
|
39
|
+
it("cuts a long patch and says how much it left out", async () => {
|
|
40
|
+
const cli = pipeCli();
|
|
41
|
+
const many = (prefix) => Array.from({ length: 50 }, (_, index) => `${prefix}${index}`).join("\n");
|
|
42
|
+
await new PatchDiffSink({ cli, maxLines: 10 }).show(result(many("a"), many("b")));
|
|
43
|
+
const lines = cli.piped.trimEnd().split("\n");
|
|
44
|
+
expect(lines).to.have.length(11);
|
|
45
|
+
expect(lines.at(-1)).to.match(/^… \d+ more lines$/);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { afterEach, beforeEach, describe, it } from "mocha";
|
|
3
|
+
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { ToolDiffSink } from "../../sinks/tool-diff-sink.js";
|
|
7
|
+
const differing = {
|
|
8
|
+
equal: false,
|
|
9
|
+
left: { label: "remote file.js", content: "remote" },
|
|
10
|
+
right: { label: "local.js", content: "local" },
|
|
11
|
+
};
|
|
12
|
+
describe("ToolDiffSink", () => {
|
|
13
|
+
let dir;
|
|
14
|
+
let created;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
dir = mkdtempSync(path.join(tmpdir(), "sk-tool-diff-sink-"));
|
|
17
|
+
created = 0;
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
rmSync(dir, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
function sink(template) {
|
|
23
|
+
return new ToolDiffSink({
|
|
24
|
+
cli: {},
|
|
25
|
+
settings: {
|
|
26
|
+
diffExec: "sh",
|
|
27
|
+
diffExecTemplate: template,
|
|
28
|
+
ideaDirectory: "",
|
|
29
|
+
},
|
|
30
|
+
createDirectory: () => {
|
|
31
|
+
created++;
|
|
32
|
+
return dir;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
it("runs the configured tool and reads the right side back", async () => {
|
|
37
|
+
const edited = await sink(`$exec -c 'cat "$file1" > "$file2"'`).show(differing);
|
|
38
|
+
expect(edited).to.equal("remote");
|
|
39
|
+
});
|
|
40
|
+
it("writes each side under a file name made of its label", async () => {
|
|
41
|
+
await sink("$exec -c true").show(differing);
|
|
42
|
+
expect(readdirSync(dir).sort()).to.deep.equal([
|
|
43
|
+
"local.js",
|
|
44
|
+
"remote_file.js",
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
it("opens nothing and creates no directory for an equal result", async () => {
|
|
48
|
+
const edited = await sink("$exec -c 'exit 1'").show({
|
|
49
|
+
...differing,
|
|
50
|
+
equal: true,
|
|
51
|
+
});
|
|
52
|
+
expect(edited).to.equal(undefined);
|
|
53
|
+
expect(created).to.equal(0);
|
|
54
|
+
});
|
|
55
|
+
it("creates its directory once", async () => {
|
|
56
|
+
const tool = sink("$exec -c true");
|
|
57
|
+
await tool.show(differing);
|
|
58
|
+
await tool.show(differing);
|
|
59
|
+
expect(created).to.equal(1);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -34,6 +34,8 @@ export declare const ABORT_STATUS_CODE = 400;
|
|
|
34
34
|
* module.
|
|
35
35
|
*/
|
|
36
36
|
export declare const ABORT_ERROR_CODE = "303";
|
|
37
|
+
/** Speed Kit error code for a Document Handler that threw an ordinary error. */
|
|
38
|
+
export declare const DOCUMENT_HANDLER_ERROR_CODE = "314";
|
|
37
39
|
/**
|
|
38
40
|
* `server-timing` value that makes the service worker classify a response as an abort.
|
|
39
41
|
*
|
|
@@ -37,6 +37,8 @@ export const ABORT_STATUS_CODE = 400;
|
|
|
37
37
|
* module.
|
|
38
38
|
*/
|
|
39
39
|
export const ABORT_ERROR_CODE = "303";
|
|
40
|
+
/** Speed Kit error code for a Document Handler that threw an ordinary error. */
|
|
41
|
+
export const DOCUMENT_HANDLER_ERROR_CODE = "314";
|
|
40
42
|
/**
|
|
41
43
|
* `server-timing` value that makes the service worker classify a response as an abort.
|
|
42
44
|
*
|
|
@@ -13,11 +13,6 @@ export declare class DocumentHandlerServer {
|
|
|
13
13
|
private entityManager?;
|
|
14
14
|
private documentHandlerCode;
|
|
15
15
|
private documentHandlerConfigCode;
|
|
16
|
-
/**
|
|
17
|
-
* The packjockel bundle for a customer with the `enableSpeedKitConfigPlugins` feature: the handler, its config
|
|
18
|
-
* and the Speed Kit config in one CommonJS module, which exports `post`.
|
|
19
|
-
*/
|
|
20
|
-
private documentHandlerBundle?;
|
|
21
16
|
private database;
|
|
22
17
|
/** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
|
|
23
18
|
private readonly appModules;
|
|
@@ -27,23 +22,11 @@ export declare class DocumentHandlerServer {
|
|
|
27
22
|
*/
|
|
28
23
|
constructor(customerConfig: CustomerConfig, files: FileListInterface, bundler: BundleService, cli: CliServiceInterface, workSpace: string, verboseLevel?: boolean, entityManager?: EntityManager);
|
|
29
24
|
transform(contentType: string, html: string, variation: string, url: string, headers: Record<string, string>): Promise<DocumentHandlerResponse>;
|
|
30
|
-
/** Runs the handler in the context, and returns the config, which calls its `post`. */
|
|
31
|
-
private createScript;
|
|
32
|
-
/** Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. */
|
|
33
|
-
private createBundleScript;
|
|
34
|
-
private getDocumentHandlerConfigPath;
|
|
35
25
|
private getTransformFunctionWrapper;
|
|
36
26
|
buildDocumentHandler(): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Bundles the handler, its config and the Speed Kit config into one module, the way the server
|
|
39
|
-
* deploys a customer with the `enableSpeedKitConfigPlugins` feature.
|
|
40
|
-
*/
|
|
41
|
-
private bundleWithPackjockel;
|
|
42
27
|
private deactivateReleaseAndDeploymentDetection;
|
|
43
28
|
private getDocumentHandler;
|
|
44
29
|
private getDynamicFetcher;
|
|
45
|
-
/** The customer's own dynamic fetcher, or else the source of the latest one. */
|
|
46
|
-
private getDynamicFetcherSource;
|
|
47
30
|
private getDynamicFetcherConfig;
|
|
48
31
|
private getStyles;
|
|
49
32
|
private getDocumentHandlerConfig;
|
|
@@ -2,7 +2,6 @@ import { LATEST_DYNAMIC_FETCHER_URL, LOCAL_DOCUMENT_HANDLER, LOCAL_DOCUMENT_HAND
|
|
|
2
2
|
import RequiredFileNotFoundError from "./error/required-file-not-found-error.js";
|
|
3
3
|
import DatabaseMock from "./templates/database-mock.js";
|
|
4
4
|
import * as vm from "node:vm";
|
|
5
|
-
import { usesConfigPlugins, } from "../integration-api/index.js";
|
|
6
5
|
import { INTEGRATION_FILES } from "../../models/files.js";
|
|
7
6
|
// documentHandlerDependencies
|
|
8
7
|
import fetch from "node-fetch";
|
|
@@ -26,11 +25,6 @@ export class DocumentHandlerServer {
|
|
|
26
25
|
entityManager;
|
|
27
26
|
documentHandlerCode;
|
|
28
27
|
documentHandlerConfigCode;
|
|
29
|
-
/**
|
|
30
|
-
* The packjockel bundle for a customer with the `enableSpeedKitConfigPlugins` feature: the handler, its config
|
|
31
|
-
* and the Speed Kit config in one CommonJS module, which exports `post`.
|
|
32
|
-
*/
|
|
33
|
-
documentHandlerBundle;
|
|
34
28
|
database;
|
|
35
29
|
/** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
|
|
36
30
|
appModules = new Map();
|
|
@@ -48,11 +42,7 @@ export class DocumentHandlerServer {
|
|
|
48
42
|
this.entityManager = entityManager;
|
|
49
43
|
}
|
|
50
44
|
async transform(contentType, html, variation, url, headers) {
|
|
51
|
-
|
|
52
|
-
const built = configPlugins
|
|
53
|
-
? this.documentHandlerBundle
|
|
54
|
-
: this.documentHandlerCode && this.documentHandlerConfigCode;
|
|
55
|
-
if (!built) {
|
|
45
|
+
if (!this.documentHandlerCode || !this.documentHandlerConfigCode) {
|
|
56
46
|
await this.buildDocumentHandler();
|
|
57
47
|
}
|
|
58
48
|
const skInternalRequest = new Request(url, html, variation, headers, {
|
|
@@ -67,21 +57,26 @@ export class DocumentHandlerServer {
|
|
|
67
57
|
skInternalError: {},
|
|
68
58
|
Abort: DocumentHandlerAbort,
|
|
69
59
|
APP: this.customerConfig.app,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
: {
|
|
74
|
-
DYNAMIC_FETCHER: await this.getDynamicFetcher(),
|
|
75
|
-
DYNAMIC_FETCHER_CONFIG: await this.getDynamicFetcherConfig(),
|
|
76
|
-
CUSTOM_STYLES: this.getStyles(),
|
|
77
|
-
}),
|
|
60
|
+
DYNAMIC_FETCHER: await this.getDynamicFetcher(),
|
|
61
|
+
DYNAMIC_FETCHER_CONFIG: await this.getDynamicFetcherConfig(),
|
|
62
|
+
CUSTOM_STYLES: this.getStyles(),
|
|
78
63
|
...this.getContextVars(),
|
|
79
64
|
...this.createNodeVmContext(),
|
|
80
65
|
skErrorContext: {},
|
|
81
66
|
};
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
const customDocumentHandlerFile = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
|
|
68
|
+
if (customDocumentHandlerFile.path) {
|
|
69
|
+
vm.runInNewContext(this.documentHandlerCode, vmContext, {
|
|
70
|
+
filename: customDocumentHandlerFile.path,
|
|
71
|
+
displayErrors: true,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
vm.runInNewContext(this.documentHandlerCode, vmContext);
|
|
76
|
+
}
|
|
77
|
+
const script = new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), {
|
|
78
|
+
filename: this.files.getByName("config_documentHandler").path,
|
|
79
|
+
});
|
|
85
80
|
const vmResponse = await safe(new Promise((resolve, reject) => {
|
|
86
81
|
vmContext.skInternalResponse.resolve = resolve;
|
|
87
82
|
// @ts-expect-error reject is unknown
|
|
@@ -97,67 +92,17 @@ export class DocumentHandlerServer {
|
|
|
97
92
|
}
|
|
98
93
|
throw new DocumentHandlerTransformError(vmResponse.errorObj);
|
|
99
94
|
}
|
|
100
|
-
/** Runs the handler in the context, and returns the config, which calls its `post`. */
|
|
101
|
-
createScript(vmContext) {
|
|
102
|
-
const customDocumentHandlerFile = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
|
|
103
|
-
if (customDocumentHandlerFile.path) {
|
|
104
|
-
vm.runInNewContext(this.documentHandlerCode, vmContext, {
|
|
105
|
-
filename: customDocumentHandlerFile.path,
|
|
106
|
-
displayErrors: true,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
vm.runInNewContext(this.documentHandlerCode, vmContext);
|
|
111
|
-
}
|
|
112
|
-
return new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), { filename: this.getDocumentHandlerConfigPath() });
|
|
113
|
-
}
|
|
114
|
-
/** Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. */
|
|
115
|
-
createBundleScript() {
|
|
116
|
-
return new vm.Script(`(function (module, exports) {\n${this.documentHandlerBundle}\n})(module, module.exports);\n\n` +
|
|
117
|
-
`module.exports.post(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`, { filename: this.getDocumentHandlerConfigPath() });
|
|
118
|
-
}
|
|
119
|
-
getDocumentHandlerConfigPath() {
|
|
120
|
-
return this.files.getByName("config_documentHandler")
|
|
121
|
-
.path;
|
|
122
|
-
}
|
|
123
95
|
getTransformFunctionWrapper() {
|
|
124
96
|
return `\n\npost(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`;
|
|
125
97
|
}
|
|
126
98
|
async buildDocumentHandler() {
|
|
127
99
|
this.cli.startAction("DOCUMENTHANDLER:BUILD", "rebuild documentHandler");
|
|
128
|
-
if (usesConfigPlugins(this.customerConfig)) {
|
|
129
|
-
this.documentHandlerBundle = await this.bundleWithPackjockel();
|
|
130
|
-
this.cli.successAction("DOCUMENTHANDLER:BUILD");
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
100
|
this.documentHandlerCode = await this.bundleDocumentHandlerCode("custom_documentHandler.js", await this.getDocumentHandler());
|
|
134
101
|
this.documentHandlerConfigCode = await this.bundleDocumentHandlerCode("config_documentHandler.js", this.deactivateReleaseAndDeploymentDetection());
|
|
135
102
|
this.cli.successAction("DOCUMENTHANDLER:BUILD");
|
|
136
103
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Bundles the handler, its config and the Speed Kit config into one module, the way the server
|
|
139
|
-
* deploys a customer with the `enableSpeedKitConfigPlugins` feature.
|
|
140
|
-
*/
|
|
141
|
-
async bundleWithPackjockel() {
|
|
142
|
-
const customDocumentHandler = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
|
|
143
|
-
return this.bundler.packjockel.bundleDocumentHandler({
|
|
144
|
-
// Without a custom one, packjockel bundles the published handler of documentHandlerVersion.
|
|
145
|
-
documentHandler: customDocumentHandler?.path
|
|
146
|
-
? await this.getDocumentHandler()
|
|
147
|
-
: undefined,
|
|
148
|
-
documentHandlerConfig: this.deactivateReleaseAndDeploymentDetection(),
|
|
149
|
-
speedKitConfig: this.files
|
|
150
|
-
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
151
|
-
.getContent(),
|
|
152
|
-
appName: this.customerConfig.app,
|
|
153
|
-
dynamicFetcher: await this.getDynamicFetcherSource(),
|
|
154
|
-
dynamicFetcherConfig: await this.getDynamicFetcherConfig(),
|
|
155
|
-
customStyle: this.getStyles(),
|
|
156
|
-
versions: this.customerConfig,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
104
|
deactivateReleaseAndDeploymentDetection() {
|
|
160
|
-
return this.getDocumentHandlerConfig().replace(
|
|
105
|
+
return this.getDocumentHandlerConfig().replace("const documentHandler =", (selected) => {
|
|
161
106
|
return (`config["executeDeploymentDetection"] = false;config["executeReleaseDetection"] = false;\n` +
|
|
162
107
|
selected);
|
|
163
108
|
});
|
|
@@ -168,17 +113,10 @@ export class DocumentHandlerServer {
|
|
|
168
113
|
.getContent();
|
|
169
114
|
}
|
|
170
115
|
async getDynamicFetcher() {
|
|
171
|
-
if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
|
|
172
|
-
return await this.bundleDynamicFetcher({ "dynamic-fetcher": "https://www.baqend.com/speed-kit/latest/" }, await this.getDynamicFetcherSource());
|
|
173
|
-
}
|
|
174
|
-
return this.getDynamicFetcherSource();
|
|
175
|
-
}
|
|
176
|
-
/** The customer's own dynamic fetcher, or else the source of the latest one. */
|
|
177
|
-
async getDynamicFetcherSource() {
|
|
178
116
|
// todo use fetchRemoteFile from integration api
|
|
179
117
|
if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
|
|
180
118
|
const response = await fetch(LATEST_DYNAMIC_FETCHER_URL);
|
|
181
|
-
return await response.text();
|
|
119
|
+
return await this.bundleDynamicFetcher({ "dynamic-fetcher": "https://www.baqend.com/speed-kit/latest/" }, await response.text());
|
|
182
120
|
}
|
|
183
121
|
return this.files
|
|
184
122
|
.getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { VirtualFileConfig } from "../integration-api/index.js";
|
|
2
|
+
/** The released document handler, run when the customer directory brings none of its own. */
|
|
3
|
+
export declare const LATEST_DOCUMENT_HANDLER_URL = "https://www.baqend.com/speed-kit-handler/latest/DocumentHandler.js";
|
|
4
|
+
/**
|
|
5
|
+
* The virtual files a local document handler run needs beside the customer's
|
|
6
|
+
* config: the document handler itself. Hand them to `integrationApi.run()`
|
|
7
|
+
* before the files reach `DocumentHandlerRuntimeServiceFactory`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function documentHandlerRuntimeFiles(): VirtualFileConfig[];
|