@speedkit/cli 4.44.0-beta.3 → 4.44.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.
Files changed (189) hide show
  1. package/CHANGELOG.md +38 -8
  2. package/README.md +68 -42
  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/helpers/race.js +4 -2
  11. package/dist/helpers/spec/race.spec.js +31 -0
  12. package/dist/models/files.d.ts +0 -1
  13. package/dist/models/files.js +0 -1
  14. package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
  15. package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +1 -7
  16. package/dist/services/browser-fetch/browser-origin-fetcher.js +3 -26
  17. package/dist/services/bundler/bundle-service-factory.d.ts +0 -3
  18. package/dist/services/bundler/bundle-service-factory.js +1 -5
  19. package/dist/services/bundler/bundle-service.d.ts +1 -10
  20. package/dist/services/bundler/bundle-service.js +1 -16
  21. package/dist/services/bundler/index.d.ts +0 -1
  22. package/dist/services/bundler/index.js +0 -1
  23. package/dist/services/cli/cli-environment.d.ts +11 -0
  24. package/dist/services/cli/cli-environment.js +37 -0
  25. package/dist/services/cli/cli-service-model.d.ts +3 -1
  26. package/dist/services/cli/cli-service.d.ts +1 -1
  27. package/dist/services/cli/cli-service.js +4 -1
  28. package/dist/services/cli/spec/cli-environment.spec.js +30 -1
  29. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  30. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
  31. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
  32. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
  33. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
  34. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
  35. package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
  36. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  37. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  38. package/dist/services/deploy/deploy-service-build-context.d.ts +2 -0
  39. package/dist/services/deploy/deploy-service-build-context.js +13 -2
  40. package/dist/services/deploy/deploy-service-factory.js +2 -9
  41. package/dist/services/deploy/deploy-service-model.d.ts +11 -1
  42. package/dist/services/deploy/deploy-service.d.ts +2 -0
  43. package/dist/services/deploy/deploy-service.js +26 -1
  44. package/dist/services/deploy/handler/customer-config-handler.d.ts +2 -2
  45. package/dist/services/deploy/handler/install-resource-handler.d.ts +2 -2
  46. package/dist/services/deploy/handler/install-resource-handler.js +6 -3
  47. package/dist/services/deploy/handler/module-handler.d.ts +2 -2
  48. package/dist/services/deploy/handler/module-handler.js +2 -2
  49. package/dist/services/deploy/handler/server-config-handler.d.ts +2 -2
  50. package/dist/services/deploy/handler/server-config-handler.js +2 -2
  51. package/dist/services/deploy/mr/live-state-check.d.ts +2 -2
  52. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +2 -7
  53. package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
  54. package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
  55. package/dist/services/deploy/policy/index.d.ts +1 -0
  56. package/dist/services/deploy/policy/index.js +1 -0
  57. package/dist/services/deploy/policy/testing-deploy-policy.d.ts +16 -0
  58. package/dist/services/deploy/policy/testing-deploy-policy.js +42 -0
  59. package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
  60. package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
  61. package/dist/services/deploy/spec/handler/install-resource-handler.spec.js +58 -0
  62. package/dist/services/deploy/spec/mr/live-state-check.spec.js +2 -2
  63. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
  64. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.d.ts +1 -0
  65. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +46 -0
  66. package/dist/services/diff/create-diff-engine.d.ts +14 -0
  67. package/dist/services/diff/create-diff-engine.js +42 -0
  68. package/dist/services/diff/customer-origin.d.ts +9 -0
  69. package/dist/services/diff/customer-origin.js +19 -0
  70. package/dist/services/diff/diff-engine.d.ts +30 -0
  71. package/dist/services/diff/diff-engine.js +49 -0
  72. package/dist/services/diff/diff-log.d.ts +9 -0
  73. package/dist/services/diff/diff-log.js +18 -0
  74. package/dist/services/diff/diff-model.d.ts +68 -0
  75. package/dist/services/diff/diff-model.js +1 -0
  76. package/dist/services/diff/diff-service-build-context.d.ts +99 -9
  77. package/dist/services/diff/diff-service-build-context.js +299 -1
  78. package/dist/services/diff/diff-service-factory.d.ts +24 -2
  79. package/dist/services/diff/diff-service-factory.js +165 -3
  80. package/dist/services/diff/diff-service.d.ts +93 -33
  81. package/dist/services/diff/diff-service.js +274 -140
  82. package/dist/services/diff/index.d.ts +12 -1
  83. package/dist/services/diff/index.js +12 -1
  84. package/dist/services/diff/noise-baseline.d.ts +28 -0
  85. package/dist/services/diff/noise-baseline.js +105 -0
  86. package/dist/services/diff/page-source.d.ts +42 -0
  87. package/dist/services/diff/page-source.js +93 -0
  88. package/dist/services/diff/side-failure.d.ts +28 -0
  89. package/dist/services/diff/side-failure.js +100 -0
  90. package/dist/services/diff/sinks/json-diff-sink.d.ts +32 -0
  91. package/dist/services/diff/sinks/json-diff-sink.js +44 -0
  92. package/dist/services/diff/sinks/no-diff-sink.d.ts +5 -0
  93. package/dist/services/diff/sinks/no-diff-sink.js +6 -0
  94. package/dist/services/diff/sinks/patch-diff-sink.d.ts +19 -0
  95. package/dist/services/diff/sinks/patch-diff-sink.js +29 -0
  96. package/dist/services/diff/sinks/tool-diff-sink.d.ts +26 -0
  97. package/dist/services/diff/sinks/tool-diff-sink.js +88 -0
  98. package/dist/services/diff/sinks/unified-patch.d.ts +7 -0
  99. package/dist/services/diff/sinks/unified-patch.js +12 -0
  100. package/dist/services/diff/spec/customer-origin.spec.d.ts +1 -0
  101. package/dist/services/diff/spec/customer-origin.spec.js +27 -0
  102. package/dist/services/diff/spec/diff-engine.spec.d.ts +1 -0
  103. package/dist/services/diff/spec/diff-engine.spec.js +47 -0
  104. package/dist/services/diff/spec/diff-service-build-context.spec.d.ts +1 -0
  105. package/dist/services/diff/spec/diff-service-build-context.spec.js +185 -0
  106. package/dist/services/diff/spec/diff-service.spec.d.ts +1 -0
  107. package/dist/services/diff/spec/diff-service.spec.js +393 -0
  108. package/dist/services/diff/spec/noise-baseline.spec.d.ts +1 -0
  109. package/dist/services/diff/spec/noise-baseline.spec.js +95 -0
  110. package/dist/services/diff/spec/page-source.spec.d.ts +1 -0
  111. package/dist/services/diff/spec/page-source.spec.js +140 -0
  112. package/dist/services/diff/spec/sinks/json-diff-sink.spec.d.ts +1 -0
  113. package/dist/services/diff/spec/sinks/json-diff-sink.spec.js +72 -0
  114. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.d.ts +1 -0
  115. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.js +47 -0
  116. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.d.ts +1 -0
  117. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.js +61 -0
  118. package/dist/services/document-handler-runtime/document-handler-abort.d.ts +2 -0
  119. package/dist/services/document-handler-runtime/document-handler-abort.js +2 -0
  120. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  121. package/dist/services/document-handler-runtime/document-handler-server.js +19 -81
  122. package/dist/services/document-handler-runtime/runtime-files.d.ts +9 -0
  123. package/dist/services/document-handler-runtime/runtime-files.js +17 -0
  124. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  125. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -68
  126. package/dist/services/integration-api/struct/customer-config.d.ts +1 -32
  127. package/dist/services/integration-api/struct/customer-config.js +3 -33
  128. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  129. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -27
  130. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -20
  131. package/dist/services/onboarding/dashboard/diff-against-current-page.d.ts +29 -7
  132. package/dist/services/onboarding/dashboard/diff-against-current-page.js +24 -37
  133. package/dist/services/onboarding/dashboard/index.js +13 -6
  134. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +21 -8
  135. package/dist/services/onboarding/dashboard/request-diff-service.js +21 -49
  136. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  137. package/dist/services/onboarding/onboarding-model.js +0 -1
  138. package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
  139. package/dist/services/onboarding/onboarding-service-factory.js +24 -30
  140. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.d.ts +1 -0
  141. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.js +57 -0
  142. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  143. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -3
  144. package/dist/services/onboarding/virtual-orestes-app/index.js +5 -5
  145. package/dist/services/origin-request/index.d.ts +3 -0
  146. package/dist/services/origin-request/index.js +3 -0
  147. package/dist/services/origin-request/origin-fetcher.d.ts +52 -0
  148. package/dist/services/origin-request/origin-fetcher.js +93 -0
  149. package/dist/services/origin-request/origin-request-service-factory.js +19 -1
  150. package/dist/services/origin-request/origin-request-service.d.ts +6 -10
  151. package/dist/services/origin-request/origin-request-service.js +28 -70
  152. package/dist/services/origin-request/runtime-config-source.d.ts +36 -0
  153. package/dist/services/origin-request/runtime-config-source.js +59 -0
  154. package/dist/services/origin-request/spec/origin-error-cause.spec.d.ts +1 -0
  155. package/dist/services/{onboarding/spec/virtual-orestes-app → origin-request/spec}/origin-error-cause.spec.js +1 -1
  156. package/dist/services/origin-request/spec/origin-fetcher.spec.d.ts +1 -0
  157. package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.js → origin-request/spec/origin-fetcher.spec.js} +46 -15
  158. package/dist/services/prewarm/assets/asset-api-client.d.ts +6 -0
  159. package/dist/services/prewarm/assets/asset-api-client.js +6 -1
  160. package/dist/services/prewarm/pre-warm-service.d.ts +10 -0
  161. package/dist/services/prewarm/pre-warm-service.js +17 -0
  162. package/dist/services/prewarm/spec/pre-warm-service.spec.d.ts +1 -0
  163. package/dist/services/prewarm/spec/pre-warm-service.spec.js +72 -0
  164. package/dist/services/query-builder/query-builder-factory.js +3 -3
  165. package/dist/services/setup/os/tool-registry.d.ts +1 -1
  166. package/oclif.manifest.json +294 -162
  167. package/package.json +1 -2
  168. package/dist/commands/diff-url-parameters.d.ts +0 -19
  169. package/dist/commands/diff-url-parameters.js +0 -121
  170. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  171. package/dist/services/bundler/error/packjockel-error.js +0 -3
  172. package/dist/services/bundler/packjockel-service.d.ts +0 -72
  173. package/dist/services/bundler/packjockel-service.js +0 -156
  174. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -143
  175. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
  176. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
  177. package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
  178. package/dist/services/deploy/error/check-module-file-error.js +0 -4
  179. package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
  180. package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
  181. package/dist/services/onboarding/server-config/index.d.ts +0 -10
  182. package/dist/services/onboarding/server-config/index.js +0 -27
  183. package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +0 -31
  184. package/dist/services/onboarding/virtual-orestes-app/crawler.js +0 -98
  185. /package/dist/{services/bundler/spec/packjockel-service.spec.d.ts → helpers/spec/race.spec.d.ts} +0 -0
  186. /package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
  187. /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
  188. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.d.ts +0 -0
  189. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.js +0 -0
