@verdaccio/hooks 6.0.0-6-next.21 → 6.0.0-6-next.23

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @verdaccio/hooks
2
2
 
3
+ ## 6.0.0-6-next.23
4
+
5
+ ### Patch Changes
6
+
7
+ - @verdaccio/core@6.0.0-6-next.53
8
+ - @verdaccio/logger@6.0.0-6-next.21
9
+
10
+ ## 6.0.0-6-next.22
11
+
12
+ ### Patch Changes
13
+
14
+ - @verdaccio/core@6.0.0-6-next.52
15
+ - @verdaccio/logger@6.0.0-6-next.20
16
+
3
17
  ## 6.0.0-6-next.21
4
18
 
5
19
  ### Patch Changes
package/build/index.js CHANGED
@@ -21,6 +21,5 @@ Object.defineProperty(exports, "sendNotification", {
21
21
  return _notify.sendNotification;
22
22
  }
23
23
  });
24
-
25
24
  var _notify = require("./notify");
26
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { handleNotify, notify, sendNotification } from './notify';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { handleNotify, notify, sendNotification } from './notify';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA"}
@@ -1,4 +1,4 @@
1
- export declare type FetchOptions = {
1
+ export type FetchOptions = {
2
2
  body: string;
3
3
  headers?: {};
4
4
  method?: string;
@@ -4,22 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.notifyRequest = notifyRequest;
7
-
8
7
  var _debug = _interopRequireDefault(require("debug"));
9
-
10
8
  var _undici = require("undici");
11
-
12
9
  var _core = require("@verdaccio/core");
13
-
14
10
  var _logger = require("@verdaccio/logger");
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  const debug = (0, _debug.default)('verdaccio:hooks:request');
19
-
20
13
  async function notifyRequest(url, options) {
21
14
  let response;
22
-
23
15
  try {
24
16
  debug('uri %o', url);
25
17
  response = await (0, _undici.fetch)(url, {
@@ -31,23 +23,18 @@ async function notifyRequest(url, options) {
31
23
  });
32
24
  debug('response.status %o', response.status);
33
25
  const body = await response.json();
34
-
35
26
  if (response.status >= _core.HTTP_STATUS.BAD_REQUEST) {
36
27
  throw new Error(body);
37
28
  }
38
-
39
29
  _logger.logger.info({
40
30
  content: options.body
41
31
  }, 'The notification @{content} has been successfully dispatched');
42
-
43
32
  return true;
44
33
  } catch (err) {
45
34
  debug('request error %o', err);
46
-
47
35
  _logger.logger.error({
48
36
  errorMessage: err === null || err === void 0 ? void 0 : err.message
49
37
  }, 'notify service has thrown an error: @{errorMessage}');
50
-
51
38
  return false;
52
39
  }
53
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"notify-request.js","names":["debug","buildDebug","notifyRequest","url","options","response","fetch","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 { fetch } from 'undici';\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 = 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"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;;;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,yBAAX,CAAd;;AAQO,eAAeC,aAAf,CAA6BC,GAA7B,EAA0CC,OAA1C,EAAmF;EACxF,IAAIC,QAAJ;;EACA,IAAI;IACFL,KAAK,CAAC,QAAD,EAAWG,GAAX,CAAL;IACAE,QAAQ,GAAG,MAAM,IAAAC,aAAA,EAAMH,GAAN,EAAW;MAC1BI,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeL,OAAO,CAACG,IAAvB,CADoB;MAE1BG,MAAM,EAAE,MAFkB;MAG1BC,OAAO,EAAE;QAAE,gBAAgB;MAAlB;IAHiB,CAAX,CAAjB;IAKAX,KAAK,CAAC,qBAAD,EAAwBK,QAAQ,CAACO,MAAjC,CAAL;IACA,MAAML,IAAI,GAAG,MAAMF,QAAQ,CAACQ,IAAT,EAAnB;;IACA,IAAIR,QAAQ,CAACO,MAAT,IAAmBE,iBAAA,CAAYC,WAAnC,EAAgD;MAC9C,MAAM,IAAIC,KAAJ,CAAUT,IAAV,CAAN;IACD;;IAEDU,cAAA,CAAOC,IAAP,CACE;MAAEC,OAAO,EAAEf,OAAO,CAACG;IAAnB,CADF,EAEE,8DAFF;;IAIA,OAAO,IAAP;EACD,CAlBD,CAkBE,OAAOa,GAAP,EAAiB;IACjBpB,KAAK,CAAC,kBAAD,EAAqBoB,GAArB,CAAL;;IACAH,cAAA,CAAOI,KAAP,CACE;MAAEC,YAAY,EAAEF,GAAF,aAAEA,GAAF,uBAAEA,GAAG,CAAEG;IAArB,CADF,EAEE,qDAFF;;IAIA,OAAO,KAAP;EACD;AACF"}
1
+ {"version":3,"file":"notify-request.js","names":["debug","buildDebug","notifyRequest","url","options","response","fetch","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 { fetch } from 'undici';\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 = 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"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AAA2C;AAE3C,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,yBAAyB,CAAC;AAQ5C,eAAeC,aAAa,CAACC,GAAW,EAAEC,OAAqB,EAAoB;EACxF,IAAIC,QAAQ;EACZ,IAAI;IACFL,KAAK,CAAC,QAAQ,EAAEG,GAAG,CAAC;IACpBE,QAAQ,GAAG,MAAM,IAAAC,aAAK,EAACH,GAAG,EAAE;MAC1BI,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACL,OAAO,CAACG,IAAI,CAAC;MAClCG,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE;QAAE,cAAc,EAAE;MAAmB;IAChD,CAAC,CAAC;IACFX,KAAK,CAAC,qBAAqB,EAAEK,QAAQ,CAACO,MAAM,CAAC;IAC7C,MAAML,IAAI,GAAG,MAAMF,QAAQ,CAACQ,IAAI,EAAE;IAClC,IAAIR,QAAQ,CAACO,MAAM,IAAIE,iBAAW,CAACC,WAAW,EAAE;MAC9C,MAAM,IAAIC,KAAK,CAACT,IAAI,CAAC;IACvB;IAEAU,cAAM,CAACC,IAAI,CACT;MAAEC,OAAO,EAAEf,OAAO,CAACG;IAAK,CAAC,EACzB,8DAA8D,CAC/D;IACD,OAAO,IAAI;EACb,CAAC,CAAC,OAAOa,GAAQ,EAAE;IACjBpB,KAAK,CAAC,kBAAkB,EAAEoB,GAAG,CAAC;IAC9BH,cAAM,CAACI,KAAK,CACV;MAAEC,YAAY,EAAEF,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG;IAAQ,CAAC,EAC9B,qDAAqD,CACtD;IACD,OAAO,KAAK;EACd;AACF"}
package/build/notify.js CHANGED
@@ -7,31 +7,22 @@ exports.compileTemplate = compileTemplate;
7
7
  exports.handleNotify = handleNotify;
8
8
  exports.notify = notify;
9
9
  exports.sendNotification = sendNotification;
10
-
11
10
  var _debug = _interopRequireDefault(require("debug"));
12
-
13
11
  var _handlebars = _interopRequireDefault(require("handlebars"));
14
-
15
12
  var _logger = require("@verdaccio/logger");
16
-
17
13
  var _notifyRequest = require("./notify-request");
18
-
19
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
-
21
15
  /* eslint-disable no-undef */
22
- const debug = (0, _debug.default)('verdaccio:hooks');
23
16
 
17
+ const debug = (0, _debug.default)('verdaccio:hooks');
24
18
  function compileTemplate(content, metadata) {
25
19
  // FUTURE: multiple handlers
26
20
  return new Promise((resolve, reject) => {
27
21
  let handler;
28
-
29
22
  try {
30
23
  if (!handler) {
31
24
  debug('compile default template handler %o', content);
32
-
33
25
  const template = _handlebars.default.compile(content);
34
-
35
26
  return resolve(template(metadata));
36
27
  }
37
28
  } catch (error) {
@@ -40,26 +31,22 @@ function compileTemplate(content, metadata) {
40
31
  }
41
32
  });
42
33
  }
43
-
44
34
  async function handleNotify(metadata, notifyEntry, remoteUser, publishedPackage) {
45
35
  var _metadata, _metadata2;
46
-
47
36
  let regex;
48
-
49
37
  if (metadata.name && notifyEntry.packagePattern) {
50
38
  regex = new RegExp(notifyEntry.packagePattern, notifyEntry.packagePatternFlags || '');
51
-
52
39
  if (!regex.test(metadata.name)) {
53
40
  return false;
54
41
  }
55
42
  }
56
-
57
- let content; // FIXME: publisher is not part of the expected types metadata
43
+ let content;
44
+ // FIXME: publisher is not part of the expected types metadata
58
45
  // @ts-ignore
59
-
60
46
  if (typeof ((_metadata = metadata) === null || _metadata === void 0 ? void 0 : _metadata.publisher) === 'undefined' || ((_metadata2 = metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.publisher) === null) {
61
47
  // @ts-ignore
62
- metadata = { ...metadata,
48
+ metadata = {
49
+ ...metadata,
63
50
  publishedPackage,
64
51
  publisher: {
65
52
  name: remoteUser.name
@@ -68,14 +55,14 @@ async function handleNotify(metadata, notifyEntry, remoteUser, publishedPackage)
68
55
  debug('template metadata %o', metadata);
69
56
  content = await compileTemplate(notifyEntry.content, metadata);
70
57
  }
71
-
72
58
  const options = {
73
59
  body: JSON.stringify(content)
74
- }; // provides fallback support, it's accept an Object {} and Array of {}
60
+ };
75
61
 
62
+ // provides fallback support, it's accept an Object {} and Array of {}
76
63
  if (notifyEntry.headers && Array.isArray(notifyEntry.headers)) {
77
- const header = {}; // FIXME: we can simplify this
78
-
64
+ const header = {};
65
+ // FIXME: we can simplify this
79
66
  notifyEntry.headers.map(function (item) {
80
67
  if (Object.is(item, item)) {
81
68
  for (const key in item) {
@@ -90,31 +77,24 @@ async function handleNotify(metadata, notifyEntry, remoteUser, publishedPackage)
90
77
  } else if (Object.is(notifyEntry.headers, notifyEntry.headers)) {
91
78
  options.headers = notifyEntry.headers;
92
79
  }
93
-
94
80
  if (!notifyEntry.endpoint) {
95
81
  debug('error due endpoint is missing');
96
82
  throw new Error('missing parameter');
97
83
  }
98
-
99
84
  return (0, _notifyRequest.notifyRequest)(notifyEntry.endpoint, {
100
85
  method: notifyEntry.method,
101
86
  ...options
102
87
  });
103
88
  }
104
-
105
89
  function sendNotification(metadata, notify, remoteUser, publishedPackage) {
106
90
  return handleNotify(metadata, notify, remoteUser, publishedPackage);
107
91
  }
108
-
109
92
  async function notify(metadata, config, remoteUser, publishedPackage) {
110
93
  debug('init send notification');
111
-
112
94
  if (config.notify) {
113
95
  const isSingle = Object.keys(config.notify).includes('method');
114
-
115
96
  if (isSingle) {
116
97
  debug('send single notification');
117
-
118
98
  try {
119
99
  const response = await sendNotification(metadata, config.notify, remoteUser, publishedPackage);
120
100
  return [response];
@@ -133,8 +113,9 @@ async function notify(metadata, config, remoteUser, publishedPackage) {
133
113
  _logger.logger.error({
134
114
  error
135
115
  }, 'notify request has failed: @error');
136
- }); // @ts-ignore
116
+ });
137
117
 
118
+ // @ts-ignore
138
119
  return Object.keys(results).map(promiseValue => results[promiseValue].value);
139
120
  }
140
121
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"notify.js","names":["debug","buildDebug","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","notifyRequest","method","sendNotification","notify","config","isSingle","keys","includes","response","results","allSettled","keyId","catch","logger","promiseValue","value"],"sources":["../src/notify.ts"],"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"],"mappings":";;;;;;;;;;AACA;;AACA;;AAEA;;AAGA;;;;AAPA;AASA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,iBAAX,CAAd;;AAEO,SAASC,eAAT,CAAyBC,OAAzB,EAAkCC,QAAlC,EAA4C;EACjD;EACA,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,IAAIC,OAAJ;;IACA,IAAI;MACF,IAAI,CAACA,OAAL,EAAc;QACZR,KAAK,CAAC,qCAAD,EAAwCG,OAAxC,CAAL;;QACA,MAAMM,QAAoC,GAAGC,mBAAA,CAAWC,OAAX,CAAmBR,OAAnB,CAA7C;;QACA,OAAOG,OAAO,CAACG,QAAQ,CAACL,QAAD,CAAT,CAAd;MACD;IACF,CAND,CAME,OAAOQ,KAAP,EAAmB;MACnBZ,KAAK,CAAC,4BAAD,EAA+BY,KAA/B,CAAL;MACAL,MAAM,CAACK,KAAD,CAAN;IACD;EACF,CAZM,CAAP;AAaD;;AAEM,eAAeC,YAAf,CACLT,QADK,EAELU,WAFK,EAGLC,UAHK,EAILC,gBAJK,EAKa;EAAA;;EAClB,IAAIC,KAAJ;;EACA,IAAIb,QAAQ,CAACc,IAAT,IAAiBJ,WAAW,CAACK,cAAjC,EAAiD;IAC/CF,KAAK,GAAG,IAAIG,MAAJ,CAAWN,WAAW,CAACK,cAAvB,EAAu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,6BAAD,CAAL;MACA,MAAMiD,OAAO,GAAG,MAAM5C,OAAO,CAAC6C,UAAR,CACpBhB,MAAM,CAACY,IAAP,CAAYF,MAAM,CAACD,MAAnB,EAA2BX,GAA3B,CAAgCmB,KAAD,IAAmB;QAChD;QACA,MAAMlB,IAAI,GAAGW,MAAM,CAACD,MAAP,CAAcQ,KAAd,CAAb;QACAnD,KAAK,CAAC,cAAD,EAAiBiC,IAAjB,CAAL;QACA,OAAOS,gBAAgB,CAACtC,QAAD,EAAW6B,IAAX,EAAiBlB,UAAjB,EAA6BC,gBAA7B,CAAvB;MACD,CALD,CADoB,EAOpBoC,KAPoB,CAObxC,KAAD,IAAW;QACjByC,cAAA,CAAOzC,KAAP,CAAa;UAAEA;QAAF,CAAb,EAAwB,mCAAxB;MACD,CATqB,CAAtB,CAFK,CAaL;;MACA,OAAOsB,MAAM,CAACY,IAAP,CAAYG,OAAZ,EAAqBjB,GAArB,CAA0BsB,YAAD,IAAkBL,OAAO,CAACK,YAAD,CAAP,CAAsBC,KAAjE,CAAP;IACD;EACF,CAhCD,MAgCO;IACLvD,KAAK,CAAC,yCAAD,CAAL;IACA,OAAO,CAAC,KAAD,CAAP;EACD;AACF"}
1
+ {"version":3,"file":"notify.js","names":["debug","buildDebug","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","notifyRequest","method","sendNotification","notify","config","isSingle","keys","includes","response","results","allSettled","keyId","catch","logger","promiseValue","value"],"sources":["../src/notify.ts"],"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"],"mappings":";;;;;;;;;AACA;AACA;AAEA;AAGA;AAA+D;AAP/D;;AASA,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,iBAAiB,CAAC;AAEpC,SAASC,eAAe,CAACC,OAAO,EAAEC,QAAQ,EAAE;EACjD;EACA,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtC,IAAIC,OAAO;IACX,IAAI;MACF,IAAI,CAACA,OAAO,EAAE;QACZR,KAAK,CAAC,qCAAqC,EAAEG,OAAO,CAAC;QACrD,MAAMM,QAAoC,GAAGC,mBAAU,CAACC,OAAO,CAACR,OAAO,CAAC;QACxE,OAAOG,OAAO,CAACG,QAAQ,CAACL,QAAQ,CAAC,CAAC;MACpC;IACF,CAAC,CAAC,OAAOQ,KAAU,EAAE;MACnBZ,KAAK,CAAC,4BAA4B,EAAEY,KAAK,CAAC;MAC1CL,MAAM,CAACK,KAAK,CAAC;IACf;EACF,CAAC,CAAC;AACJ;AAEO,eAAeC,YAAY,CAChCT,QAA0B,EAC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AAO,CAACgC,QAAQ,CAAC;MACnB,CAAC,CAAC,MAAM;QACNhD,KAAK,CAAC,sCAAsC,CAAC;QAC7C,OAAO,CAAC,KAAK,CAAC;MAChB;IACF,CAAC,MAAM;MACLA,KAAK,CAAC,6BAA6B,CAAC;MACpC,MAAMiD,OAAO,GAAG,MAAM5C,OAAO,CAAC6C,UAAU,CACtChB,MAAM,CAACY,IAAI,CAACF,MAAM,CAACD,MAAM,CAAC,CAACX,GAAG,CAAEmB,KAAa,IAAK;QAChD;QACA,MAAMlB,IAAI,GAAGW,MAAM,CAACD,MAAM,CAACQ,KAAK,CAAC;QACjCnD,KAAK,CAAC,cAAc,EAAEiC,IAAI,CAAC;QAC3B,OAAOS,gBAAgB,CAACtC,QAAQ,EAAE6B,IAAI,EAAElB,UAAU,EAAEC,gBAAgB,CAAC;MACvE,CAAC,CAAC,CACH,CAACoC,KAAK,CAAExC,KAAK,IAAK;QACjByC,cAAM,CAACzC,KAAK,CAAC;UAAEA;QAAM,CAAC,EAAE,mCAAmC,CAAC;MAC9D,CAAC,CAAC;;MAEF;MACA,OAAOsB,MAAM,CAACY,IAAI,CAACG,OAAO,CAAC,CAACjB,GAAG,CAAEsB,YAAY,IAAKL,OAAO,CAACK,YAAY,CAAC,CAACC,KAAK,CAAC;IAChF;EACF,CAAC,MAAM;IACLvD,KAAK,CAAC,yCAAyC,CAAC;IAChD,OAAO,CAAC,KAAK,CAAC;EAChB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/hooks",
3
- "version": "6.0.0-6-next.21",
3
+ "version": "6.0.0-6-next.23",
4
4
  "description": "loaders logic",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -30,18 +30,18 @@
30
30
  "npm": ">=6"
31
31
  },
32
32
  "dependencies": {
33
- "@verdaccio/core": "6.0.0-6-next.51",
34
- "@verdaccio/logger": "6.0.0-6-next.19",
35
- "core-js": "3.25.5",
33
+ "@verdaccio/core": "6.0.0-6-next.53",
34
+ "@verdaccio/logger": "6.0.0-6-next.21",
35
+ "core-js": "3.27.0",
36
36
  "debug": "4.3.4",
37
37
  "handlebars": "4.7.7",
38
38
  "undici": "4.16.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/node": "16.11.65",
42
- "@verdaccio/auth": "6.0.0-6-next.30",
43
- "@verdaccio/config": "6.0.0-6-next.51",
44
- "@verdaccio/types": "11.0.0-6-next.17"
41
+ "@types/node": "16.18.10",
42
+ "@verdaccio/auth": "6.0.0-6-next.32",
43
+ "@verdaccio/config": "6.0.0-6-next.53",
44
+ "@verdaccio/types": "11.0.0-6-next.18"
45
45
  },
46
46
  "funding": {
47
47
  "type": "opencollective",