@delopay/sdk 0.167.0 → 0.169.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
@@ -1317,6 +1317,26 @@ var JsonArrayRecordCounter = class {
1317
1317
 
1318
1318
  // src/exportDownload.ts
1319
1319
  var RECORD_COUNT_HEADER = "x-delopay-record-count";
1320
+ var PRESENTATION_HEADER = "X-Delopay-Export-Presentation";
1321
+ var MAX_PRESENTATION_HEADER = 6 * 1024;
1322
+ function encodePresentation(presentation) {
1323
+ const bytes = new TextEncoder().encode(JSON.stringify(presentation));
1324
+ let binary = "";
1325
+ for (const byte of bytes) binary += String.fromCharCode(byte);
1326
+ const encoded = btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1327
+ if (encoded.length > MAX_PRESENTATION_HEADER) {
1328
+ throw new DelopayError(
1329
+ `Export presentation is ${encoded.length} bytes encoded; the server reads at most ${MAX_PRESENTATION_HEADER}`,
1330
+ {
1331
+ status: 0,
1332
+ code: "EXPORT_PRESENTATION_TOO_LARGE",
1333
+ type: "invalid_request",
1334
+ data: { encoded_length: encoded.length, max_length: MAX_PRESENTATION_HEADER }
1335
+ }
1336
+ );
1337
+ }
1338
+ return encoded;
1339
+ }
1320
1340
  var LIST_ENVELOPE = { rows: "records", count: "record_count" };
1321
1341
  var WORKSPACE_ENVELOPE = { rows: "data", count: "total_count" };
1322
1342
  function parseRecordCount(header) {
@@ -1462,15 +1482,18 @@ var ACCEPT = {
1462
1482
  json: "application/json",
1463
1483
  pdf: "application/pdf"
1464
1484
  };
1465
- function negotiated(options, format) {
1485
+ function negotiated(options, format, presentation) {
1466
1486
  const headers = { ...options.headers, Accept: ACCEPT[format] };
1487
+ if (format === "pdf" && presentation !== void 0) {
1488
+ headers[PRESENTATION_HEADER] = encodePresentation(presentation);
1489
+ }
1467
1490
  return format === "json" ? { ...options, headers } : { ...options, headers, responseType: "blob" };
1468
1491
  }
1469
1492
  function runExport(request, method, path, base, options) {
1470
1493
  const format = options?.format ?? "json";
1471
1494
  return downloadExport(
1472
1495
  request,
1473
- { method, path, request: negotiated(base, format), format },
1496
+ { method, path, request: negotiated(base, format, options?.presentation), format },
1474
1497
  options
1475
1498
  );
1476
1499
  }
@@ -1503,24 +1526,15 @@ var Disputes = class {
1503
1526
  async workspaceAggregate(params) {
1504
1527
  return this.request("GET", "/disputes/workspace/aggregate", { query: workspaceQuery(params) });
1505
1528
  }
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
1529
  async workspaceExport(params, options) {
1530
+ const format = options?.format ?? "json";
1517
1531
  return downloadExport(
1518
1532
  this.request,
1519
1533
  {
1520
1534
  method: "GET",
1521
1535
  path: "/disputes/workspace/export",
1522
- request: { query: workspaceQuery(params) },
1523
- format: "json",
1536
+ request: negotiated({ query: workspaceQuery(params) }, format, options?.presentation),
1537
+ format,
1524
1538
  envelope: WORKSPACE_ENVELOPE
1525
1539
  },
1526
1540
  options