@jaredwray/mockhttp 0.4.3 → 0.5.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/dist/index.d.ts +6 -0
- package/dist/index.js +164 -12
- package/package.json +11 -10
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ type HttpBinOptions = {
|
|
|
7
7
|
requestInspection?: boolean;
|
|
8
8
|
responseInspection?: boolean;
|
|
9
9
|
statusCodes?: boolean;
|
|
10
|
+
cookies?: boolean;
|
|
10
11
|
};
|
|
11
12
|
type MockHttpOptions = {
|
|
12
13
|
/**
|
|
@@ -157,6 +158,11 @@ declare class MockHttp extends Hookified {
|
|
|
157
158
|
* @param fastifyInstance - the server instance to register the routes on.
|
|
158
159
|
*/
|
|
159
160
|
registerRedirectRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Register the cookie routes.
|
|
163
|
+
* @param fastifyInstance - the server instance to register the routes on.
|
|
164
|
+
*/
|
|
165
|
+
registerCookieRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
|
|
160
166
|
}
|
|
161
167
|
|
|
162
168
|
declare const start: () => Promise<MockHttp>;
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import fastifyStatic from "@fastify/static";
|
|
10
10
|
import fastifyHelmet from "@fastify/helmet";
|
|
11
11
|
import { fastifySwagger } from "@fastify/swagger";
|
|
12
|
+
import fastifyCookie from "@fastify/cookie";
|
|
12
13
|
import Fastify from "fastify";
|
|
13
14
|
import { Hookified } from "hookified";
|
|
14
15
|
import { detect } from "detect-port";
|
|
@@ -19,7 +20,7 @@ import { fastifySwaggerUi } from "@fastify/swagger-ui";
|
|
|
19
20
|
// package.json
|
|
20
21
|
var package_default = {
|
|
21
22
|
name: "@jaredwray/mockhttp",
|
|
22
|
-
version: "0.
|
|
23
|
+
version: "0.5.0",
|
|
23
24
|
description: "Mock Http - Easy way to mock http with httpbin replacement",
|
|
24
25
|
type: "module",
|
|
25
26
|
main: "dist/index.js",
|
|
@@ -37,7 +38,7 @@ var package_default = {
|
|
|
37
38
|
"docker:readme": "tsx ./scripts/create-docker-readme.ts",
|
|
38
39
|
"docker:compose:up": "docker-compose up -d",
|
|
39
40
|
"docker:compose:down": "docker-compose down",
|
|
40
|
-
prepare: "
|
|
41
|
+
prepare: "pnpm run build",
|
|
41
42
|
start: "node dist/index.js"
|
|
42
43
|
},
|
|
43
44
|
repository: {
|
|
@@ -57,25 +58,26 @@ var package_default = {
|
|
|
57
58
|
},
|
|
58
59
|
homepage: "https://github.com/jaredwray/mockhttp#readme",
|
|
59
60
|
devDependencies: {
|
|
60
|
-
"@swc/core": "^1.11.
|
|
61
|
+
"@swc/core": "^1.11.24",
|
|
61
62
|
"@types/html-escaper": "^3.0.4",
|
|
62
|
-
"@vitest/coverage-v8": "^3.1.
|
|
63
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
63
64
|
rimraf: "^6.0.1",
|
|
64
65
|
tsup: "^8.4.0",
|
|
65
|
-
tsx: "^4.19.
|
|
66
|
+
tsx: "^4.19.4",
|
|
66
67
|
typescript: "^5.8.3",
|
|
67
|
-
vitest: "^3.1.
|
|
68
|
+
vitest: "^3.1.3",
|
|
68
69
|
xo: "^0.60.0"
|
|
69
70
|
},
|
|
70
71
|
dependencies: {
|
|
72
|
+
"@fastify/cookie": "^11.0.2",
|
|
71
73
|
"@fastify/helmet": "^13.0.1",
|
|
72
74
|
"@fastify/static": "^8.1.1",
|
|
73
|
-
"@fastify/swagger": "^9.
|
|
75
|
+
"@fastify/swagger": "^9.5.1",
|
|
74
76
|
"@fastify/swagger-ui": "^5.2.2",
|
|
75
|
-
"@scalar/api-reference": "^1.28.
|
|
77
|
+
"@scalar/api-reference": "^1.28.32",
|
|
76
78
|
"detect-port": "^2.1.0",
|
|
77
|
-
fastify: "^5.
|
|
78
|
-
hookified: "^1.
|
|
79
|
+
fastify: "^5.3.2",
|
|
80
|
+
hookified: "^1.9.0",
|
|
79
81
|
"html-escaper": "^3.0.3",
|
|
80
82
|
pino: "^9.6.0",
|
|
81
83
|
"pino-pretty": "^13.0.0"
|
|
@@ -1270,6 +1272,141 @@ var redirectToRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1270
1272
|
}, handler);
|
|
1271
1273
|
}, "redirectToRoute");
|
|
1272
1274
|
|
|
1275
|
+
// src/routes/cookies/get.ts
|
|
1276
|
+
var getCookiesRouteSchema = {
|
|
1277
|
+
description: "Return cookies from the request",
|
|
1278
|
+
tags: [
|
|
1279
|
+
"Cookies"
|
|
1280
|
+
],
|
|
1281
|
+
response: {
|
|
1282
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1283
|
+
200: {
|
|
1284
|
+
type: "object",
|
|
1285
|
+
properties: {
|
|
1286
|
+
cookies: {
|
|
1287
|
+
type: "object",
|
|
1288
|
+
additionalProperties: {
|
|
1289
|
+
type: "string"
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
required: [
|
|
1294
|
+
"cookies"
|
|
1295
|
+
]
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
var getCookiesRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1300
|
+
fastify.get("/cookies", {
|
|
1301
|
+
schema: getCookiesRouteSchema
|
|
1302
|
+
}, async (request, reply) => {
|
|
1303
|
+
await reply.send({
|
|
1304
|
+
cookies: request.cookies
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
}, "getCookiesRoute");
|
|
1308
|
+
|
|
1309
|
+
// src/routes/cookies/post.ts
|
|
1310
|
+
var postCookieRouteSchema = {
|
|
1311
|
+
description: "Set a cookie",
|
|
1312
|
+
tags: [
|
|
1313
|
+
"Cookies"
|
|
1314
|
+
],
|
|
1315
|
+
body: {
|
|
1316
|
+
type: "object",
|
|
1317
|
+
properties: {
|
|
1318
|
+
name: {
|
|
1319
|
+
type: "string"
|
|
1320
|
+
},
|
|
1321
|
+
value: {
|
|
1322
|
+
type: "string"
|
|
1323
|
+
},
|
|
1324
|
+
expires: {
|
|
1325
|
+
type: "string",
|
|
1326
|
+
format: "date-time"
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
required: [
|
|
1330
|
+
"name",
|
|
1331
|
+
"value"
|
|
1332
|
+
],
|
|
1333
|
+
additionalProperties: false
|
|
1334
|
+
},
|
|
1335
|
+
response: {
|
|
1336
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1337
|
+
200: {
|
|
1338
|
+
type: "object",
|
|
1339
|
+
properties: {
|
|
1340
|
+
cookies: {
|
|
1341
|
+
type: "object",
|
|
1342
|
+
additionalProperties: {
|
|
1343
|
+
type: "string"
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
required: [
|
|
1348
|
+
"cookies"
|
|
1349
|
+
]
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
var postCookieRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1354
|
+
fastify.post("/cookies", {
|
|
1355
|
+
schema: postCookieRouteSchema
|
|
1356
|
+
}, async (request, reply) => {
|
|
1357
|
+
const { name, value, expires } = request.body;
|
|
1358
|
+
if (expires) {
|
|
1359
|
+
const date = new Date(expires);
|
|
1360
|
+
reply.setCookie(name, value, {
|
|
1361
|
+
path: "/",
|
|
1362
|
+
expires: date
|
|
1363
|
+
});
|
|
1364
|
+
} else {
|
|
1365
|
+
reply.setCookie(name, value, {
|
|
1366
|
+
path: "/"
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
return reply.status(200).send();
|
|
1370
|
+
});
|
|
1371
|
+
}, "postCookieRoute");
|
|
1372
|
+
|
|
1373
|
+
// src/routes/cookies/delete.ts
|
|
1374
|
+
var cookiesDeleteSchema = {
|
|
1375
|
+
description: "Delete a cookie",
|
|
1376
|
+
tags: [
|
|
1377
|
+
"Cookies"
|
|
1378
|
+
],
|
|
1379
|
+
querystring: {
|
|
1380
|
+
type: "object",
|
|
1381
|
+
properties: {
|
|
1382
|
+
name: {
|
|
1383
|
+
type: "string"
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
required: [
|
|
1387
|
+
"name"
|
|
1388
|
+
],
|
|
1389
|
+
additionalProperties: false
|
|
1390
|
+
},
|
|
1391
|
+
response: {
|
|
1392
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1393
|
+
204: {
|
|
1394
|
+
type: "null"
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
var deleteCookieRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1399
|
+
fastify.delete("/cookies", {
|
|
1400
|
+
schema: cookiesDeleteSchema
|
|
1401
|
+
}, async (request, reply) => {
|
|
1402
|
+
const { name } = request.query;
|
|
1403
|
+
reply.clearCookie(name, {
|
|
1404
|
+
path: "/"
|
|
1405
|
+
});
|
|
1406
|
+
return reply.status(204).send();
|
|
1407
|
+
});
|
|
1408
|
+
}, "deleteCookieRoute");
|
|
1409
|
+
|
|
1273
1410
|
// src/mock-http.ts
|
|
1274
1411
|
var MockHttp = class extends Hookified {
|
|
1275
1412
|
static {
|
|
@@ -1285,7 +1422,8 @@ var MockHttp = class extends Hookified {
|
|
|
1285
1422
|
redirects: true,
|
|
1286
1423
|
requestInspection: true,
|
|
1287
1424
|
responseInspection: true,
|
|
1288
|
-
statusCodes: true
|
|
1425
|
+
statusCodes: true,
|
|
1426
|
+
cookies: true
|
|
1289
1427
|
};
|
|
1290
1428
|
// eslint-disable-next-line new-cap
|
|
1291
1429
|
_server = Fastify();
|
|
@@ -1426,7 +1564,7 @@ var MockHttp = class extends Hookified {
|
|
|
1426
1564
|
if (this._apiDocs) {
|
|
1427
1565
|
await this.registerApiDocs();
|
|
1428
1566
|
}
|
|
1429
|
-
const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2 } = this._httpBin;
|
|
1567
|
+
const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2, cookies } = this._httpBin;
|
|
1430
1568
|
if (httpMethods) {
|
|
1431
1569
|
await this.registerHttpMethods();
|
|
1432
1570
|
}
|
|
@@ -1442,6 +1580,9 @@ var MockHttp = class extends Hookified {
|
|
|
1442
1580
|
if (redirects) {
|
|
1443
1581
|
await this.registerRedirectRoutes();
|
|
1444
1582
|
}
|
|
1583
|
+
if (cookies) {
|
|
1584
|
+
await this.registerCookieRoutes();
|
|
1585
|
+
}
|
|
1445
1586
|
if (this._autoDetectPort) {
|
|
1446
1587
|
const originalPort = this._port;
|
|
1447
1588
|
this._port = await this.detectPort();
|
|
@@ -1531,6 +1672,17 @@ var MockHttp = class extends Hookified {
|
|
|
1531
1672
|
await fastify.register(relativeRedirectRoute);
|
|
1532
1673
|
await fastify.register(redirectToRoute);
|
|
1533
1674
|
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Register the cookie routes.
|
|
1677
|
+
* @param fastifyInstance - the server instance to register the routes on.
|
|
1678
|
+
*/
|
|
1679
|
+
async registerCookieRoutes(fastifyInstance) {
|
|
1680
|
+
const fastify = fastifyInstance ?? this._server;
|
|
1681
|
+
await fastify.register(fastifyCookie);
|
|
1682
|
+
await fastify.register(getCookiesRoute);
|
|
1683
|
+
await fastify.register(postCookieRoute);
|
|
1684
|
+
await fastify.register(deleteCookieRoute);
|
|
1685
|
+
}
|
|
1534
1686
|
};
|
|
1535
1687
|
|
|
1536
1688
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaredwray/mockhttp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Mock Http - Easy way to mock http with httpbin replacement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"docker:readme": "tsx ./scripts/create-docker-readme.ts",
|
|
19
19
|
"docker:compose:up": "docker-compose up -d",
|
|
20
20
|
"docker:compose:down": "docker-compose down",
|
|
21
|
-
"prepare": "
|
|
21
|
+
"prepare": "pnpm run build",
|
|
22
22
|
"start": "node dist/index.js"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
@@ -38,25 +38,26 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/jaredwray/mockhttp#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@swc/core": "^1.11.
|
|
41
|
+
"@swc/core": "^1.11.24",
|
|
42
42
|
"@types/html-escaper": "^3.0.4",
|
|
43
|
-
"@vitest/coverage-v8": "^3.1.
|
|
43
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
44
44
|
"rimraf": "^6.0.1",
|
|
45
45
|
"tsup": "^8.4.0",
|
|
46
|
-
"tsx": "^4.19.
|
|
46
|
+
"tsx": "^4.19.4",
|
|
47
47
|
"typescript": "^5.8.3",
|
|
48
|
-
"vitest": "^3.1.
|
|
48
|
+
"vitest": "^3.1.3",
|
|
49
49
|
"xo": "^0.60.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@fastify/cookie": "^11.0.2",
|
|
52
53
|
"@fastify/helmet": "^13.0.1",
|
|
53
54
|
"@fastify/static": "^8.1.1",
|
|
54
|
-
"@fastify/swagger": "^9.
|
|
55
|
+
"@fastify/swagger": "^9.5.1",
|
|
55
56
|
"@fastify/swagger-ui": "^5.2.2",
|
|
56
|
-
"@scalar/api-reference": "^1.28.
|
|
57
|
+
"@scalar/api-reference": "^1.28.32",
|
|
57
58
|
"detect-port": "^2.1.0",
|
|
58
|
-
"fastify": "^5.
|
|
59
|
-
"hookified": "^1.
|
|
59
|
+
"fastify": "^5.3.2",
|
|
60
|
+
"hookified": "^1.9.0",
|
|
60
61
|
"html-escaper": "^3.0.3",
|
|
61
62
|
"pino": "^9.6.0",
|
|
62
63
|
"pino-pretty": "^13.0.0"
|