diff --git a/.changeset/proxy-fetch.md b/.changeset/proxy-fetch.md new file mode 100644 index 00000000..adc8830d --- /dev/null +++ b/.changeset/proxy-fetch.md @@ -0,0 +1,5 @@ +--- +"@slack/slack-github-action": patch +--- + +feat: route API and webhook requests through `globalThis.fetch`, injecting an [undici](https://github.com/nodejs/undici) `ProxyAgent` when a proxy is configured diff --git a/package-lock.json b/package-lock.json index d27f0fe9..c60bf43a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,13 +11,13 @@ "dependencies": { "@actions/core": "^3.0.1", "@actions/github": "^9.1.1", - "@slack/logger": "^4.0.1", - "@slack/web-api": "^7.19.0", - "@slack/webhook": "^7.2.0", + "@slack/logger": "^5.0.0-rc.1", + "@slack/web-api": "^8.0.0-rc.2", + "@slack/webhook": "^8.0.0-rc.2", "flat": "^6.0.1", - "https-proxy-agent": "^9.1.0", "js-yaml": "^4.2.0", - "markup-js": "^1.5.21" + "markup-js": "^1.5.21", + "undici": "^7.28.0" }, "devDependencies": { "@biomejs/biome": "^2.5.3", @@ -80,6 +80,15 @@ "undici": "^6.23.0" } }, + "node_modules/@actions/github/node_modules/undici": { + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", + "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, "node_modules/@actions/http-client": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.0.tgz", @@ -90,6 +99,15 @@ "undici": "^6.23.0" } }, + "node_modules/@actions/http-client/node_modules/undici": { + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", + "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, "node_modules/@actions/io": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz", @@ -824,94 +842,63 @@ } }, "node_modules/@slack/logger": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-4.0.1.tgz", - "integrity": "sha512-6cmdPrV/RYfd2U0mDGiMK8S7OJqpCTm7enMLRR3edccsPX8j7zXTLnaEF4fhxxJJTAIOil6+qZrnUPTuaLvwrQ==", + "version": "5.0.0-rc.1", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-5.0.0-rc.1.tgz", + "integrity": "sha512-3vO8zNGvk8n8tXpAzhIz1u/fHjhsLxGMhlZqzJEa3FxlXAe2lsY3qn8XBgKYEG2LmGP6ZWWmDq7vAPr2gZe2CQ==", "license": "MIT", "dependencies": { - "@types/node": ">=18" + "@types/node": ">=20" }, "engines": { - "node": ">= 18", - "npm": ">= 8.6.0" + "node": ">= 20", + "npm": ">=9.6.4" } }, "node_modules/@slack/types": { - "version": "2.21.1", - "resolved": "https://registry.npmjs.org/@slack/types/-/types-2.21.1.tgz", - "integrity": "sha512-I8vmSjNYWsaxuWPx6dz4yeh0h7vRBWbgAMK14LEmblbZ404BtrPbXs6jDPx4cYgGf8msDGF4A9opLZBu21FViQ==", + "version": "3.0.0-rc.1", + "resolved": "https://registry.npmjs.org/@slack/types/-/types-3.0.0-rc.1.tgz", + "integrity": "sha512-xJZm26o5YK95OdM8BliTE+LijNhMGAwLWWpSpfnrPno4DyLBthNAjC7SG/9Ow2gB7oXCeYadpF/nzlYz7XaATg==", "license": "MIT", "engines": { - "node": ">= 12.13.0", - "npm": ">= 6.12.0" + "node": ">= 20", + "npm": ">=9.6.4" } }, "node_modules/@slack/web-api": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-7.19.0.tgz", - "integrity": "sha512-ItjyjEZml+LDH8CjcCLRLJHh7VZtevPKExrRN3l5KWyBliyDnGAeoO4Y+K+fFBmRpKLYVPgqWMX4THldv2HVtA==", + "version": "8.0.0-rc.2", + "resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-8.0.0-rc.2.tgz", + "integrity": "sha512-WL+FDNMpprPPabr9EOw/xv65mlFwSvQOUjbLcD6NJ2U5Vkzb1aKjnpVvJyPIQy6+vlWlXXFZZadOTlZViMWKDg==", "license": "MIT", "dependencies": { - "@slack/logger": "^4.0.1", - "@slack/types": "^2.21.0", - "@types/node": ">=18", + "@slack/logger": "^5.0.0-rc.1", + "@slack/types": "^3.0.0-rc.1", + "@types/node": ">=20", "@types/retry": "0.12.0", - "axios": "^1.16.0", "eventemitter3": "^5.0.1", - "form-data": "^4.0.4", - "is-electron": "2.2.2", - "is-stream": "^2", "p-queue": "^6", "p-retry": "^4", "retry": "^0.13.1" }, "engines": { - "node": ">= 18", - "npm": ">= 8.6.0" - } - }, - "node_modules/@slack/web-api/node_modules/p-retry": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.6.2.tgz", - "integrity": "sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==", - "license": "MIT", - "dependencies": { - "@types/retry": "0.12.0", - "retry": "^0.13.1" - }, - "engines": { - "node": ">=8" + "node": ">= 20", + "npm": ">=9.6.4" } }, "node_modules/@slack/webhook": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@slack/webhook/-/webhook-7.2.0.tgz", - "integrity": "sha512-iGL0S6NI9Bv/kg3FS0J5EaLF1kd7uw5pdrfndqz+h1yhgguiVpRL7ReJg9Cia5knS9hUSCRY5MTjeroBwxdKtw==", - "license": "MIT", - "dependencies": { - "@slack/types": "^2.20.1", - "@types/node": ">=18", - "@types/retry": "0.12.0", - "axios": "^1.16.0", - "p-retry": "^4.6.2", - "retry": "^0.13.1" - }, - "engines": { - "node": ">= 18", - "npm": ">= 8.6.0" - } - }, - "node_modules/@slack/webhook/node_modules/p-retry": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.6.2.tgz", - "integrity": "sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==", + "version": "8.0.0-rc.2", + "resolved": "https://registry.npmjs.org/@slack/webhook/-/webhook-8.0.0-rc.2.tgz", + "integrity": "sha512-nQgi/YPNvIwh0ux2jy6L8yBMd7VgRArvONI/A97rKS6kv/1P6RwWyrVL0Ha2AK1s8KIYSz/opq2RYR4ZFRUblg==", "license": "MIT", "dependencies": { + "@slack/types": "^3.0.0-rc.1", + "@types/node": ">=20", "@types/retry": "0.12.0", + "p-retry": "^4", "retry": "^0.13.1" }, "engines": { - "node": ">=8" + "node": ">= 20", + "npm": ">=9.6.4" } }, "node_modules/@types/flat": { @@ -936,9 +923,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.13.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.2.tgz", - "integrity": "sha512-fRa09kZTgu8o71KFcDjUFuc7F+dEbZYZmkI0mg5YBTRs0yMKjYHsq/c0urDKeDb+D5qVgXOdFcuu+DZPKOITwA==", + "version": "24.13.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.3.tgz", + "integrity": "sha512-Dh8vAsV36ig5wa9OX4pXvMc9D3Veibfw2wix0CUwYODLD8nkj9UsLjASr49nPg+2eKzxhBV+v7L8pXvT4e639Q==", "license": "MIT", "dependencies": { "undici-types": "~7.18.0" @@ -977,15 +964,6 @@ "ncc": "dist/ncc/cli.js" } }, - "node_modules/agent-base": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-9.0.0.tgz", - "integrity": "sha512-TQf59BsZnytt8GdJKLPfUZ54g/iaUL2OWDSFCCvMOhsHduDQxO8xC4PNeyIkVcA5KwL2phPSv0douC0fgWzmnA==", - "license": "MIT", - "engines": { - "node": ">= 20" - } - }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -1022,22 +1000,6 @@ "node": ">=8" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/axios": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.16.0.tgz", - "integrity": "sha512-6hp5CwvTPlN2A31g5dxnwAX0orzM7pmCRDLnZSX772mv8WDqICwFjowHuPs04Mc8deIld1+ejhtaMn5vp6b+1w==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.16.0", - "form-data": "^4.0.5", - "proxy-from-env": "^2.1.0" - } - }, "node_modules/before-after-hook": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz", @@ -1070,19 +1032,6 @@ "node": ">=8" } }, - "node_modules/call-bind-apply-helpers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", - "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/chardet": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/chardet/-/chardet-2.1.1.tgz", @@ -1090,17 +1039,6 @@ "dev": true, "license": "MIT" }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -1116,31 +1054,6 @@ "node": ">= 8" } }, - "node_modules/debug": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", - "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", - "license": "MIT", - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/detect-indent": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", @@ -1174,20 +1087,6 @@ "node": ">=8" } }, - "node_modules/dunder-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", - "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "es-errors": "^1.3.0", - "gopd": "^1.2.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/enquirer": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.4.1.tgz", @@ -1202,51 +1101,6 @@ "node": ">=8.6" } }, - "node_modules/es-define-property": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", - "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-object-atoms": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", - "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-set-tostringtag": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", - "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.6", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -1356,42 +1210,6 @@ "node": ">=18" } }, - "node_modules/follow-redirects": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", - "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", - "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "hasown": "^2.0.4", - "mime-types": "^2.1.35" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", @@ -1407,52 +1225,6 @@ "node": ">=6 <7 || >=8" } }, - "node_modules/function-bind": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", - "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-intrinsic": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", - "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "es-define-property": "^1.0.1", - "es-errors": "^1.3.0", - "es-object-atoms": "^1.1.1", - "function-bind": "^1.1.2", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-symbols": "^1.1.0", - "hasown": "^2.0.2", - "math-intrinsics": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", - "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "license": "MIT", - "dependencies": { - "dunder-proto": "^1.0.1", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -1487,18 +1259,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/gopd": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", - "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -1515,59 +1275,6 @@ "node": ">=8" } }, - "node_modules/has-symbols": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", - "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/hasown": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", - "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/https-proxy-agent": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-9.1.0.tgz", - "integrity": "sha512-ag87y7cJJ9/3+GxFr8Oy4O5faDsGRGnBGsJj/YjOSsSx/5eadKLYTMPlzuR6obgoCDDm0abAAZitXXQkMOPSpA==", - "license": "MIT", - "dependencies": { - "agent-base": "9.0.0", - "debug": "^4.3.4", - "proxy-agent-negotiate": "1.1.0" - }, - "engines": { - "node": ">= 20" - } - }, "node_modules/human-id": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/human-id/-/human-id-4.1.3.tgz", @@ -1605,12 +1312,6 @@ "node": ">= 4" } }, - "node_modules/is-electron": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/is-electron/-/is-electron-2.2.2.tgz", - "integrity": "sha512-FO/Rhvz5tuw4MCWkpMzHFKWD2LsfHzIb7i6MdPYZ/KW7AlxawyLkqdy+jPZP1WubqEADE3O4FUENlJHDfQASRg==", - "license": "MIT" - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -1644,18 +1345,6 @@ "node": ">=0.12.0" } }, - "node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "license": "MIT", - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-subdir": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/is-subdir/-/is-subdir-1.2.0.tgz", @@ -1687,9 +1376,9 @@ "license": "ISC" }, "node_modules/js-yaml": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.0.tgz", - "integrity": "sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.2.0.tgz", + "integrity": "sha512-ePWsvanv0DWuDRsW8dnt+R4jQ31SCRCQ7hhNcPXZPsoBZiemuZNYGf7adZdqX2D86j6rvKp3RpCxVTSb8WQlOw==", "funding": [ { "type": "github", @@ -1746,15 +1435,6 @@ "markup-js": "src/markup.js" } }, - "node_modules/math-intrinsics": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", - "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -1779,25 +1459,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", @@ -1808,11 +1469,6 @@ "node": ">=4" } }, - "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, "node_modules/outdent": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/outdent/-/outdent-0.5.0.tgz", @@ -1903,6 +1559,19 @@ "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", "license": "MIT" }, + "node_modules/p-retry": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.6.2.tgz", + "integrity": "sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==", + "license": "MIT", + "dependencies": { + "@types/retry": "0.12.0", + "retry": "^0.13.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/p-timeout": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz", @@ -2011,32 +1680,6 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, - "node_modules/proxy-agent-negotiate": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-agent-negotiate/-/proxy-agent-negotiate-1.1.0.tgz", - "integrity": "sha512-N8IBcM3UgCVzz2L2Lqv8DVntDnnC8/hiV4nEDUPkqq72TPUgYWjQc+bdZlBPZK9LzPAvOY//gAt0S0DApoOXWQ==", - "license": "MIT", - "engines": { - "node": ">= 20" - }, - "peerDependencies": { - "kerberos": "^2.0.0" - }, - "peerDependenciesMeta": { - "kerberos": { - "optional": true - } - } - }, - "node_modules/proxy-from-env": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", - "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", - "license": "MIT", - "engines": { - "node": ">=10" - } - }, "node_modules/quansync": { "version": "0.2.11", "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz", @@ -2366,18 +2009,18 @@ } }, "node_modules/undici": { - "version": "6.27.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", - "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz", + "integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==", "license": "MIT", "engines": { - "node": ">=18.17" + "node": ">=20.18.1" } }, "node_modules/undici-types": { - "version": "7.18.2", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", - "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.28.0.tgz", + "integrity": "sha512-LJAfY+2w6HGeT8d8J1wNQsUGUEGio6NWWpwdwurQe4f6oojzCFuGLizl1KSve4irsTxyLly1QhEeE6iapdaIvQ==", "license": "MIT" }, "node_modules/universal-user-agent": { diff --git a/package.json b/package.json index daa77556..d9136898 100644 --- a/package.json +++ b/package.json @@ -44,13 +44,16 @@ "dependencies": { "@actions/core": "^3.0.1", "@actions/github": "^9.1.1", - "@slack/logger": "^4.0.1", - "@slack/web-api": "^7.19.0", - "@slack/webhook": "^7.2.0", + "@slack/logger": "^5.0.0-rc.1", + "@slack/web-api": "^8.0.0-rc.2", + "@slack/webhook": "^8.0.0-rc.2", "flat": "^6.0.1", - "https-proxy-agent": "^9.1.0", "js-yaml": "^4.2.0", - "markup-js": "^1.5.21" + "markup-js": "^1.5.21", + "undici": "^7.28.0" + }, + "overrides": { + "undici-types": "^7.28.0" }, "devDependencies": { "@biomejs/biome": "^2.5.3", diff --git a/src/client.js b/src/client.js index cbd8e2f8..7d48f2a4 100644 --- a/src/client.js +++ b/src/client.js @@ -1,7 +1,7 @@ import webapi from "@slack/web-api"; -import { HttpsProxyAgent } from "https-proxy-agent"; import Config from "./config.js"; import SlackError from "./errors.js"; +import { fetch } from "./proxies.js"; /** * The Client class creates a WebClient from @slack/web-api for use when calling @@ -23,7 +23,7 @@ export default class Client { throw new SlackError(config.core, "No token was provided to post with"); } const client = new config.webapi.WebClient(config.inputs.token, { - agent: this.proxies(config)?.httpsAgent, + fetch: fetch(config), allowAbsoluteUrls: false, logger: config.logger, retryConfig: this.retries(config.inputs.retries), @@ -72,28 +72,6 @@ export default class Client { } } - /** - * Return configurations for https proxy options if these are set. - * @param {Config} config - * @returns {import("axios").AxiosRequestConfig | undefined} - * @see {@link https://github.com/slackapi/slack-github-action/pull/205} - */ - proxies(config) { - const proxy = config.inputs.proxy; - try { - if (!proxy) { - return undefined; - } - return { - httpsAgent: new HttpsProxyAgent(proxy), - }; - } catch (/** @type {any} */ err) { - throw new SlackError(config.core, "Failed to configure the HTTPS proxy", { - cause: err, - }); - } - } - /** * Return configurations for retry options with different delays. * @param {string} option diff --git a/src/proxies.js b/src/proxies.js new file mode 100644 index 00000000..d3b64e0e --- /dev/null +++ b/src/proxies.js @@ -0,0 +1,56 @@ +import { ProxyAgent } from "undici"; +import SlackError from "./errors.js"; + +/** + * Return a fetch function that routes requests through a configured proxy. + * + * @param {import("./config.js").default} config + * @param {string?} [destination] - A provided request destination. + * @returns {typeof globalThis.fetch | undefined} + */ +export function fetch(config, destination) { + const dispatcher = proxies(config, destination); + if (!dispatcher) { + return undefined; + } + return (url, init) => globalThis.fetch(url, { ...init, dispatcher }); +} + +/** + * Return a configured proxy agent dispatcher to the request destination. + * + * @see {@link https://github.com/slackapi/slack-github-action/pull/132} + * @see {@link https://github.com/slackapi/slack-github-action/pull/205} + * + * @param {import("./config.js").default} config + * @param {string?} [destination] - The request destination to proxy towards. + * @returns {ProxyAgent | undefined} + */ +export function proxies(config, destination) { + const proxy = config.inputs.proxy; + if (!proxy) { + return undefined; + } + try { + if (destination && new URL(destination).protocol !== "https:") { + config.core.debug( + "The request destination is not HTTPS so skipping the HTTPS proxy", + ); + return undefined; + } + switch (new URL(proxy).protocol) { + case "https:": + case "http:": + return new ProxyAgent(proxy); + default: + throw new SlackError(config.core, `Unsupported URL protocol: ${proxy}`); + } + } catch (/** @type {any} */ err) { + if (err instanceof SlackError) { + throw err; + } + throw new SlackError(config.core, "Failed to configure the HTTPS proxy", { + cause: err, + }); + } +} diff --git a/src/webhook.js b/src/webhook.js index 774db82c..8a351d7e 100644 --- a/src/webhook.js +++ b/src/webhook.js @@ -1,7 +1,7 @@ import webhook from "@slack/webhook"; -import { HttpsProxyAgent } from "https-proxy-agent"; import Config from "./config.js"; import SlackError from "./errors.js"; +import { fetch } from "./proxies.js"; /** * This Webhook class posts the configured payload to the provided webhook, with @@ -19,7 +19,7 @@ export default class Webhook { } const url = config.inputs.webhook; const options = { - agent: this.proxies(config), + fetch: fetch(config, url), retryConfig: this.retries(config.inputs.retries), }; try { @@ -58,45 +58,6 @@ export default class Webhook { } } - /** - * Return configurations for http proxy options if these are set. - * @param {Config} config - * @returns {HttpsProxyAgent | undefined} - * @see {@link https://github.com/slackapi/slack-github-action/pull/132} - * @see {@link https://github.com/slackapi/slack-github-action/pull/205} - */ - proxies(config) { - const { webhook, proxy } = config.inputs; - if (!webhook) { - throw new SlackError(config.core, "No webhook was provided to proxy to"); - } - if (!proxy) { - return undefined; - } - try { - if (new URL(webhook).protocol !== "https:") { - config.core.debug( - "The webhook destination is not HTTPS so skipping the HTTPS proxy", - ); - return undefined; - } - switch (new URL(proxy).protocol) { - case "https:": - case "http:": - return new HttpsProxyAgent(proxy); - default: - throw new SlackError( - config.core, - `Unsupported URL protocol: ${proxy}`, - ); - } - } catch (/** @type {any} */ err) { - throw new SlackError(config.core, "Failed to configure the HTTPS proxy", { - cause: err, - }); - } - } - /** * Return configurations for retry options with different delays. * @param {string} option diff --git a/test/client.spec.js b/test/client.spec.js index c6e9a2f6..b9e69f8d 100644 --- a/test/client.spec.js +++ b/test/client.spec.js @@ -1,7 +1,6 @@ import assert from "node:assert"; import { beforeEach, describe, it } from "node:test"; import webapi from "@slack/web-api"; -import errors from "@slack/web-api/dist/errors.js"; import sinon from "sinon"; import Client from "../src/client.js"; import Config from "../src/config.js"; @@ -90,7 +89,7 @@ describe("client", () => { assert.ok(constructors.calledWithNew()); assert.ok( constructors.calledWith("xoxb-example-002", { - agent: undefined, + fetch: undefined, allowAbsoluteUrls: false, logger: config.logger, retryConfig: webapi.retryPolicies.fiveRetriesInFiveMinutes, @@ -137,7 +136,7 @@ describe("client", () => { assert.ok(constructors.calledWithNew()); assert.ok( constructors.calledWith("ollamapassword", { - agent: undefined, + fetch: undefined, allowAbsoluteUrls: false, logger: config.logger, retryConfig: webapi.retryPolicies.tenRetriesInAboutThirtyMinutes, @@ -286,23 +285,14 @@ describe("client", () => { describe("failure", () => { it("errors when the request to the api cannot be sent correct", async () => { - /** - * @type {webapi.WebAPICallError} - */ - const response = { - code: "slack_webapi_request_error", - data: { - error: "unexpected_request_failure", - message: "Something bad happened!", - }, - }; + const response = new Error("Something bad happened!"); try { mocks.core.getInput.reset(); mocks.core.getBooleanInput.withArgs("errors").returns(true); mocks.core.getInput.withArgs("method").returns("chat.postMessage"); mocks.core.getInput.withArgs("token").returns("xoxb-example"); mocks.core.getInput.withArgs("payload").returns(`"text": "hello"`); - mocks.calls.rejects(errors.requestErrorWithOriginal(response, true)); + mocks.calls.rejects(new webapi.WebAPIRequestError(response)); await send(mocks.core); assert.fail("Expected an error but none was found"); } catch (_err) { @@ -320,24 +310,19 @@ describe("client", () => { }); it("errors when the http portion of the request fails to send", async () => { - /** - * @type {import("axios").AxiosResponse} - */ - const response = { - code: "slack_webapi_http_error", - headers: { + const response = new webapi.WebAPIHTTPError( + 500, + "Internal Server Error", + { authorization: "none", }, - data: { - ok: false, - error: "unknown_http_method", - }, - }; + { ok: false, error: "unknown_http_method" }, + ); try { mocks.core.getInput.withArgs("method").returns("chat.postMessage"); mocks.core.getInput.withArgs("token").returns("xoxb-example"); mocks.core.getInput.withArgs("payload").returns(`"text": "hello"`); - mocks.calls.rejects(errors.httpErrorFromResponse(response)); + mocks.calls.rejects(response); await send(mocks.core); assert.fail("Expected an error but none was found"); } catch (_err) { @@ -345,11 +330,9 @@ describe("client", () => { assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok"); assert.equal(mocks.core.setOutput.getCall(0).lastArg, false); assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response"); - response.body = response.data; - response.data = undefined; - assert.deepEqual( - mocks.core.setOutput.getCall(1).lastArg, - JSON.stringify(response), + assert.equal( + JSON.parse(mocks.core.setOutput.getCall(1).lastArg).statusCode, + 500, ); assert.equal(mocks.core.setOutput.getCall(2).firstArg, "time"); assert.equal(mocks.core.setOutput.getCalls().length, 3); @@ -357,23 +340,14 @@ describe("client", () => { }); it("errors when the payload arguments are invalid for the api", async () => { - /** - * @type {webapi.WebAPICallError} - */ - const response = { - code: "slack_webapi_platform_error", - data: { - ok: false, - error: "missing_channel", - }, - }; + const response = { ok: false, error: "missing_channel" }; try { mocks.core.getInput.reset(); mocks.core.getBooleanInput.withArgs("errors").returns(true); mocks.core.getInput.withArgs("method").returns("chat.postMessage"); mocks.core.getInput.withArgs("token").returns("xoxb-example"); mocks.core.getInput.withArgs("payload").returns(`"text": "hello"`); - mocks.calls.rejects(errors.platformErrorFromResult(response)); + mocks.calls.rejects(new webapi.WebAPIPlatformError(response)); await send(mocks.core); assert.fail("Expected an error but none was found"); } catch (_err) { @@ -391,18 +365,12 @@ describe("client", () => { }); it("returns the api error and details without a exit failing", async () => { - const response = { - code: "slack_webapi_platform_error", - data: { - ok: false, - error: "missing_channel", - }, - }; + const response = { ok: false, error: "missing_channel" }; try { mocks.core.getInput.withArgs("method").returns("chat.postMessage"); mocks.core.getInput.withArgs("token").returns("xoxb-example"); mocks.core.getInput.withArgs("payload").returns(`"text": "hello"`); - mocks.calls.rejects(errors.platformErrorFromResult(response)); + mocks.calls.rejects(new webapi.WebAPIPlatformError(response)); await send(mocks.core); assert.fail("Expected an error but none was found"); } catch (_err) { @@ -420,15 +388,11 @@ describe("client", () => { }); it("errors if rate limit responses are returned after retries", async () => { - const response = { - code: "slack_webapi_rate_limited_error", - retryAfter: 12, - }; try { mocks.core.getInput.withArgs("method").returns("chat.postMessage"); mocks.core.getInput.withArgs("token").returns("xoxb-example"); mocks.core.getInput.withArgs("payload").returns(`"text": "hello"`); - mocks.calls.rejects(errors.rateLimitedErrorWithDelay(12)); + mocks.calls.rejects(new webapi.WebAPIRateLimitedError(12)); await send(mocks.core); assert.fail("Expected an error but none was found"); } catch (_err) { @@ -436,9 +400,9 @@ describe("client", () => { assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok"); assert.equal(mocks.core.setOutput.getCall(0).lastArg, false); assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response"); - assert.deepEqual( - mocks.core.setOutput.getCall(1).lastArg, - JSON.stringify(response), + assert.equal( + JSON.parse(mocks.core.setOutput.getCall(1).lastArg).retryAfter, + 12, ); assert.equal(mocks.core.setOutput.getCall(2).firstArg, "time"); assert.equal(mocks.core.setOutput.getCalls().length, 3); @@ -446,41 +410,6 @@ describe("client", () => { }); }); - describe("proxies", () => { - it("sets up the proxy agent for the provided https proxy", async () => { - const proxy = "https://example.com"; - mocks.core.getInput.withArgs("method").returns("chat.postMessage"); - mocks.core.getInput.withArgs("proxy").returns(proxy); - mocks.core.getInput.withArgs("token").returns("xoxb-example"); - const config = new Config(mocks.core); - const client = new Client(); - const { httpsAgent, proxy: proxying } = client.proxies(config); - assert.deepEqual(httpsAgent.proxy, new URL(proxy)); - assert.notStrictEqual(proxying, false); - }); - - it("fails to configure proxies with an invalid proxied url", async () => { - const proxy = "https://"; - mocks.core.getInput.withArgs("method").returns("chat.postMessage"); - mocks.core.getInput.withArgs("proxy").returns(proxy); - mocks.core.getInput.withArgs("token").returns("xoxb-example"); - try { - const config = new Config(mocks.core); - const client = new Client(); - client.proxies(config); - assert.fail("An invalid proxy URL was not thrown as error!"); - } catch (err) { - if (err instanceof SlackError) { - assert.ok( - err.message.includes("Failed to configure the HTTPS proxy"), - ); - } else { - assert.fail(err); - } - } - }); - }); - describe("retries", () => { it("uses a default of five retries in requests", async () => { const client = new Client(); diff --git a/test/index.spec.js b/test/index.spec.js index d4901f9f..55ae357e 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -40,6 +40,7 @@ export class Mock { setSecret: this.sandbox.stub(), warning: this.sandbox.stub(), }; + this.fetch = this.sandbox.stub(globalThis, "fetch"); this.fs = this.sandbox.stub(fs); this.webapi = { WebClient: function () { @@ -72,6 +73,7 @@ export class Mock { this.core.setOutput.reset(); this.core.setSecret.reset(); this.core.warning.reset(); + this.fetch.reset(); this.webapi = { WebClient: function () { this.apiCall = () => ({ diff --git a/test/proxies.spec.js b/test/proxies.spec.js new file mode 100644 index 00000000..f4ae9227 --- /dev/null +++ b/test/proxies.spec.js @@ -0,0 +1,133 @@ +import assert from "node:assert"; +import { beforeEach, describe, it } from "node:test"; +import Config from "../src/config.js"; +import SlackError from "../src/errors.js"; +import { fetch, proxies } from "../src/proxies.js"; +import { mocks } from "./index.spec.js"; + +describe("proxies", () => { + beforeEach(() => { + mocks.reset(); + }); + + describe("fetch", () => { + it("returns a custom fetch function when a proxy is configured", async () => { + mocks.core.getInput.withArgs("method").returns("chat.postMessage"); + mocks.core.getInput.withArgs("proxy").returns("https://example.com"); + mocks.core.getInput.withArgs("token").returns("xoxb-example"); + const config = new Config(mocks.core); + const fetchFn = fetch(config); + assert.strictEqual(typeof fetchFn, "function"); + }); + + it("returns undefined when no proxy is configured", async () => { + mocks.core.getInput.withArgs("method").returns("chat.postMessage"); + mocks.core.getInput.withArgs("token").returns("xoxb-example"); + const config = new Config(mocks.core); + const fetchFn = fetch(config); + assert.strictEqual(fetchFn, undefined); + }); + + it("fails to configure a fetch with an invalid proxied url", async () => { + mocks.core.getInput.withArgs("method").returns("chat.postMessage"); + mocks.core.getInput.withArgs("proxy").returns("not-a-url"); + mocks.core.getInput.withArgs("token").returns("xoxb-example"); + try { + const config = new Config(mocks.core); + fetch(config); + assert.fail("An invalid proxy URL was not thrown as error!"); + } catch (err) { + if (err instanceof SlackError) { + assert.ok( + err.message.includes("Failed to configure the HTTPS proxy"), + ); + } else { + assert.fail(err); + } + } + }); + }); + + describe("dispatcher", () => { + it("returns no dispatcher when a proxy is not configured", async () => { + mocks.core.getInput + .withArgs("webhook") + .returns("https://hooks.slack.com"); + mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); + const config = new Config(mocks.core); + const dispatcher = proxies(config, config.inputs.webhook); + assert.strictEqual(dispatcher, undefined); + }); + + it("skips proxying a non-https destination altogether", async () => { + mocks.core.getInput.withArgs("webhook").returns("http://hooks.slack.com"); + mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); + mocks.core.getInput.withArgs("proxy").returns("https://example.com"); + const config = new Config(mocks.core); + const dispatcher = proxies(config, config.inputs.webhook); + assert.strictEqual(dispatcher, undefined); + }); + + it("returns a proxy dispatcher for the provided https proxy", async () => { + mocks.core.getInput + .withArgs("webhook") + .returns("https://hooks.slack.com"); + mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); + mocks.core.getInput.withArgs("proxy").returns("https://example.com"); + const config = new Config(mocks.core); + const dispatcher = proxies(config, config.inputs.webhook); + assert.ok(dispatcher); + }); + + it("returns a proxy dispatcher for http proxies", async () => { + mocks.core.getInput + .withArgs("webhook") + .returns("https://hooks.slack.com"); + mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); + mocks.core.getInput.withArgs("proxy").returns("http://example.com"); + const config = new Config(mocks.core); + const dispatcher = proxies(config, config.inputs.webhook); + assert.ok(dispatcher); + }); + + it("fails to configure a dispatcher with an invalid proxied url", async () => { + mocks.core.getInput + .withArgs("webhook") + .returns("https://hooks.slack.com"); + mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); + mocks.core.getInput.withArgs("proxy").returns("https://"); + try { + const config = new Config(mocks.core); + proxies(config, config.inputs.webhook); + assert.fail("An invalid proxy URL was not thrown as error!"); + } catch (err) { + if (err instanceof SlackError) { + assert.ok( + err.message.includes("Failed to configure the HTTPS proxy"), + ); + } else { + assert.fail(err); + } + } + }); + + it("fails to configure a dispatcher with an unknown url protocol", async () => { + mocks.core.getInput + .withArgs("webhook") + .returns("https://hooks.slack.com"); + mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); + mocks.core.getInput.withArgs("proxy").returns("ssh://example.com"); + try { + const config = new Config(mocks.core); + proxies(config, config.inputs.webhook); + assert.fail("An unknown URL protocol was not thrown as error!"); + } catch (err) { + if (err instanceof SlackError) { + assert.ok(err.message.includes("Unsupported URL protocol")); + } else { + assert.fail(err); + } + } + }); + }); +}); diff --git a/test/webhook.spec.js b/test/webhook.spec.js index ddcd85de..91dcc88b 100644 --- a/test/webhook.spec.js +++ b/test/webhook.spec.js @@ -174,122 +174,6 @@ describe("webhook", () => { }); }); - describe("proxies", () => { - it("requires a webhook is included in the inputs", async () => { - /** - * @type {Config} - */ - const config = { - core: mocks.core, - inputs: {}, - }; - try { - new Webhook().proxies(config); - assert.fail("Failed to throw for missing input"); - } catch (err) { - if (err instanceof SlackError) { - assert.ok( - err.message.includes("No webhook was provided to proxy to"), - ); - } else { - assert.fail(err); - } - } - }); - - it("skips proxying an http webhook url altogether", async () => { - mocks.core.getInput.withArgs("webhook").returns("http://hooks.slack.com"); - mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); - mocks.core.getInput.withArgs("proxy").returns("https://example.com"); - const config = new Config(mocks.core); - const webhook = new Webhook(); - assert.strictEqual(webhook.proxies(config), undefined); - }); - - it("sets up the proxy agent for the provided https proxy", async () => { - const proxy = "https://example.com"; - mocks.core.getInput - .withArgs("webhook") - .returns("https://hooks.slack.com"); - mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); - mocks.core.getInput.withArgs("proxy").returns(proxy); - const config = new Config(mocks.core); - const webhook = new Webhook(); - const httpsAgent = webhook.proxies(config); - assert.deepEqual(httpsAgent.proxy, new URL(proxy)); - }); - - it("sets up the proxy agent for the provided http proxy", async () => { - const proxy = "http://example.com"; - mocks.core.getInput - .withArgs("webhook") - .returns("https://hooks.slack.com"); - mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); - mocks.core.getInput.withArgs("proxy").returns(proxy); - const config = new Config(mocks.core); - const webhook = new Webhook(); - const httpsAgent = webhook.proxies(config); - assert.deepEqual(httpsAgent.proxy, new URL(proxy)); - }); - - it("returns undefined when no proxy is set", async () => { - mocks.core.getInput - .withArgs("webhook") - .returns("https://hooks.slack.com"); - mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); - const config = new Config(mocks.core); - const webhook = new Webhook(); - assert.strictEqual(webhook.proxies(config), undefined); - }); - - it("fails to configure proxies with an invalid proxied url", async () => { - const proxy = "https://"; - mocks.core.getInput - .withArgs("webhook") - .returns("https://hooks.slack.com"); - mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); - mocks.core.getInput.withArgs("proxy").returns(proxy); - try { - const config = new Config(mocks.core); - const webhook = new Webhook(); - webhook.proxies(config); - assert.fail("An invalid proxy URL was not thrown as error!"); - } catch (err) { - if (err instanceof SlackError) { - assert.ok( - err.message.includes("Failed to configure the HTTPS proxy"), - ); - } else { - assert.fail(err); - } - } - }); - - it("fails to configure proxies with an unknown url protocol", async () => { - const proxy = "ssh://"; - mocks.core.getInput - .withArgs("webhook") - .returns("https://hooks.slack.com"); - mocks.core.getInput.withArgs("webhook-type").returns("incoming-webhook"); - mocks.core.getInput.withArgs("proxy").returns(proxy); - try { - const config = new Config(mocks.core); - const webhook = new Webhook(); - webhook.proxies(config); - assert.fail("An unknown URL protocol was not thrown as error!"); - } catch (err) { - if (err instanceof SlackError) { - assert.ok( - err.message.includes("Failed to configure the HTTPS proxy"), - ); - assert.ok(err.cause?.message?.includes("Unsupported URL protocol")); - } else { - assert.fail(err); - } - } - }); - }); - describe("retries", () => { it("uses a default of five retries in requests", async () => { const result = new Webhook().retries();