@dereekb/firebase-server 13.32.0 → 13.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/calcom/index.cjs.default.js +1 -0
- package/calcom/index.cjs.js +1451 -0
- package/calcom/index.cjs.mjs +2 -0
- package/calcom/index.d.ts +1 -0
- package/calcom/index.esm.js +1437 -0
- package/calcom/package.json +29 -0
- package/calcom/src/index.d.ts +1 -0
- package/calcom/src/lib/calcom.oauth.connection.cache.d.ts +49 -0
- package/calcom/src/lib/calcom.oauth.connection.config.d.ts +75 -0
- package/calcom/src/lib/calcom.oauth.connection.context.d.ts +84 -0
- package/calcom/src/lib/calcom.oauth.connection.controller.d.ts +18 -0
- package/calcom/src/lib/calcom.oauth.connection.module.d.ts +55 -0
- package/calcom/src/lib/calcom.oauth.connection.service.d.ts +33 -0
- package/calcom/src/lib/index.d.ts +6 -0
- package/discord/index.cjs.default.js +1 -0
- package/discord/index.cjs.js +761 -0
- package/discord/index.cjs.mjs +2 -0
- package/discord/index.d.ts +1 -0
- package/discord/index.esm.js +753 -0
- package/discord/package.json +29 -0
- package/discord/src/index.d.ts +1 -0
- package/discord/src/lib/discord.oauth.connection.config.d.ts +69 -0
- package/discord/src/lib/discord.oauth.connection.controller.d.ts +18 -0
- package/discord/src/lib/discord.oauth.connection.module.d.ts +39 -0
- package/discord/src/lib/discord.oauth.connection.service.d.ts +43 -0
- package/discord/src/lib/index.d.ts +4 -0
- package/index.cjs.js +14 -3
- package/index.esm.js +14 -3
- package/mailgun/package.json +9 -9
- package/mcp/package.json +11 -11
- package/model/index.cjs.js +3986 -855
- package/model/index.esm.js +3934 -862
- package/model/package.json +10 -9
- package/model/src/lib/index.d.ts +1 -0
- package/model/src/lib/userexternalconnection/index.d.ts +8 -0
- package/model/src/lib/userexternalconnection/oauth/index.d.ts +7 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.config.d.ts +110 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.controller.d.ts +68 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.error.d.ts +29 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.refresh.d.ts +24 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.registry.d.ts +54 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.service.d.ts +216 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.state.d.ts +114 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.accessor.service.d.ts +111 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.action.server.d.ts +172 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.error.d.ts +44 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.module.d.ts +129 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.private.d.ts +192 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.reader.service.d.ts +157 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.refresh.service.d.ts +46 -0
- package/oidc/index.cjs.js +104 -78
- package/oidc/index.esm.js +104 -78
- package/oidc/package.json +10 -10
- package/package.json +24 -10
- package/src/lib/env/env.config.d.ts +15 -0
- package/src/lib/env/env.service.d.ts +7 -0
- package/src/lib/nest/env/env.service.d.ts +1 -0
- package/test/index.cjs.js +14 -2
- package/test/index.esm.js +15 -3
- package/test/package.json +11 -11
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +1 -1
- package/twilio/package.json +8 -8
- package/zoho/README.md +8 -0
- package/zoho/index.cjs.js +1223 -33
- package/zoho/index.esm.js +1212 -36
- package/zoho/package.json +12 -9
- package/zoho/src/lib/index.d.ts +5 -0
- package/zoho/src/lib/zoho.oauth.connection.cache.d.ts +45 -0
- package/zoho/src/lib/zoho.oauth.connection.config.d.ts +80 -0
- package/zoho/src/lib/zoho.oauth.connection.controller.d.ts +18 -0
- package/zoho/src/lib/zoho.oauth.connection.module.d.ts +43 -0
- package/zoho/src/lib/zoho.oauth.connection.service.d.ts +107 -0
package/zoho/index.cjs.js
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var firebase = require('@dereekb/firebase');
|
|
4
4
|
var util = require('@dereekb/util');
|
|
5
|
+
var zoho = require('@dereekb/zoho');
|
|
6
|
+
var model = require('@dereekb/firebase-server/model');
|
|
7
|
+
var date = require('@dereekb/date');
|
|
8
|
+
var common = require('@nestjs/common');
|
|
9
|
+
var nestjs = require('@dereekb/zoho/nestjs');
|
|
10
|
+
var config = require('@nestjs/config');
|
|
11
|
+
var firebaseServer = require('@dereekb/firebase-server');
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* {@link SystemState} type identifier for storing Zoho access tokens in Firestore.
|
|
@@ -61,15 +68,15 @@ var zohoAccessTokenSystemStateEmbeddedTokenConverter = firebase.firestoreSubObje
|
|
|
61
68
|
return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
function _array_like_to_array(arr, len) {
|
|
71
|
+
function _array_like_to_array$1(arr, len) {
|
|
65
72
|
if (len == null || len > arr.length) len = arr.length;
|
|
66
73
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
67
74
|
return arr2;
|
|
68
75
|
}
|
|
69
|
-
function _array_without_holes(arr) {
|
|
70
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
76
|
+
function _array_without_holes$1(arr) {
|
|
77
|
+
if (Array.isArray(arr)) return _array_like_to_array$1(arr);
|
|
71
78
|
}
|
|
72
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
79
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
73
80
|
try {
|
|
74
81
|
var info = gen[key](arg);
|
|
75
82
|
var value = info.value;
|
|
@@ -83,22 +90,22 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
83
90
|
Promise.resolve(value).then(_next, _throw);
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
function _async_to_generator(fn) {
|
|
93
|
+
function _async_to_generator$2(fn) {
|
|
87
94
|
return function() {
|
|
88
95
|
var self = this, args = arguments;
|
|
89
96
|
return new Promise(function(resolve, reject) {
|
|
90
97
|
var gen = fn.apply(self, args);
|
|
91
98
|
function _next(value) {
|
|
92
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
99
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
93
100
|
}
|
|
94
101
|
function _throw(err) {
|
|
95
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
102
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
96
103
|
}
|
|
97
104
|
_next(undefined);
|
|
98
105
|
});
|
|
99
106
|
};
|
|
100
107
|
}
|
|
101
|
-
function _define_property(obj, key, value) {
|
|
108
|
+
function _define_property$4(obj, key, value) {
|
|
102
109
|
if (key in obj) {
|
|
103
110
|
Object.defineProperty(obj, key, {
|
|
104
111
|
value: value,
|
|
@@ -111,13 +118,13 @@ function _define_property(obj, key, value) {
|
|
|
111
118
|
}
|
|
112
119
|
return obj;
|
|
113
120
|
}
|
|
114
|
-
function _iterable_to_array(iter) {
|
|
121
|
+
function _iterable_to_array$1(iter) {
|
|
115
122
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
116
123
|
}
|
|
117
|
-
function _non_iterable_spread() {
|
|
124
|
+
function _non_iterable_spread$1() {
|
|
118
125
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
119
126
|
}
|
|
120
|
-
function _object_spread(target) {
|
|
127
|
+
function _object_spread$2(target) {
|
|
121
128
|
for(var i = 1; i < arguments.length; i++){
|
|
122
129
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
123
130
|
var ownKeys = Object.keys(source);
|
|
@@ -127,12 +134,12 @@ function _object_spread(target) {
|
|
|
127
134
|
}));
|
|
128
135
|
}
|
|
129
136
|
ownKeys.forEach(function(key) {
|
|
130
|
-
_define_property(target, key, source[key]);
|
|
137
|
+
_define_property$4(target, key, source[key]);
|
|
131
138
|
});
|
|
132
139
|
}
|
|
133
140
|
return target;
|
|
134
141
|
}
|
|
135
|
-
function ownKeys(object, enumerableOnly) {
|
|
142
|
+
function ownKeys$2(object, enumerableOnly) {
|
|
136
143
|
var keys = Object.keys(object);
|
|
137
144
|
if (Object.getOwnPropertySymbols) {
|
|
138
145
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
@@ -140,29 +147,29 @@ function ownKeys(object, enumerableOnly) {
|
|
|
140
147
|
}
|
|
141
148
|
return keys;
|
|
142
149
|
}
|
|
143
|
-
function _object_spread_props(target, source) {
|
|
150
|
+
function _object_spread_props$2(target, source) {
|
|
144
151
|
source = source != null ? source : {};
|
|
145
152
|
if (Object.getOwnPropertyDescriptors) {
|
|
146
153
|
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
147
154
|
} else {
|
|
148
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
155
|
+
ownKeys$2(Object(source)).forEach(function(key) {
|
|
149
156
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
150
157
|
});
|
|
151
158
|
}
|
|
152
159
|
return target;
|
|
153
160
|
}
|
|
154
|
-
function _to_consumable_array(arr) {
|
|
155
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
161
|
+
function _to_consumable_array$1(arr) {
|
|
162
|
+
return _array_without_holes$1(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread$1();
|
|
156
163
|
}
|
|
157
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
164
|
+
function _unsupported_iterable_to_array$1(o, minLen) {
|
|
158
165
|
if (!o) return;
|
|
159
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
166
|
+
if (typeof o === "string") return _array_like_to_array$1(o, minLen);
|
|
160
167
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
161
168
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
162
169
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
163
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
170
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
164
171
|
}
|
|
165
|
-
function _ts_generator(thisArg, body) {
|
|
172
|
+
function _ts_generator$2(thisArg, body) {
|
|
166
173
|
var f, y, t, _ = {
|
|
167
174
|
label: 0,
|
|
168
175
|
sent: function() {
|
|
@@ -283,9 +290,9 @@ function _ts_generator(thisArg, body) {
|
|
|
283
290
|
loadZohoAccessTokenCache: function loadZohoAccessTokenCache(serviceKey) {
|
|
284
291
|
var cache = {
|
|
285
292
|
loadCachedToken: function loadCachedToken() {
|
|
286
|
-
return _async_to_generator(function() {
|
|
293
|
+
return _async_to_generator$2(function() {
|
|
287
294
|
var document, existingData, result, tokensArray;
|
|
288
|
-
return _ts_generator(this, function(_state) {
|
|
295
|
+
return _ts_generator$2(this, function(_state) {
|
|
289
296
|
switch(_state.label){
|
|
290
297
|
case 0:
|
|
291
298
|
document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
|
|
@@ -311,17 +318,17 @@ function _ts_generator(thisArg, body) {
|
|
|
311
318
|
})();
|
|
312
319
|
},
|
|
313
320
|
updateCachedToken: function updateCachedToken(accessToken) {
|
|
314
|
-
return _async_to_generator(function() {
|
|
315
|
-
return _ts_generator(this, function(_state) {
|
|
321
|
+
return _async_to_generator$2(function() {
|
|
322
|
+
return _ts_generator$2(this, function(_state) {
|
|
316
323
|
switch(_state.label){
|
|
317
324
|
case 0:
|
|
318
325
|
// run in a transaction
|
|
319
326
|
return [
|
|
320
327
|
4,
|
|
321
328
|
systemStateCollection.firestoreContext.runTransaction(function(transaction) {
|
|
322
|
-
return _async_to_generator(function() {
|
|
329
|
+
return _async_to_generator$2(function() {
|
|
323
330
|
var _ref, documentInTransaction, existingData, existingTokens, tokens, templateOrUpdate;
|
|
324
|
-
return _ts_generator(this, function(_state) {
|
|
331
|
+
return _ts_generator$2(this, function(_state) {
|
|
325
332
|
switch(_state.label){
|
|
326
333
|
case 0:
|
|
327
334
|
documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
|
|
@@ -333,11 +340,11 @@ function _ts_generator(thisArg, body) {
|
|
|
333
340
|
existingData = _state.sent();
|
|
334
341
|
existingTokens = (_ref = existingData === null || existingData === void 0 ? void 0 : existingData.data.tokens) !== null && _ref !== void 0 ? _ref : [];
|
|
335
342
|
tokens = // filter any potential old token for this service key
|
|
336
|
-
_to_consumable_array(existingTokens.filter(function(x) {
|
|
343
|
+
_to_consumable_array$1(existingTokens.filter(function(x) {
|
|
337
344
|
return x.key !== serviceKey;
|
|
338
345
|
})).concat([
|
|
339
346
|
// add the new token
|
|
340
|
-
_object_spread_props(_object_spread({}, accessToken), {
|
|
347
|
+
_object_spread_props$2(_object_spread$2({}, accessToken), {
|
|
341
348
|
key: serviceKey
|
|
342
349
|
})
|
|
343
350
|
]);
|
|
@@ -388,16 +395,16 @@ function _ts_generator(thisArg, body) {
|
|
|
388
395
|
})();
|
|
389
396
|
},
|
|
390
397
|
clearCachedToken: function clearCachedToken() {
|
|
391
|
-
return _async_to_generator(function() {
|
|
392
|
-
return _ts_generator(this, function(_state) {
|
|
398
|
+
return _async_to_generator$2(function() {
|
|
399
|
+
return _ts_generator$2(this, function(_state) {
|
|
393
400
|
switch(_state.label){
|
|
394
401
|
case 0:
|
|
395
402
|
return [
|
|
396
403
|
4,
|
|
397
404
|
systemStateCollection.firestoreContext.runTransaction(function(transaction) {
|
|
398
|
-
return _async_to_generator(function() {
|
|
405
|
+
return _async_to_generator$2(function() {
|
|
399
406
|
var documentInTransaction, existingData, templateOrUpdate;
|
|
400
|
-
return _ts_generator(this, function(_state) {
|
|
407
|
+
return _ts_generator$2(this, function(_state) {
|
|
401
408
|
switch(_state.label){
|
|
402
409
|
case 0:
|
|
403
410
|
documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
|
|
@@ -449,8 +456,1191 @@ function _ts_generator(thisArg, body) {
|
|
|
449
456
|
return service;
|
|
450
457
|
}
|
|
451
458
|
|
|
459
|
+
function _type_of$3(obj) {
|
|
460
|
+
"@swc/helpers - typeof";
|
|
461
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
462
|
+
}
|
|
463
|
+
function __decorate(decorators, target, key, desc) {
|
|
464
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
465
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _type_of$3(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
466
|
+
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;
|
|
467
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
468
|
+
}
|
|
469
|
+
function __param(paramIndex, decorator) {
|
|
470
|
+
return function(target, key) {
|
|
471
|
+
decorator(target, key, paramIndex);
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
475
|
+
var e = new Error(message);
|
|
476
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
function _assert_this_initialized$2(self) {
|
|
480
|
+
if (self === void 0) {
|
|
481
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
482
|
+
}
|
|
483
|
+
return self;
|
|
484
|
+
}
|
|
485
|
+
function _call_super$2(_this, derived, args) {
|
|
486
|
+
derived = _get_prototype_of$2(derived);
|
|
487
|
+
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));
|
|
488
|
+
}
|
|
489
|
+
function _class_call_check$2(instance, Constructor) {
|
|
490
|
+
if (!(instance instanceof Constructor)) {
|
|
491
|
+
throw new TypeError("Cannot call a class as a function");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function _define_property$3(obj, key, value) {
|
|
495
|
+
if (key in obj) {
|
|
496
|
+
Object.defineProperty(obj, key, {
|
|
497
|
+
value: value,
|
|
498
|
+
enumerable: true,
|
|
499
|
+
configurable: true,
|
|
500
|
+
writable: true
|
|
501
|
+
});
|
|
502
|
+
} else {
|
|
503
|
+
obj[key] = value;
|
|
504
|
+
}
|
|
505
|
+
return obj;
|
|
506
|
+
}
|
|
507
|
+
function _get_prototype_of$2(o) {
|
|
508
|
+
_get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
509
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
510
|
+
};
|
|
511
|
+
return _get_prototype_of$2(o);
|
|
512
|
+
}
|
|
513
|
+
function _inherits$2(subClass, superClass) {
|
|
514
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
515
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
516
|
+
}
|
|
517
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
518
|
+
constructor: {
|
|
519
|
+
value: subClass,
|
|
520
|
+
writable: true,
|
|
521
|
+
configurable: true
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
if (superClass) _set_prototype_of$2(subClass, superClass);
|
|
525
|
+
}
|
|
526
|
+
function _object_spread$1(target) {
|
|
527
|
+
for(var i = 1; i < arguments.length; i++){
|
|
528
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
529
|
+
var ownKeys = Object.keys(source);
|
|
530
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
531
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
532
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
533
|
+
}));
|
|
534
|
+
}
|
|
535
|
+
ownKeys.forEach(function(key) {
|
|
536
|
+
_define_property$3(target, key, source[key]);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
return target;
|
|
540
|
+
}
|
|
541
|
+
function ownKeys$1(object, enumerableOnly) {
|
|
542
|
+
var keys = Object.keys(object);
|
|
543
|
+
if (Object.getOwnPropertySymbols) {
|
|
544
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
545
|
+
keys.push.apply(keys, symbols);
|
|
546
|
+
}
|
|
547
|
+
return keys;
|
|
548
|
+
}
|
|
549
|
+
function _object_spread_props$1(target, source) {
|
|
550
|
+
source = source != null ? source : {};
|
|
551
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
552
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
553
|
+
} else {
|
|
554
|
+
ownKeys$1(Object(source)).forEach(function(key) {
|
|
555
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return target;
|
|
559
|
+
}
|
|
560
|
+
function _possible_constructor_return$2(self, call) {
|
|
561
|
+
if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
|
|
562
|
+
return call;
|
|
563
|
+
}
|
|
564
|
+
return _assert_this_initialized$2(self);
|
|
565
|
+
}
|
|
566
|
+
function _set_prototype_of$2(o, p) {
|
|
567
|
+
_set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
568
|
+
o.__proto__ = p;
|
|
569
|
+
return o;
|
|
570
|
+
};
|
|
571
|
+
return _set_prototype_of$2(o, p);
|
|
572
|
+
}
|
|
573
|
+
function _type_of$2(obj) {
|
|
574
|
+
"@swc/helpers - typeof";
|
|
575
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
576
|
+
}
|
|
577
|
+
function _is_native_reflect_construct$2() {
|
|
578
|
+
try {
|
|
579
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
580
|
+
} catch (_) {}
|
|
581
|
+
return (_is_native_reflect_construct$2 = function() {
|
|
582
|
+
return !!result;
|
|
583
|
+
})();
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Controller path the Zoho external-connection OAuth endpoints are mounted at.
|
|
587
|
+
*
|
|
588
|
+
* Derived from the framework's path factory, the same expression the redirect URI and the
|
|
589
|
+
* global-prefix exclusion are built from, so the three cannot drift apart.
|
|
590
|
+
*/ var ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = model.userExternalConnectionOAuthControllerPath(firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
|
|
591
|
+
/**
|
|
592
|
+
* Routes to exclude from an app's global API route prefix so the Zoho callback controller stays
|
|
593
|
+
* mounted at `/oauth/zoho/*`.
|
|
594
|
+
*
|
|
595
|
+
* Spread this into the `exclude` list of the app's `globalApiRoutePrefix` config, alongside
|
|
596
|
+
* `FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE`.
|
|
597
|
+
*/ var ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = model.userExternalConnectionOAuthRoutesForGlobalRouteExclude(firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
|
|
598
|
+
/**
|
|
599
|
+
* The scopes requested when an app does not declare its own.
|
|
600
|
+
*
|
|
601
|
+
* Declared in code, deliberately NOT read from the environment: the set to request follows from what
|
|
602
|
+
* the integration actually does, so it belongs where it is reviewable.
|
|
603
|
+
*
|
|
604
|
+
* Least privilege for a connect that proves the handoff and labels the connection: read the
|
|
605
|
+
* authorizing user's Zoho identity, and nothing else. No `ZohoCRM.*` / `ZohoRecruit.*` scope is
|
|
606
|
+
* requested because the default integration makes no product API call — requesting one would be
|
|
607
|
+
* privilege the code never uses, which is the same error as under-requesting, in the other
|
|
608
|
+
* direction. An app that actually calls a Zoho product declares its own set on the module metadata,
|
|
609
|
+
* in code.
|
|
610
|
+
*
|
|
611
|
+
* Unlike Cal.com, Zoho does not pre-register scopes on the OAuth client, so nothing has to be
|
|
612
|
+
* registered in the API console to request this.
|
|
613
|
+
*/ var DEFAULT_ZOHO_OAUTH_SCOPES = [
|
|
614
|
+
zoho.ZOHO_ACCOUNTS_PROFILE_READ_SCOPE
|
|
615
|
+
];
|
|
616
|
+
/**
|
|
617
|
+
* Configuration for the {@link ZohoUserExternalConnectionOAuthService}.
|
|
618
|
+
*
|
|
619
|
+
* Extends the framework config with what is Zoho's own: which scopes to request, and which
|
|
620
|
+
* datacenter to authorize against.
|
|
621
|
+
*/ var ZohoUserExternalConnectionOAuthServiceConfig = /*#__PURE__*/ function(UserExternalConnectionOAuthServiceConfig) {
|
|
622
|
+
_inherits$2(ZohoUserExternalConnectionOAuthServiceConfig, UserExternalConnectionOAuthServiceConfig);
|
|
623
|
+
function ZohoUserExternalConnectionOAuthServiceConfig() {
|
|
624
|
+
_class_call_check$2(this, ZohoUserExternalConnectionOAuthServiceConfig);
|
|
625
|
+
var _this;
|
|
626
|
+
_this = _call_super$2(this, ZohoUserExternalConnectionOAuthServiceConfig, arguments), _define_property$3(_this, "scopes", void 0), /**
|
|
627
|
+
* Datacenter to authorize against. Defaults to the api's configured one.
|
|
628
|
+
*/ _define_property$3(_this, "accountsApiUrl", void 0);
|
|
629
|
+
return _this;
|
|
630
|
+
}
|
|
631
|
+
return ZohoUserExternalConnectionOAuthServiceConfig;
|
|
632
|
+
}(model.UserExternalConnectionOAuthServiceConfig);
|
|
633
|
+
/**
|
|
634
|
+
* Builds the Zoho connect flow's configuration from the app's configured origins.
|
|
635
|
+
*
|
|
636
|
+
* Nothing here is read from the environment as a value: the redirect URI is derived from the app's
|
|
637
|
+
* OAuth origin plus the mounted controller path, and the return URLs from the app URL plus
|
|
638
|
+
* code-declared paths. Registering Zoho therefore adds no deployment configuration beyond the client
|
|
639
|
+
* credentials the OAuth api already reads.
|
|
640
|
+
*
|
|
641
|
+
* @param config - The env service, the return paths, and the optional scope/datacenter overrides.
|
|
642
|
+
* @returns The validated service configuration.
|
|
643
|
+
*/ function zohoUserExternalConnectionOAuthServiceConfigFactory(config) {
|
|
644
|
+
var envService = config.envService, successPath = config.successPath, failurePath = config.failurePath, scopes = config.scopes, accountsApiUrl = config.accountsApiUrl;
|
|
645
|
+
var baseConfig = model.userExternalConnectionOAuthServiceConfigFactory({
|
|
646
|
+
envService: envService,
|
|
647
|
+
providerType: firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE,
|
|
648
|
+
successPath: successPath,
|
|
649
|
+
failurePath: failurePath
|
|
650
|
+
});
|
|
651
|
+
return _object_spread_props$1(_object_spread$1({}, baseConfig), {
|
|
652
|
+
scopes: scopes !== null && scopes !== void 0 ? scopes : DEFAULT_ZOHO_OAUTH_SCOPES,
|
|
653
|
+
accountsApiUrl: accountsApiUrl
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function _assert_this_initialized$1(self) {
|
|
658
|
+
if (self === void 0) {
|
|
659
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
660
|
+
}
|
|
661
|
+
return self;
|
|
662
|
+
}
|
|
663
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
664
|
+
try {
|
|
665
|
+
var info = gen[key](arg);
|
|
666
|
+
var value = info.value;
|
|
667
|
+
} catch (error) {
|
|
668
|
+
reject(error);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (info.done) {
|
|
672
|
+
resolve(value);
|
|
673
|
+
} else {
|
|
674
|
+
Promise.resolve(value).then(_next, _throw);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function _async_to_generator$1(fn) {
|
|
678
|
+
return function() {
|
|
679
|
+
var self = this, args = arguments;
|
|
680
|
+
return new Promise(function(resolve, reject) {
|
|
681
|
+
var gen = fn.apply(self, args);
|
|
682
|
+
function _next(value) {
|
|
683
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
684
|
+
}
|
|
685
|
+
function _throw(err) {
|
|
686
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
687
|
+
}
|
|
688
|
+
_next(undefined);
|
|
689
|
+
});
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function _call_super$1(_this, derived, args) {
|
|
693
|
+
derived = _get_prototype_of$1(derived);
|
|
694
|
+
return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
|
|
695
|
+
}
|
|
696
|
+
function _class_call_check$1(instance, Constructor) {
|
|
697
|
+
if (!(instance instanceof Constructor)) {
|
|
698
|
+
throw new TypeError("Cannot call a class as a function");
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function _defineProperties(target, props) {
|
|
702
|
+
for(var i = 0; i < props.length; i++){
|
|
703
|
+
var descriptor = props[i];
|
|
704
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
705
|
+
descriptor.configurable = true;
|
|
706
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
707
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
711
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
712
|
+
return Constructor;
|
|
713
|
+
}
|
|
714
|
+
function _define_property$2(obj, key, value) {
|
|
715
|
+
if (key in obj) {
|
|
716
|
+
Object.defineProperty(obj, key, {
|
|
717
|
+
value: value,
|
|
718
|
+
enumerable: true,
|
|
719
|
+
configurable: true,
|
|
720
|
+
writable: true
|
|
721
|
+
});
|
|
722
|
+
} else {
|
|
723
|
+
obj[key] = value;
|
|
724
|
+
}
|
|
725
|
+
return obj;
|
|
726
|
+
}
|
|
727
|
+
function _get_prototype_of$1(o) {
|
|
728
|
+
_get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
729
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
730
|
+
};
|
|
731
|
+
return _get_prototype_of$1(o);
|
|
732
|
+
}
|
|
733
|
+
function _inherits$1(subClass, superClass) {
|
|
734
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
735
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
736
|
+
}
|
|
737
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
738
|
+
constructor: {
|
|
739
|
+
value: subClass,
|
|
740
|
+
writable: true,
|
|
741
|
+
configurable: true
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
if (superClass) _set_prototype_of$1(subClass, superClass);
|
|
745
|
+
}
|
|
746
|
+
function _possible_constructor_return$1(self, call) {
|
|
747
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
748
|
+
return call;
|
|
749
|
+
}
|
|
750
|
+
return _assert_this_initialized$1(self);
|
|
751
|
+
}
|
|
752
|
+
function _set_prototype_of$1(o, p) {
|
|
753
|
+
_set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
754
|
+
o.__proto__ = p;
|
|
755
|
+
return o;
|
|
756
|
+
};
|
|
757
|
+
return _set_prototype_of$1(o, p);
|
|
758
|
+
}
|
|
759
|
+
function _type_of$1(obj) {
|
|
760
|
+
"@swc/helpers - typeof";
|
|
761
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
762
|
+
}
|
|
763
|
+
function _is_native_reflect_construct$1() {
|
|
764
|
+
try {
|
|
765
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
766
|
+
} catch (_) {}
|
|
767
|
+
return (_is_native_reflect_construct$1 = function() {
|
|
768
|
+
return !!result;
|
|
769
|
+
})();
|
|
770
|
+
}
|
|
771
|
+
function _ts_generator$1(thisArg, body) {
|
|
772
|
+
var f, y, t, _ = {
|
|
773
|
+
label: 0,
|
|
774
|
+
sent: function() {
|
|
775
|
+
if (t[0] & 1) throw t[1];
|
|
776
|
+
return t[1];
|
|
777
|
+
},
|
|
778
|
+
trys: [],
|
|
779
|
+
ops: []
|
|
780
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
781
|
+
return d(g, "next", {
|
|
782
|
+
value: verb(0)
|
|
783
|
+
}), d(g, "throw", {
|
|
784
|
+
value: verb(1)
|
|
785
|
+
}), d(g, "return", {
|
|
786
|
+
value: verb(2)
|
|
787
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
788
|
+
value: function() {
|
|
789
|
+
return this;
|
|
790
|
+
}
|
|
791
|
+
}), g;
|
|
792
|
+
function verb(n) {
|
|
793
|
+
return function(v) {
|
|
794
|
+
return step([
|
|
795
|
+
n,
|
|
796
|
+
v
|
|
797
|
+
]);
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
function step(op) {
|
|
801
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
802
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
803
|
+
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;
|
|
804
|
+
if (y = 0, t) op = [
|
|
805
|
+
op[0] & 2,
|
|
806
|
+
t.value
|
|
807
|
+
];
|
|
808
|
+
switch(op[0]){
|
|
809
|
+
case 0:
|
|
810
|
+
case 1:
|
|
811
|
+
t = op;
|
|
812
|
+
break;
|
|
813
|
+
case 4:
|
|
814
|
+
_.label++;
|
|
815
|
+
return {
|
|
816
|
+
value: op[1],
|
|
817
|
+
done: false
|
|
818
|
+
};
|
|
819
|
+
case 5:
|
|
820
|
+
_.label++;
|
|
821
|
+
y = op[1];
|
|
822
|
+
op = [
|
|
823
|
+
0
|
|
824
|
+
];
|
|
825
|
+
continue;
|
|
826
|
+
case 7:
|
|
827
|
+
op = _.ops.pop();
|
|
828
|
+
_.trys.pop();
|
|
829
|
+
continue;
|
|
830
|
+
default:
|
|
831
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
832
|
+
_ = 0;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
836
|
+
_.label = op[1];
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
840
|
+
_.label = t[1];
|
|
841
|
+
t = op;
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
if (t && _.label < t[2]) {
|
|
845
|
+
_.label = t[2];
|
|
846
|
+
_.ops.push(op);
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
if (t[2]) _.ops.pop();
|
|
850
|
+
_.trys.pop();
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
op = body.call(thisArg, _);
|
|
854
|
+
} catch (e) {
|
|
855
|
+
op = [
|
|
856
|
+
6,
|
|
857
|
+
e
|
|
858
|
+
];
|
|
859
|
+
y = 0;
|
|
860
|
+
} finally{
|
|
861
|
+
f = t = 0;
|
|
862
|
+
}
|
|
863
|
+
if (op[0] & 5) throw op[1];
|
|
864
|
+
return {
|
|
865
|
+
value: op[0] ? op[1] : void 0,
|
|
866
|
+
done: true
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* The callback parameter naming the datacenter whose accounts server issued the code.
|
|
872
|
+
*/ var ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM = 'accounts-server';
|
|
873
|
+
/**
|
|
874
|
+
* The callback parameter naming the datacenter's short location code, e.g. `us`.
|
|
875
|
+
*/ var ZOHO_OAUTH_CALLBACK_LOCATION_PARAM = 'location';
|
|
876
|
+
/**
|
|
877
|
+
* `extra` key holding the api domain a Zoho access token is usable against.
|
|
878
|
+
*
|
|
879
|
+
* Named constants because these keys are written on connect and read back on refresh — a literal in
|
|
880
|
+
* one place and a typo in the other would silently send the refresh to the wrong datacenter.
|
|
881
|
+
*/ var ZOHO_EXTRA_API_DOMAIN_KEY = 'apiDomain';
|
|
882
|
+
/**
|
|
883
|
+
* `extra` key holding the accounts host a later refresh must be sent to.
|
|
884
|
+
*/ var ZOHO_EXTRA_ACCOUNTS_SERVER_KEY = 'accountsServer';
|
|
885
|
+
/**
|
|
886
|
+
* `extra` key holding Zoho's short location code for the datacenter.
|
|
887
|
+
*/ var ZOHO_EXTRA_LOCATION_KEY = 'location';
|
|
888
|
+
/**
|
|
889
|
+
* Maps an exchanged Zoho token response to the credentials stored on the private connection document.
|
|
890
|
+
*
|
|
891
|
+
* Two things differ from Cal.com's mapper. Zoho does not rotate its refresh token, so there is
|
|
892
|
+
* nothing to prefer over the token we already hold — and `refresh_token` can be ABSENT entirely on a
|
|
893
|
+
* re-consent, which is why it is passed through as `Maybe` rather than asserted (the framework's
|
|
894
|
+
* `credentialsRetainingStoredRefreshToken` is what keeps that from destroying a working token). And
|
|
895
|
+
* `api_domain` / `accountsServer` / `location` are retained in `extra`: a Zoho access token is only
|
|
896
|
+
* usable against the api domain it was issued for, and a later refresh must go back to the same
|
|
897
|
+
* datacenter's accounts server, so dropping them would leave the stored credentials unusable.
|
|
898
|
+
*
|
|
899
|
+
* @param input - The token response, the host it came from, and the identity when one was read.
|
|
900
|
+
* @returns The credentials to store.
|
|
901
|
+
*/ function zohoUserExternalConnectionCredentials(input) {
|
|
902
|
+
var _ref, _ref1;
|
|
903
|
+
var response = input.response, accountsApiUrl = input.accountsApiUrl, location = input.location, userInfo = input.userInfo;
|
|
904
|
+
var access_token = response.access_token, refresh_token = response.refresh_token, expires_in = response.expires_in, scope = response.scope, api_domain = response.api_domain;
|
|
905
|
+
var now = Date.now();
|
|
906
|
+
var zuid = userInfo === null || userInfo === void 0 ? void 0 : userInfo.ZUID;
|
|
907
|
+
var _obj;
|
|
908
|
+
return {
|
|
909
|
+
accessToken: access_token,
|
|
910
|
+
// Maybe on purpose — absent on a re-consent that did not force the consent screen
|
|
911
|
+
refreshToken: refresh_token,
|
|
912
|
+
tokenType: 'Bearer',
|
|
913
|
+
issuedAt: new Date(now).toISOString(),
|
|
914
|
+
expiresAt: expires_in == null ? undefined : new Date(now + expires_in * util.MS_IN_SECOND).toISOString(),
|
|
915
|
+
scopes: zoho.zohoOAuthScopesFromScopeString(scope),
|
|
916
|
+
externalAccountId: zuid == null ? undefined : String(zuid),
|
|
917
|
+
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,
|
|
918
|
+
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)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Zoho's half of the external-connection authorization-code handoff.
|
|
923
|
+
*
|
|
924
|
+
* Everything else — resolving who is connecting, surfacing a refusal, retaining a refresh token the
|
|
925
|
+
* exchange did not return, persisting the credentials, choosing the redirect — is the framework's.
|
|
926
|
+
*/ exports.ZohoUserExternalConnectionOAuthService = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthService) {
|
|
927
|
+
_inherits$1(ZohoUserExternalConnectionOAuthService, AbstractUserExternalConnectionOAuthService);
|
|
928
|
+
function ZohoUserExternalConnectionOAuthService(config, stateCoder, userExternalConnectionActions, userExternalConnectionAccessor, oauthApi) {
|
|
929
|
+
_class_call_check$1(this, ZohoUserExternalConnectionOAuthService);
|
|
930
|
+
var _this;
|
|
931
|
+
_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), /**
|
|
932
|
+
* The accounts host this app authorizes against, and the fallback for an exchange whose callback
|
|
933
|
+
* named no usable one.
|
|
934
|
+
*/ _define_property$2(_this, "accountsApiUrl", void 0);
|
|
935
|
+
_this.config = config;
|
|
936
|
+
_this.stateCoder = stateCoder;
|
|
937
|
+
_this.userExternalConnectionActions = userExternalConnectionActions;
|
|
938
|
+
_this.userExternalConnectionAccessor = userExternalConnectionAccessor;
|
|
939
|
+
_this.oauthApi = oauthApi;
|
|
940
|
+
var scopes = config.scopes, accountsApiUrl = config.accountsApiUrl, userExternalConnectionOAuth = config.userExternalConnectionOAuth;
|
|
941
|
+
// read through the api rather than injecting ZohoAccountsOAuthServiceConfig directly, which the
|
|
942
|
+
// OAuth module does not export to its dependents
|
|
943
|
+
_this.accountsApiUrl = accountsApiUrl == null ? oauthApi.apiUrl : zoho.zohoAccountsConfigApiUrl(accountsApiUrl);
|
|
944
|
+
_this.authorizeUrlFactory = zoho.zohoAccountsAuthorizeUrlFactory({
|
|
945
|
+
clientId: oauthApi.clientId,
|
|
946
|
+
redirectUri: userExternalConnectionOAuth.redirectUri,
|
|
947
|
+
scopes: scopes,
|
|
948
|
+
accountsApiUrl: _this.accountsApiUrl
|
|
949
|
+
});
|
|
950
|
+
return _this;
|
|
951
|
+
}
|
|
952
|
+
_create_class(ZohoUserExternalConnectionOAuthService, [
|
|
953
|
+
{
|
|
954
|
+
key: "authorizeUrlForState",
|
|
955
|
+
value: function authorizeUrlForState(state) {
|
|
956
|
+
return this.authorizeUrlFactory({
|
|
957
|
+
state: state
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
key: "credentialsForAuthorizationCode",
|
|
963
|
+
value: function credentialsForAuthorizationCode(input) {
|
|
964
|
+
return _async_to_generator$1(function() {
|
|
965
|
+
var _this_accountsApiUrlForCallbackQuery, code, redirectUri, query, accountsApiUrl, response, userInfo, e;
|
|
966
|
+
return _ts_generator$1(this, function(_state) {
|
|
967
|
+
switch(_state.label){
|
|
968
|
+
case 0:
|
|
969
|
+
code = input.code, redirectUri = input.redirectUri, query = input.query;
|
|
970
|
+
accountsApiUrl = (_this_accountsApiUrlForCallbackQuery = this.accountsApiUrlForCallbackQuery(query)) !== null && _this_accountsApiUrlForCallbackQuery !== void 0 ? _this_accountsApiUrlForCallbackQuery : this.accountsApiUrl;
|
|
971
|
+
return [
|
|
972
|
+
4,
|
|
973
|
+
this.oauthApi.exchangeAuthorizationCode({
|
|
974
|
+
code: code,
|
|
975
|
+
redirectUri: redirectUri,
|
|
976
|
+
accountsApiUrl: accountsApiUrl
|
|
977
|
+
})
|
|
978
|
+
];
|
|
979
|
+
case 1:
|
|
980
|
+
response = _state.sent();
|
|
981
|
+
_state.label = 2;
|
|
982
|
+
case 2:
|
|
983
|
+
_state.trys.push([
|
|
984
|
+
2,
|
|
985
|
+
4,
|
|
986
|
+
,
|
|
987
|
+
5
|
|
988
|
+
]);
|
|
989
|
+
return [
|
|
990
|
+
4,
|
|
991
|
+
this.oauthApi.userInfo({
|
|
992
|
+
accessToken: response.access_token,
|
|
993
|
+
accountsApiUrl: accountsApiUrl
|
|
994
|
+
})
|
|
995
|
+
];
|
|
996
|
+
case 3:
|
|
997
|
+
userInfo = _state.sent();
|
|
998
|
+
return [
|
|
999
|
+
3,
|
|
1000
|
+
5
|
|
1001
|
+
];
|
|
1002
|
+
case 4:
|
|
1003
|
+
e = _state.sent();
|
|
1004
|
+
this.logger.warn('Connected Zoho but could not read the identity to label the connection: ', e);
|
|
1005
|
+
return [
|
|
1006
|
+
3,
|
|
1007
|
+
5
|
|
1008
|
+
];
|
|
1009
|
+
case 5:
|
|
1010
|
+
return [
|
|
1011
|
+
2,
|
|
1012
|
+
zohoUserExternalConnectionCredentials({
|
|
1013
|
+
response: response,
|
|
1014
|
+
accountsApiUrl: accountsApiUrl,
|
|
1015
|
+
location: query === null || query === void 0 ? void 0 : query[ZOHO_OAUTH_CALLBACK_LOCATION_PARAM],
|
|
1016
|
+
userInfo: userInfo
|
|
1017
|
+
})
|
|
1018
|
+
];
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}).call(this);
|
|
1022
|
+
}
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
key: "refreshCredentials",
|
|
1026
|
+
value: function refreshCredentials(input) {
|
|
1027
|
+
return _async_to_generator$1(function() {
|
|
1028
|
+
var _this_allowlistedAccountsApiUrl, credentials, refreshToken, extra, storedAccountsServer, accountsApiUrl, response, location;
|
|
1029
|
+
return _ts_generator$1(this, function(_state) {
|
|
1030
|
+
switch(_state.label){
|
|
1031
|
+
case 0:
|
|
1032
|
+
credentials = input.credentials;
|
|
1033
|
+
refreshToken = credentials.refreshToken, extra = credentials.extra;
|
|
1034
|
+
if (!refreshToken) {
|
|
1035
|
+
throw new Error('ZohoUserExternalConnectionOAuthService.refreshCredentials: the stored credentials carry no refresh token.');
|
|
1036
|
+
}
|
|
1037
|
+
// the grant lives at ONE datacenter — a refresh token issued by `accounts.zoho.eu` is not honored
|
|
1038
|
+
// by `accounts.zoho.com` — so the stored accounts server is what the refresh must be sent to. It is
|
|
1039
|
+
// re-resolved through the allowlist rather than used verbatim: the value originally arrived on a
|
|
1040
|
+
// browser redirect, and it is the POST target the client secret travels to.
|
|
1041
|
+
storedAccountsServer = extra === null || extra === void 0 ? void 0 : extra[ZOHO_EXTRA_ACCOUNTS_SERVER_KEY];
|
|
1042
|
+
accountsApiUrl = (_this_allowlistedAccountsApiUrl = this.allowlistedAccountsApiUrl(storedAccountsServer == null ? undefined : String(storedAccountsServer))) !== null && _this_allowlistedAccountsApiUrl !== void 0 ? _this_allowlistedAccountsApiUrl : this.accountsApiUrl;
|
|
1043
|
+
return [
|
|
1044
|
+
4,
|
|
1045
|
+
this.oauthApi.refreshUserAccessToken({
|
|
1046
|
+
refreshToken: refreshToken,
|
|
1047
|
+
accountsApiUrl: accountsApiUrl
|
|
1048
|
+
})
|
|
1049
|
+
];
|
|
1050
|
+
case 1:
|
|
1051
|
+
response = _state.sent();
|
|
1052
|
+
// `location` is carried forward from the stored credentials rather than re-derived: it only ever
|
|
1053
|
+
// arrives on the callback, and the framework's merge would otherwise see an undefined value.
|
|
1054
|
+
location = extra === null || extra === void 0 ? void 0 : extra[ZOHO_EXTRA_LOCATION_KEY];
|
|
1055
|
+
// the response has no `refresh_token`, which the framework's merge retains — and `api_domain` may
|
|
1056
|
+
// legitimately differ from the one issued on connect, so it is taken from the response
|
|
1057
|
+
return [
|
|
1058
|
+
2,
|
|
1059
|
+
zohoUserExternalConnectionCredentials({
|
|
1060
|
+
response: response,
|
|
1061
|
+
accountsApiUrl: accountsApiUrl,
|
|
1062
|
+
location: location == null ? undefined : String(location)
|
|
1063
|
+
})
|
|
1064
|
+
];
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
}).call(this);
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
/**
|
|
1072
|
+
* The accounts host to exchange against, taken from Zoho's `accounts-server` callback parameter.
|
|
1073
|
+
*
|
|
1074
|
+
* @param query - The raw callback query.
|
|
1075
|
+
* @returns The allowlisted accounts host the callback named, if any.
|
|
1076
|
+
*/ key: "accountsApiUrlForCallbackQuery",
|
|
1077
|
+
value: function accountsApiUrlForCallbackQuery(query) {
|
|
1078
|
+
return this.allowlistedAccountsApiUrl(query === null || query === void 0 ? void 0 : query[ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM]);
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
{
|
|
1082
|
+
/**
|
|
1083
|
+
* Resolves an untrusted accounts-host string back to one of the canonical Zoho hosts.
|
|
1084
|
+
*
|
|
1085
|
+
* Only an allowlisted Zoho host is honored. Every value passed here originated on a redirect an
|
|
1086
|
+
* attacker can compose — either the live callback query or a value persisted from an earlier one —
|
|
1087
|
+
* and it becomes the POST target the CLIENT SECRET is sent to, so an unchecked value would hand out
|
|
1088
|
+
* the secret. Resolving through the allowlist rather than comparing to it also guarantees the host
|
|
1089
|
+
* used is a canonical constant and never a caller-shaped variant of one. An unrecognized value is
|
|
1090
|
+
* dropped (and logged) rather than trusted.
|
|
1091
|
+
*
|
|
1092
|
+
* @param accountsServer - The untrusted host string, if any.
|
|
1093
|
+
* @returns The allowlisted accounts host, or null when there was none or it was not recognized.
|
|
1094
|
+
*/ key: "allowlistedAccountsApiUrl",
|
|
1095
|
+
value: function allowlistedAccountsApiUrl(accountsServer) {
|
|
1096
|
+
var result;
|
|
1097
|
+
if (accountsServer) {
|
|
1098
|
+
var key = zoho.zohoAccountsApiUrlKeyForApiUrl(accountsServer);
|
|
1099
|
+
if (key == null) {
|
|
1100
|
+
this.logger.warn('Ignored an unrecognized Zoho accounts host of "'.concat(accountsServer, '"; using the configured host instead.'));
|
|
1101
|
+
} else {
|
|
1102
|
+
result = zoho.ZOHO_ACCOUNTS_API_URLS[key];
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return result;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
]);
|
|
1109
|
+
return ZohoUserExternalConnectionOAuthService;
|
|
1110
|
+
}(model.AbstractUserExternalConnectionOAuthService);
|
|
1111
|
+
exports.ZohoUserExternalConnectionOAuthService = __decorate([
|
|
1112
|
+
common.Injectable(),
|
|
1113
|
+
__param(0, common.Inject(ZohoUserExternalConnectionOAuthServiceConfig)),
|
|
1114
|
+
__param(1, common.Inject(model.UserExternalConnectionStateCoder)),
|
|
1115
|
+
__param(2, common.Inject(model.UserExternalConnectionServerActions)),
|
|
1116
|
+
__param(3, common.Inject(model.UserExternalConnectionAccessor)),
|
|
1117
|
+
__param(4, common.Inject(nestjs.ZohoAccountsOAuthApi))
|
|
1118
|
+
], exports.ZohoUserExternalConnectionOAuthService);
|
|
1119
|
+
|
|
1120
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1121
|
+
try {
|
|
1122
|
+
var info = gen[key](arg);
|
|
1123
|
+
var value = info.value;
|
|
1124
|
+
} catch (error) {
|
|
1125
|
+
reject(error);
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
if (info.done) {
|
|
1129
|
+
resolve(value);
|
|
1130
|
+
} else {
|
|
1131
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function _async_to_generator(fn) {
|
|
1135
|
+
return function() {
|
|
1136
|
+
var self = this, args = arguments;
|
|
1137
|
+
return new Promise(function(resolve, reject) {
|
|
1138
|
+
var gen = fn.apply(self, args);
|
|
1139
|
+
function _next(value) {
|
|
1140
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1141
|
+
}
|
|
1142
|
+
function _throw(err) {
|
|
1143
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1144
|
+
}
|
|
1145
|
+
_next(undefined);
|
|
1146
|
+
});
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
function _define_property$1(obj, key, value) {
|
|
1150
|
+
if (key in obj) {
|
|
1151
|
+
Object.defineProperty(obj, key, {
|
|
1152
|
+
value: value,
|
|
1153
|
+
enumerable: true,
|
|
1154
|
+
configurable: true,
|
|
1155
|
+
writable: true
|
|
1156
|
+
});
|
|
1157
|
+
} else {
|
|
1158
|
+
obj[key] = value;
|
|
1159
|
+
}
|
|
1160
|
+
return obj;
|
|
1161
|
+
}
|
|
1162
|
+
function _object_spread(target) {
|
|
1163
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1164
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
1165
|
+
var ownKeys = Object.keys(source);
|
|
1166
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1167
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1168
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1169
|
+
}));
|
|
1170
|
+
}
|
|
1171
|
+
ownKeys.forEach(function(key) {
|
|
1172
|
+
_define_property$1(target, key, source[key]);
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
return target;
|
|
1176
|
+
}
|
|
1177
|
+
function ownKeys(object, enumerableOnly) {
|
|
1178
|
+
var keys = Object.keys(object);
|
|
1179
|
+
if (Object.getOwnPropertySymbols) {
|
|
1180
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
1181
|
+
keys.push.apply(keys, symbols);
|
|
1182
|
+
}
|
|
1183
|
+
return keys;
|
|
1184
|
+
}
|
|
1185
|
+
function _object_spread_props(target, source) {
|
|
1186
|
+
source = source != null ? source : {};
|
|
1187
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
1188
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
1189
|
+
} else {
|
|
1190
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
1191
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
return target;
|
|
1195
|
+
}
|
|
1196
|
+
function _ts_generator(thisArg, body) {
|
|
1197
|
+
var f, y, t, _ = {
|
|
1198
|
+
label: 0,
|
|
1199
|
+
sent: function() {
|
|
1200
|
+
if (t[0] & 1) throw t[1];
|
|
1201
|
+
return t[1];
|
|
1202
|
+
},
|
|
1203
|
+
trys: [],
|
|
1204
|
+
ops: []
|
|
1205
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1206
|
+
return d(g, "next", {
|
|
1207
|
+
value: verb(0)
|
|
1208
|
+
}), d(g, "throw", {
|
|
1209
|
+
value: verb(1)
|
|
1210
|
+
}), d(g, "return", {
|
|
1211
|
+
value: verb(2)
|
|
1212
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1213
|
+
value: function() {
|
|
1214
|
+
return this;
|
|
1215
|
+
}
|
|
1216
|
+
}), g;
|
|
1217
|
+
function verb(n) {
|
|
1218
|
+
return function(v) {
|
|
1219
|
+
return step([
|
|
1220
|
+
n,
|
|
1221
|
+
v
|
|
1222
|
+
]);
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
function step(op) {
|
|
1226
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1227
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1228
|
+
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;
|
|
1229
|
+
if (y = 0, t) op = [
|
|
1230
|
+
op[0] & 2,
|
|
1231
|
+
t.value
|
|
1232
|
+
];
|
|
1233
|
+
switch(op[0]){
|
|
1234
|
+
case 0:
|
|
1235
|
+
case 1:
|
|
1236
|
+
t = op;
|
|
1237
|
+
break;
|
|
1238
|
+
case 4:
|
|
1239
|
+
_.label++;
|
|
1240
|
+
return {
|
|
1241
|
+
value: op[1],
|
|
1242
|
+
done: false
|
|
1243
|
+
};
|
|
1244
|
+
case 5:
|
|
1245
|
+
_.label++;
|
|
1246
|
+
y = op[1];
|
|
1247
|
+
op = [
|
|
1248
|
+
0
|
|
1249
|
+
];
|
|
1250
|
+
continue;
|
|
1251
|
+
case 7:
|
|
1252
|
+
op = _.ops.pop();
|
|
1253
|
+
_.trys.pop();
|
|
1254
|
+
continue;
|
|
1255
|
+
default:
|
|
1256
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1257
|
+
_ = 0;
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1261
|
+
_.label = op[1];
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1264
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1265
|
+
_.label = t[1];
|
|
1266
|
+
t = op;
|
|
1267
|
+
break;
|
|
1268
|
+
}
|
|
1269
|
+
if (t && _.label < t[2]) {
|
|
1270
|
+
_.label = t[2];
|
|
1271
|
+
_.ops.push(op);
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
if (t[2]) _.ops.pop();
|
|
1275
|
+
_.trys.pop();
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
op = body.call(thisArg, _);
|
|
1279
|
+
} catch (e) {
|
|
1280
|
+
op = [
|
|
1281
|
+
6,
|
|
1282
|
+
e
|
|
1283
|
+
];
|
|
1284
|
+
y = 0;
|
|
1285
|
+
} finally{
|
|
1286
|
+
f = t = 0;
|
|
1287
|
+
}
|
|
1288
|
+
if (op[0] & 5) throw op[1];
|
|
1289
|
+
return {
|
|
1290
|
+
value: op[0] ? op[1] : void 0,
|
|
1291
|
+
done: true
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Maps stored connection credentials to a {@link ZohoAccessToken}.
|
|
1297
|
+
*
|
|
1298
|
+
* @param credentials - The credentials stored for the `zoho` provider.
|
|
1299
|
+
* @returns The equivalent Zoho access token, or null when the credentials cannot form one.
|
|
1300
|
+
*/ function zohoAccessTokenFromUserExternalConnectionCredentials(credentials) {
|
|
1301
|
+
var _credentials_extra;
|
|
1302
|
+
var expiresAt = date.safeToJsDate(credentials === null || credentials === void 0 ? void 0 : credentials.expiresAt);
|
|
1303
|
+
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];
|
|
1304
|
+
var result;
|
|
1305
|
+
// the api domain is required, not incidental: a Zoho access token is only usable against the domain
|
|
1306
|
+
// it was issued for, so a token synthesized without one would be sent to the wrong host
|
|
1307
|
+
if (credentials != null && expiresAt != null && apiDomain != null) {
|
|
1308
|
+
var _ref, _credentials_scopes;
|
|
1309
|
+
var issuedAt = date.safeToJsDate(credentials.issuedAt);
|
|
1310
|
+
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);
|
|
1311
|
+
result = {
|
|
1312
|
+
accessToken: credentials.accessToken,
|
|
1313
|
+
// joined on the same delimiter `zohoOAuthScopesFromScopeString` split them with
|
|
1314
|
+
scope: ((_credentials_scopes = credentials.scopes) !== null && _credentials_scopes !== void 0 ? _credentials_scopes : []).join(zoho.ZOHO_OAUTH_SCOPE_DELIMITER),
|
|
1315
|
+
apiDomain: String(apiDomain),
|
|
1316
|
+
expiresIn: expiresIn,
|
|
1317
|
+
expiresAt: expiresAt
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
return result;
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Creates a {@link ZohoAccessTokenCache} backed by a user's UserExternalConnection pair.
|
|
1324
|
+
*
|
|
1325
|
+
* The Zoho counterpart of `userExternalConnectionCalcomAccessTokenCache`, and the per-user counterpart
|
|
1326
|
+
* of `firebaseZohoAccountsAccessTokenCacheService` — which caches the APP's token in a `SystemState`
|
|
1327
|
+
* document and has no notion of a user.
|
|
1328
|
+
*
|
|
1329
|
+
* Zoho does not rotate refresh tokens, so unlike Cal.com there is no token here that is destroyed by
|
|
1330
|
+
* being used. What this buys instead is that a renewed access token is shared: without it every Cloud
|
|
1331
|
+
* Function instance holds its own in-memory token and refreshes independently, so a user's grant is
|
|
1332
|
+
* exercised once per instance per hour rather than once per hour.
|
|
1333
|
+
*
|
|
1334
|
+
* @param config - The accessor, the actions, and the user the cache is for.
|
|
1335
|
+
* @returns A ZohoAccessTokenCache reading and writing the user's connection pair.
|
|
1336
|
+
*/ function userExternalConnectionZohoAccessTokenCache(config) {
|
|
1337
|
+
var accessor = config.accessor, actions = config.actions, uid = config.uid;
|
|
1338
|
+
var providerType = firebase.ZOHO_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE;
|
|
1339
|
+
var connection = accessor.accessorForUser({
|
|
1340
|
+
uid: uid
|
|
1341
|
+
})(providerType);
|
|
1342
|
+
function loadCachedToken() {
|
|
1343
|
+
return _async_to_generator(function() {
|
|
1344
|
+
var credentials;
|
|
1345
|
+
return _ts_generator(this, function(_state) {
|
|
1346
|
+
switch(_state.label){
|
|
1347
|
+
case 0:
|
|
1348
|
+
return [
|
|
1349
|
+
4,
|
|
1350
|
+
connection.readUserExternalConnectionCredentials()
|
|
1351
|
+
];
|
|
1352
|
+
case 1:
|
|
1353
|
+
credentials = _state.sent();
|
|
1354
|
+
return [
|
|
1355
|
+
2,
|
|
1356
|
+
zohoAccessTokenFromUserExternalConnectionCredentials(credentials)
|
|
1357
|
+
];
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
})();
|
|
1361
|
+
}
|
|
1362
|
+
function updateCachedToken(accessToken) {
|
|
1363
|
+
return _async_to_generator(function() {
|
|
1364
|
+
var previous, now, refreshed;
|
|
1365
|
+
return _ts_generator(this, function(_state) {
|
|
1366
|
+
switch(_state.label){
|
|
1367
|
+
case 0:
|
|
1368
|
+
return [
|
|
1369
|
+
4,
|
|
1370
|
+
connection.readUserExternalConnectionCredentials()
|
|
1371
|
+
];
|
|
1372
|
+
case 1:
|
|
1373
|
+
previous = _state.sent();
|
|
1374
|
+
if (previous == null) {
|
|
1375
|
+
// nothing to merge onto, and a Zoho access token carries no refresh token — writing it alone
|
|
1376
|
+
// would store credentials that can never be renewed
|
|
1377
|
+
return [
|
|
1378
|
+
2
|
|
1379
|
+
];
|
|
1380
|
+
}
|
|
1381
|
+
now = new Date();
|
|
1382
|
+
refreshed = _object_spread_props(_object_spread({}, previous), {
|
|
1383
|
+
accessToken: accessToken.accessToken,
|
|
1384
|
+
issuedAt: now.toISOString(),
|
|
1385
|
+
expiresAt: accessToken.expiresAt.toISOString(),
|
|
1386
|
+
extra: _object_spread_props(_object_spread({}, previous.extra), _define_property$1({}, ZOHO_EXTRA_API_DOMAIN_KEY, accessToken.apiDomain))
|
|
1387
|
+
});
|
|
1388
|
+
return [
|
|
1389
|
+
4,
|
|
1390
|
+
actions.refreshUserExternalConnectionCredentials({
|
|
1391
|
+
uid: uid,
|
|
1392
|
+
providerType: providerType,
|
|
1393
|
+
credentials: model.mergeRefreshedUserExternalConnectionCredentials({
|
|
1394
|
+
previous: previous,
|
|
1395
|
+
refreshed: refreshed
|
|
1396
|
+
})
|
|
1397
|
+
})
|
|
1398
|
+
];
|
|
1399
|
+
case 2:
|
|
1400
|
+
_state.sent();
|
|
1401
|
+
return [
|
|
1402
|
+
2
|
|
1403
|
+
];
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
})();
|
|
1407
|
+
}
|
|
1408
|
+
function clearCachedToken() {
|
|
1409
|
+
return _async_to_generator(function() {
|
|
1410
|
+
var previous;
|
|
1411
|
+
return _ts_generator(this, function(_state) {
|
|
1412
|
+
switch(_state.label){
|
|
1413
|
+
case 0:
|
|
1414
|
+
return [
|
|
1415
|
+
4,
|
|
1416
|
+
connection.readUserExternalConnectionCredentials()
|
|
1417
|
+
];
|
|
1418
|
+
case 1:
|
|
1419
|
+
previous = _state.sent();
|
|
1420
|
+
if (previous == null) {
|
|
1421
|
+
return [
|
|
1422
|
+
2
|
|
1423
|
+
];
|
|
1424
|
+
}
|
|
1425
|
+
// deliberately NOT a disconnect. Zoho's factory clears the cache to force its next call to refresh,
|
|
1426
|
+
// which is a statement about the ACCESS token only — dropping the refresh token here would turn a
|
|
1427
|
+
// routine cache invalidation into a connection the user has to re-authorize.
|
|
1428
|
+
return [
|
|
1429
|
+
4,
|
|
1430
|
+
actions.refreshUserExternalConnectionCredentials({
|
|
1431
|
+
uid: uid,
|
|
1432
|
+
providerType: providerType,
|
|
1433
|
+
credentials: _object_spread_props(_object_spread({}, previous), {
|
|
1434
|
+
accessToken: '',
|
|
1435
|
+
expiresAt: new Date(0).toISOString()
|
|
1436
|
+
})
|
|
1437
|
+
})
|
|
1438
|
+
];
|
|
1439
|
+
case 2:
|
|
1440
|
+
_state.sent();
|
|
1441
|
+
return [
|
|
1442
|
+
2
|
|
1443
|
+
];
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
})();
|
|
1447
|
+
}
|
|
1448
|
+
return {
|
|
1449
|
+
loadCachedToken: loadCachedToken,
|
|
1450
|
+
updateCachedToken: updateCachedToken,
|
|
1451
|
+
clearCachedToken: clearCachedToken
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
function _assert_this_initialized(self) {
|
|
1456
|
+
if (self === void 0) {
|
|
1457
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
1458
|
+
}
|
|
1459
|
+
return self;
|
|
1460
|
+
}
|
|
1461
|
+
function _call_super(_this, derived, args) {
|
|
1462
|
+
derived = _get_prototype_of(derived);
|
|
1463
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
1464
|
+
}
|
|
1465
|
+
function _class_call_check(instance, Constructor) {
|
|
1466
|
+
if (!(instance instanceof Constructor)) {
|
|
1467
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
function _define_property(obj, key, value) {
|
|
1471
|
+
if (key in obj) {
|
|
1472
|
+
Object.defineProperty(obj, key, {
|
|
1473
|
+
value: value,
|
|
1474
|
+
enumerable: true,
|
|
1475
|
+
configurable: true,
|
|
1476
|
+
writable: true
|
|
1477
|
+
});
|
|
1478
|
+
} else {
|
|
1479
|
+
obj[key] = value;
|
|
1480
|
+
}
|
|
1481
|
+
return obj;
|
|
1482
|
+
}
|
|
1483
|
+
function _get_prototype_of(o) {
|
|
1484
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
1485
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
1486
|
+
};
|
|
1487
|
+
return _get_prototype_of(o);
|
|
1488
|
+
}
|
|
1489
|
+
function _inherits(subClass, superClass) {
|
|
1490
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
1491
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1492
|
+
}
|
|
1493
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
1494
|
+
constructor: {
|
|
1495
|
+
value: subClass,
|
|
1496
|
+
writable: true,
|
|
1497
|
+
configurable: true
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
1501
|
+
}
|
|
1502
|
+
function _possible_constructor_return(self, call) {
|
|
1503
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
1504
|
+
return call;
|
|
1505
|
+
}
|
|
1506
|
+
return _assert_this_initialized(self);
|
|
1507
|
+
}
|
|
1508
|
+
function _set_prototype_of(o, p) {
|
|
1509
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
1510
|
+
o.__proto__ = p;
|
|
1511
|
+
return o;
|
|
1512
|
+
};
|
|
1513
|
+
return _set_prototype_of(o, p);
|
|
1514
|
+
}
|
|
1515
|
+
function _type_of(obj) {
|
|
1516
|
+
"@swc/helpers - typeof";
|
|
1517
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1518
|
+
}
|
|
1519
|
+
function _is_native_reflect_construct() {
|
|
1520
|
+
try {
|
|
1521
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
1522
|
+
} catch (_) {}
|
|
1523
|
+
return (_is_native_reflect_construct = function() {
|
|
1524
|
+
return !!result;
|
|
1525
|
+
})();
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Endpoints for the Zoho external-connection authorization-code handoff.
|
|
1529
|
+
*
|
|
1530
|
+
* Mounted at `/oauth/zoho`, matching the Angular registry's default authorize path of
|
|
1531
|
+
* `/oauth/<providerType>/authorize`. Hosting rewrites do not strip the path, so this prefix is the
|
|
1532
|
+
* public path — but an app with a global API route prefix must ALSO exclude these routes from it via
|
|
1533
|
+
* {@link ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE}, or they land under
|
|
1534
|
+
* that prefix instead and no longer match the redirect URI registered with Zoho.
|
|
1535
|
+
*
|
|
1536
|
+
* The `authorize` and `callback` routes come from the base class, so this declares only where they
|
|
1537
|
+
* mount and which service serves them.
|
|
1538
|
+
*/ exports.ZohoUserExternalConnectionOAuthController = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthController) {
|
|
1539
|
+
_inherits(ZohoUserExternalConnectionOAuthController, AbstractUserExternalConnectionOAuthController);
|
|
1540
|
+
function ZohoUserExternalConnectionOAuthController(oauthService) {
|
|
1541
|
+
_class_call_check(this, ZohoUserExternalConnectionOAuthController);
|
|
1542
|
+
var _this;
|
|
1543
|
+
_this = _call_super(this, ZohoUserExternalConnectionOAuthController), _define_property(_this, "oauthService", void 0);
|
|
1544
|
+
_this.oauthService = oauthService;
|
|
1545
|
+
return _this;
|
|
1546
|
+
}
|
|
1547
|
+
return ZohoUserExternalConnectionOAuthController;
|
|
1548
|
+
}(model.AbstractUserExternalConnectionOAuthController);
|
|
1549
|
+
exports.ZohoUserExternalConnectionOAuthController = __decorate([
|
|
1550
|
+
common.Controller(ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH),
|
|
1551
|
+
__param(0, common.Inject(exports.ZohoUserExternalConnectionOAuthService))
|
|
1552
|
+
], exports.ZohoUserExternalConnectionOAuthController);
|
|
1553
|
+
|
|
1554
|
+
function _array_like_to_array(arr, len) {
|
|
1555
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1556
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1557
|
+
return arr2;
|
|
1558
|
+
}
|
|
1559
|
+
function _array_without_holes(arr) {
|
|
1560
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1561
|
+
}
|
|
1562
|
+
function _iterable_to_array(iter) {
|
|
1563
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1564
|
+
}
|
|
1565
|
+
function _non_iterable_spread() {
|
|
1566
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1567
|
+
}
|
|
1568
|
+
function _to_consumable_array(arr) {
|
|
1569
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
1570
|
+
}
|
|
1571
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1572
|
+
if (!o) return;
|
|
1573
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1574
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1575
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1576
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1577
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Convenience function used to generate ModuleMetadata for an app's Zoho external-connection OAuth
|
|
1581
|
+
* module.
|
|
1582
|
+
*
|
|
1583
|
+
* Opt-in: importing the Zoho OAuth module alone never mounts HTTP routes, so an app that only makes
|
|
1584
|
+
* outbound Zoho calls exposes no endpoints.
|
|
1585
|
+
*
|
|
1586
|
+
* The importing module must also supply `UserExternalConnectionServerActions` and
|
|
1587
|
+
* `UserExternalConnectionStateCoder` — both exported by `appUserExternalConnectionModuleMetadata`,
|
|
1588
|
+
* so pass that module in `imports`.
|
|
1589
|
+
*
|
|
1590
|
+
* @param config - The module metadata configuration.
|
|
1591
|
+
* @returns NestJS ModuleMetadata mounting the Zoho connect endpoints.
|
|
1592
|
+
*/ function appZohoUserExternalConnectionOAuthModuleMetadata(config$1) {
|
|
1593
|
+
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;
|
|
1594
|
+
var dependencyModuleImport = dependencyModule ? [
|
|
1595
|
+
dependencyModule
|
|
1596
|
+
] : [];
|
|
1597
|
+
return {
|
|
1598
|
+
imports: [
|
|
1599
|
+
config.ConfigModule
|
|
1600
|
+
].concat(_to_consumable_array(dependencyModuleImport), _to_consumable_array(imports !== null && imports !== void 0 ? imports : [])),
|
|
1601
|
+
controllers: [
|
|
1602
|
+
exports.ZohoUserExternalConnectionOAuthController
|
|
1603
|
+
],
|
|
1604
|
+
exports: [
|
|
1605
|
+
exports.ZohoUserExternalConnectionOAuthService
|
|
1606
|
+
].concat(_to_consumable_array(exports$1 !== null && exports$1 !== void 0 ? exports$1 : [])),
|
|
1607
|
+
providers: [
|
|
1608
|
+
{
|
|
1609
|
+
provide: ZohoUserExternalConnectionOAuthServiceConfig,
|
|
1610
|
+
inject: [
|
|
1611
|
+
firebaseServer.FirebaseServerEnvService
|
|
1612
|
+
],
|
|
1613
|
+
useFactory: function useFactory(envService) {
|
|
1614
|
+
return zohoUserExternalConnectionOAuthServiceConfigFactory({
|
|
1615
|
+
envService: envService,
|
|
1616
|
+
successPath: successPath,
|
|
1617
|
+
failurePath: failurePath,
|
|
1618
|
+
scopes: scopes,
|
|
1619
|
+
accountsApiUrl: accountsApiUrl
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1623
|
+
exports.ZohoUserExternalConnectionOAuthService
|
|
1624
|
+
].concat(_to_consumable_array(providers !== null && providers !== void 0 ? providers : []))
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
exports.DEFAULT_ZOHO_OAUTH_SCOPES = DEFAULT_ZOHO_OAUTH_SCOPES;
|
|
452
1629
|
exports.ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE;
|
|
1630
|
+
exports.ZOHO_EXTRA_ACCOUNTS_SERVER_KEY = ZOHO_EXTRA_ACCOUNTS_SERVER_KEY;
|
|
1631
|
+
exports.ZOHO_EXTRA_API_DOMAIN_KEY = ZOHO_EXTRA_API_DOMAIN_KEY;
|
|
1632
|
+
exports.ZOHO_EXTRA_LOCATION_KEY = ZOHO_EXTRA_LOCATION_KEY;
|
|
1633
|
+
exports.ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM = ZOHO_OAUTH_CALLBACK_ACCOUNTS_SERVER_PARAM;
|
|
1634
|
+
exports.ZOHO_OAUTH_CALLBACK_LOCATION_PARAM = ZOHO_OAUTH_CALLBACK_LOCATION_PARAM;
|
|
1635
|
+
exports.ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH;
|
|
1636
|
+
exports.ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = ZOHO_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE;
|
|
1637
|
+
exports.ZohoUserExternalConnectionOAuthServiceConfig = ZohoUserExternalConnectionOAuthServiceConfig;
|
|
1638
|
+
exports.appZohoUserExternalConnectionOAuthModuleMetadata = appZohoUserExternalConnectionOAuthModuleMetadata;
|
|
453
1639
|
exports.firebaseZohoAccountsAccessTokenCacheService = firebaseZohoAccountsAccessTokenCacheService;
|
|
454
1640
|
exports.loadZohoAccessTokenSystemState = loadZohoAccessTokenSystemState;
|
|
1641
|
+
exports.userExternalConnectionZohoAccessTokenCache = userExternalConnectionZohoAccessTokenCache;
|
|
1642
|
+
exports.zohoAccessTokenFromUserExternalConnectionCredentials = zohoAccessTokenFromUserExternalConnectionCredentials;
|
|
455
1643
|
exports.zohoAccessTokenSystemStateDataConverter = zohoAccessTokenSystemStateDataConverter;
|
|
456
1644
|
exports.zohoAccessTokenSystemStateEmbeddedTokenConverter = zohoAccessTokenSystemStateEmbeddedTokenConverter;
|
|
1645
|
+
exports.zohoUserExternalConnectionCredentials = zohoUserExternalConnectionCredentials;
|
|
1646
|
+
exports.zohoUserExternalConnectionOAuthServiceConfigFactory = zohoUserExternalConnectionOAuthServiceConfigFactory;
|