@seedcli/http 0.1.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/LICENSE +21 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +176 -0
- package/dist/client.js.map +1 -0
- package/dist/download.d.ts +3 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +47 -0
- package/dist/download.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +5 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +15 -0
- package/dist/openapi.js.map +1 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Seed CLI Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ClientConfig, HttpClient, HttpResponse, RequestOptions } from "./types.js";
|
|
2
|
+
export declare function get<T = unknown>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
3
|
+
export declare function post<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
4
|
+
export declare function put<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
5
|
+
export declare function patch<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
6
|
+
export declare function del<T = unknown>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
7
|
+
export declare function head(url: string, options?: RequestOptions): Promise<HttpResponse<void>>;
|
|
8
|
+
export declare function create(config: ClientConfig): HttpClient;
|
|
9
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EAEd,MAAM,YAAY,CAAC;AAqMpB,wBAAsB,GAAG,CAAC,CAAC,GAAG,OAAO,EACpC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED,wBAAsB,IAAI,CAAC,CAAC,GAAG,OAAO,EACrC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED,wBAAsB,GAAG,CAAC,CAAC,GAAG,OAAO,EACpC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED,wBAAsB,KAAK,CAAC,CAAC,GAAG,OAAO,EACtC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAGD,wBAAsB,GAAG,CAAC,CAAC,GAAG,OAAO,EACpC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAE7F;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAEvD"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { HttpError, HttpTimeoutError } from "./errors.js";
|
|
2
|
+
const DEFAULT_RETRY_ON = [408, 429, 500, 502, 503, 504];
|
|
3
|
+
function normalizeRetry(retry) {
|
|
4
|
+
if (retry === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
if (typeof retry === "number") {
|
|
7
|
+
return { count: retry, delay: 1000 };
|
|
8
|
+
}
|
|
9
|
+
return retry;
|
|
10
|
+
}
|
|
11
|
+
function serializeParams(params) {
|
|
12
|
+
const entries = Object.entries(params).filter(([, v]) => v !== undefined);
|
|
13
|
+
if (entries.length === 0)
|
|
14
|
+
return "";
|
|
15
|
+
const searchParams = new URLSearchParams();
|
|
16
|
+
for (const [key, value] of entries) {
|
|
17
|
+
searchParams.set(key, String(value));
|
|
18
|
+
}
|
|
19
|
+
return `?${searchParams.toString()}`;
|
|
20
|
+
}
|
|
21
|
+
async function fetchWithTimeout(url, init, timeout) {
|
|
22
|
+
if (!timeout)
|
|
23
|
+
return fetch(url, init);
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const existingSignal = init.signal;
|
|
26
|
+
if (existingSignal) {
|
|
27
|
+
existingSignal.addEventListener("abort", () => controller.abort(existingSignal.reason));
|
|
28
|
+
}
|
|
29
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof DOMException && err.name === "AbortError" && !existingSignal?.aborted) {
|
|
36
|
+
throw new HttpTimeoutError(url, timeout);
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function fetchWithRetry(url, init, timeout, retry) {
|
|
45
|
+
if (!retry || retry.count <= 0) {
|
|
46
|
+
return fetchWithTimeout(url, init, timeout);
|
|
47
|
+
}
|
|
48
|
+
const { count, delay, backoff = "exponential", retryOn = DEFAULT_RETRY_ON, onRetry } = retry;
|
|
49
|
+
let lastError;
|
|
50
|
+
for (let attempt = 0; attempt <= count; attempt++) {
|
|
51
|
+
try {
|
|
52
|
+
const response = await fetchWithTimeout(url, init, timeout);
|
|
53
|
+
// Check if we should retry based on status code
|
|
54
|
+
if (!response.ok && attempt < count && retryOn.includes(response.status)) {
|
|
55
|
+
onRetry?.(new HttpError(response.status, response.statusText), attempt + 1);
|
|
56
|
+
const waitTime = backoff === "linear" ? delay * (attempt + 1) : delay * 2 ** attempt;
|
|
57
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
64
|
+
if (attempt < count) {
|
|
65
|
+
onRetry?.(lastError, attempt + 1);
|
|
66
|
+
const waitTime = backoff === "linear" ? delay * (attempt + 1) : delay * 2 ** attempt;
|
|
67
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw lastError;
|
|
72
|
+
}
|
|
73
|
+
function buildURL(base, path, params) {
|
|
74
|
+
let url = base ? `${base.replace(/\/$/, "")}/${path.replace(/^\//, "")}` : path;
|
|
75
|
+
if (params) {
|
|
76
|
+
url += serializeParams(params);
|
|
77
|
+
}
|
|
78
|
+
return url;
|
|
79
|
+
}
|
|
80
|
+
async function request(method, url, config, body, options) {
|
|
81
|
+
const fullURL = buildURL(config.baseURL, url, options?.params);
|
|
82
|
+
const mergedHeaders = {
|
|
83
|
+
...config.headers,
|
|
84
|
+
...options?.headers,
|
|
85
|
+
};
|
|
86
|
+
if (body !== undefined &&
|
|
87
|
+
body !== null &&
|
|
88
|
+
!mergedHeaders["content-type"] &&
|
|
89
|
+
!mergedHeaders["Content-Type"]) {
|
|
90
|
+
mergedHeaders["Content-Type"] = "application/json";
|
|
91
|
+
}
|
|
92
|
+
let init = {
|
|
93
|
+
method,
|
|
94
|
+
headers: mergedHeaders,
|
|
95
|
+
body: body !== undefined && body !== null ? JSON.stringify(body) : undefined,
|
|
96
|
+
signal: options?.signal,
|
|
97
|
+
};
|
|
98
|
+
if (config.interceptors?.request) {
|
|
99
|
+
init = await config.interceptors.request(fullURL, init);
|
|
100
|
+
}
|
|
101
|
+
const timeout = options?.timeout ?? config.timeout;
|
|
102
|
+
const retry = normalizeRetry(options?.retry ?? config.retry);
|
|
103
|
+
const response = await fetchWithRetry(fullURL, init, timeout, retry);
|
|
104
|
+
let processed = response;
|
|
105
|
+
if (config.interceptors?.response) {
|
|
106
|
+
processed = await config.interceptors.response(processed);
|
|
107
|
+
}
|
|
108
|
+
if (!processed.ok) {
|
|
109
|
+
let errorData;
|
|
110
|
+
try {
|
|
111
|
+
errorData = await processed.clone().json();
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
try {
|
|
115
|
+
errorData = await processed.clone().text();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
errorData = undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
throw new HttpError(processed.status, processed.statusText, errorData);
|
|
122
|
+
}
|
|
123
|
+
let data;
|
|
124
|
+
const contentType = processed.headers.get("content-type") ?? "";
|
|
125
|
+
if (method === "HEAD") {
|
|
126
|
+
data = undefined;
|
|
127
|
+
}
|
|
128
|
+
else if (contentType.includes("application/json")) {
|
|
129
|
+
data = (await processed.json());
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
data = (await processed.text());
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
data,
|
|
136
|
+
status: processed.status,
|
|
137
|
+
statusText: processed.statusText,
|
|
138
|
+
headers: processed.headers,
|
|
139
|
+
ok: processed.ok,
|
|
140
|
+
raw: processed,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function createClient(config) {
|
|
144
|
+
return {
|
|
145
|
+
get: (url, options) => request("GET", url, config, undefined, options),
|
|
146
|
+
post: (url, body, options) => request("POST", url, config, body, options),
|
|
147
|
+
put: (url, body, options) => request("PUT", url, config, body, options),
|
|
148
|
+
patch: (url, body, options) => request("PATCH", url, config, body, options),
|
|
149
|
+
delete: (url, options) => request("DELETE", url, config, undefined, options),
|
|
150
|
+
head: (url, options) => request("HEAD", url, config, undefined, options),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const defaultConfig = {};
|
|
154
|
+
export async function get(url, options) {
|
|
155
|
+
return request("GET", url, defaultConfig, undefined, options);
|
|
156
|
+
}
|
|
157
|
+
export async function post(url, body, options) {
|
|
158
|
+
return request("POST", url, defaultConfig, body, options);
|
|
159
|
+
}
|
|
160
|
+
export async function put(url, body, options) {
|
|
161
|
+
return request("PUT", url, defaultConfig, body, options);
|
|
162
|
+
}
|
|
163
|
+
export async function patch(url, body, options) {
|
|
164
|
+
return request("PATCH", url, defaultConfig, body, options);
|
|
165
|
+
}
|
|
166
|
+
// Named 'del' internally but exported as 'delete' via index
|
|
167
|
+
export async function del(url, options) {
|
|
168
|
+
return request("DELETE", url, defaultConfig, undefined, options);
|
|
169
|
+
}
|
|
170
|
+
export async function head(url, options) {
|
|
171
|
+
return request("HEAD", url, defaultConfig, undefined, options);
|
|
172
|
+
}
|
|
173
|
+
export function create(config) {
|
|
174
|
+
return createClient(config);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS1D,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAExD,SAAS,cAAc,CAAC,KAAuC;IAC9D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,MAA6D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AO,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,GAAG,CACxB,GAAW,EACX,IAAc,EACd,OAAwB;IAExB,OAAO,OAAO,CAAI,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAC1B,GAAW,EACX,IAAc,EACd,OAAwB;IAExB,OAAO,OAAO,CAAI,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,GAAG,CACxB,GAAW,EACX,OAAwB;IAExB,OAAO,OAAO,CAAI,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAW,EAAE,OAAwB;IAC/D,OAAO,OAAO,CAAO,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,MAAoB;IAC1C,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,YAAY,CAAC;AAEpE,wBAAsB,QAAQ,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/download.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
export async function download(url, dest, options) {
|
|
4
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
5
|
+
const response = await fetch(url, {
|
|
6
|
+
headers: options?.headers,
|
|
7
|
+
signal: options?.signal,
|
|
8
|
+
});
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
throw new Error(`Download failed: HTTP ${response.status} ${response.statusText}`);
|
|
11
|
+
}
|
|
12
|
+
if (!response.body) {
|
|
13
|
+
throw new Error("Response body is empty");
|
|
14
|
+
}
|
|
15
|
+
const totalHeader = response.headers.get("content-length");
|
|
16
|
+
const total = totalHeader ? parseInt(totalHeader, 10) : null;
|
|
17
|
+
let transferred = 0;
|
|
18
|
+
const startTime = Date.now();
|
|
19
|
+
const reader = response.body.getReader();
|
|
20
|
+
const chunks = [];
|
|
21
|
+
while (true) {
|
|
22
|
+
const { done, value } = await reader.read();
|
|
23
|
+
if (done)
|
|
24
|
+
break;
|
|
25
|
+
chunks.push(value);
|
|
26
|
+
transferred += value.length;
|
|
27
|
+
if (options?.onProgress) {
|
|
28
|
+
const elapsed = (Date.now() - startTime) / 1000;
|
|
29
|
+
const speed = elapsed > 0 ? transferred / elapsed : 0;
|
|
30
|
+
const progress = {
|
|
31
|
+
total,
|
|
32
|
+
transferred,
|
|
33
|
+
percent: total ? Math.round((transferred / total) * 100) : 0,
|
|
34
|
+
speed,
|
|
35
|
+
};
|
|
36
|
+
options.onProgress(progress);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const fullBuffer = new Uint8Array(transferred);
|
|
40
|
+
let offset = 0;
|
|
41
|
+
for (const chunk of chunks) {
|
|
42
|
+
fullBuffer.set(chunk, offset);
|
|
43
|
+
offset += chunk.length;
|
|
44
|
+
}
|
|
45
|
+
await Bun.write(dest, fullBuffer);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,OAAO,E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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC;QAE5B,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACzB,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;YAChD,MAAM,KAAK,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAqB;gBAClC,KAAK;gBACL,WAAW;gBACX,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5D,KAAK;aACL,CAAC;YACF,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACxB,CAAC;IAED,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class HttpError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly statusText: string;
|
|
4
|
+
readonly data: unknown;
|
|
5
|
+
constructor(status: number, statusText: string, data?: unknown);
|
|
6
|
+
}
|
|
7
|
+
export declare class HttpTimeoutError extends Error {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly timeout: number;
|
|
10
|
+
constructor(url: string, timeout: number);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAEX,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAO9D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMxC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class HttpError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
statusText;
|
|
4
|
+
data;
|
|
5
|
+
constructor(status, statusText, data) {
|
|
6
|
+
super(`HTTP ${status}: ${statusText}`);
|
|
7
|
+
this.name = "HttpError";
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.statusText = statusText;
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class HttpTimeoutError extends Error {
|
|
14
|
+
url;
|
|
15
|
+
timeout;
|
|
16
|
+
constructor(url, timeout) {
|
|
17
|
+
super(`Request to ${url} timed out after ${timeout}ms`);
|
|
18
|
+
this.name = "HttpTimeoutError";
|
|
19
|
+
this.url = url;
|
|
20
|
+
this.timeout = timeout;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAC1B,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,IAAI,CAAU;IAEvB,YAAY,MAAc,EAAE,UAAkB,EAAE,IAAc;QAC7D,KAAK,CAAC,QAAQ,MAAM,KAAK,UAAU,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACjC,GAAG,CAAS;IACZ,OAAO,CAAS;IAEzB,YAAY,GAAW,EAAE,OAAe;QACvC,KAAK,CAAC,cAAc,GAAG,oBAAoB,OAAO,IAAI,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { create, del as delete, get, head, patch, post, put } from "./client.js";
|
|
2
|
+
export { download } from "./download.js";
|
|
3
|
+
export { HttpError, HttpTimeoutError } from "./errors.js";
|
|
4
|
+
export { createOpenAPIClient } from "./openapi.js";
|
|
5
|
+
export type { ClientConfig, DownloadOptions, DownloadProgress, HttpClient, HttpModule, HttpResponse, RequestOptions, RetryConfig, } from "./types.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,GACX,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { create, del as delete, get, head, patch, post, put } from "./client.js";
|
|
2
|
+
export { download } from "./download.js";
|
|
3
|
+
export { HttpError, HttpTimeoutError } from "./errors.js";
|
|
4
|
+
export { createOpenAPIClient } from "./openapi.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA,wBAAsB,mBAAmB,CAAC,MAAM,SAAS,EAAE,EAAE,MAAM,EAAE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,GAAG,OAAO,CAAC,OAAO,CAAC,CAiBnB"}
|
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export async function createOpenAPIClient(config) {
|
|
2
|
+
try {
|
|
3
|
+
// @ts-expect-error -- openapi-fetch is an optional peer dependency
|
|
4
|
+
const mod = await import("openapi-fetch");
|
|
5
|
+
const createClient = mod.default;
|
|
6
|
+
return createClient({
|
|
7
|
+
baseUrl: config.baseUrl,
|
|
8
|
+
headers: config.headers,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new Error("openapi-fetch is required for createOpenAPIClient. Install it with: bun add openapi-fetch");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=openapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAoB,MAG5D;IACA,IAAI,CAAC;QACJ,mEAAmE;QACnE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,GAAG,CAAC,OAGZ,CAAC;QACd,OAAO,YAAY,CAAC;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO;SACvB,CAAC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,KAAK,CACd,2FAA2F,CAC3F,CAAC;IACH,CAAC;AACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface RetryConfig {
|
|
2
|
+
count: number;
|
|
3
|
+
delay: number;
|
|
4
|
+
backoff?: "linear" | "exponential";
|
|
5
|
+
retryOn?: number[];
|
|
6
|
+
onRetry?: (error: Error, attempt: number) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface ClientConfig {
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
retry?: number | RetryConfig;
|
|
13
|
+
interceptors?: {
|
|
14
|
+
request?: (url: string, init: RequestInit) => RequestInit | Promise<RequestInit>;
|
|
15
|
+
response?: (response: Response) => Response | Promise<Response>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface RequestOptions {
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
retry?: number | RetryConfig;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
export interface HttpResponse<T = unknown> {
|
|
26
|
+
data: T;
|
|
27
|
+
status: number;
|
|
28
|
+
statusText: string;
|
|
29
|
+
headers: Headers;
|
|
30
|
+
ok: boolean;
|
|
31
|
+
raw: Response;
|
|
32
|
+
}
|
|
33
|
+
export interface DownloadProgress {
|
|
34
|
+
percent: number;
|
|
35
|
+
transferred: number;
|
|
36
|
+
total: number | null;
|
|
37
|
+
speed: number;
|
|
38
|
+
}
|
|
39
|
+
export interface DownloadOptions {
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
}
|
|
44
|
+
export interface HttpClient {
|
|
45
|
+
get<T = unknown>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
46
|
+
post<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
47
|
+
put<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
48
|
+
patch<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
49
|
+
delete<T = unknown>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
50
|
+
head(url: string, options?: RequestOptions): Promise<HttpResponse<void>>;
|
|
51
|
+
}
|
|
52
|
+
export interface HttpModule extends HttpClient {
|
|
53
|
+
create(config: ClientConfig): HttpClient;
|
|
54
|
+
download(url: string, dest: string, options?: DownloadOptions): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B,YAAY,CAAC,EAAE;QACd,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QACjF,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;KAChE,CAAC;CACF;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,O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YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAClG,KAAK,CAAC,CAAC,GAAG,OAAO,EAChB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACrF,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC7C,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9E"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@seedcli/http",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "HTTP client with OpenAPI typed client support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Rully Ardiansyah <rully@dreamshive.io>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/SeedCLI/seed",
|
|
11
|
+
"directory": "packages/http"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://seedcli.dev",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"cli",
|
|
16
|
+
"http",
|
|
17
|
+
"fetch",
|
|
18
|
+
"openapi",
|
|
19
|
+
"client",
|
|
20
|
+
"api"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"bun": ">=1.3.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"openapi-fetch": ">=0.17.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"openapi-fetch": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|