@dereekb/discord 13.33.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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/index.cjs.default.js +1 -0
  4. package/index.cjs.js +817 -0
  5. package/index.cjs.mjs +2 -0
  6. package/index.d.ts +1 -0
  7. package/index.esm.js +789 -0
  8. package/nestjs/index.cjs.default.js +1 -0
  9. package/nestjs/index.cjs.js +1928 -0
  10. package/nestjs/index.cjs.mjs +2 -0
  11. package/nestjs/index.d.ts +1 -0
  12. package/nestjs/index.esm.js +1905 -0
  13. package/nestjs/package.json +26 -0
  14. package/nestjs/src/index.d.ts +1 -0
  15. package/nestjs/src/lib/discord/discord.api.d.ts +69 -0
  16. package/nestjs/src/lib/discord/discord.api.spec.client.d.ts +20 -0
  17. package/nestjs/src/lib/discord/discord.config.d.ts +58 -0
  18. package/nestjs/src/lib/discord/discord.module.d.ts +20 -0
  19. package/nestjs/src/lib/discord/discord.util.d.ts +28 -0
  20. package/nestjs/src/lib/discord/index.d.ts +4 -0
  21. package/nestjs/src/lib/index.d.ts +3 -0
  22. package/nestjs/src/lib/oauth/index.d.ts +3 -0
  23. package/nestjs/src/lib/oauth/oauth.api.d.ts +74 -0
  24. package/nestjs/src/lib/oauth/oauth.config.d.ts +55 -0
  25. package/nestjs/src/lib/oauth/oauth.module.d.ts +22 -0
  26. package/nestjs/src/lib/webhook/index.d.ts +6 -0
  27. package/nestjs/src/lib/webhook/webhook.discord.config.d.ts +22 -0
  28. package/nestjs/src/lib/webhook/webhook.discord.controller.d.ts +8 -0
  29. package/nestjs/src/lib/webhook/webhook.discord.d.ts +59 -0
  30. package/nestjs/src/lib/webhook/webhook.discord.module.d.ts +17 -0
  31. package/nestjs/src/lib/webhook/webhook.discord.service.d.ts +18 -0
  32. package/nestjs/src/lib/webhook/webhook.discord.verify.d.ts +46 -0
  33. package/package.json +33 -0
  34. package/src/index.d.ts +1 -0
  35. package/src/lib/discord.api.page.d.ts +108 -0
  36. package/src/lib/discord.config.d.ts +19 -0
  37. package/src/lib/discord.type.d.ts +41 -0
  38. package/src/lib/index.d.ts +4 -0
  39. package/src/lib/oauth/index.d.ts +6 -0
  40. package/src/lib/oauth/oauth.api.d.ts +130 -0
  41. package/src/lib/oauth/oauth.authorize.d.ts +93 -0
  42. package/src/lib/oauth/oauth.config.d.ts +56 -0
  43. package/src/lib/oauth/oauth.d.ts +42 -0
  44. package/src/lib/oauth/oauth.error.api.d.ts +65 -0
  45. package/src/lib/oauth/oauth.factory.d.ts +36 -0
