@faasjs/request 0.0.3-beta.106 → 0.0.3-beta.108

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 CHANGED
@@ -54,7 +54,8 @@ ___
54
54
  | `agent?` | `boolean` | - |
55
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. ```ts const stream = createWriteStream('filepath') await request('https://example.com', { downloadStream: stream }) ``` |
57
+ | `downloadFile?` | `string` | Path of downloading a file from the server. ```ts await request('https://example.com', { downloadFile: 'filepath' }) ``` |
58
+ | `downloadStream?` | `NodeJS.WritableStream` | Create a write stream to download a file. ```ts import { createWriteStream } from 'fs' const stream = createWriteStream('filepath') await request('https://example.com', { downloadStream: stream }) ``` |
58
59
  | `file?` | `string` | Path of uploading a file to the server. ```ts await request('https://example.com', { file: 'filepath' }) ``` |
59
60
  | `headers?` | `http.OutgoingHttpHeaders` | - |
60
61
  | `logger?` | `Logger` | - |
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ function querystringify(obj) {
47
47
  value = encodeURIComponent(value);
48
48
  if (key === null || value === null)
49
49
  continue;
50
- pairs.push(key + "=" + value);
50
+ pairs.push(`${key}=${value}`);
51
51
  }
52
52
  }
53
53
  return pairs.length ? pairs.join("&") : "";
@@ -68,6 +68,7 @@ async function request(url$1, {
68
68
  parse,
69
69
  logger: logger$1
70
70
  } = { headers: {} }) {
71
+ var _a;
71
72
  if (!logger$1)
72
73
  logger$1 = new logger.Logger("request");
73
74
  if (mock) {
@@ -111,7 +112,7 @@ async function request(url$1, {
111
112
  if (typeof headers[key] !== "undefined" && headers[key] !== null)
112
113
  options.headers[key] = headers[key];
113
114
  if (body && typeof body !== "string")
114
- if (options.headers["Content-Type"] && options.headers["Content-Type"].toString().includes("application/x-www-form-urlencoded"))
115
+ if ((_a = options.headers["Content-Type"]) == null ? void 0 : _a.toString().includes("application/x-www-form-urlencoded"))
115
116
  body = querystringify(body);
116
117
  else
117
118
  body = JSON.stringify(body);
@@ -137,7 +138,13 @@ async function request(url$1, {
137
138
  });
138
139
  res.on("end", () => {
139
140
  const data = Buffer.concat(raw).toString();
140
- logger$1.timeEnd(url$1, "response %s %s %s", res.statusCode, res.headers["content-type"], data);
141
+ logger$1.timeEnd(
142
+ url$1,
143
+ "response %s %s %s",
144
+ res.statusCode,
145
+ res.headers["content-type"],
146
+ data
147
+ );
141
148
  const response = res.statusCode >= 200 && res.statusCode < 400 ? /* @__PURE__ */ Object.create(null) : new Error();
142
149
  response.request = options;
143
150
  response.request.body = body;
@@ -169,13 +176,17 @@ async function request(url$1, {
169
176
  const crlf = "\r\n";
170
177
  const boundary = `--${Math.random().toString(16)}`;
171
178
  const delimiter = `${crlf}--${boundary}`;
172
- const headers2 = [`Content-Disposition: form-data; name="file"; filename="${path.basename(file)}"${crlf}`];
179
+ const headers2 = [
180
+ `Content-Disposition: form-data; name="file"; filename="${path.basename(
181
+ file
182
+ )}"${crlf}`
183
+ ];
173
184
  const multipartBody = Buffer.concat([
174
185
  Buffer.from(delimiter + crlf + headers2.join("") + crlf),
175
186
  fs.readFileSync(file),
176
187
  Buffer.from(`${delimiter}--`)
177
188
  ]);
178
- req.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
189
+ req.setHeader("Content-Type", `multipart/form-data; boundary=${boundary}`);
179
190
  req.setHeader("Content-Length", multipartBody.length);
180
191
  req.write(multipartBody);
181
192
  }
package/dist/index.mjs CHANGED
@@ -24,7 +24,7 @@ function querystringify(obj) {
24
24
  value = encodeURIComponent(value);
25
25
  if (key === null || value === null)
26
26
  continue;
27
- pairs.push(key + "=" + value);
27
+ pairs.push(`${key}=${value}`);
28
28
  }
29
29
  }
30
30
  return pairs.length ? pairs.join("&") : "";
@@ -45,6 +45,7 @@ async function request(url, {
45
45
  parse,
46
46
  logger
47
47
  } = { headers: {} }) {
48
+ var _a;
48
49
  if (!logger)
49
50
  logger = new Logger("request");
50
51
  if (mock) {
@@ -88,7 +89,7 @@ async function request(url, {
88
89
  if (typeof headers[key] !== "undefined" && headers[key] !== null)
89
90
  options.headers[key] = headers[key];
90
91
  if (body && typeof body !== "string")
91
- if (options.headers["Content-Type"] && options.headers["Content-Type"].toString().includes("application/x-www-form-urlencoded"))
92
+ if ((_a = options.headers["Content-Type"]) == null ? void 0 : _a.toString().includes("application/x-www-form-urlencoded"))
92
93
  body = querystringify(body);
93
94
  else
94
95
  body = JSON.stringify(body);
@@ -114,7 +115,13 @@ async function request(url, {
114
115
  });
115
116
  res.on("end", () => {
116
117
  const data = Buffer.concat(raw).toString();
117
- logger.timeEnd(url, "response %s %s %s", res.statusCode, res.headers["content-type"], data);
118
+ logger.timeEnd(
119
+ url,
120
+ "response %s %s %s",
121
+ res.statusCode,
122
+ res.headers["content-type"],
123
+ data
124
+ );
118
125
  const response = res.statusCode >= 200 && res.statusCode < 400 ? /* @__PURE__ */ Object.create(null) : new Error();
119
126
  response.request = options;
120
127
  response.request.body = body;
@@ -146,13 +153,17 @@ async function request(url, {
146
153
  const crlf = "\r\n";
147
154
  const boundary = `--${Math.random().toString(16)}`;
148
155
  const delimiter = `${crlf}--${boundary}`;
149
- const headers2 = [`Content-Disposition: form-data; name="file"; filename="${basename(file)}"${crlf}`];
156
+ const headers2 = [
157
+ `Content-Disposition: form-data; name="file"; filename="${basename(
158
+ file
159
+ )}"${crlf}`
160
+ ];
150
161
  const multipartBody = Buffer.concat([
151
162
  Buffer.from(delimiter + crlf + headers2.join("") + crlf),
152
163
  readFileSync(file),
153
164
  Buffer.from(`${delimiter}--`)
154
165
  ]);
155
- req.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
166
+ req.setHeader("Content-Type", `multipart/form-data; boundary=${boundary}`);
156
167
  req.setHeader("Content-Length", multipartBody.length);
157
168
  req.write(multipartBody);
158
169
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/request",
3
- "version": "0.0.3-beta.106",
3
+ "version": "0.0.3-beta.108",
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.106"
24
+ "@faasjs/logger": "0.0.3-beta.108"
25
25
  },
26
26
  "engines": {
27
27
  "npm": ">=8.0.0",