@discordkit/core 3.2.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/CHANGELOG.md +423 -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 +72 -0
  6. package/dist/requests/DiscordSession.d.mts.map +1 -0
  7. package/dist/requests/DiscordSession.mjs +262 -0
  8. package/dist/requests/DiscordSession.mjs.map +1 -0
  9. package/dist/requests/addParams.d.mts +16 -0
  10. package/dist/requests/addParams.d.mts.map +1 -0
  11. package/dist/requests/addParams.mjs +26 -0
  12. package/dist/requests/addParams.mjs.map +1 -0
  13. package/dist/requests/buildURL.d.mts +8 -0
  14. package/dist/requests/buildURL.d.mts.map +1 -0
  15. package/dist/requests/buildURL.mjs +9 -0
  16. package/dist/requests/buildURL.mjs.map +1 -0
  17. package/dist/requests/getAsset.d.mts +8 -0
  18. package/dist/requests/getAsset.d.mts.map +1 -0
  19. package/dist/requests/getAsset.mjs +8 -0
  20. package/dist/requests/getAsset.mjs.map +1 -0
  21. package/dist/requests/index.d.mts +9 -0
  22. package/dist/requests/index.mjs +9 -0
  23. package/dist/requests/methods.d.mts +64 -0
  24. package/dist/requests/methods.d.mts.map +1 -0
  25. package/dist/requests/methods.mjs +12 -0
  26. package/dist/requests/methods.mjs.map +1 -0
  27. package/dist/requests/request.d.mts +28 -0
  28. package/dist/requests/request.d.mts.map +1 -0
  29. package/dist/requests/request.mjs +31 -0
  30. package/dist/requests/request.mjs.map +1 -0
  31. package/dist/requests/toProcedure.d.mts +41 -0
  32. package/dist/requests/toProcedure.d.mts.map +1 -0
  33. package/dist/requests/toProcedure.mjs +29 -0
  34. package/dist/requests/toProcedure.mjs.map +1 -0
  35. package/dist/requests/toQuery.d.mts +37 -0
  36. package/dist/requests/toQuery.d.mts.map +1 -0
  37. package/dist/requests/toQuery.mjs +10 -0
  38. package/dist/requests/toQuery.mjs.map +1 -0
  39. package/dist/requests/toValidated.d.mts +17 -0
  40. package/dist/requests/toValidated.d.mts.map +1 -0
  41. package/dist/requests/toValidated.mjs +27 -0
  42. package/dist/requests/toValidated.mjs.map +1 -0
  43. package/dist/requests/{verifyKey.d.ts → verifyKey.d.mts} +5 -1
  44. package/dist/requests/verifyKey.d.mts.map +1 -0
  45. package/dist/requests/verifyKey.mjs +64 -0
  46. package/dist/requests/verifyKey.mjs.map +1 -0
  47. package/dist/utils/isBetween.d.mts +5 -0
  48. package/dist/utils/isBetween.d.mts.map +1 -0
  49. package/dist/utils/isBetween.mjs +6 -0
  50. package/dist/utils/isBetween.mjs.map +1 -0
  51. package/dist/utils/{isNonNullable.js → isNonNullable.d.mts} +6 -2
  52. package/dist/utils/isNonNullable.d.mts.map +1 -0
  53. package/dist/utils/isNonNullable.mjs +24 -0
  54. package/dist/utils/isNonNullable.mjs.map +1 -0
  55. package/dist/utils/isNumericString.d.mts +5 -0
  56. package/dist/utils/isNumericString.d.mts.map +1 -0
  57. package/dist/utils/isNumericString.mjs +6 -0
  58. package/dist/utils/isNumericString.mjs.map +1 -0
  59. package/dist/utils/isObject.d.mts +5 -0
  60. package/dist/utils/isObject.d.mts.map +1 -0
  61. package/dist/utils/isObject.mjs +6 -0
  62. package/dist/utils/isObject.mjs.map +1 -0
  63. package/dist/utils/sleep.d.mts +8 -0
  64. package/dist/utils/sleep.d.mts.map +1 -0
  65. package/dist/utils/sleep.mjs +9 -0
  66. package/dist/utils/sleep.mjs.map +1 -0
  67. package/dist/utils/toCamelCase.d.mts +5 -0
  68. package/dist/utils/toCamelCase.d.mts.map +1 -0
  69. package/dist/utils/toCamelCase.mjs +6 -0
  70. package/dist/utils/toCamelCase.mjs.map +1 -0
  71. package/dist/utils/toCamelKeys.d.mts +20 -0
  72. package/dist/utils/toCamelKeys.d.mts.map +1 -0
  73. package/dist/utils/toCamelKeys.mjs +15 -0
  74. package/dist/utils/toCamelKeys.mjs.map +1 -0
  75. package/dist/utils/toSnakeCase.d.mts +5 -0
  76. package/dist/utils/toSnakeCase.d.mts.map +1 -0
  77. package/dist/utils/toSnakeCase.mjs +6 -0
  78. package/dist/utils/toSnakeCase.mjs.map +1 -0
  79. package/dist/utils/toSnakeKeys.d.mts +24 -0
  80. package/dist/utils/toSnakeKeys.d.mts.map +1 -0
  81. package/dist/utils/toSnakeKeys.mjs +15 -0
  82. package/dist/utils/toSnakeKeys.mjs.map +1 -0
  83. package/dist/validations/asDigits.d.mts +13 -0
  84. package/dist/validations/asDigits.d.mts.map +1 -0
  85. package/dist/validations/asDigits.mjs +12 -0
  86. package/dist/validations/asDigits.mjs.map +1 -0
  87. package/dist/validations/asInteger.d.mts +13 -0
  88. package/dist/validations/asInteger.d.mts.map +1 -0
  89. package/dist/validations/asInteger.mjs +12 -0
  90. package/dist/validations/asInteger.mjs.map +1 -0
  91. package/dist/validations/bitfield.d.mts +24 -0
  92. package/dist/validations/bitfield.d.mts.map +1 -0
  93. package/dist/validations/bitfield.mjs +22 -0
  94. package/dist/validations/bitfield.mjs.map +1 -0
  95. package/dist/validations/boundedArray.d.mts +14 -0
  96. package/dist/validations/boundedArray.d.mts.map +1 -0
  97. package/dist/validations/boundedArray.mjs +11 -0
  98. package/dist/validations/boundedArray.mjs.map +1 -0
  99. package/dist/validations/boundedInteger.d.mts +14 -0
  100. package/dist/validations/boundedInteger.d.mts.map +1 -0
  101. package/dist/validations/boundedInteger.mjs +11 -0
  102. package/dist/validations/boundedInteger.mjs.map +1 -0
  103. package/dist/validations/boundedString.d.mts +15 -0
  104. package/dist/validations/boundedString.d.mts.map +1 -0
  105. package/dist/validations/boundedString.mjs +12 -0
  106. package/dist/validations/boundedString.mjs.map +1 -0
  107. package/dist/validations/datauri.d.mts +25 -0
  108. package/dist/validations/datauri.d.mts.map +1 -0
  109. package/dist/validations/datauri.mjs +19 -0
  110. package/dist/validations/datauri.mjs.map +1 -0
  111. package/dist/validations/fileUpload.d.mts +130 -0
  112. package/dist/validations/fileUpload.d.mts.map +1 -0
  113. package/dist/validations/fileUpload.mjs +116 -0
  114. package/dist/validations/fileUpload.mjs.map +1 -0
  115. package/dist/validations/hasMimeType.d.mts +17 -0
  116. package/dist/validations/hasMimeType.d.mts.map +1 -0
  117. package/dist/validations/hasMimeType.mjs +18 -0
  118. package/dist/validations/hasMimeType.mjs.map +1 -0
  119. package/dist/validations/hasSize.d.mts +11 -0
  120. package/dist/validations/hasSize.d.mts.map +1 -0
  121. package/dist/validations/hasSize.mjs +14 -0
  122. package/dist/validations/hasSize.mjs.map +1 -0
  123. package/dist/validations/index.d.mts +15 -0
  124. package/dist/validations/index.mjs +15 -0
  125. package/dist/validations/schema.d.mts +103 -0
  126. package/dist/validations/schema.d.mts.map +1 -0
  127. package/dist/validations/schema.mjs +111 -0
  128. package/dist/validations/schema.mjs.map +1 -0
  129. package/dist/validations/{snowflake.d.ts → snowflake.d.mts} +10 -7
  130. package/dist/validations/snowflake.d.mts.map +1 -0
  131. package/dist/validations/snowflake.mjs +30 -0
  132. package/dist/validations/snowflake.mjs.map +1 -0
  133. package/dist/validations/timestamp.d.mts +8 -0
  134. package/dist/validations/timestamp.d.mts.map +1 -0
  135. package/dist/validations/timestamp.mjs +8 -0
  136. package/dist/validations/timestamp.mjs.map +1 -0
  137. package/dist/validations/toBlob.d.mts +8 -0
  138. package/dist/validations/toBlob.d.mts.map +1 -0
  139. package/dist/validations/toBlob.mjs +19 -0
  140. package/dist/validations/toBlob.mjs.map +1 -0
  141. package/dist/validations/url.d.mts +7 -0
  142. package/dist/validations/url.d.mts.map +1 -0
  143. package/dist/validations/url.mjs +7 -0
  144. package/dist/validations/url.mjs.map +1 -0
  145. package/package.json +10 -23
  146. package/dist/index.d.ts +0 -2
  147. package/dist/index.js +0 -3
  148. package/dist/index.js.map +0 -1
  149. package/dist/requests/DiscordSession.d.ts +0 -25
  150. package/dist/requests/DiscordSession.js +0 -255
  151. package/dist/requests/DiscordSession.js.map +0 -1
  152. package/dist/requests/addParams.d.ts +0 -2
  153. package/dist/requests/addParams.js +0 -11
  154. package/dist/requests/addParams.js.map +0 -1
  155. package/dist/requests/buildURL.d.ts +0 -2
  156. package/dist/requests/buildURL.js +0 -4
  157. package/dist/requests/buildURL.js.map +0 -1
  158. package/dist/requests/getAsset.d.ts +0 -2
  159. package/dist/requests/getAsset.js +0 -3
  160. package/dist/requests/getAsset.js.map +0 -1
  161. package/dist/requests/index.d.ts +0 -8
  162. package/dist/requests/index.js +0 -9
  163. package/dist/requests/index.js.map +0 -1
  164. package/dist/requests/methods.d.ts +0 -13
  165. package/dist/requests/methods.js +0 -8
  166. package/dist/requests/methods.js.map +0 -1
  167. package/dist/requests/request.d.ts +0 -2
  168. package/dist/requests/request.js +0 -30
  169. package/dist/requests/request.js.map +0 -1
  170. package/dist/requests/toProcedure.d.ts +0 -31
  171. package/dist/requests/toProcedure.js +0 -36
  172. package/dist/requests/toProcedure.js.map +0 -1
  173. package/dist/requests/toQuery.d.ts +0 -28
  174. package/dist/requests/toQuery.js +0 -9
  175. package/dist/requests/toQuery.js.map +0 -1
  176. package/dist/requests/toValidated.d.ts +0 -13
  177. package/dist/requests/toValidated.js +0 -29
  178. package/dist/requests/toValidated.js.map +0 -1
  179. package/dist/requests/verifyKey.js +0 -91
  180. package/dist/requests/verifyKey.js.map +0 -1
  181. package/dist/utils/isBetween.d.ts +0 -1
  182. package/dist/utils/isBetween.js +0 -2
  183. package/dist/utils/isBetween.js.map +0 -1
  184. package/dist/utils/isNonNullable.d.ts +0 -20
  185. package/dist/utils/isNonNullable.js.map +0 -1
  186. package/dist/utils/isNumericString.d.ts +0 -1
  187. package/dist/utils/isNumericString.js +0 -2
  188. package/dist/utils/isNumericString.js.map +0 -1
  189. package/dist/utils/isObject.d.ts +0 -1
  190. package/dist/utils/isObject.js +0 -2
  191. package/dist/utils/isObject.js.map +0 -1
  192. package/dist/utils/sleep.d.ts +0 -4
  193. package/dist/utils/sleep.js +0 -5
  194. package/dist/utils/sleep.js.map +0 -1
  195. package/dist/utils/toCamelCase.d.ts +0 -1
  196. package/dist/utils/toCamelCase.js +0 -2
  197. package/dist/utils/toCamelCase.js.map +0 -1
  198. package/dist/utils/toCamelKeys.d.ts +0 -2
  199. package/dist/utils/toCamelKeys.js +0 -16
  200. package/dist/utils/toCamelKeys.js.map +0 -1
  201. package/dist/utils/toSnakeCase.d.ts +0 -1
  202. package/dist/utils/toSnakeCase.js +0 -4
  203. package/dist/utils/toSnakeCase.js.map +0 -1
  204. package/dist/utils/toSnakeKeys.d.ts +0 -2
  205. package/dist/utils/toSnakeKeys.js +0 -16
  206. package/dist/utils/toSnakeKeys.js.map +0 -1
  207. package/dist/validations/asDigits.d.ts +0 -6
  208. package/dist/validations/asDigits.js +0 -6
  209. package/dist/validations/asDigits.js.map +0 -1
  210. package/dist/validations/asInteger.d.ts +0 -6
  211. package/dist/validations/asInteger.js +0 -6
  212. package/dist/validations/asInteger.js.map +0 -1
  213. package/dist/validations/bitfield.d.ts +0 -17
  214. package/dist/validations/bitfield.js +0 -37
  215. package/dist/validations/bitfield.js.map +0 -1
  216. package/dist/validations/boundedArray.d.ts +0 -6
  217. package/dist/validations/boundedArray.js +0 -8
  218. package/dist/validations/boundedArray.js.map +0 -1
  219. package/dist/validations/boundedInteger.d.ts +0 -6
  220. package/dist/validations/boundedInteger.js +0 -8
  221. package/dist/validations/boundedInteger.js.map +0 -1
  222. package/dist/validations/boundedString.d.ts +0 -6
  223. package/dist/validations/boundedString.js +0 -8
  224. package/dist/validations/boundedString.js.map +0 -1
  225. package/dist/validations/datauri.d.ts +0 -20
  226. package/dist/validations/datauri.js +0 -20
  227. package/dist/validations/datauri.js.map +0 -1
  228. package/dist/validations/hasMimeType.d.ts +0 -10
  229. package/dist/validations/hasMimeType.js +0 -18
  230. package/dist/validations/hasMimeType.js.map +0 -1
  231. package/dist/validations/hasSize.d.ts +0 -5
  232. package/dist/validations/hasSize.js +0 -13
  233. package/dist/validations/hasSize.js.map +0 -1
  234. package/dist/validations/index.d.ts +0 -12
  235. package/dist/validations/index.js +0 -13
  236. package/dist/validations/index.js.map +0 -1
  237. package/dist/validations/snowflake.js +0 -39
  238. package/dist/validations/snowflake.js.map +0 -1
  239. package/dist/validations/timestamp.d.ts +0 -3
  240. package/dist/validations/timestamp.js +0 -4
  241. package/dist/validations/timestamp.js.map +0 -1
  242. package/dist/validations/toBlob.d.ts +0 -4
  243. package/dist/validations/toBlob.js +0 -19
  244. package/dist/validations/toBlob.js.map +0 -1
  245. package/dist/validations/url.d.ts +0 -2
  246. package/dist/validations/url.js +0 -3
  247. package/dist/validations/url.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,423 @@
