@dereekb/firebase-server 13.38.0 → 13.40.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 (41) hide show
  1. package/calcom/package.json +15 -15
  2. package/discord/package.json +15 -15
  3. package/mailgun/package.json +14 -14
  4. package/mcp/package.json +16 -16
  5. package/model/package.json +14 -14
  6. package/model/src/lib/notification/notification.module.d.ts +1 -1
  7. package/oidc/package.json +15 -15
  8. package/package.json +36 -45
  9. package/test/package.json +16 -16
  10. package/twilio/package.json +13 -13
  11. package/zoho/package.json +15 -15
  12. package/calcom/index.cjs.default.js +0 -1
  13. package/calcom/index.cjs.js +0 -1451
  14. package/calcom/index.cjs.mjs +0 -2
  15. package/discord/index.cjs.default.js +0 -1
  16. package/discord/index.cjs.js +0 -761
  17. package/discord/index.cjs.mjs +0 -2
  18. package/index.cjs.default.js +0 -1
  19. package/index.cjs.js +0 -14713
  20. package/index.cjs.mjs +0 -2
  21. package/mailgun/index.cjs.default.js +0 -1
  22. package/mailgun/index.cjs.js +0 -436
  23. package/mailgun/index.cjs.mjs +0 -2
  24. package/mcp/index.cjs.default.js +0 -1
  25. package/mcp/index.cjs.js +0 -8781
  26. package/mcp/index.cjs.mjs +0 -2
  27. package/model/index.cjs.default.js +0 -1
  28. package/model/index.cjs.js +0 -19965
  29. package/model/index.cjs.mjs +0 -2
  30. package/oidc/index.cjs.default.js +0 -1
  31. package/oidc/index.cjs.js +0 -8085
  32. package/oidc/index.cjs.mjs +0 -2
  33. package/test/index.cjs.default.js +0 -1
  34. package/test/index.cjs.js +0 -5728
  35. package/test/index.cjs.mjs +0 -2
  36. package/twilio/index.cjs.default.js +0 -1
  37. package/twilio/index.cjs.js +0 -404
  38. package/twilio/index.cjs.mjs +0 -2
  39. package/zoho/index.cjs.default.js +0 -1
  40. package/zoho/index.cjs.js +0 -1810
  41. package/zoho/index.cjs.mjs +0 -2
