lunibee 0.1.6 → 0.1.8

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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +223 -223
  3. package/dist/builders/commands.d.ts +39 -0
  4. package/dist/builders/components.d.ts +37 -12
  5. package/dist/builders/embed.d.ts +3 -1
  6. package/dist/builders/index.d.ts +2 -2
  7. package/dist/builders/index.js +192 -29
  8. package/dist/builders/index.js.map +9 -7
  9. package/dist/collection/index.d.ts +30 -0
  10. package/dist/collection/index.js +79 -5
  11. package/dist/collection/index.js.map +4 -4
  12. package/dist/core/events.d.ts +88 -2
  13. package/dist/core/index.d.ts +46 -85
  14. package/dist/core/index.js +2395 -789
  15. package/dist/core/index.js.map +44 -22
  16. package/dist/core/permissions.d.ts +112 -53
  17. package/dist/formatters/index.d.ts +43 -3
  18. package/dist/formatters/index.js +64 -1
  19. package/dist/formatters/index.js.map +3 -3
  20. package/dist/handlers/index.js.map +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +3783 -1009
  23. package/dist/index.js.map +63 -38
  24. package/dist/managers/emoji.d.ts +38 -0
  25. package/dist/managers/guild-resources.d.ts +109 -0
  26. package/dist/managers/guild.d.ts +117 -1
  27. package/dist/managers/index.d.ts +37 -1
  28. package/dist/managers/index.js +1125 -81
  29. package/dist/managers/index.js.map +25 -20
  30. package/dist/rest/decoder.d.ts +23 -0
  31. package/dist/rest/errors.d.ts +20 -0
  32. package/dist/rest/index.d.ts +119 -25
  33. package/dist/rest/index.js +676 -204
  34. package/dist/rest/index.js.map +14 -6
  35. package/dist/rest/limiter.d.ts +42 -0
  36. package/dist/rest/redis.d.ts +54 -0
  37. package/dist/rest/route.d.ts +31 -0
  38. package/dist/rest/routes.d.ts +24 -0
  39. package/dist/rest/scheduler.d.ts +42 -0
  40. package/dist/rest/store.d.ts +67 -0
  41. package/dist/rest/transport.d.ts +40 -0
  42. package/dist/rest/webhook.d.ts +2 -2
  43. package/dist/sharding/bus.d.ts +31 -0
  44. package/dist/sharding/cluster.d.ts +71 -0
  45. package/dist/sharding/index.d.ts +18 -2
  46. package/dist/sharding/index.js +1202 -317
  47. package/dist/sharding/index.js.map +18 -7
  48. package/dist/structures/audit-log.d.ts +26 -0
  49. package/dist/structures/base.d.ts +40 -0
  50. package/dist/structures/channels.d.ts +56 -0
  51. package/dist/structures/index.d.ts +30 -1
  52. package/dist/structures/index.js +963 -87
  53. package/dist/structures/index.js.map +17 -10
  54. package/dist/structures/interactions.d.ts +12 -52
  55. package/dist/structures/options.d.ts +55 -0
  56. package/dist/structures/resources.d.ts +194 -6
  57. package/dist/types/gateway-events.d.ts +132 -0
  58. package/dist/types/gateway.d.ts +181 -0
  59. package/dist/types/index.d.ts +78 -263
  60. package/dist/types/index.js +44 -2
  61. package/dist/types/index.js.map +5 -4
  62. package/dist/utils/index.js.map +2 -2
  63. package/dist/voice/index.d.ts +116 -0
  64. package/dist/voice/index.js +261 -10
  65. package/dist/voice/index.js.map +3 -3
  66. package/dist/ws/close-codes.d.ts +23 -0
  67. package/dist/ws/decoder.d.ts +58 -0
  68. package/dist/ws/heartbeat.d.ts +87 -0
  69. package/dist/ws/index.d.ts +24 -32
  70. package/dist/ws/index.js +920 -318
  71. package/dist/ws/index.js.map +15 -5
  72. package/dist/ws/opcodes.d.ts +14 -0
  73. package/dist/ws/protocol.d.ts +110 -0
  74. package/dist/ws/reconnect.d.ts +108 -0
  75. package/dist/ws/send-budget.d.ts +17 -0
  76. package/dist/ws/session.d.ts +100 -0
  77. package/dist/ws/state.d.ts +27 -0
  78. package/dist/ws/transport.d.ts +80 -0
  79. package/package.json +23 -22
  80. package/dist/structures/permissions.d.ts +0 -73
