1 | /// <reference types="node" />
|
2 | /// <reference types="node" />
|
3 | import { Agent } from 'http';
|
4 | import { SecureContextOptions } from 'tls';
|
5 | import { Methods } from './methods';
|
6 | import { LogLevel, Logger } from './logger';
|
7 | import { RetryOptions } from './retry-policies';
|
8 | export interface WebClientOptions {
|
9 | slackApiUrl?: string;
|
10 | logger?: Logger;
|
11 | logLevel?: LogLevel;
|
12 | maxRequestConcurrency?: number;
|
13 | retryConfig?: RetryOptions;
|
14 | agent?: Agent;
|
15 | tls?: TLSOptions;
|
16 | timeout?: number;
|
17 | rejectRateLimitedCalls?: boolean;
|
18 | headers?: Record<string, string>;
|
19 | teamId?: string;
|
20 | }
|
21 | export declare type TLSOptions = Pick<SecureContextOptions, 'pfx' | 'key' | 'passphrase' | 'cert' | 'ca'>;
|
22 | export declare enum WebClientEvent {
|
23 | RATE_LIMITED = "rate_limited"
|
24 | }
|
25 | export interface WebAPICallOptions {
|
26 | [argument: string]: unknown;
|
27 | }
|
28 | export interface WebAPICallResult {
|
29 | ok: boolean;
|
30 | error?: string;
|
31 | response_metadata?: {
|
32 | warnings?: string[];
|
33 | next_cursor?: string;
|
34 | scopes?: string[];
|
35 | acceptedScopes?: string[];
|
36 | retryAfter?: number;
|
37 | messages?: string[];
|
38 | };
|
39 | [key: string]: unknown;
|
40 | }
|
41 | export interface PaginatePredicate {
|
42 | (page: WebAPICallResult): boolean | undefined | void;
|
43 | }
|
44 | export interface PageReducer<A = any> {
|
45 | (accumulator: A | undefined, page: WebAPICallResult, index: number): A;
|
46 | }
|
47 | export declare type PageAccumulator<R extends PageReducer> = R extends (accumulator: (infer A) | undefined, page: WebAPICallResult, index: number) => infer A ? A : never;
|
48 | /**
|
49 | * A client for Slack's Web API
|
50 | *
|
51 | * This client provides an alias for each {@link https://api.slack.com/methods|Web API method}. Each method is
|
52 | * a convenience wrapper for calling the {@link WebClient#apiCall} method using the method name as the first parameter.
|
53 | */
|
54 | export declare class WebClient extends Methods {
|
55 | /**
|
56 | * The base URL for reaching Slack's Web API. Consider changing this value for testing purposes.
|
57 | */
|
58 | readonly slackApiUrl: string;
|
59 | /**
|
60 | * Authentication and authorization token for accessing Slack Web API (usually begins with `xoxp` or `xoxb`)
|
61 | */
|
62 | readonly token?: string;
|
63 | /**
|
64 | * Configuration for retry operations. See {@link https://github.com/tim-kos/node-retry|node-retry} for more details.
|
65 | */
|
66 | private retryConfig;
|
67 | /**
|
68 | * Queue of requests in which a maximum of {@link WebClientOptions.maxRequestConcurrency} can concurrently be
|
69 | * in-flight.
|
70 | */
|
71 | private requestQueue;
|
72 | /**
|
73 | * Axios HTTP client instance used by this client
|
74 | */
|
75 | private axios;
|
76 | /**
|
77 | * Configuration for custom TLS handling
|
78 | */
|
79 | private tlsConfig;
|
80 | /**
|
81 | * Preference for immediately rejecting API calls which result in a rate-limited response
|
82 | */
|
83 | private rejectRateLimitedCalls;
|
84 | /**
|
85 | * The name used to prefix all logging generated from this object
|
86 | */
|
87 | private static loggerName;
|
88 | /**
|
89 | * This object's logger instance
|
90 | */
|
91 | private logger;
|
92 | /**
|
93 | * This object's teamId value
|
94 | */
|
95 | private teamId?;
|
96 | /**
|
97 | * @param token - An API token to authenticate/authorize with Slack (usually start with `xoxp`, `xoxb`)
|
98 | */
|
99 | constructor(token?: string, { slackApiUrl, logger, logLevel, maxRequestConcurrency, retryConfig, agent, tls, timeout, rejectRateLimitedCalls, headers, teamId, }?: WebClientOptions);
|
100 | /**
|
101 | * Generic method for calling a Web API method
|
102 | *
|
103 | * @param method - the Web API method to call {//api.slack.com/methods}
https: |
104 | * options - options
|
105 | */
|
106 | apiCall(method: string, options?: WebAPICallOptions): Promise<WebAPICallResult>;
|
107 | /**
|
108 | * Iterate over the result pages of a cursor-paginated Web API method. This method can return two types of values,
|
109 | * depending on which arguments are used. When up to two parameters are used, the return value is an async iterator
|
110 | * which can be used as the iterable in a for-await-of loop. When three or four parameters are used, the return
|
111 | * value is a promise that resolves at the end of iteration. The third parameter, `shouldStop`, is a function that is
|
112 | * called with each `page` and can end iteration by returning `true`. The fourth parameter, `reduce`, is a function
|
113 | * that is called with three arguments: `accumulator`, `page`, and `index`. The `accumulator` is a value of any type
|
114 | * you choose, but it will contain `undefined` when `reduce` is called for the first time. The `page` argument and
|
115 | * `index` arguments are exactly what they say they are. The `reduce` function's return value will be passed in as
|
116 | * `accumulator` the next time its called, and the returned promise will resolve to the last value of `accumulator`.
|
117 | *
|
118 | * The for-await-of syntax is part of ES2018. It is available natively in Node starting with v10.0.0. You may be able
|
119 | * to use it in earlier JavaScript runtimes by transpiling your source with a tool like Babel. However, the
|
120 | * transpiled code will likely sacrifice performance.
|
121 | *
|
122 | * @param method - the cursor-paginated Web API method to call {@link https://api.slack.com/docs/pagination}
|
123 | * @param options - options
|
124 | * @param shouldStop - a predicate that is called with each page, and should return true when pagination can end.
|
125 | * @param reduce - a callback that can be used to accumulate a value that the return promise is resolved to
|
126 | */
|
127 | paginate(method: string, options?: WebAPICallOptions): AsyncIterable<WebAPICallResult>;
|
128 | paginate(method: string, options: WebAPICallOptions, shouldStop: PaginatePredicate): Promise<void>;
|
129 | paginate<R extends PageReducer, A extends PageAccumulator<R>>(method: string, options: WebAPICallOptions, shouldStop: PaginatePredicate, reduce?: PageReducer<A>): Promise<A>;
|
130 | /**
|
131 | * Low-level function to make a single API request. handles queuing, retries, and http-level errors
|
132 | */
|
133 | private makeRequest;
|
134 | /**
|
135 | * Transforms options (a simple key-value object) into an acceptable value for a body. This can be either
|
136 | * a string, used when posting with a content-type of url-encoded. Or, it can be a readable stream, used
|
137 | * when the options contain a binary (a stream or a buffer) and the upload should be done with content-type
|
138 | * multipart/form-data.
|
139 | *
|
140 | * @param options - arguments for the Web API method
|
141 | * @param headers - a mutable object representing the HTTP headers for the outgoing request
|
142 | */
|
143 | private serializeApiCallOptions;
|
144 | /**
|
145 | * Processes an HTTP response into a WebAPICallResult by performing JSON parsing on the body and merging relevant
|
146 | * HTTP headers into the object.
|
147 | * @param response - an http response
|
148 | */
|
149 | private buildResult;
|
150 | }
|
151 | export default WebClient;
|
152 | //# sourceMappingURL=WebClient.d.ts.map |
\ | No newline at end of file |