@dereekb/zoho 12.6.21 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +1 -1
  2. package/index.cjs.js +1763 -2531
  3. package/index.esm.js +1655 -2524
  4. package/nestjs/index.cjs.js +598 -0
  5. package/nestjs/index.esm.js +582 -0
  6. package/nestjs/package.json +19 -3
  7. package/nestjs/src/lib/accounts/accounts.config.d.ts +32 -0
  8. package/nestjs/src/lib/crm/crm.api.d.ts +43 -0
  9. package/nestjs/src/lib/crm/crm.config.d.ts +10 -0
  10. package/nestjs/src/lib/crm/crm.module.d.ts +24 -0
  11. package/nestjs/src/lib/crm/index.d.ts +3 -0
  12. package/nestjs/src/lib/recruit/recruit.api.d.ts +7 -7
  13. package/package.json +14 -7
  14. package/src/lib/accounts/accounts.api.d.ts +1 -1
  15. package/src/lib/accounts/accounts.error.api.d.ts +2 -2
  16. package/src/lib/crm/crm.api.d.ts +430 -0
  17. package/src/lib/crm/crm.api.notes.d.ts +40 -0
  18. package/src/lib/crm/crm.api.tags.d.ts +160 -0
  19. package/src/lib/crm/crm.config.d.ts +24 -0
  20. package/src/lib/crm/crm.criteria.d.ts +19 -0
  21. package/src/lib/crm/crm.d.ts +325 -0
  22. package/src/lib/crm/crm.error.api.d.ts +52 -0
  23. package/src/lib/crm/crm.factory.d.ts +22 -0
  24. package/src/lib/crm/crm.notes.d.ts +48 -0
  25. package/src/lib/crm/crm.tags.d.ts +40 -0
  26. package/src/lib/crm/index.d.ts +10 -0
  27. package/src/lib/index.d.ts +1 -0
  28. package/src/lib/recruit/index.d.ts +0 -1
  29. package/src/lib/recruit/recruit.api.candidates.d.ts +6 -6
  30. package/src/lib/recruit/recruit.api.d.ts +102 -22
  31. package/src/lib/recruit/recruit.api.notes.d.ts +30 -6
  32. package/src/lib/recruit/recruit.api.tags.d.ts +30 -6
  33. package/src/lib/recruit/recruit.criteria.d.ts +8 -44
  34. package/src/lib/recruit/recruit.d.ts +7 -3
  35. package/src/lib/recruit/recruit.error.api.d.ts +7 -3
  36. package/src/lib/shared/criteria.d.ts +55 -0
  37. package/src/lib/shared/criteria.util.d.ts +10 -0
  38. package/src/lib/zoho.error.api.d.ts +64 -6
  39. package/src/lib/zoho.type.d.ts +1 -18
  40. package/nestjs/CHANGELOG.md +0 -459
  41. package/nestjs/README.md +0 -11
  42. package/nestjs/src/index.js +0 -5
  43. package/nestjs/src/index.js.map +0 -1
  44. package/nestjs/src/lib/accounts/accounts.api.js +0 -37
  45. package/nestjs/src/lib/accounts/accounts.api.js.map +0 -1
  46. package/nestjs/src/lib/accounts/accounts.config.js +0 -50
  47. package/nestjs/src/lib/accounts/accounts.config.js.map +0 -1
  48. package/nestjs/src/lib/accounts/accounts.service.js +0 -240
  49. package/nestjs/src/lib/accounts/accounts.service.js.map +0 -1
  50. package/nestjs/src/lib/accounts/index.js +0 -7
  51. package/nestjs/src/lib/accounts/index.js.map +0 -1
  52. package/nestjs/src/lib/index.js +0 -7
  53. package/nestjs/src/lib/index.js.map +0 -1
  54. package/nestjs/src/lib/recruit/index.js +0 -7
  55. package/nestjs/src/lib/recruit/index.js.map +0 -1
  56. package/nestjs/src/lib/recruit/recruit.api.js +0 -130
  57. package/nestjs/src/lib/recruit/recruit.api.js.map +0 -1
  58. package/nestjs/src/lib/recruit/recruit.config.js +0 -16
  59. package/nestjs/src/lib/recruit/recruit.config.js.map +0 -1
  60. package/nestjs/src/lib/recruit/recruit.module.js +0 -61
  61. package/nestjs/src/lib/recruit/recruit.module.js.map +0 -1
  62. package/nestjs/src/lib/zoho.config.js +0 -52
  63. package/nestjs/src/lib/zoho.config.js.map +0 -1
  64. package/src/lib/recruit/recruit.criteria.util.d.ts +0 -10
  65. /package/{index.cjs.d.ts → index.d.ts} +0 -0
  66. /package/{index.esm.d.ts → nestjs/index.d.ts} +0 -0