@@ -0,0 +1,1905 @@
1
+ import { GatewayIntentBits, Client, Events, TextChannel, InteractionType } from 'discord.js';
2
+ import { Injectable, Inject, Logger, Module, Post, Req, Controller } from '@nestjs/common';
3
+ import { isTestNodeEnv, RawBody } from '@dereekb/nestjs';
4
+ import { ConfigService, ConfigModule } from '@nestjs/config';
5
+ import { discordOAuthFactory, exchangeAuthorizationCode, refreshAccessToken, readCurrentUser, discordOAuthAuthorizeUrlFactory, discordAccessTokenFromTokenResponse } from '@dereekb/discord';
6
+ import { handlerFactory, handlerConfigurerFactory, handlerMappedSetFunctionFactory, isHexWithByteLength } from '@dereekb/util';
7
+ import { createPublicKey, verify } from 'node:crypto';
8
+
9
+ function _type_of(obj) {
10
+ "@swc/helpers - typeof";
11
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
12
+ }
13
+ function __decorate(decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ }
19
+ function __param(paramIndex, decorator) {
20
+ return function(target, key) {
21
+ decorator(target, key, paramIndex);
22
+ };
23
+ }
24
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
25
+ var e = new Error(message);
26
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
27
+ };
28
+
29
+ function _class_call_check$8(instance, Constructor) {
30
+ if (!(instance instanceof Constructor)) {
31
+ throw new TypeError("Cannot call a class as a function");
32
+ }
33
+ }
34
+ function _defineProperties$6(target, props) {
35
+ for(var i = 0; i < props.length; i++){
36
+ var descriptor = props[i];
37
+ descriptor.enumerable = descriptor.enumerable || false;
38
+ descriptor.configurable = true;
39
+ if ("value" in descriptor) descriptor.writable = true;
40
+ Object.defineProperty(target, descriptor.key, descriptor);
41
+ }
42
+ }
43
+ function _create_class$6(Constructor, protoProps, staticProps) {
44
+ if (staticProps) _defineProperties$6(Constructor, staticProps);
45
+ return Constructor;
46
+ }
47
+ function _define_property$7(obj, key, value) {
48
+ if (key in obj) {
49
+ Object.defineProperty(obj, key, {
50
+ value: value,
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true
54
+ });
55
+ } else {
56
+ obj[key] = value;
57
+ }
58
+ return obj;
59
+ }
60
+ /**
61
+ * Default environment variable for the Discord bot token.
62
+ */ var DISCORD_BOT_TOKEN_ENV_VAR = 'DISCORD_BOT_TOKEN';
63
+ /**
64
+ * Placeholder bot token value used in development and CI environments where a real Discord
65
+ * login should not be attempted. Mirrors the value used in the workspace's .env file.
66
+ */ var DISCORD_BOT_TOKEN_PLACEHOLDER = 'placeholder';
67
+ /**
68
+ * Returns true if the input is a real, usable Discord bot token.
69
+ *
70
+ * A token is usable when it is non-empty and is not the shared placeholder value, allowing
71
+ * non-production environments to skip a real gateway login that would always fail.
72
+ *
73
+ * @param botToken - The bot token read from configuration, if any.
74
+ * @returns True when the token should be used to log in.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * isUsableDiscordBotToken('placeholder'); // false
79
+ * isUsableDiscordBotToken('real-token'); // true
80
+ * ```
81
+ */ function isUsableDiscordBotToken(botToken) {
82
+ return Boolean(botToken) && botToken !== DISCORD_BOT_TOKEN_PLACEHOLDER;
83
+ }
84
+ /**
85
+ * Default gateway intents for a bot that reads guild messages.
86
+ *
87
+ * Includes Guilds, GuildMessages, and MessageContent.
88
+ * Note: MessageContent is a privileged intent and must be enabled in the Discord Developer Portal.
89
+ */ var DEFAULT_DISCORD_INTENTS = [
90
+ GatewayIntentBits.Guilds,
91
+ GatewayIntentBits.GuildMessages,
92
+ GatewayIntentBits.MessageContent
93
+ ];
94
+ /**
95
+ * Configuration for the DiscordApi service.
96
+ */ var DiscordServiceConfig = /*#__PURE__*/ function() {
97
+ function DiscordServiceConfig() {
98
+ _class_call_check$8(this, DiscordServiceConfig);
99
+ _define_property$7(this, "discord", void 0);
100
+ }
101
+ _create_class$6(DiscordServiceConfig, null, [
102
+ {
103
+ key: "assertValidConfig",
104
+ value: function assertValidConfig(config) {
105
+ if (!config.discord.botToken) {
106
+ throw new Error('No Discord bot token specified.');
107
+ }
108
+ }
109
+ }
110
+ ]);
111
+ return DiscordServiceConfig;
112
+ }
113
+ ();
114
+
115
+ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
116
+ try {
117
+ var info = gen[key](arg);
118
+ var value = info.value;
119
+ } catch (error) {
120
+ reject(error);
121
+ return;
122
+ }
123
+ if (info.done) {
124
+ resolve(value);
125
+ } else {
126
+ Promise.resolve(value).then(_next, _throw);
127
+ }
128
+ }
129
+ function _async_to_generator$4(fn) {
130
+ return function() {
131
+ var self = this, args = arguments;
132
+ return new Promise(function(resolve, reject) {
133
+ var gen = fn.apply(self, args);
134
+ function _next(value) {
135
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
136
+ }
137
+ function _throw(err) {
138
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
139
+ }
140
+ _next(undefined);
141
+ });
142
+ };
143
+ }
144
+ function _class_call_check$7(instance, Constructor) {
145
+ if (!(instance instanceof Constructor)) {
146
+ throw new TypeError("Cannot call a class as a function");
147
+ }
148
+ }
149
+ function _defineProperties$5(target, props) {
150
+ for(var i = 0; i < props.length; i++){
151
+ var descriptor = props[i];
152
+ descriptor.enumerable = descriptor.enumerable || false;
153
+ descriptor.configurable = true;
154
+ if ("value" in descriptor) descriptor.writable = true;
155
+ Object.defineProperty(target, descriptor.key, descriptor);
156
+ }
157
+ }
158
+ function _create_class$5(Constructor, protoProps, staticProps) {
159
+ if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
160
+ return Constructor;
161
+ }
162
+ function _define_property$6(obj, key, value) {
163
+ if (key in obj) {
164
+ Object.defineProperty(obj, key, {
165
+ value: value,
166
+ enumerable: true,
167
+ configurable: true,
168
+ writable: true
169
+ });
170
+ } else {
171
+ obj[key] = value;
172
+ }
173
+ return obj;
174
+ }
175
+ function _instanceof(left, right) {
176
+ "@swc/helpers - instanceof";
177
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
178
+ return !!right[Symbol.hasInstance](left);
179
+ } else {
180
+ return left instanceof right;
181
+ }
182
+ }
183
+ function _object_spread$2(target) {
184
+ for(var i = 1; i < arguments.length; i++){
185
+ var source = arguments[i] != null ? arguments[i] : {};
186
+ var ownKeys = Object.keys(source);
187
+ if (typeof Object.getOwnPropertySymbols === "function") {
188
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
189
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
190
+ }));
191
+ }
192
+ ownKeys.forEach(function(key) {
193
+ _define_property$6(target, key, source[key]);
194
+ });
195
+ }
196
+ return target;
197
+ }
198
+ function _ts_generator$4(thisArg, body) {
199
+ var f, y, t, _ = {
200
+ label: 0,
201
+ sent: function() {
202
+ if (t[0] & 1) throw t[1];
203
+ return t[1];
204
+ },
205
+ trys: [],
206
+ ops: []
207
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
208
+ return d(g, "next", {
209
+ value: verb(0)
210
+ }), d(g, "throw", {
211
+ value: verb(1)
212
+ }), d(g, "return", {
213
+ value: verb(2)
214
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
215
+ value: function() {
216
+ return this;
217
+ }
218
+ }), g;
219
+ function verb(n) {
220
+ return function(v) {
221
+ return step([
222
+ n,
223
+ v
224
+ ]);
225
+ };
226
+ }
227
+ function step(op) {
228
+ if (f) throw new TypeError("Generator is already executing.");
229
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
230
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
231
+ if (y = 0, t) op = [
232
+ op[0] & 2,
233
+ t.value
234
+ ];
235
+ switch(op[0]){
236
+ case 0:
237
+ case 1:
238
+ t = op;
239
+ break;
240
+ case 4:
241
+ _.label++;
242
+ return {
243
+ value: op[1],
244
+ done: false
245
+ };
246
+ case 5:
247
+ _.label++;
248
+ y = op[1];
249
+ op = [
250
+ 0
251
+ ];
252
+ continue;
253
+ case 7:
254
+ op = _.ops.pop();
255
+ _.trys.pop();
256
+ continue;
257
+ default:
258
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
259
+ _ = 0;
260
+ continue;
261
+ }
262
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
263
+ _.label = op[1];
264
+ break;
265
+ }
266
+ if (op[0] === 6 && _.label < t[1]) {
267
+ _.label = t[1];
268
+ t = op;
269
+ break;
270
+ }
271
+ if (t && _.label < t[2]) {
272
+ _.label = t[2];
273
+ _.ops.push(op);
274
+ break;
275
+ }
276
+ if (t[2]) _.ops.pop();
277
+ _.trys.pop();
278
+ continue;
279
+ }
280
+ op = body.call(thisArg, _);
281
+ } catch (e) {
282
+ op = [
283
+ 6,
284
+ e
285
+ ];
286
+ y = 0;
287
+ } finally{
288
+ f = t = 0;
289
+ }
290
+ if (op[0] & 5) throw op[1];
291
+ return {
292
+ value: op[0] ? op[1] : void 0,
293
+ done: true
294
+ };
295
+ }
296
+ }
297
+ /**
298
+ * Injectable service that wraps the discord.js Client for bot operations.
299
+ *
300
+ * Automatically logs in on module init and destroys the client on module destroy
301
+ * when autoLogin is enabled (default).
302
+ */ var DiscordApi = /*#__PURE__*/ function() {
303
+ function DiscordApi(config) {
304
+ _class_call_check$7(this, DiscordApi);
305
+ _define_property$6(this, "config", void 0);
306
+ _define_property$6(this, "logger", new Logger('DiscordApi'));
307
+ /**
308
+ * The underlying discord.js Client instance.
309
+ */ _define_property$6(this, "client", void 0);
310
+ this.config = config;
311
+ var clientOptions = config.discord.clientOptions;
312
+ this.client = new Client(_object_spread$2({
313
+ intents: DEFAULT_DISCORD_INTENTS
314
+ }, clientOptions));
315
+ }
316
+ _create_class$5(DiscordApi, [
317
+ {
318
+ key: "onModuleInit",
319
+ value: function onModuleInit() {
320
+ return _async_to_generator$4(function() {
321
+ var _this, _this_config_discord, _this_config_discord_autoLogin, autoLogin, botToken, result;
322
+ return _ts_generator$4(this, function(_state) {
323
+ _this = this;
324
+ _this_config_discord = this.config.discord, _this_config_discord_autoLogin = _this_config_discord.autoLogin, autoLogin = _this_config_discord_autoLogin === void 0 ? true : _this_config_discord_autoLogin, botToken = _this_config_discord.botToken;
325
+ if (autoLogin) {
326
+ result = this.client.login(botToken).then(function() {
327
+ return undefined;
328
+ }).catch(function(e) {
329
+ _this.logger.error('Failed to log in to Discord', e);
330
+ });
331
+ } else {
332
+ result = Promise.resolve();
333
+ }
334
+ return [
335
+ 2,
336
+ result
337
+ ];
338
+ });
339
+ }).call(this);
340
+ }
341
+ },
342
+ {
343
+ key: "onModuleDestroy",
344
+ value: function onModuleDestroy() {
345
+ return _async_to_generator$4(function() {
346
+ return _ts_generator$4(this, function(_state) {
347
+ return [
348
+ 2,
349
+ this.client.destroy()
350
+ ];
351
+ });
352
+ }).call(this);
353
+ }
354
+ },
355
+ {
356
+ key: "sendMessage",
357
+ value: /**
358
+ * Sends a text message to a Discord channel.
359
+ *
360
+ * @param channelId - target channel's snowflake ID
361
+ * @param content - message text to send
362
+ *
363
+ * @throws {Error} When the channel is not found or is not a text channel.
364
+ *
365
+ * @example
366
+ * ```ts
367
+ * const message = await discordApi.sendMessage('123456789', 'Hello from the bot!');
368
+ * ```
369
+ */ /**
370
+ * Sends a text message to the specified Discord channel.
371
+ *
372
+ * @param channelId - Target channel's snowflake ID.
373
+ * @param content - Message text to send.
374
+ * @returns The sent Discord Message.
375
+ * @throws {Error} When the channel is not found or is not a text channel.
376
+ */ function sendMessage(channelId, content) {
377
+ return _async_to_generator$4(function() {
378
+ var channel;
379
+ return _ts_generator$4(this, function(_state) {
380
+ switch(_state.label){
381
+ case 0:
382
+ return [
383
+ 4,
384
+ this.client.channels.fetch(channelId)
385
+ ];
386
+ case 1:
387
+ channel = _state.sent();
388
+ if (!channel || !_instanceof(channel, TextChannel)) {
389
+ throw new Error("Channel ".concat(channelId, " not found or is not a text channel."));
390
+ }
391
+ return [
392
+ 2,
393
+ channel.send(content)
394
+ ];
395
+ }
396
+ });
397
+ }).call(this);
398
+ }
399
+ },
400
+ {
401
+ /**
402
+ * Registers a handler for the MessageCreate event (incoming messages).
403
+ *
404
+ * Returns an unsubscribe function to remove the handler.
405
+ *
406
+ * @param handler - callback invoked for each incoming message
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * const unsubscribe = discordApi.onMessage((message) => {
411
+ * if (!message.author.bot) {
412
+ * console.log(`${message.author.tag}: ${message.content}`);
413
+ * }
414
+ * });
415
+ *
416
+ * // Later, to stop listening:
417
+ * unsubscribe();
418
+ * ```
419
+ */ /**
420
+ * Registers a handler for incoming Discord messages (MessageCreate event).
421
+ *
422
+ * @param handler - Callback invoked for each incoming Message.
423
+ * @returns An unsubscribe function that removes the registered handler.
424
+ */ key: "onMessage",
425
+ value: function onMessage(handler) {
426
+ var _this = this;
427
+ this.client.on(Events.MessageCreate, handler);
428
+ return function() {
429
+ return _this.client.off(Events.MessageCreate, handler);
430
+ };
431
+ }
432
+ }
433
+ ]);
434
+ return DiscordApi;
435
+ }();
436
+ DiscordApi = __decorate([
437
+ Injectable(),
438
+ __param(0, Inject(DiscordServiceConfig))
439
+ ], DiscordApi);
440
+
441
+ function _class_call_check$6(instance, Constructor) {
442
+ if (!(instance instanceof Constructor)) {
443
+ throw new TypeError("Cannot call a class as a function");
444
+ }
445
+ }
446
+ /**
447
+ * Factory that creates a DiscordServiceConfig from environment variables.
448
+ *
449
+ * autoLogin is enabled only when a real bot token is configured and the process is not running
450
+ * under a test environment, so development and CI runs (which use a placeholder token) never
451
+ * attempt a real gateway login that would fail.
452
+ *
453
+ * @param configService - The NestJS config service used to read Discord environment variables.
454
+ * @returns A validated DiscordServiceConfig populated from environment variables.
455
+ */ function discordServiceConfigFactory(configService) {
456
+ var botToken = configService.get(DISCORD_BOT_TOKEN_ENV_VAR);
457
+ var config = {
458
+ discord: {
459
+ botToken: botToken,
460
+ autoLogin: isUsableDiscordBotToken(botToken) && !isTestNodeEnv()
461
+ }
462
+ };
463
+ DiscordServiceConfig.assertValidConfig(config);
464
+ return config;
465
+ }
466
+ /**
467
+ * NestJS module that provides the DiscordApi service.
468
+ *
469
+ * Reads the bot token from the DISCORD_BOT_TOKEN environment variable.
470
+ */ var DiscordModule = function DiscordModule() {
471
+ _class_call_check$6(this, DiscordModule);
472
+ };
473
+ DiscordModule = __decorate([
474
+ Module({
475
+ imports: [
476
+ ConfigModule
477
+ ],
478
+ providers: [
479
+ {
480
+ provide: DiscordServiceConfig,
481
+ inject: [
482
+ ConfigService
483
+ ],
484
+ useFactory: discordServiceConfigFactory
485
+ },
486
+ DiscordApi
487
+ ],
488
+ exports: [
489
+ DiscordApi
490
+ ]
491
+ })
492
+ ], DiscordModule);
493
+
494
+ function _array_like_to_array$1(arr, len) {
495
+ if (len == null || len > arr.length) len = arr.length;
496
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
497
+ return arr2;
498
+ }
499
+ function _array_without_holes$1(arr) {
500
+ if (Array.isArray(arr)) return _array_like_to_array$1(arr);
501
+ }
502
+ function _iterable_to_array$1(iter) {
503
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
504
+ }
505
+ function _non_iterable_spread$1() {
506
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
507
+ }
508
+ function _to_consumable_array$1(arr) {
509
+ return _array_without_holes$1(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread$1();
510
+ }
511
+ function _unsupported_iterable_to_array$1(o, minLen) {
512
+ if (!o) return;
513
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
514
+ var n = Object.prototype.toString.call(o).slice(8, -1);
515
+ if (n === "Object" && o.constructor) n = o.constructor.name;
516
+ if (n === "Map" || n === "Set") return Array.from(n);
517
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
518
+ }
519
+ /**
520
+ * Returns default ClientOptions for a bot that reads guild messages.
521
+ *
522
+ * Includes Guilds, GuildMessages, and MessageContent intents.
523
+ *
524
+ * @returns Partial ClientOptions with the default bot intents set.
525
+ *
526
+ * @example
527
+ * ```ts
528
+ * const options = discordDefaultClientOptions();
529
+ * // options.intents === [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
530
+ * ```
531
+ */ function discordDefaultClientOptions() {
532
+ return {
533
+ intents: DEFAULT_DISCORD_INTENTS
534
+ };
535
+ }
536
+ /**
537
+ * Returns ClientOptions with additional intents merged with the defaults.
538
+ *
539
+ * @param additionalIntents - Extra intents to include beyond the defaults.
540
+ * @returns Partial ClientOptions with the merged intent list.
541
+ *
542
+ * @example
543
+ * ```ts
544
+ * const options = discordClientOptionsWithIntents([GatewayIntentBits.DirectMessages]);
545
+ * // options.intents includes Guilds, GuildMessages, MessageContent, and DirectMessages
546
+ * ```
547
+ */ function discordClientOptionsWithIntents(additionalIntents) {
548
+ return {
549
+ intents: _to_consumable_array$1(DEFAULT_DISCORD_INTENTS).concat(_to_consumable_array$1(additionalIntents))
550
+ };
551
+ }
552
+
553
+ function _class_call_check$5(instance, Constructor) {
554
+ if (!(instance instanceof Constructor)) {
555
+ throw new TypeError("Cannot call a class as a function");
556
+ }
557
+ }
558
+ function _defineProperties$4(target, props) {
559
+ for(var i = 0; i < props.length; i++){
560
+ var descriptor = props[i];
561
+ descriptor.enumerable = descriptor.enumerable || false;
562
+ descriptor.configurable = true;
563
+ if ("value" in descriptor) descriptor.writable = true;
564
+ Object.defineProperty(target, descriptor.key, descriptor);
565
+ }
566
+ }
567
+ function _create_class$4(Constructor, protoProps, staticProps) {
568
+ if (staticProps) _defineProperties$4(Constructor, staticProps);
569
+ return Constructor;
570
+ }
571
+ function _define_property$5(obj, key, value) {
572
+ if (key in obj) {
573
+ Object.defineProperty(obj, key, {
574
+ value: value,
575
+ enumerable: true,
576
+ configurable: true,
577
+ writable: true
578
+ });
579
+ } else {
580
+ obj[key] = value;
581
+ }
582
+ return obj;
583
+ }
584
+ var DISCORD_SERVICE_NAME = 'discord';
585
+ var DISCORD_CLIENT_ID_CONFIG_KEY = 'DISCORD_CLIENT_ID';
586
+ var DISCORD_CLIENT_SECRET_CONFIG_KEY = 'DISCORD_CLIENT_SECRET';
587
+ /**
588
+ * Configuration for the {@link DiscordOAuthApi}.
589
+ *
590
+ * Carries no server-level token or access-token cache, unlike `CalcomOAuthServiceConfig`: Discord has
591
+ * no api-key alternative to the client-credentials pair, and the app acting as *itself* against
592
+ * Discord authenticates with a bot token through `DiscordServiceConfig` and discord.js instead. This
593
+ * config only ever describes the OAuth client that performs the per-user authorization-code handoff.
594
+ */ var DiscordOAuthServiceConfig = /*#__PURE__*/ function() {
595
+ function DiscordOAuthServiceConfig() {
596
+ _class_call_check$5(this, DiscordOAuthServiceConfig);
597
+ _define_property$5(this, "discordOAuth", void 0);
598
+ /**
599
+ * Optional configuration for the Discord OAuth client the api builds — a custom fetch handler or
600
+ * error logger.
601
+ */ _define_property$5(this, "factoryConfig", void 0);
602
+ }
603
+ _create_class$4(DiscordOAuthServiceConfig, null, [
604
+ {
605
+ key: "assertValidConfig",
606
+ value: function assertValidConfig(config) {
607
+ var discordOAuth = config.discordOAuth;
608
+ if (!discordOAuth) {
609
+ throw new Error('DiscordOAuthServiceConfig.discordOAuth is required');
610
+ } else if (!discordOAuth.clientId) {
611
+ throw new Error("DiscordOAuthServiceConfig requires a Discord OAuth client id (".concat(DISCORD_CLIENT_ID_CONFIG_KEY, ")."));
612
+ } else if (!discordOAuth.clientSecret) {
613
+ throw new Error("DiscordOAuthServiceConfig requires a Discord OAuth client secret (".concat(DISCORD_CLIENT_SECRET_CONFIG_KEY, ")."));
614
+ }
615
+ }
616
+ },
617
+ {
618
+ key: "assertedDiscordOAuthConfig",
619
+ value: /**
620
+ * Narrows the environment-facing config to the fully-populated {@link DiscordOAuthConfig} the core
621
+ * factory requires, asserting both credentials are present.
622
+ *
623
+ * @param config - The service configuration to read.
624
+ * @returns The validated OAuth client configuration.
625
+ * @throws {Error} When either client credential is missing.
626
+ */ function assertedDiscordOAuthConfig(config) {
627
+ DiscordOAuthServiceConfig.assertValidConfig(config);
628
+ var _config_discordOAuth = config.discordOAuth, clientId = _config_discordOAuth.clientId, clientSecret = _config_discordOAuth.clientSecret;
629
+ return {
630
+ clientId: clientId,
631
+ clientSecret: clientSecret
632
+ };
633
+ }
634
+ }
635
+ ]);
636
+ return DiscordOAuthServiceConfig;
637
+ }();
638
+ /**
639
+ * Factory function that creates a {@link DiscordOAuthServiceConfig} from NestJS ConfigService
640
+ * environment variables.
641
+ *
642
+ * Fails at startup rather than at the consent screen: a missing client id otherwise composes an
643
+ * authorize URL carrying `client_id=undefined`, and a missing secret fails the exchange only after the
644
+ * user has already consented.
645
+ *
646
+ * @param configService - The NestJS ConfigService instance.
647
+ * @returns A validated DiscordOAuthServiceConfig.
648
+ * @throws {Error} When either client credential is missing.
649
+ */ function discordOAuthServiceConfigFactory(configService) {
650
+ var clientId = configService.get(DISCORD_CLIENT_ID_CONFIG_KEY);
651
+ var clientSecret = configService.get(DISCORD_CLIENT_SECRET_CONFIG_KEY);
652
+ var config = {
653
+ discordOAuth: {
654
+ clientId: clientId || undefined,
655
+ clientSecret: clientSecret || undefined
656
+ }
657
+ };
658
+ DiscordOAuthServiceConfig.assertValidConfig(config);
659
+ return config;
660
+ }
661
+
662
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
663
+ try {
664
+ var info = gen[key](arg);
665
+ var value = info.value;
666
+ } catch (error) {
667
+ reject(error);
668
+ return;
669
+ }
670
+ if (info.done) {
671
+ resolve(value);
672
+ } else {
673
+ Promise.resolve(value).then(_next, _throw);
674
+ }
675
+ }
676
+ function _async_to_generator$3(fn) {
677
+ return function() {
678
+ var self = this, args = arguments;
679
+ return new Promise(function(resolve, reject) {
680
+ var gen = fn.apply(self, args);
681
+ function _next(value) {
682
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
683
+ }
684
+ function _throw(err) {
685
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
686
+ }
687
+ _next(undefined);
688
+ });
689
+ };
690
+ }
691
+ function _class_call_check$4(instance, Constructor) {
692
+ if (!(instance instanceof Constructor)) {
693
+ throw new TypeError("Cannot call a class as a function");
694
+ }
695
+ }
696
+ function _defineProperties$3(target, props) {
697
+ for(var i = 0; i < props.length; i++){
698
+ var descriptor = props[i];
699
+ descriptor.enumerable = descriptor.enumerable || false;
700
+ descriptor.configurable = true;
701
+ if ("value" in descriptor) descriptor.writable = true;
702
+ Object.defineProperty(target, descriptor.key, descriptor);
703
+ }
704
+ }
705
+ function _create_class$3(Constructor, protoProps, staticProps) {
706
+ if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
707
+ return Constructor;
708
+ }
709
+ function _define_property$4(obj, key, value) {
710
+ if (key in obj) {
711
+ Object.defineProperty(obj, key, {
712
+ value: value,
713
+ enumerable: true,
714
+ configurable: true,
715
+ writable: true
716
+ });
717
+ } else {
718
+ obj[key] = value;
719
+ }
720
+ return obj;
721
+ }
722
+ function _object_spread$1(target) {
723
+ for(var i = 1; i < arguments.length; i++){
724
+ var source = arguments[i] != null ? arguments[i] : {};
725
+ var ownKeys = Object.keys(source);
726
+ if (typeof Object.getOwnPropertySymbols === "function") {
727
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
728
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
729
+ }));
730
+ }
731
+ ownKeys.forEach(function(key) {
732
+ _define_property$4(target, key, source[key]);
733
+ });
734
+ }
735
+ return target;
736
+ }
737
+ function ownKeys$1(object, enumerableOnly) {
738
+ var keys = Object.keys(object);
739
+ if (Object.getOwnPropertySymbols) {
740
+ var symbols = Object.getOwnPropertySymbols(object);
741
+ keys.push.apply(keys, symbols);
742
+ }
743
+ return keys;
744
+ }
745
+ function _object_spread_props$1(target, source) {
746
+ source = source != null ? source : {};
747
+ if (Object.getOwnPropertyDescriptors) {
748
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
749
+ } else {
750
+ ownKeys$1(Object(source)).forEach(function(key) {
751
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
752
+ });
753
+ }
754
+ return target;
755
+ }
756
+ function _ts_generator$3(thisArg, body) {
757
+ var f, y, t, _ = {
758
+ label: 0,
759
+ sent: function() {
760
+ if (t[0] & 1) throw t[1];
761
+ return t[1];
762
+ },
763
+ trys: [],
764
+ ops: []
765
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
766
+ return d(g, "next", {
767
+ value: verb(0)
768
+ }), d(g, "throw", {
769
+ value: verb(1)
770
+ }), d(g, "return", {
771
+ value: verb(2)
772
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
773
+ value: function() {
774
+ return this;
775
+ }
776
+ }), g;
777
+ function verb(n) {
778
+ return function(v) {
779
+ return step([
780
+ n,
781
+ v
782
+ ]);
783
+ };
784
+ }
785
+ function step(op) {
786
+ if (f) throw new TypeError("Generator is already executing.");
787
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
788
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
789
+ if (y = 0, t) op = [
790
+ op[0] & 2,
791
+ t.value
792
+ ];
793
+ switch(op[0]){
794
+ case 0:
795
+ case 1:
796
+ t = op;
797
+ break;
798
+ case 4:
799
+ _.label++;
800
+ return {
801
+ value: op[1],
802
+ done: false
803
+ };
804
+ case 5:
805
+ _.label++;
806
+ y = op[1];
807
+ op = [
808
+ 0
809
+ ];
810
+ continue;
811
+ case 7:
812
+ op = _.ops.pop();
813
+ _.trys.pop();
814
+ continue;
815
+ default:
816
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
817
+ _ = 0;
818
+ continue;
819
+ }
820
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
821
+ _.label = op[1];
822
+ break;
823
+ }
824
+ if (op[0] === 6 && _.label < t[1]) {
825
+ _.label = t[1];
826
+ t = op;
827
+ break;
828
+ }
829
+ if (t && _.label < t[2]) {
830
+ _.label = t[2];
831
+ _.ops.push(op);
832
+ break;
833
+ }
834
+ if (t[2]) _.ops.pop();
835
+ _.trys.pop();
836
+ continue;
837
+ }
838
+ op = body.call(thisArg, _);
839
+ } catch (e) {
840
+ op = [
841
+ 6,
842
+ e
843
+ ];
844
+ y = 0;
845
+ } finally{
846
+ f = t = 0;
847
+ }
848
+ if (op[0] & 5) throw op[1];
849
+ return {
850
+ value: op[0] ? op[1] : void 0,
851
+ done: true
852
+ };
853
+ }
854
+ }
855
+ /**
856
+ * Provides the app's configured Discord OAuth client.
857
+ *
858
+ * Deliberately thinner than `CalcomOAuthApi`, which owns an access-token cache service and memoizes a
859
+ * token factory per user. Discord needs neither: the external-connection framework persists each
860
+ * user's credentials itself, so this api holds one client authenticated with the *application's*
861
+ * credentials and hands out the three calls that run through it.
862
+ *
863
+ * Note this is not the bot. The app acting as itself against Discord goes through `DiscordApi` and
864
+ * discord.js with a bot token; that token never reaches this client.
865
+ */ var DiscordOAuthApi = /*#__PURE__*/ function() {
866
+ function DiscordOAuthApi(config) {
867
+ _class_call_check$4(this, DiscordOAuthApi);
868
+ var _config_factoryConfig;
869
+ _define_property$4(this, "config", void 0);
870
+ _define_property$4(this, "discordOAuth", void 0);
871
+ this.config = config;
872
+ // asserted here rather than trusted: the config's credentials are optional to mirror the DISCORD_*
873
+ // variables they are read from, while the core factory requires both
874
+ var discordOAuthConfig = DiscordOAuthServiceConfig.assertedDiscordOAuthConfig(config);
875
+ this.discordOAuth = discordOAuthFactory((_config_factoryConfig = config.factoryConfig) !== null && _config_factoryConfig !== void 0 ? _config_factoryConfig : {})(discordOAuthConfig);
876
+ }
877
+ _create_class$3(DiscordOAuthApi, [
878
+ {
879
+ key: "oauthContext",
880
+ get: function get() {
881
+ return this.discordOAuth.oauthContext;
882
+ }
883
+ },
884
+ {
885
+ key: "clientId",
886
+ get: /**
887
+ * The OAuth client id the api authorizes as. Read from the context so there is a single source.
888
+ *
889
+ * @returns The configured Discord OAuth client id.
890
+ */ function get() {
891
+ return this.oauthContext.config.clientId;
892
+ }
893
+ },
894
+ {
895
+ key: "exchangeAuthorizationCode",
896
+ get: // MARK: Accessors
897
+ /**
898
+ * Configured pass-through for {@link exchangeAuthorizationCode}.
899
+ *
900
+ * @returns Function to exchange an OAuth authorization code for tokens.
901
+ */ function get() {
902
+ return exchangeAuthorizationCode(this.oauthContext);
903
+ }
904
+ },
905
+ {
906
+ key: "refreshAccessToken",
907
+ get: /**
908
+ * Configured pass-through for {@link refreshAccessToken}.
909
+ *
910
+ * @returns Function to refresh an access token using a stored refresh token.
911
+ */ function get() {
912
+ return refreshAccessToken(this.oauthContext);
913
+ }
914
+ },
915
+ {
916
+ key: "readCurrentUser",
917
+ get: /**
918
+ * Configured pass-through for {@link readCurrentUser}.
919
+ *
920
+ * Bearer-authenticated with the user's own access token, unlike the two token-endpoint calls above,
921
+ * which authenticate with the application's Basic credentials.
922
+ *
923
+ * @returns Function to read the Discord user an access token belongs to.
924
+ */ function get() {
925
+ return readCurrentUser(this.oauthContext);
926
+ }
927
+ },
928
+ {
929
+ /**
930
+ * Builds a {@link DiscordOAuthAuthorizeUrlFactory} for the app's client id.
931
+ *
932
+ * The redirect URI and scopes stay the caller's, since they are properties of the flow being
933
+ * mounted rather than of the client, but the client id comes from this api so a caller never has to
934
+ * read it out of the config itself.
935
+ *
936
+ * @param config - The redirect URI, requested scopes, and optional authorize URL override.
937
+ * @returns A factory composing the authorize URL to redirect a user's browser to.
938
+ */ key: "authorizeUrlFactory",
939
+ value: function authorizeUrlFactory(config) {
940
+ return discordOAuthAuthorizeUrlFactory(_object_spread_props$1(_object_spread$1({}, config), {
941
+ clientId: this.clientId
942
+ }));
943
+ }
944
+ },
945
+ {
946
+ key: "exchangeAuthorizationCodeToAccessToken",
947
+ value: /**
948
+ * Exchanges an OAuth authorization code and maps the response to a {@link DiscordAccessToken}.
949
+ *
950
+ * @param input - The authorization code and the exact redirect URI it was issued for.
951
+ * @returns The exchanged access token.
952
+ */ function exchangeAuthorizationCodeToAccessToken(input) {
953
+ return _async_to_generator$3(function() {
954
+ var response;
955
+ return _ts_generator$3(this, function(_state) {
956
+ switch(_state.label){
957
+ case 0:
958
+ return [
959
+ 4,
960
+ this.exchangeAuthorizationCode(input)
961
+ ];
962
+ case 1:
963
+ response = _state.sent();
964
+ return [
965
+ 2,
966
+ discordAccessTokenFromTokenResponse(response)
967
+ ];
968
+ }
969
+ });
970
+ }).call(this);
971
+ }
972
+ },
973
+ {
974
+ key: "refreshToAccessToken",
975
+ value: /**
976
+ * Refreshes an access token and maps the response to a {@link DiscordAccessToken}.
977
+ *
978
+ * The returned `refreshToken` is the one to persist: Discord's refresh responses carry a refresh
979
+ * token of their own, so storing whatever came back is correct whether or not it rotated.
980
+ *
981
+ * @param input - The stored refresh token.
982
+ * @returns The refreshed access token.
983
+ */ function refreshToAccessToken(input) {
984
+ return _async_to_generator$3(function() {
985
+ var response;
986
+ return _ts_generator$3(this, function(_state) {
987
+ switch(_state.label){
988
+ case 0:
989
+ return [
990
+ 4,
991
+ this.refreshAccessToken(input)
992
+ ];
993
+ case 1:
994
+ response = _state.sent();
995
+ return [
996
+ 2,
997
+ discordAccessTokenFromTokenResponse(response)
998
+ ];
999
+ }
1000
+ });
1001
+ }).call(this);
1002
+ }
1003
+ }
1004
+ ]);
1005
+ return DiscordOAuthApi;
1006
+ }();
1007
+ DiscordOAuthApi = __decorate([
1008
+ Injectable(),
1009
+ __param(0, Inject(DiscordOAuthServiceConfig))
1010
+ ], DiscordOAuthApi);
1011
+
1012
+ function _array_like_to_array(arr, len) {
1013
+ if (len == null || len > arr.length) len = arr.length;
1014
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1015
+ return arr2;
1016
+ }
1017
+ function _array_without_holes(arr) {
1018
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1019
+ }
1020
+ function _iterable_to_array(iter) {
1021
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1022
+ }
1023
+ function _non_iterable_spread() {
1024
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1025
+ }
1026
+ function _to_consumable_array(arr) {
1027
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1028
+ }
1029
+ function _unsupported_iterable_to_array(o, minLen) {
1030
+ if (!o) return;
1031
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
1032
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1033
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1034
+ if (n === "Map" || n === "Set") return Array.from(n);
1035
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1036
+ }
1037
+ /**
1038
+ * Convenience function used to generate ModuleMetadata for an app's DiscordOAuthModule.
1039
+ *
1040
+ * Takes no `dependencyModule`, unlike the Cal.com equivalent: {@link DiscordOAuthApi} depends only on
1041
+ * its own config, since Discord's connect flow needs no access-token cache service.
1042
+ *
1043
+ * @param config - The module metadata configuration including an optional config factory.
1044
+ * @returns NestJS ModuleMetadata for registering the DiscordOAuthModule.
1045
+ */ function appDiscordOAuthModuleMetadata(config) {
1046
+ var _config_discordOAuthServiceConfigFactory;
1047
+ var imports = config.imports, exports = config.exports, providers = config.providers;
1048
+ return {
1049
+ imports: [
1050
+ ConfigModule
1051
+ ].concat(_to_consumable_array(imports !== null && imports !== void 0 ? imports : [])),
1052
+ exports: [
1053
+ DiscordOAuthApi
1054
+ ].concat(_to_consumable_array(exports !== null && exports !== void 0 ? exports : [])),
1055
+ providers: [
1056
+ {
1057
+ provide: DiscordOAuthServiceConfig,
1058
+ inject: [
1059
+ ConfigService
1060
+ ],
1061
+ useFactory: (_config_discordOAuthServiceConfigFactory = config.discordOAuthServiceConfigFactory) !== null && _config_discordOAuthServiceConfigFactory !== void 0 ? _config_discordOAuthServiceConfigFactory : discordOAuthServiceConfigFactory
1062
+ },
1063
+ DiscordOAuthApi
1064
+ ].concat(_to_consumable_array(providers !== null && providers !== void 0 ? providers : []))
1065
+ };
1066
+ }
1067
+
1068
+ function _define_property$3(obj, key, value) {
1069
+ if (key in obj) {
1070
+ Object.defineProperty(obj, key, {
1071
+ value: value,
1072
+ enumerable: true,
1073
+ configurable: true,
1074
+ writable: true
1075
+ });
1076
+ } else {
1077
+ obj[key] = value;
1078
+ }
1079
+ return obj;
1080
+ }
1081
+ function _object_spread(target) {
1082
+ for(var i = 1; i < arguments.length; i++){
1083
+ var source = arguments[i] != null ? arguments[i] : {};
1084
+ var ownKeys = Object.keys(source);
1085
+ if (typeof Object.getOwnPropertySymbols === "function") {
1086
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1087
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1088
+ }));
1089
+ }
1090
+ ownKeys.forEach(function(key) {
1091
+ _define_property$3(target, key, source[key]);
1092
+ });
1093
+ }
1094
+ return target;
1095
+ }
1096
+ function ownKeys(object, enumerableOnly) {
1097
+ var keys = Object.keys(object);
1098
+ if (Object.getOwnPropertySymbols) {
1099
+ var symbols = Object.getOwnPropertySymbols(object);
1100
+ keys.push.apply(keys, symbols);
1101
+ }
1102
+ return keys;
1103
+ }
1104
+ function _object_spread_props(target, source) {
1105
+ source = source != null ? source : {};
1106
+ if (Object.getOwnPropertyDescriptors) {
1107
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1108
+ } else {
1109
+ ownKeys(Object(source)).forEach(function(key) {
1110
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1111
+ });
1112
+ }
1113
+ return target;
1114
+ }
1115
+ /**
1116
+ * Casts an untyped Discord interaction to a typed one.
1117
+ *
1118
+ * @param interaction - The raw interaction to cast.
1119
+ * @returns The interaction cast to the specified typed DiscordWebhookInteraction.
1120
+ */ function discordWebhookInteraction(interaction) {
1121
+ return interaction;
1122
+ }
1123
+ var discordInteractionHandlerFactory = handlerFactory(function(x) {
1124
+ return x.type;
1125
+ });
1126
+ var discordInteractionHandlerConfigurerFactory = handlerConfigurerFactory({
1127
+ configurerForAccessor: function configurerForAccessor(accessor) {
1128
+ var fnWithKey = handlerMappedSetFunctionFactory(accessor, discordWebhookInteraction);
1129
+ var configurer = _object_spread_props(_object_spread({}, accessor), {
1130
+ handleApplicationCommand: fnWithKey(InteractionType.ApplicationCommand),
1131
+ handleMessageComponent: fnWithKey(InteractionType.MessageComponent),
1132
+ handleModalSubmit: fnWithKey(InteractionType.ModalSubmit),
1133
+ handleAutocomplete: fnWithKey(InteractionType.ApplicationCommandAutocomplete)
1134
+ });
1135
+ return configurer;
1136
+ }
1137
+ });
1138
+
1139
+ function _class_call_check$3(instance, Constructor) {
1140
+ if (!(instance instanceof Constructor)) {
1141
+ throw new TypeError("Cannot call a class as a function");
1142
+ }
1143
+ }
1144
+ function _defineProperties$2(target, props) {
1145
+ for(var i = 0; i < props.length; i++){
1146
+ var descriptor = props[i];
1147
+ descriptor.enumerable = descriptor.enumerable || false;
1148
+ descriptor.configurable = true;
1149
+ if ("value" in descriptor) descriptor.writable = true;
1150
+ Object.defineProperty(target, descriptor.key, descriptor);
1151
+ }
1152
+ }
1153
+ function _create_class$2(Constructor, protoProps, staticProps) {
1154
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
1155
+ return Constructor;
1156
+ }
1157
+ function _define_property$2(obj, key, value) {
1158
+ if (key in obj) {
1159
+ Object.defineProperty(obj, key, {
1160
+ value: value,
1161
+ enumerable: true,
1162
+ configurable: true,
1163
+ writable: true
1164
+ });
1165
+ } else {
1166
+ obj[key] = value;
1167
+ }
1168
+ return obj;
1169
+ }
1170
+ /**
1171
+ * Default environment variable for the Discord application public key.
1172
+ */ var DISCORD_PUBLIC_KEY_ENV_VAR = 'DISCORD_PUBLIC_KEY';
1173
+ /**
1174
+ * The byte length of a Discord Ed25519 public key (32 bytes = 64 hex characters).
1175
+ */ var DISCORD_ED25519_PUBLIC_KEY_BYTE_LENGTH = 32;
1176
+ /**
1177
+ * Configuration for the DiscordWebhookService.
1178
+ */ var DiscordWebhookServiceConfig = /*#__PURE__*/ function() {
1179
+ function DiscordWebhookServiceConfig() {
1180
+ _class_call_check$3(this, DiscordWebhookServiceConfig);
1181
+ _define_property$2(this, "discordWebhook", void 0);
1182
+ }
1183
+ _create_class$2(DiscordWebhookServiceConfig, null, [
1184
+ {
1185
+ key: "assertValidConfig",
1186
+ value: function assertValidConfig(config) {
1187
+ var publicKey = config.discordWebhook.publicKey;
1188
+ if (!publicKey) {
1189
+ throw new Error('No Discord public key specified.');
1190
+ }
1191
+ if (!isHexWithByteLength(publicKey, {
1192
+ byteLength: DISCORD_ED25519_PUBLIC_KEY_BYTE_LENGTH
1193
+ })) {
1194
+ throw new Error('Discord public key is not available or is invalid. Expected a 64-character hex string (32-byte Ed25519 key).');
1195
+ }
1196
+ }
1197
+ }
1198
+ ]);
1199
+ return DiscordWebhookServiceConfig;
1200
+ }
1201
+ ();
1202
+
1203
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
1204
+ try {
1205
+ var info = gen[key](arg);
1206
+ var value = info.value;
1207
+ } catch (error) {
1208
+ reject(error);
1209
+ return;
1210
+ }
1211
+ if (info.done) {
1212
+ resolve(value);
1213
+ } else {
1214
+ Promise.resolve(value).then(_next, _throw);
1215
+ }
1216
+ }
1217
+ function _async_to_generator$2(fn) {
1218
+ return function() {
1219
+ var self = this, args = arguments;
1220
+ return new Promise(function(resolve, reject) {
1221
+ var gen = fn.apply(self, args);
1222
+ function _next(value) {
1223
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
1224
+ }
1225
+ function _throw(err) {
1226
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
1227
+ }
1228
+ _next(undefined);
1229
+ });
1230
+ };
1231
+ }
1232
+ function _ts_generator$2(thisArg, body) {
1233
+ var f, y, t, _ = {
1234
+ label: 0,
1235
+ sent: function() {
1236
+ if (t[0] & 1) throw t[1];
1237
+ return t[1];
1238
+ },
1239
+ trys: [],
1240
+ ops: []
1241
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1242
+ return d(g, "next", {
1243
+ value: verb(0)
1244
+ }), d(g, "throw", {
1245
+ value: verb(1)
1246
+ }), d(g, "return", {
1247
+ value: verb(2)
1248
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1249
+ value: function() {
1250
+ return this;
1251
+ }
1252
+ }), g;
1253
+ function verb(n) {
1254
+ return function(v) {
1255
+ return step([
1256
+ n,
1257
+ v
1258
+ ]);
1259
+ };
1260
+ }
1261
+ function step(op) {
1262
+ if (f) throw new TypeError("Generator is already executing.");
1263
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1264
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1265
+ if (y = 0, t) op = [
1266
+ op[0] & 2,
1267
+ t.value
1268
+ ];
1269
+ switch(op[0]){
1270
+ case 0:
1271
+ case 1:
1272
+ t = op;
1273
+ break;
1274
+ case 4:
1275
+ _.label++;
1276
+ return {
1277
+ value: op[1],
1278
+ done: false
1279
+ };
1280
+ case 5:
1281
+ _.label++;
1282
+ y = op[1];
1283
+ op = [
1284
+ 0
1285
+ ];
1286
+ continue;
1287
+ case 7:
1288
+ op = _.ops.pop();
1289
+ _.trys.pop();
1290
+ continue;
1291
+ default:
1292
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1293
+ _ = 0;
1294
+ continue;
1295
+ }
1296
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1297
+ _.label = op[1];
1298
+ break;
1299
+ }
1300
+ if (op[0] === 6 && _.label < t[1]) {
1301
+ _.label = t[1];
1302
+ t = op;
1303
+ break;
1304
+ }
1305
+ if (t && _.label < t[2]) {
1306
+ _.label = t[2];
1307
+ _.ops.push(op);
1308
+ break;
1309
+ }
1310
+ if (t[2]) _.ops.pop();
1311
+ _.trys.pop();
1312
+ continue;
1313
+ }
1314
+ op = body.call(thisArg, _);
1315
+ } catch (e) {
1316
+ op = [
1317
+ 6,
1318
+ e
1319
+ ];
1320
+ y = 0;
1321
+ } finally{
1322
+ f = t = 0;
1323
+ }
1324
+ if (op[0] & 5) throw op[1];
1325
+ return {
1326
+ value: op[0] ? op[1] : void 0,
1327
+ done: true
1328
+ };
1329
+ }
1330
+ }
1331
+ /**
1332
+ * Creates a verifier for Discord interaction webhook requests.
1333
+ *
1334
+ * Discord signs interaction webhook requests with Ed25519. The signed message is
1335
+ * the concatenation of the x-signature-timestamp header and the raw request body.
1336
+ * The signature is provided in the x-signature-ed25519 header as a hex string.
1337
+ *
1338
+ * Uses Node.js built-in crypto with JWK key import — no external dependencies required.
1339
+ *
1340
+ * @param config - Verification config containing the application's public key.
1341
+ * @returns A DiscordWebhookEventVerifier function that validates Ed25519-signed requests.
1342
+ *
1343
+ * @example
1344
+ * ```ts
1345
+ * const verifier = discordWebhookEventVerifier({ publicKey: 'your-hex-public-key' });
1346
+ * const result = await verifier(req, rawBody);
1347
+ *
1348
+ * if (result.valid) {
1349
+ * // result.body contains the parsed interaction
1350
+ * }
1351
+ * ```
1352
+ */ function discordWebhookEventVerifier(config) {
1353
+ var publicKeyHex = config.publicKey;
1354
+ // Import the raw 32-byte Ed25519 public key via JWK format.
1355
+ var publicKey = createPublicKey({
1356
+ key: {
1357
+ kty: 'OKP',
1358
+ crv: 'Ed25519',
1359
+ x: Buffer.from(publicKeyHex, 'hex').toString('base64url')
1360
+ },
1361
+ format: 'jwk'
1362
+ });
1363
+ return function(request, rawBody) {
1364
+ return _async_to_generator$2(function() {
1365
+ var signature, timestamp, result, message, signatureBuffer, valid, body;
1366
+ return _ts_generator$2(this, function(_state) {
1367
+ signature = request.headers['x-signature-ed25519'];
1368
+ timestamp = request.headers['x-signature-timestamp'];
1369
+ if (!signature || !timestamp) {
1370
+ result = {
1371
+ valid: false
1372
+ };
1373
+ } else {
1374
+ message = Buffer.concat([
1375
+ Buffer.from(timestamp),
1376
+ rawBody
1377
+ ]);
1378
+ signatureBuffer = Buffer.from(signature, 'hex');
1379
+ valid = false;
1380
+ try {
1381
+ valid = verify(null, message, publicKey, signatureBuffer);
1382
+ } catch (unused) {
1383
+ valid = false;
1384
+ }
1385
+ if (valid) {
1386
+ body = JSON.parse(rawBody.toString('utf-8'));
1387
+ result = {
1388
+ valid: true,
1389
+ body: body
1390
+ };
1391
+ } else {
1392
+ result = {
1393
+ valid: false
1394
+ };
1395
+ }
1396
+ }
1397
+ return [
1398
+ 2,
1399
+ result
1400
+ ];
1401
+ });
1402
+ })();
1403
+ };
1404
+ }
1405
+
1406
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1407
+ try {
1408
+ var info = gen[key](arg);
1409
+ var value = info.value;
1410
+ } catch (error) {
1411
+ reject(error);
1412
+ return;
1413
+ }
1414
+ if (info.done) {
1415
+ resolve(value);
1416
+ } else {
1417
+ Promise.resolve(value).then(_next, _throw);
1418
+ }
1419
+ }
1420
+ function _async_to_generator$1(fn) {
1421
+ return function() {
1422
+ var self = this, args = arguments;
1423
+ return new Promise(function(resolve, reject) {
1424
+ var gen = fn.apply(self, args);
1425
+ function _next(value) {
1426
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1427
+ }
1428
+ function _throw(err) {
1429
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1430
+ }
1431
+ _next(undefined);
1432
+ });
1433
+ };
1434
+ }
1435
+ function _class_call_check$2(instance, Constructor) {
1436
+ if (!(instance instanceof Constructor)) {
1437
+ throw new TypeError("Cannot call a class as a function");
1438
+ }
1439
+ }
1440
+ function _defineProperties$1(target, props) {
1441
+ for(var i = 0; i < props.length; i++){
1442
+ var descriptor = props[i];
1443
+ descriptor.enumerable = descriptor.enumerable || false;
1444
+ descriptor.configurable = true;
1445
+ if ("value" in descriptor) descriptor.writable = true;
1446
+ Object.defineProperty(target, descriptor.key, descriptor);
1447
+ }
1448
+ }
1449
+ function _create_class$1(Constructor, protoProps, staticProps) {
1450
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
1451
+ return Constructor;
1452
+ }
1453
+ function _define_property$1(obj, key, value) {
1454
+ if (key in obj) {
1455
+ Object.defineProperty(obj, key, {
1456
+ value: value,
1457
+ enumerable: true,
1458
+ configurable: true,
1459
+ writable: true
1460
+ });
1461
+ } else {
1462
+ obj[key] = value;
1463
+ }
1464
+ return obj;
1465
+ }
1466
+ function _ts_generator$1(thisArg, body) {
1467
+ var f, y, t, _ = {
1468
+ label: 0,
1469
+ sent: function() {
1470
+ if (t[0] & 1) throw t[1];
1471
+ return t[1];
1472
+ },
1473
+ trys: [],
1474
+ ops: []
1475
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1476
+ return d(g, "next", {
1477
+ value: verb(0)
1478
+ }), d(g, "throw", {
1479
+ value: verb(1)
1480
+ }), d(g, "return", {
1481
+ value: verb(2)
1482
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1483
+ value: function() {
1484
+ return this;
1485
+ }
1486
+ }), g;
1487
+ function verb(n) {
1488
+ return function(v) {
1489
+ return step([
1490
+ n,
1491
+ v
1492
+ ]);
1493
+ };
1494
+ }
1495
+ function step(op) {
1496
+ if (f) throw new TypeError("Generator is already executing.");
1497
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1498
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1499
+ if (y = 0, t) op = [
1500
+ op[0] & 2,
1501
+ t.value
1502
+ ];
1503
+ switch(op[0]){
1504
+ case 0:
1505
+ case 1:
1506
+ t = op;
1507
+ break;
1508
+ case 4:
1509
+ _.label++;
1510
+ return {
1511
+ value: op[1],
1512
+ done: false
1513
+ };
1514
+ case 5:
1515
+ _.label++;
1516
+ y = op[1];
1517
+ op = [
1518
+ 0
1519
+ ];
1520
+ continue;
1521
+ case 7:
1522
+ op = _.ops.pop();
1523
+ _.trys.pop();
1524
+ continue;
1525
+ default:
1526
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1527
+ _ = 0;
1528
+ continue;
1529
+ }
1530
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1531
+ _.label = op[1];
1532
+ break;
1533
+ }
1534
+ if (op[0] === 6 && _.label < t[1]) {
1535
+ _.label = t[1];
1536
+ t = op;
1537
+ break;
1538
+ }
1539
+ if (t && _.label < t[2]) {
1540
+ _.label = t[2];
1541
+ _.ops.push(op);
1542
+ break;
1543
+ }
1544
+ if (t[2]) _.ops.pop();
1545
+ _.trys.pop();
1546
+ continue;
1547
+ }
1548
+ op = body.call(thisArg, _);
1549
+ } catch (e) {
1550
+ op = [
1551
+ 6,
1552
+ e
1553
+ ];
1554
+ y = 0;
1555
+ } finally{
1556
+ f = t = 0;
1557
+ }
1558
+ if (op[0] & 5) throw op[1];
1559
+ return {
1560
+ value: op[0] ? op[1] : void 0,
1561
+ done: true
1562
+ };
1563
+ }
1564
+ }
1565
+ /**
1566
+ * Service that handles Discord interaction webhook events.
1567
+ *
1568
+ * Verifies incoming webhook signatures and dispatches interactions to registered handlers.
1569
+ */ var DiscordWebhookService = /*#__PURE__*/ function() {
1570
+ function DiscordWebhookService(discordWebhookServiceConfig) {
1571
+ _class_call_check$2(this, DiscordWebhookService);
1572
+ _define_property$1(this, "logger", new Logger('DiscordWebhookService'));
1573
+ _define_property$1(this, "_verifier", void 0);
1574
+ _define_property$1(this, "handler", discordInteractionHandlerFactory());
1575
+ _define_property$1(this, "configure", discordInteractionHandlerConfigurerFactory(this.handler));
1576
+ this._verifier = discordWebhookEventVerifier({
1577
+ publicKey: discordWebhookServiceConfig.discordWebhook.publicKey
1578
+ });
1579
+ }
1580
+ _create_class$1(DiscordWebhookService, [
1581
+ {
1582
+ key: "updateForWebhook",
1583
+ value: function updateForWebhook(req, rawBody) {
1584
+ return _async_to_generator$1(function() {
1585
+ var result;
1586
+ return _ts_generator$1(this, function(_state) {
1587
+ switch(_state.label){
1588
+ case 0:
1589
+ return [
1590
+ 4,
1591
+ this._verifier(req, rawBody)
1592
+ ];
1593
+ case 1:
1594
+ result = _state.sent();
1595
+ if (!result.valid) return [
1596
+ 3,
1597
+ 3
1598
+ ];
1599
+ return [
1600
+ 4,
1601
+ this.updateForDiscordInteraction(result.body)
1602
+ ];
1603
+ case 2:
1604
+ _state.sent();
1605
+ return [
1606
+ 3,
1607
+ 4
1608
+ ];
1609
+ case 3:
1610
+ this.logger.warn('Received invalid Discord interaction event.', req);
1611
+ _state.label = 4;
1612
+ case 4:
1613
+ return [
1614
+ 2
1615
+ ];
1616
+ }
1617
+ });
1618
+ }).call(this);
1619
+ }
1620
+ },
1621
+ {
1622
+ key: "updateForDiscordInteraction",
1623
+ value: function updateForDiscordInteraction(interaction) {
1624
+ return _async_to_generator$1(function() {
1625
+ var result;
1626
+ return _ts_generator$1(this, function(_state) {
1627
+ switch(_state.label){
1628
+ case 0:
1629
+ return [
1630
+ 4,
1631
+ this.handler(interaction)
1632
+ ];
1633
+ case 1:
1634
+ result = _state.sent();
1635
+ if (!result) {
1636
+ this.logger.warn('Received unexpected/unhandled Discord interaction.', interaction);
1637
+ }
1638
+ return [
1639
+ 2
1640
+ ];
1641
+ }
1642
+ });
1643
+ }).call(this);
1644
+ }
1645
+ }
1646
+ ]);
1647
+ return DiscordWebhookService;
1648
+ }();
1649
+ DiscordWebhookService = __decorate([
1650
+ Injectable(),
1651
+ __param(0, Inject(DiscordWebhookServiceConfig))
1652
+ ], DiscordWebhookService);
1653
+
1654
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1655
+ try {
1656
+ var info = gen[key](arg);
1657
+ var value = info.value;
1658
+ } catch (error) {
1659
+ reject(error);
1660
+ return;
1661
+ }
1662
+ if (info.done) {
1663
+ resolve(value);
1664
+ } else {
1665
+ Promise.resolve(value).then(_next, _throw);
1666
+ }
1667
+ }
1668
+ function _async_to_generator(fn) {
1669
+ return function() {
1670
+ var self = this, args = arguments;
1671
+ return new Promise(function(resolve, reject) {
1672
+ var gen = fn.apply(self, args);
1673
+ function _next(value) {
1674
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1675
+ }
1676
+ function _throw(err) {
1677
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1678
+ }
1679
+ _next(undefined);
1680
+ });
1681
+ };
1682
+ }
1683
+ function _class_call_check$1(instance, Constructor) {
1684
+ if (!(instance instanceof Constructor)) {
1685
+ throw new TypeError("Cannot call a class as a function");
1686
+ }
1687
+ }
1688
+ function _defineProperties(target, props) {
1689
+ for(var i = 0; i < props.length; i++){
1690
+ var descriptor = props[i];
1691
+ descriptor.enumerable = descriptor.enumerable || false;
1692
+ descriptor.configurable = true;
1693
+ if ("value" in descriptor) descriptor.writable = true;
1694
+ Object.defineProperty(target, descriptor.key, descriptor);
1695
+ }
1696
+ }
1697
+ function _create_class(Constructor, protoProps, staticProps) {
1698
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1699
+ return Constructor;
1700
+ }
1701
+ function _define_property(obj, key, value) {
1702
+ if (key in obj) {
1703
+ Object.defineProperty(obj, key, {
1704
+ value: value,
1705
+ enumerable: true,
1706
+ configurable: true,
1707
+ writable: true
1708
+ });
1709
+ } else {
1710
+ obj[key] = value;
1711
+ }
1712
+ return obj;
1713
+ }
1714
+ function _ts_generator(thisArg, body) {
1715
+ var f, y, t, _ = {
1716
+ label: 0,
1717
+ sent: function() {
1718
+ if (t[0] & 1) throw t[1];
1719
+ return t[1];
1720
+ },
1721
+ trys: [],
1722
+ ops: []
1723
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1724
+ return d(g, "next", {
1725
+ value: verb(0)
1726
+ }), d(g, "throw", {
1727
+ value: verb(1)
1728
+ }), d(g, "return", {
1729
+ value: verb(2)
1730
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1731
+ value: function() {
1732
+ return this;
1733
+ }
1734
+ }), g;
1735
+ function verb(n) {
1736
+ return function(v) {
1737
+ return step([
1738
+ n,
1739
+ v
1740
+ ]);
1741
+ };
1742
+ }
1743
+ function step(op) {
1744
+ if (f) throw new TypeError("Generator is already executing.");
1745
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1746
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1747
+ if (y = 0, t) op = [
1748
+ op[0] & 2,
1749
+ t.value
1750
+ ];
1751
+ switch(op[0]){
1752
+ case 0:
1753
+ case 1:
1754
+ t = op;
1755
+ break;
1756
+ case 4:
1757
+ _.label++;
1758
+ return {
1759
+ value: op[1],
1760
+ done: false
1761
+ };
1762
+ case 5:
1763
+ _.label++;
1764
+ y = op[1];
1765
+ op = [
1766
+ 0
1767
+ ];
1768
+ continue;
1769
+ case 7:
1770
+ op = _.ops.pop();
1771
+ _.trys.pop();
1772
+ continue;
1773
+ default:
1774
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1775
+ _ = 0;
1776
+ continue;
1777
+ }
1778
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1779
+ _.label = op[1];
1780
+ break;
1781
+ }
1782
+ if (op[0] === 6 && _.label < t[1]) {
1783
+ _.label = t[1];
1784
+ t = op;
1785
+ break;
1786
+ }
1787
+ if (t && _.label < t[2]) {
1788
+ _.label = t[2];
1789
+ _.ops.push(op);
1790
+ break;
1791
+ }
1792
+ if (t[2]) _.ops.pop();
1793
+ _.trys.pop();
1794
+ continue;
1795
+ }
1796
+ op = body.call(thisArg, _);
1797
+ } catch (e) {
1798
+ op = [
1799
+ 6,
1800
+ e
1801
+ ];
1802
+ y = 0;
1803
+ } finally{
1804
+ f = t = 0;
1805
+ }
1806
+ if (op[0] & 5) throw op[1];
1807
+ return {
1808
+ value: op[0] ? op[1] : void 0,
1809
+ done: true
1810
+ };
1811
+ }
1812
+ }
1813
+ var DiscordWebhookController = /*#__PURE__*/ function() {
1814
+ function DiscordWebhookController(discordWebhookService) {
1815
+ _class_call_check$1(this, DiscordWebhookController);
1816
+ _define_property(this, "_discordWebhookService", void 0);
1817
+ this._discordWebhookService = discordWebhookService;
1818
+ }
1819
+ _create_class(DiscordWebhookController, [
1820
+ {
1821
+ key: "handleDiscordWebhook",
1822
+ value: function handleDiscordWebhook(req, rawBody) {
1823
+ return _async_to_generator(function() {
1824
+ return _ts_generator(this, function(_state) {
1825
+ switch(_state.label){
1826
+ case 0:
1827
+ return [
1828
+ 4,
1829
+ this._discordWebhookService.updateForWebhook(req, rawBody)
1830
+ ];
1831
+ case 1:
1832
+ _state.sent();
1833
+ return [
1834
+ 2
1835
+ ];
1836
+ }
1837
+ });
1838
+ }).call(this);
1839
+ }
1840
+ }
1841
+ ]);
1842
+ return DiscordWebhookController;
1843
+ }();
1844
+ __decorate([
1845
+ Post(),
1846
+ __param(0, Req()),
1847
+ __param(1, RawBody())
1848
+ ], DiscordWebhookController.prototype, "handleDiscordWebhook", null);
1849
+ DiscordWebhookController = __decorate([
1850
+ Controller('/webhook/discord'),
1851
+ __param(0, Inject(DiscordWebhookService))
1852
+ ], DiscordWebhookController);
1853
+
1854
+ function _class_call_check(instance, Constructor) {
1855
+ if (!(instance instanceof Constructor)) {
1856
+ throw new TypeError("Cannot call a class as a function");
1857
+ }
1858
+ }
1859
+ /**
1860
+ * Factory that creates a DiscordWebhookServiceConfig from environment variables.
1861
+ *
1862
+ * @param configService - The NestJS config service used to read the Discord public key environment variable.
1863
+ * @returns A validated DiscordWebhookServiceConfig populated from environment variables.
1864
+ */ function discordWebhookServiceConfigFactory(configService) {
1865
+ var config = {
1866
+ discordWebhook: {
1867
+ publicKey: configService.get(DISCORD_PUBLIC_KEY_ENV_VAR)
1868
+ }
1869
+ };
1870
+ DiscordWebhookServiceConfig.assertValidConfig(config);
1871
+ return config;
1872
+ }
1873
+ /**
1874
+ * NestJS module that provides Discord interaction webhook handling.
1875
+ *
1876
+ * Standalone — does not depend on DiscordModule (no bot token needed).
1877
+ * Reads the application public key from the DISCORD_PUBLIC_KEY environment variable.
1878
+ */ var DiscordWebhookModule = function DiscordWebhookModule() {
1879
+ _class_call_check(this, DiscordWebhookModule);
1880
+ };
1881
+ DiscordWebhookModule = __decorate([
1882
+ Module({
1883
+ imports: [
1884
+ ConfigModule
1885
+ ],
1886
+ controllers: [
1887
+ DiscordWebhookController
1888
+ ],
1889
+ providers: [
1890
+ {
1891
+ provide: DiscordWebhookServiceConfig,
1892
+ inject: [
1893
+ ConfigService
1894
+ ],
1895
+ useFactory: discordWebhookServiceConfigFactory
1896
+ },
1897
+ DiscordWebhookService
1898
+ ],
1899
+ exports: [
1900
+ DiscordWebhookService
1901
+ ]
1902
+ })
1903
+ ], DiscordWebhookModule);
1904
+
1905
+ export { DEFAULT_DISCORD_INTENTS, DISCORD_BOT_TOKEN_ENV_VAR, DISCORD_BOT_TOKEN_PLACEHOLDER, DISCORD_CLIENT_ID_CONFIG_KEY, DISCORD_CLIENT_SECRET_CONFIG_KEY, DISCORD_ED25519_PUBLIC_KEY_BYTE_LENGTH, DISCORD_PUBLIC_KEY_ENV_VAR, DISCORD_SERVICE_NAME, DiscordApi, DiscordModule, DiscordOAuthApi, DiscordOAuthServiceConfig, DiscordServiceConfig, DiscordWebhookController, DiscordWebhookModule, DiscordWebhookService, DiscordWebhookServiceConfig, appDiscordOAuthModuleMetadata, discordClientOptionsWithIntents, discordDefaultClientOptions, discordInteractionHandlerConfigurerFactory, discordInteractionHandlerFactory, discordOAuthServiceConfigFactory, discordServiceConfigFactory, discordWebhookEventVerifier, discordWebhookInteraction, discordWebhookServiceConfigFactory, isUsableDiscordBotToken };