snowtransfer 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/Constants.d.ts +59 -0
  3. package/dist/Constants.js +123 -0
  4. package/dist/Endpoints.d.ts +120 -0
  5. package/dist/Endpoints.js +121 -0
  6. package/dist/RequestHandler.d.ts +258 -0
  7. package/dist/RequestHandler.js +629 -0
  8. package/dist/SnowTransfer.d.ts +70 -0
  9. package/dist/SnowTransfer.js +105 -0
  10. package/dist/StateMachine.d.ts +89 -0
  11. package/dist/StateMachine.js +208 -0
  12. package/dist/StateMachineGraph.d.ts +3 -0
  13. package/dist/StateMachineGraph.js +23 -0
  14. package/dist/Types.d.ts +76 -0
  15. package/dist/Types.js +2 -0
  16. package/dist/index.d.ts +25 -718
  17. package/dist/index.js +63 -44
  18. package/dist/methods/Assets.d.ts +290 -0
  19. package/dist/methods/Assets.js +326 -0
  20. package/dist/methods/AuditLog.d.ts +40 -0
  21. package/dist/methods/AuditLog.js +44 -0
  22. package/dist/methods/AutoModeration.d.ts +122 -0
  23. package/dist/methods/AutoModeration.js +135 -0
  24. package/dist/methods/Bot.d.ts +65 -0
  25. package/dist/methods/Bot.js +75 -0
  26. package/dist/methods/Channel.d.ts +866 -0
  27. package/dist/methods/Channel.js +982 -0
  28. package/dist/methods/Entitlements.d.ts +87 -0
  29. package/dist/methods/Entitlements.js +99 -0
  30. package/dist/methods/Guild.d.ts +722 -0
  31. package/dist/methods/Guild.js +785 -0
  32. package/dist/methods/GuildScheduledEvent.d.ts +138 -0
  33. package/dist/methods/GuildScheduledEvent.js +155 -0
  34. package/dist/methods/GuildTemplate.d.ts +110 -0
  35. package/dist/methods/GuildTemplate.js +124 -0
  36. package/dist/methods/Interaction.d.ts +339 -0
  37. package/dist/methods/Interaction.js +359 -0
  38. package/dist/methods/Invite.d.ts +81 -0
  39. package/dist/methods/Invite.js +107 -0
  40. package/dist/methods/Sku.d.ts +58 -0
  41. package/dist/methods/Sku.js +66 -0
  42. package/dist/methods/StageInstance.d.ts +86 -0
  43. package/dist/methods/StageInstance.js +97 -0
  44. package/dist/methods/User.d.ts +167 -0
  45. package/dist/methods/User.js +184 -0
  46. package/dist/methods/Voice.d.ts +44 -0
  47. package/dist/methods/Voice.js +52 -0
  48. package/dist/methods/Webhook.d.ts +265 -0
  49. package/dist/methods/Webhook.js +256 -0
  50. package/dist/tokenless.d.ts +19 -0
  51. package/dist/tokenless.js +31 -0
  52. package/package.json +9 -9
  53. package/dist/index.js.map +0 -1
