@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.
@@ -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
- let configService;
50
- let serviceAccessTokenKey;
51
- if (typeof inputOrKey === 'string') {
52
- serviceAccessTokenKey = inputOrKey;
53
- configService = inputConfigService;
54
- } else {
55
- configService = inputOrKey.configService;
56
- serviceAccessTokenKey = inputOrKey.serviceAccessTokenKey;
57
- }
58
- const baseServicePrefix = 'ZOHO_';
59
- const servicePrefix = serviceAccessTokenKey.toUpperCase(); // "RECRUIT"
60
- const servicePrefixString = `${baseServicePrefix}${servicePrefix}_`; // "ZOHO_RECRUIT_"
61
- return key => {
62
- const baseConfigKey = `${baseServicePrefix}${key}`; // "ZOHO_ACCOUNTS_URL"
63
- const serviceSpecificConfigKey = `${servicePrefixString}${key}`; // "ZOHO_RECRUIT_ACCOUNTS_URL"
64
- return configService.get(serviceSpecificConfigKey) ?? configService.get(baseConfigKey);
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
- const servicePrefixString = servicePrefix ? `${servicePrefix}_` : '';
75
- const apiUrlConfigKey = `${servicePrefixString}${ZOHO_API_URL_CONFIG_KEY}`;
76
- const config = {
77
- apiUrl: configService.get(apiUrlConfigKey) ?? configService.get(ZOHO_API_URL_CONFIG_KEY)
78
- };
79
- if (assertValid) {
80
- if (!config.apiUrl) {
81
- throw new Error(`No Zoho API url or type specified for key "${apiUrlConfigKey}".`);
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
- if (!config.apiUrl) {
88
- throw new Error(`No Zoho API url or type specified.`);
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
- zohoAccounts;
97
- factoryConfig;
98
- static assertValidConfig(config) {
99
- const {
100
- zohoAccounts
101
- } = config;
102
- if (!zohoAccounts) {
103
- throw new Error('ZohoAccountsServiceConfig.zohoAccounts is required');
104
- } else {
105
- if (!zohoAccounts.serviceAccessTokenKey) {
106
- throw new Error('ZohoAccountsServiceConfig.zohoAccounts.serviceAccessTokenKey is required');
107
- } else if (!zohoAccounts.refreshToken) {
108
- throw new Error('ZohoAccountsServiceConfig.zohoAccounts.refreshToken is required');
109
- } else if (!zohoAccounts.apiUrl) {
110
- throw new Error('ZohoAccountsServiceConfig.zohoAccounts.apiUrl is required');
111
- } else if (!zohoAccounts.clientId) {
112
- throw new Error('ZohoAccountsServiceConfig.zohoAccounts.clientId is required');
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
- const {
144
- serviceAccessTokenKey
145
- } = input;
146
- const getFromConfigService = zohoConfigServiceReaderFunction(input);
147
- const zohoAccounts = {
148
- serviceAccessTokenKey,
149
- apiUrl: getFromConfigService('ACCOUNTS_URL'),
150
- // ZOHO_<SERVICE>_ACCOUNTS_URL, ZOHO_ACCOUNTS_URL
151
- refreshToken: getFromConfigService('ACCOUNTS_REFRESH_TOKEN'),
152
- // ZOHO_<SERVICE>_ACCOUNTS_REFRESH_TOKEN, ZOHO_ACCOUNTS_REFRESH_TOKEN
153
- clientId: getFromConfigService('ACCOUNTS_CLIENT_ID'),
154
- // ZOHO_<SERVICE>_ACCOUNTS_CLIENT_ID, ZOHO_ACCOUNTS_CLIENT_ID
155
- clientSecret: getFromConfigService('ACCOUNTS_CLIENT_SECRET') // ZOHO_<SERVICE>_ACCOUNTS_CLIENT_SECRET, ZOHO_ACCOUNTS_CLIENT_SECRET
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
- exports.ZohoAccountsAccessTokenCacheService = __decorate([common.Injectable()], exports.ZohoAccountsAccessTokenCacheService);
165
+ exports.ZohoAccountsAccessTokenCacheService = class ZohoAccountsAccessTokenCacheService {
166
+ };
167
+ exports.ZohoAccountsAccessTokenCacheService = __decorate([
168
+ common.Injectable()
169
+ ], exports.ZohoAccountsAccessTokenCacheService);
169
170
  function logMergeZohoAccountsAccessTokenCacheServiceErrorFunction(failedUpdates) {
170
- console.warn(`mergeZohoAccountsAccessTokenCacheServices(): failed updating ${failedUpdates.length} caches.`);
171
- failedUpdates.forEach(([x, e], i) => {
172
- console.warn(`Cache update failure ${i + 1}: - ${e}`);
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
- const services = [...inputServicesToMerge];
186
- const logErrorFunction = typeof logError === 'function' ? logError : logError !== false ? logMergeZohoAccountsAccessTokenCacheServiceErrorFunction : undefined;
187
- if (services.length === 0) {
188
- throw new Error('mergeZohoAccountsAccessTokenCacheServices() input cannot be empty.');
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
- return service;
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
- const tokens = existingCache ?? {};
238
- function loadZohoAccessTokenCache(service) {
239
- const accessTokenCache = {
240
- loadCachedToken: async function () {
241
- const token = tokens[service];
242
- if (logAccessToConsole) {
243
- console.log('retrieving access token from memory: ', {
244
- token,
245
- service
246
- });
247
- }
248
- return token;
249
- },
250
- updateCachedToken: async function (accessToken) {
251
- tokens[service] = accessToken;
252
- if (logAccessToConsole) {
253
- console.log('updating access token in memory: ', {
254
- accessToken,
255
- service
256
- });
257
- }
258
- },
259
- clearCachedToken: async function () {
260
- delete tokens[service];
261
- if (logAccessToConsole) {
262
- console.log('clearing access token in memory: ', {
263
- service
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
- let loadedTokens = null;
285
- async function loadTokens() {
286
- if (!loadedTokens) {
287
- return (await readTokenFile()) ?? {};
288
- } else {
289
- return loadedTokens;
290
- }
291
- }
292
- function readTokenFile() {
293
- return new Promise(resolve => {
294
- fs.mkdirSync(path.dirname(filename), {
295
- recursive: true
296
- }); // make the directory first
297
- fs.readFile(filename, {}, (x, data) => {
298
- let result = undefined;
299
- if (!x) {
300
- try {
301
- result = JSON.parse(data.toString());
302
- util.forEachKeyValue(result, {
303
- forEach: x => {
304
- if (x[1]) {
305
- x[1].expiresAt = new Date(x[1].expiresAt);
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
- } catch (e) {
310
- console.error('Failed reading token file: ', e);
311
- }
312
- }
313
- resolve(result);
314
- });
315
- }).then(x => {
316
- // update loaded tokens
317
- if (useMemoryCache) {
318
- loadedTokens = {
319
- ...loadedTokens,
320
- ...x
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
- return x;
324
- });
325
- }
326
- async function writeTokenFile(tokens) {
327
- return new Promise((resolve, reject) => {
328
- fs.writeFile(filename, JSON.stringify(tokens), {}, x => {
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
- config;
388
- cacheService;
389
- zohoAccounts;
390
- get accountsContext() {
391
- return this.zohoAccounts.accountsContext;
392
- }
393
- constructor(config, cacheService) {
394
- this.config = config;
395
- this.cacheService = cacheService;
396
- const accessTokenCache = config.zohoAccounts.accessTokenCache ? config.zohoAccounts.accessTokenCache : cacheService.loadZohoAccessTokenCache(config.zohoAccounts.serviceAccessTokenKey);
397
- this.zohoAccounts = zoho.zohoAccountsFactory(config.factoryConfig ?? {})({
398
- accessTokenCache,
399
- ...config.zohoAccounts
400
- });
401
- }
402
- // MARK: Accessors
403
- get accessToken() {
404
- return zoho.zohoAccountsAccessToken(this.accountsContext);
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([common.Injectable(), __param(0, common.Inject(ZohoAccountsServiceConfig)), __param(1, common.Inject(exports.ZohoAccountsAccessTokenCacheService)), __metadata("design:paramtypes", [ZohoAccountsServiceConfig, exports.ZohoAccountsAccessTokenCacheService])], exports.ZohoAccountsApi);
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
- zohoRecruit;
414
- factoryConfig;
415
- static assertValidConfig(config) {
416
- assertValidZohoConfig(config.zohoRecruit);
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
- config;
422
- zohoAccountsApi;
423
- zohoRecruit;
424
- get recruitContext() {
425
- return this.zohoRecruit.recruitContext;
426
- }
427
- get zohoRateLimiter() {
428
- return this.zohoRecruit.recruitContext.zohoRateLimiter;
429
- }
430
- constructor(config, zohoAccountsApi) {
431
- this.config = config;
432
- this.zohoAccountsApi = zohoAccountsApi;
433
- this.zohoRecruit = zoho.zohoRecruitFactory({
434
- ...config.factoryConfig,
435
- accountsContext: zohoAccountsApi.accountsContext
436
- })(config.zohoRecruit);
437
- }
438
- // MARK: Accessors
439
- get insertRecord() {
440
- return zoho.zohoRecruitInsertRecord(this.recruitContext);
441
- }
442
- get upsertRecord() {
443
- return zoho.zohoRecruitUpsertRecord(this.recruitContext);
444
- }
445
- get updateRecord() {
446
- return zoho.zohoRecruitUpdateRecord(this.recruitContext);
447
- }
448
- get deleteRecord() {
449
- return zoho.zohoRecruitDeleteRecord(this.recruitContext);
450
- }
451
- get getRecordById() {
452
- return zoho.zohoRecruitGetRecordById(this.recruitContext);
453
- }
454
- get getRecords() {
455
- return zoho.zohoRecruitGetRecords(this.recruitContext);
456
- }
457
- get searchRecords() {
458
- return zoho.zohoRecruitSearchRecords(this.recruitContext);
459
- }
460
- get searchRecordsPageFactory() {
461
- return zoho.zohoRecruitSearchRecordsPageFactory(this.recruitContext);
462
- }
463
- get getRelatedRecordsFunctionFactory() {
464
- return zoho.zohoRecruitGetRelatedRecordsFunctionFactory(this.recruitContext);
465
- }
466
- get getEmailsForRecord() {
467
- return zoho.zohoRecruitGetEmailsForRecord(this.recruitContext);
468
- }
469
- get getEmailsForRecordPageFactory() {
470
- return zoho.zohoRecruitGetEmailsForRecordPageFactory(this.recruitContext);
471
- }
472
- get getAttachmentsForRecord() {
473
- return zoho.zohoRecruitGetAttachmentsForRecord(this.recruitContext);
474
- }
475
- get getAttachmentsForRecordPageFactory() {
476
- return zoho.zohoRecruitGetAttachmentsForRecordPageFactory(this.recruitContext);
477
- }
478
- get uploadAttachmentForRecord() {
479
- return zoho.zohoRecruitUploadAttachmentForRecord(this.recruitContext);
480
- }
481
- get downloadAttachmentForRecord() {
482
- return zoho.zohoRecruitDownloadAttachmentForRecord(this.recruitContext);
483
- }
484
- get deleteAttachmentFromRecord() {
485
- return zoho.zohoRecruitDeleteAttachmentFromRecord(this.recruitContext);
486
- }
487
- get createNotes() {
488
- return zoho.zohoRecruitCreateNotes(this.recruitContext);
489
- }
490
- get deleteNotes() {
491
- return zoho.zohoRecruitDeleteNotes(this.recruitContext);
492
- }
493
- get createNotesForRecord() {
494
- return zoho.zohoRecruitCreateNotesForRecord(this.recruitContext);
495
- }
496
- get getNotesForRecord() {
497
- return zoho.zohoRecruitGetNotesForRecord(this.recruitContext);
498
- }
499
- get getNotesForRecordPageFactory() {
500
- return zoho.zohoRecruitGetNotesForRecordPageFactory(this.recruitContext);
501
- }
502
- get executeRestApiFunction() {
503
- return zoho.zohoRecruitExecuteRestApiFunction(this.recruitContext);
504
- }
505
- get associateCandidateRecordsWithJobOpenings() {
506
- return zoho.zohoRecruitAssociateCandidateRecordsWithJobOpenings(this.recruitContext);
507
- }
508
- get searchCandidateAssociatedJobOpeningRecords() {
509
- return zoho.zohoRecruitSearchCandidateAssociatedJobOpeningRecords(this.recruitContext);
510
- }
511
- get searchCandidateAssociatedJobOpeningRecordsPageFactory() {
512
- return zoho.zohoRecruitSearchCandidateAssociatedJobOpeningRecordsPageFactory(this.recruitContext);
513
- }
514
- get searchJobOpeningAssociatedCandidateRecords() {
515
- return zoho.zohoRecruitSearchJobOpeningAssociatedCandidateRecords(this.recruitContext);
516
- }
517
- get searchJobOpeningAssociatedCandidateRecordsPageFactory() {
518
- return zoho.zohoRecruitSearchJobOpeningAssociatedCandidateRecordsPageFactory(this.recruitContext);
519
- }
520
- get createTagsForModule() {
521
- return zoho.zohoRecruitCreateTagsForModule(this.recruitContext);
522
- }
523
- get getTagsForModule() {
524
- return zoho.zohoRecruitGetTagsForModule(this.recruitContext);
525
- }
526
- get addTagsToRecords() {
527
- return zoho.zohoRecruitAddTagsToRecords(this.recruitContext);
528
- }
529
- get removeTagsFromRecords() {
530
- return zoho.zohoRecruitRemoveTagsFromRecords(this.recruitContext);
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([common.Injectable(), __param(0, common.Inject(ZohoRecruitServiceConfig)), __param(1, common.Inject(exports.ZohoAccountsApi)), __metadata("design:paramtypes", [ZohoRecruitServiceConfig, exports.ZohoAccountsApi])], exports.ZohoRecruitApi);
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
- const getFromConfigService = zohoConfigServiceReaderFunction(zoho.ZOHO_RECRUIT_SERVICE_NAME, configService);
538
- const config = {
539
- zohoRecruit: {
540
- apiUrl: getFromConfigService(ZOHO_API_URL_CONFIG_KEY)
541
- }
542
- };
543
- ZohoRecruitServiceConfig.assertValidConfig(config);
544
- return config;
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
- return zohoAccountsServiceConfigFromConfigService({
548
- configService,
549
- serviceAccessTokenKey: zoho.ZOHO_RECRUIT_SERVICE_NAME
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
- const {
561
- dependencyModule,
562
- imports,
563
- exports: exports$1,
564
- providers
565
- } = config$1;
566
- const dependencyModuleImport = dependencyModule ? [dependencyModule] : [];
567
- return {
568
- imports: [config.ConfigModule, ...dependencyModuleImport, ...(imports ?? [])],
569
- exports: [exports.ZohoRecruitApi, ...(exports$1 ?? [])],
570
- providers: [{
571
- provide: ZohoRecruitServiceConfig,
572
- inject: [config.ConfigService],
573
- useFactory: zohoRecruitServiceConfigFactory
574
- }, exports.ZohoRecruitApi,
575
- // Accounts
576
- {
577
- provide: ZohoAccountsServiceConfig,
578
- inject: [config.ConfigService],
579
- useFactory: zohoRecruitAccountServiceConfigFactory
580
- }, exports.ZohoAccountsApi, ...(providers ?? [])]
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;