@cleanslop/cli 0.0.0-stage → 0.1.0-beta.1.2
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 +86 -2
- package/assets/skill-core.md +62 -0
- package/dist/action.d.ts +5 -0
- package/dist/action.js +22 -0
- package/dist/action.js.map +1 -0
- package/dist/args.d.ts +4 -0
- package/dist/args.js +243 -0
- package/dist/args.js.map +1 -0
- package/dist/commands/credits.d.ts +29 -0
- package/dist/commands/credits.js +267 -0
- package/dist/commands/credits.js.map +1 -0
- package/dist/commands/email.d.ts +3 -0
- package/dist/commands/email.js +51 -0
- package/dist/commands/email.js.map +1 -0
- package/dist/commands/link-identity.d.ts +3 -0
- package/dist/commands/link-identity.js +37 -0
- package/dist/commands/link-identity.js.map +1 -0
- package/dist/commands/link-login.d.ts +3 -0
- package/dist/commands/link-login.js +63 -0
- package/dist/commands/link-login.js.map +1 -0
- package/dist/commands/login.d.ts +6 -0
- package/dist/commands/login.js +198 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +40 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/report.d.ts +8 -0
- package/dist/commands/report.js +55 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/scan-upload.d.ts +3 -0
- package/dist/commands/scan-upload.js +85 -0
- package/dist/commands/scan-upload.js.map +1 -0
- package/dist/commands/scan.d.ts +3 -0
- package/dist/commands/scan.js +81 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/setup.d.ts +19 -0
- package/dist/commands/setup.js +154 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.js +29 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/whoami.d.ts +3 -0
- package/dist/commands/whoami.js +44 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/config.d.ts +26 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +64 -0
- package/dist/credentials.js +220 -0
- package/dist/credentials.js.map +1 -0
- package/dist/deps.d.ts +58 -0
- package/dist/deps.js +148 -0
- package/dist/deps.js.map +1 -0
- package/dist/exit.d.ts +24 -0
- package/dist/exit.js +29 -0
- package/dist/exit.js.map +1 -0
- package/dist/git.d.ts +14 -0
- package/dist/git.js +161 -0
- package/dist/git.js.map +1 -0
- package/dist/http.d.ts +16 -0
- package/dist/http.js +210 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/link.d.ts +106 -0
- package/dist/link.js +650 -0
- package/dist/link.js.map +1 -0
- package/dist/main.d.ts +6 -0
- package/dist/main.js +75 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp-config.d.ts +13 -0
- package/dist/mcp-config.js +65 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/output.d.ts +9 -0
- package/dist/output.js +65 -0
- package/dist/output.js.map +1 -0
- package/dist/pack.d.ts +30 -0
- package/dist/pack.js +283 -0
- package/dist/pack.js.map +1 -0
- package/dist/redact.d.ts +2 -0
- package/dist/redact.js +17 -0
- package/dist/redact.js.map +1 -0
- package/dist/skill.d.ts +10 -0
- package/dist/skill.js +110 -0
- package/dist/skill.js.map +1 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ustar.d.ts +7 -0
- package/dist/ustar.js +128 -0
- package/dist/ustar.js.map +1 -0
- package/dist/wait.d.ts +11 -0
- package/dist/wait.js +80 -0
- package/dist/wait.js.map +1 -0
- package/package.json +30 -4
package/dist/http.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { USER_AGENT } from "./config.js";
|
|
2
|
+
import { actionError, CliError, EXIT_ACTION, EXIT_PAYMENT, EXIT_POLICY, EXIT_RUNNING, EXIT_SCAN_FAILED, EXIT_SOURCE, EXIT_UNEXPECTED, EXIT_USAGE, } from "./exit.js";
|
|
3
|
+
export function hasIdentityPresentationChallenge(result) {
|
|
4
|
+
if (result.status !== 401)
|
|
5
|
+
return false;
|
|
6
|
+
const body = asErrorBody(result.json);
|
|
7
|
+
if (body.error === "identity_presentation_required")
|
|
8
|
+
return true;
|
|
9
|
+
const www = result.headers.get("www-authenticate") ?? "";
|
|
10
|
+
return /identity-presentation/i.test(www);
|
|
11
|
+
}
|
|
12
|
+
export function asRecord(value) {
|
|
13
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
export function asErrorBody(value) {
|
|
19
|
+
return (asRecord(value) ?? {});
|
|
20
|
+
}
|
|
21
|
+
export async function httpRequest(deps, origin, method, path, opts = {}) {
|
|
22
|
+
const url = `${origin}${path}`;
|
|
23
|
+
const headers = new Headers(opts.headers);
|
|
24
|
+
headers.set("User-Agent", USER_AGENT);
|
|
25
|
+
headers.set("Accept", opts.accept ?? "application/json");
|
|
26
|
+
if (opts.token) {
|
|
27
|
+
headers.set("Authorization", `Bearer ${opts.token}`);
|
|
28
|
+
}
|
|
29
|
+
if (opts.rawBody) {
|
|
30
|
+
headers.set("Content-Type", opts.contentType ?? "application/octet-stream");
|
|
31
|
+
}
|
|
32
|
+
else if (opts.body !== undefined) {
|
|
33
|
+
headers.set("Content-Type", opts.contentType ?? "application/json");
|
|
34
|
+
}
|
|
35
|
+
const init = {
|
|
36
|
+
method,
|
|
37
|
+
headers,
|
|
38
|
+
redirect: "manual",
|
|
39
|
+
};
|
|
40
|
+
if (opts.rawBody) {
|
|
41
|
+
init.body = Buffer.from(opts.rawBody);
|
|
42
|
+
}
|
|
43
|
+
else if (opts.body !== undefined) {
|
|
44
|
+
init.body = JSON.stringify(opts.body);
|
|
45
|
+
}
|
|
46
|
+
let response;
|
|
47
|
+
try {
|
|
48
|
+
response = await deps.request(url, init);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
52
|
+
throw new CliError(`Network error: ${message}`, EXIT_UNEXPECTED);
|
|
53
|
+
}
|
|
54
|
+
const text = await response.text();
|
|
55
|
+
let json = null;
|
|
56
|
+
if (text) {
|
|
57
|
+
try {
|
|
58
|
+
json = JSON.parse(text);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
json = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
status: response.status,
|
|
66
|
+
headers: response.headers,
|
|
67
|
+
text,
|
|
68
|
+
json,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function actionFromBody(body, fallback) {
|
|
72
|
+
const kind = mapActionKind(body.action?.kind, fallback);
|
|
73
|
+
return {
|
|
74
|
+
kind,
|
|
75
|
+
humanPrompt: body.action?.humanPrompt ??
|
|
76
|
+
body.message ??
|
|
77
|
+
body.error_description ??
|
|
78
|
+
body.error ??
|
|
79
|
+
"A human action is required.",
|
|
80
|
+
url: body.action?.url,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function mapActionKind(raw, fallback) {
|
|
84
|
+
switch (raw) {
|
|
85
|
+
case "approve":
|
|
86
|
+
case "install":
|
|
87
|
+
case "top-up":
|
|
88
|
+
case "beta":
|
|
89
|
+
case "reauth":
|
|
90
|
+
case "present_identity":
|
|
91
|
+
case "link_existing":
|
|
92
|
+
case "ask_human":
|
|
93
|
+
case "ask_email":
|
|
94
|
+
case "wait":
|
|
95
|
+
return raw;
|
|
96
|
+
case "open_url":
|
|
97
|
+
return fallback;
|
|
98
|
+
default:
|
|
99
|
+
return fallback;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function throwHttpError(result) {
|
|
103
|
+
const body = asErrorBody(result.json);
|
|
104
|
+
const code = body.error ?? "";
|
|
105
|
+
const message = body.message ?? body.error_description ?? code ?? `HTTP ${result.status}`;
|
|
106
|
+
if (hasIdentityPresentationChallenge(result)) {
|
|
107
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "present_identity"));
|
|
108
|
+
}
|
|
109
|
+
switch (code) {
|
|
110
|
+
case "authorization_pending":
|
|
111
|
+
case "slow_down":
|
|
112
|
+
throw new CliError(message, EXIT_ACTION);
|
|
113
|
+
case "access_denied":
|
|
114
|
+
case "expired_token":
|
|
115
|
+
case "invalid_grant":
|
|
116
|
+
throw actionError(message, {
|
|
117
|
+
kind: "approve",
|
|
118
|
+
humanPrompt: message,
|
|
119
|
+
});
|
|
120
|
+
case "out_of_scans":
|
|
121
|
+
throw new CliError(message, EXIT_PAYMENT, actionFromBody(body, "top-up"));
|
|
122
|
+
case "repo_not_connected":
|
|
123
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "install"));
|
|
124
|
+
case "github_reauth_required":
|
|
125
|
+
case "token_revoked":
|
|
126
|
+
case "token_expired":
|
|
127
|
+
case "invalid_token":
|
|
128
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "reauth"));
|
|
129
|
+
case "account_exists":
|
|
130
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "link_existing"));
|
|
131
|
+
case "link_pilot_required":
|
|
132
|
+
case "terms_required":
|
|
133
|
+
case "link_email_unverified":
|
|
134
|
+
case "link_email_mismatch":
|
|
135
|
+
case "link_email_in_use":
|
|
136
|
+
case "uploads_unavailable":
|
|
137
|
+
case "upload_quota":
|
|
138
|
+
throw new CliError(message, EXIT_POLICY, actionFromBody(body, "ask_human"));
|
|
139
|
+
case "link_unavailable":
|
|
140
|
+
throw new CliError(message, EXIT_UNEXPECTED);
|
|
141
|
+
case "beta_required":
|
|
142
|
+
throw new CliError(message, EXIT_POLICY, actionFromBody(body, "beta"));
|
|
143
|
+
case "waitlisted":
|
|
144
|
+
case "incomplete":
|
|
145
|
+
case "agent_daily_cap":
|
|
146
|
+
case "insufficient_scope":
|
|
147
|
+
throw new CliError(message, EXIT_POLICY, actionFromBody(body, "ask_human"));
|
|
148
|
+
case "commit_not_on_github":
|
|
149
|
+
case "unsupported_remote":
|
|
150
|
+
throw new CliError(message, EXIT_SOURCE, actionFromBody(body, "ask_human"));
|
|
151
|
+
case "scan_failed":
|
|
152
|
+
throw new CliError(message, EXIT_SCAN_FAILED, actionFromBody(body, "ask_human"));
|
|
153
|
+
case "rate_limited":
|
|
154
|
+
case "capacity":
|
|
155
|
+
throw new CliError(message, EXIT_RUNNING, actionFromBody(body, "wait"));
|
|
156
|
+
case "github_unavailable":
|
|
157
|
+
throw new CliError(message, EXIT_UNEXPECTED, actionFromBody(body, "wait"));
|
|
158
|
+
case "training_decision_required":
|
|
159
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "ask_human"));
|
|
160
|
+
case "report_not_ready":
|
|
161
|
+
case "scan_in_progress":
|
|
162
|
+
throw new CliError(message, EXIT_RUNNING, actionFromBody(body, "wait"));
|
|
163
|
+
case "invalid_request":
|
|
164
|
+
case "invalid_client":
|
|
165
|
+
case "unsupported_grant_type":
|
|
166
|
+
case "prompt_must_quote_recipient":
|
|
167
|
+
throw new CliError(message, EXIT_USAGE);
|
|
168
|
+
case "no_verified_email":
|
|
169
|
+
case "done_alerts_disabled":
|
|
170
|
+
case "already_sent":
|
|
171
|
+
case "too_late":
|
|
172
|
+
throw new CliError(message, EXIT_POLICY, actionFromBody(body, "ask_human"));
|
|
173
|
+
default:
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (result.status === 401) {
|
|
177
|
+
const www = result.headers.get("www-authenticate") ?? "";
|
|
178
|
+
if (/identity-presentation/i.test(www)) {
|
|
179
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "present_identity"));
|
|
180
|
+
}
|
|
181
|
+
throw new CliError(message, EXIT_ACTION, actionFromBody(body, "reauth"));
|
|
182
|
+
}
|
|
183
|
+
if (result.status === 402) {
|
|
184
|
+
throw new CliError(message, EXIT_PAYMENT, actionFromBody(body, "top-up"));
|
|
185
|
+
}
|
|
186
|
+
if (result.status === 403) {
|
|
187
|
+
throw new CliError(message, EXIT_POLICY, actionFromBody(body, "ask_human"));
|
|
188
|
+
}
|
|
189
|
+
throw new CliError(message || `HTTP ${result.status}`, EXIT_UNEXPECTED);
|
|
190
|
+
}
|
|
191
|
+
export function requireOk(result) {
|
|
192
|
+
if (result.status >= 200 && result.status < 300)
|
|
193
|
+
return result;
|
|
194
|
+
throwHttpError(result);
|
|
195
|
+
}
|
|
196
|
+
export function retryAfterMs(result, fallback) {
|
|
197
|
+
const header = result.headers.get("retry-after");
|
|
198
|
+
if (header) {
|
|
199
|
+
const sec = Number(header);
|
|
200
|
+
if (Number.isFinite(sec) && sec >= 0)
|
|
201
|
+
return Math.max(sec * 1000, fallback);
|
|
202
|
+
}
|
|
203
|
+
const body = asErrorBody(result.json);
|
|
204
|
+
const retry = body.action?.retryAfterSec;
|
|
205
|
+
if (typeof retry === "number" && retry >= 0) {
|
|
206
|
+
return Math.max(retry * 1000, fallback);
|
|
207
|
+
}
|
|
208
|
+
return fallback;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,WAAW,EACX,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,GAGX,MAAM,WAAW,CAAC;AAGnB,MAAM,UAAU,gCAAgC,CAAC,MAAkB;IACjE,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IACxC,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,IAAI,CAAC,KAAK,KAAK,gCAA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E,eAAe,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC1C,IAAI,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,MAAM,CAAC;IAC/D,cAAc,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,QAAgB;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACjD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runCli } from "./main.js";
|
|
3
|
+
runCli(process.argv.slice(2)).then((code) => {
|
|
4
|
+
process.exitCode = code;
|
|
5
|
+
}, (err) => {
|
|
6
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
7
|
+
process.stderr.write(`${message}\n`);
|
|
8
|
+
process.exitCode = 1;
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAChC,CAAC,IAAI,EAAE,EAAE;IACP,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC1B,CAAC,EACD,CAAC,GAAY,EAAE,EAAE;IACf,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;IACrC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CACF,CAAC"}
|
package/dist/link.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { CliDeps, GitResult } from "./deps.js";
|
|
2
|
+
import type { ParsedArgs } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Spend-request / SPT grant. Login never requests this. `credits buy` adds it
|
|
5
|
+
* with `auth upgrade` (or `auth login` when there is no session yet).
|
|
6
|
+
*/
|
|
7
|
+
export declare const LINK_PAYMENT_SCOPE = "payment_methods.agentic";
|
|
8
|
+
/**
|
|
9
|
+
* link-cli 0.27 defaults to `userinfo:read payment_methods.agentic` when
|
|
10
|
+
* `--scope` is omitted. Login must pass a non-empty non-payment scope.
|
|
11
|
+
* Email still comes from the identity presentation; we never call
|
|
12
|
+
* `user-info retrieve`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const LINK_LOGIN_SCOPE = "userinfo:read";
|
|
15
|
+
export declare const LINK_IDENTITY_CLAIMS: readonly ["email", "email_verified"];
|
|
16
|
+
export type LinkAttestation = {
|
|
17
|
+
authorization: string;
|
|
18
|
+
};
|
|
19
|
+
export type LinkPresentation = {
|
|
20
|
+
presentation: string;
|
|
21
|
+
};
|
|
22
|
+
export type LinkClaimsChallenge = {
|
|
23
|
+
aud: string;
|
|
24
|
+
nonce: string;
|
|
25
|
+
claims: string[];
|
|
26
|
+
interactionId: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `CLEANSLOP_LINK_CLI`, else `link-cli` on PATH, else the pinned
|
|
30
|
+
* `@stripe/link-cli` through npx, so `npx @cleanslop/cli` needs nothing else
|
|
31
|
+
* installed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runLinkCli(deps: CliDeps, args: string[], opts?: {
|
|
34
|
+
timeout?: number;
|
|
35
|
+
}): Promise<GitResult>;
|
|
36
|
+
export declare function linkScopeTokens(scope: unknown): string[];
|
|
37
|
+
export type LinkAuthMode = "wait" | "no-wait" | "resume";
|
|
38
|
+
export declare function linkAuthMode(args: ParsedArgs): LinkAuthMode;
|
|
39
|
+
/**
|
|
40
|
+
* Starts Link's device sign-in when link-cli has no session (a fresh machine or
|
|
41
|
+
* cloud sandbox). Does not request `payment_methods.agentic`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function ensureLinkAuth(deps: CliDeps, opts?: {
|
|
44
|
+
mode?: LinkAuthMode;
|
|
45
|
+
command?: string;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Ensures the Link session can create spend requests. Existing sessions that
|
|
49
|
+
* already granted `payment_methods.agentic` are left as-is. A session without
|
|
50
|
+
* that grant is widened with `auth upgrade`. No session logs in with the
|
|
51
|
+
* payment scope so a cold `credits buy` is one approval, not login + upgrade.
|
|
52
|
+
*/
|
|
53
|
+
export declare function ensureLinkPaymentScope(deps: CliDeps, opts?: {
|
|
54
|
+
mode?: LinkAuthMode;
|
|
55
|
+
command?: string;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
/** Refills an empty pool. Link issues attestations without a per-request approval. */
|
|
58
|
+
export declare function popAttestation(deps: CliDeps): Promise<LinkAttestation>;
|
|
59
|
+
export declare function requestLinkCredentials(deps: CliDeps): Promise<void>;
|
|
60
|
+
export declare function presentLinkIdentity(deps: CliDeps, input: {
|
|
61
|
+
aud: string;
|
|
62
|
+
nonce: string;
|
|
63
|
+
}): Promise<LinkPresentation>;
|
|
64
|
+
export declare function readLinkClaimsChallenge(body: unknown, origin: string): LinkClaimsChallenge;
|
|
65
|
+
export type LinkConsentSource = "flag" | "tty";
|
|
66
|
+
export declare function linkTermsUrl(origin: string): string;
|
|
67
|
+
export declare function linkTermsQuestion(termsUrl: string): string;
|
|
68
|
+
export declare function linkShareEmailQuestion(origin: string): string;
|
|
69
|
+
export declare function linkBridgeEmailQuestion(origin: string): string;
|
|
70
|
+
export declare function requireLinkSignupConsent(deps: CliDeps, args: ParsedArgs, origin: string): Promise<LinkConsentSource>;
|
|
71
|
+
export declare function requireLinkBridgeConsent(deps: CliDeps, args: ParsedArgs, origin: string): Promise<LinkConsentSource>;
|
|
72
|
+
/** Same schedule as link-cli `runMppPayWithSpendRequest`. */
|
|
73
|
+
export declare const SPT_RETRIEVAL_DELAYS_MS: number[];
|
|
74
|
+
export type SpendRequestStatus = "pending" | "approved" | "denied" | "expired" | "requires_action" | "canceled" | "unknown";
|
|
75
|
+
export type SpendRequestSnapshot = {
|
|
76
|
+
id: string;
|
|
77
|
+
status: SpendRequestStatus;
|
|
78
|
+
displayMessage: string | null;
|
|
79
|
+
resolution: string | null;
|
|
80
|
+
sharedPaymentToken: string | null;
|
|
81
|
+
approvalUrl: string | null;
|
|
82
|
+
};
|
|
83
|
+
export declare function parseSpendRequestJson(stdout: string): SpendRequestSnapshot | null;
|
|
84
|
+
/** Hidden test override. Exact `"1"` appends `--test` on spend-request create. */
|
|
85
|
+
export declare function linkSpendRequestTestArgs(deps: CliDeps): string[];
|
|
86
|
+
export declare function isLinkSpendRequestNotFound(result: GitResult): boolean;
|
|
87
|
+
export declare function createLinkSpendRequest(deps: CliDeps, input: {
|
|
88
|
+
networkId: string;
|
|
89
|
+
amount: number;
|
|
90
|
+
currency: string;
|
|
91
|
+
context: string;
|
|
92
|
+
lineItem: string;
|
|
93
|
+
total: string;
|
|
94
|
+
idempotencyKey: string;
|
|
95
|
+
}): Promise<SpendRequestSnapshot>;
|
|
96
|
+
export declare function retrieveLinkSpendRequest(deps: CliDeps, spendRequestId: string, opts?: {
|
|
97
|
+
includeSpt?: boolean;
|
|
98
|
+
}): Promise<SpendRequestSnapshot>;
|
|
99
|
+
export declare function retrieveSharedPaymentToken(deps: CliDeps, spendRequestId: string): Promise<string | null>;
|
|
100
|
+
export declare function linkSignupBody(deps: CliDeps, acceptTerms: string, consentSource: LinkConsentSource): {
|
|
101
|
+
client: string;
|
|
102
|
+
agentHint: string;
|
|
103
|
+
hostHint: string;
|
|
104
|
+
acceptTerms: string;
|
|
105
|
+
consentSource: LinkConsentSource;
|
|
106
|
+
};
|