Skip to content

Commit

Permalink
@slack/web-api: prep for next major release. bump min node to v18 (#1667
Browse files Browse the repository at this point in the history
)
  • Loading branch information
filmaj authored Oct 5, 2023
1 parent 1374422 commit 6e8a31e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 121 deletions.
19 changes: 4 additions & 15 deletions packages/web-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,16 @@ The `@slack/web-api` package contains a simple, convenient, and configurable HTT

## Requirements

This package supports Node v14 and higher. It's highly recommended to use [the latest LTS version of
This package supports Node v18 and higher. It's highly recommended to use [the latest LTS version of
node](https://github.com/nodejs/Release#release-schedule), and the documentation is written using syntax and features
from that version.

This package also has experimental support for Deno v1.15.2 and higher, though not all features are supported at this
time.

## Installation

### Node.js

```shell
$ npm install @slack/web-api
```

### Deno

```typescript
import { WebClient } from 'https://deno.land/x/slack_web_api/mod.js';
```

<!-- START: Remove before copying into the docs directory -->

## Usage
Expand Down Expand Up @@ -394,6 +383,6 @@ If you get stuck, we're here to help. The following are the best ways to get ass

* [Issue Tracker](http://github.com/slackapi/node-slack-sdk/issues) for questions, feature requests, bug reports and
general discussion related to these packages. Try searching before you create a new issue.
* [Email us](mailto:developers@slack.com) in Slack developer support: `developers@slack.com`
* [Bot Developers Hangout](https://community.botkit.ai/): a Slack community for developers
building all types of bots. You can find the maintainers and users of these packages in **#sdk-node-slack-sdk**.
* [Email us](mailto:feedback@slack.com): `feedback@slack.com`
* [Community Slack](https://community.slack.com/): a Slack community for developers
building all kinds of Slack apps. You can find the maintainers and users of these packages in **#lang-javascript**.
65 changes: 31 additions & 34 deletions packages/web-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"dist/**/*"
],
"engines": {
"node": ">= 12.13.0",
"npm": ">= 6.12.0"
"node": ">= 18",
"npm": ">= 8.6.0"
},
"repository": "slackapi/node-slack-sdk",
"homepage": "https://slack.dev/node-slack-sdk/web-api",
Expand All @@ -37,51 +37,48 @@
"build": "npm run build:clean && tsc",
"build:clean": "shx rm -rf ./dist ./coverage ./.nyc_output",
"lint": "eslint --ext .ts src",
"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",
"mocha": "mocha --config .mocharc.json src/*.spec.js",
"test": "npm run lint && npm run test:unit && npm run test:types",
"test:unit": "npm run build && nyc --reporter=text-summary npm run mocha",
"test:types": "tsd",
"coverage": "codecov -F webapi --root=$PWD",
"ref-docs:model": "api-extractor run",
"watch": "npx nodemon --watch 'src' --ext 'ts' --exec npm run build",
"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"
"watch": "npx nodemon --watch 'src' --ext 'ts' --exec npm run build"
},
"dependencies": {
"@slack/logger": "^3.0.0",
"@slack/types": "^2.8.0",
"@types/is-stream": "^1.1.0",
"@types/node": ">=12.0.0",
"axios": "^0.27.2",
"eventemitter3": "^3.1.0",
"form-data": "^2.5.0",
"@slack/logger": "^4.0.0",
"@slack/types": "^2.9.0",
"@types/node": ">=18.0.0",
"axios": "^1.5.1",
"eventemitter3": "^5.0.1",
"form-data": "^4.0.0",
"is-electron": "2.2.2",
"is-stream": "^1.1.0",
"p-queue": "^6.6.1",
"p-retry": "^4.0.0"
"is-stream": "^2.0.0",
"p-queue": "^6.6.2",
"p-retry": "^4.6.1",
"retry": "^0.13.1"
},
"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",
"@microsoft/api-extractor": "^7.38.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"busboy": "^1.6.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",
"chai": "^4.3.8",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^9.1.0",
"nock": "^13.2.6",
"mocha": "^10.2.0",
"nock": "^13.3.3",
"nyc": "^15.1.0",
"shelljs": "^0.8.3",
"shx": "^0.3.2",
"sinon": "^7.2.7",
"source-map-support": "^0.5.10",
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.8.1",
"tsd": "0.29.0",
"typescript": "^4.1"
Expand Down
15 changes: 0 additions & 15 deletions packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ describe('WebClient', function () {
assert.instanceOf(client, WebClient);
assert.notExists(client.axios.defaults.headers.Authorization);
});
it('should not modify global defaults in axios', function () {
// https://github.com/slackapi/node-slack-sdk/issues/1037
const client = new WebClient();

const globalDefault = axios.defaults.headers.post['Content-Type'];
// The axios.default's defaults should not be modified.
// Specifically, defaults.headers.post should be kept as-is
assert.exists(globalDefault);

const instanceDefault = client.axios.defaults.headers.post['Content-Type'];
// WebClient intentionally removes the default Content-Type
// from the underlying AxiosInstance used for performing web API calls
assert.notExists(instanceDefault)
});
});

