@dereekb/zoho 10.2.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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/index.cjs.d.ts +1 -0
  4. package/index.cjs.js +3353 -0
  5. package/index.esm.js +4396 -0
  6. package/nestjs/CHANGELOG.md +16 -0
  7. package/nestjs/README.md +11 -0
  8. package/nestjs/package.json +6 -0
  9. package/nestjs/src/index.d.ts +1 -0
  10. package/nestjs/src/index.js +5 -0
  11. package/nestjs/src/index.js.map +1 -0
  12. package/nestjs/src/lib/accounts/accounts.api.d.ts +11 -0
  13. package/nestjs/src/lib/accounts/accounts.api.js +33 -0
  14. package/nestjs/src/lib/accounts/accounts.api.js.map +1 -0
  15. package/nestjs/src/lib/accounts/accounts.config.d.ts +15 -0
  16. package/nestjs/src/lib/accounts/accounts.config.js +48 -0
  17. package/nestjs/src/lib/accounts/accounts.config.js.map +1 -0
  18. package/nestjs/src/lib/accounts/accounts.service.d.ts +34 -0
  19. package/nestjs/src/lib/accounts/accounts.service.js +152 -0
  20. package/nestjs/src/lib/accounts/accounts.service.js.map +1 -0
  21. package/nestjs/src/lib/accounts/index.d.ts +3 -0
  22. package/nestjs/src/lib/accounts/index.js +7 -0
  23. package/nestjs/src/lib/accounts/index.js.map +1 -0
  24. package/nestjs/src/lib/index.d.ts +3 -0
  25. package/nestjs/src/lib/index.js +7 -0
  26. package/nestjs/src/lib/index.js.map +1 -0
  27. package/nestjs/src/lib/recruit/index.d.ts +3 -0
  28. package/nestjs/src/lib/recruit/index.js +7 -0
  29. package/nestjs/src/lib/recruit/index.js.map +1 -0
  30. package/nestjs/src/lib/recruit/recruit.api.d.ts +16 -0
  31. package/nestjs/src/lib/recruit/recruit.api.js +47 -0
  32. package/nestjs/src/lib/recruit/recruit.api.js.map +1 -0
  33. package/nestjs/src/lib/recruit/recruit.config.d.ts +10 -0
  34. package/nestjs/src/lib/recruit/recruit.config.js +14 -0
  35. package/nestjs/src/lib/recruit/recruit.config.js.map +1 -0
  36. package/nestjs/src/lib/recruit/recruit.module.d.ts +7 -0
  37. package/nestjs/src/lib/recruit/recruit.module.js +54 -0
  38. package/nestjs/src/lib/recruit/recruit.module.js.map +1 -0
  39. package/nestjs/src/lib/zoho.config.d.ts +27 -0
  40. package/nestjs/src/lib/zoho.config.js +52 -0
  41. package/nestjs/src/lib/zoho.config.js.map +1 -0
  42. package/package.json +30 -0
  43. package/src/index.d.ts +1 -0
  44. package/src/lib/accounts/accounts.api.d.ts +27 -0
  45. package/src/lib/accounts/accounts.config.d.ts +45 -0
  46. package/src/lib/accounts/accounts.d.ts +75 -0
  47. package/src/lib/accounts/accounts.error.api.d.ts +28 -0
  48. package/src/lib/accounts/accounts.factory.d.ts +34 -0
  49. package/src/lib/accounts/index.d.ts +5 -0
  50. package/src/lib/index.d.ts +6 -0
  51. package/src/lib/recruit/index.d.ts +5 -0
  52. package/src/lib/recruit/recruit.api.d.ts +144 -0
  53. package/src/lib/recruit/recruit.config.d.ts +23 -0
  54. package/src/lib/recruit/recruit.d.ts +108 -0
  55. package/src/lib/recruit/recruit.error.api.d.ts +29 -0
  56. package/src/lib/recruit/recruit.factory.d.ts +16 -0
  57. package/src/lib/zoho.api.page.d.ts +37 -0
  58. package/src/lib/zoho.config.d.ts +35 -0
  59. package/src/lib/zoho.error.api.d.ts +145 -0
  60. package/src/lib/zoho.type.d.ts +20 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertValidZohoConfig = exports.readZohoConfigFromConfigService = exports.zohoConfigServiceReaderFunction = exports.ZOHO_API_URL_CONFIG_KEY = void 0;
