@invinite-org/invinite-data-cli 2.0.0 → 4.0.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.
- package/README.md +341 -374
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/claude-plugin/agents/invinite-data.md +59 -28
- package/claude-plugin/commands/analyze-earnings-call.md +15 -14
- package/claude-plugin/commands/analyze-filing.md +8 -7
- package/claude-plugin/commands/compare-companies.md +5 -5
- package/claude-plugin/commands/financial-research.md +9 -9
- package/claude-plugin/commands/ownership-review.md +6 -6
- package/claude-plugin/skills/invinite-data-cli/SKILL.md +466 -570
- package/dist/bin/invd.js +11 -2
- package/dist/bin/invd.js.map +1 -1
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +48 -29
- package/dist/src/cli.js.map +1 -1
- package/dist/src/client/api-client.d.ts +24 -24
- package/dist/src/client/api-client.js +52 -70
- package/dist/src/client/api-client.js.map +1 -1
- package/dist/src/client/pagination.d.ts +12 -11
- package/dist/src/client/pagination.js +47 -56
- package/dist/src/client/pagination.js.map +1 -1
- package/dist/src/commands/agent-setup.d.ts +21 -0
- package/dist/src/commands/agent-setup.js +112 -0
- package/dist/src/commands/agent-setup.js.map +1 -0
- package/dist/src/commands/api.d.ts +27 -0
- package/dist/src/commands/api.js +180 -0
- package/dist/src/commands/api.js.map +1 -0
- package/dist/src/commands/auth.d.ts +37 -0
- package/dist/src/commands/auth.js +336 -0
- package/dist/src/commands/auth.js.map +1 -0
- package/dist/src/commands/completion.d.ts +7 -0
- package/dist/src/commands/completion.js +115 -0
- package/dist/src/commands/completion.js.map +1 -0
- package/dist/src/commands/config.d.ts +4 -0
- package/dist/src/commands/config.js +85 -48
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/plugin.d.ts +8 -0
- package/dist/src/commands/plugin.js +8 -10
- package/dist/src/commands/plugin.js.map +1 -1
- package/dist/src/config/auth.d.ts +17 -1
- package/dist/src/config/auth.js +50 -36
- package/dist/src/config/auth.js.map +1 -1
- package/dist/src/config/config-manager.d.ts +56 -4
- package/dist/src/config/config-manager.js +173 -29
- package/dist/src/config/config-manager.js.map +1 -1
- package/dist/src/config/toml.d.ts +7 -0
- package/dist/src/config/toml.js +79 -0
- package/dist/src/config/toml.js.map +1 -0
- package/dist/src/examples.d.ts +22 -0
- package/dist/src/examples.js +56 -0
- package/dist/src/examples.js.map +1 -0
- package/dist/src/generated/cli-manifest.json +5583 -4916
- package/dist/src/hand-written-commands.d.ts +11 -41
- package/dist/src/hand-written-commands.js +7 -17
- package/dist/src/hand-written-commands.js.map +1 -1
- package/dist/src/output/jq.d.ts +15 -0
- package/dist/src/output/jq.js +234 -0
- package/dist/src/output/jq.js.map +1 -0
- package/dist/src/output/options.d.ts +29 -0
- package/dist/src/output/options.js +72 -0
- package/dist/src/output/options.js.map +1 -0
- package/dist/src/output/render.d.ts +54 -0
- package/dist/src/output/render.js +160 -0
- package/dist/src/output/render.js.map +1 -0
- package/dist/src/shared/errors.d.ts +59 -15
- package/dist/src/shared/errors.js +126 -38
- package/dist/src/shared/errors.js.map +1 -1
- package/dist/src/shared/prompt.d.ts +10 -0
- package/dist/src/shared/prompt.js +24 -0
- package/dist/src/shared/prompt.js.map +1 -0
- package/dist/src/shared/spinner.js +2 -1
- package/dist/src/shared/spinner.js.map +1 -1
- package/dist/src/spec-commands.d.ts +14 -6
- package/dist/src/spec-commands.js +454 -174
- package/dist/src/spec-commands.js.map +1 -1
- package/dist/src/spec-flags.d.ts +11 -6
- package/dist/src/spec-flags.js +14 -7
- package/dist/src/spec-flags.js.map +1 -1
- package/dist/src/spec-manifest.d.ts +416 -116
- package/dist/src/spec-manifest.js +44 -13
- package/dist/src/spec-manifest.js.map +1 -1
- package/dist/src/update-notifier.d.ts +9 -0
- package/dist/src/update-notifier.js +63 -0
- package/dist/src/update-notifier.js.map +1 -0
- package/package.json +2 -3
- package/dist/src/client/earnings-live.d.ts +0 -194
- package/dist/src/client/earnings-live.js +0 -300
- package/dist/src/client/earnings-live.js.map +0 -1
- package/dist/src/client/news-live.d.ts +0 -72
- package/dist/src/client/news-live.js +0 -120
- package/dist/src/client/news-live.js.map +0 -1
- package/dist/src/client/pdf.d.ts +0 -15
- package/dist/src/client/pdf.js +0 -15
- package/dist/src/client/pdf.js.map +0 -1
- package/dist/src/client/websocket-client.d.ts +0 -19
- package/dist/src/client/websocket-client.js +0 -174
- package/dist/src/client/websocket-client.js.map +0 -1
- package/dist/src/commands/earnings.d.ts +0 -16
- package/dist/src/commands/earnings.js +0 -464
- package/dist/src/commands/earnings.js.map +0 -1
- package/dist/src/commands/login.d.ts +0 -15
- package/dist/src/commands/login.js +0 -249
- package/dist/src/commands/login.js.map +0 -1
- package/dist/src/commands/news.d.ts +0 -2
- package/dist/src/commands/news.js +0 -69
- package/dist/src/commands/news.js.map +0 -1
- package/dist/src/commands/sec.d.ts +0 -47
- package/dist/src/commands/sec.js +0 -191
- package/dist/src/commands/sec.js.map +0 -1
- package/dist/src/commands/ws.d.ts +0 -33
- package/dist/src/commands/ws.js +0 -116
- package/dist/src/commands/ws.js.map +0 -1
- package/dist/src/formatters/json-formatter.d.ts +0 -1
- package/dist/src/formatters/json-formatter.js +0 -4
- package/dist/src/formatters/json-formatter.js.map +0 -1
- package/dist/src/formatters/table-formatter.d.ts +0 -4
- package/dist/src/formatters/table-formatter.js +0 -73
- package/dist/src/formatters/table-formatter.js.map +0 -1
- package/dist/src/formatters/time.d.ts +0 -2
- package/dist/src/formatters/time.js +0 -14
- package/dist/src/formatters/time.js.map +0 -1
- package/dist/src/shared/output.d.ts +0 -3
- package/dist/src/shared/output.js +0 -13
- package/dist/src/shared/output.js.map +0 -1
- package/dist/src/shared/readiness.d.ts +0 -4
- package/dist/src/shared/readiness.js +0 -60
- package/dist/src/shared/readiness.js.map +0 -1
- package/dist/src/shared/types.d.ts +0 -11
- package/dist/src/shared/types.js +0 -2
- package/dist/src/shared/types.js.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { getSetting } from '../config/config-manager.js';
|
|
4
|
+
import { pick } from '../formatters/flatten.js';
|
|
5
|
+
import { UsageError } from '../shared/errors.js';
|
|
6
|
+
import { runJq } from './jq.js';
|
|
7
|
+
/**
|
|
8
|
+
* Every generated command prints through here: data to stdout (`table` on a terminal, `plain` tab-separated when
|
|
9
|
+
* piped, or `json` / `jsonl` / `csv` on request), progress / cost / coverage notes to stderr (callers), long human
|
|
10
|
+
* output through `INVD_PAGER` / `PAGER` on a terminal.
|
|
11
|
+
*/
|
|
12
|
+
export const OUTPUT_FORMATS = ['table', 'plain', 'json', 'jsonl', 'csv'];
|
|
13
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
14
|
+
/** `NO_COLOR` turns colour off unless `FORCE_COLOR` asks for it (chalk reads `FORCE_COLOR` itself). */
|
|
15
|
+
export function applyColorEnv(env = process.env) {
|
|
16
|
+
if (env.NO_COLOR && !env.FORCE_COLOR)
|
|
17
|
+
chalk.level = 0;
|
|
18
|
+
}
|
|
19
|
+
/** A row reduced to `fields` (dotted paths kept as their dotted key). */
|
|
20
|
+
export function selectFields(row, fields) {
|
|
21
|
+
return Object.fromEntries(fields.map(field => [field, pick(row, field) ?? null]));
|
|
22
|
+
}
|
|
23
|
+
/** Fails on a `--json` field the operation's rows do not have, listing the ones they do. */
|
|
24
|
+
export function checkFields(fields, known, flag = '--json') {
|
|
25
|
+
if (known.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
const unknown = fields.filter(field => !known.includes(field.split('.')[0] ?? field));
|
|
28
|
+
if (unknown.length > 0) {
|
|
29
|
+
throw new UsageError(`${flag}: unknown field ${unknown.join(', ')}. Fields: ${known.join(', ')}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The body with `select` / `prune` applied to its rows (a list keeps its envelope) or to the object. */
|
|
33
|
+
export function shapeBody(body, shape, settings) {
|
|
34
|
+
const fields = settings.select ?? settings.prune;
|
|
35
|
+
if (!fields || !isRecord(body))
|
|
36
|
+
return body;
|
|
37
|
+
if (shape.list && Array.isArray(body.data))
|
|
38
|
+
return { ...body, data: body.data.map(row => selectFields(row, fields)) };
|
|
39
|
+
return selectFields(body, fields);
|
|
40
|
+
}
|
|
41
|
+
function cell(value, column) {
|
|
42
|
+
if (value === null || value === undefined)
|
|
43
|
+
return '—';
|
|
44
|
+
if (typeof value === 'number') {
|
|
45
|
+
if (column && /(^|_)(year|quarter)$/.test(column))
|
|
46
|
+
return String(value);
|
|
47
|
+
if (Number.isInteger(value) && Math.abs(value) >= 1000)
|
|
48
|
+
return value.toLocaleString('en-US');
|
|
49
|
+
if (!Number.isInteger(value))
|
|
50
|
+
return value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 4 });
|
|
51
|
+
return String(value);
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'boolean')
|
|
54
|
+
return value ? 'Yes' : 'No';
|
|
55
|
+
if (Array.isArray(value))
|
|
56
|
+
return value.map(item => (isRecord(item) ? JSON.stringify(item) : String(item))).join(', ');
|
|
57
|
+
if (isRecord(value))
|
|
58
|
+
return JSON.stringify(value);
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
61
|
+
const plainCell = (value) => {
|
|
62
|
+
if (value === null || value === undefined)
|
|
63
|
+
return '';
|
|
64
|
+
if (typeof value === 'object')
|
|
65
|
+
return JSON.stringify(value);
|
|
66
|
+
return String(value).replace(/[\t\n]/g, ' ');
|
|
67
|
+
};
|
|
68
|
+
export function tableText(rows, columns) {
|
|
69
|
+
if (rows.length === 0)
|
|
70
|
+
return chalk.yellow('No results.');
|
|
71
|
+
const cols = columns && columns.length > 0 ? [...columns] : Object.keys(rows[0] ?? {});
|
|
72
|
+
const widths = cols.map(col => Math.max(col.length, ...rows.map(row => cell(row[col], col).length)));
|
|
73
|
+
const lines = [
|
|
74
|
+
cols.map((col, i) => chalk.bold(col.padEnd(widths[i] ?? 0))).join(' '),
|
|
75
|
+
cols.map((_col, i) => '─'.repeat(widths[i] ?? 0)).join(' '),
|
|
76
|
+
...rows.map(row => cols.map((col, i) => cell(row[col], col).padEnd(widths[i] ?? 0)).join(' ').trimEnd()),
|
|
77
|
+
];
|
|
78
|
+
return lines.join('\n');
|
|
79
|
+
}
|
|
80
|
+
export function plainText(rows, columns) {
|
|
81
|
+
const cols = columns && columns.length > 0 ? [...columns] : Object.keys(rows[0] ?? {});
|
|
82
|
+
return [cols.join('\t'), ...rows.map(row => cols.map(col => plainCell(row[col])).join('\t'))].join('\n');
|
|
83
|
+
}
|
|
84
|
+
export function keyValueText(row) {
|
|
85
|
+
const width = Math.max(0, ...Object.keys(row).map(key => key.length));
|
|
86
|
+
return Object.entries(row).map(([key, value]) => ` ${chalk.bold(key.padEnd(width))} ${cell(value, key)}`).join('\n');
|
|
87
|
+
}
|
|
88
|
+
const csvCell = (value) => {
|
|
89
|
+
const text = plainCell(value);
|
|
90
|
+
return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
91
|
+
};
|
|
92
|
+
/** The CSV columns of some rows: every key, first-seen order. */
|
|
93
|
+
export const csvColumns = (rows) => [...new Set(rows.flatMap(row => (isRecord(row) ? Object.keys(row) : [])))];
|
|
94
|
+
export const csvHeader = (columns) => columns.map(csvCell).join(',');
|
|
95
|
+
export const csvRow = (row, columns) => columns.map(column => csvCell(isRecord(row) ? row[column] : undefined)).join(',');
|
|
96
|
+
/** The rows a body contributes to JSONL / CSV: a list's `data[]`, else the object itself. */
|
|
97
|
+
export const bodyRows = (body, shape) => shape.list && isRecord(body) && Array.isArray(body.data) ? body.data : body === undefined ? [] : [body];
|
|
98
|
+
const tableRows = (rows, columns) => rows.map(row => (columns ? selectFields(row, columns) : isRecord(row) ? row : { value: row }));
|
|
99
|
+
/** The human view of one body: the operation's columns as a table / key-value list, else indented JSON. */
|
|
100
|
+
export function humanText(body, shape, settings) {
|
|
101
|
+
const fields = settings.select ?? settings.prune;
|
|
102
|
+
const columns = fields ?? settings.order ?? shape.columns;
|
|
103
|
+
const plain = settings.format === 'plain';
|
|
104
|
+
if (shape.list) {
|
|
105
|
+
const rows = tableRows(bodyRows(body, shape), columns);
|
|
106
|
+
return plain ? plainText(rows, columns) : tableText(rows, columns);
|
|
107
|
+
}
|
|
108
|
+
if (isRecord(body) && (shape.view === 'keyValue' || fields)) {
|
|
109
|
+
const row = columns ? selectFields(body, columns) : body;
|
|
110
|
+
return plain ? plainText([row], Object.keys(row)) : keyValueText(row);
|
|
111
|
+
}
|
|
112
|
+
return JSON.stringify(body, null, 2);
|
|
113
|
+
}
|
|
114
|
+
/** The whole text of one (non-streamed) body in the chosen format. */
|
|
115
|
+
export function renderBody(body, shape, settings) {
|
|
116
|
+
if (settings.jq)
|
|
117
|
+
return runJq(settings.jq, body).join('\n');
|
|
118
|
+
const shaped = shapeBody(body, shape, settings);
|
|
119
|
+
switch (settings.format) {
|
|
120
|
+
case 'json':
|
|
121
|
+
return JSON.stringify(shaped, null, 2);
|
|
122
|
+
case 'jsonl':
|
|
123
|
+
return bodyRows(shaped, shape).map(row => JSON.stringify(row)).join('\n');
|
|
124
|
+
case 'csv': {
|
|
125
|
+
const rows = bodyRows(shaped, shape);
|
|
126
|
+
const columns = settings.select ?? settings.prune ?? settings.order ?? csvColumns(rows);
|
|
127
|
+
return [csvHeader(columns), ...rows.map(row => csvRow(row, columns))].join('\n');
|
|
128
|
+
}
|
|
129
|
+
default:
|
|
130
|
+
return humanText(body, shape, settings);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** The pager command for human output: `INVD_PAGER` / config `pager`, else `PAGER`; `''` / `cat` = none. */
|
|
134
|
+
export function pagerCommand(env = process.env) {
|
|
135
|
+
const configured = getSetting('pager').value || env.PAGER || '';
|
|
136
|
+
return configured && configured !== 'cat' ? configured : undefined;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Writes `text` to stdout; human output longer than the terminal goes through the pager when stdout is a
|
|
140
|
+
* terminal and a pager is set.
|
|
141
|
+
*/
|
|
142
|
+
export function emit(text, opts = {}) {
|
|
143
|
+
if (text === '')
|
|
144
|
+
return;
|
|
145
|
+
const pager = opts.human && process.stdout.isTTY ? pagerCommand() : undefined;
|
|
146
|
+
if (pager && text.split('\n').length > (process.stdout.rows || 24)) {
|
|
147
|
+
const result = spawnSync(pager, { shell: true, input: `${text}\n`, stdio: ['pipe', 'inherit', 'inherit'] });
|
|
148
|
+
if (!result.error)
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
console.log(text);
|
|
152
|
+
}
|
|
153
|
+
/** The format when none was asked for: the `output` setting, else `table` on a terminal and `plain` in a pipe. */
|
|
154
|
+
export function defaultFormat() {
|
|
155
|
+
const configured = getSetting('output').value;
|
|
156
|
+
if (OUTPUT_FORMATS.includes(configured))
|
|
157
|
+
return configured;
|
|
158
|
+
return process.stdout.isTTY ? 'table' : 'plain';
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/output/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC;AAoBlF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EA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IAAI,IAAI,KAAK,EAAE;QAAE,OAAO;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;QACnE,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;QAC5G,IAAI,CAAC,MAAM,CAAC,KAAK;YAAE,OAAO;IAC5B,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AAED,kHAAkH;AAClH,MAAM,UAAU,aAAa;IAC3B,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;IAC9C,IAAK,cAAoC,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,UAA0B,CAAC;IAClG,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC"}
|
|
@@ -1,41 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit codes (`invd --help` and the README list them): 0 ok, 1 failure, 2 usage, 3 partial (an unsaved download or
|
|
3
|
+
* an interrupted `--all`), 4 authentication required, 5 integrity, 6 credits exhausted / plan required.
|
|
4
|
+
*/
|
|
5
|
+
export declare const EXIT: {
|
|
6
|
+
readonly ok: 0;
|
|
7
|
+
readonly failure: 1;
|
|
8
|
+
readonly usage: 2;
|
|
9
|
+
readonly partial: 3;
|
|
10
|
+
readonly auth: 4;
|
|
11
|
+
readonly integrity: 5;
|
|
12
|
+
readonly credits: 6;
|
|
13
|
+
};
|
|
14
|
+
/** A v2 error answer (RFC 9457 problem+json): `code` is stable, `detail` says what happened. */
|
|
1
15
|
export declare class ApiError extends Error {
|
|
2
16
|
statusCode: number;
|
|
17
|
+
/** The problem's `title` (or the status text). */
|
|
3
18
|
errorType: string;
|
|
4
19
|
/** The answer's `Retry-After`, in milliseconds (absent when the header was missing or unreadable). */
|
|
5
20
|
retryAfterMs?: number | undefined;
|
|
6
|
-
/** The
|
|
21
|
+
/** The problem's stable `code` (`invalid_parameter`, `not_covered`, `plan_required` …). */
|
|
7
22
|
code?: string | undefined;
|
|
8
|
-
/** The parsed
|
|
23
|
+
/** The parsed error body, kept whole (`request_id`, `param`, `errors[]`, `docs_url`) for `--json`. */
|
|
9
24
|
body?: unknown | undefined;
|
|
10
|
-
constructor(statusCode: number,
|
|
25
|
+
constructor(statusCode: number,
|
|
26
|
+
/** The problem's `title` (or the status text). */
|
|
27
|
+
errorType: string, message: string,
|
|
11
28
|
/** The answer's `Retry-After`, in milliseconds (absent when the header was missing or unreadable). */
|
|
12
29
|
retryAfterMs?: number | undefined,
|
|
13
|
-
/** The
|
|
30
|
+
/** The problem's stable `code` (`invalid_parameter`, `not_covered`, `plan_required` …). */
|
|
14
31
|
code?: string | undefined,
|
|
15
|
-
/** The parsed
|
|
32
|
+
/** The parsed error body, kept whole (`request_id`, `param`, `errors[]`, `docs_url`) for `--json`. */
|
|
16
33
|
body?: unknown | undefined);
|
|
17
34
|
}
|
|
35
|
+
/** A command line `invd` refuses before any request (wrong value, missing argument, a needed `--yes`). Exit 2. */
|
|
36
|
+
export declare class UsageError extends Error {
|
|
37
|
+
readonly exitCode: 2;
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/** No API key anywhere (`INVD_API_KEY`, `.env`, keychain, config). Exit 4. */
|
|
41
|
+
export declare class AuthRequiredError extends Error {
|
|
42
|
+
readonly exitCode: 4;
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Part of the answer was written, the rest failed: `--all` stopped on a page after earlier pages were printed
|
|
47
|
+
* (`cursor` resumes it). Exit 3, so a script can resume exactly these.
|
|
48
|
+
*/
|
|
49
|
+
export declare class PartialResultError extends Error {
|
|
50
|
+
cause: unknown;
|
|
51
|
+
written: number;
|
|
52
|
+
cursor?: string | undefined;
|
|
53
|
+
readonly exitCode: 3;
|
|
54
|
+
constructor(cause: unknown, written: number, cursor?: string | undefined);
|
|
55
|
+
}
|
|
18
56
|
/**
|
|
19
57
|
* A download whose bytes stopped short of the length the server announced: nothing was saved (the `.part` file is
|
|
20
|
-
* removed). Exit
|
|
58
|
+
* removed). Exit 3 (partial), so a script can retry exactly these.
|
|
21
59
|
*/
|
|
22
60
|
export declare class PartialDownloadError extends Error {
|
|
23
61
|
received: number;
|
|
24
62
|
expected?: number | undefined;
|
|
25
|
-
readonly exitCode
|
|
63
|
+
readonly exitCode: 3;
|
|
26
64
|
constructor(received: number, expected?: number | undefined);
|
|
27
65
|
}
|
|
28
|
-
/** Saved bytes that do not match the size / SHA-256 / media type the API stated: nothing was saved. Exit
|
|
66
|
+
/** Saved bytes that do not match the size / SHA-256 / media type the API stated: nothing was saved. Exit 5. */
|
|
29
67
|
export declare class IntegrityError extends Error {
|
|
30
|
-
readonly exitCode
|
|
68
|
+
readonly exitCode: 5;
|
|
31
69
|
constructor(message: string);
|
|
32
70
|
}
|
|
71
|
+
/** The process exit code of an error (`ApiError` by its problem `code`, else its status). */
|
|
72
|
+
export declare function exitCodeFor(error: unknown): number;
|
|
73
|
+
/** Commander's own exits: help and version keep their code (0, or 1 for help shown on a bare group); anything else is usage (2). */
|
|
74
|
+
export declare function exitCodeOfCommanderError(error: {
|
|
75
|
+
code: string;
|
|
76
|
+
exitCode: number;
|
|
77
|
+
}): number;
|
|
33
78
|
/** `Retry-After` as delay-seconds or an HTTP date → milliseconds from `now`; `undefined` when unreadable. */
|
|
34
79
|
export declare function parseRetryAfter(value: string | null | undefined, now?: number): number | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* One dim line after an `ApiError` a person can act on: a 401 points at `invd login`, a 403 whose message names the
|
|
37
|
-
* plan a route needs ("requires the PRO plan") names that plan.
|
|
38
|
-
*/
|
|
80
|
+
/** One dim line after an `ApiError` a person can act on. */
|
|
39
81
|
export declare function apiErrorHint(error: ApiError): string | undefined;
|
|
40
|
-
/**
|
|
41
|
-
export declare function
|
|
82
|
+
/** Prints an error the way every command does (red line, detail, hint, the problem as JSON under `--json`). */
|
|
83
|
+
export declare function printError(error: unknown): void;
|
|
84
|
+
/** Wraps a command action: a thrown error is printed and becomes the process's exit code. */
|
|
85
|
+
export declare function withErrorHandling<A extends unknown[]>(fn: (...args: A) => Promise<void>): (...args: A) => Promise<void>;
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { isJsonMode } from './json-mode.js';
|
|
3
|
+
/**
|
|
4
|
+
* Exit codes (`invd --help` and the README list them): 0 ok, 1 failure, 2 usage, 3 partial (an unsaved download or
|
|
5
|
+
* an interrupted `--all`), 4 authentication required, 5 integrity, 6 credits exhausted / plan required.
|
|
6
|
+
*/
|
|
7
|
+
export const EXIT = { ok: 0, failure: 1, usage: 2, partial: 3, auth: 4, integrity: 5, credits: 6 };
|
|
8
|
+
/** A v2 error answer (RFC 9457 problem+json): `code` is stable, `detail` says what happened. */
|
|
3
9
|
export class ApiError extends Error {
|
|
4
10
|
statusCode;
|
|
5
11
|
errorType;
|
|
6
12
|
retryAfterMs;
|
|
7
13
|
code;
|
|
8
14
|
body;
|
|
9
|
-
constructor(statusCode,
|
|
15
|
+
constructor(statusCode,
|
|
16
|
+
/** The problem's `title` (or the status text). */
|
|
17
|
+
errorType, message,
|
|
10
18
|
/** The answer's `Retry-After`, in milliseconds (absent when the header was missing or unreadable). */
|
|
11
19
|
retryAfterMs,
|
|
12
|
-
/** The
|
|
20
|
+
/** The problem's stable `code` (`invalid_parameter`, `not_covered`, `plan_required` …). */
|
|
13
21
|
code,
|
|
14
|
-
/** The parsed
|
|
22
|
+
/** The parsed error body, kept whole (`request_id`, `param`, `errors[]`, `docs_url`) for `--json`. */
|
|
15
23
|
body) {
|
|
16
24
|
super(message);
|
|
17
25
|
this.statusCode = statusCode;
|
|
@@ -22,14 +30,48 @@ export class ApiError extends Error {
|
|
|
22
30
|
this.name = 'ApiError';
|
|
23
31
|
}
|
|
24
32
|
}
|
|
33
|
+
/** A command line `invd` refuses before any request (wrong value, missing argument, a needed `--yes`). Exit 2. */
|
|
34
|
+
export class UsageError extends Error {
|
|
35
|
+
exitCode = EXIT.usage;
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'UsageError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** No API key anywhere (`INVD_API_KEY`, `.env`, keychain, config). Exit 4. */
|
|
42
|
+
export class AuthRequiredError extends Error {
|
|
43
|
+
exitCode = EXIT.auth;
|
|
44
|
+
constructor(message = 'No API key configured. Run: invd auth login') {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = 'AuthRequiredError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Part of the answer was written, the rest failed: `--all` stopped on a page after earlier pages were printed
|
|
51
|
+
* (`cursor` resumes it). Exit 3, so a script can resume exactly these.
|
|
52
|
+
*/
|
|
53
|
+
export class PartialResultError extends Error {
|
|
54
|
+
cause;
|
|
55
|
+
written;
|
|
56
|
+
cursor;
|
|
57
|
+
exitCode = EXIT.partial;
|
|
58
|
+
constructor(cause, written, cursor) {
|
|
59
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
60
|
+
super(`Stopped after ${written} row(s): ${reason}${cursor ? ` — resume with --cursor ${cursor}` : ''}`);
|
|
61
|
+
this.cause = cause;
|
|
62
|
+
this.written = written;
|
|
63
|
+
this.cursor = cursor;
|
|
64
|
+
this.name = 'PartialResultError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
25
67
|
/**
|
|
26
68
|
* A download whose bytes stopped short of the length the server announced: nothing was saved (the `.part` file is
|
|
27
|
-
* removed). Exit
|
|
69
|
+
* removed). Exit 3 (partial), so a script can retry exactly these.
|
|
28
70
|
*/
|
|
29
71
|
export class PartialDownloadError extends Error {
|
|
30
72
|
received;
|
|
31
73
|
expected;
|
|
32
|
-
exitCode =
|
|
74
|
+
exitCode = EXIT.partial;
|
|
33
75
|
constructor(received, expected) {
|
|
34
76
|
const of = expected === undefined ? 'of an unknown length' : `of ${expected}`;
|
|
35
77
|
super(`Partial download: received ${received} bytes ${of}; nothing was saved (run the command again)`);
|
|
@@ -38,14 +80,47 @@ export class PartialDownloadError extends Error {
|
|
|
38
80
|
this.name = 'PartialDownloadError';
|
|
39
81
|
}
|
|
40
82
|
}
|
|
41
|
-
/** Saved bytes that do not match the size / SHA-256 / media type the API stated: nothing was saved. Exit
|
|
83
|
+
/** Saved bytes that do not match the size / SHA-256 / media type the API stated: nothing was saved. Exit 5. */
|
|
42
84
|
export class IntegrityError extends Error {
|
|
43
|
-
exitCode =
|
|
85
|
+
exitCode = EXIT.integrity;
|
|
44
86
|
constructor(message) {
|
|
45
87
|
super(message);
|
|
46
88
|
this.name = 'IntegrityError';
|
|
47
89
|
}
|
|
48
90
|
}
|
|
91
|
+
/** Problem `code`s with their own exit code; any other API error exits 1. */
|
|
92
|
+
const CODE_EXIT = {
|
|
93
|
+
invalid_parameter: EXIT.usage,
|
|
94
|
+
unknown_parameter: EXIT.usage,
|
|
95
|
+
cursor_mismatch: EXIT.usage,
|
|
96
|
+
unauthorized: EXIT.auth,
|
|
97
|
+
forbidden: EXIT.auth,
|
|
98
|
+
plan_required: EXIT.credits,
|
|
99
|
+
insufficient_credits: EXIT.credits,
|
|
100
|
+
};
|
|
101
|
+
/** The process exit code of an error (`ApiError` by its problem `code`, else its status). */
|
|
102
|
+
export function exitCodeFor(error) {
|
|
103
|
+
if (error instanceof ApiError) {
|
|
104
|
+
const byCode = error.code ? CODE_EXIT[error.code] : undefined;
|
|
105
|
+
if (byCode !== undefined)
|
|
106
|
+
return byCode;
|
|
107
|
+
if (error.statusCode === 401)
|
|
108
|
+
return EXIT.auth;
|
|
109
|
+
if (error.statusCode === 402)
|
|
110
|
+
return EXIT.credits;
|
|
111
|
+
return EXIT.failure;
|
|
112
|
+
}
|
|
113
|
+
if (error instanceof Error && 'exitCode' in error && typeof error.exitCode === 'number')
|
|
114
|
+
return error.exitCode;
|
|
115
|
+
return EXIT.failure;
|
|
116
|
+
}
|
|
117
|
+
/** Commander's own exits: help and version keep their code (0, or 1 for help shown on a bare group); anything else is usage (2). */
|
|
118
|
+
export function exitCodeOfCommanderError(error) {
|
|
119
|
+
if (['commander.helpDisplayed', 'commander.version', 'commander.help', 'commander.executeSubCommandAsync'].includes(error.code)) {
|
|
120
|
+
return error.exitCode;
|
|
121
|
+
}
|
|
122
|
+
return EXIT.usage;
|
|
123
|
+
}
|
|
49
124
|
/** `Retry-After` as delay-seconds or an HTTP date → milliseconds from `now`; `undefined` when unreadable. */
|
|
50
125
|
export function parseRetryAfter(value, now = Date.now()) {
|
|
51
126
|
if (!value?.trim())
|
|
@@ -56,44 +131,57 @@ export function parseRetryAfter(value, now = Date.now()) {
|
|
|
56
131
|
const date = Date.parse(value);
|
|
57
132
|
return Number.isNaN(date) ? undefined : Math.max(0, date - now);
|
|
58
133
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* plan a route needs ("requires the PRO plan") names that plan.
|
|
62
|
-
*/
|
|
63
|
-
export function apiErrorHint(error) {
|
|
64
|
-
if (error.statusCode === 401)
|
|
65
|
-
return 'Run: invd login';
|
|
66
|
-
if (error.statusCode !== 403)
|
|
134
|
+
const field = (body, key) => {
|
|
135
|
+
if (typeof body !== 'object' || body === null)
|
|
67
136
|
return undefined;
|
|
68
|
-
const
|
|
69
|
-
return
|
|
137
|
+
const value = Reflect.get(body, key);
|
|
138
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
139
|
+
};
|
|
140
|
+
/** One dim line after an `ApiError` a person can act on. */
|
|
141
|
+
export function apiErrorHint(error) {
|
|
142
|
+
if (error.code === 'unauthorized' || error.statusCode === 401)
|
|
143
|
+
return 'Run: invd auth login';
|
|
144
|
+
if (error.code === 'plan_required')
|
|
145
|
+
return `This operation needs a higher plan: ${field(error.body, 'docs_url') ?? 'invd me show'}`;
|
|
146
|
+
if (error.code === 'insufficient_credits')
|
|
147
|
+
return 'Credits exhausted for this period: invd me show';
|
|
148
|
+
if (error.code === 'not_covered')
|
|
149
|
+
return 'Find the company: invd companies list --q <name>';
|
|
150
|
+
return field(error.body, 'docs_url');
|
|
151
|
+
}
|
|
152
|
+
/** Prints an error the way every command does (red line, detail, hint, the problem as JSON under `--json`). */
|
|
153
|
+
export function printError(error) {
|
|
154
|
+
if (error instanceof ApiError) {
|
|
155
|
+
const code = error.code && error.code !== error.errorType ? ` (${error.code})` : '';
|
|
156
|
+
console.error(chalk.red(`Error ${error.statusCode}: ${error.errorType}${code}`));
|
|
157
|
+
console.error(error.message);
|
|
158
|
+
const requestId = field(error.body, 'request_id');
|
|
159
|
+
if (requestId)
|
|
160
|
+
console.error(chalk.dim(`request id: ${requestId}`));
|
|
161
|
+
const line = apiErrorHint(error);
|
|
162
|
+
if (line)
|
|
163
|
+
console.error(chalk.dim(line));
|
|
164
|
+
if (isJsonMode() && error.body !== undefined && error.body !== null) {
|
|
165
|
+
// The problem body (code, param, errors[], request_id) as one JSON line, for scripts.
|
|
166
|
+
console.error(JSON.stringify(typeof error.body === 'object' ? error.body : { status: error.statusCode, body: error.body }));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (error instanceof Error) {
|
|
170
|
+
console.error(chalk.red('Error:'), error.message);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
console.error(chalk.red('An unexpected error occurred'));
|
|
174
|
+
}
|
|
70
175
|
}
|
|
71
|
-
/**
|
|
72
|
-
export function withErrorHandling(fn
|
|
176
|
+
/** Wraps a command action: a thrown error is printed and becomes the process's exit code. */
|
|
177
|
+
export function withErrorHandling(fn) {
|
|
73
178
|
return async (...args) => {
|
|
74
179
|
try {
|
|
75
180
|
await fn(...args);
|
|
76
181
|
}
|
|
77
182
|
catch (error) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.error(chalk.red(`Error ${error.statusCode}: ${error.errorType}${code}`));
|
|
81
|
-
console.error(error.message);
|
|
82
|
-
const line = hint?.(error);
|
|
83
|
-
if (line)
|
|
84
|
-
console.error(chalk.dim(line));
|
|
85
|
-
if (isJsonMode() && error.body !== undefined && error.body !== null) {
|
|
86
|
-
// The structured answer (state, code, readiness, the subject's fields) as one JSON line, for scripts.
|
|
87
|
-
console.error(JSON.stringify({ status: error.statusCode, ...(typeof error.body === 'object' ? error.body : { body: error.body }) }));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (error instanceof Error) {
|
|
91
|
-
console.error(chalk.red('Error:'), error.message);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
console.error(chalk.red('An unexpected error occurred'));
|
|
95
|
-
}
|
|
96
|
-
process.exit(error instanceof PartialDownloadError || error instanceof IntegrityError ? error.exitCode : 1);
|
|
183
|
+
printError(error);
|
|
184
|
+
process.exit(exitCodeFor(error));
|
|
97
185
|
}
|
|
98
186
|
};
|
|
99
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/shared/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,OAAO,QAAS,SAAQ,KAAK;IAExB;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/shared/errors.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,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC9H,CAAC;IACH,CAAC;SAAM,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,iBAAiB,CAAsB,EAAiC;IACtF,OAAO,KAAK,EAAE,GAAG,IAAO,EAAiB,EAAE;QACzC,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asks before something costly or destructive. `--yes` answers for the person; `--no-input` (or no terminal on
|
|
3
|
+
* stdin, e.g. CI) refuses with exit 2 instead of waiting for an answer nobody can give.
|
|
4
|
+
*/
|
|
5
|
+
export declare function confirmOrRefuse(question: string, flags: {
|
|
6
|
+
yes?: boolean;
|
|
7
|
+
input?: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
/** Reads all of stdin as text (`--body-file -`, `auth login --with-token`). */
|
|
10
|
+
export declare function readStdin(): Promise<string>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UsageError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Asks before something costly or destructive. `--yes` answers for the person; `--no-input` (or no terminal on
|
|
4
|
+
* stdin, e.g. CI) refuses with exit 2 instead of waiting for an answer nobody can give.
|
|
5
|
+
*/
|
|
6
|
+
export async function confirmOrRefuse(question, flags) {
|
|
7
|
+
if (flags.yes)
|
|
8
|
+
return;
|
|
9
|
+
if (flags.input === false || !process.stdin.isTTY) {
|
|
10
|
+
throw new UsageError(`${question} Pass --yes to go ahead without a prompt.`);
|
|
11
|
+
}
|
|
12
|
+
const { default: Enquirer } = await import('enquirer');
|
|
13
|
+
const answer = await new Enquirer().prompt({ type: 'confirm', name: 'ok', message: question, initial: false });
|
|
14
|
+
if (!answer.ok)
|
|
15
|
+
throw new UsageError('Cancelled.');
|
|
16
|
+
}
|
|
17
|
+
/** Reads all of stdin as text (`--body-file -`, `auth login --with-token`). */
|
|
18
|
+
export async function readStdin() {
|
|
19
|
+
const chunks = [];
|
|
20
|
+
for await (const chunk of process.stdin)
|
|
21
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
22
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/shared/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,KAAyC;IAC/F,IAAI,KAAK,CAAC,GAAG;QAAE,OAAO;IACtB,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAClD,MAAM,IAAI,UAAU,CAAC,GAAG,QAAQ,2CAA2C,CAAC,CAAC;IAC/E,CAAC;IACD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAoB,CAAC;IAClI,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;AACrD,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClH,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -6,7 +6,8 @@ export function setJsonMode(enabled) {
|
|
|
6
6
|
setJsonOutput(enabled);
|
|
7
7
|
}
|
|
8
8
|
export function createSpinner(text) {
|
|
9
|
-
|
|
9
|
+
// Progress is for a person watching a terminal: silent under --json and when stderr is not a terminal.
|
|
10
|
+
if (jsonMode || !process.stderr.isTTY) {
|
|
10
11
|
return ora({ text, isSilent: true });
|
|
11
12
|
}
|
|
12
13
|
return ora(text).start();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spinner.js","sourceRoot":"","sources":["../../../src/shared/spinner.ts"],"names":[],"mappings":"AAAA,OAAO,GAAiB,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,IAAI,QAAQ,GAAG,KAAK,CAAC;AAErB,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,QAAQ,GAAG,OAAO,CAAC;IACnB,aAAa,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,QAAQ,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"spinner.js","sourceRoot":"","sources":["../../../src/shared/spinner.ts"],"names":[],"mappings":"AAAA,OAAO,GAAiB,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,IAAI,QAAQ,GAAG,KAAK,CAAC;AAErB,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,QAAQ,GAAG,OAAO,CAAC;IACnB,aAAa,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,uGAAuG;IACvG,IAAI,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { type
|
|
2
|
+
import { type QueryValue } from './client/api-client.js';
|
|
3
|
+
import { type Manifest, type ManifestParam } from './spec-manifest.js';
|
|
3
4
|
/**
|
|
4
|
-
* Registers
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* view as the human output. A group a hand-written command already registered (`earnings`, whose download commands
|
|
8
|
-
* are rostered in `src/hand-written-commands.ts`) gets the generated actions attached; commander refuses a duplicate.
|
|
5
|
+
* Registers the manifest's operations: `invd <group> <action>` (a group's `list` is its default, so
|
|
6
|
+
* `invd filings AAPL` lists), one positional for the natural key, one flag per parameter, the output / paging /
|
|
7
|
+
* metering flags, and `invd financials` as ONE command over its six operations (`--basis` × `--view`).
|
|
9
8
|
*/
|
|
10
9
|
export declare function registerSpecCommands(program: Command, manifest: Manifest): void;
|
|
10
|
+
/** One flag value validated and converted to what goes on the wire; refuses by flag name (exit 2). */
|
|
11
|
+
export declare function wireValue(param: ManifestParam, raw: unknown): QueryValue;
|
|
12
|
+
/** `2026Q3`, `2026 Q3`, `FY2026Q3` → fiscal year and quarter. */
|
|
13
|
+
export declare function parseFiscalPeriod(text: string): {
|
|
14
|
+
fiscalYear: string;
|
|
15
|
+
fiscalQuarter: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/** The yellow stderr line of a `meta.coverage` that is not complete (v2 readiness: a 200 with `state`). */
|
|
18
|
+
export declare function coverageNote(body: unknown): string | undefined;
|