@faasjs/request 0.0.3-beta.100 → 0.0.3-beta.102
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 +10 -10
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +7 -4
- package/dist/index.mjs +8 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -111,10 +111,6 @@ ___
|
|
|
111
111
|
|
|
112
112
|
Request
|
|
113
113
|
|
|
114
|
-
**`Url`**
|
|
115
|
-
|
|
116
|
-
https://faasjs.com/doc/request.html
|
|
117
|
-
|
|
118
114
|
#### Type parameters
|
|
119
115
|
|
|
120
116
|
| Name | Type |
|
|
@@ -132,6 +128,10 @@ https://faasjs.com/doc/request.html
|
|
|
132
128
|
|
|
133
129
|
`Promise`<[`Response`](#response)<`T`\>\>
|
|
134
130
|
|
|
131
|
+
**`Url`**
|
|
132
|
+
|
|
133
|
+
https://faasjs.com/doc/request.html
|
|
134
|
+
|
|
135
135
|
___
|
|
136
136
|
|
|
137
137
|
### setMock
|
|
@@ -140,12 +140,6 @@ ___
|
|
|
140
140
|
|
|
141
141
|
Mock requests
|
|
142
142
|
|
|
143
|
-
**`Example`**
|
|
144
|
-
|
|
145
|
-
```ts
|
|
146
|
-
setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
|
|
147
|
-
```
|
|
148
|
-
|
|
149
143
|
#### Parameters
|
|
150
144
|
|
|
151
145
|
| Name | Type | Description |
|
|
@@ -155,3 +149,9 @@ setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200,
|
|
|
155
149
|
#### Returns
|
|
156
150
|
|
|
157
151
|
`void`
|
|
152
|
+
|
|
153
|
+
**`Example`**
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
|
|
157
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -49,11 +49,21 @@ type RequestOptions = {
|
|
|
49
49
|
* Create a write stream to download a file.
|
|
50
50
|
*
|
|
51
51
|
* ```ts
|
|
52
|
+
* import { createWriteStream } from 'fs'
|
|
53
|
+
*
|
|
52
54
|
* const stream = createWriteStream('filepath')
|
|
53
55
|
* await request('https://example.com', { downloadStream: stream })
|
|
54
56
|
* ```
|
|
55
57
|
*/
|
|
56
58
|
downloadStream?: NodeJS.WritableStream;
|
|
59
|
+
/**
|
|
60
|
+
* Path of downloading a file from the server.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* await request('https://example.com', { downloadFile: 'filepath' })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
downloadFile?: string;
|
|
57
67
|
pfx?: Buffer;
|
|
58
68
|
passphrase?: string;
|
|
59
69
|
agent?: boolean;
|
|
@@ -83,6 +93,7 @@ declare function querystringify(obj: any): string;
|
|
|
83
93
|
* @param {string=} options.auth Auth, format: user:password
|
|
84
94
|
* @param {string=} options.file Upload file path
|
|
85
95
|
* @param {WritableStream=} options.downloadStream Download stream
|
|
96
|
+
* @param {string=} options.downloadFile Download to file
|
|
86
97
|
* @param {Buffer=} options.pfx pfx
|
|
87
98
|
* @param {string=} options.passphrase passphrase
|
|
88
99
|
* @param {boolean=} options.agent agent
|
|
@@ -91,6 +102,6 @@ declare function querystringify(obj: any): string;
|
|
|
91
102
|
* @returns {promise}
|
|
92
103
|
* @url https://faasjs.com/doc/request.html
|
|
93
104
|
*/
|
|
94
|
-
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
105
|
+
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, downloadFile, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
95
106
|
|
|
96
107
|
export { Request, RequestOptions, Response, querystringify, request, setMock };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,11 +49,21 @@ type RequestOptions = {
|
|
|
49
49
|
* Create a write stream to download a file.
|
|
50
50
|
*
|
|
51
51
|
* ```ts
|
|
52
|
+
* import { createWriteStream } from 'fs'
|
|
53
|
+
*
|
|
52
54
|
* const stream = createWriteStream('filepath')
|
|
53
55
|
* await request('https://example.com', { downloadStream: stream })
|
|
54
56
|
* ```
|
|
55
57
|
*/
|
|
56
58
|
downloadStream?: NodeJS.WritableStream;
|
|
59
|
+
/**
|
|
60
|
+
* Path of downloading a file from the server.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* await request('https://example.com', { downloadFile: 'filepath' })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
downloadFile?: string;
|
|
57
67
|
pfx?: Buffer;
|
|
58
68
|
passphrase?: string;
|
|
59
69
|
agent?: boolean;
|
|
@@ -83,6 +93,7 @@ declare function querystringify(obj: any): string;
|
|
|
83
93
|
* @param {string=} options.auth Auth, format: user:password
|
|
84
94
|
* @param {string=} options.file Upload file path
|
|
85
95
|
* @param {WritableStream=} options.downloadStream Download stream
|
|
96
|
+
* @param {string=} options.downloadFile Download to file
|
|
86
97
|
* @param {Buffer=} options.pfx pfx
|
|
87
98
|
* @param {string=} options.passphrase passphrase
|
|
88
99
|
* @param {boolean=} options.agent agent
|
|
@@ -91,6 +102,6 @@ declare function querystringify(obj: any): string;
|
|
|
91
102
|
* @returns {promise}
|
|
92
103
|
* @url https://faasjs.com/doc/request.html
|
|
93
104
|
*/
|
|
94
|
-
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
105
|
+
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, downloadFile, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
95
106
|
|
|
96
107
|
export { Request, RequestOptions, Response, querystringify, request, setMock };
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ async function request(url$1, {
|
|
|
61
61
|
auth,
|
|
62
62
|
file,
|
|
63
63
|
downloadStream,
|
|
64
|
+
downloadFile,
|
|
64
65
|
pfx,
|
|
65
66
|
passphrase,
|
|
66
67
|
agent,
|
|
@@ -99,7 +100,7 @@ async function request(url$1, {
|
|
|
99
100
|
host: uri.host ? uri.host.replace(/:[0-9]+$/, "") : uri.host,
|
|
100
101
|
method: method ? method.toUpperCase() : "GET",
|
|
101
102
|
path: uri.pathname + uri.search,
|
|
102
|
-
port: uri.port,
|
|
103
|
+
port: uri.port || (uri.protocol === "https:" ? "443" : "80"),
|
|
103
104
|
timeout,
|
|
104
105
|
auth,
|
|
105
106
|
pfx,
|
|
@@ -124,9 +125,11 @@ async function request(url$1, {
|
|
|
124
125
|
const req = protocol.request(options, function(res) {
|
|
125
126
|
if (downloadStream) {
|
|
126
127
|
res.pipe(downloadStream);
|
|
127
|
-
downloadStream.on("finish",
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
downloadStream.on("finish", () => resolve(void 0));
|
|
129
|
+
} else if (downloadFile) {
|
|
130
|
+
const stream = fs.createWriteStream(downloadFile);
|
|
131
|
+
res.pipe(stream);
|
|
132
|
+
stream.on("finish", () => resolve(void 0));
|
|
130
133
|
} else {
|
|
131
134
|
const raw = [];
|
|
132
135
|
res.on("data", (chunk) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
2
|
import * as https from 'https';
|
|
3
3
|
import { URL } from 'url';
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
4
|
+
import { createWriteStream, readFileSync } from 'fs';
|
|
5
5
|
import { basename } from 'path';
|
|
6
6
|
import { Logger } from '@faasjs/logger';
|
|
7
7
|
|
|
@@ -38,6 +38,7 @@ async function request(url, {
|
|
|
38
38
|
auth,
|
|
39
39
|
file,
|
|
40
40
|
downloadStream,
|
|
41
|
+
downloadFile,
|
|
41
42
|
pfx,
|
|
42
43
|
passphrase,
|
|
43
44
|
agent,
|
|
@@ -76,7 +77,7 @@ async function request(url, {
|
|
|
76
77
|
host: uri.host ? uri.host.replace(/:[0-9]+$/, "") : uri.host,
|
|
77
78
|
method: method ? method.toUpperCase() : "GET",
|
|
78
79
|
path: uri.pathname + uri.search,
|
|
79
|
-
port: uri.port,
|
|
80
|
+
port: uri.port || (uri.protocol === "https:" ? "443" : "80"),
|
|
80
81
|
timeout,
|
|
81
82
|
auth,
|
|
82
83
|
pfx,
|
|
@@ -101,9 +102,11 @@ async function request(url, {
|
|
|
101
102
|
const req = protocol.request(options, function(res) {
|
|
102
103
|
if (downloadStream) {
|
|
103
104
|
res.pipe(downloadStream);
|
|
104
|
-
downloadStream.on("finish",
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
downloadStream.on("finish", () => resolve(void 0));
|
|
106
|
+
} else if (downloadFile) {
|
|
107
|
+
const stream = createWriteStream(downloadFile);
|
|
108
|
+
res.pipe(stream);
|
|
109
|
+
stream.on("finish", () => resolve(void 0));
|
|
107
110
|
} else {
|
|
108
111
|
const raw = [];
|
|
109
112
|
res.on("data", (chunk) => {
|
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.102",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@faasjs/logger": "0.0.3-beta.
|
|
24
|
+
"@faasjs/logger": "0.0.3-beta.102"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
27
|
"npm": ">=8.0.0",
|