@verdaccio/hooks 8.1.0 → 8.1.1
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/build/notify-request.js
CHANGED
|
@@ -2,11 +2,14 @@ const require_runtime = require("./_virtual/_rolldown/runtime.js");
|
|
|
2
2
|
let debug = require("debug");
|
|
3
3
|
debug = require_runtime.__toESM(debug);
|
|
4
4
|
let _verdaccio_logger = require("@verdaccio/logger");
|
|
5
|
-
let got_cjs = require("got-cjs");
|
|
6
|
-
got_cjs = require_runtime.__toESM(got_cjs);
|
|
7
5
|
let _verdaccio_core = require("@verdaccio/core");
|
|
8
6
|
//#region src/notify-request.ts
|
|
9
7
|
var debug$1 = (0, debug.default)("verdaccio:hooks:request");
|
|
8
|
+
var gotInstance;
|
|
9
|
+
function loadGot() {
|
|
10
|
+
gotInstance ??= import("got").then((mod) => mod.default);
|
|
11
|
+
return gotInstance;
|
|
12
|
+
}
|
|
10
13
|
function verifyMethod(value) {
|
|
11
14
|
const valid = [
|
|
12
15
|
"GET",
|
|
@@ -22,7 +25,6 @@ function verifyMethod(value) {
|
|
|
22
25
|
}
|
|
23
26
|
var baseHeaders = { "Content-Type": "application/json" };
|
|
24
27
|
async function notifyRequest(url, options) {
|
|
25
|
-
let response;
|
|
26
28
|
try {
|
|
27
29
|
const method = verifyMethod(options.method);
|
|
28
30
|
debug$1("uri %o", url);
|
|
@@ -51,13 +53,12 @@ async function notifyRequest(url, options) {
|
|
|
51
53
|
debug$1("final url with search params %o", finalUrl);
|
|
52
54
|
} else if (options.body !== void 0) requestOptions.body = options.body;
|
|
53
55
|
else throw new Error("Notification body is undefined");
|
|
54
|
-
response = await (
|
|
56
|
+
const response = await (await loadGot())(finalUrl, {
|
|
55
57
|
...requestOptions,
|
|
56
|
-
|
|
58
|
+
throwHttpErrors: false
|
|
57
59
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (body.statusCode >= _verdaccio_core.HTTP_STATUS.BAD_REQUEST) throw new Error(body);
|
|
60
|
+
debug$1("response.status %o", response.statusCode);
|
|
61
|
+
if (response.statusCode >= _verdaccio_core.HTTP_STATUS.BAD_REQUEST) throw new Error(`notification service responded with status code ${response.statusCode}`);
|
|
61
62
|
_verdaccio_logger.logger.info({ content: options.body }, "The notification @{content} has been successfully dispatched");
|
|
62
63
|
return true;
|
|
63
64
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify-request.js","names":[],"sources":["../src/notify-request.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Method } from 'got
|
|
1
|
+
{"version":3,"file":"notify-request.js","names":[],"sources":["../src/notify-request.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Got, Method } from 'got';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\n\nconst debug = buildDebug('verdaccio:hooks:request');\n\n// got >=12 is ESM-only; load it lazily through a dynamic import so the\n// CommonJS build can use it as well (import() is available from CJS code on\n// every supported Node.js, unlike require(esm) which needs >=22.12)\nlet gotInstance: Promise<Got> | undefined;\nfunction loadGot(): Promise<Got> {\n gotInstance ??= import('got').then((mod) => mod.default);\n return gotInstance;\n}\n\nexport type FetchOptions = {\n body: string;\n headers?: {};\n method?: string;\n};\n\nexport function verifyMethod(value: any): Method {\n const valid: Method[] = ['GET', 'POST', 'PUT'];\n\n if (typeof value === 'string') {\n const upper = value.toUpperCase() as Method;\n\n if (valid.includes(upper)) {\n return upper;\n } else {\n logger.warn(\n { method: value },\n 'The notification method @{method} is not valid, using default POST method'\n );\n }\n }\n\n return 'POST';\n}\n\nconst baseHeaders = { 'Content-Type': 'application/json' };\nexport async function notifyRequest(url: string, options: FetchOptions): Promise<boolean> {\n try {\n const method: Method = verifyMethod(options.method);\n debug('uri %o', url);\n debug('headers %o', options.headers);\n debug('method %o', method);\n\n let userHeaders: Record<string, any> = {};\n\n if (options.headers) {\n if (typeof options.headers === 'string') {\n userHeaders = JSON.parse(options.headers);\n } else if (typeof options.headers === 'object') {\n userHeaders = options.headers;\n }\n }\n\n const headers = { ...baseHeaders, ...userHeaders };\n const requestOptions: { method: Method; headers: Record<string, any>; body?: string } = {\n method,\n headers,\n };\n\n let finalUrl = url;\n if (method === 'GET') {\n debug('using GET with query params');\n const urlObj = new URL(url);\n const params = new URLSearchParams(options.body);\n params.set('body', options.body);\n urlObj.search = params.toString();\n finalUrl = urlObj.toString();\n debug('final url with search params %o', finalUrl);\n } else if (options.body !== undefined) {\n requestOptions.body = options.body;\n } else {\n throw new Error('Notification body is undefined');\n }\n\n const got = await loadGot();\n // validate the real HTTP status ourselves; the response body is not\n // required to be JSON (e.g. Slack replies with a plain \"ok\")\n const response = await got(finalUrl, {\n ...requestOptions,\n throwHttpErrors: false,\n });\n debug('response.status %o', response.statusCode);\n\n if (response.statusCode >= HTTP_STATUS.BAD_REQUEST) {\n throw new Error(`notification service responded with status code ${response.statusCode}`);\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?.message);\n logger.error(\n { errorMessage: err?.message },\n 'notify service has thrown an error: @{errorMessage}'\n );\n return false;\n }\n}\n"],"mappings":";;;;;;AAMA,IAAM,WAAA,GAAA,MAAA,SAAmB,yBAAyB;AAKlD,IAAI;AACJ,SAAS,UAAwB;CAC/B,gBAAgB,OAAO,OAAO,MAAM,QAAQ,IAAI,OAAO;CACvD,OAAO;AACT;AAQA,SAAgB,aAAa,OAAoB;CAC/C,MAAM,QAAkB;EAAC;EAAO;EAAQ;CAAK;CAE7C,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,QAAQ,MAAM,YAAY;EAEhC,IAAI,MAAM,SAAS,KAAK,GACtB,OAAO;OAEP,kBAAA,OAAO,KACL,EAAE,QAAQ,MAAM,GAChB,2EACF;CAEJ;CAEA,OAAO;AACT;AAEA,IAAM,cAAc,EAAE,gBAAgB,mBAAmB;AACzD,eAAsB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ebug from "debug";
|
|
2
2
|
import { logger } from "@verdaccio/logger";
|
|
3
|
-
import got from "got-cjs";
|
|
4
3
|
import { HTTP_STATUS } from "@verdaccio/core";
|
|
5
4
|
//#region src/notify-request.ts
|
|
6
5
|
var debug = buildDebug("verdaccio:hooks:request");
|
|
6
|
+
var gotInstance;
|
|
7
|
+
function loadGot() {
|
|
8
|
+
gotInstance ??= import("got").then((mod) => mod.default);
|
|
9
|
+
return gotInstance;
|
|
10
|
+
}
|
|
7
11
|
function verifyMethod(value) {
|
|
8
12
|
const valid = [
|
|
9
13
|
"GET",
|
|
@@ -19,7 +23,6 @@ function verifyMethod(value) {
|
|
|
19
23
|
}
|
|
20
24
|
var baseHeaders = { "Content-Type": "application/json" };
|
|
21
25
|
async function notifyRequest(url, options) {
|
|
22
|
-
let response;
|
|
23
26
|
try {
|
|
24
27
|
const method = verifyMethod(options.method);
|
|
25
28
|
debug("uri %o", url);
|
|
@@ -48,13 +51,12 @@ async function notifyRequest(url, options) {
|
|
|
48
51
|
debug("final url with search params %o", finalUrl);
|
|
49
52
|
} else if (options.body !== void 0) requestOptions.body = options.body;
|
|
50
53
|
else throw new Error("Notification body is undefined");
|
|
51
|
-
response = await
|
|
54
|
+
const response = await (await loadGot())(finalUrl, {
|
|
52
55
|
...requestOptions,
|
|
53
|
-
|
|
56
|
+
throwHttpErrors: false
|
|
54
57
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (body.statusCode >= HTTP_STATUS.BAD_REQUEST) throw new Error(body);
|
|
58
|
+
debug("response.status %o", response.statusCode);
|
|
59
|
+
if (response.statusCode >= HTTP_STATUS.BAD_REQUEST) throw new Error(`notification service responded with status code ${response.statusCode}`);
|
|
58
60
|
logger.info({ content: options.body }, "The notification @{content} has been successfully dispatched");
|
|
59
61
|
return true;
|
|
60
62
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify-request.mjs","names":[],"sources":["../src/notify-request.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Method } from 'got
|
|
1
|
+
{"version":3,"file":"notify-request.mjs","names":[],"sources":["../src/notify-request.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Got, Method } from 'got';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\n\nconst debug = buildDebug('verdaccio:hooks:request');\n\n// got >=12 is ESM-only; load it lazily through a dynamic import so the\n// CommonJS build can use it as well (import() is available from CJS code on\n// every supported Node.js, unlike require(esm) which needs >=22.12)\nlet gotInstance: Promise<Got> | undefined;\nfunction loadGot(): Promise<Got> {\n gotInstance ??= import('got').then((mod) => mod.default);\n return gotInstance;\n}\n\nexport type FetchOptions = {\n body: string;\n headers?: {};\n method?: string;\n};\n\nexport function verifyMethod(value: any): Method {\n const valid: Method[] = ['GET', 'POST', 'PUT'];\n\n if (typeof value === 'string') {\n const upper = value.toUpperCase() as Method;\n\n if (valid.includes(upper)) {\n return upper;\n } else {\n logger.warn(\n { method: value },\n 'The notification method @{method} is not valid, using default POST method'\n );\n }\n }\n\n return 'POST';\n}\n\nconst baseHeaders = { 'Content-Type': 'application/json' };\nexport async function notifyRequest(url: string, options: FetchOptions): Promise<boolean> {\n try {\n const method: Method = verifyMethod(options.method);\n debug('uri %o', url);\n debug('headers %o', options.headers);\n debug('method %o', method);\n\n let userHeaders: Record<string, any> = {};\n\n if (options.headers) {\n if (typeof options.headers === 'string') {\n userHeaders = JSON.parse(options.headers);\n } else if (typeof options.headers === 'object') {\n userHeaders = options.headers;\n }\n }\n\n const headers = { ...baseHeaders, ...userHeaders };\n const requestOptions: { method: Method; headers: Record<string, any>; body?: string } = {\n method,\n headers,\n };\n\n let finalUrl = url;\n if (method === 'GET') {\n debug('using GET with query params');\n const urlObj = new URL(url);\n const params = new URLSearchParams(options.body);\n params.set('body', options.body);\n urlObj.search = params.toString();\n finalUrl = urlObj.toString();\n debug('final url with search params %o', finalUrl);\n } else if (options.body !== undefined) {\n requestOptions.body = options.body;\n } else {\n throw new Error('Notification body is undefined');\n }\n\n const got = await loadGot();\n // validate the real HTTP status ourselves; the response body is not\n // required to be JSON (e.g. Slack replies with a plain \"ok\")\n const response = await got(finalUrl, {\n ...requestOptions,\n throwHttpErrors: false,\n });\n debug('response.status %o', response.statusCode);\n\n if (response.statusCode >= HTTP_STATUS.BAD_REQUEST) {\n throw new Error(`notification service responded with status code ${response.statusCode}`);\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?.message);\n logger.error(\n { errorMessage: err?.message },\n 'notify service has thrown an error: @{errorMessage}'\n );\n return false;\n }\n}\n"],"mappings":";;;;AAMA,IAAM,QAAQ,WAAW,yBAAyB;AAKlD,IAAI;AACJ,SAAS,UAAwB;CAC/B,gBAAgB,OAAO,OAAO,MAAM,QAAQ,IAAI,OAAO;CACvD,OAAO;AACT;AAQA,SAAgB,aAAa,OAAoB;CAC/C,MAAM,QAAkB;EAAC;EAAO;EAAQ;CAAK;CAE7C,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,QAAQ,MAAM,YAAY;EAEhC,IAAI,MAAM,SAAS,KAAK,GACtB,OAAO;OAEP,OAAO,KACL,EAAE,QAAQ,MAAM,GAChB,2EACF;CAEJ;CAEA,OAAO;AACT;AAEA,IAAM,cAAc,EAAE,gBAAgB,mBAAmB;AACzD,eAAsB,cAAc,KAAa,SAAyC;CACxF,IAAI;EACF,MAAM,SAAiB,aAAa,QAAQ,MAAM;EAClD,MAAM,UAAU,GAAG;EACnB,MAAM,cAAc,QAAQ,OAAO;EACnC,MAAM,aAAa,MAAM;EAEzB,IAAI,cAAmC,CAAC;EAExC,IAAI,QAAQ;OACN,OAAO,QAAQ,YAAY,UAC7B,cAAc,KAAK,MAAM,QAAQ,OAAO;QACnC,IAAI,OAAO,QAAQ,YAAY,UACpC,cAAc,QAAQ;EAAA;EAK1B,MAAM,iBAAkF;GACtF;GACA,SAAA;IAHgB,GAAG;IAAa,GAAG;GAGnC;EACF;EAEA,IAAI,WAAW;EACf,IAAI,WAAW,OAAO;GACpB,MAAM,6BAA6B;GACnC,MAAM,SAAS,IAAI,IAAI,GAAG;GAC1B,MAAM,SAAS,IAAI,gBAAgB,QAAQ,IAAI;GAC/C,OAAO,IAAI,QAAQ,QAAQ,IAAI;GAC/B,OAAO,SAAS,OAAO,SAAS;GAChC,WAAW,OAAO,SAAS;GAC3B,MAAM,mCAAmC,QAAQ;EACnD,OAAO,IAAI,QAAQ,SAAS,KAAA,GAC1B,eAAe,OAAO,QAAQ;OAE9B,MAAM,IAAI,MAAM,gCAAgC;EAMlD,MAAM,WAAW,OAAM,MAHL,QAAQ,GAGC,UAAU;GACnC,GAAG;GACH,iBAAiB;EACnB,CAAC;EACD,MAAM,sBAAsB,SAAS,UAAU;EAE/C,IAAI,SAAS,cAAc,YAAY,aACrC,MAAM,IAAI,MAAM,mDAAmD,SAAS,YAAY;EAG1F,OAAO,KACL,EAAE,SAAS,QAAQ,KAAK,GACxB,8DACF;EACA,OAAO;CACT,SAAS,KAAU;EACjB,MAAM,qBAAqB,KAAK,OAAO;EACvC,OAAO,MACL,EAAE,cAAc,KAAK,QAAQ,GAC7B,qDACF;EACA,OAAO;CACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/hooks",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"description": "Verdaccio Hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"enterprise",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"@verdaccio/core": "8.2.0",
|
|
52
52
|
"@verdaccio/logger": "8.1.0",
|
|
53
53
|
"debug": "4.4.3",
|
|
54
|
-
"got
|
|
54
|
+
"got": "15.1.0",
|
|
55
55
|
"handlebars": "4.7.9"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@verdaccio/config": "8.2.0",
|
|
59
59
|
"@verdaccio/types": "13.0.5",
|
|
60
|
-
"nock": "
|
|
60
|
+
"nock": "14.0.16",
|
|
61
61
|
"vite": "8.0.16",
|
|
62
62
|
"vitest": "4.1.2",
|
|
63
63
|
"@verdaccio/test-helper": "4.1.0"
|