@speedkit/cli 4.44.0-beta.4 → 4.45.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.
Files changed (196) hide show
  1. package/CHANGELOG.md +40 -11
  2. package/README.md +77 -47
  3. package/dist/base/sk-command.d.ts +7 -0
  4. package/dist/base/sk-command.js +19 -0
  5. package/dist/commands/deploy.d.ts +1 -0
  6. package/dist/commands/deploy.js +5 -1
  7. package/dist/commands/diff.d.ts +47 -0
  8. package/dist/commands/diff.js +67 -0
  9. package/dist/commands/generate-pop-config.js +3 -7
  10. package/dist/commands/origin-request.d.ts +2 -1
  11. package/dist/commands/origin-request.js +1 -0
  12. package/dist/helpers/race.js +4 -2
  13. package/dist/helpers/spec/race.spec.js +31 -0
  14. package/dist/models/files.d.ts +0 -1
  15. package/dist/models/files.js +0 -1
  16. package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
  17. package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +1 -7
  18. package/dist/services/browser-fetch/browser-origin-fetcher.js +3 -26
  19. package/dist/services/bundler/bundle-service-factory.d.ts +0 -3
  20. package/dist/services/bundler/bundle-service-factory.js +1 -5
  21. package/dist/services/bundler/bundle-service.d.ts +1 -10
  22. package/dist/services/bundler/bundle-service.js +1 -16
  23. package/dist/services/bundler/index.d.ts +0 -1
  24. package/dist/services/bundler/index.js +0 -1
  25. package/dist/services/cli/cli-environment.d.ts +11 -0
  26. package/dist/services/cli/cli-environment.js +37 -0
  27. package/dist/services/cli/cli-service-model.d.ts +3 -1
  28. package/dist/services/cli/cli-service.d.ts +1 -1
  29. package/dist/services/cli/cli-service.js +4 -1
  30. package/dist/services/cli/spec/cli-environment.spec.js +30 -1
  31. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  32. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
  33. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
  34. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
  35. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
  36. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
  37. package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
  38. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  39. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  40. package/dist/services/deploy/deploy-service-build-context.d.ts +2 -0
  41. package/dist/services/deploy/deploy-service-build-context.js +13 -2
  42. package/dist/services/deploy/deploy-service-factory.js +2 -9
  43. package/dist/services/deploy/deploy-service-model.d.ts +11 -1
  44. package/dist/services/deploy/deploy-service.d.ts +2 -0
  45. package/dist/services/deploy/deploy-service.js +26 -1
  46. package/dist/services/deploy/handler/customer-config-handler.d.ts +2 -2
  47. package/dist/services/deploy/handler/install-resource-handler.d.ts +2 -2
  48. package/dist/services/deploy/handler/install-resource-handler.js +6 -3
  49. package/dist/services/deploy/handler/module-handler.d.ts +2 -2
  50. package/dist/services/deploy/handler/module-handler.js +2 -2
  51. package/dist/services/deploy/handler/server-config-handler.d.ts +2 -2
  52. package/dist/services/deploy/handler/server-config-handler.js +2 -2
  53. package/dist/services/deploy/mr/live-state-check.d.ts +2 -2
  54. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +2 -7
  55. package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
  56. package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
  57. package/dist/services/deploy/policy/index.d.ts +1 -0
  58. package/dist/services/deploy/policy/index.js +1 -0
  59. package/dist/services/deploy/policy/testing-deploy-policy.d.ts +16 -0
  60. package/dist/services/deploy/policy/testing-deploy-policy.js +42 -0
  61. package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
  62. package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
  63. package/dist/services/deploy/spec/handler/install-resource-handler.spec.js +58 -0
  64. package/dist/services/deploy/spec/mr/live-state-check.spec.js +2 -2
  65. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
  66. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.d.ts +1 -0
  67. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +46 -0
  68. package/dist/services/diff/create-diff-engine.d.ts +14 -0
  69. package/dist/services/diff/create-diff-engine.js +42 -0
  70. package/dist/services/diff/customer-origin.d.ts +9 -0
  71. package/dist/services/diff/customer-origin.js +19 -0
  72. package/dist/services/diff/diff-engine.d.ts +30 -0
  73. package/dist/services/diff/diff-engine.js +49 -0
  74. package/dist/services/diff/diff-log.d.ts +9 -0
  75. package/dist/services/diff/diff-log.js +18 -0
  76. package/dist/services/diff/diff-model.d.ts +68 -0
  77. package/dist/services/diff/diff-model.js +1 -0
  78. package/dist/services/diff/diff-service-build-context.d.ts +99 -9
  79. package/dist/services/diff/diff-service-build-context.js +299 -1
  80. package/dist/services/diff/diff-service-factory.d.ts +24 -2
  81. package/dist/services/diff/diff-service-factory.js +165 -3
  82. package/dist/services/diff/diff-service.d.ts +93 -33
  83. package/dist/services/diff/diff-service.js +274 -140
  84. package/dist/services/diff/index.d.ts +12 -1
  85. package/dist/services/diff/index.js +12 -1
  86. package/dist/services/diff/noise-baseline.d.ts +28 -0
  87. package/dist/services/diff/noise-baseline.js +105 -0
  88. package/dist/services/diff/page-source.d.ts +42 -0
  89. package/dist/services/diff/page-source.js +93 -0
  90. package/dist/services/diff/side-failure.d.ts +28 -0
  91. package/dist/services/diff/side-failure.js +100 -0
  92. package/dist/services/diff/sinks/json-diff-sink.d.ts +32 -0
  93. package/dist/services/diff/sinks/json-diff-sink.js +44 -0
  94. package/dist/services/diff/sinks/no-diff-sink.d.ts +5 -0
  95. package/dist/services/diff/sinks/no-diff-sink.js +6 -0
  96. package/dist/services/diff/sinks/patch-diff-sink.d.ts +19 -0
  97. package/dist/services/diff/sinks/patch-diff-sink.js +29 -0
  98. package/dist/services/diff/sinks/tool-diff-sink.d.ts +26 -0
  99. package/dist/services/diff/sinks/tool-diff-sink.js +88 -0
  100. package/dist/services/diff/sinks/unified-patch.d.ts +7 -0
  101. package/dist/services/diff/sinks/unified-patch.js +12 -0
  102. package/dist/services/diff/spec/customer-origin.spec.d.ts +1 -0
  103. package/dist/services/diff/spec/customer-origin.spec.js +27 -0
  104. package/dist/services/diff/spec/diff-engine.spec.d.ts +1 -0
  105. package/dist/services/diff/spec/diff-engine.spec.js +47 -0
  106. package/dist/services/diff/spec/diff-service-build-context.spec.d.ts +1 -0
  107. package/dist/services/diff/spec/diff-service-build-context.spec.js +185 -0
  108. package/dist/services/diff/spec/diff-service.spec.d.ts +1 -0
  109. package/dist/services/diff/spec/diff-service.spec.js +393 -0
  110. package/dist/services/diff/spec/noise-baseline.spec.d.ts +1 -0
  111. package/dist/services/diff/spec/noise-baseline.spec.js +95 -0
  112. package/dist/services/diff/spec/page-source.spec.d.ts +1 -0
  113. package/dist/services/diff/spec/page-source.spec.js +140 -0
  114. package/dist/services/diff/spec/sinks/json-diff-sink.spec.d.ts +1 -0
  115. package/dist/services/diff/spec/sinks/json-diff-sink.spec.js +72 -0
  116. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.d.ts +1 -0
  117. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.js +47 -0
  118. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.d.ts +1 -0
  119. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.js +61 -0
  120. package/dist/services/document-handler-runtime/document-handler-abort.d.ts +2 -0
  121. package/dist/services/document-handler-runtime/document-handler-abort.js +2 -0
  122. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  123. package/dist/services/document-handler-runtime/document-handler-server.js +19 -81
  124. package/dist/services/document-handler-runtime/runtime-files.d.ts +9 -0
  125. package/dist/services/document-handler-runtime/runtime-files.js +17 -0
  126. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  127. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -68
  128. package/dist/services/integration-api/struct/customer-config.d.ts +1 -32
  129. package/dist/services/integration-api/struct/customer-config.js +3 -33
  130. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  131. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -27
  132. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -25
  133. package/dist/services/onboarding/dashboard/diff-against-current-page.d.ts +29 -7
  134. package/dist/services/onboarding/dashboard/diff-against-current-page.js +24 -37
  135. package/dist/services/onboarding/dashboard/index.js +13 -6
  136. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +21 -8
  137. package/dist/services/onboarding/dashboard/request-diff-service.js +21 -49
  138. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  139. package/dist/services/onboarding/onboarding-model.js +0 -1
  140. package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
  141. package/dist/services/onboarding/onboarding-service-factory.js +24 -30
  142. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.d.ts +1 -0
  143. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.js +57 -0
  144. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  145. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -3
  146. package/dist/services/onboarding/virtual-orestes-app/index.js +5 -5
  147. package/dist/services/origin-request/index.d.ts +3 -0
  148. package/dist/services/origin-request/index.js +3 -0
  149. package/dist/services/origin-request/origin-fetcher.d.ts +52 -0
  150. package/dist/services/origin-request/origin-fetcher.js +93 -0
  151. package/dist/services/origin-request/origin-request-service-build-context.d.ts +6 -3
  152. package/dist/services/origin-request/origin-request-service-build-context.js +30 -4
  153. package/dist/services/origin-request/origin-request-service-factory.d.ts +5 -0
  154. package/dist/services/origin-request/origin-request-service-factory.js +40 -6
  155. package/dist/services/origin-request/origin-request-service.d.ts +6 -10
  156. package/dist/services/origin-request/origin-request-service.js +28 -70
  157. package/dist/services/origin-request/runtime-config-source.d.ts +36 -0
  158. package/dist/services/origin-request/runtime-config-source.js +59 -0
  159. package/dist/services/origin-request/spec/origin-error-cause.spec.d.ts +1 -0
  160. package/dist/services/{onboarding/spec/virtual-orestes-app → origin-request/spec}/origin-error-cause.spec.js +1 -1
  161. package/dist/services/origin-request/spec/origin-fetcher.spec.d.ts +1 -0
  162. package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.js → origin-request/spec/origin-fetcher.spec.js} +46 -15
  163. package/dist/services/origin-request/spec/origin-request-service-build-context.spec.d.ts +1 -0
  164. package/dist/services/origin-request/spec/origin-request-service-build-context.spec.js +32 -0
  165. package/dist/services/prewarm/assets/asset-api-client.d.ts +6 -0
  166. package/dist/services/prewarm/assets/asset-api-client.js +6 -1
  167. package/dist/services/prewarm/pre-warm-service.d.ts +10 -0
  168. package/dist/services/prewarm/pre-warm-service.js +17 -0
  169. package/dist/services/prewarm/spec/pre-warm-service.spec.d.ts +1 -0
  170. package/dist/services/prewarm/spec/pre-warm-service.spec.js +72 -0
  171. package/dist/services/query-builder/query-builder-factory.js +3 -3
  172. package/dist/services/setup/os/tool-registry.d.ts +1 -1
  173. package/oclif.manifest.json +162 -23
  174. package/package.json +1 -2
  175. package/dist/commands/diff-url-parameters.d.ts +0 -19
  176. package/dist/commands/diff-url-parameters.js +0 -121
  177. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  178. package/dist/services/bundler/error/packjockel-error.js +0 -3
  179. package/dist/services/bundler/packjockel-service.d.ts +0 -72
  180. package/dist/services/bundler/packjockel-service.js +0 -156
  181. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -143
  182. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
  183. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
  184. package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
  185. package/dist/services/deploy/error/check-module-file-error.js +0 -4
  186. package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
  187. package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
  188. package/dist/services/onboarding/server-config/index.d.ts +0 -10
  189. package/dist/services/onboarding/server-config/index.js +0 -27
  190. package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +0 -31
  191. package/dist/services/onboarding/virtual-orestes-app/crawler.js +0 -98
  192. /package/dist/{services/bundler/spec/packjockel-service.spec.d.ts → helpers/spec/race.spec.d.ts} +0 -0
  193. /package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
  194. /package/dist/services/{onboarding/spec/virtual-orestes-app/origin-error-cause.spec.d.ts → deploy/spec/handler/install-resource-handler.spec.d.ts} +0 -0
  195. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.d.ts +0 -0
  196. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.js +0 -0
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A log that writes every line to stderr and leaves stdout to the JSON
3
+ * payload, so `sk diff --output json` can be piped into a parser.
4
+ */
5
+ export function stderrLog(cli) {
6
+ const note = (message) => cli.note(message);
7
+ return {
8
+ write: note,
9
+ writeError: note,
10
+ writeSuccess: note,
11
+ writeWarning: note,
12
+ comment: note,
13
+ spacer: () => cli.note(""),
14
+ startAction: () => undefined,
15
+ successAction: () => undefined,
16
+ failAction: () => undefined,
17
+ };
18
+ }
@@ -0,0 +1,68 @@
1
+ /** One side of a comparison: what it is called, and what it holds. */
2
+ export interface DiffSide {
3
+ /** Names the side in a diff tool's title or a patch header. */
4
+ readonly label: string;
5
+ readonly content: string;
6
+ /** Where the side came from, for a sink that reports it: url, status, … */
7
+ readonly details?: Readonly<Record<string, unknown>>;
8
+ }
9
+ /** The outcome of comparing two sides. */
10
+ export interface DiffResult {
11
+ /** Equal apart from whitespace. */
12
+ readonly equal: boolean;
13
+ readonly left: DiffSide;
14
+ /**
15
+ * The right side as it stands after the sink showed it: a diff tool may
16
+ * have edited it, so a deploy can take changes over from remote.
17
+ */
18
+ readonly right: DiffSide;
19
+ }
20
+ /** Why a side could not be built, as Speed Kit's server classifies it. */
21
+ export interface SideFailure {
22
+ /** The origin answered an error, or the documentHandler aborted or threw. */
23
+ readonly kind: "origin" | "documentHandlerAbort" | "documentHandlerError";
24
+ /** The Speed Kit error code: 109, 105, 104, 100, 303 or 314. */
25
+ readonly code: string;
26
+ /** The cause name the code resolves to, such as `OriginStatusNotFound`. */
27
+ readonly cause: string;
28
+ /** The origin's status, for an origin error. */
29
+ readonly status?: number;
30
+ /** The status text, or the message the documentHandler stopped with. */
31
+ readonly reason?: string;
32
+ }
33
+ /** A side that could not be built: what it would have been, and why not. */
34
+ export interface FailedSide {
35
+ readonly label: string;
36
+ readonly failure: SideFailure;
37
+ readonly details?: Readonly<Record<string, unknown>>;
38
+ }
39
+ /**
40
+ * How a comparison ended. `uncacheable` is a verdict: the documentHandler
41
+ * aborts a side, so Speed Kit never caches it and there is nothing to diff.
42
+ * `failed` means the sides could not be compared at all.
43
+ */
44
+ export type ComparisonOutcome = "equal" | "differs" | "uncacheable" | "failed";
45
+ /** A comparison that ended without a diff, because a side could not be built. */
46
+ export interface FailedComparison {
47
+ readonly outcome: Extract<ComparisonOutcome, "uncacheable" | "failed">;
48
+ readonly left: DiffSide | FailedSide;
49
+ readonly right: DiffSide | FailedSide;
50
+ }
51
+ /**
52
+ * Where a comparison goes: a diff tool, a patch on stdout, nowhere. The engine
53
+ * decides whether two sides are equal; the sink only shows the result, equal
54
+ * or not.
55
+ */
56
+ export interface DiffSink {
57
+ /**
58
+ * Shows one result. Resolves to the right side's content after showing it,
59
+ * when the sink lets a person edit it, and to undefined otherwise.
60
+ */
61
+ show(result: DiffResult): Promise<string | undefined>;
62
+ /** Records a comparison a side failed, for a sink that reports every one. */
63
+ fail?(comparison: FailedComparison): void;
64
+ /** Called once after the last result, for a sink that writes them together. */
65
+ finish?(): void;
66
+ }
67
+ /** How a comparison is shown; `--output` of `sk diff`. */
68
+ export type DiffOutput = "tool" | "patch" | "json" | "none";
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,104 @@
1
- import { CommandContextValues } from "../cli/index.js";
2
- export interface DiffServiceBuildContextValues extends CommandContextValues {
3
- /** The diff tool, `diffExec` in the settings; null when none is opened. */
4
- readonly executablePath: string | null;
5
- /** How the tool is called, `diffExecTemplate` in the settings. */
6
- readonly executableTemplate: string | null;
7
- /** A deploy that nobody drives never opens a diff tool. */
8
- readonly opensDiffTool?: boolean;
1
+ import { Interfaces } from "@oclif/core";
2
+ import { CliEnvironment, CommandContextValues } from "../cli/index.js";
3
+ import { DiffOutput } from "./diff-model.js";
4
+ declare const args: {
5
+ customerPath: Interfaces.Arg<string, {
6
+ exists?: boolean;
7
+ }>;
8
+ pageUrl: Interfaces.Arg<string, Record<string, unknown>>;
9
+ };
10
+ declare const flags: {
11
+ variations: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
12
+ against: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
13
+ variation: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
14
+ baseline: Interfaces.BooleanFlag<boolean>;
15
+ params: Interfaces.BooleanFlag<boolean>;
16
+ param: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
17
+ output: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
18
+ raw: Interfaces.BooleanFlag<boolean>;
19
+ ignore: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
20
+ browserFetch: Interfaces.BooleanFlag<boolean>;
21
+ host: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
22
+ variationsFile: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
23
+ hideDiff: Interfaces.BooleanFlag<boolean>;
24
+ configName: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
25
+ };
26
+ /** Two variations of a page, compared with each other: the left one first. */
27
+ export type VariationPair = readonly [left: string, right: string];
28
+ /**
29
+ * The pair `--variations` names: one variation against desktop, or two
30
+ * against each other. More than two is refused, rather than guessing which
31
+ * pairs were meant.
32
+ */
33
+ export declare function variationPair(names: readonly string[] | undefined): VariationPair | undefined;
34
+ /**
35
+ * The command line with an empty value after a bare `--param`,
36
+ * `--variation` or `--variations`, which oclif would refuse: given last, or before another
37
+ * flag, each asks which to take. A bare flag before the positional args
38
+ * takes the next one as its value, as any flag does.
39
+ */
40
+ export declare function withAskingFlags(argv: readonly string[]): string[];
41
+ /** What `sk diff` compares, and how it shows the result, as the service reads it. */
42
+ export interface DiffOptions {
43
+ /** Absent with `--raw` and no customer: no app, so no runtime config and no documentHandler. */
44
+ readonly customerPath?: string;
45
+ readonly configName: string;
46
+ readonly pageUrl: string;
47
+ /** The page {@link pageUrl} is compared with, in place of the parameter check. */
48
+ readonly against?: string;
49
+ /** The variation `against` and a parameter check without `variations` request. */
50
+ readonly variation: string;
51
+ /** Ask which variation to request the pages in, in place of {@link variation}. */
52
+ readonly chooseVariation?: boolean;
53
+ /** The two variations compared with each other; absent for a parameter check only. */
54
+ readonly variations?: VariationPair;
55
+ /** Ask which variations to compare, in place of {@link variations}. */
56
+ readonly chooseVariations?: boolean;
57
+ /** Fetch every side twice, and ignore what differs between the two. */
58
+ readonly baseline: boolean;
59
+ /** Check the query parameters also when variations are compared. */
60
+ readonly params: boolean;
61
+ /** The only parameters checked, all removed together; absent for every one on its own. */
62
+ readonly parameters?: readonly string[];
63
+ /** Ask which parameters to check, besides {@link parameters}. */
64
+ readonly chooseParameters?: boolean;
65
+ readonly output: DiffOutput;
66
+ /** Compare the origin's HTML without running the documentHandler. */
67
+ readonly raw: boolean;
68
+ /** Patterns removed from both sides before they are compared. */
69
+ readonly ignore: readonly string[];
70
+ readonly host?: string;
71
+ readonly variationsFile?: string;
72
+ /** Fetch through a headless Chrome instead of a direct request. */
73
+ readonly browserFetch: boolean;
74
+ }
75
+ export interface DiffServiceBuildContextValues extends CommandContextValues, DiffOptions {
9
76
  }
10
77
  declare const DiffServiceBuildContext_base: new (values: DiffServiceBuildContextValues) => Readonly<DiffServiceBuildContextValues>;
11
- /** How two contents are compared, and whether a person looks at the result. */
78
+ /** What a diff of one page is built from: `sk diff`'s args and flags. */
12
79
  export declare class DiffServiceBuildContext extends DiffServiceBuildContext_base {
80
+ static readonly args: {
81
+ customerPath: Interfaces.Arg<string, {
82
+ exists?: boolean;
83
+ }>;
84
+ pageUrl: Interfaces.Arg<string, Record<string, unknown>>;
85
+ };
86
+ static readonly flags: {
87
+ variations: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
88
+ against: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
89
+ variation: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
90
+ baseline: Interfaces.BooleanFlag<boolean>;
91
+ params: Interfaces.BooleanFlag<boolean>;
92
+ param: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
93
+ output: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
94
+ raw: Interfaces.BooleanFlag<boolean>;
95
+ ignore: Interfaces.OptionFlag<string[], Interfaces.CustomOptions>;
96
+ browserFetch: Interfaces.BooleanFlag<boolean>;
97
+ host: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
98
+ variationsFile: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
99
+ hideDiff: Interfaces.BooleanFlag<boolean>;
100
+ configName: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
101
+ };
102
+ static create(parsedArgs: Interfaces.InferredArgs<typeof args>, parsedFlags: Interfaces.InferredFlags<typeof flags>, environment: CliEnvironment): DiffServiceBuildContext;
13
103
  }
14
104
  export {};
@@ -1,4 +1,302 @@
1
+ import { Args, Flags } from "@oclif/core";
2
+ import { CLI_CONFIG_NAME, CLI_CUSTOMER_CONFIG, } from "../integration-api/customer-config-flags.js";
1
3
  import { Context } from "../../models/context.js";
2
- /** How two contents are compared, and whether a person looks at the result. */
4
+ import ApplicationError from "../error-handling/error/application-error.js";
5
+ import { DEFAULT_TYPE } from "../origin-request/index.js";
6
+ import { defaultDiffOutput } from "./create-diff-engine.js";
7
+ const OUTPUTS = ["tool", "patch", "json", "none"];
8
+ /** `desktop` is what a person calls the variation Speed Kit calls `default`. */
9
+ function variationName(name) {
10
+ const trimmed = name.trim();
11
+ return trimmed.toLowerCase() === "desktop" ? DEFAULT_TYPE : trimmed;
12
+ }
13
+ /** Whether an argument is a page rather than a customer directory. */
14
+ function isUrl(value) {
15
+ return /^https?:\/\//i.test(value ?? "");
16
+ }
17
+ const args = {
18
+ customerPath: Args.directory({
19
+ ...CLI_CUSTOMER_CONFIG.customerPath,
20
+ required: false,
21
+ description: "The customer config path; optional with --raw, which then compares the origin's HTML with Speed Kit's device defaults",
22
+ }),
23
+ pageUrl: Args.string({
24
+ name: "pageUrl",
25
+ required: false,
26
+ description: "The page to diff, with the query parameters to check, or the first page of an --against comparison",
27
+ example: "https://www.decathlon.de/?sort=price",
28
+ }),
29
+ };
30
+ const flags = {
31
+ ...CLI_CONFIG_NAME,
32
+ variations: Flags.string({
33
+ multiple: true,
34
+ delimiter: ",",
35
+ description: "One variation to compare against desktop, or two to compare with each other: mobile, or tablet,mobile. A custom variation works too; an empty one asks which",
36
+ }),
37
+ against: Flags.string({
38
+ description: "Compare the page against this other page, both requested and rendered the same way: ?color=red against ?color=blue. Replaces the parameter check",
39
+ }),
40
+ variation: Flags.string({
41
+ description: "The one variation the pages are requested in, for --against or the parameter check: mobile, tablet or a custom one; an empty one asks which. Defaults to desktop",
42
+ }),
43
+ baseline: Flags.boolean({
44
+ description: "Fetch every side twice and ignore what differs between the two, such as nonces, timestamps or reordered preloads. Doubles the requests: 4 per comparison",
45
+ }),
46
+ params: Flags.boolean({
47
+ description: "With --variations, also check the query parameters, once for each of the two variations. Without --variations it is what sk diff does",
48
+ }),
49
+ param: Flags.string({
50
+ multiple: true,
51
+ description: "Check only this query parameter of the url: sort. Several, as sort,page or repeated, are removed together; an empty one asks which. Implies --params with --variations",
52
+ }),
53
+ output: Flags.string({
54
+ char: "o",
55
+ options: OUTPUTS,
56
+ description: "How a diff is shown: the diff tool, a unified patch, JSON, or only the verdict. Defaults to the tool at a terminal and to a patch otherwise",
57
+ }),
58
+ raw: Flags.boolean({
59
+ description: "Compare the origin's HTML as it is, without running the customer's documentHandler",
60
+ }),
61
+ ignore: Flags.string({
62
+ multiple: true,
63
+ description: "Remove what this regex matches from both sides before comparing, e.g. a nonce or a timestamp",
64
+ }),
65
+ browserFetch: Flags.boolean({
66
+ description: "Fetch every page through a headless Chrome, for an origin whose bot protection refuses a direct request. Needs the customer path",
67
+ }),
68
+ host: Flags.string({
69
+ description: "Send this Host header, emulating an origin-map host override",
70
+ }),
71
+ variationsFile: Flags.string({
72
+ description: "Resolve the requests against a runtime config in a local file instead of the app's deployed one",
73
+ }),
74
+ hideDiff: Flags.boolean({
75
+ char: "h",
76
+ hidden: true,
77
+ deprecated: { to: "output" },
78
+ description: "Show no diff; the same as --output none",
79
+ }),
80
+ };
81
+ /**
82
+ * The pair `--variations` names: one variation against desktop, or two
83
+ * against each other. More than two is refused, rather than guessing which
84
+ * pairs were meant.
85
+ */
86
+ export function variationPair(names) {
87
+ const variations = (names ?? []).map(variationName).filter(Boolean);
88
+ if (variations.length === 0)
89
+ return undefined;
90
+ if (variations.length > 2) {
91
+ throw new ApplicationError(`--variations compares two variations, not ${variations.length}.`, [
92
+ "One against desktop: --variations mobile",
93
+ "Two with each other: --variations tablet,mobile",
94
+ ]);
95
+ }
96
+ const [left, right] = variations.length === 1 ? [DEFAULT_TYPE, variations[0]] : variations;
97
+ if (left === right) {
98
+ throw new ApplicationError(`--variations compares ${left} with itself.`, [
99
+ "Name another variation; desktop is Speed Kit's default.",
100
+ ]);
101
+ }
102
+ return [left, right];
103
+ }
104
+ /**
105
+ * The page `--against` compares the page with. It replaces the parameter
106
+ * check and the variation pair, so the flags of those are refused next to it.
107
+ */
108
+ function againstUrl(pageUrl, parsedFlags) {
109
+ const { against } = parsedFlags;
110
+ if (against === undefined)
111
+ return undefined;
112
+ if (!isUrl(against)) {
113
+ throw new ApplicationError(`--against takes a page url, not "${against}".`);
114
+ }
115
+ if (new URL(against).href === new URL(pageUrl).href) {
116
+ throw new ApplicationError("--against compares the page with itself.", [
117
+ 'Name another url: --against "https://www.example.com/?color=blue"',
118
+ ]);
119
+ }
120
+ const conflicting = [
121
+ parsedFlags.param !== undefined && "--param",
122
+ parsedFlags.params && "--params",
123
+ parsedFlags.variations !== undefined && "--variations",
124
+ ].filter(Boolean);
125
+ if (conflicting.length > 0) {
126
+ throw new ApplicationError(`--against compares two pages, so it does not take ${conflicting.join(", ")}.`, parsedFlags.variations === undefined
127
+ ? undefined
128
+ : ["For another variation than desktop, name one: --variation mobile"]);
129
+ }
130
+ return against;
131
+ }
132
+ /**
133
+ * The one variation `--variation` names, desktop by default, or before an
134
+ * empty one is answered. `--variations` compares a pair, so the two are
135
+ * refused together.
136
+ */
137
+ function singleVariation(parsedFlags) {
138
+ if (parsedFlags.variation === undefined)
139
+ return DEFAULT_TYPE;
140
+ if (parsedFlags.variations !== undefined) {
141
+ throw new ApplicationError("--variation names the one variation pages are requested in, --variations a pair to compare: pass one of them.");
142
+ }
143
+ return variationName(parsedFlags.variation) || DEFAULT_TYPE;
144
+ }
145
+ /**
146
+ * Whether an empty `--variation` asks which variation to request the pages
147
+ * in. Only a person at a terminal can answer.
148
+ */
149
+ function choosesVariation(value, environment) {
150
+ if (value === undefined || value.trim() !== "")
151
+ return false;
152
+ if (environment.nonInteractive) {
153
+ throw new ApplicationError("An empty --variation asks which variation to request the pages in, and this run cannot ask.", ["Name it: --variation mobile"]);
154
+ }
155
+ return true;
156
+ }
157
+ /** The parameters a `--param` value names. */
158
+ function parameterNames(value) {
159
+ return value
160
+ .split(",")
161
+ .map((name) => name.trim())
162
+ .filter(Boolean);
163
+ }
164
+ /**
165
+ * The parameters `--param` selects, from every flag and comma-separated
166
+ * name, each once. The url must carry each of them: a name it lacks would be
167
+ * checked as a removal that removes nothing.
168
+ */
169
+ function selectedParameters(pageUrl, values) {
170
+ const sole = urlParameters(pageUrl);
171
+ const selected = [
172
+ ...new Set([
173
+ ...(values ?? []).flatMap(parameterNames),
174
+ // An empty --param takes a url's only parameter without asking.
175
+ ...(asksForParameters(values) && sole.length === 1 ? sole : []),
176
+ ]),
177
+ ];
178
+ if (selected.length === 0)
179
+ return undefined;
180
+ const present = new Set(sole);
181
+ const missing = selected.filter((name) => !present.has(name));
182
+ if (missing.length > 0) {
183
+ throw new ApplicationError(`${pageUrl} has no parameter ${missing.map((name) => `"${name}"`).join(", ")}.`, [
184
+ present.size > 0
185
+ ? `Its parameters: ${[...present].join(", ")}`
186
+ : "The url has no query parameters.",
187
+ ]);
188
+ }
189
+ return selected;
190
+ }
191
+ /** Whether a `--param` names nothing: it asks which parameters to take. */
192
+ function asksForParameters(values) {
193
+ return (values ?? []).some((value) => parameterNames(value).length === 0);
194
+ }
195
+ /** The url's query parameters, each once. */
196
+ function urlParameters(pageUrl) {
197
+ return [...new Set(new URL(pageUrl).searchParams.keys())];
198
+ }
199
+ /**
200
+ * Whether an empty `--param` asks which parameters to check. A url with a
201
+ * single parameter leaves nothing to choose: that one is taken without
202
+ * asking. Otherwise only a person at a terminal can answer.
203
+ */
204
+ function choosesParameters(pageUrl, values, environment) {
205
+ if (!asksForParameters(values))
206
+ return false;
207
+ const parameters = urlParameters(pageUrl);
208
+ if (parameters.length === 0) {
209
+ throw new ApplicationError(`${pageUrl} has no query parameters to choose from.`);
210
+ }
211
+ if (parameters.length === 1)
212
+ return false;
213
+ if (environment.nonInteractive) {
214
+ throw new ApplicationError("An empty --param asks which parameters to check, and this run cannot ask.", ["Name the parameter: --param sort"]);
215
+ }
216
+ return true;
217
+ }
218
+ /**
219
+ * Whether an empty `--variations` asks which variations to compare. Only a
220
+ * person at a terminal can answer.
221
+ */
222
+ function choosesVariations(values, environment) {
223
+ if (!(values ?? []).some((value) => value.trim() === ""))
224
+ return false;
225
+ if (environment.nonInteractive) {
226
+ throw new ApplicationError("An empty --variations asks which variations to compare, and this run cannot ask.", ["Name them: --variations mobile, or --variations tablet,mobile"]);
227
+ }
228
+ return true;
229
+ }
230
+ /** The flags that ask when they are given without a value. */
231
+ const ASKING_FLAGS = new Set(["--param", "--variation", "--variations"]);
232
+ /**
233
+ * The command line with an empty value after a bare `--param`,
234
+ * `--variation` or `--variations`, which oclif would refuse: given last, or before another
235
+ * flag, each asks which to take. A bare flag before the positional args
236
+ * takes the next one as its value, as any flag does.
237
+ */
238
+ export function withAskingFlags(argv) {
239
+ return argv.flatMap((argument, index) => {
240
+ const next = argv[index + 1];
241
+ const bare = ASKING_FLAGS.has(argument) &&
242
+ (next === undefined || next.startsWith("-"));
243
+ return bare ? [argument, ""] : [argument];
244
+ });
245
+ }
246
+ /** What a diff of one page is built from: `sk diff`'s args and flags. */
3
247
  export class DiffServiceBuildContext extends Context() {
248
+ static args = args;
249
+ static flags = flags;
250
+ static create(parsedArgs, parsedFlags, environment) {
251
+ const output = parsedFlags.hideDiff
252
+ ? "none"
253
+ : (parsedFlags.output ?? defaultDiffOutput(environment));
254
+ // `sk diff --raw <url>`: a lone url is the page, not a customer directory.
255
+ const [customerPath, pageUrl] = isUrl(parsedArgs.customerPath)
256
+ ? [undefined, parsedArgs.customerPath]
257
+ : [parsedArgs.customerPath, parsedArgs.pageUrl];
258
+ if (!pageUrl) {
259
+ throw new ApplicationError("sk diff needs the page to diff.", [
260
+ "sk diff <customerPath> <pageUrl>, or sk diff --raw <pageUrl>",
261
+ ]);
262
+ }
263
+ if (!customerPath && parsedFlags.browserFetch) {
264
+ throw new ApplicationError("--browserFetch needs the customer path.", [
265
+ "sk diff <customerPath> <pageUrl> --browserFetch",
266
+ ]);
267
+ }
268
+ if (!customerPath && !parsedFlags.raw) {
269
+ throw new ApplicationError("Without a customer path there is no documentHandler to render with.", ["Name the customer, or pass --raw to compare the origin's HTML."]);
270
+ }
271
+ const against = againstUrl(pageUrl, parsedFlags);
272
+ const variation = singleVariation(parsedFlags);
273
+ const chooseVariation = choosesVariation(parsedFlags.variation, environment);
274
+ const chooseVariations = choosesVariations(parsedFlags.variations, environment);
275
+ const parameters = selectedParameters(pageUrl, parsedFlags.param);
276
+ const chooseParameters = choosesParameters(pageUrl, parsedFlags.param, environment);
277
+ return new DiffServiceBuildContext({
278
+ environment,
279
+ customerPath,
280
+ configName: parsedFlags.configName,
281
+ pageUrl,
282
+ against,
283
+ variation,
284
+ chooseVariation,
285
+ variations: chooseVariations
286
+ ? undefined
287
+ : variationPair(parsedFlags.variations),
288
+ chooseVariations,
289
+ baseline: parsedFlags.baseline,
290
+ params: parsedFlags.params || parameters !== undefined || chooseParameters,
291
+ parameters,
292
+ chooseParameters,
293
+ output,
294
+ raw: parsedFlags.raw,
295
+ ignore: parsedFlags.ignore ?? [],
296
+ host: parsedFlags.host,
297
+ variationsFile: parsedFlags.variationsFile,
298
+ browserFetch: parsedFlags.browserFetch,
299
+ });
300
+ }
4
301
  }
302
+ DiffServiceBuildContext;
@@ -2,7 +2,29 @@ import { DiffServiceBuildContext } from "./diff-service-build-context.js";
2
2
  import { DiffService } from "./diff-service.js";
3
3
  export declare class DiffServiceFactory {
4
4
  private readonly context;
5
- service?: DiffService;
5
+ private service?;
6
6
  constructor(context: DiffServiceBuildContext);
7
- getService(): DiffService;
7
+ buildService(): Promise<DiffService>;
8
+ private build;
9
+ /**
10
+ * The options, with the parameters an empty `--param` asked for added to
11
+ * the ones removed. Asked first, before anything is loaded or fetched.
12
+ */
13
+ private withChosenParameters;
14
+ /**
15
+ * The options, with the variations an empty `--variations` or
16
+ * `--variation` asked for.
17
+ */
18
+ private withChosenVariations;
19
+ /** The one variation an empty `--variation` asks for. */
20
+ private chooseVariation;
21
+ /**
22
+ * The runtime config: a local file when one is named, else the app's. Without
23
+ * a customer there is no app, and the requests carry Speed Kit's device
24
+ * defaults only.
25
+ */
26
+ private loadRuntimeConfig;
27
+ /** The customer's files, with the released document handler unless it brings its own. */
28
+ private getIntegrationFiles;
29
+ private buildDocumentHandler;
8
30
  }