@speedkit/cli 4.43.0-beta.1 → 4.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/README.md +12 -2
- package/dist/commands/onboarding.d.ts +3 -0
- package/dist/commands/onboarding.js +7 -1
- package/dist/services/bundler/bundle-service-factory.d.ts +1 -6
- package/dist/services/bundler/bundle-service-factory.js +2 -9
- 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.js +0 -1
- package/dist/services/cli/cli-settings.d.ts +0 -5
- package/dist/services/cli/cli-settings.js +0 -1
- package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
- 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-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 +0 -2
- package/dist/services/document-handler-runtime/document-handler-runtime-model.js +0 -2
- package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
- package/dist/services/document-handler-runtime/document-handler-server.js +20 -82
- 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 +1 -2
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -70
- package/dist/services/integration-api/struct/customer-config.d.ts +1 -19
- package/dist/services/integration-api/struct/customer-config.js +3 -11
- 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 -30
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -24
- package/dist/services/onboarding/error/inject-installation-error.d.ts +6 -0
- package/dist/services/onboarding/error/inject-installation-error.js +11 -0
- package/dist/services/onboarding/error/inject-target-error.d.ts +6 -0
- package/dist/services/onboarding/error/inject-target-error.js +11 -0
- package/dist/services/onboarding/error/missing-customer-path-error.d.ts +1 -1
- package/dist/services/onboarding/error/missing-customer-path-error.js +2 -1
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +4 -14
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +6 -45
- package/dist/services/onboarding/fetch-events/document-rewrite.d.ts +19 -0
- package/dist/services/onboarding/fetch-events/document-rewrite.js +47 -0
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +5 -1
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +7 -2
- package/dist/services/onboarding/html-rewrites.d.ts +3 -3
- package/dist/services/onboarding/html-rewrites.js +3 -3
- package/dist/services/onboarding/index.d.ts +1 -1
- package/dist/services/onboarding/index.js +1 -1
- package/dist/services/onboarding/inject/content-security-policy.d.ts +14 -0
- package/dist/services/onboarding/inject/content-security-policy.js +54 -0
- package/dist/services/onboarding/inject/deployed-installation.d.ts +15 -0
- package/dist/services/onboarding/inject/deployed-installation.js +32 -0
- package/dist/services/onboarding/inject/foreign-install-request.d.ts +27 -0
- package/dist/services/onboarding/inject/foreign-install-request.js +50 -0
- package/dist/services/onboarding/inject/inject-document-rewrite.d.ts +23 -0
- package/dist/services/onboarding/inject/inject-document-rewrite.js +52 -0
- package/dist/services/onboarding/inject/inject-service.d.ts +32 -0
- package/dist/services/onboarding/inject/inject-service.js +72 -0
- package/dist/services/onboarding/inject/injected-installation.d.ts +29 -0
- package/dist/services/onboarding/inject/injected-installation.js +37 -0
- package/dist/services/onboarding/onboarding-service-build-context.d.ts +15 -1
- package/dist/services/onboarding/onboarding-service-build-context.js +31 -2
- package/dist/services/onboarding/onboarding-service-factory.d.ts +23 -5
- package/dist/services/onboarding/onboarding-service-factory.js +87 -7
- package/dist/services/onboarding/spec/inject/content-security-policy.spec.js +47 -0
- package/dist/services/onboarding/spec/inject/deployed-installation.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/deployed-installation.spec.js +49 -0
- package/dist/services/onboarding/spec/inject/foreign-install-request.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/foreign-install-request.spec.js +47 -0
- package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.js +66 -0
- package/dist/services/onboarding/spec/inject/injected-installation.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/injected-installation.spec.js +24 -0
- package/dist/services/onboarding/spec/onboarding-service-build-context.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/onboarding-service-build-context.spec.js +22 -0
- package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +53 -2
- package/dist/services/onboarding/templates/install-speed-kit-html-template.js +3 -0
- package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
- package/dist/services/query-builder/query-builder-factory.js +3 -3
- package/oclif.manifest.json +26 -3
- package/package.json +1 -2
- 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 -70
- package/dist/services/bundler/packjockel-service.js +0 -171
- package/dist/services/bundler/spec/packjockel-service.spec.js +0 -149
- /package/dist/services/{bundler/spec/packjockel-service.spec.d.ts → onboarding/spec/inject/content-security-policy.spec.d.ts} +0 -0
|
@@ -2,20 +2,38 @@ import { OnboardingServiceBuildContext } from "./onboarding-service-build-contex
|
|
|
2
2
|
import { BrowserContext } from "./onboarding-model.js";
|
|
3
3
|
import { OnboardingService } from "./onboarding-service.js";
|
|
4
4
|
import { BrowseService } from "./browse/browse-service.js";
|
|
5
|
+
import { InjectService } from "./inject/inject-service.js";
|
|
6
|
+
import { DeployedInstallation } from "./inject/deployed-installation.js";
|
|
5
7
|
import { BrowserExtensions } from "./browser/extension/extension-validator.js";
|
|
6
8
|
export declare class OnboardingServiceFactory {
|
|
7
9
|
private readonly context;
|
|
8
10
|
constructor(context: OnboardingServiceBuildContext);
|
|
9
11
|
/**
|
|
10
|
-
* The service `sk onboarding` runs: the browse service under `--browse`, the
|
|
11
|
-
* otherwise.
|
|
12
|
+
* The service `sk onboarding` runs: the browse service under `--browse`, the inject service under
|
|
13
|
+
* `--inject`, the onboarding service otherwise.
|
|
12
14
|
*
|
|
13
|
-
* @throws {MissingCustomerPathError} Without `--browse` and without a CUSTOMERPATH.
|
|
15
|
+
* @throws {MissingCustomerPathError} Without `--browse`, without `--inject` and without a CUSTOMERPATH.
|
|
14
16
|
*/
|
|
15
|
-
getService(): Promise<OnboardingService | BrowseService>;
|
|
17
|
+
getService(): Promise<OnboardingService | BrowseService | InjectService>;
|
|
18
|
+
/**
|
|
19
|
+
* The site with a deployed installation injected. It builds no install resource, no service
|
|
20
|
+
* worker and no documentHandler.
|
|
21
|
+
*/
|
|
22
|
+
private getInjectService;
|
|
16
23
|
/** The live site in the onboarding Chrome: the same launch, none of the interception. */
|
|
17
24
|
private getBrowseService;
|
|
18
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* What inject mode injects, and where. The app and the domain come from the flags, else from a
|
|
27
|
+
* local `config_customer.json`. The service worker path and the scope come from the installation
|
|
28
|
+
* itself, so they are right for an installation that a local config does not describe.
|
|
29
|
+
*
|
|
30
|
+
* @throws {InjectTargetError} Without an app, or without a domain.
|
|
31
|
+
* @throws {InjectInstallationError} When the server has no installation for the domain.
|
|
32
|
+
*/
|
|
33
|
+
private resolveInjectTarget;
|
|
34
|
+
/** The one request inject mode sends before Chrome starts. A spec replaces it. */
|
|
35
|
+
protected readDeployedInstallation(installPath: string, origin: string): Promise<DeployedInstallation>;
|
|
36
|
+
/** Only config_customer.json: browse mode and inject mode read nothing else. */
|
|
19
37
|
private readCustomerConfig;
|
|
20
38
|
/**
|
|
21
39
|
* Resolves the extensions and the Chrome executable, then builds the launch. Onboarding and
|
|
@@ -6,13 +6,14 @@ import { BundleServiceFactory } from "../bundler/index.js";
|
|
|
6
6
|
import { DiffServiceBuildContext, DiffServiceFactory } from "../diff/index.js";
|
|
7
7
|
import { DocumentHandlerRuntimeServiceBuildContext } from "../document-handler-runtime/document-handler-runtime-service-build-context.js";
|
|
8
8
|
import DocumentHandlerRuntimeServiceFactory from "../document-handler-runtime/factory/document-handler-runtime-service-factory.js";
|
|
9
|
-
import { ExternalFileReader, IntegrationApiServiceBuildContext, VirtualFile, ExternalRecipe, IntegrationApiFactory, } from "../integration-api/index.js";
|
|
9
|
+
import { CustomerConfig, ExternalFileReader, IntegrationApiServiceBuildContext, VirtualFile, ExternalRecipe, IntegrationApiFactory, } from "../integration-api/index.js";
|
|
10
10
|
import { InstallFileRecipe } from "./config-renderer/install-file-recipe.js";
|
|
11
11
|
import { SpeedKitInstallContext } from "./config-renderer/speed-kit-install-context.js";
|
|
12
12
|
import { Dashboard } from "./dashboard/index.js";
|
|
13
13
|
import { RequestDiffService } from "./dashboard/request-diff-service.js";
|
|
14
14
|
import { FetchEventHandler } from "./fetch-event-handler.js";
|
|
15
15
|
import { CustomerDomainDocumentResponse } from "./fetch-events/customer-domain-document-response.js";
|
|
16
|
+
import { LocalDocumentRewrite } from "./fetch-events/document-rewrite.js";
|
|
16
17
|
import { CustomerServiceWorkerJs } from "./fetch-events/customer-service-worker-js.js";
|
|
17
18
|
import { DashboardRequest } from "./fetch-events/dashboard-request.js";
|
|
18
19
|
import { SpeedKitAssetRequest } from "./fetch-events/speed-kit-asset-request.js";
|
|
@@ -25,6 +26,12 @@ import { BrowserContext, } from "./onboarding-model.js";
|
|
|
25
26
|
import { OnboardingService } from "./onboarding-service.js";
|
|
26
27
|
import { BrowseService } from "./browse/browse-service.js";
|
|
27
28
|
import { resolveBrowseUrl } from "./browse/browse-url.js";
|
|
29
|
+
import { InjectDocumentRewrite } from "./inject/inject-document-rewrite.js";
|
|
30
|
+
import { InjectService } from "./inject/inject-service.js";
|
|
31
|
+
import { ForeignInstallRequest } from "./inject/foreign-install-request.js";
|
|
32
|
+
import { InjectedInstallation } from "./inject/injected-installation.js";
|
|
33
|
+
import { readDeployedInstallation, } from "./inject/deployed-installation.js";
|
|
34
|
+
import { InjectTargetError } from "./error/inject-target-error.js";
|
|
28
35
|
import { MissingCustomerPathError } from "./error/missing-customer-path-error.js";
|
|
29
36
|
import { Cache } from "./request-cache/cache.js";
|
|
30
37
|
import { InstallSpeedKitHtmlTemplate } from "./templates/install-speed-kit-html-template.js";
|
|
@@ -53,20 +60,49 @@ export class OnboardingServiceFactory {
|
|
|
53
60
|
this.context = context;
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
|
-
* The service `sk onboarding` runs: the browse service under `--browse`, the
|
|
57
|
-
* otherwise.
|
|
63
|
+
* The service `sk onboarding` runs: the browse service under `--browse`, the inject service under
|
|
64
|
+
* `--inject`, the onboarding service otherwise.
|
|
58
65
|
*
|
|
59
|
-
* @throws {MissingCustomerPathError} Without `--browse` and without a CUSTOMERPATH.
|
|
66
|
+
* @throws {MissingCustomerPathError} Without `--browse`, without `--inject` and without a CUSTOMERPATH.
|
|
60
67
|
*/
|
|
61
68
|
async getService() {
|
|
62
69
|
if (this.context.browse) {
|
|
63
70
|
return this.getBrowseService();
|
|
64
71
|
}
|
|
72
|
+
if (this.context.inject) {
|
|
73
|
+
return this.getInjectService();
|
|
74
|
+
}
|
|
65
75
|
if (!this.context.customerPath) {
|
|
66
76
|
throw new MissingCustomerPathError();
|
|
67
77
|
}
|
|
68
78
|
return this.getOnboardingService();
|
|
69
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* The site with a deployed installation injected. It builds no install resource, no service
|
|
82
|
+
* worker and no documentHandler.
|
|
83
|
+
*/
|
|
84
|
+
async getInjectService() {
|
|
85
|
+
const cli = this.context.environment.cli;
|
|
86
|
+
const localConfig = this.context.customerPath
|
|
87
|
+
? await this.readCustomerConfig()
|
|
88
|
+
: undefined;
|
|
89
|
+
applyOriginProxy(localConfig?.chromeFlags, cli);
|
|
90
|
+
const { customerConfig, installation, domainToStart } = await this.resolveInjectTarget(localConfig);
|
|
91
|
+
const { browserContext } = await this.prepareBrowser(domainToStart, customerConfig.chromeFlags);
|
|
92
|
+
const handlers = [
|
|
93
|
+
new ForeignInstallRequest(customerConfig.appDomain, cli, installation.testingId),
|
|
94
|
+
new CustomerDomainDocumentResponse(customerConfig, new InjectDocumentRewrite(installation, `https://${customerConfig.appDomain}`, this.context.ignoreContentSecurityPolicy, cli)),
|
|
95
|
+
new SpeedKitInstallHtml(customerConfig, browserContext, new InstallSpeedKitHtmlTemplate(), installation.installPath),
|
|
96
|
+
new CustomerServiceWorkerJs(customerConfig),
|
|
97
|
+
];
|
|
98
|
+
return new InjectService({
|
|
99
|
+
browserContext,
|
|
100
|
+
fetchEventHandler: new FetchEventHandler(handlers, customerConfig, cli, this.getConfigApi(customerConfig.app)),
|
|
101
|
+
installation,
|
|
102
|
+
scope: customerConfig.scope,
|
|
103
|
+
cli,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
70
106
|
/** The live site in the onboarding Chrome: the same launch, none of the interception. */
|
|
71
107
|
async getBrowseService() {
|
|
72
108
|
const cli = this.context.environment.cli;
|
|
@@ -78,7 +114,51 @@ export class OnboardingServiceFactory {
|
|
|
78
114
|
const { browserContext } = await this.prepareBrowser(url, customerConfig?.chromeFlags);
|
|
79
115
|
return new BrowseService(browserContext, cli);
|
|
80
116
|
}
|
|
81
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* What inject mode injects, and where. The app and the domain come from the flags, else from a
|
|
119
|
+
* local `config_customer.json`. The service worker path and the scope come from the installation
|
|
120
|
+
* itself, so they are right for an installation that a local config does not describe.
|
|
121
|
+
*
|
|
122
|
+
* @throws {InjectTargetError} Without an app, or without a domain.
|
|
123
|
+
* @throws {InjectInstallationError} When the server has no installation for the domain.
|
|
124
|
+
*/
|
|
125
|
+
async resolveInjectTarget(localConfig) {
|
|
126
|
+
const app = this.context.app || localConfig?.app;
|
|
127
|
+
if (!app) {
|
|
128
|
+
throw new InjectTargetError("app");
|
|
129
|
+
}
|
|
130
|
+
if (!this.context.domain && !localConfig) {
|
|
131
|
+
throw new InjectTargetError("domain");
|
|
132
|
+
}
|
|
133
|
+
const domainToStart = resolveBrowseUrl(this.context.domain, localConfig);
|
|
134
|
+
const origin = new URL(domainToStart).origin;
|
|
135
|
+
// A local config for another app describes neither its install path nor its app domain.
|
|
136
|
+
const ownConfig = localConfig?.app === app ? localConfig : undefined;
|
|
137
|
+
const installation = new InjectedInstallation({
|
|
138
|
+
installPath: ownConfig?.installPath ??
|
|
139
|
+
`https://${app}.app.baqend.com/v1/speedkit/install.js`,
|
|
140
|
+
installParams: ownConfig?.installParams ?? 'async="" crossorigin="anonymous"',
|
|
141
|
+
}, this.context.testing);
|
|
142
|
+
const deployed = await this.readDeployedInstallation(installation.installPath, origin);
|
|
143
|
+
const origins = new Set([...(localConfig?.origins ?? []), origin]);
|
|
144
|
+
const customerConfig = CustomerConfig.createFrom({
|
|
145
|
+
app,
|
|
146
|
+
origins: [...origins],
|
|
147
|
+
domain: domainToStart,
|
|
148
|
+
swPath: deployed.swPath,
|
|
149
|
+
scope: deployed.scope,
|
|
150
|
+
appDomain: ownConfig?.appDomain,
|
|
151
|
+
installPath: installation.installPath,
|
|
152
|
+
installParams: installation.installParams,
|
|
153
|
+
chromeFlags: localConfig?.chromeFlags,
|
|
154
|
+
});
|
|
155
|
+
return { customerConfig, installation, domainToStart };
|
|
156
|
+
}
|
|
157
|
+
/** The one request inject mode sends before Chrome starts. A spec replaces it. */
|
|
158
|
+
readDeployedInstallation(installPath, origin) {
|
|
159
|
+
return readDeployedInstallation(installPath, origin);
|
|
160
|
+
}
|
|
161
|
+
/** Only config_customer.json: browse mode and inject mode read nothing else. */
|
|
82
162
|
async readCustomerConfig() {
|
|
83
163
|
const integrationApi = new IntegrationApiFactory(new IntegrationApiServiceBuildContext({
|
|
84
164
|
environment: this.context.environment,
|
|
@@ -150,7 +230,7 @@ export class OnboardingServiceFactory {
|
|
|
150
230
|
customerPath: this.context.customerPath,
|
|
151
231
|
verboseLevel: this.context.verboseLevel,
|
|
152
232
|
}), files).buildDocumentHandlerServer();
|
|
153
|
-
const bundler = new BundleServiceFactory(this.context.customerPath
|
|
233
|
+
const bundler = new BundleServiceFactory(this.context.customerPath).buildService();
|
|
154
234
|
const skTemplate = new InstallSpeedKitJsTemplate();
|
|
155
235
|
const speedKitInstallContext = new SpeedKitInstallContext(customerConfig, this.context.configName, files, bundler, skTemplate);
|
|
156
236
|
await this.buildInstallResource(speedKitInstallContext, files, cli);
|
|
@@ -246,7 +326,7 @@ export class OnboardingServiceFactory {
|
|
|
246
326
|
})).getService();
|
|
247
327
|
const requestDiffService = new RequestDiffService(DiffService, documentHandler, cli);
|
|
248
328
|
const handlers = [
|
|
249
|
-
new CustomerDomainDocumentResponse(customerConfig, files.getByName(INTEGRATION_FILES.CONFIG.DYNAMIC_BLOCKS), files.getByName(INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES), this.context.ignoreContentSecurityPolicy),
|
|
329
|
+
new CustomerDomainDocumentResponse(customerConfig, new LocalDocumentRewrite(customerConfig, files.getByName(INTEGRATION_FILES.CONFIG.DYNAMIC_BLOCKS), files.getByName(INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES), this.context.ignoreContentSecurityPolicy)),
|
|
250
330
|
new SpeedKitInstallHtml(customerConfig, browserContext, new InstallSpeedKitHtmlTemplate()),
|
|
251
331
|
new SpeedKitInstallJs(customerConfig, files.getByName(INTEGRATION_FILES.BUILD.INSTALL), cli),
|
|
252
332
|
new CustomerServiceWorkerJs(customerConfig),
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { allowSource, allowSourceInMetaTags, } from "../../inject/content-security-policy.js";
|
|
4
|
+
const APP = "https://example.app.baqend.com";
|
|
5
|
+
describe("allowSource", () => {
|
|
6
|
+
it("adds the source to script-src and connect-src", () => {
|
|
7
|
+
const result = allowSource("script-src 'self' 'nonce-abc'; connect-src 'self'; img-src *", APP);
|
|
8
|
+
expect(result.policy).to.equal(`script-src 'self' 'nonce-abc' ${APP}; connect-src 'self' ${APP}; img-src *`);
|
|
9
|
+
expect(result.amended).to.deep.equal(["script-src", "connect-src"]);
|
|
10
|
+
});
|
|
11
|
+
it("creates a missing directive from default-src", () => {
|
|
12
|
+
const result = allowSource("default-src 'self'; script-src 'self'", APP);
|
|
13
|
+
expect(result.policy).to.equal(`default-src 'self'; script-src 'self' ${APP}; connect-src 'self' ${APP}`);
|
|
14
|
+
expect(result.amended).to.deep.equal(["script-src", "connect-src"]);
|
|
15
|
+
});
|
|
16
|
+
it("leaves a missing directive out when no default-src restricts it", () => {
|
|
17
|
+
const result = allowSource("script-src 'self'", APP);
|
|
18
|
+
expect(result.policy).to.equal(`script-src 'self' ${APP}`);
|
|
19
|
+
expect(result.amended).to.deep.equal(["script-src"]);
|
|
20
|
+
});
|
|
21
|
+
it("replaces 'none', which allows no second source", () => {
|
|
22
|
+
const result = allowSource("default-src 'none'", APP);
|
|
23
|
+
expect(result.policy).to.equal(`default-src 'none'; script-src ${APP}; connect-src ${APP}`);
|
|
24
|
+
});
|
|
25
|
+
it("adds the source to script-src-elem, which overrides script-src", () => {
|
|
26
|
+
const result = allowSource("script-src 'self'; script-src-elem 'self'", APP);
|
|
27
|
+
expect(result.policy).to.equal(`script-src 'self' ${APP}; script-src-elem 'self' ${APP}`);
|
|
28
|
+
});
|
|
29
|
+
it("reports nothing when the policy allows the source already", () => {
|
|
30
|
+
const policy = `script-src 'self' ${APP}; connect-src ${APP}`;
|
|
31
|
+
const result = allowSource(policy, APP);
|
|
32
|
+
expect(result.policy).to.equal(policy);
|
|
33
|
+
expect(result.amended).to.deep.equal([]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("allowSourceInMetaTags", () => {
|
|
37
|
+
it("amends the policy of a meta tag and reports the directives", () => {
|
|
38
|
+
const amended = [];
|
|
39
|
+
const html = allowSourceInMetaTags(`<head><meta http-equiv="Content-Security-Policy" content="script-src 'self'"></head>`, APP, (directives) => amended.push(directives));
|
|
40
|
+
expect(html).to.equal(`<head><meta http-equiv="Content-Security-Policy" content="script-src 'self' ${APP}"></head>`);
|
|
41
|
+
expect(amended).to.deep.equal([["script-src"]]);
|
|
42
|
+
});
|
|
43
|
+
it("leaves HTML without a policy unchanged", () => {
|
|
44
|
+
const html = `<head><meta charset="utf-8"></head>`;
|
|
45
|
+
expect(allowSourceInMetaTags(html, APP, () => undefined)).to.equal(html);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { InjectInstallationError } from "../../error/inject-installation-error.js";
|
|
4
|
+
import { parseInstallResource, readDeployedInstallation, } from "../../inject/deployed-installation.js";
|
|
5
|
+
const ORIGIN = "https://www.example.com";
|
|
6
|
+
const INSTALL = "https://example.app.baqend.com/v1/speedkit/install.js";
|
|
7
|
+
function answer(status, body = "") {
|
|
8
|
+
return async () => new Response(status === 204 ? null : body, { status });
|
|
9
|
+
}
|
|
10
|
+
describe("parseInstallResource", () => {
|
|
11
|
+
it("reads the service worker path without its query", () => {
|
|
12
|
+
expect(parseInstallResource(`var speedKit={appName:"example",sw:"/apps/speed-kit/sw.js?r=abc&v=2.22.5",split:0};`, ORIGIN)).to.deep.equal({ swPath: "/apps/speed-kit/sw.js", scope: "/" });
|
|
13
|
+
});
|
|
14
|
+
it("reads the scope that the installation names", () => {
|
|
15
|
+
expect(parseInstallResource(`{sw:"/de/sw.js",scope:"/de/"}`, ORIGIN)).to.deep.equal({ swPath: "/de/sw.js", scope: "/de/" });
|
|
16
|
+
});
|
|
17
|
+
it("finds nothing in a resource without a service worker", () => {
|
|
18
|
+
expect(parseInstallResource("/* empty */", ORIGIN)).to.equal(undefined);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("readDeployedInstallation", () => {
|
|
22
|
+
it("fetches the install resource as a page of the origin", async () => {
|
|
23
|
+
const requests = [];
|
|
24
|
+
const fetchResource = (async (url, init) => {
|
|
25
|
+
requests.push({
|
|
26
|
+
url,
|
|
27
|
+
origin: init.headers.origin,
|
|
28
|
+
});
|
|
29
|
+
return new Response(`{sw:"/wrapper-sw.js?r=abc"}`);
|
|
30
|
+
});
|
|
31
|
+
const installation = await readDeployedInstallation(`${INSTALL}?r=abc`, ORIGIN, fetchResource);
|
|
32
|
+
expect(installation).to.deep.equal({
|
|
33
|
+
swPath: "/wrapper-sw.js",
|
|
34
|
+
scope: "/",
|
|
35
|
+
});
|
|
36
|
+
expect(requests).to.deep.equal([
|
|
37
|
+
{ url: `${INSTALL}?r=abc`, origin: ORIGIN },
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
it("fails when the origin has no live installation", async () => {
|
|
41
|
+
const error = await readDeployedInstallation(INSTALL, ORIGIN, answer(204)).catch((error_) => error_);
|
|
42
|
+
expect(error).to.be.instanceOf(InjectInstallationError);
|
|
43
|
+
expect(error.message).to.contain("204");
|
|
44
|
+
});
|
|
45
|
+
it("fails when the install resource names no service worker", async () => {
|
|
46
|
+
const error = await readDeployedInstallation(INSTALL, ORIGIN, answer(200, "/* empty */")).catch((error_) => error_);
|
|
47
|
+
expect(error).to.be.instanceOf(InjectInstallationError);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { AbortResponse } from "../../browser/abort-response.js";
|
|
4
|
+
import { ForeignInstallRequest } from "../../inject/foreign-install-request.js";
|
|
5
|
+
const APP = "example.app.baqend.com";
|
|
6
|
+
function handler(testingId) {
|
|
7
|
+
const warnings = [];
|
|
8
|
+
const cli = {
|
|
9
|
+
writeWarning: (message) => warnings.push(message),
|
|
10
|
+
};
|
|
11
|
+
return { warnings, handler: new ForeignInstallRequest(APP, cli, testingId) };
|
|
12
|
+
}
|
|
13
|
+
function request(url) {
|
|
14
|
+
return { request: { url } };
|
|
15
|
+
}
|
|
16
|
+
describe("ForeignInstallRequest", () => {
|
|
17
|
+
it("has a pattern that the dispatcher matches against an install resource", () => {
|
|
18
|
+
const [{ urlPattern }] = handler().handler.patterns;
|
|
19
|
+
const expression = new RegExp(urlPattern);
|
|
20
|
+
expect(expression.test("https://other.app.baqend.com/v1/speedkit/install.js")).to.equal(true);
|
|
21
|
+
expect(expression.test("https://www.example.com/app.js")).to.equal(false);
|
|
22
|
+
});
|
|
23
|
+
it("lets the install resource of the injected app through", async () => {
|
|
24
|
+
const { handler: foreign, warnings } = handler();
|
|
25
|
+
const response = await foreign.handle(request(`https://${APP}/v1/speedkit/install.js?d=production`));
|
|
26
|
+
expect(response).to.equal(null);
|
|
27
|
+
expect(warnings).to.deep.equal([]);
|
|
28
|
+
});
|
|
29
|
+
it("blocks the install resource of another app, and says so once", async () => {
|
|
30
|
+
const { handler: foreign, warnings } = handler();
|
|
31
|
+
const url = "https://other.app.baqend.com/v1/speedkit/install.js";
|
|
32
|
+
const response = await foreign.handle(request(url));
|
|
33
|
+
await foreign.handle(request(url));
|
|
34
|
+
expect(response).to.be.instanceOf(AbortResponse);
|
|
35
|
+
expect(response.errorReason).to.equal("BlockedByClient");
|
|
36
|
+
expect(warnings).to.have.length(1);
|
|
37
|
+
expect(warnings[0]).to.contain(url);
|
|
38
|
+
});
|
|
39
|
+
it("blocks the live installation of the app while a testing installation is injected", async () => {
|
|
40
|
+
const { handler: foreign } = handler("abc-123");
|
|
41
|
+
expect(await foreign.handle(request(`https://${APP}/v1/speedkit/install.js`))).to.be.instanceOf(AbortResponse);
|
|
42
|
+
});
|
|
43
|
+
it("lets the testing installation through, also when the worker added the id again", async () => {
|
|
44
|
+
const { handler: foreign } = handler("abc-123");
|
|
45
|
+
expect(await foreign.handle(request(`https://${APP}/v1/speedkit/install.js?r=abc-123&r=abc-123`))).to.equal(null);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { InjectDocumentRewrite } from "../../inject/inject-document-rewrite.js";
|
|
4
|
+
import { InjectedInstallation } from "../../inject/injected-installation.js";
|
|
5
|
+
const APP = "https://example.app.baqend.com";
|
|
6
|
+
const INSTALL = `${APP}/v1/speedkit/install.js`;
|
|
7
|
+
function rewrite(removeContentSecurityPolicy = false, testingId) {
|
|
8
|
+
const warnings = [];
|
|
9
|
+
const cli = {
|
|
10
|
+
writeWarning: (message) => warnings.push(message),
|
|
11
|
+
};
|
|
12
|
+
const installation = new InjectedInstallation({ installPath: INSTALL, installParams: 'crossorigin="anonymous"' }, testingId);
|
|
13
|
+
return {
|
|
14
|
+
warnings,
|
|
15
|
+
rewrite: new InjectDocumentRewrite(installation, APP, removeContentSecurityPolicy, cli),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
describe("InjectDocumentRewrite", () => {
|
|
19
|
+
it("injects the install script into a document without Speed Kit", () => {
|
|
20
|
+
const html = rewrite().rewrite.html("<html><head></head></html>");
|
|
21
|
+
expect(html).to.contain(`src="${INSTALL}" crossorigin="anonymous"`);
|
|
22
|
+
});
|
|
23
|
+
it("replaces the live install script with the testing installation", () => {
|
|
24
|
+
const html = rewrite(false, "abc-123").rewrite.html(`<html><head><script src="${INSTALL}" async></script></head></html>`);
|
|
25
|
+
expect(html.match(/install\.js/g)).to.have.length(1);
|
|
26
|
+
expect(html).to.contain(`src="${INSTALL}?r=abc-123"`);
|
|
27
|
+
});
|
|
28
|
+
it("reuses the nonce of the origin for the install script", () => {
|
|
29
|
+
const html = rewrite().rewrite.html(`<html><head><script nonce="n0nce">1</script></head></html>`);
|
|
30
|
+
expect(html).to.contain(`<script nonce="n0nce" src="${INSTALL}"`);
|
|
31
|
+
});
|
|
32
|
+
it("amends the policy header and prints the change once", () => {
|
|
33
|
+
const { rewrite: documentRewrite, warnings } = rewrite();
|
|
34
|
+
const headers = [
|
|
35
|
+
{ name: "Content-Security-Policy", value: "script-src 'self'" },
|
|
36
|
+
{
|
|
37
|
+
name: "Content-Security-Policy-Report-Only",
|
|
38
|
+
value: "script-src 'self'",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const first = documentRewrite.headers(headers);
|
|
42
|
+
documentRewrite.headers(headers);
|
|
43
|
+
expect(first).to.deep.equal([
|
|
44
|
+
{ name: "Content-Security-Policy", value: `script-src 'self' ${APP}` },
|
|
45
|
+
{
|
|
46
|
+
name: "Content-Security-Policy-Report-Only",
|
|
47
|
+
value: "script-src 'self'",
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
expect(warnings).to.have.length(1);
|
|
51
|
+
expect(warnings[0]).to.contain("script-src");
|
|
52
|
+
});
|
|
53
|
+
it("removes every policy with -s", () => {
|
|
54
|
+
const { rewrite: documentRewrite, warnings } = rewrite(true);
|
|
55
|
+
const headers = documentRewrite.headers([
|
|
56
|
+
{ name: "content-security-policy", value: "script-src 'self'" },
|
|
57
|
+
{ name: "content-type", value: "text/html" },
|
|
58
|
+
]);
|
|
59
|
+
const html = documentRewrite.html(`<html><head><meta http-equiv="Content-Security-Policy" content="script-src 'self'"></head></html>`);
|
|
60
|
+
expect(headers).to.deep.equal([
|
|
61
|
+
{ name: "content-type", value: "text/html" },
|
|
62
|
+
]);
|
|
63
|
+
expect(html).not.to.contain("Content-Security-Policy");
|
|
64
|
+
expect(warnings).to.deep.equal([]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { InjectedInstallation } from "../../inject/injected-installation.js";
|
|
4
|
+
const RESOURCE = {
|
|
5
|
+
installPath: "https://example.app.baqend.com/v1/speedkit/install.js",
|
|
6
|
+
installParams: 'async="" crossorigin="anonymous"',
|
|
7
|
+
};
|
|
8
|
+
describe("InjectedInstallation", () => {
|
|
9
|
+
it("injects the latest deployed installation without a testing id", () => {
|
|
10
|
+
const installation = new InjectedInstallation(RESOURCE);
|
|
11
|
+
expect(installation.installPath).to.equal(RESOURCE.installPath);
|
|
12
|
+
expect(installation.installParams).to.equal(RESOURCE.installParams);
|
|
13
|
+
expect(installation.installPage("/")).to.equal("/speed-kit-install.html?url=%2F&enableSpeedKit=1");
|
|
14
|
+
});
|
|
15
|
+
it("names the testing installation in the install resource and on the install page", () => {
|
|
16
|
+
const installation = new InjectedInstallation(RESOURCE, "abc-123");
|
|
17
|
+
expect(installation.installPath).to.equal(`${RESOURCE.installPath}?r=abc-123`);
|
|
18
|
+
expect(installation.installPage("/de/")).to.equal("/de/speed-kit-install.html?url=%2Fde%2F&enableSpeedKit=1&debugSpeedKit=abc-123");
|
|
19
|
+
});
|
|
20
|
+
it("appends to an install path that has a query", () => {
|
|
21
|
+
const installation = new InjectedInstallation({ ...RESOURCE, installPath: "/sk/install.js?v=2" }, "abc-123");
|
|
22
|
+
expect(installation.installPath).to.equal("/sk/install.js?v=2&r=abc-123");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { withInjectDefault } from "../onboarding-service-build-context.js";
|
|
4
|
+
describe("withInjectDefault", () => {
|
|
5
|
+
it("gives --inject at the end the latest installation", () => {
|
|
6
|
+
expect(withInjectDefault(["customers/shop", "--inject"])).to.deep.equal([
|
|
7
|
+
"customers/shop",
|
|
8
|
+
"--inject=latest",
|
|
9
|
+
]);
|
|
10
|
+
});
|
|
11
|
+
it("gives --inject before another flag the latest installation", () => {
|
|
12
|
+
expect(withInjectDefault(["customers/shop", "--inject", "--headless"])).to.deep.equal(["customers/shop", "--inject=latest", "--headless"]);
|
|
13
|
+
});
|
|
14
|
+
it("keeps the id that follows --inject", () => {
|
|
15
|
+
const argv = ["customers/shop", "--inject", "abc-123", "-p"];
|
|
16
|
+
expect(withInjectDefault(argv)).to.deep.equal(argv);
|
|
17
|
+
});
|
|
18
|
+
it("keeps --inject=<id>", () => {
|
|
19
|
+
const argv = ["customers/shop", "--inject=abc-123"];
|
|
20
|
+
expect(withInjectDefault(argv)).to.deep.equal(argv);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -5,6 +5,8 @@ import { tmpdir } from "node:os";
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { BrowseService } from "../browse/browse-service.js";
|
|
7
7
|
import { BrowseDomainError } from "../error/browse-domain-error.js";
|
|
8
|
+
import { InjectTargetError } from "../error/inject-target-error.js";
|
|
9
|
+
import { InjectService } from "../inject/inject-service.js";
|
|
8
10
|
import { MissingCustomerPathError } from "../error/missing-customer-path-error.js";
|
|
9
11
|
import { BrowserContext } from "../onboarding-model.js";
|
|
10
12
|
import { OnboardingServiceBuildContext, } from "../onboarding-service-build-context.js";
|
|
@@ -40,12 +42,18 @@ function buildContext(values = {}) {
|
|
|
40
42
|
debugPort: 9290,
|
|
41
43
|
browserFetch: false,
|
|
42
44
|
browse: false,
|
|
45
|
+
inject: false,
|
|
43
46
|
...values,
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
/** Records what browse mode would launch, instead of resolving extensions and Chrome. */
|
|
47
50
|
class RecordingFactory extends OnboardingServiceFactory {
|
|
48
51
|
launched;
|
|
52
|
+
installationRead;
|
|
53
|
+
async readDeployedInstallation(installPath, origin) {
|
|
54
|
+
this.installationRead = { installPath, origin };
|
|
55
|
+
return { swPath: "/deployed-sw.js", scope: "/" };
|
|
56
|
+
}
|
|
49
57
|
async prepareBrowser(domain, customerChromeFlags) {
|
|
50
58
|
this.launched = { domain, customerChromeFlags };
|
|
51
59
|
return {
|
|
@@ -60,7 +68,7 @@ class RecordingFactory extends OnboardingServiceFactory {
|
|
|
60
68
|
}
|
|
61
69
|
describe("OnboardingServiceFactory", () => {
|
|
62
70
|
describe("CUSTOMERPATH", () => {
|
|
63
|
-
it("is required without --browse", async () => {
|
|
71
|
+
it("is required without --browse and without --inject", async () => {
|
|
64
72
|
const factory = new OnboardingServiceFactory(buildContext());
|
|
65
73
|
const error = await factory.getService().catch((error_) => error_);
|
|
66
74
|
expect(error).to.be.instanceOf(MissingCustomerPathError);
|
|
@@ -81,7 +89,7 @@ describe("OnboardingServiceFactory", () => {
|
|
|
81
89
|
expect(factory.launched).to.equal(undefined);
|
|
82
90
|
});
|
|
83
91
|
});
|
|
84
|
-
describe("
|
|
92
|
+
describe("a mode that reads only config_customer.json", () => {
|
|
85
93
|
let customerPath;
|
|
86
94
|
before(() => {
|
|
87
95
|
customerPath = mkdtempSync(join(tmpdir(), "sk-browse-"));
|
|
@@ -114,6 +122,49 @@ describe("OnboardingServiceFactory", () => {
|
|
|
114
122
|
await factory.getService();
|
|
115
123
|
expect(factory.launched?.domain).to.equal("https://shop.example.com/");
|
|
116
124
|
});
|
|
125
|
+
it("builds the inject service under --inject, without any other config file", async () => {
|
|
126
|
+
const factory = new RecordingFactory(buildContext({ inject: true, testing: "abc-123", customerPath }));
|
|
127
|
+
const service = await factory.getService();
|
|
128
|
+
expect(service).to.be.instanceOf(InjectService);
|
|
129
|
+
expect(factory.launched).to.deep.equal({
|
|
130
|
+
domain: "https://www.example.com/",
|
|
131
|
+
customerChromeFlags: ["--lang=fr"],
|
|
132
|
+
});
|
|
133
|
+
expect(factory.installationRead).to.deep.equal({
|
|
134
|
+
installPath: "https://example-shop.app.baqend.com/v1/speedkit/install.js?d=production&r=abc-123",
|
|
135
|
+
origin: "https://www.example.com",
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("inject mode without a CUSTOMERPATH", () => {
|
|
140
|
+
it("takes the app and the domain from the flags", async () => {
|
|
141
|
+
const factory = new RecordingFactory(buildContext({
|
|
142
|
+
inject: true,
|
|
143
|
+
app: "example-shop",
|
|
144
|
+
domain: "www.example.com",
|
|
145
|
+
}));
|
|
146
|
+
const service = await factory.getService();
|
|
147
|
+
expect(service).to.be.instanceOf(InjectService);
|
|
148
|
+
expect(factory.launched).to.deep.equal({
|
|
149
|
+
domain: "https://www.example.com/",
|
|
150
|
+
customerChromeFlags: undefined,
|
|
151
|
+
});
|
|
152
|
+
expect(factory.installationRead).to.deep.equal({
|
|
153
|
+
installPath: "https://example-shop.app.baqend.com/v1/speedkit/install.js",
|
|
154
|
+
origin: "https://www.example.com",
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
for (const [missing, values] of [
|
|
158
|
+
["app", { domain: "www.example.com" }],
|
|
159
|
+
["domain", { app: "example-shop" }],
|
|
160
|
+
]) {
|
|
161
|
+
it(`fails without ${missing === "app" ? "an app" : "a domain"}`, async () => {
|
|
162
|
+
const factory = new RecordingFactory(buildContext({ inject: true, ...values }));
|
|
163
|
+
const error = await factory.getService().catch((error_) => error_);
|
|
164
|
+
expect(error).to.be.instanceOf(InjectTargetError);
|
|
165
|
+
expect(factory.launched).to.equal(undefined);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
117
168
|
});
|
|
118
169
|
describe("buildBrowserContext", () => {
|
|
119
170
|
const inputs = {
|
|
@@ -192,6 +192,9 @@ aside.loader:not(.stop)::after {
|
|
|
192
192
|
step1.classList.add('error')
|
|
193
193
|
showError(new Error('unable to load script: {{{installPath}}}' ))
|
|
194
194
|
})
|
|
195
|
+
{{#if crossOrigin}}
|
|
196
|
+
installScript.crossOrigin = 'anonymous';
|
|
197
|
+
{{/if}}
|
|
195
198
|
installScript.setAttribute('src','{{{installPath}}}')
|
|
196
199
|
document.querySelector('head').appendChild(installScript)
|
|
197
200
|
|
|
@@ -5,11 +5,6 @@ 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
|
-
|
|
13
8
|
// Reset potential split test parameters
|
|
14
9
|
speedKit.split = 1.0;
|
|
15
10
|
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(app, 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(app, origin, speedKitConfigFile) {
|
|
76
|
+
const result = await safe(speedKitConfigFile.evaluate(app, origin));
|
|
77
77
|
if (result.success !== true) {
|
|
78
78
|
throw new ParseConfigSpeedKitError(result.error);
|
|
79
79
|
}
|