@delopay/sdk 0.165.0 → 0.166.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/dist/internal.cjs CHANGED
@@ -1192,6 +1192,289 @@ var Customers = class {
1192
1192
  }
1193
1193
  };
1194
1194
 
1195
+ // src/recordCounter.ts
1196
+ var LF = 10;
1197
+ var CR = 13;
1198
+ var QUOTE = 34;
1199
+ var BACKSLASH = 92;
1200
+ var OPEN_BRACE = 123;
1201
+ var CLOSE_BRACE = 125;
1202
+ var OPEN_BRACKET = 91;
1203
+ var CLOSE_BRACKET = 93;
1204
+ var CsvRecordCounter = class {
1205
+ constructor() {
1206
+ this.inQuotes = false;
1207
+ this.newlines = 0;
1208
+ /** Whether anything but a line break has arrived since the last newline. */
1209
+ this.lineHasContent = false;
1210
+ }
1211
+ push(chunk) {
1212
+ let inQuotes = this.inQuotes;
1213
+ let newlines = this.newlines;
1214
+ let lineHasContent = this.lineHasContent;
1215
+ for (const byte of chunk) {
1216
+ if (byte === QUOTE) {
1217
+ inQuotes = !inQuotes;
1218
+ lineHasContent = true;
1219
+ } else if (inQuotes) {
1220
+ lineHasContent = true;
1221
+ } else if (byte === LF) {
1222
+ newlines++;
1223
+ lineHasContent = false;
1224
+ } else if (byte !== CR) {
1225
+ lineHasContent = true;
1226
+ }
1227
+ }
1228
+ this.inQuotes = inQuotes;
1229
+ this.newlines = newlines;
1230
+ this.lineHasContent = lineHasContent;
1231
+ }
1232
+ get records() {
1233
+ return Math.max(0, this.newlines - 1);
1234
+ }
1235
+ /**
1236
+ * The export writer ends every line — the header and each record — with a
1237
+ * newline, so a whole body ends on one, outside quotes. RFC 4180 lets a
1238
+ * final line break be omitted, but these bodies never omit it, and without
1239
+ * that rule a file cut part-way through its last unquoted field
1240
+ * (`pay_1,12` of `pay_1,123`) would count as one more whole record and
1241
+ * match the figure it was announced with.
1242
+ */
1243
+ get complete() {
1244
+ return this.newlines >= 1 && !this.inQuotes && !this.lineHasContent;
1245
+ }
1246
+ /**
1247
+ * The records that ended. An unterminated tail is not one of them — see
1248
+ * {@link complete}.
1249
+ */
1250
+ finish() {
1251
+ return this.records;
1252
+ }
1253
+ };
1254
+ var SEEKING = 0;
1255
+ var COUNTING = 1;
1256
+ var CLOSED = 2;
1257
+ var JsonArrayRecordCounter = class {
1258
+ constructor() {
1259
+ this.depth = 0;
1260
+ this.inString = false;
1261
+ this.escaped = false;
1262
+ this.topIsObject = false;
1263
+ this.state = SEEKING;
1264
+ this.count = 0;
1265
+ }
1266
+ push(chunk) {
1267
+ if (this.state === CLOSED) return;
1268
+ let { depth, inString, escaped, topIsObject, count } = this;
1269
+ let state = this.state;
1270
+ for (const byte of chunk) {
1271
+ if (inString) {
1272
+ if (escaped) escaped = false;
1273
+ else if (byte === BACKSLASH) escaped = true;
1274
+ else if (byte === QUOTE) inString = false;
1275
+ continue;
1276
+ }
1277
+ if (byte === QUOTE) {
1278
+ inString = true;
1279
+ } else if (byte === OPEN_BRACE || byte === OPEN_BRACKET) {
1280
+ if (depth === 0 && byte === OPEN_BRACE) topIsObject = true;
1281
+ if (byte === OPEN_BRACKET && depth === 1 && topIsObject && state === SEEKING) {
1282
+ state = COUNTING;
1283
+ }
1284
+ depth++;
1285
+ } else if (byte === CLOSE_BRACE || byte === CLOSE_BRACKET) {
1286
+ depth--;
1287
+ if (state === COUNTING) {
1288
+ if (depth === 2) count++;
1289
+ else if (depth === 1) {
1290
+ state = CLOSED;
1291
+ break;
1292
+ }
1293
+ }
1294
+ }
1295
+ }
1296
+ this.depth = depth;
1297
+ this.inString = inString;
1298
+ this.escaped = escaped;
1299
+ this.topIsObject = topIsObject;
1300
+ this.state = state;
1301
+ this.count = count;
1302
+ }
1303
+ get records() {
1304
+ return this.count;
1305
+ }
1306
+ /**
1307
+ * Whether the rows array has closed. What follows it is checked by parsing
1308
+ * the whole document, which a cut-off body fails.
1309
+ */
1310
+ get complete() {
1311
+ return this.state === CLOSED;
1312
+ }
1313
+ finish() {
1314
+ return this.count;
1315
+ }
1316
+ };
1317
+
1318
+ // src/exportDownload.ts
1319
+ var RECORD_COUNT_HEADER = "x-delopay-record-count";
1320
+ var LIST_ENVELOPE = { rows: "records", count: "record_count" };
1321
+ var WORKSPACE_ENVELOPE = { rows: "data", count: "total_count" };
1322
+ function parseRecordCount(header) {
1323
+ if (header === null) return null;
1324
+ const trimmed = header.trim();
1325
+ if (!/^\d+$/.test(trimmed)) return null;
1326
+ const value = Number(trimmed);
1327
+ return Number.isSafeInteger(value) ? value : null;
1328
+ }
1329
+ function counterFor(format) {
1330
+ if (format === "csv") return new CsvRecordCounter();
1331
+ if (format === "json") return new JsonArrayRecordCounter();
1332
+ return null;
1333
+ }
1334
+ function isRecord(value) {
1335
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1336
+ }
1337
+ function announced(expected) {
1338
+ return expected === null ? "" : ` of the ${expected} announced`;
1339
+ }
1340
+ function incomplete(message, expected, received, requestId) {
1341
+ return new DelopayError(message, {
1342
+ status: 0,
1343
+ code: "EXPORT_INCOMPLETE",
1344
+ type: "export_incomplete",
1345
+ ...requestId !== void 0 ? { requestId } : {},
1346
+ data: { expected_records: expected, received_records: received }
1347
+ });
1348
+ }
1349
+ async function downloadExport(request, call, options) {
1350
+ const { format } = call;
1351
+ const envelope = call.envelope ?? LIST_ENVELOPE;
1352
+ const onProgress = options?.onProgress;
1353
+ let latest = {
1354
+ phase: "preparing",
1355
+ receivedBytes: 0,
1356
+ totalBytes: null,
1357
+ receivedRecords: 0,
1358
+ expectedRecords: null
1359
+ };
1360
+ const seen = { attempt: -1, counter: null, expected: null, requestId: void 0, listenerError: null };
1361
+ const report = (progress) => {
1362
+ latest = progress;
1363
+ if (!onProgress) return;
1364
+ try {
1365
+ onProgress({ ...progress });
1366
+ } catch (error) {
1367
+ seen.listenerError = { error };
1368
+ throw error;
1369
+ }
1370
+ };
1371
+ report(latest);
1372
+ const onDownloadProgress = (event) => {
1373
+ if (event.attempt !== seen.attempt) {
1374
+ seen.attempt = event.attempt;
1375
+ seen.counter = counterFor(format);
1376
+ seen.expected = format === "pdf" ? null : parseRecordCount(event.headers.get(RECORD_COUNT_HEADER));
1377
+ seen.requestId = event.headers.get("x-request-id") ?? event.headers.get("x-trace-id") ?? void 0;
1378
+ }
1379
+ if (event.chunk.byteLength > 0) seen.counter?.push(event.chunk);
1380
+ report({
1381
+ phase: "receiving",
1382
+ receivedBytes: event.loaded,
1383
+ totalBytes: event.total,
1384
+ receivedRecords: seen.counter?.records ?? 0,
1385
+ expectedRecords: seen.expected
1386
+ });
1387
+ };
1388
+ let result;
1389
+ try {
1390
+ result = await request(call.method, call.path, {
1391
+ ...call.request,
1392
+ ...options?.signal !== void 0 ? { signal: options.signal } : {},
1393
+ ...options?.timeout !== void 0 ? { timeout: options.timeout } : {},
1394
+ onDownloadProgress
1395
+ });
1396
+ } catch (err) {
1397
+ if (seen.listenerError !== null && err === seen.listenerError.error) throw err;
1398
+ if (format === "json" && seen.attempt >= 0 && err instanceof SyntaxError) {
1399
+ const received2 = seen.counter?.records ?? 0;
1400
+ throw incomplete(
1401
+ seen.expected === null ? `Export incomplete: the body ended part-way through the JSON document, after ${received2} records` : `Export incomplete: the server announced ${seen.expected} records, and the body ended part-way through the JSON document after ${received2}`,
1402
+ seen.expected,
1403
+ received2,
1404
+ seen.requestId
1405
+ );
1406
+ }
1407
+ throw err;
1408
+ }
1409
+ const { expected, requestId } = seen;
1410
+ let received = 0;
1411
+ if (format === "json") {
1412
+ const rows = isRecord(result) ? result[envelope.rows] : void 0;
1413
+ if (!Array.isArray(rows)) {
1414
+ throw incomplete(
1415
+ `Export incomplete: the body is not an export envelope with a "${envelope.rows}" array, so it carries 0 records${announced(expected)}`,
1416
+ expected,
1417
+ 0,
1418
+ requestId
1419
+ );
1420
+ }
1421
+ received = rows.length;
1422
+ const declared = isRecord(result) ? result[envelope.count] : void 0;
1423
+ if (typeof declared === "number" && declared !== rows.length) {
1424
+ throw incomplete(
1425
+ `Export incomplete: the file's ${envelope.count} is ${declared}, but it carries ${rows.length} records`,
1426
+ declared,
1427
+ rows.length,
1428
+ requestId
1429
+ );
1430
+ }
1431
+ } else if (format === "csv") {
1432
+ const counter = seen.counter;
1433
+ received = counter?.finish() ?? 0;
1434
+ if (!counter?.complete) {
1435
+ throw incomplete(
1436
+ `Export incomplete: the CSV body ended part-way through a line, after ${received} complete records${announced(expected)}`,
1437
+ expected,
1438
+ received,
1439
+ requestId
1440
+ );
1441
+ }
1442
+ }
1443
+ if (expected !== null && received !== expected) {
1444
+ throw incomplete(
1445
+ `Export incomplete: the server announced ${expected} records, and the body carried ${received}`,
1446
+ expected,
1447
+ received,
1448
+ requestId
1449
+ );
1450
+ }
1451
+ report({
1452
+ phase: "done",
1453
+ receivedBytes: latest.receivedBytes,
1454
+ totalBytes: latest.totalBytes,
1455
+ receivedRecords: received,
1456
+ expectedRecords: expected
1457
+ });
1458
+ return result;
1459
+ }
1460
+ var ACCEPT = {
1461
+ csv: "text/csv",
1462
+ json: "application/json",
1463
+ pdf: "application/pdf"
1464
+ };
1465
+ function negotiated(options, format) {
1466
+ const headers = { ...options.headers, Accept: ACCEPT[format] };
1467
+ return format === "json" ? { ...options, headers } : { ...options, headers, responseType: "blob" };
1468
+ }
1469
+ function runExport(request, method, path, base, options) {
1470
+ const format = options?.format ?? "json";
1471
+ return downloadExport(
1472
+ request,
1473
+ { method, path, request: negotiated(base, format), format },
1474
+ options
1475
+ );
1476
+ }
1477
+
1195
1478
  // src/resources/disputes.ts
