snowtransfer 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/Constants.d.ts +59 -0
  3. package/dist/Constants.js +123 -0
  4. package/dist/Endpoints.d.ts +120 -0
  5. package/dist/Endpoints.js +121 -0
  6. package/dist/RequestHandler.d.ts +258 -0
  7. package/dist/RequestHandler.js +629 -0
  8. package/dist/SnowTransfer.d.ts +70 -0
  9. package/dist/SnowTransfer.js +105 -0
  10. package/dist/StateMachine.d.ts +89 -0
  11. package/dist/StateMachine.js +208 -0
  12. package/dist/StateMachineGraph.d.ts +3 -0
  13. package/dist/StateMachineGraph.js +23 -0
  14. package/dist/Types.d.ts +76 -0
  15. package/dist/Types.js +2 -0
  16. package/dist/index.d.ts +25 -718
  17. package/dist/index.js +63 -44
  18. package/dist/methods/Assets.d.ts +290 -0
  19. package/dist/methods/Assets.js +326 -0
  20. package/dist/methods/AuditLog.d.ts +40 -0
  21. package/dist/methods/AuditLog.js +44 -0
  22. package/dist/methods/AutoModeration.d.ts +122 -0
  23. package/dist/methods/AutoModeration.js +135 -0
  24. package/dist/methods/Bot.d.ts +65 -0
  25. package/dist/methods/Bot.js +75 -0
  26. package/dist/methods/Channel.d.ts +866 -0
  27. package/dist/methods/Channel.js +982 -0
  28. package/dist/methods/Entitlements.d.ts +87 -0
  29. package/dist/methods/Entitlements.js +99 -0
  30. package/dist/methods/Guild.d.ts +722 -0
  31. package/dist/methods/Guild.js +785 -0
  32. package/dist/methods/GuildScheduledEvent.d.ts +138 -0
  33. package/dist/methods/GuildScheduledEvent.js +155 -0
  34. package/dist/methods/GuildTemplate.d.ts +110 -0
  35. package/dist/methods/GuildTemplate.js +124 -0
  36. package/dist/methods/Interaction.d.ts +339 -0
  37. package/dist/methods/Interaction.js +359 -0
  38. package/dist/methods/Invite.d.ts +81 -0
  39. package/dist/methods/Invite.js +107 -0
  40. package/dist/methods/Sku.d.ts +58 -0
  41. package/dist/methods/Sku.js +66 -0
  42. package/dist/methods/StageInstance.d.ts +86 -0
  43. package/dist/methods/StageInstance.js +97 -0
  44. package/dist/methods/User.d.ts +167 -0
  45. package/dist/methods/User.js +184 -0
  46. package/dist/methods/Voice.d.ts +44 -0
  47. package/dist/methods/Voice.js +52 -0
  48. package/dist/methods/Webhook.d.ts +265 -0
  49. package/dist/methods/Webhook.js +256 -0
  50. package/dist/tokenless.d.ts +19 -0
  51. package/dist/tokenless.js +31 -0
  52. package/package.json +9 -9
  53. package/dist/index.js.map +0 -1
