@speedkit/cli 4.44.1 → 4.45.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 +15 -0
- package/README.md +10 -6
- package/dist/commands/origin-request.d.ts +2 -1
- package/dist/commands/origin-request.js +4 -1
- package/dist/services/diff/side-failure.js +17 -1
- package/dist/services/diff/spec/diff-service.spec.js +16 -0
- package/dist/services/onboarding/onboarding-model.d.ts +0 -6
- package/dist/services/onboarding/onboarding-model.js +0 -6
- package/dist/services/origin-request/origin-request-service-build-context.d.ts +6 -3
- package/dist/services/origin-request/origin-request-service-build-context.js +30 -4
- package/dist/services/origin-request/origin-request-service-factory.d.ts +5 -0
- package/dist/services/origin-request/origin-request-service-factory.js +28 -12
- package/dist/services/origin-request/origin-request-service.d.ts +2 -1
- package/dist/services/origin-request/origin-request-service.js +4 -2
- package/dist/services/origin-request/spec/origin-request-service-build-context.spec.d.ts +1 -0
- package/dist/services/origin-request/spec/origin-request-service-build-context.spec.js +32 -0
- package/dist/services/origin-request/spec/origin-request-service.spec.d.ts +1 -0
- package/dist/services/origin-request/spec/origin-request-service.spec.js +9 -0
- package/oclif.manifest.json +12 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [4.45.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.45.0...v4.45.1) (2026-10-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **diff:** an unreachable local pre-renderer fails the diff ([9b92707](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/9b927072fcd751f0fffea3f12c53bd5d9d63573d))
|
|
7
|
+
* **origin-request:** exit 2 when the runtime config cannot be used ([613b6e0](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/613b6e035b866ffc3d9e1c39683d6cb02cb42fd5))
|
|
8
|
+
|
|
9
|
+
# [4.45.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.44.1...v4.45.0) (2026-10-15)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **origin-request:** a raw mode without a customer ([9acce74](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/9acce74f54622caff99a422d89b362f574ec440b))
|
|
15
|
+
|
|
1
16
|
## [4.44.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.44.0...v4.44.1) (2026-10-15)
|
|
2
17
|
|
|
3
18
|
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ By either...
|
|
|
89
89
|
* [`sk help [COMMAND]`](#sk-help-command)
|
|
90
90
|
* [`sk login [APP]`](#sk-login-app)
|
|
91
91
|
* [`sk onboarding [CUSTOMERPATH]`](#sk-onboarding-customerpath)
|
|
92
|
-
* [`sk origin-request CUSTOMERPATH PAGEURL`](#sk-origin-request-customerpath-pageurl)
|
|
92
|
+
* [`sk origin-request [CUSTOMERPATH] [PAGEURL]`](#sk-origin-request-customerpath-pageurl)
|
|
93
93
|
* [`sk prewarm APP PATH`](#sk-prewarm-app-path)
|
|
94
94
|
* [`sk pull CUSTOMERPATH`](#sk-pull-customerpath)
|
|
95
95
|
* [`sk query parameter CUSTOMERPATH`](#sk-query-parameter-customerpath)
|
|
@@ -826,18 +826,18 @@ EXAMPLES
|
|
|
826
826
|
$ sk onboarding customers/decathlon.de --inject <installationId>
|
|
827
827
|
```
|
|
828
828
|
|
|
829
|
-
## `sk origin-request CUSTOMERPATH PAGEURL`
|
|
829
|
+
## `sk origin-request [CUSTOMERPATH] [PAGEURL]`
|
|
830
830
|
|
|
831
831
|
Request a page from origin with the exact headers Speed Kit's server sends for a cache variation, using the app's deployed runtime config
|
|
832
832
|
|
|
833
833
|
```
|
|
834
834
|
USAGE
|
|
835
|
-
$ sk origin-request CUSTOMERPATH PAGEURL [-c <value>] [-v <value>] [--host <value>] [--body <value>] [--grep
|
|
836
|
-
<value>] [--json] [--variations <value>]
|
|
835
|
+
$ sk origin-request [CUSTOMERPATH] [PAGEURL] [-c <value>] [-v <value>] [--host <value>] [--body <value>] [--grep
|
|
836
|
+
<value>] [--json] [--variations <value>] [--raw]
|
|
837
837
|
|
|
838
838
|
ARGUMENTS
|
|
839
|
-
CUSTOMERPATH The customer config path
|
|
840
|
-
PAGEURL Page to request from origin
|
|
839
|
+
[CUSTOMERPATH] The customer config path; optional with --raw, which then sends Speed Kit's device defaults
|
|
840
|
+
[PAGEURL] Page to request from origin
|
|
841
841
|
|
|
842
842
|
FLAGS
|
|
843
843
|
-c, --configName=<value> [default: production] The costumer config name
|
|
@@ -847,6 +847,8 @@ FLAGS
|
|
|
847
847
|
--grep=<value> Print body lines matching this regex, case-insensitive
|
|
848
848
|
--host=<value> Send this Host header, emulating an origin-map host override
|
|
849
849
|
--json Machine-readable output
|
|
850
|
+
--raw Request without a customer: the customer path becomes optional, and the request carries
|
|
851
|
+
Speed Kit's device defaults (default, mobile, tablet) and no variation of an app
|
|
850
852
|
--variations=<value> Simulate against a runtime config in a local file instead of the app's deployed one
|
|
851
853
|
|
|
852
854
|
DESCRIPTION
|
|
@@ -859,6 +861,8 @@ EXAMPLES
|
|
|
859
861
|
$ sk origin-request customers/decathlon.de https://www.decathlon.de/ -v mobile
|
|
860
862
|
|
|
861
863
|
$ sk origin-request customers/decathlon.de https://www.decathlon.de/ --grep "storeId" --body /tmp/origin.html
|
|
864
|
+
|
|
865
|
+
$ sk origin-request --raw https://www.decathlon.de/ -v mobile --body /tmp/mobile.html
|
|
862
866
|
```
|
|
863
867
|
|
|
864
868
|
## `sk prewarm APP PATH`
|
|
@@ -4,10 +4,10 @@ export default class OriginRequest extends SkCommand<OriginRequestServiceBuildCo
|
|
|
4
4
|
static description: string;
|
|
5
5
|
static buildContext: typeof OriginRequestServiceBuildContext;
|
|
6
6
|
static args: {
|
|
7
|
-
pageUrl: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
8
7
|
customerPath: import("@oclif/core/interfaces").Arg<string, {
|
|
9
8
|
exists?: boolean;
|
|
10
9
|
}>;
|
|
10
|
+
pageUrl: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
11
11
|
};
|
|
12
12
|
static flags: {
|
|
13
13
|
variation: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -16,6 +16,7 @@ export default class OriginRequest extends SkCommand<OriginRequestServiceBuildCo
|
|
|
16
16
|
grep: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
17
|
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
18
|
variations: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
raw: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
20
|
configName: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
21
|
};
|
|
21
22
|
static examples: string[];
|
|
@@ -9,9 +9,12 @@ export default class OriginRequest extends SkCommand {
|
|
|
9
9
|
`$ sk origin-request <customerPath> <pageUrl>`,
|
|
10
10
|
`$ sk origin-request customers/decathlon.de https://www.decathlon.de/ -v mobile`,
|
|
11
11
|
`$ sk origin-request customers/decathlon.de https://www.decathlon.de/ --grep "storeId" --body /tmp/origin.html`,
|
|
12
|
+
`$ sk origin-request --raw https://www.decathlon.de/ -v mobile --body /tmp/mobile.html`,
|
|
12
13
|
];
|
|
13
14
|
async run() {
|
|
14
15
|
const service = await new OriginRequestServiceFactory(this.context).buildService();
|
|
15
|
-
|
|
16
|
+
// Exit 2 like `sk diff` when nothing could be requested, so a script does not read a success.
|
|
17
|
+
if (!(await service.run()))
|
|
18
|
+
this.exit(2);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ABORT_ERROR_CODE, DOCUMENT_HANDLER_ERROR_CODE, isDocumentHandlerAbort, } from "../document-handler-runtime/document-handler-abort.js";
|
|
1
|
+
import { ABORT_ERROR_CODE, DOCUMENT_HANDLER_ERROR_CODE, isDocumentHandlerAbort, isLocalPrerendererUnreachable, LOCAL_PRERENDERER_PORT, } from "../document-handler-runtime/document-handler-abort.js";
|
|
2
2
|
import ApplicationError from "../error-handling/error/application-error.js";
|
|
3
3
|
import { DocumentHandlerTransformError } from "../onboarding/error/document-handler-transform-error.js";
|
|
4
4
|
import { VmEmptyResponseError } from "../onboarding/error/vm-empty-response-error.js";
|
|
5
5
|
import { ORIGIN_ERROR_CODE, originErrorCauseName, originErrorCode, } from "../origin-request/index.js";
|
|
6
|
+
/** The cause of an SSR fetch that found no local pre-renderer: a setup gap, not a verdict. */
|
|
7
|
+
const LOCAL_PRERENDERER_UNREACHABLE = "LocalPrerendererUnreachable";
|
|
6
8
|
/** How a failure reads in a log line: its cause name and Speed Kit error code. */
|
|
7
9
|
function causeLine(failure) {
|
|
8
10
|
return `${failure.cause} (${failure.code})`;
|
|
@@ -14,6 +16,11 @@ function hints(failure) {
|
|
|
14
16
|
"Speed Kit never caches this page: the documentHandler aborts it, and the service worker falls back to origin.",
|
|
15
17
|
];
|
|
16
18
|
}
|
|
19
|
+
if (failure.cause === LOCAL_PRERENDERER_UNREACHABLE) {
|
|
20
|
+
return [
|
|
21
|
+
"Start the pre-renderer in puppeteer-lambda (`npm run run:dev`), then diff again.",
|
|
22
|
+
];
|
|
23
|
+
}
|
|
17
24
|
if (failure.kind === "documentHandlerError") {
|
|
18
25
|
return [
|
|
19
26
|
"Check config_documentHandler.es6 | custom_documentHandler.js: the documentHandler threw.",
|
|
@@ -84,6 +91,15 @@ export function documentHandlerFailure(error) {
|
|
|
84
91
|
!(error instanceof VmEmptyResponseError)) {
|
|
85
92
|
return undefined;
|
|
86
93
|
}
|
|
94
|
+
// The documentHandler wraps the refused SSR fetch as an abort, but Speed Kit's server has a renderer.
|
|
95
|
+
if (isLocalPrerendererUnreachable(error)) {
|
|
96
|
+
return {
|
|
97
|
+
kind: "documentHandlerError",
|
|
98
|
+
code: DOCUMENT_HANDLER_ERROR_CODE,
|
|
99
|
+
cause: LOCAL_PRERENDERER_UNREACHABLE,
|
|
100
|
+
reason: `SSR is configured, but no pre-renderer is listening on localhost:${LOCAL_PRERENDERER_PORT}`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
87
103
|
return isDocumentHandlerAbort(error)
|
|
88
104
|
? {
|
|
89
105
|
kind: "documentHandlerAbort",
|
|
@@ -329,6 +329,22 @@ describe("DiffService failed sides", () => {
|
|
|
329
329
|
});
|
|
330
330
|
expect(log.lines.join("\n")).to.contain("ServerDocumentHandlerAbort (303): old-engine PLP");
|
|
331
331
|
});
|
|
332
|
+
it("fails, not ends as not cacheable, when no local pre-renderer listens", async () => {
|
|
333
|
+
const refused = new TypeError("fetch failed", {
|
|
334
|
+
cause: { code: "ECONNREFUSED", port: 3001 },
|
|
335
|
+
});
|
|
336
|
+
const { diff, failed, log } = service("https://shop.test/?a=1", {
|
|
337
|
+
"https://shop.test/?a=1": new PageSideFailure({
|
|
338
|
+
url: "https://shop.test/?a=1",
|
|
339
|
+
variation: "default",
|
|
340
|
+
failure: documentHandlerFailure(new DocumentHandlerTransformError(new DocumentHandlerAbort(refused.toString(), { error: refused }))),
|
|
341
|
+
}),
|
|
342
|
+
"https://shop.test/": "<p>none</p>",
|
|
343
|
+
});
|
|
344
|
+
expect(await diff.run()).to.equal("failed");
|
|
345
|
+
expect(failed[0].outcome).to.equal("failed");
|
|
346
|
+
expect(log.lines.join("\n")).to.contain("Start the pre-renderer");
|
|
347
|
+
});
|
|
332
348
|
it("ranks a diff above a page that is not cacheable", async () => {
|
|
333
349
|
const { diff, failed } = service("https://shop.test/?a=1&b=2", {
|
|
334
350
|
"https://shop.test/?a=1&b=2": "<p>a b</p>",
|
|
@@ -184,11 +184,5 @@ export type DevelopmentToolsMessage = {
|
|
|
184
184
|
id: "localCacheError";
|
|
185
185
|
data: LocalCacheError[];
|
|
186
186
|
};
|
|
187
|
-
export declare const USER_AGENT: {
|
|
188
|
-
DESKTOP: string;
|
|
189
|
-
MOBILE: string;
|
|
190
|
-
TABLET: string;
|
|
191
|
-
TV: string;
|
|
192
|
-
};
|
|
193
187
|
export declare const SpeedKitInstallRegex: RegExp;
|
|
194
188
|
export declare const META_CONTENT_TYPE_REGEX: RegExp;
|
|
@@ -208,11 +208,5 @@ export class BrowserContext {
|
|
|
208
208
|
export const DEFAULT_DF_PATH = "https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js";
|
|
209
209
|
export const DEFAULT_SNIPPET_PATH = "https://www.baqend.com/speed-kit/latest/snippet.js";
|
|
210
210
|
export const DEFAULT_SW_PATH = "https://www.baqend.com/speed-kit/latest/sw.js";
|
|
211
|
-
export const USER_AGENT = {
|
|
212
|
-
DESKTOP: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15 (compatible; SpeedKit/1.0)",
|
|
213
|
-
MOBILE: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1 (compatible; SpeedKit/1.0)",
|
|
214
|
-
TABLET: "Mozilla/5.0 (iPad; CPU OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1 (compatible; SpeedKit/1.0)",
|
|
215
|
-
TV: "Mozilla/5.0 (Linux; NetCast; U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 SmartTV/10.0 Colt/2.0 (compatible; SpeedKit/1.0)",
|
|
216
|
-
};
|
|
217
211
|
export const SpeedKitInstallRegex = /<script[^>]*src[^>]*app\.baqend\.com\/v1\/speedkit\/install.js[^>]*>(?:(?!<\/script>).)*<\/script>/s;
|
|
218
212
|
export const META_CONTENT_TYPE_REGEX = /<meta[^"]*http-equiv="content-type"[^"]*content="text\/html;[^"]*charset=([^\s"(),./:;<=>?@[\]]*)"/is;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Interfaces } from "@oclif/core";
|
|
2
2
|
import { CommandContextValues, CliEnvironment } from "../cli/index.js";
|
|
3
3
|
declare const args: {
|
|
4
|
-
pageUrl: Interfaces.Arg<string, Record<string, unknown>>;
|
|
5
4
|
customerPath: Interfaces.Arg<string, {
|
|
6
5
|
exists?: boolean;
|
|
7
6
|
}>;
|
|
7
|
+
pageUrl: Interfaces.Arg<string, Record<string, unknown>>;
|
|
8
8
|
};
|
|
9
9
|
declare const flags: {
|
|
10
10
|
variation: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
@@ -13,11 +13,13 @@ declare const flags: {
|
|
|
13
13
|
grep: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
14
14
|
json: Interfaces.BooleanFlag<boolean>;
|
|
15
15
|
variations: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
16
|
+
raw: Interfaces.BooleanFlag<boolean>;
|
|
16
17
|
configName: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
17
18
|
};
|
|
18
19
|
/** What `sk origin-request` asks for, as the service reads it. */
|
|
19
20
|
export interface OriginRequestOptions {
|
|
20
|
-
|
|
21
|
+
/** Absent with `--raw <pageUrl>`: no app, so only the device defaults resolve. */
|
|
22
|
+
readonly customerPath?: string;
|
|
21
23
|
readonly configName: string;
|
|
22
24
|
readonly pageUrl: string;
|
|
23
25
|
readonly variation?: string;
|
|
@@ -33,10 +35,10 @@ declare const OriginRequestServiceBuildContext_base: new (values: OriginRequestS
|
|
|
33
35
|
/** What an origin request is built from. */
|
|
34
36
|
export declare class OriginRequestServiceBuildContext extends OriginRequestServiceBuildContext_base {
|
|
35
37
|
static readonly args: {
|
|
36
|
-
pageUrl: Interfaces.Arg<string, Record<string, unknown>>;
|
|
37
38
|
customerPath: Interfaces.Arg<string, {
|
|
38
39
|
exists?: boolean;
|
|
39
40
|
}>;
|
|
41
|
+
pageUrl: Interfaces.Arg<string, Record<string, unknown>>;
|
|
40
42
|
};
|
|
41
43
|
static readonly flags: {
|
|
42
44
|
variation: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
@@ -45,6 +47,7 @@ export declare class OriginRequestServiceBuildContext extends OriginRequestServi
|
|
|
45
47
|
grep: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
46
48
|
json: Interfaces.BooleanFlag<boolean>;
|
|
47
49
|
variations: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
50
|
+
raw: Interfaces.BooleanFlag<boolean>;
|
|
48
51
|
configName: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
49
52
|
};
|
|
50
53
|
static create(parsedArgs: Interfaces.InferredArgs<typeof args>, parsedFlags: Interfaces.InferredFlags<typeof flags>, environment: CliEnvironment): OriginRequestServiceBuildContext;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { Args, Flags } from "@oclif/core";
|
|
2
2
|
import { CLI_CONFIG_NAME, CLI_CUSTOMER_CONFIG, } from "../integration-api/customer-config-flags.js";
|
|
3
3
|
import { Context } from "../../models/context.js";
|
|
4
|
+
import ApplicationError from "../error-handling/error/application-error.js";
|
|
5
|
+
/** Whether an argument is a page rather than a customer directory. */
|
|
6
|
+
function isUrl(value) {
|
|
7
|
+
return /^https?:\/\//i.test(value ?? "");
|
|
8
|
+
}
|
|
4
9
|
const args = {
|
|
5
|
-
|
|
10
|
+
customerPath: Args.directory({
|
|
11
|
+
...CLI_CUSTOMER_CONFIG.customerPath,
|
|
12
|
+
required: false,
|
|
13
|
+
description: "The customer config path; optional with --raw, which then sends Speed Kit's device defaults",
|
|
14
|
+
}),
|
|
6
15
|
pageUrl: Args.string({
|
|
7
16
|
name: "pageUrl",
|
|
8
|
-
required:
|
|
17
|
+
required: false,
|
|
9
18
|
description: "Page to request from origin",
|
|
10
19
|
example: "https://www.decathlon.de/",
|
|
11
20
|
}),
|
|
@@ -31,17 +40,34 @@ const flags = {
|
|
|
31
40
|
variations: Flags.string({
|
|
32
41
|
description: "Simulate against a runtime config in a local file instead of the app's deployed one",
|
|
33
42
|
}),
|
|
43
|
+
raw: Flags.boolean({
|
|
44
|
+
description: "Request without a customer: the customer path becomes optional, and the request carries Speed Kit's device defaults (default, mobile, tablet) and no variation of an app",
|
|
45
|
+
}),
|
|
34
46
|
};
|
|
35
47
|
/** What an origin request is built from. */
|
|
36
48
|
export class OriginRequestServiceBuildContext extends Context() {
|
|
37
49
|
static args = args;
|
|
38
50
|
static flags = flags;
|
|
39
51
|
static create(parsedArgs, parsedFlags, environment) {
|
|
52
|
+
// `sk origin-request --raw <url>`: a lone url is the page, not a customer directory.
|
|
53
|
+
const [customerPath, pageUrl] = isUrl(parsedArgs.customerPath)
|
|
54
|
+
? [undefined, parsedArgs.customerPath]
|
|
55
|
+
: [parsedArgs.customerPath, parsedArgs.pageUrl];
|
|
56
|
+
if (!pageUrl) {
|
|
57
|
+
throw new ApplicationError("sk origin-request needs the page to request.", [
|
|
58
|
+
"sk origin-request <customerPath> <pageUrl>, or sk origin-request --raw <pageUrl>",
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
if (!customerPath && !parsedFlags.raw) {
|
|
62
|
+
throw new ApplicationError("Without a customer path there is no runtime config to build the request from.", [
|
|
63
|
+
"Name the customer, or pass --raw to send Speed Kit's device defaults.",
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
40
66
|
return new OriginRequestServiceBuildContext({
|
|
41
67
|
environment,
|
|
42
|
-
customerPath
|
|
68
|
+
customerPath,
|
|
43
69
|
configName: parsedFlags.configName,
|
|
44
|
-
pageUrl
|
|
70
|
+
pageUrl,
|
|
45
71
|
variation: parsedFlags.variation,
|
|
46
72
|
host: parsedFlags.host,
|
|
47
73
|
bodyFile: parsedFlags.body,
|
|
@@ -6,6 +6,11 @@ export declare class OriginRequestServiceFactory {
|
|
|
6
6
|
constructor(context: OriginRequestServiceBuildContext);
|
|
7
7
|
buildService(): Promise<OriginRequestService>;
|
|
8
8
|
private build;
|
|
9
|
+
/**
|
|
10
|
+
* The runtime config: a local file when one is named, else the app's. Without a customer there is
|
|
11
|
+
* no app, and the request carries Speed Kit's device defaults only.
|
|
12
|
+
*/
|
|
13
|
+
private loadRuntimeConfig;
|
|
9
14
|
private getIntegrationFiles;
|
|
10
15
|
private getConfigApi;
|
|
11
16
|
}
|
|
@@ -3,7 +3,7 @@ import { IntegrationApiServiceBuildContext, IntegrationApiFactory, } from "../in
|
|
|
3
3
|
import { applyOriginProxy } from "../../helpers/origin-proxy.js";
|
|
4
4
|
import { OriginRequestService } from "./origin-request-service.js";
|
|
5
5
|
import { OriginFetcher } from "./origin-fetcher.js";
|
|
6
|
-
import { RuntimeConfigSource } from "./runtime-config-source.js";
|
|
6
|
+
import { RuntimeConfigSource, } from "./runtime-config-source.js";
|
|
7
7
|
export class OriginRequestServiceFactory {
|
|
8
8
|
context;
|
|
9
9
|
service = undefined;
|
|
@@ -18,16 +18,14 @@ export class OriginRequestServiceFactory {
|
|
|
18
18
|
}
|
|
19
19
|
async build() {
|
|
20
20
|
const cli = this.context.environment.cli;
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const customer = this.context.customerPath
|
|
22
|
+
? (await this.getIntegrationFiles(this.context.customerPath)).getCustomerConfig().config
|
|
23
|
+
: undefined;
|
|
23
24
|
// `--json` owns stdout, so the proxy line stays out of a machine-readable run.
|
|
24
|
-
applyOriginProxy(customer
|
|
25
|
-
const config = await
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
fileFlag: "--variations",
|
|
29
|
-
}).load(this.context.variationsFile);
|
|
30
|
-
const usable = config && Object.keys(config.variations).length > 0;
|
|
25
|
+
applyOriginProxy(customer?.chromeFlags, this.context.json ? undefined : cli);
|
|
26
|
+
const config = await this.loadRuntimeConfig(customer?.app);
|
|
27
|
+
// Without a customer, an empty set is the point: only the device defaults resolve.
|
|
28
|
+
const usable = config && (!customer || Object.keys(config.variations).length > 0);
|
|
31
29
|
if (config && !usable) {
|
|
32
30
|
cli.writeError("the config carries no speedKit.variations — nothing to simulate");
|
|
33
31
|
}
|
|
@@ -40,10 +38,28 @@ export class OriginRequestServiceFactory {
|
|
|
40
38
|
})
|
|
41
39
|
: undefined);
|
|
42
40
|
}
|
|
43
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The runtime config: a local file when one is named, else the app's. Without a customer there is
|
|
43
|
+
* no app, and the request carries Speed Kit's device defaults only.
|
|
44
|
+
*/
|
|
45
|
+
async loadRuntimeConfig(app) {
|
|
46
|
+
const cli = this.context.environment.cli;
|
|
47
|
+
if (!app && !this.context.variationsFile) {
|
|
48
|
+
if (!this.context.json) {
|
|
49
|
+
cli.writeWarning("no customer: the request carries Speed Kit's device defaults only, no variation of an app");
|
|
50
|
+
}
|
|
51
|
+
return { variations: {}, authentications: [] };
|
|
52
|
+
}
|
|
53
|
+
return new RuntimeConfigSource({
|
|
54
|
+
cli,
|
|
55
|
+
configApi: app ? this.getConfigApi(app) : undefined,
|
|
56
|
+
fileFlag: "--variations",
|
|
57
|
+
}).load(this.context.variationsFile);
|
|
58
|
+
}
|
|
59
|
+
async getIntegrationFiles(customerPath) {
|
|
44
60
|
const integrationApiContext = new IntegrationApiServiceBuildContext({
|
|
45
61
|
environment: this.context.environment,
|
|
46
|
-
basePath:
|
|
62
|
+
basePath: customerPath,
|
|
47
63
|
configName: this.context.configName,
|
|
48
64
|
whitelist: [],
|
|
49
65
|
});
|
|
@@ -24,6 +24,7 @@ export declare class OriginRequestService {
|
|
|
24
24
|
constructor(context: OriginRequestOptions, cli: CliServiceInterface,
|
|
25
25
|
/** Absent when the runtime config could not be used; the reason is reported. */
|
|
26
26
|
fetcher: OriginFetcher | undefined);
|
|
27
|
-
|
|
27
|
+
/** False when the request was not sent, because the runtime config could not be used. */
|
|
28
|
+
run(): Promise<boolean>;
|
|
28
29
|
private report;
|
|
29
30
|
}
|
|
@@ -36,11 +36,12 @@ export class OriginRequestService {
|
|
|
36
36
|
this.cli = cli;
|
|
37
37
|
this.fetcher = fetcher;
|
|
38
38
|
}
|
|
39
|
+
/** False when the request was not sent, because the runtime config could not be used. */
|
|
39
40
|
async run() {
|
|
40
41
|
// Without a runtime config every request would resolve to the bare defaults, so the report
|
|
41
42
|
// would describe a request the server never sends. Stop instead of simulating something wrong.
|
|
42
43
|
if (!this.fetcher)
|
|
43
|
-
return;
|
|
44
|
+
return false;
|
|
44
45
|
const variation = this.context.variation ?? DEFAULT_TYPE;
|
|
45
46
|
const { url, init, resolved } = this.fetcher.prepare(this.context.pageUrl, this.context.variation);
|
|
46
47
|
const headers = printable(init.headers);
|
|
@@ -61,9 +62,10 @@ export class OriginRequestService {
|
|
|
61
62
|
setCookie: setCookies,
|
|
62
63
|
bodyLength: body.length,
|
|
63
64
|
}, null, 2));
|
|
64
|
-
return;
|
|
65
|
+
return true;
|
|
65
66
|
}
|
|
66
67
|
this.report(variation, resolved, headers, response, setCookies, body);
|
|
68
|
+
return true;
|
|
67
69
|
}
|
|
68
70
|
report(variation, resolved, headers, response, setCookies, body) {
|
|
69
71
|
this.cli.write(`variation ${variation}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { OriginRequestServiceBuildContext } from "../origin-request-service-build-context.js";
|
|
4
|
+
const environment = {};
|
|
5
|
+
function create(args, flags = {}) {
|
|
6
|
+
return OriginRequestServiceBuildContext.create(args, { configName: "production", json: false, raw: false, ...flags }, environment);
|
|
7
|
+
}
|
|
8
|
+
describe("OriginRequestServiceBuildContext", () => {
|
|
9
|
+
it("takes the customer and the page", () => {
|
|
10
|
+
const context = create({
|
|
11
|
+
customerPath: "customers/shop",
|
|
12
|
+
pageUrl: "https://shop.test/",
|
|
13
|
+
});
|
|
14
|
+
expect(context.customerPath).to.equal("customers/shop");
|
|
15
|
+
expect(context.pageUrl).to.equal("https://shop.test/");
|
|
16
|
+
});
|
|
17
|
+
it("takes a lone url as the page with --raw", () => {
|
|
18
|
+
const context = create({ customerPath: "https://shop.test/" }, { raw: true });
|
|
19
|
+
expect(context.customerPath).to.equal(undefined);
|
|
20
|
+
expect(context.pageUrl).to.equal("https://shop.test/");
|
|
21
|
+
});
|
|
22
|
+
it("keeps the customer with --raw when one is named", () => {
|
|
23
|
+
const context = create({ customerPath: "customers/shop", pageUrl: "https://shop.test/" }, { raw: true });
|
|
24
|
+
expect(context.customerPath).to.equal("customers/shop");
|
|
25
|
+
});
|
|
26
|
+
it("refuses a lone url without --raw", () => {
|
|
27
|
+
expect(() => create({ customerPath: "https://shop.test/" })).to.throw(/no runtime config/);
|
|
28
|
+
});
|
|
29
|
+
it("refuses a run without a page", () => {
|
|
30
|
+
expect(() => create({ customerPath: "customers/shop" })).to.throw(/needs the page/);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { OriginRequestService } from "../origin-request-service.js";
|
|
4
|
+
describe("OriginRequestService", () => {
|
|
5
|
+
it("reports that it sent nothing when the runtime config was not usable", async () => {
|
|
6
|
+
const service = new OriginRequestService({ pageUrl: "https://shop.test/" }, {}, undefined);
|
|
7
|
+
expect(await service.run()).to.equal(false);
|
|
8
|
+
});
|
|
9
|
+
});
|
package/oclif.manifest.json
CHANGED
|
@@ -918,21 +918,22 @@
|
|
|
918
918
|
"aliases": [],
|
|
919
919
|
"args": {
|
|
920
920
|
"customerPath": {
|
|
921
|
-
"description": "The customer config path",
|
|
921
|
+
"description": "The customer config path; optional with --raw, which then sends Speed Kit's device defaults",
|
|
922
922
|
"name": "customerPath",
|
|
923
|
-
"required":
|
|
923
|
+
"required": false
|
|
924
924
|
},
|
|
925
925
|
"pageUrl": {
|
|
926
926
|
"description": "Page to request from origin",
|
|
927
927
|
"name": "pageUrl",
|
|
928
|
-
"required":
|
|
928
|
+
"required": false
|
|
929
929
|
}
|
|
930
930
|
},
|
|
931
931
|
"description": "Request a page from origin with the exact headers Speed Kit's server sends for a cache variation, using the app's deployed runtime config",
|
|
932
932
|
"examples": [
|
|
933
933
|
"$ sk origin-request <customerPath> <pageUrl>",
|
|
934
934
|
"$ sk origin-request customers/decathlon.de https://www.decathlon.de/ -v mobile",
|
|
935
|
-
"$ sk origin-request customers/decathlon.de https://www.decathlon.de/ --grep \"storeId\" --body /tmp/origin.html"
|
|
935
|
+
"$ sk origin-request customers/decathlon.de https://www.decathlon.de/ --grep \"storeId\" --body /tmp/origin.html",
|
|
936
|
+
"$ sk origin-request --raw https://www.decathlon.de/ -v mobile --body /tmp/mobile.html"
|
|
936
937
|
],
|
|
937
938
|
"flags": {
|
|
938
939
|
"configName": {
|
|
@@ -986,6 +987,12 @@
|
|
|
986
987
|
"hasDynamicHelp": false,
|
|
987
988
|
"multiple": false,
|
|
988
989
|
"type": "option"
|
|
990
|
+
},
|
|
991
|
+
"raw": {
|
|
992
|
+
"description": "Request without a customer: the customer path becomes optional, and the request carries Speed Kit's device defaults (default, mobile, tablet) and no variation of an app",
|
|
993
|
+
"name": "raw",
|
|
994
|
+
"allowNo": false,
|
|
995
|
+
"type": "boolean"
|
|
989
996
|
}
|
|
990
997
|
},
|
|
991
998
|
"hasDynamicHelp": false,
|
|
@@ -1920,5 +1927,5 @@
|
|
|
1920
1927
|
]
|
|
1921
1928
|
}
|
|
1922
1929
|
},
|
|
1923
|
-
"version": "4.
|
|
1930
|
+
"version": "4.45.1"
|
|
1924
1931
|
}
|