curl-wrap 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/index.d.ts +133 -0
  2. package/package.json +2 -1
package/index.d.ts ADDED
@@ -0,0 +1,133 @@
1
+ import { CookieJar } from "tough-cookie";
2
+
3
+ interface CurlOptions {
4
+ method?: string; // HTTP method (e.g., GET, POST)
5
+ headers?: Record<string, string>; // Request headers
6
+ body?: string | object | null; // Request body
7
+ timeout?: number; // Timeout in milliseconds
8
+ [key: string]: any; // Allow additional options
9
+ }
10
+
11
+ interface CurlResponse {
12
+ url: string;
13
+ body: string; // Response body as a string
14
+ headers: Record<string, string>; // Response headers
15
+ statusCode: number; // HTTP status code
16
+ status: number; // alias for .statusCode
17
+ ip: string;
18
+ errorMsg: string;
19
+ }
20
+
21
+ export function curl(
22
+ url: string,
23
+ options?: CurlOptions
24
+ ): Promise<CurlResponse>;
25
+
26
+ type BrowserType =
27
+ | "chrome"
28
+ | "edge"
29
+ | "chromeMobile"
30
+ | "firefox"
31
+ | "safari";
32
+
33
+ export class Curl {
34
+ constructor();
35
+
36
+ url(url: string): Curl;
37
+ static url(url: string): Curl;
38
+
39
+ get(url: string): Curl;
40
+ static get(url: string): Curl;
41
+
42
+ post(url: string): Curl;
43
+ static post(url: string): Curl;
44
+
45
+ put(url: string): Curl;
46
+ static put(url: string): Curl;
47
+
48
+ static getNewCookieJar(...args: any[]): CookieJar;
49
+ static getGlobalCookieJar(): CookieJar;
50
+
51
+ static hasCurlImpersonateChrome(): boolean;
52
+ static hasCurlImpersonateFirefox(): boolean;
53
+
54
+ cliCommand(command: string): Curl;
55
+ cliOptions(options: string | string[]): Curl;
56
+
57
+ impersonate(browser?: BrowserType): Curl;
58
+
59
+ followRedirect(shouldFollowRedirect?: boolean): Curl;
60
+ maxRedirects(numRedirects: number): Curl;
61
+
62
+ header(headerName: string | object, headerValue?: string): Curl;
63
+ headers(headers: object): Curl;
64
+
65
+ json(body?: object): Curl;
66
+ body(body: any, contentType?: string): Curl;
67
+
68
+ referer(referer: string): Curl;
69
+ referrer(referrer: string): Curl;
70
+
71
+ userAgent(userAgent: string): Curl;
72
+ contentType(contentType: string): Curl;
73
+
74
+ isJSON(): boolean;
75
+ isForm(): boolean;
76
+
77
+ cookie(
78
+ cookieName: string | boolean | object,
79
+ cookieValue?: string
80
+ ): Curl;
81
+ cookies(cookies: object | boolean): Curl;
82
+
83
+ globalCookies(options?: boolean | object): Curl;
84
+ cookieJar(cookieJar: CookieJar, options?: { readOnly?: boolean }): Curl;
85
+ cookieFile(fileName: string, options?: object): Curl;
86
+
87
+ timeout(timeout: number): Curl;
88
+ timeoutMs(timeoutInMs: number): Curl;
89
+
90
+ field(fieldName: string | object, fieldValue?: string): Curl;
91
+ fields(fields: object): Curl;
92
+
93
+ query(name: string | object, value?: string): Curl;
94
+ compress(askForCompression?: boolean): Curl;
95
+
96
+ method(method: string): Curl;
97
+
98
+ httpAuth(
99
+ username: string | { username: string; password: string },
100
+ password?: string
101
+ ): Curl;
102
+ bearerToken(token: string): Curl;
103
+ apiToken(token: string): Curl;
104
+
105
+ useProxy(shouldUseProxy?: boolean): Curl;
106
+ proxy(proxy: string | object, options?: object): Curl;
107
+
108
+ keepalive(isKeepAlive?: boolean): Curl;
109
+
110
+ get(): Curl;
111
+ post(): Curl;
112
+ put(): Curl;
113
+
114
+ verbose(isVerbose?: boolean): Curl;
115
+
116
+ fetch(): Promise<CurlResponse>;
117
+
118
+ then(
119
+ successCallback: (response: any) => CurlResponse,
120
+ errorCallback?: (error: Error) => CurlResponse
121
+ ): Promise<CurlResponse>;
122
+
123
+ catch(
124
+ errorCallback: (error: Error) => CurlResponse
125
+ ): Promise<CurlResponse>;
126
+
127
+ finally(callback: () => CurlResponse): Promise<CurlResponse>;
128
+
129
+ // Additional properties for options or cookie jars
130
+ private options: any;
131
+ private _fields: Record<string, any>;
132
+ private _query: Record<string, any>;
133
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "curl-wrap",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Nodejs library that wraps curl command line",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/hkk12369/curl-wrap.git"