@@ -1,72 +0,0 @@
1
- /**
2
- * The tags of the Speed Kit assets that packjockel bundles, each a version such as `1.8.0` or a channel
3
- * such as `@release`. packjockel takes `latest` for a tag that is not set. The names are the client
4
- * config keys of packjockel.
5
- */
6
- export interface AssetVersions {
7
- /** Speed Kit: snippet, service worker and dynamic fetcher */
8
- speedKitVersion?: string;
9
- rumPluginVersion?: string;
10
- /** predictive preloading */
11
- ppVersion?: string;
12
- configPluginsVersion?: string;
13
- documentHandlerVersion?: string;
14
- }
15
- export interface PackjockelBundleRequest {
16
- /** The entry points by file name, in output order. */
17
- entryPoints: Record<string, string>;
18
- versions?: AssetVersions;
19
- define?: Record<string, string>;
20
- platform?: "browser" | "node";
21
- target?: "es5" | "es6";
22
- minify?: boolean;
23
- }
24
- export interface PackjockelDocumentHandlerRequest {
25
- /** The document handler library; without it packjockel bundles the published one of `documentHandlerVersion`. */
26
- documentHandler?: string;
27
- documentHandlerConfig: string;
28
- speedKitConfig: string;
29
- appName: string;
30
- dynamicFetcher?: string;
31
- dynamicFetcherConfig?: string;
32
- customStyle?: string;
33
- versions?: AssetVersions;
34
- }
35
- /**
36
- * Bundles with the packjockel binary in embedded mode, so no packjockel server is needed.
37
- *
38
- * Every input goes to the binary as a file, because a document handler is too large for one
39
- * command line argument.
40
- */
41
- export declare class PackjockelService {
42
- private readonly resolveBinary;
43
- /**
44
- * @param resolveBinary returns the packjockel binary; it runs only when a bundle is needed, so
45
- * a platform without a packjockel package fails only for the `enableSpeedKitConfigPlugins` feature
46
- */
47
- constructor(resolveBinary?: () => string);
48
- /**
49
- * Bundles the entry points in their order into one script. packjockel puts a script before them
50
- * which exposes the `SpeedKit` global.
51
- *
52
- * @returns the bundled code
53
- */
54
- bundle(request: PackjockelBundleRequest): Promise<string>;
55
- /**
56
- * Bundles a document handler with its config, the embedded Speed Kit config and the default `post`.
57
- *
58
- * @returns the code of one CommonJS module, which exports `post`
59
- */
60
- bundleDocumentHandler(request: PackjockelDocumentHandlerRequest): Promise<string>;
61
- /**
62
- * Runs packjockel in a scratch directory, which is removed afterwards.
63
- *
64
- * @param buildArgs writes the inputs into the directory and returns the arguments that read them
65
- */
66
- private run;
67
- /**
68
- * Runs the binary without stdin: packjockel reads a piped stdin as the document handler, and only
69
- * without input it bundles the published one.
70
- */
71
- private execute;
72
- }
@@ -1,156 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { binaryPath } from "@speedkit/packjockel";
6
- import { PackjockelError } from "./error/packjockel-error.js";
7
- const VERSION_FLAGS = {
8
- speedKitVersion: "--speed-kit-version",
9
- rumPluginVersion: "--rum-plugin-version",
10
- ppVersion: "--pp-version",
11
- configPluginsVersion: "--config-plugins-version",
12
- documentHandlerVersion: "--document-handler-version",
13
- };
14
- /**
15
- * Bundles with the packjockel binary in embedded mode, so no packjockel server is needed.
16
- *
17
- * Every input goes to the binary as a file, because a document handler is too large for one
18
- * command line argument.
19
- */
20
- export class PackjockelService {
21
- resolveBinary;
22
- /**
23
- * @param resolveBinary returns the packjockel binary; it runs only when a bundle is needed, so
24
- * a platform without a packjockel package fails only for the `enableSpeedKitConfigPlugins` feature
25
- */
26
- constructor(resolveBinary = binaryPath) {
27
- this.resolveBinary = resolveBinary;
28
- }
29
- /**
30
- * Bundles the entry points in their order into one script. packjockel puts a script before them
31
- * which exposes the `SpeedKit` global.
32
- *
33
- * @returns the bundled code
34
- */
35
- async bundle(request) {
36
- return this.run(async (directory) => {
37
- const args = [
38
- "bundle",
39
- "--bundle",
40
- `--platform=${request.platform ?? "browser"}`,
41
- `--target=${request.target ?? "es5"}`,
42
- ];
43
- if (request.minify) {
44
- args.push("--minify");
45
- }
46
- args.push(...keyValueFlags("--define", request.define));
47
- for (const [name, code] of Object.entries(request.entryPoints)) {
48
- args.push(await writeInput(directory, name, code));
49
- }
50
- return args;
51
- }, request.versions);
52
- }
53
- /**
54
- * Bundles a document handler with its config, the embedded Speed Kit config and the default `post`.
55
- *
56
- * @returns the code of one CommonJS module, which exports `post`
57
- */
58
- async bundleDocumentHandler(request) {
59
- return this.run(async (directory) => {
60
- const args = ["bundle", "document-handler"];
61
- if (request.documentHandler !== undefined) {
62
- args.push(await writeInput(directory, "DocumentHandler.js", request.documentHandler));
63
- }
64
- args.push(`--document-handler-config=${await writeInput(directory, "documentHandlerConfig.js", request.documentHandlerConfig)}`, `--speed-kit-config=${await writeInput(directory, "speedKitConfig.js", request.speedKitConfig)}`, `--app-name=${request.appName}`);
65
- const optional = {
66
- "dynamic-fetcher": ["dynamicFetcher.js", request.dynamicFetcher],
67
- "dynamic-fetcher-config": [
68
- "dynamicFetcherConfig.js",
69
- request.dynamicFetcherConfig,
70
- ],
71
- "custom-style": ["customStyle.css", request.customStyle],
72
- };
73
- for (const [flag, [name, value]] of Object.entries(optional)) {
74
- if (value) {
75
- args.push(`--${flag}=${await writeInput(directory, name, value)}`);
76
- }
77
- }
78
- return args;
79
- }, request.versions);
80
- }
81
- /**
82
- * Runs packjockel in a scratch directory, which is removed afterwards.
83
- *
84
- * @param buildArgs writes the inputs into the directory and returns the arguments that read them
85
- */
86
- async run(buildArgs, versions = {}) {
87
- const directory = await mkdtemp(join(tmpdir(), "sk-packjockel-"));
88
- try {
89
- const output = join(directory, "out.js");
90
- const args = [
91
- ...(await buildArgs(directory)),
92
- ...versionFlags(versions),
93
- "--embedded",
94
- `--output=${output}`,
95
- ];
96
- await this.execute(args);
97
- return await readFile(output, "utf8");
98
- }
99
- finally {
100
- await rm(directory, { recursive: true, force: true });
101
- }
102
- }
103
- /**
104
- * Runs the binary without stdin: packjockel reads a piped stdin as the document handler, and only
105
- * without input it bundles the published one.
106
- */
107
- execute(args) {
108
- let binary;
109
- try {
110
- binary = this.resolveBinary();
111
- }
112
- catch (error) {
113
- return Promise.reject(new PackjockelError(error.message));
114
- }
115
- return new Promise((resolve, reject) => {
116
- const child = spawn(binary, args, {
117
- stdio: ["ignore", "ignore", "pipe"],
118
- });
119
- let stderr = "";
120
- child.stderr.on("data", (chunk) => (stderr += chunk));
121
- child.on("error", (error) => reject(new PackjockelError(`packjockel failed: ${error.message}`)));
122
- child.on("close", (code) => {
123
- if (code === 0) {
124
- resolve();
125
- }
126
- else {
127
- reject(new PackjockelError(`packjockel failed: ${withoutLogLines(stderr) || `exit code ${code}`}`));
128
- }
129
- });
130
- });
131
- }
132
- }
133
- /** Writes one input into the scratch directory and returns the `file://` value that reads it. */
134
- async function writeInput(directory, name, content) {
135
- const path = join(directory, name);
136
- await writeFile(path, content);
137
- return `file://${path}`;
138
- }
139
- /** The flags of the tags that are set. */
140
- function versionFlags(versions) {
141
- return Object.entries(VERSION_FLAGS)
142
- .filter(([key]) => versions[key])
143
- .map(([key, flag]) => `${flag}=${versions[key]}`);
144
- }
145
- function keyValueFlags(flag, values = {}) {
146
- return Object.entries(values).map(([key, value]) => `${flag}=${key}=${value}`);
147
- }
148
- /** packjockel and its cache log to stderr as well; the error is in the remaining lines. */
149
- function withoutLogLines(stderr = "") {
150
- return stderr
151
- .split("\n")
152
- .filter((line) => line.trim() &&
153
- !line.startsWith("time=") &&
154
- !/^\d{4}\/\d{2}\/\d{2} /.test(line))
155
- .join("\n");
156
- }
@@ -1,143 +0,0 @@
1
- import { expect } from "chai";
2
- import { afterEach, beforeEach, describe, it } from "mocha";
3
- import { chmod, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
- import { existsSync } from "node:fs";
5
- import { tmpdir } from "node:os";
6
- import { join } from "node:path";
7
- import { PackjockelService } from "../packjockel-service.js";
8
- import { PackjockelError } from "../error/packjockel-error.js";
9
- /**
10
- * A packjockel stand-in: it records its arguments, the content of every `file://` input and a
11
- * piped stdin, and writes a fixed bundle to `--output`.
12
- */
13
- const FAKE_PACKJOCKEL = `#!/bin/sh
14
- if [ -p /dev/stdin ] || [ -f /dev/stdin ]; then
15
- echo "piped" > "$RECORD_DIR/stdin"
16
- fi
17
- out=""
18
- for arg in "$@"; do
19
- echo "$arg" >> "$RECORD_DIR/args"
20
- case "$arg" in
21
- --output=*) out="\${arg#--output=}" ;;
22
- esac
23
- path=$(echo "$arg" | sed -n 's|.*file://||p')
24
- if [ -n "$path" ]; then
25
- echo "$(basename "$path"): $(cat "$path")" >> "$RECORD_DIR/inputs"
26
- fi
27
- done
28
- if [ -n "$FAIL" ]; then
29
- echo "time=\\"2026\\" level=info msg=starting" >&2
30
- echo "invalid bundle: could not resolve x" >&2
31
- exit 1
32
- fi
33
- echo "bundled" > "$out"
34
- `;
35
- describe("PackjockelService", () => {
36
- let directory;
37
- let service;
38
- beforeEach(async () => {
39
- directory = await mkdtemp(join(tmpdir(), "packjockel-spec-"));
40
- const binary = join(directory, "packjockel");
41
- await writeFile(binary, FAKE_PACKJOCKEL);
42
- await chmod(binary, 0o755);
43
- process.env.RECORD_DIR = directory;
44
- service = new PackjockelService(() => binary);
45
- });
46
- afterEach(async () => {
47
- delete process.env.RECORD_DIR;
48
- delete process.env.FAIL;
49
- await rm(directory, { recursive: true, force: true });
50
- });
51
- async function recorded() {
52
- const args = (await readFile(join(directory, "args"), "utf8"))
53
- .trim()
54
- .split("\n");
55
- const inputs = (await readFile(join(directory, "inputs"), "utf8"))
56
- .trim()
57
- .split("\n");
58
- return { args, inputs };
59
- }
60
- it("should bundle the entry points in their order", async () => {
61
- const bundle = await service.bundle({
62
- entryPoints: { "rum.js": "rum()", "config.js": "SpeedKit.config = {}" },
63
- versions: { configPluginsVersion: "@release", rumPluginVersion: "" },
64
- define: { APP: '"shop"' },
65
- platform: "browser",
66
- });
67
- const { args, inputs } = await recorded();
68
- expect(bundle.trim()).to.equal("bundled");
69
- expect(args.slice(0, 5)).to.deep.equal([
70
- "bundle",
71
- "--bundle",
72
- "--platform=browser",
73
- "--target=es5",
74
- '--define=APP="shop"',
75
- ]);
76
- expect(args).to.include("--config-plugins-version=@release");
77
- expect(args.filter((arg) => arg.endsWith("-version=")), "a tag that is not set is left to packjockel").to.deep.equal([]);
78
- expect(args).to.include("--embedded");
79
- expect(inputs).to.deep.equal([
80
- "rum.js: rum()",
81
- "config.js: SpeedKit.config = {}",
82
- ]);
83
- });
84
- it("should bundle a document handler with every input it got", async () => {
85
- await service.bundleDocumentHandler({
86
- documentHandler: "var DocumentHandler = 1",
87
- documentHandlerConfig: "export default new DocumentHandler()",
88
- speedKitConfig: "SpeedKit.config = {}",
89
- appName: "shop",
90
- dynamicFetcherConfig: "window.dynamicBlockConfig = {}",
91
- });
92
- const { args, inputs } = await recorded();
93
- expect(args.slice(0, 2)).to.deep.equal(["bundle", "document-handler"]);
94
- expect(args).to.include("--app-name=shop");
95
- expect(args.some((arg) => arg.startsWith("--dynamic-fetcher="))).to.equal(false);
96
- expect(inputs).to.deep.equal([
97
- "DocumentHandler.js: var DocumentHandler = 1",
98
- "documentHandlerConfig.js: export default new DocumentHandler()",
99
- "speedKitConfig.js: SpeedKit.config = {}",
100
- "dynamicFetcherConfig.js: window.dynamicBlockConfig = {}",
101
- ]);
102
- });
103
- it("should leave the document handler to packjockel without one", async () => {
104
- await service.bundleDocumentHandler({
105
- documentHandlerConfig: "export default new DomDocumentHandler()",
106
- speedKitConfig: "SpeedKit.config = {}",
107
- appName: "shop",
108
- versions: {
109
- documentHandlerVersion: "1.8.0",
110
- speedKitVersion: "2.22.4",
111
- rumPluginVersion: "@release",
112
- },
113
- });
114
- const { args, inputs } = await recorded();
115
- expect(args.slice(0, 2)).to.deep.equal(["bundle", "document-handler"]);
116
- expect(args[2], "no handler argument").to.match(/^--document-handler-config=/);
117
- expect(args).to.include("--document-handler-version=1.8.0");
118
- expect(args).to.include("--speed-kit-version=2.22.4");
119
- expect(args).to.include("--rum-plugin-version=@release");
120
- expect(existsSync(join(directory, "stdin")), "packjockel reads a piped stdin as the handler").to.equal(false);
121
- expect(inputs).to.deep.equal([
122
- "documentHandlerConfig.js: export default new DomDocumentHandler()",
123
- "speedKitConfig.js: SpeedKit.config = {}",
124
- ]);
125
- });
126
- it("should report the error of packjockel without its log lines", async () => {
127
- process.env.FAIL = "1";
128
- const failure = await service
129
- .bundle({ entryPoints: { "config.js": "x" } })
130
- .catch((error) => error);
131
- expect(failure).to.be.instanceOf(PackjockelError);
132
- expect(failure.message).to.equal("packjockel failed: invalid bundle: could not resolve x");
133
- });
134
- it("should report a platform without a packjockel package", async () => {
135
- const failure = await new PackjockelService(() => {
136
- throw new Error("packjockel: @speedkit/packjockel-aix-ppc64 is not installed.");
137
- })
138
- .bundle({ entryPoints: { "config.js": "x" } })
139
- .catch((error) => error);
140
- expect(failure).to.be.instanceOf(PackjockelError);
141
- expect(failure.message).to.contain("is not installed");
142
- });
143
- });
@@ -1,15 +0,0 @@
1
- import { PostDeployCheckInterface } from "../../deploy-service-model.js";
2
- import { FileListInterface } from "../../../integration-api/index.js";
3
- import { CliServiceInterface } from "../../../cli/index.js";
4
- import { ConfigApiService } from "../../../config-api/index.js";
5
- import { DeployPolicyInterface } from "../../policy/index.js";
6
- export declare class DeprecatedDeploymentDetectionCheck implements PostDeployCheckInterface {
7
- private fileList;
8
- private cli;
9
- private configApi;
10
- private app;
11
- private policy;
12
- constructor(fileList: FileListInterface, cli: CliServiceInterface, configApi: ConfigApiService, app: string, policy: DeployPolicyInterface);
13
- check(): Promise<void>;
14
- private deleteDeploymentJobDefinition;
15
- }
@@ -1,70 +0,0 @@
1
- import { INTEGRATION_FILES } from "../../../../models/files.js";
2
- import { safe } from "../../../../helpers/safe.js";
3
- import { PostDeployDeploymentDetectionError } from "../../error/post-deploy-deployment-detection-error.js";
4
- import { DeployQuestion } from "../../policy/index.js";
5
- export class DeprecatedDeploymentDetectionCheck {
6
- fileList;
7
- cli;
8
- configApi;
9
- app;
10
- policy;
11
- constructor(fileList, cli, configApi, app, policy) {
12
- this.fileList = fileList;
13
- this.cli = cli;
14
- this.configApi = configApi;
15
- this.app = app;
16
- this.policy = policy;
17
- }
18
- async check() {
19
- this.cli.startAction("POST:CHECK:DEPLOYMENT_DETECTION", "[postDeployCheck] deploymentDetection");
20
- const configFile = this.fileList.getByName(INTEGRATION_FILES.CONFIG.DOCUMENT_HANDLER);
21
- const moduleFile = this.fileList.getByName(INTEGRATION_FILES.DEPRECATED.DEPLOYMENT_DETECTION);
22
- // no config_documentHandler or module: deploymentDetection found
23
- if (!configFile || moduleFile) {
24
- this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION");
25
- return;
26
- }
27
- const content = configFile.getContent();
28
- if (!content.includes("executeDeploymentDetection: true") &&
29
- !content.includes("executeDeploymentDetection: {")) {
30
- this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION");
31
- return;
32
- }
33
- const entityManager = await this.configApi.client.getEntityManager();
34
- const deployCheckJob = await entityManager["jobs.Definition"]
35
- .find()
36
- .eq("id", "/db/jobs.Definition/deployment-check")
37
- .singleResult();
38
- const moduleResult = await safe(this.configApi.getModule(INTEGRATION_FILES.DEPRECATED.DEPLOYMENT_DETECTION));
39
- this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION");
40
- if (deployCheckJob) {
41
- this.cli.writeWarning(`Found active Job for ${this.cli.style.bold("deprecated")} deploymentDetection in app: ${this.app}`);
42
- if (await this.policy.confirm(DeployQuestion.DeleteDeprecatedJob, "Delete job for deploymentDetection?")) {
43
- await this.deleteDeploymentJobDefinition(deployCheckJob);
44
- }
45
- }
46
- if (moduleResult.success &&
47
- moduleResult.data &&
48
- moduleResult.data.length > 0) {
49
- this.cli.writeWarning(`Found ${this.cli.style.bold("deprecated")} module deploymentDetection in app: ${this.app}`);
50
- if (await this.policy.confirm(DeployQuestion.DeleteDeprecatedModule, "Delete module deploymentDetection?")) {
51
- this.cli.startAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE", "Delete module deploymentDetection");
52
- await this.configApi.deleteModule(INTEGRATION_FILES.DEPRECATED.DEPLOYMENT_DETECTION);
53
- this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE");
54
- }
55
- }
56
- }
57
- async deleteDeploymentJobDefinition(deployCheckJob) {
58
- this.cli.startAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE_CRON", "Delete job deploymentDetection-check");
59
- const result = await safe(deployCheckJob.delete());
60
- if (result.success === true) {
61
- this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE_CRON");
62
- return;
63
- }
64
- this.cli.failAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE_CRON");
65
- throw new PostDeployDeploymentDetectionError(result.error, [
66
- `check https://dashboard.baqend.com/app/${this.app}/db/jobs.Definition`,
67
- "delete entry manual",
68
- ]);
69
- }
70
- }
@@ -1,4 +0,0 @@
1
- import ApplicationError from "../../error-handling/error/application-error.js";
2
- export declare class CheckModuleFileError extends ApplicationError {
3
- readonly code = "CHECK_MODULE_ERROR";
4
- }
@@ -1,4 +0,0 @@
1
- import ApplicationError from "../../error-handling/error/application-error.js";
2
- export class CheckModuleFileError extends ApplicationError {
3
- code = "CHECK_MODULE_ERROR";
4
- }
@@ -1,4 +0,0 @@
1
- import ApplicationError from "../../error-handling/error/application-error.js";
2
- export declare class PostDeployDeploymentDetectionError extends ApplicationError {
3
- readonly code = "POST_DEPLOY";
4
- }
@@ -1,4 +0,0 @@
1
- import ApplicationError from "../../error-handling/error/application-error.js";
2
- export class PostDeployDeploymentDetectionError extends ApplicationError {
3
- code = "POST_DEPLOY";
4
- }
@@ -1,10 +0,0 @@
1
- import { CliServiceInterface } from "../../cli/index.js";
2
- import { SpeedKitServerConfig } from "../onboarding-model.js";
3
- import { ConfigApiService } from "../../config-api/index.js";
4
- export declare class ServerConfig {
5
- private cli;
6
- private client?;
7
- constructor(cli: CliServiceInterface, client?: ConfigApiService);
8
- getServerSpeedKitConfig(): Promise<SpeedKitServerConfig | null>;
9
- private getServerConfig;
10
- }
@@ -1,27 +0,0 @@
1
- import { safe } from "../../../helpers/safe.js";
2
- export class ServerConfig {
3
- cli;
4
- client;
5
- constructor(cli, client) {
6
- this.cli = cli;
7
- this.client = client;
8
- }
9
- async getServerSpeedKitConfig() {
10
- const serverConfig = await this.getServerConfig();
11
- if (!serverConfig) {
12
- return;
13
- }
14
- return JSON.parse(serverConfig);
15
- }
16
- async getServerConfig() {
17
- this.cli.startAction("ONBOARDING:FETCH:RUNTIME_CONFIG", "wait for credentials from server-config");
18
- const serverConfigResponse = await safe(this.client.getServerConfig());
19
- if (serverConfigResponse.success === false) {
20
- this.cli.failAction("ONBOARDING:FETCH:RUNTIME_CONFIG");
21
- this.cli.writeError(`unable to load serverConfig: ${serverConfigResponse.error}`);
22
- return;
23
- }
24
- this.cli.successAction("ONBOARDING:FETCH:RUNTIME_CONFIG");
25
- return serverConfigResponse.data;
26
- }
27
- }
@@ -1,31 +0,0 @@
1
- import { SpeedKitServerConfig } from "../onboarding-model.js";
2
- import { CliServiceInterface } from "../../cli/index.js";
3
- export declare class Crawler {
4
- private cli;
5
- private speedKitServerConfig?;
6
- /** Warnings already shown, so a per-fetch condition is reported once per session. */
7
- private readonly warned;
8
- constructor(cli: CliServiceInterface, speedKitServerConfig?: SpeedKitServerConfig);
9
- private warnOnce;
10
- fetchRemote(originUrl: string, variation: string): Promise<{
11
- response: Response;
12
- url: string;
13
- } | undefined>;
14
- /**
15
- * Builds the origin request exactly as the Baqend asset server builds it, so a locally cached
16
- * document matches what production would cache for the same variation.
17
- *
18
- * The resolution itself lives in `services/origin-request` and is shared with
19
- * `sk origin-request`, so there is one owner for it and one place the server's behaviour is
20
- * pinned by specs. That covers the base headers, the wildcard-then-variation order, the regex
21
- * templates with their `${group}` substitution, and the query params.
22
- *
23
- * Two things stay local: origin basic auth, which no variation carries, and tolerance for a
24
- * custom variation the config does not define — the server rejects that request, but failing a
25
- * whole onboarding session over it would be unhelpful, so it falls back to the base headers and
26
- * warns once. A missing runtime config is not reported here; the fetch that failed to load it
27
- * says what it costs.
28
- */
29
- private prepareOriginRequest;
30
- private prepareAuthRequest;
31
- }
@@ -1,98 +0,0 @@
1
- import { safe } from "../../../helpers/safe.js";
2
- import { resolveRequest, UndefinedVariationError, } from "../../origin-request/index.js";
3
- import { originFetch } from "../../../helpers/origin-proxy.js";
4
- import { randomUUID } from "node:crypto";
5
- export class Crawler {
6
- cli;
7
- speedKitServerConfig;
8
- /** Warnings already shown, so a per-fetch condition is reported once per session. */
9
- warned = new Set();
10
- constructor(cli, speedKitServerConfig) {
11
- this.cli = cli;
12
- this.speedKitServerConfig = speedKitServerConfig;
13
- }
14
- warnOnce(key, message) {
15
- if (this.warned.has(key))
16
- return;
17
- this.warned.add(key);
18
- this.cli.writeWarning(message);
19
- }
20
- async fetchRemote(originUrl, variation) {
21
- // origin URL with the variation's query params applied — returned so callers compare it
22
- // (not the bare originUrl) against response.url for redirect detection
23
- const { url, init } = this.prepareOriginRequest(originUrl, variation);
24
- const uuid = randomUUID();
25
- this.cli.startAction(`DOCUMENTHANDLER:FETCH:${uuid}`, `[documentHandler:fetch]: ${url}`);
26
- const fetchResponse = await safe(originFetch(url, init));
27
- if (fetchResponse.success === true) {
28
- this.cli.successAction(`DOCUMENTHANDLER:FETCH:${uuid}`);
29
- return { response: fetchResponse.data, url };
30
- }
31
- this.cli.failAction(`DOCUMENTHANDLER:FETCH:${uuid}`, `error while fetching Asset: ${originUrl}`);
32
- this.cli.writeError(fetchResponse.error);
33
- this.cli.writeError(JSON.stringify(fetchResponse.errorObj));
34
- }
35
- /**
36
- * Builds the origin request exactly as the Baqend asset server builds it, so a locally cached
37
- * document matches what production would cache for the same variation.
38
- *
39
- * The resolution itself lives in `services/origin-request` and is shared with
40
- * `sk origin-request`, so there is one owner for it and one place the server's behaviour is
41
- * pinned by specs. That covers the base headers, the wildcard-then-variation order, the regex
42
- * templates with their `${group}` substitution, and the query params.
43
- *
44
- * Two things stay local: origin basic auth, which no variation carries, and tolerance for a
45
- * custom variation the config does not define — the server rejects that request, but failing a
46
- * whole onboarding session over it would be unhelpful, so it falls back to the base headers and
47
- * warns once. A missing runtime config is not reported here; the fetch that failed to load it
48
- * says what it costs.
49
- */
50
- prepareOriginRequest(originUrl, variationParameter) {
51
- const variations = this.speedKitServerConfig?.speedKit?.variations ?? {};
52
- let resolved;
53
- try {
54
- resolved = resolveRequest(variations, originUrl, variationParameter);
55
- }
56
- catch (error) {
57
- // Only a custom variation reaches this branch: a device variation (default, mobile, tablet)
58
- // never throws. It starts from its built-in default, and an entry for it in the runtime
59
- // config is applied on top, so a configured user agent or header still wins.
60
- if (!(error instanceof UndefinedVariationError))
61
- throw error;
62
- const defined = Object.keys(variations);
63
- this.warnOnce(`undefined-variation:${variationParameter}`, `variation ${variationParameter} is not defined in the runtime config — ` +
64
- (defined.length
65
- ? `defined are: ${defined.join(", ")}. `
66
- : "it defines no variations at all. ") +
67
- "Falling back to the base headers.");
68
- resolved = resolveRequest({}, originUrl);
69
- }
70
- const init = { headers: { ...resolved.headers } };
71
- // Only a request that matched no specific variation falls back to origin basic auth. The
72
- // wildcard applies to every request, so it does not count as a match.
73
- const matchedSpecificVariation = resolved.appliedKeys.some((key) => key !== "*" && !key.startsWith("device-default:"));
74
- if (!matchedSpecificVariation) {
75
- const authentication = this.prepareAuthRequest(originUrl);
76
- if (authentication)
77
- init.headers["Authorization"] = authentication;
78
- }
79
- return { url: resolved.url, init };
80
- }
81
- prepareAuthRequest(originUrl) {
82
- // A missing `authentications` has to leave through the same door as an empty one. Comparing
83
- // `undefined < 1` yields false, so the previous guard fell through and iterated undefined.
84
- if (!this.speedKitServerConfig?.speedKit?.authentications?.length) {
85
- return;
86
- }
87
- const origin = new URL(originUrl).origin;
88
- for (const auth of this.speedKitServerConfig.speedKit.authentications) {
89
- if (!auth.uri.includes(origin)) {
90
- continue;
91
- }
92
- if (auth.type === "basic") {
93
- return `Basic ${Buffer.from(`${auth.user}:${auth.password}`).toString("base64")}`;
94
- }
95
- }
96
- return;
97
- }
98
- }