@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.
- package/LICENSE +1 -1
- package/index.cjs.js +1763 -2531
- package/index.esm.js +1655 -2524
- package/nestjs/index.cjs.js +598 -0
- package/nestjs/index.esm.js +582 -0
- package/nestjs/package.json +19 -3
- package/nestjs/src/lib/accounts/accounts.config.d.ts +32 -0
- package/nestjs/src/lib/crm/crm.api.d.ts +43 -0
- package/nestjs/src/lib/crm/crm.config.d.ts +10 -0
- package/nestjs/src/lib/crm/crm.module.d.ts +24 -0
- package/nestjs/src/lib/crm/index.d.ts +3 -0
- package/nestjs/src/lib/recruit/recruit.api.d.ts +7 -7
- package/package.json +14 -7
- package/src/lib/accounts/accounts.api.d.ts +1 -1
- package/src/lib/accounts/accounts.error.api.d.ts +2 -2
- package/src/lib/crm/crm.api.d.ts +430 -0
- package/src/lib/crm/crm.api.notes.d.ts +40 -0
- package/src/lib/crm/crm.api.tags.d.ts +160 -0
- package/src/lib/crm/crm.config.d.ts +24 -0
- package/src/lib/crm/crm.criteria.d.ts +19 -0
- package/src/lib/crm/crm.d.ts +325 -0
- package/src/lib/crm/crm.error.api.d.ts +52 -0
- package/src/lib/crm/crm.factory.d.ts +22 -0
- package/src/lib/crm/crm.notes.d.ts +48 -0
- package/src/lib/crm/crm.tags.d.ts +40 -0
- package/src/lib/crm/index.d.ts +10 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/recruit/index.d.ts +0 -1
- package/src/lib/recruit/recruit.api.candidates.d.ts +6 -6
- package/src/lib/recruit/recruit.api.d.ts +102 -22
- package/src/lib/recruit/recruit.api.notes.d.ts +30 -6
- package/src/lib/recruit/recruit.api.tags.d.ts +30 -6
- package/src/lib/recruit/recruit.criteria.d.ts +8 -44
- package/src/lib/recruit/recruit.d.ts +7 -3
- package/src/lib/recruit/recruit.error.api.d.ts +7 -3
- package/src/lib/shared/criteria.d.ts +55 -0
- package/src/lib/shared/criteria.util.d.ts +10 -0
- package/src/lib/zoho.error.api.d.ts +64 -6
- package/src/lib/zoho.type.d.ts +1 -18
- package/nestjs/CHANGELOG.md +0 -459
- package/nestjs/README.md +0 -11
- package/nestjs/src/index.js +0 -5
- package/nestjs/src/index.js.map +0 -1
- package/nestjs/src/lib/accounts/accounts.api.js +0 -37
- package/nestjs/src/lib/accounts/accounts.api.js.map +0 -1
- package/nestjs/src/lib/accounts/accounts.config.js +0 -50
- package/nestjs/src/lib/accounts/accounts.config.js.map +0 -1
- package/nestjs/src/lib/accounts/accounts.service.js +0 -240
- package/nestjs/src/lib/accounts/accounts.service.js.map +0 -1
- package/nestjs/src/lib/accounts/index.js +0 -7
- package/nestjs/src/lib/accounts/index.js.map +0 -1
- package/nestjs/src/lib/index.js +0 -7
- package/nestjs/src/lib/index.js.map +0 -1
- package/nestjs/src/lib/recruit/index.js +0 -7
- package/nestjs/src/lib/recruit/index.js.map +0 -1
- package/nestjs/src/lib/recruit/recruit.api.js +0 -130
- package/nestjs/src/lib/recruit/recruit.api.js.map +0 -1
- package/nestjs/src/lib/recruit/recruit.config.js +0 -16
- package/nestjs/src/lib/recruit/recruit.config.js.map +0 -1
- package/nestjs/src/lib/recruit/recruit.module.js +0 -61
- package/nestjs/src/lib/recruit/recruit.module.js.map +0 -1
- package/nestjs/src/lib/zoho.config.js +0 -52
- package/nestjs/src/lib/zoho.config.js.map +0 -1
- package/src/lib/recruit/recruit.criteria.util.d.ts +0 -10
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
- /package/{index.esm.d.ts → nestjs/index.d.ts} +0 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var common = require('@nestjs/common');
|
|
4
|
+
var zoho = require('@dereekb/zoho');
|
|
5
|
+
var util = require('@dereekb/util');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var fs = require('fs');
|
|
8
|
+
var config = require('@nestjs/config');
|
|
9
|
+
|
|
10
|
+
/******************************************************************************
|
|
11
|
+
Copyright (c) Microsoft Corporation.
|
|
12
|
+
|
|
13
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
14
|
+
purpose with or without fee is hereby granted.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
18
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
20
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
22
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
+
***************************************************************************** */
|
|
24
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function __decorate(decorators, target, key, desc) {
|
|
28
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
30
|
+
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;
|
|
31
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function __param(paramIndex, decorator) {
|
|
35
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function __metadata(metadataKey, metadataValue) {
|
|
39
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
+
var e = new Error(message);
|
|
44
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const ZOHO_API_URL_CONFIG_KEY = 'API_URL';
|
|
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
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reads the ZohoConfig config from the ConfigService.
|
|
69
|
+
*
|
|
70
|
+
* @param configService
|
|
71
|
+
* @param prefix
|
|
72
|
+
*/
|
|
73
|
+
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}".`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return config;
|
|
85
|
+
}
|
|
86
|
+
function assertValidZohoConfig(config) {
|
|
87
|
+
if (!config.apiUrl) {
|
|
88
|
+
throw new Error(`No Zoho API url or type specified.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Configuration for ZohoService
|
|
94
|
+
*/
|
|
95
|
+
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
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Builds a {@link ZohoAccountsServiceConfig} by reading Zoho Accounts OAuth credentials
|
|
119
|
+
* from a NestJS `ConfigService` (typically backed by environment variables).
|
|
120
|
+
*
|
|
121
|
+
* ## Environment Variable Resolution
|
|
122
|
+
*
|
|
123
|
+
* For each credential, the function first looks for a **service-specific** environment variable
|
|
124
|
+
* (e.g. `ZOHO_CRM_ACCOUNTS_URL`), then falls back to the **shared** variable
|
|
125
|
+
* (e.g. `ZOHO_ACCOUNTS_URL`). The service prefix is derived from `serviceAccessTokenKey`
|
|
126
|
+
* uppercased (e.g. `'crm'` → `ZOHO_CRM_`, `'recruit'` → `ZOHO_RECRUIT_`).
|
|
127
|
+
*
|
|
128
|
+
* | Credential | Shared env var | Service-specific env var (example: CRM) |
|
|
129
|
+
* |------------------|-------------------------------|----------------------------------------------|
|
|
130
|
+
* | Accounts API URL | `ZOHO_ACCOUNTS_URL` | `ZOHO_CRM_ACCOUNTS_URL` |
|
|
131
|
+
* | Refresh Token | `ZOHO_ACCOUNTS_REFRESH_TOKEN` | `ZOHO_CRM_ACCOUNTS_REFRESH_TOKEN` |
|
|
132
|
+
* | Client ID | `ZOHO_ACCOUNTS_CLIENT_ID` | `ZOHO_CRM_ACCOUNTS_CLIENT_ID` |
|
|
133
|
+
* | Client Secret | `ZOHO_ACCOUNTS_CLIENT_SECRET` | `ZOHO_CRM_ACCOUNTS_CLIENT_SECRET` |
|
|
134
|
+
*
|
|
135
|
+
* When using Zoho Recruit, replace `CRM` with `RECRUIT` in the service-specific variable names.
|
|
136
|
+
*
|
|
137
|
+
* @param input - The {@link ZohoAccountsServiceConfigFromConfigServiceInput} containing the
|
|
138
|
+
* `ConfigService` and the `serviceAccessTokenKey` for the target Zoho service.
|
|
139
|
+
* @returns A validated {@link ZohoAccountsServiceConfig} ready for use with `ZohoAccountsApi`.
|
|
140
|
+
* @throws If any required credential (apiUrl, refreshToken, clientId) is missing.
|
|
141
|
+
*/
|
|
142
|
+
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;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Service used for retrieving ZohoAccessTokenCache for Zoho services.
|
|
166
|
+
*/
|
|
167
|
+
exports.ZohoAccountsAccessTokenCacheService = class ZohoAccountsAccessTokenCacheService {};
|
|
168
|
+
exports.ZohoAccountsAccessTokenCacheService = __decorate([common.Injectable()], exports.ZohoAccountsAccessTokenCacheService);
|
|
169
|
+
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
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Merges the input services in order to use some as a backup source.
|
|
177
|
+
*
|
|
178
|
+
* If once source fails retrieval, the next will be tried.
|
|
179
|
+
*
|
|
180
|
+
* When updating a cached token, it will update the token across all services.
|
|
181
|
+
*
|
|
182
|
+
* @param servicesToMerge Must include atleast one service. Empty arrays will throw an error.
|
|
183
|
+
*/
|
|
184
|
+
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;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return service;
|
|
229
|
+
}
|
|
230
|
+
// MARK: Memory Access Token Cache
|
|
231
|
+
/**
|
|
232
|
+
* Creates a ZohoAccountsAccessTokenCacheService that uses in-memory storage.
|
|
233
|
+
*
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
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
|
+
}
|
|
267
|
+
};
|
|
268
|
+
return accessTokenCache;
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
loadZohoAccessTokenCache
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// MARK: File System Access Token Cache
|
|
275
|
+
const DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoho-access-tokens.json';
|
|
276
|
+
/**
|
|
277
|
+
* Creates a ZohoAccountsAccessTokenCacheService that reads and writes the access token to the file system.
|
|
278
|
+
*
|
|
279
|
+
* Useful for testing.
|
|
280
|
+
*
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
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);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
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
|
|
321
|
+
};
|
|
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
|
+
}
|
|
375
|
+
};
|
|
376
|
+
return accessTokenCache;
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
loadZohoAccessTokenCache,
|
|
380
|
+
readTokenFile,
|
|
381
|
+
writeTokenFile,
|
|
382
|
+
deleteTokenFile
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
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
|
+
}
|
|
406
|
+
};
|
|
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);
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Configuration for ZohoRecruitService
|
|
411
|
+
*/
|
|
412
|
+
class ZohoRecruitServiceConfig {
|
|
413
|
+
zohoRecruit;
|
|
414
|
+
factoryConfig;
|
|
415
|
+
static assertValidConfig(config) {
|
|
416
|
+
assertValidZohoConfig(config.zohoRecruit);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
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
|
+
}
|
|
532
|
+
};
|
|
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);
|
|
534
|
+
|
|
535
|
+
// MARK: Provider Factories
|
|
536
|
+
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;
|
|
545
|
+
}
|
|
546
|
+
function zohoRecruitAccountServiceConfigFactory(configService) {
|
|
547
|
+
return zohoAccountsServiceConfigFromConfigService({
|
|
548
|
+
configService,
|
|
549
|
+
serviceAccessTokenKey: zoho.ZOHO_RECRUIT_SERVICE_NAME
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Convenience function used to generate ModuleMetadata for an app's ZohoRecruitModule.
|
|
554
|
+
*
|
|
555
|
+
* @param provide
|
|
556
|
+
* @param useFactory
|
|
557
|
+
* @returns
|
|
558
|
+
*/
|
|
559
|
+
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
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
exports.DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = DEFAULT_FILE_ZOHO_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH;
|
|
585
|
+
exports.ZOHO_API_URL_CONFIG_KEY = ZOHO_API_URL_CONFIG_KEY;
|
|
586
|
+
exports.ZohoAccountsServiceConfig = ZohoAccountsServiceConfig;
|
|
587
|
+
exports.ZohoRecruitServiceConfig = ZohoRecruitServiceConfig;
|
|
588
|
+
exports.appZohoRecruitModuleMetadata = appZohoRecruitModuleMetadata;
|
|
589
|
+
exports.assertValidZohoConfig = assertValidZohoConfig;
|
|
590
|
+
exports.fileZohoAccountsAccessTokenCacheService = fileZohoAccountsAccessTokenCacheService;
|
|
591
|
+
exports.logMergeZohoAccountsAccessTokenCacheServiceErrorFunction = logMergeZohoAccountsAccessTokenCacheServiceErrorFunction;
|
|
592
|
+
exports.memoryZohoAccountsAccessTokenCacheService = memoryZohoAccountsAccessTokenCacheService;
|
|
593
|
+
exports.mergeZohoAccountsAccessTokenCacheServices = mergeZohoAccountsAccessTokenCacheServices;
|
|
594
|
+
exports.readZohoConfigFromConfigService = readZohoConfigFromConfigService;
|
|
595
|
+
exports.zohoAccountsServiceConfigFromConfigService = zohoAccountsServiceConfigFromConfigService;
|
|
596
|
+
exports.zohoConfigServiceReaderFunction = zohoConfigServiceReaderFunction;
|
|
597
|
+
exports.zohoRecruitAccountServiceConfigFactory = zohoRecruitAccountServiceConfigFactory;
|
|
598
|
+
exports.zohoRecruitServiceConfigFactory = zohoRecruitServiceConfigFactory;
|