@dereekb/zoho 13.0.0 → 13.0.2
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/index.cjs.default.js +1 -0
- package/index.cjs.js +1187 -1353
- package/index.cjs.mjs +2 -0
- package/index.esm.js +1187 -1353
- package/nestjs/index.cjs.default.js +1 -0
- package/nestjs/index.cjs.js +435 -420
- package/nestjs/index.cjs.mjs +2 -0
- package/nestjs/index.esm.js +435 -420
- package/nestjs/package.json +18 -15
- package/package.json +19 -24
package/nestjs/index.cjs.js
CHANGED
|
@@ -46,23 +46,24 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
46
46
|
|
|
47
47
|
const ZOHO_API_URL_CONFIG_KEY = 'API_URL';
|
|
48
48
|
function zohoConfigServiceReaderFunction(inputOrKey, inputConfigService) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
let configService;
|
|
50
|
+
let serviceAccessTokenKey;
|
|
51
|
+
if (typeof inputOrKey === 'string') {
|
|
52
|
+
serviceAccessTokenKey = inputOrKey;
|
|
53
|
+
configService = inputConfigService;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
configService = inputOrKey.configService;
|
|
57
|
+
serviceAccessTokenKey = inputOrKey.serviceAccessTokenKey;
|
|
58
|
+
}
|
|
59
|
+
const baseServicePrefix = 'ZOHO_';
|
|
60
|
+
const servicePrefix = serviceAccessTokenKey.toUpperCase(); // "RECRUIT"
|
|
61
|
+
const servicePrefixString = `${baseServicePrefix}${servicePrefix}_`; // "ZOHO_RECRUIT_"
|
|
62
|
+
return (key) => {
|
|
63
|
+
const baseConfigKey = `${baseServicePrefix}${key}`; // "ZOHO_ACCOUNTS_URL"
|
|
64
|
+
const serviceSpecificConfigKey = `${servicePrefixString}${key}`; // "ZOHO_RECRUIT_ACCOUNTS_URL"
|
|
65
|
+
return configService.get(serviceSpecificConfigKey) ?? configService.get(baseConfigKey);
|
|
66
|
+
};
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* Reads the ZohoConfig config from the ConfigService.
|
|
@@ -71,48 +72,50 @@ function zohoConfigServiceReaderFunction(inputOrKey, inputConfigService) {
|
|
|
71
72
|
* @param prefix
|
|
72
73
|
*/
|
|
73
74
|
function readZohoConfigFromConfigService(configService, servicePrefix, assertValid = true) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
const servicePrefixString = servicePrefix ? `${servicePrefix}_` : '';
|
|
76
|
+
const apiUrlConfigKey = `${servicePrefixString}${ZOHO_API_URL_CONFIG_KEY}`;
|
|
77
|
+
const config = {
|
|
78
|
+
apiUrl: configService.get(apiUrlConfigKey) ?? configService.get(ZOHO_API_URL_CONFIG_KEY)
|
|
79
|
+
};
|
|
80
|
+
if (assertValid) {
|
|
81
|
+
if (!config.apiUrl) {
|
|
82
|
+
throw new Error(`No Zoho API url or type specified for key "${apiUrlConfigKey}".`);
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
|
-
|
|
84
|
-
return config;
|
|
85
|
+
return config;
|
|
85
86
|
}
|
|
86
87
|
function assertValidZohoConfig(config) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
if (!config.apiUrl) {
|
|
89
|
+
throw new Error(`No Zoho API url or type specified.`);
|
|
90
|
+
}
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/**
|
|
93
94
|
* Configuration for ZohoService
|
|
94
95
|
*/
|
|
95
96
|
class ZohoAccountsServiceConfig {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
97
|
+
zohoAccounts;
|
|
98
|
+
factoryConfig;
|
|
99
|
+
static assertValidConfig(config) {
|
|
100
|
+
const { zohoAccounts } = config;
|
|
101
|
+
if (!zohoAccounts) {
|
|
102
|
+
throw new Error('ZohoAccountsServiceConfig.zohoAccounts is required');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
if (!zohoAccounts.serviceAccessTokenKey) {
|
|
106
|
+
throw new Error('ZohoAccountsServiceConfig.zohoAccounts.serviceAccessTokenKey is required');
|
|
107
|
+
}
|
|
108
|
+
else if (!zohoAccounts.refreshToken) {
|
|
109
|
+
throw new Error('ZohoAccountsServiceConfig.zohoAccounts.refreshToken is required');
|
|
110
|
+
}
|
|
111
|
+
else if (!zohoAccounts.apiUrl) {
|
|
112
|
+
throw new Error('ZohoAccountsServiceConfig.zohoAccounts.apiUrl is required');
|
|
113
|
+
}
|
|
114
|
+
else if (!zohoAccounts.clientId) {
|
|
115
|
+
throw new Error('ZohoAccountsServiceConfig.zohoAccounts.clientId is required');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
116
119
|
}
|
|
117
120
|
/**
|
|
118
121
|
* Builds a {@link ZohoAccountsServiceConfig} by reading Zoho Accounts OAuth credentials
|
|
@@ -140,37 +143,35 @@ class ZohoAccountsServiceConfig {
|
|
|
140
143
|
* @throws If any required credential (apiUrl, refreshToken, clientId) is missing.
|
|
141
144
|
*/
|
|
142
145
|
function zohoAccountsServiceConfigFromConfigService(input) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const config = {
|
|
158
|
-
zohoAccounts
|
|
159
|
-
};
|
|
160
|
-
ZohoAccountsServiceConfig.assertValidConfig(config);
|
|
161
|
-
return config;
|
|
146
|
+
const { serviceAccessTokenKey } = input;
|
|
147
|
+
const getFromConfigService = zohoConfigServiceReaderFunction(input);
|
|
148
|
+
const zohoAccounts = {
|
|
149
|
+
serviceAccessTokenKey,
|
|
150
|
+
apiUrl: getFromConfigService('ACCOUNTS_URL'), // ZOHO_<SERVICE>_ACCOUNTS_URL, ZOHO_ACCOUNTS_URL
|
|
151
|
+
refreshToken: getFromConfigService('ACCOUNTS_REFRESH_TOKEN'), // ZOHO_<SERVICE>_ACCOUNTS_REFRESH_TOKEN, ZOHO_ACCOUNTS_REFRESH_TOKEN
|
|
152
|
+
clientId: getFromConfigService('ACCOUNTS_CLIENT_ID'), // ZOHO_<SERVICE>_ACCOUNTS_CLIENT_ID, ZOHO_ACCOUNTS_CLIENT_ID
|
|
153
|
+
clientSecret: getFromConfigService('ACCOUNTS_CLIENT_SECRET') // ZOHO_<SERVICE>_ACCOUNTS_CLIENT_SECRET, ZOHO_ACCOUNTS_CLIENT_SECRET
|
|
154
|
+
};
|
|
155
|
+
const config = {
|
|
156
|
+
zohoAccounts
|
|
157
|
+
};
|
|
158
|
+
ZohoAccountsServiceConfig.assertValidConfig(config);
|
|
159
|
+
return config;
|
|
162
160
|
}
|
|
163
161
|
|
|
164
162
|
/**
|
|
165
163
|
* Service used for retrieving ZohoAccessTokenCache for Zoho services.
|
|
166
164
|
*/
|
|
167
|
-
exports.ZohoAccountsAccessTokenCacheService = class ZohoAccountsAccessTokenCacheService {
|
|
168
|
-
|
|
165
|
+
exports.ZohoAccountsAccessTokenCacheService = class ZohoAccountsAccessTokenCacheService {
|
|
166
|
+
};
|
|
167
|
+
exports.ZohoAccountsAccessTokenCacheService = __decorate([
|
|
168
|
+
common.Injectable()
|
|
169
|
+
], exports.ZohoAccountsAccessTokenCacheService);
|
|
169
170
|
function logMergeZohoAccountsAccessTokenCacheServiceErrorFunction(failedUpdates) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
console.warn(`mergeZohoAccountsAccessTokenCacheServices(): failed updating ${failedUpdates.length} caches.`);
|
|
172
|
+
failedUpdates.forEach(([x, e], i) => {
|
|
173
|
+
console.warn(`Cache update failure ${i + 1}: - ${e}`);
|
|
174
|
+
});
|
|
174
175
|
}
|
|
175
176
|
/**
|
|
176
177
|
* Merges the input services in order to use some as a backup source.
|
|
@@ -182,50 +183,56 @@ function logMergeZohoAccountsAccessTokenCacheServiceErrorFunction(failedUpdates)
|
|
|
182
183
|
* @param servicesToMerge Must include atleast one service. Empty arrays will throw an error.
|
|
183
184
|
*/
|
|
184
185
|
function mergeZohoAccountsAccessTokenCacheServices(inputServicesToMerge, logError) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
const service = {
|
|
191
|
-
loadZohoAccessTokenCache: function (service) {
|
|
192
|
-
const accessCachesForServices = services.map(x => x.loadZohoAccessTokenCache(service));
|
|
193
|
-
const loadCachedTokenFromFirstService = util.tryWithPromiseFactoriesFunction({
|
|
194
|
-
promiseFactories: accessCachesForServices.map(x => () => x.loadCachedToken().catch(() => null).then(x => {
|
|
195
|
-
let result = undefined;
|
|
196
|
-
if (x && !util.isPast(x.expiresAt)) {
|
|
197
|
-
result = x; // only return from cache if it is not expired
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
})),
|
|
201
|
-
successOnMaybe: false,
|
|
202
|
-
throwErrors: false
|
|
203
|
-
});
|
|
204
|
-
const cacheForService = {
|
|
205
|
-
loadCachedToken: function () {
|
|
206
|
-
return loadCachedTokenFromFirstService();
|
|
207
|
-
},
|
|
208
|
-
updateCachedToken: async function (accessToken) {
|
|
209
|
-
return Promise.allSettled(accessCachesForServices.map(x => x.updateCachedToken(accessToken).then(() => null).catch(e => {
|
|
210
|
-
return [x, e];
|
|
211
|
-
}))).then(x => {
|
|
212
|
-
// only find the failures if we're logging
|
|
213
|
-
if (logErrorFunction != null) {
|
|
214
|
-
const failedUpdates = util.filterMaybeArrayValues(x.map(y => y.value));
|
|
215
|
-
if (failedUpdates.length) {
|
|
216
|
-
logErrorFunction(failedUpdates);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
clearCachedToken: async function () {
|
|
222
|
-
await Promise.allSettled(accessCachesForServices.map(x => x.clearCachedToken()));
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
return cacheForService;
|
|
186
|
+
const services = [...inputServicesToMerge];
|
|
187
|
+
const logErrorFunction = typeof logError === 'function' ? logError : logError !== false ? logMergeZohoAccountsAccessTokenCacheServiceErrorFunction : undefined;
|
|
188
|
+
if (services.length === 0) {
|
|
189
|
+
throw new Error('mergeZohoAccountsAccessTokenCacheServices() input cannot be empty.');
|
|
226
190
|
}
|
|
227
|
-
|
|
228
|
-
|
|
191
|
+
const service = {
|
|
192
|
+
loadZohoAccessTokenCache: function (service) {
|
|
193
|
+
const accessCachesForServices = services.map((x) => x.loadZohoAccessTokenCache(service));
|
|
194
|
+
const loadCachedTokenFromFirstService = util.tryWithPromiseFactoriesFunction({
|
|
195
|
+
promiseFactories: accessCachesForServices.map((x) => () => x
|
|
196
|
+
.loadCachedToken()
|
|
197
|
+
.catch(() => null)
|
|
198
|
+
.then((x) => {
|
|
199
|
+
let result = undefined;
|
|
200
|
+
if (x && !util.isPast(x.expiresAt)) {
|
|
201
|
+
result = x; // only return from cache if it is not expired
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
})),
|
|
205
|
+
successOnMaybe: false,
|
|
206
|
+
throwErrors: false
|
|
207
|
+
});
|
|
208
|
+
const cacheForService = {
|
|
209
|
+
loadCachedToken: function () {
|
|
210
|
+
return loadCachedTokenFromFirstService();
|
|
211
|
+
},
|
|
212
|
+
updateCachedToken: async function (accessToken) {
|
|
213
|
+
return Promise.allSettled(accessCachesForServices.map((x) => x
|
|
214
|
+
.updateCachedToken(accessToken)
|
|
215
|
+
.then(() => null)
|
|
216
|
+
.catch((e) => {
|
|
217
|
+
return [x, e];
|
|
218
|
+
}))).then((x) => {
|
|
219
|
+
// only find the failures if we're logging
|
|
220
|
+
if (logErrorFunction != null) {
|
|
221
|
+
const failedUpdates = util.filterMaybeArrayValues(x.map((y) => y.value));
|
|
222
|
+
if (failedUpdates.length) {
|
|
223
|
+
logErrorFunction(failedUpdates);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
clearCachedToken: async function () {
|
|
229
|
+
await Promise.allSettled(accessCachesForServices.map((x) => x.clearCachedToken()));
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
return cacheForService;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
return service;
|
|
229
236
|
}
|
|
230
237
|
// MARK: Memory Access Token Cache
|
|
231
238
|
/**
|
|
@@ -234,42 +241,34 @@ function mergeZohoAccountsAccessTokenCacheServices(inputServicesToMerge, logErro
|
|
|
234
241
|
* @returns
|
|
235
242
|
*/
|
|
236
243
|
function memoryZohoAccountsAccessTokenCacheService(existingCache, logAccessToConsole) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
244
|
+
const tokens = existingCache ?? {};
|
|
245
|
+
function loadZohoAccessTokenCache(service) {
|
|
246
|
+
const accessTokenCache = {
|
|
247
|
+
loadCachedToken: async function () {
|
|
248
|
+
const token = tokens[service];
|
|
249
|
+
if (logAccessToConsole) {
|
|
250
|
+
console.log('retrieving access token from memory: ', { token, service });
|
|
251
|
+
}
|
|
252
|
+
return token;
|
|
253
|
+
},
|
|
254
|
+
updateCachedToken: async function (accessToken) {
|
|
255
|
+
tokens[service] = accessToken;
|
|
256
|
+
if (logAccessToConsole) {
|
|
257
|
+
console.log('updating access token in memory: ', { accessToken, service });
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
clearCachedToken: async function () {
|
|
261
|
+
delete tokens[service];
|
|
262
|
+
if (logAccessToConsole) {
|
|
263
|
+
console.log('clearing access token in memory: ', { service });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
return accessTokenCache;
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
loadZohoAccessTokenCache
|
|
267
271
|
};
|
|
268
|
-
return accessTokenCache;
|
|
269
|
-
}
|
|
270
|
-
return {
|
|
271
|
-
loadZohoAccessTokenCache
|
|
272
|
-
};
|
|
273
272
|
}
|
|
274
273
|
// MARK: File System Access Token Cache
|
|
275
274
|
const DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoho-access-tokens.json';
|
|
@@ -281,273 +280,289 @@ const DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoho-ac
|
|
|
281
280
|
* @returns
|
|
282
281
|
*/
|
|
283
282
|
function fileZohoAccountsAccessTokenCacheService(filename = DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH, useMemoryCache = true) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
283
|
+
let loadedTokens = null;
|
|
284
|
+
async function loadTokens() {
|
|
285
|
+
if (!loadedTokens) {
|
|
286
|
+
return (await readTokenFile()) ?? {};
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
return loadedTokens;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function readTokenFile() {
|
|
293
|
+
return new Promise((resolve) => {
|
|
294
|
+
fs.mkdirSync(path.dirname(filename), { recursive: true }); // make the directory first
|
|
295
|
+
fs.readFile(filename, {}, (x, data) => {
|
|
296
|
+
let result = undefined;
|
|
297
|
+
if (!x) {
|
|
298
|
+
try {
|
|
299
|
+
result = JSON.parse(data.toString());
|
|
300
|
+
util.forEachKeyValue(result, {
|
|
301
|
+
forEach: (x) => {
|
|
302
|
+
if (x[1]) {
|
|
303
|
+
x[1].expiresAt = new Date(x[1].expiresAt);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
catch (e) {
|
|
309
|
+
console.error('Failed reading token file: ', e);
|
|
310
|
+
}
|
|
306
311
|
}
|
|
307
|
-
|
|
312
|
+
resolve(result);
|
|
308
313
|
});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
314
|
+
}).then((x) => {
|
|
315
|
+
// update loaded tokens
|
|
316
|
+
if (useMemoryCache) {
|
|
317
|
+
loadedTokens = {
|
|
318
|
+
...loadedTokens,
|
|
319
|
+
...x
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return x;
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
async function writeTokenFile(tokens) {
|
|
326
|
+
return new Promise((resolve, reject) => {
|
|
327
|
+
fs.writeFile(filename, JSON.stringify(tokens), {}, (x) => {
|
|
328
|
+
if (!x) {
|
|
329
|
+
resolve();
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
reject(x);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
async function deleteTokenFile() {
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
fs.rm(filename, (x) => {
|
|
340
|
+
if (!x) {
|
|
341
|
+
resolve();
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
reject(x);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function loadZohoAccessTokenCache(service) {
|
|
350
|
+
const accessTokenCache = {
|
|
351
|
+
loadCachedToken: async function () {
|
|
352
|
+
const tokens = await loadTokens();
|
|
353
|
+
const token = tokens[service];
|
|
354
|
+
// console.log('retrieving access token from file: ', { token, service });
|
|
355
|
+
return token;
|
|
356
|
+
},
|
|
357
|
+
updateCachedToken: async function (accessToken) {
|
|
358
|
+
const tokens = await loadTokens();
|
|
359
|
+
if (tokens) {
|
|
360
|
+
tokens[service] = accessToken;
|
|
361
|
+
}
|
|
362
|
+
// console.log('updating access token in file: ', { accessToken, service });
|
|
363
|
+
try {
|
|
364
|
+
await writeTokenFile(tokens);
|
|
365
|
+
}
|
|
366
|
+
catch (e) {
|
|
367
|
+
console.error('Failed updating access token in file: ', e);
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
clearCachedToken: async function () {
|
|
371
|
+
try {
|
|
372
|
+
await writeTokenFile({});
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
console.error('Failed clearing access token in file: ', e);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
321
378
|
};
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (!x) {
|
|
330
|
-
resolve();
|
|
331
|
-
} else {
|
|
332
|
-
reject(x);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
async function deleteTokenFile() {
|
|
338
|
-
return new Promise((resolve, reject) => {
|
|
339
|
-
fs.rm(filename, x => {
|
|
340
|
-
if (!x) {
|
|
341
|
-
resolve();
|
|
342
|
-
} else {
|
|
343
|
-
reject(x);
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
function loadZohoAccessTokenCache(service) {
|
|
349
|
-
const accessTokenCache = {
|
|
350
|
-
loadCachedToken: async function () {
|
|
351
|
-
const tokens = await loadTokens();
|
|
352
|
-
const token = tokens[service];
|
|
353
|
-
// console.log('retrieving access token from file: ', { token, service });
|
|
354
|
-
return token;
|
|
355
|
-
},
|
|
356
|
-
updateCachedToken: async function (accessToken) {
|
|
357
|
-
const tokens = await loadTokens();
|
|
358
|
-
if (tokens) {
|
|
359
|
-
tokens[service] = accessToken;
|
|
360
|
-
}
|
|
361
|
-
// console.log('updating access token in file: ', { accessToken, service });
|
|
362
|
-
try {
|
|
363
|
-
await writeTokenFile(tokens);
|
|
364
|
-
} catch (e) {
|
|
365
|
-
console.error('Failed updating access token in file: ', e);
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
clearCachedToken: async function () {
|
|
369
|
-
try {
|
|
370
|
-
await writeTokenFile({});
|
|
371
|
-
} catch (e) {
|
|
372
|
-
console.error('Failed clearing access token in file: ', e);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
379
|
+
return accessTokenCache;
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
loadZohoAccessTokenCache,
|
|
383
|
+
readTokenFile,
|
|
384
|
+
writeTokenFile,
|
|
385
|
+
deleteTokenFile
|
|
375
386
|
};
|
|
376
|
-
return accessTokenCache;
|
|
377
|
-
}
|
|
378
|
-
return {
|
|
379
|
-
loadZohoAccessTokenCache,
|
|
380
|
-
readTokenFile,
|
|
381
|
-
writeTokenFile,
|
|
382
|
-
deleteTokenFile
|
|
383
|
-
};
|
|
384
387
|
}
|
|
385
388
|
|
|
386
389
|
exports.ZohoAccountsApi = class ZohoAccountsApi {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
390
|
+
config;
|
|
391
|
+
cacheService;
|
|
392
|
+
zohoAccounts;
|
|
393
|
+
get accountsContext() {
|
|
394
|
+
return this.zohoAccounts.accountsContext;
|
|
395
|
+
}
|
|
396
|
+
constructor(config, cacheService) {
|
|
397
|
+
this.config = config;
|
|
398
|
+
this.cacheService = cacheService;
|
|
399
|
+
const accessTokenCache = config.zohoAccounts.accessTokenCache ? config.zohoAccounts.accessTokenCache : cacheService.loadZohoAccessTokenCache(config.zohoAccounts.serviceAccessTokenKey);
|
|
400
|
+
this.zohoAccounts = zoho.zohoAccountsFactory(config.factoryConfig ?? {})({
|
|
401
|
+
accessTokenCache,
|
|
402
|
+
...config.zohoAccounts
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
// MARK: Accessors
|
|
406
|
+
get accessToken() {
|
|
407
|
+
return zoho.zohoAccountsAccessToken(this.accountsContext);
|
|
408
|
+
}
|
|
406
409
|
};
|
|
407
|
-
exports.ZohoAccountsApi = __decorate([
|
|
410
|
+
exports.ZohoAccountsApi = __decorate([
|
|
411
|
+
common.Injectable(),
|
|
412
|
+
__param(0, common.Inject(ZohoAccountsServiceConfig)),
|
|
413
|
+
__param(1, common.Inject(exports.ZohoAccountsAccessTokenCacheService)),
|
|
414
|
+
__metadata("design:paramtypes", [ZohoAccountsServiceConfig,
|
|
415
|
+
exports.ZohoAccountsAccessTokenCacheService])
|
|
416
|
+
], exports.ZohoAccountsApi);
|
|
408
417
|
|
|
409
418
|
/**
|
|
410
419
|
* Configuration for ZohoRecruitService
|
|
411
420
|
*/
|
|
412
421
|
class ZohoRecruitServiceConfig {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
422
|
+
zohoRecruit;
|
|
423
|
+
factoryConfig;
|
|
424
|
+
static assertValidConfig(config) {
|
|
425
|
+
assertValidZohoConfig(config.zohoRecruit);
|
|
426
|
+
}
|
|
418
427
|
}
|
|
419
428
|
|
|
420
429
|
exports.ZohoRecruitApi = class ZohoRecruitApi {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
430
|
+
config;
|
|
431
|
+
zohoAccountsApi;
|
|
432
|
+
zohoRecruit;
|
|
433
|
+
get recruitContext() {
|
|
434
|
+
return this.zohoRecruit.recruitContext;
|
|
435
|
+
}
|
|
436
|
+
get zohoRateLimiter() {
|
|
437
|
+
return this.zohoRecruit.recruitContext.zohoRateLimiter;
|
|
438
|
+
}
|
|
439
|
+
constructor(config, zohoAccountsApi) {
|
|
440
|
+
this.config = config;
|
|
441
|
+
this.zohoAccountsApi = zohoAccountsApi;
|
|
442
|
+
this.zohoRecruit = zoho.zohoRecruitFactory({
|
|
443
|
+
...config.factoryConfig,
|
|
444
|
+
accountsContext: zohoAccountsApi.accountsContext
|
|
445
|
+
})(config.zohoRecruit);
|
|
446
|
+
}
|
|
447
|
+
// MARK: Accessors
|
|
448
|
+
get insertRecord() {
|
|
449
|
+
return zoho.zohoRecruitInsertRecord(this.recruitContext);
|
|
450
|
+
}
|
|
451
|
+
get upsertRecord() {
|
|
452
|
+
return zoho.zohoRecruitUpsertRecord(this.recruitContext);
|
|
453
|
+
}
|
|
454
|
+
get updateRecord() {
|
|
455
|
+
return zoho.zohoRecruitUpdateRecord(this.recruitContext);
|
|
456
|
+
}
|
|
457
|
+
get deleteRecord() {
|
|
458
|
+
return zoho.zohoRecruitDeleteRecord(this.recruitContext);
|
|
459
|
+
}
|
|
460
|
+
get getRecordById() {
|
|
461
|
+
return zoho.zohoRecruitGetRecordById(this.recruitContext);
|
|
462
|
+
}
|
|
463
|
+
get getRecords() {
|
|
464
|
+
return zoho.zohoRecruitGetRecords(this.recruitContext);
|
|
465
|
+
}
|
|
466
|
+
get searchRecords() {
|
|
467
|
+
return zoho.zohoRecruitSearchRecords(this.recruitContext);
|
|
468
|
+
}
|
|
469
|
+
get searchRecordsPageFactory() {
|
|
470
|
+
return zoho.zohoRecruitSearchRecordsPageFactory(this.recruitContext);
|
|
471
|
+
}
|
|
472
|
+
get getRelatedRecordsFunctionFactory() {
|
|
473
|
+
return zoho.zohoRecruitGetRelatedRecordsFunctionFactory(this.recruitContext);
|
|
474
|
+
}
|
|
475
|
+
get getEmailsForRecord() {
|
|
476
|
+
return zoho.zohoRecruitGetEmailsForRecord(this.recruitContext);
|
|
477
|
+
}
|
|
478
|
+
get getEmailsForRecordPageFactory() {
|
|
479
|
+
return zoho.zohoRecruitGetEmailsForRecordPageFactory(this.recruitContext);
|
|
480
|
+
}
|
|
481
|
+
get getAttachmentsForRecord() {
|
|
482
|
+
return zoho.zohoRecruitGetAttachmentsForRecord(this.recruitContext);
|
|
483
|
+
}
|
|
484
|
+
get getAttachmentsForRecordPageFactory() {
|
|
485
|
+
return zoho.zohoRecruitGetAttachmentsForRecordPageFactory(this.recruitContext);
|
|
486
|
+
}
|
|
487
|
+
get uploadAttachmentForRecord() {
|
|
488
|
+
return zoho.zohoRecruitUploadAttachmentForRecord(this.recruitContext);
|
|
489
|
+
}
|
|
490
|
+
get downloadAttachmentForRecord() {
|
|
491
|
+
return zoho.zohoRecruitDownloadAttachmentForRecord(this.recruitContext);
|
|
492
|
+
}
|
|
493
|
+
get deleteAttachmentFromRecord() {
|
|
494
|
+
return zoho.zohoRecruitDeleteAttachmentFromRecord(this.recruitContext);
|
|
495
|
+
}
|
|
496
|
+
get createNotes() {
|
|
497
|
+
return zoho.zohoRecruitCreateNotes(this.recruitContext);
|
|
498
|
+
}
|
|
499
|
+
get deleteNotes() {
|
|
500
|
+
return zoho.zohoRecruitDeleteNotes(this.recruitContext);
|
|
501
|
+
}
|
|
502
|
+
get createNotesForRecord() {
|
|
503
|
+
return zoho.zohoRecruitCreateNotesForRecord(this.recruitContext);
|
|
504
|
+
}
|
|
505
|
+
get getNotesForRecord() {
|
|
506
|
+
return zoho.zohoRecruitGetNotesForRecord(this.recruitContext);
|
|
507
|
+
}
|
|
508
|
+
get getNotesForRecordPageFactory() {
|
|
509
|
+
return zoho.zohoRecruitGetNotesForRecordPageFactory(this.recruitContext);
|
|
510
|
+
}
|
|
511
|
+
get executeRestApiFunction() {
|
|
512
|
+
return zoho.zohoRecruitExecuteRestApiFunction(this.recruitContext);
|
|
513
|
+
}
|
|
514
|
+
get associateCandidateRecordsWithJobOpenings() {
|
|
515
|
+
return zoho.zohoRecruitAssociateCandidateRecordsWithJobOpenings(this.recruitContext);
|
|
516
|
+
}
|
|
517
|
+
get searchCandidateAssociatedJobOpeningRecords() {
|
|
518
|
+
return zoho.zohoRecruitSearchCandidateAssociatedJobOpeningRecords(this.recruitContext);
|
|
519
|
+
}
|
|
520
|
+
get searchCandidateAssociatedJobOpeningRecordsPageFactory() {
|
|
521
|
+
return zoho.zohoRecruitSearchCandidateAssociatedJobOpeningRecordsPageFactory(this.recruitContext);
|
|
522
|
+
}
|
|
523
|
+
get searchJobOpeningAssociatedCandidateRecords() {
|
|
524
|
+
return zoho.zohoRecruitSearchJobOpeningAssociatedCandidateRecords(this.recruitContext);
|
|
525
|
+
}
|
|
526
|
+
get searchJobOpeningAssociatedCandidateRecordsPageFactory() {
|
|
527
|
+
return zoho.zohoRecruitSearchJobOpeningAssociatedCandidateRecordsPageFactory(this.recruitContext);
|
|
528
|
+
}
|
|
529
|
+
get createTagsForModule() {
|
|
530
|
+
return zoho.zohoRecruitCreateTagsForModule(this.recruitContext);
|
|
531
|
+
}
|
|
532
|
+
get getTagsForModule() {
|
|
533
|
+
return zoho.zohoRecruitGetTagsForModule(this.recruitContext);
|
|
534
|
+
}
|
|
535
|
+
get addTagsToRecords() {
|
|
536
|
+
return zoho.zohoRecruitAddTagsToRecords(this.recruitContext);
|
|
537
|
+
}
|
|
538
|
+
get removeTagsFromRecords() {
|
|
539
|
+
return zoho.zohoRecruitRemoveTagsFromRecords(this.recruitContext);
|
|
540
|
+
}
|
|
532
541
|
};
|
|
533
|
-
exports.ZohoRecruitApi = __decorate([
|
|
542
|
+
exports.ZohoRecruitApi = __decorate([
|
|
543
|
+
common.Injectable(),
|
|
544
|
+
__param(0, common.Inject(ZohoRecruitServiceConfig)),
|
|
545
|
+
__param(1, common.Inject(exports.ZohoAccountsApi)),
|
|
546
|
+
__metadata("design:paramtypes", [ZohoRecruitServiceConfig,
|
|
547
|
+
exports.ZohoAccountsApi])
|
|
548
|
+
], exports.ZohoRecruitApi);
|
|
534
549
|
|
|
535
550
|
// MARK: Provider Factories
|
|
536
551
|
function zohoRecruitServiceConfigFactory(configService) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
552
|
+
const getFromConfigService = zohoConfigServiceReaderFunction(zoho.ZOHO_RECRUIT_SERVICE_NAME, configService);
|
|
553
|
+
const config = {
|
|
554
|
+
zohoRecruit: {
|
|
555
|
+
apiUrl: getFromConfigService(ZOHO_API_URL_CONFIG_KEY)
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
ZohoRecruitServiceConfig.assertValidConfig(config);
|
|
559
|
+
return config;
|
|
545
560
|
}
|
|
546
561
|
function zohoRecruitAccountServiceConfigFactory(configService) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
562
|
+
return zohoAccountsServiceConfigFromConfigService({
|
|
563
|
+
configService,
|
|
564
|
+
serviceAccessTokenKey: zoho.ZOHO_RECRUIT_SERVICE_NAME
|
|
565
|
+
});
|
|
551
566
|
}
|
|
552
567
|
/**
|
|
553
568
|
* Convenience function used to generate ModuleMetadata for an app's ZohoRecruitModule.
|
|
@@ -557,28 +572,28 @@ function zohoRecruitAccountServiceConfigFactory(configService) {
|
|
|
557
572
|
* @returns
|
|
558
573
|
*/
|
|
559
574
|
function appZohoRecruitModuleMetadata(config$1) {
|
|
560
|
-
|
|
561
|
-
dependencyModule
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
575
|
+
const { dependencyModule, imports, exports: exports$1, providers } = config$1;
|
|
576
|
+
const dependencyModuleImport = dependencyModule ? [dependencyModule] : [];
|
|
577
|
+
return {
|
|
578
|
+
imports: [config.ConfigModule, ...dependencyModuleImport, ...(imports ?? [])],
|
|
579
|
+
exports: [exports.ZohoRecruitApi, ...(exports$1 ?? [])],
|
|
580
|
+
providers: [
|
|
581
|
+
{
|
|
582
|
+
provide: ZohoRecruitServiceConfig,
|
|
583
|
+
inject: [config.ConfigService],
|
|
584
|
+
useFactory: zohoRecruitServiceConfigFactory
|
|
585
|
+
},
|
|
586
|
+
exports.ZohoRecruitApi,
|
|
587
|
+
// Accounts
|
|
588
|
+
{
|
|
589
|
+
provide: ZohoAccountsServiceConfig,
|
|
590
|
+
inject: [config.ConfigService],
|
|
591
|
+
useFactory: zohoRecruitAccountServiceConfigFactory
|
|
592
|
+
},
|
|
593
|
+
exports.ZohoAccountsApi,
|
|
594
|
+
...(providers ?? [])
|
|
595
|
+
]
|
|
596
|
+
};
|
|
582
597
|
}
|
|
583
598
|
|
|
584
599
|
exports.DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH;
|