@@ -0,0 +1,258 @@
1
+ import { EventEmitter } from "node:events";
2
+ import SM = require("./StateMachine");
3
+ import type { HTTPMethod, RequestEventData, HandlerEvents } from "./Types";
4
+ declare global {
5
+ var snowtransferDebugLogging: boolean;
6
+ }
7
+ /**
8
+ * @since 0.3.0
9
+ */
10
+ export declare class DiscordAPIError extends Error {
11
+ method: string;
12
+ path: string;
13
+ code: number;
14
+ httpStatus: number;
15
+ request: RequestEventData;
16
+ response: Response;
17
+ constructor(error: {
18
+ message?: string;
19
+ code?: number;
20
+ }, request: RequestEventData, response: Response);
21
+ }
22
+ /**
23
+ * @since 0.17.0
24
+ */
25
+ export interface Counter {
26
+ id: string;
27
+ /**
28
+ * Like new.
29
+ * @since 0.17.0
30
+ */
31
+ hasReset(): boolean;
32
+ /**
33
+ * Returns true only if the caller is allowed to call take() and then consume a function.
34
+ * @since 0.17.0
35
+ */
36
+ canTake(): boolean;
37
+ /**
38
+ * Take a use out of the counter
39
+ * @since 0.17.0
40
+ */
41
+ take(): boolean;
42
+ /** @since 0.17.0 */
43
+ timeUntilReset(): number;
44
+ /** @since 0.17.0 */
45
+ responseReceived(): void;
46
+ /** @since 0.17.0 */
47
+ applyCount(limit: number | null, remaining: number, resetAfter: number): void;
48
+ }
49
+ /**
50
+ * @since 0.17.0
51
+ */
52
+ export declare class IntervalCounter implements Counter {
53
+ limit: number;
54
+ reset: number;
55
+ /**
56
+ * Remaining amount of executions during the current timeframe
57
+ */
58
+ remaining: number;
59
+ private firstRequestTime;
60
+ private resetAt;
61
+ readonly id: string;
62
+ /**
63
+ * Create a new base bucket
64
+ * @param limit Number of functions that may be executed during the timeframe set in reset
65
+ * @param reset Timeframe in milliseconds until the ratelimit resets after first
66
+ */
67
+ constructor(limit: number, reset: number);
68
+ private checkReset;
69
+ hasReset(): boolean;
70
+ canTake(): boolean;
71
+ take(): boolean;
72
+ timeUntilReset(): number;
73
+ responseReceived(): void;
74
+ applyCount(limit: number | null, remaining: number, resetAfter: number): void;
75
+ }
76
+ /**
77
+ * @since 0.17.0
78
+ */
79
+ export declare class LeakyCounter implements Counter {
80
+ limit: number;
81
+ /**
82
+ * Remaining amount of executions during the current timeframe
83
+ */
84
+ remaining: number;
85
+ private resetAt;
86
+ readonly id: string;
87
+ /**
88
+ * Create a new base bucket
89
+ * @param limit Number of functions that may be executed until some are reset
90
+ */
91
+ constructor(limit: number);
92
+ private checkReset;
93
+ hasReset(): boolean;
94
+ canTake(): boolean;
95
+ take(): boolean;
96
+ timeUntilReset(): number;
97
+ responseReceived(): void;
98
+ applyCount(limit: number | null, remaining: number, resetAfter: number): void;
99
+ }
100
+ /**
101
+ * Bucket used for saving ratelimits
102
+ * @since 0.1.0
103
+ */
104
+ export declare class Bucket {
105
+ /** Tracks the state this bucket is in (blocked, running, waiting, etc) and what operations are allowed. */
106
+ readonly sm: SM;
107
+ /** Wrapped functions which always resolve (not reject) after the original function has completed and resolved. The original function may manipulate rate limit buckets in that time before it resolves. */
108
+ readonly calls: Array<() => any>;
109
+ /** The backing counters of the bucket that determine how many functions can be consumed in a timeframe. */
110
+ readonly counters: Array<Counter>;
111
+ private pauseRequested;
112
+ /**
113
+ * Create a new bucket
114
+ */
115
+ constructor(counters: Array<Counter>);
116
+ /**
117
+ * Queue a function to be executed
118
+ * @since 0.12.0
119
+ * @param fn function to be executed
120
+ * @returns Result of the function if any
121
+ */
122
+ enqueue<T>(fn: (bkt: this) => Promise<T>): Promise<T>;
123
+ /**
124
+ * Pause the bucket from consuming more functions until resumed
125
+ * @since 0.16.0
126
+ */
127
+ pause(): void;
128
+ /**
129
+ * If the bucket is paused, resume it
130
+ * @since 0.16.0
131
+ */
132
+ resume(): void;
133
+ /**
134
+ * Clear the current queue of events to be sent
135
+ * @since 0.1.0
136
+ */
137
+ dropQueue(): void;
138
+ }
139
+ /**
140
+ * Ratelimiter used for handling the ratelimits imposed by the rest api
141
+ * @since 0.1.0
142
+ */
143
+ export declare class Ratelimiter {
144
+ /**
145
+ * A Map of Buckets keyed by route keys that store rate limit info
146
+ */
147
+ readonly buckets: Map<string, Bucket>;
148
+ /**
149
+ * The bucket that limits how many requests per second you can make globally
150
+ */
151
+ readonly globalBucket: Bucket;
152
+ /**
153
+ * If you're being globally rate limited
154
+ */
155
+ get global(): boolean;
156
+ constructor();
157
+ /**
158
+ * Returns a key for saving ratelimits for routes
159
+ * (Taken from https://github.com/abalabahaha/eris/blob/master/lib/rest/RequestHandler.js) -> I luv u abal <3
160
+ * @since 0.1.0
161
+ * @param url url to reduce to a key something like /channels/266277541646434305/messages/266277541646434305/
162
+ * @param method method of the request, usual http methods like get, etc.
163
+ * @returns reduced url: /channels/266277541646434305/messages/:id/
164
+ */
165
+ routify(url: string, method: string): string;
166
+ /**
167
+ * Choose a bucket from the route and enqueue a rest call in it
168
+ * @since 0.1.0
169
+ * @param fn function to call once the ratelimit is ready
170
+ * @param url Endpoint of the request
171
+ * @param method Http method used by the request
172
+ */
173
+ queue<T>(fn: (bucket: Bucket) => Promise<T>, url: string, method: string): Promise<T>;
174
+ /**
175
+ * Set if this Ratelimiter is hitting a global ratelimit for `ms` duration
176
+ * @since 0.12.0
177
+ * @param ms How long in milliseconds this Ratelimiter is globally ratelimited for
178
+ */
179
+ setGlobal(ms: number): void;
180
+ }
181
+ export type RequestHandlerOptions = {
182
+ /** The base URL to use when making requests. Defaults to https://discord.com */
183
+ baseHost: string;
184
+ /** The base path of the base URL to use for the API. Defaults to /api/v${Constants.REST_API_VERSION} */
185
+ baseURL: string;
186
+ /** If rate limit buckets should be ignored */
187
+ bypassBuckets: boolean;
188
+ /** If failed requests that can be retried should be retried, up to retryLimit times. */
189
+ retryFailed: boolean;
190
+ /** How many times requests should be retried if they fail and can be retried. */
191
+ retryLimit: number;
192
+ headers: {
193
+ Authorization?: string;
194
+ "User-Agent": string;
195
+ [header: string]: string | undefined;
196
+ };
197
+ fetch: typeof globalThis.fetch;
198
+ };
199
+ /**
200
+ * Request Handler class
201
+ * @since 0.1.0
202
+ */
203
+ export declare class RequestHandler extends EventEmitter<HandlerEvents> {
204
+ ratelimiter: Ratelimiter;
205
+ options: RequestHandlerOptions;
206
+ latency: number;
207
+ apiURL: string;
208
+ /**
209
+ * Create a new request handler
210
+ * @param ratelimiter ratelimiter to use for ratelimiting requests
211
+ * @param options options
212
+ */
213
+ constructor(ratelimiter: Ratelimiter, options?: {
214
+ token?: string;
215
+ } & Partial<Omit<RequestHandlerOptions, "headers">>);
216
+ /**
217
+ * Request a route from the discord api
218
+ * @since 0.1.0
219
+ * @param endpoint endpoint to request
220
+ * @param params URL query parameters to add on to the URL
221
+ * @param method http method to use
222
+ * @param dataType type of the data being sent
223
+ * @param data data to send, if any
224
+ * @param extraHeaders Any headers to send on top of the existing ones for this request
225
+ * @param retries How many retries should be performed for this request if it fails when possible and not a bad status code is returned
226
+ * @param rawResponse If the raw Response Object from fetch should be returned instead of trying to return a response.json() or undefined if no body
227
+ * @returns Result of the request
228
+ */
229
+ request(endpoint: string, params: Record<string, any> | undefined, method: HTTPMethod, dataType: "json", data?: any, extraHeaders?: Record<string, string>, retries?: number, rawResponse?: boolean): Promise<any>;
230
+ request(endpoint: string, params: Record<string, any> | undefined, method: HTTPMethod, dataType: "multipart", data?: FormData, extraHeaders?: Record<string, string>, retries?: number, rawResponse?: boolean): Promise<any>;
231
+ request(endpoint: string, params: Record<string, any> | undefined, method: HTTPMethod, dataType: "json" | "multipart", data?: any, extraHeaders?: Record<string, string>, retries?: number, rawResponse?: true): Promise<Response>;
232
+ /**
233
+ * Apply the received ratelimit headers to the ratelimit bucket
234
+ * @since 0.1.0
235
+ * @param bkt Ratelimit bucket to apply the headers to
236
+ * @param headers Http headers received from discord
237
+ */
238
+ private _applyRatelimitHeaders;
239
+ /**
240
+ * Execute a normal json request
241
+ * @since 0.1.0
242
+ * @param endpoint Endpoint to use
243
+ * @param params URL query parameters to add on to the URL
244
+ * @param data Data to send
245
+ * @returns Result of the request
246
+ */
247
+ private _request;
248
+ /**
249
+ * Execute a multipart/form-data request
250
+ * @since 0.1.0
251
+ * @param endpoint Endpoint to use
252
+ * @param params URL query parameters to add on to the URL
253
+ * @param method Http Method to use
254
+ * @param data data to send
255
+ * @returns Result of the request
256
+ */
257
+ private _multiPartRequest;
258
+ }