-
Notifications
You must be signed in to change notification settings - Fork 17
/
types.ts
129 lines (113 loc) · 3.8 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import type { TypedSlackAPIMethodsType } from "./typed-method-types/mod.ts";
import type { SlackAPIMethodsType } from "./generated/method-types/mod.ts";
export type { DatastoreItem } from "./typed-method-types/apps.ts";
export type {
ValidTriggerTypes as Trigger,
} from "./typed-method-types/workflows/triggers/mod.ts";
// TODO: [brk-chg] remove this in favor of `Response`
export type BaseResponse = {
/**
* @description `true` if the response from the server was successful, `false` otherwise.
*/
ok: boolean;
/**
* @description: Optional error description returned by the server.
*/
error?: string;
/**
* @description Optional list of warnings returned by the server.
*/
warnings?: string[];
/**
* @description Optional metadata about the response returned by the server.
*/
"response_metadata"?: {
warnings?: string[];
messages?: string[];
};
/**
* @description Get the original `Response` object created by `fetch`
*
* ```ts
* const originalResponse = response.toFetchResponse();
* console.log(originalResponse.headers);
* ```
*/
toFetchResponse(): Response;
// deno-lint-ignore no-explicit-any
[otherOptions: string]: any;
};
export type SlackAPIClient =
& BaseSlackClient
& TypedSlackAPIMethodsType
& SlackAPIMethodsType;
export type BaseSlackClient = {
setSlackApiUrl: (slackApiUrl: string) => BaseSlackClient;
apiCall: BaseClientCall;
response: BaseClientResponse;
};
// TODO: [brk-chg] return a `Promise<Response>` object
type BaseClientCall = (
method: string,
data?: SlackAPIMethodArgs,
) => Promise<BaseResponse>;
// TODO: [brk-chg] return a `Promise<Response>` object
type BaseClientResponse = (
url: string,
data: Record<string, unknown>,
) => Promise<BaseResponse>;
export type SlackAPIOptions = {
/**
* @description Optional url endpoint for the Slack API used for api calls. Defaults to https://slack.com/api/
*/
slackApiUrl?: string;
};
export type BaseMethodArgs = {
/**
* @description Optional override token. If set, it will be used as the token
* for this single API call rather than the token provided when creating the client.
*/
token?: string;
};
export type CursorPaginationArgs = {
/**
* @description Paginate through collections of data by setting the `cursor` parameter
* to a `next_cursor` attribute returned by a previous request's `response_metadata`.
* Default value fetches the first "page" of the collection.
* Used in conjunction with `limit`, these parameters allow for
* {@link https://api.slack.com/docs/pagination#cursors cursor-based pagination}.
*/
cursor?: string;
/**
* @description The maximum number of items to return. Fewer than the requested
* number of items may be returned, even if the end of the result list hasn't
* been reached.
* Used in conjunction with `cursor`, these parameters allow for
* {@link https://api.slack.com/docs/pagination#cursors cursor-based pagination}.
*/
limit?: number;
};
export type CursorPaginationResponse = {
"response_metadata"?: {
/**
* @description A pointer that can be provided as parameter for a follow-up
* call to the same API to retrieve the next set of results, should more exist.
* If this property does not exist or is the empty string, there are no further
* results to retrieve.
* See {@link https://api.slack.com/docs/pagination#cursors our docs on cursor-based pagination}
* for more details
*/
next_cursor?: string;
};
};
export type SlackAPIMethodArgs = BaseMethodArgs & {
[name: string]: unknown;
};
export type SlackAPIMethod = {
(args?: SlackAPIMethodArgs): Promise<BaseResponse>;
};
export type SlackAPICursorPaginatedMethod = {
(
args?: SlackAPIMethodArgs & CursorPaginationArgs,
): Promise<BaseResponse & CursorPaginationResponse>;
};