@zeroheight/adoption-cli 3.0.2 → 3.1.1-rc.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 (74) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/cli.d.ts +8 -5
  3. package/dist/cli.js +12924 -36
  4. package/package.json +11 -6
  5. package/dist/ast/analyze.d.ts +0 -50
  6. package/dist/ast/analyze.js +0 -247
  7. package/dist/ast/parser.d.ts +0 -13
  8. package/dist/ast/parser.js +0 -14
  9. package/dist/commands/analyze.d.ts +0 -16
  10. package/dist/commands/analyze.js +0 -53
  11. package/dist/commands/analyze.utils.d.ts +0 -27
  12. package/dist/commands/analyze.utils.js +0 -204
  13. package/dist/commands/auth.d.ts +0 -9
  14. package/dist/commands/auth.js +0 -28
  15. package/dist/commands/monitor-repo.d.ts +0 -10
  16. package/dist/commands/monitor-repo.js +0 -42
  17. package/dist/commands/monitor-repo.utils.d.ts +0 -31
  18. package/dist/commands/monitor-repo.utils.js +0 -81
  19. package/dist/commands/track-package.d.ts +0 -9
  20. package/dist/commands/track-package.js +0 -41
  21. package/dist/commands/track-package.utils.d.ts +0 -25
  22. package/dist/commands/track-package.utils.js +0 -82
  23. package/dist/common/api.d.ts +0 -113
  24. package/dist/common/api.js +0 -174
  25. package/dist/common/config.d.ts +0 -14
  26. package/dist/common/config.js +0 -41
  27. package/dist/common/errors.d.ts +0 -15
  28. package/dist/common/errors.js +0 -26
  29. package/dist/common/logging.d.ts +0 -4
  30. package/dist/common/logging.js +0 -26
  31. package/dist/common/types/package-file.d.ts +0 -13
  32. package/dist/common/types/package-file.js +0 -1
  33. package/dist/components/analyze/analyze.d.ts +0 -14
  34. package/dist/components/analyze/analyze.js +0 -428
  35. package/dist/components/analyze/non-interactive-analyze.d.ts +0 -16
  36. package/dist/components/analyze/non-interactive-analyze.js +0 -164
  37. package/dist/components/auth/auth.d.ts +0 -7
  38. package/dist/components/auth/auth.js +0 -119
  39. package/dist/components/auth/credentials-already-exists.d.ts +0 -13
  40. package/dist/components/auth/credentials-already-exists.js +0 -16
  41. package/dist/components/auth/credentials-preview.d.ts +0 -10
  42. package/dist/components/auth/credentials-preview.js +0 -20
  43. package/dist/components/auth/no-credentials-onboarding.d.ts +0 -8
  44. package/dist/components/auth/no-credentials-onboarding.js +0 -62
  45. package/dist/components/color-usage-table.d.ts +0 -7
  46. package/dist/components/color-usage-table.js +0 -38
  47. package/dist/components/help-info.d.ts +0 -5
  48. package/dist/components/help-info.js +0 -24
  49. package/dist/components/latest-version-info.d.ts +0 -9
  50. package/dist/components/latest-version-info.js +0 -27
  51. package/dist/components/monitor-repo/monitor-repo.d.ts +0 -2
  52. package/dist/components/monitor-repo/monitor-repo.js +0 -9
  53. package/dist/components/monitor-repo/non-interactive-monitor-repo.d.ts +0 -7
  54. package/dist/components/monitor-repo/non-interactive-monitor-repo.js +0 -127
  55. package/dist/components/repo-name-prompt.d.ts +0 -8
  56. package/dist/components/repo-name-prompt.js +0 -97
  57. package/dist/components/track-package/non-interactive-track-package.d.ts +0 -5
  58. package/dist/components/track-package/non-interactive-track-package.js +0 -117
  59. package/dist/components/track-package/track-package.d.ts +0 -2
  60. package/dist/components/track-package/track-package.js +0 -206
  61. package/dist/components/ui/confirm-input.d.ts +0 -10
  62. package/dist/components/ui/confirm-input.js +0 -10
  63. package/dist/components/ui/continue-prompt.d.ts +0 -6
  64. package/dist/components/ui/continue-prompt.js +0 -16
  65. package/dist/components/usage-table.d.ts +0 -7
  66. package/dist/components/usage-table.js +0 -14
  67. package/dist/lockfile-parsers/lock-parser.d.ts +0 -9
  68. package/dist/lockfile-parsers/lock-parser.js +0 -5
  69. package/dist/lockfile-parsers/npm-lock-parser.d.ts +0 -6
  70. package/dist/lockfile-parsers/npm-lock-parser.js +0 -54
  71. package/dist/lockfile-parsers/pnpm-lock-parser.d.ts +0 -6
  72. package/dist/lockfile-parsers/pnpm-lock-parser.js +0 -51
  73. package/dist/lockfile-parsers/yarn-lock-parser.d.ts +0 -6
  74. package/dist/lockfile-parsers/yarn-lock-parser.js +0 -70