describe('Methods superclass', function () {
Expand Down Expand Up @@ -149,7 +135,6 @@ describe('WebClient', function () {
assert.equal(error.code, ErrorCode.RequestError);
assert.equal(error.original.config.timeout, timeoutOverride);
assert.equal(error.original.isAxiosError, true);
assert.equal(error.original.request.aborted, true);
done();
} catch (err) {
done(err);
Expand Down
7 changes: 3 additions & 4 deletions packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class WebClient extends Methods {
this.axios = axios.create({
timeout,
baseURL: slackApiUrl,
// eslint-disable-next-line @typescript-eslint/naming-convention
headers: isElectron() ? headers : { 'User-Agent': getUserAgent(), ...headers },
httpAgent: agent,
httpsAgent: agent,
Expand All @@ -220,7 +221,6 @@ export class WebClient extends Methods {

/**
* Generic method for calling a Web API method
*
* @param method - the Web API method to call {@link https://api.slack.com/methods}
* @param options - options
*/
Expand Down Expand Up @@ -299,7 +299,6 @@ export class WebClient extends Methods {
* The for-await-of syntax is part of ES2018. It is available natively in Node starting with v10.0.0. You may be able
* to use it in earlier JavaScript runtimes by transpiling your source with a tool like Babel. However, the
* transpiled code will likely sacrifice performance.
*
* @param method - the cursor-paginated Web API method to call {@link https://api.slack.com/docs/pagination}
* @param options - options
* @param shouldStop - a predicate that is called with each page, and should return true when pagination can end.
Expand Down Expand Up @@ -592,7 +591,6 @@ export class WebClient extends Methods {
* a string, used when posting with a content-type of url-encoded. Or, it can be a readable stream, used
* when the options contain a binary (a stream or a buffer) and the upload should be done with content-type
* multipart/form-data.
*
* @param options - arguments for the Web API method
* @param headers - a mutable object representing the HTTP headers for the outgoing request
*/
Expand Down Expand Up @@ -760,7 +758,8 @@ export default WebClient;
* @param pageSize - the maximum number of additional items to fetch in the next request.
*/
function paginationOptionsForNextPage(
previousResult: WebAPICallResult | undefined, pageSize: number,
previousResult: WebAPICallResult | undefined,
pageSize: number,
): CursorPaginationEnabled | undefined {
if (
previousResult !== undefined &&
Expand Down
8 changes: 7 additions & 1 deletion packages/web-api/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ export function httpErrorFromResponse(response: AxiosResponse): WebAPIHTTPError
) as Partial<WebAPIHTTPError>;
error.statusCode = response.status;
error.statusMessage = response.statusText;
error.headers = response.headers;
const nonNullHeaders: Record<string, string> = {};
Object.keys(response.headers).forEach((k) => {
if (k && response.headers[k]) {
nonNullHeaders[k] = response.headers[k];
}
});
error.headers = nonNullHeaders;
error.body = response.data;
return (error as WebAPIHTTPError);
}
Expand Down
Loading

0 comments on commit 6e8a31e

Please sign in to comment.