@jaredwray/mockhttp 1.4.0 → 1.5.1

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 CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@jaredwray/mockhttp",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Mock Http - Easy way to mock http with httpbin replacement",
5
5
  "type": "module",
6
- "main": "dist/index.js",
6
+ "main": "dist/index.mjs",
7
+ "types": "dist/index.d.mts",
7
8
  "directories": {
8
9
  "test": "test"
9
10
  },
@@ -12,7 +13,8 @@
12
13
  "test": "pnpm lint && vitest run --coverage",
13
14
  "test:ci": "biome check --error-on-warnings && vitest run --coverage",
14
15
  "dev": "pnpm lint && tsx src/index.ts --watch",
15
- "build": "rimraf ./dist && tsup src/index.ts --format esm --dts --clean",
16
+ "build": "tsdown src/index.ts --format esm --dts",
17
+ "clean": "rimraf ./node_modules ./dist ./coverage DOCKER.md",
16
18
  "docker:build": "docker build -t jaredwray/mockhttp .",
17
19
  "docker:run": "docker run -p 3000:3000 jaredwray/mockhttp",
18
20
  "docker:push": "docker push jaredwray/mockhttp",
@@ -20,8 +22,8 @@
20
22
  "docker:readme": "tsx ./scripts/create-docker-readme.ts",
21
23
  "docker:compose:up": "docker-compose up -d",
22
24
  "docker:compose:down": "docker-compose down",
23
- "prepare": "pnpm run build",
24
- "start": "node dist/index.js"
25
+ "prepublishOnly": "pnpm run build",
26
+ "start": "node dist/index.mjs"
25
27
  },
26
28
  "repository": {
27
29
  "type": "git",
@@ -51,27 +53,27 @@
51
53
  },
52
54
  "homepage": "https://github.com/jaredwray/mockhttp#readme",
53
55
  "devDependencies": {
54
- "@biomejs/biome": "^2.3.14",
55
- "@swc/core": "^1.15.11",
56
+ "@biomejs/biome": "^2.4.11",
57
+ "@swc/core": "^1.15.24",
56
58
  "@types/html-escaper": "^3.0.4",
57
- "@vitest/coverage-v8": "^4.0.18",
58
- "rimraf": "^6.1.2",
59
- "tsup": "^8.5.1",
59
+ "@vitest/coverage-v8": "^4.1.4",
60
+ "rimraf": "^6.1.3",
61
+ "tsdown": "^0.21.7",
60
62
  "tsx": "^4.21.0",
61
- "typescript": "^5.9.3",
62
- "vitest": "^4.0.18"
63
+ "typescript": "6.0.2",
64
+ "vitest": "^4.1.4"
63
65
  },
64
66
  "dependencies": {
65
67
  "@fastify/cookie": "^11.0.2",
66
68
  "@fastify/helmet": "^13.0.2",
67
69
  "@fastify/rate-limit": "^10.3.0",
68
- "@fastify/static": "^9.0.0",
70
+ "@fastify/static": "^9.1.0",
69
71
  "@fastify/swagger": "^9.7.0",
70
72
  "@fastify/swagger-ui": "^5.2.5",
71
- "@scalar/api-reference": "^1.44.16",
73
+ "@scalar/api-reference": "^1.52.1",
72
74
  "detect-port": "^2.1.0",
73
- "fastify": "^5.7.4",
74
- "hookified": "^1.15.1",
75
+ "fastify": "^5.8.4",
76
+ "hookified": "^2.1.1",
75
77
  "html-escaper": "^3.0.3",
76
78
  "pino": "^10.3.1",
77
79
  "pino-pretty": "^13.1.3"
@@ -84,6 +86,14 @@
84
86
  "pnpm": {
85
87
  "overrides": {
86
88
  "set-cookie-parser": "2.7.2"
87
- }
89
+ },
90
+ "onlyBuiltDependencies": [
91
+ "@swc/core",
92
+ "core-js",
93
+ "esbuild",
94
+ "protobufjs",
95
+ "unrs-resolver",
96
+ "vue-demi"
97
+ ]
88
98
  }
