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