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) #1684

Closed
wants to merge 7 commits into from
Closed
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
7 changes: 7 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ jobs:
working-directory: ${{ matrix.package }}
run: |
npm install || npm list
# depending on which package we are testing, also npm link up other dependent packages
case "$PWD" in
*/webhook) pushd ../types && npm i && popd && npm link ../types;;
*/web-api) pushd ../types && npm i && popd && npm link ../types && pushd ../logger && npm i && popd && npm link ../logger;;
# TODO: add oauth and socket-mode here once those packages have new major versions released
*) ;; # default
esac
npm test
2 changes: 1 addition & 1 deletion packages/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $ npm install @slack/types

## Usage

This package exports a many different types and interfaces. It is best to peruse the source code to see what is
This package exports many different types and interfaces. It is best to peruse the source code to see what is
available, but a brief list:

- Block Kit blocks and elements (`./src/block-kit/*`)
Expand Down
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.6.0",
"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
16 changes: 0 additions & 16 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 Expand Up @@ -226,7 +211,6 @@ describe('WebClient', function () {
{ method: 'chat.postEphemeral', args: { channel: "C123", blocks: [] } },
{ method: 'chat.postMessage', args: { channel: "C123", blocks: [] } },
{ method: 'chat.scheduleMessage', args: { channel: "C123", post_at: "100000000", blocks: [] } },
{ method: 'chat.update', args: { channel: "C123", ts: "123.456", blocks: [] } },
];
const warningTestPatterns = textWarningTestPatterns.concat(attachmentWarningTestPatterns);

Expand Down
18 changes: 9 additions & 9 deletions packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { SecureContextOptions } from 'tls';
import zlib from 'zlib';
import { TextDecoder } from 'util';
import isStream from 'is-stream';
import PQueue from 'p-queue';
import pQueue from 'p-queue';
import pRetry, { AbortError } from 'p-retry';
import axios, { AxiosInstance, AxiosResponse } from 'axios';
// eslint-disable-next-line @typescript-eslint/naming-convention
import FormData from 'form-data';
import isElectron from 'is-electron';
import {
Expand Down Expand Up @@ -124,7 +125,7 @@ export class WebClient extends Methods {
* Queue of requests in which a maximum of {@link WebClientOptions.maxRequestConcurrency} can concurrently be
* in-flight.
*/
private requestQueue: PQueue;
private requestQueue: pQueue;

/**
* Axios HTTP client instance used by this client
Expand Down Expand Up @@ -178,7 +179,8 @@ export class WebClient extends Methods {
this.slackApiUrl = slackApiUrl;

this.retryConfig = retryConfig;
this.requestQueue = new PQueue({ concurrency: maxRequestConcurrency });
// eslint-disable-next-line new-cap
this.requestQueue = new pQueue({ concurrency: maxRequestConcurrency });
// NOTE: may want to filter the keys to only those acceptable for TLS options
this.tlsConfig = tls !== undefined ? tls : {};
this.rejectRateLimitedCalls = rejectRateLimitedCalls;
Expand All @@ -200,6 +202,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 +223,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 +301,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 @@ -407,7 +408,6 @@ export class WebClient extends Methods {
* URLs returned from step 1 (e.g. https://files.slack.com/upload/v1/...\")
*
* **#3**: Complete uploads {@link https://api.slack.com/methods/files.completeUploadExternal files.completeUploadExternal}
*
* @param options
*/
public async filesUploadV2(options: FilesUploadV2Arguments): Promise<WebAPICallResult> {
Expand Down Expand Up @@ -592,7 +592,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 +759,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 Expand Up @@ -825,7 +825,7 @@ function warnDeprecations(method: string, logger: Logger): void {
* @param options arguments for the Web API method
*/
function warnIfFallbackIsMissing(method: string, logger: Logger, options?: WebAPICallOptions): void {
const targetMethods = ['chat.postEphemeral', 'chat.postMessage', 'chat.scheduleMessage', 'chat.update'];
const targetMethods = ['chat.postEphemeral', 'chat.postMessage', 'chat.scheduleMessage'];
const isTargetMethod = targetMethods.includes(method);

const hasAttachments = (args: WebAPICallOptions) => Array.isArray(args.attachments) && args.attachments.length;
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
Loading