@verdaccio/hooks 6.0.0-6-next.44 → 6.0.0-6-next.45
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/CHANGELOG.md +9 -0
- package/build/notify-request.js +2 -2
- package/build/notify-request.js.map +1 -1
- package/package.json +9 -8
- package/src/notify-request.ts +2 -2
- package/test/notify-request.spec.ts +20 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @verdaccio/hooks
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.45
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0a6412ca9: refactor: got instead undici
|
|
8
|
+
- Updated dependencies [0a6412ca9]
|
|
9
|
+
- @verdaccio/core@6.0.0-6-next.75
|
|
10
|
+
- @verdaccio/logger@6.0.0-6-next.43
|
|
11
|
+
|
|
3
12
|
## 6.0.0-6-next.44
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/build/notify-request.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.notifyRequest = notifyRequest;
|
|
7
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
-
var
|
|
8
|
+
var _gotCjs = _interopRequireDefault(require("got-cjs"));
|
|
9
9
|
var _core = require("@verdaccio/core");
|
|
10
10
|
var _logger = require("@verdaccio/logger");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -14,7 +14,7 @@ async function notifyRequest(url, options) {
|
|
|
14
14
|
let response;
|
|
15
15
|
try {
|
|
16
16
|
debug('uri %o', url);
|
|
17
|
-
response =
|
|
17
|
+
response = _gotCjs.default.post(url, {
|
|
18
18
|
body: JSON.stringify(options.body),
|
|
19
19
|
method: 'POST',
|
|
20
20
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify-request.js","names":["_debug","_interopRequireDefault","require","
|
|
1
|
+
{"version":3,"file":"notify-request.js","names":["_debug","_interopRequireDefault","require","_gotCjs","_core","_logger","obj","__esModule","default","debug","buildDebug","notifyRequest","url","options","response","got","post","body","JSON","stringify","method","headers","status","json","HTTP_STATUS","BAD_REQUEST","Error","logger","info","content","err","error","errorMessage","message"],"sources":["../src/notify-request.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport got from 'got-cjs';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\n\nconst debug = buildDebug('verdaccio:hooks:request');\n\nexport type FetchOptions = {\n body: string;\n headers?: {};\n method?: string;\n};\n\nexport async function notifyRequest(url: string, options: FetchOptions): Promise<boolean> {\n let response;\n try {\n debug('uri %o', url);\n response = got.post(url, {\n body: JSON.stringify(options.body),\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n });\n debug('response.status %o', response.status);\n const body = await response.json();\n if (response.status >= HTTP_STATUS.BAD_REQUEST) {\n throw new Error(body);\n }\n\n logger.info(\n { content: options.body },\n 'The notification @{content} has been successfully dispatched'\n );\n return true;\n } catch (err: any) {\n debug('request error %o', err);\n logger.error(\n { errorMessage: err?.message },\n 'notify service has thrown an error: @{errorMessage}'\n );\n return false;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAA2C,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,yBAAyB,CAAC;AAQ5C,eAAeC,aAAaA,CAACC,GAAW,EAAEC,OAAqB,EAAoB;EACxF,IAAIC,QAAQ;EACZ,IAAI;IACFL,KAAK,CAAC,QAAQ,EAAEG,GAAG,CAAC;IACpBE,QAAQ,GAAGC,eAAG,CAACC,IAAI,CAACJ,GAAG,EAAE;MACvBK,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACN,OAAO,CAACI,IAAI,CAAC;MAClCG,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE;QAAE,cAAc,EAAE;MAAmB;IAChD,CAAC,CAAC;IACFZ,KAAK,CAAC,qBAAqB,EAAEK,QAAQ,CAACQ,MAAM,CAAC;IAC7C,MAAML,IAAI,GAAG,MAAMH,QAAQ,CAACS,IAAI,CAAC,CAAC;IAClC,IAAIT,QAAQ,CAACQ,MAAM,IAAIE,iBAAW,CAACC,WAAW,EAAE;MAC9C,MAAM,IAAIC,KAAK,CAACT,IAAI,CAAC;IACvB;IAEAU,cAAM,CAACC,IAAI,CACT;MAAEC,OAAO,EAAEhB,OAAO,CAACI;IAAK,CAAC,EACzB,8DACF,CAAC;IACD,OAAO,IAAI;EACb,CAAC,CAAC,OAAOa,GAAQ,EAAE;IACjBrB,KAAK,CAAC,kBAAkB,EAAEqB,GAAG,CAAC;IAC9BH,cAAM,CAACI,KAAK,CACV;MAAEC,YAAY,EAAEF,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG;IAAQ,CAAC,EAC9B,qDACF,CAAC;IACD,OAAO,KAAK;EACd;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/hooks",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.45",
|
|
4
4
|
"description": "loaders logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,20 +26,21 @@
|
|
|
26
26
|
"verdaccio"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
33
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
32
|
+
"@verdaccio/core": "6.0.0-6-next.75",
|
|
33
|
+
"@verdaccio/logger": "6.0.0-6-next.43",
|
|
34
34
|
"core-js": "3.30.2",
|
|
35
35
|
"debug": "4.3.4",
|
|
36
36
|
"handlebars": "4.7.7",
|
|
37
|
-
"
|
|
37
|
+
"got-cjs": "12.5.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@verdaccio/auth": "6.0.0-6-next.
|
|
41
|
-
"@verdaccio/config": "6.0.0-6-next.
|
|
42
|
-
"@verdaccio/types": "11.0.0-6-next.25"
|
|
40
|
+
"@verdaccio/auth": "6.0.0-6-next.54",
|
|
41
|
+
"@verdaccio/config": "6.0.0-6-next.75",
|
|
42
|
+
"@verdaccio/types": "11.0.0-6-next.25",
|
|
43
|
+
"nock": "13.2.9"
|
|
43
44
|
},
|
|
44
45
|
"funding": {
|
|
45
46
|
"type": "opencollective",
|
package/src/notify-request.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import buildDebug from 'debug';
|
|
2
|
-
import
|
|
2
|
+
import got from 'got-cjs';
|
|
3
3
|
|
|
4
4
|
import { HTTP_STATUS } from '@verdaccio/core';
|
|
5
5
|
import { logger } from '@verdaccio/logger';
|
|
@@ -16,7 +16,7 @@ export async function notifyRequest(url: string, options: FetchOptions): Promise
|
|
|
16
16
|
let response;
|
|
17
17
|
try {
|
|
18
18
|
debug('uri %o', url);
|
|
19
|
-
response =
|
|
19
|
+
response = got.post(url, {
|
|
20
20
|
body: JSON.stringify(options.body),
|
|
21
21
|
method: 'POST',
|
|
22
22
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nock from 'nock';
|
|
2
2
|
|
|
3
3
|
import { createRemoteUser, parseConfigFile } from '@verdaccio/config';
|
|
4
4
|
import { setup } from '@verdaccio/logger';
|
|
@@ -21,26 +21,21 @@ const domain = 'http://slack-service';
|
|
|
21
21
|
|
|
22
22
|
const options = {
|
|
23
23
|
path: '/foo?auth_token=mySecretToken',
|
|
24
|
-
method: 'POST',
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
describe('Notifications:: notifyRequest', () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
nock.cleanAll();
|
|
29
|
+
});
|
|
28
30
|
test('when sending a empty notification', async () => {
|
|
29
|
-
|
|
30
|
-
setGlobalDispatcher(mockAgent);
|
|
31
|
-
const mockClient = mockAgent.get(domain);
|
|
32
|
-
mockClient.intercept(options).reply(200, { body: 'test' });
|
|
31
|
+
nock(domain).post(options.path).reply(200, { body: 'test' });
|
|
33
32
|
|
|
34
33
|
const notificationResponse = await notify({}, {}, createRemoteUser('foo', []), 'bar');
|
|
35
34
|
expect(notificationResponse).toEqual([false]);
|
|
36
35
|
});
|
|
37
36
|
|
|
38
37
|
test('when sending a single notification', async () => {
|
|
39
|
-
|
|
40
|
-
setGlobalDispatcher(mockAgent);
|
|
41
|
-
const mockClient = mockAgent.get(domain);
|
|
42
|
-
mockClient.intercept(options).reply(200, { body: 'test' });
|
|
43
|
-
|
|
38
|
+
nock(domain).post(options.path).reply(200, { body: 'test' });
|
|
44
39
|
const notificationResponse = await notify(
|
|
45
40
|
{},
|
|
46
41
|
singleHeaderNotificationConfig,
|
|
@@ -48,14 +43,10 @@ describe('Notifications:: notifyRequest', () => {
|
|
|
48
43
|
'bar'
|
|
49
44
|
);
|
|
50
45
|
expect(notificationResponse).toEqual([true]);
|
|
51
|
-
await mockClient.close();
|
|
52
46
|
});
|
|
53
47
|
|
|
54
48
|
test('when notification endpoint is missing', async () => {
|
|
55
|
-
|
|
56
|
-
setGlobalDispatcher(mockAgent);
|
|
57
|
-
const mockClient = mockAgent.get(domain);
|
|
58
|
-
mockClient.intercept(options).reply(200, { body: 'test' });
|
|
49
|
+
nock(domain).post(options.path).reply(200, { body: 'test' });
|
|
59
50
|
const name = 'package';
|
|
60
51
|
const config: Partial<Config> = {
|
|
61
52
|
// @ts-ignore
|
|
@@ -70,16 +61,22 @@ describe('Notifications:: notifyRequest', () => {
|
|
|
70
61
|
});
|
|
71
62
|
|
|
72
63
|
test('when multiple notifications', async () => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
nock(domain)
|
|
65
|
+
.post(options.path)
|
|
66
|
+
.once()
|
|
67
|
+
.reply(200, { body: 'test' })
|
|
68
|
+
.post(options.path)
|
|
69
|
+
.once()
|
|
70
|
+
.reply(400, {})
|
|
71
|
+
.post(options.path)
|
|
72
|
+
.once()
|
|
73
|
+
.reply(500, { message: 'Something bad happened' });
|
|
74
|
+
// mockClient.intercept(options).reply(200, { body: 'test' });
|
|
75
|
+
// mockClient.intercept(options).reply(400, {});
|
|
76
|
+
// mockClient.intercept(options).reply(500, { message: 'Something bad happened' });
|
|
79
77
|
|
|
80
78
|
const name = 'package';
|
|
81
79
|
const responses = await notify({ name }, multiNotificationConfig, { name: 'foo' }, 'bar');
|
|
82
80
|
expect(responses).toEqual([true, false, false]);
|
|
83
|
-
await mockClient.close();
|
|
84
81
|
});
|
|
85
82
|
});
|