Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@slack/web-api: prep for next major release. bump min node to v18 #1667

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
Copy link
Contributor

@WilliamBergamin WilliamBergamin Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should they email [email protected] or [email protected]? other repos tell developers to email [email protected]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is [email protected]

* [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 () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't feel like this test offers much value and since this PR moves from axios 0.x to 1.x, also not sure how much we should be testing the output of other packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmaj As you can see, the context behind this unit test is #1037 This package had an issue polluting the global singleton instance of axios package. This test tries to prevent the same issue from occurring again. If axois 1.x does not allow such destructive operations to the global singleton, we can safely remove this test. Thus, I don't think we're testing 3rd party library here. We verify our package works without any major side effects.

If investigation on how to properly maintain this test with axios 1.x could require our time and efforts, it's fine to delete the test anyways. Whenever we have something similar in the future, we can add tests again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking this!

// 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In axios 1.0, this assertion no longer passes. Not sure how important that is. Let me know if you have opinions on that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any issues with the deletion

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 @@ -613,7 +612,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 @@ -781,7 +779,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> = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript made me do it 😄

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
Loading