1196
1479
  function workspaceQuery(params) {
1197
1480
  if (!params) return void 0;
@@ -1220,9 +1503,28 @@ var Disputes = class {
1220
1503
  async workspaceAggregate(params) {
1221
1504
  return this.request("GET", "/disputes/workspace/aggregate", { query: workspaceQuery(params) });
1222
1505
  }
1223
- /** Export the complete filtered set, or throw on the server's explicit export-limit refusal. */
1224
- async workspaceExport(params) {
1225
- return this.request("GET", "/disputes/workspace/export", { query: workspaceQuery(params) });
1506
+ /**
1507
+ * Export the complete filtered set, or throw on the server's explicit
1508
+ * export-limit refusal. `GET /disputes/workspace/export`
1509
+ *
1510
+ * The body is streamed, and held to the `X-Delopay-Record-Count` the server
1511
+ * announces and to its own `total_count`: a set that arrives short rejects
1512
+ * with `EXPORT_INCOMPLETE` rather than resolving. `options` reports the
1513
+ * download's progress and takes a signal and an idle timeout — see
1514
+ * {@link ExportTransferOptions}.
1515
+ */
1516
+ async workspaceExport(params, options) {
1517
+ return downloadExport(
1518
+ this.request,
1519
+ {
1520
+ method: "GET",
1521
+ path: "/disputes/workspace/export",
1522
+ request: { query: workspaceQuery(params) },
1523
+ format: "json",
1524
+ envelope: WORKSPACE_ENVELOPE
1525
+ },
1526
+ options
1527
+ );
1226
1528
  }
1227
1529
  /**
1228
1530
  * Retrieve a dispute by its ID.
@@ -4379,77 +4681,68 @@ var Export = class {
4379
4681
  this.request = request;
4380
4682
  }
4381
4683
  async transactions(params, options) {
4382
- return this.request(
4383
- "POST",
4384
- "/export/transactions",
4385
- transactionBody(params, options)
4386
- );
4684
+ return runExport(this.request, "POST", "/export/transactions", { body: params ?? {} }, options);
4387
4685
  }
4388
4686
  async transactionsForProfile(params, options) {
4389
- return this.request(
4687
+ return runExport(
4688
+ this.request,
4390
4689
  "POST",
4391
4690
  "/export/profile/transactions",
4392
- transactionBody(params, options)
4691
+ { body: params ?? {} },
4692
+ options
4393
4693
  );
4394
4694
  }
4395
4695
  async refunds(params, options) {
4396
- return this.request("POST", "/refunds/list/export", bodied(params ?? {}, options));
4696
+ return runExport(this.request, "POST", "/refunds/list/export", { body: params ?? {} }, options);
4397
4697
  }
4398
4698
  async refundsForProfile(params, options) {
4399
- return this.request(
4699
+ return runExport(
4700
+ this.request,
4400
4701
  "POST",
4401
4702
  "/refunds/profile/list/export",
4402
- bodied(params ?? {}, options)
4703
+ { body: params ?? {} },
4704
+ options
4403
4705
  );
4404
4706
  }
4405
4707
  async disputes(params, options) {
4406
- return this.request("GET", "/disputes/list/export", queried(params, options));
4708
+ return runExport(this.request, "GET", "/disputes/list/export", queried(params), options);
4407
4709
  }
4408
4710
  async disputesForProfile(params, options) {
4409
- return this.request(
4711
+ return runExport(
4712
+ this.request,
4410
4713
  "GET",
4411
4714
  "/disputes/profile/list/export",
4412
- queried(params, options)
4715
+ queried(params),
4716
+ options
4413
4717
  );
4414
4718
  }
4415
4719
  async payouts(params, options) {
4416
- return this.request("POST", "/payouts/list/export", bodied(params, options));
4720
+ return runExport(this.request, "POST", "/payouts/list/export", { body: params }, options);
4417
4721
  }
4418
4722
  async payoutsForProfile(params, options) {
4419
- return this.request("POST", "/payouts/profile/list/export", bodied(params, options));
4723
+ return runExport(
4724
+ this.request,
4725
+ "POST",
4726
+ "/payouts/profile/list/export",
4727
+ { body: params },
4728
+ options
4729
+ );
4420
4730
  }
4421
4731
  async subscriptions(profileId, params, options) {
4422
- return this.request(
4732
+ return runExport(
4733
+ this.request,
4423
4734
  "GET",
4424
4735
  "/subscriptions/list/export",
4425
- queried(params, options, { "X-Profile-Id": profileId })
4736
+ queried(params, { "X-Profile-Id": profileId }),
4737
+ options
4426
4738
  );
4427
4739
  }
4428
4740
  async auditLog(params, options) {
4429
- return this.request("GET", "/audit/export", queried(params, options));
4741
+ return runExport(this.request, "GET", "/audit/export", queried(params), options);
4430
4742
  }
4431
4743
  };
4432
- var ACCEPT = {
4433
- csv: "text/csv",
4434
- json: "application/json",
4435
- pdf: "application/pdf"
4436
- };
4437
- function negotiated(options, format) {
4438
- const headers = { ...options.headers, Accept: ACCEPT[format] };
4439
- return format === "json" ? { ...options, headers } : { ...options, headers, responseType: "blob" };
4440
- }
4441
- function transactionBody(params, options) {
4442
- const format = options?.format ?? "json";
4443
- return negotiated({ body: { ...params, format } }, format);
4444
- }
4445
- function bodied(body, options) {
4446
- return negotiated({ body }, options?.format ?? "json");
4447
- }
4448
- function queried(params, options, headers) {
4449
- return negotiated(
4450
- { query: params ?? {}, ...headers ? { headers } : {} },
4451
- options?.format ?? "json"
4452
- );
4744
+ function queried(params, headers) {
4745
+ return { query: params ?? {}, ...headers ? { headers } : {} };
4453
4746
  }
4454
4747
 
4455
4748
  // src/resources/featureMatrix.ts
@@ -5822,6 +6115,112 @@ function findIdempotencyKey(headers) {
5822
6115
  }
5823
6116
  function noop() {
5824
6117
  }
6118
+ var ListenerFailure = class {
6119
+ constructor(cause) {
6120
+ this.cause = cause;
6121
+ }
6122
+ };
6123
+ var BodyStreamFailure = class {
6124
+ constructor(cause) {
6125
+ this.cause = cause;
6126
+ }
6127
+ };
6128
+ function abortError() {
6129
+ const error = new Error("The operation was aborted");
6130
+ error.name = "AbortError";
6131
+ return error;
6132
+ }
6133
+ function parseContentLength(header) {
6134
+ if (header === null || !/^\s*\d+\s*$/.test(header)) return null;
6135
+ const value = Number(header);
6136
+ return Number.isSafeInteger(value) ? value : null;
6137
+ }
6138
+ function readChunk(reader, signal) {
6139
+ if (signal.aborted) return Promise.reject(abortError());
6140
+ return new Promise((resolve, reject) => {
6141
+ const onAbort = () => reject(abortError());
6142
+ signal.addEventListener("abort", onAbort, { once: true });
6143
+ reader.read().then(
6144
+ (result) => {
6145
+ signal.removeEventListener("abort", onAbort);
6146
+ resolve(result);
6147
+ },
6148
+ (cause) => {
6149
+ signal.removeEventListener("abort", onAbort);
6150
+ reject(signal.aborted ? abortError() : new BodyStreamFailure(cause));
6151
+ }
6152
+ );
6153
+ });
6154
+ }
6155
+ function concatChunks(chunks, length) {
6156
+ const out = new Uint8Array(length);
6157
+ let offset = 0;
6158
+ for (const chunk of chunks) {
6159
+ out.set(chunk, offset);
6160
+ offset += chunk.byteLength;
6161
+ }
6162
+ return out.buffer;
6163
+ }
6164
+ async function receiveWithProgress(response, responseType, listener, attempt, signal, onActivity) {
6165
+ const headers = response.headers ?? new Headers();
6166
+ const total = parseContentLength(headers.get("content-length"));
6167
+ let loaded = 0;
6168
+ const notify = (chunk) => {
6169
+ try {
6170
+ listener({ loaded, total, chunk: chunk.slice(), headers, attempt });
6171
+ } catch (cause) {
6172
+ throw new ListenerFailure(cause);
6173
+ }
6174
+ };
6175
+ onActivity();
6176
+ notify(new Uint8Array(0));
6177
+ const body = response.body;
6178
+ if (!body || typeof body.getReader !== "function") {
6179
+ if (responseType === "blob") {
6180
+ const blob = await response.blob();
6181
+ const bytes3 = new Uint8Array(await blob.arrayBuffer());
6182
+ loaded = bytes3.byteLength;
6183
+ if (loaded > 0) notify(bytes3);
6184
+ return blob;
6185
+ }
6186
+ if (responseType === "arraybuffer") {
6187
+ const buffer = await response.arrayBuffer();
6188
+ loaded = buffer.byteLength;
6189
+ if (loaded > 0) notify(new Uint8Array(buffer));
6190
+ return buffer;
6191
+ }
6192
+ const text2 = await response.text();
6193
+ const bytes2 = new TextEncoder().encode(text2);
6194
+ loaded = bytes2.byteLength;
6195
+ if (loaded > 0) notify(bytes2);
6196
+ return text2 ? JSON.parse(text2) : void 0;
6197
+ }
6198
+ const reader = body.getReader();
6199
+ const chunks = [];
6200
+ try {
6201
+ for (; ; ) {
6202
+ const { done, value } = await readChunk(reader, signal);
6203
+ if (done) break;
6204
+ if (!value || value.byteLength === 0) continue;
6205
+ chunks.push(value);
6206
+ loaded += value.byteLength;
6207
+ onActivity();
6208
+ notify(value);
6209
+ }
6210
+ } catch (err) {
6211
+ reader.cancel().catch(noop);
6212
+ throw err;
6213
+ }
6214
+ const bytes = concatChunks(chunks, loaded);
6215
+ if (responseType === "blob") {
6216
+ return new Blob([bytes], { type: headers.get("content-type") ?? "" });
6217
+ }
6218
+ if (responseType === "arraybuffer") {
6219
+ return bytes;
6220
+ }
6221
+ const text = new TextDecoder().decode(bytes);
6222
+ return text ? JSON.parse(text) : void 0;
6223
+ }
5825
6224
  function combineSignals(signals) {
5826
6225
  const controller = new AbortController();
5827
6226
  const listeners = [];
@@ -6103,7 +6502,12 @@ var Delopay = class {
6103
6502
  emit("retry", { attempt, maxRetries: this.maxRetries, method, path });
6104
6503
  }
6105
6504
  const timeoutCtrl = new AbortController();
6106
- const timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
6505
+ let timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
6506
+ const restartIdleTimer = () => {
6507
+ if (timeoutCtrl.signal.aborted) return;
6508
+ clearTimeout(timeoutId);
6509
+ timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
6510
+ };
6107
6511
  const combined = combineSignals(
6108
6512
  callerSignal ? [timeoutCtrl.signal, callerSignal] : [timeoutCtrl.signal]
6109
6513
  );
@@ -6161,6 +6565,16 @@ var Delopay = class {
6161
6565
  }
6162
6566
  throw error;
6163
6567
  }
6568
+ if (options?.onDownloadProgress) {
6569
+ return await receiveWithProgress(
6570
+ response,
6571
+ options.responseType,
6572
+ options.onDownloadProgress,
6573
+ attempt,
6574
+ combined.signal,
6575
+ restartIdleTimer
6576
+ );
6577
+ }
6164
6578
  if (options?.responseType === "blob") {
6165
6579
  return await response.blob();
6166
6580
  }
@@ -6173,6 +6587,20 @@ var Delopay = class {
6173
6587
  if (err instanceof DelopayError || err instanceof DelopayAuthenticationError) {
6174
6588
  throw err;
6175
6589
  }
6590
+ if (err instanceof ListenerFailure) {
6591
+ throw err.cause;
6592
+ }
6593
+ if (err instanceof BodyStreamFailure) {
6594
+ const cause = err.cause;
6595
+ const detail = cause instanceof Error ? cause.message : String(cause ?? "body stream failed");
6596
+ lastError = new DelopayError(`Network error: ${detail}`, {
6597
+ status: 0,
6598
+ code: "NETWORK",
6599
+ type: "network_error"
6600
+ });
6601
+ if (isRetryable && attempt < this.maxRetries) continue;
6602
+ throw lastError;
6603
+ }
6176
6604
  if (err instanceof Error && err.name === "AbortError") {
6177
6605
  if (callerSignal?.aborted) {
6178
6606
  throw new DelopayError("Request aborted", {
@@ -9820,6 +10248,15 @@ var AdminPortal = class {
9820
10248
  query
9821
10249
  });
9822
10250
  }
10251
+ async exportTransactions(params, options) {
10252
+ return runExport(
10253
+ this.request,
10254
+ "GET",
10255
+ "/admin-portal/transactions/export",
10256
+ { query: transactionListQuery(params) },
10257
+ options
10258
+ );
10259
+ }
9823
10260
  /**
9824
10261
  * Full detail for a single transaction of ANY merchant — the same
9825
10262
  * `PaymentResponse` the merchant `payments.retrieve` returns. Admin-scoped:
@@ -10418,11 +10855,13 @@ var AdminPortal = class {
10418
10855
  }
10419
10856
  /**
10420
10857
  * Export a settlement statement as PDF. Returns the raw bytes as a `Blob`
10421
- * with the same auth and error handling as every other call.
10858
+ * with the same auth and error handling as every other call. `options`
10859
+ * takes a signal, a timeout and an `onDownloadProgress` listener for the
10860
+ * download's bytes (the PDF carries a `Content-Length`, so `total` is set).
10422
10861
  *
10423
10862
  * `GET /admin-portal/accounts/{merchantId}/settlement/statements/{statementId}/pdf`
10424
10863
  */
10425
- async downloadSettlementStatementPdf(merchantId, statementId, params) {
10864
+ async downloadSettlementStatementPdf(merchantId, statementId, params, options) {
10426
10865
  return this.request(
10427
10866
  "GET",
10428
10867
  `/admin-portal/accounts/${encodeURIComponent(merchantId)}/settlement/statements/${encodeURIComponent(statementId)}/pdf`,
@@ -10431,7 +10870,8 @@ var AdminPortal = class {
10431
10870
  currency: params?.currency,
10432
10871
  include_transactions: params?.include_transactions
10433
10872
  },
10434
- responseType: "blob"
10873
+ responseType: "blob",
10874
+ ...options
10435
10875
  }
10436
10876
  );
10437
10877
  }
@@ -10536,17 +10976,16 @@ var AuditLogs = class {
10536
10976
  return this.request("GET", `/admin-portal/audit/${encodeURIComponent(logId)}`);
10537
10977
  }
10538
10978
  async export(params, options) {
10539
- const format = options?.format ?? "json";
10540
- const accept = format === "csv" ? "text/csv" : format === "pdf" ? "application/pdf" : "application/json";
10541
- const request = {
10542
- query: params,
10979
+ return runExport(
10980
+ this.request,
10981
+ "GET",
10982
+ "/admin-portal/audit/export",
10543
10983
  // The format is negotiated by `Accept`, never a query field: the query
10544
10984
  // here is the list's own filter model, and adding a key to it would fork
10545
10985
  // the filter vocabulary the export exists to reuse.
10546
- headers: { Accept: accept }
10547
- };
10548
- if (format !== "json") request.responseType = "blob";
10549
- return this.request("GET", "/admin-portal/audit/export", request);
10986
+ { query: params },
10987
+ options
10988
+ );
10550
10989
  }
10551
10990
  };
10552
10991