@@ -0,0 +1,265 @@
1
+ import type { RequestHandler } from "../RequestHandler";
2
+ import type { FileInput, SnowTransferOptions } from "../Types";
3
+ import { type RESTDeleteAPIWebhookResult, type RESTDeleteAPIWebhookWithTokenResult, type RESTDeleteAPIWebhookWithTokenMessageResult, type RESTGetAPIChannelWebhooksResult, type RESTGetAPIGuildWebhooksResult, type RESTGetAPIWebhookResult, type RESTGetAPIWebhookWithTokenMessageResult, type RESTPatchAPIWebhookJSONBody, type RESTPatchAPIWebhookResult, type RESTPatchAPIWebhookWithTokenJSONBody, type RESTPatchAPIWebhookWithTokenMessageJSONBody, type RESTPatchAPIWebhookWithTokenMessageResult, type RESTPatchAPIWebhookWithTokenResult, type RESTPostAPIChannelWebhookJSONBody, type RESTPostAPIChannelWebhookResult, type RESTPostAPIWebhookWithTokenGitHubQuery, type RESTPostAPIWebhookWithTokenGitHubResult, type RESTPostAPIWebhookWithTokenGitHubWaitResult, type RESTPostAPIWebhookWithTokenJSONBody, type RESTPostAPIWebhookWithTokenQuery, type RESTPostAPIWebhookWithTokenResult, type RESTPostAPIWebhookWithTokenSlackQuery, type RESTPostAPIWebhookWithTokenSlackResult, type RESTPostAPIWebhookWithTokenSlackWaitResult, type RESTPostAPIWebhookWithTokenWaitResult } from "discord-api-types/v10";
4
+ /**
5
+ * Methods for handling webhook interactions
6
+ * @since 0.1.0
7
+ */
8
+ declare class WebhookMethods {
9
+ readonly requestHandler: RequestHandler;
10
+ options: SnowTransferOptions;
11
+ /**
12
+ * Create a new Method Handler
13
+ *
14
+ * Usually SnowTransfer creates a method handler for you, this is here for completion
15
+ *
16
+ * You can access the methods listed via `client.webhook.method`, where `client` is an initialized SnowTransfer instance
17
+ * @param requestHandler request handler that calls the rest api
18
+ * @param options Options for the SnowTransfer instance
19
+ */
20
+ constructor(requestHandler: RequestHandler, options: SnowTransferOptions);
21
+ /**
22
+ * Create a new Webhook
23
+ * @since 0.1.0
24
+ * @param channelId Id of the channel
25
+ * @param data Object with webhook properties
26
+ * @param reason Reason for creating the webhook
27
+ * @returns [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
28
+ *
29
+ * | Permissions needed | Condition |
30
+ * |--------------------|-----------|
31
+ * | MANAGE_WEBHOOKS | always |
32
+ *
33
+ * @example
34
+ * // Create a new Webhook with the name "Webby Webhook"
35
+ * const client = new SnowTransfer("TOKEN")
36
+ * const webhookData = {
37
+ * name: "Webby Webhook"
38
+ * }
39
+ * const webhook = await client.webhook.createWebhook("channel Id", webhookData)
40
+ */
41
+ createWebhook(channelId: string, data: RESTPostAPIChannelWebhookJSONBody, reason?: string): Promise<RESTPostAPIChannelWebhookResult>;
42
+ /**
43
+ * Get all webhooks within a channel
44
+ * @since 0.5.0
45
+ * @param channelId Id of the channel
46
+ * @returns Array of [Webhook Objects](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
47
+ *
48
+ * | Permissions needed | Condition |
49
+ * |--------------------|-----------|
50
+ * | MANAGE_WEBHOOKS | always |
51
+ *
52
+ * @example
53
+ * // Get all webhooks within a channel
54
+ * const client = new SnowTransfer("TOKEN")
55
+ * const webhooks = await client.webhook.getChannelWebhooks("channel Id")
56
+ */
57
+ getChannelWebhooks(channelId: string): Promise<RESTGetAPIChannelWebhooksResult>;
58
+ /**
59
+ * Get all webhooks within a guild
60
+ * @since 0.5.0
61
+ * @param guildId Id of the guild
62
+ * @returns Array of [Webhook Objects](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
63
+ *
64
+ * | Permissions needed | Condition |
65
+ * |--------------------|-----------|
66
+ * | MANAGE_WEBHOOKS | always |
67
+ *
68
+ * @example
69
+ * // Get all webhooks within a guild
70
+ * const client = new SnowTransfer("TOKEN")
71
+ * const webhooks = await client.webhook.getGuildWebhooks("guild Id")
72
+ */
73
+ getGuildWebhooks(guildId: string): Promise<RESTGetAPIGuildWebhooksResult>;
74
+ /**
75
+ * Get a single Webhook via Id
76
+ * @since 0.1.0
77
+ * @param webhookId Id of the webhook
78
+ * @param token Webhook token
79
+ * @returns [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
80
+ *
81
+ * | Permissions needed | Condition |
82
+ * |--------------------|---------------|
83
+ * | MANAGE_WEBHOOKS | without token |
84
+ *
85
+ * @example
86
+ * // Get a webhook via Id providing a webhook token
87
+ * const client = new SnowTransfer() // No token needed if webhook token is provided
88
+ * const webhook = await client.webhook.getWebhook("webhook Id", "webhook token")
89
+ */
90
+ getWebhook(webhookId: string, token?: string): Promise<RESTGetAPIWebhookResult>;
91
+ /**
92
+ * Update a webhook without a token
93
+ * @since 0.18.0
94
+ * @param webhookId Id of the webhook
95
+ * @param data Updated Webhook properties
96
+ * @param reason Reason for updating the webhook
97
+ * @returns Updated [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
98
+ *
99
+ * | Permissions needed | Condition |
100
+ * |--------------------|-----------|
101
+ * | MANAGE_WEBHOOKS | always |
102
+ *
103
+ * @example
104
+ * // Rename a webhook to "Captain Hook" without a webhook token
105
+ * const client = new SnowTransfer("TOKEN")
106
+ * const webhookData = {
107
+ * name: "Captain Hook"
108
+ * }
109
+ * const webhook = await client.webhook.editWebhook("webhook Id", webhookData)
110
+ */
111
+ editWebhook(webhookId: string, data: RESTPatchAPIWebhookJSONBody, reason?: string): Promise<RESTPatchAPIWebhookResult>;
112
+ /**
113
+ * Update a webhook with a token
114
+ * @since 0.18.0
115
+ * @param webhookId Id of the webhook
116
+ * @param token Token of the webhook
117
+ * @param data Updated webhook properties
118
+ * @param reason Reason for updating the webhook
119
+ * @returns Updated [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
120
+ *
121
+ * @example
122
+ * // Rename a webhook to "Captain Hook" with a webhook token
123
+ * const client = new SnowTransfer() // No token needed if webhook token is provided
124
+ * const webhookData = {
125
+ * name: "Captain Hook"
126
+ * }
127
+ * const webhook = await client.webhook.editWebhookToken("webhook Id", "webhook token", webhookData)
128
+ */
129
+ editWebhookToken(webhookId: string, token: string, data: RESTPatchAPIWebhookWithTokenJSONBody, reason?: string): Promise<RESTPatchAPIWebhookWithTokenResult>;
130
+ /**
131
+ * Delete a Webhook
132
+ * @since 0.1.0
133
+ * @param webhookId Id of the webhook
134
+ * @param reason Reason for deleting the webhook
135
+ * @returns Resolves the Promise on successful execution
136
+ *
137
+ * | Permissions needed | Condition |
138
+ * |--------------------|-----------|
139
+ * | MANAGE_WEBHOOKS | always |
140
+ *
141
+ * @example
142
+ * // Delete a webhook via Id without a webhook token
143
+ * const client = new SnowTransfer("TOKEN");
144
+ * client.webhook.deleteWebhook("webhook Id")
145
+ */
146
+ deleteWebhook(webhookId: string, reason?: string): Promise<RESTDeleteAPIWebhookResult>;
147
+ /**
148
+ * Delete a Webhook with a token
149
+ * @since 0.17.0
150
+ * @param webhookId Id of the webhook
151
+ * @param token Webhook token
152
+ * @returns Resolves the Promise on successful execution
153
+ *
154
+ * @example
155
+ * // Delete a webhook via Id providing a webhook token
156
+ * const client = new SnowTransfer(); // No token needed if webhook token is provided
157
+ * client.webhook.deleteWebhookToken("webhook Id", "webhook token")
158
+ */
159
+ deleteWebhookToken(webhookId: string, token: string, reason?: string): Promise<RESTDeleteAPIWebhookWithTokenResult>;
160
+ /**
161
+ * Send a message via Webhook
162
+ * @since 0.1.0
163
+ * @param webhookId Id of the webhook
164
+ * @param token webhook token
165
+ * @param data Webhook data to send
166
+ * @param options Options for executing the webhook
167
+ * @returns Resolves the Promise on successful execution unless wait is set to true, which returns a [message]() object
168
+ *
169
+ * @example
170
+ * // Send a message saying "Hi from my webhook" with a previously created webhook
171
+ * const client = new SnowTransfer()
172
+ * client.webhook.executeWebhook("webhook Id", "webhook token", { content: "Hi from my webhook" })
173
+ */
174
+ executeWebhook(webhookId: string, token: string, data: RESTPostAPIWebhookWithTokenJSONBody & {
175
+ files?: Array<{
176
+ name: string;
177
+ file: FileInput;
178
+ }>;
179
+ }, options?: RESTPostAPIWebhookWithTokenQuery & {
180
+ wait?: false;
181
+ }): Promise<RESTPostAPIWebhookWithTokenResult>;
182
+ executeWebhook(webhookId: string, token: string, data: RESTPostAPIWebhookWithTokenJSONBody & {
183
+ files?: Array<{
184
+ name: string;
185
+ file: FileInput;
186
+ }>;
187
+ }, options: RESTPostAPIWebhookWithTokenQuery & {
188
+ wait: true;
189
+ }): Promise<RESTPostAPIWebhookWithTokenWaitResult>;
190
+ /**
191
+ * Execute a slack style Webhook
192
+ * @since 0.1.0
193
+ * @param webhookId Id of the Webhook
194
+ * @param token Webhook token
195
+ * @param data Check [Slack's documentation](https://api.slack.com/incoming-webhooks)
196
+ * @param options Options for executing the webhook
197
+ * @returns Resolves the Promise on successful execution
198
+ *
199
+ * @example
200
+ * const client = new SnowTransfer() // No token needed
201
+ * client.webhook.executeSlackWebhook("webhook Id", "webhook token", slackdata)
202
+ */
203
+ executeWebhookSlack(webhookId: string, token: string, data: any, options?: RESTPostAPIWebhookWithTokenSlackQuery & {
204
+ wait?: false;
205
+ }): Promise<RESTPostAPIWebhookWithTokenSlackResult>;
206
+ executeWebhookSlack(webhookId: string, token: string, data: any, options?: RESTPostAPIWebhookWithTokenSlackQuery & {
207
+ wait: true;
208
+ }): Promise<RESTPostAPIWebhookWithTokenSlackWaitResult>;
209
+ /**
210
+ * Executes a github style Webhook
211
+ * @since 0.3.0
212
+ * @param webhookId Id of the Webhook
213
+ * @param token Webhook token
214
+ * @param data Check [GitHub's documentation](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-object)
215
+ * @param options Options for executing the webhook
216
+ * @returns Resolves the Promise on successful execution
217
+ */
218
+ executeWebhookGitHub(webhookId: string, token: string, data: any, options?: RESTPostAPIWebhookWithTokenGitHubQuery & {
219
+ wait?: false;
220
+ }): Promise<RESTPostAPIWebhookWithTokenGitHubResult>;
221
+ executeWebhookGitHub(webhookId: string, token: string, data: any, options?: RESTPostAPIWebhookWithTokenGitHubQuery & {
222
+ wait: true;
223
+ }): Promise<RESTPostAPIWebhookWithTokenGitHubWaitResult>;
224
+ /**
225
+ * Get a single message from a specific Webhook via Id
226
+ * @since 0.3.0
227
+ * @param webhookId Id of the Webhook
228
+ * @param token Webhook token
229
+ * @param messageId Id of the message
230
+ * @param threadId Id of the thread the message was sent in
231
+ * @returns [discord message](https://discord.com/developers/docs/resources/channel#message-object) object
232
+ */
233
+ getWebhookMessage(webhookId: string, token: string, messageId: string, threadId?: string): Promise<RESTGetAPIWebhookWithTokenMessageResult>;
234
+ /**
235
+ * Edit a message sent by a Webhook
236
+ * @since 0.3.0
237
+ * @param webhookId Id of the Webhook
238
+ * @param token Webhook token
239
+ * @param messageId Id of the message
240
+ * @param data Data to send
241
+ * @returns [discord message](https://discord.com/developers/docs/resources/channel#message-object) object
242
+ *
243
+ * @example
244
+ * const client = new SnowTransfer()
245
+ * const message = await client.webhook.editWebhookMessage("webhook Id", "webhook token", "message Id", { content: "New content" })
246
+ */
247
+ editWebhookMessage(webhookId: string, token: string, messageId: string, data: RESTPatchAPIWebhookWithTokenMessageJSONBody & {
248
+ thread_id?: string;
249
+ files?: Array<{
250
+ name: string;
251
+ file: FileInput;
252
+ }>;
253
+ }): Promise<RESTPatchAPIWebhookWithTokenMessageResult>;
254
+ /**
255
+ * Delete a message sent by a Webhook
256
+ * @since 0.3.0
257
+ * @param webhookId Id of the Webhook
258
+ * @param token Webhook token
259
+ * @param messageId Id of the message
260
+ * @param threadId Id of the thread the message was sent in
261
+ * @returns Resolves the Promise on successful execution
262
+ */
263
+ deleteWebhookMessage(webhookId: string, token: string, messageId: string, threadId?: string): Promise<RESTDeleteAPIWebhookWithTokenMessageResult>;
264
+ }
265
+ export = WebhookMethods;
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ const Endpoints = require("../Endpoints");
3
+ const Constants = require("../Constants");
4
+ const v10_1 = require("discord-api-types/v10");
5
+ /**
6
+ * Methods for handling webhook interactions
7
+ * @since 0.1.0
8
+ */
9
+ class WebhookMethods {
10
+ requestHandler;
11
+ options;
12
+ /**
13
+ * Create a new Method Handler
14
+ *
15
+ * Usually SnowTransfer creates a method handler for you, this is here for completion
16
+ *
17
+ * You can access the methods listed via `client.webhook.method`, where `client` is an initialized SnowTransfer instance
18
+ * @param requestHandler request handler that calls the rest api
19
+ * @param options Options for the SnowTransfer instance
20
+ */
21
+ constructor(requestHandler, options) {
22
+ this.requestHandler = requestHandler;
23
+ this.options = options;
24
+ }
25
+ /**
26
+ * Create a new Webhook
27
+ * @since 0.1.0
28
+ * @param channelId Id of the channel
29
+ * @param data Object with webhook properties
30
+ * @param reason Reason for creating the webhook
31
+ * @returns [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
32
+ *
33
+ * | Permissions needed | Condition |
34
+ * |--------------------|-----------|
35
+ * | MANAGE_WEBHOOKS | always |
36
+ *
37
+ * @example
38
+ * // Create a new Webhook with the name "Webby Webhook"
39
+ * const client = new SnowTransfer("TOKEN")
40
+ * const webhookData = {
41
+ * name: "Webby Webhook"
42
+ * }
43
+ * const webhook = await client.webhook.createWebhook("channel Id", webhookData)
44
+ */
45
+ async createWebhook(channelId, data, reason) {
46
+ return this.requestHandler.request(Endpoints.CHANNEL_WEBHOOKS(channelId), {}, "post", "json", data, Constants.reasonHeader(reason));
47
+ }
48
+ /**
49
+ * Get all webhooks within a channel
50
+ * @since 0.5.0
51
+ * @param channelId Id of the channel
52
+ * @returns Array of [Webhook Objects](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
53
+ *
54
+ * | Permissions needed | Condition |
55
+ * |--------------------|-----------|
56
+ * | MANAGE_WEBHOOKS | always |
57
+ *
58
+ * @example
59
+ * // Get all webhooks within a channel
60
+ * const client = new SnowTransfer("TOKEN")
61
+ * const webhooks = await client.webhook.getChannelWebhooks("channel Id")
62
+ */
63
+ async getChannelWebhooks(channelId) {
64
+ return this.requestHandler.request(Endpoints.CHANNEL_WEBHOOKS(channelId), {}, "get", "json");
65
+ }
66
+ /**
67
+ * Get all webhooks within a guild
68
+ * @since 0.5.0
69
+ * @param guildId Id of the guild
70
+ * @returns Array of [Webhook Objects](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
71
+ *
72
+ * | Permissions needed | Condition |
73
+ * |--------------------|-----------|
74
+ * | MANAGE_WEBHOOKS | always |
75
+ *
76
+ * @example
77
+ * // Get all webhooks within a guild
78
+ * const client = new SnowTransfer("TOKEN")
79
+ * const webhooks = await client.webhook.getGuildWebhooks("guild Id")
80
+ */
81
+ async getGuildWebhooks(guildId) {
82
+ return this.requestHandler.request(Endpoints.GUILD_WEBHOOKS(guildId), {}, "get", "json");
83
+ }
84
+ /**
85
+ * Get a single Webhook via Id
86
+ * @since 0.1.0
87
+ * @param webhookId Id of the webhook
88
+ * @param token Webhook token
89
+ * @returns [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
90
+ *
91
+ * | Permissions needed | Condition |
92
+ * |--------------------|---------------|
93
+ * | MANAGE_WEBHOOKS | without token |
94
+ *
95
+ * @example
96
+ * // Get a webhook via Id providing a webhook token
97
+ * const client = new SnowTransfer() // No token needed if webhook token is provided
98
+ * const webhook = await client.webhook.getWebhook("webhook Id", "webhook token")
99
+ */
100
+ async getWebhook(webhookId, token) {
101
+ if (token)
102
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN(webhookId, token), {}, "get", "json");
103
+ return this.requestHandler.request(Endpoints.WEBHOOK(webhookId), {}, "get", "json");
104
+ }
105
+ /**
106
+ * Update a webhook without a token
107
+ * @since 0.18.0
108
+ * @param webhookId Id of the webhook
109
+ * @param data Updated Webhook properties
110
+ * @param reason Reason for updating the webhook
111
+ * @returns Updated [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
112
+ *
113
+ * | Permissions needed | Condition |
114
+ * |--------------------|-----------|
115
+ * | MANAGE_WEBHOOKS | always |
116
+ *
117
+ * @example
118
+ * // Rename a webhook to "Captain Hook" without a webhook token
119
+ * const client = new SnowTransfer("TOKEN")
120
+ * const webhookData = {
121
+ * name: "Captain Hook"
122
+ * }
123
+ * const webhook = await client.webhook.editWebhook("webhook Id", webhookData)
124
+ */
125
+ async editWebhook(webhookId, data, reason) {
126
+ return this.requestHandler.request(Endpoints.WEBHOOK(webhookId), {}, "patch", "json", data, Constants.reasonHeader(reason));
127
+ }
128
+ /**
129
+ * Update a webhook with a token
130
+ * @since 0.18.0
131
+ * @param webhookId Id of the webhook
132
+ * @param token Token of the webhook
133
+ * @param data Updated webhook properties
134
+ * @param reason Reason for updating the webhook
135
+ * @returns Updated [Webhook Object](https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure)
136
+ *
137
+ * @example
138
+ * // Rename a webhook to "Captain Hook" with a webhook token
139
+ * const client = new SnowTransfer() // No token needed if webhook token is provided
140
+ * const webhookData = {
141
+ * name: "Captain Hook"
142
+ * }
143
+ * const webhook = await client.webhook.editWebhookToken("webhook Id", "webhook token", webhookData)
144
+ */
145
+ async editWebhookToken(webhookId, token, data, reason) {
146
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN(webhookId, token), {}, "patch", "json", data, Constants.reasonHeader(reason));
147
+ }
148
+ /**
149
+ * Delete a Webhook
150
+ * @since 0.1.0
151
+ * @param webhookId Id of the webhook
152
+ * @param reason Reason for deleting the webhook
153
+ * @returns Resolves the Promise on successful execution
154
+ *
155
+ * | Permissions needed | Condition |
156
+ * |--------------------|-----------|
157
+ * | MANAGE_WEBHOOKS | always |
158
+ *
159
+ * @example
160
+ * // Delete a webhook via Id without a webhook token
161
+ * const client = new SnowTransfer("TOKEN");
162
+ * client.webhook.deleteWebhook("webhook Id")
163
+ */
164
+ async deleteWebhook(webhookId, reason) {
165
+ return this.requestHandler.request(Endpoints.WEBHOOK(webhookId), {}, "delete", "json", undefined, Constants.reasonHeader(reason));
166
+ }
167
+ /**
168
+ * Delete a Webhook with a token
169
+ * @since 0.17.0
170
+ * @param webhookId Id of the webhook
171
+ * @param token Webhook token
172
+ * @returns Resolves the Promise on successful execution
173
+ *
174
+ * @example
175
+ * // Delete a webhook via Id providing a webhook token
176
+ * const client = new SnowTransfer(); // No token needed if webhook token is provided
177
+ * client.webhook.deleteWebhookToken("webhook Id", "webhook token")
178
+ */
179
+ async deleteWebhookToken(webhookId, token, reason) {
180
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN(webhookId, token), {}, "delete", "json", undefined, Constants.reasonHeader(reason));
181
+ }
182
+ async executeWebhook(webhookId, token, data, options) {
183
+ if (typeof data !== "string" && !data.content && !data.embeds?.length && !data.components?.length && !data.files?.length && !data.poll)
184
+ throw new Error("Missing content, embeds, components, files, or poll");
185
+ if (typeof data === "string")
186
+ data = { content: data };
187
+ const payload = Constants.cloneUserInput(data);
188
+ const opts = { ...options };
189
+ if ((payload.content || payload.embeds) &&
190
+ payload.flags &&
191
+ (payload.flags & v10_1.MessageFlags.IsComponentsV2) === v10_1.MessageFlags.IsComponentsV2)
192
+ throw new Error("The message flags was set to include IsComponentsV2, but content and/or embeds were also present. You can either have content/embeds or components v2, not both.");
193
+ // Sanitize the message
194
+ payload.allowed_mentions ??= this.options.allowed_mentions;
195
+ if (payload.files)
196
+ return this.requestHandler.request(`${Endpoints.WEBHOOK_TOKEN(webhookId, token)}`, opts, "post", "multipart", await Constants.standardMultipartHandler(payload));
197
+ else
198
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN(webhookId, token), opts, "post", "json", payload);
199
+ }
200
+ async executeWebhookSlack(webhookId, token, data, options) {
201
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN_SLACK(webhookId, token), options, "post", "json", data);
202
+ }
203
+ async executeWebhookGitHub(webhookId, token, data, options = {}) {
204
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN_GITHUB(webhookId, token), options, "post", "json", data);
205
+ }
206
+ /**
207
+ * Get a single message from a specific Webhook via Id
208
+ * @since 0.3.0
209
+ * @param webhookId Id of the Webhook
210
+ * @param token Webhook token
211
+ * @param messageId Id of the message
212
+ * @param threadId Id of the thread the message was sent in
213
+ * @returns [discord message](https://discord.com/developers/docs/resources/channel#message-object) object
214
+ */
215
+ async getWebhookMessage(webhookId, token, messageId, threadId) {
216
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId), { thread_id: threadId }, "get", "json");
217
+ }
218
+ /**
219
+ * Edit a message sent by a Webhook
220
+ * @since 0.3.0
221
+ * @param webhookId Id of the Webhook
222
+ * @param token Webhook token
223
+ * @param messageId Id of the message
224
+ * @param data Data to send
225
+ * @returns [discord message](https://discord.com/developers/docs/resources/channel#message-object) object
226
+ *
227
+ * @example
228
+ * const client = new SnowTransfer()
229
+ * const message = await client.webhook.editWebhookMessage("webhook Id", "webhook token", "message Id", { content: "New content" })
230
+ */
231
+ async editWebhookMessage(webhookId, token, messageId, data) {
232
+ let threadId = undefined;
233
+ if (data.thread_id)
234
+ threadId = data.thread_id;
235
+ const payload = Constants.cloneUserInput(data);
236
+ delete payload.thread_id;
237
+ payload.allowed_mentions ??= this.options.allowed_mentions;
238
+ if (payload.files)
239
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId), { thread_id: threadId }, "patch", "multipart", await Constants.standardMultipartHandler(payload));
240
+ else
241
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId), { thread_id: threadId }, "patch", "json", payload);
242
+ }
243
+ /**
244
+ * Delete a message sent by a Webhook
245
+ * @since 0.3.0
246
+ * @param webhookId Id of the Webhook
247
+ * @param token Webhook token
248
+ * @param messageId Id of the message
249
+ * @param threadId Id of the thread the message was sent in
250
+ * @returns Resolves the Promise on successful execution
251
+ */
252
+ async deleteWebhookMessage(webhookId, token, messageId, threadId) {
253
+ return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN_MESSAGE(webhookId, token, messageId), { thread_id: threadId }, "delete", "json");
254
+ }
255
+ }
256
+ module.exports = WebhookMethods;
@@ -0,0 +1,19 @@
1
+ import type { RESTPostOAuth2AccessTokenResult } from "discord-api-types/v10";
2
+ /**
3
+ * Get an oauth token after being authorized
4
+ * @since 0.11.0
5
+ * @param clientId The ID of your application. For older bots, this is different from your bot's user ID
6
+ * @param redirectURI The URI Discord will redirect the user to after they authorize
7
+ * @param clientSecret The secret of your client you can obtain from the Application page
8
+ * @param code The code returned from Discord from the oauth authorize flow
9
+ * @returns The authorization
10
+ *
11
+ * @example
12
+ * const { tokenless } = require("snowtransfer")
13
+ * const result = await tokenless.getOauth2Token(id, redirectURI, secret, code)
14
+ */
15
+ declare function getOauth2Token(clientId: string, redirectURI: string, clientSecret: string, code: string): Promise<RESTPostOAuth2AccessTokenResult>;
16
+ declare const _default: {
17
+ getOauth2Token: typeof getOauth2Token;
18
+ };
19
+ export = _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ const Endpoints = require("./Endpoints");
3
+ /**
4
+ * Get an oauth token after being authorized
5
+ * @since 0.11.0
6
+ * @param clientId The ID of your application. For older bots, this is different from your bot's user ID
7
+ * @param redirectURI The URI Discord will redirect the user to after they authorize
8
+ * @param clientSecret The secret of your client you can obtain from the Application page
9
+ * @param code The code returned from Discord from the oauth authorize flow
10
+ * @returns The authorization
11
+ *
12
+ * @example
13
+ * const { tokenless } = require("snowtransfer")
14
+ * const result = await tokenless.getOauth2Token(id, redirectURI, secret, code)
15
+ */
16
+ async function getOauth2Token(clientId, redirectURI, clientSecret, code) {
17
+ const response = await fetch(`${Endpoints.BASE_HOST}${Endpoints.OAUTH2_TOKEN}`, {
18
+ method: "POST",
19
+ body: new URLSearchParams({
20
+ grant_type: "authorization_code",
21
+ code,
22
+ client_id: clientId,
23
+ client_secret: clientSecret,
24
+ redirect_uri: redirectURI
25
+ })
26
+ });
27
+ return response.json();
28
+ }
29
+ module.exports = {
30
+ getOauth2Token
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snowtransfer",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Minimalistic Rest client for the Discord Api",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,10 +18,11 @@
18
18
  "microservice bot"
19
19
  ],
