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