@redocly/cli 1.28.5 → 1.30.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 (90) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/lib/__tests__/commands/push-region.test.js +3 -3
  3. package/lib/__tests__/utils.test.js +1 -0
  4. package/lib/auth/__tests__/device-flow.test.js +62 -0
  5. package/lib/auth/__tests__/oauth-client.test.js +93 -0
  6. package/lib/auth/device-flow.d.ts +26 -0
  7. package/lib/auth/device-flow.js +133 -0
  8. package/lib/auth/oauth-client.d.ts +14 -0
  9. package/lib/auth/oauth-client.js +93 -0
  10. package/lib/commands/auth.d.ts +13 -0
  11. package/lib/commands/auth.js +51 -0
  12. package/lib/commands/push.d.ts +1 -1
  13. package/lib/commands/push.js +4 -4
  14. package/lib/commands/split/index.js +4 -4
  15. package/lib/index.js +14 -15
  16. package/lib/otel.d.ts +10 -0
  17. package/lib/otel.js +47 -0
  18. package/lib/reunite/api/__tests__/domains.test.js +32 -0
  19. package/lib/{cms → reunite}/api/api-client.d.ts +9 -0
  20. package/lib/{cms → reunite}/api/api-client.js +2 -1
  21. package/lib/reunite/api/domains.d.ts +4 -0
  22. package/lib/reunite/api/domains.js +22 -0
  23. package/lib/reunite/commands/__tests__/push.test.d.ts +1 -0
  24. package/lib/reunite/commands/__tests__/utils.test.d.ts +1 -0
  25. package/lib/types.d.ts +4 -4
  26. package/lib/utils/miscellaneous.d.ts +5 -4
  27. package/lib/utils/miscellaneous.js +14 -14
  28. package/package.json +7 -2
  29. package/src/__tests__/commands/push-region.test.ts +2 -2
  30. package/src/__tests__/utils.test.ts +1 -0
  31. package/src/auth/__tests__/device-flow.test.ts +73 -0
  32. package/src/auth/__tests__/oauth-client.test.ts +117 -0
  33. package/src/auth/device-flow.ts +175 -0
  34. package/src/auth/oauth-client.ts +111 -0
  35. package/src/commands/auth.ts +66 -0
  36. package/src/commands/push.ts +3 -3
  37. package/src/commands/split/index.ts +9 -9
  38. package/src/index.ts +14 -15
  39. package/src/otel.ts +59 -0
  40. package/src/reunite/api/__tests__/domains.test.ts +41 -0
  41. package/src/{cms → reunite}/api/api-client.ts +1 -1
  42. package/src/reunite/api/domains.ts +23 -0
  43. package/src/types.ts +4 -3
  44. package/src/utils/miscellaneous.ts +20 -18
  45. package/tsconfig.tsbuildinfo +1 -1
  46. package/lib/cms/api/__tests__/domains.test.js +0 -13
  47. package/lib/cms/api/domains.d.ts +0 -1
  48. package/lib/cms/api/domains.js +0 -11
  49. package/lib/commands/login.d.ts +0 -9
  50. package/lib/commands/login.js +0 -23
  51. package/src/cms/api/__tests__/domains.test.ts +0 -15
  52. package/src/cms/api/domains.ts +0 -11
  53. package/src/commands/login.ts +0 -34
  54. /package/lib/{cms/api/__tests__/api-keys.test.d.ts → auth/__tests__/device-flow.test.d.ts} +0 -0
  55. /package/lib/{cms/api/__tests__/api.client.test.d.ts → auth/__tests__/oauth-client.test.d.ts} +0 -0
  56. /package/lib/{cms/api/__tests__/domains.test.d.ts → reunite/api/__tests__/api-keys.test.d.ts} +0 -0
  57. /package/lib/{cms → reunite}/api/__tests__/api-keys.test.js +0 -0
  58. /package/lib/{cms/commands/__tests__/push-status.test.d.ts → reunite/api/__tests__/api.client.test.d.ts} +0 -0
  59. /package/lib/{cms → reunite}/api/__tests__/api.client.test.js +0 -0
  60. /package/lib/{cms/commands/__tests__/push.test.d.ts → reunite/api/__tests__/domains.test.d.ts} +0 -0
  61. /package/lib/{cms → reunite}/api/api-keys.d.ts +0 -0
  62. /package/lib/{cms → reunite}/api/api-keys.js +0 -0
  63. /package/lib/{cms → reunite}/api/index.d.ts +0 -0
  64. /package/lib/{cms → reunite}/api/index.js +0 -0
  65. /package/lib/{cms → reunite}/api/types.d.ts +0 -0
  66. /package/lib/{cms → reunite}/api/types.js +0 -0
  67. /package/lib/{cms/commands/__tests__/utils.test.d.ts → reunite/commands/__tests__/push-status.test.d.ts} +0 -0
  68. /package/lib/{cms → reunite}/commands/__tests__/push-status.test.js +0 -0
  69. /package/lib/{cms → reunite}/commands/__tests__/push.test.js +0 -0
  70. /package/lib/{cms → reunite}/commands/__tests__/utils.test.js +0 -0
  71. /package/lib/{cms → reunite}/commands/push-status.d.ts +0 -0
  72. /package/lib/{cms → reunite}/commands/push-status.js +0 -0
  73. /package/lib/{cms → reunite}/commands/push.d.ts +0 -0
  74. /package/lib/{cms → reunite}/commands/push.js +0 -0
  75. /package/lib/{cms → reunite}/commands/utils.d.ts +0 -0
  76. /package/lib/{cms → reunite}/commands/utils.js +0 -0
  77. /package/lib/{cms → reunite}/utils.d.ts +0 -0
  78. /package/lib/{cms → reunite}/utils.js +0 -0
  79. /package/src/{cms → reunite}/api/__tests__/api-keys.test.ts +0 -0
  80. /package/src/{cms → reunite}/api/__tests__/api.client.test.ts +0 -0
  81. /package/src/{cms → reunite}/api/api-keys.ts +0 -0
  82. /package/src/{cms → reunite}/api/index.ts +0 -0
  83. /package/src/{cms → reunite}/api/types.ts +0 -0
  84. /package/src/{cms → reunite}/commands/__tests__/push-status.test.ts +0 -0
  85. /package/src/{cms → reunite}/commands/__tests__/push.test.ts +0 -0
  86. /package/src/{cms → reunite}/commands/__tests__/utils.test.ts +0 -0
  87. /package/src/{cms → reunite}/commands/push-status.ts +0 -0
  88. /package/src/{cms → reunite}/commands/push.ts +0 -0
  89. /package/src/{cms → reunite}/commands/utils.ts +0 -0
  90. /package/src/{cms → reunite}/utils.ts +0 -0
