@speedkit/cli 4.39.0 → 4.41.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 (37) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +10 -1
  3. package/dist/commands/airports_iata.json +9202 -1
  4. package/dist/commands/generate-customer-config.d.ts +2 -0
  5. package/dist/commands/generate-customer-config.js +7 -1
  6. package/dist/services/customer-config/customer-config-service-build-context.d.ts +8 -0
  7. package/dist/services/customer-config/customer-config-service-build-context.js +8 -0
  8. package/dist/services/customer-config/customer-config-service-factory.js +3 -1
  9. package/dist/services/customer-config/customer-config-service.d.ts +10 -7
  10. package/dist/services/customer-config/customer-config-service.js +138 -308
  11. package/dist/services/customer-config/index.d.ts +2 -0
  12. package/dist/services/customer-config/index.js +2 -0
  13. package/dist/services/customer-config/spec/wizard-answers.spec.d.ts +1 -0
  14. package/dist/services/customer-config/spec/wizard-answers.spec.js +207 -0
  15. package/dist/services/customer-config/wizard-answers.d.ts +48 -0
  16. package/dist/services/customer-config/wizard-answers.js +67 -0
  17. package/dist/services/customer-config/wizard-questions.d.ts +86 -0
  18. package/dist/services/customer-config/wizard-questions.js +400 -0
  19. package/dist/services/onboarding/browser/executable/executable-validator.js +1 -1
  20. package/dist/services/onboarding/browser/extension/devtools-panel.d.ts +36 -0
  21. package/dist/services/onboarding/browser/extension/devtools-panel.js +82 -0
  22. package/dist/services/onboarding/browser/extension/extension-bridge.d.ts +55 -24
  23. package/dist/services/onboarding/browser/extension/extension-bridge.js +161 -66
  24. package/dist/services/onboarding/onboarding-model.d.ts +29 -1
  25. package/dist/services/onboarding/onboarding-model.js +7 -13
  26. package/dist/services/onboarding/onboarding-service-factory.d.ts +1 -0
  27. package/dist/services/onboarding/onboarding-service-factory.js +24 -3
  28. package/dist/services/onboarding/onboarding-service.d.ts +8 -0
  29. package/dist/services/onboarding/onboarding-service.js +28 -0
  30. package/dist/services/onboarding/spec/browser/extension/devtools-panel.spec.d.ts +1 -0
  31. package/dist/services/onboarding/spec/browser/extension/devtools-panel.spec.js +99 -0
  32. package/dist/services/onboarding/spec/browser/extension/extension-bridge.spec.d.ts +1 -0
  33. package/dist/services/onboarding/spec/browser/extension/extension-bridge.spec.js +235 -0
  34. package/dist/services/onboarding/spec/onboarding-model.spec.js +29 -0
  35. package/dist/templates/speedKit.Revalidated.js +5 -1
  36. package/oclif.manifest.json +17 -2
  37. package/package.json +1 -1
