@servicetitan/startup 39.1.0 → 39.2.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 (96) hide show
  1. package/dist/cli/commands/mfe-list.d.ts +0 -2
  2. package/dist/cli/commands/mfe-list.d.ts.map +1 -1
  3. package/dist/cli/commands/mfe-list.js +4 -30
  4. package/dist/cli/commands/mfe-list.js.map +1 -1
  5. package/dist/cli/commands/mfe-package-clean.js +1 -2
  6. package/dist/cli/commands/mfe-package-clean.js.map +1 -1
  7. package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
  8. package/dist/cli/commands/mfe-package-publish.js +7 -5
  9. package/dist/cli/commands/mfe-package-publish.js.map +1 -1
  10. package/dist/cli/commands/mfe-package-rollback.d.ts.map +1 -1
  11. package/dist/cli/commands/mfe-package-rollback.js +5 -3
  12. package/dist/cli/commands/mfe-package-rollback.js.map +1 -1
  13. package/dist/cli/commands/mfe-publish.d.ts +1 -0
  14. package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
  15. package/dist/cli/commands/mfe-publish.js +14 -12
  16. package/dist/cli/commands/mfe-publish.js.map +1 -1
  17. package/dist/cli/commands/registry/command-registry.d.ts +13 -4
  18. package/dist/cli/commands/registry/command-registry.d.ts.map +1 -1
  19. package/dist/cli/commands/registry/mfe-list.d.ts +2 -1
  20. package/dist/cli/commands/registry/mfe-list.d.ts.map +1 -1
  21. package/dist/cli/commands/registry/mfe-list.js +3 -1
  22. package/dist/cli/commands/registry/mfe-list.js.map +1 -1
  23. package/dist/cli/commands/registry/mfe-package-clean.d.ts +2 -1
  24. package/dist/cli/commands/registry/mfe-package-clean.d.ts.map +1 -1
  25. package/dist/cli/commands/registry/mfe-package-clean.js +4 -2
  26. package/dist/cli/commands/registry/mfe-package-clean.js.map +1 -1
  27. package/dist/cli/commands/registry/mfe-package-publish.d.ts +2 -1
  28. package/dist/cli/commands/registry/mfe-package-publish.d.ts.map +1 -1
  29. package/dist/cli/commands/registry/mfe-package-publish.js +4 -2
  30. package/dist/cli/commands/registry/mfe-package-publish.js.map +1 -1
  31. package/dist/cli/commands/registry/mfe-package-rollback.d.ts +2 -1
  32. package/dist/cli/commands/registry/mfe-package-rollback.d.ts.map +1 -1
  33. package/dist/cli/commands/registry/mfe-package-rollback.js +4 -2
  34. package/dist/cli/commands/registry/mfe-package-rollback.js.map +1 -1
  35. package/dist/cli/commands/registry/upload-sourcemaps.d.ts +5 -0
  36. package/dist/cli/commands/registry/upload-sourcemaps.d.ts.map +1 -1
  37. package/dist/cli/commands/registry/upload-sourcemaps.js +5 -0
  38. package/dist/cli/commands/registry/upload-sourcemaps.js.map +1 -1
  39. package/dist/cli/commands/review/types.js.map +1 -1
  40. package/dist/cli/commands/upload-sourcemaps.d.ts.map +1 -1
  41. package/dist/cli/commands/upload-sourcemaps.js +4 -7
  42. package/dist/cli/commands/upload-sourcemaps.js.map +1 -1
  43. package/dist/cli/commands/utils/get-mfe-registry.d.ts +4 -0
  44. package/dist/cli/commands/utils/get-mfe-registry.d.ts.map +1 -0
  45. package/dist/cli/commands/utils/get-mfe-registry.js +28 -0
  46. package/dist/cli/commands/utils/get-mfe-registry.js.map +1 -0
  47. package/dist/cli/commands/utils/get-unpkg-host.d.ts +2 -0
  48. package/dist/cli/commands/utils/get-unpkg-host.d.ts.map +1 -0
  49. package/dist/cli/commands/utils/get-unpkg-host.js +18 -0
  50. package/dist/cli/commands/utils/get-unpkg-host.js.map +1 -0
  51. package/dist/cli/commands/utils/index.d.ts +3 -1
  52. package/dist/cli/commands/utils/index.d.ts.map +1 -1
  53. package/dist/cli/commands/utils/index.js +3 -1
  54. package/dist/cli/commands/utils/index.js.map +1 -1
  55. package/dist/cli/commands/utils/login.d.ts +2 -0
  56. package/dist/cli/commands/utils/login.d.ts.map +1 -0
  57. package/dist/cli/commands/utils/login.js +56 -0
  58. package/dist/cli/commands/utils/login.js.map +1 -0
  59. package/dist/cli/commands/utils/purge-cache.d.ts.map +1 -1
  60. package/dist/cli/commands/utils/purge-cache.js +2 -4
  61. package/dist/cli/commands/utils/purge-cache.js.map +1 -1
  62. package/dist/cli/index.js +4 -1
  63. package/dist/cli/index.js.map +1 -1
  64. package/package.json +15 -16
  65. package/src/cli/commands/__tests__/mfe-list.test.ts +25 -56
  66. package/src/cli/commands/__tests__/mfe-package-clean.test.ts +6 -0
  67. package/src/cli/commands/__tests__/mfe-package-publish.test.ts +52 -47
  68. package/src/cli/commands/__tests__/mfe-package-rollback.test.ts +4 -2
  69. package/src/cli/commands/__tests__/mfe-publish.test.ts +51 -14
  70. package/src/cli/commands/__tests__/upload-sourcemaps.test.ts +27 -13
  71. package/src/cli/commands/mfe-list.ts +7 -36
  72. package/src/cli/commands/mfe-package-clean.ts +2 -2
  73. package/src/cli/commands/mfe-package-publish.ts +10 -8
  74. package/src/cli/commands/mfe-package-rollback.ts +6 -5
  75. package/src/cli/commands/mfe-publish.ts +17 -16
  76. package/src/cli/commands/registry/mfe-list.ts +6 -1
  77. package/src/cli/commands/registry/mfe-package-clean.ts +7 -1
  78. package/src/cli/commands/registry/mfe-package-publish.ts +7 -1
  79. package/src/cli/commands/registry/mfe-package-rollback.ts +4 -2
  80. package/src/cli/commands/registry/upload-sourcemaps.ts +1 -0
  81. package/src/cli/commands/upload-sourcemaps.ts +4 -7
  82. package/src/cli/commands/utils/__tests__/get-mfe-registry.test.ts +24 -0
  83. package/src/cli/commands/utils/__tests__/get-unpkg-host.test.ts +32 -0
  84. package/src/cli/commands/utils/__tests__/login.test.ts +122 -0
  85. package/src/cli/commands/utils/__tests__/purge-cache.test.ts +17 -15
  86. package/src/cli/commands/utils/get-mfe-registry.ts +6 -0
  87. package/src/cli/commands/utils/get-unpkg-host.ts +8 -0
  88. package/src/cli/commands/utils/index.ts +3 -1
  89. package/src/cli/commands/utils/login.ts +38 -0
  90. package/src/cli/commands/utils/purge-cache.ts +2 -5
  91. package/src/cli/index.ts +2 -1
  92. package/dist/cli/commands/utils/constants.d.ts +0 -2
  93. package/dist/cli/commands/utils/constants.d.ts.map +0 -1
  94. package/dist/cli/commands/utils/constants.js +0 -13
  95. package/dist/cli/commands/utils/constants.js.map +0 -1
  96. package/src/cli/commands/utils/constants.ts +0 -1
