@kosmojs/fetch 0.0.20 → 0.0.21
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/package.json +4 -4
- package/pkg/defaults.d.ts +5 -0
- package/pkg/index.d.ts +6 -0
- package/pkg/index.js +85 -105
- package/pkg/index.js.map +3 -3
- package/pkg/{src/types.d.ts → types.d.ts} +11 -3
- package/pkg/utils.d.ts +4 -0
- package/pkg/src/defaults.d.ts +0 -10
- package/pkg/src/index.d.ts +0 -9
- package/pkg/test/fetch.test.d.ts +0 -1
- package/pkg/test/mocks.d.ts +0 -1
- package/pkg/test/setup.d.ts +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present, Slee Woo and KosmoJS 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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@kosmojs/fetch",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.21",
|
|
5
5
|
"author": "Slee Woo",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
],
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"types": "./pkg/
|
|
15
|
+
"types": "./pkg/index.d.ts",
|
|
16
16
|
"default": "./pkg/index.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"qs": "^6.
|
|
20
|
+
"qs": "^6.15.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/qs": "^6.
|
|
23
|
+
"@types/qs": "^6.15.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "esbuilder src/index.ts",
|
package/pkg/index.d.ts
ADDED
package/pkg/index.js
CHANGED
|
@@ -1,78 +1,89 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/utils.ts
|
|
2
2
|
import qs from "qs";
|
|
3
|
+
var stringify = (data) => {
|
|
4
|
+
return qs.stringify(data, {
|
|
5
|
+
arrayFormat: "brackets",
|
|
6
|
+
indices: false,
|
|
7
|
+
encodeValuesOnly: true
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var join = (...args) => {
|
|
11
|
+
for (const a of args) {
|
|
12
|
+
if (typeof a === "string" || typeof a === "number") {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(
|
|
16
|
+
`The "path" argument must be of type string or number. Received type ${typeof a} (${JSON.stringify(a)})`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return args.join("/").replace(/\/+/g, "/");
|
|
20
|
+
};
|
|
21
|
+
var createHost = (host) => {
|
|
22
|
+
if (typeof host === "string") {
|
|
23
|
+
return host;
|
|
24
|
+
}
|
|
25
|
+
if (typeof host === "object") {
|
|
26
|
+
return [
|
|
27
|
+
host.secure ? "https://" : "http://",
|
|
28
|
+
host.hostname,
|
|
29
|
+
host.port ? `:${host.port}` : ""
|
|
30
|
+
].join("").replace(/\/+$/, "");
|
|
31
|
+
}
|
|
32
|
+
throw new Error(
|
|
33
|
+
"Expected host to be a string or an object like { hostname: string; port?: number; secure?: boolean }"
|
|
34
|
+
);
|
|
35
|
+
};
|
|
3
36
|
|
|
4
37
|
// src/defaults.ts
|
|
5
|
-
var
|
|
38
|
+
var defaults = {
|
|
6
39
|
responseMode: "json",
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
Accept: "application/json",
|
|
10
|
-
"Content-Type": "application/json"
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
stringify: (o) => new URLSearchParams(o).toString(),
|
|
40
|
+
stringify,
|
|
14
41
|
errorHandler: console.error
|
|
15
42
|
};
|
|
16
43
|
|
|
17
44
|
// src/index.ts
|
|
18
45
|
var bodylessMethods = ["GET", "DELETE"];
|
|
19
|
-
var index_default = (base,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
function wrapper(method) {
|
|
36
|
-
function _wrapper(path, data) {
|
|
46
|
+
var index_default = (base, baseOpts) => {
|
|
47
|
+
function factory(method) {
|
|
48
|
+
return async (...args) => {
|
|
49
|
+
const [path, data, opts] = args;
|
|
50
|
+
const {
|
|
51
|
+
responseMode,
|
|
52
|
+
stringify: stringify2,
|
|
53
|
+
errorHandler,
|
|
54
|
+
...fetchOpts
|
|
55
|
+
// Remaining options passed directly to fetch
|
|
56
|
+
} = {
|
|
57
|
+
...defaults,
|
|
58
|
+
...baseOpts,
|
|
59
|
+
...opts
|
|
60
|
+
};
|
|
37
61
|
const url = [
|
|
38
62
|
String(base),
|
|
39
|
-
...Array.isArray(path) ? path : ["string", "number"].includes(typeof path) ? [path] : []
|
|
63
|
+
...Array.isArray(path) ? path.flat() : ["string", "number"].includes(typeof path) ? [path] : []
|
|
40
64
|
// No path provided
|
|
41
65
|
].join("/");
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (contentType === null) {
|
|
55
|
-
headers.delete("Content-Type");
|
|
56
|
-
} else if (contentType) {
|
|
57
|
-
headers.set("Content-Type", contentType);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
let searchParams = "";
|
|
61
|
-
let body = JSON.stringify({});
|
|
62
|
-
if (data instanceof Blob || data instanceof FormData || Object.prototype.toString.call(data) === "[object ArrayBuffer]") {
|
|
63
|
-
body = data;
|
|
64
|
-
} else if (typeof data === "string") {
|
|
65
|
-
if (bodylessMethods.includes(method)) {
|
|
66
|
-
searchParams = data;
|
|
67
|
-
} else {
|
|
68
|
-
body = data;
|
|
69
|
-
}
|
|
70
|
-
} else if (typeof data === "object") {
|
|
71
|
-
if (bodylessMethods.includes(method)) {
|
|
72
|
-
searchParams = stringify2(data);
|
|
66
|
+
const headers = new Headers({
|
|
67
|
+
...data?.headers instanceof Headers ? Object.fromEntries(data.headers.entries()) : data?.headers
|
|
68
|
+
// Use as-is if already a plain object
|
|
69
|
+
});
|
|
70
|
+
let contentType;
|
|
71
|
+
let body;
|
|
72
|
+
if (data?.json) {
|
|
73
|
+
contentType = "application/json";
|
|
74
|
+
body = JSON.stringify(data.json);
|
|
75
|
+
} else if (data?.form) {
|
|
76
|
+
if (data.form instanceof FormData) {
|
|
77
|
+
body = data.form;
|
|
73
78
|
} else {
|
|
74
|
-
|
|
79
|
+
contentType = "application/x-www-form-urlencoded";
|
|
80
|
+
body = stringify2(data.form);
|
|
75
81
|
}
|
|
82
|
+
} else if (data?.raw) {
|
|
83
|
+
body = data.raw;
|
|
84
|
+
}
|
|
85
|
+
if (contentType && !headers.get("Content-Type")) {
|
|
86
|
+
headers.set("Content-Type", contentType);
|
|
76
87
|
}
|
|
77
88
|
const config = {
|
|
78
89
|
...fetchOpts,
|
|
@@ -81,72 +92,41 @@ var index_default = (base, opts) => {
|
|
|
81
92
|
// Only include body for non-bodyless methods
|
|
82
93
|
...bodylessMethods.includes(method) ? {} : { body }
|
|
83
94
|
};
|
|
84
|
-
|
|
95
|
+
const searchParams = data?.query ? `?${stringify2(data.query)}` : "";
|
|
96
|
+
return fetch(url + searchParams, config).then((response) => {
|
|
85
97
|
return Promise.all([
|
|
86
98
|
response,
|
|
87
|
-
responseMode === "raw" ? response : response[responseMode]().catch(() =>
|
|
99
|
+
responseMode === "raw" ? response : response[responseMode]().catch((e) => e)
|
|
88
100
|
// Parse response body
|
|
89
101
|
]);
|
|
90
102
|
}).then(([response, data2]) => {
|
|
91
103
|
if (response.ok) {
|
|
92
|
-
return data2;
|
|
104
|
+
return data2 instanceof Error ? void 0 : data2;
|
|
93
105
|
}
|
|
94
106
|
const error = new Error(
|
|
95
107
|
data2?.error || response.statusText
|
|
96
108
|
);
|
|
97
109
|
error.response = response;
|
|
98
110
|
error.body = data2;
|
|
99
|
-
errorHandler
|
|
111
|
+
if (errorHandler) {
|
|
112
|
+
return errorHandler(error);
|
|
113
|
+
}
|
|
100
114
|
throw error;
|
|
101
115
|
});
|
|
102
|
-
}
|
|
103
|
-
return _wrapper;
|
|
116
|
+
};
|
|
104
117
|
}
|
|
105
118
|
return {
|
|
106
|
-
GET:
|
|
107
|
-
POST:
|
|
108
|
-
PUT:
|
|
109
|
-
PATCH:
|
|
110
|
-
DELETE:
|
|
119
|
+
GET: factory("GET"),
|
|
120
|
+
POST: factory("POST"),
|
|
121
|
+
PUT: factory("PUT"),
|
|
122
|
+
PATCH: factory("PATCH"),
|
|
123
|
+
DELETE: factory("DELETE")
|
|
111
124
|
};
|
|
112
125
|
};
|
|
113
|
-
var stringify = (data) => {
|
|
114
|
-
return qs.stringify(data, {
|
|
115
|
-
arrayFormat: "brackets",
|
|
116
|
-
indices: false,
|
|
117
|
-
encodeValuesOnly: true
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
var join = (...args) => {
|
|
121
|
-
for (const a of args) {
|
|
122
|
-
if (typeof a === "string" || typeof a === "number") {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
throw new Error(
|
|
126
|
-
`The "path" argument must be of type string or number. Received type ${typeof a} (${JSON.stringify(a)})`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
return args.join("/").replace(/\/+/g, "/");
|
|
130
|
-
};
|
|
131
|
-
var createHost = (host) => {
|
|
132
|
-
if (typeof host === "string") {
|
|
133
|
-
return host;
|
|
134
|
-
}
|
|
135
|
-
if (typeof host === "object") {
|
|
136
|
-
return [
|
|
137
|
-
host.secure ? "https://" : "http://",
|
|
138
|
-
host.hostname,
|
|
139
|
-
host.port ? `:${host.port}` : ""
|
|
140
|
-
].join("").replace(/\/+$/, "");
|
|
141
|
-
}
|
|
142
|
-
throw new Error(
|
|
143
|
-
"Expected host to be a string or an object like { hostname: string; port?: number; secure?: boolean }"
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
126
|
export {
|
|
147
127
|
createHost,
|
|
148
128
|
index_default as default,
|
|
149
|
-
|
|
129
|
+
defaults,
|
|
150
130
|
join,
|
|
151
131
|
stringify
|
|
152
132
|
};
|
package/pkg/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["import qs from \"qs\";\n\nimport
|
|
5
|
-
"mappings": ";AAAA,OAAO,QAAQ
|
|
3
|
+
"sources": ["../src/utils.ts", "../src/defaults.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import qs from \"qs\";\n\nimport type { HostOpt } from \"./types\";\n\nexport const stringify = (data: Record<string, unknown>) => {\n return qs.stringify(data, {\n arrayFormat: \"brackets\",\n indices: false,\n encodeValuesOnly: true,\n });\n};\n\nexport const join = (...args: Array<unknown>): string => {\n for (const a of args) {\n if (typeof a === \"string\" || typeof a === \"number\") {\n continue;\n }\n throw new Error(\n `The \"path\" argument must be of type string or number. Received type ${typeof a} (${JSON.stringify(a)})`,\n );\n }\n return args.join(\"/\").replace(/\\/+/g, \"/\");\n};\n\nexport const createHost = (host: HostOpt): string => {\n if (typeof host === \"string\") {\n return host;\n }\n\n if (typeof host === \"object\") {\n return [\n host.secure ? \"https://\" : \"http://\",\n host.hostname,\n host.port ? `:${host.port}` : \"\",\n ]\n .join(\"\")\n .replace(/\\/+$/, \"\");\n }\n\n throw new Error(\n \"Expected host to be a string or an object like { hostname: string; port?: number; secure?: boolean }\",\n );\n};\n", "import type { Defaults } from \"./types\";\nimport { stringify } from \"./utils\";\n\nexport const defaults = {\n responseMode: \"json\",\n stringify,\n errorHandler: console.error,\n} satisfies Defaults;\n", "import { defaults } from \"./defaults\";\nimport type {\n FetchMapper,\n FetchMethod,\n HTTPError,\n HTTPMethod,\n Options,\n} from \"./types\";\n\nexport * from \"./defaults\";\nexport * from \"./types\";\nexport * from \"./utils\";\n\n// HTTP methods that typically don't include a request body\nconst bodylessMethods = [\"GET\", \"DELETE\"];\n\n// Main factory function that creates a configured fetch client instance\nexport default (base: string | URL, baseOpts?: Options): FetchMapper => {\n // Factory function that creates HTTP method implementations\n function factory(method: HTTPMethod): FetchMethod {\n return async (...args: Partial<Parameters<FetchMethod>>) => {\n const [path, data, opts] = args;\n\n const {\n responseMode,\n stringify,\n errorHandler,\n ...fetchOpts // Remaining options passed directly to fetch\n } = {\n ...defaults,\n ...baseOpts,\n ...opts,\n };\n\n // Construct URL from base and path segments\n const url = [\n String(base),\n ...(Array.isArray(path)\n ? path.flat()\n : [\"string\", \"number\"].includes(typeof path)\n ? [path] // Wrap single value in array\n : []), // No path provided\n ].join(\"/\");\n\n // Normalize headers to Headers instance for consistent API\n const headers = new Headers({\n ...(data?.headers instanceof Headers\n ? Object.fromEntries(data.headers.entries()) // Convert Headers to plain object\n : data?.headers), // Use as-is if already a plain object\n });\n\n let contentType: string | undefined;\n let body: unknown;\n\n // Handle different data types for request body\n if (data?.json) {\n contentType = \"application/json\";\n body = JSON.stringify(data.json);\n } else if (data?.form) {\n if (data.form instanceof FormData) {\n // let fetch set Content-Type, with boundary etc.\n body = data.form;\n } else {\n contentType = \"application/x-www-form-urlencoded\";\n body = stringify(data.form as never);\n }\n } else if (data?.raw) {\n // no Content-Type needed\n body = data.raw;\n }\n\n if (contentType && !headers.get(\"Content-Type\")) {\n headers.set(\"Content-Type\", contentType);\n }\n\n // Prepare fetch configuration\n const config = {\n ...fetchOpts,\n method,\n headers,\n // Only include body for non-bodyless methods\n ...(bodylessMethods.includes(method) ? {} : { body }),\n };\n\n const searchParams = data?.query\n ? `?${stringify(data.query as never)}`\n : \"\";\n\n return fetch(url + searchParams, config as never)\n .then((response) => {\n // Return both response and parsed data based on responseMode\n return Promise.all([\n response,\n responseMode === \"raw\"\n ? response // Return full response object\n : response[responseMode]().catch((e) => e), // Parse response body\n ]);\n })\n .then(([response, data]) => {\n if (response.ok) {\n return data instanceof Error ? undefined : data;\n }\n // Create enhanced error object for HTTP errors\n const error = new Error(\n data?.error || response.statusText,\n ) as HTTPError;\n error.response = response;\n error.body = data;\n if (errorHandler) {\n return errorHandler(error);\n }\n throw error;\n });\n };\n }\n\n return {\n GET: factory(\"GET\"),\n POST: factory(\"POST\"),\n PUT: factory(\"PUT\"),\n PAT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AK,CAAC,CAAC,UAAUC,KAAI,MAAM;AAC1B,YAAI,SAAS,IAAI;AACf,iBAAOA,iBAAgB,QAAQ,SAAYA;AAAA,QAC7C;AAEA,cAAM,QAAQ,IAAI;AAAA,UAChBA,OAAM,SAAS,SAAS;AAAA,QAC1B;AACA,cAAM,WAAW;AACjB,cAAM,OAAOA;AACb,YAAI,cAAc;AAChB,iBAAO,aAAa,KAAK;AAAA,QAC3B;AACA,cAAM;AAAA,MACR,CAAC;AAAA,IACL;AAAA,EACF;AAEA,SAAO;AAAA,IACL,KAAK,QAAQ,KAAK;AAAA,IAClB,MAAM,QAAQ,MAAM;AAAA,IACpB,KAAK,QAAQ,KAAK;AAAA,IAClB,OAAO,QAAQ,OAAO;AAAA,IACtB,QAAQ,QAAQ,QAAQ;AAAA,EAC1B;AACF;",
|
|
6
6
|
"names": ["stringify", "data"]
|
|
7
7
|
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
export interface Defaults {
|
|
2
2
|
responseMode: ResponseMode;
|
|
3
|
-
headers: Record<string, string> | Headers;
|
|
4
3
|
stringify: (d: Record<string, unknown>) => string;
|
|
5
4
|
errorHandler: (e: unknown) => void;
|
|
6
5
|
}
|
|
7
6
|
export type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
8
7
|
export type ResponseMode = "json" | "text" | "blob" | "formData" | "arrayBuffer" | "raw";
|
|
9
|
-
export type Options = Partial<Defaults> & Pick<RequestInit, "cache" | "credentials" | "
|
|
10
|
-
export type
|
|
8
|
+
export type Options = Partial<Defaults> & Pick<RequestInit, "cache" | "credentials" | "integrity" | "keepalive" | "mode" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window">;
|
|
9
|
+
export type PathEntry = string | number;
|
|
10
|
+
export type Data = Partial<Record<"query" | "json" | "form" | "raw", unknown> & {
|
|
11
|
+
headers: Headers | Record<string, string>;
|
|
12
|
+
}>;
|
|
13
|
+
export type FetchMethod = {
|
|
14
|
+
<T = unknown>(): Promise<T>;
|
|
15
|
+
<T = unknown>(path: PathEntry | Array<PathEntry>): Promise<T>;
|
|
16
|
+
<T = unknown>(path: PathEntry | Array<PathEntry>, data: Data): Promise<T>;
|
|
17
|
+
<T = unknown>(path: PathEntry | Array<PathEntry>, data: Data, opts: Options): Promise<T>;
|
|
18
|
+
};
|
|
11
19
|
export type FetchMapper = Record<HTTPMethod, FetchMethod>;
|
|
12
20
|
export interface HTTPError<T extends object = object> extends Error {
|
|
13
21
|
body: T;
|
package/pkg/utils.d.ts
ADDED
package/pkg/src/defaults.d.ts
DELETED
package/pkg/src/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import defaults from "./defaults";
|
|
2
|
-
import type { FetchMapper, HostOpt, Options } from "./types";
|
|
3
|
-
export { defaults };
|
|
4
|
-
export * from "./types";
|
|
5
|
-
declare const _default: (base: string | URL, opts?: Options) => FetchMapper;
|
|
6
|
-
export default _default;
|
|
7
|
-
export declare const stringify: (data: Record<string, unknown>) => string;
|
|
8
|
-
export declare const join: (...args: Array<unknown>) => string;
|
|
9
|
-
export declare const createHost: (host: HostOpt) => string;
|
package/pkg/test/fetch.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/pkg/test/mocks.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const server: import("msw/node").SetupServerApi;
|
package/pkg/test/setup.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|