89
99
  }
package/dist/index.d.ts DELETED
@@ -1,456 +0,0 @@
1
- import { RateLimitPluginOptions } from '@fastify/rate-limit';
2
- import { FastifyRequest, FastifyInstance } from 'fastify';
3
- import { Hookified, HookifiedOptions } from 'hookified';
4
-
5
- type CertificateOptions = {
6
- /**
7
- * Common Name for the certificate subject. Defaults to 'localhost'.
8
- */
9
- commonName?: string;
10
- /**
11
- * Subject Alternative Names. Defaults to [dns:localhost, ip:127.0.0.1, ip:::1].
12
- */
13
- altNames?: Array<{
14
- type: "dns";
15
- value: string;
16
- } | {
17
- type: "ip";
18
- value: string;
19
- }>;
20
- /**
21
- * Number of days the certificate is valid. Defaults to 365.
22
- */
23
- validityDays?: number;
24
- /**
25
- * RSA key size in bits. Defaults to 2048.
26
- */
27
- keySize?: number;
28
- };
29
- type CertificateResult = {
30
- /**
31
- * PEM-encoded X.509 certificate.
32
- */
33
- cert: string;
34
- /**
35
- * PEM-encoded PKCS#8 private key.
36
- */
37
- key: string;
38
- };
39
- type CertificateFileOptions = CertificateOptions & {
40
- /**
41
- * File path to write the certificate PEM.
42
- */
43
- certPath: string;
44
- /**
45
- * File path to write the private key PEM.
46
- */
47
- keyPath: string;
48
- };
49
- /**
50
- * Generate a self-signed certificate using only Node.js built-in crypto.
51
- * Returns PEM-encoded certificate and private key strings.
52
- */
53
- declare function generateCertificate(options?: CertificateOptions): CertificateResult;
54
- /**
55
- * Generate a self-signed certificate and write PEM files to disk.
56
- * Returns the same CertificateResult as generateCertificate().
57
- */
58
- declare function generateCertificateFiles(options: CertificateFileOptions): Promise<CertificateResult>;
59
-
60
- /**
61
- * Configuration for the injected response
62
- */
63
- type InjectionResponse = {
64
- /**
65
- * The response body (can be string, object, or buffer)
66
- */
67
- response: string | Record<string, unknown> | Buffer;
68
- /**
69
- * HTTP status code for the response
70
- * @default 200
71
- */
72
- statusCode?: number;
73
- /**
74
- * Response headers
75
- */
76
- headers?: Record<string, string | string[]>;
77
- };
78
- /**
79
- * Criteria for matching requests to inject responses
80
- */
81
- type InjectionMatcher = {
82
- /**
83
- * URL path to match (supports wildcards with *)
84
- * @example "/api/users" - exact match
85
- * @example "/api/*" - wildcard match
86
- */
87
- url?: string;
88
- /**
89
- * Hostname to match
90
- * @example "localhost"
91
- * @example "api.example.com"
92
- */
93
- hostname?: string;
94
- /**
95
- * HTTP method to match
96
- * @example "GET"
97
- * @example "POST"
98
- */
99
- method?: string;
100
- /**
101
- * Request headers to match (all specified headers must match)
102
- */
103
- headers?: Record<string, string>;
104
- };
105
- /**
106
- * Function that returns an injection response
107
- */
108
- type InjectionResponseFunction = (request: FastifyRequest) => InjectionResponse;
109
- /**
110
- * A tap represents an active injection that can be removed later
111
- */
112
- type InjectionTap = {
113
- /**
114
- * Unique identifier for this injection
115
- */
116
- id: string;
117
- /**
118
- * The response configuration or a function that returns it
119
- */
120
- response: InjectionResponse | InjectionResponseFunction;
121
- /**
122
- * The request matcher configuration
123
- */
124
- matcher?: InjectionMatcher;
125
- };
126
- /**
127
- * Manages HTTP response injections for testing and mocking
128
- */
129
- declare class TapManager {
130
- private _injections;
131
- constructor();
132
- /**
133
- * Get all active injection taps
134
- */
135
- get injections(): Map<string, InjectionTap>;
136
- /**
137
- * Check if there are any active injections
138
- */
139
- get hasInjections(): boolean;
140
- /**
141
- * Inject a custom response for requests matching the given criteria
142
- * @param response - The response configuration or a function that returns it
143
- * @param matcher - Optional criteria to match requests
144
- * @returns A tap object that can be used to remove the injection
145
- */
146
- inject(response: InjectionResponse | InjectionResponseFunction, matcher?: InjectionMatcher): InjectionTap;
147
- /**
148
- * Remove an injection by its tap object or ID
149
- * @param tapOrId - The tap object or tap ID to remove
150
- * @returns true if the injection was removed, false if it wasn't found
151
- */
152
- removeInjection(tapOrId: InjectionTap | string): boolean;
153
- /**
154
- * Find the first injection that matches the given request
155
- * @param request - The Fastify request object
156
- * @returns The matching injection tap, or undefined if no match
157
- */
158
- matchRequest(request: FastifyRequest): InjectionTap | undefined;
159
- /**
160
- * Clear all injections
161
- */
162
- clear(): void;
163
- /**
164
- * Check if a request matches the given matcher criteria
165
- * @param request - The Fastify request object
166
- * @param matcher - The matcher criteria (undefined matches all requests)
167
- * @returns true if the request matches
168
- */
169
- private requestMatches;
170
- /**
171
- * Check if a URL matches a pattern (supports wildcards with *)
172
- * @param url - The URL to test
173
- * @param pattern - The pattern to match against
174
- * @returns true if the URL matches the pattern
175
- */
176
- private urlMatches;
177
- }
178
-
179
- type HttpBinOptions = {
180
- httpMethods?: boolean;
181
- redirects?: boolean;
182
- requestInspection?: boolean;
183
- responseInspection?: boolean;
184
- statusCodes?: boolean;
185
- responseFormats?: boolean;
186
- cookies?: boolean;
187
- anything?: boolean;
188
- auth?: boolean;
189
- images?: boolean;
190
- dynamicData?: boolean;
191
- };
192
- type HttpsOptions = {
193
- /**
194
- * PEM-encoded certificate string, or file path to a certificate PEM file.
195
- */
196
- cert?: string;
197
- /**
198
- * PEM-encoded private key string, or file path to a private key PEM file.
199
- */
200
- key?: string;
201
- /**
202
- * If true, auto-generate a self-signed certificate. Defaults to true when no cert/key provided.
203
- */
204
- autoGenerate?: boolean;
205
- /**
206
- * Options for auto-generating a self-signed certificate. Only used when auto-generating.
207
- */
208
- certificateOptions?: CertificateOptions;
209
- };
210
- type MockHttpOptions = {
211
- /**
212
- * The port to listen on. If not provided, defaults to 3000 and detects the next available port if in use.
213
- */
214
- port?: number;
215
- /**
216
- * The host to listen on. If not provided, defaults to '0.0.0.0'.
217
- */
218
- host?: string;
219
- /**
220
- * Whether to automatically detect the next available port if the provided port is in use. Defaults
221
- * to true.
222
- */
223
- autoDetectPort?: boolean;
224
- /**
225
- * Whether to use Helmet for security headers. Defaults to true.
226
- */
227
- helmet?: boolean;
228
- /**
229
- * Whether to use Swagger for API documentation. Defaults to true.
230
- */
231
- apiDocs?: boolean;
232
- /**
233
- * Whether to use Swagger UI. Defaults to true.
234
- */
235
- httpBin?: HttpBinOptions;
236
- /**
237
- * Rate limiting options. Defaults to 1000 requests per minute (localhost excluded).
238
- * Set to undefined to disable rate limiting, or provide custom options to configure.
239
- */
240
- rateLimit?: boolean | RateLimitPluginOptions;
241
- /**
242
- * Hookified options.
243
- */
244
- hookOptions?: HookifiedOptions;
245
- /**
246
- * Whether to enable logging. Defaults to true.
247
- */
248
- logging?: boolean;
249
- /**
250
- * HTTPS configuration. Set to true to auto-generate a self-signed certificate,
251
- * or provide an object with cert/key strings/paths or auto-generation options.
252
- */
253
- https?: boolean | HttpsOptions;
254
- };
255
- declare class MockHttp extends Hookified {
256
- private _port;
257
- private _host;
258
- private _autoDetectPort;
259
- private _helmet;
260
- private _apiDocs;
261
- private _logging;
262
- private _httpBin;
263
- private _rateLimit?;
264
- private _https;
265
- private _httpsCredentials;
266
- private _server;
267
- private _taps;
268
- constructor(options?: MockHttpOptions);
269
- /**
270
- * The port to listen on. If not provided, defaults to 3000 and detects the next available port if in use.
271
- * @default 3000
272
- */
273
- get port(): number;
274
- /**
275
- * The port to listen on. If not provided, defaults to 3000 and detects the next available port if in use.
276
- * @default 3000
277
- */
278
- set port(port: number);
279
- /**
280
- * The host to listen on. If not provided, defaults to 'localhost'.
281
- * @default 'localhost'
282
- */
283
- get host(): string;
284
- /**
285
- * The host to listen on. If not provided, defaults to 'localhost'.
286
- * @default 'localhost'
287
- */
288
- set host(host: string);
289
- /**
290
- * Whether to automatically detect the next available port if the provided port is in use. Defaults to true.
291
- * @default true
292
- */
293
- get autoDetectPort(): boolean;
294
- /**
295
- * Whether to automatically detect the next available port if the provided port is in use. Defaults to true.
296
- * @default true
297
- */
298
- set autoDetectPort(autoDetectPort: boolean);
299
- /**
300
- * Whether to use Helmet for security headers. Defaults to true.
301
- * @default true
302
- */
303
- get helmet(): boolean;
304
- /**
305
- * Whether to use Helmet for security headers. Defaults to true.
306
- * @default true
307
- */
308
- set helmet(helmet: boolean);
309
- /**
310
- * Whether to use Swagger for API documentation. Defaults to true.
311
- * @default true
312
- */
313
- get apiDocs(): boolean;
314
- /**
315
- * Whether to use Swagger for API documentation. Defaults to true.
316
- * @default true
317
- */
318
- set apiDocs(apiDocs: boolean);
319
- /**
320
- * Whether to enable logging. Defaults to true.
321
- * @default true
322
- */
323
- get logging(): boolean;
324
- /**
325
- * Whether to enable logging. Defaults to true.
326
- * @default true
327
- */
328
- set logging(logging: boolean);
329
- /**
330
- * HTTPS configuration. Set to true to auto-generate a self-signed certificate,
331
- * or provide an HttpsOptions object with cert/key or auto-generation options.
332
- */
333
- get https(): HttpsOptions | undefined;
334
- /**
335
- * HTTPS configuration. Set to true to auto-generate a self-signed certificate,
336
- * or provide an HttpsOptions object with cert/key or auto-generation options.
337
- */
338
- set https(value: boolean | HttpsOptions | undefined);
339
- /**
340
- * Whether the server is running in HTTPS mode.
341
- */
342
- get isHttps(): boolean;
343
- /**
344
- * HTTP Bin options. Defaults to all enabled.
345
- */
346
- get httpBin(): HttpBinOptions;
347
- /**
348
- * HTTP Bin options. Defaults to all enabled.
349
- */
350
- set httpBin(httpBinary: HttpBinOptions);
351
- /**
352
- * Rate limiting options. Defaults to 1000 requests per minute (localhost excluded).
353
- * Set to undefined to disable rate limiting, or provide custom options to configure.
354
- * @default { max: 1000, timeWindow: "1 minute", allowList: ["127.0.0.1", "::1"] }
355
- */
356
- get rateLimit(): RateLimitPluginOptions | undefined;
357
- /**
358
- * Rate limiting options. Defaults to 1000 requests per minute (localhost excluded).
359
- * Set to undefined to disable rate limiting, or provide custom options to configure.
360
- *
361
- * Note: Changing this property requires restarting the server (close() then start()) for changes to take effect.
362
- * @default { max: 1000, timeWindow: "1 minute", allowList: ["127.0.0.1", "::1"] }
363
- */
364
- set rateLimit(rateLimit: RateLimitPluginOptions | undefined);
365
- /**
366
- * The Fastify server instance.
367
- */
368
- get server(): FastifyInstance;
369
- /**
370
- * The Fastify server instance.
371
- */
372
- set server(server: FastifyInstance);
373
- /**
374
- * The TapManager instance for managing injection taps.
375
- */
376
- get taps(): TapManager;
377
- /**
378
- * The TapManager instance for managing injection taps.
379
- */
380
- set taps(taps: TapManager);
381
- /**
382
- * Start the Fastify server. If the server is already running, it will be closed and restarted.
383
- */
384
- start(): Promise<void>;
385
- /**
386
- * Close the Fastify server.
387
- */
388
- close(): Promise<void>;
389
- /**
390
- * Detect the next available port to run on.
391
- * @returns The port that is available to run on
392
- */
393
- detectPort(): Promise<number>;
394
- /**
395
- * This will register the API documentation routes including openapi and swagger ui.
396
- * @param fastifyInstance - the server instance to register the routes on.
397
- */
398
- registerApiDocs(fastifyInstance?: FastifyInstance): Promise<void>;
399
- /**
400
- * Register the HTTP methods routes.
401
- * @param fastifyInstance - the server instance to register the routes on.
402
- */
403
- registerHttpMethods(fastifyInstance?: FastifyInstance): Promise<void>;
404
- /**
405
- * Register the status code routes.
406
- * @param fastifyInstance - the server instance to register the routes on.
407
- */
408
- registerStatusCodeRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
409
- /**
410
- * Register the request inspection routes.
411
- * @param fastifyInstance - the server instance to register the routes on.
412
- */
413
- registerRequestInspectionRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
414
- /**
415
- * Register the response inspection routes.
416
- * @param fastifyInstance - the server instance to register the routes on.
417
- */
418
- registerResponseInspectionRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
419
- registerResponseFormatRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
420
- /**
421
- * Register the redirect routes.
422
- * @param fastifyInstance - the server instance to register the routes on.
423
- */
424
- registerRedirectRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
425
- /**
426
- * Register the cookie routes.
427
- * @param fastifyInstance - the server instance to register the routes on.
428
- */
429
- registerCookieRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
430
- /**
431
- * Register the anything routes.
432
- * @param fastifyInstance - the server instance to register the routes on.
433
- */
434
- registerAnythingRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
435
- /**
436
- * Register the auth routes.
437
- * @param fastifyInstance - the server instance to register the routes on.
438
- */
439
- registerAuthRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
440
- /**
441
- * Register the image routes.
442
- * @param fastifyInstance - the server instance to register the routes on.
443
- */
444
- registerImageRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
445
- /**
446
- * Register the dynamic data routes.
447
- * @param fastifyInstance - the server instance to register the routes on.
448
- */
449
- registerDynamicDataRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
450
- private resolveHttpsCredentials;
451
- private loadPemValue;
452
- }
453
-
454
- declare const start: () => Promise<MockHttp>;
455
-
456
- export { type CertificateFileOptions, type CertificateOptions, type CertificateResult, type HttpsOptions, type InjectionMatcher, type InjectionResponse, type InjectionTap, MockHttp as default, generateCertificate, generateCertificateFiles, MockHttp as mockhttp, start };