@dereekb/firebase-server 13.31.0 → 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 (80) hide show
  1. package/calcom/index.cjs.default.js +1 -0
  2. package/calcom/index.cjs.js +1451 -0
  3. package/calcom/index.cjs.mjs +2 -0
  4. package/calcom/index.d.ts +1 -0
  5. package/calcom/index.esm.js +1437 -0
  6. package/calcom/package.json +29 -0
  7. package/calcom/src/index.d.ts +1 -0
  8. package/calcom/src/lib/calcom.oauth.connection.cache.d.ts +49 -0
  9. package/calcom/src/lib/calcom.oauth.connection.config.d.ts +75 -0
  10. package/calcom/src/lib/calcom.oauth.connection.context.d.ts +84 -0
  11. package/calcom/src/lib/calcom.oauth.connection.controller.d.ts +18 -0
  12. package/calcom/src/lib/calcom.oauth.connection.module.d.ts +55 -0
  13. package/calcom/src/lib/calcom.oauth.connection.service.d.ts +33 -0
  14. package/calcom/src/lib/index.d.ts +6 -0
  15. package/discord/index.cjs.default.js +1 -0
  16. package/discord/index.cjs.js +761 -0
  17. package/discord/index.cjs.mjs +2 -0
  18. package/discord/index.d.ts +1 -0
  19. package/discord/index.esm.js +753 -0
  20. package/discord/package.json +29 -0
  21. package/discord/src/index.d.ts +1 -0
  22. package/discord/src/lib/discord.oauth.connection.config.d.ts +69 -0
  23. package/discord/src/lib/discord.oauth.connection.controller.d.ts +18 -0
  24. package/discord/src/lib/discord.oauth.connection.module.d.ts +39 -0
  25. package/discord/src/lib/discord.oauth.connection.service.d.ts +43 -0
  26. package/discord/src/lib/index.d.ts +4 -0
  27. package/index.cjs.js +14 -3
  28. package/index.esm.js +14 -3
  29. package/mailgun/package.json +9 -9
  30. package/mcp/package.json +11 -11
  31. package/model/index.cjs.js +11077 -6072
  32. package/model/index.esm.js +11020 -6081
  33. package/model/package.json +10 -9
  34. package/model/src/lib/index.d.ts +1 -0
  35. package/model/src/lib/mailgun/index.d.ts +1 -0
  36. package/model/src/lib/mailgun/notification.healthcheck.mailgun.d.ts +115 -0
  37. package/model/src/lib/notification/index.d.ts +2 -0
  38. package/model/src/lib/notification/notification.action.server.d.ts +42 -3
  39. package/model/src/lib/notification/notification.error.d.ts +31 -0
  40. package/model/src/lib/notification/notification.healthcheck.d.ts +39 -0
  41. package/model/src/lib/notification/notification.healthcheck.service.d.ts +118 -0
  42. package/model/src/lib/notification/notification.send.service.d.ts +22 -0
  43. package/model/src/lib/userexternalconnection/index.d.ts +8 -0
  44. package/model/src/lib/userexternalconnection/oauth/index.d.ts +7 -0
  45. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.config.d.ts +110 -0
  46. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.controller.d.ts +68 -0
  47. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.error.d.ts +29 -0
  48. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.refresh.d.ts +24 -0
  49. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.registry.d.ts +54 -0
  50. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.service.d.ts +216 -0
  51. package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.state.d.ts +114 -0
  52. package/model/src/lib/userexternalconnection/userexternalconnection.accessor.service.d.ts +111 -0
  53. package/model/src/lib/userexternalconnection/userexternalconnection.action.server.d.ts +172 -0
  54. package/model/src/lib/userexternalconnection/userexternalconnection.error.d.ts +44 -0
  55. package/model/src/lib/userexternalconnection/userexternalconnection.module.d.ts +129 -0
  56. package/model/src/lib/userexternalconnection/userexternalconnection.private.d.ts +192 -0
  57. package/model/src/lib/userexternalconnection/userexternalconnection.reader.service.d.ts +157 -0
  58. package/model/src/lib/userexternalconnection/userexternalconnection.refresh.service.d.ts +46 -0
  59. package/oidc/index.cjs.js +104 -78
  60. package/oidc/index.esm.js +104 -78
  61. package/oidc/package.json +10 -10
  62. package/package.json +24 -10
  63. package/src/lib/env/env.config.d.ts +15 -0
  64. package/src/lib/env/env.service.d.ts +7 -0
  65. package/src/lib/nest/env/env.service.d.ts +1 -0
  66. package/test/index.cjs.js +14 -2
  67. package/test/index.esm.js +15 -3
  68. package/test/package.json +11 -11
  69. package/test/src/lib/firebase/firebase.admin.auth.d.ts +1 -1
  70. package/twilio/package.json +8 -8
  71. package/zoho/README.md +8 -0
  72. package/zoho/index.cjs.js +1223 -33
  73. package/zoho/index.esm.js +1212 -36
  74. package/zoho/package.json +12 -9
  75. package/zoho/src/lib/index.d.ts +5 -0
  76. package/zoho/src/lib/zoho.oauth.connection.cache.d.ts +45 -0
  77. package/zoho/src/lib/zoho.oauth.connection.config.d.ts +80 -0
  78. package/zoho/src/lib/zoho.oauth.connection.controller.d.ts +18 -0
  79. package/zoho/src/lib/zoho.oauth.connection.module.d.ts +43 -0
  80. package/zoho/src/lib/zoho.oauth.connection.service.d.ts +107 -0