@@ -0,0 +1,235 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { ExtensionBridge } from "../../../browser/extension/extension-bridge.js";
4
+ const ID = "gbiigacjibjkoldfdgjkomkddifgkeja";
5
+ const WORKER_URL = `chrome-extension://${ID}/background.js`;
6
+ function session(handlers) {
7
+ return {
8
+ send: async (method, params = {}) => {
9
+ const handler = handlers[method];
10
+ if (!handler)
11
+ throw new Error(`'${method}' wasn't found`);
12
+ return handler(params);
13
+ },
14
+ detach: async () => undefined,
15
+ };
16
+ }
17
+ /**
18
+ * A browser with the devtools extension installed, as CDP shows it.
19
+ *
20
+ * `worker` is whether its service worker is running, which is the whole
21
+ * point: the panel's updates used to need one, and nothing restarted a worker
22
+ * that had stopped.
23
+ */
24
+ function browserWith({ listed = true, worker = true, pages = ["https://shop.example/"], direct = true, } = {}) {
25
+ const state = {
26
+ worker,
27
+ direct,
28
+ pages,
29
+ /** Every snapshot stored, and through which path. */
30
+ stored: [],
31
+ /** Holds the next direct write until released. */
32
+ gate: null,
33
+ };
34
+ const listeners = {};
35
+ const workerTarget = {
36
+ type: () => "service_worker",
37
+ url: () => WORKER_URL,
38
+ createCDPSession: async () => session({
39
+ "Runtime.evaluate": ({ expression }) => {
40
+ const text = String(expression);
41
+ if (text.includes("getManifest")) {
42
+ return { result: { value: "speed-kit DevTools" } };
43
+ }
44
+ const json = text.slice(text.indexOf("(") + 1, text.lastIndexOf(")"));
45
+ state.stored.push({ via: "worker", value: JSON.parse(json).skCli });
46
+ return { result: { value: undefined } };
47
+ },
48
+ }),
49
+ };
50
+ const browser = {
51
+ targets: () => (state.worker ? [workerTarget] : []),
52
+ waitForTarget: async () => {
53
+ throw new Error("Waiting for target failed: timeout");
54
+ },
55
+ target: () => ({
56
+ createCDPSession: async () => session(listed
57
+ ? {
58
+ "Extensions.getExtensions": () => ({
59
+ extensions: [
60
+ { id: "abcdefghijklmnopabcdefghijklmnop", name: "Other" },
61
+ { id: ID, name: "speed-kit DevTools" },
62
+ ],
63
+ }),
64
+ }
65
+ : {}),
66
+ }),
67
+ pages: async () => state.pages.map((url) => ({
68
+ url: () => url,
69
+ createCDPSession: async () => session({
70
+ "Extensions.setStorageItems": async (params) => {
71
+ if (!state.direct) {
72
+ throw new Error("Extensions.setStorageItems wasn't found");
73
+ }
74
+ if (!isWebUrl(url))
75
+ throw new Error("Extension not found.");
76
+ expect(params.id).to.equal(ID);
77
+ expect(params.storageArea).to.equal("local");
78
+ const gate = state.gate;
79
+ state.gate = null;
80
+ await gate;
81
+ state.stored.push({
82
+ via: "direct",
83
+ value: params.values.skCli,
84
+ });
85
+ },
86
+ }),
87
+ })),
88
+ on: (event, listener) => {
89
+ (listeners[event] ??= []).push(listener);
90
+ },
91
+ };
92
+ return {
93
+ browser,
94
+ state,
95
+ /** A page finishing a navigation to `url`, as Puppeteer reports it. */
96
+ navigated(url) {
97
+ state.pages = [url];
98
+ for (const listener of listeners.targetchanged ?? []) {
99
+ listener({ type: () => "page", url: () => url });
100
+ }
101
+ },
102
+ };
103
+ }
104
+ function isWebUrl(url) {
105
+ return /^https?:\/\//.test(url);
106
+ }
107
+ function recordingCli() {
108
+ const lines = [];
109
+ return {
110
+ lines,
111
+ cli: {
112
+ writeWarning: (message) => lines.push({ level: "warning", message }),
113
+ writeError: (message) => lines.push({ level: "error", message }),
114
+ writeSuccess: (message) => lines.push({ level: "success", message }),
115
+ },
116
+ };
117
+ }
118
+ function messagesOf(value) {
119
+ return value.messages;
120
+ }
121
+ const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
122
+ describe("ExtensionBridge", () => {
123
+ describe("init", () => {
124
+ it("finds the extension without a running service worker", async () => {
125
+ const { browser } = browserWith({ worker: false });
126
+ const bridge = new ExtensionBridge(recordingCli().cli, true);
127
+ await bridge.init(browser);
128
+ expect(bridge.available).to.equal(true);
129
+ });
130
+ it("falls back to the worker's manifest name when the list is refused", async () => {
131
+ const { browser, state } = browserWith({ listed: false });
132
+ const bridge = new ExtensionBridge(recordingCli().cli, true);
133
+ await bridge.init(browser);
134
+ await bridge.writeMessages([]);
135
+ expect(bridge.available).to.equal(true);
136
+ expect(state.stored).to.have.length(1);
137
+ });
138
+ it("refuses to start without a devtools extension", async () => {
139
+ const { browser } = browserWith();
140
+ const bridge = new ExtensionBridge(recordingCli().cli, false);
141
+ let error;
142
+ await bridge.init(browser).catch((e) => (error = e));
143
+ expect(error?.message).to.contain("no devtools extension loaded");
144
+ });
145
+ });
146
+ describe("writeMessages", () => {
147
+ it("writes the storage directly, from the page on the customer origin", async () => {
148
+ const { browser, state } = browserWith({
149
+ pages: ["about:blank", "https://shop.example/"],
150
+ });
151
+ const bridge = new ExtensionBridge(recordingCli().cli, true);
152
+ await bridge.init(browser);
153
+ await bridge.writeMessages([{ id: "todo", data: [] }]);
154
+ expect(state.stored).to.have.length(1);
155
+ expect(state.stored[0].via).to.equal("direct");
156
+ expect(messagesOf(state.stored[0].value)).to.deep.equal([
157
+ { id: "todo", data: [] },
158
+ ]);
159
+ });
160
+ it("still reaches the panel after the service worker stopped", async () => {
161
+ // The failure this replaced: every write after the worker stopped
162
+ // answered "service-worker target not found", for the rest of the run.
163
+ const { browser, state } = browserWith();
164
+ const { cli, lines } = recordingCli();
165
+ const bridge = new ExtensionBridge(cli, true);
166
+ await bridge.init(browser);
167
+ state.worker = false;
168
+ await bridge.writeMessages([]);
169
+ expect(state.stored.map((s) => s.via)).to.deep.equal(["direct"]);
170
+ expect(lines).to.deep.equal([]);
171
+ });
172
+ it("goes through the service worker when the direct write is refused", async () => {
173
+ const { browser, state } = browserWith({ direct: false });
174
+ const bridge = new ExtensionBridge(recordingCli().cli, true);
175
+ await bridge.init(browser);
176
+ await bridge.writeMessages([]);
177
+ expect(state.stored.map((s) => s.via)).to.deep.equal(["worker"]);
178
+ });
179
+ it("writes only the newest snapshot once the one in flight has landed", async () => {
180
+ const { browser, state } = browserWith();
181
+ const bridge = new ExtensionBridge(recordingCli().cli, true);
182
+ await bridge.init(browser);
183
+ let release;
184
+ state.gate = new Promise((resolve) => (release = resolve));
185
+ const writes = [
186
+ bridge.writeMessages(["a"]),
187
+ bridge.writeMessages(["b"]),
188
+ bridge.writeMessages(["c"]),
189
+ ];
190
+ await settle();
191
+ release();
192
+ await Promise.all(writes);
193
+ expect(state.stored.map((s) => messagesOf(s.value))).to.deep.equal([
194
+ ["a"],
195
+ ["c"],
196
+ ]);
197
+ });
198
+ it("reports an outage once and retries on the next page load", async () => {
199
+ const { browser, state, navigated } = browserWith({
200
+ worker: false,
201
+ pages: ["about:blank"],
202
+ });
203
+ const { cli, lines } = recordingCli();
204
+ const bridge = new ExtensionBridge(cli, true);
205
+ await bridge.init(browser);
206
+ await bridge.writeMessages(["a"]);
207
+ await bridge.writeMessages(["b"]);
208
+ expect(state.stored).to.deep.equal([]);
209
+ expect(lines.map((l) => l.level)).to.deep.equal(["warning"]);
210
+ expect(lines[0].message).to.contain("not receiving updates");
211
+ navigated("https://shop.example/");
212
+ await settle();
213
+ await settle();
214
+ expect(state.stored.map((s) => messagesOf(s.value))).to.deep.equal([
215
+ ["b"],
216
+ ]);
217
+ expect(lines.map((l) => l.level)).to.deep.equal(["warning", "success"]);
218
+ });
219
+ it("does not retry on a navigation when nothing is pending", async () => {
220
+ const { browser, state, navigated } = browserWith();
221
+ const bridge = new ExtensionBridge(recordingCli().cli, true);
222
+ await bridge.init(browser);
223
+ await bridge.writeMessages([]);
224
+ navigated("https://shop.example/other");
225
+ await settle();
226
+ expect(state.stored).to.have.length(1);
227
+ });
228
+ it("warns instead of writing before init", async () => {
229
+ const { cli, lines } = recordingCli();
230
+ const bridge = new ExtensionBridge(cli, true);
231
+ await bridge.writeMessages([]);
232
+ expect(lines[0].message).to.contain("before init()");
233
+ });
234
+ });
235
+ });
@@ -158,3 +158,32 @@ describe("BrowserContext system chromeFlags", () => {
158
158
  expect(newContext(true).findFeatureFindings()).to.deep.equal([]);
159
159
  });
