@t-req/core 0.1.0
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/LICENSE +21 -0
- package/README.md +632 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/config/define.d.ts +6 -0
- package/dist/config/define.d.ts.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/index.js.map +12 -0
- package/dist/config/load.d.ts +15 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/merge.d.ts +8 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/types.d.ts +22 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/cookies.d.ts +21 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +45 -0
- package/dist/cookies.js.map +12 -0
- package/dist/engine/engine.d.ts +31 -0
- package/dist/engine/engine.d.ts.map +1 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +6 -0
- package/dist/engine/index.js.map +18 -0
- package/dist/execute.d.ts +13 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/file-loader.d.ts +101 -0
- package/dist/file-loader.d.ts.map +1 -0
- package/dist/form-data-builder.d.ts +64 -0
- package/dist/form-data-builder.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +20 -0
- package/dist/interpolate.d.ts +11 -0
- package/dist/interpolate.d.ts.map +1 -0
- package/dist/parser.d.ts +16 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/runtime/auto-transport.d.ts +9 -0
- package/dist/runtime/auto-transport.d.ts.map +1 -0
- package/dist/runtime/fetch-transport.d.ts +11 -0
- package/dist/runtime/fetch-transport.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +12 -0
- package/dist/runtime/node-io.d.ts +6 -0
- package/dist/runtime/node-io.d.ts.map +1 -0
- package/dist/runtime/types.d.ts +62 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/types.d.ts +297 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/optional.d.ts +40 -0
- package/dist/utils/optional.d.ts.map +1 -0
- package/package.json +92 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import type { CookieJar } from 'tough-cookie';
|
|
2
|
+
import type { EventSink, IO, Transport } from './runtime/types';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a file reference in request body using `< ./path` syntax.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const fileRef: FileReference = {
|
|
9
|
+
* path: './fixtures/payload.json'
|
|
10
|
+
* };
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface FileReference {
|
|
14
|
+
/** Relative path to the file */
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Represents a field in form data body.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Text field
|
|
23
|
+
* const textField: FormField = {
|
|
24
|
+
* name: 'title',
|
|
25
|
+
* value: 'My Document',
|
|
26
|
+
* isFile: false,
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* // File field
|
|
30
|
+
* const fileField: FormField = {
|
|
31
|
+
* name: 'document',
|
|
32
|
+
* value: '',
|
|
33
|
+
* isFile: true,
|
|
34
|
+
* path: './uploads/doc.pdf',
|
|
35
|
+
* filename: 'report.pdf', // optional custom filename
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface FormField {
|
|
40
|
+
/** Field name */
|
|
41
|
+
name: string;
|
|
42
|
+
/** Text value (for non-file fields) */
|
|
43
|
+
value: string;
|
|
44
|
+
/** Whether this field is a file upload */
|
|
45
|
+
isFile: boolean;
|
|
46
|
+
/** File path if isFile is true (from @./path syntax) */
|
|
47
|
+
path?: string;
|
|
48
|
+
/** Custom filename for file upload (from | syntax) */
|
|
49
|
+
filename?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Represents a parsed HTTP request from a .http file.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const request: ParsedRequest = {
|
|
57
|
+
* name: 'getUsers',
|
|
58
|
+
* method: 'GET',
|
|
59
|
+
* url: 'https://api.example.com/users',
|
|
60
|
+
* headers: { 'Authorization': 'Bearer token' },
|
|
61
|
+
* body: undefined,
|
|
62
|
+
* raw: 'GET https://api.example.com/users\nAuthorization: Bearer token',
|
|
63
|
+
* meta: { timeout: '5000' }
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export interface ParsedRequest {
|
|
68
|
+
/** Optional name for the request, from `### Name` or `# @name name` */
|
|
69
|
+
name?: string;
|
|
70
|
+
/** HTTP method (GET, POST, PUT, DELETE, PATCH, etc.) */
|
|
71
|
+
method: string;
|
|
72
|
+
/** Full URL including any query parameters */
|
|
73
|
+
url: string;
|
|
74
|
+
/** Request headers as key-value pairs */
|
|
75
|
+
headers: Record<string, string>;
|
|
76
|
+
/** Request body content (for POST, PUT, PATCH requests) */
|
|
77
|
+
body?: string;
|
|
78
|
+
/** File reference if body uses `< ./path` syntax */
|
|
79
|
+
bodyFile?: FileReference;
|
|
80
|
+
/** Form fields if body uses form data syntax (field = value) */
|
|
81
|
+
formData?: FormField[];
|
|
82
|
+
/** Original raw content of the request block */
|
|
83
|
+
raw: string;
|
|
84
|
+
/** Meta directives from comments like `# @directive value` */
|
|
85
|
+
meta: Record<string, string>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A function that resolves dynamic values during interpolation.
|
|
89
|
+
* Receives zero or more string arguments from the template.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const envResolver: Resolver = (key) => process.env[key] || '';
|
|
94
|
+
* const randomResolver: Resolver = (min = '0', max = '100') =>
|
|
95
|
+
* String(Math.floor(Math.random() * (Number(max) - Number(min) + 1)) + Number(min));
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export type Resolver = (...args: string[]) => string | Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Configuration options for variable interpolation.
|
|
101
|
+
*/
|
|
102
|
+
export interface InterpolateOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Custom resolvers for dynamic values like `{{$env(KEY)}}`.
|
|
105
|
+
* Resolver names must start with `$`.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* {
|
|
110
|
+
* resolvers: {
|
|
111
|
+
* $env: (key) => process.env[key] || '',
|
|
112
|
+
* $timestamp: () => String(Date.now()),
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
resolvers?: Record<string, Resolver>;
|
|
118
|
+
/**
|
|
119
|
+
* How to handle undefined variables.
|
|
120
|
+
* - `'throw'`: Throw an error (default)
|
|
121
|
+
* - `'keep'`: Keep the `{{variable}}` placeholder
|
|
122
|
+
* - `'empty'`: Replace with empty string
|
|
123
|
+
*/
|
|
124
|
+
undefinedBehavior?: 'throw' | 'keep' | 'empty';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A reusable interpolator instance with async support.
|
|
128
|
+
* Created using `createInterpolator()`.
|
|
129
|
+
*/
|
|
130
|
+
export interface Interpolator {
|
|
131
|
+
/**
|
|
132
|
+
* Interpolate variables in a target string or object.
|
|
133
|
+
* Supports async resolvers.
|
|
134
|
+
*/
|
|
135
|
+
interpolate<T>(target: T, variables: Record<string, unknown>): Promise<T>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Request object for HTTP execution.
|
|
139
|
+
* This is the minimal representation needed to execute a request.
|
|
140
|
+
*/
|
|
141
|
+
export interface ExecuteRequest {
|
|
142
|
+
/** HTTP method */
|
|
143
|
+
method: string;
|
|
144
|
+
/** Full URL to request */
|
|
145
|
+
url: string;
|
|
146
|
+
/** Request headers */
|
|
147
|
+
headers?: Record<string, string>;
|
|
148
|
+
/** Request body (string, ArrayBuffer, FormData, or URLSearchParams) */
|
|
149
|
+
body?: string | ArrayBuffer | FormData | URLSearchParams;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Options for HTTP request execution (internal use).
|
|
153
|
+
*/
|
|
154
|
+
export interface ExecuteOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Request timeout in milliseconds.
|
|
157
|
+
* @default 30000
|
|
158
|
+
*/
|
|
159
|
+
timeout?: number;
|
|
160
|
+
/**
|
|
161
|
+
* AbortSignal for cancellation. Takes precedence over timeout.
|
|
162
|
+
*/
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
/**
|
|
165
|
+
* Whether to automatically follow redirects.
|
|
166
|
+
* @default true
|
|
167
|
+
*/
|
|
168
|
+
followRedirects?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Whether to validate SSL certificates.
|
|
171
|
+
* Set to false for self-signed certificates.
|
|
172
|
+
* @default true
|
|
173
|
+
*/
|
|
174
|
+
validateSSL?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Proxy URL to use for requests.
|
|
177
|
+
* @example 'http://proxy.example.com:8080'
|
|
178
|
+
*/
|
|
179
|
+
proxy?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Configuration for creating an HTTP client.
|
|
183
|
+
*/
|
|
184
|
+
export interface ClientConfig {
|
|
185
|
+
/**
|
|
186
|
+
* Variables available to all requests.
|
|
187
|
+
* Can be overridden per-request.
|
|
188
|
+
*/
|
|
189
|
+
variables?: Record<string, unknown>;
|
|
190
|
+
/**
|
|
191
|
+
* Custom resolvers for dynamic values.
|
|
192
|
+
* @see InterpolateOptions.resolvers
|
|
193
|
+
*/
|
|
194
|
+
resolvers?: Record<string, Resolver>;
|
|
195
|
+
/**
|
|
196
|
+
* Cookie jar for automatic cookie handling.
|
|
197
|
+
* Create with `createCookieJar()`.
|
|
198
|
+
*/
|
|
199
|
+
cookieJar?: CookieJar;
|
|
200
|
+
/**
|
|
201
|
+
* Optional IO adapter for filesystem access (Node/Bun/Tauri).
|
|
202
|
+
* Required for `client.run(path)` in runtimes without Bun filesystem APIs.
|
|
203
|
+
*/
|
|
204
|
+
io?: IO;
|
|
205
|
+
/**
|
|
206
|
+
* Optional transport adapter to control how requests are executed.
|
|
207
|
+
*/
|
|
208
|
+
transport?: Transport;
|
|
209
|
+
/**
|
|
210
|
+
* Optional event sink for engine-style observability (useful for TUI/agent UX).
|
|
211
|
+
*/
|
|
212
|
+
onEvent?: EventSink;
|
|
213
|
+
/**
|
|
214
|
+
* Default timeout in milliseconds for all requests.
|
|
215
|
+
* Can be overridden per-request.
|
|
216
|
+
* @default 30000
|
|
217
|
+
*/
|
|
218
|
+
timeout?: number;
|
|
219
|
+
/**
|
|
220
|
+
* Default settings for all requests.
|
|
221
|
+
*/
|
|
222
|
+
defaults?: {
|
|
223
|
+
/** Default headers to include */
|
|
224
|
+
headers?: Record<string, string>;
|
|
225
|
+
/** Whether to follow redirects */
|
|
226
|
+
followRedirects?: boolean;
|
|
227
|
+
/** Whether to validate SSL certificates */
|
|
228
|
+
validateSSL?: boolean;
|
|
229
|
+
/** Proxy URL */
|
|
230
|
+
proxy?: string;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Options for running a request.
|
|
235
|
+
*/
|
|
236
|
+
export interface RunOptions {
|
|
237
|
+
/** Additional variables for this request */
|
|
238
|
+
variables?: Record<string, unknown>;
|
|
239
|
+
/**
|
|
240
|
+
* Timeout in milliseconds for this request.
|
|
241
|
+
* Converted to AbortSignal internally.
|
|
242
|
+
*/
|
|
243
|
+
timeout?: number;
|
|
244
|
+
/**
|
|
245
|
+
* AbortSignal for cancellation.
|
|
246
|
+
* Takes precedence over timeout if both provided.
|
|
247
|
+
*/
|
|
248
|
+
signal?: AbortSignal;
|
|
249
|
+
/**
|
|
250
|
+
* Base path for resolving file references when using `runString`.
|
|
251
|
+
* Ignored by `run(path)`, which derives base path from the .http file location.
|
|
252
|
+
*/
|
|
253
|
+
basePath?: string;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* High-level HTTP client with variable interpolation and cookies.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const client = createClient({
|
|
261
|
+
* variables: { baseUrl: 'https://api.example.com' },
|
|
262
|
+
* cookieJar: createCookieJar(),
|
|
263
|
+
* });
|
|
264
|
+
*
|
|
265
|
+
* // Run a request from a .http file
|
|
266
|
+
* const res = await client.run('./auth/login.http');
|
|
267
|
+
* const { token } = await res.json();
|
|
268
|
+
*
|
|
269
|
+
* // Set variable for subsequent requests
|
|
270
|
+
* client.setVariable('token', token);
|
|
271
|
+
*
|
|
272
|
+
* // Run another request
|
|
273
|
+
* const profile = await client.run('./users/profile.http');
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
export interface Client {
|
|
277
|
+
/**
|
|
278
|
+
* Parse and execute a request from a .http file.
|
|
279
|
+
* Returns a native fetch Response.
|
|
280
|
+
*
|
|
281
|
+
* @param path Path to the .http file
|
|
282
|
+
* @param options Optional variables, timeout, or abort signal
|
|
283
|
+
*/
|
|
284
|
+
run(path: string, options?: RunOptions): Promise<Response>;
|
|
285
|
+
/**
|
|
286
|
+
* Parse and execute a request from in-memory `.http` content.
|
|
287
|
+
* Useful for editors, TUI previews, and Tauri renderer execution.
|
|
288
|
+
*/
|
|
289
|
+
runString(content: string, options?: RunOptions): Promise<Response>;
|
|
290
|
+
/** Merge new variables with existing ones */
|
|
291
|
+
setVariables(vars: Record<string, unknown>): void;
|
|
292
|
+
/** Set a single variable */
|
|
293
|
+
setVariable(key: string, value: unknown): void;
|
|
294
|
+
/** Get a copy of all current variables */
|
|
295
|
+
getVariables(): Record<string, unknown>;
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAMhE;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,SAAS;IACxB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,aAAa;IAC5B,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,gEAAg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U,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3D;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpE,6CAA6C;IAC7C,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAElD,4BAA4B;IAC5B,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAE/C,0CAA0C;IAC1C,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fluent builder for constructing objects with optional properties.
|
|
3
|
+
* Eliminates verbose conditional spread patterns.
|
|
4
|
+
*/
|
|
5
|
+
export interface OptionalBuilder<T extends object> {
|
|
6
|
+
/**
|
|
7
|
+
* Add properties when a condition is true.
|
|
8
|
+
*/
|
|
9
|
+
when<K extends keyof T>(condition: boolean, props: Pick<Required<T>, K>): OptionalBuilder<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Add a property if its value is defined (not undefined).
|
|
12
|
+
*/
|
|
13
|
+
ifDefined<K extends keyof T>(key: K, value: T[K] | undefined): OptionalBuilder<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Return the built object.
|
|
16
|
+
*/
|
|
17
|
+
build(): T;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a fluent builder for constructing objects with optional properties.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Instead of:
|
|
25
|
+
* const obj = {
|
|
26
|
+
* method,
|
|
27
|
+
* url,
|
|
28
|
+
* ...(body !== undefined && { body }),
|
|
29
|
+
* ...(timeout !== undefined && { timeout })
|
|
30
|
+
* };
|
|
31
|
+
*
|
|
32
|
+
* // Use:
|
|
33
|
+
* const obj = setOptional<Request>({ method, url })
|
|
34
|
+
* .ifDefined('body', body)
|
|
35
|
+
* .ifDefined('timeout', timeout)
|
|
36
|
+
* .build();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function setOptional<T extends object>(base: T): OptionalBuilder<T>;
|
|
40
|
+
//# sourceMappingURL=optional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../../src/utils/optional.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM;IAC/C;;OAEG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IAE7F;;OAEG;IACH,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IAElF;;OAEG;IACH,KAAK,IAAI,CAAC,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAwBzE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@t-req/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "HTTP request parsing, execution, and testing. Define requests in .http files, test them in isolation.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/tensorix-labs/t-req",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/tensorix-labs/t-req#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/tensorix-labs/t-req/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"http",
|
|
17
|
+
"api",
|
|
18
|
+
"testing",
|
|
19
|
+
"requests",
|
|
20
|
+
"bun",
|
|
21
|
+
"rest",
|
|
22
|
+
"http-client",
|
|
23
|
+
"api-testing",
|
|
24
|
+
"http-file",
|
|
25
|
+
"rest-client"
|
|
26
|
+
],
|
|
27
|
+
"author": "tensorix labs",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18",
|
|
30
|
+
"bun": ">=1.0.0"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "dist/index.js",
|
|
34
|
+
"types": "dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./engine": {
|
|
42
|
+
"types": "./dist/engine/index.d.ts",
|
|
43
|
+
"import": "./dist/engine/index.js",
|
|
44
|
+
"default": "./dist/engine/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./runtime": {
|
|
47
|
+
"types": "./dist/runtime/index.d.ts",
|
|
48
|
+
"import": "./dist/runtime/index.js",
|
|
49
|
+
"default": "./dist/runtime/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./config": {
|
|
52
|
+
"types": "./dist/config/index.d.ts",
|
|
53
|
+
"import": "./dist/config/index.js",
|
|
54
|
+
"default": "./dist/config/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./cookies": {
|
|
57
|
+
"types": "./dist/cookies.d.ts",
|
|
58
|
+
"import": "./dist/cookies.js",
|
|
59
|
+
"default": "./dist/cookies.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public",
|
|
64
|
+
"provenance": true
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"dist",
|
|
68
|
+
"README.md",
|
|
69
|
+
"LICENSE"
|
|
70
|
+
],
|
|
71
|
+
"scripts": {
|
|
72
|
+
"clean": "rm -rf dist",
|
|
73
|
+
"build": "bun run build:js && bun run build:types",
|
|
74
|
+
"build:js": "bun build --target node --minify --sourcemap --outdir ./dist --root ./src ./src/index.ts ./src/engine/index.ts ./src/runtime/index.ts ./src/config/index.ts ./src/cookies.ts",
|
|
75
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
76
|
+
"test": "bun test",
|
|
77
|
+
"test:e2e": "bun test test/e2e.test.ts",
|
|
78
|
+
"test:unit": "bun test --ignore test/e2e.test.ts",
|
|
79
|
+
"lint": "biome check .",
|
|
80
|
+
"lint:fix": "biome check --write .",
|
|
81
|
+
"format": "biome format --write .",
|
|
82
|
+
"check-types": "tsc -p tsconfig.build.json --noEmit",
|
|
83
|
+
"prepublishOnly": "bun run build && bun run test:unit"
|
|
84
|
+
},
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@types/bun": "latest",
|
|
87
|
+
"@types/tough-cookie": "^4.0.5"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"tough-cookie": "^6.0.0"
|
|
91
|
+
}
|
|
92
|
+
}
|