@@ -1,174 +0,0 @@
1
- import { IncorrectScopeError, MaxRetriesError, UnauthorizedError, UnknownError, } from "./errors.js";
2
- import logger from "./logging.js";
3
- const API_PATH = "/open_api/v2";
4
- export var ResponseStatus;
5
- (function (ResponseStatus) {
6
- ResponseStatus["Success"] = "success";
7
- ResponseStatus["Error"] = "error";
8
- ResponseStatus["Fail"] = "fail";
9
- })(ResponseStatus || (ResponseStatus = {}));
10
- export function getZeroheightURL() {
11
- if (process.env["NODE_ENV"] === "dev") {
12
- return new URL("https://zeroheight.dev");
13
- }
14
- else {
15
- return new URL("https://zeroheight.com");
16
- }
17
- }
18
- export async function submitPackageDetails(name, path, version, aliases, credentials) {
19
- return post("/design_system_packages", {
20
- name,
21
- path,
22
- latest_version: version,
23
- aliases,
24
- }, credentials);
25
- }
26
- export async function submitMonitoredRepoDetails(name, version, lockfilePath, packages, credentials) {
27
- return post("/monitored_repositories", {
28
- name,
29
- lock_file_path: lockfilePath,
30
- packages,
31
- version,
32
- }, credentials);
33
- }
34
- export async function submitComponentUsageData(usage, repoName, credentials) {
35
- return post("/component_usages", {
36
- repo_name: repoName,
37
- usage: transformUsageByName(usage),
38
- }, credentials);
39
- }
40
- export async function submitTokenLiteralUsageData(usage, repoName, credentials) {
41
- return post("/token_literal_usages", {
42
- token_literal_usage: {
43
- repo_name: repoName,
44
- usage: transformTokenLiteralUsageByName(usage),
45
- },
46
- }, credentials);
47
- }
48
- export async function getExistingRepoNames(credentials) {
49
- return get("/component_usages/repo_names", credentials);
50
- }
51
- export async function getAuthDetails(credentials) {
52
- return get("/auth_tokens", credentials);
53
- }
54
- async function get(path, credentials) {
55
- return request(path, credentials, {
56
- method: "GET",
57
- });
58
- }
59
- async function post(path, body, credentials) {
60
- return request(path, credentials, {
61
- method: "POST",
62
- body: JSON.stringify(body),
63
- });
64
- }
65
- async function sleep(ms) {
66
- return new Promise((resolve) => setTimeout(resolve, ms));
67
- }
68
- async function request(path, credentials, init) {
69
- const url = getZeroheightURL();
70
- url.pathname = API_PATH + path;
71
- if (process.env["NODE_ENV"] === "dev") {
72
- process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
73
- }
74
- const maxRetries = 3;
75
- let retries = 0;
76
- while (retries < maxRetries) {
77
- logger.info({ request: { url: url.toString(), init, retries } }, "Making API request");
78
- const response = await fetch(url, {
79
- ...init,
80
- headers: {
81
- "X-API-CLIENT-NAME": "cli",
82
- "X-API-CLIENT": credentials.client,
83
- "X-API-KEY": credentials.token,
84
- "Content-Type": "application/json",
85
- },
86
- });
87
- if (response.status === 401) {
88
- logger.error({ response: { status: response.status, body: await response.text() } }, "Unauthorized response from API");
89
- throw new UnauthorizedError();
90
- }
91
- else if (response.status === 429) {
92
- retries++;
93
- const responseData = await response.json();
94
- const waitTime = responseData.data.reset_time * 1000 - Date.now();
95
- logger.info(`Rate limited, waiting for ${waitTime}ms`);
96
- await sleep(waitTime);
97
- continue;
98
- }
99
- else if (response.status < 200 || response.status >= 300) {
100
- logger.error({ response: { status: response.status, body: await response.text() } }, "API request failed");
101
- if (response.status === 403) {
102
- throw new IncorrectScopeError();
103
- }
104
- else {
105
- throw new UnknownError();
106
- }
107
- }
108
- const responseJson = await response.json();
109
- logger.info({ response: { status: response.status, body: responseJson } }, "API response");
110
- return responseJson;
111
- }
112
- throw new MaxRetriesError();
113
- }
114
- export function mergeUsageProps(newProps, currentProps) {
115
- if (!currentProps)
116
- return newProps;
117
- if (!newProps)
118
- return currentProps;
119
- const props = Array.from(new Set([...Object.keys(currentProps), ...Object.keys(newProps)]));
120
- const mergedProps = {};
121
- props.forEach((prop) => {
122
- const existingProp = currentProps[prop] ?? {};
123
- const newProp = newProps[prop];
124
- const mergedValues = [
125
- ...(existingProp?.values ?? []),
126
- ...(newProp?.values ?? []),
127
- ];
128
- mergedProps[prop] = {
129
- type: Array.from(new Set([...(existingProp.type ?? []), ...(newProp?.type ?? [])])),
130
- count: mergedValues.length,
131
- values: mergedValues,
132
- };
133
- });
134
- return mergedProps;
135
- }
136
- /**
137
- * Transform usage map grouped by file into usage map grouped by component
138
- */
139
- function transformUsageByName(usage) {
140
- const transformedUsageMap = new Map();
141
- for (const [file, rawUsage] of usage) {
142
- for (const { count, package: packageName, name, props } of rawUsage) {
143
- const key = `package:${packageName} name:${name}`;
144
- const currentValue = transformedUsageMap.get(key);
145
- const newFileList = [...(currentValue?.files ?? []), file]; // Add file to list
146
- transformedUsageMap.set(key, {
147
- name: currentValue?.name ?? name,
148
- files: Array.from(new Set(newFileList)), // Ensure unique file paths
149
- count: count + (currentValue?.count ?? 0),
150
- package: packageName,
151
- props: mergeUsageProps(props, currentValue?.props ?? {}),
152
- });
153
- }
154
- }
155
- return Array.from(transformedUsageMap.values());
156
- }
157
- function transformTokenLiteralUsageByName(usage) {
158
- const transformedUsageMap = new Map();
159
- for (const [file, { hex, rgb, hsla }] of usage) {
160
- // These values shouldn't collide as they're all different notations and types
161
- const values = [...hex, ...rgb, ...hsla];
162
- for (const colorValue of values) {
163
- const currentValue = transformedUsageMap.get(colorValue);
164
- const newFileList = [...(currentValue?.files ?? []), file];
165
- transformedUsageMap.set(colorValue, {
166
- value: colorValue,
167
- type: "color",
168
- files: newFileList,
169
- count: (currentValue?.count ?? 0) + 1,
170
- });
171
- }
172
- }
173
- return Array.from(transformedUsageMap.values());
174
- }
@@ -1,14 +0,0 @@
1
- export interface Credentials {
2
- token: string;
3
- client: string;
4
- }
5
- export interface Config extends Credentials {
6
- repoNames: Record<string, string>;
7
- }
8
- export declare function configPath(): string;
9
- /**
10
- * Read the credentials from the user's home directory
11
- * @returns access token and client id or null
12
- */
13
- export declare function readConfig(): Promise<Config | null>;
14
- export declare function writeConfig(newValues: Partial<Config>): Promise<void>;
@@ -1,41 +0,0 @@
1
- import { readFile, writeFile } from "fs/promises";
2
- import { homedir } from "os";
3
- import path from "path";
4
- export function configPath() {
5
- return path.join(homedir(), ".zeroheight-config.json");
6
- }
7
- /**
8
- * Read the credentials from the user's home directory
9
- * @returns access token and client id or null
10
- */
11
- export async function readConfig() {
12
- try {
13
- const rawData = await readFile(configPath(), "utf8");
14
- const { token, client, repoNames = {} } = JSON.parse(rawData);
15
- return { token, client, repoNames };
16
- }
17
- catch (e) {
18
- const client = process.env["ZEROHEIGHT_CLIENT_ID"];
19
- const token = process.env["ZEROHEIGHT_ACCESS_TOKEN"];
20
- if (client && token) {
21
- return { token, client, repoNames: {} };
22
- }
23
- return null;
24
- }
25
- }
26
- export async function writeConfig(newValues) {
27
- const config = (await readConfig()) ??
28
- {
29
- repoNames: {},
30
- };
31
- // TODO: if we have a more complex config, we should use a deep merge here
32
- const payload = JSON.stringify({
33
- ...config,
34
- ...newValues,
35
- repoNames: {
36
- ...config.repoNames,
37
- ...(newValues.repoNames ?? {}),
38
- },
39
- });
40
- return writeFile(configPath(), payload);
41
- }
@@ -1,15 +0,0 @@
1
- export declare class ApiError extends Error {
2
- constructor(message: string);
3
- }
4
- export declare class UnauthorizedError extends ApiError {
5
- constructor();
6
- }
7
- export declare class IncorrectScopeError extends ApiError {
8
- constructor();
9
- }
10
- export declare class UnknownError extends ApiError {
11
- constructor();
12
- }
13
- export declare class MaxRetriesError extends ApiError {
14
- constructor();
15
- }
@@ -1,26 +0,0 @@
1
- export class ApiError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = "ApiError";
5
- }
6
- }
7
- export class UnauthorizedError extends ApiError {
8
- constructor() {
9
- super("Unauthorized. Please reset your authentication by running: npx @zeroheight/adoption-cli auth");
10
- }
11
- }
12
- export class IncorrectScopeError extends ApiError {
13
- constructor() {
14
- super("The authentication token used does not have the correct scope. \n\nPlease create a new authentication token with the 'Adoption' scopes and then reset your authentication by running: npx @zeroheight/adoption-cli auth");
15
- }
16
- }
17
- export class UnknownError extends ApiError {
18
- constructor() {
19
- super("An unknown error occurred while calling the zeroheight API");
20
- }
21
- }
22
- export class MaxRetriesError extends ApiError {
23
- constructor() {
24
- super("Max retries exceeded while calling the zeroheight API");
25
- }
26
- }
@@ -1,4 +0,0 @@
1
- declare const logger: import("pino").Logger<never, boolean>;
2
- export declare function setFileStream(path: string): void;
3
- export declare function setStdErrStream(): void;
4
- export default logger;
@@ -1,26 +0,0 @@
1
- import { pino } from "pino";
2
- import { createWriteStream } from "fs";
3
- import pretty from "pino-pretty";
4
- const streams = [];
5
- const loggerOptions = {
6
- base: null,
7
- level: "warn",
8
- timestamp: pino.stdTimeFunctions.isoTime,
9
- formatters: {
10
- level: (label) => {
11
- return { level: label.toUpperCase() };
12
- },
13
- },
14
- };
15
- const multistream = pino.multistream(streams);
16
- const logger = pino(loggerOptions, multistream);
17
- export function setFileStream(path) {
18
- multistream.add({ stream: createWriteStream(path, { flags: "a" }) });
19
- }
20
- export function setStdErrStream() {
21
- multistream.add({
22
- stream: pretty({ destination: process.stderr, ignore: "pid,hostname" }),
23
- level: "error",
24
- });
25
- }
26
- export default logger;
@@ -1,13 +0,0 @@
1
- /**
2
- * Sparse package.json interface, only containing properties we care about
3
- */
4
- export interface PackageFile {
5
- name: string;
6
- path: string;
7
- version: string;
8
- exports?: Record<string, Partial<{
9
- import: string;
10
- require: string;
11
- types: string;
12
- }> | string>;
13
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import { RawColorUsageMap, RawComponentUsageMap } from "../../commands/analyze.js";
3
- export interface AnalyzeProps {
4
- onAnalyzeFiles: () => Promise<{
5
- errorFile: string | null;
6
- usage: RawComponentUsageMap;
7
- }>;
8
- onAnalyzeColorUsage: () => Promise<{
9
- errorFile: string | null;
10
- usage: RawColorUsageMap;
11
- }>;
12
- repoName?: string;
13
- }
14
- export default function Analyze({ onAnalyzeFiles, onAnalyzeColorUsage, repoName, }: AnalyzeProps): React.JSX.Element;