@@ -0,0 +1,582 @@
1
+ import { Injectable, Inject } from '@nestjs/common';
2
+ import { zohoAccountsFactory, zohoAccountsAccessToken, zohoRecruitFactory, zohoRecruitInsertRecord, zohoRecruitUpsertRecord, zohoRecruitUpdateRecord, zohoRecruitDeleteRecord, zohoRecruitGetRecordById, zohoRecruitGetRecords, zohoRecruitSearchRecords, zohoRecruitSearchRecordsPageFactory, zohoRecruitGetRelatedRecordsFunctionFactory, zohoRecruitGetEmailsForRecord, zohoRecruitGetEmailsForRecordPageFactory, zohoRecruitGetAttachmentsForRecord, zohoRecruitGetAttachmentsForRecordPageFactory, zohoRecruitUploadAttachmentForRecord, zohoRecruitDownloadAttachmentForRecord, zohoRecruitDeleteAttachmentFromRecord, zohoRecruitCreateNotes, zohoRecruitDeleteNotes, zohoRecruitCreateNotesForRecord, zohoRecruitGetNotesForRecord, zohoRecruitGetNotesForRecordPageFactory, zohoRecruitExecuteRestApiFunction, zohoRecruitAssociateCandidateRecordsWithJobOpenings, zohoRecruitSearchCandidateAssociatedJobOpeningRecords, zohoRecruitSearchCandidateAssociatedJobOpeningRecordsPageFactory, zohoRecruitSearchJobOpeningAssociatedCandidateRecords, zohoRecruitSearchJobOpeningAssociatedCandidateRecordsPageFactory, zohoRecruitCreateTagsForModule, zohoRecruitGetTagsForModule, zohoRecruitAddTagsToRecords, zohoRecruitRemoveTagsFromRecords, ZOHO_RECRUIT_SERVICE_NAME } from '@dereekb/zoho';
3
+ import { forEachKeyValue, tryWithPromiseFactoriesFunction, isPast, filterMaybeArrayValues } from '@dereekb/util';
4
+ import { dirname } from 'path';
5
+ import { rm, writeFile, mkdirSync, readFile } from 'fs';
6
+ import { ConfigService, ConfigModule } from '@nestjs/config';
7
+
8
+ /******************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
23
+
24
+
25
+ function __decorate(decorators, target, key, desc) {
26
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
30
+ }
31
+
32
+ function __param(paramIndex, decorator) {
33
+ return function (target, key) { decorator(target, key, paramIndex); }
34
+ }
35
+
36
+ function __metadata(metadataKey, metadataValue) {
37
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
38
+ }
39
+
40
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
41
+ var e = new Error(message);
42
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
43
+ };
44
+
45
+ const ZOHO_API_URL_CONFIG_KEY = 'API_URL';
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
+ };
64
+ }
65
+ /**
66
+ * Reads the ZohoConfig config from the ConfigService.
67
+ *
68
+ * @param configService
69
+ * @param prefix
70
+ */
71
+ 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}".`);
80
+ }
81
+ }
82
+ return config;
83
+ }
84
+ function assertValidZohoConfig(config) {
85
+ if (!config.apiUrl) {
86
+ throw new Error(`No Zoho API url or type specified.`);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Configuration for ZohoService
92
+ */
93
+ 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
+ }
114
+ }
115
+ /**
116
+ * Builds a {@link ZohoAccountsServiceConfig} by reading Zoho Accounts OAuth credentials
117
+ * from a NestJS `ConfigService` (typically backed by environment variables).
118
+ *
119
+ * ## Environment Variable Resolution
120
+ *
121
+ * For each credential, the function first looks for a **service-specific** environment variable
122
+ * (e.g. `ZOHO_CRM_ACCOUNTS_URL`), then falls back to the **shared** variable
123
+ * (e.g. `ZOHO_ACCOUNTS_URL`). The service prefix is derived from `serviceAccessTokenKey`
124
+ * uppercased (e.g. `'crm'` → `ZOHO_CRM_`, `'recruit'` → `ZOHO_RECRUIT_`).
125
+ *
126
+ * | Credential | Shared env var | Service-specific env var (example: CRM) |
127
+ * |------------------|-------------------------------|----------------------------------------------|
128
+ * | Accounts API URL | `ZOHO_ACCOUNTS_URL` | `ZOHO_CRM_ACCOUNTS_URL` |
129
+ * | Refresh Token | `ZOHO_ACCOUNTS_REFRESH_TOKEN` | `ZOHO_CRM_ACCOUNTS_REFRESH_TOKEN` |
130
+ * | Client ID | `ZOHO_ACCOUNTS_CLIENT_ID` | `ZOHO_CRM_ACCOUNTS_CLIENT_ID` |
131
+ * | Client Secret | `ZOHO_ACCOUNTS_CLIENT_SECRET` | `ZOHO_CRM_ACCOUNTS_CLIENT_SECRET` |
132
+ *
133
+ * When using Zoho Recruit, replace `CRM` with `RECRUIT` in the service-specific variable names.
134
+ *
135
+ * @param input - The {@link ZohoAccountsServiceConfigFromConfigServiceInput} containing the
136
+ * `ConfigService` and the `serviceAccessTokenKey` for the target Zoho service.
137
+ * @returns A validated {@link ZohoAccountsServiceConfig} ready for use with `ZohoAccountsApi`.
138
+ * @throws If any required credential (apiUrl, refreshToken, clientId) is missing.
139
+ */
140
+ 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;
160
+ }
161
+
162
+ /**
163
+ * Service used for retrieving ZohoAccessTokenCache for Zoho services.
164
+ */
165
+ let ZohoAccountsAccessTokenCacheService = class ZohoAccountsAccessTokenCacheService {};
166
+ ZohoAccountsAccessTokenCacheService = __decorate([Injectable()], ZohoAccountsAccessTokenCacheService);
167
+ 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
+ });
172
+ }
173
+ /**
174
+ * Merges the input services in order to use some as a backup source.
175
+ *
176
+ * If once source fails retrieval, the next will be tried.
177
+ *
178
+ * When updating a cached token, it will update the token across all services.
179
+ *
180
+ * @param servicesToMerge Must include atleast one service. Empty arrays will throw an error.
181
+ */
182
+ 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;
224
+ }
225
+ };
226
+ return service;
227
+ }
228
+ // MARK: Memory Access Token Cache
229
+ /**
230
+ * Creates a ZohoAccountsAccessTokenCacheService that uses in-memory storage.
231
+ *
232
+ * @returns
233
+ */
234
+ 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
+ }
265
+ };
266
+ return accessTokenCache;
267
+ }
268
+ return {
269
+ loadZohoAccessTokenCache
270
+ };
271
+ }
272
+ // MARK: File System Access Token Cache
273
+ const DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoho-access-tokens.json';
274
+ /**
275
+ * Creates a ZohoAccountsAccessTokenCacheService that reads and writes the access token to the file system.
276
+ *
277
+ * Useful for testing.
278
+ *
279
+ * @returns
280
+ */
281
+ 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);
304
+ }
305
+ }
306
+ });
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
319
+ };
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
+ }
373
+ };
374
+ return accessTokenCache;
375
+ }
376
+ return {
377
+ loadZohoAccessTokenCache,
378
+ readTokenFile,
379
+ writeTokenFile,
380
+ deleteTokenFile
381
+ };
382
+ }
383
+
384
+ 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
+ }
404
+ };
405
+ ZohoAccountsApi = __decorate([Injectable(), __param(0, Inject(ZohoAccountsServiceConfig)), __param(1, Inject(ZohoAccountsAccessTokenCacheService)), __metadata("design:paramtypes", [ZohoAccountsServiceConfig, ZohoAccountsAccessTokenCacheService])], ZohoAccountsApi);
406
+
407
+ /**
408
+ * Configuration for ZohoRecruitService
409
+ */
410
+ class ZohoRecruitServiceConfig {
411
+ zohoRecruit;
412
+ factoryConfig;
413
+ static assertValidConfig(config) {
414
+ assertValidZohoConfig(config.zohoRecruit);
415
+ }
416
+ }
417
+
418
+ 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
+ }
530
+ };
531
+ ZohoRecruitApi = __decorate([Injectable(), __param(0, Inject(ZohoRecruitServiceConfig)), __param(1, Inject(ZohoAccountsApi)), __metadata("design:paramtypes", [ZohoRecruitServiceConfig, ZohoAccountsApi])], ZohoRecruitApi);
532
+
533
+ // MARK: Provider Factories
534
+ 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;
543
+ }
544
+ function zohoRecruitAccountServiceConfigFactory(configService) {
545
+ return zohoAccountsServiceConfigFromConfigService({
546
+ configService,
547
+ serviceAccessTokenKey: ZOHO_RECRUIT_SERVICE_NAME
548
+ });
549
+ }
550
+ /**
551
+ * Convenience function used to generate ModuleMetadata for an app's ZohoRecruitModule.
552
+ *
553
+ * @param provide
554
+ * @param useFactory
555
+ * @returns
556
+ */
557
+ 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
+ };
580
+ }
581
+
582
+ 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 };
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "@dereekb/zoho/nestjs",
3
- "version": "12.6.21",
4
- "type": "commonjs",
3
+ "version": "13.0.0",
5
4
  "types": "./src/index.d.ts",