@@ -0,0 +1,23 @@
1
+ /** Normalised shape of a Discord error payload. */
2
+ export interface DecodedError {
3
+ message?: string;
4
+ code?: number;
5
+ retry_after?: number;
6
+ global?: boolean;
7
+ }
8
+ /** Turns a raw {@link Response} into a payload and the error metadata retries need. */
9
+ export declare class ResponseDecoder {
10
+ /** Reads a Discord response payload as JSON, text, or nothing for 204. */
11
+ read(response: Response): Promise<unknown>;
12
+ /** Extracts Discord's error metadata from a decoded payload. */
13
+ errorData(payload: unknown): DecodedError;
14
+ /**
15
+ * Resolves Retry-After (seconds) from the payload, falling back to the
16
+ * header and finally to one second.
17
+ *
18
+ * An absent header is explicitly *not* a zero delay: `Number(null)` is 0,
19
+ * which is finite, so reading it directly would answer a 429 that carries
20
+ * no Retry-After by retrying immediately — exactly when backing off matters.
21
+ */
22
+ retryAfter(response: Response, data: DecodedError): number;
23
+ }
@@ -0,0 +1,20 @@
1
+ /** Error thrown when Discord rejects a REST request. */
2
+ export declare class RESTError extends Error {
3
+ /** HTTP status returned by Discord. */ readonly status: number;
4
+ /** Discord API error code, when provided. */ readonly code?: number;
5
+ /** Raw Discord validation/error payload. */ readonly errors?: unknown;
6
+ /** HTTP method used for the failed request. */ readonly method?: string;
7
+ /** API path used for the failed request. */ readonly path?: string;
8
+ /** Creates a REST error with request context. @param message Error message. @param status HTTP status. @param code Discord error code. @param errors Raw error payload. @param options Request context and cause. */
9
+ constructor(message: string, status: number, code?: number, errors?: unknown, options?: {
10
+ method?: string;
11
+ path?: string;
12
+ cause?: unknown;
13
+ });
14
+ }
15
+ /** Creates the cancellation error shared by every stage of the request pipeline. */
16
+ export declare function abortError(path: string, reason: unknown): RESTError;
17
+ /** Waits for a delay, rejecting early if the signal aborts. */
18
+ export declare function sleep(delay: number, signal: AbortSignal | undefined, path: string): Promise<void>;
19
+ /** Awaits a promise, rejecting early if the signal aborts. */
20
+ export declare function abortable(promise: Promise<void>, signal: AbortSignal | undefined, path: string): Promise<void>;
@@ -1,26 +1,84 @@
1
- /** Error thrown when Discord rejects a REST request. */
2
- export declare class RESTError extends Error {
3
- /** HTTP status returned by Discord. */ readonly status: number;
4
- /** Discord API error code, when provided. */ readonly code?: number;
5
- /** Raw Discord validation/error payload. */ readonly errors?: unknown;
6
- /** HTTP method used for the failed request. */ readonly method?: string;
7
- /** API path used for the failed request. */ readonly path?: string;
8
- /** Creates a REST error with request context. @param message Error message. @param status HTTP status. @param code Discord error code. @param errors Raw error payload. @param options Request context and cause. */
9
- constructor(message: string, status: number, code?: number, errors?: unknown, options?: {
10
- method?: string;
11
- path?: string;
12
- cause?: unknown;
13
- });
14
- }
15
- /** Options controlling an individual REST request. */
16
- export interface RESTRequestOptions {
17
- /** Abort signal used to cancel the request and any queued wait. */ signal?: AbortSignal;
18
- }
1
+ import { type RateLimitStore } from "./store.js";
2
+ import { RESTError } from "./errors.js";
3
+ import { type RESTQuery } from "./route.js";
4
+ import { HttpTransport } from "./transport.js";
5
+ /** A file attachment sent as part of a multipart REST request. */
19
6
  export interface RESTFileAttachment {
20
7
  name: string;
21
8
  data: Blob | Uint8Array | ArrayBuffer;
22
9
  contentType?: string;
23
10
  }