4
+ exports.ZOHO_API_URL_CONFIG_KEY = 'API_URL';
5
+ function zohoConfigServiceReaderFunction(inputOrKey, inputConfigService) {
6
+ let configService;
7
+ let serviceAccessTokenKey;
8
+ if (typeof inputOrKey === 'string') {
9
+ serviceAccessTokenKey = inputOrKey;
10
+ configService = inputConfigService;
11
+ }
12
+ else {
13
+ configService = inputOrKey.configService;
14
+ serviceAccessTokenKey = inputOrKey.serviceAccessTokenKey;
15
+ }
16
+ const baseServicePrefix = 'ZOHO_';
17
+ const servicePrefix = serviceAccessTokenKey.toUpperCase(); // "RECRUIT"
18
+ const servicePrefixString = `${baseServicePrefix}${servicePrefix}_`; // "ZOHO_RECRUIT_"
19
+ return (key) => {
20
+ const baseConfigKey = `${baseServicePrefix}${key}`; // "ZOHO_ACCOUNTS_URL"
21
+ const serviceSpecificConfigKey = `${servicePrefixString}${key}`; // "ZOHO_RECRUIT_ACCOUNTS_URL"
22
+ return configService.get(serviceSpecificConfigKey) ?? configService.get(baseConfigKey);
23
+ };
24
+ }
25
+ exports.zohoConfigServiceReaderFunction = zohoConfigServiceReaderFunction;
26
+ /**
27
+ * Reads the ZohoConfig config from the ConfigService.
28
+ *
29
+ * @param configService
30
+ * @param prefix
31
+ */
32
+ function readZohoConfigFromConfigService(configService, servicePrefix, assertValid = true) {
33
+ const servicePrefixString = servicePrefix ? `${servicePrefix}_` : '';
34
+ const apiUrlConfigKey = `${servicePrefixString}${exports.ZOHO_API_URL_CONFIG_KEY}`;
35
+ const config = {
36
+ apiUrl: configService.get(apiUrlConfigKey) ?? configService.get(exports.ZOHO_API_URL_CONFIG_KEY)
37
+ };
38
+ if (assertValid) {
39
+ if (!config.apiUrl) {
40
+ throw new Error(`No Zoho API url or type specified for key "${apiUrlConfigKey}".`);
41
+ }
42
+ }
43
+ return config;
44
+ }
45
+ exports.readZohoConfigFromConfigService = readZohoConfigFromConfigService;
46
+ function assertValidZohoConfig(config) {
47
+ if (!config.apiUrl) {
48
+ throw new Error(`No Zoho API url or type specified.`);
49
+ }
50
+ }
51
+ exports.assertValidZohoConfig = assertValidZohoConfig;
52
+ //# sourceMappingURL=zoho.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zoho.config.js","sourceRoot":"","sources":["../../../../../../packages/zoho/nestjs/src/lib/zoho.config.ts"],"names":[],"mappings":";;;AAGa,QAAA,uBAAuB,GAAG,SAAS,CAAC;AAoBjD,SAAgB,+BAA+B,CAAC,UAAqE,EAAE,kBAAkC;IACvJ,IAAI,aAA4B,CAAC;IACjC,IAAI,qBAAgD,CAAC;IAErD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,qBAAqB,GAAG,UAAU,CAAC;QACnC,aAAa,GAAG,kBAAmB,CAAC;KACrC;SAAM;QACL,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC;QACzC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,CAAC;KAC1D;IAED,MAAM,iBAAiB,GAAG,OAAO,CAAC;IAClC,MAAM,aAAa,GAAG,qBAAqB,CAAC,WAAW,EAAE,CAAC,CAAC,YAAY;IACvE,MAAM,mBAAmB,GAAG,GAAG,iBAAiB,GAAG,aAAa,GAAG,CAAC,CAAC,kBAAkB;IAEvF,OAAO,CAAC,GAAW,EAAU,EAAE;QAC7B,MAAM,aAAa,GAAG,GAAG,iBAAiB,GAAG,GAAG,EAAE,CAAC,CAAC,sBAAsB;QAC1E,MAAM,wBAAwB,GAAG,GAAG,mBAAmB,GAAG,GAAG,EAAE,CAAC,CAAC,8BAA8B;QAC/F,OAAO,aAAa,CAAC,GAAG,CAAS,wBAAwB,CAAC,IAAK,aAAa,CAAC,GAAG,CAAS,aAAa,CAAY,CAAC;IACrH,CAAC,CAAC;AACJ,CAAC;AArBD,0EAqBC;AAED;;;;;GAKG;AACH,SAAgB,+BAA+B,CAAC,aAA4B,EAAE,aAAsB,EAAE,WAAW,GAAG,IAAI;IACtH,MAAM,mBAAmB,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,MAAM,eAAe,GAAG,GAAG,mBAAmB,GAAG,+BAAuB,EAAE,CAAC;IAE3E,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,aAAa,CAAC,GAAG,CAAS,eAAe,CAAC,IAAK,aAAa,CAAC,GAAG,CAAS,+BAAuB,CAAY;KACrH,CAAC;IAEF,IAAI,WAAW,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,8CAA8C,eAAe,IAAI,CAAC,CAAC;SACpF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAfD,0EAeC;AAED,SAAgB,qBAAqB,CAAC,MAAkB;IACtD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;KACvD;AACH,CAAC;AAJD,sDAIC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@dereekb/zoho",
3
+ "version": "10.2.0",
4
+ "exports": {
5
+ ".": {
6
+ "types": "./src/index.d.ts",
7
+ "node": {
8
+ "require": "./index.cjs.js",
9
+ "import": "./index.mjs"
10
+ },
11
+ "browser": {
12
+ "require": "./index.cjs.js",
13
+ "import": "./index.esm.js"
14
+ },
15
+ "default": "./index.cjs.js"
16
+ },
17
+ "./nestjs": {
18
+ "types": "./nestjs/src/index.d.ts",
19
+ "main": "./nestjs/src/index.js",
20
+ "require": "./nestjs/src/index.js",
21
+ "default": "./nestjs/src/index.js"
22
+ }
23
+ },
24
+ "peerDependencies": {
25
+ "@dereekb/util": "*",
26
+ "make-error": "^1.3.0"
27
+ },
28
+ "module": "./index.esm.js",
29
+ "main": "./index.cjs.js"
30
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib';
@@ -0,0 +1,27 @@
1
+ import { FetchJsonBody, FetchJsonInput } from '@dereekb/util/fetch';
2
+ import { ZohoAccountsContext } from './accounts.config';
3
+ import { ZohoAuthClientIdAndSecretPair, ZohoRefreshToken } from '../zoho.config';
4
+ import { ZohoAccessTokenApiDomain, ZohoAccessTokenScopesString, ZohoAccessTokenString } from './accounts';
5
+ import { Maybe, Seconds } from '@dereekb/util';
6
+ import { ZohoAccountsAccessTokenErrorCode } from './accounts.error.api';
7
+ export interface ZohoAccountsAccessTokenInput {
8
+ readonly client?: Maybe<ZohoAuthClientIdAndSecretPair>;
9
+ readonly refreshToken?: Maybe<ZohoRefreshToken>;
10
+ }
11
+ export interface ZohoAccountsAccessTokenResponse {
12
+ access_token: ZohoAccessTokenString;
13
+ scope: ZohoAccessTokenScopesString;
14
+ api_domain: ZohoAccessTokenApiDomain;
15
+ token_type: 'Bearer';
16
+ expires_in: Seconds;
17
+ }
18
+ export interface ZohoAccountsAccessTokenErrorResponse {
19
+ error: ZohoAccountsAccessTokenErrorCode;
20
+ }
21
+ /**
22
+ * Trades a refresh token for a new AccessToken
23
+ * @param context
24
+ * @returns
25
+ */
26
+ export declare function accessToken(context: ZohoAccountsContext): (input?: ZohoAccountsAccessTokenInput) => Promise<ZohoAccountsAccessTokenResponse>;
27
+ export declare function zohoAccountsApiFetchJsonInput(method: string, body?: FetchJsonBody): FetchJsonInput;
@@ -0,0 +1,45 @@
1
+ import { FactoryWithRequiredInput, Maybe } from '@dereekb/util';
2
+ import { ConfiguredFetch, FetchJsonFunction } from '@dereekb/util/fetch';
3
+ import { ZohoApiUrl, ZohoRefreshToken, ZohoConfig, ZohoAuthClientIdAndSecretPair } from '../zoho.config';
4
+ import { ZohoAccessTokenCache, ZohoAccessTokenFactory } from './accounts';
5
+ /**
6
+ * The Zoho Accounts API URL for the US datacenter.
7
+ */
8
+ export declare const ZOHO_ACCOUNTS_US_API_URL = "https://accounts.zoho.com";
9
+ /**
10
+ * Url for the Zoho Accounts API.
11
+ *
12
+ * You can find a list here of Account URLs here:
13
+ *
14
+ * https://help.zoho.com/portal/en/kb/creator/developer-guide/others/url-patterns/articles/know-your-creator-account-s-base-url
15
+ */
16
+ export type ZohoAccountsApiUrl = ZohoApiUrl;
17
+ export type ZohoAccountsApiUrlKey = 'us';
18
+ export type ZohoAccountsConfigApiUrlInput = ZohoAccountsApiUrlKey | ZohoAccountsApiUrl;
19
+ export declare function zohoAccountsConfigApiUrl(input: ZohoAccountsConfigApiUrlInput): ZohoApiUrl;
20
+ /**
21
+ * Configuration for ZohoAccounts.
22
+ */
23
+ export interface ZohoAccountsConfig extends ZohoConfig, ZohoAuthClientIdAndSecretPair {
24
+ /**
25
+ * Refresh token used for generaing new ZohoAccessToken values.
26
+ */
27
+ readonly refreshToken: ZohoRefreshToken;
28
+ /**
29
+ * Optional ZohoAccessTokenCache for caching access tokens.
30
+ */
31
+ readonly accessTokenCache?: Maybe<ZohoAccessTokenCache>;
32
+ }
33
+ export interface ZohoAccountsFetchFactoryInput {
34
+ readonly apiUrl: ZohoApiUrl;
35
+ }
36
+ export type ZohoAccountsFetchFactory = FactoryWithRequiredInput<ConfiguredFetch, ZohoAccountsFetchFactoryInput>;
37
+ export interface ZohoAccountsContext {
38
+ readonly fetch: ConfiguredFetch;
39
+ readonly fetchJson: FetchJsonFunction;
40
+ readonly loadAccessToken: ZohoAccessTokenFactory;
41
+ readonly config: ZohoAccountsConfig;
42
+ }
43
+ export interface ZohoAccountsContextRef {
44
+ readonly accountsContext: ZohoAccountsContext;
45
+ }
@@ -0,0 +1,75 @@
1
+ import { Maybe } from '@dereekb/util';
2
+ import { ZohoApiServiceName } from '../zoho.config';
3
+ /**
4
+ * Arbitrary key used to identify a specific service's access token. Typically coincides with the ZohoApiServiceName.
5
+ *
6
+ * I.E. recruit
7
+ */
8
+ export type ZohoServiceAccessTokenKey = ZohoApiServiceName | string;
9
+ /**
10
+ * Access token authorization string generated from a refresh token.
11
+ */
12
+ export type ZohoAccessTokenString = string;
13
+ /**
14
+ * Scopes string for a ZohoAccessToken
15
+ *
16
+ * Example: "ZohoRecruit.modules.ALL"
17
+ */
18
+ export type ZohoAccessTokenScopesString = string;
19
+ /**
20
+ * Api domain string for a ZohoAccessToken
21
+ *
22
+ * Example: "https://www.zohoapis.com"
23
+ */
24
+ export type ZohoAccessTokenApiDomain = string;
25
+ /**
26
+ * Zoho account access token.
27
+ */
28
+ export interface ZohoAccessToken {
29
+ readonly accessToken: ZohoAccessTokenString;
30
+ readonly scope: ZohoAccessTokenScopesString;
31
+ readonly apiDomain: ZohoAccessTokenApiDomain;
32
+ /**
33
+ * Length of time the token is valid for.
34
+ */
35
+ readonly expiresIn: number;
36
+ /**
37
+ * Date the token expires at.
38
+ */
39
+ readonly expiresAt: Date;
40
+ }
41
+ /**
42
+ * Used for retrieving and storing ZohoAccessToken values.
43
+ */
44
+ export interface ZohoAccessTokenCache {
45
+ /**
46
+ * Loads the token from the cache, if available.
47
+ *
48
+ * The token may be expired.
49
+ */
50
+ loadCachedToken(): Promise<Maybe<ZohoAccessToken>>;
51
+ /**
52
+ * Updates the cache with the given access token.
53
+ */
54
+ updateCachedToken(accessToken: ZohoAccessToken): Promise<void>;
55
+ }
56
+ /**
57
+ * Source for retriving a ZohoAccessToken.
58
+ *
59
+ * Throws an ZohoAccountsAuthRetrievalError error if the token could not be retrieved.
60
+ */
61
+ export type ZohoAccessTokenFactory = () => Promise<ZohoAccessToken>;
62
+ /**
63
+ * A ZohoAccessTokenFactory that always generates a new ZohoAccessToken.
64
+ */
65
+ export type ZohoAccessTokenRefresher = ZohoAccessTokenFactory;
66
+ /**
67
+ * Source for retriving a ZohoAccessToken string.
68
+ *
69
+ * Throws an ZohoAccountsAuthRetrievalError error if the token could not be retrieved.
70
+ */
71
+ export type ZohoAccessTokenStringFactory = () => Promise<ZohoAccessTokenString>;
72
+ /**
73
+ * Generates a new ZohoAccessTokenStringFactory.
74
+ */
75
+ export declare function zohoAccessTokenStringFactory(zohoAccessTokenFactory: ZohoAccessTokenFactory): ZohoAccessTokenStringFactory;
@@ -0,0 +1,28 @@
1
+ import { FetchRequestFactoryError, FetchResponseError } from '@dereekb/util/fetch';
2
+ import { ZohoServerErrorResponseData, ParsedZohoServerError } from '../zoho.error.api';
3
+ /**
4
+ * Error in the following cases:
5
+ * - the refresh token string is invalid
6
+ */
7
+ export declare const ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE = "invalid_code";
8
+ export declare const ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE = "invalid_client";
9
+ export type ZohoAccountsAccessTokenErrorCode = typeof ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE | typeof ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE;
10
+ /**
11
+ * Thrown if the call to the Zoho API creating an access token using a refresh token fails.
12
+ */
13
+ export declare class ZohoAccountsAccessTokenError extends FetchRequestFactoryError {
14
+ readonly errorCode: ZohoAccountsAccessTokenErrorCode;
15
+ constructor(errorCode: ZohoAccountsAccessTokenErrorCode);
16
+ }
17
+ /**
18
+ * Thrown if a valid ZohoAccessToken cannot be retrieved successfully.
19
+ */
20
+ export declare class ZohoAccountsAuthFailureError extends FetchRequestFactoryError {
21
+ readonly reason?: string | undefined;
22
+ constructor(reason?: string | undefined);
23
+ }
24
+ export declare const logZohoAccountsErrorToConsole: import("../zoho.error.api").LogZohoServerErrorFunction;
25
+ export declare function parseZohoAccountsError(responseError: FetchResponseError): Promise<ParsedZohoServerError>;
26
+ export declare function parseZohoAccountsServerErrorResponseData(errorResponseData: ZohoServerErrorResponseData, responseError: FetchResponseError): ParsedZohoServerError;
27
+ export declare const interceptZohoAccountsErrorResponse: import("@dereekb/util/fetch").FetchJsonInterceptJsonResponseFunction;
28
+ export declare const handleZohoAccountsErrorFetch: import("../zoho.error.api").HandleZohoErrorFetchFactory;
@@ -0,0 +1,34 @@
1
+ import { ZohoAccountsConfig, ZohoAccountsContextRef, ZohoAccountsFetchFactory } from './accounts.config';
2
+ import { LogZohoServerErrorFunction } from '../zoho.error.api';
3
+ import { ZohoAccessTokenCache, ZohoAccessTokenFactory, ZohoAccessTokenRefresher } from './accounts';
4
+ import { Maybe, Milliseconds } from '@dereekb/util';
5
+ export type ZohoAccounts = ZohoAccountsContextRef;
6
+ export interface ZohoAccountsFactoryConfig {
7
+ /**
8
+ * Creates a new fetch instance to use when making calls.
9
+ */
10
+ fetchFactory?: ZohoAccountsFetchFactory;
11
+ /**
12
+ * Custom log error function.
13
+ */
14
+ logZohoServerErrorFunction?: LogZohoServerErrorFunction;
15
+ }
16
+ export type ZohoAccountsFactory = (config: ZohoAccountsConfig) => ZohoAccounts;
17
+ export declare function zohoAccountsFactory(factoryConfig: ZohoAccountsFactoryConfig): ZohoAccountsFactory;
18
+ export interface ZohoAccountsZohoAccessTokenFactoryConfig {
19
+ /**
20
+ * Number of milliseconds before the expiration time a token should be discarded.
21
+ *
22
+ * Defaults to 1 minute.
23
+ */
24
+ readonly tokenExpirationBuffer?: Milliseconds;
25
+ readonly tokenRefresher: ZohoAccessTokenRefresher;
26
+ readonly accessTokenCache?: Maybe<ZohoAccessTokenCache>;
27
+ }
28
+ /**
29
+ * Creates a ZohoAccountsZohoAccessTokenFactoryConfig
30
+ *
31
+ * @param config
32
+ * @returns
33
+ */
34
+ export declare function zohoAccountsZohoAccessTokenFactory(config: ZohoAccountsZohoAccessTokenFactoryConfig): ZohoAccessTokenFactory;
@@ -0,0 +1,5 @@
1
+ export * from './accounts';
2
+ export * from './accounts.api';
3
+ export * from './accounts.config';
4
+ export * from './accounts.error.api';
5
+ export * from './accounts.factory';
@@ -0,0 +1,6 @@
1
+ export * from './recruit';
2
+ export * from './accounts';
3
+ export * from './zoho.error.api';
4
+ export * from './zoho.api.page';
5
+ export * from './zoho.config';
6
+ export * from './zoho.type';
@@ -0,0 +1,5 @@
1
+ export * from './recruit.api';
2
+ export * from './recruit.config';
3
+ export * from './recruit.error.api';
4
+ export * from './recruit.factory';
5
+ export * from './recruit';
@@ -0,0 +1,144 @@
1
+ import { ZohoDataArrayResultRef, ZohoPageResult } from './../zoho.api.page';
2
+ import { FetchJsonBody, FetchJsonInput } from '@dereekb/util/fetch';
3
+ import { ZohoRecruitContext } from './recruit.config';
4
+ import { NewZohoRecruitRecordData, UpdateZohoRecruitRecordData, ZohoRecruitCommaSeparateFieldNames, ZohoRecruitCustomViewId, ZohoRecruitDraftOrSaveState, ZohoRecruitFieldName, ZohoRecruitModuleName, ZohoRecruitRecord, ZohoRecruitRecordFieldsData, ZohoRecruitRecordId, ZohoRecruitRecordUpdateDetails, ZohoRecruitSearchRecordsCriteriaTreeElement, ZohoRecruitTerritoryId, ZohoRecruitTrueFalseBoth } from './recruit';
5
+ import { EmailAddress, Maybe, PhoneNumber, SortingOrder } from '@dereekb/util';
6
+ import { ZohoServerErrorDataWithDetails, ZohoServerErrorStatus, ZohoServerSuccessCode, ZohoServerSuccessStatus } from '../zoho.error.api';
7
+ export interface ZohoRecruitModuleNameRef {
8
+ readonly module: ZohoRecruitModuleName;
9
+ }
10
+ export type ZohoRecruitUpdateRecordResult<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> = ZohoRecruitMultiRecordResult<RECORD_INPUT_TYPE, ZohoRecruitUpdateRecordResponseSuccessEntry, ZohoRecruitUpdateRecordResponseErrorEntry>;
11
+ export type ZohoRecruitUpdateRecordResponse = ZohoDataArrayResultRef<ZohoRecruitUpdateRecordResponseEntry>;
12
+ export type ZohoRecruitUpdateRecordResponseEntry = ZohoRecruitUpdateRecordResponseSuccessEntry | ZohoRecruitUpdateRecordResponseErrorEntry;
13
+ export interface ZohoRecruitUpdateRecordResponseSuccessEntry {
14
+ readonly code: ZohoServerSuccessCode;
15
+ readonly details: ZohoRecruitRecordUpdateDetails;
16
+ readonly status: ZohoServerSuccessStatus;
17
+ readonly message: string;
18
+ }
19
+ export interface ZohoRecruitUpdateRecordResponseErrorEntry extends ZohoServerErrorDataWithDetails {
20
+ readonly status: ZohoServerErrorStatus;
21
+ }
22
+ export type ZohoRecruitUpdateRecordInput<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> = ZohoRecruitUpdateSingleRecordInput<RECORD_INPUT_TYPE> | ZohoRecruitUpdateMultiRecordInput<RECORD_INPUT_TYPE>;
23
+ export interface ZohoRecruitUpdateSingleRecordInput<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> extends ZohoRecruitModuleNameRef {
24
+ readonly data: RECORD_INPUT_TYPE;
25
+ }
26
+ export interface ZohoRecruitUpdateMultiRecordInput<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> extends ZohoRecruitModuleNameRef {
27
+ readonly data: RECORD_INPUT_TYPE[];
28
+ }
29
+ export type ZohoRecruitUpdateRecordLikeFunction<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> = ZohoRecruitUpdateMultiRecordFunction<RECORD_INPUT_TYPE> & ZohoRecruitUpdateSingleRecordFunction<RECORD_INPUT_TYPE>;
30
+ export type ZohoRecruitUpdateSingleRecordFunction<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> = (input: ZohoRecruitUpdateSingleRecordInput<RECORD_INPUT_TYPE>) => Promise<ZohoRecruitRecordUpdateDetails>;
31
+ export type ZohoRecruitUpdateMultiRecordFunction<RECORD_INPUT_TYPE extends ZohoRecruitRecordFieldsData> = (input: ZohoRecruitUpdateMultiRecordInput<RECORD_INPUT_TYPE>) => Promise<ZohoRecruitUpdateRecordResult<RECORD_INPUT_TYPE>>;
32
+ export type ZohoRecruitInsertRecordFunction = ZohoRecruitUpdateRecordLikeFunction<NewZohoRecruitRecordData>;
33
+ /**
34
+ * Inserts one or more records into Recruit.
35
+ *
36
+ * https://www.zoho.com/recruit/developer-guide/apiv2/insert-records.html
37
+ *
38
+ * @param context
39
+ * @returns
40
+ */
41
+ export declare function insertRecord(context: ZohoRecruitContext): ZohoRecruitInsertRecordFunction;
42
+ export type ZohoRecruitUpsertRecordFunction = ZohoRecruitUpdateRecordLikeFunction<NewZohoRecruitRecordData | ZohoRecruitRecordFieldsData>;
43
+ /**
44
+ * Updates or inserts one or more records in Recruit.
45
+ *
46
+ * https://www.zoho.com/recruit/developer-guide/apiv2/upsert-records.html
47
+ *
48
+ * @param context
49
+ * @returns
50
+ */
51
+ export declare function upsertRecord(context: ZohoRecruitContext): ZohoRecruitUpsertRecordFunction;
52
+ export type ZohoRecruitUpdateRecordFunction = ZohoRecruitUpdateRecordLikeFunction<UpdateZohoRecruitRecordData>;
53
+ /**
54
+ * Updates one or more records in Recruit.
55
+ *
56
+ * https://www.zoho.com/recruit/developer-guide/apiv2/update-records.html
57
+ *
58
+ * @param context
59
+ * @returns
60
+ */
61
+ export declare function updateRecord(context: ZohoRecruitContext): ZohoRecruitUpdateRecordFunction;
62
+ export interface ZohoRecruitGetRecordByIdInput extends ZohoRecruitModuleNameRef {
63
+ readonly id: ZohoRecruitRecordId;
64
+ }
65
+ export type ZohoRecruitGetRecordByIdResponse = ZohoDataArrayResultRef<ZohoRecruitRecord>;
66
+ export type ZohoRecruitGetRecordByIdResult<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord> = T;
67
+ export type ZohoRecruitGetRecordByIdFunction = <T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord>(input: ZohoRecruitGetRecordByIdInput) => Promise<ZohoRecruitGetRecordByIdResult<T>>;
68
+ /**
69
+ * Retrieves a specific record from the given module.
70
+ *
71
+ * https://www.zoho.com/recruit/developer-guide/apiv2/get-records.html
72
+ *
73
+ * @param context
74
+ * @returns
75
+ */
76
+ export declare function getRecordById(context: ZohoRecruitContext): ZohoRecruitGetRecordByIdFunction;
77
+ export interface ZohoRecruitGetRecordsPageFilter {
78
+ readonly converted?: ZohoRecruitTrueFalseBoth;
79
+ readonly approved?: ZohoRecruitTrueFalseBoth;
80
+ readonly page?: number;
81
+ readonly per_page?: number;
82
+ }
83
+ export interface ZohoRecruitGetRecordsInput extends ZohoRecruitModuleNameRef, ZohoRecruitGetRecordsPageFilter {
84
+ readonly fields?: ZohoRecruitCommaSeparateFieldNames;
85
+ readonly sort_order?: SortingOrder;
86
+ readonly sort_by?: ZohoRecruitFieldName;
87
+ readonly cvid?: ZohoRecruitCustomViewId;
88
+ readonly territory_id?: ZohoRecruitTerritoryId;
89
+ readonly include_child?: boolean;
90
+ readonly $state?: ZohoRecruitDraftOrSaveState;
91
+ }
92
+ export type ZohoRecruitGetRecordsResponse<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord> = ZohoPageResult<T>;
93
+ export type ZohoRecruitGetRecordsFunction = <T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord>(input: ZohoRecruitGetRecordsInput) => Promise<ZohoRecruitGetRecordsResponse<T>>;
94
+ /**
95
+ * Retrieves records from the given module. Used for paginating across all records.
96
+ *
97
+ * https://www.zoho.com/recruit/developer-guide/apiv2/get-records.html
98
+ *
99
+ * @param context
100
+ * @returns
101
+ */
102
+ export declare function getRecords(context: ZohoRecruitContext): ZohoRecruitGetRecordsFunction;
103
+ /**
104
+ * Configuration for searching records.
105
+ *
106
+ * Only criteria, email, phone, or word will be used at a single time.
107
+ */
108
+ export interface ZohoRecruitSearchRecordsInput<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord> extends ZohoRecruitModuleNameRef, ZohoRecruitGetRecordsPageFilter {
109
+ readonly criteria?: Maybe<ZohoRecruitSearchRecordsCriteriaTreeElement<T>>;
110
+ readonly email?: Maybe<EmailAddress>;
111
+ readonly phone?: Maybe<PhoneNumber>;
112
+ readonly word?: Maybe<string>;
113
+ }
114
+ export type ZohoRecruitSearchRecordsResponse<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord> = ZohoRecruitGetRecordsResponse<T>;
115
+ export type ZohoRecruitSearchRecordsFunction = <T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecord>(input: ZohoRecruitSearchRecordsInput<T>) => Promise<ZohoRecruitSearchRecordsResponse<T>>;
116
+ /**
117
+ * Searches records from the given module.
118
+ *
119
+ * https://www.zoho.com/recruit/developer-guide/apiv2/search-records.html
120
+ *
121
+ * @param context
122
+ * @returns
123
+ */
124
+ export declare function searchRecords(context: ZohoRecruitContext): ZohoRecruitSearchRecordsFunction;
125
+ export declare function zohoRecruitUrlSearchParamsMinusModule(input: object | Record<string, string | number>): URLSearchParams;
126
+ export declare function zohoRecruitApiFetchJsonInput(method: string, body?: FetchJsonBody): FetchJsonInput;
127
+ export interface ZohoRecruitMultiRecordResult<I, OS, OE> {
128
+ readonly successItems: ZohoRecruitMultiRecordResultEntry<I, OS>[];
129
+ readonly errorItems: ZohoRecruitMultiRecordResultEntry<I, OE>[];
130
+ }
131
+ export interface ZohoRecrutMultiRecordResultItem {
132
+ readonly status: ZohoServerSuccessStatus | ZohoServerErrorStatus;
133
+ }
134
+ export declare function zohoRecruitMultiRecordResult<I, OS extends ZohoRecrutMultiRecordResultItem, OE extends ZohoRecrutMultiRecordResultItem>(input: I[], results: (OS | OE)[]): ZohoRecruitMultiRecordResult<I, OS, OE>;
135
+ export interface ZohoRecruitMultiRecordResultEntry<I, O> {
136
+ /**
137
+ * Input record/data.
138
+ */
139
+ readonly input: I;
140
+ /**
141
+ * The result of the insert.
142
+ */
143
+ readonly result: O;
144
+ }
@@ -0,0 +1,23 @@
1
+ import { FactoryWithRequiredInput } from '@dereekb/util';
2
+ import { ConfiguredFetch, FetchJsonFunction } from '@dereekb/util/fetch';
3
+ import { ZohoApiUrl, ZohoRefreshToken, ZohoApiUrlKey, ZohoConfig, ZohoApiServiceName } from '../zoho.config';
4
+ import { ZohoServiceAccessTokenKey } from '../accounts';
5
+ export declare const ZOHO_RECRUIT_SERVICE_NAME: ZohoApiServiceName | ZohoServiceAccessTokenKey;
6
+ export type ZohoRecruitApiUrl = ZohoApiUrl;
7
+ export type ZohoRecruitApiKey = ZohoRefreshToken;
8
+ export type ZohoRecruitApiUrlKey = ZohoApiUrlKey;
9
+ export type ZohoRecruitConfigApiUrlInput = ZohoRecruitApiUrlKey | ZohoRecruitApiUrl;
10
+ export declare function zohoRecruitConfigApiUrl(input: ZohoRecruitConfigApiUrlInput): ZohoApiUrl;
11
+ export type ZohoRecruitConfig = ZohoConfig;
12
+ export interface ZohoRecruitFetchFactoryInput {
13
+ readonly apiUrl: ZohoRecruitApiUrl;
14
+ }
15
+ export type ZohoRecruitFetchFactory = FactoryWithRequiredInput<ConfiguredFetch, ZohoRecruitFetchFactoryInput>;
16
+ export interface ZohoRecruitContext {
17
+ readonly fetch: ConfiguredFetch;
18
+ readonly fetchJson: FetchJsonFunction;
19
+ readonly config: ZohoRecruitConfig;
20
+ }
21
+ export interface ZohoRecruitContextRef {
22
+ readonly recruitContext: ZohoRecruitContext;
23
+ }
@@ -0,0 +1,108 @@
1
+ import { CommaSeparatedString, ISO8601DateString, Maybe, UniqueModelWithId } from '@dereekb/util';
2
+ /**
3
+ * Zoho Recruit module name.
4
+ *
5
+ * Example "Candidates"
6
+ */
7
+ export type ZohoRecruitModuleName = string;
8
+ /**
9
+ * Zoho Recruit record id
10
+ *
11
+ * Example "576214000000569001"
12
+ */
13
+ export type ZohoRecruitRecordId = string;
14
+ /**
15
+ * Zoho Recruit custom view id
16
+ */
17
+ export type ZohoRecruitCustomViewId = string;
18
+ /**
19
+ * Zoho Recruit territory id
20
+ */
21
+ export type ZohoRecruitTerritoryId = string;
22
+ /**
23
+ * The name of a field on a record.
24
+ */
25
+ export type ZohoRecruitFieldName = string;
26
+ export type ZohoRecruitDraftOrSaveState = 'draft' | 'save';
27
+ /**
28
+ * Comma separated list of field names
29
+ */
30
+ export type ZohoRecruitCommaSeparateFieldNames = CommaSeparatedString;
31
+ export type ZohoRecruitTrueFalseBoth = 'true' | 'false' | 'both';
32
+ export interface ZohoRecruitCreatedByData {
33
+ name: string;
34
+ id: string;
35
+ }
36
+ export type ZohoRecruitRecordFieldsData = Record<ZohoRecruitFieldName, any>;
37
+ export interface ZohoRecordDraftStateData {
38
+ /**
39
+ * Used to update a draft record or to convert a draft to a normal record.
40
+ *
41
+ * When creating, passing "draft" will create the record as a draft.
42
+ */
43
+ $state?: ZohoRecruitDraftOrSaveState;
44
+ }
45
+ export type NewZohoRecruitRecordData = ZohoRecruitRecordFieldsData & ZohoRecordDraftStateData;
46
+ /**
47
+ * A ZohoRecruit record containing the corresponding record's id.
48
+ */
49
+ export type UpdateZohoRecruitRecordData = UniqueModelWithId & ZohoRecruitRecordFieldsData & ZohoRecordDraftStateData;
50
+ /**
51
+ * A ZohoRecruit record containing record details.
52
+ */
53
+ export type ZohoRecruitRecord = UniqueModelWithId & ZohoRecruitRecordFieldsData;
54
+ /**
55
+ * Update details returned by the server for an updated object.
56
+ */
57
+ export interface ZohoRecruitRecordUpdateDetails {
58
+ id: ZohoRecruitRecordId;
59
+ Modified_Time: ISO8601DateString;
60
+ Modified_By: ZohoRecruitCreatedByData;
61
+ Created_Time: ISO8601DateString;
62
+ Created_By: ZohoRecruitCreatedByData;
63
+ }
64
+ /**
65
+ * Encoded criteria string.
66
+ */
67
+ export type ZohoRecruitSearchRecordsCriteriaString = string;
68
+ /**
69
+ * Creates a ZohoRecruitSearchRecordsCriteriaString from a ZohoRecruitSearchRecordsCriteriaTree.
70
+ *
71
+ * If the input tree is empty, returns undefined.
72
+ */
73
+ export declare function zohoRecruitSearchRecordsCriteriaString<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData>(input: Maybe<ZohoRecruitSearchRecordsCriteriaTreeElement<T>>): Maybe<ZohoRecruitSearchRecordsCriteriaString>;
74
+ export declare function zohoRecruitSearchRecordsCriteriaStringForTree<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData>(tree: ZohoRecruitSearchRecordsCriteriaTree<T>): Maybe<ZohoRecruitSearchRecordsCriteriaString>;
75
+ /**
76
+ * Tree items
77
+ *
78
+ * If both AND and OR values are provided at the root tree, then the will be merged together with AND.
79
+ */
80
+ export interface ZohoRecruitSearchRecordsCriteriaTree<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData> {
81
+ /**
82
+ * Items to AND with eachother
83
+ */
84
+ readonly and?: Maybe<ZohoRecruitSearchRecordsCriteriaTreeElement<T>[]>;
85
+ /**
86
+ * Items to OR with eachother
87
+ */
88
+ readonly or?: Maybe<ZohoRecruitSearchRecordsCriteriaTreeElement<T>[]>;
89
+ }
90
+ export type ZohoRecruitSearchRecordsCriteriaTreeElement<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData> = ZohoRecruitSearchRecordsCriteriaEntryArray<T> | ZohoRecruitSearchRecordsCriteriaTree | ZohoRecruitSearchRecordsCriteriaString;
91
+ export type ZohoRecruitSearchRecordsCriteriaFilterType = 'starts_with' | 'equals' | 'contains';
92
+ export type ZohoRecruitSearchRecordsCriteriaEntryArray<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData> = ZohoRecruitSearchRecordsCriteriaEntry<T>[];
93
+ export interface ZohoRecruitSearchRecordsCriteriaEntry<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData> {
94
+ readonly field: keyof T extends string ? keyof T : never;
95
+ readonly filter: ZohoRecruitSearchRecordsCriteriaFilterType;
96
+ readonly value: string;
97
+ }
98
+ /**
99
+ * Escape used for ZohoRecruitSearchRecordsCriteriaString
100
+ */
101
+ export declare const escapeZohoFieldValueForCriteriaString: import("@dereekb/util").EscapeStringCharactersFunction;
102
+ /**
103
+ * Converts the input entry to a ZohoRecruitSearchRecordsCriteriaString. Properly escapes any parenthesis or commas.
104
+ *
105
+ * @param entry
106
+ * @returns
107
+ */
108
+ export declare function zohoRecruitSearchRecordsCriteriaEntryToCriteriaString<T extends ZohoRecruitRecordFieldsData = ZohoRecruitRecordFieldsData>(entry: ZohoRecruitSearchRecordsCriteriaEntry<T>): ZohoRecruitSearchRecordsCriteriaString;
@@ -0,0 +1,29 @@
1
+ import { FetchResponseError } from '@dereekb/util/fetch';
2
+ import { BaseError } from 'make-error';
3
+ import { ZohoServerErrorDataWithDetails, ZohoServerErrorResponseData, ZohoServerError, ParsedZohoServerError } from '../zoho.error.api';
4
+ import { ZohoRecruitModuleName, ZohoRecruitRecordId } from './recruit';
5
+ import { ZohoDataArrayResultRef } from '../zoho.api.page';
6
+ export declare class ZohoRecruitRecordNoContentError extends BaseError {
7
+ readonly moduleName?: string | undefined;
8
+ readonly recordId?: string | undefined;
9
+ constructor(moduleName?: string | undefined, recordId?: string | undefined);
10
+ }
11
+ export declare class ZohoRecruitRecordCrudError extends ZohoServerError<ZohoServerErrorDataWithDetails> {
12
+ }
13
+ export declare class ZohoRecruitRecordCrudMandatoryFieldNotFoundError extends ZohoRecruitRecordCrudError {
14
+ }
15
+ export declare class ZohoRecruitRecordCrudDuplicateDataError extends ZohoRecruitRecordCrudError {
16
+ }
17
+ export type ZohoRecruitRecordCrudInvalidDataErrorDetails = Record<string, string>;
18
+ export declare class ZohoRecruitRecordCrudInvalidDataError extends ZohoRecruitRecordCrudError {
19
+ get invalidFieldDetails(): ZohoRecruitRecordCrudInvalidDataErrorDetails;
20
+ }
21
+ export declare class ZohoRecruitRecordCrudNoMatchingRecordError extends ZohoRecruitRecordCrudInvalidDataError {
22
+ }
23
+ export declare function zohoRecruitRecordCrudError(error: ZohoServerErrorDataWithDetails): ZohoRecruitRecordCrudError;
24
+ export declare function assertRecordDataArrayResultHasContent<T>(moduleName?: ZohoRecruitModuleName, recordId?: ZohoRecruitRecordId): <R extends ZohoDataArrayResultRef<T>>(x: R) => R;
25
+ export declare const logZohoRecruitErrorToConsole: import("../zoho.error.api").LogZohoServerErrorFunction;
26
+ export declare function parseZohoRecruitError(responseError: FetchResponseError): Promise<ParsedZohoServerError>;
27
+ export declare function parseZohoRecruitServerErrorResponseData(errorResponseData: ZohoServerErrorResponseData, responseError: FetchResponseError): ParsedZohoServerError;
28
+ export declare const interceptZohoRecruitErrorResponse: import("@dereekb/util/fetch").FetchJsonInterceptJsonResponseFunction;
29
+ export declare const handleZohoRecruitErrorFetch: import("../zoho.error.api").HandleZohoErrorFetchFactory;
@@ -0,0 +1,16 @@
1
+ import { ZohoRecruitConfig, ZohoRecruitContextRef, ZohoRecruitFetchFactory } from './recruit.config';
2
+ import { LogZohoServerErrorFunction } from '../zoho.error.api';
3
+ import { ZohoAccountsContextRef } from '../accounts/accounts.config';
4
+ export type ZohoRecruit = ZohoRecruitContextRef;
5
+ export interface ZohoRecruitFactoryConfig extends ZohoAccountsContextRef {
6
+ /**
7
+ * Creates a new fetch instance to use when making calls.
8
+ */
9
+ fetchFactory?: ZohoRecruitFetchFactory;
10
+ /**
11
+ * Custom log error function.
12
+ */
13
+ logZohoServerErrorFunction?: LogZohoServerErrorFunction;
14
+ }
15
+ export type ZohoRecruitFactory = (config: ZohoRecruitConfig) => ZohoRecruit;
16
+ export declare function zohoRecruitFactory(factoryConfig: ZohoRecruitFactoryConfig): ZohoRecruitFactory;