6
- "main": "./src/index.js"
5
+ "module": "./index.esm.js",
6
+ "main": "./index.cjs.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.d.ts",
10
+ "node": {
11
+ "require": "./index.cjs.js"
12
+ },
13
+ "browser": {
14
+ "require": "./index.cjs.js",
15
+ "import": "./index.esm.js"
16
+ },
17
+ "default": "./index.cjs.js"
18
+ }
19
+ },
20
+ "peerDependencies": {
21
+ "core-js": "^3.0.0"
22
+ }
7
23
  }
@@ -11,5 +11,37 @@ export declare abstract class ZohoAccountsServiceConfig {
11
11
  readonly factoryConfig?: ZohoAccountsFactoryConfig;
12
12
  static assertValidConfig(config: ZohoAccountsServiceConfig): void;
13
13
  }
14
+ /**
15
+ * Input configuration for {@link zohoAccountsServiceConfigFromConfigService}.
16
+ *
17
+ * Requires a NestJS `ConfigService` instance (typically populated from environment variables)
18
+ * and a `serviceAccessTokenKey` that identifies which Zoho service (e.g. `'crm'` or `'recruit'`)
19
+ * is being configured. The key is used to derive service-specific environment variable names.
20
+ */
14
21
  export type ZohoAccountsServiceConfigFromConfigServiceInput = ZohoConfigServiceReaderConfig;
