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