@tryghost/webhook-mock-receiver 2.3.15 → 2.3.17
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/lib/WebhookMockReceiver.js +29 -7
- package/package.json +6 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { AssertionError } = require('assert');
|
|
2
2
|
const { URL } = require('url');
|
|
3
|
-
const
|
|
3
|
+
const nockModule = require('nock');
|
|
4
|
+
const nock = nockModule.default || nockModule;
|
|
4
5
|
const pWaitFor = require('p-wait-for').default;
|
|
5
6
|
class WebhookMockReceiver {
|
|
6
7
|
constructor({ snapshotManager }) {
|
|
@@ -28,12 +29,33 @@ class WebhookMockReceiver {
|
|
|
28
29
|
const recordRequest = this.recordRequest;
|
|
29
30
|
|
|
30
31
|
this._receiver = nock(parsedURL.origin)
|
|
31
|
-
.post(parsedURL.pathname
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
.post(parsedURL.pathname)
|
|
33
|
+
.reply(
|
|
34
|
+
200,
|
|
35
|
+
async function (...args) {
|
|
36
|
+
if (args.length === 1) {
|
|
37
|
+
// Nock 15 passes a Fetch Request; older versions pass URI and body.
|
|
38
|
+
const request = args[0];
|
|
39
|
+
const text = await request.text();
|
|
40
|
+
let body = text;
|
|
41
|
+
if (
|
|
42
|
+
text &&
|
|
43
|
+
request.headers.get('content-type')?.includes('application/json')
|
|
44
|
+
) {
|
|
45
|
+
try {
|
|
46
|
+
body = JSON.parse(text);
|
|
47
|
+
} catch {
|
|
48
|
+
// Preserve non-JSON payloads, as Nock's body matcher does.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
recordRequest(body, { headers: Object.fromEntries(request.headers) });
|
|
52
|
+
} else {
|
|
53
|
+
recordRequest(args[1], this.req);
|
|
54
|
+
}
|
|
55
|
+
return { status: 'OK' };
|
|
56
|
+
},
|
|
57
|
+
{ 'Content-Length': '15' },
|
|
58
|
+
);
|
|
37
59
|
|
|
38
60
|
return this;
|
|
39
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/webhook-mock-receiver",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"repository": {
|
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"got": "16.0.0",
|
|
24
|
+
"nock": "15.0.1",
|
|
24
25
|
"sinon": "22.1.0"
|
|
25
26
|
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"nock": "^13.0.0 || ^14.0.0 || ^15.0.0"
|
|
29
|
+
},
|
|
26
30
|
"engines": {
|
|
27
31
|
"node": "^22.12.0 || >=24.0.0"
|
|
28
32
|
},
|
|
29
33
|
"scripts": {
|
|
30
34
|
"dev": "echo \"Implement me!\"",
|
|
31
|
-
"test": "NODE_ENV=testing vitest run --coverage",
|
|
35
|
+
"test": "NODE_ENV=testing vitest run --config ../../vitest.config.ts --root . --coverage",
|
|
32
36
|
"lint": "oxlint -c ../../.oxlintrc.json .",
|
|
33
37
|
"posttest": "pnpm run lint"
|
|
34
38
|
}
|