@discordjs/rest 1.0.0 → 1.0.1-dev.1658362255-96b62b6.0

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 (66) hide show
  1. package/README.md +15 -12
  2. package/dist/index.cjs +31 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +9 -827
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.mjs +9 -985
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/lib/CDN.cjs +87 -0
  9. package/dist/lib/CDN.cjs.map +1 -0
  10. package/dist/lib/CDN.d.ts +199 -0
  11. package/dist/lib/CDN.d.ts.map +1 -0
  12. package/dist/lib/CDN.mjs +83 -0
  13. package/dist/lib/CDN.mjs.map +1 -0
  14. package/dist/lib/REST.cjs +61 -0
  15. package/dist/lib/REST.cjs.map +1 -0
  16. package/dist/lib/REST.d.ts +279 -0
  17. package/dist/lib/REST.d.ts.map +1 -0
  18. package/dist/lib/REST.mjs +57 -0
  19. package/dist/lib/REST.mjs.map +1 -0
  20. package/dist/lib/RequestManager.cjs +223 -0
  21. package/dist/lib/RequestManager.cjs.map +1 -0
  22. package/dist/lib/RequestManager.d.ts +232 -0
  23. package/dist/lib/RequestManager.d.ts.map +1 -0
  24. package/dist/lib/RequestManager.mjs +218 -0
  25. package/dist/lib/RequestManager.mjs.map +1 -0
  26. package/dist/lib/errors/DiscordAPIError.cjs +55 -0
  27. package/dist/lib/errors/DiscordAPIError.cjs.map +1 -0
  28. package/dist/lib/errors/DiscordAPIError.d.ts +53 -0
  29. package/dist/lib/errors/DiscordAPIError.d.ts.map +1 -0
  30. package/dist/lib/errors/DiscordAPIError.mjs +51 -0
  31. package/dist/lib/errors/DiscordAPIError.mjs.map +1 -0
  32. package/dist/lib/errors/HTTPError.cjs +17 -0
  33. package/dist/lib/errors/HTTPError.cjs.map +1 -0
  34. package/dist/lib/errors/HTTPError.d.ts +21 -0
  35. package/dist/lib/errors/HTTPError.d.ts.map +1 -0
  36. package/dist/lib/errors/HTTPError.mjs +13 -0
  37. package/dist/lib/errors/HTTPError.mjs.map +1 -0
  38. package/dist/lib/errors/RateLimitError.cjs +23 -0
  39. package/dist/lib/errors/RateLimitError.cjs.map +1 -0
  40. package/dist/lib/errors/RateLimitError.d.ts +17 -0
  41. package/dist/lib/errors/RateLimitError.d.ts.map +1 -0
  42. package/dist/lib/errors/RateLimitError.mjs +19 -0
  43. package/dist/lib/errors/RateLimitError.mjs.map +1 -0
  44. package/dist/lib/handlers/IHandler.d.ts +9 -0
  45. package/dist/lib/handlers/IHandler.d.ts.map +1 -0
  46. package/dist/lib/handlers/SequentialHandler.cjs +299 -0
  47. package/dist/lib/handlers/SequentialHandler.cjs.map +1 -0
  48. package/dist/lib/handlers/SequentialHandler.d.ts +88 -0
  49. package/dist/lib/handlers/SequentialHandler.d.ts.map +1 -0
  50. package/dist/lib/handlers/SequentialHandler.mjs +295 -0
  51. package/dist/lib/handlers/SequentialHandler.mjs.map +1 -0
  52. package/dist/lib/utils/constants.cjs +49 -0
  53. package/dist/lib/utils/constants.cjs.map +1 -0
  54. package/dist/lib/utils/constants.d.ts +21 -0
  55. package/dist/lib/utils/constants.d.ts.map +1 -0
  56. package/dist/lib/utils/constants.mjs +49 -0
  57. package/dist/lib/utils/constants.mjs.map +1 -0
  58. package/dist/lib/utils/utils.cjs +111 -0
  59. package/dist/lib/utils/utils.cjs.map +1 -0
  60. package/dist/lib/utils/utils.d.ts +32 -0
  61. package/dist/lib/utils/utils.d.ts.map +1 -0
  62. package/dist/lib/utils/utils.mjs +103 -0
  63. package/dist/lib/utils/utils.mjs.map +1 -0
  64. package/package.json +13 -10
  65. package/dist/index.js +0 -1026
  66. package/dist/index.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,827 +1,9 @@