@@ -0,0 +1,753 @@
1
+ import { DISCORD_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE } from '@dereekb/firebase';
2
+ import { userExternalConnectionOAuthControllerPath, userExternalConnectionOAuthRoutesForGlobalRouteExclude, UserExternalConnectionOAuthServiceConfig, userExternalConnectionOAuthServiceConfigFactory, UserExternalConnectionStateCoder, UserExternalConnectionServerActions, UserExternalConnectionAccessor, AbstractUserExternalConnectionOAuthService, AbstractUserExternalConnectionOAuthController } from '@dereekb/firebase-server/model';
3
+ import { Injectable, Inject, Controller } from '@nestjs/common';
4
+ import { DISCORD_OAUTH_SCOPE_DELIMITER } from '@dereekb/discord';
5
+ import { DiscordOAuthApi } from '@dereekb/discord/nestjs';
6
+ import { ConfigModule } from '@nestjs/config';
7
+ import { FirebaseServerEnvService } from '@dereekb/firebase-server';
8
+
9
+ function _assert_this_initialized$2(self) {
10
+ if (self === void 0) {
11
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
12
+ }
13
+ return self;
14
+ }
15
+ function _call_super$2(_this, derived, args) {
16
+ derived = _get_prototype_of$2(derived);
17
+ return _possible_constructor_return$2(_this, _is_native_reflect_construct$2() ? Reflect.construct(derived, args || [], _get_prototype_of$2(_this).constructor) : derived.apply(_this, args));
18
+ }
19
+ function _class_call_check$2(instance, Constructor) {
20
+ if (!(instance instanceof Constructor)) {
21
+ throw new TypeError("Cannot call a class as a function");
22
+ }
23
+ }
24
+ function _define_property$2(obj, key, value) {
25
+ if (key in obj) {
26
+ Object.defineProperty(obj, key, {
27
+ value: value,
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true
31
+ });
32
+ } else {
33
+ obj[key] = value;
34
+ }
35
+ return obj;
36
+ }
37
+ function _get_prototype_of$2(o) {
38
+ _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
39
+ return o.__proto__ || Object.getPrototypeOf(o);
40
+ };
41
+ return _get_prototype_of$2(o);
42
+ }
43
+ function _inherits$2(subClass, superClass) {
44
+ if (typeof superClass !== "function" && superClass !== null) {
45
+ throw new TypeError("Super expression must either be null or a function");
46
+ }
47
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
48
+ constructor: {
49
+ value: subClass,
50
+ writable: true,
51
+ configurable: true
52
+ }
53
+ });
54
+ if (superClass) _set_prototype_of$2(subClass, superClass);
55
+ }
56
+ function _object_spread(target) {
57
+ for(var i = 1; i < arguments.length; i++){
58
+ var source = arguments[i] != null ? arguments[i] : {};
59
+ var ownKeys = Object.keys(source);
60
+ if (typeof Object.getOwnPropertySymbols === "function") {
61
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
62
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
63
+ }));
64
+ }
65
+ ownKeys.forEach(function(key) {
66
+ _define_property$2(target, key, source[key]);
67
+ });
68
+ }
69
+ return target;
70
+ }
71
+ function ownKeys(object, enumerableOnly) {
72
+ var keys = Object.keys(object);
73
+ if (Object.getOwnPropertySymbols) {
74
+ var symbols = Object.getOwnPropertySymbols(object);
75
+ keys.push.apply(keys, symbols);
76
+ }
77
+ return keys;
78
+ }
79
+ function _object_spread_props(target, source) {
80
+ source = source != null ? source : {};
81
+ if (Object.getOwnPropertyDescriptors) {
82
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
83
+ } else {
84
+ ownKeys(Object(source)).forEach(function(key) {
85
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
86
+ });
87
+ }
88
+ return target;
89
+ }
90
+ function _possible_constructor_return$2(self, call) {
91
+ if (call && (_type_of$3(call) === "object" || typeof call === "function")) {
92
+ return call;
93
+ }
94
+ return _assert_this_initialized$2(self);
95
+ }
96
+ function _set_prototype_of$2(o, p) {
97
+ _set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
98
+ o.__proto__ = p;
99
+ return o;
100
+ };
101
+ return _set_prototype_of$2(o, p);
102
+ }
103
+ function _type_of$3(obj) {
104
+ "@swc/helpers - typeof";
105
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
106
+ }
107
+ function _is_native_reflect_construct$2() {
108
+ try {
109
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
110
+ } catch (_) {}
111
+ return (_is_native_reflect_construct$2 = function() {
112
+ return !!result;
113
+ })();
114
+ }
115
+ /**
116
+ * Controller path the Discord external-connection OAuth endpoints are mounted at.
117
+ *
118
+ * Derived from the framework's path factory, the same expression the redirect URI and the
119
+ * global-prefix exclusion are built from, so the three cannot drift apart.
120
+ */ var DISCORD_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = userExternalConnectionOAuthControllerPath(DISCORD_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
121
+ /**
122
+ * Routes to exclude from an app's global API route prefix so the Discord callback controller stays
123
+ * mounted at `/oauth/discord/*`.
124
+ *
125
+ * Spread this into the `exclude` list of the app's `globalApiRoutePrefix` config, alongside
126
+ * `FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE`.
127
+ */ var DISCORD_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = userExternalConnectionOAuthRoutesForGlobalRouteExclude(DISCORD_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
128
+ /**
129
+ * The scopes requested when an app does not declare its own.
130
+ *
131
+ * Declared in code, deliberately NOT read from the environment: the set to request follows from what
132
+ * the integration actually does, so it is a property of the code rather than of a deployment.
133
+ *
134
+ * `identify` alone. It is the least-privilege scope that still makes a Discord connection meaningful
135
+ * — a token granted no scopes can do nothing — and it is what lets the connection be labeled with the
136
+ * account it belongs to. Excludes `email`, which is a real privilege escalation the label does not
137
+ * need, and `guilds` / `connections` / `bot`, which nothing here reads.
138
+ */ var DEFAULT_DISCORD_OAUTH_SCOPES = [
139
+ 'identify'
140
+ ];
141
+ /**
142
+ * Configuration for the {@link DiscordUserExternalConnectionOAuthService}.
143
+ *
144
+ * Extends the framework config with the one thing that is Discord's own — which scopes to request.
145
+ *
146
+ * The client credentials are NOT here: they belong to `DiscordOAuthServiceConfig` in
147
+ * `@dereekb/discord/nestjs`, and the service reads them through the injected `DiscordOAuthApi`.
148
+ */ var DiscordUserExternalConnectionOAuthServiceConfig = /*#__PURE__*/ function(UserExternalConnectionOAuthServiceConfig) {
149
+ _inherits$2(DiscordUserExternalConnectionOAuthServiceConfig, UserExternalConnectionOAuthServiceConfig);
150
+ function DiscordUserExternalConnectionOAuthServiceConfig() {
151
+ _class_call_check$2(this, DiscordUserExternalConnectionOAuthServiceConfig);
152
+ var _this;
153
+ _this = _call_super$2(this, DiscordUserExternalConnectionOAuthServiceConfig, arguments), _define_property$2(_this, "scopes", void 0);
154
+ return _this;
155
+ }
156
+ return DiscordUserExternalConnectionOAuthServiceConfig;
157
+ }(UserExternalConnectionOAuthServiceConfig);
158
+ /**
159
+ * Builds the Discord connect flow's configuration from the app's configured origins.
160
+ *
161
+ * Nothing here is read from the environment as a value: the redirect URI is derived from the app's
162
+ * OAuth origin plus the mounted controller path, and the return URLs from the app URL plus
163
+ * code-declared paths. The client credentials are read by `discordOAuthServiceConfigFactory` in
164
+ * `@dereekb/discord/nestjs`, so registering Discord adds no deployment configuration here.
165
+ *
166
+ * @param config - The env service, the return paths, and the optional scope override.
167
+ * @returns The validated service configuration.
168
+ */ function discordUserExternalConnectionOAuthServiceConfigFactory(config) {
169
+ var envService = config.envService, successPath = config.successPath, failurePath = config.failurePath, scopes = config.scopes;
170
+ var baseConfig = userExternalConnectionOAuthServiceConfigFactory({
171
+ envService: envService,
172
+ providerType: DISCORD_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE,
173
+ successPath: successPath,
174
+ failurePath: failurePath
175
+ });
176
+ return _object_spread_props(_object_spread({}, baseConfig), {
177
+ scopes: scopes !== null && scopes !== void 0 ? scopes : DEFAULT_DISCORD_OAUTH_SCOPES
178
+ });
179
+ }
180
+
181
+ function _type_of$2(obj) {
182
+ "@swc/helpers - typeof";
183
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
184
+ }
185
+ function __decorate(decorators, target, key, desc) {
186
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
187
+ if ((typeof Reflect === "undefined" ? "undefined" : _type_of$2(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
188
+ 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;
189
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
190
+ }
191
+ function __param(paramIndex, decorator) {
192
+ return function(target, key) {
193
+ decorator(target, key, paramIndex);
194
+ };
195
+ }
196
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
197
+ var e = new Error(message);
198
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
199
+ };
200
+
201
+ function _assert_this_initialized$1(self) {
202
+ if (self === void 0) {
203
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
204
+ }
205
+ return self;
206
+ }
207
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
208
+ try {
209
+ var info = gen[key](arg);
210
+ var value = info.value;
211
+ } catch (error) {
212
+ reject(error);
213
+ return;
214
+ }
215
+ if (info.done) {
216
+ resolve(value);
217
+ } else {
218
+ Promise.resolve(value).then(_next, _throw);
219
+ }
220
+ }
221
+ function _async_to_generator(fn) {
222
+ return function() {
223
+ var self = this, args = arguments;
224
+ return new Promise(function(resolve, reject) {
225
+ var gen = fn.apply(self, args);
226
+ function _next(value) {
227
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
228
+ }
229
+ function _throw(err) {
230
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
231
+ }
232
+ _next(undefined);
233
+ });
234
+ };
235
+ }
236
+ function _call_super$1(_this, derived, args) {
237
+ derived = _get_prototype_of$1(derived);
238
+ return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
239
+ }
240
+ function _class_call_check$1(instance, Constructor) {
241
+ if (!(instance instanceof Constructor)) {
242
+ throw new TypeError("Cannot call a class as a function");
243
+ }
244
+ }
245
+ function _defineProperties(target, props) {
246
+ for(var i = 0; i < props.length; i++){
247
+ var descriptor = props[i];
248
+ descriptor.enumerable = descriptor.enumerable || false;
249
+ descriptor.configurable = true;
250
+ if ("value" in descriptor) descriptor.writable = true;
251
+ Object.defineProperty(target, descriptor.key, descriptor);
252
+ }
253
+ }
254
+ function _create_class(Constructor, protoProps, staticProps) {
255
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
256
+ return Constructor;
257
+ }
258
+ function _define_property$1(obj, key, value) {
259
+ if (key in obj) {
260
+ Object.defineProperty(obj, key, {
261
+ value: value,
262
+ enumerable: true,
263
+ configurable: true,
264
+ writable: true
265
+ });
266
+ } else {
267
+ obj[key] = value;
268
+ }
269
+ return obj;
270
+ }
271
+ function _get_prototype_of$1(o) {
272
+ _get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
273
+ return o.__proto__ || Object.getPrototypeOf(o);
274
+ };
275
+ return _get_prototype_of$1(o);
276
+ }
277
+ function _inherits$1(subClass, superClass) {
278
+ if (typeof superClass !== "function" && superClass !== null) {
279
+ throw new TypeError("Super expression must either be null or a function");
280
+ }
281
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
282
+ constructor: {
283
+ value: subClass,
284
+ writable: true,
285
+ configurable: true
286
+ }
287
+ });
288
+ if (superClass) _set_prototype_of$1(subClass, superClass);
289
+ }
290
+ function _possible_constructor_return$1(self, call) {
291
+ if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
292
+ return call;
293
+ }
294
+ return _assert_this_initialized$1(self);
295
+ }
296
+ function _set_prototype_of$1(o, p) {
297
+ _set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
298
+ o.__proto__ = p;
299
+ return o;
300
+ };
301
+ return _set_prototype_of$1(o, p);
302
+ }
303
+ function _type_of$1(obj) {
304
+ "@swc/helpers - typeof";
305
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
306
+ }
307
+ function _is_native_reflect_construct$1() {
308
+ try {
309
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
310
+ } catch (_) {}
311
+ return (_is_native_reflect_construct$1 = function() {
312
+ return !!result;
313
+ })();
314
+ }
315
+ function _ts_generator(thisArg, body) {
316
+ var f, y, t, _ = {
317
+ label: 0,
318
+ sent: function() {
319
+ if (t[0] & 1) throw t[1];
320
+ return t[1];
321
+ },
322
+ trys: [],
323
+ ops: []
324
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
325
+ return d(g, "next", {
326
+ value: verb(0)
327
+ }), d(g, "throw", {
328
+ value: verb(1)
329
+ }), d(g, "return", {
330
+ value: verb(2)
331
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
332
+ value: function() {
333
+ return this;
334
+ }
335
+ }), g;
336
+ function verb(n) {
337
+ return function(v) {
338
+ return step([
339
+ n,
340
+ v
341
+ ]);
342
+ };
343
+ }
344
+ function step(op) {
345
+ if (f) throw new TypeError("Generator is already executing.");
346
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
347
+ 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;
348
+ if (y = 0, t) op = [
349
+ op[0] & 2,
350
+ t.value
351
+ ];
352
+ switch(op[0]){
353
+ case 0:
354
+ case 1:
355
+ t = op;
356
+ break;
357
+ case 4:
358
+ _.label++;
359
+ return {
360
+ value: op[1],
361
+ done: false
362
+ };
363
+ case 5:
364
+ _.label++;
365
+ y = op[1];
366
+ op = [
367
+ 0
368
+ ];
369
+ continue;
370
+ case 7:
371
+ op = _.ops.pop();
372
+ _.trys.pop();
373
+ continue;
374
+ default:
375
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
376
+ _ = 0;
377
+ continue;
378
+ }
379
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
380
+ _.label = op[1];
381
+ break;
382
+ }
383
+ if (op[0] === 6 && _.label < t[1]) {
384
+ _.label = t[1];
385
+ t = op;
386
+ break;
387
+ }
388
+ if (t && _.label < t[2]) {
389
+ _.label = t[2];
390
+ _.ops.push(op);
391
+ break;
392
+ }
393
+ if (t[2]) _.ops.pop();
394
+ _.trys.pop();
395
+ continue;
396
+ }
397
+ op = body.call(thisArg, _);
398
+ } catch (e) {
399
+ op = [
400
+ 6,
401
+ e
402
+ ];
403
+ y = 0;
404
+ } finally{
405
+ f = t = 0;
406
+ }
407
+ if (op[0] & 5) throw op[1];
408
+ return {
409
+ value: op[0] ? op[1] : void 0,
410
+ done: true
411
+ };
412
+ }
413
+ }
414
+ /**
415
+ * Maps an exchanged Discord token, plus the identity it belongs to, to the credentials stored on the
416
+ * private connection document.
417
+ *
418
+ * The `refreshToken` written here is the one the exchange returned. Discord's refresh responses carry
419
+ * a refresh token of their own, so persisting whatever came back is correct whether or not it rotated.
420
+ *
421
+ * @param input - The exchanged token and the resolved Discord user, when one could be read.
422
+ * @returns The credentials to store.
423
+ */ function discordUserExternalConnectionCredentials(input) {
424
+ var _currentUser_global_name;
425
+ var accessToken = input.accessToken, currentUser = input.currentUser;
426
+ var token = accessToken.accessToken, refreshToken = accessToken.refreshToken, expiresAt = accessToken.expiresAt, scope = accessToken.scope;
427
+ // split on the same delimiter the authorize request joins with, so the round trip stays symmetric
428
+ var scopes = scope ? scope.split(DISCORD_OAUTH_SCOPE_DELIMITER).filter(function(x) {
429
+ return x.length > 0;
430
+ }) : undefined;
431
+ return {
432
+ accessToken: token,
433
+ refreshToken: refreshToken,
434
+ tokenType: 'Bearer',
435
+ issuedAt: new Date().toISOString(),
436
+ expiresAt: expiresAt.toISOString(),
437
+ scopes: scopes,
438
+ externalAccountId: currentUser === null || currentUser === void 0 ? void 0 : currentUser.id,
439
+ // global_name is the user's chosen display name; username is the fallback for accounts that never
440
+ // migrated off the legacy username#discriminator pair
441
+ label: currentUser ? (_currentUser_global_name = currentUser.global_name) !== null && _currentUser_global_name !== void 0 ? _currentUser_global_name : currentUser.username : undefined
442
+ };
443
+ }
444
+ /**
445
+ * Discord's half of the external-connection authorization-code handoff.
446
+ *
447
+ * Everything else — resolving who is connecting, surfacing a refusal, persisting the credentials,
448
+ * choosing the redirect — is the framework's.
449
+ */ var DiscordUserExternalConnectionOAuthService = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthService) {
450
+ _inherits$1(DiscordUserExternalConnectionOAuthService, AbstractUserExternalConnectionOAuthService);
451
+ function DiscordUserExternalConnectionOAuthService(config, stateCoder, userExternalConnectionActions, userExternalConnectionAccessor, oauthApi) {
452
+ _class_call_check$1(this, DiscordUserExternalConnectionOAuthService);
453
+ var _this;
454
+ _this = _call_super$1(this, DiscordUserExternalConnectionOAuthService), _define_property$1(_this, "config", void 0), _define_property$1(_this, "stateCoder", void 0), _define_property$1(_this, "userExternalConnectionActions", void 0), _define_property$1(_this, "userExternalConnectionAccessor", void 0), _define_property$1(_this, "oauthApi", void 0), _define_property$1(_this, "authorizeUrlFactory", void 0);
455
+ _this.config = config;
456
+ _this.stateCoder = stateCoder;
457
+ _this.userExternalConnectionActions = userExternalConnectionActions;
458
+ _this.userExternalConnectionAccessor = userExternalConnectionAccessor;
459
+ _this.oauthApi = oauthApi;
460
+ var scopes = config.scopes, userExternalConnectionOAuth = config.userExternalConnectionOAuth;
461
+ // no clientId guard here, unlike the Cal.com equivalent: DiscordOAuthConfig requires both
462
+ // credentials, so DiscordOAuthApi cannot construct without a client id to authorize as
463
+ _this.authorizeUrlFactory = oauthApi.authorizeUrlFactory({
464
+ redirectUri: userExternalConnectionOAuth.redirectUri,
465
+ scopes: scopes
466
+ });
467
+ return _this;
468
+ }
469
+ _create_class(DiscordUserExternalConnectionOAuthService, [
470
+ {
471
+ key: "authorizeUrlForState",
472
+ value: function authorizeUrlForState(state) {
473
+ return this.authorizeUrlFactory({
474
+ state: state
475
+ });
476
+ }
477
+ },
478
+ {
479
+ key: "credentialsForAuthorizationCode",
480
+ value: function credentialsForAuthorizationCode(input) {
481
+ return _async_to_generator(function() {
482
+ var accessToken, currentUser, e;
483
+ return _ts_generator(this, function(_state) {
484
+ switch(_state.label){
485
+ case 0:
486
+ return [
487
+ 4,
488
+ this.oauthApi.exchangeAuthorizationCodeToAccessToken({
489
+ code: input.code,
490
+ redirectUri: input.redirectUri
491
+ })
492
+ ];
493
+ case 1:
494
+ accessToken = _state.sent();
495
+ _state.label = 2;
496
+ case 2:
497
+ _state.trys.push([
498
+ 2,
499
+ 4,
500
+ ,
501
+ 5
502
+ ]);
503
+ return [
504
+ 4,
505
+ this.oauthApi.readCurrentUser({
506
+ accessToken: accessToken.accessToken
507
+ })
508
+ ];
509
+ case 3:
510
+ currentUser = _state.sent();
511
+ return [
512
+ 3,
513
+ 5
514
+ ];
515
+ case 4:
516
+ e = _state.sent();
517
+ this.logger.warn('Connected Discord but could not read the identity to label the connection: ', e);
518
+ return [
519
+ 3,
520
+ 5
521
+ ];
522
+ case 5:
523
+ return [
524
+ 2,
525
+ discordUserExternalConnectionCredentials({
526
+ accessToken: accessToken,
527
+ currentUser: currentUser
528
+ })
529
+ ];
530
+ }
531
+ });
532
+ }).call(this);
533
+ }
534
+ },
535
+ {
536
+ key: "refreshCredentials",
537
+ value: function refreshCredentials(input) {
538
+ return _async_to_generator(function() {
539
+ var refreshToken, accessToken;
540
+ return _ts_generator(this, function(_state) {
541
+ switch(_state.label){
542
+ case 0:
543
+ refreshToken = input.credentials.refreshToken;
544
+ if (!refreshToken) {
545
+ throw new Error('DiscordUserExternalConnectionOAuthService.refreshCredentials: the stored credentials carry no refresh token.');
546
+ }
547
+ return [
548
+ 4,
549
+ this.oauthApi.refreshToAccessToken({
550
+ refreshToken: refreshToken
551
+ })
552
+ ];
553
+ case 1:
554
+ accessToken = _state.sent();
555
+ // deliberately no identity lookup here, unlike the code exchange: the label was resolved on connect
556
+ // and the framework's merge carries it forward, so spending a request to re-read an unchanged
557
+ // display name on every refresh would buy nothing.
558
+ return [
559
+ 2,
560
+ discordUserExternalConnectionCredentials({
561
+ accessToken: accessToken
562
+ })
563
+ ];
564
+ }
565
+ });
566
+ }).call(this);
567
+ }
568
+ }
569
+ ]);
570
+ return DiscordUserExternalConnectionOAuthService;
571
+ }(AbstractUserExternalConnectionOAuthService);
572
+ DiscordUserExternalConnectionOAuthService = __decorate([
573
+ Injectable(),
574
+ __param(0, Inject(DiscordUserExternalConnectionOAuthServiceConfig)),
575
+ __param(1, Inject(UserExternalConnectionStateCoder)),
576
+ __param(2, Inject(UserExternalConnectionServerActions)),
577
+ __param(3, Inject(UserExternalConnectionAccessor)),
578
+ __param(4, Inject(DiscordOAuthApi))
579
+ ], DiscordUserExternalConnectionOAuthService);
580
+
581
+ function _assert_this_initialized(self) {
582
+ if (self === void 0) {
583
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
584
+ }
585
+ return self;
586
+ }
587
+ function _call_super(_this, derived, args) {
588
+ derived = _get_prototype_of(derived);
589
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
590
+ }
591
+ function _class_call_check(instance, Constructor) {
592
+ if (!(instance instanceof Constructor)) {
593
+ throw new TypeError("Cannot call a class as a function");
594
+ }
595
+ }
596
+ function _define_property(obj, key, value) {
597
+ if (key in obj) {
598
+ Object.defineProperty(obj, key, {
599
+ value: value,
600
+ enumerable: true,
601
+ configurable: true,
602
+ writable: true
603
+ });
604
+ } else {
605
+ obj[key] = value;
606
+ }
607
+ return obj;
608
+ }
609
+ function _get_prototype_of(o) {
610
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
611
+ return o.__proto__ || Object.getPrototypeOf(o);
612
+ };
613
+ return _get_prototype_of(o);
614
+ }
615
+ function _inherits(subClass, superClass) {
616
+ if (typeof superClass !== "function" && superClass !== null) {
617
+ throw new TypeError("Super expression must either be null or a function");
618
+ }
619
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
620
+ constructor: {
621
+ value: subClass,
622
+ writable: true,
623
+ configurable: true
624
+ }
625
+ });
626
+ if (superClass) _set_prototype_of(subClass, superClass);
627
+ }
628
+ function _possible_constructor_return(self, call) {
629
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
630
+ return call;
631
+ }
632
+ return _assert_this_initialized(self);
633
+ }
634
+ function _set_prototype_of(o, p) {
635
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
636
+ o.__proto__ = p;
637
+ return o;
638
+ };
639
+ return _set_prototype_of(o, p);
640
+ }
641
+ function _type_of(obj) {
642
+ "@swc/helpers - typeof";
643
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
644
+ }
645
+ function _is_native_reflect_construct() {
646
+ try {
647
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
648
+ } catch (_) {}
649
+ return (_is_native_reflect_construct = function() {
650
+ return !!result;
651
+ })();
652
+ }
653
+ /**
654
+ * Endpoints for the Discord external-connection authorization-code handoff.
655
+ *
656
+ * Mounted at `/oauth/discord`, matching the Angular registry's default authorize path of
657
+ * `/oauth/<providerType>/authorize`. Hosting rewrites do not strip the path, so this prefix is the
658
+ * public path — but an app with a global API route prefix must ALSO exclude these routes from it via
659
+ * {@link DISCORD_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE}, or they land under
660
+ * that prefix instead and no longer match the redirect URI registered with Discord.
661
+ *
662
+ * The `authorize` and `callback` routes come from the base class, so this declares only where they
663
+ * mount and which service serves them.
664
+ */ var DiscordUserExternalConnectionOAuthController = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthController) {
665
+ _inherits(DiscordUserExternalConnectionOAuthController, AbstractUserExternalConnectionOAuthController);
666
+ function DiscordUserExternalConnectionOAuthController(oauthService) {
667
+ _class_call_check(this, DiscordUserExternalConnectionOAuthController);
668
+ var _this;
669
+ _this = _call_super(this, DiscordUserExternalConnectionOAuthController), _define_property(_this, "oauthService", void 0);
670
+ _this.oauthService = oauthService;
671
+ return _this;
672
+ }
673
+ return DiscordUserExternalConnectionOAuthController;
674
+ }(AbstractUserExternalConnectionOAuthController);
675
+ DiscordUserExternalConnectionOAuthController = __decorate([
676
+ Controller(DISCORD_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH),
677
+ __param(0, Inject(DiscordUserExternalConnectionOAuthService))
678
+ ], DiscordUserExternalConnectionOAuthController);
679
+
680
+ function _array_like_to_array(arr, len) {
681
+ if (len == null || len > arr.length) len = arr.length;
682
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
683
+ return arr2;
684
+ }
685
+ function _array_without_holes(arr) {
686
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
687
+ }
688
+ function _iterable_to_array(iter) {
689
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
690
+ }
691
+ function _non_iterable_spread() {
692
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
693
+ }
694
+ function _to_consumable_array(arr) {
695
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
696
+ }
697
+ function _unsupported_iterable_to_array(o, minLen) {
698
+ if (!o) return;
699
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
700
+ var n = Object.prototype.toString.call(o).slice(8, -1);
701
+ if (n === "Object" && o.constructor) n = o.constructor.name;
702
+ if (n === "Map" || n === "Set") return Array.from(n);
703
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
704
+ }
705
+ /**
706
+ * Convenience function used to generate ModuleMetadata for an app's Discord external-connection
707
+ * OAuth module.
708
+ *
709
+ * Opt-in, like the webhook module: importing the Discord OAuth module alone never mounts HTTP routes,
710
+ * so an app that only runs a Discord bot exposes no connect endpoints.
711
+ *
712
+ * The importing module must also supply `UserExternalConnectionServerActions` and
713
+ * `UserExternalConnectionStateCoder` — both exported by `appUserExternalConnectionModuleMetadata`,
714
+ * so pass that module in `imports`.
715
+ *
716
+ * @param config - The module metadata configuration.
717
+ * @returns NestJS ModuleMetadata mounting the Discord connect endpoints.
718
+ */ function appDiscordUserExternalConnectionOAuthModuleMetadata(config) {
719
+ var dependencyModule = config.dependencyModule, successPath = config.successPath, failurePath = config.failurePath, scopes = config.scopes, imports = config.imports, exports = config.exports, providers = config.providers;
720
+ var dependencyModuleImport = dependencyModule ? [
721
+ dependencyModule
722
+ ] : [];
723
+ return {
724
+ imports: [
725
+ ConfigModule
726
+ ].concat(_to_consumable_array(dependencyModuleImport), _to_consumable_array(imports !== null && imports !== void 0 ? imports : [])),
727
+ controllers: [
728
+ DiscordUserExternalConnectionOAuthController
729
+ ],
730
+ exports: [
731
+ DiscordUserExternalConnectionOAuthService
732
+ ].concat(_to_consumable_array(exports !== null && exports !== void 0 ? exports : [])),
733
+ providers: [
734
+ {
735
+ provide: DiscordUserExternalConnectionOAuthServiceConfig,
736
+ inject: [
737
+ FirebaseServerEnvService
738
+ ],
739
+ useFactory: function useFactory(envService) {
740
+ return discordUserExternalConnectionOAuthServiceConfigFactory({
741
+ envService: envService,
742
+ successPath: successPath,
743
+ failurePath: failurePath,
744
+ scopes: scopes
745
+ });
746
+ }
747
+ },
748
+ DiscordUserExternalConnectionOAuthService
749
+ ].concat(_to_consumable_array(providers !== null && providers !== void 0 ? providers : []))
750
+ };
751
+ }
752
+
753
+ export { DEFAULT_DISCORD_OAUTH_SCOPES, DISCORD_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH, DISCORD_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE, DiscordUserExternalConnectionOAuthController, DiscordUserExternalConnectionOAuthService, DiscordUserExternalConnectionOAuthServiceConfig, appDiscordUserExternalConnectionOAuthModuleMetadata, discordUserExternalConnectionCredentials, discordUserExternalConnectionOAuthServiceConfigFactory };