@@ -3,6 +3,7 @@ import { blue, gray, green, red, yellow } from 'colorette';
3
3
  import { performance } from 'perf_hooks';
4
4
  import * as glob from 'glob';
5
5
  import * as fs from 'fs';
6
+ import * as os from 'os';
6
7
  import * as readline from 'readline';
7
8
  import { Writable } from 'stream';
8
9
  import { execSync } from 'child_process';
@@ -28,7 +29,9 @@ import { deprecatedRefDocsSchema } from '@redocly/config/lib/reference-docs-conf
28
29
  import { outputExtensions } from '../types';
29
30
  import { version } from './update-version-notifier';
30
31
  import { DESTINATION_REGEX } from '../commands/push';
31
- import fetch, { DEFAULT_FETCH_TIMEOUT } from './fetch-with-timeout';
32
+ import { RedoclyOAuthClient } from '../auth/oauth-client';
33
+ import { getReuniteUrl } from '../reunite/api';
34
+ import { otelTelemetry } from '../otel';
32
35
 
33
36
  import type { Arguments } from 'yargs';
34
37
  import type {
@@ -546,6 +549,8 @@ export function cleanColors(input: string): string {
546
549
  return input.replace(/\x1b\[\d+m/g, '');
547
550
  }
548
551
 
552
+ otelTelemetry.init();
553
+
549
554
  export async function sendTelemetry(
550
555
  argv: Arguments | undefined,
551
556
  exit_code: ExitCode,
@@ -565,33 +570,29 @@ export async function sendTelemetry(
565
570
  } = argv;
566
571
  const event_time = new Date().toISOString();
567
572
  const redoclyClient = new RedoclyClient();
568
- const logged_in = redoclyClient.hasTokens();
573
+ const oauthClient = new RedoclyOAuthClient('redocly-cli', version);
574
+ const reuniteUrl = getReuniteUrl(argv.residency as string | undefined);
575
+ const logged_in = redoclyClient.hasTokens() || (await oauthClient.isAuthorized(reuniteUrl));
569
576
  const data: Analytics = {
570
577
  event: 'cli_command',
571
578
  event_time,
572
- logged_in,
573
- command,
574
- arguments: cleanArgs(args),
579
+ logged_in: logged_in ? 'yes' : 'no',
580
+ command: `${command}`,
581
+ arguments: JSON.stringify(cleanArgs(args)),
575
582
  node_version: process.version,
576
583
  npm_version: execSync('npm -v').toString().replace('\n', ''),
584
+ os_platform: os.platform(),
577
585
  version,
578
586
  exit_code,
579
587
  environment: process.env.REDOCLY_ENVIRONMENT,
580
588
  environment_ci: process.env.CI,
581
589
  raw_input: cleanRawInput(process.argv.slice(2)),
582
- has_config,
590
+ has_config: has_config ? 'yes' : 'no',
583
591
  spec_version,
584
592
  spec_keyword,
585
593
  spec_full_version,
586
594
  };
587
- await fetch(`https://api.redocly.com/registry/telemetry/cli`, {
588
- timeout: DEFAULT_FETCH_TIMEOUT,
589
- method: 'POST',
590
- headers: {
591
- 'content-type': 'application/json',
592
- },
593
- body: JSON.stringify(data),
594
- });
595
+ otelTelemetry.send(data.command, data);
595
596
  } catch (err) {
596
597
  // Do nothing.
597
598
  }
@@ -602,17 +603,18 @@ export type ExitCode = 0 | 1 | 2;
602
603
  export type Analytics = {
603
604
  event: string;
604
605
  event_time: string;
605
- logged_in: boolean;
606
- command: string | number;
607
- arguments: Record<string, unknown>;
606
+ logged_in: 'yes' | 'no';
607
+ command: string;
608
+ arguments: string;
608
609
  node_version: string;
609
610
  npm_version: string;
611
+ os_platform: string;
610
612
  version: string;
611
613
  exit_code: ExitCode;
612
614
  environment?: string;
613
615
  environment_ci?: string;
614
616
  raw_input: string;
615
- has_config?: boolean;
617
+ has_config?: 'yes' | 'no';
616
618
  spec_version?: string;
617
619
  spec_keyword?: string;
618
620
  spec_full_version?: string;