@xemahq/authorization-internal-api-client 0.9.0 → 0.9.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.
@@ -463,6 +463,37 @@ function isJsonMediaType(contentType) {
463
463
  const essence = contentType.split(';')[0]?.trim().toLowerCase() ?? '';
464
464
  return essence === 'application/json' || essence.endsWith('+json');
465
465
  }
466
+ /**
467
+ * Does this media type carry TEXT a caller reads as a string?
468
+ *
469
+ * The response body is decoded by its declared media type, in three classes,
470
+ * and each class matches what the generated function's return type says for
471
+ * the schema such a route declares:
472
+ *
473
+ * - JSON (`application/json` or an RFC 6839 `+json` suffix) → parsed;
474
+ * - TEXT (`text/*` — including `text/event-stream` — `application/javascript`,
475
+ * `application/ecmascript`, `application/xml` or an RFC 7303 `+xml`
476
+ * suffix) → a string, which is what a `{ type: string }` schema generates;
477
+ * - anything else — `application/octet-stream`, `application/gzip`,
478
+ * `application/pdf`, an Office document type, any `format: binary` body —
479
+ * → a `Blob`, which is what a `format: binary` schema generates.
480
+ *
481
+ * Reading every non-JSON body as text, as this transport did until 2026-10-04,
482
+ * handed a caller typed `Blob` a string: `response.text()` decodes the bytes
483
+ * as UTF-8, so a PDF or a gzip tarball arrived corrupted under a type that
484
+ * promised the bytes.
485
+ *
486
+ * A response with NO content type is read as text, so an empty body stays the
487
+ * empty string it always was.
488
+ */
489
+ function isTextMediaType(contentType) {
490
+ const essence = contentType.split(';')[0]?.trim().toLowerCase() ?? '';
491
+ return (essence.startsWith('text/') ||
492
+ essence === 'application/javascript' ||
493
+ essence === 'application/ecmascript' ||
494
+ essence === 'application/xml' ||
495
+ essence.endsWith('+xml'));
496
+ }
466
497
  async function parseBody(response) {
467
498
  // 204 FIRST, and deliberately — this ORDER is carried from `develop`, which
468
499
  // fixed the same defect independently and got this half right where `main`
@@ -478,7 +509,10 @@ async function parseBody(response) {
478
509
  if (isJsonMediaType(contentType)) {
479
510
  return response.json();
480
511
  }
481
- return response.text();
512
+ if (contentType === null || isTextMediaType(contentType)) {
513
+ return response.text();
514
+ }
515
+ return response.blob();
482
516
  }
483
517
  function parseRetryAfter(value) {
484
518
  if (!value)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/authorization-internal-api-client",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "service": "authorization-api",
20
20
  "biome": "authorization",
21
21
  "target": "server",
22
- "generator": "@xemahq/api-client-generator@2.1.1",
22
+ "generator": "@xemahq/api-client-generator@2.2.0",
23
23
  "source": "openapi.internal.json"
24
24
  },
25
25
  "license": "LicenseRef-Xema-BSL-1.1",