@speedkit/cli 4.43.0 → 4.44.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/CHANGELOG.md +7 -0
- package/dist/services/bundler/bundle-service-factory.d.ts +6 -1
- package/dist/services/bundler/bundle-service-factory.js +9 -2
- 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 +70 -0
- package/dist/services/bundler/packjockel-service.js +171 -0
- package/dist/services/bundler/spec/packjockel-service.spec.d.ts +1 -0
- package/dist/services/bundler/spec/packjockel-service.spec.js +149 -0
- package/dist/services/cli/cli-environment.js +1 -0
- package/dist/services/cli/cli-settings.d.ts +5 -0
- package/dist/services/cli/cli-settings.js +1 -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/deploy-service-factory.js +1 -1
- package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +1 -1
- package/dist/services/document-handler-runtime/document-handler-runtime-model.d.ts +2 -0
- package/dist/services/document-handler-runtime/document-handler-runtime-model.js +2 -0
- package/dist/services/document-handler-runtime/document-handler-server.d.ts +17 -0
- package/dist/services/document-handler-runtime/document-handler-server.js +82 -20
- package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +1 -1
- package/dist/services/integration-api/integration-api-factory.js +1 -1
- package/dist/services/integration-api/integration-api-model.d.ts +2 -1
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +70 -8
- package/dist/services/integration-api/struct/customer-config.d.ts +19 -1
- package/dist/services/integration-api/struct/customer-config.js +11 -3
- package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +9 -4
- package/dist/services/integration-api/struct/speed-kit-config-file.js +30 -10
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +24 -8
- package/dist/services/onboarding/onboarding-service-factory.js +1 -1
- package/dist/services/onboarding/templates/install-speed-kit-js-template.js +5 -0
- package/dist/services/query-builder/query-builder-factory.js +3 -3
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
|
@@ -13,6 +13,11 @@ 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 `configPlugins` feature: the handler, its config
|
|
18
|
+
* and the Speed Kit config in one CommonJS module, which exports `post`.
|
|
19
|
+
*/
|
|
20
|
+
private documentHandlerBundle?;
|
|
16
21
|
private database;
|
|
17
22
|
/** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
|
|
18
23
|
private readonly appModules;
|
|
@@ -22,11 +27,23 @@ export declare class DocumentHandlerServer {
|
|
|
22
27
|
*/
|
|
23
28
|
constructor(customerConfig: CustomerConfig, files: FileListInterface, bundler: BundleService, cli: CliServiceInterface, workSpace: string, verboseLevel?: boolean, entityManager?: EntityManager);
|
|
24
29
|
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;
|
|
25
35
|
private getTransformFunctionWrapper;
|
|
26
36
|
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 `configPlugins` feature.
|
|
40
|
+
*/
|
|
41
|
+
private bundleWithPackjockel;
|
|
27
42
|
private deactivateReleaseAndDeploymentDetection;
|
|
28
43
|
private getDocumentHandler;
|
|
29
44
|
private getDynamicFetcher;
|
|
45
|
+
/** The customer's own dynamic fetcher, or else the source of the latest one. */
|
|
46
|
+
private getDynamicFetcherSource;
|
|
30
47
|
private getDynamicFetcherConfig;
|
|
31
48
|
private getStyles;
|
|
32
49
|
private getDocumentHandlerConfig;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { LATEST_DYNAMIC_FETCHER_URL, LOCAL_DOCUMENT_HANDLER, LOCAL_DOCUMENT_HANDLER_CONFIG, LOCAL_DYNAMIC_FETCHER, LOCAL_DYNAMIC_FETCHER_CONFIG, LOCAL_STYLES, } from "./document-handler-runtime-model.js";
|
|
1
|
+
import { DYNAMIC_FETCHER_BASE_PATH, LATEST_DYNAMIC_FETCHER_URL, LOCAL_DOCUMENT_HANDLER, LOCAL_DOCUMENT_HANDLER_CONFIG, LOCAL_DYNAMIC_FETCHER, LOCAL_DYNAMIC_FETCHER_CONFIG, LOCAL_STYLES, } from "./document-handler-runtime-model.js";
|
|
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 { speedKitConfigBasePath, } from "../bundler/index.js";
|
|
6
|
+
import { usesConfigPlugins, } from "../integration-api/index.js";
|
|
5
7
|
import { INTEGRATION_FILES } from "../../models/files.js";
|
|
6
8
|
// documentHandlerDependencies
|
|
7
9
|
import fetch from "node-fetch";
|
|
@@ -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 `configPlugins` 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,21 @@ 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
|
+
: {
|
|
75
|
+
DYNAMIC_FETCHER: await this.getDynamicFetcher(),
|
|
76
|
+
DYNAMIC_FETCHER_CONFIG: await this.getDynamicFetcherConfig(),
|
|
77
|
+
CUSTOM_STYLES: this.getStyles(),
|
|
78
|
+
}),
|
|
63
79
|
...this.getContextVars(),
|
|
64
80
|
...this.createNodeVmContext(),
|
|
65
81
|
skErrorContext: {},
|
|
66
82
|
};
|
|
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
|
-
});
|
|
83
|
+
const script = configPlugins
|
|
84
|
+
? this.createBundleScript()
|
|
85
|
+
: this.createScript(vmContext);
|
|
80
86
|
const vmResponse = await safe(new Promise((resolve, reject) => {
|
|
81
87
|
vmContext.skInternalResponse.resolve = resolve;
|
|
82
88
|
// @ts-expect-error reject is unknown
|
|
@@ -92,17 +98,66 @@ export class DocumentHandlerServer {
|
|
|
92
98
|
}
|
|
93
99
|
throw new DocumentHandlerTransformError(vmResponse.errorObj);
|
|
94
100
|
}
|
|
101
|
+
/** Runs the handler in the context, and returns the config, which calls its `post`. */
|
|
102
|
+
createScript(vmContext) {
|
|
103
|
+
const customDocumentHandlerFile = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
|
|
104
|
+
if (customDocumentHandlerFile.path) {
|
|
105
|
+
vm.runInNewContext(this.documentHandlerCode, vmContext, {
|
|
106
|
+
filename: customDocumentHandlerFile.path,
|
|
107
|
+
displayErrors: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
vm.runInNewContext(this.documentHandlerCode, vmContext);
|
|
112
|
+
}
|
|
113
|
+
return new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), { filename: this.getDocumentHandlerConfigPath() });
|
|
114
|
+
}
|
|
115
|
+
/** Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. */
|
|
116
|
+
createBundleScript() {
|
|
117
|
+
return new vm.Script(`(function (module, exports) {\n${this.documentHandlerBundle}\n})(module, module.exports);\n\n` +
|
|
118
|
+
`module.exports.post(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`, { filename: this.getDocumentHandlerConfigPath() });
|
|
119
|
+
}
|
|
120
|
+
getDocumentHandlerConfigPath() {
|
|
121
|
+
return this.files.getByName("config_documentHandler")
|
|
122
|
+
.path;
|
|
123
|
+
}
|
|
95
124
|
getTransformFunctionWrapper() {
|
|
96
125
|
return `\n\npost(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`;
|
|
97
126
|
}
|
|
98
127
|
async buildDocumentHandler() {
|
|
99
128
|
this.cli.startAction("DOCUMENTHANDLER:BUILD", "rebuild documentHandler");
|
|
129
|
+
if (usesConfigPlugins(this.customerConfig)) {
|
|
130
|
+
this.documentHandlerBundle = await this.bundleWithPackjockel();
|
|
131
|
+
this.cli.successAction("DOCUMENTHANDLER:BUILD");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
100
134
|
this.documentHandlerCode = await this.bundleDocumentHandlerCode("custom_documentHandler.js", await this.getDocumentHandler());
|
|
101
135
|
this.documentHandlerConfigCode = await this.bundleDocumentHandlerCode("config_documentHandler.js", this.deactivateReleaseAndDeploymentDetection());
|
|
102
136
|
this.cli.successAction("DOCUMENTHANDLER:BUILD");
|
|
103
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Bundles the handler, its config and the Speed Kit config into one module, the way the server
|
|
140
|
+
* deploys a customer with the `configPlugins` feature.
|
|
141
|
+
*/
|
|
142
|
+
async bundleWithPackjockel() {
|
|
143
|
+
return this.bundler.packjockel.bundleDocumentHandler({
|
|
144
|
+
documentHandler: await this.getDocumentHandler(),
|
|
145
|
+
documentHandlerConfig: this.deactivateReleaseAndDeploymentDetection(),
|
|
146
|
+
speedKitConfig: this.files
|
|
147
|
+
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
148
|
+
.getContent(),
|
|
149
|
+
appName: this.customerConfig.app,
|
|
150
|
+
dynamicFetcher: await this.getDynamicFetcherSource(),
|
|
151
|
+
dynamicFetcherConfig: await this.getDynamicFetcherConfig(),
|
|
152
|
+
customStyle: this.getStyles(),
|
|
153
|
+
basePaths: {
|
|
154
|
+
"speed-kit-config": speedKitConfigBasePath(this.customerConfig.configPluginsVersion),
|
|
155
|
+
"dynamic-fetcher": DYNAMIC_FETCHER_BASE_PATH,
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
104
159
|
deactivateReleaseAndDeploymentDetection() {
|
|
105
|
-
return this.getDocumentHandlerConfig().replace(
|
|
160
|
+
return this.getDocumentHandlerConfig().replace(/const documentHandler =|export default new /, (selected) => {
|
|
106
161
|
return (`config["executeDeploymentDetection"] = false;config["executeReleaseDetection"] = false;\n` +
|
|
107
162
|
selected);
|
|
108
163
|
});
|
|
@@ -113,10 +168,17 @@ export class DocumentHandlerServer {
|
|
|
113
168
|
.getContent();
|
|
114
169
|
}
|
|
115
170
|
async getDynamicFetcher() {
|
|
171
|
+
if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
|
|
172
|
+
return await this.bundleDynamicFetcher({ "dynamic-fetcher": DYNAMIC_FETCHER_BASE_PATH }, 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() {
|
|
116
178
|
// todo use fetchRemoteFile from integration api
|
|
117
179
|
if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
|
|
118
180
|
const response = await fetch(LATEST_DYNAMIC_FETCHER_URL);
|
|
119
|
-
return await
|
|
181
|
+
return await response.text();
|
|
120
182
|
}
|
|
121
183
|
return this.files
|
|
122
184
|
.getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js
CHANGED
|
@@ -25,7 +25,7 @@ export default class DocumentHandlerRuntimeServiceFactory {
|
|
|
25
25
|
const customerConfig = this.getCustomerConfig(files);
|
|
26
26
|
const cliService = this.context.environment.cli;
|
|
27
27
|
await this.installAdditionalDependencies(customerConfig, cliService);
|
|
28
|
-
const bundler = new BundleServiceFactory(this.context.customerPath).buildService();
|
|
28
|
+
const bundler = new BundleServiceFactory(this.context.customerPath, this.context.environment.settings.packjockelPath).buildService();
|
|
29
29
|
// the non-prompting lookup: the document handler runs with a session when
|
|
30
30
|
// there is one and without when there is not, so it must not stop the
|
|
31
31
|
// command at a login prompt to find out
|
|
@@ -30,7 +30,7 @@ export class IntegrationApiFactory {
|
|
|
30
30
|
const virtualFileHandler = new VirtualFileHandler(cli);
|
|
31
31
|
this.service = new IntegrationApiService(fileReader, virtualFileHandler, new MandatoryFilesValidator(), [
|
|
32
32
|
new CustomerConfigHandler(fileReader, cli, new CustomerConfigValidator(), this.context.configName, this.context.environment.settings.testApp, this.context.useTestConfig ?? false),
|
|
33
|
-
new InstallResourceHandler(fileReader, new BundleServiceFactory("./").buildService()),
|
|
33
|
+
new InstallResourceHandler(fileReader, new BundleServiceFactory("./", this.context.environment.settings.packjockelPath).buildService()),
|
|
34
34
|
new ServerConfigHandler(fileReader),
|
|
35
35
|
new ModuleHandler(fileReader),
|
|
36
36
|
], new FileWriter(fs, this.context.basePath), this.whitelist.length === 0);
|
|
@@ -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,7 +90,7 @@ 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;
|
|
@@ -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,57 @@ 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 configPlugins feature", () => {
|
|
130
|
+
const SOURCE = "window.speedKit = { split: 0.1 };";
|
|
131
|
+
const EMBEDDED = {
|
|
132
|
+
app: "shop-de",
|
|
133
|
+
features: { configPlugins: 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 its plugins of the pinned release", 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
|
+
basePaths: {
|
|
153
|
+
"speed-kit-config": "https://www.baqend.com/speed-kit-config/release/",
|
|
154
|
+
},
|
|
155
|
+
define: { APP: '"shop-de"' },
|
|
156
|
+
platform: "browser",
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it("should read SpeedKit.config and the plugins pushed without a guard", async () => {
|
|
160
|
+
const { file } = embeddedFile(`SpeedKit.configPlugins.push({ name: "StripQueryParamPlugin" });
|
|
161
|
+
SpeedKit.config = { split: 0.3, appName: "shop-de" };`);
|
|
162
|
+
const config = await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
163
|
+
expect(config.split).to.equal(0.3);
|
|
164
|
+
expect(config.raw.appName).to.equal("shop-de");
|
|
165
|
+
});
|
|
166
|
+
it("should still read a config that assigns window.speedKit", async () => {
|
|
167
|
+
const { file } = embeddedFile(`window.speedKit = { split: 0.7 };`);
|
|
168
|
+
const config = await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
169
|
+
expect(config.split).to.equal(0.7);
|
|
170
|
+
});
|
|
171
|
+
it("should not reuse a reading of the other bundler", async () => {
|
|
172
|
+
const { file, packjockel } = embeddedFile(`SpeedKit.config = {};`);
|
|
173
|
+
await file.evaluate(EMBEDDED, "https://www.shop.de");
|
|
174
|
+
await file.evaluate({ app: "shop-de" }, "https://www.shop.de");
|
|
175
|
+
expect(packjockel.requests).to.have.length(1);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
116
178
|
});
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The installation features of a config. `null` leaves a feature at its default.
|
|
3
|
+
*/
|
|
4
|
+
export interface CustomerFeatures {
|
|
5
|
+
/**
|
|
6
|
+
* packjockel bundles the config with the config plugins of its target and
|
|
7
|
+
* embeds it into the document handler and the install script. The config
|
|
8
|
+
* writes `SpeedKit.config`.
|
|
9
|
+
*/
|
|
10
|
+
configPlugins?: boolean | null;
|
|
11
|
+
[feature: string]: unknown;
|
|
12
|
+
}
|
|
1
13
|
export interface CustomerConfigs {
|
|
2
14
|
production: CustomerConfig;
|
|
3
15
|
[configName: string]: CustomerConfig;
|
|
@@ -21,6 +33,12 @@ export declare class CustomerConfig {
|
|
|
21
33
|
* installation whose split is greater than 0 for any origin.
|
|
22
34
|
*/
|
|
23
35
|
readonly needsCustomerApproval?: boolean;
|
|
24
|
-
|
|
36
|
+
readonly features?: CustomerFeatures;
|
|
37
|
+
/**
|
|
38
|
+
* The speed-kit-config release the packjockel bundles import plugins from: a version such as
|
|
39
|
+
* `1.8.0`, or a channel such as `@release`.
|
|
40
|
+
*/
|
|
41
|
+
readonly configPluginsVersion?: string;
|
|
42
|
+
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, configPluginsVersion?: string);
|
|
25
43
|
static createFrom(configFile: Partial<CustomerConfig>, configName?: string): CustomerConfig;
|
|
26
44
|
}
|
|
@@ -18,7 +18,13 @@ export class CustomerConfig {
|
|
|
18
18
|
* installation whose split is greater than 0 for any origin.
|
|
19
19
|
*/
|
|
20
20
|
needsCustomerApproval;
|
|
21
|
-
|
|
21
|
+
features;
|
|
22
|
+
/**
|
|
23
|
+
* The speed-kit-config release the packjockel bundles import plugins from: a version such as
|
|
24
|
+
* `1.8.0`, or a channel such as `@release`.
|
|
25
|
+
*/
|
|
26
|
+
configPluginsVersion;
|
|
27
|
+
constructor(app, origins, domain, swPath, scope, appDomain, installPath, installParameters, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, configPluginsVersion) {
|
|
22
28
|
this.app = app;
|
|
23
29
|
this.origins = origins;
|
|
24
30
|
this.domain = domain;
|
|
@@ -32,11 +38,13 @@ export class CustomerConfig {
|
|
|
32
38
|
this.chromeFlags = chromeFlags;
|
|
33
39
|
this.dependencies = dependencies;
|
|
34
40
|
this.needsCustomerApproval = needsCustomerApproval;
|
|
41
|
+
this.features = features;
|
|
42
|
+
this.configPluginsVersion = configPluginsVersion;
|
|
35
43
|
}
|
|
36
44
|
static createFrom(configFile, configName) {
|
|
37
|
-
const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, } = configFile;
|
|
45
|
+
const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, configPluginsVersion, } = configFile;
|
|
38
46
|
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 ||
|
|
39
|
-
`https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false);
|
|
47
|
+
`https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false, features || {}, configPluginsVersion);
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
class RequiredParameter {
|
|
@@ -1,7 +1,10 @@
|
|
|
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" | "configPluginsVersion">;
|
|
5
8
|
/** The name the config deployed to the app is read back under. */
|
|
6
9
|
export declare const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
|
|
7
10
|
/** The file a {@link SpeedKitConfigFile} stands for. */
|
|
@@ -23,7 +26,7 @@ export interface SpeedKitConfigFileInit {
|
|
|
23
26
|
export declare class SpeedKitConfigFile extends InstallResourceFile implements SpeedKitConfigInterface {
|
|
24
27
|
private readonly bundler;
|
|
25
28
|
/**
|
|
26
|
-
* One evaluation per app and
|
|
29
|
+
* One evaluation per app, origin and bundler. A config branches on
|
|
27
30
|
* `window.location`, so the same file read for two origins is two different
|
|
28
31
|
* configs — and bundling one is expensive enough not to repeat per caller.
|
|
29
32
|
*/
|
|
@@ -34,8 +37,8 @@ export declare class SpeedKitConfigFile extends InstallResourceFile implements S
|
|
|
34
37
|
*/
|
|
35
38
|
constructor(file: SpeedKitConfigFileInit, bundler: BundleService);
|
|
36
39
|
setContent(content: string): void;
|
|
37
|
-
/** The config this file describes for one
|
|
38
|
-
evaluate(
|
|
40
|
+
/** The config this file describes for one customer and origin. */
|
|
41
|
+
evaluate(customer: SpeedKitConfigCustomer, origin: string): Promise<SpeedKitConfig>;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* A SpeedKit config that has no file on disk behind it — the one deployed to
|
|
@@ -60,3 +63,5 @@ export declare class VirtualSpeedKitConfigFile extends SpeedKitConfigFile implem
|
|
|
60
63
|
delete(): Promise<void>;
|
|
61
64
|
onChange(): void;
|
|
62
65
|
}
|
|
66
|
+
/** The customer has the `configPlugins` feature: packjockel bundles its config. */
|
|
67
|
+
export declare function usesConfigPlugins(customer: SpeedKitConfigCustomer): boolean;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as vm from "node:vm";
|
|
2
|
+
import { speedKitConfigBasePath, } from "../../bundler/index.js";
|
|
2
3
|
import { EvaluateSkConfigError } from "../error/evaluate-sk-config-error.js";
|
|
3
4
|
import ApplicationError from "../../error-handling/error/application-error.js";
|
|
4
5
|
import { StaticRecipe } from "../virtual/static-recipe.js";
|
|
5
6
|
import { InstallResourceFile } from "./install-resource-file.js";
|
|
6
|
-
import { SpeedKitConfig } from "./speed-kit-config.js";
|
|
7
|
+
import { SpeedKitConfig, } from "./speed-kit-config.js";
|
|
7
8
|
/** The name the config deployed to the app is read back under. */
|
|
8
9
|
export const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
|
|
9
10
|
/**
|
|
@@ -17,7 +18,7 @@ export const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
|
|
|
17
18
|
export class SpeedKitConfigFile extends InstallResourceFile {
|
|
18
19
|
bundler;
|
|
19
20
|
/**
|
|
20
|
-
* One evaluation per app and
|
|
21
|
+
* One evaluation per app, origin and bundler. A config branches on
|
|
21
22
|
* `window.location`, so the same file read for two origins is two different
|
|
22
23
|
* configs — and bundling one is expensive enough not to repeat per caller.
|
|
23
24
|
*/
|
|
@@ -34,14 +35,15 @@ export class SpeedKitConfigFile extends InstallResourceFile {
|
|
|
34
35
|
super.setContent(content);
|
|
35
36
|
this.evaluations.clear();
|
|
36
37
|
}
|
|
37
|
-
/** The config this file describes for one
|
|
38
|
-
evaluate(
|
|
39
|
-
const
|
|
38
|
+
/** The config this file describes for one customer and origin. */
|
|
39
|
+
evaluate(customer, origin) {
|
|
40
|
+
const { app } = customer;
|
|
41
|
+
const key = `${app}|${origin}|${usesConfigPlugins(customer) ? "packjockel" : "esbuild"}`;
|
|
40
42
|
const cached = this.evaluations.get(key);
|
|
41
43
|
if (cached) {
|
|
42
44
|
return cached;
|
|
43
45
|
}
|
|
44
|
-
const evaluation = bundle(this.bundler, this.getContent(),
|
|
46
|
+
const evaluation = bundle(this.bundler, this.getContent(), customer)
|
|
45
47
|
.then((code) => evaluateSpeedKitConfig(app, origin, code, this.path))
|
|
46
48
|
.catch((error) => {
|
|
47
49
|
// A failure is not an answer: forget it, so the next caller — or the
|
|
@@ -95,7 +97,8 @@ export class VirtualSpeedKitConfigFile extends SpeedKitConfigFile {
|
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
97
99
|
* Run a bundled config against a browser mock and hand back what it assigned to
|
|
98
|
-
* `window.speedKit`, together with the config
|
|
100
|
+
* `SpeedKit.config`, or else to `window.speedKit`, together with the config
|
|
101
|
+
* plugins it registered.
|
|
99
102
|
*
|
|
100
103
|
* @param app the app the config is evaluated for, exposed to it as `APP`
|
|
101
104
|
* @param origin the origin the config is evaluated for, its `window.location`
|
|
@@ -113,7 +116,7 @@ function evaluateSpeedKitConfig(app, origin, code, filename) {
|
|
|
113
116
|
if (browserContext.vmError !== null) {
|
|
114
117
|
throw new EvaluateSkConfigError(`[${filename}] ${browserContext.vmError?.message}`);
|
|
115
118
|
}
|
|
116
|
-
return SpeedKitConfig.createFrom(browserContext.window.speedKit, registeredPlugins(browserContext));
|
|
119
|
+
return SpeedKitConfig.createFrom(browserContext.window.SpeedKit.config ?? browserContext.window.speedKit, registeredPlugins(browserContext));
|
|
117
120
|
}
|
|
118
121
|
/**
|
|
119
122
|
* The plugins a config registered, read the way `ConfigController.getPlugins`
|
|
@@ -136,7 +139,9 @@ function buildBrowserMock(origin, app) {
|
|
|
136
139
|
},
|
|
137
140
|
customVariation: [],
|
|
138
141
|
},
|
|
139
|
-
|
|
142
|
+
// An embedded config pushes its plugins without creating the list, the
|
|
143
|
+
// way packjockel hands it over.
|
|
144
|
+
SpeedKit: { configPlugins: [] },
|
|
140
145
|
serviceWorkerUrl: "",
|
|
141
146
|
screen: { width: 0, height: 0 },
|
|
142
147
|
devicePixelRatio: 1,
|
|
@@ -214,10 +219,25 @@ function safeFileContentWrapper(fileContent) {
|
|
|
214
219
|
}
|
|
215
220
|
`;
|
|
216
221
|
}
|
|
217
|
-
|
|
222
|
+
/** The customer has the `configPlugins` feature: packjockel bundles its config. */
|
|
223
|
+
export function usesConfigPlugins(customer) {
|
|
224
|
+
return customer.features?.configPlugins === true;
|
|
225
|
+
}
|
|
226
|
+
async function bundle(bundler, content, customer) {
|
|
218
227
|
if (!content) {
|
|
219
228
|
throw new ApplicationError("Content is empty");
|
|
220
229
|
}
|
|
230
|
+
const app = customer.app;
|
|
231
|
+
if (usesConfigPlugins(customer)) {
|
|
232
|
+
return bundler.packjockel.bundle({
|
|
233
|
+
entryPoints: { "config.js": content },
|
|
234
|
+
basePaths: {
|
|
235
|
+
"speed-kit-config": speedKitConfigBasePath(customer.configPluginsVersion),
|
|
236
|
+
},
|
|
237
|
+
define: { APP: JSON.stringify(app) },
|
|
238
|
+
platform: "browser",
|
|
239
|
+
});
|
|
240
|
+
}
|
|
221
241
|
return bundler.bundle({
|
|
222
242
|
basePaths: {
|
|
223
243
|
"speed-kit-config": "https://www.baqend.com/speed-kit-config/latest/",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { speedKitConfigBasePath } from "../../bundler/index.js";
|
|
2
|
+
import { usesConfigPlugins, } from "../../integration-api/index.js";
|
|
1
3
|
import { INTEGRATION_FILES } from "../../../models/files.js";
|
|
2
4
|
const IMPORT_PATHS = {
|
|
3
5
|
rum: "https://www.baqend.com/rum/latest/",
|
|
@@ -19,8 +21,10 @@ export class SpeedKitInstallContext {
|
|
|
19
21
|
this.skTemplate = skTemplate;
|
|
20
22
|
}
|
|
21
23
|
async getSpeedKitInstallJs() {
|
|
24
|
+
const configPlugins = usesConfigPlugins(this.customerConfig);
|
|
22
25
|
const configJs = this.skTemplate.render({
|
|
23
26
|
config: this.getConfigSpeedKit(),
|
|
27
|
+
configPlugins,
|
|
24
28
|
forceInstall: this.customerConfig.forceInstall,
|
|
25
29
|
installPath: this.customerConfig.installPath,
|
|
26
30
|
installParams: this.customerConfig.installParams,
|
|
@@ -29,15 +33,27 @@ export class SpeedKitInstallContext {
|
|
|
29
33
|
.getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
|
|
30
34
|
.getContent(),
|
|
31
35
|
});
|
|
36
|
+
const entryPoints = {
|
|
37
|
+
"rum.js": this.prepareConfigLoadHandler(),
|
|
38
|
+
"config.js": configJs,
|
|
39
|
+
"loader.js": this.files
|
|
40
|
+
.getByName(INTEGRATION_FILES.CUSTOM.LOADER)
|
|
41
|
+
.getContent(),
|
|
42
|
+
};
|
|
43
|
+
if (configPlugins) {
|
|
44
|
+
return this.bundler.packjockel.bundle({
|
|
45
|
+
entryPoints,
|
|
46
|
+
basePaths: {
|
|
47
|
+
...IMPORT_PATHS,
|
|
48
|
+
"speed-kit-config": speedKitConfigBasePath(this.customerConfig.configPluginsVersion),
|
|
49
|
+
},
|
|
50
|
+
define: { APP: JSON.stringify(this.customerConfig.app) },
|
|
51
|
+
platform: "browser",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
32
54
|
return this.bundler.bundle({
|
|
33
55
|
basePaths: IMPORT_PATHS,
|
|
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
|
-
},
|
|
56
|
+
entryPoints,
|
|
41
57
|
logLevel: "error",
|
|
42
58
|
minify: false,
|
|
43
59
|
platform: "browser",
|
|
@@ -72,7 +88,7 @@ export class SpeedKitInstallContext {
|
|
|
72
88
|
return config.replace(value, "100");
|
|
73
89
|
});
|
|
74
90
|
}
|
|
75
|
-
return configString.replace(/window\.speedKit[^{]*=[^{]*{/, (configOpenTag) => {
|
|
91
|
+
return configString.replace(/(?:window\.speedKit|SpeedKit\.config)[^{]*=[^{]*{/, (configOpenTag) => {
|
|
76
92
|
return configOpenTag + `\n delayRacedOrigin: 100,\n`;
|
|
77
93
|
});
|
|
78
94
|
}
|
|
@@ -230,7 +230,7 @@ export class OnboardingServiceFactory {
|
|
|
230
230
|
customerPath: this.context.customerPath,
|
|
231
231
|
verboseLevel: this.context.verboseLevel,
|
|
232
232
|
}), files).buildDocumentHandlerServer();
|
|
233
|
-
const bundler = new BundleServiceFactory(this.context.customerPath).buildService();
|
|
233
|
+
const bundler = new BundleServiceFactory(this.context.customerPath, this.context.environment.settings.packjockelPath).buildService();
|
|
234
234
|
const skTemplate = new InstallSpeedKitJsTemplate();
|
|
235
235
|
const speedKitInstallContext = new SpeedKitInstallContext(customerConfig, this.context.configName, files, bundler, skTemplate);
|
|
236
236
|
await this.buildInstallResource(speedKitInstallContext, files, cli);
|
|
@@ -5,6 +5,11 @@ export class InstallSpeedKitJsTemplate extends AbstractTemplate {
|
|
|
5
5
|
// Config
|
|
6
6
|
{{{config}}}
|
|
7
7
|
|
|
8
|
+
{{#if configPlugins}}
|
|
9
|
+
// The config writes SpeedKit.config, which packjockel exposes; the overrides below change it.
|
|
10
|
+
var speedKit = SpeedKit.config;
|
|
11
|
+
{{/if}}
|
|
12
|
+
|
|
8
13
|
// Reset potential split test parameters
|
|
9
14
|
speedKit.split = 1.0;
|
|
10
15
|
speedKit.splitTestId = 'debug';
|
|
@@ -22,7 +22,7 @@ export class QueryBuilderFactory {
|
|
|
22
22
|
const customerConfig = files.getCustomerConfig().config;
|
|
23
23
|
const app = customerConfig.app;
|
|
24
24
|
const origins = customerConfig.origins ?? [];
|
|
25
|
-
const speedKitConfig = await this.getSpeedKitConfig(
|
|
25
|
+
const speedKitConfig = await this.getSpeedKitConfig(customerConfig, origins[0], files.getSpeedKitConfig());
|
|
26
26
|
const serviceContext = {
|
|
27
27
|
app,
|
|
28
28
|
bySet: this.context.bySet,
|
|
@@ -72,8 +72,8 @@ export class QueryBuilderFactory {
|
|
|
72
72
|
const integrationApi = new IntegrationApiFactory(integrationApiContext).buildService();
|
|
73
73
|
return await integrationApi.run();
|
|
74
74
|
}
|
|
75
|
-
async getSpeedKitConfig(
|
|
76
|
-
const result = await safe(speedKitConfigFile.evaluate(
|
|
75
|
+
async getSpeedKitConfig(customer, origin, speedKitConfigFile) {
|
|
76
|
+
const result = await safe(speedKitConfigFile.evaluate(customer, origin));
|
|
77
77
|
if (result.success !== true) {
|
|
78
78
|
throw new ParseConfigSpeedKitError(result.error);
|
|
79
79
|
}
|