@quillaudits/cli 0.1.3 → 0.2.1
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 +30 -17
- package/dist/qs.js +1357 -107
- package/package.json +7 -2
package/dist/qs.js
CHANGED
|
@@ -4,8 +4,9 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
8
|
-
import { basename, resolve } from "node:path";
|
|
7
|
+
import { readFileSync as readFileSync2, existsSync, statSync as statSync2, writeFileSync } from "node:fs";
|
|
8
|
+
import { basename as basename2, resolve } from "node:path";
|
|
9
|
+
import { createInterface } from "node:readline";
|
|
9
10
|
|
|
10
11
|
// src/config.ts
|
|
11
12
|
import { homedir } from "node:os";
|
|
@@ -62,6 +63,25 @@ async function requireConfig() {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// src/api.ts
|
|
66
|
+
class ApiClientError extends Error {
|
|
67
|
+
status;
|
|
68
|
+
code;
|
|
69
|
+
details;
|
|
70
|
+
constructor(status, code, message, details) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.name = "ApiClientError";
|
|
73
|
+
this.status = status;
|
|
74
|
+
this.code = code;
|
|
75
|
+
this.details = details;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function isPaymentRequiredDetails(d) {
|
|
79
|
+
if (!d || typeof d !== "object")
|
|
80
|
+
return false;
|
|
81
|
+
const o = d;
|
|
82
|
+
return typeof o.quote_id === "string" && typeof o.project_id === "string" && typeof o.project_version_id === "string" && o.quote != null && typeof o.quote === "object" && o.project != null && typeof o.project === "object" && o.version != null && typeof o.version === "object";
|
|
83
|
+
}
|
|
84
|
+
|
|
65
85
|
class QuillShieldApi {
|
|
66
86
|
cfg;
|
|
67
87
|
constructor(cfg) {
|
|
@@ -91,25 +111,20 @@ class QuillShieldApi {
|
|
|
91
111
|
return null;
|
|
92
112
|
const text = await res.text();
|
|
93
113
|
if (!res.ok) {
|
|
94
|
-
let parsed;
|
|
114
|
+
let parsed = null;
|
|
95
115
|
try {
|
|
96
116
|
parsed = JSON.parse(text);
|
|
97
117
|
} catch {
|
|
98
|
-
throw new
|
|
118
|
+
throw new ApiClientError(res.status, "http_error", `API error ${res.status}: ${text.slice(0, 200)}`);
|
|
99
119
|
}
|
|
100
|
-
|
|
101
|
-
const err = new Error(msg);
|
|
102
|
-
err.code = parsed.error?.code;
|
|
103
|
-
err.details = parsed.error?.details;
|
|
104
|
-
throw err;
|
|
120
|
+
throw new ApiClientError(res.status, parsed.error?.code ?? "http_error", parsed.error?.message ?? `API error ${res.status}`, parsed.error?.details);
|
|
105
121
|
}
|
|
106
122
|
if (!text)
|
|
107
123
|
return null;
|
|
108
124
|
return JSON.parse(text);
|
|
109
125
|
}
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
return { orgs: [] };
|
|
126
|
+
async getConfig() {
|
|
127
|
+
return this.request("GET", "/v1/config");
|
|
113
128
|
}
|
|
114
129
|
async listProjects() {
|
|
115
130
|
return this.request("GET", "/v1/projects");
|
|
@@ -120,20 +135,117 @@ class QuillShieldApi {
|
|
|
120
135
|
async listVersions(projectId) {
|
|
121
136
|
return this.request("GET", `/v1/projects/${projectId}/versions`);
|
|
122
137
|
}
|
|
123
|
-
async
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
async submitForCheckout(args) {
|
|
139
|
+
try {
|
|
140
|
+
if (args.kind === "git") {
|
|
141
|
+
await this.request("POST", "/v1/audit/submit", {
|
|
142
|
+
body: {
|
|
143
|
+
repo_url: args.repo_url,
|
|
144
|
+
git_ref: args.git_ref,
|
|
145
|
+
project_name: args.project_name,
|
|
146
|
+
scope_files: args.scope_files
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
const form = new FormData;
|
|
151
|
+
const blob = new Blob([new Uint8Array(args.file)], { type: "application/zip" });
|
|
152
|
+
form.append("file", blob, args.filename);
|
|
153
|
+
if (args.project_name)
|
|
154
|
+
form.append("project_name", args.project_name);
|
|
155
|
+
if (args.scope_files?.length) {
|
|
156
|
+
form.append("scope_files", args.scope_files.join(`
|
|
134
157
|
`));
|
|
158
|
+
}
|
|
159
|
+
await this.request("POST", "/v1/audit/submit", { body: form });
|
|
160
|
+
}
|
|
161
|
+
throw new Error("Unexpected success from /audit/submit — expected payment_required");
|
|
162
|
+
} catch (err) {
|
|
163
|
+
if (err instanceof ApiClientError && err.code === "payment_required" && isPaymentRequiredDetails(err.details)) {
|
|
164
|
+
const d = err.details;
|
|
165
|
+
return {
|
|
166
|
+
quote_id: d.quote_id,
|
|
167
|
+
project: d.project,
|
|
168
|
+
version: d.version,
|
|
169
|
+
quote: d.quote,
|
|
170
|
+
scope: d.scope ?? { file_count: 0, files: [], total_files: 0 }
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
throw err;
|
|
135
174
|
}
|
|
136
|
-
|
|
175
|
+
}
|
|
176
|
+
async createQuote(projectVersionId) {
|
|
177
|
+
return this.request("POST", "/v1/quotes", {
|
|
178
|
+
body: { project_version_id: projectVersionId }
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async getQuote(quoteId) {
|
|
182
|
+
return this.request("GET", `/v1/quotes/${quoteId}`);
|
|
183
|
+
}
|
|
184
|
+
async applyCoupon(quoteId, couponCode) {
|
|
185
|
+
return this.request("POST", `/v1/quotes/${quoteId}/apply-coupon`, {
|
|
186
|
+
body: { coupon_code: couponCode }
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
async removeCoupon(quoteId) {
|
|
190
|
+
return this.request("POST", `/v1/quotes/${quoteId}/remove-coupon`, {
|
|
191
|
+
body: {}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
async createOrder(quoteId, paymentMethod) {
|
|
195
|
+
return this.request("POST", `/v1/quotes/${quoteId}/orders`, {
|
|
196
|
+
body: { payment_method: paymentMethod }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async getOrder(orderId) {
|
|
200
|
+
return this.request("GET", `/v1/orders/${orderId}`);
|
|
201
|
+
}
|
|
202
|
+
async listOrders() {
|
|
203
|
+
return this.request("GET", "/v1/orders");
|
|
204
|
+
}
|
|
205
|
+
async confirmStripePayment(orderId) {
|
|
206
|
+
return this.request("POST", `/v1/orders/${orderId}/confirm-stripe-payment`, {
|
|
207
|
+
body: {}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
async refreshCheckoutSession(orderId) {
|
|
211
|
+
return this.request("POST", `/v1/orders/${orderId}/refresh-checkout-session`, {
|
|
212
|
+
body: {}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
async startAudit(orderId) {
|
|
216
|
+
return this.request("POST", `/v1/orders/${orderId}/start-audit`, {
|
|
217
|
+
body: {}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
async mockConfirmPayment(orderId) {
|
|
221
|
+
return this.request("POST", "/v1/webhooks/mock-confirm", {
|
|
222
|
+
body: { order_id: orderId }
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
async mockConfirmTopup(topupOrderId) {
|
|
226
|
+
return this.request("POST", "/v1/webhooks/mock-confirm-topup", {
|
|
227
|
+
body: { topup_order_id: topupOrderId }
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async getWallet() {
|
|
231
|
+
return this.request("GET", "/v1/wallet");
|
|
232
|
+
}
|
|
233
|
+
async getWalletTransactions() {
|
|
234
|
+
return this.request("GET", "/v1/wallet/transactions");
|
|
235
|
+
}
|
|
236
|
+
async createWalletTopup(amountCents) {
|
|
237
|
+
return this.request("POST", "/v1/wallet/topups", {
|
|
238
|
+
body: { amount_cents: amountCents }
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async getWalletTopup(topupOrderId) {
|
|
242
|
+
return this.request("GET", `/v1/wallet/topups/${topupOrderId}`);
|
|
243
|
+
}
|
|
244
|
+
async confirmWalletTopupPayment(topupOrderId) {
|
|
245
|
+
return this.request("POST", `/v1/wallet/topups/${topupOrderId}/confirm-stripe-payment`, { body: {} });
|
|
246
|
+
}
|
|
247
|
+
async refreshWalletTopupCheckoutSession(topupOrderId) {
|
|
248
|
+
return this.request("POST", `/v1/wallet/topups/${topupOrderId}/refresh-checkout-session`, { body: {} });
|
|
137
249
|
}
|
|
138
250
|
async getAudit(jobId) {
|
|
139
251
|
return this.request("GET", `/v1/audits/${jobId}`);
|
|
@@ -149,10 +261,30 @@ class QuillShieldApi {
|
|
|
149
261
|
}
|
|
150
262
|
async getReportUrl(jobId, format = "pdf") {
|
|
151
263
|
const res = await this.request("GET", `/v1/audits/${jobId}/report?format=${format}`);
|
|
152
|
-
|
|
264
|
+
if (typeof res === "string")
|
|
265
|
+
return res;
|
|
266
|
+
return res.url ?? JSON.stringify(res);
|
|
153
267
|
}
|
|
154
|
-
async
|
|
155
|
-
|
|
268
|
+
async downloadReport(jobId, format = "pdf") {
|
|
269
|
+
const url = `${this.cfg.api_url}/v1/audits/${jobId}/report?format=${format}`;
|
|
270
|
+
const res = await fetch(url, { headers: this.headers({ Accept: "*/*" }) });
|
|
271
|
+
if (!res.ok) {
|
|
272
|
+
const text = await res.text();
|
|
273
|
+
throw new ApiClientError(res.status, "http_error", text.slice(0, 200) || `Report download failed (${res.status})`);
|
|
274
|
+
}
|
|
275
|
+
const contentType = res.headers.get("content-type") ?? "application/octet-stream";
|
|
276
|
+
if (contentType.includes("application/json")) {
|
|
277
|
+
const body = await res.json();
|
|
278
|
+
if (body.url) {
|
|
279
|
+
const fileRes = await fetch(body.url);
|
|
280
|
+
if (!fileRes.ok)
|
|
281
|
+
throw new Error(`Failed to download report from URL (${fileRes.status})`);
|
|
282
|
+
const bytes2 = Buffer.from(await fileRes.arrayBuffer());
|
|
283
|
+
return { bytes: bytes2, contentType: fileRes.headers.get("content-type") ?? contentType, filename: `report-${jobId}.${format}` };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
287
|
+
return { bytes, contentType, filename: `report-${jobId}.${format}` };
|
|
156
288
|
}
|
|
157
289
|
streamEvents(jobId, onEvent, onError) {
|
|
158
290
|
const url = `${this.cfg.api_url}/v1/audits/${jobId}/events?api_key=${encodeURIComponent(this.cfg.api_key)}`;
|
|
@@ -219,6 +351,898 @@ function parseSse(raw) {
|
|
|
219
351
|
return { event, data: dataStr };
|
|
220
352
|
}
|
|
221
353
|
}
|
|
354
|
+
function formatUsd(cents) {
|
|
355
|
+
return `$${(cents / 100).toFixed(2)}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/payment.ts
|
|
359
|
+
import { spawn } from "node:child_process";
|
|
360
|
+
import { platform } from "node:os";
|
|
361
|
+
function defaultLog() {
|
|
362
|
+
return {
|
|
363
|
+
info: (msg) => console.log(`● ${msg}`),
|
|
364
|
+
success: (msg) => console.log(`✓ ${msg}`),
|
|
365
|
+
warn: (msg) => console.log(`⚠ ${msg}`)
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function printQuote(quote) {
|
|
369
|
+
console.log();
|
|
370
|
+
console.log(` Quote ${quote.id}`);
|
|
371
|
+
console.log(` Tier ${quote.tier_label} (${quote.bloc_total} BLOC)`);
|
|
372
|
+
console.log(` Base ${formatUsd(quote.base_price_cents)}`);
|
|
373
|
+
if (quote.coupon_discount_cents > 0) {
|
|
374
|
+
console.log(` Coupon -${formatUsd(quote.coupon_discount_cents)}${quote.coupon_code ? ` (${quote.coupon_code})` : ""}`);
|
|
375
|
+
}
|
|
376
|
+
if (quote.cashback_cents > 0) {
|
|
377
|
+
console.log(` Cashback ${formatUsd(quote.cashback_cents)} (after pay)`);
|
|
378
|
+
}
|
|
379
|
+
if (quote.prepaid_credit_applied_cents > 0) {
|
|
380
|
+
console.log(` Prepaid -${formatUsd(quote.prepaid_credit_applied_cents)}`);
|
|
381
|
+
}
|
|
382
|
+
if (quote.refund_credit_applied_cents > 0) {
|
|
383
|
+
console.log(` Refund credit -${formatUsd(quote.refund_credit_applied_cents)}`);
|
|
384
|
+
}
|
|
385
|
+
if (quote.signup_bonus_applied_cents > 0) {
|
|
386
|
+
console.log(` Bonus -${formatUsd(quote.signup_bonus_applied_cents)}`);
|
|
387
|
+
}
|
|
388
|
+
console.log(` Due ${formatUsd(quote.final_price_cents)} ${quote.currency}`);
|
|
389
|
+
console.log(` Expires ${quote.expires_at}`);
|
|
390
|
+
console.log();
|
|
391
|
+
}
|
|
392
|
+
async function openBrowser(url) {
|
|
393
|
+
const p = platform();
|
|
394
|
+
const cmd = p === "darwin" ? "open" : p === "win32" ? "cmd" : "xdg-open";
|
|
395
|
+
const args = p === "win32" ? ["/c", "start", "", url] : [url];
|
|
396
|
+
await new Promise((resolve) => {
|
|
397
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
398
|
+
child.on("error", () => resolve());
|
|
399
|
+
child.unref();
|
|
400
|
+
setTimeout(resolve, 500);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
function selectCheckoutUrl(order) {
|
|
404
|
+
if (order.final_price_cents <= 0)
|
|
405
|
+
return null;
|
|
406
|
+
if (order.payment_status === "paid")
|
|
407
|
+
return null;
|
|
408
|
+
return order.stripe_checkout_url;
|
|
409
|
+
}
|
|
410
|
+
async function payQuoteAndStartAudit(api, quoteId, opts = {}) {
|
|
411
|
+
const log = opts.log ?? defaultLog();
|
|
412
|
+
const method = opts.method ?? "stripe";
|
|
413
|
+
const timeoutMs = opts.timeoutMs ?? 10 * 60 * 1000;
|
|
414
|
+
let quote = await api.getQuote(quoteId);
|
|
415
|
+
if (opts.coupon) {
|
|
416
|
+
log.info(`Applying coupon ${opts.coupon}...`);
|
|
417
|
+
quote = await api.applyCoupon(quoteId, opts.coupon);
|
|
418
|
+
}
|
|
419
|
+
printQuote(quote);
|
|
420
|
+
if (quote.final_price_cents > 0 && !opts.yes) {
|
|
421
|
+
const ok = opts.confirmCharge ? await opts.confirmCharge(quote) : true;
|
|
422
|
+
if (!ok) {
|
|
423
|
+
throw new Error("Payment cancelled");
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
log.info(`Creating ${method} order...`);
|
|
427
|
+
let order = await api.createOrder(quoteId, method);
|
|
428
|
+
log.success(`Order ${order.id} — ${order.payment_status} (${formatUsd(order.final_price_cents)})`);
|
|
429
|
+
const cfg = await api.getConfig().catch(() => ({ stripe_mock: false, crypto_enabled: false }));
|
|
430
|
+
const isMock = !!cfg.stripe_mock;
|
|
431
|
+
if (order.payment_status === "paid") {
|
|
432
|
+
log.success("Order already paid (covered by credits / $0).");
|
|
433
|
+
} else if (isMock) {
|
|
434
|
+
log.info("Mock payments enabled — confirming payment...");
|
|
435
|
+
const mock = await api.mockConfirmPayment(order.id);
|
|
436
|
+
order = await api.getOrder(order.id);
|
|
437
|
+
log.success(`Mock payment ${mock.order.payment_status}`);
|
|
438
|
+
} else {
|
|
439
|
+
if (!order.stripe_checkout_url) {
|
|
440
|
+
log.info("Refreshing checkout session...");
|
|
441
|
+
order = await api.refreshCheckoutSession(order.id);
|
|
442
|
+
}
|
|
443
|
+
const url = selectCheckoutUrl(order);
|
|
444
|
+
if (!url) {
|
|
445
|
+
throw new Error("No Stripe checkout URL available for this order");
|
|
446
|
+
}
|
|
447
|
+
if (url.startsWith("mock://")) {
|
|
448
|
+
throw new Error("Received mock checkout URL but stripe_mock is false — check API config");
|
|
449
|
+
}
|
|
450
|
+
console.log(` Checkout URL: ${url}`);
|
|
451
|
+
const doOpen = opts.open === true || opts.open !== false && !opts.noOpen && process.stdin.isTTY;
|
|
452
|
+
if (doOpen) {
|
|
453
|
+
log.info("Opening browser for payment...");
|
|
454
|
+
await openBrowser(url);
|
|
455
|
+
} else {
|
|
456
|
+
log.warn("Open the checkout URL in a browser to complete payment.");
|
|
457
|
+
}
|
|
458
|
+
log.info("Waiting for payment...");
|
|
459
|
+
const deadline = Date.now() + timeoutMs;
|
|
460
|
+
while (Date.now() < deadline) {
|
|
461
|
+
try {
|
|
462
|
+
order = await api.confirmStripePayment(order.id);
|
|
463
|
+
} catch {
|
|
464
|
+
order = await api.getOrder(order.id);
|
|
465
|
+
}
|
|
466
|
+
if (order.payment_status === "paid")
|
|
467
|
+
break;
|
|
468
|
+
if (order.payment_status === "failed" || order.payment_status === "cancelled") {
|
|
469
|
+
throw new Error(`Payment ${order.payment_status}`);
|
|
470
|
+
}
|
|
471
|
+
await sleep(3000);
|
|
472
|
+
}
|
|
473
|
+
if (order.payment_status !== "paid") {
|
|
474
|
+
throw new Error(`Timed out waiting for payment (status: ${order.payment_status})`);
|
|
475
|
+
}
|
|
476
|
+
log.success("Payment confirmed");
|
|
477
|
+
}
|
|
478
|
+
order = await api.getOrder(order.id);
|
|
479
|
+
let jobId = order.audit_job_id;
|
|
480
|
+
if (!jobId) {
|
|
481
|
+
if (order.payment_status !== "paid") {
|
|
482
|
+
throw new Error(`Cannot start audit — order is ${order.payment_status}`);
|
|
483
|
+
}
|
|
484
|
+
log.info("Starting audit...");
|
|
485
|
+
const started = await api.startAudit(order.id);
|
|
486
|
+
jobId = started.audit_job_id;
|
|
487
|
+
}
|
|
488
|
+
log.success(`Audit job ${jobId}`);
|
|
489
|
+
return { quote, order, audit_job_id: jobId };
|
|
490
|
+
}
|
|
491
|
+
async function payWalletTopup(api, amountCents, opts = {}) {
|
|
492
|
+
const log = opts.log ?? defaultLog();
|
|
493
|
+
const timeoutMs = opts.timeoutMs ?? 10 * 60 * 1000;
|
|
494
|
+
log.info(`Creating top-up for ${formatUsd(amountCents)}...`);
|
|
495
|
+
let topup = await api.createWalletTopup(amountCents);
|
|
496
|
+
const cfg = await api.getConfig().catch(() => ({ stripe_mock: false, crypto_enabled: false }));
|
|
497
|
+
if (cfg.stripe_mock) {
|
|
498
|
+
log.info("Mock payments enabled — confirming top-up...");
|
|
499
|
+
await api.mockConfirmTopup(topup.id);
|
|
500
|
+
topup = await api.getWalletTopup(topup.id);
|
|
501
|
+
} else {
|
|
502
|
+
if (!topup.stripe_checkout_url) {
|
|
503
|
+
topup = await api.refreshWalletTopupCheckoutSession(topup.id);
|
|
504
|
+
}
|
|
505
|
+
const url = topup.stripe_checkout_url;
|
|
506
|
+
if (!url)
|
|
507
|
+
throw new Error("No Stripe checkout URL for top-up");
|
|
508
|
+
console.log(` Checkout URL: ${url}`);
|
|
509
|
+
const doOpen = opts.open === true || opts.open !== false && !opts.noOpen && process.stdin.isTTY;
|
|
510
|
+
if (doOpen)
|
|
511
|
+
await openBrowser(url);
|
|
512
|
+
log.info("Waiting for top-up payment...");
|
|
513
|
+
const deadline = Date.now() + timeoutMs;
|
|
514
|
+
while (Date.now() < deadline) {
|
|
515
|
+
try {
|
|
516
|
+
topup = await api.confirmWalletTopupPayment(topup.id);
|
|
517
|
+
} catch {
|
|
518
|
+
topup = await api.getWalletTopup(topup.id);
|
|
519
|
+
}
|
|
520
|
+
if (topup.payment_status === "paid")
|
|
521
|
+
break;
|
|
522
|
+
if (topup.payment_status === "failed" || topup.payment_status === "cancelled") {
|
|
523
|
+
throw new Error(`Top-up ${topup.payment_status}`);
|
|
524
|
+
}
|
|
525
|
+
await sleep(3000);
|
|
526
|
+
}
|
|
527
|
+
if (topup.payment_status !== "paid") {
|
|
528
|
+
throw new Error(`Timed out waiting for top-up (status: ${topup.payment_status})`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
log.success(`Top-up ${topup.id} paid`);
|
|
532
|
+
return { topup };
|
|
533
|
+
}
|
|
534
|
+
function sleep(ms) {
|
|
535
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/folder-zip.ts
|
|
539
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
540
|
+
import { join as join2, relative, basename, sep } from "node:path";
|
|
541
|
+
|
|
542
|
+
// ../../node_modules/.bun/fflate@0.8.3/node_modules/fflate/esm/index.mjs
|
|
543
|
+
import { createRequire as createRequire2 } from "module";
|
|
544
|
+
var require2 = createRequire2("/");
|
|
545
|
+
var _a;
|
|
546
|
+
var Worker;
|
|
547
|
+
var isMarkedAsUntransferable;
|
|
548
|
+
try {
|
|
549
|
+
_a = require2("worker_threads"), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
|
|
550
|
+
} catch (e) {}
|
|
551
|
+
var u8 = Uint8Array;
|
|
552
|
+
var u16 = Uint16Array;
|
|
553
|
+
var i32 = Int32Array;
|
|
554
|
+
var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]);
|
|
555
|
+
var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]);
|
|
556
|
+
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
557
|
+
var freb = function(eb, start) {
|
|
558
|
+
var b = new u16(31);
|
|
559
|
+
for (var i = 0;i < 31; ++i) {
|
|
560
|
+
b[i] = start += 1 << eb[i - 1];
|
|
561
|
+
}
|
|
562
|
+
var r = new i32(b[30]);
|
|
563
|
+
for (var i = 1;i < 30; ++i) {
|
|
564
|
+
for (var j = b[i];j < b[i + 1]; ++j) {
|
|
565
|
+
r[j] = j - b[i] << 5 | i;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return { b, r };
|
|
569
|
+
};
|
|
570
|
+
var _a = freb(fleb, 2);
|
|
571
|
+
var fl = _a.b;
|
|
572
|
+
var revfl = _a.r;
|
|
573
|
+
fl[28] = 258, revfl[258] = 28;
|
|
574
|
+
var _b = freb(fdeb, 0);
|
|
575
|
+
var fd = _b.b;
|
|
576
|
+
var revfd = _b.r;
|
|
577
|
+
var rev = new u16(32768);
|
|
578
|
+
for (i = 0;i < 32768; ++i) {
|
|
579
|
+
x = (i & 43690) >> 1 | (i & 21845) << 1;
|
|
580
|
+
x = (x & 52428) >> 2 | (x & 13107) << 2;
|
|
581
|
+
x = (x & 61680) >> 4 | (x & 3855) << 4;
|
|
582
|
+
rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
|
|
583
|
+
}
|
|
584
|
+
var x;
|
|
585
|
+
var i;
|
|
586
|
+
var hMap = function(cd, mb, r) {
|
|
587
|
+
var s = cd.length;
|
|
588
|
+
var i2 = 0;
|
|
589
|
+
var l = new u16(mb);
|
|
590
|
+
for (;i2 < s; ++i2) {
|
|
591
|
+
if (cd[i2])
|
|
592
|
+
++l[cd[i2] - 1];
|
|
593
|
+
}
|
|
594
|
+
var le = new u16(mb);
|
|
595
|
+
for (i2 = 1;i2 < mb; ++i2) {
|
|
596
|
+
le[i2] = le[i2 - 1] + l[i2 - 1] << 1;
|
|
597
|
+
}
|
|
598
|
+
var co;
|
|
599
|
+
if (r) {
|
|
600
|
+
co = new u16(1 << mb);
|
|
601
|
+
var rvb = 15 - mb;
|
|
602
|
+
for (i2 = 0;i2 < s; ++i2) {
|
|
603
|
+
if (cd[i2]) {
|
|
604
|
+
var sv = i2 << 4 | cd[i2];
|
|
605
|
+
var r_1 = mb - cd[i2];
|
|
606
|
+
var v = le[cd[i2] - 1]++ << r_1;
|
|
607
|
+
for (var m = v | (1 << r_1) - 1;v <= m; ++v) {
|
|
608
|
+
co[rev[v] >> rvb] = sv;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
} else {
|
|
613
|
+
co = new u16(s);
|
|
614
|
+
for (i2 = 0;i2 < s; ++i2) {
|
|
615
|
+
if (cd[i2]) {
|
|
616
|
+
co[i2] = rev[le[cd[i2] - 1]++] >> 15 - cd[i2];
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return co;
|
|
621
|
+
};
|
|
622
|
+
var flt = new u8(288);
|
|
623
|
+
for (i = 0;i < 144; ++i)
|
|
624
|
+
flt[i] = 8;
|
|
625
|
+
var i;
|
|
626
|
+
for (i = 144;i < 256; ++i)
|
|
627
|
+
flt[i] = 9;
|
|
628
|
+
var i;
|
|
629
|
+
for (i = 256;i < 280; ++i)
|
|
630
|
+
flt[i] = 7;
|
|
631
|
+
var i;
|
|
632
|
+
for (i = 280;i < 288; ++i)
|
|
633
|
+
flt[i] = 8;
|
|
634
|
+
var i;
|
|
635
|
+
var fdt = new u8(32);
|
|
636
|
+
for (i = 0;i < 32; ++i)
|
|
637
|
+
fdt[i] = 5;
|
|
638
|
+
var i;
|
|
639
|
+
var flm = /* @__PURE__ */ hMap(flt, 9, 0);
|
|
640
|
+
var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
|
|
641
|
+
var shft = function(p) {
|
|
642
|
+
return (p + 7) / 8 | 0;
|
|
643
|
+
};
|
|
644
|
+
var slc = function(v, s, e) {
|
|
645
|
+
if (s == null || s < 0)
|
|
646
|
+
s = 0;
|
|
647
|
+
if (e == null || e > v.length)
|
|
648
|
+
e = v.length;
|
|
649
|
+
return new u8(v.subarray(s, e));
|
|
650
|
+
};
|
|
651
|
+
var ec = [
|
|
652
|
+
"unexpected EOF",
|
|
653
|
+
"invalid block type",
|
|
654
|
+
"invalid length/literal",
|
|
655
|
+
"invalid distance",
|
|
656
|
+
"stream finished",
|
|
657
|
+
"no stream handler",
|
|
658
|
+
,
|
|
659
|
+
"no callback",
|
|
660
|
+
"invalid UTF-8 data",
|
|
661
|
+
"extra field too long",
|
|
662
|
+
"date not in range 1980-2099",
|
|
663
|
+
"filename too long",
|
|
664
|
+
"stream finishing",
|
|
665
|
+
"invalid zip data"
|
|
666
|
+
];
|
|
667
|
+
var err = function(ind, msg, nt) {
|
|
668
|
+
var e = new Error(msg || ec[ind]);
|
|
669
|
+
e.code = ind;
|
|
670
|
+
if (Error.captureStackTrace)
|
|
671
|
+
Error.captureStackTrace(e, err);
|
|
672
|
+
if (!nt)
|
|
673
|
+
throw e;
|
|
674
|
+
return e;
|
|
675
|
+
};
|
|
676
|
+
var wbits = function(d, p, v) {
|
|
677
|
+
v <<= p & 7;
|
|
678
|
+
var o = p / 8 | 0;
|
|
679
|
+
d[o] |= v;
|
|
680
|
+
d[o + 1] |= v >> 8;
|
|
681
|
+
};
|
|
682
|
+
var wbits16 = function(d, p, v) {
|
|
683
|
+
v <<= p & 7;
|
|
684
|
+
var o = p / 8 | 0;
|
|
685
|
+
d[o] |= v;
|
|
686
|
+
d[o + 1] |= v >> 8;
|
|
687
|
+
d[o + 2] |= v >> 16;
|
|
688
|
+
};
|
|
689
|
+
var hTree = function(d, mb) {
|
|
690
|
+
var t = [];
|
|
691
|
+
for (var i2 = 0;i2 < d.length; ++i2) {
|
|
692
|
+
if (d[i2])
|
|
693
|
+
t.push({ s: i2, f: d[i2] });
|
|
694
|
+
}
|
|
695
|
+
var s = t.length;
|
|
696
|
+
var t2 = t.slice();
|
|
697
|
+
if (!s)
|
|
698
|
+
return { t: et, l: 0 };
|
|
699
|
+
if (s == 1) {
|
|
700
|
+
var v = new u8(t[0].s + 1);
|
|
701
|
+
v[t[0].s] = 1;
|
|
702
|
+
return { t: v, l: 1 };
|
|
703
|
+
}
|
|
704
|
+
t.sort(function(a, b) {
|
|
705
|
+
return a.f - b.f;
|
|
706
|
+
});
|
|
707
|
+
t.push({ s: -1, f: 25001 });
|
|
708
|
+
var l = t[0], r = t[1], i0 = 0, i1 = 1, i22 = 2;
|
|
709
|
+
t[0] = { s: -1, f: l.f + r.f, l, r };
|
|
710
|
+
while (i1 != s - 1) {
|
|
711
|
+
l = t[t[i0].f < t[i22].f ? i0++ : i22++];
|
|
712
|
+
r = t[i0 != i1 && t[i0].f < t[i22].f ? i0++ : i22++];
|
|
713
|
+
t[i1++] = { s: -1, f: l.f + r.f, l, r };
|
|
714
|
+
}
|
|
715
|
+
var maxSym = t2[0].s;
|
|
716
|
+
for (var i2 = 1;i2 < s; ++i2) {
|
|
717
|
+
if (t2[i2].s > maxSym)
|
|
718
|
+
maxSym = t2[i2].s;
|
|
719
|
+
}
|
|
720
|
+
var tr = new u16(maxSym + 1);
|
|
721
|
+
var mbt = ln(t[i1 - 1], tr, 0);
|
|
722
|
+
if (mbt > mb) {
|
|
723
|
+
var i2 = 0, dt = 0;
|
|
724
|
+
var lft = mbt - mb, cst = 1 << lft;
|
|
725
|
+
t2.sort(function(a, b) {
|
|
726
|
+
return tr[b.s] - tr[a.s] || a.f - b.f;
|
|
727
|
+
});
|
|
728
|
+
for (;i2 < s; ++i2) {
|
|
729
|
+
var i2_1 = t2[i2].s;
|
|
730
|
+
if (tr[i2_1] > mb) {
|
|
731
|
+
dt += cst - (1 << mbt - tr[i2_1]);
|
|
732
|
+
tr[i2_1] = mb;
|
|
733
|
+
} else
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
dt >>= lft;
|
|
737
|
+
while (dt > 0) {
|
|
738
|
+
var i2_2 = t2[i2].s;
|
|
739
|
+
if (tr[i2_2] < mb)
|
|
740
|
+
dt -= 1 << mb - tr[i2_2]++ - 1;
|
|
741
|
+
else
|
|
742
|
+
++i2;
|
|
743
|
+
}
|
|
744
|
+
for (;i2 >= 0 && dt; --i2) {
|
|
745
|
+
var i2_3 = t2[i2].s;
|
|
746
|
+
if (tr[i2_3] == mb) {
|
|
747
|
+
--tr[i2_3];
|
|
748
|
+
++dt;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
mbt = mb;
|
|
752
|
+
}
|
|
753
|
+
return { t: new u8(tr), l: mbt };
|
|
754
|
+
};
|
|
755
|
+
var ln = function(n, l, d) {
|
|
756
|
+
return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
|
|
757
|
+
};
|
|
758
|
+
var lc = function(c) {
|
|
759
|
+
var s = c.length;
|
|
760
|
+
while (s && !c[--s])
|
|
761
|
+
;
|
|
762
|
+
var cl = new u16(++s);
|
|
763
|
+
var cli = 0, cln = c[0], cls = 1;
|
|
764
|
+
var w = function(v) {
|
|
765
|
+
cl[cli++] = v;
|
|
766
|
+
};
|
|
767
|
+
for (var i2 = 1;i2 <= s; ++i2) {
|
|
768
|
+
if (c[i2] == cln && i2 != s)
|
|
769
|
+
++cls;
|
|
770
|
+
else {
|
|
771
|
+
if (!cln && cls > 2) {
|
|
772
|
+
for (;cls > 138; cls -= 138)
|
|
773
|
+
w(32754);
|
|
774
|
+
if (cls > 2) {
|
|
775
|
+
w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
|
|
776
|
+
cls = 0;
|
|
777
|
+
}
|
|
778
|
+
} else if (cls > 3) {
|
|
779
|
+
w(cln), --cls;
|
|
780
|
+
for (;cls > 6; cls -= 6)
|
|
781
|
+
w(8304);
|
|
782
|
+
if (cls > 2)
|
|
783
|
+
w(cls - 3 << 5 | 8208), cls = 0;
|
|
784
|
+
}
|
|
785
|
+
while (cls--)
|
|
786
|
+
w(cln);
|
|
787
|
+
cls = 1;
|
|
788
|
+
cln = c[i2];
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return { c: cl.subarray(0, cli), n: s };
|
|
792
|
+
};
|
|
793
|
+
var clen = function(cf, cl) {
|
|
794
|
+
var l = 0;
|
|
795
|
+
for (var i2 = 0;i2 < cl.length; ++i2)
|
|
796
|
+
l += cf[i2] * cl[i2];
|
|
797
|
+
return l;
|
|
798
|
+
};
|
|
799
|
+
var wfblk = function(out, pos, dat) {
|
|
800
|
+
var s = dat.length;
|
|
801
|
+
var o = shft(pos + 2);
|
|
802
|
+
out[o] = s & 255;
|
|
803
|
+
out[o + 1] = s >> 8;
|
|
804
|
+
out[o + 2] = out[o] ^ 255;
|
|
805
|
+
out[o + 3] = out[o + 1] ^ 255;
|
|
806
|
+
for (var i2 = 0;i2 < s; ++i2)
|
|
807
|
+
out[o + i2 + 4] = dat[i2];
|
|
808
|
+
return (o + 4 + s) * 8;
|
|
809
|
+
};
|
|
810
|
+
var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
|
|
811
|
+
wbits(out, p++, final);
|
|
812
|
+
++lf[256];
|
|
813
|
+
var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l;
|
|
814
|
+
var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l;
|
|
815
|
+
var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
|
|
816
|
+
var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
|
|
817
|
+
var lcfreq = new u16(19);
|
|
818
|
+
for (var i2 = 0;i2 < lclt.length; ++i2)
|
|
819
|
+
++lcfreq[lclt[i2] & 31];
|
|
820
|
+
for (var i2 = 0;i2 < lcdt.length; ++i2)
|
|
821
|
+
++lcfreq[lcdt[i2] & 31];
|
|
822
|
+
var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
|
|
823
|
+
var nlcc = 19;
|
|
824
|
+
for (;nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
|
|
825
|
+
;
|
|
826
|
+
var flen = bl + 5 << 3;
|
|
827
|
+
var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
|
|
828
|
+
var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
|
|
829
|
+
if (bs >= 0 && flen <= ftlen && flen <= dtlen)
|
|
830
|
+
return wfblk(out, p, dat.subarray(bs, bs + bl));
|
|
831
|
+
var lm, ll, dm, dl;
|
|
832
|
+
wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
|
|
833
|
+
if (dtlen < ftlen) {
|
|
834
|
+
lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
|
|
835
|
+
var llm = hMap(lct, mlcb, 0);
|
|
836
|
+
wbits(out, p, nlc - 257);
|
|
837
|
+
wbits(out, p + 5, ndc - 1);
|
|
838
|
+
wbits(out, p + 10, nlcc - 4);
|
|
839
|
+
p += 14;
|
|
840
|
+
for (var i2 = 0;i2 < nlcc; ++i2)
|
|
841
|
+
wbits(out, p + 3 * i2, lct[clim[i2]]);
|
|
842
|
+
p += 3 * nlcc;
|
|
843
|
+
var lcts = [lclt, lcdt];
|
|
844
|
+
for (var it = 0;it < 2; ++it) {
|
|
845
|
+
var clct = lcts[it];
|
|
846
|
+
for (var i2 = 0;i2 < clct.length; ++i2) {
|
|
847
|
+
var len = clct[i2] & 31;
|
|
848
|
+
wbits(out, p, llm[len]), p += lct[len];
|
|
849
|
+
if (len > 15)
|
|
850
|
+
wbits(out, p, clct[i2] >> 5 & 127), p += clct[i2] >> 12;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
} else {
|
|
854
|
+
lm = flm, ll = flt, dm = fdm, dl = fdt;
|
|
855
|
+
}
|
|
856
|
+
for (var i2 = 0;i2 < li; ++i2) {
|
|
857
|
+
var sym = syms[i2];
|
|
858
|
+
if (sym > 255) {
|
|
859
|
+
var len = sym >> 18 & 31;
|
|
860
|
+
wbits16(out, p, lm[len + 257]), p += ll[len + 257];
|
|
861
|
+
if (len > 7)
|
|
862
|
+
wbits(out, p, sym >> 23 & 31), p += fleb[len];
|
|
863
|
+
var dst = sym & 31;
|
|
864
|
+
wbits16(out, p, dm[dst]), p += dl[dst];
|
|
865
|
+
if (dst > 3)
|
|
866
|
+
wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
|
|
867
|
+
} else {
|
|
868
|
+
wbits16(out, p, lm[sym]), p += ll[sym];
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
wbits16(out, p, lm[256]);
|
|
872
|
+
return p + ll[256];
|
|
873
|
+
};
|
|
874
|
+
var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
|
|
875
|
+
var et = /* @__PURE__ */ new u8(0);
|
|
876
|
+
var dflt = function(dat, lvl, plvl, pre, post, st) {
|
|
877
|
+
var s = st.z || dat.length;
|
|
878
|
+
var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
|
|
879
|
+
var w = o.subarray(pre, o.length - post);
|
|
880
|
+
var lst = st.l;
|
|
881
|
+
var pos = (st.r || 0) & 7;
|
|
882
|
+
if (lvl) {
|
|
883
|
+
if (pos)
|
|
884
|
+
w[0] = st.r >> 3;
|
|
885
|
+
var opt = deo[lvl - 1];
|
|
886
|
+
var n = opt >> 13, c = opt & 8191;
|
|
887
|
+
var msk_1 = (1 << plvl) - 1;
|
|
888
|
+
var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
|
|
889
|
+
var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
|
|
890
|
+
var hsh = function(i3) {
|
|
891
|
+
return (dat[i3] ^ dat[i3 + 1] << bs1_1 ^ dat[i3 + 2] << bs2_1) & msk_1;
|
|
892
|
+
};
|
|
893
|
+
var syms = new i32(25000);
|
|
894
|
+
var lf = new u16(288), df = new u16(32);
|
|
895
|
+
var lc_1 = 0, eb = 0, i2 = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
|
|
896
|
+
for (;i2 + 2 < s; ++i2) {
|
|
897
|
+
var hv = hsh(i2);
|
|
898
|
+
var imod = i2 & 32767, pimod = head[hv];
|
|
899
|
+
prev[imod] = pimod;
|
|
900
|
+
head[hv] = imod;
|
|
901
|
+
if (wi <= i2) {
|
|
902
|
+
var rem = s - i2;
|
|
903
|
+
if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
|
|
904
|
+
pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i2 - bs, pos);
|
|
905
|
+
li = lc_1 = eb = 0, bs = i2;
|
|
906
|
+
for (var j = 0;j < 286; ++j)
|
|
907
|
+
lf[j] = 0;
|
|
908
|
+
for (var j = 0;j < 30; ++j)
|
|
909
|
+
df[j] = 0;
|
|
910
|
+
}
|
|
911
|
+
var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
|
|
912
|
+
if (rem > 2 && hv == hsh(i2 - dif)) {
|
|
913
|
+
var maxn = Math.min(n, rem) - 1;
|
|
914
|
+
var maxd = Math.min(32767, i2);
|
|
915
|
+
var ml = Math.min(258, rem);
|
|
916
|
+
while (dif <= maxd && --ch_1 && imod != pimod) {
|
|
917
|
+
if (dat[i2 + l] == dat[i2 + l - dif]) {
|
|
918
|
+
var nl = 0;
|
|
919
|
+
for (;nl < ml && dat[i2 + nl] == dat[i2 + nl - dif]; ++nl)
|
|
920
|
+
;
|
|
921
|
+
if (nl > l) {
|
|
922
|
+
l = nl, d = dif;
|
|
923
|
+
if (nl > maxn)
|
|
924
|
+
break;
|
|
925
|
+
var mmd = Math.min(dif, nl - 2);
|
|
926
|
+
var md = 0;
|
|
927
|
+
for (var j = 0;j < mmd; ++j) {
|
|
928
|
+
var ti = i2 - dif + j & 32767;
|
|
929
|
+
var pti = prev[ti];
|
|
930
|
+
var cd = ti - pti & 32767;
|
|
931
|
+
if (cd > md)
|
|
932
|
+
md = cd, pimod = ti;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
imod = pimod, pimod = prev[imod];
|
|
937
|
+
dif += imod - pimod & 32767;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
if (d) {
|
|
941
|
+
syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
|
|
942
|
+
var lin = revfl[l] & 31, din = revfd[d] & 31;
|
|
943
|
+
eb += fleb[lin] + fdeb[din];
|
|
944
|
+
++lf[257 + lin];
|
|
945
|
+
++df[din];
|
|
946
|
+
wi = i2 + l;
|
|
947
|
+
++lc_1;
|
|
948
|
+
} else {
|
|
949
|
+
syms[li++] = dat[i2];
|
|
950
|
+
++lf[dat[i2]];
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
for (i2 = Math.max(i2, wi);i2 < s; ++i2) {
|
|
955
|
+
syms[li++] = dat[i2];
|
|
956
|
+
++lf[dat[i2]];
|
|
957
|
+
}
|
|
958
|
+
pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i2 - bs, pos);
|
|
959
|
+
if (!lst) {
|
|
960
|
+
st.r = pos & 7 | w[pos / 8 | 0] << 3;
|
|
961
|
+
pos -= 7;
|
|
962
|
+
st.h = head, st.p = prev, st.i = i2, st.w = wi;
|
|
963
|
+
}
|
|
964
|
+
} else {
|
|
965
|
+
for (var i2 = st.w || 0;i2 < s + lst; i2 += 65535) {
|
|
966
|
+
var e = i2 + 65535;
|
|
967
|
+
if (e >= s) {
|
|
968
|
+
w[pos / 8 | 0] = lst;
|
|
969
|
+
e = s;
|
|
970
|
+
}
|
|
971
|
+
pos = wfblk(w, pos + 1, dat.subarray(i2, e));
|
|
972
|
+
}
|
|
973
|
+
st.i = s;
|
|
974
|
+
}
|
|
975
|
+
return slc(o, 0, pre + shft(pos) + post);
|
|
976
|
+
};
|
|
977
|
+
var crct = /* @__PURE__ */ function() {
|
|
978
|
+
var t = new Int32Array(256);
|
|
979
|
+
for (var i2 = 0;i2 < 256; ++i2) {
|
|
980
|
+
var c = i2, k = 9;
|
|
981
|
+
while (--k)
|
|
982
|
+
c = (c & 1 && -306674912) ^ c >>> 1;
|
|
983
|
+
t[i2] = c;
|
|
984
|
+
}
|
|
985
|
+
return t;
|
|
986
|
+
}();
|
|
987
|
+
var crc = function() {
|
|
988
|
+
var c = -1;
|
|
989
|
+
return {
|
|
990
|
+
p: function(d) {
|
|
991
|
+
var cr = c;
|
|
992
|
+
for (var i2 = 0;i2 < d.length; ++i2)
|
|
993
|
+
cr = crct[cr & 255 ^ d[i2]] ^ cr >>> 8;
|
|
994
|
+
c = cr;
|
|
995
|
+
},
|
|
996
|
+
d: function() {
|
|
997
|
+
return ~c;
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
};
|
|
1001
|
+
var dopt = function(dat, opt, pre, post, st) {
|
|
1002
|
+
if (!st) {
|
|
1003
|
+
st = { l: 1 };
|
|
1004
|
+
if (opt.dictionary) {
|
|
1005
|
+
var dict = opt.dictionary.subarray(-32768);
|
|
1006
|
+
var newDat = new u8(dict.length + dat.length);
|
|
1007
|
+
newDat.set(dict);
|
|
1008
|
+
newDat.set(dat, dict.length);
|
|
1009
|
+
dat = newDat;
|
|
1010
|
+
st.w = dict.length;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
|
|
1014
|
+
};
|
|
1015
|
+
var mrg = function(a, b) {
|
|
1016
|
+
var o = {};
|
|
1017
|
+
for (var k in a)
|
|
1018
|
+
o[k] = a[k];
|
|
1019
|
+
for (var k in b)
|
|
1020
|
+
o[k] = b[k];
|
|
1021
|
+
return o;
|
|
1022
|
+
};
|
|
1023
|
+
var wbytes = function(d, b, v) {
|
|
1024
|
+
for (;v; ++b)
|
|
1025
|
+
d[b] = v, v >>>= 8;
|
|
1026
|
+
};
|
|
1027
|
+
function deflateSync(data, opts) {
|
|
1028
|
+
return dopt(data, opts || {}, 0, 0);
|
|
1029
|
+
}
|
|
1030
|
+
var fltn = function(d, p, t, o) {
|
|
1031
|
+
for (var k in d) {
|
|
1032
|
+
var val = d[k], n = p + k, op = o;
|
|
1033
|
+
if (Array.isArray(val))
|
|
1034
|
+
op = mrg(o, val[1]), val = val[0];
|
|
1035
|
+
if (ArrayBuffer.isView(val))
|
|
1036
|
+
t[n] = [val, op];
|
|
1037
|
+
else {
|
|
1038
|
+
t[n += "/"] = [new u8(0), op];
|
|
1039
|
+
fltn(val, n, t, o);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder;
|
|
1044
|
+
var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder;
|
|
1045
|
+
var tds = 0;
|
|
1046
|
+
try {
|
|
1047
|
+
td.decode(et, { stream: true });
|
|
1048
|
+
tds = 1;
|
|
1049
|
+
} catch (e) {}
|
|
1050
|
+
function strToU8(str, latin1) {
|
|
1051
|
+
if (latin1) {
|
|
1052
|
+
var ar_1 = new u8(str.length);
|
|
1053
|
+
for (var i2 = 0;i2 < str.length; ++i2)
|
|
1054
|
+
ar_1[i2] = str.charCodeAt(i2);
|
|
1055
|
+
return ar_1;
|
|
1056
|
+
}
|
|
1057
|
+
if (te)
|
|
1058
|
+
return te.encode(str);
|
|
1059
|
+
var l = str.length;
|
|
1060
|
+
var ar = new u8(str.length + (str.length >> 1));
|
|
1061
|
+
var ai = 0;
|
|
1062
|
+
var w = function(v) {
|
|
1063
|
+
ar[ai++] = v;
|
|
1064
|
+
};
|
|
1065
|
+
for (var i2 = 0;i2 < l; ++i2) {
|
|
1066
|
+
if (ai + 5 > ar.length) {
|
|
1067
|
+
var n = new u8(ai + 8 + (l - i2 << 1));
|
|
1068
|
+
n.set(ar);
|
|
1069
|
+
ar = n;
|
|
1070
|
+
}
|
|
1071
|
+
var c = str.charCodeAt(i2);
|
|
1072
|
+
if (c < 128 || latin1)
|
|
1073
|
+
w(c);
|
|
1074
|
+
else if (c < 2048)
|
|
1075
|
+
w(192 | c >> 6), w(128 | c & 63);
|
|
1076
|
+
else if (c > 55295 && c < 57344)
|
|
1077
|
+
c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i2) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
1078
|
+
else
|
|
1079
|
+
w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
1080
|
+
}
|
|
1081
|
+
return slc(ar, 0, ai);
|
|
1082
|
+
}
|
|
1083
|
+
var exfl = function(ex) {
|
|
1084
|
+
var le = 0;
|
|
1085
|
+
if (ex) {
|
|
1086
|
+
for (var k in ex) {
|
|
1087
|
+
var l = ex[k].length;
|
|
1088
|
+
if (l > 65535)
|
|
1089
|
+
err(9);
|
|
1090
|
+
le += l + 4;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return le;
|
|
1094
|
+
};
|
|
1095
|
+
var wzh = function(d, b, f, fn, u, c, ce, co) {
|
|
1096
|
+
var fl2 = fn.length, ex = f.extra, col = co && co.length;
|
|
1097
|
+
var exl = exfl(ex);
|
|
1098
|
+
wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4;
|
|
1099
|
+
if (ce != null)
|
|
1100
|
+
d[b++] = 20, d[b++] = f.os;
|
|
1101
|
+
d[b] = 20, b += 2;
|
|
1102
|
+
d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8;
|
|
1103
|
+
d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
|
|
1104
|
+
var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
|
|
1105
|
+
if (y < 0 || y > 119)
|
|
1106
|
+
err(10);
|
|
1107
|
+
wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4;
|
|
1108
|
+
if (c != -1) {
|
|
1109
|
+
wbytes(d, b, f.crc);
|
|
1110
|
+
wbytes(d, b + 4, c < 0 ? -c - 2 : c);
|
|
1111
|
+
wbytes(d, b + 8, f.size);
|
|
1112
|
+
}
|
|
1113
|
+
wbytes(d, b + 12, fl2);
|
|
1114
|
+
wbytes(d, b + 14, exl), b += 16;
|
|
1115
|
+
if (ce != null) {
|
|
1116
|
+
wbytes(d, b, col);
|
|
1117
|
+
wbytes(d, b + 6, f.attrs);
|
|
1118
|
+
wbytes(d, b + 10, ce), b += 14;
|
|
1119
|
+
}
|
|
1120
|
+
d.set(fn, b);
|
|
1121
|
+
b += fl2;
|
|
1122
|
+
if (exl) {
|
|
1123
|
+
for (var k in ex) {
|
|
1124
|
+
var exf = ex[k], l = exf.length;
|
|
1125
|
+
wbytes(d, b, +k);
|
|
1126
|
+
wbytes(d, b + 2, l);
|
|
1127
|
+
d.set(exf, b + 4), b += 4 + l;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
if (col)
|
|
1131
|
+
d.set(co, b), b += col;
|
|
1132
|
+
return b;
|
|
1133
|
+
};
|
|
1134
|
+
var wzf = function(o, b, c, d, e) {
|
|
1135
|
+
wbytes(o, b, 101010256);
|
|
1136
|
+
wbytes(o, b + 8, c);
|
|
1137
|
+
wbytes(o, b + 10, c);
|
|
1138
|
+
wbytes(o, b + 12, d);
|
|
1139
|
+
wbytes(o, b + 16, e);
|
|
1140
|
+
};
|
|
1141
|
+
function zipSync(data, opts) {
|
|
1142
|
+
if (!opts)
|
|
1143
|
+
opts = {};
|
|
1144
|
+
var r = {};
|
|
1145
|
+
var files = [];
|
|
1146
|
+
fltn(data, "", r, opts);
|
|
1147
|
+
var o = 0;
|
|
1148
|
+
var tot = 0;
|
|
1149
|
+
for (var fn in r) {
|
|
1150
|
+
var _a2 = r[fn], file = _a2[0], p = _a2[1];
|
|
1151
|
+
var compression = p.level == 0 ? 0 : 8;
|
|
1152
|
+
var f = strToU8(fn), s = f.length;
|
|
1153
|
+
var com = p.comment, m = com && strToU8(com), ms = m && m.length;
|
|
1154
|
+
var exl = exfl(p.extra);
|
|
1155
|
+
if (s > 65535)
|
|
1156
|
+
err(11);
|
|
1157
|
+
var d = compression ? deflateSync(file, p) : file, l = d.length;
|
|
1158
|
+
var c = crc();
|
|
1159
|
+
c.p(file);
|
|
1160
|
+
files.push(mrg(p, {
|
|
1161
|
+
size: file.length,
|
|
1162
|
+
crc: c.d(),
|
|
1163
|
+
c: d,
|
|
1164
|
+
f,
|
|
1165
|
+
m,
|
|
1166
|
+
u: s != fn.length || m && com.length != ms,
|
|
1167
|
+
o,
|
|
1168
|
+
compression
|
|
1169
|
+
}));
|
|
1170
|
+
o += 30 + s + exl + l;
|
|
1171
|
+
tot += 76 + 2 * (s + exl) + (ms || 0) + l;
|
|
1172
|
+
}
|
|
1173
|
+
var out = new u8(tot + 22), oe = o, cdl = tot - o;
|
|
1174
|
+
for (var i2 = 0;i2 < files.length; ++i2) {
|
|
1175
|
+
var f = files[i2];
|
|
1176
|
+
wzh(out, f.o, f, f.f, f.u, f.c.length);
|
|
1177
|
+
var badd = 30 + f.f.length + exfl(f.extra);
|
|
1178
|
+
out.set(f.c, f.o + badd);
|
|
1179
|
+
wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
|
|
1180
|
+
}
|
|
1181
|
+
wzf(out, o, files.length, cdl, oe);
|
|
1182
|
+
return out;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// src/folder-zip.ts
|
|
1186
|
+
var SKIP_DIRS = new Set([
|
|
1187
|
+
".git",
|
|
1188
|
+
"node_modules",
|
|
1189
|
+
"out",
|
|
1190
|
+
"cache",
|
|
1191
|
+
"broadcast",
|
|
1192
|
+
"artifacts",
|
|
1193
|
+
"typechain",
|
|
1194
|
+
"typechain-types",
|
|
1195
|
+
".forge-artifacts",
|
|
1196
|
+
"deps",
|
|
1197
|
+
"lib",
|
|
1198
|
+
"test",
|
|
1199
|
+
"tests",
|
|
1200
|
+
"script",
|
|
1201
|
+
"scripts",
|
|
1202
|
+
"mock",
|
|
1203
|
+
"mocks"
|
|
1204
|
+
]);
|
|
1205
|
+
function walkDir(dir, base = dir) {
|
|
1206
|
+
const results = [];
|
|
1207
|
+
let entries;
|
|
1208
|
+
try {
|
|
1209
|
+
entries = readdirSync(dir);
|
|
1210
|
+
} catch {
|
|
1211
|
+
return results;
|
|
1212
|
+
}
|
|
1213
|
+
for (const entry of entries) {
|
|
1214
|
+
const fullPath = join2(dir, entry);
|
|
1215
|
+
const relPath = relative(base, fullPath).split(sep).join("/");
|
|
1216
|
+
let st;
|
|
1217
|
+
try {
|
|
1218
|
+
st = statSync(fullPath);
|
|
1219
|
+
} catch {
|
|
1220
|
+
continue;
|
|
1221
|
+
}
|
|
1222
|
+
if (st.isDirectory()) {
|
|
1223
|
+
if (SKIP_DIRS.has(entry))
|
|
1224
|
+
continue;
|
|
1225
|
+
results.push(...walkDir(fullPath, base));
|
|
1226
|
+
} else if (st.isFile()) {
|
|
1227
|
+
results.push([relPath, fullPath]);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return results;
|
|
1231
|
+
}
|
|
1232
|
+
function zipFolder(folderPath) {
|
|
1233
|
+
const files = walkDir(folderPath);
|
|
1234
|
+
const zippable = {};
|
|
1235
|
+
for (const [relPath, absPath] of files) {
|
|
1236
|
+
zippable[relPath] = new Uint8Array(readFileSync(absPath));
|
|
1237
|
+
}
|
|
1238
|
+
if (Object.keys(zippable).length === 0) {
|
|
1239
|
+
throw new Error(`No files found in folder: ${folderPath}`);
|
|
1240
|
+
}
|
|
1241
|
+
return zipSync(zippable, { level: 6 });
|
|
1242
|
+
}
|
|
1243
|
+
function folderName(folderPath) {
|
|
1244
|
+
return basename(folderPath);
|
|
1245
|
+
}
|
|
222
1246
|
|
|
223
1247
|
// src/index.ts
|
|
224
1248
|
var BOLD = "\x1B[1m";
|
|
@@ -242,48 +1266,80 @@ function warn(msg) {
|
|
|
242
1266
|
function fail(msg) {
|
|
243
1267
|
console.error(`${RED}✗${RESET} ${msg}`);
|
|
244
1268
|
}
|
|
1269
|
+
var cliLog = { info, success, warn };
|
|
245
1270
|
function printHelp() {
|
|
246
|
-
console.log(`${BOLD}QuillAudits CLI${RESET} —
|
|
1271
|
+
console.log(`${BOLD}QuillAudits CLI${RESET} — paid audit workflow (quote → order → pay → start)
|
|
247
1272
|
|
|
248
1273
|
${BOLD}USAGE${RESET}
|
|
249
1274
|
qs <command> [options]
|
|
250
1275
|
|
|
251
1276
|
${BOLD}COMMANDS${RESET}
|
|
252
1277
|
${BOLD}init${RESET} Configure API key + URL
|
|
253
|
-
${BOLD}audit${RESET} <git-url> [options] Submit
|
|
254
|
-
--ref <ref> Branch/tag/commit
|
|
1278
|
+
${BOLD}audit${RESET} <git-url> [options] Submit + pay + start an audit
|
|
1279
|
+
--ref <ref> Branch/tag/commit
|
|
255
1280
|
--name <name> Override project name
|
|
256
|
-
--scope <file1,file2,...>
|
|
257
|
-
|
|
258
|
-
--
|
|
1281
|
+
--scope <file1,file2,...> Scope files (default: all .sol)
|
|
1282
|
+
--coupon <CODE> Apply coupon before paying
|
|
1283
|
+
--method <stripe|crypto> Payment method (default: stripe)
|
|
1284
|
+
--yes Skip charge confirmation
|
|
1285
|
+
--no-pay Stop after quote (do not pay)
|
|
1286
|
+
--no-open Do not open browser for Stripe
|
|
1287
|
+
--open Force open browser
|
|
1288
|
+
--watch Watch progress after start
|
|
1289
|
+
${BOLD}audit${RESET} --zip <path> […] Upload zip/sol then pay
|
|
1290
|
+
${BOLD}audit${RESET} --dir <path> […] Zip a folder then pay
|
|
259
1291
|
|
|
260
|
-
${BOLD}
|
|
261
|
-
|
|
262
|
-
--
|
|
263
|
-
|
|
1292
|
+
${BOLD}quote${RESET} <version-id> Create a quote for a project version
|
|
1293
|
+
${BOLD}pay${RESET} <quote-id> [options] Pay a quote and start the audit
|
|
1294
|
+
--coupon <CODE> --method … --yes --no-open --open --watch
|
|
1295
|
+
|
|
1296
|
+
${BOLD}wallet${RESET} Show wallet balances
|
|
1297
|
+
${BOLD}topup${RESET} <amount> Top up wallet (dollars, e.g. 50 or 50.00)
|
|
1298
|
+
--yes --no-open --open
|
|
1299
|
+
${BOLD}orders${RESET} List recent orders
|
|
1300
|
+
${BOLD}order${RESET} <order-id> Show an order
|
|
264
1301
|
|
|
265
1302
|
${BOLD}status${RESET} <job-id> Check audit status
|
|
266
1303
|
${BOLD}watch${RESET} <job-id> Live progress stream (SSE)
|
|
267
1304
|
${BOLD}findings${RESET} <job-id> List findings
|
|
268
1305
|
${BOLD}report${RESET} <job-id> [options] Download report
|
|
269
|
-
--format <pdf|json>
|
|
1306
|
+
--format <pdf|json|md> Report format (default: pdf)
|
|
1307
|
+
--out <path> Write file to path
|
|
270
1308
|
|
|
271
1309
|
${BOLD}projects${RESET} List projects
|
|
272
|
-
${BOLD}versions${RESET} <project-id> List versions
|
|
273
|
-
${BOLD}credits${RESET} Show credit balance
|
|
1310
|
+
${BOLD}versions${RESET} <project-id> List versions
|
|
274
1311
|
${BOLD}cancel${RESET} <job-id> Cancel a running audit
|
|
275
1312
|
${BOLD}logout${RESET} Clear stored credentials
|
|
1313
|
+
${BOLD}credits${RESET} Deprecated alias for ${BOLD}wallet${RESET}
|
|
276
1314
|
|
|
277
1315
|
${BOLD}EXAMPLES${RESET}
|
|
278
1316
|
qs init
|
|
279
|
-
qs audit https://github.com/org/contract --ref main --watch
|
|
280
|
-
qs audit --
|
|
281
|
-
qs
|
|
282
|
-
qs
|
|
283
|
-
qs
|
|
284
|
-
qs report 01KXK... --format pdf
|
|
1317
|
+
qs audit https://github.com/org/contract --ref main --yes --watch
|
|
1318
|
+
qs audit --dir ./contracts --coupon SAVE10 --yes
|
|
1319
|
+
qs quote 01KXK... && qs pay 01KXK... --yes --watch
|
|
1320
|
+
qs wallet
|
|
1321
|
+
qs topup 50 --yes
|
|
285
1322
|
`);
|
|
286
1323
|
}
|
|
1324
|
+
async function promptConfirm(message) {
|
|
1325
|
+
if (!process.stdin.isTTY)
|
|
1326
|
+
return false;
|
|
1327
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1328
|
+
const answer = await new Promise((resolve2) => {
|
|
1329
|
+
rl.question(`${message} [y/N] `, resolve2);
|
|
1330
|
+
});
|
|
1331
|
+
rl.close();
|
|
1332
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
1333
|
+
}
|
|
1334
|
+
async function confirmChargeIfNeeded(quote, yes) {
|
|
1335
|
+
if (quote.final_price_cents <= 0 || yes)
|
|
1336
|
+
return true;
|
|
1337
|
+
if (!process.stdin.isTTY) {
|
|
1338
|
+
fail("Refusing to charge without --yes in non-interactive mode");
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
return promptConfirm(`Charge ${formatUsd(quote.final_price_cents)} and start the audit?`);
|
|
1342
|
+
}
|
|
287
1343
|
async function cmdInit() {
|
|
288
1344
|
console.log(`${BOLD}QuillAudits CLI Setup${RESET}
|
|
289
1345
|
`);
|
|
@@ -322,8 +1378,8 @@ Verifying connection...`);
|
|
|
322
1378
|
const api = new QuillShieldApi(savedCfg);
|
|
323
1379
|
const projects = await api.listProjects();
|
|
324
1380
|
success(`Connected! Found ${projects.length} existing project(s).`);
|
|
325
|
-
} catch (
|
|
326
|
-
fail(`Connection failed: ${
|
|
1381
|
+
} catch (err2) {
|
|
1382
|
+
fail(`Connection failed: ${err2.message}`);
|
|
327
1383
|
console.log("You can re-run `qs init` to fix the configuration.");
|
|
328
1384
|
}
|
|
329
1385
|
}
|
|
@@ -334,73 +1390,247 @@ async function cmdAudit(args) {
|
|
|
334
1390
|
args,
|
|
335
1391
|
options: {
|
|
336
1392
|
zip: { type: "string" },
|
|
1393
|
+
dir: { type: "string" },
|
|
337
1394
|
ref: { type: "string" },
|
|
338
1395
|
name: { type: "string" },
|
|
339
1396
|
scope: { type: "string" },
|
|
1397
|
+
coupon: { type: "string" },
|
|
1398
|
+
method: { type: "string", default: "stripe" },
|
|
1399
|
+
yes: { type: "boolean", default: false },
|
|
1400
|
+
"no-pay": { type: "boolean", default: false },
|
|
1401
|
+
"no-open": { type: "boolean", default: false },
|
|
1402
|
+
open: { type: "boolean", default: false },
|
|
340
1403
|
watch: { type: "boolean", default: false }
|
|
341
1404
|
},
|
|
342
1405
|
allowPositionals: true
|
|
343
1406
|
});
|
|
344
1407
|
const scopeFiles = values.scope ? values.scope.split(",").map((s) => s.trim()).filter(Boolean) : undefined;
|
|
345
|
-
|
|
1408
|
+
const method = values.method === "crypto" ? "crypto" : "stripe";
|
|
1409
|
+
let submitArgs;
|
|
346
1410
|
if (values.zip) {
|
|
347
1411
|
const zipPath = resolve(values.zip);
|
|
348
1412
|
if (!existsSync(zipPath)) {
|
|
349
1413
|
fail(`File not found: ${zipPath}`);
|
|
350
1414
|
process.exit(1);
|
|
351
1415
|
}
|
|
352
|
-
const buf =
|
|
353
|
-
const filename =
|
|
1416
|
+
const buf = readFileSync2(zipPath);
|
|
1417
|
+
const filename = basename2(zipPath);
|
|
354
1418
|
info(`Uploading ${filename} (${(buf.length / 1024).toFixed(0)} KB)...`);
|
|
355
|
-
|
|
1419
|
+
submitArgs = {
|
|
1420
|
+
kind: "zip",
|
|
356
1421
|
file: buf,
|
|
357
1422
|
filename,
|
|
358
1423
|
project_name: values.name,
|
|
359
1424
|
scope_files: scopeFiles
|
|
360
|
-
}
|
|
1425
|
+
};
|
|
1426
|
+
} else if (values.dir) {
|
|
1427
|
+
const dirPath = resolve(values.dir);
|
|
1428
|
+
if (!existsSync(dirPath)) {
|
|
1429
|
+
fail(`Folder not found: ${dirPath}`);
|
|
1430
|
+
process.exit(1);
|
|
1431
|
+
}
|
|
1432
|
+
if (!statSync2(dirPath).isDirectory()) {
|
|
1433
|
+
fail(`Path is not a directory: ${dirPath}`);
|
|
1434
|
+
process.exit(1);
|
|
1435
|
+
}
|
|
1436
|
+
const fname = folderName(dirPath);
|
|
1437
|
+
info(`Zipping folder "${fname}"...`);
|
|
1438
|
+
const buf = Buffer.from(zipFolder(dirPath));
|
|
1439
|
+
info(`Uploading ${fname}.zip (${(buf.length / 1024).toFixed(0)} KB)...`);
|
|
1440
|
+
submitArgs = {
|
|
1441
|
+
kind: "zip",
|
|
1442
|
+
file: buf,
|
|
1443
|
+
filename: `${fname}.zip`,
|
|
1444
|
+
project_name: values.name ?? fname,
|
|
1445
|
+
scope_files: scopeFiles
|
|
1446
|
+
};
|
|
361
1447
|
} else if (positionals[0]) {
|
|
362
1448
|
const repoUrl = positionals[0];
|
|
363
1449
|
info(`Submitting ${repoUrl}${values.ref ? ` @ ${values.ref}` : ""}...`);
|
|
364
|
-
|
|
1450
|
+
submitArgs = {
|
|
1451
|
+
kind: "git",
|
|
365
1452
|
repo_url: repoUrl,
|
|
366
1453
|
git_ref: values.ref,
|
|
367
1454
|
project_name: values.name,
|
|
368
1455
|
scope_files: scopeFiles
|
|
369
|
-
}
|
|
1456
|
+
};
|
|
370
1457
|
} else {
|
|
371
|
-
fail("Provide a git URL or --
|
|
372
|
-
process.exit(1);
|
|
373
|
-
}
|
|
374
|
-
if (!res) {
|
|
375
|
-
fail("Submission failed — no response received.");
|
|
1458
|
+
fail("Provide a git URL, --zip <path>, or --dir <path>");
|
|
376
1459
|
process.exit(1);
|
|
377
1460
|
}
|
|
1461
|
+
const handoff = await api.submitForCheckout(submitArgs);
|
|
378
1462
|
console.log();
|
|
379
|
-
success("
|
|
1463
|
+
success("Project prepared — payment required to start audit");
|
|
380
1464
|
console.log();
|
|
381
|
-
console.log(` ${BOLD}Project${RESET} ${
|
|
382
|
-
console.log(` ${BOLD}Version${RESET} ${
|
|
383
|
-
console.log(` ${BOLD}SLOC${RESET} ${
|
|
384
|
-
console.log(` ${BOLD}Scope${RESET} ${
|
|
385
|
-
if (
|
|
386
|
-
for (const f of
|
|
1465
|
+
console.log(` ${BOLD}Project${RESET} ${handoff.project.name} (${handoff.project.id})`);
|
|
1466
|
+
console.log(` ${BOLD}Version${RESET} ${handoff.version.id}`);
|
|
1467
|
+
console.log(` ${BOLD}SLOC${RESET} ${handoff.version.sloc ?? "?"}`);
|
|
1468
|
+
console.log(` ${BOLD}Scope${RESET} ${handoff.scope.file_count} file(s)`);
|
|
1469
|
+
if (handoff.scope.files?.length) {
|
|
1470
|
+
for (const f of handoff.scope.files.slice(0, 20)) {
|
|
387
1471
|
console.log(` ${DIM}${f}${RESET}`);
|
|
388
1472
|
}
|
|
389
|
-
if (
|
|
390
|
-
console.log(` ${DIM}... and ${
|
|
1473
|
+
if (handoff.scope.total_files > handoff.scope.files.length) {
|
|
1474
|
+
console.log(` ${DIM}... and ${handoff.scope.total_files - handoff.scope.files.length} more${RESET}`);
|
|
391
1475
|
}
|
|
392
1476
|
}
|
|
393
|
-
console.log(` ${BOLD}
|
|
394
|
-
|
|
395
|
-
|
|
1477
|
+
console.log(` ${BOLD}Quote${RESET} ${handoff.quote_id}`);
|
|
1478
|
+
if (values["no-pay"]) {
|
|
1479
|
+
printQuote(handoff.quote);
|
|
1480
|
+
console.log(` Continue with: ${DIM}qs pay ${handoff.quote_id} --yes${RESET}`);
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
const paid = await payQuoteAndStartAudit(api, handoff.quote_id, {
|
|
1484
|
+
coupon: values.coupon,
|
|
1485
|
+
method,
|
|
1486
|
+
yes: values.yes,
|
|
1487
|
+
noOpen: values["no-open"],
|
|
1488
|
+
open: values.open,
|
|
1489
|
+
log: cliLog,
|
|
1490
|
+
confirmCharge: async (q) => confirmChargeIfNeeded(q, values.yes)
|
|
1491
|
+
});
|
|
396
1492
|
console.log();
|
|
397
|
-
console.log(`
|
|
398
|
-
console.log(`
|
|
1493
|
+
console.log(` ${BOLD}Job ID${RESET} ${SKY}${paid.audit_job_id}${RESET}`);
|
|
1494
|
+
console.log(` Track progress: ${DIM}qs watch ${paid.audit_job_id}${RESET}`);
|
|
1495
|
+
console.log(` Get findings: ${DIM}qs findings ${paid.audit_job_id}${RESET}`);
|
|
399
1496
|
if (values.watch) {
|
|
400
1497
|
console.log();
|
|
401
|
-
await cmdWatch([
|
|
1498
|
+
await cmdWatch([paid.audit_job_id]);
|
|
402
1499
|
}
|
|
403
1500
|
}
|
|
1501
|
+
async function cmdQuote(args) {
|
|
1502
|
+
const cfg = await requireConfig();
|
|
1503
|
+
const api = new QuillShieldApi(cfg);
|
|
1504
|
+
const versionId = args[0];
|
|
1505
|
+
if (!versionId) {
|
|
1506
|
+
fail("Usage: qs quote <version-id>");
|
|
1507
|
+
process.exit(1);
|
|
1508
|
+
}
|
|
1509
|
+
info(`Creating quote for version ${versionId}...`);
|
|
1510
|
+
const quote = await api.createQuote(versionId);
|
|
1511
|
+
success(`Quote ${quote.id}`);
|
|
1512
|
+
printQuote(quote);
|
|
1513
|
+
console.log(` Pay with: ${DIM}qs pay ${quote.id} --yes${RESET}`);
|
|
1514
|
+
}
|
|
1515
|
+
async function cmdPay(args) {
|
|
1516
|
+
const cfg = await requireConfig();
|
|
1517
|
+
const api = new QuillShieldApi(cfg);
|
|
1518
|
+
const { values, positionals } = parseArgs({
|
|
1519
|
+
args,
|
|
1520
|
+
options: {
|
|
1521
|
+
coupon: { type: "string" },
|
|
1522
|
+
method: { type: "string", default: "stripe" },
|
|
1523
|
+
yes: { type: "boolean", default: false },
|
|
1524
|
+
"no-open": { type: "boolean", default: false },
|
|
1525
|
+
open: { type: "boolean", default: false },
|
|
1526
|
+
watch: { type: "boolean", default: false }
|
|
1527
|
+
},
|
|
1528
|
+
allowPositionals: true
|
|
1529
|
+
});
|
|
1530
|
+
const quoteId = positionals[0];
|
|
1531
|
+
if (!quoteId) {
|
|
1532
|
+
fail("Usage: qs pay <quote-id> [options]");
|
|
1533
|
+
process.exit(1);
|
|
1534
|
+
}
|
|
1535
|
+
const method = values.method === "crypto" ? "crypto" : "stripe";
|
|
1536
|
+
const paid = await payQuoteAndStartAudit(api, quoteId, {
|
|
1537
|
+
coupon: values.coupon,
|
|
1538
|
+
method,
|
|
1539
|
+
yes: values.yes,
|
|
1540
|
+
noOpen: values["no-open"],
|
|
1541
|
+
open: values.open,
|
|
1542
|
+
log: cliLog,
|
|
1543
|
+
confirmCharge: async (q) => confirmChargeIfNeeded(q, values.yes)
|
|
1544
|
+
});
|
|
1545
|
+
console.log(` ${BOLD}Job ID${RESET} ${SKY}${paid.audit_job_id}${RESET}`);
|
|
1546
|
+
if (values.watch)
|
|
1547
|
+
await cmdWatch([paid.audit_job_id]);
|
|
1548
|
+
}
|
|
1549
|
+
async function cmdWallet() {
|
|
1550
|
+
const cfg = await requireConfig();
|
|
1551
|
+
const api = new QuillShieldApi(cfg);
|
|
1552
|
+
const w = await api.getWallet();
|
|
1553
|
+
console.log(`${BOLD}Wallet${RESET}
|
|
1554
|
+
`);
|
|
1555
|
+
console.log(` Prepaid ${GREEN}${formatUsd(w.prepaid_credit_cents)}${RESET}`);
|
|
1556
|
+
console.log(` Bonus ${formatUsd(w.bonus_credit_cents)}`);
|
|
1557
|
+
console.log(` Refund ${formatUsd(w.refund_credit_cents)}`);
|
|
1558
|
+
if (w.signup_bonus_remaining_cents > 0) {
|
|
1559
|
+
console.log(` Signup left ${formatUsd(w.signup_bonus_remaining_cents)}${w.signup_bonus_expires_at ? ` (expires ${w.signup_bonus_expires_at})` : ""}`);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
async function cmdTopup(args) {
|
|
1563
|
+
const cfg = await requireConfig();
|
|
1564
|
+
const api = new QuillShieldApi(cfg);
|
|
1565
|
+
const { values, positionals } = parseArgs({
|
|
1566
|
+
args,
|
|
1567
|
+
options: {
|
|
1568
|
+
yes: { type: "boolean", default: false },
|
|
1569
|
+
"no-open": { type: "boolean", default: false },
|
|
1570
|
+
open: { type: "boolean", default: false }
|
|
1571
|
+
},
|
|
1572
|
+
allowPositionals: true
|
|
1573
|
+
});
|
|
1574
|
+
const raw = positionals[0];
|
|
1575
|
+
if (!raw) {
|
|
1576
|
+
fail("Usage: qs topup <amount-dollars> e.g. qs topup 50");
|
|
1577
|
+
process.exit(1);
|
|
1578
|
+
}
|
|
1579
|
+
const dollars = Number(raw);
|
|
1580
|
+
if (!Number.isFinite(dollars) || dollars <= 0) {
|
|
1581
|
+
fail("Amount must be a positive number of dollars");
|
|
1582
|
+
process.exit(1);
|
|
1583
|
+
}
|
|
1584
|
+
const amountCents = Math.round(dollars * 100);
|
|
1585
|
+
if (!values.yes) {
|
|
1586
|
+
const ok = await confirmChargeIfNeeded({ final_price_cents: amountCents }, false);
|
|
1587
|
+
if (!ok)
|
|
1588
|
+
process.exit(1);
|
|
1589
|
+
}
|
|
1590
|
+
await payWalletTopup(api, amountCents, {
|
|
1591
|
+
yes: values.yes,
|
|
1592
|
+
noOpen: values["no-open"],
|
|
1593
|
+
open: values.open,
|
|
1594
|
+
log: cliLog
|
|
1595
|
+
});
|
|
1596
|
+
await cmdWallet();
|
|
1597
|
+
}
|
|
1598
|
+
async function cmdOrders() {
|
|
1599
|
+
const cfg = await requireConfig();
|
|
1600
|
+
const api = new QuillShieldApi(cfg);
|
|
1601
|
+
const rows = await api.listOrders();
|
|
1602
|
+
if (rows.length === 0) {
|
|
1603
|
+
console.log("No orders yet.");
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
console.log(`${BOLD}Orders (${rows.length})${RESET}
|
|
1607
|
+
`);
|
|
1608
|
+
for (const o of rows) {
|
|
1609
|
+
console.log(` ${SKY}${o.id}${RESET} ${o.kind} ${formatUsd(o.final_price_cents)} ${o.payment_status}`);
|
|
1610
|
+
console.log(` ${DIM}${o.project_name} · ${o.created_at}${RESET}`);
|
|
1611
|
+
if (o.audit_job_id)
|
|
1612
|
+
console.log(` job ${o.audit_job_id}`);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
async function cmdOrder(args) {
|
|
1616
|
+
const cfg = await requireConfig();
|
|
1617
|
+
const api = new QuillShieldApi(cfg);
|
|
1618
|
+
const id = args[0];
|
|
1619
|
+
if (!id) {
|
|
1620
|
+
fail("Usage: qs order <order-id>");
|
|
1621
|
+
process.exit(1);
|
|
1622
|
+
}
|
|
1623
|
+
const o = await api.getOrder(id);
|
|
1624
|
+
console.log(` ${BOLD}Order${RESET} ${o.id}`);
|
|
1625
|
+
console.log(` ${BOLD}Status${RESET} ${o.payment_status}`);
|
|
1626
|
+
console.log(` ${BOLD}Amount${RESET} ${formatUsd(o.final_price_cents)}`);
|
|
1627
|
+
console.log(` ${BOLD}Method${RESET} ${o.payment_method ?? "—"}`);
|
|
1628
|
+
console.log(` ${BOLD}Quote${RESET} ${o.quote_id}`);
|
|
1629
|
+
console.log(` ${BOLD}Version${RESET} ${o.project_version_id}`);
|
|
1630
|
+
console.log(` ${BOLD}Job${RESET} ${o.audit_job_id ?? "—"}`);
|
|
1631
|
+
if (o.stripe_checkout_url)
|
|
1632
|
+
console.log(` ${BOLD}Checkout${RESET} ${o.stripe_checkout_url}`);
|
|
1633
|
+
}
|
|
404
1634
|
async function cmdStatus(args) {
|
|
405
1635
|
const cfg = await requireConfig();
|
|
406
1636
|
const api = new QuillShieldApi(cfg);
|
|
@@ -416,7 +1646,6 @@ async function cmdStatus(args) {
|
|
|
416
1646
|
console.log(` ${BOLD}Version${RESET} ${job.project_version_id}`);
|
|
417
1647
|
console.log(` ${BOLD}Depth${RESET} ${job.depth}`);
|
|
418
1648
|
console.log(` ${BOLD}Trigger${RESET} ${job.trigger}`);
|
|
419
|
-
console.log(` ${BOLD}Credits${RESET} ${job.credits_quoted} quoted / ${job.credits_charged} charged`);
|
|
420
1649
|
if (job.progress) {
|
|
421
1650
|
console.log(` ${BOLD}Phase${RESET} ${job.progress.phase} (${job.progress.pct}%)`);
|
|
422
1651
|
}
|
|
@@ -451,14 +1680,14 @@ Job already ${colorStatus(job.status)}.`);
|
|
|
451
1680
|
return;
|
|
452
1681
|
}
|
|
453
1682
|
info("Connecting to live stream...");
|
|
454
|
-
const done = new Promise((
|
|
1683
|
+
const done = new Promise((resolveDone) => {
|
|
455
1684
|
let stream = api.streamEvents(jobId, (event, data) => {
|
|
456
1685
|
switch (event) {
|
|
457
1686
|
case "status":
|
|
458
1687
|
console.log(` [status] ${colorStatus(data.status)}`);
|
|
459
1688
|
if (["completed", "failed", "cancelled"].includes(data.status)) {
|
|
460
1689
|
stream.close();
|
|
461
|
-
|
|
1690
|
+
resolveDone();
|
|
462
1691
|
}
|
|
463
1692
|
break;
|
|
464
1693
|
case "phase":
|
|
@@ -481,19 +1710,19 @@ ${BOLD}Job ${data.status}.${RESET}`);
|
|
|
481
1710
|
if (data.error)
|
|
482
1711
|
console.log(` ${RED}Error: ${data.error}${RESET}`);
|
|
483
1712
|
stream.close();
|
|
484
|
-
|
|
1713
|
+
resolveDone();
|
|
485
1714
|
break;
|
|
486
1715
|
}
|
|
487
1716
|
}, (_err) => {
|
|
488
1717
|
console.log(`${DIM}(stream disconnected, falling back to polling)${RESET}`);
|
|
489
|
-
pollUntilDone(api, jobId,
|
|
1718
|
+
pollUntilDone(api, jobId, resolveDone);
|
|
490
1719
|
});
|
|
491
1720
|
});
|
|
492
1721
|
await done;
|
|
493
1722
|
console.log(`
|
|
494
1723
|
Run ${DIM}qs findings ${jobId}${RESET} to see full results.`);
|
|
495
1724
|
}
|
|
496
|
-
async function pollUntilDone(api, jobId,
|
|
1725
|
+
async function pollUntilDone(api, jobId, resolveDone) {
|
|
497
1726
|
const poll = async () => {
|
|
498
1727
|
try {
|
|
499
1728
|
const job = await api.getAudit(jobId);
|
|
@@ -502,16 +1731,16 @@ async function pollUntilDone(api, jobId, resolve2) {
|
|
|
502
1731
|
${BOLD}Job ${job.status}.${RESET}`);
|
|
503
1732
|
if (job.error)
|
|
504
1733
|
console.log(` ${RED}Error: ${job.error}${RESET}`);
|
|
505
|
-
|
|
1734
|
+
resolveDone();
|
|
506
1735
|
return;
|
|
507
1736
|
}
|
|
508
1737
|
if (job.progress) {
|
|
509
1738
|
console.log(` [poll] ${job.progress.phase} (${job.progress.pct}%)`);
|
|
510
1739
|
}
|
|
511
1740
|
setTimeout(poll, 5000);
|
|
512
|
-
} catch (
|
|
513
|
-
fail(`Polling failed: ${
|
|
514
|
-
|
|
1741
|
+
} catch (err2) {
|
|
1742
|
+
fail(`Polling failed: ${err2.message}`);
|
|
1743
|
+
resolveDone();
|
|
515
1744
|
}
|
|
516
1745
|
};
|
|
517
1746
|
setTimeout(poll, 5000);
|
|
@@ -552,25 +1781,30 @@ async function cmdReport(args) {
|
|
|
552
1781
|
const api = new QuillShieldApi(cfg);
|
|
553
1782
|
const { values, positionals } = parseArgs({
|
|
554
1783
|
args,
|
|
555
|
-
options: {
|
|
1784
|
+
options: {
|
|
1785
|
+
format: { type: "string", default: "pdf" },
|
|
1786
|
+
out: { type: "string" }
|
|
1787
|
+
},
|
|
556
1788
|
allowPositionals: true
|
|
557
1789
|
});
|
|
558
1790
|
const jobId = positionals[0];
|
|
559
1791
|
if (!jobId) {
|
|
560
|
-
fail("Usage: qs report <job-id> [--format pdf|json]");
|
|
1792
|
+
fail("Usage: qs report <job-id> [--format pdf|json|md] [--out path]");
|
|
561
1793
|
process.exit(1);
|
|
562
1794
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
1795
|
+
const format = values.format || "pdf";
|
|
1796
|
+
info(`Fetching ${format} report for job ${jobId}...`);
|
|
1797
|
+
const { bytes, filename } = await api.downloadReport(jobId, format);
|
|
1798
|
+
const outPath = resolve(values.out ?? filename);
|
|
1799
|
+
writeFileSync(outPath, bytes);
|
|
1800
|
+
success(`Wrote ${outPath} (${(bytes.length / 1024).toFixed(0)} KB)`);
|
|
567
1801
|
}
|
|
568
1802
|
async function cmdProjects() {
|
|
569
1803
|
const cfg = await requireConfig();
|
|
570
1804
|
const api = new QuillShieldApi(cfg);
|
|
571
1805
|
const projects = await api.listProjects();
|
|
572
1806
|
if (projects.length === 0) {
|
|
573
|
-
console.log("No projects yet. Run `qs audit <git-url
|
|
1807
|
+
console.log("No projects yet. Run `qs audit <git-url> --yes` to create one.");
|
|
574
1808
|
return;
|
|
575
1809
|
}
|
|
576
1810
|
console.log(`${BOLD}Projects (${projects.length})${RESET}
|
|
@@ -602,12 +1836,6 @@ async function cmdVersions(args) {
|
|
|
602
1836
|
console.log(` ${DIM}${v.created_at}${RESET}`);
|
|
603
1837
|
}
|
|
604
1838
|
}
|
|
605
|
-
async function cmdCredits() {
|
|
606
|
-
const cfg = await requireConfig();
|
|
607
|
-
const api = new QuillShieldApi(cfg);
|
|
608
|
-
const { balance } = await api.getCredits();
|
|
609
|
-
console.log(` ${BOLD}Credit balance${RESET} ${GREEN}${balance}${RESET}`);
|
|
610
|
-
}
|
|
611
1839
|
async function cmdCancel(args) {
|
|
612
1840
|
const cfg = await requireConfig();
|
|
613
1841
|
const api = new QuillShieldApi(cfg);
|
|
@@ -623,31 +1851,32 @@ async function cmdLogout() {
|
|
|
623
1851
|
await clearConfig();
|
|
624
1852
|
success("Logged out. Config removed from ~/.quillshield/config.json");
|
|
625
1853
|
}
|
|
1854
|
+
async function cmdCredits() {
|
|
1855
|
+
warn("`qs credits` is deprecated — showing wallet instead.");
|
|
1856
|
+
await cmdWallet();
|
|
1857
|
+
}
|
|
626
1858
|
var stdinBuffer = [];
|
|
627
|
-
var stdinEnded = false;
|
|
628
1859
|
async function readLine() {
|
|
629
1860
|
if (stdinBuffer.length > 0) {
|
|
630
1861
|
return stdinBuffer.shift();
|
|
631
1862
|
}
|
|
632
|
-
return new Promise((
|
|
1863
|
+
return new Promise((resolveLine) => {
|
|
633
1864
|
process.stdin.resume();
|
|
634
1865
|
process.stdin.setEncoding("utf8");
|
|
635
1866
|
const onData = (chunk) => {
|
|
636
1867
|
const lines = chunk.split(`
|
|
637
1868
|
`);
|
|
638
1869
|
const first = lines.shift();
|
|
639
|
-
for (const line of lines)
|
|
1870
|
+
for (const line of lines)
|
|
640
1871
|
stdinBuffer.push(line);
|
|
641
|
-
}
|
|
642
1872
|
process.stdin.pause();
|
|
643
1873
|
process.stdin.removeListener("data", onData);
|
|
644
|
-
|
|
1874
|
+
resolveLine(first.trim());
|
|
645
1875
|
};
|
|
646
1876
|
const onEnd = () => {
|
|
647
|
-
stdinEnded = true;
|
|
648
1877
|
process.stdin.removeListener("end", onEnd);
|
|
649
1878
|
process.stdin.removeListener("data", onData);
|
|
650
|
-
|
|
1879
|
+
resolveLine("");
|
|
651
1880
|
};
|
|
652
1881
|
process.stdin.on("data", onData);
|
|
653
1882
|
process.stdin.on("end", onEnd);
|
|
@@ -681,6 +1910,24 @@ async function main() {
|
|
|
681
1910
|
case "audit":
|
|
682
1911
|
await cmdAudit(rest);
|
|
683
1912
|
break;
|
|
1913
|
+
case "quote":
|
|
1914
|
+
await cmdQuote(rest);
|
|
1915
|
+
break;
|
|
1916
|
+
case "pay":
|
|
1917
|
+
await cmdPay(rest);
|
|
1918
|
+
break;
|
|
1919
|
+
case "wallet":
|
|
1920
|
+
await cmdWallet();
|
|
1921
|
+
break;
|
|
1922
|
+
case "topup":
|
|
1923
|
+
await cmdTopup(rest);
|
|
1924
|
+
break;
|
|
1925
|
+
case "orders":
|
|
1926
|
+
await cmdOrders();
|
|
1927
|
+
break;
|
|
1928
|
+
case "order":
|
|
1929
|
+
await cmdOrder(rest);
|
|
1930
|
+
break;
|
|
684
1931
|
case "status":
|
|
685
1932
|
await cmdStatus(rest);
|
|
686
1933
|
break;
|
|
@@ -713,9 +1960,12 @@ async function main() {
|
|
|
713
1960
|
console.log("Run `qs help` for usage.");
|
|
714
1961
|
process.exit(1);
|
|
715
1962
|
}
|
|
716
|
-
} catch (
|
|
717
|
-
const e =
|
|
1963
|
+
} catch (err2) {
|
|
1964
|
+
const e = err2;
|
|
718
1965
|
fail(e.message);
|
|
1966
|
+
if (e instanceof ApiClientError && e.code) {
|
|
1967
|
+
console.error(` ${DIM}code: ${e.code}${RESET}`);
|
|
1968
|
+
}
|
|
719
1969
|
if (e.message.includes("Not configured")) {
|
|
720
1970
|
console.log("Run `qs init` to set up your API key.");
|
|
721
1971
|
}
|