@faasjs/request 0.0.3-beta.5 → 0.0.3-beta.50
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/README.md +3 -3
- package/dist/index.d.ts +9 -0
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,10 +52,10 @@ ___
|
|
|
52
52
|
| Name | Type | Description |
|
|
53
53
|
| :------ | :------ | :------ |
|
|
54
54
|
| `agent?` | `boolean` | - |
|
|
55
|
-
| `auth?` | `string` | The authentication credentials to use for the request.
|
|
55
|
+
| `auth?` | `string` | The authentication credentials to use for the request. Format: `username:password` |
|
|
56
56
|
| `body?` | { `[key: string]`: `any`; } \| `string` | - |
|
|
57
|
-
| `downloadStream?` | `NodeJS.WritableStream` | Create a write stream to download a file. |
|
|
58
|
-
| `file?` | `string` | Path of uploading a file to the server. |
|
|
57
|
+
| `downloadStream?` | `NodeJS.WritableStream` | Create a write stream to download a file. ```ts const stream = createWriteStream('filepath') await request('https://example.com', { downloadStream: stream }) ``` |
|
|
58
|
+
| `file?` | `string` | Path of uploading a file to the server. ```ts await request('https://example.com', { file: 'filepath' }) ``` |
|
|
59
59
|
| `headers?` | `http.OutgoingHttpHeaders` | - |
|
|
60
60
|
| `logger?` | `Logger` | - |
|
|
61
61
|
| `method?` | `string` | The HTTP method to use when making the request. Defaults to GET. |
|
package/dist/index.d.ts
CHANGED
|
@@ -39,10 +39,19 @@ type RequestOptions = {
|
|
|
39
39
|
auth?: string;
|
|
40
40
|
/**
|
|
41
41
|
* Path of uploading a file to the server.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* await request('https://example.com', { file: 'filepath' })
|
|
45
|
+
* ```
|
|
42
46
|
*/
|
|
43
47
|
file?: string;
|
|
44
48
|
/**
|
|
45
49
|
* Create a write stream to download a file.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const stream = createWriteStream('filepath')
|
|
53
|
+
* await request('https://example.com', { downloadStream: stream })
|
|
54
|
+
* ```
|
|
46
55
|
*/
|
|
47
56
|
downloadStream?: NodeJS.WritableStream;
|
|
48
57
|
pfx?: Buffer;
|
package/dist/index.js
CHANGED
|
@@ -136,7 +136,7 @@ async function request(url, {
|
|
|
136
136
|
res.on("end", () => {
|
|
137
137
|
const data = Buffer.concat(raw).toString();
|
|
138
138
|
logger.timeEnd(url, "response %s %s %s", res.statusCode, res.headers["content-type"], data);
|
|
139
|
-
const response = /* @__PURE__ */ Object.create(null);
|
|
139
|
+
const response = res.statusCode >= 200 && res.statusCode < 400 ? /* @__PURE__ */ Object.create(null) : new Error();
|
|
140
140
|
response.request = options;
|
|
141
141
|
response.request.body = body;
|
|
142
142
|
response.statusCode = res.statusCode;
|
|
@@ -145,7 +145,7 @@ async function request(url, {
|
|
|
145
145
|
response.body = data;
|
|
146
146
|
if (response.body && response.headers["content-type"] && response.headers["content-type"].includes("application/json"))
|
|
147
147
|
try {
|
|
148
|
-
response.body = parse
|
|
148
|
+
response.body = (parse || JSON.parse)(response.body);
|
|
149
149
|
logger.debug("response.parse JSON");
|
|
150
150
|
} catch (error) {
|
|
151
151
|
console.warn("response plain body", response.body);
|
|
@@ -155,6 +155,7 @@ async function request(url, {
|
|
|
155
155
|
resolve(response);
|
|
156
156
|
else {
|
|
157
157
|
logger.debug("response.error %j", response);
|
|
158
|
+
response.message = `${res.statusCode} ${res.statusMessage}`;
|
|
158
159
|
reject(response);
|
|
159
160
|
}
|
|
160
161
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -104,7 +104,7 @@ async function request(url, {
|
|
|
104
104
|
res.on("end", () => {
|
|
105
105
|
const data = Buffer.concat(raw).toString();
|
|
106
106
|
logger.timeEnd(url, "response %s %s %s", res.statusCode, res.headers["content-type"], data);
|
|
107
|
-
const response = /* @__PURE__ */ Object.create(null);
|
|
107
|
+
const response = res.statusCode >= 200 && res.statusCode < 400 ? /* @__PURE__ */ Object.create(null) : new Error();
|
|
108
108
|
response.request = options;
|
|
109
109
|
response.request.body = body;
|
|
110
110
|
response.statusCode = res.statusCode;
|
|
@@ -113,7 +113,7 @@ async function request(url, {
|
|
|
113
113
|
response.body = data;
|
|
114
114
|
if (response.body && response.headers["content-type"] && response.headers["content-type"].includes("application/json"))
|
|
115
115
|
try {
|
|
116
|
-
response.body = parse
|
|
116
|
+
response.body = (parse || JSON.parse)(response.body);
|
|
117
117
|
logger.debug("response.parse JSON");
|
|
118
118
|
} catch (error) {
|
|
119
119
|
console.warn("response plain body", response.body);
|
|
@@ -123,6 +123,7 @@ async function request(url, {
|
|
|
123
123
|
resolve(response);
|
|
124
124
|
else {
|
|
125
125
|
logger.debug("response.error %j", response);
|
|
126
|
+
response.message = `${res.statusCode} ${res.statusMessage}`;
|
|
126
127
|
reject(response);
|
|
127
128
|
}
|
|
128
129
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/request",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.50",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@faasjs/logger": "^0.0.3-beta.
|
|
25
|
+
"@faasjs/logger": "^0.0.3-beta.50"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"npm": ">=8.0.0",
|