package/zoho/index.cjs.js DELETED
@@ -1,1810 +0,0 @@
1
- 'use strict';
2
-
3
- var firebase = require('@dereekb/firebase');
4
- var firebaseServer = require('@dereekb/firebase-server');
5
- var util = require('@dereekb/util');
6
- var nestjs = require('@dereekb/nestjs');
7
- var zoho = require('@dereekb/zoho');
8
- var model = require('@dereekb/firebase-server/model');
9
- var date = require('@dereekb/date');
10
- var common = require('@nestjs/common');
11
- var nestjs$1 = require('@dereekb/zoho/nestjs');
12
- var config = require('@nestjs/config');
13
-
14
- /**
15
- * {@link SystemState} type identifier for storing Zoho access tokens in Firestore.
16
- */ var ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = 'zoho_access_token';
17
- /**
18
- * Creates the embedded-token converter, encrypting the `accessToken` at rest.
19
- *
20
- * This is a factory rather than a module-level const because `firestoreEncryptedField` resolves and
21
- * validates the encryption key eagerly at construction — the secret must be known at runtime.
22
- *
23
- * ONLY `accessToken` is encrypted, deliberately. `firestoreEncryptedField` round-trips through
24
- * `JSON.stringify`/`JSON.parse`, so anything placed inside the encrypted blob loses its type — and
25
- * `expiresAt` is a `Date`. Encrypting the token string alone keeps every date outside the blob,
26
- * which is what lets {@link zohoAccessTokenSystemStateDataConverterFactory} keep filtering expired
27
- * entries without having to decrypt them first. Do not "improve" this by encrypting the whole
28
- * token object or the `tokens` array.
29
- *
30
- * Accepted trade-off: `key`, `scope`, `apiDomain`, `expiresIn` and `expiresAt` remain plaintext at
31
- * rest. None of them is a credential.
32
- *
33
- * @param config - The encryption configuration.
34
- * @returns The embedded token field converter.
35
- */ function zohoAccessTokenSystemStateEmbeddedTokenConverterFactory(config) {
36
- return firebase.firestoreSubObject({
37
- objectField: {
38
- fields: {
39
- key: firebase.firestoreString(),
40
- accessToken: firebaseServer.firestoreEncryptedField({
41
- secret: config.encryptionSecret,
42
- default: '',
43
- // This is a cache of ~1h tokens, so an undecryptable entry is a cache MISS, not an error.
44
- // The empty sentinel is dropped by the `tokens` filter, and the next Zoho call re-mints.
45
- // This is also what makes a rotated secret survivable here (unlike uecp/jwks).
46
- onDecodeFailure: function onDecodeFailure() {
47
- return '';
48
- }
49
- }),
50
- scope: firebase.firestoreString(),
51
- apiDomain: firebase.firestoreString(),
52
- expiresIn: firebase.firestoreNumber({
53
- default: 3600
54
- }),
55
- expiresAt: firebase.firestoreDate()
56
- }
57
- }
58
- });
59
- }
60
- /**
61
- * Firestore field converter for {@link ZohoAccessTokenSystemStateData}.
62
- *
63
- * Automatically filters out expired tokens on read and enforces uniqueness by service key.
64
- * Must be registered in the app's {@link SystemStateStoredDataConverterMap} under
65
- * the {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} key.
66
- */ /**
67
- * Builds the {@link ZohoAccessTokenSystemStateData} converter around a given embedded-token converter.
68
- *
69
- * Shared by the encrypted factory and the deprecated plaintext const so the array's expiry filter and
70
- * per-key dedup behavior can only ever be defined once.
71
- *
72
- * @param embeddedTokenConverter - The converter for each entry in the `tokens` array.
73
- * @returns The stored-data field converter.
74
- */ function zohoAccessTokenSystemStateDataConverterForEmbeddedTokenConverter(embeddedTokenConverter) {
75
- return firebase.firestoreSubObject({
76
- objectField: {
77
- fields: {
78
- tokens: firebase.firestoreObjectArray({
79
- firestoreField: embeddedTokenConverter,
80
- filterUnique: util.filterUniqueFunction(function(x) {
81
- return x.key;
82
- }),
83
- // `firestoreObjectArray` maps BEFORE it filters, so this runs on already-decoded entries.
84
- // The `accessToken` check is what drops an entry whose decryption failed (onDecodeFailure
85
- // leaves an empty string behind) — without it such an entry would surface as a token with
86
- // an empty secret rather than as a cache miss.
87
- filter: function filter(x) {
88
- return Boolean(x === null || x === void 0 ? void 0 : x.accessToken) && ((x === null || x === void 0 ? void 0 : x.expiresAt) ? !util.isPast(x.expiresAt) : true // filter out empty/expired values
89
- );
90
- }
91
- }),
92
- lat: firebase.firestoreDate({
93
- saveDefaultAsNow: true
94
- })
95
- }
96
- }
97
- });
98
- }
99
- /**
100
- * Creates the {@link ZohoAccessTokenSystemStateData} converter, encrypting each token's
101
- * `accessToken` at rest.
102
- *
103
- * Register the result in a SERVER-ONLY converter map under {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} —
104
- * see `systemStatePrivateFirestoreCollection()` in `@dereekb/firebase-server/model`. It must never be
105
- * registered in an app's client-shared `SystemStateStoredDataConverterMap`.
106
- *
107
- * @param config - The encryption configuration.
108
- * @returns The stored-data field converter.
109
- */ function zohoAccessTokenSystemStateDataConverterFactory(config) {
110
- return zohoAccessTokenSystemStateDataConverterForEmbeddedTokenConverter(zohoAccessTokenSystemStateEmbeddedTokenConverterFactory(config));
111
- }
112
- /**
113
- * Loads the {@link SystemStateDocument} that stores {@link ZohoAccessTokenSystemStateData},
114
- * using {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} as the document ID.
115
- *
116
- * @param accessor - The document accessor for the SystemState collection.
117
- * @returns The SystemState document for the Zoho access token data.
118
- *
119
- * @example
120
- * ```ts
121
- * const doc = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessor());
122
- * const data = await doc.snapshotData();
123
- * ```
124
- */ function loadZohoAccessTokenSystemState(accessor) {
125
- return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
126
- }
127
- // COMPAT: Deprecated aliases
128
- /**
129
- * @deprecated stores the access token in PLAINTEXT. Use
130
- * {@link zohoAccessTokenSystemStateEmbeddedTokenConverterFactory} instead, which encrypts it at rest.
131
- */ var zohoAccessTokenSystemStateEmbeddedTokenConverter = firebase.firestoreSubObject({
132
- objectField: {
133
- fields: {
134
- key: firebase.firestoreString(),
135
- accessToken: firebase.firestoreString(),
136
- scope: firebase.firestoreString(),
137
- apiDomain: firebase.firestoreString(),
138
- expiresIn: firebase.firestoreNumber({
139
- default: 3600
140
- }),
141
- expiresAt: firebase.firestoreDate()
142
- }
143
- }
144
- });
145
- /**
146
- * @deprecated stores access tokens in PLAINTEXT. Use {@link zohoAccessTokenSystemStateDataConverterFactory}
147
- * instead, and register it on a server-only SystemStatePrivate collection.
148
- */ var zohoAccessTokenSystemStateDataConverter = zohoAccessTokenSystemStateDataConverterForEmbeddedTokenConverter(zohoAccessTokenSystemStateEmbeddedTokenConverter);
149
-
150
- function _array_like_to_array$1(arr, len) {
151
- if (len == null || len > arr.length) len = arr.length;
152
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
153
- return arr2;
154
- }
155
- function _array_without_holes$1(arr) {
156
- if (Array.isArray(arr)) return _array_like_to_array$1(arr);
157
- }
158
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
159
- try {
160
- var info = gen[key](arg);
161
- var value = info.value;
162
- } catch (error) {
163
- reject(error);
164
- return;
165
- }
166
- if (info.done) {
167
- resolve(value);
168
- } else {
169
- Promise.resolve(value).then(_next, _throw);
170
- }
171
- }
172
- function _async_to_generator$2(fn) {
173
- return function() {
174
- var self = this, args = arguments;
175
- return new Promise(function(resolve, reject) {
176
- var gen = fn.apply(self, args);
177
- function _next(value) {
178
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
179
- }
180
- function _throw(err) {
181
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
182
- }
183
- _next(undefined);
184
- });
185
- };
186
- }
187
- function _define_property$5(obj, key, value) {
188
- if (key in obj) {
189
- Object.defineProperty(obj, key, {
190
- value: value,
191
- enumerable: true,
192
- configurable: true,
193
- writable: true
194
- });
195
- } else {
196
- obj[key] = value;
197
- }
198
- return obj;
199
- }
200
- function _iterable_to_array$1(iter) {
201
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
202
- }
203
- function _non_iterable_spread$1() {
204
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
205
- }
206
- function _object_spread$2(target) {
207
- for(var i = 1; i < arguments.length; i++){
208
- var source = arguments[i] != null ? arguments[i] : {};
209
- var ownKeys = Object.keys(source);
210
- if (typeof Object.getOwnPropertySymbols === "function") {
211
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
212
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
213
- }));
214
- }
215
- ownKeys.forEach(function(key) {
216
- _define_property$5(target, key, source[key]);
217
- });
218
- }
219
- return target;
220
- }
221
- function ownKeys$2(object, enumerableOnly) {
222
- var keys = Object.keys(object);
223
- if (Object.getOwnPropertySymbols) {
224
- var symbols = Object.getOwnPropertySymbols(object);
225
- keys.push.apply(keys, symbols);
226
- }
227
- return keys;
228
- }
229
- function _object_spread_props$2(target, source) {
230
- source = source != null ? source : {};
231
- if (Object.getOwnPropertyDescriptors) {
232
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
233
- } else {
234
- ownKeys$2(Object(source)).forEach(function(key) {
235
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
236
- });
237
- }
238
- return target;
239
- }
240
- function _to_consumable_array$1(arr) {
241
- return _array_without_holes$1(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread$1();
242
- }
243
- function _unsupported_iterable_to_array$1(o, minLen) {
244
- if (!o) return;
245
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
246
- var n = Object.prototype.toString.call(o).slice(8, -1);
247
- if (n === "Object" && o.constructor) n = o.constructor.name;
248
- if (n === "Map" || n === "Set") return Array.from(n);
249
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
250
- }
251
- function _ts_generator$2(thisArg, body) {
252
- var f, y, t, _ = {
253
- label: 0,
254
- sent: function() {
255
- if (t[0] & 1) throw t[1];
256
- return t[1];
257
- },
258
- trys: [],
259
- ops: []
260
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
261
- return d(g, "next", {
262
- value: verb(0)
263
- }), d(g, "throw", {
264
- value: verb(1)
265
- }), d(g, "return", {
266
- value: verb(2)
267
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
268
- value: function() {
269
- return this;
270
- }
271
- }), g;
272
- function verb(n) {
273
- return function(v) {
274
- return step([
275
- n,
276
- v
277
- ]);
278
- };
279
- }
280
- function step(op) {
281
- if (f) throw new TypeError("Generator is already executing.");
282
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
283
- 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;
284
- if (y = 0, t) op = [
285
- op[0] & 2,
286
- t.value
287
- ];
288
- switch(op[0]){
289
- case 0:
290
- case 1:
291
- t = op;
292
- break;
293
- case 4:
294
- _.label++;
295
- return {
296
- value: op[1],
297
- done: false
298
- };
299
- case 5:
300
- _.label++;
301
- y = op[1];
302
- op = [
303
- 0
304
- ];
305
- continue;
306
- case 7:
307
- op = _.ops.pop();
308
- _.trys.pop();
309
- continue;
310
- default:
311
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
312
- _ = 0;
313
- continue;
314
- }
315
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
316
- _.label = op[1];
317
- break;
318
- }
319
- if (op[0] === 6 && _.label < t[1]) {
320
- _.label = t[1];
321
- t = op;
322
- break;
323
- }
324
- if (t && _.label < t[2]) {
325
- _.label = t[2];
326
- _.ops.push(op);
327
- break;
328
- }
329
- if (t[2]) _.ops.pop();
330
- _.trys.pop();
331
- continue;
332
- }
333
- op = body.call(thisArg, _);
334
- } catch (e) {
335
- op = [
336
- 6,
337
- e
338
- ];
339
- y = 0;
340
- } finally{
341
- f = t = 0;
342
- }
343
- if (op[0] & 5) throw op[1];
344
- return {
345
- value: op[0] ? op[1] : void 0,
346
- done: true
347
- };
348
- }
349
- }
350
- /**
351
- * Creates a {@link ZohoAccountsAccessTokenCacheService} backed by Firestore {@link SystemState} documents.
352
- *
353
- * Each Zoho service integration gets its own cached access token entry keyed by the service key.
354
- * Tokens are stored in a single {@link SystemState} document (type {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE})
355
- * and token updates/clears use Firestore transactions for concurrency safety.
356
- *
357
- * The access token is a credential, so pass a SERVER-ONLY collection — a
358
- * `systemStatePrivateFirestoreCollection()` from `@dereekb/firebase-server/model`, whose converter
359
- * map registers {@link zohoAccessTokenSystemStateDataConverterFactory} and encrypts the token at
360
- * rest. Passing an app's client-shared `systemStateCollection` still type-checks (for backwards
361
- * compatibility) but requires the converter to be registered in the client-shared map, which drags
362
- * `@dereekb/firebase-server` into browser builds.
363
- *
364
- * @param systemStateCollection - The Firestore collection for system state documents.
365
- * @returns A cache service backed by Firestore system state documents.
366
- *
367
- * @example
368
- * ```ts
369
- * const cacheService = firebaseZohoAccountsAccessTokenCacheService(systemStatePrivateCollection);
370
- * const cache = cacheService.loadZohoAccessTokenCache('my-zoho-service');
371
- * const token = await cache.loadCachedToken();
372
- * ```
373
- */ function firebaseZohoAccountsAccessTokenCacheService(systemStateCollection) {
374
- var systemStateDocumentAccessor = systemStateCollection.documentAccessor();
375
- var service = {
376
- loadZohoAccessTokenCache: function loadZohoAccessTokenCache(serviceKey) {
377
- var cache = {
378
- loadCachedToken: function loadCachedToken() {
379
- return _async_to_generator$2(function() {
380
- var document, existingData, result, tokensArray;
381
- return _ts_generator$2(this, function(_state) {
382
- switch(_state.label){
383
- case 0:
384
- document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
385
- return [
386
- 4,
387
- document.snapshotData()
388
- ];
389
- case 1:
390
- existingData = _state.sent();
391
- result = null;
392
- if (existingData != null) {
393
- tokensArray = existingData.data.tokens;
394
- result = tokensArray.find(function(x) {
395
- return x.key === serviceKey;
396
- });
397
- }
398
- return [
399
- 2,
400
- result
401
- ];
402
- }
403
- });
404
- })();
405
- },
406
- updateCachedToken: function updateCachedToken(accessToken) {
407
- return _async_to_generator$2(function() {
408
- return _ts_generator$2(this, function(_state) {
409
- switch(_state.label){
410
- case 0:
411
- // run in a transaction
412
- return [
413
- 4,
414
- systemStateCollection.firestoreContext.runTransaction(function(transaction) {
415
- return _async_to_generator$2(function() {
416
- var _ref, documentInTransaction, existingData, existingTokens, tokens, templateOrUpdate;
417
- return _ts_generator$2(this, function(_state) {
418
- switch(_state.label){
419
- case 0:
420
- documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
421
- return [
422
- 4,
423
- documentInTransaction.snapshotData()
424
- ];
425
- case 1:
426
- existingData = _state.sent();
427
- existingTokens = (_ref = existingData === null || existingData === void 0 ? void 0 : existingData.data.tokens) !== null && _ref !== void 0 ? _ref : [];
428
- tokens = // filter any potential old token for this service key
429
- _to_consumable_array$1(existingTokens.filter(function(x) {
430
- return x.key !== serviceKey;
431
- })).concat([
432
- // add the new token
433
- _object_spread_props$2(_object_spread$2({}, accessToken), {
434
- key: serviceKey
435
- })
436
- ]);
437
- templateOrUpdate = {
438
- data: {
439
- tokens: tokens,
440
- lat: new Date()
441
- }
442
- };
443
- if (!existingData) return [
444
- 3,
445
- 3
446
- ];
447
- return [
448
- 4,
449
- documentInTransaction.update(templateOrUpdate)
450
- ];
451
- case 2:
452
- _state.sent();
453
- return [
454
- 3,
455
- 5
456
- ];
457
- case 3:
458
- return [
459
- 4,
460
- documentInTransaction.create(templateOrUpdate)
461
- ];
462
- case 4:
463
- _state.sent();
464
- _state.label = 5;
465
- case 5:
466
- return [
467
- 2
468
- ];
469
- }
470
- });
471
- })();
472
- })
473
- ];
474
- case 1:
475
- _state.sent();
476
- return [
477
- 2
478
- ];
479
- }
480
- });
481
- })();
482
- },
483
- clearCachedToken: function clearCachedToken() {
484
- return _async_to_generator$2(function() {
485
- return _ts_generator$2(this, function(_state) {
486
- switch(_state.label){
487
- case 0:
488
- return [
489
- 4,
490
- systemStateCollection.firestoreContext.runTransaction(function(transaction) {
491
- return _async_to_generator$2(function() {
492
- var documentInTransaction, existingData, templateOrUpdate;
493
- return _ts_generator$2(this, function(_state) {
494
- switch(_state.label){
495
- case 0:
496
- documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
497
- return [
498
- 4,
499
- documentInTransaction.snapshotData()
500
- ];
501
- case 1:
502
- existingData = _state.sent();
503
- templateOrUpdate = {
504
- data: {
505
- tokens: [],
506
- lat: new Date()
507
- }
508
- };
509
- if (!existingData) return [
510
- 3,
511
- 3
512
- ];
513
- return [
514
- 4,
515
- documentInTransaction.update(templateOrUpdate)
516
- ];
517
- case 2:
518
- _state.sent();
519
- _state.label = 3;
520
- case 3:
521
- return [
522
- 2
523
- ];
524
- }
525
- });
526
- })();
527
- })
528
- ];
529
- case 1:
530
- _state.sent();
531
- return [
532
- 2
533
- ];
534
- }
535
- });
536
- })();
537
- }
538
- };
539
- return cache;
540
- }
541
- };
542
- return service;
543
- }
544
-
545
- function _define_property$4(obj, key, value) {
546
- if (key in obj) {
547
- Object.defineProperty(obj, key, {
548
- value: value,
549
- enumerable: true,
550
- configurable: true,
551
- writable: true
552
- });
553
- } else {
554
- obj[key] = value;
555
- }
556
- return obj;
557
- }
558
- // MARK: Environment Variable Keys
559
- /**
560
- * Environment variable name for the Zoho access token cache encryption secret
561
- * (hex-encoded AES-256 key).
562
- *
563
- * There is NO key rotation — `firestoreEncryptedField` resolves and validates the key once at
564
- * converter construction and closes over it. Unlike the `uecp` and `oidcJwksKey` secrets, however,
565
- * rotating this one is SURVIVABLE: the Zoho converter supplies an `onDecodeFailure` handler, so
566
- * every entry written under the old key simply degrades to a cache miss and the next Zoho call
567
- * re-mints a token. Rotation costs one extra token request per service key, not an outage.
568
- */ var ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET_ENV_KEY = 'ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET';
569
- /**
570
- * Deterministic secret used when running in a testing environment and no real secret is configured,
571
- * so specs never need a live credential.
572
- *
573
- * Deliberately distinct from the OIDC JWKS and UserExternalConnection testing secrets so a leaked
574
- * emulator blob is attributable. ("Zoho Access Token Cache Test Key", hex-encoded.)
575
- */ var TESTING_ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET = '5a6f686f2041636365737320546f6b656e2043616368652054657374204b6579';
576
- // MARK: Config
577
- /**
578
- * Reads the Zoho access token encryption secret from the environment.
579
- *
580
- * @param configService - The Nest config service used to read the encryption secret.
581
- * @param envService - Used to detect a testing environment for the secret fallback.
582
- * @returns The validated encryption secret.
583
- * @throws {Error} When the configured secret is invalid outside a testing environment.
584
- */ function zohoAccessTokenEncryptionSecretFactory(configService, envService) {
585
- var _configService_get;
586
- var encryptionSecret = (_configService_get = configService.get(ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET_ENV_KEY)) !== null && _configService_get !== void 0 ? _configService_get : '';
587
- if (!nestjs.isValidAES256GCMEncryptionSecret(encryptionSecret)) {
588
- if (envService.isTestingEnv) {
589
- encryptionSecret = TESTING_ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET;
590
- } else {
591
- throw new Error("zohoAccessTokenEncryptionSecretFactory: The secret provided by ".concat(ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET_ENV_KEY, " is not valid. Expected a 64-character hexadecimal string."));
592
- }
593
- }
594
- return encryptionSecret;
595
- }
596
- // MARK: Converter Map Entry
597
- /**
598
- * Builds the converter map entry for the Zoho access token cache, for use in a SERVER-ONLY
599
- * SystemState converter map.
600
- *
601
- * @param config - The encryption configuration.
602
- * @returns A partial converter map containing only the Zoho access token entry.
603
- *
604
- * @example
605
- * ```typescript
606
- * const collections = systemStatePrivateFirestoreCollection({
607
- * firestoreContext,
608
- * converters: {
609
- * ...zohoAccessTokenSystemStatePrivateConverterEntry({ encryptionSecret })
610
- * }
611
- * });
612
- * ```
613
- */ function zohoAccessTokenSystemStatePrivateConverterEntry(config) {
614
- return _define_property$4({}, ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE, zohoAccessTokenSystemStateDataConverterFactory(config));
615
- }
616
-
617
- function _type_of$3(obj) {
618
- "@swc/helpers - typeof";
619
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
620
- }
621
- function __decorate(decorators, target, key, desc) {
622
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
623
- if ((typeof Reflect === "undefined" ? "undefined" : _type_of$3(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
624
- 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;
625
- return c > 3 && r && Object.defineProperty(target, key, r), r;
626
- }
627
- function __param(paramIndex, decorator) {
628
- return function(target, key) {
629
- decorator(target, key, paramIndex);
630
- };
631
- }
632
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
633
- var e = new Error(message);
634
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
635
- };
636
-
637
- function _assert_this_initialized$2(self) {
638
- if (self === void 0) {
639
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
640
- }
641
- return self;
642
- }
643
- function _call_super$2(_this, derived, args) {
644
- derived = _get_prototype_of$2(derived);
645
- 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));
646
- }
647
- function _class_call_check$2(instance, Constructor) {
648
- if (!(instance instanceof Constructor)) {
649
- throw new TypeError("Cannot call a class as a function");
650
- }
651
- }
652
- function _define_property$3(obj, key, value) {
653
- if (key in obj) {
654
- Object.defineProperty(obj, key, {
655
- value: value,
656
- enumerable: true,
657
- configurable: true,
658
- writable: true
659
- });
660
- } else {
661
- obj[key] = value;
662
- }
663
- return obj;
664
- }
665
- function _get_prototype_of$2(o) {
666
- _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
667
- return o.__proto__ || Object.getPrototypeOf(o);
668
- };
669
- return _get_prototype_of$2(o);
670
- }
671
- function _inherits$2(subClass, superClass) {
672
- if (typeof superClass !== "function" && superClass !== null) {
673
- throw new TypeError("Super expression must either be null or a function");
674
- }
675
- subClass.prototype = Object.create(superClass && superClass.prototype, {
676
- constructor: {
677
- value: subClass,
678
- writable: true,
679
- configurable: true
680
- }
681
- });
682
- if (superClass) _set_prototype_of$2(subClass, superClass);
683
- }
684
- function _object_spread$1(target) {
685
- for(var i = 1; i < arguments.length; i++){
686
- var source = arguments[i] != null ? arguments[i] : {};
687
- var ownKeys = Object.keys(source);
688
- if (typeof Object.getOwnPropertySymbols === "function") {
689
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
690
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
691
- }));
692
- }
693
- ownKeys.forEach(function(key) {
694
- _define_property$3(target, key, source[key]);
695
- });
696
- }
697
- return target;
698
- }
699
- function ownKeys$1(object, enumerableOnly) {
700
- var keys = Object.keys(object);
701
- if (Object.getOwnPropertySymbols) {
702
- var symbols = Object.getOwnPropertySymbols(object);
703
- keys.push.apply(keys, symbols);
704
- }
705
- return keys;
706
- }
707
- function _object_spread_props$1(target, source) {
708
- source = source != null ? source : {};
709
- if (Object.getOwnPropertyDescriptors) {
710
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
711
- } else {
712
- ownKeys$1(Object(source)).forEach(function(key) {
713
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
714
- });
715
- }
716
- return target;
717
- }
718
- function _possible_constructor_return$2(self, call) {
719
- if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
720
- return call;
721
- }
722
- return _assert_this_initialized$2(self);
723
- }
724
- function _set_prototype_of$2(o, p) {
725
- _set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
726
- o.__proto__ = p;
727
- return o;
728
- };
729
- return _set_prototype_of$2(o, p);
730
- }
731
- function _type_of$2(obj) {
732
- "@swc/helpers - typeof";
733
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
734
- }
735
- function _is_native_reflect_construct$2() {
736
- try {
737
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
738
- } catch (_) {}
739
- return (_is_native_reflect_construct$2 = function() {
740
- return !!result;
741
- })();
742
- }
743
- /**
744
- * Controller path the Zoho external-connection OAuth endpoints are mounted at.
745
- *
746
- * Derived from the framework's path factory, the same expression the redirect URI and the
747
- * global-prefix exclusion are built from, so the three cannot drift apart.
748
- */ var ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = model.userExternalConnectionOAuthControllerPath(firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
749
- /**
750
- * Routes to exclude from an app's global API route prefix so the Zoho callback controller stays
751
- * mounted at `/oauth/zoho/*`.
752
- *
753
- * Spread this into the `exclude` list of the app's `globalApiRoutePrefix` config, alongside
754
- * `FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE`.
755
- */ var ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = model.userExternalConnectionOAuthRoutesForGlobalRouteExclude(firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
756
- /**
757
- * The scopes requested when an app does not declare its own.
758
- *
759
- * Declared in code, deliberately NOT read from the environment: the set to request follows from what
760
- * the integration actually does, so it belongs where it is reviewable.
761
- *
762
- * Least privilege for a connect that proves the handoff and labels the connection: read the
763
- * authorizing user's Zoho identity, and nothing else. No `ZohoCRM.*` / `ZohoRecruit.*` scope is
764
- * requested because the default integration makes no product API call — requesting one would be
765
- * privilege the code never uses, which is the same error as under-requesting, in the other
766
- * direction. An app that actually calls a Zoho product declares its own set on the module metadata,
767
- * in code.
768
- *
769
- * Unlike Cal.com, Zoho does not pre-register scopes on the OAuth client, so nothing has to be
770
- * registered in the API console to request this.
771
- */ var DEFAULT_ZOHO_OAUTH_SCOPES = [
772
- zoho.ZOHO_ACCOUNTS_PROFILE_READ_SCOPE
773
- ];
774
- /**
775
- * Configuration for the {@link ZohoUserExternalConnectionOAuthService}.
776
- *
777
- * Extends the framework config with what is Zoho's own: which scopes to request, and which
778
- * datacenter to authorize against.
779
- */ var ZohoUserExternalConnectionOAuthServiceConfig = /*#__PURE__*/ function(UserExternalConnectionOAuthServiceConfig) {
780
- _inherits$2(ZohoUserExternalConnectionOAuthServiceConfig, UserExternalConnectionOAuthServiceConfig);
781
- function ZohoUserExternalConnectionOAuthServiceConfig() {
782
- _class_call_check$2(this, ZohoUserExternalConnectionOAuthServiceConfig);
783
- var _this;
784
- _this = _call_super$2(this, ZohoUserExternalConnectionOAuthServiceConfig, arguments), _define_property$3(_this, "scopes", void 0), /**
785
- * Datacenter to authorize against. Defaults to the api's configured one.
786
- */ _define_property$3(_this, "accountsApiUrl", void 0);
787
- return _this;
788
- }
789
- return ZohoUserExternalConnectionOAuthServiceConfig;
790
- }(model.UserExternalConnectionOAuthServiceConfig);
791
- /**
792
- * Builds the Zoho connect flow's configuration from the app's configured origins.
793
- *
794
- * Nothing here is read from the environment as a value: the redirect URI is derived from the app's
795
- * OAuth origin plus the mounted controller path, and the return URLs from the app URL plus
796
- * code-declared paths. Registering Zoho therefore adds no deployment configuration beyond the client
797
- * credentials the OAuth api already reads.
798
- *
799
- * @param config - The env service, the return paths, and the optional scope/datacenter overrides.
800
- * @returns The validated service configuration.
801
- */ function zohoUserExternalConnectionOAuthServiceConfigFactory(config) {
802
- var envService = config.envService, successPath = config.successPath, failurePath = config.failurePath, scopes = config.scopes, accountsApiUrl = config.accountsApiUrl;
803
- var baseConfig = model.userExternalConnectionOAuthServiceConfigFactory({
804
- envService: envService,
805
- providerType: firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE,
806
- successPath: successPath,
807
- failurePath: failurePath
808
- });
809
- return _object_spread_props$1(_object_spread$1({}, baseConfig), {
810
- scopes: scopes !== null && scopes !== void 0 ? scopes : DEFAULT_ZOHO_OAUTH_SCOPES,
811
- accountsApiUrl: accountsApiUrl
812
- });
813
- }
814
-
815
- function _assert_this_initialized$1(self) {
816
- if (self === void 0) {
817
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
818
- }
819
- return self;
820
- }
821
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
822
- try {
823
- var info = gen[key](arg);
824
- var value = info.value;
825
- } catch (error) {
826
- reject(error);
827
- return;
828
- }
829
- if (info.done) {
830
- resolve(value);
831
- } else {
832
- Promise.resolve(value).then(_next, _throw);
833
- }
834
- }
835
- function _async_to_generator$1(fn) {
836
- return function() {
837
- var self = this, args = arguments;
838
- return new Promise(function(resolve, reject) {
839
- var gen = fn.apply(self, args);
840
- function _next(value) {
841
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
842
- }
843
- function _throw(err) {
844
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
845
- }
846
- _next(undefined);
847
- });
848
- };
849
- }
850
- function _call_super$1(_this, derived, args) {
851
- derived = _get_prototype_of$1(derived);
852
- return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
853
- }
854
- function _class_call_check$1(instance, Constructor) {
855
- if (!(instance instanceof Constructor)) {
856
- throw new TypeError("Cannot call a class as a function");
857
- }
858
- }
859
- function _defineProperties(target, props) {
860
- for(var i = 0; i < props.length; i++){
861
- var descriptor = props[i];
862
- descriptor.enumerable = descriptor.enumerable || false;
863
- descriptor.configurable = true;
864
- if ("value" in descriptor) descriptor.writable = true;
865
- Object.defineProperty(target, descriptor.key, descriptor);
866
- }
867
- }
868
- function _create_class(Constructor, protoProps, staticProps) {
869
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
870
- return Constructor;
871
- }
872
- function _define_property$2(obj, key, value) {
873
- if (key in obj) {
874
- Object.defineProperty(obj, key, {
875
- value: value,
876
- enumerable: true,
877
- configurable: true,
878
- writable: true
879
- });
880
- } else {
881
- obj[key] = value;
882
- }
883
- return obj;
884
- }
885
- function _get_prototype_of$1(o) {
886
- _get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
887
- return o.__proto__ || Object.getPrototypeOf(o);
888
- };
889
- return _get_prototype_of$1(o);
890
- }
891
- function _inherits$1(subClass, superClass) {
892
- if (typeof superClass !== "function" && superClass !== null) {
893
- throw new TypeError("Super expression must either be null or a function");
894
- }
895
- subClass.prototype = Object.create(superClass && superClass.prototype, {
896
- constructor: {
897
- value: subClass,
898
- writable: true,
899
- configurable: true
900
- }
901
- });
902
- if (superClass) _set_prototype_of$1(subClass, superClass);
903
- }
904
- function _possible_constructor_return$1(self, call) {
905
- if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
906
- return call;
907
- }
908
- return _assert_this_initialized$1(self);
909
- }
910
- function _set_prototype_of$1(o, p) {
911
- _set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
912
- o.__proto__ = p;
913
- return o;
914
- };
915
- return _set_prototype_of$1(o, p);
916
- }
917
- function _type_of$1(obj) {
918
- "@swc/helpers - typeof";
919
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
920
- }
921
- function _is_native_reflect_construct$1() {
922
- try {
923
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
924
- } catch (_) {}
925
- return (_is_native_reflect_construct$1 = function() {
926
- return !!result;
927
- })();
928
- }
929
- function _ts_generator$1(thisArg, body) {
930
- var f, y, t, _ = {
931
- label: 0,
932
- sent: function() {
933
- if (t[0] & 1) throw t[1];
934
- return t[1];
935
- },
936
- trys: [],
937
- ops: []
938
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
939
- return d(g, "next", {
940
- value: verb(0)
941
- }), d(g, "throw", {
942
- value: verb(1)
943
- }), d(g, "return", {
944
- value: verb(2)
945
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
946
- value: function() {
947
- return this;
948
- }
949
- }), g;
950
- function verb(n) {
951
- return function(v) {
952
- return step([
953
- n,
954
- v
955
- ]);
956
- };
957
- }
958
- function step(op) {
959
- if (f) throw new TypeError("Generator is already executing.");
960
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
961
- 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;
962
- if (y = 0, t) op = [
963
- op[0] & 2,
964
- t.value
965
- ];
966
- switch(op[0]){
967
- case 0:
968
- case 1:
969
- t = op;
970
- break;
971
- case 4:
972
- _.label++;
973
- return {
974
- value: op[1],
975
- done: false
976
- };
977
- case 5:
978
- _.label++;
979
- y = op[1];
980
- op = [
981
- 0
982
- ];
983
- continue;
984
- case 7:
985
- op = _.ops.pop();
986
- _.trys.pop();
987
- continue;
988
- default:
989
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
990
- _ = 0;
991
- continue;
992
- }
993
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
994
- _.label = op[1];
995
- break;
996
- }
997
- if (op[0] === 6 && _.label < t[1]) {
998
- _.label = t[1];
999
- t = op;
1000
- break;
1001
- }
1002
- if (t && _.label < t[2]) {
1003
- _.label = t[2];
1004
- _.ops.push(op);
1005
- break;
1006
- }
1007
- if (t[2]) _.ops.pop();
1008
- _.trys.pop();
1009
- continue;
1010
- }
1011
- op = body.call(thisArg, _);
1012
- } catch (e) {
1013
- op = [
1014
- 6,
1015
- e
1016
- ];
1017
- y = 0;
1018
- } finally{
1019
- f = t = 0;
1020
- }
1021
- if (op[0] & 5) throw op[1];
1022
- return {
1023
- value: op[0] ? op[1] : void 0,
1024
- done: true
1025
- };
1026
- }
1027
- }
1028
- /**
1029
- * The callback parameter naming the datacenter whose accounts server issued the code.
1030
- */ var ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM = 'accounts-server';
1031
- /**
1032
- * The callback parameter naming the datacenter's short location code, e.g. `us`.
1033
- */ var ZOHO_OAUTH_CALLBACK_LOCATION_PARAM = 'location';
1034
- /**
1035
- * `extra` key holding the api domain a Zoho access token is usable against.
1036
- *
1037
- * Named constants because these keys are written on connect and read back on refresh — a literal in
1038
- * one place and a typo in the other would silently send the refresh to the wrong datacenter.
1039
- */ var ZOHO_EXTRA_API_DOMAIN_KEY = 'apiDomain';
1040
- /**
1041
- * `extra` key holding the accounts host a later refresh must be sent to.
1042
- */ var ZOHO_EXTRA_ACCOUNTS_SERVER_KEY = 'accountsServer';
1043
- /**
1044
- * `extra` key holding Zoho's short location code for the datacenter.
1045
- */ var ZOHO_EXTRA_LOCATION_KEY = 'location';
1046
- /**
1047
- * Maps an exchanged Zoho token response to the credentials stored on the private connection document.
1048
- *
1049
- * Two things differ from Cal.com's mapper. Zoho does not rotate its refresh token, so there is
1050
- * nothing to prefer over the token we already hold — and `refresh_token` can be ABSENT entirely on a
1051
- * re-consent, which is why it is passed through as `Maybe` rather than asserted (the framework's
1052
- * `credentialsRetainingStoredRefreshToken` is what keeps that from destroying a working token). And
1053
- * `api_domain` / `accountsServer` / `location` are retained in `extra`: a Zoho access token is only
1054
- * usable against the api domain it was issued for, and a later refresh must go back to the same
1055
- * datacenter's accounts server, so dropping them would leave the stored credentials unusable.
1056
- *
1057
- * @param input - The token response, the host it came from, and the identity when one was read.
1058
- * @returns The credentials to store.
1059
- */ function zohoUserExternalConnectionCredentials(input) {
1060
- var _ref, _ref1;
1061
- var response = input.response, accountsApiUrl = input.accountsApiUrl, location = input.location, userInfo = input.userInfo;
1062
- var access_token = response.access_token, refresh_token = response.refresh_token, expires_in = response.expires_in, scope = response.scope, api_domain = response.api_domain;
1063
- var now = Date.now();
1064
- var zuid = userInfo === null || userInfo === void 0 ? void 0 : userInfo.ZUID;
1065
- var _obj;
1066
- return {
1067
- accessToken: access_token,
1068
- // Maybe on purpose — absent on a re-consent that did not force the consent screen
1069
- refreshToken: refresh_token,
1070
- tokenType: 'Bearer',
1071
- issuedAt: new Date(now).toISOString(),
1072
- expiresAt: expires_in == null ? undefined : new Date(now + expires_in * util.MS_IN_SECOND).toISOString(),
1073
- scopes: zoho.zohoOAuthScopesFromScopeString(scope),
1074
- externalAccountId: zuid == null ? undefined : String(zuid),
1075
- label: (_ref = (_ref1 = userInfo === null || userInfo === void 0 ? void 0 : userInfo.Email) !== null && _ref1 !== void 0 ? _ref1 : userInfo === null || userInfo === void 0 ? void 0 : userInfo.Display_Name) !== null && _ref !== void 0 ? _ref : undefined,
1076
- extra: (_obj = {}, _define_property$2(_obj, ZOHO_EXTRA_API_DOMAIN_KEY, api_domain), _define_property$2(_obj, ZOHO_EXTRA_ACCOUNTS_SERVER_KEY, accountsApiUrl), _define_property$2(_obj, ZOHO_EXTRA_LOCATION_KEY, location), _obj)
1077
- };
1078
- }
1079
- /**
1080
- * Zoho's half of the external-connection authorization-code handoff.
1081
- *
1082
- * Everything else — resolving who is connecting, surfacing a refusal, retaining a refresh token the
1083
- * exchange did not return, persisting the credentials, choosing the redirect — is the framework's.
1084
- */ exports.ZohoUserExternalConnectionOAuthService = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthService) {
1085
- _inherits$1(ZohoUserExternalConnectionOAuthService, AbstractUserExternalConnectionOAuthService);
1086
- function ZohoUserExternalConnectionOAuthService(config, stateCoder, userExternalConnectionActions, userExternalConnectionAccessor, oauthApi) {
1087
- _class_call_check$1(this, ZohoUserExternalConnectionOAuthService);
1088
- var _this;
1089
- _this = _call_super$1(this, ZohoUserExternalConnectionOAuthService), _define_property$2(_this, "config", void 0), _define_property$2(_this, "stateCoder", void 0), _define_property$2(_this, "userExternalConnectionActions", void 0), _define_property$2(_this, "userExternalConnectionAccessor", void 0), _define_property$2(_this, "oauthApi", void 0), _define_property$2(_this, "authorizeUrlFactory", void 0), /**
1090
- * The accounts host this app authorizes against, and the fallback for an exchange whose callback
1091
- * named no usable one.
1092
- */ _define_property$2(_this, "accountsApiUrl", void 0);
1093
- _this.config = config;
1094
- _this.stateCoder = stateCoder;
1095
- _this.userExternalConnectionActions = userExternalConnectionActions;
1096
- _this.userExternalConnectionAccessor = userExternalConnectionAccessor;
1097
- _this.oauthApi = oauthApi;
1098
- var scopes = config.scopes, accountsApiUrl = config.accountsApiUrl, userExternalConnectionOAuth = config.userExternalConnectionOAuth;
1099
- // read through the api rather than injecting ZohoAccountsOAuthServiceConfig directly, which the
1100
- // OAuth module does not export to its dependents
1101
- _this.accountsApiUrl = accountsApiUrl == null ? oauthApi.apiUrl : zoho.zohoAccountsConfigApiUrl(accountsApiUrl);
1102
- _this.authorizeUrlFactory = zoho.zohoAccountsAuthorizeUrlFactory({
1103
- clientId: oauthApi.clientId,
1104
- redirectUri: userExternalConnectionOAuth.redirectUri,
1105
- scopes: scopes,
1106
- accountsApiUrl: _this.accountsApiUrl
1107
- });
1108
- return _this;
1109
- }
1110
- _create_class(ZohoUserExternalConnectionOAuthService, [
1111
- {
1112
- key: "authorizeUrlForState",
1113
- value: function authorizeUrlForState(state) {
1114
- return this.authorizeUrlFactory({
1115
- state: state
1116
- });
1117
- }
1118
- },
1119
- {
1120
- key: "credentialsForAuthorizationCode",
1121
- value: function credentialsForAuthorizationCode(input) {
1122
- return _async_to_generator$1(function() {
1123
- var _this_accountsApiUrlForCallbackQuery, code, redirectUri, query, accountsApiUrl, response, userInfo, e;
1124
- return _ts_generator$1(this, function(_state) {
1125
- switch(_state.label){
1126
- case 0:
1127
- code = input.code, redirectUri = input.redirectUri, query = input.query;
1128
- accountsApiUrl = (_this_accountsApiUrlForCallbackQuery = this.accountsApiUrlForCallbackQuery(query)) !== null && _this_accountsApiUrlForCallbackQuery !== void 0 ? _this_accountsApiUrlForCallbackQuery : this.accountsApiUrl;
1129
- return [
1130
- 4,
1131
- this.oauthApi.exchangeAuthorizationCode({
1132
- code: code,
1133
- redirectUri: redirectUri,
1134
- accountsApiUrl: accountsApiUrl
1135
- })
1136
- ];
1137
- case 1:
1138
- response = _state.sent();
1139
- _state.label = 2;
1140
- case 2:
1141
- _state.trys.push([
1142
- 2,
1143
- 4,
1144
- ,
1145
- 5
1146
- ]);
1147
- return [
1148
- 4,
1149
- this.oauthApi.userInfo({
1150
- accessToken: response.access_token,
1151
- accountsApiUrl: accountsApiUrl
1152
- })
1153
- ];
1154
- case 3:
1155
- userInfo = _state.sent();
1156
- return [
1157
- 3,
1158
- 5
1159
- ];
1160
- case 4:
1161
- e = _state.sent();
1162
- this.logger.warn('Connected Zoho but could not read the identity to label the connection: ', e);
1163
- return [
1164
- 3,
1165
- 5
1166
- ];
1167
- case 5:
1168
- return [
1169
- 2,
1170
- zohoUserExternalConnectionCredentials({
1171
- response: response,
1172
- accountsApiUrl: accountsApiUrl,
1173
- location: query === null || query === void 0 ? void 0 : query[ZOHO_OAUTH_CALLBACK_LOCATION_PARAM],
1174
- userInfo: userInfo
1175
- })
1176
- ];
1177
- }
1178
- });
1179
- }).call(this);
1180
- }
1181
- },
1182
- {
1183
- key: "refreshCredentials",
1184
- value: function refreshCredentials(input) {
1185
- return _async_to_generator$1(function() {
1186
- var _this_allowlistedAccountsApiUrl, credentials, refreshToken, extra, storedAccountsServer, accountsApiUrl, response, location;
1187
- return _ts_generator$1(this, function(_state) {
1188
- switch(_state.label){
1189
- case 0:
1190
- credentials = input.credentials;
1191
- refreshToken = credentials.refreshToken, extra = credentials.extra;
1192
- if (!refreshToken) {
1193
- throw new Error('ZohoUserExternalConnectionOAuthService.refreshCredentials: the stored credentials carry no refresh token.');
1194
- }
1195
- // the grant lives at ONE datacenter — a refresh token issued by `accounts.zoho.eu` is not honored
1196
- // by `accounts.zoho.com` — so the stored accounts server is what the refresh must be sent to. It is
1197
- // re-resolved through the allowlist rather than used verbatim: the value originally arrived on a
1198
- // browser redirect, and it is the POST target the client secret travels to.
1199
- storedAccountsServer = extra === null || extra === void 0 ? void 0 : extra[ZOHO_EXTRA_ACCOUNTS_SERVER_KEY];
1200
- accountsApiUrl = (_this_allowlistedAccountsApiUrl = this.allowlistedAccountsApiUrl(storedAccountsServer == null ? undefined : String(storedAccountsServer))) !== null && _this_allowlistedAccountsApiUrl !== void 0 ? _this_allowlistedAccountsApiUrl : this.accountsApiUrl;
1201
- return [
1202
- 4,
1203
- this.oauthApi.refreshUserAccessToken({
1204
- refreshToken: refreshToken,
1205
- accountsApiUrl: accountsApiUrl
1206
- })
1207
- ];
1208
- case 1:
1209
- response = _state.sent();
1210
- // `location` is carried forward from the stored credentials rather than re-derived: it only ever
1211
- // arrives on the callback, and the framework's merge would otherwise see an undefined value.
1212
- location = extra === null || extra === void 0 ? void 0 : extra[ZOHO_EXTRA_LOCATION_KEY];
1213
- // the response has no `refresh_token`, which the framework's merge retains — and `api_domain` may
1214
- // legitimately differ from the one issued on connect, so it is taken from the response
1215
- return [
1216
- 2,
1217
- zohoUserExternalConnectionCredentials({
1218
- response: response,
1219
- accountsApiUrl: accountsApiUrl,
1220
- location: location == null ? undefined : String(location)
1221
- })
1222
- ];
1223
- }
1224
- });
1225
- }).call(this);
1226
- }
1227
- },
1228
- {
1229
- /**
1230
- * The accounts host to exchange against, taken from Zoho's `accounts-server` callback parameter.
1231
- *
1232
- * @param query - The raw callback query.
1233
- * @returns The allowlisted accounts host the callback named, if any.
1234
- */ key: "accountsApiUrlForCallbackQuery",
1235
- value: function accountsApiUrlForCallbackQuery(query) {
1236
- return this.allowlistedAccountsApiUrl(query === null || query === void 0 ? void 0 : query[ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM]);
1237
- }
1238
- },
1239
- {
1240
- /**
1241
- * Resolves an untrusted accounts-host string back to one of the canonical Zoho hosts.
1242
- *
1243
- * Only an allowlisted Zoho host is honored. Every value passed here originated on a redirect an
1244
- * attacker can compose — either the live callback query or a value persisted from an earlier one —
1245
- * and it becomes the POST target the CLIENT SECRET is sent to, so an unchecked value would hand out
1246
- * the secret. Resolving through the allowlist rather than comparing to it also guarantees the host
1247
- * used is a canonical constant and never a caller-shaped variant of one. An unrecognized value is
1248
- * dropped (and logged) rather than trusted.
1249
- *
1250
- * @param accountsServer - The untrusted host string, if any.
1251
- * @returns The allowlisted accounts host, or null when there was none or it was not recognized.
1252
- */ key: "allowlistedAccountsApiUrl",
1253
- value: function allowlistedAccountsApiUrl(accountsServer) {
1254
- var result;
1255
- if (accountsServer) {
1256
- var key = zoho.zohoAccountsApiUrlKeyForApiUrl(accountsServer);
1257
- if (key == null) {
1258
- this.logger.warn('Ignored an unrecognized Zoho accounts host of "'.concat(accountsServer, '"; using the configured host instead.'));
1259
- } else {
1260
- result = zoho.ZOHO_ACCOUNTS_API_URLS[key];
1261
- }
1262
- }
1263
- return result;
1264
- }
1265
- }
1266
- ]);
1267
- return ZohoUserExternalConnectionOAuthService;
1268
- }(model.AbstractUserExternalConnectionOAuthService);
1269
- exports.ZohoUserExternalConnectionOAuthService = __decorate([
1270
- common.Injectable(),
1271
- __param(0, common.Inject(ZohoUserExternalConnectionOAuthServiceConfig)),
1272
- __param(1, common.Inject(model.UserExternalConnectionStateCoder)),
1273
- __param(2, common.Inject(model.UserExternalConnectionServerActions)),
1274
- __param(3, common.Inject(model.UserExternalConnectionAccessor)),
1275
- __param(4, common.Inject(nestjs$1.ZohoAccountsOAuthApi))
1276
- ], exports.ZohoUserExternalConnectionOAuthService);
1277
-
1278
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1279
- try {
1280
- var info = gen[key](arg);
1281
- var value = info.value;
1282
- } catch (error) {
1283
- reject(error);
1284
- return;
1285
- }
1286
- if (info.done) {
1287
- resolve(value);
1288
- } else {
1289
- Promise.resolve(value).then(_next, _throw);
1290
- }
1291
- }
1292
- function _async_to_generator(fn) {
1293
- return function() {
1294
- var self = this, args = arguments;
1295
- return new Promise(function(resolve, reject) {
1296
- var gen = fn.apply(self, args);
1297
- function _next(value) {
1298
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1299
- }
1300
- function _throw(err) {
1301
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1302
- }
1303
- _next(undefined);
1304
- });
1305
- };
1306
- }
1307
- function _define_property$1(obj, key, value) {
1308
- if (key in obj) {
1309
- Object.defineProperty(obj, key, {
1310
- value: value,
1311
- enumerable: true,
1312
- configurable: true,
1313
- writable: true
1314
- });
1315
- } else {
1316
- obj[key] = value;
1317
- }
1318
- return obj;
1319
- }
1320
- function _object_spread(target) {
1321
- for(var i = 1; i < arguments.length; i++){
1322
- var source = arguments[i] != null ? arguments[i] : {};
1323
- var ownKeys = Object.keys(source);
1324
- if (typeof Object.getOwnPropertySymbols === "function") {
1325
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1326
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1327
- }));
1328
- }
1329
- ownKeys.forEach(function(key) {
1330
- _define_property$1(target, key, source[key]);
1331
- });
1332
- }
1333
- return target;
1334
- }
1335
- function ownKeys(object, enumerableOnly) {
1336
- var keys = Object.keys(object);
1337
- if (Object.getOwnPropertySymbols) {
1338
- var symbols = Object.getOwnPropertySymbols(object);
1339
- keys.push.apply(keys, symbols);
1340
- }
1341
- return keys;
1342
- }
1343
- function _object_spread_props(target, source) {
1344
- source = source != null ? source : {};
1345
- if (Object.getOwnPropertyDescriptors) {
1346
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1347
- } else {
1348
- ownKeys(Object(source)).forEach(function(key) {
1349
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1350
- });
1351
- }
1352
- return target;
1353
- }
1354
- function _ts_generator(thisArg, body) {
1355
- var f, y, t, _ = {
1356
- label: 0,
1357
- sent: function() {
1358
- if (t[0] & 1) throw t[1];
1359
- return t[1];
1360
- },
1361
- trys: [],
1362
- ops: []
1363
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1364
- return d(g, "next", {
1365
- value: verb(0)
1366
- }), d(g, "throw", {
1367
- value: verb(1)
1368
- }), d(g, "return", {
1369
- value: verb(2)
1370
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1371
- value: function() {
1372
- return this;
1373
- }
1374
- }), g;
1375
- function verb(n) {
1376
- return function(v) {
1377
- return step([
1378
- n,
1379
- v
1380
- ]);
1381
- };
1382
- }
1383
- function step(op) {
1384
- if (f) throw new TypeError("Generator is already executing.");
1385
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
1386
- 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;
1387
- if (y = 0, t) op = [
1388
- op[0] & 2,
1389
- t.value
1390
- ];
1391
- switch(op[0]){
1392
- case 0:
1393
- case 1:
1394
- t = op;
1395
- break;
1396
- case 4:
1397
- _.label++;
1398
- return {
1399
- value: op[1],
1400
- done: false
1401
- };
1402
- case 5:
1403
- _.label++;
1404
- y = op[1];
1405
- op = [
1406
- 0
1407
- ];
1408
- continue;
1409
- case 7:
1410
- op = _.ops.pop();
1411
- _.trys.pop();
1412
- continue;
1413
- default:
1414
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1415
- _ = 0;
1416
- continue;
1417
- }
1418
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1419
- _.label = op[1];
1420
- break;
1421
- }
1422
- if (op[0] === 6 && _.label < t[1]) {
1423
- _.label = t[1];
1424
- t = op;
1425
- break;
1426
- }
1427
- if (t && _.label < t[2]) {
1428
- _.label = t[2];
1429
- _.ops.push(op);
1430
- break;
1431
- }
1432
- if (t[2]) _.ops.pop();
1433
- _.trys.pop();
1434
- continue;
1435
- }
1436
- op = body.call(thisArg, _);
1437
- } catch (e) {
1438
- op = [
1439
- 6,
1440
- e
1441
- ];
1442
- y = 0;
1443
- } finally{
1444
- f = t = 0;
1445
- }
1446
- if (op[0] & 5) throw op[1];
1447
- return {
1448
- value: op[0] ? op[1] : void 0,
1449
- done: true
1450
- };
1451
- }
1452
- }
1453
- /**
1454
- * Maps stored connection credentials to a {@link ZohoAccessToken}.
1455
- *
1456
- * @param credentials - The credentials stored for the `zoho` provider.
1457
- * @returns The equivalent Zoho access token, or null when the credentials cannot form one.
1458
- */ function zohoAccessTokenFromUserExternalConnectionCredentials(credentials) {
1459
- var _credentials_extra;
1460
- var expiresAt = date.safeToJsDate(credentials === null || credentials === void 0 ? void 0 : credentials.expiresAt);
1461
- var apiDomain = credentials === null || credentials === void 0 ? void 0 : (_credentials_extra = credentials.extra) === null || _credentials_extra === void 0 ? void 0 : _credentials_extra[ZOHO_EXTRA_API_DOMAIN_KEY];
1462
- var result;
1463
- // the api domain is required, not incidental: a Zoho access token is only usable against the domain
1464
- // it was issued for, so a token synthesized without one would be sent to the wrong host
1465
- if (credentials != null && expiresAt != null && apiDomain != null) {
1466
- var _ref, _credentials_scopes;
1467
- var issuedAt = date.safeToJsDate(credentials.issuedAt);
1468
- var expiresIn = Math.round((expiresAt.getTime() - ((_ref = issuedAt === null || issuedAt === void 0 ? void 0 : issuedAt.getTime()) !== null && _ref !== void 0 ? _ref : Date.now())) / util.MS_IN_SECOND);
1469
- result = {
1470
- accessToken: credentials.accessToken,
1471
- // joined on the same delimiter `zohoOAuthScopesFromScopeString` split them with
1472
- scope: ((_credentials_scopes = credentials.scopes) !== null && _credentials_scopes !== void 0 ? _credentials_scopes : []).join(zoho.ZOHO_OAUTH_SCOPE_DELIMITER),
1473
- apiDomain: String(apiDomain),
1474
- expiresIn: expiresIn,
1475
- expiresAt: expiresAt
1476
- };
1477
- }
1478
- return result;
1479
- }
1480
- /**
1481
- * Creates a {@link ZohoAccessTokenCache} backed by a user's UserExternalConnection pair.
1482
- *
1483
- * The Zoho counterpart of `userExternalConnectionCalcomAccessTokenCache`, and the per-user counterpart
1484
- * of `firebaseZohoAccountsAccessTokenCacheService` — which caches the APP's token in a `SystemState`
1485
- * document and has no notion of a user.
1486
- *
1487
- * Zoho does not rotate refresh tokens, so unlike Cal.com there is no token here that is destroyed by
1488
- * being used. What this buys instead is that a renewed access token is shared: without it every Cloud
1489
- * Function instance holds its own in-memory token and refreshes independently, so a user's grant is
1490
- * exercised once per instance per hour rather than once per hour.
1491
- *
1492
- * @param config - The accessor, the actions, and the user the cache is for.
1493
- * @returns A ZohoAccessTokenCache reading and writing the user's connection pair.
1494
- */ function userExternalConnectionZohoAccessTokenCache(config) {
1495
- var accessor = config.accessor, actions = config.actions, uid = config.uid;
1496
- var providerType = firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE;
1497
- var connection = accessor.accessorForUser({
1498
- uid: uid
1499
- })(providerType);
1500
- function loadCachedToken() {
1501
- return _async_to_generator(function() {
1502
- var credentials;
1503
- return _ts_generator(this, function(_state) {
1504
- switch(_state.label){
1505
- case 0:
1506
- return [
1507
- 4,
1508
- connection.readUserExternalConnectionCredentials()
1509
- ];
1510
- case 1:
1511
- credentials = _state.sent();
1512
- return [
1513
- 2,
1514
- zohoAccessTokenFromUserExternalConnectionCredentials(credentials)
1515
- ];
1516
- }
1517
- });
1518
- })();
1519
- }
1520
- function updateCachedToken(accessToken) {
1521
- return _async_to_generator(function() {
1522
- var previous, now, refreshed;
1523
- return _ts_generator(this, function(_state) {
1524
- switch(_state.label){
1525
- case 0:
1526
- return [
1527
- 4,
1528
- connection.readUserExternalConnectionCredentials()
1529
- ];
1530
- case 1:
1531
- previous = _state.sent();
1532
- if (previous == null) {
1533
- // nothing to merge onto, and a Zoho access token carries no refresh token — writing it alone
1534
- // would store credentials that can never be renewed
1535
- return [
1536
- 2
1537
- ];
1538
- }
1539
- now = new Date();
1540
- refreshed = _object_spread_props(_object_spread({}, previous), {
1541
- accessToken: accessToken.accessToken,
1542
- issuedAt: now.toISOString(),
1543
- expiresAt: accessToken.expiresAt.toISOString(),
1544
- extra: _object_spread_props(_object_spread({}, previous.extra), _define_property$1({}, ZOHO_EXTRA_API_DOMAIN_KEY, accessToken.apiDomain))
1545
- });
1546
- return [
1547
- 4,
1548
- actions.refreshUserExternalConnectionCredentials({
1549
- uid: uid,
1550
- providerType: providerType,
1551
- credentials: model.mergeRefreshedUserExternalConnectionCredentials({
1552
- previous: previous,
1553
- refreshed: refreshed
1554
- })
1555
- })
1556
- ];
1557
- case 2:
1558
- _state.sent();
1559
- return [
1560
- 2
1561
- ];
1562
- }
1563
- });
1564
- })();
1565
- }
1566
- function clearCachedToken() {
1567
- return _async_to_generator(function() {
1568
- var previous;
1569
- return _ts_generator(this, function(_state) {
1570
- switch(_state.label){
1571
- case 0:
1572
- return [
1573
- 4,
1574
- connection.readUserExternalConnectionCredentials()
1575
- ];
1576
- case 1:
1577
- previous = _state.sent();
1578
- if (previous == null) {
1579
- return [
1580
- 2
1581
- ];
1582
- }
1583
- // deliberately NOT a disconnect. Zoho's factory clears the cache to force its next call to refresh,
1584
- // which is a statement about the ACCESS token only — dropping the refresh token here would turn a
1585
- // routine cache invalidation into a connection the user has to re-authorize.
1586
- return [
1587
- 4,
1588
- actions.refreshUserExternalConnectionCredentials({
1589
- uid: uid,
1590
- providerType: providerType,
1591
- credentials: _object_spread_props(_object_spread({}, previous), {
1592
- accessToken: '',
1593
- expiresAt: new Date(0).toISOString()
1594
- })
1595
- })
1596
- ];
1597
- case 2:
1598
- _state.sent();
1599
- return [
1600
- 2
1601
- ];
1602
- }
1603
- });
1604
- })();
1605
- }
1606
- return {
1607
- loadCachedToken: loadCachedToken,
1608
- updateCachedToken: updateCachedToken,
1609
- clearCachedToken: clearCachedToken
1610
- };
1611
- }
1612
-
1613
- function _assert_this_initialized(self) {
1614
- if (self === void 0) {
1615
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1616
- }
1617
- return self;
1618
- }
1619
- function _call_super(_this, derived, args) {
1620
- derived = _get_prototype_of(derived);
1621
- return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
1622
- }
1623
- function _class_call_check(instance, Constructor) {
1624
- if (!(instance instanceof Constructor)) {
1625
- throw new TypeError("Cannot call a class as a function");
1626
- }
1627
- }
1628
- function _define_property(obj, key, value) {
1629
- if (key in obj) {
1630
- Object.defineProperty(obj, key, {
1631
- value: value,
1632
- enumerable: true,
1633
- configurable: true,
1634
- writable: true
1635
- });
1636
- } else {
1637
- obj[key] = value;
1638
- }
1639
- return obj;
1640
- }
1641
- function _get_prototype_of(o) {
1642
- _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
1643
- return o.__proto__ || Object.getPrototypeOf(o);
1644
- };
1645
- return _get_prototype_of(o);
1646
- }
1647
- function _inherits(subClass, superClass) {
1648
- if (typeof superClass !== "function" && superClass !== null) {
1649
- throw new TypeError("Super expression must either be null or a function");
1650
- }
1651
- subClass.prototype = Object.create(superClass && superClass.prototype, {
1652
- constructor: {
1653
- value: subClass,
1654
- writable: true,
1655
- configurable: true
1656
- }
1657
- });
1658
- if (superClass) _set_prototype_of(subClass, superClass);
1659
- }
1660
- function _possible_constructor_return(self, call) {
1661
- if (call && (_type_of(call) === "object" || typeof call === "function")) {
1662
- return call;
1663
- }
1664
- return _assert_this_initialized(self);
1665
- }
1666
- function _set_prototype_of(o, p) {
1667
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
1668
- o.__proto__ = p;
1669
- return o;
1670
- };
1671
- return _set_prototype_of(o, p);
1672
- }
1673
- function _type_of(obj) {
1674
- "@swc/helpers - typeof";
1675
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1676
- }
1677
- function _is_native_reflect_construct() {
1678
- try {
1679
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
1680
- } catch (_) {}
1681
- return (_is_native_reflect_construct = function() {
1682
- return !!result;
1683
- })();
1684
- }
1685
- /**
1686
- * Endpoints for the Zoho external-connection authorization-code handoff.
1687
- *
1688
- * Mounted at `/oauth/zoho`, matching the Angular registry's default authorize path of
1689
- * `/oauth/<providerType>/authorize`. Hosting rewrites do not strip the path, so this prefix is the
1690
- * public path — but an app with a global API route prefix must ALSO exclude these routes from it via
1691
- * {@link ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE}, or they land under
1692
- * that prefix instead and no longer match the redirect URI registered with Zoho.
1693
- *
1694
- * The `authorize` and `callback` routes come from the base class, so this declares only where they
1695
- * mount and which service serves them.
1696
- */ exports.ZohoUserExternalConnectionOAuthController = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthController) {
1697
- _inherits(ZohoUserExternalConnectionOAuthController, AbstractUserExternalConnectionOAuthController);
1698
- function ZohoUserExternalConnectionOAuthController(oauthService) {
1699
- _class_call_check(this, ZohoUserExternalConnectionOAuthController);
1700
- var _this;
1701
- _this = _call_super(this, ZohoUserExternalConnectionOAuthController), _define_property(_this, "oauthService", void 0);
1702
- _this.oauthService = oauthService;
1703
- return _this;
1704
- }
1705
- return ZohoUserExternalConnectionOAuthController;
1706
- }(model.AbstractUserExternalConnectionOAuthController);
1707
- exports.ZohoUserExternalConnectionOAuthController = __decorate([
1708
- common.Controller(ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH),
1709
- __param(0, common.Inject(exports.ZohoUserExternalConnectionOAuthService))
1710
- ], exports.ZohoUserExternalConnectionOAuthController);
1711
-
1712
- function _array_like_to_array(arr, len) {
1713
- if (len == null || len > arr.length) len = arr.length;
1714
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1715
- return arr2;
1716
- }
1717
- function _array_without_holes(arr) {
1718
- if (Array.isArray(arr)) return _array_like_to_array(arr);
1719
- }
1720
- function _iterable_to_array(iter) {
1721
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1722
- }
1723
- function _non_iterable_spread() {
1724
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1725
- }
1726
- function _to_consumable_array(arr) {
1727
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1728
- }
1729
- function _unsupported_iterable_to_array(o, minLen) {
1730
- if (!o) return;
1731
- if (typeof o === "string") return _array_like_to_array(o, minLen);
1732
- var n = Object.prototype.toString.call(o).slice(8, -1);
1733
- if (n === "Object" && o.constructor) n = o.constructor.name;
1734
- if (n === "Map" || n === "Set") return Array.from(n);
1735
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1736
- }
1737
- /**
1738
- * Convenience function used to generate ModuleMetadata for an app's Zoho external-connection OAuth
1739
- * module.
1740
- *
1741
- * Opt-in: importing the Zoho OAuth module alone never mounts HTTP routes, so an app that only makes
1742
- * outbound Zoho calls exposes no endpoints.
1743
- *
1744
- * The importing module must also supply `UserExternalConnectionServerActions` and
1745
- * `UserExternalConnectionStateCoder` — both exported by `appUserExternalConnectionModuleMetadata`,
1746
- * so pass that module in `imports`.
1747
- *
1748
- * @param config - The module metadata configuration.
1749
- * @returns NestJS ModuleMetadata mounting the Zoho connect endpoints.
1750
- */ function appZohoUserExternalConnectionOAuthModuleMetadata(config$1) {
1751
- var dependencyModule = config$1.dependencyModule, successPath = config$1.successPath, failurePath = config$1.failurePath, scopes = config$1.scopes, accountsApiUrl = config$1.accountsApiUrl, imports = config$1.imports, exports$1 = config$1.exports, providers = config$1.providers;
1752
- var dependencyModuleImport = dependencyModule ? [
1753
- dependencyModule
1754
- ] : [];
1755
- return {
1756
- imports: [
1757
- config.ConfigModule
1758
- ].concat(_to_consumable_array(dependencyModuleImport), _to_consumable_array(imports !== null && imports !== void 0 ? imports : [])),
1759
- controllers: [
1760
- exports.ZohoUserExternalConnectionOAuthController
1761
- ],
1762
- exports: [
1763
- exports.ZohoUserExternalConnectionOAuthService
1764
- ].concat(_to_consumable_array(exports$1 !== null && exports$1 !== void 0 ? exports$1 : [])),
1765
- providers: [
1766
- {
1767
- provide: ZohoUserExternalConnectionOAuthServiceConfig,
1768
- inject: [
1769
- firebaseServer.FirebaseServerEnvService
1770
- ],
1771
- useFactory: function useFactory(envService) {
1772
- return zohoUserExternalConnectionOAuthServiceConfigFactory({
1773
- envService: envService,
1774
- successPath: successPath,
1775
- failurePath: failurePath,
1776
- scopes: scopes,
1777
- accountsApiUrl: accountsApiUrl
1778
- });
1779
- }
1780
- },
1781
- exports.ZohoUserExternalConnectionOAuthService
1782
- ].concat(_to_consumable_array(providers !== null && providers !== void 0 ? providers : []))
1783
- };
1784
- }
1785
-
1786
- exports.DEFAULT_ZOHO_OAUTH_SCOPES = DEFAULT_ZOHO_OAUTH_SCOPES;
1787
- exports.TESTING_ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET = TESTING_ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET;
1788
- exports.ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET_ENV_KEY = ZOHO_ACCESS_TOKEN_ENCRYPTION_SECRET_ENV_KEY;
1789
- exports.ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE;
1790
- exports.ZOHO_EXTRA_ACCOUNTS_SERVER_KEY = ZOHO_EXTRA_ACCOUNTS_SERVER_KEY;
1791
- exports.ZOHO_EXTRA_API_DOMAIN_KEY = ZOHO_EXTRA_API_DOMAIN_KEY;
1792
- exports.ZOHO_EXTRA_LOCATION_KEY = ZOHO_EXTRA_LOCATION_KEY;
1793
- exports.ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM = ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM;
1794
- exports.ZOHO_OAUTH_CALLBACK_LOCATION_PARAM = ZOHO_OAUTH_CALLBACK_LOCATION_PARAM;
1795
- exports.ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH;
1796
- exports.ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE;
1797
- exports.ZohoUserExternalConnectionOAuthServiceConfig = ZohoUserExternalConnectionOAuthServiceConfig;
1798
- exports.appZohoUserExternalConnectionOAuthModuleMetadata = appZohoUserExternalConnectionOAuthModuleMetadata;
1799
- exports.firebaseZohoAccountsAccessTokenCacheService = firebaseZohoAccountsAccessTokenCacheService;
1800
- exports.loadZohoAccessTokenSystemState = loadZohoAccessTokenSystemState;
1801
- exports.userExternalConnectionZohoAccessTokenCache = userExternalConnectionZohoAccessTokenCache;
1802
- exports.zohoAccessTokenEncryptionSecretFactory = zohoAccessTokenEncryptionSecretFactory;
1803
- exports.zohoAccessTokenFromUserExternalConnectionCredentials = zohoAccessTokenFromUserExternalConnectionCredentials;
1804
- exports.zohoAccessTokenSystemStateDataConverter = zohoAccessTokenSystemStateDataConverter;
1805
- exports.zohoAccessTokenSystemStateDataConverterFactory = zohoAccessTokenSystemStateDataConverterFactory;
1806
- exports.zohoAccessTokenSystemStateEmbeddedTokenConverter = zohoAccessTokenSystemStateEmbeddedTokenConverter;
1807
- exports.zohoAccessTokenSystemStateEmbeddedTokenConverterFactory = zohoAccessTokenSystemStateEmbeddedTokenConverterFactory;
1808
- exports.zohoAccessTokenSystemStatePrivateConverterEntry = zohoAccessTokenSystemStatePrivateConverterEntry;
1809
- exports.zohoUserExternalConnectionCredentials = zohoUserExternalConnectionCredentials;
1810
- exports.zohoUserExternalConnectionOAuthServiceConfigFactory = zohoUserExternalConnectionOAuthServiceConfigFactory;