@mitumba/sdk 5.14.0 → 5.15.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/index.mjs CHANGED
@@ -279,6 +279,17 @@ var APIClient = class {
279
279
  }
280
280
  }
281
281
  async request(method, path, body, params, options) {
282
+ const response = await this.send(method, path, body, params, options);
283
+ if (response.status === 204) {
284
+ return void 0;
285
+ }
286
+ return response.json();
287
+ }
288
+ /**
289
+ * One request with authentication, proactive and reactive token refresh, retries and error decoding.
290
+ * Resolves with the successful response, unread, so the caller chooses how to read its body.
291
+ */
292
+ async send(method, path, body, params, options) {
282
293
  if (!isSessionEndpoint(path)) {
283
294
  await this.ensureFreshToken(options);
284
295
  }
@@ -368,10 +379,7 @@ var APIClient = class {
368
379
  }
369
380
  throw new APIError(response.status, normalizeAPIErrorResponse(decoded, response.statusText));
370
381
  }
371
- if (response.status === 204) {
372
- return void 0;
373
- }
374
- return response.json();
382
+ return response;
375
383
  }
376
384
  async handleTokenRefresh(signal) {
377
385
  if (this.isRefreshing && this.refreshPromise) {
@@ -423,6 +431,18 @@ var APIClient = class {
423
431
  get(path, params, options) {
424
432
  return this.request("GET", path, void 0, params, options);
425
433
  }
434
+ /**
435
+ * A GET whose response is a file (a PDF, an image) rather than JSON. Authentication, refresh,
436
+ * retries and errors are exactly those of {@link get}; an error response still decodes its JSON body.
437
+ */
438
+ async getFile(path, params, options) {
439
+ const response = await this.send("GET", path, void 0, params, options);
440
+ return {
441
+ blob: await response.blob(),
442
+ contentType: response.headers.get("Content-Type") ?? "application/octet-stream",
443
+ headers: response.headers
444
+ };
445
+ }
426
446
  post(path, body, options) {
427
447
  return this.request("POST", path, body, void 0, options);
428
448
  }
@@ -1089,6 +1109,18 @@ var SearchModule = class {
1089
1109
  };
1090
1110
 
1091
1111
  // src/modules/orders.ts
1112
+ function dispositionFilename(header) {
1113
+ if (!header) return null;
1114
+ const extended = /filename\*\s*=\s*(?:UTF-8|utf-8)''([^;]+)/.exec(header);
1115
+ if (extended?.[1]) {
1116
+ try {
1117
+ return decodeURIComponent(extended[1].trim());
1118
+ } catch {
1119
+ }
1120
+ }
1121
+ const plain = /filename\s*=\s*"?([^";]+)"?/.exec(header);
1122
+ return plain?.[1]?.trim() || null;
1123
+ }
1092
1124
  var OrdersModule = class {
1093
1125
  constructor(client) {
1094
1126
  this.client = client;
@@ -1111,6 +1143,21 @@ var OrdersModule = class {
1111
1143
  async transition(id, input, options) {
1112
1144
  return this.client.post(`/orders/${id}/transition`, input, options);
1113
1145
  }
1146
+ /**
1147
+ * Get an order's invoice or receipt as a PDF: its receipt once it is paid, its invoice while it awaits
1148
+ * payment. Buyer only. Every order of one checkout returns the same document.
1149
+ *
1150
+ * Errors: 404 document_not_found when the order has no document to show.
1151
+ */
1152
+ async getDocument(id, options) {
1153
+ const file = await this.client.getFile(`/orders/${encodeURIComponent(id)}/document`, void 0, options);
1154
+ const kind = file.headers.get("X-Mitumba-Document") === "receipt" ? "receipt" : "invoice";
1155
+ return {
1156
+ kind,
1157
+ filename: dispositionFilename(file.headers.get("Content-Disposition")) ?? `Mitumba-${id}.pdf`,
1158
+ blob: file.blob
1159
+ };
1160
+ }
1114
1161
  /**
1115
1162
  * Get the order history for the current authenticated user.
1116
1163
  */