22
+ /**
23
+ * Builds a {@link ZohoAccountsServiceConfig} by reading Zoho Accounts OAuth credentials
24
+ * from a NestJS `ConfigService` (typically backed by environment variables).
25
+ *
26
+ * ## Environment Variable Resolution
27
+ *
28
+ * For each credential, the function first looks for a **service-specific** environment variable
29
+ * (e.g. `ZOHO_CRM_ACCOUNTS_URL`), then falls back to the **shared** variable
30
+ * (e.g. `ZOHO_ACCOUNTS_URL`). The service prefix is derived from `serviceAccessTokenKey`
31
+ * uppercased (e.g. `'crm'` → `ZOHO_CRM_`, `'recruit'` → `ZOHO_RECRUIT_`).
32
+ *
33
+ * | Credential | Shared env var | Service-specific env var (example: CRM) |
34
+ * |------------------|-------------------------------|----------------------------------------------|
35
+ * | Accounts API URL | `ZOHO_ACCOUNTS_URL` | `ZOHO_CRM_ACCOUNTS_URL` |
36
+ * | Refresh Token | `ZOHO_ACCOUNTS_REFRESH_TOKEN` | `ZOHO_CRM_ACCOUNTS_REFRESH_TOKEN` |
37
+ * | Client ID | `ZOHO_ACCOUNTS_CLIENT_ID` | `ZOHO_CRM_ACCOUNTS_CLIENT_ID` |
38
+ * | Client Secret | `ZOHO_ACCOUNTS_CLIENT_SECRET` | `ZOHO_CRM_ACCOUNTS_CLIENT_SECRET` |
39
+ *
40
+ * When using Zoho Recruit, replace `CRM` with `RECRUIT` in the service-specific variable names.
41
+ *
42
+ * @param input - The {@link ZohoAccountsServiceConfigFromConfigServiceInput} containing the
43
+ * `ConfigService` and the `serviceAccessTokenKey` for the target Zoho service.
44
+ * @returns A validated {@link ZohoAccountsServiceConfig} ready for use with `ZohoAccountsApi`.
45
+ * @throws If any required credential (apiUrl, refreshToken, clientId) is missing.
46
+ */
15
47
  export declare function zohoAccountsServiceConfigFromConfigService(input: ZohoAccountsServiceConfigFromConfigServiceInput): ZohoAccountsServiceConfig;