@getanyapi/sdk 0.9.6 → 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 +18 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -6
- package/dist/index.d.ts +58 -6
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
/**
|
|
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
|
|
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
|
|
863
|
+
const requestId = requestIdOf(response.headers);
|
|
853
864
|
if (response.status === 200) {
|
|
854
865
|
const text = await response.text();
|
|
855
866
|
try {
|
|
@@ -887,8 +898,12 @@ var AnyAPI = class {
|
|
|
887
898
|
};
|
|
888
899
|
|
|
889
900
|
// src/core/types.ts
|
|
901
|
+
var OUTPUT_NOT_RETAINED = "the run output was not retained: this response is an idempotent replay whose stored payload has expired or was too large to store, so only the run metadata came back. Re-run the request without the idempotency key (or with a fresh one) to fetch the data again.";
|
|
890
902
|
function unwrap(result) {
|
|
891
903
|
const output = result.output;
|
|
904
|
+
if (output === null || output === void 0) {
|
|
905
|
+
throw new AnyAPIError(OUTPUT_NOT_RETAINED, 200);
|
|
906
|
+
}
|
|
892
907
|
if (output !== null && typeof output === "object" && "found" in output) {
|
|
893
908
|
const env = output;
|
|
894
909
|
if (env.found) {
|