@dereekb/zoho 13.31.0 → 13.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.js +5 -5
- package/cli/package.json +7 -7
- package/index.cjs.js +365 -43
- package/index.esm.js +341 -43
- package/nestjs/index.cjs.js +350 -36
- package/nestjs/index.esm.js +346 -38
- package/nestjs/package.json +5 -5
- package/nestjs/src/lib/accounts/accounts.oauth.api.d.ts +107 -0
- package/nestjs/src/lib/accounts/accounts.oauth.config.d.ts +45 -0
- package/nestjs/src/lib/accounts/accounts.oauth.module.d.ts +22 -0
- package/nestjs/src/lib/accounts/index.d.ts +3 -0
- package/package.json +8 -8
- package/src/lib/accounts/accounts.api.d.ts +112 -2
- package/src/lib/accounts/accounts.authorize.d.ts +119 -0
- package/src/lib/accounts/accounts.config.d.ts +65 -2
- package/src/lib/accounts/accounts.factory.d.ts +69 -0
- package/src/lib/accounts/index.d.ts +1 -0
package/nestjs/index.cjs.js
CHANGED
|
@@ -81,12 +81,12 @@ function readZohoConfigFromConfigService(configOrService, servicePrefix) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function _class_call_check$
|
|
84
|
+
function _class_call_check$g(instance, Constructor) {
|
|
85
85
|
if (!(instance instanceof Constructor)) {
|
|
86
86
|
throw new TypeError("Cannot call a class as a function");
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
function _defineProperties$
|
|
89
|
+
function _defineProperties$e(target, props) {
|
|
90
90
|
for(var i = 0; i < props.length; i++){
|
|
91
91
|
var descriptor = props[i];
|
|
92
92
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
@@ -95,11 +95,11 @@ function _defineProperties$c(target, props) {
|
|
|
95
95
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
function _create_class$
|
|
99
|
-
if (staticProps) _defineProperties$
|
|
98
|
+
function _create_class$e(Constructor, protoProps, staticProps) {
|
|
99
|
+
if (staticProps) _defineProperties$e(Constructor, staticProps);
|
|
100
100
|
return Constructor;
|
|
101
101
|
}
|
|
102
|
-
function _define_property$
|
|
102
|
+
function _define_property$g(obj, key, value) {
|
|
103
103
|
if (key in obj) {
|
|
104
104
|
Object.defineProperty(obj, key, {
|
|
105
105
|
value: value,
|
|
@@ -116,11 +116,11 @@ function _define_property$e(obj, key, value) {
|
|
|
116
116
|
* Configuration for ZohoService
|
|
117
117
|
*/ var ZohoAccountsServiceConfig = /*#__PURE__*/ function() {
|
|
118
118
|
function ZohoAccountsServiceConfig() {
|
|
119
|
-
_class_call_check$
|
|
120
|
-
_define_property$
|
|
121
|
-
_define_property$
|
|
119
|
+
_class_call_check$g(this, ZohoAccountsServiceConfig);
|
|
120
|
+
_define_property$g(this, "zohoAccounts", void 0);
|
|
121
|
+
_define_property$g(this, "factoryConfig", void 0);
|
|
122
122
|
}
|
|
123
|
-
_create_class$
|
|
123
|
+
_create_class$e(ZohoAccountsServiceConfig, null, [
|
|
124
124
|
{
|
|
125
125
|
key: "assertValidConfig",
|
|
126
126
|
value: function assertValidConfig(config) {
|
|
@@ -184,7 +184,7 @@ function _define_property$e(obj, key, value) {
|
|
|
184
184
|
return config;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
function _array_like_to_array$
|
|
187
|
+
function _array_like_to_array$5(arr, len) {
|
|
188
188
|
if (len == null || len > arr.length) len = arr.length;
|
|
189
189
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
190
190
|
return arr2;
|
|
@@ -192,8 +192,8 @@ function _array_like_to_array$4(arr, len) {
|
|
|
192
192
|
function _array_with_holes(arr) {
|
|
193
193
|
if (Array.isArray(arr)) return arr;
|
|
194
194
|
}
|
|
195
|
-
function _array_without_holes$
|
|
196
|
-
if (Array.isArray(arr)) return _array_like_to_array$
|
|
195
|
+
function _array_without_holes$5(arr) {
|
|
196
|
+
if (Array.isArray(arr)) return _array_like_to_array$5(arr);
|
|
197
197
|
}
|
|
198
198
|
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
199
199
|
try {
|
|
@@ -224,12 +224,12 @@ function _async_to_generator$3(fn) {
|
|
|
224
224
|
});
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
|
-
function _class_call_check$
|
|
227
|
+
function _class_call_check$f(instance, Constructor) {
|
|
228
228
|
if (!(instance instanceof Constructor)) {
|
|
229
229
|
throw new TypeError("Cannot call a class as a function");
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
function _define_property$
|
|
232
|
+
function _define_property$f(obj, key, value) {
|
|
233
233
|
if (key in obj) {
|
|
234
234
|
Object.defineProperty(obj, key, {
|
|
235
235
|
value: value,
|
|
@@ -250,7 +250,7 @@ function _instanceof(left, right) {
|
|
|
250
250
|
return left instanceof right;
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
function _iterable_to_array$
|
|
253
|
+
function _iterable_to_array$5(iter) {
|
|
254
254
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
255
255
|
}
|
|
256
256
|
function _iterable_to_array_limit(arr, i) {
|
|
@@ -280,7 +280,7 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
280
280
|
function _non_iterable_rest() {
|
|
281
281
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
282
282
|
}
|
|
283
|
-
function _non_iterable_spread$
|
|
283
|
+
function _non_iterable_spread$5() {
|
|
284
284
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
285
285
|
}
|
|
286
286
|
function _object_spread$6(target) {
|
|
@@ -293,7 +293,7 @@ function _object_spread$6(target) {
|
|
|
293
293
|
}));
|
|
294
294
|
}
|
|
295
295
|
ownKeys.forEach(function(key) {
|
|
296
|
-
_define_property$
|
|
296
|
+
_define_property$f(target, key, source[key]);
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
return target;
|
|
@@ -318,22 +318,22 @@ function _object_spread_props$5(target, source) {
|
|
|
318
318
|
return target;
|
|
319
319
|
}
|
|
320
320
|
function _sliced_to_array(arr, i) {
|
|
321
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$
|
|
321
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$5(arr, i) || _non_iterable_rest();
|
|
322
322
|
}
|
|
323
|
-
function _to_consumable_array$
|
|
324
|
-
return _array_without_holes$
|
|
323
|
+
function _to_consumable_array$5(arr) {
|
|
324
|
+
return _array_without_holes$5(arr) || _iterable_to_array$5(arr) || _unsupported_iterable_to_array$5(arr) || _non_iterable_spread$5();
|
|
325
325
|
}
|
|
326
326
|
function _type_of(obj) {
|
|
327
327
|
"@swc/helpers - typeof";
|
|
328
328
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
329
329
|
}
|
|
330
|
-
function _unsupported_iterable_to_array$
|
|
330
|
+
function _unsupported_iterable_to_array$5(o, minLen) {
|
|
331
331
|
if (!o) return;
|
|
332
|
-
if (typeof o === "string") return _array_like_to_array$
|
|
332
|
+
if (typeof o === "string") return _array_like_to_array$5(o, minLen);
|
|
333
333
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
334
334
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
335
335
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
336
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$
|
|
336
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$5(o, minLen);
|
|
337
337
|
}
|
|
338
338
|
function _ts_generator$3(thisArg, body) {
|
|
339
339
|
var f, y, t, _ = {
|
|
@@ -437,7 +437,7 @@ function _ts_generator$3(thisArg, body) {
|
|
|
437
437
|
/**
|
|
438
438
|
* Service used for retrieving ZohoAccessTokenCache for Zoho services.
|
|
439
439
|
*/ exports.ZohoAccountsAccessTokenCacheService = function ZohoAccountsAccessTokenCacheService() {
|
|
440
|
-
_class_call_check$
|
|
440
|
+
_class_call_check$f(this, ZohoAccountsAccessTokenCacheService);
|
|
441
441
|
};
|
|
442
442
|
exports.ZohoAccountsAccessTokenCacheService = __decorate([
|
|
443
443
|
common.Injectable()
|
|
@@ -512,7 +512,7 @@ function updateZohoCacheCapturingError(cache, accessToken) {
|
|
|
512
512
|
* @returns A merged ZohoAccountsAccessTokenCacheService that delegates across all inputs.
|
|
513
513
|
* @throws {Error} When `inputServicesToMerge` is empty.
|
|
514
514
|
*/ function mergeZohoAccountsAccessTokenCacheServices(inputServicesToMerge, logError) {
|
|
515
|
-
var services = _to_consumable_array$
|
|
515
|
+
var services = _to_consumable_array$5(inputServicesToMerge);
|
|
516
516
|
var logErrorFunction = typeof logError === 'function' ? logError : logError === false ? undefined : logMergeZohoAccountsAccessTokenCacheServiceErrorFunction;
|
|
517
517
|
if (services.length === 0) {
|
|
518
518
|
throw new Error('mergeZohoAccountsAccessTokenCacheServices() input cannot be empty.');
|
|
@@ -980,12 +980,12 @@ var DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoho-acce
|
|
|
980
980
|
};
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
-
function _class_call_check$
|
|
983
|
+
function _class_call_check$e(instance, Constructor) {
|
|
984
984
|
if (!(instance instanceof Constructor)) {
|
|
985
985
|
throw new TypeError("Cannot call a class as a function");
|
|
986
986
|
}
|
|
987
987
|
}
|
|
988
|
-
function _defineProperties$
|
|
988
|
+
function _defineProperties$d(target, props) {
|
|
989
989
|
for(var i = 0; i < props.length; i++){
|
|
990
990
|
var descriptor = props[i];
|
|
991
991
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
@@ -994,11 +994,11 @@ function _defineProperties$b(target, props) {
|
|
|
994
994
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
995
995
|
}
|
|
996
996
|
}
|
|
997
|
-
function _create_class$
|
|
998
|
-
if (protoProps) _defineProperties$
|
|
997
|
+
function _create_class$d(Constructor, protoProps, staticProps) {
|
|
998
|
+
if (protoProps) _defineProperties$d(Constructor.prototype, protoProps);
|
|
999
999
|
return Constructor;
|
|
1000
1000
|
}
|
|
1001
|
-
function _define_property$
|
|
1001
|
+
function _define_property$e(obj, key, value) {
|
|
1002
1002
|
if (key in obj) {
|
|
1003
1003
|
Object.defineProperty(obj, key, {
|
|
1004
1004
|
value: value,
|
|
@@ -1021,18 +1021,18 @@ function _object_spread$5(target) {
|
|
|
1021
1021
|
}));
|
|
1022
1022
|
}
|
|
1023
1023
|
ownKeys.forEach(function(key) {
|
|
1024
|
-
_define_property$
|
|
1024
|
+
_define_property$e(target, key, source[key]);
|
|
1025
1025
|
});
|
|
1026
1026
|
}
|
|
1027
1027
|
return target;
|
|
1028
1028
|
}
|
|
1029
1029
|
exports.ZohoAccountsApi = /*#__PURE__*/ function() {
|
|
1030
1030
|
function ZohoAccountsApi(config, cacheService) {
|
|
1031
|
-
_class_call_check$
|
|
1031
|
+
_class_call_check$e(this, ZohoAccountsApi);
|
|
1032
1032
|
var _config_zohoAccounts_accessTokenCache, _config_factoryConfig;
|
|
1033
|
-
_define_property$
|
|
1034
|
-
_define_property$
|
|
1035
|
-
_define_property$
|
|
1033
|
+
_define_property$e(this, "config", void 0);
|
|
1034
|
+
_define_property$e(this, "cacheService", void 0);
|
|
1035
|
+
_define_property$e(this, "zohoAccounts", void 0);
|
|
1036
1036
|
this.config = config;
|
|
1037
1037
|
this.cacheService = cacheService;
|
|
1038
1038
|
var accessTokenCache = (_config_zohoAccounts_accessTokenCache = config.zohoAccounts.accessTokenCache) !== null && _config_zohoAccounts_accessTokenCache !== void 0 ? _config_zohoAccounts_accessTokenCache : cacheService.loadZohoAccessTokenCache(config.zohoAccounts.serviceAccessTokenKey);
|
|
@@ -1040,7 +1040,7 @@ exports.ZohoAccountsApi = /*#__PURE__*/ function() {
|
|
|
1040
1040
|
accessTokenCache: accessTokenCache
|
|
1041
1041
|
}, config.zohoAccounts));
|
|
1042
1042
|
}
|
|
1043
|
-
_create_class$
|
|
1043
|
+
_create_class$d(ZohoAccountsApi, [
|
|
1044
1044
|
{
|
|
1045
1045
|
key: "accountsContext",
|
|
1046
1046
|
get: function get() {
|
|
@@ -1063,6 +1063,314 @@ exports.ZohoAccountsApi = __decorate([
|
|
|
1063
1063
|
__param(1, common.Inject(exports.ZohoAccountsAccessTokenCacheService))
|
|
1064
1064
|
], exports.ZohoAccountsApi);
|
|
1065
1065
|
|
|
1066
|
+
function _class_call_check$d(instance, Constructor) {
|
|
1067
|
+
if (!(instance instanceof Constructor)) {
|
|
1068
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
function _defineProperties$c(target, props) {
|
|
1072
|
+
for(var i = 0; i < props.length; i++){
|
|
1073
|
+
var descriptor = props[i];
|
|
1074
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1075
|
+
descriptor.configurable = true;
|
|
1076
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1077
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
function _create_class$c(Constructor, protoProps, staticProps) {
|
|
1081
|
+
if (staticProps) _defineProperties$c(Constructor, staticProps);
|
|
1082
|
+
return Constructor;
|
|
1083
|
+
}
|
|
1084
|
+
function _define_property$d(obj, key, value) {
|
|
1085
|
+
if (key in obj) {
|
|
1086
|
+
Object.defineProperty(obj, key, {
|
|
1087
|
+
value: value,
|
|
1088
|
+
enumerable: true,
|
|
1089
|
+
configurable: true,
|
|
1090
|
+
writable: true
|
|
1091
|
+
});
|
|
1092
|
+
} else {
|
|
1093
|
+
obj[key] = value;
|
|
1094
|
+
}
|
|
1095
|
+
return obj;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Environment key naming the Zoho Accounts datacenter (or a full accounts URL) to authorize against.
|
|
1099
|
+
*/ var ZOHO_ACCOUNTS_URL_CONFIG_KEY = 'ZOHO_ACCOUNTS_URL';
|
|
1100
|
+
/**
|
|
1101
|
+
* Environment key holding the Zoho OAuth client id.
|
|
1102
|
+
*/ var ZOHO_ACCOUNTS_CLIENT_ID_CONFIG_KEY = 'ZOHO_ACCOUNTS_CLIENT_ID';
|
|
1103
|
+
/**
|
|
1104
|
+
* Environment key holding the Zoho OAuth client secret.
|
|
1105
|
+
*/ var ZOHO_ACCOUNTS_CLIENT_SECRET_CONFIG_KEY = 'ZOHO_ACCOUNTS_CLIENT_SECRET';
|
|
1106
|
+
/**
|
|
1107
|
+
* Configuration for {@link ZohoAccountsOAuthApi}.
|
|
1108
|
+
*
|
|
1109
|
+
* Read from the three existing flat `ZOHO_ACCOUNTS_*` keys rather than composed through
|
|
1110
|
+
* `zohoConfigServiceReaderFunction`, which requires a `serviceAccessTokenKey` a per-user OAuth
|
|
1111
|
+
* client does not have. Notably absent: `ZOHO_ACCOUNTS_REFRESH_TOKEN` (a per-user flow has no
|
|
1112
|
+
* server refresh token) and any scope variable (scopes are declared in code).
|
|
1113
|
+
*/ var ZohoAccountsOAuthServiceConfig = /*#__PURE__*/ function() {
|
|
1114
|
+
function ZohoAccountsOAuthServiceConfig() {
|
|
1115
|
+
_class_call_check$d(this, ZohoAccountsOAuthServiceConfig);
|
|
1116
|
+
_define_property$d(this, "zohoAccountsOAuth", void 0);
|
|
1117
|
+
_define_property$d(this, "factoryConfig", void 0);
|
|
1118
|
+
}
|
|
1119
|
+
_create_class$c(ZohoAccountsOAuthServiceConfig, null, [
|
|
1120
|
+
{
|
|
1121
|
+
key: "assertValidConfig",
|
|
1122
|
+
value: function assertValidConfig(config) {
|
|
1123
|
+
var zohoAccountsOAuth = config.zohoAccountsOAuth;
|
|
1124
|
+
if (!zohoAccountsOAuth) {
|
|
1125
|
+
throw new Error('ZohoAccountsOAuthServiceConfig.zohoAccountsOAuth is required');
|
|
1126
|
+
}
|
|
1127
|
+
if (!zohoAccountsOAuth.clientId) {
|
|
1128
|
+
throw new Error("ZohoAccountsOAuthServiceConfig requires a clientId (".concat(ZOHO_ACCOUNTS_CLIENT_ID_CONFIG_KEY, ")."));
|
|
1129
|
+
}
|
|
1130
|
+
if (!zohoAccountsOAuth.clientSecret) {
|
|
1131
|
+
throw new Error("ZohoAccountsOAuthServiceConfig requires a clientSecret (".concat(ZOHO_ACCOUNTS_CLIENT_SECRET_CONFIG_KEY, ")."));
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
]);
|
|
1136
|
+
return ZohoAccountsOAuthServiceConfig;
|
|
1137
|
+
}();
|
|
1138
|
+
/**
|
|
1139
|
+
* Factory function that creates a {@link ZohoAccountsOAuthServiceConfig} from NestJS ConfigService
|
|
1140
|
+
* environment variables.
|
|
1141
|
+
*
|
|
1142
|
+
* @param configService - The NestJS ConfigService instance.
|
|
1143
|
+
* @returns A validated ZohoAccountsOAuthServiceConfig.
|
|
1144
|
+
* @throws {Error} When the client id or client secret is not configured.
|
|
1145
|
+
*/ function zohoAccountsOAuthServiceConfigFactory(configService) {
|
|
1146
|
+
var clientId = configService.get(ZOHO_ACCOUNTS_CLIENT_ID_CONFIG_KEY);
|
|
1147
|
+
var clientSecret = configService.get(ZOHO_ACCOUNTS_CLIENT_SECRET_CONFIG_KEY);
|
|
1148
|
+
var apiUrl = configService.get(ZOHO_ACCOUNTS_URL_CONFIG_KEY);
|
|
1149
|
+
var config = {
|
|
1150
|
+
zohoAccountsOAuth: {
|
|
1151
|
+
clientId: clientId || undefined,
|
|
1152
|
+
clientSecret: clientSecret || undefined,
|
|
1153
|
+
apiUrl: apiUrl || undefined
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
ZohoAccountsOAuthServiceConfig.assertValidConfig(config);
|
|
1157
|
+
return config;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
function _class_call_check$c(instance, Constructor) {
|
|
1161
|
+
if (!(instance instanceof Constructor)) {
|
|
1162
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
function _defineProperties$b(target, props) {
|
|
1166
|
+
for(var i = 0; i < props.length; i++){
|
|
1167
|
+
var descriptor = props[i];
|
|
1168
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1169
|
+
descriptor.configurable = true;
|
|
1170
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1171
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function _create_class$b(Constructor, protoProps, staticProps) {
|
|
1175
|
+
if (protoProps) _defineProperties$b(Constructor.prototype, protoProps);
|
|
1176
|
+
return Constructor;
|
|
1177
|
+
}
|
|
1178
|
+
function _define_property$c(obj, key, value) {
|
|
1179
|
+
if (key in obj) {
|
|
1180
|
+
Object.defineProperty(obj, key, {
|
|
1181
|
+
value: value,
|
|
1182
|
+
enumerable: true,
|
|
1183
|
+
configurable: true,
|
|
1184
|
+
writable: true
|
|
1185
|
+
});
|
|
1186
|
+
} else {
|
|
1187
|
+
obj[key] = value;
|
|
1188
|
+
}
|
|
1189
|
+
return obj;
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* The Zoho Accounts endpoints a per-user connect flow needs: the authorization-code exchange, the
|
|
1193
|
+
* per-user token refresh, and the identity lookup that labels the connection.
|
|
1194
|
+
*
|
|
1195
|
+
* Deliberately separate from {@link ZohoAccountsApi}, which requires a server refresh token and a
|
|
1196
|
+
* token cache. A per-user handoff has neither — the handoff is how a refresh token is obtained.
|
|
1197
|
+
*/ exports.ZohoAccountsOAuthApi = /*#__PURE__*/ function() {
|
|
1198
|
+
function ZohoAccountsOAuthApi(config) {
|
|
1199
|
+
_class_call_check$c(this, ZohoAccountsOAuthApi);
|
|
1200
|
+
var _config_factoryConfig;
|
|
1201
|
+
_define_property$c(this, "config", void 0);
|
|
1202
|
+
_define_property$c(this, "_clientFactory", void 0);
|
|
1203
|
+
/**
|
|
1204
|
+
* Per-host clients, memoized so a repeated datacenter reuses one client rather than rebuilding
|
|
1205
|
+
* its fetch stack per callback.
|
|
1206
|
+
*/ _define_property$c(this, "_clients", new Map());
|
|
1207
|
+
/**
|
|
1208
|
+
* The accounts host configured for this app.
|
|
1209
|
+
*/ _define_property$c(this, "apiUrl", void 0);
|
|
1210
|
+
/**
|
|
1211
|
+
* The OAuth client id the authorize request is composed with.
|
|
1212
|
+
*/ _define_property$c(this, "clientId", void 0);
|
|
1213
|
+
_define_property$c(this, "_clientSecret", void 0);
|
|
1214
|
+
this.config = config;
|
|
1215
|
+
// asserted here rather than trusted, so a config assembled in code (not through the env factory,
|
|
1216
|
+
// which already asserts) cannot reach the consent screen with an undefined client id
|
|
1217
|
+
ZohoAccountsOAuthServiceConfig.assertValidConfig(config);
|
|
1218
|
+
var _config_zohoAccountsOAuth = config.zohoAccountsOAuth, apiUrl = _config_zohoAccountsOAuth.apiUrl, clientId = _config_zohoAccountsOAuth.clientId, clientSecret = _config_zohoAccountsOAuth.clientSecret;
|
|
1219
|
+
this.apiUrl = zoho.zohoAccountsConfigApiUrl(apiUrl !== null && apiUrl !== void 0 ? apiUrl : 'us');
|
|
1220
|
+
this.clientId = clientId;
|
|
1221
|
+
this._clientSecret = clientSecret;
|
|
1222
|
+
this._clientFactory = zoho.zohoAccountsOAuthClientFactory((_config_factoryConfig = config.factoryConfig) !== null && _config_factoryConfig !== void 0 ? _config_factoryConfig : {});
|
|
1223
|
+
}
|
|
1224
|
+
_create_class$b(ZohoAccountsOAuthApi, [
|
|
1225
|
+
{
|
|
1226
|
+
key: "oauthClientContext",
|
|
1227
|
+
get: /**
|
|
1228
|
+
* The client for the configured datacenter.
|
|
1229
|
+
*/ function get() {
|
|
1230
|
+
return this.oauthClientContextForApiUrl(this.apiUrl);
|
|
1231
|
+
}
|
|
1232
|
+
},
|
|
1233
|
+
{
|
|
1234
|
+
/**
|
|
1235
|
+
* The client for a specific accounts host, memoized per host.
|
|
1236
|
+
*
|
|
1237
|
+
* Zoho echoes the issuing datacenter back as `accounts-server` on the callback, and a code issued
|
|
1238
|
+
* by one datacenter cannot be exchanged at another. Callers MUST have checked the host against
|
|
1239
|
+
* `isKnownZohoAccountsApiUrl` first — this method will happily build a client for any URL, and the
|
|
1240
|
+
* client secret travels to whatever host it is given.
|
|
1241
|
+
*
|
|
1242
|
+
* @param apiUrl - The datacenter key or full accounts URL to build a client for.
|
|
1243
|
+
* @returns The memoized client context for that host.
|
|
1244
|
+
*/ key: "oauthClientContextForApiUrl",
|
|
1245
|
+
value: function oauthClientContextForApiUrl(apiUrl) {
|
|
1246
|
+
var resolvedApiUrl = zoho.zohoAccountsConfigApiUrl(apiUrl);
|
|
1247
|
+
var context = this._clients.get(resolvedApiUrl);
|
|
1248
|
+
if (context == null) {
|
|
1249
|
+
context = this._clientFactory({
|
|
1250
|
+
clientId: this.clientId,
|
|
1251
|
+
clientSecret: this._clientSecret,
|
|
1252
|
+
apiUrl: resolvedApiUrl
|
|
1253
|
+
}).oauthClientContext;
|
|
1254
|
+
this._clients.set(resolvedApiUrl, context);
|
|
1255
|
+
}
|
|
1256
|
+
return context;
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
{
|
|
1260
|
+
// MARK: Accessors
|
|
1261
|
+
/**
|
|
1262
|
+
* Exchanges a single-use authorization code for tokens.
|
|
1263
|
+
*
|
|
1264
|
+
* @param input - The code, the redirect URI it was issued against, and the optional accounts host.
|
|
1265
|
+
* @returns The Zoho token response. `refresh_token` may be absent on a re-consent.
|
|
1266
|
+
*/ key: "exchangeAuthorizationCode",
|
|
1267
|
+
value: function exchangeAuthorizationCode(input) {
|
|
1268
|
+
var code = input.code, redirectUri = input.redirectUri, accountsApiUrl = input.accountsApiUrl;
|
|
1269
|
+
var context = this.oauthClientContextForApiUrl(accountsApiUrl !== null && accountsApiUrl !== void 0 ? accountsApiUrl : this.apiUrl);
|
|
1270
|
+
return zoho.zohoAccountsRefreshTokenFromAuthorizationCode(context)({
|
|
1271
|
+
code: code,
|
|
1272
|
+
redirectUri: redirectUri
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
},
|
|
1276
|
+
{
|
|
1277
|
+
/**
|
|
1278
|
+
* Exchanges a user's refresh token for a new access token.
|
|
1279
|
+
*
|
|
1280
|
+
* Zoho does not rotate refresh tokens, so the token passed in stays valid and the response carries
|
|
1281
|
+
* no replacement — the caller keeps the one it already has. The response DOES carry `api_domain`,
|
|
1282
|
+
* which is the host the new access token is usable against, so persist it.
|
|
1283
|
+
*
|
|
1284
|
+
* @param input - The user's refresh token and the optional accounts host.
|
|
1285
|
+
* @returns The Zoho access token response.
|
|
1286
|
+
*/ key: "refreshUserAccessToken",
|
|
1287
|
+
value: function refreshUserAccessToken(input) {
|
|
1288
|
+
var refreshToken = input.refreshToken, accountsApiUrl = input.accountsApiUrl;
|
|
1289
|
+
var context = this.oauthClientContextForApiUrl(accountsApiUrl !== null && accountsApiUrl !== void 0 ? accountsApiUrl : this.apiUrl);
|
|
1290
|
+
return zoho.zohoAccountsUserAccessToken(context)({
|
|
1291
|
+
refreshToken: refreshToken
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
{
|
|
1296
|
+
/**
|
|
1297
|
+
* Reads the Zoho identity an access token was issued to.
|
|
1298
|
+
*
|
|
1299
|
+
* @param input - The access token and the optional accounts host.
|
|
1300
|
+
* @returns The user info response.
|
|
1301
|
+
*/ key: "userInfo",
|
|
1302
|
+
value: function userInfo(input) {
|
|
1303
|
+
var accessToken = input.accessToken, accountsApiUrl = input.accountsApiUrl;
|
|
1304
|
+
var context = this.oauthClientContextForApiUrl(accountsApiUrl !== null && accountsApiUrl !== void 0 ? accountsApiUrl : this.apiUrl);
|
|
1305
|
+
return zoho.zohoAccountsUserInfo(context)({
|
|
1306
|
+
accessToken: accessToken
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
]);
|
|
1311
|
+
return ZohoAccountsOAuthApi;
|
|
1312
|
+
}();
|
|
1313
|
+
exports.ZohoAccountsOAuthApi = __decorate([
|
|
1314
|
+
common.Injectable(),
|
|
1315
|
+
__param(0, common.Inject(ZohoAccountsOAuthServiceConfig))
|
|
1316
|
+
], exports.ZohoAccountsOAuthApi);
|
|
1317
|
+
|
|
1318
|
+
function _array_like_to_array$4(arr, len) {
|
|
1319
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1320
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1321
|
+
return arr2;
|
|
1322
|
+
}
|
|
1323
|
+
function _array_without_holes$4(arr) {
|
|
1324
|
+
if (Array.isArray(arr)) return _array_like_to_array$4(arr);
|
|
1325
|
+
}
|
|
1326
|
+
function _iterable_to_array$4(iter) {
|
|
1327
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1328
|
+
}
|
|
1329
|
+
function _non_iterable_spread$4() {
|
|
1330
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1331
|
+
}
|
|
1332
|
+
function _to_consumable_array$4(arr) {
|
|
1333
|
+
return _array_without_holes$4(arr) || _iterable_to_array$4(arr) || _unsupported_iterable_to_array$4(arr) || _non_iterable_spread$4();
|
|
1334
|
+
}
|
|
1335
|
+
function _unsupported_iterable_to_array$4(o, minLen) {
|
|
1336
|
+
if (!o) return;
|
|
1337
|
+
if (typeof o === "string") return _array_like_to_array$4(o, minLen);
|
|
1338
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1339
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1340
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1341
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$4(o, minLen);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Convenience function used to generate ModuleMetadata for an app's ZohoAccountsOAuthModule.
|
|
1345
|
+
*
|
|
1346
|
+
* Unlike `appZohoCrmModuleMetadata`, this needs no `ZohoAccountsAccessTokenCacheService` and
|
|
1347
|
+
* therefore no dependency module: a per-user connect flow has no server token to cache.
|
|
1348
|
+
*
|
|
1349
|
+
* @param config - The module metadata configuration including an optional config factory.
|
|
1350
|
+
* @returns NestJS ModuleMetadata for registering the ZohoAccountsOAuthApi.
|
|
1351
|
+
*/ function appZohoAccountsOAuthModuleMetadata(config$1) {
|
|
1352
|
+
var _config_zohoAccountsOAuthServiceConfigFactory;
|
|
1353
|
+
var imports = config$1.imports, exports$1 = config$1.exports, providers = config$1.providers;
|
|
1354
|
+
return {
|
|
1355
|
+
imports: [
|
|
1356
|
+
config.ConfigModule
|
|
1357
|
+
].concat(_to_consumable_array$4(imports !== null && imports !== void 0 ? imports : [])),
|
|
1358
|
+
exports: [
|
|
1359
|
+
exports.ZohoAccountsOAuthApi
|
|
1360
|
+
].concat(_to_consumable_array$4(exports$1 !== null && exports$1 !== void 0 ? exports$1 : [])),
|
|
1361
|
+
providers: [
|
|
1362
|
+
{
|
|
1363
|
+
provide: ZohoAccountsOAuthServiceConfig,
|
|
1364
|
+
inject: [
|
|
1365
|
+
config.ConfigService
|
|
1366
|
+
],
|
|
1367
|
+
useFactory: (_config_zohoAccountsOAuthServiceConfigFactory = config$1.zohoAccountsOAuthServiceConfigFactory) !== null && _config_zohoAccountsOAuthServiceConfigFactory !== void 0 ? _config_zohoAccountsOAuthServiceConfigFactory : zohoAccountsOAuthServiceConfigFactory
|
|
1368
|
+
},
|
|
1369
|
+
exports.ZohoAccountsOAuthApi
|
|
1370
|
+
].concat(_to_consumable_array$4(providers !== null && providers !== void 0 ? providers : []))
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1066
1374
|
function _class_call_check$b(instance, Constructor) {
|
|
1067
1375
|
if (!(instance instanceof Constructor)) {
|
|
1068
1376
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -4328,16 +4636,21 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
4328
4636
|
}
|
|
4329
4637
|
|
|
4330
4638
|
exports.DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH;
|
|
4639
|
+
exports.ZOHO_ACCOUNTS_CLIENT_ID_CONFIG_KEY = ZOHO_ACCOUNTS_CLIENT_ID_CONFIG_KEY;
|
|
4640
|
+
exports.ZOHO_ACCOUNTS_CLIENT_SECRET_CONFIG_KEY = ZOHO_ACCOUNTS_CLIENT_SECRET_CONFIG_KEY;
|
|
4641
|
+
exports.ZOHO_ACCOUNTS_URL_CONFIG_KEY = ZOHO_ACCOUNTS_URL_CONFIG_KEY;
|
|
4331
4642
|
exports.ZOHO_API_URL_CONFIG_KEY = ZOHO_API_URL_CONFIG_KEY;
|
|
4332
4643
|
exports.ZOHO_ORG_ID_CONFIG_KEY = ZOHO_ORG_ID_CONFIG_KEY;
|
|
4333
4644
|
exports.ZOHO_SIGN_WEBHOOK_SECRET_TOKEN_ENV_VAR = ZOHO_SIGN_WEBHOOK_SECRET_TOKEN_ENV_VAR;
|
|
4334
4645
|
exports.ZOHO_SIGN_WEBHOOK_SIGNATURE_HEADER = ZOHO_SIGN_WEBHOOK_SIGNATURE_HEADER;
|
|
4646
|
+
exports.ZohoAccountsOAuthServiceConfig = ZohoAccountsOAuthServiceConfig;
|
|
4335
4647
|
exports.ZohoAccountsServiceConfig = ZohoAccountsServiceConfig;
|
|
4336
4648
|
exports.ZohoCrmServiceConfig = ZohoCrmServiceConfig;
|
|
4337
4649
|
exports.ZohoDeskServiceConfig = ZohoDeskServiceConfig;
|
|
4338
4650
|
exports.ZohoRecruitServiceConfig = ZohoRecruitServiceConfig;
|
|
4339
4651
|
exports.ZohoSignServiceConfig = ZohoSignServiceConfig;
|
|
4340
4652
|
exports.ZohoSignWebhookServiceConfig = ZohoSignWebhookServiceConfig;
|
|
4653
|
+
exports.appZohoAccountsOAuthModuleMetadata = appZohoAccountsOAuthModuleMetadata;
|
|
4341
4654
|
exports.appZohoCrmModuleMetadata = appZohoCrmModuleMetadata;
|
|
4342
4655
|
exports.appZohoDeskModuleMetadata = appZohoDeskModuleMetadata;
|
|
4343
4656
|
exports.appZohoRecruitModuleMetadata = appZohoRecruitModuleMetadata;
|
|
@@ -4348,6 +4661,7 @@ exports.logMergeZohoAccountsAccessTokenCacheServiceErrorFunction = logMergeZohoA
|
|
|
4348
4661
|
exports.memoryZohoAccountsAccessTokenCacheService = memoryZohoAccountsAccessTokenCacheService;
|
|
4349
4662
|
exports.mergeZohoAccountsAccessTokenCacheServices = mergeZohoAccountsAccessTokenCacheServices;
|
|
4350
4663
|
exports.readZohoConfigFromConfigService = readZohoConfigFromConfigService;
|
|
4664
|
+
exports.zohoAccountsOAuthServiceConfigFactory = zohoAccountsOAuthServiceConfigFactory;
|
|
4351
4665
|
exports.zohoAccountsServiceConfigFromConfigService = zohoAccountsServiceConfigFromConfigService;
|
|
4352
4666
|
exports.zohoConfigServiceReaderFunction = zohoConfigServiceReaderFunction;
|
|
4353
4667
|
exports.zohoCrmAccountServiceConfigFactory = zohoCrmAccountServiceConfigFactory;
|