@speedkit/cli 4.50.5 → 4.51.0-beta.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/dist/services/bundler/bundle-service-factory.d.ts +3 -0
- package/dist/services/bundler/bundle-service-factory.js +5 -1
- package/dist/services/bundler/bundle-service.d.ts +10 -1
- package/dist/services/bundler/bundle-service.js +16 -1
- package/dist/services/bundler/error/packjockel-error.d.ts +3 -0
- package/dist/services/bundler/error/packjockel-error.js +3 -0
- package/dist/services/bundler/index.d.ts +1 -0
- package/dist/services/bundler/index.js +1 -0
- package/dist/services/bundler/packjockel-service.d.ts +112 -0
- package/dist/services/bundler/packjockel-service.js +202 -0
- package/dist/services/bundler/spec/packjockel-service.spec.d.ts +1 -0
- package/dist/services/bundler/spec/packjockel-service.spec.js +186 -0
- package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +2 -3
- package/dist/services/deploy/checks/pre-deploy/split-change-check.js +2 -3
- package/dist/services/deploy/handler/customer-config-handler.d.ts +9 -0
- package/dist/services/deploy/handler/customer-config-handler.js +41 -6
- package/dist/services/deploy/interface/install.d.ts +7 -1
- package/dist/services/deploy/mr/live-state-check.js +21 -2
- package/dist/services/deploy/policy/auto-deploy-policy.js +2 -0
- package/dist/services/deploy/policy/deploy-policy-model.d.ts +4 -0
- package/dist/services/deploy/policy/deploy-policy-model.js +4 -0
- package/dist/services/deploy/policy/testing-deploy-policy.js +2 -0
- package/dist/services/deploy/spec/handler/customer-config-handler.spec.d.ts +1 -0
- package/dist/services/deploy/spec/handler/customer-config-handler.spec.js +98 -0
- package/dist/services/deploy/spec/mr/live-state-check.spec.js +45 -4
- package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +2 -0
- package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +3 -1
- package/dist/services/document-handler-runtime/document-handler-browser-mock.d.ts +13 -0
- package/dist/services/document-handler-runtime/document-handler-browser-mock.js +69 -0
- package/dist/services/document-handler-runtime/document-handler-server.d.ts +27 -0
- package/dist/services/document-handler-runtime/document-handler-server.js +112 -19
- package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.d.ts +1 -0
- package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.js +34 -0
- package/dist/services/integration-api/integration-api-model.d.ts +4 -1
- package/dist/services/integration-api/spec/customer-config-file.spec.d.ts +1 -0
- package/dist/services/integration-api/spec/customer-config-file.spec.js +56 -0
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +68 -8
- package/dist/services/integration-api/struct/customer-config-file.d.ts +15 -0
- package/dist/services/integration-api/struct/customer-config-file.js +42 -0
- package/dist/services/integration-api/struct/customer-config.d.ts +55 -1
- package/dist/services/integration-api/struct/customer-config.js +70 -3
- package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +11 -4
- package/dist/services/integration-api/struct/speed-kit-config-file.js +31 -10
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +2 -0
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +29 -8
- package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +3 -1
- package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +10 -2
- package/dist/services/onboarding/file-events/file-watcher.d.ts +3 -1
- package/dist/services/onboarding/file-events/file-watcher.js +9 -2
- package/dist/services/onboarding/onboarding-service-factory.js +12 -2
- package/dist/services/onboarding/spec/file-events/file-watcher.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/file-events/file-watcher.spec.js +67 -0
- package/dist/services/onboarding/templates/install-speed-kit-js-template.js +5 -0
- package/dist/services/pull/pull-service.js +23 -5
- package/dist/services/query-builder/query-builder-factory.js +3 -3
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
|
@@ -2,11 +2,13 @@ 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 { embedsConfigInServiceWorker, usesConfigPlugins, } from "../integration-api/index.js";
|
|
5
6
|
import { INTEGRATION_FILES } from "../../models/files.js";
|
|
6
7
|
// documentHandlerDependencies
|
|
7
8
|
import fetch from "node-fetch";
|
|
8
9
|
import { Request } from "./server/request.js";
|
|
9
10
|
import { DocumentHandlerResponse } from "./server/document-handler-response.js";
|
|
11
|
+
import { createBrowserGlobals, missingBrowserGlobal, } from "./document-handler-browser-mock.js";
|
|
10
12
|
import { DocumentHandlerAbort } from "./document-handler-abort.js";
|
|
11
13
|
import { DocumentHandlerConsole } from "./document-handler-console.js";
|
|
12
14
|
import { safe } from "../../helpers/safe.js";
|
|
@@ -25,6 +27,11 @@ export class DocumentHandlerServer {
|
|
|
25
27
|
entityManager;
|
|
26
28
|
documentHandlerCode;
|
|
27
29
|
documentHandlerConfigCode;
|
|
30
|
+
/**
|
|
31
|
+
* The packjockel bundle for a customer with the `enableSpeedKitConfigPlugins` feature: the handler, its config
|
|
32
|
+
* and the Speed Kit config in one CommonJS module, which exports `post`.
|
|
33
|
+
*/
|
|
34
|
+
documentHandlerBundle;
|
|
28
35
|
database;
|
|
29
36
|
/** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
|
|
30
37
|
appModules = new Map();
|
|
@@ -42,7 +49,11 @@ export class DocumentHandlerServer {
|
|
|
42
49
|
this.entityManager = entityManager;
|
|
43
50
|
}
|
|
44
51
|
async transform(contentType, html, variation, url, headers) {
|
|
45
|
-
|
|
52
|
+
const configPlugins = usesConfigPlugins(this.customerConfig);
|
|
53
|
+
const built = configPlugins
|
|
54
|
+
? this.documentHandlerBundle
|
|
55
|
+
: this.documentHandlerCode && this.documentHandlerConfigCode;
|
|
56
|
+
if (!built) {
|
|
46
57
|
await this.buildDocumentHandler();
|
|
47
58
|
}
|
|
48
59
|
const skInternalRequest = new Request(url, html, variation, headers, {
|
|
@@ -57,26 +68,24 @@ export class DocumentHandlerServer {
|
|
|
57
68
|
skInternalError: {},
|
|
58
69
|
Abort: DocumentHandlerAbort,
|
|
59
70
|
APP: this.customerConfig.app,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
// packjockel defines these in the bundle itself.
|
|
72
|
+
...(configPlugins
|
|
73
|
+
? {
|
|
74
|
+
// A fresh mock per request, so that one transform sees no state of the last one.
|
|
75
|
+
skBrowserGlobals: createBrowserGlobals(this.customerConfig.app),
|
|
76
|
+
}
|
|
77
|
+
: {
|
|
78
|
+
DYNAMIC_FETCHER: await this.getDynamicFetcher(),
|
|
79
|
+
DYNAMIC_FETCHER_CONFIG: await this.getDynamicFetcherConfig(),
|
|
80
|
+
CUSTOM_STYLES: this.getStyles(),
|
|
81
|
+
}),
|
|
63
82
|
...this.getContextVars(),
|
|
64
83
|
...this.createNodeVmContext(),
|
|
65
84
|
skErrorContext: {},
|
|
66
85
|
};
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
});
|
|
86
|
+
const script = configPlugins
|
|
87
|
+
? this.createBundleScript()
|
|
88
|
+
: this.createScript(vmContext);
|
|
80
89
|
const vmResponse = await safe(new Promise((resolve, reject) => {
|
|
81
90
|
vmContext.skInternalResponse.resolve = resolve;
|
|
82
91
|
// @ts-expect-error reject is unknown
|
|
@@ -92,17 +101,94 @@ export class DocumentHandlerServer {
|
|
|
92
101
|
}
|
|
93
102
|
throw new DocumentHandlerTransformError(vmResponse.errorObj);
|
|
94
103
|
}
|
|
104
|
+
/** Runs the handler in the context, and returns the config, which calls its `post`. */
|
|
105
|
+
createScript(vmContext) {
|
|
106
|
+
const customDocumentHandlerFile = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
|
|
107
|
+
if (customDocumentHandlerFile.path) {
|
|
108
|
+
vm.runInNewContext(this.documentHandlerCode, vmContext, {
|
|
109
|
+
filename: customDocumentHandlerFile.path,
|
|
110
|
+
displayErrors: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
vm.runInNewContext(this.documentHandlerCode, vmContext);
|
|
115
|
+
}
|
|
116
|
+
return new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), { filename: this.getDocumentHandlerConfigPath() });
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. The browser mock
|
|
120
|
+
* shadows the globals of the bundle, as on the server.
|
|
121
|
+
*/
|
|
122
|
+
createBundleScript() {
|
|
123
|
+
const names = Object.keys(createBrowserGlobals(this.customerConfig.app));
|
|
124
|
+
return new vm.Script(`(function (module, exports, ${names.join(", ")}) {\n${this.documentHandlerBundle}\n})(module, module.exports, ${names.map((name) => `skBrowserGlobals.${name}`).join(", ")});\n\n` +
|
|
125
|
+
`module.exports.post(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`, { filename: this.getDocumentHandlerConfigPath() });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Loads the bundle once without the browser mock. The service worker embeds the config without a browser
|
|
129
|
+
* around it, so the server's proof rejects a config that reads a browser global while it loads.
|
|
130
|
+
*
|
|
131
|
+
* @returns the browser global the config reads, or undefined
|
|
132
|
+
*/
|
|
133
|
+
findBrowserGlobalRead() {
|
|
134
|
+
const loaded = safe(() => vm.runInNewContext(this.documentHandlerBundle, {
|
|
135
|
+
APP: this.customerConfig.app,
|
|
136
|
+
...this.getContextVars(),
|
|
137
|
+
...this.createNodeVmContext(),
|
|
138
|
+
}, { filename: this.getDocumentHandlerConfigPath() }));
|
|
139
|
+
return loaded.success === true
|
|
140
|
+
? undefined
|
|
141
|
+
: missingBrowserGlobal(loaded.errorObj);
|
|
142
|
+
}
|
|
143
|
+
getDocumentHandlerConfigPath() {
|
|
144
|
+
return this.files.getByName("config_documentHandler")
|
|
145
|
+
.path;
|
|
146
|
+
}
|
|
95
147
|
getTransformFunctionWrapper() {
|
|
96
148
|
return `\n\npost(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`;
|
|
97
149
|
}
|
|
98
150
|
async buildDocumentHandler() {
|
|
99
151
|
this.cli.startAction("DOCUMENTHANDLER:BUILD", "rebuild documentHandler");
|
|
152
|
+
if (usesConfigPlugins(this.customerConfig)) {
|
|
153
|
+
this.documentHandlerBundle = await this.bundleWithPackjockel();
|
|
154
|
+
const read = embedsConfigInServiceWorker(this.customerConfig)
|
|
155
|
+
? this.findBrowserGlobalRead()
|
|
156
|
+
: undefined;
|
|
157
|
+
if (read) {
|
|
158
|
+
this.cli.failAction("DOCUMENTHANDLER:BUILD", `embeddedConfig: the Speed Kit config reads "${read}" while it loads, so the server rejects it. Read it in a callback, or turn embeddedConfig off.`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.cli.successAction("DOCUMENTHANDLER:BUILD");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
100
164
|
this.documentHandlerCode = await this.bundleDocumentHandlerCode("custom_documentHandler.js", await this.getDocumentHandler());
|
|
101
165
|
this.documentHandlerConfigCode = await this.bundleDocumentHandlerCode("config_documentHandler.js", this.deactivateReleaseAndDeploymentDetection());
|
|
102
166
|
this.cli.successAction("DOCUMENTHANDLER:BUILD");
|
|
103
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Bundles the handler, its config and the Speed Kit config into one module, the way the server
|
|
170
|
+
* deploys a customer with the `enableSpeedKitConfigPlugins` feature.
|
|
171
|
+
*/
|
|
172
|
+
async bundleWithPackjockel() {
|
|
173
|
+
const customDocumentHandler = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
|
|
174
|
+
return this.bundler.packjockel.bundleDocumentHandler({
|
|
175
|
+
// Without a custom one, packjockel bundles the published handler of documentHandlerVersion.
|
|
176
|
+
documentHandler: customDocumentHandler?.path
|
|
177
|
+
? await this.getDocumentHandler()
|
|
178
|
+
: undefined,
|
|
179
|
+
documentHandlerConfig: this.deactivateReleaseAndDeploymentDetection(),
|
|
180
|
+
speedKitConfig: this.files
|
|
181
|
+
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
182
|
+
.getContent(),
|
|
183
|
+
appName: this.customerConfig.app,
|
|
184
|
+
dynamicFetcher: await this.getDynamicFetcherSource(),
|
|
185
|
+
dynamicFetcherConfig: await this.getDynamicFetcherConfig(),
|
|
186
|
+
customStyle: this.getStyles(),
|
|
187
|
+
versions: this.customerConfig,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
104
190
|
deactivateReleaseAndDeploymentDetection() {
|
|
105
|
-
return this.getDocumentHandlerConfig().replace(
|
|
191
|
+
return this.getDocumentHandlerConfig().replace(/const documentHandler =|export default new /, (selected) => {
|
|
106
192
|
return (`config["executeDeploymentDetection"] = false;config["executeReleaseDetection"] = false;\n` +
|
|
107
193
|
selected);
|
|
108
194
|
});
|
|
@@ -113,10 +199,17 @@ export class DocumentHandlerServer {
|
|
|
113
199
|
.getContent();
|
|
114
200
|
}
|
|
115
201
|
async getDynamicFetcher() {
|
|
202
|
+
if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
|
|
203
|
+
return await this.bundleDynamicFetcher({ "dynamic-fetcher": "https://www.baqend.com/speed-kit/latest/" }, await this.getDynamicFetcherSource());
|
|
204
|
+
}
|
|
205
|
+
return this.getDynamicFetcherSource();
|
|
206
|
+
}
|
|
207
|
+
/** The customer's own dynamic fetcher, or else the source of the latest one. */
|
|
208
|
+
async getDynamicFetcherSource() {
|
|
116
209
|
// todo use fetchRemoteFile from integration api
|
|
117
210
|
if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
|
|
118
211
|
const response = await fetch(LATEST_DYNAMIC_FETCHER_URL);
|
|
119
|
-
return await
|
|
212
|
+
return await response.text();
|
|
120
213
|
}
|
|
121
214
|
return this.files
|
|
122
215
|
.getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import vm from "node:vm";
|
|
4
|
+
import { createBrowserGlobals, missingBrowserGlobal, } from "../document-handler-browser-mock.js";
|
|
5
|
+
describe("createBrowserGlobals", () => {
|
|
6
|
+
it("should let a config read location.hostname, like the server", () => {
|
|
7
|
+
const globals = createBrowserGlobals("shop");
|
|
8
|
+
const names = Object.keys(globals);
|
|
9
|
+
const read = vm.compileFunction("return [location.hostname, window.location === location, top === window, typeof setTimeout];", names);
|
|
10
|
+
expect(read(...names.map((name) => globals[name]))).to.deep.equal([
|
|
11
|
+
"shop.app.baqend.com",
|
|
12
|
+
true,
|
|
13
|
+
true,
|
|
14
|
+
// The mock shadows no timer: the document handler keeps the real one of Node.js.
|
|
15
|
+
"function",
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("missingBrowserGlobal", () => {
|
|
20
|
+
it("should name a browser global that a config reads without the mock", () => {
|
|
21
|
+
const read = (code) => {
|
|
22
|
+
try {
|
|
23
|
+
vm.runInNewContext(code, {});
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return missingBrowserGlobal(error);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
expect(read("location.hostname")).to.equal("location");
|
|
30
|
+
// Only a browser global makes a config not embeddable.
|
|
31
|
+
expect(read("db.find()")).to.equal(undefined);
|
|
32
|
+
expect(read("var x = 1;")).to.equal(undefined);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -13,6 +13,7 @@ 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";
|
|
16
17
|
import { CustomerConfig } from "./struct/customer-config.js";
|
|
17
18
|
import { RoFile } from "./struct/ro-file.js";
|
|
18
19
|
import { VirtualFile } from "./struct/virtual-file.js";
|
|
@@ -89,11 +90,13 @@ export interface InstallResourceInterface extends ConfigFileInterface, FileInter
|
|
|
89
90
|
readonly remoteKey: string;
|
|
90
91
|
}
|
|
91
92
|
export interface SpeedKitConfigInterface extends InstallResourceInterface {
|
|
92
|
-
evaluate(
|
|
93
|
+
evaluate(customer: SpeedKitConfigCustomer, origin: string): Promise<SpeedKitConfig>;
|
|
93
94
|
}
|
|
94
95
|
export interface CustomerConfigInterface extends ConfigFileInterface {
|
|
95
96
|
config: CustomerConfig;
|
|
96
97
|
updateOrigins(origins: string[]): void;
|
|
98
|
+
updateFeatures(live?: Record<string, unknown>): boolean;
|
|
99
|
+
updateVersions(live: Record<string, unknown>): boolean;
|
|
97
100
|
readonly configName: string;
|
|
98
101
|
}
|
|
99
102
|
export interface VirtualFileRecipe {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { CustomerConfig, CustomerConfigFile, } from "../../integration-api/index.js";
|
|
4
|
+
function fileWith(production) {
|
|
5
|
+
const content = JSON.stringify({ production }, null, 2);
|
|
6
|
+
return new CustomerConfigFile("config_customer.json", "config_customer.json", content, CustomerConfig.createFrom(production, "production"), "production");
|
|
7
|
+
}
|
|
8
|
+
const BASE = {
|
|
9
|
+
app: "example-shop",
|
|
10
|
+
domain: "production",
|
|
11
|
+
origins: ["https://www.example.com"],
|
|
12
|
+
swPath: "/sw.js",
|
|
13
|
+
scope: "/",
|
|
14
|
+
};
|
|
15
|
+
describe("CustomerConfigFile.updateFeatures", () => {
|
|
16
|
+
it("takes over the features the installation sets", () => {
|
|
17
|
+
const file = fileWith({ ...BASE, features: { embeddedConfig: false } });
|
|
18
|
+
const changed = file.updateFeatures({
|
|
19
|
+
embeddedConfig: true,
|
|
20
|
+
prefetchingOnDeploymentJob: null,
|
|
21
|
+
});
|
|
22
|
+
expect(changed).to.equal(true);
|
|
23
|
+
expect(JSON.parse(file.getContent()).production.features).to.deep.equal({
|
|
24
|
+
embeddedConfig: true,
|
|
25
|
+
});
|
|
26
|
+
expect(file.config.features).to.deep.equal({ embeddedConfig: true });
|
|
27
|
+
});
|
|
28
|
+
it("drops the features when the installation sets none", () => {
|
|
29
|
+
const file = fileWith({ ...BASE, features: { embeddedConfig: true } });
|
|
30
|
+
expect(file.updateFeatures({ embeddedConfig: null })).to.equal(true);
|
|
31
|
+
expect(JSON.parse(file.getContent()).production).to.not.have.property("features");
|
|
32
|
+
});
|
|
33
|
+
it("leaves an equal file alone", () => {
|
|
34
|
+
const file = fileWith({ ...BASE, features: { embeddedConfig: true } });
|
|
35
|
+
const before = file.getContent();
|
|
36
|
+
expect(file.updateFeatures({ embeddedConfig: true })).to.equal(false);
|
|
37
|
+
expect(file.getContent()).to.equal(before);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("CustomerConfigFile.updateVersions", () => {
|
|
41
|
+
it("writes the tags of the installation and drops the ones at latest", () => {
|
|
42
|
+
const file = fileWith({ ...BASE, ppVersion: "1.2.0" });
|
|
43
|
+
const changed = file.updateVersions({
|
|
44
|
+
speedKitVersion: "2.22.4",
|
|
45
|
+
rumPluginsVersion: null,
|
|
46
|
+
ppVersion: null,
|
|
47
|
+
configPluginsVersion: null,
|
|
48
|
+
documentHandlerVersion: null,
|
|
49
|
+
});
|
|
50
|
+
const production = JSON.parse(file.getContent()).production;
|
|
51
|
+
expect(changed).to.equal(true);
|
|
52
|
+
expect(production.speedKitVersion).to.equal("2.22.4");
|
|
53
|
+
expect(production).to.not.have.property("ppVersion");
|
|
54
|
+
expect(file.config.speedKitVersion).to.equal("2.22.4");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -2,8 +2,21 @@ 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 { BundleServiceFactory } from "../../bundler/index.js";
|
|
5
|
+
import { BundleService, 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
|
+
}
|
|
7
20
|
function configFile(source) {
|
|
8
21
|
return new SpeedKitConfigFile({
|
|
9
22
|
name: INTEGRATION_FILES.CONFIG.SPEED_KIT,
|
|
@@ -13,7 +26,7 @@ function configFile(source) {
|
|
|
13
26
|
}, bundler);
|
|
14
27
|
}
|
|
15
28
|
function evaluate(source) {
|
|
16
|
-
return configFile(source).evaluate(
|
|
29
|
+
return configFile(source).evaluate(SHOP_DE, "https://www.shop.de");
|
|
17
30
|
}
|
|
18
31
|
/** What the config assigned, for the tests about the browser mock itself. */
|
|
19
32
|
async function evaluateRaw(source) {
|
|
@@ -89,19 +102,19 @@ describe("SpeedKitConfigFile", () => {
|
|
|
89
102
|
// builder and the pre-deploy checks both go through here.
|
|
90
103
|
const file = configFile(`window.speedKit = { host: window.location.host };`);
|
|
91
104
|
const [first, second] = await Promise.all([
|
|
92
|
-
file.evaluate(
|
|
93
|
-
file.evaluate(
|
|
105
|
+
file.evaluate(SHOP_DE, "https://www.shop.de"),
|
|
106
|
+
file.evaluate(SHOP_DE, "https://www.shop.de"),
|
|
94
107
|
]);
|
|
95
|
-
const otherOrigin = await file.evaluate(
|
|
108
|
+
const otherOrigin = await file.evaluate(SHOP_DE, "https://m.shop.de");
|
|
96
109
|
expect(first).to.equal(second);
|
|
97
110
|
expect(otherOrigin).to.not.equal(first);
|
|
98
111
|
expect(otherOrigin.raw.host).to.equal("m.shop.de");
|
|
99
112
|
});
|
|
100
113
|
it("should forget what it read when the file changes", async () => {
|
|
101
114
|
const file = configFile(`window.speedKit = { split: 0.1 };`);
|
|
102
|
-
const before = await file.evaluate(
|
|
115
|
+
const before = await file.evaluate(SHOP_DE, "https://www.shop.de");
|
|
103
116
|
file.setContent(`window.speedKit = { split: 0.5 };`);
|
|
104
|
-
const after = await file.evaluate(
|
|
117
|
+
const after = await file.evaluate(SHOP_DE, "https://www.shop.de");
|
|
105
118
|
expect(before.split).to.equal(0.1);
|
|
106
119
|
expect(after.split).to.equal(0.5);
|
|
107
120
|
});
|
|
@@ -109,8 +122,55 @@ describe("SpeedKitConfigFile", () => {
|
|
|
109
122
|
const source = `window.speedKit = { split: 0.5, appName: APP };`;
|
|
110
123
|
const remote = await VirtualSpeedKitConfigFile.createRemote(source, bundler);
|
|
111
124
|
const local = await evaluate(source);
|
|
112
|
-
const deployed = await remote.evaluate(
|
|
125
|
+
const deployed = await remote.evaluate(SHOP_DE, "https://www.shop.de");
|
|
113
126
|
expect(deployed).to.deep.equal(local);
|
|
114
127
|
expect(remote.getContent()).to.equal(source);
|
|
115
128
|
});
|
|
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
|
+
});
|
|
116
176
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CustomerConfig, File, CustomerConfigInterface, FILE_TYPE } from "../integration-api-model.js";
|
|
2
|
+
import { VersionTag } from "./customer-config.js";
|
|
2
3
|
export declare class CustomerConfigFile extends File implements CustomerConfigInterface {
|
|
3
4
|
config: CustomerConfig;
|
|
4
5
|
readonly configName: string;
|
|
@@ -7,5 +8,19 @@ export declare class CustomerConfigFile extends File implements CustomerConfigIn
|
|
|
7
8
|
constructor(name: string, path: string, content: string, config: CustomerConfig, configName: string, testApp?: string);
|
|
8
9
|
setContent(content: string): void;
|
|
9
10
|
updateOrigins(origins: string[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* Takes over the features the installation sets. The file then holds exactly these, and none
|
|
13
|
+
* when the installation sets none.
|
|
14
|
+
*
|
|
15
|
+
* @returns whether the features changed
|
|
16
|
+
*/
|
|
17
|
+
updateFeatures(live?: Record<string, unknown>): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Takes over the version tags of the installation. A tag the installation leaves at `latest` is
|
|
20
|
+
* removed from the file.
|
|
21
|
+
*
|
|
22
|
+
* @returns whether a tag changed
|
|
23
|
+
*/
|
|
24
|
+
updateVersions(live: Record<VersionTag, unknown>): boolean;
|
|
10
25
|
private updateConfigByContent;
|
|
11
26
|
}
|
|
@@ -2,6 +2,7 @@ import { CustomerConfig, File, FILE_TYPE, } from "../integration-api-model.js";
|
|
|
2
2
|
import { safe } from "../../../helpers/safe.js";
|
|
3
3
|
import CustomerConfigError from "../error/customer-config-error.js";
|
|
4
4
|
import { isSame } from "../array-helper.js";
|
|
5
|
+
import { declaredFields, versionsOfConfig, } from "./customer-config.js";
|
|
5
6
|
export class CustomerConfigFile extends File {
|
|
6
7
|
config;
|
|
7
8
|
configName;
|
|
@@ -28,6 +29,47 @@ export class CustomerConfigFile extends File {
|
|
|
28
29
|
configContent[this.configName].origins = origins;
|
|
29
30
|
this.setContent(JSON.stringify(configContent, null, 2));
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Takes over the features the installation sets. The file then holds exactly these, and none
|
|
34
|
+
* when the installation sets none.
|
|
35
|
+
*
|
|
36
|
+
* @returns whether the features changed
|
|
37
|
+
*/
|
|
38
|
+
updateFeatures(live) {
|
|
39
|
+
const features = declaredFields(live);
|
|
40
|
+
if (JSON.stringify(declaredFields(this.config.features)) ===
|
|
41
|
+
JSON.stringify(features)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const configContent = JSON.parse(this.getContent());
|
|
45
|
+
if (Object.keys(features).length > 0) {
|
|
46
|
+
configContent[this.configName].features = features;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
delete configContent[this.configName].features;
|
|
50
|
+
}
|
|
51
|
+
this.setContent(JSON.stringify(configContent, null, 2));
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Takes over the version tags of the installation. A tag the installation leaves at `latest` is
|
|
56
|
+
* removed from the file.
|
|
57
|
+
*
|
|
58
|
+
* @returns whether a tag changed
|
|
59
|
+
*/
|
|
60
|
+
updateVersions(live) {
|
|
61
|
+
if (JSON.stringify(versionsOfConfig(this.config)) === JSON.stringify(live)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const configContent = JSON.parse(this.getContent());
|
|
65
|
+
const others = Object.entries(configContent[this.configName]).filter(([key]) => !(key in live));
|
|
66
|
+
configContent[this.configName] = {
|
|
67
|
+
...Object.fromEntries(others),
|
|
68
|
+
...declaredFields(live),
|
|
69
|
+
};
|
|
70
|
+
this.setContent(JSON.stringify(configContent, null, 2));
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
31
73
|
updateConfigByContent() {
|
|
32
74
|
const configsResult = safe(() => {
|
|
33
75
|
return JSON.parse(this.getContent());
|
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
import type { AssetVersions } from "../../bundler/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The installation features of a config, under the field names the installation stores. `sk deploy` sends
|
|
4
|
+
* them and `sk pull` writes them back. An omitted feature is `null`, so a deploy resets it.
|
|
5
|
+
*/
|
|
6
|
+
export interface CustomerFeatures {
|
|
7
|
+
/**
|
|
8
|
+
* packjockel bundles the config with the config plugins of its target and
|
|
9
|
+
* embeds it into the document handler and the install script. The config
|
|
10
|
+
* writes `SpeedKit.config`.
|
|
11
|
+
*/
|
|
12
|
+
enableSpeedKitConfigPlugins?: boolean | null;
|
|
13
|
+
/** The server embeds the config into the service worker as well. */
|
|
14
|
+
embeddedConfig?: boolean | null;
|
|
15
|
+
[feature: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** The fields that are set, without the `null` ones. */
|
|
18
|
+
export declare function declaredFields(features?: Record<string, unknown> | null): Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* The fields whose value in `local` differs from `live`, with the value of `local`. A field that either
|
|
21
|
+
* side omits is `null`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function changedFields(local?: Record<string, unknown> | null, live?: Record<string, unknown> | null): Record<string, unknown>;
|
|
24
|
+
/** Each version tag of a config, with the field of the installation that stores it. */
|
|
25
|
+
export declare const VERSION_FIELDS: {
|
|
26
|
+
readonly speedKitVersion: "swVersion";
|
|
27
|
+
readonly rumPluginsVersion: "rumVersion";
|
|
28
|
+
readonly ppVersion: "ppVersion";
|
|
29
|
+
readonly configPluginsVersion: "configPluginsVersion";
|
|
30
|
+
readonly documentHandlerVersion: "documentHandlerVersion";
|
|
31
|
+
};
|
|
32
|
+
export type VersionTag = keyof typeof VERSION_FIELDS;
|
|
33
|
+
/** The version tags of a config. A blank or omitted tag is `null`, which means `latest`. */
|
|
34
|
+
export declare function versionsOfConfig(config?: Partial<Record<VersionTag, unknown>> | null): Record<VersionTag, unknown>;
|
|
35
|
+
/** The version tags an installation stores, under the names of the config. */
|
|
36
|
+
export declare function versionsOfInstall(install?: object | null): Record<VersionTag, unknown>;
|
|
1
37
|
export interface CustomerConfigs {
|
|
2
38
|
production: CustomerConfig;
|
|
3
39
|
[configName: string]: CustomerConfig;
|
|
@@ -21,6 +57,24 @@ export declare class CustomerConfig {
|
|
|
21
57
|
* installation whose split is greater than 0 for any origin.
|
|
22
58
|
*/
|
|
23
59
|
readonly needsCustomerApproval?: boolean;
|
|
24
|
-
|
|
60
|
+
readonly features?: CustomerFeatures;
|
|
61
|
+
/**
|
|
62
|
+
* The tag of Speed Kit (snippet, service worker, dynamic fetcher) for the `enableSpeedKitConfigPlugins` feature: a
|
|
63
|
+
* version such as `2.22.4`, or a channel such as `@release`; `latest` when not set. This and the other
|
|
64
|
+
* tags are named like the client config keys of packjockel.
|
|
65
|
+
*/
|
|
66
|
+
readonly speedKitVersion?: string;
|
|
67
|
+
/** The tag of RUM for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
68
|
+
readonly rumPluginsVersion?: string;
|
|
69
|
+
/** The tag of predictive preloading for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
70
|
+
readonly ppVersion?: string;
|
|
71
|
+
/** The tag of the speed-kit-config plugins for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
|
|
72
|
+
readonly configPluginsVersion?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The tag of the published document handler for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}.
|
|
75
|
+
* A `custom_documentHandler.js` replaces it.
|
|
76
|
+
*/
|
|
77
|
+
readonly documentHandlerVersion?: string;
|
|
78
|
+
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);
|
|
25
79
|
static createFrom(configFile: Partial<CustomerConfig>, configName?: string): CustomerConfig;
|
|
26
80
|
}
|