@verdaccio/hooks 6.0.0-6-next.12 → 6.0.0-6-next.15

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,57 @@
1
1
  # @verdaccio/hooks
2
2
 
3
+ ## 6.0.0-6-next.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 351aeeaa: fix(deps): @verdaccio/utils should be a prod dep of local-storage
8
+ - Updated dependencies [351aeeaa]
9
+ - @verdaccio/core@6.0.0-6-next.7
10
+ - @verdaccio/logger@6.0.0-6-next.13
11
+
12
+ ## 6.0.0-6-next.14
13
+
14
+ ### Major Changes
15
+
16
+ - 292c0a37: feat!: replace deprecated request dependency by got
17
+
18
+ This is a big refactoring of the core, fetching dependencies, improve code, more tests and better stability. This is essential for the next release, will take some time but would allow modularize more the core.
19
+
20
+ ## Notes
21
+
22
+ - Remove deprecated `request` by other `got`, retry improved, custom Agent ( got does not include it built-in)
23
+ - Remove `async` dependency from storage (used by core) it was linked with proxy somehow safe to remove now
24
+ - Refactor with promises instead callback wherever is possible
25
+ - ~Document the API~
26
+ - Improve testing, integration tests
27
+ - Bugfix
28
+ - Clean up old validations
29
+ - Improve performance
30
+
31
+ ## 💥 Breaking changes
32
+
33
+ - Plugin API methods were callbacks based are returning promises, this will break current storage plugins, check documentation for upgrade.
34
+ - Write Tarball, Read Tarball methods parameters change, a new set of options like `AbortController` signals are being provided to the `addAbortSignal` can be internally used with Streams when a request is aborted. eg: `addAbortSignal(signal, fs.createReadStream(pathName));`
35
+ - `@verdaccio/streams` stream abort support is legacy is being deprecated removed
36
+ - Remove AWS and Google Cloud packages for future refactoring [#2574](https://github.com/verdaccio/verdaccio/pull/2574).
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [292c0a37]
41
+ - Updated dependencies [a3a209b5]
42
+ - Updated dependencies [00d1d2a1]
43
+ - @verdaccio/core@6.0.0-6-next.6
44
+ - @verdaccio/logger@6.0.0-6-next.12
45
+
46
+ ## 6.0.0-6-next.13
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [82cb0f2b]
51
+ - Updated dependencies [5167bb52]
52
+ - @verdaccio/core@6.0.0-6-next.5
53
+ - @verdaccio/logger@6.0.0-6-next.11
54
+
3
55
  ## 6.0.0-6-next.12
4
56
 
5
57
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export { handleNotify, notify, sendNotification } from './notify';\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { handleNotify, notify, sendNotification } from './notify';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA"}
@@ -7,6 +7,8 @@ exports.notifyRequest = notifyRequest;
7
7
 
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
9
 
10
+ var _undici = require("undici");
11
+
10
12
  var _core = require("@verdaccio/core");
11
13
 
12
14
  var _logger = require("@verdaccio/logger");
@@ -15,14 +17,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
17
 
16
18
  const debug = (0, _debug.default)('verdaccio:hooks:request');
17
19
 
18
- const fetch = require('undici-fetch');
19
-
20
20
  async function notifyRequest(url, options) {
21
21
  let response;
22
22
 
23
23
  try {
24
24
  debug('uri %o', url);
25
- response = await fetch(url, {
25
+ response = await (0, _undici.fetch)(url, {
26
26
  body: JSON.stringify(options.body),
27
27
  method: 'POST',
28
28
  headers: {
@@ -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,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"}
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 +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":";;;;;;;;;;AACA;;AACA;;AAEA;;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AOQ,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"}
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,EAAk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A,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"}
package/package.json CHANGED
@@ -1,60 +1,60 @@
1
1
  {
2
- "name": "@verdaccio/hooks",
3
- "version": "6.0.0-6-next.12",
4
- "description": "loaders logic",
5
- "main": "./build/index.js",
6
- "types": "build/index.d.ts",
7
- "author": {
8
- "name": "Juan Picado",
9
- "email": "juanpicado19@gmail.com"
10
- },
11
- "repository": {
12
- "type": "https",
13
- "url": "https://github.com/verdaccio/verdaccio"
14
- },
15
- "license": "MIT",
16
- "homepage": "https://verdaccio.org",
17
- "keywords": [
18
- "private",
19
- "package",
20
- "repository",
21
- "registry",
22
- "enterprise",
23
- "modules",
24
- "proxy",
25
- "server",
26
- "verdaccio"
27
- ],
28
- "engines": {
29
- "node": ">=14",
30
- "npm": ">=6"
31
- },
32
- "dependencies": {
33
- "@verdaccio/core": "6.0.0-6-next.4",
34
- "@verdaccio/logger": "6.0.0-6-next.10",
35
- "core-js": "3.20.3",
36
- "debug": "4.3.3",
37
- "handlebars": "4.7.7",
38
- "undici": "4.12.2",
39
- "undici-fetch": "1.0.0-rc.4"
40
- },
41
- "devDependencies": {
42
- "@types/node": "16.11.21",
43
- "@verdaccio/auth": "6.0.0-6-next.18",
44
- "@verdaccio/config": "6.0.0-6-next.12",
45
- "@verdaccio/types": "11.0.0-6-next.10"
46
- },
47
- "funding": {
48
- "type": "opencollective",
49
- "url": "https://opencollective.com/verdaccio"
50
- },
51
- "scripts": {
52
- "clean": "rimraf ./build",
53
- "test": "cross-env NODE_ENV=test BABEL_ENV=test jest",
54
- "type-check": "tsc --noEmit -p tsconfig.build.json",
55
- "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
56
- "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
57
- "watch": "pnpm build:js -- --watch",
58
- "build": "pnpm run build:js && pnpm run build:types"
59
- }
60
- }
2
+ "name": "@verdaccio/hooks",
3
+ "version": "6.0.0-6-next.15",
4
+ "description": "loaders logic",
5
+ "main": "./build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "author": {
8
+ "name": "Juan Picado",
9
+ "email": "juanpicado19@gmail.com"
10
+ },
11
+ "repository": {
12
+ "type": "https",
13
+ "url": "https://github.com/verdaccio/verdaccio"
14
+ },
15
+ "license": "MIT",
16
+ "homepage": "https://verdaccio.org",
17
+ "keywords": [
18
+ "private",
19
+ "package",
20
+ "repository",
21
+ "registry",
22
+ "enterprise",
23
+ "modules",
24
+ "proxy",
25
+ "server",
26
+ "verdaccio"
27
+ ],
28
+ "engines": {
29
+ "node": ">=14",
30
+ "npm": ">=6"
31
+ },
32
+ "dependencies": {
33
+ "@verdaccio/core": "6.0.0-6-next.7",
34
+ "@verdaccio/logger": "6.0.0-6-next.13",
35
+ "core-js": "3.25.0",
36
+ "debug": "4.3.4",
37
+ "handlebars": "4.7.7",
38
+ "undici": "4.16.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "16.11.56",
42
+ "@verdaccio/auth": "6.0.0-6-next.24",
43
+ "@verdaccio/config": "6.0.0-6-next.16",
44
+ "@verdaccio/types": "11.0.0-6-next.15"
45
+ },
46
+ "funding": {
47
+ "type": "opencollective",
48
+ "url": "https://opencollective.com/verdaccio"
49
+ },
50
+ "scripts": {
51
+ "clean": "rimraf ./build",
52
+ "test": "jest",
53
+ "type-check": "tsc --noEmit -p tsconfig.build.json",
54
+ "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
55
+ "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
56
+ "watch": "pnpm build:js -- --watch",
57
+ "build": "pnpm run build:js && pnpm run build:types"
58
+ },
59
+ "readme": "# @verdaccio/hooks\n\n[![backers](https://opencollective.com/verdaccio/tiers/backer/badge.svg?label=Backer&color=brightgreen)](https://opencollective.com/verdaccio)\n[![stackshare](https://img.shields.io/badge/Follow%20on-StackShare-blue.svg?logo=stackshare&style=flat)](https://stackshare.io/verdaccio)\n[![MIT](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)\n[![Crowdin](https://d322cqt584bo4o.cloudfront.net/verdaccio/localized.svg)](https://crowdin.com/project/verdaccio)\n[![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/verdaccio/verdaccio)](https://www.tickgit.com/browse?repo=github.com/verdaccio/verdaccio)\n\n[![Twitter followers](https://img.shields.io/twitter/follow/verdaccio_npm.svg?style=social&label=Follow)](https://twitter.com/verdaccio_npm)\n[![Github](https://img.shields.io/github/stars/verdaccio/verdaccio.svg?style=social&label=Stars)](https://github.com/verdaccio/verdaccio/stargazers)\n\n## Donations\n\nVerdaccio is run by **volunteers**; nobody is working full-time on it. If you find this project to be useful and would like to support its development, consider making a donation - **your logo might end up in this readme.** 😉\n\n**[Donate](https://opencollective.com/verdaccio)** 💵👍🏻 starting from _\\$1/month_ or just one single contribution.\n\n## Report a vulnerability\n\nIf you want to report a security vulnerability, please follow the steps which we have defined for you in our [security policy](https://github.com/verdaccio/verdaccio/security/policy).\n\n## Open Collective Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio#sponsor)]\n\n[![sponsor](https://opencollective.com/verdaccio/sponsor/0/avatar.svg)](https://opencollective.com/verdaccio/sponsor/0/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/1/avatar.svg)](https://opencollective.com/verdaccio/sponsor/1/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/2/avatar.svg)](https://opencollective.com/verdaccio/sponsor/2/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/3/avatar.svg)](https://opencollective.com/verdaccio/sponsor/3/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/4/avatar.svg)](https://opencollective.com/verdaccio/sponsor/4/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/5/avatar.svg)](https://opencollective.com/verdaccio/sponsor/5/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/6/avatar.svg)](https://opencollective.com/verdaccio/sponsor/6/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/7/avatar.svg)](https://opencollective.com/verdaccio/sponsor/7/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/8/avatar.svg)](https://opencollective.com/verdaccio/sponsor/8/website)\n[![sponsor](https://opencollective.com/verdaccio/sponsor/9/avatar.svg)](https://opencollective.com/verdaccio/sponsor/9/website)\n\n## Open Collective Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio#backer)]\n\n[![backers](https://opencollective.com/verdaccio/backers.svg?width=890)](https://opencollective.com/verdaccio#backers)\n\n## Special Thanks\n\nThanks to the following companies to help us to achieve our goals providing free open source licenses.\n\n[![jetbrain](assets/thanks/jetbrains/logo.png)](https://www.jetbrains.com/)\n[![crowdin](assets/thanks/crowdin/logo.png)](https://crowdin.com/)\n[![balsamiq](assets/thanks/balsamiq/logo.jpg)](https://balsamiq.com/)\n\n## Contributors\n\nThis project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].\n\n[![contributors](https://opencollective.com/verdaccio/contributors.svg?width=890&button=true)](../../graphs/contributors)\n\n### FAQ / Contact / Troubleshoot\n\nIf you have any issue you can try the following options, do no desist to ask or check our issues database, perhaps someone has asked already what you are looking for.\n\n- [Blog](https://verdaccio.org/blog/)\n- [Donations](https://opencollective.com/verdaccio)\n- [Reporting an issue](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md#reporting-a-bug)\n- [Running discussions](https://github.com/verdaccio/verdaccio/issues?q=is%3Aissue+is%3Aopen+label%3Adiscuss)\n- [Chat](http://chat.verdaccio.org/)\n- [Logos](https://verdaccio.org/docs/en/logo)\n- [Docker Examples](https://github.com/verdaccio/docker-examples)\n- [FAQ](https://github.com/verdaccio/verdaccio/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Aquestion%20)\n\n### License\n\nVerdaccio is [MIT licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)\n\nThe Verdaccio documentation and logos (excluding /thanks, e.g., .md, .png, .sketch) files within the /assets folder) is\n[Creative Commons licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE-docs).\n"
60
+ }
@@ -1,10 +1,10 @@
1
1
  import buildDebug from 'debug';
2
+ import { fetch } from 'undici';
2
3
 
3
4
  import { HTTP_STATUS } from '@verdaccio/core';
4
5
  import { logger } from '@verdaccio/logger';
5
6
 
6
7
  const debug = buildDebug('verdaccio:hooks:request');
7
- const fetch = require('undici-fetch');
8
8
 
9
9
  export type FetchOptions = {
10
10
  body: string;
@@ -1,3 +1,5 @@
1
+ import { MockAgent, setGlobalDispatcher } from 'undici';
2
+
1
3
  import { createRemoteUser, parseConfigFile } from '@verdaccio/config';
2
4
  import { setup } from '@verdaccio/logger';
3
5
  import { Config } from '@verdaccio/types';
@@ -16,8 +18,6 @@ const multiNotificationConfig = parseConfigFile(parseConfigurationNotifyFile('mu
16
18
  setup([]);
17
19
 
18
20
  const domain = 'http://slack-service';
19
- const { MockAgent } = require('undici');
20
- const { setGlobalDispatcher } = require('undici-fetch');
21
21
 
22
22
  const options = {
23
23
  path: '/foo?auth_token=mySecretToken',