@speedkit/cli 4.37.0 → 4.38.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 (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/commands/find-pops.js +2 -2
  3. package/dist/commands/generate-pop-config.js +9 -2
  4. package/dist/commands/login.js +0 -1
  5. package/dist/helpers/origin-proxy.d.ts +2 -2
  6. package/dist/helpers/origin-proxy.js +24 -11
  7. package/dist/helpers/spec/origin-proxy.spec.js +85 -0
  8. package/dist/services/athena/athena-service-build-context.d.ts +8 -0
  9. package/dist/services/athena/athena-service-factory.d.ts +10 -0
  10. package/dist/services/athena/athena-service-factory.js +18 -2
  11. package/dist/services/athena/baqend-athena-service.d.ts +27 -0
  12. package/dist/services/athena/baqend-athena-service.js +69 -7
  13. package/dist/services/athena/error/baqend-query-error.d.ts +4 -0
  14. package/dist/services/athena/error/baqend-query-error.js +4 -0
  15. package/dist/services/athena/error/unreadable-response.d.ts +18 -0
  16. package/dist/services/athena/error/unreadable-response.js +29 -0
  17. package/dist/services/athena/index.d.ts +2 -0
  18. package/dist/services/athena/index.js +2 -0
  19. package/dist/services/athena/spec/baqend-athena-service.spec.js +84 -8
  20. package/dist/services/cli/cli-environment.d.ts +7 -0
  21. package/dist/services/cli/cli-environment.js +7 -0
  22. package/dist/services/config-api/client.js +3 -3
  23. package/dist/services/config-api/config-api-factory.d.ts +12 -1
  24. package/dist/services/config-api/config-api-factory.js +13 -3
  25. package/dist/services/config-api/ensure-login.d.ts +52 -0
  26. package/dist/services/config-api/ensure-login.js +93 -0
  27. package/dist/services/config-api/entity-manager-provider.d.ts +24 -2
  28. package/dist/services/config-api/entity-manager-provider.js +40 -6
  29. package/dist/services/config-api/error/login-error.d.ts +7 -1
  30. package/dist/services/config-api/error/login-error.js +13 -2
  31. package/dist/services/config-api/spec/ensure-login.spec.d.ts +1 -0
  32. package/dist/services/config-api/spec/ensure-login.spec.js +95 -0
  33. package/dist/services/deploy/deploy-service-build-context.d.ts +7 -0
  34. package/dist/services/deploy/deploy-service-factory.js +6 -1
  35. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +1 -0
  36. package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +4 -2
  37. package/dist/services/onboarding/onboarding-service-factory.d.ts +5 -0
  38. package/dist/services/onboarding/onboarding-service-factory.js +9 -4
  39. package/dist/services/onboarding/spec/virtual-orestes-app/crawler.spec.js +34 -1
  40. package/dist/services/pop-config/pop-config-factory.js +1 -0
  41. package/dist/services/prewarm/auto-pre-warm-factory.js +11 -1
  42. package/dist/services/query-builder/query-builder-factory.js +4 -0
  43. package/oclif.manifest.json +144 -144
  44. package/package.json +1 -1
@@ -1,7 +1,6 @@
1
1
  import { IntegrationApiServiceBuildContext, IntegrationApiFactory, } from "../../integration-api/index.js";
2
2
  import { DocumentHandlerServer } from "../document-handler-server.js";
3
3
  import { BundleServiceFactory } from "../../bundler/index.js";
4
- import { EntityManagerProvider } from "../../config-api/entity-manager-provider.js";
5
4
  import { safe } from "../../../helpers/safe.js";
6
5
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
7
6
  import { resolve } from "node:path";
@@ -27,7 +26,10 @@ export default class DocumentHandlerRuntimeServiceFactory {
27
26
  const cliService = this.context.environment.cli;
28
27
  await this.installAdditionalDependencies(customerConfig, cliService);
29
28
  const bundler = new BundleServiceFactory(this.context.customerPath).buildService();
30
- const entityManagerResult = await safe(new EntityManagerProvider().getEntityManager(customerConfig.app));
29
+ // the non-prompting lookup: the document handler runs with a session when
30
+ // there is one and without when there is not, so it must not stop the
31
+ // command at a login prompt to find out
32
+ const entityManagerResult = await this.context.environment.entityManagerProvider.tryGetEntityManager(customerConfig.app);
31
33
  return new DocumentHandlerServer(customerConfig, files, bundler, cliService, this.context.environment.nodeModulesPath, this.context.verboseLevel, entityManagerResult.success ? entityManagerResult.data : null);
32
34
  }
33
35
  getCustomerConfig(files) {
@@ -33,6 +33,11 @@ export declare class OnboardingServiceFactory {
33
33
  }): BrowserContext;
34
34
  private getOnboardingService;
35
35
  private prepareMessagehandler;
36
+ /**
37
+ * The app token for the devtools extension, or `null` when nobody is logged
38
+ * in — onboarding shows what it can without one rather than stopping for a
39
+ * login it does not strictly need.
40
+ */
36
41
  private getAppToken;
37
42
  private buildInstallResource;
38
43
  private getAthenaClient;
@@ -37,7 +37,6 @@ import { installBrowserOriginFetch } from "../browser-fetch/index.js";
37
37
  import { Crawler } from "./virtual-orestes-app/crawler.js";
38
38
  import { VirtualOrestesApp } from "./virtual-orestes-app/index.js";
39
39
  import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.js";
40
- import { account } from "baqend/cli";
41
40
  import * as fs from "node:fs";
42
41
  import * as path from "node:path";
43
42
  import { StaticRecipe } from "../integration-api/virtual/static-recipe.js";
@@ -192,9 +191,13 @@ export class OnboardingServiceFactory {
192
191
  }
193
192
  return messageHandler;
194
193
  }