1
- import { EventEmitter } from 'node:events';
2
- import { Collection } from '@discordjs/collection';
3
- import { Dispatcher, BodyInit, Agent, request } from 'undici';
4
- import { URLSearchParams as URLSearchParams$1 } from 'node:url';
5
-
6
- interface IHandler {
7
- queueRequest: (routeId: RouteData, url: string, options: RequestOptions, requestData: HandlerRequestData) => Promise<Dispatcher.ResponseData>;
8
- get inactive(): boolean;
9
- readonly id: string;
10
- }
11
-
12
- /**
13
- * Represents a file to be added to the request
14
- */
15
- interface RawFile {
16
- /**
17
- * The name of the file
18
- */
19
- name: string;
20
- /**
21
- * An explicit key to use for key of the formdata field for this file.
22
- * When not provided, the index of the file in the files array is used in the form `files[${index}]`.
23
- * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)
24
- */
25
- key?: string;
26
- /**
27
- * The actual data for the file
28
- */
29
- data: string | number | boolean | Buffer;
30
- /**
31
- * Content-Type of the file
32
- */
33
- contentType?: string;
34
- }
35
- /**
36
- * Represents possible data to be given to an endpoint
37
- */
38
- interface RequestData {
39
- /**
40
- * Whether to append JSON data to form data instead of `payload_json` when sending files
41
- */
42
- appendToFormData?: boolean;
43
- /**
44
- * If this request needs the `Authorization` header
45
- *
46
- * @default true
47
- */
48
- auth?: boolean;
49
- /**
50
- * The authorization prefix to use for this request, useful if you use this with bearer tokens
51
- *
52
- * @default 'Bot'
53
- */
54
- authPrefix?: 'Bot' | 'Bearer';
55
- /**
56
- * The body to send to this request.
57
- * If providing as BodyInit, set `passThroughBody: true`
58
- */
59
- body?: BodyInit | unknown;
60
- /**
61
- * The {@link https://undici.nodejs.org/#/docs/api/Agent Agent} to use for the request.
62
- */
63
- dispatcher?: Agent;
64
- /**
65
- * Files to be attached to this request
66
- */
67
- files?: RawFile[] | undefined;
68
- /**
69
- * Additional headers to add to this request
70
- */
71
- headers?: Record<string, string>;
72
- /**
73
- * Whether to pass-through the body property directly to `fetch()`.
74
- * <warn>This only applies when files is NOT present</warn>
75
- */
76
- passThroughBody?: boolean;
77
- /**
78
- * Query string parameters to append to the called endpoint
79
- */
80
- query?: URLSearchParams;
81
- /**
82
- * Reason to show in the audit logs
83
- */
84
- reason?: string;
85
- /**
86
- * If this request should be versioned
87
- *
88
- * @default true
89
- */
90
- versioned?: boolean;
91
- }
92
- /**
93
- * Possible headers for an API call
94
- */
95
- interface RequestHeaders {
96
- Authorization?: string;
97
- 'User-Agent': string;
98
- 'X-Audit-Log-Reason'?: string;
99
- }
100
- /**
101
- * Possible API methods to be used when doing requests
102
- */
103
- declare const enum RequestMethod {
104
- Delete = "DELETE",
105
- Get = "GET",
106
- Patch = "PATCH",
107
- Post = "POST",
108
- Put = "PUT"
109
- }
110
- declare type RouteLike = `/${string}`;
111
- /**
112
- * Internal request options
113
- *
114
- * @internal
115
- */
116
- interface InternalRequest extends RequestData {
117
- method: RequestMethod;
118
- fullRoute: RouteLike;
119
- }
120
- declare type HandlerRequestData = Pick<InternalRequest, 'files' | 'body' | 'auth'>;
121
- /**
122
- * Parsed route data for an endpoint
123
- *
124
- * @internal
125
- */
126
- interface RouteData {
127
- majorParameter: string;
128
- bucketRoute: string;
129
- original: RouteLike;
130
- }
131
- /**
132
- * Represents a hash and its associated fields
133
- *
134
- * @internal
135
- */
136
- interface HashData {
137
- value: string;
138
- lastAccess: number;
139
- }
140
- interface RequestManager {
141
- on: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
142
- once: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
143
- emit: (<K extends keyof RestEvents>(event: K, ...args: RestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, ...args: any[]) => boolean);
144
- off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
145
- removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
146
- }
147
- /**
148
- * Represents the class that manages handlers for endpoints
149
- */
150
- declare class RequestManager extends EventEmitter {
151
- #private;
152
- /**
153
- * The {@link https://undici.nodejs.org/#/docs/api/Agent Agent} for all requests
154
- * performed by this manager.
155
- */
156
- agent: Dispatcher | null;
157
- /**
158
- * The number of requests remaining in the global bucket
159
- */
160
- globalRemaining: number;
161
- /**
162
- * The promise used to wait out the global rate limit
163
- */
164
- globalDelay: Promise<void> | null;
165
- /**
166
- * The timestamp at which the global bucket resets
167
- */
168
- globalReset: number;
169
- /**
170
- * API bucket hashes that are cached from provided routes
171
- */
172
- readonly hashes: Collection<string, HashData>;
173
- /**
174
- * Request handlers created from the bucket hash and the major parameters
175
- */
176
- readonly handlers: Collection<string, IHandler>;
177
- private hashTimer;
178
- private handlerTimer;
179
- readonly options: RESTOptions;
180
- constructor(options: Partial<RESTOptions>);
181
- private setupSweepers;
182
- /**
183
- * Sets the default agent to use for requests performed by this manager
184
- *
185
- * @param agent - The agent to use
186
- */
187
- setAgent(agent: Dispatcher): this;
188
- /**
189
- * Sets the authorization token that should be used for requests
190
- *
191
- * @param token - The authorization token to use
192
- */
193
- setToken(token: string): this;
194
- /**
195
- * Queues a request to be sent
196
- *
197
- * @param request - All the information needed to make a request
198
- *
199
- * @returns The response from the api request
200
- */
201
- queueRequest(request: InternalRequest): Promise<Dispatcher.ResponseData>;
202
- /**
203
- * Creates a new rate limit handler from a hash, based on the hash and the major parameter
204
- *
205
- * @param hash - The hash for the route
206
- * @param majorParameter - The major parameter for this handler
207
- *
208
- * @private
209
- */
210
- private createHandler;
211
- /**
212
- * Formats the request data to a usable format for fetch
213
- *
214
- * @param request - The request data
215
- */
216
- private resolveRequest;
217
- /**
218
- * Stops the hash sweeping interval
219
- */
220
- clearHashSweeper(): void;
221
- /**
222
- * Stops the request handler sweeping interval
223
- */
224
- clearHandlerSweeper(): void;
225
- /**
226
- * Generates route data for an endpoint:method
227
- *
228
- * @param endpoint - The raw endpoint to generalize
229
- * @param method - The HTTP method this endpoint is called without
230
- *
231
- * @private
232
- */
233
- private static generateRouteData;
234
- }
235
-
236
- /**
237
- * Options to be passed when creating the REST instance
238
- */
239
- interface RESTOptions {
240
- /**
241
- * The agent to set globally
242
- */
243
- agent: Dispatcher;
244
- /**
245
- * The base api path, without version
246
- * @default 'https://discord.com/api'
247
- */
248
- api: string;
249
- /**
250
- * The authorization prefix to use for requests, useful if you want to use
251
- * bearer tokens
252
- *
253
- * @default 'Bot'
254
- */
255
- authPrefix: 'Bot' | 'Bearer';
256
- /**
257
- * The cdn path
258
- *
259
- * @default 'https://cdn.discordapp.com'
260
- */
261
- cdn: string;
262
- /**
263
- * Additional headers to send for all API requests
264
- *
265
- * @default {}
266
- */
267
- headers: Record<string, string>;
268
- /**
269
- * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).
270
- * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
271
- *
272
- * @default 0
273
- */
274
- invalidRequestWarningInterval: number;
275
- /**
276
- * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)
277
- *
278
- * @default 50
279
- */
280
- globalRequestsPerSecond: number;
281
- /**
282
- * The extra offset to add to rate limits in milliseconds
283
- *
284
- * @default 50
285
- */
286
- offset: number;
287
- /**
288
- * Determines how rate limiting and pre-emptive throttling should be handled.
289
- * When an array of strings, each element is treated as a prefix for the request route
290
- * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)
291
- * for which to throw {@link RateLimitError}s. All other request routes will be queued normally
292
- *
293
- * @default null
294
- */
295
- rejectOnRateLimit: string[] | RateLimitQueueFilter | null;
296
- /**
297
- * The number of retries for errors with the 500 code, or errors
298
- * that timeout
299
- *
300
- * @default 3
301
- */
302
- retries: number;
303
- /**
304
- * The time to wait in milliseconds before a request is aborted
305
- *
306
- * @default 15_000
307
- */
308
- timeout: number;
309
- /**
310
- * Extra information to add to the user agent
311
- *
312
- * @default `Node.js ${process.version}`
313
- */
314
- userAgentAppendix: string;
315
- /**
316
- * The version of the API to use
317
- *
318
- * @default '10'
319
- */
320
- version: string;
321
- /**
322
- * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)
323
- *
324
- * @default 14_400_000
325
- */
326
- hashSweepInterval: number;
327
- /**
328
- * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)
329
- *
330
- * @default 86_400_000
331
- */
332
- hashLifetime: number;
333
- /**
334
- * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)
335
- *
336
- * @default 3_600_000
337
- */
338
- handlerSweepInterval: number;
339
- }
340
- /**
341
- * Data emitted on `RESTEvents.RateLimited`
342
- */
343
- interface RateLimitData {
344
- /**
345
- * The time, in milliseconds, until the request-lock is reset
346
- */
347
- timeToReset: number;
348
- /**
349
- * The amount of requests we can perform before locking requests
350
- */
351
- limit: number;
352
- /**
353
- * The HTTP method being performed
354
- */
355
- method: string;
356
- /**
357
- * The bucket hash for this request
358
- */
359
- hash: string;
360
- /**
361
- * The full URL for this request
362
- */
363
- url: string;
364
- /**
365
- * The route being hit in this request
366
- */
367
- route: string;
368
- /**
369
- * The major parameter of the route
370
- *
371
- * For example, in `/channels/x`, this will be `x`.
372
- * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.
373
- */
374
- majorParameter: string;
375
- /**
376
- * Whether the rate limit that was reached was the global limit
377
- */
378
- global: boolean;
379
- }
380
- /**
381
- * A function that determines whether the rate limit hit should throw an Error
382
- */
383
- declare type RateLimitQueueFilter = (rateLimitData: RateLimitData) => boolean | Promise<boolean>;
384
- interface APIRequest {
385
- /**
386
- * The HTTP method used in this request
387
- */
388
- method: string;
389
- /**
390
- * The full path used to make the request
391
- */
392
- path: RouteLike;
393
- /**
394
- * The API route identifying the ratelimit for this request
395
- */
396
- route: string;
397
- /**
398
- * Additional HTTP options for this request
399
- */
400
- options: RequestOptions;
401
- /**
402
- * The data that was used to form the body of this request
403
- */
404
- data: HandlerRequestData;
405
- /**
406
- * The number of times this request has been attempted
407
- */
408
- retries: number;
409
- }
410
- interface InvalidRequestWarningData {
411
- /**
412
- * Number of invalid requests that have been made in the window
413
- */
414
- count: number;
415
- /**
416
- * Time in milliseconds remaining before the count resets
417
- */
418
- remainingTime: number;
419
- }
420
- interface RestEvents {
421
- invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
422
- restDebug: [info: string];
423
- rateLimited: [rateLimitInfo: RateLimitData];
424
- response: [request: APIRequest, response: Dispatcher.ResponseData];
425
- newListener: [name: string, listener: (...args: any) => void];
426
- removeListener: [name: string, listener: (...args: any) => void];
427
- hashSweep: [sweptHashes: Collection<string, HashData>];
428
- handlerSweep: [sweptHandlers: Collection<string, IHandler>];
429
- }
430
- declare type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;
431
- interface REST {
432
- on: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
433
- once: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
434
- emit: (<K extends keyof RestEvents>(event: K, ...args: RestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, ...args: any[]) => boolean);
435
- off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
436
- removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
437
- }
438
- declare class REST extends EventEmitter {
439
- readonly cdn: CDN;
440
- readonly requestManager: RequestManager;
441
- constructor(options?: Partial<RESTOptions>);
442
- /**
443
- * Gets the agent set for this instance
444
- */
445
- getAgent(): Dispatcher | null;
446
- /**
447
- * Sets the default agent to use for requests performed by this instance
448
- *
449
- * @param agent - Sets the agent to use
450
- */
451
- setAgent(agent: Dispatcher): this;
452
- /**
453
- * Sets the authorization token that should be used for requests
454
- *
455
- * @param token - The authorization token to use
456
- */
457
- setToken(token: string): this;
458
- /**
459
- * Runs a get request from the api
460
- *
461
- * @param fullRoute - The full route to query
462
- * @param options - Optional request options
463
- */
464
- get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
465
- /**
466
- * Runs a delete request from the api
467
- *
468
- * @param fullRoute - The full route to query
469
- * @param options - Optional request options
470
- */
471
- delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
472
- /**
473
- * Runs a post request from the api
474
- *
475
- * @param fullRoute - The full route to query
476
- * @param options - Optional request options
477
- */
478
- post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
479
- /**
480
- * Runs a put request from the api
481
- *
482
- * @param fullRoute - The full route to query
483
- * @param options - Optional request options
484
- */
485
- put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
486
- /**
487
- * Runs a patch request from the api
488
- *
489
- * @param fullRoute - The full route to query
490
- * @param options - Optional request options
491
- */
492
- patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>;
493
- /**
494
- * Runs a request from the api
495
- *
496
- * @param options - Request options
497
- */
498
- request(options: InternalRequest): Promise<unknown>;
499
- /**
500
- * Runs a request from the API, yielding the raw Response object
501
- *
502
- * @param options - Request options
503
- */
504
- raw(options: InternalRequest): Promise<Dispatcher.ResponseData>;
505
- }
506
-
507
- declare const DefaultUserAgent: string;
508
- declare const DefaultRestOptions: Required<RESTOptions>;
509
- /**
510
- * The events that the REST manager emits
511
- */
512
- declare const enum RESTEvents {
513
- Debug = "restDebug",
514
- InvalidRequestWarning = "invalidRequestWarning",
515
- RateLimited = "rateLimited",
516
- Response = "response",
517
- HashSweep = "hashSweep",
518
- HandlerSweep = "handlerSweep"
519
- }
520
- declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
521
- declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json"];
522
- declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
523
- declare type ImageExtension = typeof ALLOWED_EXTENSIONS[number];
524
- declare type StickerExtension = typeof ALLOWED_STICKER_EXTENSIONS[number];
525
- declare type ImageSize = typeof ALLOWED_SIZES[number];
526
-
527
- /**
528
- * The options used for image URLs
529
- */
530
- interface BaseImageURLOptions {
531
- /**
532
- * The extension to use for the image URL
533
- *
534
- * @default 'webp'
535
- */
536
- extension?: ImageExtension;
537
- /**
538
- * The size specified in the image URL
539
- */
540
- size?: ImageSize;
541
- }
542
- /**
543
- * The options used for image URLs with animated content
544
- */
545
- interface ImageURLOptions extends BaseImageURLOptions {
546
- /**
547
- * Whether or not to prefer the static version of an image asset.
548
- */
549
- forceStatic?: boolean;
550
- }
551
- /**
552
- * The options to use when making a CDN URL
553
- */
554
- interface MakeURLOptions {
555
- /**
556
- * The extension to use for the image URL
557
- *
558
- * @default 'webp'
559
- */
560
- extension?: string | undefined;
561
- /**
562
- * The size specified in the image URL
563
- */
564
- size?: ImageSize;
565
- /**
566
- * The allowed extensions that can be used
567
- */
568
- allowedExtensions?: ReadonlyArray<string>;
569
- }
570
- /**
571
- * The CDN link builder
572
- */
573
- declare class CDN {
574
- private readonly base;
575
- constructor(base?: string);
576
- /**
577
- * Generates an app asset URL for a client's asset.
578
- *
579
- * @param clientId - The client id that has the asset
580
- * @param assetHash - The hash provided by Discord for this asset
581
- * @param options - Optional options for the asset
582
- */
583
- appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string;
584
- /**
585
- * Generates an app icon URL for a client's icon.
586
- *
587
- * @param clientId - The client id that has the icon
588
- * @param iconHash - The hash provided by Discord for this icon
589
- * @param options - Optional options for the icon
590
- */
591
- appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
592
- /**
593
- * Generates an avatar URL, e.g. for a user or a webhook.
594
- *
595
- * @param id - The id that has the icon
596
- * @param avatarHash - The hash provided by Discord for this avatar
597
- * @param options - Optional options for the avatar
598
- */
599
- avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
600
- /**
601
- * Generates a banner URL, e.g. for a user or a guild.
602
- *
603
- * @param id - The id that has the banner splash
604
- * @param bannerHash - The hash provided by Discord for this banner
605
- * @param options - Optional options for the banner
606
- */
607
- banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
608
- /**
609
- * Generates an icon URL for a channel, e.g. a group DM.
610
- *
611
- * @param channelId - The channel id that has the icon
612
- * @param iconHash - The hash provided by Discord for this channel
613
- * @param options - Optional options for the icon
614
- */
615
- channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
616
- /**
617
- * Generates the default avatar URL for a discriminator.
618
- *
619
- * @param discriminator - The discriminator modulo 5
620
- */
621
- defaultAvatar(discriminator: number): string;
622
- /**
623
- * Generates a discovery splash URL for a guild's discovery splash.
624
- *
625
- * @param guildId - The guild id that has the discovery splash
626
- * @param splashHash - The hash provided by Discord for this splash
627
- * @param options - Optional options for the splash
628
- */
629
- discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
630
- /**
631
- * Generates an emoji's URL for an emoji.
632
- *
633
- * @param emojiId - The emoji id
634
- * @param extension - The extension of the emoji
635
- */
636
- emoji(emojiId: string, extension?: ImageExtension): string;
637
- /**
638
- * Generates a guild member avatar URL.
639
- *
640
- * @param guildId - The id of the guild
641
- * @param userId - The id of the user
642
- * @param avatarHash - The hash provided by Discord for this avatar
643
- * @param options - Optional options for the avatar
644
- */
645
- guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
646
- /**
647
- * Generates a guild member banner URL.
648
- *
649
- * @param guildId - The id of the guild
650
- * @param userId - The id of the user
651
- * @param bannerHash - The hash provided by Discord for this banner
652
- * @param options - Optional options for the banner
653
- */
654
- guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string;
655
- /**
656
- * Generates an icon URL, e.g. for a guild.
657
- *
658
- * @param id - The id that has the icon splash
659
- * @param iconHash - The hash provided by Discord for this icon
660
- * @param options - Optional options for the icon
661
- */
662
- icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string;
663
- /**
664
- * Generates a URL for the icon of a role
665
- * @param roleId - The id of the role that has the icon
666
- * @param roleIconHash - The hash provided by Discord for this role icon
667
- * @param options - Optional options for the role icon
668
- */
669
- roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string;
670
- /**
671
- * Generates a guild invite splash URL for a guild's invite splash.
672
- *
673
- * @param guildId - The guild id that has the invite splash
674
- * @param splashHash - The hash provided by Discord for this splash
675
- * @param options - Optional options for the splash
676
- */
677
- splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
678
- /**
679
- * Generates a sticker URL.
680
- *
681
- * @param stickerId - The sticker id
682
- * @param extension - The extension of the sticker
683
- */
684
- sticker(stickerId: string, extension?: StickerExtension): string;
685
- /**
686
- * Generates a sticker pack banner URL.
687
- *
688
- * @param bannerId - The banner id
689
- * @param options - Optional options for the banner
690
- */
691
- stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string;
692
- /**
693
- * Generates a team icon URL for a team's icon.
694
- *
695
- * @param teamId - The team id that has the icon
696
- * @param iconHash - The hash provided by Discord for this icon
697
- * @param options - Optional options for the icon
698
- */
699
- teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string;
700
- /**
701
- * Generates a cover image for a guild scheduled event.
702
- *
703
- * @param scheduledEventId - The scheduled event id
704
- * @param coverHash - The hash provided by discord for this cover image
705
- * @param options - Optional options for the cover image
706
- */
707
- guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string;
708
- /**
709
- * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
710
- *
711
- * @param route - The base cdn route
712
- * @param hash - The hash provided by Discord for this icon
713
- * @param options - Optional options for the link
714
- */
715
- private dynamicMakeURL;
716
- /**
717
- * Constructs the URL for the resource
718
- *
719
- * @param route - The base cdn route
720
- * @param options - The extension/size options for the link
721
- */
722
- private makeURL;
723
- }
724
-
725
- interface DiscordErrorFieldInformation {
726
- code: string;
727
- message: string;
728
- }
729
- interface DiscordErrorGroupWrapper {
730
- _errors: DiscordError[];
731
- }
732
- declare type DiscordError = DiscordErrorGroupWrapper | DiscordErrorFieldInformation | {
733
- [k: string]: DiscordError;
734
- } | string;
735
- interface DiscordErrorData {
736
- code: number;
737
- message: string;
738
- errors?: DiscordError;
739
- }
740
- interface OAuthErrorData {
741
- error: string;
742
- error_description?: string;
743
- }
744
- interface RequestBody {
745
- files: RawFile[] | undefined;
746
- json: unknown | undefined;
747
- }
748
- /**
749
- * Represents an API error returned by Discord
750
- * @extends Error
751
- */
752
- declare class DiscordAPIError extends Error {
753
- rawError: DiscordErrorData | OAuthErrorData;
754
- code: number | string;
755
- status: number;
756
- method: string;
757
- url: string;
758
- requestBody: RequestBody;
759
- /**
760
- * @param rawError - The error reported by Discord
761
- * @param code - The error code reported by Discord
762
- * @param status - The status code of the response
763
- * @param method - The method of the request that erred
764
- * @param url - The url of the request that erred
765
- * @param bodyData - The unparsed data for the request that errored
766
- */
767
- constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'files' | 'body'>);
768
- /**
769
- * The name of the error
770
- */
771
- get name(): string;
772
- private static getMessage;
773
- private static flattenDiscordError;
774
- }
775
-
776
- /**
777
- * Represents a HTTP error
778
- */
779
- declare class HTTPError extends Error {
780
- name: string;
781
- status: number;
782
- method: string;
783
- url: string;
784
- requestBody: RequestBody;
785
- /**
786
- * @param name - The name of the error
787
- * @param status - The status code of the response
788
- * @param method - The method of the request that erred
789
- * @param url - The url of the request that erred
790
- * @param bodyData - The unparsed data for the request that errored
791
- */
792
- constructor(name: string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'files' | 'body'>);
793
- }
794
-
795
- declare class RateLimitError extends Error implements RateLimitData {
796
- timeToReset: number;
797
- limit: number;
798
- method: string;
799
- hash: string;
800
- url: string;
801
- route: string;
802
- majorParameter: string;
803
- global: boolean;
804
- constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData);
805
- /**
806
- * The name of the error
807
- */
808
- get name(): string;
809
- }
810
-
811
- /**
812
- * Creates and populates an URLSearchParams instance from an object, stripping
813
- * out null and undefined values, while also coercing non-strings to strings.
814
- *
815
- * @param options - The options to use
816
- *
817
- * @returns A populated URLSearchParams instance
818
- */
819
- declare function makeURLSearchParams(options?: Record<string, unknown>): URLSearchParams$1;
820
- /**
821
- * Converts the response to usable data
822
- *
823
- * @param res - The fetch response
824
- */
825
- declare function parseResponse(res: Dispatcher.ResponseData): Promise<unknown>;
826
-
827
- export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, APIRequest, BaseImageURLOptions, CDN, DefaultRestOptions, DefaultUserAgent, DiscordAPIError, DiscordErrorData, HTTPError, HandlerRequestData, HashData, ImageExtension, ImageSize, ImageURLOptions, InternalRequest, InvalidRequestWarningData, MakeURLOptions, OAuthErrorData, REST, RESTEvents, RESTOptions, RateLimitData, RateLimitError, RateLimitQueueFilter, RawFile, RequestBody, RequestData, RequestHeaders, RequestManager, RequestMethod, RequestOptions, RestEvents, RouteData, RouteLike, StickerExtension, makeURLSearchParams, parseResponse };
1
+ export * from './lib/CDN';
2
+ export * from './lib/errors/DiscordAPIError';
3
+ export * from './lib/errors/HTTPError';
4
+ export * from './lib/errors/RateLimitError';
5
+ export * from './lib/RequestManager';
6
+ export * from './lib/REST';
7
+ export * from './lib/utils/constants';
8
+ export { makeURLSearchParams, parseResponse } from './lib/utils/utils';
9
+ //# sourceMappingURL=index.d.ts.map