@cargo-ai/api 1.0.41 → 1.0.43
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/build/src/api/workspaceManagement/index.d.ts.map +1 -1
- package/build/src/api/workspaceManagement/index.js +19 -9
- package/build/src/fetcher/client.d.ts +30 -14
- package/build/src/fetcher/client.d.ts.map +1 -1
- package/build/src/fetcher/client.js +8 -7
- package/build/src/fetcher/error.d.ts +13 -2
- package/build/src/fetcher/error.d.ts.map +1 -1
- package/build/src/fetcher/error.js +15 -8
- package/build/src/fetcher/index.d.ts +6 -6
- package/build/src/fetcher/index.d.ts.map +1 -1
- package/build/src/fetcher/index.js +159 -132
- package/build/src/fetcher/params.d.ts +29 -0
- package/build/src/fetcher/params.d.ts.map +1 -0
- package/build/src/fetcher/params.js +98 -0
- package/build/src/fetcher/send.d.ts +29 -0
- package/build/src/fetcher/send.d.ts.map +1 -0
- package/build/src/fetcher/send.js +73 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/workspaceManagement/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/workspaceManagement/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAOtD,UAAU,kCAAkC;IAC1C,OAAO,EAAE,OAAO,CAAC;CAClB;AAaD,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE;QACT,GAAG,EAAE,CACH,OAAO,EAAE,mBAAmB,CAAC,GAAG,CAAC,oBAAoB,KAClD,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC1D,UAAU,EAAE,MAAM,OAAO,CAAC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CAAC;IACF,MAAM,EAAE;QACN,MAAM,EAAE,CACN,OAAO,EAAE,mBAAmB,CAAC,GAAG,CAAC,mBAAmB,KACjD,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;KAC1D,CAAC;IACF,OAAO,EAAE;QACP,MAAM,EAAE,CACN,OAAO,EAAE,mBAAmB,CAAC,GAAG,CAAC,oBAAoB,KAClD,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;KAC3D,CAAC;CACH;AAED,eAAO,MAAM,2BAA2B,iBAErC,kCAAkC,KAAG,sBAqqBvC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { WorkspaceManagement } from "../../domains/index.js";
|
|
3
2
|
import { getErrorWithReasonErrorMessage, zodFetcherUploadFileErrorReason, } from "../../fetcher/index.js";
|
|
3
|
+
import { sendWithProgress } from "../../fetcher/send.js";
|
|
4
4
|
// Files at/above this size are uploaded directly to S3 in parts, bypassing the
|
|
5
5
|
// API ingress (and its body-size / request-timeout limits). Smaller files keep
|
|
6
6
|
// the simpler single-request multipart/form-data path.
|
|
@@ -219,17 +219,27 @@ export const buildWorkspaceManagementApi = ({ fetcher, }) => {
|
|
|
219
219
|
uploadId,
|
|
220
220
|
partNumber,
|
|
221
221
|
});
|
|
222
|
-
//
|
|
223
|
-
// proxied Node environments (CLI, CI sandboxes). In
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
222
|
+
// Reuse the fetcher's transport (proxy-tunneling `fetch`) so S3
|
|
223
|
+
// PUTs work in proxied Node environments (CLI, CI sandboxes). In
|
|
224
|
+
// browsers `sendWithProgress` uses XHR for real upload progress;
|
|
225
|
+
// in Node it falls back to `fetch` (coarse per-part progress).
|
|
226
|
+
const response = await sendWithProgress({
|
|
227
|
+
method: "PUT",
|
|
228
|
+
url,
|
|
229
|
+
headers: {},
|
|
230
|
+
body: blob,
|
|
231
|
+
onProgress: (loaded) => {
|
|
232
|
+
loadedByPart[partIndex] = loaded;
|
|
228
233
|
reportProgress();
|
|
229
234
|
},
|
|
230
|
-
|
|
235
|
+
fetchImpl: fetcher.transport?.fetch !== undefined
|
|
236
|
+
? fetcher.transport.fetch
|
|
237
|
+
: (input, init) => fetch(input, init),
|
|
231
238
|
});
|
|
232
|
-
|
|
239
|
+
if (response.ok === false) {
|
|
240
|
+
throw new Error(`S3 part upload failed with status ${response.status}`);
|
|
241
|
+
}
|
|
242
|
+
const etag = response.getHeader("etag") ?? undefined;
|
|
233
243
|
if (etag === undefined) {
|
|
234
244
|
throw new Error("S3 did not return an ETag for the uploaded part (check bucket CORS ExposeHeaders)");
|
|
235
245
|
}
|
|
@@ -1,25 +1,41 @@
|
|
|
1
|
-
import type { AxiosInstance } from "axios";
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* A `fetch`-compatible transport. Matches the platform `fetch` signature so
|
|
3
|
+
* the global can be used directly, and so Node callers can inject a
|
|
4
|
+
* proxy-tunneling implementation (see the CLI's `getProxyFetch`, which wraps
|
|
5
|
+
* undici's `ProxyAgent`) — the global `fetch` does not honor `HTTPS_PROXY` /
|
|
6
|
+
* `HTTP_PROXY` on its own.
|
|
7
|
+
*/
|
|
8
|
+
export type FetchLike = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
9
|
+
/**
|
|
10
|
+
* Optional transport overrides for the underlying HTTP client.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* The client is `fetch`-based (edge/browser/Node all expose `fetch`), so the
|
|
13
|
+
* only override that matters now is `fetch` itself. Node callers behind an
|
|
14
|
+
* HTTP/HTTPS proxy pass a proxy-tunneling `fetch` here; browser and edge
|
|
15
|
+
* builds omit it and use the platform global.
|
|
13
16
|
*/
|
|
14
17
|
export type ClientTransport = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Override the `fetch` implementation used for every request. Defaults to
|
|
20
|
+
* the platform global when omitted. Node callers behind an HTTP/HTTPS proxy
|
|
21
|
+
* pass a proxy-tunneling `fetch` (undici `ProxyAgent`) here, since the global
|
|
22
|
+
* `fetch` does not honor proxy env vars.
|
|
23
|
+
*/
|
|
24
|
+
fetch?: FetchLike;
|
|
18
25
|
};
|
|
19
26
|
export type ClientDependencies = {
|
|
20
27
|
baseUrl: string;
|
|
21
28
|
transport?: ClientTransport;
|
|
22
29
|
};
|
|
23
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The resolved HTTP client: a base URL (with the `/v1` prefix already
|
|
32
|
+
* applied) and the `fetch` implementation to use.
|
|
33
|
+
*/
|
|
34
|
+
export type Client = {
|
|
35
|
+
/** Base URL including the `/v1` API prefix. */
|
|
36
|
+
baseUrl: string;
|
|
37
|
+
transport: ClientTransport | undefined;
|
|
38
|
+
fetchImpl: FetchLike;
|
|
39
|
+
};
|
|
24
40
|
export declare const buildClient: (dependencies: ClientDependencies) => Client;
|
|
25
41
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/fetcher/client.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/fetcher/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,GAAG,GAAG,EACnB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,eAAe,GAAG,SAAS,CAAC;IACvC,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,WAAW,iBAAkB,kBAAkB,KAAG,MAa9D,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
export const buildClient = (dependencies) => {
|
|
3
2
|
const { baseUrl, transport } = dependencies;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
const fetchImpl = transport?.fetch !== undefined
|
|
4
|
+
? transport.fetch
|
|
5
|
+
: (input, init) => fetch(input, init);
|
|
6
|
+
return {
|
|
7
|
+
baseUrl: `${baseUrl}/v1`,
|
|
8
|
+
transport,
|
|
9
|
+
fetchImpl,
|
|
10
|
+
};
|
|
10
11
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AxiosError } from "axios";
|
|
2
1
|
import type * as Zod from "zod";
|
|
3
2
|
type HttpStatus = number;
|
|
4
3
|
type HttpStatusText = string;
|
|
@@ -94,7 +93,19 @@ export declare class FetcherServerErrorClass<T> extends Error implements Fetcher
|
|
|
94
93
|
statusText: string;
|
|
95
94
|
};
|
|
96
95
|
}
|
|
97
|
-
|
|
96
|
+
/**
|
|
97
|
+
* A transport-agnostic view of a failed request, built by the fetcher from a
|
|
98
|
+
* `fetch` `Response` (or from a thrown network error, in which case `status`
|
|
99
|
+
* is `undefined`). Replaces the previous `AxiosError` input so the error
|
|
100
|
+
* layer no longer depends on Axios.
|
|
101
|
+
*/
|
|
102
|
+
export type FetcherErrorInput<T> = {
|
|
103
|
+
status?: number;
|
|
104
|
+
statusText?: string;
|
|
105
|
+
data?: T;
|
|
106
|
+
originalError?: Error;
|
|
107
|
+
};
|
|
108
|
+
export declare const fromFetcherError: <T>(input: FetcherErrorInput<T>) => Promise<FetcherError<T>>;
|
|
98
109
|
export declare const determineIfIsFetcherError: (error: unknown) => error is FetcherError<any>;
|
|
99
110
|
export declare const getErrorWithReasonErrorMessage: <Output extends string>(error: unknown, zodSchema: Zod.ZodType<Output, unknown, Zod.z.core.$ZodTypeInternals<Output, unknown>>, errorMessages: Record<Output, string | ((data: Record<string, unknown>) => string | undefined) | undefined>) => unknown;
|
|
100
111
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/fetcher/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/fetcher/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,KAAK,CAAC;AAEhC,KAAK,UAAU,GAAG,MAAM,CAAC;AACzB,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,UAAU,gBAAiB,SAAQ,KAAK;IACtC,aAAa,CAAC,EAAE,KAAK,CAAC;IAEtB,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB,CAAC,CAAC,CAAE,SAAQ,gBAAgB;IACpE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,gBAAgB;IAC9D,IAAI,EAAE,cAAc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{
|
|
|
40
40
|
data;
|
|
41
41
|
constructor(status, statusText, data, originalError) {
|
|
42
42
|
super("API request failure: Authorization error");
|
|
43
|
-
Object.setPrototypeOf(this,
|
|
43
|
+
Object.setPrototypeOf(this, FetcherAuthorizationErrorClass.prototype);
|
|
44
44
|
if (Error.captureStackTrace) {
|
|
45
|
-
Error.captureStackTrace(this,
|
|
45
|
+
Error.captureStackTrace(this, FetcherAuthorizationErrorClass);
|
|
46
46
|
}
|
|
47
47
|
const errorMessage = data.errorMessage;
|
|
48
48
|
const reason = data.reason;
|
|
@@ -134,17 +134,24 @@ export class FetcherServerErrorClass extends Error {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
export const fromFetcherError = async (
|
|
138
|
-
const errorType = getFetcherErrorTypeFromStatus(
|
|
137
|
+
export const fromFetcherError = async (input) => {
|
|
138
|
+
const errorType = getFetcherErrorTypeFromStatus(input.status);
|
|
139
|
+
const originalError = input.originalError;
|
|
140
|
+
const statusText = input.statusText !== undefined ? input.statusText : "";
|
|
141
|
+
// Empty error bodies parse to `undefined` (e.g. a bare 401/429/502). The
|
|
142
|
+
// error constructors read `.errorMessage`/`.reason` off this, so default to
|
|
143
|
+
// `{}` to avoid a TypeError. (Axios handed over `''` here, which was also
|
|
144
|
+
// safe to property-access.)
|
|
145
|
+
const data = (input.data !== undefined && input.data !== null ? input.data : {});
|
|
139
146
|
switch (errorType) {
|
|
140
147
|
case "NetworkError":
|
|
141
|
-
return new FetcherNetworkErrorClass(
|
|
148
|
+
return new FetcherNetworkErrorClass(originalError);
|
|
142
149
|
case "AuthorizationError":
|
|
143
|
-
return new FetcherAuthorizationErrorClass(
|
|
150
|
+
return new FetcherAuthorizationErrorClass(input.status, statusText, data, originalError);
|
|
144
151
|
case "RequestError":
|
|
145
|
-
return new FetcherRequestErrorClass(
|
|
152
|
+
return new FetcherRequestErrorClass(input.status, statusText, data, originalError);
|
|
146
153
|
default:
|
|
147
|
-
return new FetcherServerErrorClass(
|
|
154
|
+
return new FetcherServerErrorClass(input.status, statusText, data, originalError);
|
|
148
155
|
}
|
|
149
156
|
};
|
|
150
157
|
export const determineIfIsFetcherError = (error) => {
|
|
@@ -15,8 +15,8 @@ export type FetcherDependencies = {
|
|
|
15
15
|
accessToken?: string;
|
|
16
16
|
origin?: FetcherOrigin;
|
|
17
17
|
/**
|
|
18
|
-
* Optional transport overrides forwarded to the
|
|
19
|
-
* proxy-tunneling
|
|
18
|
+
* Optional transport overrides forwarded to the HTTP client, e.g. a
|
|
19
|
+
* proxy-tunneling `fetch` supplied by Node callers behind a proxy.
|
|
20
20
|
*/
|
|
21
21
|
transport?: ClientTransport;
|
|
22
22
|
};
|
|
@@ -44,10 +44,10 @@ export type FetcherBlobRequest = {
|
|
|
44
44
|
export type Fetcher = {
|
|
45
45
|
baseUrl: string;
|
|
46
46
|
/**
|
|
47
|
-
* Transport config (proxy
|
|
48
|
-
* Exposed so consumers (e.g. workspaceManagement multipart uploads)
|
|
49
|
-
*
|
|
50
|
-
*
|
|
47
|
+
* Transport config (e.g. a proxy-tunneling `fetch`) passed at build time.
|
|
48
|
+
* Exposed so consumers (e.g. workspaceManagement multipart uploads) reuse
|
|
49
|
+
* the same transport for their own requests to third-party hosts (S3
|
|
50
|
+
* presigned URLs). Undefined in browser builds.
|
|
51
51
|
*/
|
|
52
52
|
transport: ClientTransport | undefined;
|
|
53
53
|
uploadFile: (url: string, { formData, onProgress, onComplete, onError }: FetcherUploadFilePayload) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fetcher/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fetcher/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,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;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,SAAS,EAAE,eAAe,GAAG,SAAS,CAAC;IACvC,UAAU,EAAE,CACV,GAAG,EAAE,MAAM,EACX,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,wBAAwB,KACpE,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,KAAK,CAAC,OAAO,EACX,OAAO,EAAE,cAAc,GAAG;QAAE,sBAAsB,EAAE,KAAK,CAAA;KAAE,GAC1D,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,KAAK,CAAC,OAAO,EACX,OAAO,EAAE,cAAc,GAAG;QAAE,sBAAsB,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;KAAE,GACtE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7B;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D,CAAC;AAiCF,eAAO,MAAM,YAAY,iBAAkB,mBAAmB,KAAG,OAwOhE,CAAC"}
|
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
import { nullToUndefined } from "@cargo-ai/utils";
|
|
2
|
-
import axios from "axios";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import { buildClient } from "./client.js";
|
|
5
|
-
import { fromFetcherError } from "./error.js";
|
|
4
|
+
import { determineIfIsFetcherError, fromFetcherError } from "./error.js";
|
|
5
|
+
import { combineUrl, serializeParams } from "./params.js";
|
|
6
|
+
import { sendWithProgress } from "./send.js";
|
|
6
7
|
export { determineIfIsFetcherError, FetcherRequestErrorClass, getErrorWithReasonErrorMessage, } from "./error.js";
|
|
8
|
+
// Same total budget as the previous Axios client (`timeout: 360 * 1000`);
|
|
9
|
+
// enforced here with an AbortController since `fetch` has no timeout option.
|
|
10
|
+
const REQUEST_TIMEOUT_MS = 360 * 1000;
|
|
7
11
|
export const zodFetcherUploadFileErrorReason = z.enum(["noFile"]);
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
};
|
|
19
|
-
const reshapeBlobErrorAsJson = async (axiosError) => {
|
|
20
|
-
const response = axiosError.response;
|
|
21
|
-
const contentType = response?.headers?.["content-type"];
|
|
22
|
-
if (typeof contentType !== "string" ||
|
|
23
|
-
contentType.includes("application/json") === false) {
|
|
24
|
-
return axiosError;
|
|
25
|
-
}
|
|
26
|
-
const text = await binaryBodyText(response?.data);
|
|
27
|
-
if (text === undefined) {
|
|
28
|
-
return axiosError;
|
|
12
|
+
// Parse a response body as JSON when possible, matching Axios' auto-JSON
|
|
13
|
+
// behavior. Falls back to the raw text (or `undefined` for empty bodies) so
|
|
14
|
+
// callers and the error normalizer always get *something* usable.
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
const parseResponseBody = async (response) => {
|
|
17
|
+
const text = await response.text();
|
|
18
|
+
if (text.length === 0) {
|
|
19
|
+
return undefined;
|
|
29
20
|
}
|
|
30
21
|
try {
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
...axiosError,
|
|
34
|
-
response: { ...response, data: parsed },
|
|
35
|
-
};
|
|
22
|
+
return JSON.parse(text);
|
|
36
23
|
}
|
|
37
24
|
catch {
|
|
38
|
-
return
|
|
25
|
+
return text;
|
|
39
26
|
}
|
|
40
27
|
};
|
|
28
|
+
// Build a header bag, dropping `undefined` values (Axios omitted them; the
|
|
29
|
+
// `fetch` `Headers` object would otherwise stringify them to `"undefined"`).
|
|
30
|
+
const buildHeaders = (entries) => {
|
|
31
|
+
const headers = {};
|
|
32
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
33
|
+
if (value !== undefined) {
|
|
34
|
+
headers[key] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return headers;
|
|
38
|
+
};
|
|
41
39
|
export const buildFetcher = (dependencies) => {
|
|
42
40
|
const { baseUrl, workspaceUuid, appUuid, getAccessToken, accessToken: initialAccessToken, origin, transport, } = dependencies;
|
|
43
41
|
const client = buildClient({ baseUrl, transport });
|
|
@@ -48,128 +46,157 @@ export const buildFetcher = (dependencies) => {
|
|
|
48
46
|
}
|
|
49
47
|
: {};
|
|
50
48
|
const appHeaders = appUuid !== undefined ? { "x-cargo-app-uuid": appUuid } : {};
|
|
51
|
-
const
|
|
52
|
-
const { endpoint, method, params, payload, forceTokenRefresh = false, replaceNullByUndefined = true, withoutWorkspace = false, } = request;
|
|
53
|
-
const source = axios.CancelToken.source();
|
|
54
|
-
let accessToken = initialAccessToken;
|
|
49
|
+
const resolveAccessToken = async (forceTokenRefresh) => {
|
|
55
50
|
if (getAccessToken !== undefined) {
|
|
56
|
-
|
|
51
|
+
return getAccessToken(forceTokenRefresh);
|
|
57
52
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
53
|
+
return initialAccessToken;
|
|
54
|
+
};
|
|
55
|
+
const workspaceHeaderFor = (withoutWorkspace) => workspaceUuid !== undefined && withoutWorkspace === false
|
|
56
|
+
? { "selected-workspace-uuid": workspaceUuid }
|
|
57
|
+
: {};
|
|
58
|
+
const authHeaders = (accessToken, withoutWorkspace) => buildHeaders({
|
|
59
|
+
authorization: accessToken !== undefined ? `Bearer ${accessToken}` : undefined,
|
|
60
|
+
...workspaceHeaderFor(withoutWorkspace),
|
|
61
|
+
...originHeaders,
|
|
62
|
+
...appHeaders,
|
|
63
|
+
});
|
|
64
|
+
const fetcherFetch = async (request) => {
|
|
65
|
+
const { endpoint, method, params, payload, forceTokenRefresh = false, replaceNullByUndefined = true, withoutWorkspace = false, } = request;
|
|
66
|
+
const accessToken = await resolveAccessToken(forceTokenRefresh);
|
|
67
|
+
const url = `${combineUrl(client.baseUrl, endpoint)}${serializeParams(params)}`;
|
|
68
|
+
const hasBody = payload !== undefined && method !== "get";
|
|
69
|
+
const headers = authHeaders(accessToken, withoutWorkspace);
|
|
70
|
+
if (hasBody) {
|
|
71
|
+
headers["content-type"] = "application/json";
|
|
72
|
+
}
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
75
|
+
// The timeout must cover the whole exchange including body download (Axios'
|
|
76
|
+
// `timeout` did), so keep it armed until the body is read and only clear it
|
|
77
|
+
// in the `finally`. A network failure, or an abort while reading the body,
|
|
78
|
+
// both surface as a NetworkError (no HTTP status).
|
|
79
|
+
let response;
|
|
75
80
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
let data;
|
|
82
|
+
try {
|
|
83
|
+
response = await client.fetchImpl(url, {
|
|
84
|
+
method: method.toUpperCase(),
|
|
85
|
+
headers,
|
|
86
|
+
body: hasBody ? JSON.stringify(payload) : undefined,
|
|
87
|
+
signal: controller.signal,
|
|
88
|
+
});
|
|
89
|
+
data = await parseResponseBody(response);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
throw await fromFetcherError({
|
|
93
|
+
status: 0,
|
|
94
|
+
originalError: error instanceof Error ? error : undefined,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
clearTimeout(timeout);
|
|
99
|
+
}
|
|
100
|
+
if (response.ok === false) {
|
|
101
|
+
throw await fromFetcherError({
|
|
102
|
+
status: response.status,
|
|
103
|
+
statusText: response.statusText,
|
|
104
|
+
data,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (replaceNullByUndefined === true) {
|
|
108
|
+
return nullToUndefined(data);
|
|
109
|
+
}
|
|
110
|
+
return data;
|
|
87
111
|
};
|
|
88
112
|
const uploadFile = async (url, payload) => {
|
|
89
113
|
const { formData, onProgress, onComplete, onError } = payload;
|
|
90
|
-
// Mirror the fetch path:
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
.then(({ data }) => {
|
|
114
|
+
// Mirror the fetch path: static token, overridden by the refreshing getter
|
|
115
|
+
// when present (a caller passing a static accessToken — e.g. the CLI —
|
|
116
|
+
// must still send an auth header).
|
|
117
|
+
const accessToken = await resolveAccessToken(false);
|
|
118
|
+
// Do NOT set content-type: the transport sets the multipart boundary.
|
|
119
|
+
const headers = authHeaders(accessToken, false);
|
|
120
|
+
try {
|
|
121
|
+
const response = await sendWithProgress({
|
|
122
|
+
method: "POST",
|
|
123
|
+
url: combineUrl(client.baseUrl, url),
|
|
124
|
+
headers,
|
|
125
|
+
body: formData,
|
|
126
|
+
onProgress: (loaded, total) => {
|
|
127
|
+
onProgress(total > 0 ? Math.round((100 * loaded) / total) : 0);
|
|
128
|
+
},
|
|
129
|
+
fetchImpl: client.fetchImpl,
|
|
130
|
+
});
|
|
131
|
+
if (response.ok === false) {
|
|
132
|
+
onError();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const text = await response.text();
|
|
136
|
+
const data = text.length > 0 ? JSON.parse(text) : {};
|
|
115
137
|
// The content upload endpoint responds `{ files: [file] }`; other upload
|
|
116
|
-
// endpoints respond with the file fields flat. Handle both
|
|
117
|
-
|
|
118
|
-
const file =
|
|
138
|
+
// endpoints respond with the file fields flat. Handle both.
|
|
139
|
+
const firstFile = data.files !== undefined ? data.files[0] : undefined;
|
|
140
|
+
const file = firstFile !== undefined ? firstFile : data;
|
|
119
141
|
onComplete({
|
|
120
|
-
uuid: file
|
|
121
|
-
s3Filename: file
|
|
122
|
-
contentType: file
|
|
123
|
-
name: file
|
|
142
|
+
uuid: file.uuid,
|
|
143
|
+
s3Filename: file.s3Filename !== undefined ? file.s3Filename : "",
|
|
144
|
+
contentType: file.contentType !== undefined ? file.contentType : "",
|
|
145
|
+
name: file.name !== undefined ? file.name : "",
|
|
124
146
|
});
|
|
125
|
-
}
|
|
126
|
-
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
127
149
|
onError();
|
|
128
|
-
}
|
|
150
|
+
}
|
|
129
151
|
};
|
|
130
152
|
const fetchBlob = async (request) => {
|
|
131
153
|
const { endpoint, params, forceTokenRefresh = false, withoutWorkspace = false, } = request;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
154
|
+
const accessToken = await resolveAccessToken(forceTokenRefresh);
|
|
155
|
+
const url = `${combineUrl(client.baseUrl, endpoint)}${serializeParams(params)}`;
|
|
156
|
+
const headers = authHeaders(accessToken, withoutWorkspace);
|
|
157
|
+
const controller = new AbortController();
|
|
158
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
159
|
+
// Keep the timeout armed until the body (`.blob()` / error body) is fully
|
|
160
|
+
// read, matching Axios' whole-response timeout. `.blob()` and the error
|
|
161
|
+
// parse both run inside the try so an abort mid-download is normalized.
|
|
162
|
+
try {
|
|
163
|
+
const response = await client.fetchImpl(url, {
|
|
164
|
+
method: "GET",
|
|
165
|
+
headers,
|
|
166
|
+
signal: controller.signal,
|
|
167
|
+
});
|
|
168
|
+
if (response.ok === false) {
|
|
169
|
+
// `fetch` hands us the error body directly (no Axios blob/arraybuffer
|
|
170
|
+
// dance), so parse it as JSON when present for the typed error shape.
|
|
171
|
+
const data = await parseResponseBody(response);
|
|
172
|
+
throw await fromFetcherError({
|
|
173
|
+
status: response.status,
|
|
174
|
+
statusText: response.statusText,
|
|
175
|
+
data,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return await response.blob();
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
// Re-throw an already-normalized FetcherError (the non-ok branch above);
|
|
182
|
+
// wrap anything else (network failure / abort) as a NetworkError.
|
|
183
|
+
if (determineIfIsFetcherError(error)) {
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
throw await fromFetcherError({
|
|
187
|
+
status: 0,
|
|
188
|
+
originalError: error instanceof Error ? error : undefined,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
clearTimeout(timeout);
|
|
135
193
|
}
|
|
136
|
-
const workspaceHeaders = workspaceUuid !== undefined && withoutWorkspace === false
|
|
137
|
-
? { "selected-workspace-uuid": workspaceUuid }
|
|
138
|
-
: {};
|
|
139
|
-
// axios' Node http adapter has no "blob" responseType (it silently decodes
|
|
140
|
-
// the body as utf-8 text, corrupting binary content) — request an
|
|
141
|
-
// arraybuffer there and wrap it in a Blob so every caller keeps one contract.
|
|
142
|
-
const isBrowser = typeof window !== "undefined";
|
|
143
|
-
return client
|
|
144
|
-
.get(endpoint, {
|
|
145
|
-
params,
|
|
146
|
-
responseType: isBrowser ? "blob" : "arraybuffer",
|
|
147
|
-
headers: {
|
|
148
|
-
authorization: accessToken !== undefined ? `Bearer ${accessToken}` : undefined,
|
|
149
|
-
...workspaceHeaders,
|
|
150
|
-
...originHeaders,
|
|
151
|
-
...appHeaders,
|
|
152
|
-
},
|
|
153
|
-
})
|
|
154
|
-
.then((response) => isBrowser
|
|
155
|
-
? response.data
|
|
156
|
-
: new Blob([response.data]))
|
|
157
|
-
.catch(async (axiosError) => {
|
|
158
|
-
// Axios returns the server's error body as a Blob when
|
|
159
|
-
// `responseType: "blob"` is set, which means our standard
|
|
160
|
-
// `fromFetcherError` path can't see the structured `reason` /
|
|
161
|
-
// `errorMessage` fields. Re-hydrate the body as JSON when the
|
|
162
|
-
// server flagged it that way so callers get the same typed
|
|
163
|
-
// error shape they'd get from `fetch`.
|
|
164
|
-
const reshaped = await reshapeBlobErrorAsJson(axiosError);
|
|
165
|
-
throw await fromFetcherError(reshaped);
|
|
166
|
-
});
|
|
167
194
|
};
|
|
168
195
|
return {
|
|
169
196
|
baseUrl,
|
|
170
197
|
transport,
|
|
171
198
|
uploadFile,
|
|
172
|
-
fetch:
|
|
199
|
+
fetch: fetcherFetch,
|
|
173
200
|
fetchBlob,
|
|
174
201
|
};
|
|
175
202
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a query-params object into a `?a=1&b=2` string, matching Axios'
|
|
3
|
+
* default `paramsSerializer` so the backend keeps receiving the exact same
|
|
4
|
+
* wire format it did under the Axios client. The notable Axios conventions
|
|
5
|
+
* reproduced here:
|
|
6
|
+
*
|
|
7
|
+
* - `null` / `undefined` values are omitted.
|
|
8
|
+
* - A top-level array uses the bracket form: `ids=[1,2]` → `ids[]=1&ids[]=2`.
|
|
9
|
+
* - Arrays nested inside an object are indexed:
|
|
10
|
+
* `filter={tags:[a,b]}` → `filter[tags][0]=a&filter[tags][1]=b`.
|
|
11
|
+
* - Nested objects use bracket paths: `filter={x:1}` → `filter[x]=1`.
|
|
12
|
+
*
|
|
13
|
+
* Encoding matches Axios' `AxiosURLSearchParams` byte-for-byte: `encodeURIComponent`
|
|
14
|
+
* then un-escape the characters Axios leaves literal (`:`, `$`, `,`) and render
|
|
15
|
+
* space as `+`. Brackets stay percent-encoded (`%5B`/`%5D`), as Axios does for
|
|
16
|
+
* object/array params. (Plain `URLSearchParams` diverges here — it encodes `:`
|
|
17
|
+
* and `,` — so we encode by hand.)
|
|
18
|
+
*/
|
|
19
|
+
export declare const serializeParams: (params?: Record<string, any>) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Join a base URL and an endpoint the way Axios' `combineURLs` did: exactly one
|
|
22
|
+
* slash between them regardless of whether the endpoint has a leading slash.
|
|
23
|
+
* Most endpoints are relative (`connection/connectors`), a few are rooted
|
|
24
|
+
* (`/initWorkspace`) — both must yield `…/v1/<endpoint>`. Naive concatenation
|
|
25
|
+
* produced `…/v1connection/...`. Absolute endpoints pass through untouched,
|
|
26
|
+
* matching Axios.
|
|
27
|
+
*/
|
|
28
|
+
export declare const combineUrl: (baseUrl: string, endpoint: string) => string;
|
|
29
|
+
//# sourceMappingURL=params.d.ts.map
|