11
+ /**
12
+ * Options controlling an individual REST request.
13
+ *
14
+ * Lunibee's canonical call shape is positional (`post(path, body)`); these options
15
+ * add the Discord.js-`@discordjs/rest`-familiar per-request knobs (`query`, `headers`,
16
+ * `reason`, `auth`) additively without changing that positional default.
17
+ */
18
+ export interface RESTRequestOptions {
19
+ /** Abort signal used to cancel the request and any queued wait. */ signal?: AbortSignal;
20
+ /** Query-string appended to the path (`URLSearchParams`, a record, or a raw string). */ query?: RESTQuery;
21
+ /** Extra request headers merged in (library headers such as `Authorization` win). */ headers?: Record<string, string>;
22
+ /** Audit-log reason, sent as the `X-Audit-Log-Reason` header. */ reason?: string;
23
+ /** Set `false` to omit the `Authorization` header for this request. Defaults to `true`. */ auth?: boolean;
24
+ }
25
+ /**
26
+ * Discord.js-familiar request payload. Superset of {@link RESTRequestOptions} that also
27
+ * carries the `body` and `files`, matching `@discordjs/rest`'s `RequestData`. It powers the
28
+ * additive `method(path, { body })` overloads without breaking the positional signature.
29
+ */
30
+ export interface RequestData extends RESTRequestOptions {
31
+ /** Request body. Encoded as JSON unless `files` are present (then multipart). */ body?: unknown;
32
+ /** File attachments; presence upgrades the request to `multipart/form-data`. */ files?: RESTFileAttachment[];
33
+ }
34
+ /** Context passed to `RESTHooks.onRequest`. */
35
+ export interface RESTRequestContext {
36
+ method: string;
37
+ path: string;
38
+ attempt: number;
39
+ }
40
+ /** Context passed to `RESTHooks.onResponse`. */
41
+ export interface RESTResponseContext {
42
+ method: string;
43
+ path: string;
44
+ status: number;
45
+ durationMs: number;
46
+ }
47
+ /** Context passed to `RESTHooks.onRateLimit`. */
48
+ export interface RESTRateLimitContext {
49
+ method: string;
50
+ path: string;
51
+ retryAfterMs: number;
52
+ global: boolean;
53
+ bucket?: string;
54
+ }
55
+ /** Context passed to `RESTHooks.onRetry`. */
56
+ export interface RESTRetryContext {
57
+ method: string;
58
+ path: string;
59
+ attempt: number;
60
+ status: number;
61
+ delayMs: number;
62
+ }
63
+ /**
64
+ * Lightweight callback hooks for REST request lifecycle events.
65
+ *
66
+ * All callbacks are optional. They are dispatched in isolation from the request
67
+ * path (deferred to a microtask, and any thrown error is swallowed), so a hook
68
+ * cannot break or reject a request. Even so, hooks **must** be fast and
69
+ * non-blocking: heavy synchronous work in a hook still steals event-loop time
70
+ * from in-flight requests. Offload anything expensive to your own queue.
71
+ */
72
+ export interface RESTHooks {
73
+ /** Called just before every HTTP attempt. */
74
+ onRequest?(ctx: RESTRequestContext): void;
75
+ /** Called after a successful or failed response is received. */
76
+ onResponse?(ctx: RESTResponseContext): void;
77
+ /** Called when a rate limit is encountered and the client is about to wait. */
78
+ onRateLimit?(ctx: RESTRateLimitContext): void;
79
+ /** Called when a failed request is about to be retried. */
80
+ onRetry?(ctx: RESTRetryContext): void;
81
+ }
24
82
  /** Configures which REST failures may be retried. */
25
83
  export interface RetryPolicy {
26
84
  /** Maximum retry attempts. */ maxRetries: number;
@@ -39,7 +97,22 @@ export declare class REST {
39
97
  retries?: number;
40
98
  retryPolicy?: RetryPolicy;
41
99
  baseURL?: string;
100
+ hooks?: RESTHooks;
101
+ store?: RateLimitStore;
102
+ /** Replaces the HTTP stage, e.g. with a recording transport in tests. */
103
+ transport?: HttpTransport;
104
+ /**
105
+ * Lets requests on a bucket whose limit is known run concurrently, up
106
+ * to its `remaining` allowance, instead of one at a time. Requires a
107
+ * store with `reserve`. Requests on one bucket may then complete out
108
+ * of order (e.g. messages to one channel). Defaults to `false`.
109
+ */
110
+ concurrentBuckets?: boolean;
42
111
  });
112
+ /** The rate-limit store backing this transport. */
113
+ get store(): RateLimitStore;
114
+ /** Replaces the current hook set. Pass an empty object to clear all hooks. */
115
+ setHooks(hooks: RESTHooks): this;
43
116
  /** Sets the authentication token. @param token Discord bot token. @returns Nothing. @throws {TypeError} If token is empty. */
44
117
  setToken(token: string): void;
45
118
  /** Executes an HTTP request with Discord bucket/global rate limits, retry handling, and AbortSignal support.
@@ -47,16 +120,23 @@ export declare class REST {
47
120
  * @param method HTTP method.
48
121
  * @param path API path.
49
122
  * @param body Optional JSON body, FormData for file uploads, or undefined.
50
- * @param options Cancellation options.
123
+ * @param options Request options: cancellation `signal` plus the Discord.js-familiar
124
+ * `query`, `headers`, `reason`, `auth`, and `files` (which upgrade to multipart).
51
125
  * @returns Decoded response body.
52
126
  * @throws {RESTError} If Discord or transport rejects the request.
53
127
  */
