Skip to content

Commit

Permalink
Merge branch 'master' into convert-typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
clavin authored Jul 23, 2019
2 parents 3eabc38 + c3f910b commit b806e32
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/_packages/rtm_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ Import the `HttpsProxyAgent` class, and create an instance that can be used as t

```javascript
const { RTMClient } = require('@slack/rtm-api');
const { HttpsProxyAgent } = require('https-proxy-agent');
const HttpsProxyAgent = require('https-proxy-agent');
const token = process.env.SLACK_BOT_TOKEN;

// One of the ways you can configure HttpsProxyAgent is using a simple string.
Expand Down
2 changes: 1 addition & 1 deletion docs/_packages/web_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Import the `HttpsProxyAgent` class, and create an instance that can be used as t

```javascript
const { WebClient } = require('@slack/web-api');
const { HttpsProxyAgent } = require('https-proxy-agent');
const HttpsProxyAgent = require('https-proxy-agent');
const token = process.env.SLACK_TOKEN;

// One of the ways you can configure HttpsProxyAgent is using a simple string.
Expand Down
6 changes: 3 additions & 3 deletions docs/_packages/webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The webhook can be initialized with default arguments that are reused each time
parameter to the constructor to set the default arguments.

```javascript
const IncomingWebhook = require('@slack/webhook');
const { IncomingWebhook } = require('@slack/webhook');
const url = process.env.SLACK_WEBHOOK_URL;

// Initialize with defaults
Expand All @@ -72,7 +72,7 @@ Something interesting just happened in your app, so its time to send the notific
the message. The method returns a `Promise` that resolves once the notification is sent.

```javascript
const IncomingWebhook = require('@slack/webhook');
const { IncomingWebhook } = require('@slack/webhook');
const url = process.env.SLACK_WEBHOOK_URL;

const webhook = new IncomingWebhook(url);
Expand Down Expand Up @@ -107,7 +107,7 @@ Import the `HttpsProxyAgent` class, and create an instance that can be used as t

```javascript
const { IncomingWebhook } = require('@slack/webhook');
const { HttpsProxyAgent } = require('https-proxy-agent');
const HttpsProxyAgent = require('https-proxy-agent');
const url = process.env.SLACK_WEBHOOK_URL;

// One of the ways you can configure HttpsProxyAgent is using a simple string.
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"npm": ">= 5.5.1"
},
"repository": "slackapi/node-slack-sdk",
"homepage": "https://slack.dev/node-slack-sdk/tutorials/migrating-to-v5/",
"homepage": "https://slack.dev/node-slack-sdk/tutorials/migrating-to-v5",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/events-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"lodash.isfunction": "^3.0.8",
"mocha": "^6.1.4",
"nop": "^1.0.0",
"nyc": "^12.0.2",
"nyc": "^14.1.1",
"proxyquire": "^1.7.10",
"shx": "^0.3.2",
"sinon": "^4.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/interactive-messages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
"eslint": "^4.9.0",
"estraverse": "^4.2.0",
"get-random-port": "0.0.1",
"jsdoc-to-markdown": "^4.0.1",
"jsdoc-to-markdown": "^5.0.0",
"mocha": "^6.1.4",
"nop": "^1.0.0",
"nyc": "^11.6.0",
"nyc": "^14.1.1",
"proxyquire": "^2.0.1",
"shx": "^0.3.2",
"sinon": "^4.5.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/web-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@
"dependencies": {
"@slack/logger": "^1.0.0",
"@slack/types": "^1.0.0",
"@types/form-data": "^2.2.1",
"@types/is-stream": "^1.1.0",
"@types/node": ">=8.9.0",
"@types/p-queue": "^2.3.2",
"axios": "^0.18.0",
"eventemitter3": "^3.1.0",
"form-data": "^2.3.3",
"form-data": "^2.5.0",
"is-stream": "^1.1.0",
"p-queue": "^2.4.2",
"p-retry": "^4.0.0"
Expand All @@ -63,7 +62,7 @@
"codecov": "^3.2.0",
"mocha": "^6.0.2",
"nock": "^10.0.6",
"nyc": "^13.3.0",
"nyc": "^14.1.1",
"shelljs": "^0.8.3",
"shx": "^0.3.2",
"sinon": "^7.2.7",
Expand Down
40 changes: 39 additions & 1 deletion packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,18 @@ describe('WebClient', function () {
});
});

it('should include retryAfter metadata if the response has retry info', function () {
const scope = nock('https://slack.com')
.post(/api/)
.reply(200, { ok: true }, { 'retry-after': 100 });
const client = new WebClient(token);
return client.apiCall('method')
.then((data) => {
assert(data.response_metadata.retryAfter === 100);
scope.done();
});
});

it('should pause the remaining requests in queue', function () {
const startTime = Date.now();
const retryAfter = 1;
Expand Down Expand Up @@ -856,9 +868,35 @@ describe('WebClient', function () {
done();
});
});
// TODO: when parsing the retry header fails
});

it('should throw an error if the response has no retry info', function (done) {
const scope = nock('https://slack.com')
.post(/api/)
.reply(429, {}, { 'retry-after': undefined });
const client = new WebClient(token);
client.apiCall('method')
.catch((err) => {
assert.instanceOf(err, Error);
scope.done();
done();
});
});

it('should throw an error if the response has an invalid retry-after header', function (done) {
const scope = nock('https://slack.com')
.post(/api/)
.reply(429, {}, { 'retry-after': 'notanumber' });
const client = new WebClient(token);
client.apiCall('method')
.catch((err) => {
assert.instanceOf(err, Error);
scope.done();
done();
});
});


afterEach(function () {
nock.cleanAll();
});
Expand Down
6 changes: 5 additions & 1 deletion packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,11 @@ function paginationOptionsForNextPage(
*/
function parseRetryHeaders(response: AxiosResponse): number | undefined {
if (response.headers['retry-after'] !== undefined) {
return parseInt((response.headers['retry-after'] as string), 10);
const retryAfter = parseInt((response.headers['retry-after'] as string), 10);

if (!Number.isNaN(retryAfter)) {
return retryAfter;
}
}
return undefined;
}
6 changes: 3 additions & 3 deletions packages/webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The webhook can be initialized with default arguments that are reused each time
parameter to the constructor to set the default arguments.

```javascript
const IncomingWebhook = require('@slack/webhook');
const { IncomingWebhook } = require('@slack/webhook');
const url = process.env.SLACK_WEBHOOK_URL;

