11// Slack plugin module implements client behavior.
22import { createHash } from "node:crypto" ;
33import { type WebClientOptions , WebClient } from "@slack/web-api" ;
4- import {
5- resolveSlackWebClientOptions ,
6- resolveSlackWriteClientOptions ,
7- } from "./client-options.js" ;
4+ import { resolveSlackWebClientOptions , resolveSlackWriteClientOptions } from "./client-options.js" ;
85
96const SLACK_WRITE_CLIENT_CACHE_MAX = 32 ;
107const slackWriteClientCache = new Map < string , WebClient > ( ) ;
118
9+ type SlackWriteClientCacheOptions = Pick < WebClientOptions , "slackApiUrl" > ;
10+
1211export {
1312 resolveSlackWebClientOptions ,
1413 resolveSlackWriteClientOptions ,
@@ -28,12 +27,15 @@ export function createSlackTokenCacheKey(token: string): string {
2827 return `sha256:${ createHash ( "sha256" ) . update ( token ) . digest ( "base64url" ) } ` ;
2928}
3029
31- function slackWriteClientCacheKey ( token : string , options : WebClientOptions ) : string {
30+ function slackWriteClientCacheKey ( token : string , options : SlackWriteClientCacheOptions ) : string {
3231 const tokenKey = createSlackTokenCacheKey ( token ) ;
3332 return options . slackApiUrl ? `${ tokenKey } :api:${ options . slackApiUrl } ` : tokenKey ;
3433}
3534
36- export function getSlackWriteClient ( token : string , options : WebClientOptions = { } ) : WebClient {
35+ export function getSlackWriteClient (
36+ token : string ,
37+ options : SlackWriteClientCacheOptions = { } ,
38+ ) : WebClient {
3739 const resolvedOptions = resolveSlackWriteClientOptions ( options ) ;
3840 const tokenKey = slackWriteClientCacheKey ( token , resolvedOptions ) ;
3941 const cached = slackWriteClientCache . get ( tokenKey ) ;
0 commit comments