160
160
  });
161
+ describe("BrowserContext launch options", () => {
162
+ it("installs extensions over the pipe on every Chromium build", () => {
163
+ const withExtensions = {
164
+ settings: {
165
+ ...environment.settings,
166
+ chromeExtensionPaths: "/ext/devtools,/ext/other",
167
+ },
168
+ };
169
+ for (const browserVersionString of [
170
+ "Google Chrome for Testing 154.0.8037.57",
171
+ "Chromium 153.0.8010.52 Arch Linux",
172
+ ]) {
173
+ const options = new BrowserContext("example.com", browserVersionString, [], withExtensions, undefined, false, false, undefined).getPuppeteerLaunchOptions();
174
+ // The pipe and Puppeteer's --enable-unsafe-extension-debugging are what
175
+ // the `Extensions` domain requires, and ExtensionBridge writes through it.
176
+ expect(options.pipe).to.equal(true);
177
+ expect(options.enableExtensions).to.deep.equal([
178
+ "/ext/devtools",
179
+ "/ext/other",
180
+ ]);
181
+ expect(options.args.filter((arg) => /extension/.test(arg))).to.deep.equal([]);
182
+ }
183
+ });
184
+ it("launches without extensions when none are configured", () => {
185
+ const options = newContext(false).getPuppeteerLaunchOptions();
186
+ expect(options.enableExtensions).to.equal(undefined);
187
+ expect(options.pipe).to.equal(undefined);
188
+ });
189
+ });
@@ -5,7 +5,11 @@ const https = require("node:https");
5
5
 