@@ -1,40 +1,42 @@
1
1
  import { runCommandOutput } from '../../../utils';
2
+ import { getUnpkgHost } from '../get-unpkg-host';
2
3
  import { purgeCache } from '../purge-cache';
3
4
 
5
+ jest.mock('@servicetitan/install', () => ({ isCI: jest.fn() }));
4
6
  jest.mock('../../../utils', () => ({
5
7
  ...jest.requireActual('../../../utils'),
6
8
  runCommandOutput: jest.fn(),
7
9
  }));
10
+ jest.mock('../get-unpkg-host', () => ({
11
+ getUnpkgHost: jest.fn(),
12
+ }));
8
13
 
9
14
  describe(purgeCache.name, () => {
10
- let args: Parameters<typeof purgeCache>[0];
15
+ const unpkgHost = 'https://foo.com';
11
16
  const packageName = '@servicetitan/foo';
17
+ const registry = 'https://bar.com';
12
18
  const tag = 'prod';
19
+ let args: Parameters<typeof purgeCache>[0];
13
20
 
14
21
  beforeEach(() => {
15
22
  jest.clearAllMocks();
16
- args = { packageName, tag };
23
+ jest.mocked(getUnpkgHost).mockReturnValue(unpkgHost);
24
+ args = { packageName, registry, tag };
17
25
  });
18
26
 
19
27
  const subject = () => purgeCache(args);
20
28
 
21
- test('runs mfe-purge-cache with host "https://unpkg.servicetitan.com", package name and tag', () => {
29
+ test('fetches host for registry', () => {
22
30
  subject();
23
31
 
24
- expect(runCommandOutput).toHaveBeenCalledWith(
25
- `npx startup mfe-purge-cache --host https://unpkg.servicetitan.com --package-name ${packageName} --tag ${tag}`
26
- );
32
+ expect(getUnpkgHost).toHaveBeenCalledWith(registry);
27
33
  });
28
34
 
29
- describe('when registry is "https://verdaccio.st.dev"', () => {
30
- beforeEach(() => (args.registry = 'https://verdaccio.st.dev'));
31
-
32
- test('runs mfe-purge-cache with host "https://unpkg.st.dev"', () => {
33
- subject();
35
+ test('runs mfe-purge-cache', () => {
36
+ subject();
34
37
 
35
- expect(runCommandOutput).toHaveBeenCalledWith(
36
- expect.stringContaining(`--host https://unpkg.st.dev`)
37
- );
38
- });
38
+ expect(runCommandOutput).toHaveBeenCalledWith(
39
+ `npx startup mfe-purge-cache --host ${unpkgHost} --package-name ${packageName} --tag ${tag}`
40
+ );
39
41
  });
40
42
  });
@@ -0,0 +1,6 @@
1
+ export const PROD_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';
2
+ export const DEV_MFE_REGISTRY = 'https://verdaccio.st.dev';
3
+
4
+ export function getMfeRegistry(registry?: string): string {
5
+ return registry ?? PROD_MFE_REGISTRY;
6
+ }
@@ -0,0 +1,8 @@
1
+ import { DEV_MFE_REGISTRY, getMfeRegistry } from './get-mfe-registry';
2
+
3
+ const PROD_UNPKG_HOST = 'https://unpkg.servicetitan.com';
4
+ const DEV_UNPKG_HOST = 'https://unpkg.st.dev';
5
+
6
+ export function getUnpkgHost(registry?: string): string {
7
+ return getMfeRegistry(registry) === DEV_MFE_REGISTRY ? DEV_UNPKG_HOST : PROD_UNPKG_HOST;
8
+ }
@@ -1,3 +1,5 @@
1
1
  export * from './build-rollback-tag';
2
- export * from './constants';
2
+ export * from './get-mfe-registry';
3
+ export * from './get-unpkg-host';
4
+ export * from './login';
3
5
  export * from './purge-cache';
@@ -0,0 +1,38 @@
1
+ import { npmWhoAmI } from '@servicetitan/install';
2
+ import chalk from 'chalk';
3
+ import readline from 'readline/promises';
4
+ import { isTTY, runCommand } from '../../utils';
5
+ import { DEV_MFE_REGISTRY, PROD_MFE_REGISTRY } from './get-mfe-registry';
6
+
7
+ const OKTA_REGISTRIES: string[] = [PROD_MFE_REGISTRY, DEV_MFE_REGISTRY];
8
+
9
+ export async function login(registry: string) {
10
+ if (npmWhoAmI({ registry }) !== undefined) {
11
+ return;
12
+ }
13
+
14
+ if (!OKTA_REGISTRIES.includes(registry)) {
15
+ throw new Error(`Registry ${registry} is not recognized. Please log in manually.`);
16
+ }
17
+
18
+ const message = `This machine is not authorized to access ${registry}.`;
19
+ if (!isTTY()) {
20
+ throw new Error(message);
21
+ }
22
+
23
+ const answer = await ask(chalk.bold.cyan(`${message} Authorize? [Y/n] `));
24
+ if (answer && answer !== 'y') {
25
+ throw new Error('Not authorized');
26
+ }
27
+
28
+ await runCommand(`npx --yes verdaccio-okta-oauth@latest --registry=${registry}`, {
29
+ quiet: true,
30
+ });
31
+ }
32
+
33
+ async function ask(question: string) {
34
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
35
+ const answer = await rl.question(question);
36
+ rl.close();
37
+ return answer.trim().toLowerCase();
38
+ }
@@ -1,12 +1,9 @@
1
1
  import { runCommandOutput } from '../../utils';
2
-
3
- const DEV_MFE_REGISTRY = 'https://verdaccio.st.dev';
4
- const DEFAULT_UNPKG_HOST = 'https://unpkg.servicetitan.com';
5
- const DEV_UNPKG_HOST = 'https://unpkg.st.dev';
2
+ import { getUnpkgHost } from './get-unpkg-host';
6
3
 
7
4
  export function purgeCache(options: { packageName: string; registry?: string; tag: string }) {
8
5
  const { packageName, registry, tag } = options;
9
- const host = registry === DEV_MFE_REGISTRY ? DEV_UNPKG_HOST : DEFAULT_UNPKG_HOST;
6
+ const host = getUnpkgHost(registry);
10
7
  runCommandOutput(
11
8
  `npx startup mfe-purge-cache --host ${host} --package-name ${packageName} --tag ${tag}`
12
9
  );
package/src/cli/index.ts CHANGED
@@ -40,7 +40,8 @@ function addCommand(name: CommandName, y: typeof yargs) {
40
40
  const { description, options: { _, ...options } = {} } = entry;
41
41
  const nameWithArgs = name + (_?.description ? ` ${_.description}` : '');
42
42
  const groupedOptions = Object.entries(options).reduce((result, [key, value]) => {
43
- result[kebabCase(key)] = { group: 'Command Options:', ...value };
43
+ const suffix = /\W+$/.exec(key)?.[0] ?? ''; // fix for kebabCase dropping `\u00A0` suffixes
44
+ result[kebabCase(key) + suffix] = { group: 'Command Options:', ...value };
44
45
  return result;
45
46
  }, {} as CommandOptions);
46
47
  const handler = (argv: any) => handleCommand(name, argv);
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT_MFE_REGISTRY = "https://verdaccio.servicetitan.com";
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,uCAAuC,CAAC"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DEFAULT_MFE_REGISTRY", {
6
- enumerable: true,
7
- get: function() {
8
- return DEFAULT_MFE_REGISTRY;
9
- }
10
- });
11
- const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';
12
-
13
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cli/commands/utils/constants.ts"],"sourcesContent":["export const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';\n"],"names":["DEFAULT_MFE_REGISTRY"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,uBAAuB"}
@@ -1 +0,0 @@
1
- export const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';