54
- request<T>(method: string, path: string, body?: unknown, options?: RESTRequestOptions): Promise<T>;
55
- /** Sends a GET request. @param path API path. @param options Cancellation options. @returns Decoded response. @throws {RESTError} When the request fails. */ get<T>(path: string, options?: RESTRequestOptions): Promise<T>;
56
- /** Sends a POST request. @param path API path. @param body Optional JSON body. @param options Cancellation options. @returns Decoded response. @throws {RESTError} When the request fails. */ post<T>(path: string, body?: unknown, options?: RESTRequestOptions): Promise<T>;
57
- /** Sends a PATCH request. @param path API path. @param body Optional JSON body. @param options Cancellation options. @returns Decoded response. @throws {RESTError} When the request fails. */ patch<T>(path: string, body?: unknown, options?: RESTRequestOptions): Promise<T>;
58
- /** Sends a PUT request. @param path API path. @param body Optional JSON body. @param options Cancellation options. @returns Decoded response. @throws {RESTError} When the request fails. */ put<T>(path: string, body?: unknown, options?: RESTRequestOptions): Promise<T>;
59
- /** Sends a DELETE request. @param path API path. @param options Cancellation options. @returns Decoded response. @throws {RESTError} When the request fails. */ delete<T>(path: string, options?: RESTRequestOptions): Promise<T>;
128
+ request<T>(method: string, path: string, body?: unknown, options?: RequestData): Promise<T>;
129
+ /** Sends a GET request. @param path API path. @param options Request options (`query`, `headers`, `signal`, …). @returns Decoded response. @throws {RESTError} When the request fails. */ get<T>(path: string, options?: RequestData): Promise<T>;
130
+ /** Sends a POST request. Accepts a raw body (`post(path, body)`) or a Discord.js-familiar `post(path, { body })`. @param path API path. @param body Optional JSON body, or a `RequestData` wrapper. @param options Request options. @returns Decoded response. @throws {RESTError} When the request fails. */
131
+ post<T>(path: string, options: RequestData): Promise<T>;
132
+ post<T>(path: string, body?: unknown, options?: RequestData): Promise<T>;
133
+ /** Sends a PATCH request. Accepts a raw body (`patch(path, body)`) or a Discord.js-familiar `patch(path, { body })`. @param path API path. @param body Optional JSON body, or a `RequestData` wrapper. @param options Request options. @returns Decoded response. @throws {RESTError} When the request fails. */
134
+ patch<T>(path: string, options: RequestData): Promise<T>;
135
+ patch<T>(path: string, body?: unknown, options?: RequestData): Promise<T>;
136
+ /** Sends a PUT request. Accepts a raw body (`put(path, body)`) or a Discord.js-familiar `put(path, { body })`. @param path API path. @param body Optional JSON body, or a `RequestData` wrapper. @param options Request options. @returns Decoded response. @throws {RESTError} When the request fails. */
137
+ put<T>(path: string, options: RequestData): Promise<T>;
138
+ put<T>(path: string, body?: unknown, options?: RequestData): Promise<T>;
139
+ /** Sends a DELETE request. @param path API path. @param options Request options (`reason`, `headers`, `signal`, …). @returns Decoded response. @throws {RESTError} When the request fails. */ delete<T>(path: string, options?: RequestData): Promise<T>;
60
140
  /**
61
141
  * Sends a multipart/form-data POST request for file uploads.
62
142
  * Attaches a JSON payload as `payload_json` and files as additional fields.
@@ -80,4 +160,18 @@ export declare class REST {
80
160
  patchWithFiles<T>(path: string, payload: unknown, files: RESTFileAttachment[], options?: RESTRequestOptions): Promise<T>;
81
161
  }
82
162
  export { Routes } from "./routes.js";
163
+ export { RESTError, abortError } from "./errors.js";
164
+ export { createRouteKey, normalizeRoutePath, majorParameter, scopeBucket, serializeQuery, type RouteKey, type RESTQuery, } from "./route.js";
165
+ export { RequestScheduler } from "./scheduler.js";
166
+ export { RateLimiter } from "./limiter.js";
167
+ export { HttpTransport, TransportError, type TransportRequest, type FetchLike, } from "./transport.js";
168
+ export { ResponseDecoder, type DecodedError } from "./decoder.js";
169
+ export { type RateLimitStore, type BucketState, type Reservation, MemoryRateLimitStore, } from "./store.js";
170
+ export { RedisRateLimitStore, type RedisRateLimitStoreOptions, type MinimalRedisClient, } from "./redis.js";
83
171
  export { WebhookClient, type WebhookClientOptions, type WebhookMessageOptions, } from "./webhook.js";
172
+ /**
173
+ * Discord.js-familiar alias for {@link RESTError}. `@discordjs/rest` throws `DiscordAPIError`
174
+ * on a Discord-rejected request; Lunibee keeps `RESTError` as the canonical class and exports
175
+ * this alias so Discord.js-shaped `catch (err) { if (err instanceof DiscordAPIError) … }` works.
176
+ */
177
+ export { RESTError as DiscordAPIError };