messaging-api-slack
Advanced tools
Comparing version 1.0.0-beta.27 to 1.0.0-beta.29
import { AxiosInstance } from 'axios'; | ||
import { OnRequestFunction } from 'messaging-api-common'; | ||
import * as Types from './SlackTypes'; | ||
export default class SlackOAuthClient { | ||
_token: string; | ||
_onRequest: OnRequestFunction | undefined; | ||
_axios: AxiosInstance; | ||
chat: { | ||
/** | ||
* @deprecated Use `new SlackOAuthClient(...)` instead. | ||
*/ | ||
static connect(accessTokenOrConfig: string | Types.ClientConfig): SlackOAuthClient; | ||
/** | ||
* The underlying axios instance. | ||
*/ | ||
readonly axios: AxiosInstance; | ||
/** | ||
* The access token used by the client. | ||
*/ | ||
readonly accessToken: string; | ||
/** | ||
* chat.* APIs. | ||
*/ | ||
readonly chat: { | ||
postMessage: (options: Types.PostMessageOptions) => Promise<Types.OAuthAPIResponse>; | ||
@@ -22,3 +33,6 @@ postEphemeral: (options: Types.PostEphemeralOptions) => Promise<Types.OAuthAPIResponse>; | ||
}; | ||
views: { | ||
/** | ||
* views.* APIs. | ||
*/ | ||
readonly views: { | ||
open: (options: Types.OpenViewOptions) => Promise<Types.OAuthAPIResponse>; | ||
@@ -30,8 +44,6 @@ publish: (options: Types.PublishViewOptions) => Promise<Types.OAuthAPIResponse>; | ||
/** | ||
* @deprecated Use `new SlackOAuthClient(...)` instead. | ||
* The callback to be called when receiving requests. | ||
*/ | ||
static connect(accessTokenOrConfig: string | Types.ClientConfig): SlackOAuthClient; | ||
private onRequest?; | ||
constructor(accessTokenOrConfig: string | Types.ClientConfig); | ||
get axios(): AxiosInstance; | ||
get accessToken(): string; | ||
callMethod(method: Types.AvailableMethod, inputBody?: Record<string, any>): Promise<Types.OAuthAPIResponse>; | ||
@@ -38,0 +50,0 @@ /** |
@@ -36,8 +36,8 @@ "use strict"; | ||
// Bot User OAuth Access Token | ||
this._token = accessTokenOrConfig; | ||
this.accessToken = accessTokenOrConfig; | ||
} | ||
else { | ||
const config = accessTokenOrConfig; | ||
this._token = config.accessToken; | ||
this._onRequest = config.onRequest; | ||
this.accessToken = config.accessToken; | ||
this.onRequest = config.onRequest; | ||
origin = config.origin; | ||
@@ -47,3 +47,3 @@ } | ||
// https://api.slack.com/web | ||
this._axios = axios_1.default.create({ | ||
this.axios = axios_1.default.create({ | ||
baseURL: `${origin || 'https://slack.com'}/api/`, | ||
@@ -54,3 +54,3 @@ headers: { | ||
}); | ||
this._axios.interceptors.request.use(messaging_api_common_1.createRequestInterceptor({ onRequest: this._onRequest })); | ||
this.axios.interceptors.request.use(messaging_api_common_1.createRequestInterceptor({ onRequest: this.onRequest })); | ||
this.chat = { | ||
@@ -84,13 +84,7 @@ postMessage: this._postMessage.bind(this), | ||
} | ||
get axios() { | ||
return this._axios; | ||
} | ||
get accessToken() { | ||
return this._token; | ||
} | ||
callMethod(method, inputBody = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const body = Object.assign(Object.assign({}, omit_1.default(inputBody, ['token', 'accessToken'])), { token: inputBody.accessToken || inputBody.token || this._token }); | ||
const response = yield this._axios.post(method, querystring_1.default.stringify(messaging_api_common_1.snakecaseKeysDeep(body))); | ||
const body = Object.assign(Object.assign({}, omit_1.default(inputBody, ['token', 'accessToken'])), { token: inputBody.accessToken || inputBody.token || this.accessToken }); | ||
const response = yield this.axios.post(method, querystring_1.default.stringify(messaging_api_common_1.snakecaseKeysDeep(body))); | ||
const data = messaging_api_common_1.camelcaseKeysDeep(response.data); | ||
@@ -97,0 +91,0 @@ if (!data.ok) { |
@@ -9,4 +9,2 @@ import { AxiosInstance } from 'axios'; | ||
export default class SlackWebhookClient { | ||
_axios: AxiosInstance; | ||
_onRequest: OnRequestFunction | undefined; | ||
/** | ||
@@ -16,4 +14,11 @@ * @deprecated Use `new SlackWebhookClient(...)` instead. | ||
static connect(urlOrConfig: string | ClientConfig): SlackWebhookClient; | ||
/** | ||
* The underlying axios instance. | ||
*/ | ||
readonly axios: AxiosInstance; | ||
/** | ||
* The callback to be called when receiving requests. | ||
*/ | ||
private onRequest?; | ||
constructor(urlOrConfig: string | ClientConfig); | ||
get axios(): AxiosInstance; | ||
sendRawBody(body: Record<string, any>): Promise<Types.SendMessageSuccessResponse>; | ||
@@ -20,0 +25,0 @@ sendText(text: string): Promise<Types.SendMessageSuccessResponse>; |
@@ -15,3 +15,3 @@ "use strict"; | ||
url = config.url; | ||
this._onRequest = config.onRequest; | ||
this.onRequest = config.onRequest; | ||
} | ||
@@ -23,7 +23,7 @@ else { | ||
// https://api.slack.com/incoming-webhooks | ||
this._axios = axios_1.default.create({ | ||
this.axios = axios_1.default.create({ | ||
baseURL: url, | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
this._axios.interceptors.request.use(messaging_api_common_1.createRequestInterceptor({ onRequest: this._onRequest })); | ||
this.axios.interceptors.request.use(messaging_api_common_1.createRequestInterceptor({ onRequest: this.onRequest })); | ||
} | ||
@@ -37,9 +37,4 @@ /** | ||
} | ||
get axios() { | ||
return this._axios; | ||
} | ||
sendRawBody(body) { | ||
return this._axios | ||
.post('', messaging_api_common_1.snakecaseKeysDeep(body)) | ||
.then((res) => res.data); | ||
return this.axios.post('', messaging_api_common_1.snakecaseKeysDeep(body)).then((res) => res.data); | ||
} | ||
@@ -46,0 +41,0 @@ sendText(text) { |
@@ -9,10 +9,12 @@ { | ||
}, | ||
"version": "1.0.0-beta.27", | ||
"version": "1.0.0-beta.29", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@types/lodash": "^4.14.156", | ||
"@types/warning": "^3.0.0", | ||
"axios": "^0.19.2", | ||
"axios-error": "^1.0.0-beta.27", | ||
"lodash": "^4.17.15", | ||
"messaging-api-common": "^1.0.0-beta.26" | ||
"messaging-api-common": "^1.0.0-beta.29" | ||
}, | ||
@@ -28,3 +30,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "38107f34a63c32cf0a1c7994c4c39a2d6034daa4" | ||
"gitHead": "3389b14efbdcaf968ed7476820edaaaa95da0772" | ||
} |
@@ -11,3 +11,3 @@ import MockAdapter from 'axios-mock-adapter'; | ||
beforeEach(() => { | ||
axios = require('axios'); // eslint-disable-line global-require | ||
axios = require('axios'); | ||
_create = axios.create; | ||
@@ -78,3 +78,3 @@ }); | ||
beforeEach(() => { | ||
axios = require('axios'); // eslint-disable-line global-require | ||
axios = require('axios'); | ||
_create = axios.create; | ||
@@ -81,0 +81,0 @@ }); |
@@ -11,3 +11,3 @@ import MockAdapter from 'axios-mock-adapter'; | ||
beforeEach(() => { | ||
axios = require('axios'); // eslint-disable-line global-require | ||
axios = require('axios'); | ||
_create = axios.create; | ||
@@ -63,3 +63,3 @@ }); | ||
beforeEach(() => { | ||
axios = require('axios'); // eslint-disable-line global-require | ||
axios = require('axios'); | ||
_create = axios.create; | ||
@@ -66,0 +66,0 @@ }); |
@@ -33,9 +33,29 @@ import querystring from 'querystring'; | ||
export default class SlackOAuthClient { | ||
_token: string; | ||
/** | ||
* @deprecated Use `new SlackOAuthClient(...)` instead. | ||
*/ | ||
static connect( | ||
accessTokenOrConfig: string | Types.ClientConfig | ||
): SlackOAuthClient { | ||
warning( | ||
false, | ||
'`SlackOAuthClient.connect(...)` is deprecated. Use `new SlackOAuthClient(...)` instead.' | ||
); | ||
return new SlackOAuthClient(accessTokenOrConfig); | ||
} | ||
_onRequest: OnRequestFunction | undefined; | ||
/** | ||
* The underlying axios instance. | ||
*/ | ||
readonly axios: AxiosInstance; | ||
_axios: AxiosInstance; | ||
/** | ||
* The access token used by the client. | ||
*/ | ||
readonly accessToken: string; | ||
chat: { | ||
/** | ||
* chat.* APIs. | ||
*/ | ||
readonly chat: { | ||
postMessage: ( | ||
@@ -73,3 +93,6 @@ options: Types.PostMessageOptions | ||
views: { | ||
/** | ||
* views.* APIs. | ||
*/ | ||
readonly views: { | ||
open: (options: Types.OpenViewOptions) => Promise<Types.OAuthAPIResponse>; | ||
@@ -86,13 +109,5 @@ publish: ( | ||
/** | ||
* @deprecated Use `new SlackOAuthClient(...)` instead. | ||
* The callback to be called when receiving requests. | ||
*/ | ||
static connect( | ||
accessTokenOrConfig: string | Types.ClientConfig | ||
): SlackOAuthClient { | ||
warning( | ||
false, | ||
'`SlackOAuthClient.connect(...)` is deprecated. Use `new SlackOAuthClient(...)` instead.' | ||
); | ||
return new SlackOAuthClient(accessTokenOrConfig); | ||
} | ||
private onRequest?: OnRequestFunction; | ||
@@ -104,8 +119,8 @@ constructor(accessTokenOrConfig: string | Types.ClientConfig) { | ||
// Bot User OAuth Access Token | ||
this._token = accessTokenOrConfig; | ||
this.accessToken = accessTokenOrConfig; | ||
} else { | ||
const config = accessTokenOrConfig; | ||
this._token = config.accessToken; | ||
this._onRequest = config.onRequest; | ||
this.accessToken = config.accessToken; | ||
this.onRequest = config.onRequest; | ||
origin = config.origin; | ||
@@ -116,3 +131,3 @@ } | ||
// https://api.slack.com/web | ||
this._axios = axios.create({ | ||
this.axios = axios.create({ | ||
baseURL: `${origin || 'https://slack.com'}/api/`, | ||
@@ -124,4 +139,4 @@ headers: { | ||
this._axios.interceptors.request.use( | ||
createRequestInterceptor({ onRequest: this._onRequest }) | ||
this.axios.interceptors.request.use( | ||
createRequestInterceptor({ onRequest: this.onRequest }) | ||
); | ||
@@ -152,10 +167,2 @@ | ||
get axios(): AxiosInstance { | ||
return this._axios; | ||
} | ||
get accessToken(): string { | ||
return this._token; | ||
} | ||
async callMethod( | ||
@@ -168,6 +175,6 @@ method: Types.AvailableMethod, | ||
...omit(inputBody, ['token', 'accessToken']), | ||
token: inputBody.accessToken || inputBody.token || this._token, | ||
token: inputBody.accessToken || inputBody.token || this.accessToken, | ||
}; | ||
const response = await this._axios.post( | ||
const response = await this.axios.post( | ||
method, | ||
@@ -174,0 +181,0 @@ querystring.stringify(snakecaseKeysDeep(body) as any) |
@@ -17,6 +17,2 @@ import axios, { AxiosInstance } from 'axios'; | ||
export default class SlackWebhookClient { | ||
_axios: AxiosInstance; | ||
_onRequest: OnRequestFunction | undefined; | ||
/** | ||
@@ -33,2 +29,12 @@ * @deprecated Use `new SlackWebhookClient(...)` instead. | ||
/** | ||
* The underlying axios instance. | ||
*/ | ||
readonly axios: AxiosInstance; | ||
/** | ||
* The callback to be called when receiving requests. | ||
*/ | ||
private onRequest?: OnRequestFunction; | ||
constructor(urlOrConfig: string | ClientConfig) { | ||
@@ -41,3 +47,3 @@ let url; | ||
url = config.url; | ||
this._onRequest = config.onRequest; | ||
this.onRequest = config.onRequest; | ||
} else { | ||
@@ -49,3 +55,3 @@ url = urlOrConfig; | ||
// https://api.slack.com/incoming-webhooks | ||
this._axios = axios.create({ | ||
this.axios = axios.create({ | ||
baseURL: url, | ||
@@ -55,17 +61,11 @@ headers: { 'Content-Type': 'application/json' }, | ||
this._axios.interceptors.request.use( | ||
createRequestInterceptor({ onRequest: this._onRequest }) | ||
this.axios.interceptors.request.use( | ||
createRequestInterceptor({ onRequest: this.onRequest }) | ||
); | ||
} | ||
get axios(): AxiosInstance { | ||
return this._axios; | ||
} | ||
sendRawBody( | ||
body: Record<string, any> | ||
): Promise<Types.SendMessageSuccessResponse> { | ||
return this._axios | ||
.post('', snakecaseKeysDeep(body)) | ||
.then((res) => res.data); | ||
return this.axios.post('', snakecaseKeysDeep(body)).then((res) => res.data); | ||
} | ||
@@ -72,0 +72,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
326041
5353
6
+ Added@types/lodash@^4.14.156
+ Added@types/warning@^3.0.0
+ Added@types/warning@3.0.3(transitive)