20
20
  "scripts": {
21
- "build:src": "tsup src/index.ts --clean --dts --sourcemap --format cjs --target node22 --minify-whitespace --minify-syntax --treeshake && node ./sourceMapPostProcess.js",
21
+ "build:src": "tsc -p .",
22
22
  "build:docs": "typedoc --name SnowTransfer --excludeExternals --sort static-first --sort alphabetical",
23
23
  "build": "npm run build:src && npm run build:docs",
24
- "lint": "eslint ."
24
+ "lint": "eslint .",
25
+ "test": "npm run build:src && node --test \"test/**/*.test.js\""
25
26
  },
26
27
  "repository": {
27
28
  "type": "git",
@@ -35,13 +36,12 @@
35
36
  },
36
37
  "devDependencies": {
37
38
  "@eslint/js": "^10.0.1",
38
- "@types/node": "^26.0.1",
39
- "@typescript-eslint/eslint-plugin": "^8.62.0",
40
- "@typescript-eslint/parser": "^8.62.0",
41
- "eslint": "^10.5.0",
39
+ "@types/node": "^26.1.0",
40
+ "@typescript-eslint/eslint-plugin": "^8.62.1",
41
+ "@typescript-eslint/parser": "^8.62.1",
42
+ "eslint": "^10.6.0",
42
43
  "globals": "^17.7.0",
43
- "tsup": "^8.5.1",
44
- "typedoc": "^0.28.19",
44
+ "typedoc": "^0.28.20",
45
45
  "typedoc-plugin-mdn-links": "^5.1.1",
46
46
  "typescript": "^6.0.3"
47
47
  },