@slack/web-api
Advanced tools
Comparing version 7.6.0 to 7.7.0
@@ -5,2 +5,3 @@ /// <reference types="node" /> | ||
import type { SecureContextOptions } from 'node:tls'; | ||
import { type InternalAxiosRequestConfig, type AxiosAdapter } from 'axios'; | ||
import { LogLevel, type Logger } from './logger'; | ||
@@ -30,2 +31,16 @@ import { Methods } from './methods'; | ||
attachOriginalToWebAPIRequestError?: boolean; | ||
/** | ||
* Custom function to modify outgoing requests. See {@link https://axios-http.com/docs/interceptors Axios interceptor documentation} for more details. | ||
* @type {Function | undefined} | ||
* @default undefined | ||
*/ | ||
requestInterceptor?: RequestInterceptor; | ||
/** | ||
* Custom functions for modifing and handling outgoing requests. | ||
* Useful if you would like to manage outgoing request with a custom http client. | ||
* See {@link https://github.com/axios/axios/blob/v1.x/README.md?plain=1#L586 Axios adapter documentation} for more information. | ||
* @type {Function | undefined} | ||
* @default undefined | ||
*/ | ||
adapter?: AdapterConfig; | ||
} | ||
@@ -52,2 +67,17 @@ export type TLSOptions = Pick<SecureContextOptions, 'pfx' | 'key' | 'passphrase' | 'cert' | 'ca'>; | ||
/** | ||
* An alias to {@link https://github.com/axios/axios/blob/v1.x/index.d.ts#L367 Axios' `InternalAxiosRequestConfig`} object, | ||
* which is the main parameter type provided to Axios interceptors and adapters. | ||
*/ | ||
export type RequestConfig = InternalAxiosRequestConfig; | ||
/** | ||
* An alias to {@link https://github.com/axios/axios/blob/v1.x/index.d.ts#L489 Axios' `AxiosInterceptorManager<InternalAxiosRequestConfig>` onFufilled} method, | ||
* which controls the custom request interceptor logic | ||
*/ | ||
export type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>; | ||
/** | ||
* An alias to {@link https://github.com/axios/axios/blob/v1.x/index.d.ts#L112 Axios' `AxiosAdapter`} interface, | ||
* which is the contract required to specify an adapter | ||
*/ | ||
export type AdapterConfig = AxiosAdapter; | ||
/** | ||
* A client for Slack's Web API | ||
@@ -107,4 +137,7 @@ * | ||
* @param token - An API token to authenticate/authorize with Slack (usually start with `xoxp`, `xoxb`) | ||
* @param {Object} [webClientOptions] - Configuration options. | ||
* @param {Function} [webClientOptions.requestInterceptor] - An interceptor to mutate outgoing requests. See {@link https://axios-http.com/docs/interceptors Axios interceptors} | ||
* @param {Function} [webClientOptions.adapter] - An adapter to allow custom handling of requests. Useful if you would like to use a pre-configured http client. See {@link https://github.com/axios/axios/blob/v1.x/README.md?plain=1#L586 Axios adapter} | ||
*/ | ||
constructor(token?: string, { slackApiUrl, logger, logLevel, maxRequestConcurrency, retryConfig, agent, tls, timeout, rejectRateLimitedCalls, headers, teamId, attachOriginalToWebAPIRequestError, }?: WebClientOptions); | ||
constructor(token?: string, { slackApiUrl, logger, logLevel, maxRequestConcurrency, retryConfig, agent, tls, timeout, rejectRateLimitedCalls, headers, teamId, attachOriginalToWebAPIRequestError, requestInterceptor, adapter, }?: WebClientOptions); | ||
/** | ||
@@ -187,6 +220,5 @@ * Generic method for calling a Web API method | ||
* multipart/form-data. | ||
* @param options - arguments for the Web API method | ||
* @param headers - a mutable object representing the HTTP headers for the outgoing request | ||
* @param config - The Axios request configuration object | ||
*/ | ||
private serializeApiCallOptions; | ||
private serializeApiCallData; | ||
/** | ||
@@ -193,0 +225,0 @@ * Processes an HTTP response into a WebAPICallResult by performing JSON parsing on the body and merging relevant |
@@ -110,4 +110,7 @@ "use strict"; | ||
* @param token - An API token to authenticate/authorize with Slack (usually start with `xoxp`, `xoxb`) | ||
* @param {Object} [webClientOptions] - Configuration options. | ||
* @param {Function} [webClientOptions.requestInterceptor] - An interceptor to mutate outgoing requests. See {@link https://axios-http.com/docs/interceptors Axios interceptors} | ||
* @param {Function} [webClientOptions.adapter] - An adapter to allow custom handling of requests. Useful if you would like to use a pre-configured http client. See {@link https://github.com/axios/axios/blob/v1.x/README.md?plain=1#L586 Axios adapter} | ||
*/ | ||
constructor(token, { slackApiUrl = 'https://slack.com/api/', logger = undefined, logLevel = undefined, maxRequestConcurrency = 100, retryConfig = retry_policies_1.tenRetriesInAboutThirtyMinutes, agent = undefined, tls = undefined, timeout = 0, rejectRateLimitedCalls = false, headers = {}, teamId = undefined, attachOriginalToWebAPIRequestError = true, } = {}) { | ||
constructor(token, { slackApiUrl = 'https://slack.com/api/', logger = undefined, logLevel = undefined, maxRequestConcurrency = 100, retryConfig = retry_policies_1.tenRetriesInAboutThirtyMinutes, agent = undefined, tls = undefined, timeout = 0, rejectRateLimitedCalls = false, headers = {}, teamId = undefined, attachOriginalToWebAPIRequestError = true, requestInterceptor = undefined, adapter = undefined, } = {}) { | ||
super(); | ||
@@ -136,2 +139,3 @@ this.token = token; | ||
this.axios = axios_1.default.create({ | ||
adapter: adapter ? (config) => adapter(Object.assign(Object.assign({}, config), { adapter: undefined })) : undefined, | ||
timeout, | ||
@@ -142,3 +146,2 @@ baseURL: slackApiUrl, | ||
httpsAgent: agent, | ||
transformRequest: [this.serializeApiCallOptions.bind(this)], | ||
validateStatus: () => true, // all HTTP status codes should result in a resolved promise (as opposed to only 2xx) | ||
@@ -152,4 +155,10 @@ maxRedirects: 0, | ||
}); | ||
// serializeApiCallOptions will always determine the appropriate content-type | ||
// serializeApiCallData will always determine the appropriate content-type | ||
this.axios.defaults.headers.post['Content-Type'] = undefined; | ||
// request interceptors have reversed execution order | ||
// see: https://github.com/axios/axios/blob/v1.x/test/specs/interceptors.spec.js#L88 | ||
if (requestInterceptor) { | ||
this.axios.interceptors.request.use(requestInterceptor, null); | ||
} | ||
this.axios.interceptors.request.use(this.serializeApiCallData.bind(this), null); | ||
this.logger.debug('initialized'); | ||
@@ -486,11 +495,11 @@ } | ||
* multipart/form-data. | ||
* @param options - arguments for the Web API method | ||
* @param headers - a mutable object representing the HTTP headers for the outgoing request | ||
* @param config - The Axios request configuration object | ||
*/ | ||
serializeApiCallOptions(options, headers) { | ||
serializeApiCallData(config) { | ||
const { data, headers } = config; | ||
// The following operation both flattens complex objects into a JSON-encoded strings and searches the values for | ||
// binary content | ||
let containsBinaryData = false; | ||
// biome-ignore lint/suspicious/noExplicitAny: call options can be anything | ||
const flattened = Object.entries(options).map(([key, value]) => { | ||
// biome-ignore lint/suspicious/noExplicitAny: HTTP request data can be anything | ||
const flattened = Object.entries(data).map(([key, value]) => { | ||
if (value === undefined || value === null) { | ||
@@ -545,3 +554,5 @@ return []; | ||
} | ||
return form; | ||
config.data = form; | ||
config.headers = headers; | ||
return config; | ||
} | ||
@@ -553,3 +564,3 @@ // Otherwise, a simple key-value object is returned | ||
const initialValue = {}; | ||
return (0, node_querystring_1.stringify)(flattened.reduce((accumulator, [key, value]) => { | ||
config.data = (0, node_querystring_1.stringify)(flattened.reduce((accumulator, [key, value]) => { | ||
if (key !== undefined && value !== undefined) { | ||
@@ -560,2 +571,4 @@ accumulator[key] = value; | ||
}, initialValue)); | ||
config.headers = headers; | ||
return config; | ||
} | ||
@@ -562,0 +575,0 @@ /** |
{ | ||
"name": "@slack/web-api", | ||
"version": "7.6.0", | ||
"version": "7.7.0", | ||
"description": "Official library for using the Slack Platform's Web API", | ||
@@ -5,0 +5,0 @@ "author": "Slack Technologies, LLC", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2572709
39224