@dereekb/zoho 13.0.5 → 13.0.7
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/index.cjs.js +2164 -231
- package/index.esm.js +2143 -232
- package/nestjs/LICENSE +21 -0
- package/nestjs/README.md +11 -0
- package/nestjs/docs/configuration.md +165 -0
- package/nestjs/docs/crm-getting-started.md +296 -0
- package/nestjs/index.cjs.js +653 -5
- package/nestjs/index.esm.js +647 -7
- package/nestjs/package.json +3 -3
- package/nestjs/src/lib/crm/crm.api.d.ts +46 -0
- package/nestjs/src/lib/crm/crm.config.d.ts +16 -1
- package/nestjs/src/lib/crm/crm.module.d.ts +77 -8
- package/nestjs/src/lib/index.d.ts +2 -0
- package/nestjs/src/lib/recruit/recruit.api.d.ts +50 -0
- package/nestjs/src/lib/recruit/recruit.config.d.ts +16 -1
- package/nestjs/src/lib/recruit/recruit.module.d.ts +77 -8
- package/nestjs/src/lib/sign/index.d.ts +3 -0
- package/nestjs/src/lib/sign/sign.api.d.ts +54 -0
- package/nestjs/src/lib/sign/sign.config.d.ts +10 -0
- package/nestjs/src/lib/sign/sign.module.d.ts +94 -0
- package/package.json +2 -2
- package/src/lib/accounts/accounts.api.d.ts +149 -3
- package/src/lib/accounts/accounts.factory.d.ts +73 -6
- package/src/lib/crm/crm.api.d.ts +599 -62
- package/src/lib/crm/crm.api.notes.d.ts +46 -3
- package/src/lib/crm/crm.api.tags.d.ts +65 -2
- package/src/lib/crm/crm.config.d.ts +30 -0
- package/src/lib/crm/crm.criteria.d.ts +60 -3
- package/src/lib/crm/crm.error.api.d.ts +42 -0
- package/src/lib/crm/crm.factory.d.ts +39 -3
- package/src/lib/crm/crm.notes.d.ts +36 -0
- package/src/lib/crm/crm.tags.d.ts +3 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/recruit/recruit.api.candidates.d.ts +44 -3
- package/src/lib/recruit/recruit.api.d.ts +719 -57
- package/src/lib/recruit/recruit.api.notes.d.ts +140 -0
- package/src/lib/recruit/recruit.api.tags.d.ts +122 -14
- package/src/lib/recruit/recruit.config.d.ts +30 -0
- package/src/lib/recruit/recruit.criteria.d.ts +55 -3
- package/src/lib/recruit/recruit.error.api.d.ts +39 -0
- package/src/lib/recruit/recruit.factory.d.ts +39 -3
- package/src/lib/recruit/recruit.notes.d.ts +21 -0
- package/src/lib/recruit/recruit.tags.d.ts +3 -0
- package/src/lib/shared/criteria.d.ts +95 -11
- package/src/lib/shared/criteria.util.d.ts +19 -4
- package/src/lib/sign/index.d.ts +6 -0
- package/src/lib/sign/sign.api.d.ts +397 -0
- package/src/lib/sign/sign.api.page.d.ts +109 -0
- package/src/lib/sign/sign.config.d.ts +24 -0
- package/src/lib/sign/sign.d.ts +225 -0
- package/src/lib/sign/sign.error.api.d.ts +7 -0
- package/src/lib/sign/sign.factory.d.ts +58 -0
- package/src/lib/zoho.api.page.d.ts +41 -10
- package/src/lib/zoho.config.d.ts +24 -9
- package/src/lib/zoho.limit.d.ts +41 -9
- package/src/lib/zoho.type.d.ts +24 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/zoho",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.7",
|
|
4
4
|
"exports": {
|
|
5
5
|
"./nestjs": {
|
|
6
6
|
"module": "./nestjs/index.esm.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@dereekb/util": "13.0.
|
|
20
|
+
"@dereekb/util": "13.0.7",
|
|
21
21
|
"@nestjs/common": "^11.0.0",
|
|
22
22
|
"@nestjs/config": "^4.0.0",
|
|
23
23
|
"make-error": "^1.3.0"
|
|
@@ -4,24 +4,170 @@ import { type ZohoAuthClientIdAndSecretPair, type ZohoRefreshToken } from '../zo
|
|
|
4
4
|
import { type ZohoAccessTokenApiDomain, type ZohoAccessTokenScopesString, type ZohoAccessTokenString } from './accounts';
|
|
5
5
|
import { type Maybe, type Seconds } from '@dereekb/util';
|
|
6
6
|
import { type ZohoAccountsAccessTokenErrorCode } from './accounts.error.api';
|
|
7
|
+
/**
|
|
8
|
+
* Optional overrides for the access token request. When omitted, values
|
|
9
|
+
* are read from the {@link ZohoAccountsContext}'s config.
|
|
10
|
+
*/
|
|
7
11
|
export interface ZohoAccountsAccessTokenInput {
|
|
12
|
+
/**
|
|
13
|
+
* Override client credentials. Falls back to the context config's `clientId`/`clientSecret`.
|
|
14
|
+
*/
|
|
8
15
|
readonly client?: Maybe<ZohoAuthClientIdAndSecretPair>;
|
|
16
|
+
/**
|
|
17
|
+
* Override refresh token. Falls back to the context config's `refreshToken`.
|
|
18
|
+
*/
|
|
9
19
|
readonly refreshToken?: Maybe<ZohoRefreshToken>;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Successful response from the Zoho OAuth `/oauth/v2/token` endpoint
|
|
23
|
+
* when exchanging a refresh token for a new access token.
|
|
24
|
+
*/
|
|
11
25
|
export interface ZohoAccountsAccessTokenResponse {
|
|
26
|
+
/**
|
|
27
|
+
* Short-lived OAuth access token for authenticating API calls.
|
|
28
|
+
*/
|
|
12
29
|
access_token: ZohoAccessTokenString;
|
|
30
|
+
/**
|
|
31
|
+
* Comma-separated list of OAuth scopes granted to this token.
|
|
32
|
+
*/
|
|
13
33
|
scope: ZohoAccessTokenScopesString;
|
|
34
|
+
/**
|
|
35
|
+
* The API domain to use for subsequent API calls (e.g. `'https://www.zohoapis.com'`).
|
|
36
|
+
*/
|
|
14
37
|
api_domain: ZohoAccessTokenApiDomain;
|
|
38
|
+
/**
|
|
39
|
+
* Token type, always `'Bearer'`.
|
|
40
|
+
*/
|
|
15
41
|
token_type: 'Bearer';
|
|
42
|
+
/**
|
|
43
|
+
* Number of seconds until the access token expires.
|
|
44
|
+
*/
|
|
16
45
|
expires_in: Seconds;
|
|
17
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Error response from the Zoho OAuth token endpoint when the refresh fails.
|
|
49
|
+
*/
|
|
18
50
|
export interface ZohoAccountsAccessTokenErrorResponse {
|
|
51
|
+
/**
|
|
52
|
+
* Error code indicating the reason for failure (e.g. `'invalid_code'`, `'invalid_client'`).
|
|
53
|
+
*/
|
|
19
54
|
error: ZohoAccountsAccessTokenErrorCode;
|
|
20
55
|
}
|
|
21
56
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
57
|
+
* Creates a function that exchanges a refresh token for a new short-lived access token
|
|
58
|
+
* via the Zoho OAuth `/oauth/v2/token` endpoint.
|
|
59
|
+
*
|
|
60
|
+
* The returned function accepts optional overrides for client credentials and refresh token.
|
|
61
|
+
* When omitted, values are read from the {@link ZohoAccountsContext}'s config.
|
|
62
|
+
*
|
|
63
|
+
* @param context - Authenticated Zoho Accounts context providing fetch and config
|
|
64
|
+
* @returns Function that exchanges a refresh token for an access token
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const getAccessToken = zohoAccountsAccessToken(accountsContext);
|
|
69
|
+
*
|
|
70
|
+
* // Using config defaults:
|
|
71
|
+
* const { access_token, expires_in } = await getAccessToken();
|
|
72
|
+
*
|
|
73
|
+
* // With overrides:
|
|
74
|
+
* const response = await getAccessToken({
|
|
75
|
+
* client: { clientId: 'other-id', clientSecret: 'other-secret' },
|
|
76
|
+
* refreshToken: 'other-refresh-token'
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @see https://www.zoho.com/accounts/protocol/oauth/web-apps/access-token-expiry.html
|
|
25
81
|
*/
|
|
26
82
|
export declare function zohoAccountsAccessToken(context: ZohoAccountsContext): (input?: ZohoAccountsAccessTokenInput) => Promise<ZohoAccountsAccessTokenResponse>;
|
|
83
|
+
/**
|
|
84
|
+
* OAuth authorization code received from the Zoho authorization server
|
|
85
|
+
* after the user grants consent. Single-use and short-lived.
|
|
86
|
+
*/
|
|
87
|
+
export type ZohoAuthorizationCode = string;
|
|
88
|
+
/**
|
|
89
|
+
* Input for exchanging an authorization code for a refresh token and initial access token.
|
|
90
|
+
*/
|
|
91
|
+
export interface ZohoAccountsRefreshTokenFromAuthorizationCodeInput {
|
|
92
|
+
/**
|
|
93
|
+
* Override client credentials. Falls back to the context config's `clientId`/`clientSecret`.
|
|
94
|
+
*/
|
|
95
|
+
readonly client?: Maybe<ZohoAuthClientIdAndSecretPair>;
|
|
96
|
+
/**
|
|
97
|
+
* The single-use authorization code obtained from the Zoho consent flow.
|
|
98
|
+
*/
|
|
99
|
+
readonly code: ZohoAuthorizationCode;
|
|
100
|
+
/**
|
|
101
|
+
* The redirect URI registered in the Zoho API console.
|
|
102
|
+
* Must exactly match the URI used during the authorization request.
|
|
103
|
+
*/
|
|
104
|
+
readonly redirectUri: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Successful response from the Zoho OAuth `/oauth/v2/token` endpoint
|
|
108
|
+
* when exchanging an authorization code for tokens.
|
|
109
|
+
*/
|
|
110
|
+
export interface ZohoAccountsRefreshTokenFromAuthorizationCodeResponse {
|
|
111
|
+
/**
|
|
112
|
+
* Short-lived OAuth access token for authenticating API calls.
|
|
113
|
+
*/
|
|
114
|
+
readonly access_token: ZohoAccessTokenString;
|
|
115
|
+
/**
|
|
116
|
+
* Long-lived refresh token for obtaining new access tokens.
|
|
117
|
+
* Only included if `access_type=offline` was passed during the authorization request.
|
|
118
|
+
*/
|
|
119
|
+
readonly refresh_token?: ZohoRefreshToken;
|
|
120
|
+
/**
|
|
121
|
+
* Comma-separated list of OAuth scopes granted to this token.
|
|
122
|
+
*/
|
|
123
|
+
readonly scope: ZohoAccessTokenScopesString;
|
|
124
|
+
/**
|
|
125
|
+
* The API domain to use for subsequent API calls (e.g. `'https://www.zohoapis.com'`).
|
|
126
|
+
*/
|
|
127
|
+
readonly api_domain: ZohoAccessTokenApiDomain;
|
|
128
|
+
/**
|
|
129
|
+
* Token type, always `'Bearer'`.
|
|
130
|
+
*/
|
|
131
|
+
readonly token_type: 'Bearer';
|
|
132
|
+
/**
|
|
133
|
+
* Number of seconds until the access token expires (typically 3600).
|
|
134
|
+
*/
|
|
135
|
+
readonly expires_in: Seconds;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Exchanges a single-use authorization code for tokens.
|
|
139
|
+
*/
|
|
140
|
+
export type ZohoAccountsRefreshTokenFromAuthorizationCodeFunction = (input: ZohoAccountsRefreshTokenFromAuthorizationCodeInput) => Promise<ZohoAccountsRefreshTokenFromAuthorizationCodeResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a function that exchanges a single-use OAuth authorization code for
|
|
143
|
+
* an access token and (optionally) a long-lived refresh token via the Zoho
|
|
144
|
+
* `/oauth/v2/token` endpoint with `grant_type=authorization_code`.
|
|
145
|
+
*
|
|
146
|
+
* This is the second step of the Zoho OAuth 2.0 web server flow:
|
|
147
|
+
* 1. Redirect the user to Zoho's consent page to obtain an authorization code
|
|
148
|
+
* 2. Exchange the authorization code for tokens using this function
|
|
149
|
+
* 3. Use the refresh token with {@link zohoAccountsAccessToken} to obtain new access tokens
|
|
150
|
+
*
|
|
151
|
+
* The refresh token is only returned if `access_type=offline` was passed during
|
|
152
|
+
* the initial authorization request.
|
|
153
|
+
*
|
|
154
|
+
* @param context - Zoho Accounts context providing fetch and config (clientId/clientSecret)
|
|
155
|
+
* @returns Function that exchanges an authorization code for tokens
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const exchangeCode = zohoAccountsRefreshTokenFromAuthorizationCode(accountsContext);
|
|
160
|
+
*
|
|
161
|
+
* const { access_token, refresh_token } = await exchangeCode({
|
|
162
|
+
* code: '1000.abc123.def456',
|
|
163
|
+
* redirectUri: 'https://myapp.example.com/oauth/callback'
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @see https://www.zoho.com/accounts/protocol/oauth/web-apps/access-token.html
|
|
168
|
+
*/
|
|
169
|
+
export declare function zohoAccountsRefreshTokenFromAuthorizationCode(context: ZohoAccountsContext): ZohoAccountsRefreshTokenFromAuthorizationCodeFunction;
|
|
170
|
+
/**
|
|
171
|
+
* Constructs a standard {@link FetchJsonInput} for Zoho Accounts API calls with the given HTTP method and optional body.
|
|
172
|
+
*/
|
|
27
173
|
export declare function zohoAccountsApiFetchJsonInput(method: string, body?: FetchJsonBody): FetchJsonInput;
|
|
@@ -2,33 +2,100 @@ import { type ZohoAccountsConfig, type ZohoAccountsContextRef, type ZohoAccounts
|
|
|
2
2
|
import { type LogZohoServerErrorFunction } from '../zoho.error.api';
|
|
3
3
|
import { type ZohoAccessTokenCache, type ZohoAccessTokenFactory, type ZohoAccessTokenRefresher } from './accounts';
|
|
4
4
|
import { type Maybe, type Milliseconds } from '@dereekb/util';
|
|
5
|
+
/**
|
|
6
|
+
* Top-level Zoho Accounts client instance, providing access to the authenticated {@link ZohoAccountsContext}
|
|
7
|
+
* used for OAuth token management.
|
|
8
|
+
*/
|
|
5
9
|
export type ZohoAccounts = ZohoAccountsContextRef;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for creating a {@link ZohoAccountsFactory}, with optional overrides
|
|
12
|
+
* for the HTTP client and error logging.
|
|
13
|
+
*/
|
|
6
14
|
export interface ZohoAccountsFactoryConfig {
|
|
7
15
|
/**
|
|
8
|
-
*
|
|
16
|
+
* Custom fetch factory for creating the underlying HTTP client.
|
|
17
|
+
* Defaults to a standard fetch service with JSON content headers and a 20-second timeout.
|
|
9
18
|
*/
|
|
10
19
|
fetchFactory?: ZohoAccountsFetchFactory;
|
|
11
20
|
/**
|
|
12
|
-
* Custom
|
|
21
|
+
* Custom error logging function invoked when Zoho API errors are encountered.
|
|
13
22
|
*/
|
|
14
23
|
logZohoServerErrorFunction?: LogZohoServerErrorFunction;
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Factory function that creates a {@link ZohoAccounts} client from a {@link ZohoAccountsConfig}.
|
|
27
|
+
*/
|
|
16
28
|
export type ZohoAccountsFactory = (config: ZohoAccountsConfig) => ZohoAccounts;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a {@link ZohoAccountsFactory} from the given configuration.
|
|
31
|
+
*
|
|
32
|
+
* The factory pre-initializes shared resources (rate limiter) once, then produces
|
|
33
|
+
* {@link ZohoAccounts} client instances for each {@link ZohoAccountsConfig}. Each client
|
|
34
|
+
* handles OAuth token refresh via the configured `refreshToken`, `clientId`, and `clientSecret`,
|
|
35
|
+
* with in-memory caching and optional external {@link ZohoAccessTokenCache} support.
|
|
36
|
+
*
|
|
37
|
+
* The Accounts client is the foundation for CRM, Recruit, and Sign clients, as it provides
|
|
38
|
+
* the {@link ZohoAccountsContext} needed for OAuth token management.
|
|
39
|
+
*
|
|
40
|
+
* @param factoryConfig - Configuration providing optional fetch and logging overrides
|
|
41
|
+
* @returns A factory function that creates authenticated Zoho Accounts clients
|
|
42
|
+
* @throws {Error} If `refreshToken`, `clientId`, or `clientSecret` are missing from the config
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const factory = zohoAccountsFactory({});
|
|
47
|
+
*
|
|
48
|
+
* const zohoAccounts = factory({
|
|
49
|
+
* refreshToken: 'your-refresh-token',
|
|
50
|
+
* clientId: 'your-client-id',
|
|
51
|
+
* clientSecret: 'your-client-secret',
|
|
52
|
+
* apiUrl: 'us'
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Pass the accounts context to CRM/Recruit/Sign factories:
|
|
56
|
+
* const crmFactory = zohoCrmFactory({
|
|
57
|
+
* accountsContext: zohoAccounts.accountsContext
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
17
61
|
export declare function zohoAccountsFactory(factoryConfig: ZohoAccountsFactoryConfig): ZohoAccountsFactory;
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for {@link zohoAccountsZohoAccessTokenFactory}, controlling token refresh,
|
|
64
|
+
* caching, and expiration buffer behavior.
|
|
65
|
+
*/
|
|
18
66
|
export interface ZohoAccountsZohoAccessTokenFactoryConfig {
|
|
19
67
|
/**
|
|
20
|
-
* Number of milliseconds before the expiration time a token should be discarded
|
|
68
|
+
* Number of milliseconds before the expiration time a token should be discarded
|
|
69
|
+
* and refreshed proactively.
|
|
21
70
|
*
|
|
22
71
|
* Defaults to 1 minute.
|
|
23
72
|
*/
|
|
24
73
|
readonly tokenExpirationBuffer?: Milliseconds;
|
|
74
|
+
/**
|
|
75
|
+
* Function that fetches a fresh access token from the Zoho OAuth endpoint.
|
|
76
|
+
*/
|
|
25
77
|
readonly tokenRefresher: ZohoAccessTokenRefresher;
|
|
78
|
+
/**
|
|
79
|
+
* Optional external cache for persisting tokens across process restarts.
|
|
80
|
+
* When provided, tokens are loaded from and saved to this cache in addition
|
|
81
|
+
* to the in-memory cache.
|
|
82
|
+
*/
|
|
26
83
|
readonly accessTokenCache?: Maybe<ZohoAccessTokenCache>;
|
|
27
84
|
}
|
|
28
85
|
/**
|
|
29
|
-
* Creates a
|
|
86
|
+
* Creates a {@link ZohoAccessTokenFactory} that manages access token lifecycle with
|
|
87
|
+
* in-memory caching, optional external cache support, and automatic refresh.
|
|
88
|
+
*
|
|
89
|
+
* Token resolution order:
|
|
90
|
+
* 1. Return the in-memory cached token if valid (not expired within the buffer)
|
|
91
|
+
* 2. Load from the external {@link ZohoAccessTokenCache} if available
|
|
92
|
+
* 3. Fetch a fresh token via the {@link ZohoAccessTokenRefresher}
|
|
93
|
+
*
|
|
94
|
+
* The returned function also exposes a `resetAccessToken()` method to invalidate
|
|
95
|
+
* the current cached token, typically called on {@link ZohoInvalidTokenError}.
|
|
30
96
|
*
|
|
31
|
-
* @param config
|
|
32
|
-
* @returns
|
|
97
|
+
* @param config - Token refresh, caching, and expiration buffer configuration
|
|
98
|
+
* @returns A token factory function with `resetAccessToken` for cache invalidation
|
|
99
|
+
* @throws {ZohoAccountsAuthFailureError} If the token refresher fails
|
|
33
100
|
*/
|
|
34
101
|
export declare function zohoAccountsZohoAccessTokenFactory(config: ZohoAccountsZohoAccessTokenFactoryConfig): ZohoAccessTokenFactory;
|