@verdaccio/hooks 6.0.0-6-next.7 → 6.0.0-6-next.11
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 +44 -0
- package/build/notify-request.js +3 -3
- package/build/notify-request.js.map +1 -1
- package/build/notify.d.ts +1 -1
- package/build/notify.js +9 -15
- package/build/notify.js.map +1 -1
- package/package.json +11 -12
- package/src/notify-request.ts +1 -1
- package/src/notify.ts +4 -4
- package/test/notify-request.spec.ts +2 -1
- package/tsconfig.json +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @verdaccio/hooks
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [730b5d8c]
|
|
8
|
+
- @verdaccio/logger@6.0.0-6-next.9
|
|
9
|
+
|
|
10
|
+
## 6.0.0-6-next.10
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [24b9be02]
|
|
15
|
+
- Updated dependencies [e75c0a3b]
|
|
16
|
+
- @verdaccio/core@6.0.0-6-next.4
|
|
17
|
+
- @verdaccio/logger@6.0.0-6-next.8
|
|
18
|
+
|
|
19
|
+
## 6.0.0-6-next.9
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [6c1eb021]
|
|
24
|
+
- @verdaccio/core@6.0.0-6-next.3
|
|
25
|
+
- @verdaccio/logger@6.0.0-6-next.7
|
|
26
|
+
|
|
27
|
+
## 6.0.0-6-next.8
|
|
28
|
+
|
|
29
|
+
### Major Changes
|
|
30
|
+
|
|
31
|
+
- 794af76c: Remove Node 12 support
|
|
32
|
+
|
|
33
|
+
- We need move to the new `undici` and does not support Node.js 12
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- b702ea36: abort search request support for proxy
|
|
38
|
+
- 154b2ecd: refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [794af76c]
|
|
43
|
+
- Updated dependencies [154b2ecd]
|
|
44
|
+
- @verdaccio/core@6.0.0-6-next.2
|
|
45
|
+
- @verdaccio/logger@6.0.0-6-next.6
|
|
46
|
+
|
|
3
47
|
## 6.0.0-6-next.7
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/build/notify-request.js
CHANGED
|
@@ -7,9 +7,9 @@ exports.notifyRequest = notifyRequest;
|
|
|
7
7
|
|
|
8
8
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _core = require("@verdaccio/core");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _logger = require("@verdaccio/logger");
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
@@ -32,7 +32,7 @@ async function notifyRequest(url, options) {
|
|
|
32
32
|
debug('response.status %o', response.status);
|
|
33
33
|
const body = await response.json();
|
|
34
34
|
|
|
35
|
-
if (response.status >=
|
|
35
|
+
if (response.status >= _core.HTTP_STATUS.BAD_REQUEST) {
|
|
36
36
|
throw new Error(body);
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/notify-request.ts"],"names":["debug","fetch","require","notifyRequest","url","options","response","body","JSON","stringify","method","headers","status","json","HTTP_STATUS","BAD_REQUEST","Error","logger","info","content","err","error","errorMessage","message"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;;;AAEA,MAAMA,KAAK,GAAG,oBAAW,yBAAX,CAAd;;AACA,MAAMC,KAAK,GAAGC,OAAO,CAAC,cAAD,CAArB;;AAQO,eAAeC,aAAf,CAA6BC,GAA7B,EAA0CC,OAA1C,EAAmF;AACxF,MAAIC,QAAJ;;AACA,MAAI;AACFN,IAAAA,KAAK,CAAC,QAAD,EAAWI,GAAX,CAAL;AACAE,IAAAA,QAAQ,GAAG,MAAML,KAAK,CAACG,GAAD,EAAM;AAC1BG,MAAAA,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeJ,OAAO,CAACE,IAAvB,CADoB;AAE1BG,MAAAA,MAAM,EAAE,MAFkB;AAG1BC,MAAAA,OAAO,EAAE;AAAE,wBAAgB;AAAlB;AAHiB,KAAN,CAAtB;AAKAX,IAAAA,KAAK,CAAC,qBAAD,EAAwBM,QAAQ,CAACM,MAAjC,CAAL;AACA,UAAML,IAAI,GAAG,MAAMD,QAAQ,CAACO,IAAT,EAAnB;;AACA,QAAIP,QAAQ,CAACM,MAAT,IAAmBE,
|
|
1
|
+
{"version":3,"sources":["../src/notify-request.ts"],"names":["debug","fetch","require","notifyRequest","url","options","response","body","JSON","stringify","method","headers","status","json","HTTP_STATUS","BAD_REQUEST","Error","logger","info","content","err","error","errorMessage","message"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;;;AAEA,MAAMA,KAAK,GAAG,oBAAW,yBAAX,CAAd;;AACA,MAAMC,KAAK,GAAGC,OAAO,CAAC,cAAD,CAArB;;AAQO,eAAeC,aAAf,CAA6BC,GAA7B,EAA0CC,OAA1C,EAAmF;AACxF,MAAIC,QAAJ;;AACA,MAAI;AACFN,IAAAA,KAAK,CAAC,QAAD,EAAWI,GAAX,CAAL;AACAE,IAAAA,QAAQ,GAAG,MAAML,KAAK,CAACG,GAAD,EAAM;AAC1BG,MAAAA,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeJ,OAAO,CAACE,IAAvB,CADoB;AAE1BG,MAAAA,MAAM,EAAE,MAFkB;AAG1BC,MAAAA,OAAO,EAAE;AAAE,wBAAgB;AAAlB;AAHiB,KAAN,CAAtB;AAKAX,IAAAA,KAAK,CAAC,qBAAD,EAAwBM,QAAQ,CAACM,MAAjC,CAAL;AACA,UAAML,IAAI,GAAG,MAAMD,QAAQ,CAACO,IAAT,EAAnB;;AACA,QAAIP,QAAQ,CAACM,MAAT,IAAmBE,kBAAYC,WAAnC,EAAgD;AAC9C,YAAM,IAAIC,KAAJ,CAAUT,IAAV,CAAN;AACD;;AAEDU,mBAAOC,IAAP,CACE;AAAEC,MAAAA,OAAO,EAAEd,OAAO,CAACE;AAAnB,KADF,EAEE,8DAFF;;AAIA,WAAO,IAAP;AACD,GAlBD,CAkBE,OAAOa,GAAP,EAAiB;AACjBpB,IAAAA,KAAK,CAAC,kBAAD,EAAqBoB,GAArB,CAAL;;AACAH,mBAAOI,KAAP,CACE;AAAEC,MAAAA,YAAY,EAAEF,GAAF,aAAEA,GAAF,uBAAEA,GAAG,CAAEG;AAArB,KADF,EAEE,qDAFF;;AAIA,WAAO,KAAP;AACD;AACF","sourcesContent":["import buildDebug from 'debug';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\n\nconst debug = buildDebug('verdaccio:hooks:request');\nconst fetch = require('undici-fetch');\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 = await fetch(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"],"file":"notify-request.js"}
|
package/build/notify.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, Package, RemoteUser
|
|
1
|
+
import { Config, Notification, Package, RemoteUser } from '@verdaccio/types';
|
|
2
2
|
export declare function compileTemplate(content: any, metadata: any): Promise<unknown>;
|
|
3
3
|
export declare function handleNotify(metadata: Partial<Package>, notifyEntry: any, remoteUser: Partial<RemoteUser>, publishedPackage: string): Promise<boolean>;
|
|
4
4
|
export declare function sendNotification(metadata: Partial<Package>, notify: Notification, remoteUser: Partial<RemoteUser>, publishedPackage: string): Promise<boolean>;
|
package/build/notify.js
CHANGED
|
@@ -5,27 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.compileTemplate = compileTemplate;
|
|
7
7
|
exports.handleNotify = handleNotify;
|
|
8
|
-
exports.sendNotification = sendNotification;
|
|
9
8
|
exports.notify = notify;
|
|
9
|
+
exports.sendNotification = sendNotification;
|
|
10
10
|
|
|
11
|
-
require("
|
|
11
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
12
12
|
|
|
13
13
|
var _handlebars = _interopRequireDefault(require("handlebars"));
|
|
14
14
|
|
|
15
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
16
|
-
|
|
17
15
|
var _logger = require("@verdaccio/logger");
|
|
18
16
|
|
|
19
17
|
var _notifyRequest = require("./notify-request");
|
|
20
18
|
|
|
21
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
26
|
-
|
|
27
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
28
|
-
|
|
21
|
+
/* eslint-disable no-undef */
|
|
29
22
|
const debug = (0, _debug.default)('verdaccio:hooks');
|
|
30
23
|
|
|
31
24
|
function compileTemplate(content, metadata) {
|
|
@@ -66,12 +59,12 @@ async function handleNotify(metadata, notifyEntry, remoteUser, publishedPackage)
|
|
|
66
59
|
|
|
67
60
|
if (typeof ((_metadata = metadata) === null || _metadata === void 0 ? void 0 : _metadata.publisher) === 'undefined' || ((_metadata2 = metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.publisher) === null) {
|
|
68
61
|
// @ts-ignore
|
|
69
|
-
metadata =
|
|
62
|
+
metadata = { ...metadata,
|
|
70
63
|
publishedPackage,
|
|
71
64
|
publisher: {
|
|
72
65
|
name: remoteUser.name
|
|
73
66
|
}
|
|
74
|
-
}
|
|
67
|
+
};
|
|
75
68
|
debug('template metadata %o', metadata);
|
|
76
69
|
content = await compileTemplate(notifyEntry.content, metadata);
|
|
77
70
|
}
|
|
@@ -103,9 +96,10 @@ async function handleNotify(metadata, notifyEntry, remoteUser, publishedPackage)
|
|
|
103
96
|
throw new Error('missing parameter');
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
return (0, _notifyRequest.notifyRequest)(notifyEntry.endpoint,
|
|
107
|
-
method: notifyEntry.method
|
|
108
|
-
|
|
99
|
+
return (0, _notifyRequest.notifyRequest)(notifyEntry.endpoint, {
|
|
100
|
+
method: notifyEntry.method,
|
|
101
|
+
...options
|
|
102
|
+
});
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
function sendNotification(metadata, notify, remoteUser, publishedPackage) {
|
package/build/notify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/notify.ts"],"names":["debug","compileTemplate","content","metadata","Promise","resolve","reject","handler","template","Handlebars","compile","error","handleNotify","notifyEntry","remoteUser","publishedPackage","regex","name","packagePattern","RegExp","packagePatternFlags","test","publisher","options","body","JSON","stringify","headers","Array","isArray","header","map","item","Object","is","key","hasOwnProperty","endpoint","Error","method","sendNotification","notify","config","isSingle","keys","includes","response","results","allSettled","keyId","catch","logger","promiseValue","value"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/notify.ts"],"names":["debug","compileTemplate","content","metadata","Promise","resolve","reject","handler","template","Handlebars","compile","error","handleNotify","notifyEntry","remoteUser","publishedPackage","regex","name","packagePattern","RegExp","packagePatternFlags","test","publisher","options","body","JSON","stringify","headers","Array","isArray","header","map","item","Object","is","key","hasOwnProperty","endpoint","Error","method","sendNotification","notify","config","isSingle","keys","includes","response","results","allSettled","keyId","catch","logger","promiseValue","value"],"mappings":";;;;;;;;;;AACA;;AACA;;AAEA;;AAGA;;;;AAPA;AASA,MAAMA,KAAK,GAAG,oBAAW,iBAAX,CAAd;;AAEO,SAASC,eAAT,CAAyBC,OAAzB,EAAkCC,QAAlC,EAA4C;AACjD;AACA,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtC,QAAIC,OAAJ;;AACA,QAAI;AACF,UAAI,CAACA,OAAL,EAAc;AACZP,QAAAA,KAAK,CAAC,qCAAD,EAAwCE,OAAxC,CAAL;;AACA,cAAMM,QAAoC,GAAGC,oBAAWC,OAAX,CAAmBR,OAAnB,CAA7C;;AACA,eAAOG,OAAO,CAACG,QAAQ,CAACL,QAAD,CAAT,CAAd;AACD;AACF,KAND,CAME,OAAOQ,KAAP,EAAmB;AACnBX,MAAAA,KAAK,CAAC,4BAAD,EAA+BW,KAA/B,CAAL;AACAL,MAAAA,MAAM,CAACK,KAAD,CAAN;AACD;AACF,GAZM,CAAP;AAaD;;AAEM,eAAeC,YAAf,CACLT,QADK,EAELU,WAFK,EAGLC,UAHK,EAILC,gBAJK,EAKa;AAAA;;AAClB,MAAIC,KAAJ;;AACA,MAAIb,QAAQ,CAACc,IAAT,IAAiBJ,WAAW,CAACK,cAAjC,EAAiD;AAC/CF,IAAAA,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MA,eAAO,CAAC+B,QAAD,CAAP;AACD,OARD,CAQE,MAAM;AACN9C,QAAAA,KAAK,CAAC,sCAAD,CAAL;AACA,eAAO,CAAC,KAAD,CAAP;AACD;AACF,KAdD,MAcO;AACLA,MAAAA,KAAK,CAAC,6BAAD,CAAL;AACA,YAAM+C,OAAO,GAAG,MAAM3C,OAAO,CAAC4C,UAAR,CACpBf,MAAM,CAACW,IAAP,CAAYF,MAAM,CAACD,MAAnB,EAA2BV,GAA3B,CAAgCkB,KAAD,IAAmB;AAChD;AACA,cAAMjB,IAAI,GAAGU,MAAM,CAACD,MAAP,CAAcQ,KAAd,CAAb;AACAjD,QAAAA,KAAK,CAAC,cAAD,EAAiBgC,IAAjB,CAAL;AACA,eAAOQ,gBAAgB,CAACrC,QAAD,EAAW6B,IAAX,EAAiBlB,UAAjB,EAA6BC,gBAA7B,CAAvB;AACD,OALD,CADoB,EAOpBmC,KAPoB,CAObvC,KAAD,IAAW;AACjBwC,uBAAOxC,KAAP,CAAa;AAAEA,UAAAA;AAAF,SAAb,EAAwB,mCAAxB;AACD,OATqB,CAAtB,CAFK,CAaL;;AACA,aAAOsB,MAAM,CAACW,IAAP,CAAYG,OAAZ,EAAqBhB,GAArB,CAA0BqB,YAAD,IAAkBL,OAAO,CAACK,YAAD,CAAP,CAAsBC,KAAjE,CAAP;AACD;AACF,GAhCD,MAgCO;AACLrD,IAAAA,KAAK,CAAC,yCAAD,CAAL;AACA,WAAO,CAAC,KAAD,CAAP;AACD;AACF","sourcesContent":["/* eslint-disable no-undef */\nimport buildDebug from 'debug';\nimport Handlebars from 'handlebars';\n\nimport { logger } from '@verdaccio/logger';\nimport { Config, Notification, Package, RemoteUser } from '@verdaccio/types';\n\nimport { FetchOptions, notifyRequest } from './notify-request';\n\nconst debug = buildDebug('verdaccio:hooks');\n\nexport function compileTemplate(content, metadata) {\n // FUTURE: multiple handlers\n return new Promise((resolve, reject) => {\n let handler;\n try {\n if (!handler) {\n debug('compile default template handler %o', content);\n const template: HandlebarsTemplateDelegate = Handlebars.compile(content);\n return resolve(template(metadata));\n }\n } catch (error: any) {\n debug('error template handler %o', error);\n reject(error);\n }\n });\n}\n\nexport async function handleNotify(\n metadata: Partial<Package>,\n notifyEntry,\n remoteUser: Partial<RemoteUser>,\n publishedPackage: string\n): Promise<boolean> {\n let regex;\n if (metadata.name && notifyEntry.packagePattern) {\n regex = new RegExp(notifyEntry.packagePattern, notifyEntry.packagePatternFlags || '');\n if (!regex.test(metadata.name)) {\n return false;\n }\n }\n\n let content;\n // FIXME: publisher is not part of the expected types metadata\n // @ts-ignore\n if (typeof metadata?.publisher === 'undefined' || metadata?.publisher === null) {\n // @ts-ignore\n metadata = { ...metadata, publishedPackage, publisher: { name: remoteUser.name as string } };\n debug('template metadata %o', metadata);\n content = await compileTemplate(notifyEntry.content, metadata);\n }\n\n const options: FetchOptions = {\n body: JSON.stringify(content),\n };\n\n // provides fallback support, it's accept an Object {} and Array of {}\n if (notifyEntry.headers && Array.isArray(notifyEntry.headers)) {\n const header = {};\n // FIXME: we can simplify this\n notifyEntry.headers.map(function (item): void {\n if (Object.is(item, item)) {\n for (const key in item) {\n /* eslint no-prototype-builtins: 0 */\n if (item.hasOwnProperty(key)) {\n header[key] = item[key];\n }\n }\n }\n });\n options.headers = header;\n } else if (Object.is(notifyEntry.headers, notifyEntry.headers)) {\n options.headers = notifyEntry.headers;\n }\n\n if (!notifyEntry.endpoint) {\n debug('error due endpoint is missing');\n throw new Error('missing parameter');\n }\n\n return notifyRequest(notifyEntry.endpoint, {\n method: notifyEntry.method,\n ...options,\n });\n}\n\nexport function sendNotification(\n metadata: Partial<Package>,\n notify: Notification,\n remoteUser: Partial<RemoteUser>,\n publishedPackage: string\n): Promise<boolean> {\n return handleNotify(metadata, notify, remoteUser, publishedPackage) as Promise<any>;\n}\n\nexport async function notify(\n metadata: Partial<Package>,\n config: Partial<Config>,\n remoteUser: Partial<RemoteUser>,\n publishedPackage: string\n): Promise<boolean[]> {\n debug('init send notification');\n if (config.notify) {\n const isSingle = Object.keys(config.notify).includes('method');\n if (isSingle) {\n debug('send single notification');\n try {\n const response = await sendNotification(\n metadata,\n config.notify as Notification,\n remoteUser,\n publishedPackage\n );\n return [response];\n } catch {\n debug('error on sending single notification');\n return [false];\n }\n } else {\n debug('send multiples notification');\n const results = await Promise.allSettled(\n Object.keys(config.notify).map((keyId: string) => {\n // @ts-ignore\n const item = config.notify[keyId];\n debug('send item %o', item);\n return sendNotification(metadata, item, remoteUser, publishedPackage);\n })\n ).catch((error) => {\n logger.error({ error }, 'notify request has failed: @error');\n });\n\n // @ts-ignore\n return Object.keys(results).map((promiseValue) => results[promiseValue].value);\n }\n } else {\n debug('no notifications configuration detected');\n return [false];\n }\n}\n"],"file":"notify.js"}
|
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.11",
|
|
4
4
|
"description": "loaders logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,24 +26,23 @@
|
|
|
26
26
|
"verdaccio"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=14",
|
|
30
30
|
"npm": ">=6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/
|
|
34
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
35
|
-
"core-js": "3.
|
|
36
|
-
"debug": "4.3.
|
|
33
|
+
"@verdaccio/core": "6.0.0-6-next.4",
|
|
34
|
+
"@verdaccio/logger": "6.0.0-6-next.9",
|
|
35
|
+
"core-js": "3.20.2",
|
|
36
|
+
"debug": "4.3.3",
|
|
37
37
|
"handlebars": "4.7.7",
|
|
38
|
-
"undici": "4.
|
|
38
|
+
"undici": "4.12.2",
|
|
39
39
|
"undici-fetch": "1.0.0-rc.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "16.
|
|
43
|
-
"@verdaccio/auth": "6.0.0-6-next.
|
|
44
|
-
"@verdaccio/
|
|
45
|
-
"@verdaccio/
|
|
46
|
-
"@verdaccio/types": "11.0.0-6-next.8"
|
|
42
|
+
"@types/node": "16.11.19",
|
|
43
|
+
"@verdaccio/auth": "6.0.0-6-next.17",
|
|
44
|
+
"@verdaccio/config": "6.0.0-6-next.12",
|
|
45
|
+
"@verdaccio/types": "11.0.0-6-next.10"
|
|
47
46
|
},
|
|
48
47
|
"funding": {
|
|
49
48
|
"type": "opencollective",
|
package/src/notify-request.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import buildDebug from 'debug';
|
|
2
2
|
|
|
3
|
+
import { HTTP_STATUS } from '@verdaccio/core';
|
|
3
4
|
import { logger } from '@verdaccio/logger';
|
|
4
|
-
import { HTTP_STATUS } from '@verdaccio/commons-api';
|
|
5
5
|
|
|
6
6
|
const debug = buildDebug('verdaccio:hooks:request');
|
|
7
7
|
const fetch = require('undici-fetch');
|
package/src/notify.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
|
-
|
|
2
|
+
import buildDebug from 'debug';
|
|
3
3
|
import Handlebars from 'handlebars';
|
|
4
4
|
|
|
5
|
-
import buildDebug from 'debug';
|
|
6
|
-
import { Config, Package, RemoteUser, Notification } from '@verdaccio/types';
|
|
7
5
|
import { logger } from '@verdaccio/logger';
|
|
8
|
-
import {
|
|
6
|
+
import { Config, Notification, Package, RemoteUser } from '@verdaccio/types';
|
|
7
|
+
|
|
8
|
+
import { FetchOptions, notifyRequest } from './notify-request';
|
|
9
9
|
|
|
10
10
|
const debug = buildDebug('verdaccio:hooks');
|
|
11
11
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { createRemoteUser, parseConfigFile } from '@verdaccio/config';
|
|
1
2
|
import { setup } from '@verdaccio/logger';
|
|
2
3
|
import { Config } from '@verdaccio/types';
|
|
3
|
-
|
|
4
|
+
|
|
4
5
|
import { notify } from '../src/notify';
|
|
5
6
|
import { parseConfigurationFile } from './__helper';
|
|
6
7
|
|