flaks-request 1.0.7 → 1.0.8
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/package.json +2 -1
- package/types/handle-request.d.ts +9 -0
- package/types/helpers.d.ts +47 -0
- package/types/index.d.ts +10 -0
- package/types/methods/request-file.d.ts +13 -0
- package/types/methods/request-headers.d.ts +11 -0
- package/types/methods/request.d.ts +10 -0
- package/types/types.d.ts +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flaks-request",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Lightweight lib for requests",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"flaks",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"src/**/*",
|
|
22
|
+
"types/**/*",
|
|
22
23
|
"index.js",
|
|
23
24
|
"index.d.ts"
|
|
24
25
|
]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @import { RequestHandler, RequestOptions } from './types' */
|
|
2
|
+
export = handleRequest;
|
|
3
|
+
import type { RequestHandler, RequestOptions } from './types';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {RequestOptions} requestOptions
|
|
7
|
+
* @param {RequestHandler} responseHandler
|
|
8
|
+
*/
|
|
9
|
+
declare function handleRequest(requestOptions: RequestOptions, responseHandler: RequestHandler): Promise<any>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
declare const _exports: {
|
|
2
|
+
buildSearchParams: typeof buildSearchParams;
|
|
3
|
+
safeParse: typeof safeParse;
|
|
4
|
+
resolveUrl: typeof resolveUrl;
|
|
5
|
+
buildResponse: typeof buildResponse;
|
|
6
|
+
};
|
|
7
|
+
export = _exports;
|
|
8
|
+
import type { JsonValue, SearchParamsObject } from './types';
|
|
9
|
+
import type { RequestOptions, RequestResponse } from './types';
|
|
10
|
+
import { IncomingMessage } from "node:http";
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {SearchParamsObject} obj
|
|
14
|
+
* @param {string} prefix
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
declare function buildSearchParams(obj: SearchParamsObject, prefix?: string): import("node:url").URLSearchParams;
|
|
18
|
+
declare function safeParse(text?: string): {
|
|
19
|
+
body: JsonValue;
|
|
20
|
+
isJson: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
isJson?: undefined;
|
|
23
|
+
body: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {RequestOptions} requestOptions
|
|
28
|
+
*/
|
|
29
|
+
declare function resolveUrl(requestOptions: RequestOptions): string;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {RequestOptions} requestOptions
|
|
33
|
+
* @param {IncomingMessage} res
|
|
34
|
+
* @param {RequestResponse['body']} [body]
|
|
35
|
+
* @param {RequestResponse['isJson']} [isJson]
|
|
36
|
+
* @param {RequestResponse['verbose']} [verbose]
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
declare function buildResponse(requestOptions: RequestOptions, res: IncomingMessage, success?: boolean, body?: RequestResponse['body'], isJson?: RequestResponse['isJson'], verbose?: RequestResponse['verbose']): {
|
|
40
|
+
success: boolean;
|
|
41
|
+
status: number;
|
|
42
|
+
headers: import("node:http").IncomingHttpHeaders;
|
|
43
|
+
body: JsonValue | undefined;
|
|
44
|
+
isJson: boolean | undefined;
|
|
45
|
+
requestOptions: RequestOptions;
|
|
46
|
+
verbose: string[] | undefined;
|
|
47
|
+
};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _exports: {
|
|
2
|
+
request: typeof request;
|
|
3
|
+
requestHeaders: typeof requestHeaders;
|
|
4
|
+
requestFile: typeof requestFile;
|
|
5
|
+
buildSearchParams: (obj: import("./types").SearchParamsObject, prefix?: string) => import("node:url").URLSearchParams;
|
|
6
|
+
};
|
|
7
|
+
export = _exports;
|
|
8
|
+
import request = require("./methods/request");
|
|
9
|
+
import requestFile = require("./methods/request-file");
|
|
10
|
+
import requestHeaders = require("./methods/request-headers");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @import { RequestOptions, RequestResponse } from '../types' */
|
|
2
|
+
export = requestFile;
|
|
3
|
+
import type { RequestOptions, RequestResponse } from '../types';
|
|
4
|
+
import { WriteStream } from "node:fs";
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {RequestOptions} requestOptions
|
|
8
|
+
* @param {WriteStream} stream
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<RequestResponse>}
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
declare function requestFile(requestOptions: RequestOptions, stream: WriteStream): Promise<RequestResponse>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @import { RequestOptions, RequestResponse } from '../types' */
|
|
2
|
+
export = requestHeaders;
|
|
3
|
+
import type { RequestOptions, RequestResponse } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {RequestOptions} requestOptions
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<RequestResponse>}
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
declare function requestHeaders(requestOptions: RequestOptions): Promise<RequestResponse>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @import { RequestOptions, RequestResponse } from '../types' */
|
|
2
|
+
export = request;
|
|
3
|
+
import type { RequestOptions, RequestResponse } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {RequestOptions} requestOptions
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<RequestResponse>}
|
|
9
|
+
*/
|
|
10
|
+
declare function request(requestOptions: RequestOptions): Promise<RequestResponse>;
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IncomingHttpHeaders, IncomingMessage } from "node:http";
|
|
2
|
+
type SearchParamsValue = string | number | boolean | null | undefined | SearchParamsObject | unknown[];
|
|
3
|
+
export interface SearchParamsObject {
|
|
4
|
+
[key: string]: SearchParamsValue;
|
|
5
|
+
}
|
|
6
|
+
export interface RequestOptions {
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
search?: SearchParamsObject;
|
|
9
|
+
json?: unknown;
|
|
10
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
11
|
+
path: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
maxRedirects?: number;
|
|
15
|
+
}
|
|
16
|
+
export type RequestHandler = (res: IncomingMessage, resolve: (value: RequestResponse) => void, reject: (err: Error) => void) => void;
|
|
17
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
18
|
+
[key: string]: JsonValue;
|
|
19
|
+
};
|
|
20
|
+
export interface RequestResponse {
|
|
21
|
+
success?: boolean;
|
|
22
|
+
status: number;
|
|
23
|
+
headers: IncomingHttpHeaders;
|
|
24
|
+
body?: JsonValue;
|
|
25
|
+
isJson?: boolean;
|
|
26
|
+
requestOptions: RequestOptions;
|
|
27
|
+
verbose?: string[];
|
|
28
|
+
}
|
|
29
|
+
export {};
|