nansen-cli 2.3.0 → 2.4.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/CHANGELOG.md +64 -0
- package/README.md +32 -32
- package/docs/auth.md +56 -0
- package/docs/browser-login.md +101 -7
- package/docs/error-codes.md +249 -0
- package/package.json +10 -4
- package/skills/nansen-agent-guide/SKILL.md +17 -1
- package/skills/nansen-alerts-webhook-listener/SKILL.md +1 -1
- package/skills/nansen-dca-tracker/SKILL.md +1 -1
- package/skills/nansen-defi-positions/SKILL.md +1 -1
- package/skills/nansen-exit-signals/SKILL.md +2 -2
- package/skills/nansen-fund-tracker/SKILL.md +1 -1
- package/skills/nansen-general-search/SKILL.md +1 -1
- package/skills/nansen-holder-analysis/SKILL.md +2 -2
- package/skills/nansen-limit-orders/SKILL.md +1 -1
- package/skills/nansen-mpp-payment/SKILL.md +2 -2
- package/skills/nansen-perp-screener/SKILL.md +1 -1
- package/skills/nansen-perp-trader-profile/SKILL.md +1 -1
- package/skills/nansen-polymarket-deep-dive/SKILL.md +1 -1
- package/skills/nansen-polymarket-insider-scan/SKILL.md +1 -1
- package/skills/nansen-polymarket-trader-profile/SKILL.md +1 -1
- package/skills/nansen-portfolio-tracker/SKILL.md +1 -1
- package/skills/nansen-prediction-markets/SKILL.md +1 -1
- package/skills/nansen-sm-cross-chain-flows/SKILL.md +1 -1
- package/skills/nansen-smart-alerts/SKILL.md +2 -1
- package/skills/nansen-smart-money-alpha/SKILL.md +1 -1
- package/skills/nansen-smart-money-tracker/SKILL.md +8 -7
- package/skills/nansen-smart-money-trend/SKILL.md +1 -1
- package/skills/nansen-token-research/SKILL.md +1 -1
- package/skills/nansen-token-screener/SKILL.md +1 -1
- package/skills/nansen-token-transfer-analysis/SKILL.md +1 -1
- package/skills/nansen-trading/SKILL.md +1 -1
- package/skills/nansen-wallet-batch/SKILL.md +1 -1
- package/skills/nansen-wallet-clustering/SKILL.md +1 -1
- package/skills/nansen-wallet-deep-dive/SKILL.md +1 -1
- package/skills/nansen-wallet-keychain-migration/SKILL.md +1 -1
- package/skills/nansen-wallet-manager/SKILL.md +1 -1
- package/skills/nansen-wallet-profiler/SKILL.md +1 -1
- package/skills/nansen-web-fetcher/SKILL.md +1 -1
- package/skills/nansen-web-searcher/SKILL.md +1 -1
- package/src/api-endpoints.json +1605 -0
- package/src/api.js +202 -97
- package/src/auth-credentials.js +1 -0
- package/src/auth-state.js +2 -2
- package/src/auth-store-native.js +6 -1
- package/src/auth-store-worker.js +1 -1
- package/src/auth-store.js +9 -4
- package/src/bridge.js +19 -10
- package/src/cli.js +188 -89
- package/src/commands/agent.js +2 -3
- package/src/commands/alerts.js +277 -9
- package/src/commands/feedback.js +98 -37
- package/src/commands/mcp.js +1 -1
- package/src/commands/research.js +14 -37
- package/src/cost-cache.js +33 -7
- package/src/doctor.js +14 -5
- package/src/error-codes.js +226 -0
- package/src/input-validation.js +551 -0
- package/src/limit-order.js +12 -3
- package/src/perp.js +2 -1
- package/src/privy.js +89 -11
- package/src/query-options.js +30 -7
- package/src/rpc-urls.js +3 -1
- package/src/schema.json +1137 -145
- package/src/solana-tx.js +4 -0
- package/src/trade-validation.js +167 -8
- package/src/trading.js +172 -12
- package/src/transfer.js +7 -1
- package/src/update-check.js +32 -5
- package/src/wallet.js +211 -57
- package/src/walletconnect-x402.js +14 -8
package/src/commands/alerts.js
CHANGED
|
@@ -5,6 +5,241 @@
|
|
|
5
5
|
|
|
6
6
|
import { NansenError, ErrorCode } from '../api.js';
|
|
7
7
|
import { parseCsvOption } from '../query-options.js';
|
|
8
|
+
import { unknownCommandError } from '../input-validation.js';
|
|
9
|
+
|
|
10
|
+
// ============= Channel secret redaction =============
|
|
11
|
+
|
|
12
|
+
export const REDACTED = '****';
|
|
13
|
+
|
|
14
|
+
// Webhook hosts with a known URL shape, and how many leading path segments
|
|
15
|
+
// identify the channel without granting access: Slack keeps /services/<team>,
|
|
16
|
+
// Discord keeps /api/webhooks/<id>. Any other URL keeps only its scheme and
|
|
17
|
+
// port, since a custom endpoint can carry a token in any part of its hostname,
|
|
18
|
+
// the path or the query.
|
|
19
|
+
const KNOWN_WEBHOOK_HOSTS = [
|
|
20
|
+
{ host: /^hooks\.slack\.com$/i, keepSegments: 2 },
|
|
21
|
+
{ host: /^(?:ptb\.|canary\.)?discord(?:app)?\.com$/i, keepSegments: 3 },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const SECRET_KEY_PATTERN = /url|secret|token|key|password|auth/i;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Mask a webhook URL. Userinfo, query, hash and at least the last path segment
|
|
28
|
+
* are always dropped. A value that does not parse as an http(s) URL is masked
|
|
29
|
+
* entirely.
|
|
30
|
+
*/
|
|
31
|
+
export function redactUrl(url) {
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = new URL(String(url).replace(/\\\//g, '/'));
|
|
35
|
+
} catch {
|
|
36
|
+
return REDACTED;
|
|
37
|
+
}
|
|
38
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') return REDACTED;
|
|
39
|
+
const known = KNOWN_WEBHOOK_HOSTS.find(h => h.host.test(parsed.hostname));
|
|
40
|
+
const host = known ? parsed.hostname : REDACTED;
|
|
41
|
+
const origin = `${parsed.protocol}//${host}${parsed.port ? `:${parsed.port}` : ''}`;
|
|
42
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
43
|
+
const keep = known ? Math.min(known.keepSegments, Math.max(0, segments.length - 1)) : 0;
|
|
44
|
+
return [origin, ...segments.slice(0, keep), REDACTED].join('/');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Everything under a credential key is a credential, whatever its type: a
|
|
48
|
+
// number, a boolean, or an object whose own keys look harmless (`{ value }`).
|
|
49
|
+
// Only URLs get the partial, identifying mask; null stays null.
|
|
50
|
+
function maskSecretValue(key, value) {
|
|
51
|
+
if (value == null) return value;
|
|
52
|
+
if (typeof value === 'string') return /url/i.test(key) ? redactUrl(value) : REDACTED;
|
|
53
|
+
if (Array.isArray(value)) return value.map(v => maskSecretValue(key, v));
|
|
54
|
+
if (typeof value === 'object') {
|
|
55
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, maskSecretValue(/url/i.test(k) ? k : key, v)]));
|
|
56
|
+
}
|
|
57
|
+
return REDACTED;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function redactChannelData(value) {
|
|
61
|
+
if (Array.isArray(value)) return value.map(redactChannelData);
|
|
62
|
+
if (!value || typeof value !== 'object') return value;
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const [key, v] of Object.entries(value)) {
|
|
65
|
+
out[key] = SECRET_KEY_PATTERN.test(key) ? maskSecretValue(key, v) : redactChannelData(v);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return a copy of an alerts API response with channel credentials masked:
|
|
72
|
+
* Slack/Discord/webhook URLs and webhook signing secrets. Anyone holding a
|
|
73
|
+
* webhook URL can post to the channel, and CLI output is routinely pasted into
|
|
74
|
+
* chats, logs and tickets, so these are hidden unless --reveal is passed.
|
|
75
|
+
* Works on any response shape by masking every `channels` array it finds.
|
|
76
|
+
* Telegram chat IDs are not credentials and stay visible.
|
|
77
|
+
*/
|
|
78
|
+
export function redactAlertSecrets(value) {
|
|
79
|
+
if (Array.isArray(value)) return value.map(redactAlertSecrets);
|
|
80
|
+
if (!value || typeof value !== 'object') return value;
|
|
81
|
+
const out = {};
|
|
82
|
+
for (const [key, v] of Object.entries(value)) {
|
|
83
|
+
if (key === 'channels' && Array.isArray(v)) {
|
|
84
|
+
// The whole channel, not just `data`, in case credentials sit at its top level.
|
|
85
|
+
out[key] = v.map(redactChannelData);
|
|
86
|
+
} else {
|
|
87
|
+
out[key] = redactAlertSecrets(v);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Any http(s) URL in error text, including the JSON-escaped `https:\/\/` form.
|
|
94
|
+
// Alert errors have no reason to quote URLs other than channels and the
|
|
95
|
+
// Nansen links the CLI's own errors point to, so everything else is masked
|
|
96
|
+
// rather than guessing which are webhooks.
|
|
97
|
+
const URL_IN_TEXT = /https?:(?:\\?\/){2}[^\s"'<>]+/gi;
|
|
98
|
+
// Exact URLs, not hosts: a generic webhook can point at any host and path,
|
|
99
|
+
// including a nansen.ai one. A URL differing in any part (path, query, hash,
|
|
100
|
+
// port, userinfo) is masked. Trailing sentence punctuation is ignored.
|
|
101
|
+
const NANSEN_LINKS = new Set([
|
|
102
|
+
'https://docs.nansen.ai/',
|
|
103
|
+
'https://docs.nansen.ai/getting-started/error-handling',
|
|
104
|
+
'https://app.nansen.ai/api?tab=api',
|
|
105
|
+
'https://app.nansen.ai/auth/agent-setup',
|
|
106
|
+
]);
|
|
107
|
+
|
|
108
|
+
function isNansenLink(url) {
|
|
109
|
+
try {
|
|
110
|
+
return NANSEN_LINKS.has(new URL(url.replace(/\\\//g, '/').replace(/[.,;:!?)\]]+$/, '')).href);
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Keys in a request payload whose values are credentials. Narrower than
|
|
117
|
+
// SECRET_KEY_PATTERN so alert filters such as `tokens` or `tokenSectors`
|
|
118
|
+
// are not mistaken for secrets and masked out of error messages: `token` and
|
|
119
|
+
// `key` count only at the end of a key (`accessToken`, `apiKey`).
|
|
120
|
+
const CREDENTIAL_KEY_PATTERN = /url|secret|password|passphrase|credential|token$|key$|^auth/i;
|
|
121
|
+
|
|
122
|
+
const maskCredential = v => (/^https?:/i.test(v) ? redactUrl(v) : REDACTED);
|
|
123
|
+
|
|
124
|
+
// Mask credential-keyed fields anywhere in an error body, not only inside
|
|
125
|
+
// `channels`: an error can echo a stored secret on its own (`{ detail: { secret } }`),
|
|
126
|
+
// including on `list`, where there is no request payload to match it against.
|
|
127
|
+
// Nansen URLs (e.g. links to docs) stay readable.
|
|
128
|
+
function maskCredentialKeys(value) {
|
|
129
|
+
if (Array.isArray(value)) return value.map(maskCredentialKeys);
|
|
130
|
+
if (!value || typeof value !== 'object') return value;
|
|
131
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => {
|
|
132
|
+
if (!CREDENTIAL_KEY_PATTERN.test(k)) return [k, maskCredentialKeys(v)];
|
|
133
|
+
return [k, typeof v === 'string' && isNansenLink(v) ? v : maskSecretValue(k, v)];
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Credential values in a request payload (channel flags, --data, or existing
|
|
138
|
+
// alert data merged into an update) or in an error body. Every string or
|
|
139
|
+
// number under a credential key counts, at any depth, as they would be echoed
|
|
140
|
+
// as text. Objects already visited are skipped, so circular details are safe.
|
|
141
|
+
function payloadCredentials(value, underCredentialKey = false, out = [], seen = new WeakSet()) {
|
|
142
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
143
|
+
if (underCredentialKey) out.push(String(value));
|
|
144
|
+
} else if (value && typeof value === 'object' && !seen.has(value)) {
|
|
145
|
+
seen.add(value);
|
|
146
|
+
const entries = Array.isArray(value) ? value.map(v => [null, v]) : Object.entries(value);
|
|
147
|
+
for (const [k, v] of entries) {
|
|
148
|
+
payloadCredentials(v, underCredentialKey || (k !== null && CREDENTIAL_KEY_PATTERN.test(k)), out, seen);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Credentials sent or passed on this invocation, mapped to their masked form.
|
|
155
|
+
// They are matched by value, which covers a secret that is not a URL.
|
|
156
|
+
function suppliedChannelSecrets(options, payload, errorBody) {
|
|
157
|
+
const secrets = [];
|
|
158
|
+
// Flag values shorter than the minimum are left alone: URLs that short are
|
|
159
|
+
// not valid and buildChannels rejects short --webhook-secret values. --data
|
|
160
|
+
// has no minimum, so a payload credential of any length is matched; values
|
|
161
|
+
// shorter than 8 characters only as a whole token, so a short secret such
|
|
162
|
+
// as `abc1` does not garble unrelated words that contain it.
|
|
163
|
+
const add = (value, masked, minLength) => {
|
|
164
|
+
for (const v of [value].flat()) {
|
|
165
|
+
if (typeof v !== 'string' || v.length < Math.max(1, minLength)) continue;
|
|
166
|
+
const wholeToken = v.length < 8;
|
|
167
|
+
secrets.push([v, masked(v), wholeToken]);
|
|
168
|
+
const escaped = JSON.stringify(v).slice(1, -1).replace(/\//g, '\\/');
|
|
169
|
+
if (escaped !== v) secrets.push([escaped, masked(v), wholeToken]);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
for (const flag of ['slack', 'discord', 'webhook']) add(options[flag], redactUrl, 8);
|
|
173
|
+
add(options['webhook-secret'], () => REDACTED, 16);
|
|
174
|
+
add(payloadCredentials(payload), maskCredential, 1);
|
|
175
|
+
// A credential field in the error body names the value, so the same secret
|
|
176
|
+
// is also scrubbed wherever the message quotes it (e.g. a stored secret on
|
|
177
|
+
// `list`, where there is no payload to match against).
|
|
178
|
+
add(payloadCredentials(errorBody).filter(v => !isNansenLink(v)), maskCredential, 1);
|
|
179
|
+
// Longest first, so a value that contains another is replaced whole.
|
|
180
|
+
return secrets.sort((a, b) => b[0].length - a[0].length);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function scrubString(text, secrets) {
|
|
184
|
+
let out = text;
|
|
185
|
+
for (const [value, masked, wholeToken] of secrets) {
|
|
186
|
+
if (!wholeToken) {
|
|
187
|
+
out = out.split(value).join(masked);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const escaped = value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
191
|
+
out = out.replace(new RegExp(`(?<![A-Za-z0-9])${escaped}(?![A-Za-z0-9])`, 'g'), () => masked);
|
|
192
|
+
}
|
|
193
|
+
// Sentence punctuation the URL pattern swallows (`(https://x/y).`) is kept
|
|
194
|
+
// outside the mask, so the text around a masked URL stays intact.
|
|
195
|
+
return out.replace(URL_IN_TEXT, match => {
|
|
196
|
+
const [, url, tail] = match.match(/^(.*?)([.,;:!?)\]]*)$/);
|
|
197
|
+
return isNansenLink(url) ? match : redactUrl(url) + tail;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function scrubDeep(value, secrets) {
|
|
202
|
+
if (typeof value === 'string') return scrubString(value, secrets);
|
|
203
|
+
if (Array.isArray(value)) return value.map(v => scrubDeep(v, secrets));
|
|
204
|
+
if (!value || typeof value !== 'object') return value;
|
|
205
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, scrubDeep(v, secrets)]));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Return an error safe to print: the message and details have channel
|
|
210
|
+
* credentials masked. API error bodies are copied into NansenError.details and
|
|
211
|
+
* printed, and a validation error can echo the channels it rejected. If the
|
|
212
|
+
* details cannot be walked (e.g. a circular structure), they are dropped.
|
|
213
|
+
* `payload` is the request body that was sent, if any.
|
|
214
|
+
*/
|
|
215
|
+
export function redactAlertError(error, options = {}, payload = undefined) {
|
|
216
|
+
const secrets = suppliedChannelSecrets(options, payload, [error?.details, error?.data]);
|
|
217
|
+
const scrub = value => {
|
|
218
|
+
if (value == null) return value;
|
|
219
|
+
try {
|
|
220
|
+
return scrubDeep(maskCredentialKeys(redactAlertSecrets(value)), secrets);
|
|
221
|
+
} catch {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const message = typeof error?.message === 'string' ? scrubString(error.message, secrets) : error?.message;
|
|
226
|
+
if (error instanceof NansenError) {
|
|
227
|
+
return new NansenError(message, error.code, error.status, scrub(error.details));
|
|
228
|
+
}
|
|
229
|
+
if (error instanceof Error) {
|
|
230
|
+
// formatError() reads message, code, status and details/data.
|
|
231
|
+
const scrubbed = new Error(message);
|
|
232
|
+
scrubbed.name = error.name;
|
|
233
|
+
for (const key of ['code', 'status']) {
|
|
234
|
+
if (error[key] !== undefined) scrubbed[key] = error[key];
|
|
235
|
+
}
|
|
236
|
+
for (const key of ['details', 'data']) {
|
|
237
|
+
if (error[key] !== undefined) scrubbed[key] = scrub(error[key]);
|
|
238
|
+
}
|
|
239
|
+
return scrubbed;
|
|
240
|
+
}
|
|
241
|
+
return error;
|
|
242
|
+
}
|
|
8
243
|
|
|
9
244
|
// ============= Formatting =============
|
|
10
245
|
|
|
@@ -488,16 +723,21 @@ SUBCOMMANDS:
|
|
|
488
723
|
toggle Enable or disable an alert
|
|
489
724
|
delete Delete an alert
|
|
490
725
|
|
|
726
|
+
Channel credentials (Slack/Discord/webhook URLs, webhook signing secrets) are
|
|
727
|
+
redacted in output and error messages of every subcommand. Pass --reveal to
|
|
728
|
+
show them.
|
|
729
|
+
|
|
491
730
|
Run: nansen alerts <subcommand> --help`,
|
|
492
731
|
|
|
493
732
|
list: `nansen alerts list — List all alerts
|
|
494
733
|
|
|
495
734
|
USAGE:
|
|
496
|
-
nansen alerts list [--table] [--pretty] [--type <type>] [--enabled|--disabled] [--token-address <addr>] [--chain <chain>] [--limit <n>] [--offset <n>]
|
|
735
|
+
nansen alerts list [--table] [--pretty] [--type <type>] [--enabled|--disabled] [--token-address <addr>] [--chain <chain>] [--limit <n>] [--offset <n>] [--reveal]
|
|
497
736
|
|
|
498
737
|
OPTIONS:
|
|
499
738
|
--table Human-readable table output (columns: ID, NAME, TYPE, ENABLED, CHANNELS)
|
|
500
739
|
--pretty Indented JSON output
|
|
740
|
+
--reveal Show full channel webhook URLs and secrets (redacted by default)
|
|
501
741
|
--type <type> Filter by alert type (sm-token-flows, common-token-transfer, smart-contract-call)
|
|
502
742
|
--enabled / --disabled Filter by enabled state
|
|
503
743
|
--token-address <addr> Filter by token address
|
|
@@ -528,6 +768,7 @@ OPTIONS (all types):
|
|
|
528
768
|
--description '<text>' Alert description
|
|
529
769
|
--disabled Create in disabled state
|
|
530
770
|
--data '<json>' Raw JSON merged on top of named flags (escape hatch)
|
|
771
|
+
--reveal Show full channel URLs and secrets in the response (redacted by default)
|
|
531
772
|
|
|
532
773
|
OPTIONS (sm-token-flows):
|
|
533
774
|
At least one flow threshold required (inflow, outflow, or netflow):
|
|
@@ -566,7 +807,7 @@ EXAMPLES:
|
|
|
566
807
|
USAGE:
|
|
567
808
|
nansen alerts update <id> [--name <name>] [--chains <chains>] [--enabled|--disabled] [type-specific flags...]
|
|
568
809
|
|
|
569
|
-
All create options are accepted. Only provided fields are updated.
|
|
810
|
+
All create options are accepted, including --reveal. Only provided fields are updated.
|
|
570
811
|
See: nansen alerts create --help for type-specific flags.
|
|
571
812
|
|
|
572
813
|
NOTE: --type cannot change an existing alert's type (use delete + create instead).
|
|
@@ -581,7 +822,10 @@ EXAMPLES:
|
|
|
581
822
|
|
|
582
823
|
USAGE:
|
|
583
824
|
nansen alerts toggle <id> --enabled
|
|
584
|
-
nansen alerts toggle <id> --disabled
|
|
825
|
+
nansen alerts toggle <id> --disabled
|
|
826
|
+
|
|
827
|
+
OPTIONS:
|
|
828
|
+
--reveal Show full channel URLs and secrets in the response (redacted by default)`,
|
|
585
829
|
|
|
586
830
|
delete: `nansen alerts delete — Delete an alert
|
|
587
831
|
|
|
@@ -599,6 +843,17 @@ USAGE:
|
|
|
599
843
|
if (options["webhook-secret"] && !options.webhook) {
|
|
600
844
|
throw new NansenError('--webhook-secret requires --webhook', ErrorCode.INVALID_PARAMS);
|
|
601
845
|
}
|
|
846
|
+
for (const flag of ['slack', 'discord', 'webhook', 'webhook-secret']) {
|
|
847
|
+
if (Array.isArray(options[flag])) {
|
|
848
|
+
throw new NansenError(`--${flag} can only be passed once`, ErrorCode.INVALID_PARAMS);
|
|
849
|
+
}
|
|
850
|
+
if (typeof options[flag] === 'string' && options[flag].includes(REDACTED)) {
|
|
851
|
+
throw new NansenError(
|
|
852
|
+
`--${flag} looks like a redacted value from alerts output. Pass the full value (nansen alerts list --reveal shows it).`,
|
|
853
|
+
ErrorCode.INVALID_PARAMS,
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
602
857
|
const channels = [];
|
|
603
858
|
if (options.telegram) channels.push({ type: 'telegram', data: { chatId: String(options.telegram) } });
|
|
604
859
|
if (options.slack) channels.push({ type: 'slack', data: { webhookUrl: options.slack } });
|
|
@@ -614,6 +869,10 @@ USAGE:
|
|
|
614
869
|
return channels.length > 0 ? channels : null;
|
|
615
870
|
}
|
|
616
871
|
|
|
872
|
+
// Request body of create/update, so a failed request's error can be
|
|
873
|
+
// scrubbed of every credential it carried.
|
|
874
|
+
let sentPayload;
|
|
875
|
+
|
|
617
876
|
const handlers = {
|
|
618
877
|
'list': async () => {
|
|
619
878
|
if (flags.enabled && flags.disabled) throw new NansenError('Cannot specify both --enabled and --disabled', ErrorCode.INVALID_PARAMS);
|
|
@@ -683,7 +942,7 @@ USAGE:
|
|
|
683
942
|
const dataOverride = parseDataOverride(options);
|
|
684
943
|
if (dataOverride) data = deepMergePlain(data, dataOverride);
|
|
685
944
|
validateAlertData(type, data);
|
|
686
|
-
|
|
945
|
+
sentPayload = {
|
|
687
946
|
name,
|
|
688
947
|
type,
|
|
689
948
|
timeWindow,
|
|
@@ -691,7 +950,8 @@ USAGE:
|
|
|
691
950
|
data,
|
|
692
951
|
...(options.description ? { description: options.description } : {}),
|
|
693
952
|
isEnabled: !flags.disabled,
|
|
694
|
-
}
|
|
953
|
+
};
|
|
954
|
+
return apiInstance.alertsCreate(sentPayload);
|
|
695
955
|
},
|
|
696
956
|
'update': async () => {
|
|
697
957
|
const id = args[1];
|
|
@@ -730,6 +990,7 @@ USAGE:
|
|
|
730
990
|
if (flags.disabled) params.isEnabled = false;
|
|
731
991
|
// Validate merged data if present, otherwise validate existing data
|
|
732
992
|
validateAlertData(type, params.data ?? existing.data);
|
|
993
|
+
sentPayload = params;
|
|
733
994
|
return apiInstance.alertsUpdate(params);
|
|
734
995
|
},
|
|
735
996
|
'toggle': () => {
|
|
@@ -748,7 +1009,7 @@ USAGE:
|
|
|
748
1009
|
};
|
|
749
1010
|
|
|
750
1011
|
if (!handlers[sub]) {
|
|
751
|
-
throw
|
|
1012
|
+
throw unknownCommandError('alerts subcommand', sub, ['list', 'create', 'update', 'toggle', 'delete']);
|
|
752
1013
|
}
|
|
753
1014
|
|
|
754
1015
|
// Subcommand-level help: --help flag or "help" as second positional arg
|
|
@@ -758,8 +1019,10 @@ USAGE:
|
|
|
758
1019
|
}
|
|
759
1020
|
|
|
760
1021
|
try {
|
|
761
|
-
|
|
1022
|
+
const result = await handlers[sub]();
|
|
1023
|
+
return flags.reveal ? result : redactAlertSecrets(result);
|
|
762
1024
|
} catch (err) {
|
|
1025
|
+
let error = err;
|
|
763
1026
|
// Rewrite cryptic channel validation errors from the API into actionable messages.
|
|
764
1027
|
// e.g. "Failed to send a welcome message to the channel index 0" → tells the user
|
|
765
1028
|
// which channel type failed and what to check.
|
|
@@ -776,9 +1039,14 @@ USAGE:
|
|
|
776
1039
|
: ch?.type === 'webhook'
|
|
777
1040
|
? `Invalid webhook URL (${ch.data.webhookUrl}). Ensure the endpoint is reachable and returns 2xx.`
|
|
778
1041
|
: err.message;
|
|
779
|
-
|
|
1042
|
+
// Keep the API's details (and its request ID); they are redacted below
|
|
1043
|
+
// like any other error body unless --reveal is passed.
|
|
1044
|
+
error = new NansenError(hint, err.code ?? ErrorCode.INVALID_PARAMS, err.status, err.details ?? null);
|
|
780
1045
|
}
|
|
781
|
-
|
|
1046
|
+
// API error bodies (message and details) can echo the submitted channels,
|
|
1047
|
+
// and the hint above quotes the webhook URL; all are masked here unless
|
|
1048
|
+
// --reveal is passed.
|
|
1049
|
+
throw flags.reveal ? error : redactAlertError(error, options, sentPayload);
|
|
782
1050
|
}
|
|
783
1051
|
},
|
|
784
1052
|
};
|