6
6
  const agent = new https.Agent({ rejectUnauthorized: false });
7
7
 
8
- {{config}} // eslint-disable-line
8
+ {
9
+ {
10
+ config;
11
+ }
12
+ } // eslint-disable-line
9
13
 
10
14
  const ORIGIN_PATHS = Object.keys(ORIGIN_POPS).filter((origin) =>
11
15
  origin.endsWith("/"),
@@ -451,7 +451,9 @@
451
451
  "description": "Generates a customer config guided by a wizard 🧙‍",
452
452
  "examples": [
453
453
  "$ sk generate-customer-config -a <app> -d <customersDirectory>",
454
- "$ sk generate-customer-config -a decathlon -d customers"
454
+ "$ sk generate-customer-config -a decathlon -d customers",
455
+ "$ sk generate-customer-config --print-questions",
456
+ "$ sk generate-customer-config -a decathlon --answers answers.json < /dev/null"
455
457
  ],
456
458
  "flags": {
457
459
  "app": {
@@ -488,6 +490,19 @@
488
490
  "pre-poc"
489
491
  ],
490
492
  "type": "option"
493
+ },
494
+ "answers": {
495
+ "description": "JSON file with the wizard answers. The wizard then asks nothing: a missing key takes the question's default, and a question without one stops the run",
496
+ "name": "answers",
497
+ "hasDynamicHelp": false,
498
+ "multiple": false,
499
+ "type": "option"
500
+ },
501
+ "print-questions": {
502
+ "description": "Print every wizard question as JSON — key, type, choices, default, condition — and exit. The keys are the keys of --answers",
503
+ "name": "print-questions",
504
+ "allowNo": false,
505
+ "type": "boolean"
491
506
  }
492
507
  },
493
508
  "hasDynamicHelp": false,
@@ -1746,5 +1761,5 @@
1746
1761
  ]
1747
1762
  }
1748
1763
  },
1749
- "version": "4.39.0"
1764
+ "version": "4.41.0"
1750
1765
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.39.0",
4
+ "version": "4.41.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"