@getanyapi/sdk 0.9.7 → 0.9.8

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.cjs CHANGED
@@ -101,7 +101,10 @@ module.exports = __toCommonJS(index_exports);
101
101
  var AnyAPIError = class extends Error {
102
102
  /** HTTP status code, or 0 for transport-level failures (connection/timeout). */
103
103
  status;
104
- /** The x-request-id response header when present, else undefined. */
104
+ /**
105
+ * The gateway's X-Anyapi-Request-Id response header when present (falling back to a
106
+ * proxy-set x-request-id), else undefined. Quote it to AnyAPI support.
107
+ */
105
108
  requestId;
106
109
  /** Stable gateway error code when the JSON body includes one, else undefined. */
107
110
  code;
@@ -136,6 +139,14 @@ var ConnectionError = class extends AnyAPIError {
136
139
  };
137
140
  var TimeoutError = class extends AnyAPIError {
138
141
  };
142
+ var REQUEST_ID_HEADERS = ["x-anyapi-request-id", "x-request-id"];
143
+ function requestIdOf(headers) {
144
+ for (const name of REQUEST_ID_HEADERS) {
145
+ const value = headers.get(name);
146
+ if (value) return value;
147
+ }
148
+ return void 0;
149
+ }
139
150
  function errorFromStatus(status, message, requestId, code) {
140
151
  switch (status) {
141
152
  case 400:
@@ -506,7 +517,7 @@ async function agentSignup(options = {}) {
506
517
  0
507
518
  );
508
519
  }
509
- const requestId = response.headers.get("x-request-id") ?? void 0;
520
+ const requestId = requestIdOf(response.headers);
510
521
  const text = await response.text().catch(() => "");
511
522
  if (response.status !== 200) {
512
523
  let message = `request failed with status ${response.status}`;
@@ -849,7 +860,7 @@ var AnyAPI = class {
849
860
  }
850
861
  throw connErr;
851
862
  }
852
- const requestId = response.headers.get("x-request-id") ?? void 0;
863
+ const requestId = requestIdOf(response.headers);
853
864
  if (response.status === 200) {
854
865
  const text = await response.text();
855
866
  try {