@discordkit/core 3.1.0 → 4.0.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 (173) hide show
  1. package/CHANGELOG.md +416 -0
  2. package/README.md +52 -0
  3. package/dist/index.d.mts +23 -0
  4. package/dist/index.mjs +23 -0
  5. package/dist/requests/DiscordSession.d.mts +30 -0
  6. package/dist/requests/DiscordSession.mjs +202 -0
  7. package/dist/requests/addParams.d.mts +15 -0
  8. package/dist/requests/addParams.mjs +24 -0
  9. package/dist/requests/buildURL.d.mts +7 -0
  10. package/dist/requests/buildURL.mjs +7 -0
  11. package/dist/requests/getAsset.d.mts +7 -0
  12. package/dist/requests/getAsset.mjs +6 -0
  13. package/dist/requests/index.d.mts +9 -0
  14. package/dist/requests/index.mjs +9 -0
  15. package/dist/requests/methods.d.mts +63 -0
  16. package/dist/requests/methods.mjs +10 -0
  17. package/dist/requests/request.d.mts +27 -0
  18. package/dist/requests/request.mjs +29 -0
  19. package/dist/requests/toProcedure.d.mts +40 -0
  20. package/dist/requests/toProcedure.mjs +27 -0
  21. package/dist/requests/toQuery.d.mts +36 -0
  22. package/dist/requests/toQuery.mjs +17 -0
  23. package/dist/requests/toValidated.d.mts +16 -0
  24. package/dist/requests/toValidated.mjs +25 -0
  25. package/dist/requests/verifyKey.d.mts +13 -0
  26. package/dist/requests/verifyKey.mjs +63 -0
  27. package/dist/utils/isBetween.d.mts +4 -0
  28. package/dist/utils/isBetween.mjs +4 -0
  29. package/dist/utils/{isNonNullable.d.ts → isNonNullable.d.mts} +5 -2
  30. package/dist/utils/isNonNullable.mjs +22 -0
  31. package/dist/utils/isNumericString.d.mts +4 -0
  32. package/dist/utils/isNumericString.mjs +4 -0
  33. package/dist/utils/isObject.d.mts +4 -0
  34. package/dist/utils/isObject.mjs +4 -0
  35. package/dist/utils/sleep.d.mts +7 -0
  36. package/dist/utils/sleep.mjs +7 -0
  37. package/dist/utils/toCamelCase.d.mts +4 -0
  38. package/dist/utils/toCamelCase.mjs +4 -0
  39. package/dist/utils/toCamelKeys.d.mts +6 -0
  40. package/dist/utils/toCamelKeys.mjs +13 -0
  41. package/dist/utils/toSnakeCase.d.mts +4 -0
  42. package/dist/utils/toSnakeCase.mjs +4 -0
  43. package/dist/utils/toSnakeKeys.d.mts +6 -0
  44. package/dist/utils/toSnakeKeys.mjs +13 -0
  45. package/dist/validations/asDigits.d.mts +12 -0
  46. package/dist/validations/asDigits.mjs +10 -0
  47. package/dist/validations/asInteger.d.mts +12 -0
  48. package/dist/validations/asInteger.mjs +10 -0
  49. package/dist/validations/bitfield.d.mts +23 -0
  50. package/dist/validations/bitfield.mjs +20 -0
  51. package/dist/validations/boundedArray.d.mts +13 -0
  52. package/dist/validations/boundedArray.mjs +9 -0
  53. package/dist/validations/boundedInteger.d.mts +13 -0
  54. package/dist/validations/boundedInteger.mjs +9 -0
  55. package/dist/validations/boundedString.d.mts +14 -0
  56. package/dist/validations/boundedString.mjs +10 -0
  57. package/dist/validations/datauri.d.mts +24 -0
  58. package/dist/validations/datauri.mjs +17 -0
  59. package/dist/validations/fileUpload.d.mts +129 -0
  60. package/dist/validations/fileUpload.mjs +114 -0
  61. package/dist/validations/hasMimeType.d.mts +16 -0
  62. package/dist/validations/hasMimeType.mjs +16 -0
  63. package/dist/validations/hasSize.d.mts +10 -0
  64. package/dist/validations/hasSize.mjs +12 -0
  65. package/dist/validations/index.d.mts +15 -0
  66. package/dist/validations/index.mjs +15 -0
  67. package/dist/validations/schema.d.mts +102 -0
  68. package/dist/validations/schema.mjs +109 -0
  69. package/dist/validations/{snowflake.d.ts → snowflake.d.mts} +9 -7
  70. package/dist/validations/snowflake.mjs +28 -0
  71. package/dist/validations/{timestamp.d.ts → timestamp.d.mts} +5 -1
  72. package/dist/validations/timestamp.mjs +6 -0
  73. package/dist/validations/toBlob.d.mts +9 -0
  74. package/dist/validations/toBlob.mjs +17 -0
  75. package/dist/validations/url.d.mts +6 -0
  76. package/dist/validations/url.mjs +5 -0
  77. package/package.json +13 -23
  78. package/dist/index.d.ts +0 -2
  79. package/dist/index.js +0 -3
  80. package/dist/index.js.map +0 -1
  81. package/dist/requests/DiscordSession.d.ts +0 -16
  82. package/dist/requests/DiscordSession.js +0 -42
  83. package/dist/requests/DiscordSession.js.map +0 -1
  84. package/dist/requests/addParams.d.ts +0 -2
  85. package/dist/requests/addParams.js +0 -11
  86. package/dist/requests/addParams.js.map +0 -1
  87. package/dist/requests/buildURL.d.ts +0 -2
  88. package/dist/requests/buildURL.js +0 -4
  89. package/dist/requests/buildURL.js.map +0 -1
  90. package/dist/requests/getAsset.d.ts +0 -2
  91. package/dist/requests/getAsset.js +0 -3
  92. package/dist/requests/getAsset.js.map +0 -1
  93. package/dist/requests/index.d.ts +0 -7
  94. package/dist/requests/index.js +0 -8
  95. package/dist/requests/index.js.map +0 -1
  96. package/dist/requests/methods.d.ts +0 -13
  97. package/dist/requests/methods.js +0 -8
  98. package/dist/requests/methods.js.map +0 -1
  99. package/dist/requests/request.d.ts +0 -2
  100. package/dist/requests/request.js +0 -35
  101. package/dist/requests/request.js.map +0 -1
  102. package/dist/requests/toProcedure.d.ts +0 -31
  103. package/dist/requests/toProcedure.js +0 -36
  104. package/dist/requests/toProcedure.js.map +0 -1
  105. package/dist/requests/toQuery.d.ts +0 -28
  106. package/dist/requests/toQuery.js +0 -9
  107. package/dist/requests/toQuery.js.map +0 -1
  108. package/dist/requests/toValidated.d.ts +0 -13
  109. package/dist/requests/toValidated.js +0 -29
  110. package/dist/requests/toValidated.js.map +0 -1
  111. package/dist/utils/isBetween.d.ts +0 -1
  112. package/dist/utils/isBetween.js +0 -2
  113. package/dist/utils/isBetween.js.map +0 -1
  114. package/dist/utils/isNonNullable.js +0 -20
  115. package/dist/utils/isNonNullable.js.map +0 -1
  116. package/dist/utils/isNumericString.d.ts +0 -1
  117. package/dist/utils/isNumericString.js +0 -2
  118. package/dist/utils/isNumericString.js.map +0 -1
  119. package/dist/utils/isObject.d.ts +0 -1
  120. package/dist/utils/isObject.js +0 -2
  121. package/dist/utils/isObject.js.map +0 -1
  122. package/dist/utils/toCamelCase.d.ts +0 -1
  123. package/dist/utils/toCamelCase.js +0 -2
  124. package/dist/utils/toCamelCase.js.map +0 -1
  125. package/dist/utils/toCamelKeys.d.ts +0 -2
  126. package/dist/utils/toCamelKeys.js +0 -16
  127. package/dist/utils/toCamelKeys.js.map +0 -1
  128. package/dist/utils/toSnakeCase.d.ts +0 -1
  129. package/dist/utils/toSnakeCase.js +0 -4
  130. package/dist/utils/toSnakeCase.js.map +0 -1
  131. package/dist/utils/toSnakeKeys.d.ts +0 -2
  132. package/dist/utils/toSnakeKeys.js +0 -16
  133. package/dist/utils/toSnakeKeys.js.map +0 -1
  134. package/dist/validations/asDigits.d.ts +0 -6
  135. package/dist/validations/asDigits.js +0 -6
  136. package/dist/validations/asDigits.js.map +0 -1
  137. package/dist/validations/asInteger.d.ts +0 -6
  138. package/dist/validations/asInteger.js +0 -6
  139. package/dist/validations/asInteger.js.map +0 -1
  140. package/dist/validations/bitfield.d.ts +0 -17
  141. package/dist/validations/bitfield.js +0 -37
  142. package/dist/validations/bitfield.js.map +0 -1
  143. package/dist/validations/boundedArray.d.ts +0 -6
  144. package/dist/validations/boundedArray.js +0 -8
  145. package/dist/validations/boundedArray.js.map +0 -1
  146. package/dist/validations/boundedInteger.d.ts +0 -6
  147. package/dist/validations/boundedInteger.js +0 -8
  148. package/dist/validations/boundedInteger.js.map +0 -1
  149. package/dist/validations/boundedString.d.ts +0 -6
  150. package/dist/validations/boundedString.js +0 -8
  151. package/dist/validations/boundedString.js.map +0 -1
  152. package/dist/validations/datauri.d.ts +0 -20
  153. package/dist/validations/datauri.js +0 -20
  154. package/dist/validations/datauri.js.map +0 -1
  155. package/dist/validations/hasMimeType.d.ts +0 -10
  156. package/dist/validations/hasMimeType.js +0 -18
  157. package/dist/validations/hasMimeType.js.map +0 -1
  158. package/dist/validations/hasSize.d.ts +0 -5
  159. package/dist/validations/hasSize.js +0 -13
  160. package/dist/validations/hasSize.js.map +0 -1
  161. package/dist/validations/index.d.ts +0 -12
  162. package/dist/validations/index.js +0 -13
  163. package/dist/validations/index.js.map +0 -1
  164. package/dist/validations/snowflake.js +0 -39
  165. package/dist/validations/snowflake.js.map +0 -1
  166. package/dist/validations/timestamp.js +0 -4
  167. package/dist/validations/timestamp.js.map +0 -1
  168. package/dist/validations/toBlob.d.ts +0 -4
  169. package/dist/validations/toBlob.js +0 -19
  170. package/dist/validations/toBlob.js.map +0 -1
  171. package/dist/validations/url.d.ts +0 -2
  172. package/dist/validations/url.js +0 -3
  173. package/dist/validations/url.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,416 @@