1
+ # @discordkit/core
2
+
3
+
4
+
5
+ ## 4.0.1
6
+ <sub>2026-06-22</sub>
7
+
8
+ - [#60](https://github.com/discordkit/discordkit/pull/60) *(patch)* Thanks [@Saeris](https://github.com/Saeris)!
9
+ Dropped the `type-fest` dependency. `toCamelKeys`/`toSnakeKeys` now use local `CamelKeys`/`SnakeKeys` types instead of type-fest's `CamelCasedPropertiesDeep`/`SnakeCasedPropertiesDeep` — behaviorally identical for the underscore-delimited Discord API keys these convert, with one fewer runtime dependency.
10
+
11
+ ## 4.0.0
12
+ <sub>2026-06-04</sub>
13
+
14
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## Drop pre-built `*Safe` / `*Procedure` / `*Query` exports
15
+ 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.
16
+ ### Migration
17
+ The helpers themselves still ship from `@discordkit/core` — call them yourself where you need them:
18
+ ```ts
19
+ // Before
20
+ import {
21
+ getGuildSafe,
22
+ getGuildProcedure,
23
+ getGuildQuery
24
+ } from "@discordkit/client";
25
+ // After
26
+ import { toValidated, toProcedure, toQuery } from "@discordkit/core";
27
+ import { getGuild, getGuildSchema } from "@discordkit/client";
28
+ import { guildSchema } from "@discordkit/client";
29
+ const getGuildSafe = toValidated(getGuild, getGuildSchema, guildSchema);
30
+ const getGuildProcedure = toProcedure(
31
+ `query`,
32
+ getGuild,
33
+ getGuildSchema,
34
+ guildSchema
35
+ );
36
+ const getGuildQuery = toQuery(getGuild);
37
+ ```
38
+ 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.
39
+ ### Also removed
40
+ - The `procedures.ts` barrel files (per-subdir and root) and their `allProcedures` / `<group>Procedures` namespace re-exports.
41
+ ### See also
42
+ - `README.md` for the updated integration examples.
43
+ - `examples/with-nextjs/src/app/api/trpc/[trpc]/trpc.ts` for a working tRPC router built on the new pattern.
44
+ - [#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
45
+ Every endpoint Fetcher now carries a capability marker that determines which per-call options it accepts. The two capabilities introduced in v4:
46
+ - `{ 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.
47
+ - `{ auditLogReason: true }` — endpoints whose Discord docs explicitly state "supports the `X-Audit-Log-Reason` header". The call accepts an optional `{ reason: string }`.
48
+ The `Fetcher<S, R, C>` generic in `@discordkit/core` encodes these capabilities at the type level:
49
+ ```ts
50
+ type FetcherCapabilities = {
51
+ anonymous?: boolean; // endpoint MUST skip Authorization
52
+ auditLogReason?: boolean; // endpoint accepts X-Audit-Log-Reason
53
+ };
54
+ type Fetcher<S, R, C extends FetcherCapabilities = {}> = (
55
+ input: S,
56
+ options: RequestOptionsFor<C>
57
+ ) => Promise<R>;
58
+ ```
59
+ ### What changed for consumers
60
+ #### Anonymous endpoints (17 total)
61
+ These endpoints REQUIRE `{ anonymous: true }` as the second argument:
62
+ - **Webhook (9)**: `getWebhookWithToken`, `modifyWebhookWithToken`, `deleteWebhookWithToken`, `getWebhookMessage`, `editWebhookMessage`, `deleteWebhookMessage`, `executeWebhook`, `executeSlackCompatibleWebhook`, `executeGitHubCompatibleWebhook`
63
+ - **Interaction tokens (8)**: `createInteractionResponse`, `getOriginalInteractionResponse`, `editOriginalInteractionResponse`, `deleteOriginalInteractionResponse`, `createFollowupMessage`, `getFollowupMessage`, `editFollowupMessage`, `deleteFollowupMessage`
64
+ ```ts
65
+ // Before (v3.x)
66
+ await editWebhookMessage({ webhook, token, message, body });
67
+ // After (v4)
68
+ await editWebhookMessage(
69
+ { webhook, token, message, body },
70
+ { anonymous: true }
71
+ );
72
+ ```
73
+ #### Audit-log-reason endpoints (54 total)
74
+ These endpoints OPTIONALLY accept `{ reason: string }`:
75
+ ```ts
76
+ // Before (v3.x): no way to thread X-Audit-Log-Reason at the call site
77
+ await modifyGuildRole({ guild, role, body: { name: "Mod" } });
78
+ // After (v4)
79
+ await modifyGuildRole(
80
+ { guild, role, body: { name: "Mod" } },
81
+ { reason: "Promoted alice to moderator" }
82
+ );
83
+ ```
84
+ Affected folders: `auto-moderation`, `application-commands`, `channel`, `emoji`, `guild`, `guild-scheduled-event`, `invite`, `messages`, `permissions`, `sticker`, `template`, `webhook`.
85
+ ### Why
86
+ - The previous "second-argument boolean for anonymous, no support for audit-log reason" pattern was easy to forget and easy to misuse.
87
+ - A type-level capability marker surfaces the requirement at the call site instead of failing silently at runtime when Discord rejects the request.
88
+ - Wrappers like `toValidated`, `toProcedure`, and `toQuery` forward the capability through `Fetcher<S, R, C>` so the same guarantees hold post-composition.
89
+ ### Migration
90
+ For each call site, audit whether the endpoint is now capability-marked:
91
+ - Anonymous endpoints — add `{ anonymous: true }` as the second arg. TypeScript will flag every site you missed.
92
+ - Audit-log endpoints — no change required. Add `{ reason: "..." }` opportunistically wherever you've previously logged the cause-of-mutation elsewhere.
93
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## `multipart()` schema wrapper and `fileUpload` helper
94
+ `@discordkit/core` adds two new exports for endpoints that send `multipart/form-data` bodies (file uploads, sticker creation, attachment-bearing messages):
95
+ - `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.
96
+ - `fileUpload(opts)` — a Valibot schema for File/Blob inputs with optional MIME-type and byte-size constraints, used inside `multipart()` schemas.
97
+ ```ts
98
+ import { fileUpload } from "@discordkit/core/validations/fileUpload";
99
+ const uploadSchema = multipart(
100
+ v.object({
101
+ avatar: fileUpload({
102
+ mimeTypes: [`image/png`, `image/jpeg`],
103
+ maxSize: 256_000
104
+ }),
105
+ nick: boundedString({ max: 32 })
106
+ })
107
+ );
108
+ ```
109
+ ### Endpoints migrated to `multipart()` in `@discordkit/client`
110
+ Every endpoint that previously hand-rolled FormData now uses `multipart()` + `fileUpload` from `@discordkit/core`:
111
+ - `createMessage`, `editMessage`, `executeWebhook`, `editWebhookMessage`, `editOriginalInteractionResponse`, `editFollowupMessage`, `createFollowupMessage`, `createInteractionResponse`
112
+ - `createGuildSticker`, `modifyCurrentMember`, `modifyCurrentUser`, `modifyGuild`
113
+ ### What changed for consumers
114
+ - 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.
115
+ - `toValidated` automatically detects the multipart wrapper and validates uploads through the wrapped schema before the request goes out.
116
+ ### Migration
117
+ If you previously constructed `FormData` by hand and passed it to one of these endpoints, switch to the structured shape the schema expects:
118
+ ```ts
119
+ // Before
120
+ const formData = new FormData();
121
+ formData.append("file", file);
122
+ formData.append("payload_json", JSON.stringify({ content: "look at this" }));
123
+ await executeWebhook({ webhook, token, body: formData }, { anonymous: true });
124
+ // After
125
+ await executeWebhook(
126
+ { webhook, token, body: { file, content: "look at this" } },
127
+ { anonymous: true }
128
+ );
129
+ ```
130
+ The request layer handles FormData construction internally.
131
+ - [#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`
132
+ `@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.
133
+ ### Why this exists
134
+ 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:
135
+ - Dramatic duplication of nested object shapes in `.d.ts` output
136
+ - Slow IDE hover (tsserver expands the full shape on every reference)
137
+ - Occasional TS2502 / "type too complex" errors on deeply circular schemas (Channel, Message, Interaction)
138
+ The fix: annotate the published type as `v.GenericSchema<T>` so downstream `.d.ts` references `T` by name instead of inlining it.
139
+ ### What's new
140
+ ```ts
141
+ import {
142
+ schema,
143
+ partialSchema,
144
+ pickFields,
145
+ omitFields,
146
+ requiredFields,
147
+ variantSchema
148
+ } from "@discordkit/core/validations/schema";
149
+ const _userSchema = v.object({
150
+ /* ... */
151
+ });
152
+ export interface User extends v.InferOutput<typeof _userSchema> {}
153
+ export const userSchema = schema<User>(_userSchema);
154
+ ```
155
+ - `schema<T>(s)` — type-erases the runtime schema to `v.GenericSchema<T>`. Runtime unchanged.
156
+ - `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<...>`).
157
+ - `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.
158
+ All six are annotated with `@__NO_SIDE_EFFECTS__` so tree-shakers can drop unused calls.
159
+ ### Trade-offs
160
+ 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.
161
+ ### `@discordkit/client` sweep
162
+ 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.
163
+ ### Migration
164
+ 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:
165
+ ```ts
166
+ // Before
167
+ const patchSchema = v.partial(modifyGuildSchema);
168
+ // After
169
+ import { partialSchema } from "@discordkit/core/validations/schema";
170
+ const patchSchema = partialSchema(modifyGuildSchema);
171
+ ```
172
+ - [#50](https://github.com/discordkit/discordkit/pull/50) *(major)* Thanks [@Saeris](https://github.com/Saeris)! - ## Toolchain migration + consumer bundle size
173
+ Two changes that don't alter the public API but affect how `@discordkit/client` integrates into downstream projects.
174
+ ### Tree-shaking
175
+ - Every `@discordkit/core` and `@discordkit/client` export is annotated with `@__NO_SIDE_EFFECTS__` on its enclosing function and `"sideEffects": false` in each package.json.
176
+ - 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.
177
+ - Combined effect: consumer bundles only pay for what they actually import. A consumer that uses one endpoint no longer pulls in all 200+.
178
+ ### Toolchain
179
+ The contributor toolchain switched from `ESLint + Prettier + Turbo + Changesets` to:
180
+ - **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.
181
+ - **Bumpy** — per-PR `.bumpy/*.md` files instead of `.changeset/*.md`. Each PR adds one or more markdown files declaring the package bumps it triggers.
182
+ - **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.
183
+ - **Package exports gain a `development` condition** pointing at `src/`. Type-aware lint and `tsc` no longer require `dist/` to exist.
184
+ ### CI
185
+ - New `.github/workflows/ci.yml` matrix tests against Node `22`, `lts`, and `latest`.
186
+ - New `.github/workflows/bumpy-check.yml` verifies every PR adds a bump file.
187
+
188
+ ## 3.2.0
189
+
190
+ ### Minor Changes
191
+
192
+ - [#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
193
+
194
+ ## 3.1.0
195
+
196
+ ### Minor Changes
197
+
198
+ - [`357ff21`](https://github.com/discordkit/discordkit/commit/357ff21d9a3d7a7a3f9ef1be920720f8e34fa096) Thanks [@Saeris](https://github.com/Saeris)! - ## Reduce generated types complexity with new core schemas
199
+
200
+ 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.
201
+
202
+ ## 3.0.2
203
+
204
+ ### Patch Changes
205
+
206
+ - [#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
207
+
208
+ 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.
209
+
210
+ Could this have been solved by bundling instead? Maybe, who knows. Shipping Typescript be weird sometimes.
211
+
212
+ ## 3.0.1
213
+
214
+ ### Patch Changes
215
+
216
+ - [`01e8f20`](https://github.com/discordkit/discordkit/commit/01e8f2068a50a99db8f592694bf012a2a53a5fbf) Thanks [@Saeris](https://github.com/Saeris)! - Fix complex types generating as `any` during build
217
+
218
+ ## 3.0.0
219
+
220
+ ### Major Changes
221
+
222
+ - [#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
223
+
224
+ 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:
225
+
226
+ ## BREAKING CHANGES
227
+
228
+ ### new `bitfield` datatype
229
+
230
+ 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.
231
+
232
+ 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.
233
+
234
+ 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.
235
+
236
+ ### new `datauri` datatype
237
+
238
+ 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.
239
+
240
+ ### updates to numerous schemas
241
+
242
+ 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.
243
+
244
+ ### schema reorganization
245
+
246
+ 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.
247
+
248
+ 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.
249
+
250
+ ***
251
+
252
+ ## FEATURES
253
+
254
+ ### add new Voice endpoints
255
+
256
+ added the following 4 endpoints under the voice category:
257
+ - `getCurrentUserVoiceState`
258
+ - `getUserVoiceState`
259
+ - `modifyCurrentUserVoiceState`
260
+ - `modifyUserVoiceState`
261
+
262
+ ### add Poll schemas and endpoints
263
+
264
+ This adds support for Polls and their associated endpoints:
265
+ - `endPoll`
266
+ - `getAnswerVoters`
267
+
268
+ ### add SKU schemas and endpoint
269
+
270
+ Added new schemas for SKU objects and a new endpoint to list SKUs
271
+ - `listSKUs`
272
+
273
+ ### add Lobby schemas and endpoints
274
+
275
+ Includes for Lobby types and adds the following new endpoints:
276
+ - `addMemberToLobby`
277
+ - `createLobby`
278
+ - `deleteLobby`
279
+ - `getLobby`
280
+ - `leaveLobby`
281
+ - `linkChannelToLobby`
282
+ - `modifyLobby`
283
+ - `removeMemberFromLobby`
284
+ - `unlinkChannelFromLobby`
285
+
286
+ ### add Soundboard schemas and endpoints
287
+
288
+ Added schemas for Soundboard data types and the following endpoints:
289
+ - `createGuildSoundboardSound`
290
+ - `deleteGuildSoundboardSound`
291
+ - `getGuildSoundboardSound`
292
+ - `listDefaultSoundboardSounds`
293
+ - `listGuildSoundboardSounds`
294
+ - `modifyGuildSoundboardSound`
295
+ - `sendSoundboardSound`
296
+
297
+ ### add Subscription schemas and endpoints
298
+
299
+ Added schemas for Subscription data types and the following endpoints:
300
+ - `getSKUSubscription`
301
+ - `listSKUSubscriptions`
302
+
303
+ ### add Snowflake date utilities
304
+
305
+ 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.
306
+
307
+ ### add Avatar Decoration image utility
308
+
309
+ Added a new image URL utility to fetch Avatar Decorations
310
+
311
+ ### added `hasMimeType()` and `toBlob` schema actions
312
+
313
+ These Valibot schema actions aid with validating `datauri` strings to better ensure that fields are receiving well-formatted data from end-users.
314
+
315
+ `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.
316
+
317
+ `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.
318
+
319
+ ### add Component types
320
+
321
+ Added schemas covering every Message Component type and updated the existing ones to match those in the API docs
322
+
323
+ ### update Interaction data types and endpoints
324
+
325
+ Interactions are now up to date with their specifications within the API docs
326
+
327
+ ### add new `hasSize()` validation action
328
+
329
+ 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
330
+
331
+ ### update Audit Log schemas and endpoint
332
+
333
+ Audit Logs have been reorganized and updated to reflect their current specification in the Discord API docs
334
+
335
+ ### update Auto Moderation schemas and endpoints
336
+
337
+ Reorganized to better reflect the organization of the API docs. All types and endpoints have been synced to their current specifications.
338
+
339
+ ### add Application Emoji endpoints
340
+
341
+ Applications have their own set of endpoints for Emojis and now they've been added!
342
+
343
+ ### add support for Scheduled Event Recurrence Rules
344
+
345
+ All of the types and endpoints for Scheduled Events have been updated to their latest specifications, including the addition of recurrence rules.
346
+
347
+ ### update Guild schemas and endpoints
348
+
349
+ Updated all Guild data types and endpoints to reflect the latest specifications. This added three new endpoints for Guilds:
350
+ - `buildGuildBan`
351
+ - `getGuildRole`
352
+ - `modifyGuildIncidentActions`
353
+
354
+ ### update Message schemas and endpoints
355
+
356
+ Updated all Message data types and endpoints to reflect their latest specifications.
357
+
358
+ ### update Stage, Sticker, and User schemas and endpoints
359
+
360
+ Updates all of the data types and endpoints for Stickers, Stages, and Users to reflect their latest specifications.
361
+
362
+ Adds a new endpoint for Stickers:
363
+ - `getStickerPacks`
364
+
365
+ ***
366
+
367
+ ## FIXES
368
+
369
+ ### properly handle Sticker gif urls
370
+
371
+ Stickers have an exception for retrieving them in a gif file format, which uses a different base url than the standard Discord CDN
372
+
373
+ ## 2.0.0
374
+
375
+ ### Major Changes
376
+
377
+ - [#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`
378
+
379
+ This update represents a major refactor of both the core and client library codebases.
380
+
381
+ 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.
382
+
383
+ 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.
384
+
385
+ ## 1.1.0-next.0
386
+
387
+ ### Minor Changes
388
+
389
+ - Replace `zod` with `valibot`
390
+
391
+ ## 1.0.3
392
+
393
+ ### Patch Changes
394
+
395
+ - [#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.
396
+
397
+ ## 1.0.2
398
+
399
+ ### Patch Changes
400
+
401
+ - [#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 😰
402
+
403
+ ## 1.0.1
404
+
405
+ ### Patch Changes
406
+
407
+ - [#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.
408
+
409
+ ## 1.0.0
410
+
411
+ ### Major Changes
412
+
413
+ - [#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
414
+
415
+ This marks the first major release of Discordkit! 🥳
416
+
417
+ 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.
418
+
419
+ 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.
420
+
421
+ 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.
422
+
423
+ 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,72 @@
1
+ import { RequestOptions } from "./request.mjs";
2
+
3
+ //#region src/requests/DiscordSession.d.ts
4
+ declare const endpoint = "https://discord.com/api/v10/";
5
+ /**
6
+ * A disposable handle scoping requests to a single user's token, returned by
7
+ * {@link DiscordSession.asUser}. Use with `using` for automatic cleanup:
8
+ *
9
+ * ```ts
10
+ * using user = discord.asUser(accessToken);
11
+ * const me = await user.request(() => getCurrentUser());
12
+ * ```
13
+ */
14
+ interface UserSession extends Disposable {
15
+ /** Run `fn` with this user's token active; restores the previous token after. */
16
+ request: <T>(fn: () => Promise<T>) => Promise<T>;
17
+ }
18
+ /** @internal */
19
+ declare class DiscordSession {
20
+ #private;
21
+ endpoint: string;
22
+ maxRetries: number;
23
+ get ready(): boolean;
24
+ constructor(authToken?: `${`Bot` | `Bearer`} ${string}` | null);
25
+ /**
26
+ * Clears the current session details, then attempts to set
27
+ * new session values
28
+ */
29
+ setToken: (token: `${`Bot` | `Bearer`} ${string}`) => this;
30
+ clearSession: () => this;
31
+ /** Clear the active per-request token; requests fall back to the session token. */
32
+ clearActiveToken: () => this;
33
+ /**
34
+ * Scope subsequent requests to a single user's OAuth2 access token.
35
+ *
36
+ * Pass the **bare** access token (no `Bearer ` prefix — it's added for you).
37
+ * Returns a disposable handle whose `request()` method runs a callback with
38
+ * the user's token active, so any discordkit fetcher called inside it
39
+ * authenticates as that user instead of the bot session:
40
+ *
41
+ * ```ts
42
+ * using user = discord.asUser(accessToken);
43
+ * const guilds = await user.request(() => getCurrentUserGuilds({}));
44
+ * // `using` disposes the handle at scope exit — even on throw — clearing
45
+ * // the active token so it can't leak into a later request (important on
46
+ * // reused serverless/warm instances).
47
+ * ```
48
+ *
49
+ * Without `using`, call {@link clearActiveToken} yourself when done, or rely
50
+ * on each `request()` restoring the previous token after it resolves.
51
+ */
52
+ asUser: (accessToken: string) => UserSession;
53
+ /**
54
+ * Whether a request can authenticate right now — either an active
55
+ * per-request token or a session token is set. Used by the request layer to
56
+ * decide if it must fail early for lack of auth.
57
+ */
58
+ get hasAuth(): boolean;
59
+ getSession: () => string;
60
+ /**
61
+ * Queue a request to be processed with rate limiting
62
+ */
63
+ queueRequest: (resource: URL, method: string, body?: string | FormData | null, options?: RequestOptions) => Promise<Response>;
64
+ /**
65
+ * Get current queue size (useful for monitoring)
66
+ */
67
+ getQueueSize: () => number;
68
+ }
69
+ declare const discord: DiscordSession;
70
+ //#endregion
71
+ export { DiscordSession, UserSession, discord, endpoint };
72
+ //# sourceMappingURL=DiscordSession.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DiscordSession.d.mts","names":[],"sources":["../../src/requests/DiscordSession.ts"],"mappings":";;;cAGa,QAAA;;AAAb;;;;AAAqB;AAyCrB;;;UAAiB,WAAA,SAAoB,UAAA;EAEZ;EAAvB,OAAA,MAAa,EAAA,QAAU,OAAA,CAAQ,CAAA,MAAO,OAAA,CAAQ,CAAA;AAAA;;cAInC,cAAA;EAAA;EACX,QAAA;EACA,UAAA;EAAA,IA8BI,KAAA;cAIQ,SAAA;EAxCmB;;;;EAkD/B,QAAA,GAAY,KAAA;EAcZ,YAAA;EA5DW;EA2EX,gBAAA;;;;;;;;;;;;;;;;;;;;EAwBA,MAAA,GAAU,WAAA,aAAsB,WAAA;EAAtB;;;;;EAAA,IA0BN,OAAA;EAIJ,UAAA;EAeE;;;EAFF,YAAA,GACE,QAAA,EAAU,GAAA,EACV,MAAA,UACA,IAAA,YAAgB,QAAA,SAChB,OAAA,GAAU,cAAA,KACT,OAAA,CAAQ,QAAA;EADT;;;EA8PF,YAAA;AAAA;AAAA,cAGW,OAAA,EAAO,cAAuB"}