@faasjs/request 0.0.3-beta.86 → 0.0.3-beta.87

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.
@@ -0,0 +1,96 @@
1
+ import * as http from 'http';
2
+ import { Logger } from '@faasjs/logger';
3
+
4
+ type Request = {
5
+ headers?: http.OutgoingHttpHeaders;
6
+ method?: string;
7
+ host?: string;
8
+ path?: string;
9
+ query?: http.OutgoingHttpHeaders;
10
+ body?: {
11
+ [key: string]: any;
12
+ };
13
+ };
14
+ type Response<T = any> = {
15
+ request?: Request;
16
+ statusCode?: number;
17
+ statusMessage?: string;
18
+ headers: http.OutgoingHttpHeaders;
19
+ body: T;
20
+ };
21
+ type RequestOptions = {
22
+ headers?: http.OutgoingHttpHeaders;
23
+ /**
24
+ * The HTTP method to use when making the request. Defaults to GET.
25
+ */
26
+ method?: string;
27
+ query?: {
28
+ [key: string]: any;
29
+ };
30
+ body?: {
31
+ [key: string]: any;
32
+ } | string;
33
+ timeout?: number;
34
+ /**
35
+ * The authentication credentials to use for the request.
36
+ *
37
+ * Format: `username:password`
38
+ */
39
+ auth?: string;
40
+ /**
41
+ * Path of uploading a file to the server.
42
+ *
43
+ * ```ts
44
+ * await request('https://example.com', { file: 'filepath' })
45
+ * ```
46
+ */
47
+ file?: string;
48
+ /**
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
+ * ```
55
+ */
56
+ downloadStream?: NodeJS.WritableStream;
57
+ pfx?: Buffer;
58
+ passphrase?: string;
59
+ agent?: boolean;
60
+ /**
61
+ * Body parser. Defaults to `JSON.parse`.
62
+ */
63
+ parse?: (body: string) => any;
64
+ logger?: Logger;
65
+ };
66
+ type Mock = (url: string, options: RequestOptions) => Promise<Response>;
67
+ /**
68
+ * Mock requests
69
+ * @param handler {function | null} null to disable mock
70
+ * @example setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
71
+ */
72
+ declare function setMock(handler: Mock | null): void;
73
+ declare function querystringify(obj: any): string;
74
+ /**
75
+ * Request
76
+ * @param {string} url Url
77
+ * @param {object=} [options={}] Options
78
+ * @param {string} [options.method=GET] Method
79
+ * @param {object} [options.query={}] Query
80
+ * @param {object} [options.headers={}] Headers
81
+ * @param {object=} options.body Body
82
+ * @param {number=} options.timeout Timeout
83
+ * @param {string=} options.auth Auth, format: user:password
84
+ * @param {string=} options.file Upload file path
85
+ * @param {WritableStream=} options.downloadStream Download stream
86
+ * @param {Buffer=} options.pfx pfx
87
+ * @param {string=} options.passphrase passphrase
88
+ * @param {boolean=} options.agent agent
89
+ * @param {parse=} options.parse body parser, default is JSON.parse
90
+ *
91
+ * @returns {promise}
92
+ * @url https://faasjs.com/doc/request.html
93
+ */
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>>;
95
+
96
+ export { Request, RequestOptions, Response, querystringify, request, setMock };
package/dist/index.js CHANGED
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/request",
3
- "version": "0.0.3-beta.86",
3
+ "version": "0.0.3-beta.87",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,13 +15,13 @@
15
15
  },
16
16
  "funding": "https://github.com/sponsors/faasjs",
17
17
  "scripts": {
18
- "build": "tsup-node src/index.ts --format esm,cjs --dts --clean"
18
+ "build": "tsup-node src/index.ts --config ../../tsup.config.json"
19
19
  },
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "@faasjs/logger": "^0.0.3-beta.86"
24
+ "@faasjs/logger": "^0.0.3-beta.87"
25
25
  },
26
26
  "engines": {
27
27
  "npm": ">=8.0.0",