194
+ /**
195
+ * The app token for the devtools extension, or `null` when nobody is logged
196
+ * in — onboarding shows what it can without one rather than stopping for a
197
+ * login it does not strictly need.
198
+ */
195
199
  async getAppToken(app) {
196
- // skipInput=true -> fail instead of prompting when no valid login is cached
197
- const result = await safe(account.login({ app, skipInput: true }));
200
+ const result = await this.context.environment.entityManagerProvider.tryGetEntityManager(app);
198
201
  if (result.success !== true) {
199
202
  return null;
200
203
  }
@@ -212,6 +215,8 @@ export class OnboardingServiceFactory {
212
215
  cli.failAction("ONBOARDING:BUILD:INSTALL_RESOURCE", result.error);
213
216
  }
214
217
  async getAthenaClient(app) {
218
+ // no promptForLogin: onboarding shows the Athena data when a login is
219
+ // there and carries on without one, so it must not stop at a prompt
215
220
  const athenaFactory = new AthenaServiceFactory(new AthenaServiceBuildContext({
216
221
  environment: this.context.environment,
217
222
  app,
@@ -223,7 +228,7 @@ export class OnboardingServiceFactory {
223
228
  }
224
229
  getConfigApi(app) {
225
230
  const configApiContext = new ConfigApiContext(app);
226
- return new ConfigApiServiceFactory(configApiContext).getService();
231
+ return new ConfigApiServiceFactory(configApiContext, this.context.environment.entityManagerProvider).getService();
227
232
  }
228
233
  async getFetchEventHandler(files, customerConfig, documentHandler, cache, cli, browserContext, athenaClient, messageHandler, fileWatcher, speedKitServiceWorkerJs) {
229
234
  const configApi = this.getConfigApi(customerConfig.app);
@@ -23,8 +23,13 @@ function stubCli() {
23
23
  describe("Crawler.fetchRemote", () => {
24
24
  let server;
25
25
  let url;
26
+ /** Raw headers of the last request, exactly as they arrived on the wire. */
27
+ let received;
26
28
  beforeEach(async () => {
27
- server = http.createServer((_request, response) => response.end("origin"));
29
+ server = http.createServer((request, response) => {
30
+ received = request.headers;
31
+ response.end("origin");
32
+ });
28
33
  await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
29
34
  url = `http://127.0.0.1:${server.address().port}/`;
30
35
  });
@@ -46,4 +51,32 @@ describe("Crawler.fetchRemote", () => {
46
51
  expect(await result.response.text()).to.equal("origin");
47
52
  expect(warnings.join(" ")).to.contain("no variations available");
48
53
  });
54
+ describe("a runtime config that sets Accept-Language to null", () => {
55
+ const withVariations = (variations) => ({ speedKit: { variations } });
56
+ it("sends no Accept-Language, not even the one fetch adds by default", async () => {
57
+ const { cli } = stubCli();
58
+ const serverConfig = withVariations({
59
+ "*": { headers: { "Accept-Language": null } },
60
+ });
61
+ await new Crawler(cli, serverConfig).fetchRemote(url, "mobile");
62
+ expect(received).to.not.have.property("accept-language");
63
+ expect(received).to.not.have.property("sec-fetch-mode");
64
+ expect(received["user-agent"]).to.contain("SpeedKit/1.0");
65
+ });
66
+ it("sends the value a concrete variation sets over the wildcard", async () => {
67
+ const { cli } = stubCli();
68
+ const serverConfig = withVariations({
69
+ "*": { headers: { "Accept-Language": null } },
70
+ mobile: { headers: { "Accept-Language": "en-GB" } },
71
+ });
72
+ await new Crawler(cli, serverConfig).fetchRemote(url, "mobile");
73
+ expect(received["accept-language"]).to.equal("en-GB");
74
+ });
75
+ it("keeps the server's base value when no config touches the header", async () => {
76
+ const { cli } = stubCli();
77
+ const serverConfig = withVariations({ "*": { headers: {} } });
78
+ await new Crawler(cli, serverConfig).fetchRemote(url, "DEFAULT");
79
+ expect(received["accept-language"]).to.equal("*");
80
+ });
81
+ });
49
82
  });
@@ -9,6 +9,7 @@ export class PopConfigFactory {
9
9
  const athenaService = await new AthenaServiceFactory(new AthenaServiceBuildContext({
10
10
  environment: this.context.environment,
11
11
  app: this.context.app,
12
+ promptForLogin: true,
12
13
  })).getService();
13
14
  return new PopConfigService(athenaService);
14
15
  }
@@ -2,6 +2,7 @@ import { QueryBuilderFactory } from "../query-builder/query-builder-factory.js";
2
2
  import { PrewarmQueryServiceBuildContext } from "../query-builder/query-builder-service-build-context.js";
3
3
  import { normalizeDevices } from "../query-builder/queries/device.js";
4
4
  import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.js";
5
+ import { ensureBaqendLogin } from "../config-api/ensure-login.js";
5
6
  import { AssetApiClient } from "./assets/asset-api-client.js";
6
7
  import { CsvReader } from "./csv-reader.js";
7
8
  import { PreWarmService } from "./pre-warm-service.js";
@@ -25,6 +26,9 @@ export class AutoPreWarmFactory {
25
26
  }
26
27
  async getService() {
27
28
  const cli = this.context.environment.cli;
29
+ // One session for the whole run: the query and the asset API that warms
30
+ // its result are the same app, so they share the environment's login.
31
+ const entityManagerProvider = this.context.environment.entityManagerProvider;
28
32
  const queryService = await new QueryBuilderFactory(new PrewarmQueryServiceBuildContext({
29
33
  environment: this.context.environment,
30
34
  configName: this.context.configName,
@@ -46,8 +50,14 @@ export class AutoPreWarmFactory {
46
50
  catalog: this.context.catalog,
47
51
  })).buildService();
48
52
  const app = queryService.app;
53
+ // Before the query runs, not after: warming the result needs a Baqend
54
+ // session whichever way the query itself was answered, and with AWS
55
+ // credentials the Athena path never asks for one. Building the query above
56
+ // is local, so nothing has been spent yet when this fails. On the Baqend
57
+ // path the session is already there and this costs nothing.
58
+ await ensureBaqendLogin(app, entityManagerProvider, cli);
49
59
  const rows = await queryService.execute();
50
- const configApi = new ConfigApiServiceFactory(new ConfigApiContext(app)).getService();
60
+ const configApi = new ConfigApiServiceFactory(new ConfigApiContext(app), entityManagerProvider).getService();
51
61
  const entityManager = await configApi.client.getEntityManager();
52
62
  const assetApiClient = new AssetApiClient(entityManager.token, app, this.context.sortParameters, cli);
53
63
  const csvReader = new CsvReader();
@@ -54,6 +54,10 @@ export class QueryBuilderFactory {
54
54
  app,
55
55
  workgroup: this.context.workgroup,
56
56
  catalog: this.context.catalog,
57
+ // the query is the command's whole job here, so a missing login
58
+ // is asked for up front rather than failing the run half way
59
+ // through
60
+ promptForLogin: true,
57
61
  })).getService()
58
62
  : undefined;
59
63
  return new QueryBuilderService(serviceContext, parseRuleSets(speedKitConfig), cli, athenaService);
@@ -1291,6 +1291,149 @@
1291
1291
  "setup.js"
1292
1292
  ]
1293
1293
  },
1294
+ "extension:add": {
1295
+ "aliases": [],
1296
+ "args": {
1297
+ "ref": {
1298
+ "description": "Chrome Web Store link or extension id",
1299
+ "name": "ref",
1300
+ "required": false
1301
+ }
1302
+ },
1303
+ "description": "Install a Chrome extension into the onboarding browser by Web Store link or id",
1304
+ "examples": [
1305
+ "$ sk extension add fmkadmapgofadopljbjfkapdkoienihi",
1306
+ "$ sk extension add https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi",
1307
+ "$ sk extension add"
1308
+ ],
1309
+ "flags": {},
1310
+ "hasDynamicHelp": false,
1311
+ "hiddenAliases": [],
1312
+ "id": "extension:add",
1313
+ "pluginAlias": "@speedkit/cli",
1314
+ "pluginName": "@speedkit/cli",
1315
+ "pluginType": "core",
1316
+ "strict": true,
1317
+ "enableJsonFlag": false,
1318
+ "isESM": true,
1319
+ "relativePath": [
1320
+ "dist",
1321
+ "commands",
1322
+ "extension",
1323
+ "add.js"
1324
+ ]
1325
+ },
1326
+ "extension:devtools": {
1327
+ "aliases": [],
1328
+ "args": {},
1329
+ "description": "Install the integration-devtools extension for the onboarding browser, or update it to the latest release",
1330
+ "examples": [
1331
+ "$ sk extension devtools",
1332
+ "$ sk extension devtools --force"
1333
+ ],
1334
+ "flags": {
1335
+ "force": {
1336
+ "description": "reinstall the latest release even when it is up to date",
1337
+ "name": "force",
1338
+ "allowNo": false,
1339
+ "type": "boolean"
1340
+ }
1341
+ },
1342
+ "hasDynamicHelp": false,
1343
+ "hiddenAliases": [],
1344
+ "id": "extension:devtools",
1345
+ "pluginAlias": "@speedkit/cli",
1346
+ "pluginName": "@speedkit/cli",
1347
+ "pluginType": "core",
1348
+ "strict": true,
1349
+ "enableJsonFlag": false,
1350
+ "isESM": true,
1351
+ "relativePath": [
1352
+ "dist",
1353
+ "commands",
1354
+ "extension",
1355
+ "devtools.js"
1356
+ ]
1357
+ },
1358
+ "extension:list": {
1359
+ "aliases": [],
1360
+ "args": {},
1361
+ "description": "List Chrome extensions managed by the setup wizard",
1362
+ "examples": [
1363
+ "$ sk extension list"
1364
+ ],
1365
+ "flags": {},
1366
+ "hasDynamicHelp": false,
1367
+ "hiddenAliases": [],
1368
+ "id": "extension:list",
1369
+ "pluginAlias": "@speedkit/cli",
1370
+ "pluginName": "@speedkit/cli",
1371
+ "pluginType": "core",
1372
+ "strict": true,
1373
+ "enableJsonFlag": false,
1374
+ "isESM": true,
1375
+ "relativePath": [
1376
+ "dist",
1377
+ "commands",
1378
+ "extension",
1379
+ "list.js"
1380
+ ]
1381
+ },
1382
+ "extension:remove": {
1383
+ "aliases": [],
1384
+ "args": {
1385
+ "ref": {
1386
+ "description": "Chrome Web Store link or extension id",
1387
+ "name": "ref",
1388
+ "required": false
1389
+ }
1390
+ },
1391
+ "description": "Remove a managed Chrome extension",
1392
+ "examples": [
1393
+ "$ sk extension remove",
1394
+ "$ sk extension remove <id>"
1395
+ ],
1396
+ "flags": {},
1397
+ "hasDynamicHelp": false,
1398
+ "hiddenAliases": [],
1399
+ "id": "extension:remove",
1400
+ "pluginAlias": "@speedkit/cli",
1401
+ "pluginName": "@speedkit/cli",
1402
+ "pluginType": "core",
1403
+ "strict": true,
1404
+ "enableJsonFlag": false,
1405
+ "isESM": true,
1406
+ "relativePath": [
1407
+ "dist",
1408
+ "commands",
1409
+ "extension",
1410
+ "remove.js"
1411
+ ]
1412
+ },
1413
+ "extension:update": {
1414
+ "aliases": [],
1415
+ "args": {},
1416
+ "description": "Check managed Chrome extensions for updates and install them",
1417
+ "examples": [
1418
+ "$ sk extension update"
1419
+ ],
1420
+ "flags": {},
1421
+ "hasDynamicHelp": false,
1422
+ "hiddenAliases": [],
1423
+ "id": "extension:update",
1424
+ "pluginAlias": "@speedkit/cli",
1425
+ "pluginName": "@speedkit/cli",
1426
+ "pluginType": "core",
1427
+ "strict": true,
1428
+ "enableJsonFlag": false,
1429
+ "isESM": true,
1430
+ "relativePath": [
1431
+ "dist",
1432
+ "commands",
1433
+ "extension",
1434
+ "update.js"
1435
+ ]
1436
+ },
1294
1437
  "query:parameter": {
1295
1438
  "aliases": [
1296
1439
  "build-parameter-query"
@@ -1601,150 +1744,7 @@
1601
1744
  "query",
1602
1745
  "prewarm.js"
1603
1746
  ]
1604
- },
1605
- "extension:add": {
1606
- "aliases": [],
1607
- "args": {
1608
- "ref": {
1609
- "description": "Chrome Web Store link or extension id",
1610
- "name": "ref",
1611
- "required": false
1612
- }
1613
- },
1614
- "description": "Install a Chrome extension into the onboarding browser by Web Store link or id",
1615
- "examples": [
1616
- "$ sk extension add fmkadmapgofadopljbjfkapdkoienihi",
1617
- "$ sk extension add https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi",
1618
- "$ sk extension add"
1619
- ],
1620
- "flags": {},
1621
- "hasDynamicHelp": false,
1622
- "hiddenAliases": [],
1623
- "id": "extension:add",
1624
- "pluginAlias": "@speedkit/cli",
1625
- "pluginName": "@speedkit/cli",
1626
- "pluginType": "core",
1627
- "strict": true,
1628
- "enableJsonFlag": false,
1629
- "isESM": true,
1630
- "relativePath": [
1631
- "dist",
1632
- "commands",
1633
- "extension",
1634
- "add.js"
1635
- ]
1636
- },
1637
- "extension:devtools": {
1638
- "aliases": [],
1639
- "args": {},
1640
- "description": "Install the integration-devtools extension for the onboarding browser, or update it to the latest release",
1641
- "examples": [
1642
- "$ sk extension devtools",
1643
- "$ sk extension devtools --force"
1644
- ],
1645
- "flags": {
1646
- "force": {
1647
- "description": "reinstall the latest release even when it is up to date",
1648
- "name": "force",
1649
- "allowNo": false,
1650
- "type": "boolean"
1651
- }
1652
- },
1653
- "hasDynamicHelp": false,
1654
- "hiddenAliases": [],
1655
- "id": "extension:devtools",
1656
- "pluginAlias": "@speedkit/cli",
1657
- "pluginName": "@speedkit/cli",
1658
- "pluginType": "core",
1659
- "strict": true,
1660
- "enableJsonFlag": false,
1661
- "isESM": true,
1662
- "relativePath": [
1663
- "dist",
1664
- "commands",
1665
- "extension",
1666
- "devtools.js"
1667
- ]
1668
- },
1669
- "extension:list": {
1670
- "aliases": [],
1671
- "args": {},
1672
- "description": "List Chrome extensions managed by the setup wizard",
1673
- "examples": [
1674
- "$ sk extension list"
1675
- ],
1676
- "flags": {},
1677
- "hasDynamicHelp": false,
1678
- "hiddenAliases": [],
1679
- "id": "extension:list",
1680
- "pluginAlias": "@speedkit/cli",
1681
- "pluginName": "@speedkit/cli",
1682
- "pluginType": "core",
1683
- "strict": true,
1684
- "enableJsonFlag": false,
1685
- "isESM": true,
1686
- "relativePath": [
1687
- "dist",
1688
- "commands",
1689
- "extension",
1690
- "list.js"
1691
- ]
1692
- },
1693
- "extension:remove": {
1694
- "aliases": [],
1695
- "args": {
1696
- "ref": {
1697
- "description": "Chrome Web Store link or extension id",
1698
- "name": "ref",
1699
- "required": false
1700
- }
1701
- },
1702
- "description": "Remove a managed Chrome extension",
1703
- "examples": [
1704
- "$ sk extension remove",
1705
- "$ sk extension remove <id>"
1706
- ],
1707
- "flags": {},
1708
- "hasDynamicHelp": false,
1709
- "hiddenAliases": [],
1710
- "id": "extension:remove",
1711
- "pluginAlias": "@speedkit/cli",
1712
- "pluginName": "@speedkit/cli",
1713
- "pluginType": "core",
1714
- "strict": true,
1715
- "enableJsonFlag": false,
1716
- "isESM": true,
1717
- "relativePath": [
1718
- "dist",
1719
- "commands",
1720
- "extension",
1721
- "remove.js"
1722
- ]
1723
- },
1724
- "extension:update": {
1725
- "aliases": [],
1726
- "args": {},
1727
- "description": "Check managed Chrome extensions for updates and install them",
1728
- "examples": [
1729
- "$ sk extension update"
1730
- ],
1731
- "flags": {},
1732
- "hasDynamicHelp": false,
1733
- "hiddenAliases": [],
1734
- "id": "extension:update",
1735
- "pluginAlias": "@speedkit/cli",
1736
- "pluginName": "@speedkit/cli",
1737
- "pluginType": "core",
1738
- "strict": true,
1739
- "enableJsonFlag": false,
1740
- "isESM": true,
1741
- "relativePath": [
1742
- "dist",
1743
- "commands",
1744
- "extension",
1745
- "update.js"
1746
- ]
1747
1747
  }
1748
1748
  },
1749
- "version": "4.37.0"
1749
+ "version": "4.38.0"
1750
1750
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.37.0",
4
+ "version": "4.38.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"