@taybart/corvid 0.1.28 → 0.1.30
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.js +11 -7
- package/dist/network.d.ts +2 -10
- package/dist/network.js +11 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -539,17 +539,19 @@ class request {
|
|
|
539
539
|
url = `${url}?${reqParams.toString()}`;
|
|
540
540
|
}
|
|
541
541
|
override.headers = override.headers || {};
|
|
542
|
+
const headers = {
|
|
543
|
+
...this.opts.headers,
|
|
544
|
+
...override.headers
|
|
545
|
+
};
|
|
546
|
+
if (body instanceof FormData) delete headers['Content-Type'];
|
|
542
547
|
this.log.debug(`${this.opts.method} ${url}`);
|
|
543
548
|
return {
|
|
544
549
|
url,
|
|
545
550
|
options: {
|
|
546
551
|
method: override.method || this.opts.method,
|
|
547
552
|
credentials: this.opts.credentials,
|
|
548
|
-
headers
|
|
549
|
-
|
|
550
|
-
...override.headers
|
|
551
|
-
},
|
|
552
|
-
body: JSON.stringify(body)
|
|
553
|
+
headers,
|
|
554
|
+
body: body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer ? body : JSON.stringify(body)
|
|
553
555
|
}
|
|
554
556
|
};
|
|
555
557
|
}
|
|
@@ -579,8 +581,10 @@ class request {
|
|
|
579
581
|
body
|
|
580
582
|
};
|
|
581
583
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
+
const ct = res.headers.get('content-type') ?? '';
|
|
585
|
+
this.log.debug(`content type: ${ct}`);
|
|
586
|
+
if (ct.includes('application/json')) return await res.json();
|
|
587
|
+
if (ct.startsWith('image/') || 'application/octet-stream' === ct) return await res.blob();
|
|
584
588
|
return await res.text();
|
|
585
589
|
}
|
|
586
590
|
constructor(opts = {}, verbose = false){
|
package/dist/network.d.ts
CHANGED
|
@@ -55,16 +55,8 @@ export declare class request {
|
|
|
55
55
|
options: {
|
|
56
56
|
method: string | undefined;
|
|
57
57
|
credentials: RequestCredentials | undefined;
|
|
58
|
-
headers:
|
|
59
|
-
|
|
60
|
-
toString(): string;
|
|
61
|
-
toLocaleString(): string;
|
|
62
|
-
valueOf(): Object;
|
|
63
|
-
hasOwnProperty(v: PropertyKey): boolean;
|
|
64
|
-
isPrototypeOf(v: Object): boolean;
|
|
65
|
-
propertyIsEnumerable(v: PropertyKey): boolean;
|
|
66
|
-
};
|
|
67
|
-
body: string;
|
|
58
|
+
headers: Record<string, string>;
|
|
59
|
+
body: string | ArrayBuffer | FormData | Blob;
|
|
68
60
|
};
|
|
69
61
|
};
|
|
70
62
|
do({ path, params: passedParams, override, _recurselevel, }?: {
|
package/dist/network.js
CHANGED
|
@@ -114,17 +114,19 @@ class request {
|
|
|
114
114
|
url = `${url}?${reqParams.toString()}`;
|
|
115
115
|
}
|
|
116
116
|
override.headers = override.headers || {};
|
|
117
|
+
const headers = {
|
|
118
|
+
...this.opts.headers,
|
|
119
|
+
...override.headers
|
|
120
|
+
};
|
|
121
|
+
if (body instanceof FormData) delete headers['Content-Type'];
|
|
117
122
|
this.log.debug(`${this.opts.method} ${url}`);
|
|
118
123
|
return {
|
|
119
124
|
url,
|
|
120
125
|
options: {
|
|
121
126
|
method: override.method || this.opts.method,
|
|
122
127
|
credentials: this.opts.credentials,
|
|
123
|
-
headers
|
|
124
|
-
|
|
125
|
-
...override.headers
|
|
126
|
-
},
|
|
127
|
-
body: JSON.stringify(body)
|
|
128
|
+
headers,
|
|
129
|
+
body: body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer ? body : JSON.stringify(body)
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
}
|
|
@@ -154,8 +156,10 @@ class request {
|
|
|
154
156
|
body
|
|
155
157
|
};
|
|
156
158
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
const ct = res.headers.get('content-type') ?? '';
|
|
160
|
+
this.log.debug(`content type: ${ct}`);
|
|
161
|
+
if (ct.includes('application/json')) return await res.json();
|
|
162
|
+
if (ct.startsWith('image/') || 'application/octet-stream' === ct) return await res.blob();
|
|
159
163
|
return await res.text();
|
|
160
164
|
}
|
|
161
165
|
constructor(opts = {}, verbose = false){
|