1
+ # @discordkit/core
2
+
3
+
4
+ ## 4.0.0
5
+ <sub>2026-06-04</sub>
6
+
7
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## Drop pre-built `*Safe` / `*Procedure` / `*Query` exports
8
+ Each `@discordkit/client` endpoint now exports only two symbols: the input `*Schema` and the raw Fetcher. The runtime-validated `*Safe` Proxy, the tRPC `*Procedure` builder, and the react-query `*Query` wrapper are no longer pre-wired per endpoint.
9
+ ### Migration
10
+ The helpers themselves still ship from `@discordkit/core` — call them yourself where you need them:
11
+ ```ts
12
+ // Before
13
+ import {
14
+ getGuildSafe,
15
+ getGuildProcedure,
16
+ getGuildQuery
17
+ } from "@discordkit/client";
18
+ // After
19
+ import { toValidated, toProcedure, toQuery } from "@discordkit/core";
20
+ import { getGuild, getGuildSchema } from "@discordkit/client";
21
+ import { guildSchema } from "@discordkit/client";
22
+ const getGuildSafe = toValidated(getGuild, getGuildSchema, guildSchema);
23
+ const getGuildProcedure = toProcedure(
24
+ `query`,
25
+ getGuild,
26
+ getGuildSchema,
27
+ guildSchema
28
+ );
29
+ const getGuildQuery = toQuery(getGuild);
30
+ ```
31
+ The new pattern keeps the integration logic visible at the consumer site, removes ~600 dead exports from the published surface, and lets you customize the wrapping (different schemas, different procedure types, layered middleware) without forking the library.
32
+ ### Also removed
33
+ - The `procedures.ts` barrel files (per-subdir and root) and their `allProcedures` / `<group>Procedures` namespace re-exports.
34
+ ### See also
35
+ - `README.md` for the updated integration examples.
36
+ - `examples/with-nextjs/src/app/api/trpc/[trpc]/trpc.ts` for a working tRPC router built on the new pattern.
37
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## Capability-aware `Fetcher<S, R, C>` and required per-call options
38
+ Every endpoint Fetcher now carries a capability marker that determines which per-call options it accepts. The two capabilities introduced in v4:
39
+ - `{ anonymous: true }` — endpoints whose Discord docs explicitly state "does not require authentication". Required at the call site; passing anything other than `true` is a type error.
40
+ - `{ auditLogReason: true }` — endpoints whose Discord docs explicitly state "supports the `X-Audit-Log-Reason` header". The call accepts an optional `{ reason: string }`.
41
+ The `Fetcher<S, R, C>` generic in `@discordkit/core` encodes these capabilities at the type level:
42
+ ```ts
43
+ type FetcherCapabilities = {
44
+ anonymous?: boolean; // endpoint MUST skip Authorization
45
+ auditLogReason?: boolean; // endpoint accepts X-Audit-Log-Reason
46
+ };
47
+ type Fetcher<S, R, C extends FetcherCapabilities = {}> = (
48
+ input: S,
49
+ options: RequestOptionsFor<C>
50
+ ) => Promise<R>;
51
+ ```
52
+ ### What changed for consumers
53
+ #### Anonymous endpoints (17 total)
54
+ These endpoints REQUIRE `{ anonymous: true }` as the second argument:
55
+ - **Webhook (9)**: `getWebhookWithToken`, `modifyWebhookWithToken`, `deleteWebhookWithToken`, `getWebhookMessage`, `editWebhookMessage`, `deleteWebhookMessage`, `executeWebhook`, `executeSlackCompatibleWebhook`, `executeGitHubCompatibleWebhook`
56
+ - **Interaction tokens (8)**: `createInteractionResponse`, `getOriginalInteractionResponse`, `editOriginalInteractionResponse`, `deleteOriginalInteractionResponse`, `createFollowupMessage`, `getFollowupMessage`, `editFollowupMessage`, `deleteFollowupMessage`
57
+ ```ts
58
+ // Before (v3.x)
59
+ await editWebhookMessage({ webhook, token, message, body });
60
+ // After (v4)
61
+ await editWebhookMessage(
62
+ { webhook, token, message, body },
63
+ { anonymous: true }
64
+ );
65
+ ```
66
+ #### Audit-log-reason endpoints (54 total)
67
+ These endpoints OPTIONALLY accept `{ reason: string }`:
68
+ ```ts
69
+ // Before (v3.x): no way to thread X-Audit-Log-Reason at the call site
70
+ await modifyGuildRole({ guild, role, body: { name: "Mod" } });
71
+ // After (v4)
72
+ await modifyGuildRole(
73
+ { guild, role, body: { name: "Mod" } },
74
+ { reason: "Promoted alice to moderator" }
75
+ );
76
+ ```
77
+ Affected folders: `auto-moderation`, `application-commands`, `channel`, `emoji`, `guild`, `guild-scheduled-event`, `invite`, `messages`, `permissions`, `sticker`, `template`, `webhook`.
78
+ ### Why
79
+ - The previous "second-argument boolean for anonymous, no support for audit-log reason" pattern was easy to forget and easy to misuse.
80
+ - A type-level capability marker surfaces the requirement at the call site instead of failing silently at runtime when Discord rejects the request.
81
+ - Wrappers like `toValidated`, `toProcedure`, and `toQuery` forward the capability through `Fetcher<S, R, C>` so the same guarantees hold post-composition.
82
+ ### Migration
83
+ For each call site, audit whether the endpoint is now capability-marked:
84
+ - Anonymous endpoints — add `{ anonymous: true }` as the second arg. TypeScript will flag every site you missed.
85
+ - Audit-log endpoints — no change required. Add `{ reason: "..." }` opportunistically wherever you've previously logged the cause-of-mutation elsewhere.
86
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## `multipart()` schema wrapper and `fileUpload` helper
87
+ `@discordkit/core` adds two new exports for endpoints that send `multipart/form-data` bodies (file uploads, sticker creation, attachment-bearing messages):
88
+ - `multipart(schema)` — wraps an object schema so the request layer serializes it as `FormData` instead of JSON. Files declared in the schema become parts; other fields become JSON-encoded form fields keyed as `payload_json` per Discord's REST conventions.
89
+ - `fileUpload(opts)` — a Valibot schema for File/Blob inputs with optional MIME-type and byte-size constraints, used inside `multipart()` schemas.
90
+ ```ts
91
+ import { fileUpload } from "@discordkit/core/validations/fileUpload";
92
+ const uploadSchema = multipart(
93
+ v.object({
94
+ avatar: fileUpload({
95
+ mimeTypes: [`image/png`, `image/jpeg`],
96
+ maxSize: 256_000
97
+ }),
98
+ nick: boundedString({ max: 32 })
99
+ })
100
+ );
101
+ ```
102
+ ### Endpoints migrated to `multipart()` in `@discordkit/client`
103
+ Every endpoint that previously hand-rolled FormData now uses `multipart()` + `fileUpload` from `@discordkit/core`:
104
+ - `createMessage`, `editMessage`, `executeWebhook`, `editWebhookMessage`, `editOriginalInteractionResponse`, `editFollowupMessage`, `createFollowupMessage`, `createInteractionResponse`
105
+ - `createGuildSticker`, `modifyCurrentMember`, `modifyCurrentUser`, `modifyGuild`
106
+ ### What changed for consumers
107
+ - The schemas exported by these endpoints now describe their **inputs** uniformly — no more separate `*Multipart` types vs. JSON-body types. The same `parse` / `safeParse` call validates both file and field shapes.
108
+ - `toValidated` automatically detects the multipart wrapper and validates uploads through the wrapped schema before the request goes out.
109
+ ### Migration
110
+ If you previously constructed `FormData` by hand and passed it to one of these endpoints, switch to the structured shape the schema expects:
111
+ ```ts
112
+ // Before
113
+ const formData = new FormData();
114
+ formData.append("file", file);
115
+ formData.append("payload_json", JSON.stringify({ content: "look at this" }));
116
+ await executeWebhook({ webhook, token, body: formData }, { anonymous: true });
117
+ // After
118
+ await executeWebhook(
119
+ { webhook, token, body: { file, content: "look at this" } },
120
+ { anonymous: true }
121
+ );
122
+ ```
123
+ The request layer handles FormData construction internally.
124
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## "Pattern B" schema typing — `schema<T>`, `partialSchema`, `pickFields`/`omitFields`/`requiredFields`, `variantSchema`
125
+ `@discordkit/core` adds six new helpers under `@discordkit/core/validations/schema` that change how `@discordkit/client` declares the types of its exported schemas. The goal: stop downstream `.d.ts` files from inlining the entire entries map of every schema they reference.
126
+ ### Why this exists
127
+ In v3.x, the type of every published schema was the full `v.ObjectSchema<{ id: v.GenericSchema<string>, ... }>` shape. Every consumer file that imported a schema re-inlined that entries map into its own emitted declarations. The result:
128
+ - Dramatic duplication of nested object shapes in `.d.ts` output
129
+ - Slow IDE hover (tsserver expands the full shape on every reference)
130
+ - Occasional TS2502 / "type too complex" errors on deeply circular schemas (Channel, Message, Interaction)
131
+ The fix: annotate the published type as `v.GenericSchema<T>` so downstream `.d.ts` references `T` by name instead of inlining it.
132
+ ### What's new
133
+ ```ts
134
+ import {
135
+ schema,
136
+ partialSchema,
137
+ pickFields,
138
+ omitFields,
139
+ requiredFields,
140
+ variantSchema
141
+ } from "@discordkit/core/validations/schema";
142
+ const _userSchema = v.object({
143
+ /* ... */
144
+ });
145
+ export interface User extends v.InferOutput<typeof _userSchema> {}
146
+ export const userSchema = schema<User>(_userSchema);
147
+ ```
148
+ - `schema<T>(s)` — type-erases the runtime schema to `v.GenericSchema<T>`. Runtime unchanged.
149
+ - `partialSchema<T>(s)`, `pickFields<T, K>(s, keys)`, `omitFields<T, K>(s, keys)`, `requiredFields<T, K>(s, keys)` — replacements for `v.partial` / `v.pick` / `v.omit` / `v.required` that accept type-erased `GenericSchema<T>` (which the raw Valibot functions reject because their constraint is `ObjectSchema<...>`).
150
+ - `variantSchema<T>(key, schemas)` — replacement for `v.variant` that accepts erased variants. Preferred over `v.union` for discriminated unions because it dispatches in O(1) by the discriminator field.
151
+ All six are annotated with `@__NO_SIDE_EFFECTS__` so tree-shakers can drop unused calls.
152
+ ### Trade-offs
153
+ After annotation, `v.partial(userSchema)`, `v.pick(userSchema, [...])`, and direct field-access patterns like `userSchema.entries.id` stop type-checking. Use the equivalent helpers above for the common cases.
154
+ ### `@discordkit/client` sweep
155
+ Every exported schema in `@discordkit/client` is now annotated through `schema<T>`. Discriminated unions (Component, ModerationAction, Channel, etc.) use `variantSchema` and dispatch on their discriminator field instead of trying each branch.
156
+ ### Migration
157
+ Most consumer code is unaffected — `getGuildSchema`, `guildSchema`, etc. still validate the same shapes at runtime. Only consumers that **manipulate the schema value** at the type level (e.g. via `v.partial`/`v.pick`/`schema.entries`) need the new helpers:
158
+ ```ts
159
+ // Before
160
+ const patchSchema = v.partial(modifyGuildSchema);
161
+ // After
162
+ import { partialSchema } from "@discordkit/core/validations/schema";
163
+ const patchSchema = partialSchema(modifyGuildSchema);
164
+ ```
165
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## Toolchain migration + consumer bundle size
166
+ Two changes that don't alter the public API but affect how `@discordkit/client` integrates into downstream projects.
167
+ ### Tree-shaking
168
+ - Every `@discordkit/core` and `@discordkit/client` export is annotated with `@__NO_SIDE_EFFECTS__` on its enclosing function and `"sideEffects": false` in each package.json.
169
+ - The 614 client source files that previously imported from the `@discordkit/core` package barrel have been migrated to deep submodule paths — `from "@discordkit/core/validations/snowflake"` instead of `from "@discordkit/core"`. The published `dist/*.mjs` carry these deep imports too, so consumer bundlers see exactly which submodules are needed.
170
+ - Combined effect: consumer bundles only pay for what they actually import. A consumer that uses one endpoint no longer pulls in all 200+.
171
+ ### Toolchain
172
+ The contributor toolchain switched from `ESLint + Prettier + Turbo + Changesets` to:
173
+ - **Vite+** (`vp`) — unified `vp check` (oxlint + oxfmt + tsc), `vp test` (vitest), `vp pack` (tsdown). A single `vite.config.ts` per workspace declares lint, format, test, and pack settings.
174
+ - **Bumpy** — per-PR `.bumpy/*.md` files instead of `.changeset/*.md`. Each PR adds one or more markdown files declaring the package bumps it triggers.
175
+ - **Per-package `tsconfig` removed** in favor of a single root `tsconfig.json`. The root adds `customConditions: ["development"]` so workspace imports resolve to `src/` during development without each package needing to build before its peers can typecheck.
176
+ - **Package exports gain a `development` condition** pointing at `src/`. Type-aware lint and `tsc` no longer require `dist/` to exist.
177
+ ### CI
178
+ - New `.github/workflows/ci.yml` matrix tests against Node `22`, `lts`, and `latest`.
179
+ - New `.github/workflows/bumpy-check.yml` verifies every PR adds a bump file.
180
+
181
+ ## 3.2.0
182
+
183
+ ### Minor Changes
184
+
185
+ - [#47](https://github.com/discordkit/discordkit/pull/47) [`1a9de57`](https://github.com/discordkit/discordkit/commit/1a9de5746861831bfc0c24c5237b98d9ae45ca6c) Thanks [@Saeris](https://github.com/Saeris)! - Add request queue process with automatic rate limit throttling
186
+
187
+ ## 3.1.0
188
+
189
+ ### Minor Changes
190
+
191
+ - [`357ff21`](https://github.com/discordkit/discordkit/commit/357ff21d9a3d7a7a3f9ef1be920720f8e34fa096) Thanks [@Saeris](https://github.com/Saeris)! - ## Reduce generated types complexity with new core schemas
192
+
193
+ This update is mainly internal refactoring. It introduces some new custom schemas to `@discordkit/core` that help to reduce overall type complexity in the generated types. This is accomplished by encapsulating common validation patterns into reusable schemas, which are then coerced to simple types which mask the complexity of their pipelines. As an end-user, this would make no difference in the runtime validation behavior, nor would it change the shape of the types you consume. However it does obfuscate the internal types of most schemas, which would make them a little more difficult to hook into and make modifications to.
194
+
195
+ ## 3.0.2
196
+
197
+ ### Patch Changes
198
+
199
+ - [#32](https://github.com/discordkit/discordkit/pull/32) [`c2574cd`](https://github.com/discordkit/discordkit/commit/c2574cd8c256d6122d17616e8ebf5eda608a62ac) Thanks [@Saeris](https://github.com/Saeris)! - ## Fix wildly complex type definitions
200
+
201
+ Turns out, if you use `import * as v from "valibot";` _instead of_ destructured imports (as Discordkit did previously), you get _way simpler_ type definitions back from `tsc`. Before, for example, `Message` was over 7.5k lines long (at best, before hand optimization it widened to `any`). Now after this refactor... it's down to _800 lines_! That's almost a 10x reduction just for changing up how you import things. Wild.
202
+
203
+ Could this have been solved by bundling instead? Maybe, who knows. Shipping Typescript be weird sometimes.
204
+
205
+ ## 3.0.1
206
+
207
+ ### Patch Changes
208
+
209
+ - [`01e8f20`](https://github.com/discordkit/discordkit/commit/01e8f2068a50a99db8f592694bf012a2a53a5fbf) Thanks [@Saeris](https://github.com/Saeris)! - Fix complex types generating as `any` during build
210
+
211
+ ## 3.0.0
212
+
213
+ ### Major Changes
214
+
215
+ - [#29](https://github.com/discordkit/discordkit/pull/29) [`e9d799a`](https://github.com/discordkit/discordkit/commit/e9d799a56d92031675c5db6102cdd35be3a1fe7a) Thanks [@Saeris](https://github.com/Saeris)! - # June 2025 Sync
216
+
217
+ Wow, has it already been more than 3 years since the first commit? Time sure flies! A lot has changed in Discord's API in the past couple of yers, and this new major version seeks to get things synced up to present! There are a lot of breaking changes with this release, some of them organizational, others to the schemas themselves in terms of either shape or expected field values. But the design goal of this update was to model Discord's API as accurately as possible and help prevent submitting malformed data. To support this, a bunch of new data types have been added and the tests have been made even more robust! Hopefully from now on, updates will be more incremental and on a more frequent cadence. Here's a wall of text summarizing the changes:
218
+
219
+ ## BREAKING CHANGES
220
+
221
+ ### new `bitfield` datatype
222
+
223
+ Added a new `bitfield` custom schema for validating integer and string values of serialized bitfields. Discord uses this datatype to encapsulate flags for various things such as Permissions.
224
+
225
+ The best way to validate bitfields involves coercing the serialized values to `BigInt`s, and as such there needs to be a way to re-serialize these values back to their expected representation within a given schema. To do this, `asDigits()` and `asInteger()` were added as transformation actions.
226
+
227
+ This also involved added a means by which to mock this new datatype, which is powered by `enum` representations of the possible flags and their semantic meanings. Because of how delicate this ended up being, the entire set of mocking utilities needed to be overhauled and new tests were added to `@discordkit/core` to catch edge cases.
228
+
229
+ ### new `datauri` datatype
230
+
231
+ Many of Discord's fields expect Data URI strings for images. A new `datauri` schema has been added to provide an extra layer of validation for these strings to guard against sending invalid data.
232
+
233
+ ### updates to numerous schemas
234
+
235
+ The addition of `bitfield` schemas came as a result of syncing Discordkit's schemas with the latest Discord API specification. As such, expect that the type signatures of nearly every schema will be affected by these changes.
236
+
237
+ ### schema reorganization
238
+
239
+ Discordkit's file and folder structure is designed to align closely with the organization of the official API docs. While most endpoints are grouped by their URL structure, there are some exceptions such as with Messages which have their own section separate from Channels (the URL path many of them belong to) and so for ease of maintenance these files have been relocated to reflect that.
240
+
241
+ Moving forward, additional things such as shared types may be moved into folders according to their location within the official documentation. This will apply to things such as Application Commands, Interactions, Message Components and Permissions / Roles.
242
+
243
+ ***
244
+
245
+ ## FEATURES
246
+
247
+ ### add new Voice endpoints
248
+
249
+ added the following 4 endpoints under the voice category:
250
+ - `getCurrentUserVoiceState`
251
+ - `getUserVoiceState`
252
+ - `modifyCurrentUserVoiceState`
253
+ - `modifyUserVoiceState`
254
+
255
+ ### add Poll schemas and endpoints
256
+
257
+ This adds support for Polls and their associated endpoints:
258
+ - `endPoll`
259
+ - `getAnswerVoters`
260
+
261
+ ### add SKU schemas and endpoint
262
+
263
+ Added new schemas for SKU objects and a new endpoint to list SKUs
264
+ - `listSKUs`
265
+
266
+ ### add Lobby schemas and endpoints
267
+
268
+ Includes for Lobby types and adds the following new endpoints:
269
+ - `addMemberToLobby`
270
+ - `createLobby`
271
+ - `deleteLobby`
272
+ - `getLobby`
273
+ - `leaveLobby`
274
+ - `linkChannelToLobby`
275
+ - `modifyLobby`
276
+ - `removeMemberFromLobby`
277
+ - `unlinkChannelFromLobby`
278
+
279
+ ### add Soundboard schemas and endpoints
280
+
281
+ Added schemas for Soundboard data types and the following endpoints:
282
+ - `createGuildSoundboardSound`
283
+ - `deleteGuildSoundboardSound`
284
+ - `getGuildSoundboardSound`
285
+ - `listDefaultSoundboardSounds`
286
+ - `listGuildSoundboardSounds`
287
+ - `modifyGuildSoundboardSound`
288
+ - `sendSoundboardSound`
289
+
290
+ ### add Subscription schemas and endpoints
291
+
292
+ Added schemas for Subscription data types and the following endpoints:
293
+ - `getSKUSubscription`
294
+ - `listSKUSubscriptions`
295
+
296
+ ### add Snowflake date utilities
297
+
298
+ Added two new utility functions: `snowflakeToDate()` and `dateToSnowflake()`, which can be used when working with Discord's `after` and `before` fields, which often expect ISO timestamps relative to a given object's snowflake ID.
299
+
300
+ ### add Avatar Decoration image utility
301
+
302
+ Added a new image URL utility to fetch Avatar Decorations
303
+
304
+ ### added `hasMimeType()` and `toBlob` schema actions
305
+
306
+ These Valibot schema actions aid with validating `datauri` strings to better ensure that fields are receiving well-formatted data from end-users.
307
+
308
+ `hasMimeType()` behaves similarly to Valibot's built-in `mimeType()` validation action, which only operates on Blobs. Without native support for Data URIs, this is necessary to ensure proper encoding of images.
309
+
310
+ `toBlob` is a transformation action that can transform a `datauri` to a Blob, which then can be used with any of Valibot's actions that operate on that data type, such as `maxSize()` to ensure that the provided value does not exceed a certain file size.
311
+
312
+ ### add Component types
313
+
314
+ Added schemas covering every Message Component type and updated the existing ones to match those in the API docs
315
+
316
+ ### update Interaction data types and endpoints
317
+
318
+ Interactions are now up to date with their specifications within the API docs
319
+
320
+ ### add new `hasSize()` validation action
321
+
322
+ Added a new `hasSize()` validation action which can be used with `datauri` schemas to validate approximately whether they are a given size or within a size range in terms of bytes
323
+
324
+ ### update Audit Log schemas and endpoint
325
+
326
+ Audit Logs have been reorganized and updated to reflect their current specification in the Discord API docs
327
+
328
+ ### update Auto Moderation schemas and endpoints
329
+
330
+ Reorganized to better reflect the organization of the API docs. All types and endpoints have been synced to their current specifications.
331
+
332
+ ### add Application Emoji endpoints
333
+
334
+ Applications have their own set of endpoints for Emojis and now they've been added!
335
+
336
+ ### add support for Scheduled Event Recurrence Rules
337
+
338
+ All of the types and endpoints for Scheduled Events have been updated to their latest specifications, including the addition of recurrence rules.
339
+
340
+ ### update Guild schemas and endpoints
341
+
342
+ Updated all Guild data types and endpoints to reflect the latest specifications. This added three new endpoints for Guilds:
343
+ - `buildGuildBan`
344
+ - `getGuildRole`
345
+ - `modifyGuildIncidentActions`
346
+
347
+ ### update Message schemas and endpoints
348
+
349
+ Updated all Message data types and endpoints to reflect their latest specifications.
350
+
351
+ ### update Stage, Sticker, and User schemas and endpoints
352
+
353
+ Updates all of the data types and endpoints for Stickers, Stages, and Users to reflect their latest specifications.
354
+
355
+ Adds a new endpoint for Stickers:
356
+ - `getStickerPacks`
357
+
358
+ ***
359
+
360
+ ## FIXES
361
+
362
+ ### properly handle Sticker gif urls
363
+
364
+ Stickers have an exception for retrieving them in a gif file format, which uses a different base url than the standard Discord CDN
365
+
366
+ ## 2.0.0
367
+
368
+ ### Major Changes
369
+
370
+ - [#12](https://github.com/discordkit/discordkit/pull/12) [`5562b2b`](https://github.com/discordkit/discordkit/commit/5562b2b367776e4e70f40be2297b19bea4206991) Thanks [@Saeris](https://github.com/Saeris)! - Migrate schemas from `zod` to `valibot`
371
+
372
+ This update represents a major refactor of both the core and client library codebases.
373
+
374
+ Since Valibot has now become stable, Discordkit is migrating away from `zod` in favor of `valibot` as it's schema library because of it's significantly lighter weight when bundling. This choice was made because Discordkit is designed to be used in a variety of environments such as edge functions, serverless runtimes, and directly on clients, all of which are places where every byte saved counts towards better performance. From the beginning, Discordkit was designed to be functional in nature, so that you'll only bundle what you import and consume, which is the shared ethos of Valibot.
375
+
376
+ Along with this change comes some significant refinements to every schema, so that it closer matches the behavior of Discord's API. Work on updating these schemas to match the v10 API one to one is ongoing, and as such some of the latest field updates may not yet be reflected in Discordkit. These will be patched in incrementally following this release.
377
+
378
+ ## 1.1.0-next.0
379
+
380
+ ### Minor Changes
381
+
382
+ - Replace `zod` with `valibot`
383
+
384
+ ## 1.0.3
385
+
386
+ ### Patch Changes
387
+
388
+ - [#9](https://github.com/discordkit/discordkit/pull/9) [`f973cc1`](https://github.com/discordkit/discordkit/commit/f973cc1b0b072d830d3e38fd291135bcd3f5c8c2) Thanks [@Saeris](https://github.com/Saeris)! - Added a new versioning script to workaround `@changeset/cli`'s inability to correctly run `yarn npm publish`, which accidentally leaves workspace protocol dependency versions unchanged and published to npm. Shoutout to https://github.com/PrairieLearn/PrairieLearn/pull/7533 for the fix.
389
+
390
+ ## 1.0.2
391
+
392
+ ### Patch Changes
393
+
394
+ - [#7](https://github.com/discordkit/discordkit/pull/7) [`2f4b55b`](https://github.com/discordkit/discordkit/commit/2f4b55b2d894e2295f8e6e2eb4fee9a97bbd0f6c) Thanks [@Saeris](https://github.com/Saeris)! - Actually fix missing build artifacts 😰
395
+
396
+ ## 1.0.1
397
+
398
+ ### Patch Changes
399
+
400
+ - [#5](https://github.com/discordkit/discordkit/pull/5) [`3be92aa`](https://github.com/discordkit/discordkit/commit/3be92aa51a2e533e05cdef5b8e1954307c3e1699) Thanks [@Saeris](https://github.com/Saeris)! - Add missing cjs build artifacts.
401
+
402
+ ## 1.0.0
403
+
404
+ ### Major Changes
405
+
406
+ - [#3](https://github.com/discordkit/discordkit/pull/3) [`e371616`](https://github.com/discordkit/discordkit/commit/e37161619e6ff02c0ac792c5727030f09207c22f) Thanks [@Saeris](https://github.com/Saeris)! - # v1.0.0
407
+
408
+ This marks the first major release of Discordkit! 🥳
409
+
410
+ Since the first few commits to Discordkit were made, this release includes out of the box support for [`tRPC``](https://trpc.io/) and [`react-query``](https://tanstack.com/query/latest) alongside isomorphic use in a JavaScript/TypeScript project with the bare request handlers.
411
+
412
+ Basic integration tests were added for every included API endpoint and all endpoints have had their schemas and doc comments updated to the latest v10 API specification.
413
+
414
+ Some initial usage documentation has been added and will be improved over the next several weeks. This will include some basic examples of usage alongside popular frameworks and libraries. Use cases are still being explored for this initial release, and so the immediate priority is ensuring that the supporting release infrastructure is in working order.
415
+
416
+ At this time there is _no support for file uploads_. Additionally, reason headers also cannot yet be set. Support for these will be added shortly.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ <div align="center">
2
+
3
+ ![Discordkit](https://raw.githubusercontent.com/discordkit/discordkit/main/static/logo-light.svg#gh-light-mode-only)
4
+ ![Discordkit](https://raw.githubusercontent.com/discordkit/discordkit/main/static/logo-dark.svg#gh-dark-mode-only)
5
+
6
+ [![npm version][npm_badge]][npm]
7
+ [![CI status][ci_badge]][ci]
8
+
9
+ Runtime helpers and shared validation primitives that power [`@discordkit/client`][client].
10
+
11
+ </div>
12
+
13
+ ---
14
+
15
+ ## 📦 Installation
16
+
17
+ `@discordkit/core` is installed automatically as a dependency of [`@discordkit/client`][client]. Install it directly when you want the composition helpers without the endpoint surface:
18
+
19
+ ```bash
20
+ npm install --save-dev @discordkit/core valibot
21
+ # or
22
+ yarn add -D @discordkit/core valibot
23
+ ```
24
+
25
+ ## What's inside
26
+
27
+ - **Composition helpers** — `toValidated`, `toProcedure`, `toQuery`. Wrap any Fetcher with runtime validation, build tRPC procedures, or produce react-query queryFns. Designed to be called at the consumer site rather than pre-wired per endpoint.
28
+ - **Session management** — `DiscordSession` and the default `discord` instance: token storage, base URL configuration, header construction, anonymous-request opt-out.
29
+ - **Request layer** — `get` / `post` / `patch` / `put` / `remove` / `multipart` low-level helpers + the `Fetcher<S, R, C>` capability-aware type used by every endpoint in `@discordkit/client`.
30
+ - **Validation primitives** — schema typing helpers (`schema<T>`, `partialSchema`, `pickFields`, `omitFields`, `requiredFields`, `variantSchema`), `boundedString`, `boundedInteger`, `snowflake`, `timestamp`, `datauri`, `fileUpload`, etc. Build your own schemas without re-deriving them.
31
+ - **`@__NO_SIDE_EFFECTS__` annotations and `sideEffects: false`** — every export is tree-shake-friendly. Consumer bundles only pay for what they actually import.
32
+
33
+ ## Usage
34
+
35
+ See the [`@discordkit/client` README][client] for the full usage walkthrough — every example there relies on `@discordkit/core` for the actual composition.
36
+
37
+ ## 📣 Acknowledgements
38
+
39
+ Endpoint documentation taken from Discord's [Official API docs][discord_api].
40
+
41
+ ## 🥂 License
42
+
43
+ Released under the [MIT license][license] © [Drake Costa][personal-website].
44
+
45
+ [npm_badge]: https://img.shields.io/npm/v/@discordkit/core.svg?style=flat
46
+ [npm]: https://www.npmjs.com/package/@discordkit/core
47
+ [ci_badge]: https://github.com/discordkit/discordkit/actions/workflows/ci.yml/badge.svg
48
+ [ci]: https://github.com/discordkit/discordkit/actions/workflows/ci.yml
49
+ [client]: https://www.npmjs.com/package/@discordkit/client
50
+ [discord_api]: https://discord.com/developers/docs
51
+ [license]: https://github.com/discordkit/discordkit/blob/main/LICENSE.md
52
+ [personal-website]: https://saeris.gg
@@ -0,0 +1,23 @@
1
+ import { discord, endpoint } from "./requests/DiscordSession.mjs";
2
+ import { buildURL } from "./requests/buildURL.mjs";
3
+ import { getAsset } from "./requests/getAsset.mjs";
4
+ import { Fetcher, FetcherCapabilities, RequestOptionsFor, get, patch, post, put, remove } from "./requests/methods.mjs";
5
+ import { toProcedure } from "./requests/toProcedure.mjs";
6
+ import { QueryFunction, toQuery } from "./requests/toQuery.mjs";
7
+ import { toValidated } from "./requests/toValidated.mjs";
8
+ import { verifyKey } from "./requests/verifyKey.mjs";
9
+ import { Flags, bitfield } from "./validations/bitfield.mjs";
10
+ import { asDigits } from "./validations/asDigits.mjs";
11
+ import { asInteger } from "./validations/asInteger.mjs";
12
+ import { boundedArray } from "./validations/boundedArray.mjs";
13
+ import { boundedInteger } from "./validations/boundedInteger.mjs";
14
+ import { boundedString } from "./validations/boundedString.mjs";
15
+ import { datauri, datauriRegex, extractDataURIMetadata, toBase64 } from "./validations/datauri.mjs";
16
+ import { FileUpload, MULTIPART_MARKER, collectFileUploads, fileUpload, isFileUpload, multipart, shouldSerializeAsMultipart, toMultipartBody } from "./validations/fileUpload.mjs";
17
+ import { hasMimeType } from "./validations/hasMimeType.mjs";
18
+ import { omitFields, partialSchema, pickFields, requiredFields, schema, variantSchema } from "./validations/schema.mjs";
19
+ import { toBlob } from "./validations/toBlob.mjs";
20
+ import { DISCORD_EPOCH, snowflake, snowflakeToDate } from "./validations/snowflake.mjs";
21
+ import { timestamp } from "./validations/timestamp.mjs";
22
+ import { url } from "./validations/url.mjs";
23
+ export { DISCORD_EPOCH, Fetcher, FetcherCapabilities, FileUpload, Flags, MULTIPART_MARKER, QueryFunction, RequestOptionsFor, asDigits, asInteger, bitfield, boundedArray, boundedInteger, boundedString, buildURL, collectFileUploads, datauri, datauriRegex, discord, endpoint, extractDataURIMetadata, fileUpload, get, getAsset, hasMimeType, isFileUpload, multipart, omitFields, partialSchema, patch, pickFields, post, put, remove, requiredFields, schema, shouldSerializeAsMultipart, snowflake, snowflakeToDate, timestamp, toBase64, toBlob, toMultipartBody, toProcedure, toQuery, toValidated, url, variantSchema, verifyKey };
package/dist/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ import { discord, endpoint } from "./requests/DiscordSession.mjs";
2
+ import { buildURL } from "./requests/buildURL.mjs";
3
+ import { getAsset } from "./requests/getAsset.mjs";
4
+ import { MULTIPART_MARKER, collectFileUploads, fileUpload, isFileUpload, multipart, shouldSerializeAsMultipart, toMultipartBody } from "./validations/fileUpload.mjs";
5
+ import { get, patch, post, put, remove } from "./requests/methods.mjs";
6
+ import { toProcedure } from "./requests/toProcedure.mjs";
7
+ import { toQuery } from "./requests/toQuery.mjs";
8
+ import { toValidated } from "./requests/toValidated.mjs";
9
+ import { verifyKey } from "./requests/verifyKey.mjs";
10
+ import { asDigits } from "./validations/asDigits.mjs";
11
+ import { asInteger } from "./validations/asInteger.mjs";
12
+ import { bitfield } from "./validations/bitfield.mjs";
13
+ import { boundedArray } from "./validations/boundedArray.mjs";
14
+ import { boundedInteger } from "./validations/boundedInteger.mjs";
15
+ import { boundedString } from "./validations/boundedString.mjs";
16
+ import { datauri, datauriRegex, extractDataURIMetadata, toBase64 } from "./validations/datauri.mjs";
17
+ import { hasMimeType } from "./validations/hasMimeType.mjs";
18
+ import { omitFields, partialSchema, pickFields, requiredFields, schema, variantSchema } from "./validations/schema.mjs";
19
+ import { toBlob } from "./validations/toBlob.mjs";
20
+ import { DISCORD_EPOCH, snowflake, snowflakeToDate } from "./validations/snowflake.mjs";
21
+ import { timestamp } from "./validations/timestamp.mjs";
22
+ import { url } from "./validations/url.mjs";
23
+ export { DISCORD_EPOCH, MULTIPART_MARKER, asDigits, asInteger, bitfield, boundedArray, boundedInteger, boundedString, buildURL, collectFileUploads, datauri, datauriRegex, discord, endpoint, extractDataURIMetadata, fileUpload, get, getAsset, hasMimeType, isFileUpload, multipart, omitFields, partialSchema, patch, pickFields, post, put, remove, requiredFields, schema, shouldSerializeAsMultipart, snowflake, snowflakeToDate, timestamp, toBase64, toBlob, toMultipartBody, toProcedure, toQuery, toValidated, url, variantSchema, verifyKey };
@@ -0,0 +1,30 @@
1
+ import { RequestOptions } from "./request.mjs";
2
+
3
+ //#region src/requests/DiscordSession.d.ts
4
+ declare const endpoint = "https://discord.com/api/v10/";
5
+ /** @internal */
6
+ declare class DiscordSession {
7
+ #private;
8
+ endpoint: string;
9
+ maxRetries: number;
10
+ get ready(): boolean;
11
+ constructor(authToken?: `${`Bot` | `Bearer`} ${string}` | null);
12
+ /**
13
+ * Clears the current session details, then attempts to set
14
+ * new session values
15
+ */
16
+ setToken: (token: `${`Bot` | `Bearer`} ${string}`) => this;
17
+ clearSession: () => this;
18
+ getSession: () => string;
19
+ /**
20
+ * Queue a request to be processed with rate limiting
21
+ */
22
+ queueRequest: (resource: URL, method: string, body?: string | FormData | null, options?: RequestOptions) => Promise<Response>;
23
+ /**
24
+ * Get current queue size (useful for monitoring)
25
+ */
26
+ getQueueSize: () => number;
27
+ }
28
+ declare const discord: DiscordSession;
29
+ //#endregion
30
+ export { DiscordSession, discord, endpoint };