// Initialize with defaults
Expand All @@ -70,7 +70,7 @@ Something interesting just happened in your app, so its time to send the notific
the message. The method returns a `Promise` that resolves once the notification is sent.

```javascript
const IncomingWebhook = require('@slack/webhook');
const { IncomingWebhook } = require('@slack/webhook');
const url = process.env.SLACK_WEBHOOK_URL;

const webhook = new IncomingWebhook(url);
Expand Down Expand Up @@ -105,7 +105,7 @@ Import the `HttpsProxyAgent` class, and create an instance that can be used as t

```javascript
const { IncomingWebhook } = require('@slack/webhook');
const { HttpsProxyAgent } = require('https-proxy-agent');
const HttpsProxyAgent = require('https-proxy-agent');
const url = process.env.SLACK_WEBHOOK_URL;

// One of the ways you can configure HttpsProxyAgent is using a simple string.
Expand Down
2 changes: 1 addition & 1 deletion packages/webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"codecov": "^3.2.0",
"mocha": "^6.0.2",
"nock": "^10.0.6",
"nyc": "^13.3.0",
"nyc": "^14.1.1",
"shx": "^0.3.2",
"sinon": "^7.2.7",
"source-map-support": "^0.5.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/webhook/src/IncomingWebhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Agent } from 'http';
import axios, { AxiosInstance, AxiosResponse } from 'axios';
import { httpErrorWithOriginal, requestErrorWithOriginal } from './errors';
import { getUserAgent } from './instrument';
import { MessageAttachment, Block } from '@slack/types';
import { MessageAttachment, Block, KnownBlock } from '@slack/types';

/**
* A client for Slack's Incoming Webhooks
Expand Down Expand Up @@ -100,7 +100,7 @@ export interface IncomingWebhookDefaultArguments {

export interface IncomingWebhookSendArguments extends IncomingWebhookDefaultArguments {
attachments?: MessageAttachment[];
blocks?: Block[];
blocks?: (KnownBlock | Block)[];
unfurl_links?: boolean;
unfurl_media?: boolean;
}
Expand Down

0 comments on commit b806e32

Please sign in to comment.