diff --git a/dist/index.js b/dist/index.js index 731c0010..2abc5792 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2201,6 +2201,7 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getUserAgent = exports.addAppMetadata = void 0; const os = __importStar(__nccwpck_require__(2037)); +const path_1 = __nccwpck_require__(1017); // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs const packageJson = __nccwpck_require__(9087); /** @@ -2209,8 +2210,14 @@ const packageJson = __nccwpck_require__(9087); function replaceSlashes(s) { return s.replace('/', ':'); } +// TODO: for the deno build (see the `npm run build:deno` npm run script), we could replace the `os-browserify` npm +// module shim with our own shim leveraging the deno beta compatibility layer for node's `os` module (for more info +// see https://deno.land/std@0.116.0/node/os.ts). At the time of writing this TODO (2021/11/25), this required deno +// v1.16.2 and use of the --unstable flag. Once support for this exists without the --unstable flag, we can improve +// the `os` module deno shim to correctly report operating system from a deno runtime. Until then, the below `os`- +// based code will report "browser/undefined" from a deno runtime. const baseUserAgent = `${replaceSlashes(packageJson.name)}/${packageJson.version} ` + - `node/${process.version.replace('v', '')} ` + + `${(0, path_1.basename)(process.title)}/${process.version.replace('v', '')} ` + `${os.platform()}/${os.release()}`; const appMetadata = {}; /** @@ -2321,6 +2328,7 @@ class Methods extends eventemitter3_1.EventEmitter { }, clearResolution: bindApiCall(this, 'admin.apps.clearResolution'), requests: { + cancel: bindApiCall(this, 'admin.apps.requests.cancel'), list: bindApiCall(this, 'admin.apps.requests.list'), }, restrict: bindApiCall(this, 'admin.apps.restrict'), @@ -3305,8 +3313,10 @@ module.exports = function httpAdapter(config) { done(); resolvePromise(value); }; + var rejected = false; var reject = function reject(value) { done(); + rejected = true; rejectPromise(value); }; var data = config.data; @@ -3344,6 +3354,10 @@ module.exports = function httpAdapter(config) { )); } + if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) { + return reject(createError('Request body larger than maxBodyLength limit', config)); + } + // Add Content-Length header if data exists if (!headerNames['content-length']) { headers['Content-Length'] = data.length; @@ -3514,27 +3528,40 @@ module.exports = function httpAdapter(config) { // make sure the content length is not over the maxContentLength if specified if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) { + // stream.destoy() emit aborted event before calling reject() on Node.js v16 + rejected = true; stream.destroy(); reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded', config, null, lastRequest)); } }); + stream.on('aborted', function handlerStreamAborted() { + if (rejected) { + return; + } + stream.destroy(); + reject(createError('error request aborted', config, 'ERR_REQUEST_ABORTED', lastRequest)); + }); + stream.on('error', function handleStreamError(err) { if (req.aborted) return; reject(enhanceError(err, config, null, lastRequest)); }); stream.on('end', function handleStreamEnd() { - var responseData = Buffer.concat(responseBuffer); - if (config.responseType !== 'arraybuffer') { - responseData = responseData.toString(config.responseEncoding); - if (!config.responseEncoding || config.responseEncoding === 'utf8') { - responseData = utils.stripBOM(responseData); + try { + var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer); + if (config.responseType !== 'arraybuffer') { + responseData = responseData.toString(config.responseEncoding); + if (!config.responseEncoding || config.responseEncoding === 'utf8') { + responseData = utils.stripBOM(responseData); + } } + response.data = responseData; + } catch (err) { + reject(enhanceError(err, config, err.code, response.request, response)); } - - response.data = responseData; settle(resolve, reject, response); }); } @@ -3546,6 +3573,12 @@ module.exports = function httpAdapter(config) { reject(enhanceError(err, config, null, req)); }); + // set tcp keep alive to prevent drop connection by peer + req.on('socket', function handleRequestSocket(socket) { + // default interval of sending ack packet is 1 minute + socket.setKeepAlive(true, 1000 * 60); + }); + // Handle request timeout if (config.timeout) { // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types. @@ -4094,14 +4127,18 @@ function Axios(instanceConfig) { * * @param {Object} config The config specific for this request (merged with this.defaults) */ -Axios.prototype.request = function request(config) { +Axios.prototype.request = function request(configOrUrl, config) { /*eslint no-param-reassign:0*/ // Allow for axios('example/url'[, config]) a la fetch API - if (typeof config === 'string') { - config = arguments[1] || {}; - config.url = arguments[0]; - } else { + if (typeof configOrUrl === 'string') { config = config || {}; + config.url = configOrUrl; + } else { + config = configOrUrl || {}; + } + + if (!config.url) { + throw new Error('Provided config url is not valid'); } config = mergeConfig(this.defaults, config); @@ -4186,6 +4223,9 @@ Axios.prototype.request = function request(config) { }; Axios.prototype.getUri = function getUri(config) { + if (!config.url) { + throw new Error('Provided config url is not valid'); + } config = mergeConfig(this.defaults, config); return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, ''); }; @@ -4796,7 +4836,7 @@ module.exports = defaults; /***/ ((module) => { module.exports = { - "version": "0.24.0" + "version": "0.25.0" }; /***/ }), @@ -4997,18 +5037,20 @@ module.exports = function isAbsoluteURL(url) { // A URL is considered absolute if it begins with "://" or "//" (protocol-relative URL). // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed // by any combination of letters, digits, plus, period, or hyphen. - return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); + return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url); }; /***/ }), /***/ 650: -/***/ ((module) => { +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { "use strict"; +var utils = __nccwpck_require__(328); + /** * Determines whether the payload is an error thrown by Axios * @@ -5016,7 +5058,7 @@ module.exports = function isAbsoluteURL(url) { * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false */ module.exports = function isAxiosError(payload) { - return (typeof payload === 'object') && (payload.isAxiosError === true); + return utils.isObject(payload) && (payload.isAxiosError === true); }; @@ -5323,7 +5365,7 @@ var toString = Object.prototype.toString; * @returns {boolean} True if value is an Array, otherwise false */ function isArray(val) { - return toString.call(val) === '[object Array]'; + return Array.isArray(val); } /** @@ -5364,7 +5406,7 @@ function isArrayBuffer(val) { * @returns {boolean} True if value is an FormData, otherwise false */ function isFormData(val) { - return (typeof FormData !== 'undefined') && (val instanceof FormData); + return toString.call(val) === '[object FormData]'; } /** @@ -5378,7 +5420,7 @@ function isArrayBufferView(val) { if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) { result = ArrayBuffer.isView(val); } else { - result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer); + result = (val) && (val.buffer) && (isArrayBuffer(val.buffer)); } return result; } @@ -5485,7 +5527,7 @@ function isStream(val) { * @returns {boolean} True if value is a URLSearchParams object, otherwise false */ function isURLSearchParams(val) { - return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; + return toString.call(val) === '[object URLSearchParams]'; } /** @@ -10450,7 +10492,7 @@ module.exports = require("zlib"); /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"_args":[["@slack/web-api@6.5.1","/home/runner/work/slack-upload-file/slack-upload-file"]],"_from":"@slack/web-api@6.5.1","_id":"@slack/web-api@6.5.1","_inBundle":false,"_integrity":"sha512-W1PDIdHz/GtDpC8afpPUsXMfAQ+sZGwmfxx+Ug83uhRD8zECrypGTmIyCqrCSWzf2qVKT9XvMftZX3m0AmPY8A==","_location":"/@slack/web-api","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@slack/web-api@6.5.1","name":"@slack/web-api","escapedName":"@slack%2fweb-api","scope":"@slack","rawSpec":"6.5.1","saveSpec":null,"fetchSpec":"6.5.1"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/@slack/web-api/-/web-api-6.5.1.tgz","_spec":"6.5.1","_where":"/home/runner/work/slack-upload-file/slack-upload-file","author":{"name":"Slack Technologies, LLC"},"bugs":{"url":"https://github.com/slackapi/node-slack-sdk/issues"},"dependencies":{"@slack/logger":"^3.0.0","@slack/types":"^2.0.0","@types/is-stream":"^1.1.0","@types/node":">=12.0.0","axios":"^0.24.0","eventemitter3":"^3.1.0","form-data":"^2.5.0","is-electron":"2.2.0","is-stream":"^1.1.0","p-queue":"^6.6.1","p-retry":"^4.0.0"},"description":"Official library for using the Slack Platform\'s Web API","devDependencies":{"@aoberoi/capture-console":"^1.1.0","@microsoft/api-extractor":"^7.3.4","@types/chai":"^4.1.7","@types/mocha":"^5.2.6","@typescript-eslint/eslint-plugin":"^4.4.1","@typescript-eslint/parser":"^4.4.0","busboy":"^0.3.0","chai":"^4.2.0","codecov":"^3.2.0","esbuild":"^0.13.15","eslint":"^7.32.0","eslint-config-airbnb-base":"^14.2.1","eslint-config-airbnb-typescript":"^12.3.1","eslint-plugin-import":"^2.22.1","eslint-plugin-jsdoc":"^30.6.1","eslint-plugin-node":"^11.1.0","mocha":"^9.1.0","nock":"^13.1.0","nyc":"^14.1.1","shelljs":"^0.8.3","shx":"^0.3.2","sinon":"^7.2.7","source-map-support":"^0.5.10","ts-node":"^9.0.0","tsd":"^0.13.1","typescript":"^4.1"},"engines":{"node":">= 12.13.0","npm":">= 6.12.0"},"files":["dist/**/*"],"homepage":"https://slack.dev/node-slack-sdk/web-api","keywords":["slack","web-api","bot","client","http","api","proxy","rate-limiting","pagination"],"license":"MIT","main":"dist/index.js","name":"@slack/web-api","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/slackapi/node-slack-sdk.git"},"scripts":{"build":"npm run build:clean && tsc","build:clean":"shx rm -rf ./dist ./coverage ./.nyc_output","build:deno":"esbuild --bundle --define:process.cwd=String --define:process.version=\'\\"v16.0.0\\"\' --define:Buffer=dummy_buffer --inject:./deno-shims/buffer-shim.js --target=esnext --format=esm --outfile=./mod.js src/index.ts","coverage":"codecov -F webapi --root=$PWD","lint":"eslint --ext .ts src","prepare":"npm run build","ref-docs:model":"api-extractor run","test":"npm run lint && npm run build && npm run test:mocha && npm run test:types","test:mocha":"nyc mocha --config .mocharc.json src/*.spec.js","test:types":"tsd","watch":"npx nodemon --watch \'src\' --ext \'ts\' --exec npm run build"},"tsd":{"directory":"test/types"},"types":"./dist/index.d.ts","version":"6.5.1"}'); +module.exports = JSON.parse('{"_args":[["@slack/web-api@6.6.0","/home/runner/work/slack-upload-file/slack-upload-file"]],"_from":"@slack/web-api@6.6.0","_id":"@slack/web-api@6.6.0","_inBundle":false,"_integrity":"sha512-4z8tBBIQFojH9uSrsmnI0pGDpOZmJ3UO+Ewwtj3SfkokAUJz3d2dSH5sPk9jKcGfx39e34LoJ+l1YSavvHQeeg==","_location":"/@slack/web-api","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@slack/web-api@6.6.0","name":"@slack/web-api","escapedName":"@slack%2fweb-api","scope":"@slack","rawSpec":"6.6.0","saveSpec":null,"fetchSpec":"6.6.0"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/@slack/web-api/-/web-api-6.6.0.tgz","_spec":"6.6.0","_where":"/home/runner/work/slack-upload-file/slack-upload-file","author":{"name":"Slack Technologies, LLC"},"bugs":{"url":"https://github.com/slackapi/node-slack-sdk/issues"},"dependencies":{"@slack/logger":"^3.0.0","@slack/types":"^2.0.0","@types/is-stream":"^1.1.0","@types/node":">=12.0.0","axios":"^0.25.0","eventemitter3":"^3.1.0","form-data":"^2.5.0","is-electron":"2.2.0","is-stream":"^1.1.0","p-queue":"^6.6.1","p-retry":"^4.0.0"},"description":"Official library for using the Slack Platform\'s Web API","devDependencies":{"@aoberoi/capture-console":"^1.1.0","@microsoft/api-extractor":"^7.3.4","@types/chai":"^4.1.7","@types/mocha":"^5.2.6","@typescript-eslint/eslint-plugin":"^4.4.1","@typescript-eslint/parser":"^4.4.0","busboy":"^0.3.0","chai":"^4.2.0","codecov":"^3.2.0","esbuild":"^0.13.15","eslint":"^7.32.0","eslint-config-airbnb-base":"^14.2.1","eslint-config-airbnb-typescript":"^12.3.1","eslint-plugin-import":"^2.22.1","eslint-plugin-jsdoc":"^30.6.1","eslint-plugin-node":"^11.1.0","mocha":"^9.1.0","nock":"^13.1.0","nyc":"^15.1.0","shelljs":"^0.8.3","shx":"^0.3.2","sinon":"^7.2.7","source-map-support":"^0.5.10","ts-node":"^9.0.0","tsd":"^0.13.1","typescript":"^4.1"},"engines":{"node":">= 12.13.0","npm":">= 6.12.0"},"files":["dist/**/*"],"homepage":"https://slack.dev/node-slack-sdk/web-api","keywords":["slack","web-api","bot","client","http","api","proxy","rate-limiting","pagination"],"license":"MIT","main":"dist/index.js","name":"@slack/web-api","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/slackapi/node-slack-sdk.git"},"scripts":{"build":"npm run build:clean && tsc","build:clean":"shx rm -rf ./dist ./coverage ./.nyc_output","build:deno":"esbuild --bundle --define:process.cwd=String --define:process.version=\'\\"v1.15.2\\"\' --define:process.title=\'\\"deno\\"\' --define:Buffer=dummy_buffer --inject:./deno-shims/buffer-shim.js --inject:./deno-shims/xhr-shim.js --target=esnext --format=esm --outfile=./mod.js src/index.ts","coverage":"codecov -F webapi --root=$PWD","lint":"eslint --ext .ts src","prepare":"npm run build","ref-docs:model":"api-extractor run","test":"npm run lint && npm run build && npm run test:mocha && npm run test:types","test:mocha":"nyc mocha --config .mocharc.json src/*.spec.js","test:types":"tsd","watch":"npx nodemon --watch \'src\' --ext \'ts\' --exec npm run build"},"tsd":{"directory":"test/types"},"types":"./dist/index.d.ts","version":"6.6.0"}'); /***/ }),