@dereekb/zoho 13.39.0 → 13.40.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/cli/index.js +7 -5
- package/cli/package.json +7 -7
- package/index.esm.js +3354 -556
- package/nestjs/docs/analytics-testing.md +202 -0
- package/nestjs/index.esm.js +867 -268
- package/nestjs/package.json +5 -5
- package/nestjs/src/lib/analytics/analytics.api.d.ts +236 -0
- package/nestjs/src/lib/analytics/analytics.config.d.ts +24 -0
- package/nestjs/src/lib/analytics/analytics.module.d.ts +65 -0
- package/nestjs/src/lib/analytics/index.d.ts +3 -0
- package/nestjs/src/lib/index.d.ts +1 -0
- package/package.json +8 -8
- package/src/lib/analytics/analytics.api.export.d.ts +167 -0
- package/src/lib/analytics/analytics.api.import.d.ts +252 -0
- package/src/lib/analytics/analytics.api.modeling.d.ts +106 -0
- package/src/lib/analytics/analytics.api.orgs.d.ts +36 -0
- package/src/lib/analytics/analytics.api.rows.d.ts +214 -0
- package/src/lib/analytics/analytics.api.views.d.ts +104 -0
- package/src/lib/analytics/analytics.api.workspaces.d.ts +96 -0
- package/src/lib/analytics/analytics.config.d.ts +92 -0
- package/src/lib/analytics/analytics.d.ts +86 -0
- package/src/lib/analytics/analytics.data.d.ts +74 -0
- package/src/lib/analytics/analytics.diff.d.ts +178 -0
- package/src/lib/analytics/analytics.error.api.d.ts +150 -0
- package/src/lib/analytics/analytics.export.d.ts +91 -0
- package/src/lib/analytics/analytics.factory.d.ts +56 -0
- package/src/lib/analytics/analytics.import.d.ts +176 -0
- package/src/lib/analytics/analytics.job.d.ts +132 -0
- package/src/lib/analytics/analytics.limit.d.ts +55 -0
- package/src/lib/analytics/analytics.org.d.ts +51 -0
- package/src/lib/analytics/analytics.param.d.ts +70 -0
- package/src/lib/analytics/analytics.view.d.ts +99 -0
- package/src/lib/analytics/index.d.ts +20 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/zoho.limit.d.ts +14 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type FetchJsonInterceptJsonResponseFunction, FetchResponseError } from '@dereekb/util/fetch';
|
|
3
|
+
import { type ParsedZohoServerError, type ZohoServerErrorData, ZohoServerFetchResponseError } from '../zoho.error.api';
|
|
4
|
+
/**
|
|
5
|
+
* Value of the `status` field on a successful Zoho Analytics response.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ZOHO_ANALYTICS_SUCCESS_STATUS = "success";
|
|
8
|
+
/**
|
|
9
|
+
* Value of the `status` field on a failed Zoho Analytics response.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ZOHO_ANALYTICS_FAILURE_STATUS = "failure";
|
|
12
|
+
/**
|
|
13
|
+
* Numeric error code returned by the Zoho Analytics API.
|
|
14
|
+
*
|
|
15
|
+
* Analytics identifies errors with numbers (e.g. `8535`) rather than the symbolic string codes
|
|
16
|
+
* (e.g. `'INVALID_TOKEN'`) used by CRM, Recruit, Desk and Sign.
|
|
17
|
+
*/
|
|
18
|
+
export type ZohoAnalyticsErrorCode = number | string;
|
|
19
|
+
/**
|
|
20
|
+
* The error payload nested under `data` on a failed Zoho Analytics response.
|
|
21
|
+
*/
|
|
22
|
+
export interface ZohoAnalyticsErrorResponseDataError {
|
|
23
|
+
readonly errorCode?: Maybe<ZohoAnalyticsErrorCode>;
|
|
24
|
+
readonly errorMessage?: Maybe<string>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Error response returned by the Zoho Analytics API.
|
|
28
|
+
*
|
|
29
|
+
* Analytics uses its own envelope rather than the `{ error }` / `{ data: [] }` shapes returned by
|
|
30
|
+
* the other Zoho services:
|
|
31
|
+
*
|
|
32
|
+
* ```json
|
|
33
|
+
* {"status":"failure","summary":"META_DBNAME_DUPLICATE",
|
|
34
|
+
* "data":{"errorCode":7101,"errorMessage":"Workspace with the same name exists already"}}
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see https://www.zoho.com/analytics/api/v2/api-specification.html
|
|
38
|
+
*/
|
|
39
|
+
export interface ZohoAnalyticsErrorResponseData {
|
|
40
|
+
readonly status?: Maybe<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Symbolic constant naming the failure, e.g. `'META_DBNAME_DUPLICATE'`.
|
|
43
|
+
*/
|
|
44
|
+
readonly summary?: Maybe<string>;
|
|
45
|
+
readonly data?: Maybe<ZohoAnalyticsErrorResponseDataError>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Extra detail attached to a parsed Zoho Analytics error.
|
|
49
|
+
*/
|
|
50
|
+
export interface ZohoAnalyticsServerErrorDetails {
|
|
51
|
+
/**
|
|
52
|
+
* The `summary` constant from the Analytics error envelope.
|
|
53
|
+
*/
|
|
54
|
+
readonly summary?: Maybe<string>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Error code returned when the provided OAuth token is invalid or expired.
|
|
58
|
+
*
|
|
59
|
+
* Mapped to {@link ZohoInvalidTokenError} so that the Analytics fetch wrapper clears the cached
|
|
60
|
+
* access token and the next request retrieves a fresh one.
|
|
61
|
+
*
|
|
62
|
+
* @see https://www.zoho.com/analytics/api/v2/common-error-codes.html
|
|
63
|
+
*/
|
|
64
|
+
export declare const ZOHO_ANALYTICS_INVALID_OAUTH_TOKEN_ERROR_CODE = "8535";
|
|
65
|
+
/**
|
|
66
|
+
* Error code returned when the `ZANALYTICS-ORGID` header is missing from the request.
|
|
67
|
+
*
|
|
68
|
+
* @see https://www.zoho.com/analytics/api/v2/common-error-codes.html
|
|
69
|
+
*/
|
|
70
|
+
export declare const ZOHO_ANALYTICS_ORG_ID_NOT_PRESENT_ERROR_CODE = "8083";
|
|
71
|
+
/**
|
|
72
|
+
* Error code returned when the per-minute API frequency limit is exceeded.
|
|
73
|
+
*
|
|
74
|
+
* Analytics allows 100 requests per minute overall (40/min for bulk operations, 60/min for
|
|
75
|
+
* metadata).
|
|
76
|
+
*
|
|
77
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-frequency.html
|
|
78
|
+
*/
|
|
79
|
+
export declare const ZOHO_ANALYTICS_FREQUENCY_LIMIT_ERROR_CODE = "6045";
|
|
80
|
+
/**
|
|
81
|
+
* Error codes returned when the plan's daily API unit quota is exhausted.
|
|
82
|
+
*
|
|
83
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-units.html
|
|
84
|
+
*/
|
|
85
|
+
export declare const ZOHO_ANALYTICS_DAILY_UNIT_LIMIT_ERROR_CODES: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Error raised when a Zoho Analytics request omits the required organization id header.
|
|
88
|
+
*
|
|
89
|
+
* Indicates the `ZohoAnalyticsConfig` is missing its `orgId`.
|
|
90
|
+
*/
|
|
91
|
+
export declare class ZohoAnalyticsMissingOrgIdError extends ZohoServerFetchResponseError {
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns true when the input looks like a failed Zoho Analytics response envelope.
|
|
95
|
+
*
|
|
96
|
+
* @param value - A parsed JSON response body.
|
|
97
|
+
* @returns Whether the body is an Analytics failure envelope.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isZohoAnalyticsErrorResponseData(value: unknown): value is ZohoAnalyticsErrorResponseData;
|
|
100
|
+
/**
|
|
101
|
+
* Normalizes a Zoho Analytics error envelope into the shared {@link ZohoServerErrorData} shape,
|
|
102
|
+
* stringifying the numeric error code so it can be compared against the shared string codes.
|
|
103
|
+
*
|
|
104
|
+
* @param errorResponseData - The Analytics failure envelope.
|
|
105
|
+
* @returns Normalized error data with code, message and the originating summary as details.
|
|
106
|
+
*/
|
|
107
|
+
export declare function zohoAnalyticsServerErrorData(errorResponseData: ZohoAnalyticsErrorResponseData): ZohoServerErrorData<ZohoAnalyticsServerErrorDetails>;
|
|
108
|
+
/**
|
|
109
|
+
* Parses a Zoho Analytics response body into a typed error.
|
|
110
|
+
*
|
|
111
|
+
* Analytics error codes are numeric and unrelated to the symbolic codes the shared parser knows,
|
|
112
|
+
* so the Analytics-specific codes are classified here. Bodies that are not Analytics failure
|
|
113
|
+
* envelopes fall through to the shared parser, which covers errors raised upstream of Analytics
|
|
114
|
+
* (for example by Zoho Accounts during a token exchange).
|
|
115
|
+
*
|
|
116
|
+
* @param errorResponseData - The raw response body from the Zoho Analytics API.
|
|
117
|
+
* @param responseError - The original fetch response error for context.
|
|
118
|
+
* @returns The parsed Zoho server error, or undefined if the error could not be classified.
|
|
119
|
+
*/
|
|
120
|
+
export declare function parseZohoAnalyticsServerErrorResponseData(errorResponseData: unknown, responseError: FetchResponseError): ParsedZohoServerError;
|
|
121
|
+
/**
|
|
122
|
+
* Pre-configured console logger for Zoho Analytics server errors.
|
|
123
|
+
*/
|
|
124
|
+
export declare const logZohoAnalyticsErrorToConsole: import("..").LogZohoServerErrorFunction;
|
|
125
|
+
/**
|
|
126
|
+
* Parses a fetch response error into a typed Zoho Analytics error by reading and interpreting the
|
|
127
|
+
* JSON error body.
|
|
128
|
+
*
|
|
129
|
+
* @param responseError - The fetch response error to parse.
|
|
130
|
+
* @returns The parsed Zoho server error, or undefined if the response could not be parsed.
|
|
131
|
+
*/
|
|
132
|
+
export declare function parseZohoAnalyticsError(responseError: FetchResponseError): Promise<ParsedZohoServerError>;
|
|
133
|
+
/**
|
|
134
|
+
* Fetch response interceptor that detects a Zoho Analytics failure envelope returned with an HTTP
|
|
135
|
+
* 200 status and converts it into a thrown error.
|
|
136
|
+
*
|
|
137
|
+
* The shared `interceptZohoErrorResponseFactory` cannot be reused here: it looks for an
|
|
138
|
+
* `error` key, which Analytics never sets.
|
|
139
|
+
*
|
|
140
|
+
* @param json - The parsed response body.
|
|
141
|
+
* @param response - The originating HTTP response.
|
|
142
|
+
* @returns The body unchanged when it is not a failure envelope.
|
|
143
|
+
* @throws {ZohoServerFetchResponseError} When the body is an Analytics failure envelope.
|
|
144
|
+
*/
|
|
145
|
+
export declare const interceptZohoAnalytics200StatusWithErrorResponse: FetchJsonInterceptJsonResponseFunction;
|
|
146
|
+
/**
|
|
147
|
+
* Wraps a fetch function with Zoho Analytics error parsing and console logging, ensuring all
|
|
148
|
+
* Analytics API errors are surfaced as typed exceptions.
|
|
149
|
+
*/
|
|
150
|
+
export declare const handleZohoAnalyticsErrorFetch: import("..").HandleZohoErrorFetchFactory;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type WebsiteUrl } from '@dereekb/util';
|
|
2
|
+
import { type ZohoAnalyticsCriteria, type ZohoAnalyticsName } from './analytics';
|
|
3
|
+
import { type ZohoAnalyticsDelimiter, type ZohoAnalyticsQuoted } from './analytics.import';
|
|
4
|
+
import { type ZohoAnalyticsJobStatus } from './analytics.job';
|
|
5
|
+
/**
|
|
6
|
+
* Format of exported Zoho Analytics data.
|
|
7
|
+
*
|
|
8
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/export-data.html
|
|
9
|
+
*/
|
|
10
|
+
export type ZohoAnalyticsExportResponseFormat = 'csv' | 'json' | 'xml' | 'xls' | 'pdf' | 'html' | 'image';
|
|
11
|
+
/**
|
|
12
|
+
* Record delimiter of exported CSV data. `0` DOS, `1` UNIX, `2` MAC.
|
|
13
|
+
*/
|
|
14
|
+
export type ZohoAnalyticsRecordDelimiter = 0 | 1 | 2;
|
|
15
|
+
/**
|
|
16
|
+
* Options controlling a Zoho Analytics data export.
|
|
17
|
+
*
|
|
18
|
+
* Only the data-oriented options are modeled. The presentation options that apply to the `pdf`,
|
|
19
|
+
* `html` and `image` formats (margins, headers, paper size, and so on) are not, since they are
|
|
20
|
+
* unrelated to moving data; pass them by extending this type if they are ever needed.
|
|
21
|
+
*
|
|
22
|
+
* Note there is no offset or limit option: Zoho Analytics does not paginate row data. Narrow a
|
|
23
|
+
* large export with `criteria` and `selectedColumns`, or use an asynchronous export job.
|
|
24
|
+
*
|
|
25
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/export-data.html
|
|
26
|
+
*/
|
|
27
|
+
export interface ZohoAnalyticsExportConfig {
|
|
28
|
+
readonly responseFormat: ZohoAnalyticsExportResponseFormat;
|
|
29
|
+
/**
|
|
30
|
+
* Restricts the export to rows matching this filter expression.
|
|
31
|
+
*/
|
|
32
|
+
readonly criteria?: ZohoAnalyticsCriteria;
|
|
33
|
+
/**
|
|
34
|
+
* Restricts the export to these columns.
|
|
35
|
+
*/
|
|
36
|
+
readonly selectedColumns?: ZohoAnalyticsName[];
|
|
37
|
+
readonly showHiddenCols?: boolean;
|
|
38
|
+
readonly showPersonalCols?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* CSV only. Field delimiter.
|
|
41
|
+
*/
|
|
42
|
+
readonly delimiter?: ZohoAnalyticsDelimiter;
|
|
43
|
+
/**
|
|
44
|
+
* CSV only. Record delimiter.
|
|
45
|
+
*/
|
|
46
|
+
readonly recordDelimiter?: ZohoAnalyticsRecordDelimiter;
|
|
47
|
+
/**
|
|
48
|
+
* CSV only. Quote character.
|
|
49
|
+
*/
|
|
50
|
+
readonly quoted?: ZohoAnalyticsQuoted;
|
|
51
|
+
/**
|
|
52
|
+
* CSV only. Whether to include a header row. Defaults to true.
|
|
53
|
+
*/
|
|
54
|
+
readonly includeHeader?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* JSON only. Whether to emit rows as column-name/value pairs. Defaults to true.
|
|
57
|
+
*/
|
|
58
|
+
readonly keyValueFormat?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Options for an asynchronous export job.
|
|
62
|
+
*/
|
|
63
|
+
export interface ZohoAnalyticsExportJobConfig extends ZohoAnalyticsExportConfig {
|
|
64
|
+
/**
|
|
65
|
+
* URL that Zoho posts the job's completion status to.
|
|
66
|
+
*/
|
|
67
|
+
readonly callbackUrl?: WebsiteUrl;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Options for an asynchronous export job driven by a SQL query.
|
|
71
|
+
*
|
|
72
|
+
* This runs an ad-hoc query and exports its result. It does not create anything: to persist a
|
|
73
|
+
* query as a reusable view, create a query table through the Modeling API instead.
|
|
74
|
+
*
|
|
75
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/export-data-async/create-export/sql-query.html
|
|
76
|
+
*/
|
|
77
|
+
export interface ZohoAnalyticsExportJobSqlQueryConfig extends ZohoAnalyticsExportJobConfig {
|
|
78
|
+
/**
|
|
79
|
+
* The SQL `SELECT` statement to export the results of.
|
|
80
|
+
*/
|
|
81
|
+
readonly sqlQuery: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Status of an asynchronous export job.
|
|
85
|
+
*/
|
|
86
|
+
export interface ZohoAnalyticsExportJobStatus extends ZohoAnalyticsJobStatus {
|
|
87
|
+
/**
|
|
88
|
+
* URL the exported file can be downloaded from once the job has completed.
|
|
89
|
+
*/
|
|
90
|
+
readonly downloadUrl?: WebsiteUrl;
|
|
91
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ZohoAnalyticsConfig, type ZohoAnalyticsContextRef, type ZohoAnalyticsFetchFactory } from './analytics.config';
|
|
2
|
+
import { type LogZohoServerErrorFunction } from '../zoho.error.api';
|
|
3
|
+
import { type ZohoAccountsContextRef } from '../accounts/accounts.config';
|
|
4
|
+
import { type ZohoRateLimitedFetchHandlerConfig } from '../zoho.limit';
|
|
5
|
+
import { type Maybe } from '@dereekb/util';
|
|
6
|
+
/**
|
|
7
|
+
* Top-level Zoho Analytics client instance, providing access to the authenticated {@link ZohoAnalyticsContext}.
|
|
8
|
+
*/
|
|
9
|
+
export type ZohoAnalytics = ZohoAnalyticsContextRef;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for creating a {@link ZohoAnalyticsFactory}, combining account credentials
|
|
12
|
+
* with optional overrides for rate limiting, fetch behavior, and error logging.
|
|
13
|
+
*/
|
|
14
|
+
export interface ZohoAnalyticsFactoryConfig extends ZohoAccountsContextRef {
|
|
15
|
+
/**
|
|
16
|
+
* Custom rate limiter configuration to control request concurrency and throttling.
|
|
17
|
+
*/
|
|
18
|
+
readonly rateLimiterConfig?: Maybe<ZohoRateLimitedFetchHandlerConfig>;
|
|
19
|
+
/**
|
|
20
|
+
* Custom fetch factory for creating the underlying HTTP client.
|
|
21
|
+
* Defaults to a standard fetch service with the Zoho-oauthtoken authorization and
|
|
22
|
+
* ZANALYTICS-ORGID headers and a 20-second timeout.
|
|
23
|
+
*/
|
|
24
|
+
readonly fetchFactory?: ZohoAnalyticsFetchFactory;
|
|
25
|
+
/**
|
|
26
|
+
* Custom error logging function invoked when Zoho API errors are encountered.
|
|
27
|
+
*/
|
|
28
|
+
readonly logZohoServerErrorFunction?: LogZohoServerErrorFunction;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Factory function that creates a {@link ZohoAnalytics} client from a {@link ZohoAnalyticsConfig}.
|
|
32
|
+
*/
|
|
33
|
+
export type ZohoAnalyticsFactory = (config: ZohoAnalyticsConfig) => ZohoAnalytics;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a {@link ZohoAnalyticsFactory} from the given configuration.
|
|
36
|
+
*
|
|
37
|
+
* The factory pre-initializes shared resources (access token provider, rate limiter)
|
|
38
|
+
* once, then produces {@link ZohoAnalytics} client instances for each {@link ZohoAnalyticsConfig}.
|
|
39
|
+
* Each client handles OAuth token refresh on {@link ZohoInvalidTokenError}, rate limiting,
|
|
40
|
+
* and Zoho Analytics' failure envelope returned with a 200 status.
|
|
41
|
+
*
|
|
42
|
+
* Two details differ from the other Zoho services:
|
|
43
|
+
*
|
|
44
|
+
* - Analytics authorizes with the `Zoho-oauthtoken` scheme rather than `Bearer`.
|
|
45
|
+
* - The `ZANALYTICS-ORGID` header is only attached when the config carries an `orgId`, because
|
|
46
|
+
* `GET /orgs` is the bootstrap call that discovers it and is the one endpoint that does not
|
|
47
|
+
* require it.
|
|
48
|
+
*
|
|
49
|
+
* @param factoryConfig - Configuration providing account credentials and optional overrides.
|
|
50
|
+
* @returns A factory function that creates authenticated Zoho Analytics clients.
|
|
51
|
+
*
|
|
52
|
+
* @see https://www.zoho.com/analytics/api/v2/api-specification.html
|
|
53
|
+
*
|
|
54
|
+
* @__NO_SIDE_EFFECTS__
|
|
55
|
+
*/
|
|
56
|
+
export declare function zohoAnalyticsFactory(factoryConfig: ZohoAnalyticsFactoryConfig): ZohoAnalyticsFactory;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { type WebsiteUrl } from '@dereekb/util';
|
|
2
|
+
import { type ZohoAnalyticsName, type ZohoAnalyticsViewId } from './analytics';
|
|
3
|
+
import { type ZohoAnalyticsColumnDataType } from './analytics.view';
|
|
4
|
+
/**
|
|
5
|
+
* How an import combines incoming data with the rows already in the target table.
|
|
6
|
+
*
|
|
7
|
+
* - `append` adds the incoming rows, leaving existing rows untouched.
|
|
8
|
+
* - `truncateadd` deletes every existing row first, making the import a full replacement.
|
|
9
|
+
* - `updateadd` updates rows matching `matchingColumns` and inserts the rest.
|
|
10
|
+
*
|
|
11
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/import-data/existing-table.html
|
|
12
|
+
*/
|
|
13
|
+
export type ZohoAnalyticsImportType = 'append' | 'truncateadd' | 'updateadd';
|
|
14
|
+
/**
|
|
15
|
+
* Format of the data being imported.
|
|
16
|
+
*/
|
|
17
|
+
export type ZohoAnalyticsImportFileType = 'csv' | 'json';
|
|
18
|
+
/**
|
|
19
|
+
* What an import does when a row cannot be imported.
|
|
20
|
+
*
|
|
21
|
+
* - `abort` fails the whole import.
|
|
22
|
+
* - `skiprow` discards the offending row and continues.
|
|
23
|
+
* - `setcolumnempty` blanks the offending value and continues.
|
|
24
|
+
*/
|
|
25
|
+
export type ZohoAnalyticsImportOnError = 'abort' | 'skiprow' | 'setcolumnempty';
|
|
26
|
+
/**
|
|
27
|
+
* Thousand separator present in the imported data.
|
|
28
|
+
*
|
|
29
|
+
* `0` comma, `1` dot, `2` space, `3` single quote.
|
|
30
|
+
*/
|
|
31
|
+
export type ZohoAnalyticsThousandSeparator = 0 | 1 | 2 | 3;
|
|
32
|
+
/**
|
|
33
|
+
* Decimal separator present in the imported data. `0` dot, `1` comma.
|
|
34
|
+
*/
|
|
35
|
+
export type ZohoAnalyticsDecimalSeparator = 0 | 1;
|
|
36
|
+
/**
|
|
37
|
+
* Field delimiter of imported CSV data.
|
|
38
|
+
*
|
|
39
|
+
* `0` comma, `1` tab, `2` semicolon, `3` space.
|
|
40
|
+
*/
|
|
41
|
+
export type ZohoAnalyticsDelimiter = 0 | 1 | 2 | 3;
|
|
42
|
+
/**
|
|
43
|
+
* Text qualifier of imported CSV data.
|
|
44
|
+
*
|
|
45
|
+
* `0` none, `1` single quote, `2` double quote.
|
|
46
|
+
*/
|
|
47
|
+
export type ZohoAnalyticsQuoted = 0 | 1 | 2;
|
|
48
|
+
/**
|
|
49
|
+
* Explicit data type for a column being created by an import.
|
|
50
|
+
*/
|
|
51
|
+
export interface ZohoAnalyticsImportColumnDataType {
|
|
52
|
+
readonly columnName: ZohoAnalyticsName;
|
|
53
|
+
readonly dataType: ZohoAnalyticsColumnDataType;
|
|
54
|
+
readonly geoRole?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Import options shared by every import variant.
|
|
58
|
+
*
|
|
59
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/import-data/existing-table.html
|
|
60
|
+
*/
|
|
61
|
+
export interface ZohoAnalyticsImportBaseConfig {
|
|
62
|
+
readonly fileType?: ZohoAnalyticsImportFileType;
|
|
63
|
+
/**
|
|
64
|
+
* Whether Zoho should auto-identify the format of the incoming data.
|
|
65
|
+
*
|
|
66
|
+
* Required by every import endpoint, despite reading like an optimization: a CONFIG that omits it
|
|
67
|
+
* is rejected with error 8504, "The parameter CONFIG is not proper". The client therefore sends
|
|
68
|
+
* `true` when this is unset, so it only has to be given to opt out with `false`.
|
|
69
|
+
*/
|
|
70
|
+
readonly autoIdentify?: boolean;
|
|
71
|
+
readonly onError?: ZohoAnalyticsImportOnError;
|
|
72
|
+
/**
|
|
73
|
+
* Restricts the import to these columns.
|
|
74
|
+
*/
|
|
75
|
+
readonly selectedColumns?: ZohoAnalyticsName[];
|
|
76
|
+
/**
|
|
77
|
+
* Number of leading rows to skip.
|
|
78
|
+
*/
|
|
79
|
+
readonly skipTop?: number;
|
|
80
|
+
readonly thousandSeparator?: ZohoAnalyticsThousandSeparator;
|
|
81
|
+
readonly decimalSeparator?: ZohoAnalyticsDecimalSeparator;
|
|
82
|
+
/**
|
|
83
|
+
* Date format used by date columns that are not auto-detected, e.g. `'dd-MMM-YYYY'`.
|
|
84
|
+
*/
|
|
85
|
+
readonly dateFormat?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Per-column date formats, keyed by column name.
|
|
88
|
+
*/
|
|
89
|
+
readonly columnDateFormat?: Record<ZohoAnalyticsName, string>;
|
|
90
|
+
/**
|
|
91
|
+
* Rows beginning with this single character are skipped.
|
|
92
|
+
*/
|
|
93
|
+
readonly commentChar?: string;
|
|
94
|
+
readonly delimiter?: ZohoAnalyticsDelimiter;
|
|
95
|
+
readonly quoted?: ZohoAnalyticsQuoted;
|
|
96
|
+
readonly retainColumnNames?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Import options for importing into an existing table.
|
|
100
|
+
*/
|
|
101
|
+
export interface ZohoAnalyticsImportConfig extends ZohoAnalyticsImportBaseConfig {
|
|
102
|
+
readonly importType: ZohoAnalyticsImportType;
|
|
103
|
+
/**
|
|
104
|
+
* Columns used to match incoming rows against existing ones.
|
|
105
|
+
*
|
|
106
|
+
* Required when `importType` is `'updateadd'`.
|
|
107
|
+
*/
|
|
108
|
+
readonly matchingColumns?: ZohoAnalyticsName[];
|
|
109
|
+
/**
|
|
110
|
+
* Explicit data types for columns added by this import.
|
|
111
|
+
*/
|
|
112
|
+
readonly columnDataTypes?: ZohoAnalyticsImportColumnDataType[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Import options for creating a new table from the imported data.
|
|
116
|
+
*
|
|
117
|
+
* There is no `importType` here: a new table has nothing to append to or replace.
|
|
118
|
+
*/
|
|
119
|
+
export interface ZohoAnalyticsImportNewTableConfig extends ZohoAnalyticsImportBaseConfig {
|
|
120
|
+
/**
|
|
121
|
+
* Name of the table to create.
|
|
122
|
+
*/
|
|
123
|
+
readonly tableName: ZohoAnalyticsName;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Options accepted only by the asynchronous import job and batch import endpoints.
|
|
127
|
+
*/
|
|
128
|
+
export interface ZohoAnalyticsImportJobConfigOptions {
|
|
129
|
+
/**
|
|
130
|
+
* URL that Zoho posts the job's completion status to.
|
|
131
|
+
*/
|
|
132
|
+
readonly callbackUrl?: WebsiteUrl;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Import options for an asynchronous import job into an existing table.
|
|
136
|
+
*/
|
|
137
|
+
export interface ZohoAnalyticsImportJobConfig extends ZohoAnalyticsImportConfig, ZohoAnalyticsImportJobConfigOptions {
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Import options for an asynchronous import job that creates a new table.
|
|
141
|
+
*/
|
|
142
|
+
export interface ZohoAnalyticsImportJobNewTableConfig extends ZohoAnalyticsImportNewTableConfig, ZohoAnalyticsImportJobConfigOptions {
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Summary of what an import actually did.
|
|
146
|
+
*
|
|
147
|
+
* Compare `successRowCount` against `totalRowCount`: an import can report success overall while
|
|
148
|
+
* silently rejecting individual rows.
|
|
149
|
+
*/
|
|
150
|
+
export interface ZohoAnalyticsImportSummary {
|
|
151
|
+
readonly importType?: string;
|
|
152
|
+
readonly totalColumnCount?: number;
|
|
153
|
+
readonly selectedColumnCount?: number;
|
|
154
|
+
readonly totalRowCount?: number;
|
|
155
|
+
readonly successRowCount?: number;
|
|
156
|
+
readonly warnings?: number;
|
|
157
|
+
readonly importOperation?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Payload returned by a completed import.
|
|
161
|
+
*
|
|
162
|
+
* A response with `status: 'success'` can still describe partially rejected data — always inspect
|
|
163
|
+
* `importSummary` and `importErrors` rather than treating success as "every row landed".
|
|
164
|
+
*/
|
|
165
|
+
export interface ZohoAnalyticsImportResult {
|
|
166
|
+
readonly importSummary: ZohoAnalyticsImportSummary;
|
|
167
|
+
/**
|
|
168
|
+
* Resolved data type of each imported column, keyed by column name.
|
|
169
|
+
*/
|
|
170
|
+
readonly columnDetails?: Record<ZohoAnalyticsName, string>;
|
|
171
|
+
/**
|
|
172
|
+
* Description of the rows or columns that failed to import. Empty when nothing was rejected.
|
|
173
|
+
*/
|
|
174
|
+
readonly importErrors?: string;
|
|
175
|
+
readonly viewId?: ZohoAnalyticsViewId;
|
|
176
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type Milliseconds } from '@dereekb/util';
|
|
2
|
+
import { type ZohoAnalyticsJobId, type ZohoAnalyticsTimestampString } from './analytics';
|
|
3
|
+
/**
|
|
4
|
+
* Status code of an asynchronous Zoho Analytics import or export job.
|
|
5
|
+
*
|
|
6
|
+
* Returned as a string even though the values are numeric.
|
|
7
|
+
*
|
|
8
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/export-data-async/get-export.html
|
|
9
|
+
*/
|
|
10
|
+
export type ZohoAnalyticsJobCode = string;
|
|
11
|
+
/**
|
|
12
|
+
* The job has been accepted but has not started yet. Keep polling.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ZOHO_ANALYTICS_JOB_CODE_NOT_INITIATED: ZohoAnalyticsJobCode;
|
|
15
|
+
/**
|
|
16
|
+
* The job is running. Keep polling.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ZOHO_ANALYTICS_JOB_CODE_IN_PROGRESS: ZohoAnalyticsJobCode;
|
|
19
|
+
/**
|
|
20
|
+
* The job failed.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ZOHO_ANALYTICS_JOB_CODE_ERROR: ZohoAnalyticsJobCode;
|
|
23
|
+
/**
|
|
24
|
+
* The job finished successfully. Export results can now be downloaded.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ZOHO_ANALYTICS_JOB_CODE_COMPLETED: ZohoAnalyticsJobCode;
|
|
27
|
+
/**
|
|
28
|
+
* No job exists for the given id.
|
|
29
|
+
*
|
|
30
|
+
* Declared by Zoho but not observed in practice: asking for a job that does not exist throws a 404
|
|
31
|
+
* (error 8120 for an export job, 8137 for an import job) rather than resolving with this code, so
|
|
32
|
+
* polling never terminates on it. Verified against the live API.
|
|
33
|
+
*/
|
|
34
|
+
export declare const ZOHO_ANALYTICS_JOB_CODE_NOT_FOUND: ZohoAnalyticsJobCode;
|
|
35
|
+
/**
|
|
36
|
+
* Maximum number of concurrent import jobs, and separately export jobs, allowed per organization.
|
|
37
|
+
*
|
|
38
|
+
* @see https://www.zoho.com/analytics/api/v2/bulk-api/import-data-async/create-import-job/existing-table.html
|
|
39
|
+
*/
|
|
40
|
+
export declare const ZOHO_ANALYTICS_MAX_CONCURRENT_JOBS = 5;
|
|
41
|
+
/**
|
|
42
|
+
* Default interval between Zoho Analytics job status checks.
|
|
43
|
+
*
|
|
44
|
+
* Checking job status costs zero API units, so polling is inexpensive; the interval exists to stay
|
|
45
|
+
* within the request frequency limit.
|
|
46
|
+
*
|
|
47
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-units.html
|
|
48
|
+
*/
|
|
49
|
+
export declare const DEFAULT_ZOHO_ANALYTICS_JOB_POLL_WAIT: Milliseconds;
|
|
50
|
+
/**
|
|
51
|
+
* Default maximum number of Zoho Analytics job status checks before giving up.
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_ZOHO_ANALYTICS_JOB_MAX_POLLS = 150;
|
|
54
|
+
/**
|
|
55
|
+
* Common shape of an asynchronous Zoho Analytics job status.
|
|
56
|
+
*/
|
|
57
|
+
export interface ZohoAnalyticsJobStatus {
|
|
58
|
+
readonly jobId: ZohoAnalyticsJobId;
|
|
59
|
+
readonly jobCode: ZohoAnalyticsJobCode;
|
|
60
|
+
/**
|
|
61
|
+
* Epoch milliseconds at which the job's result stops being retrievable, roughly an hour after
|
|
62
|
+
* completion.
|
|
63
|
+
*
|
|
64
|
+
* Returned by import jobs as well as export jobs, despite being documented only for exports.
|
|
65
|
+
*/
|
|
66
|
+
readonly expiryTime?: ZohoAnalyticsTimestampString;
|
|
67
|
+
/**
|
|
68
|
+
* Human-readable status, e.g. `'JOB COMPLETED'`.
|
|
69
|
+
*/
|
|
70
|
+
readonly jobStatus: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns true while the job is still queued or running and should continue to be polled.
|
|
74
|
+
*
|
|
75
|
+
* @param jobCode - The job's current status code.
|
|
76
|
+
* @returns Whether the job has not yet reached a terminal state.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isZohoAnalyticsJobPending(jobCode: ZohoAnalyticsJobCode): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Returns true when the job finished successfully.
|
|
81
|
+
*
|
|
82
|
+
* @param jobCode - The job's current status code.
|
|
83
|
+
* @returns Whether the job completed.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isZohoAnalyticsJobComplete(jobCode: ZohoAnalyticsJobCode): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Returns true when the job reached a terminal failure, either erroring or not existing.
|
|
88
|
+
*
|
|
89
|
+
* In practice only {@link ZOHO_ANALYTICS_JOB_CODE_ERROR} is reachable through the job endpoints: an
|
|
90
|
+
* unknown job id throws rather than reporting {@link ZOHO_ANALYTICS_JOB_CODE_NOT_FOUND}.
|
|
91
|
+
*
|
|
92
|
+
* @param jobCode - The job's current status code.
|
|
93
|
+
* @returns Whether the job failed.
|
|
94
|
+
*/
|
|
95
|
+
export declare function isZohoAnalyticsJobError(jobCode: ZohoAnalyticsJobCode): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Configuration for {@link pollZohoAnalyticsJob}.
|
|
98
|
+
*/
|
|
99
|
+
export interface PollZohoAnalyticsJobConfig<T> {
|
|
100
|
+
/**
|
|
101
|
+
* Loads the job's current status.
|
|
102
|
+
*/
|
|
103
|
+
readonly loadJob: () => Promise<T>;
|
|
104
|
+
/**
|
|
105
|
+
* Reads the status code from a loaded job.
|
|
106
|
+
*/
|
|
107
|
+
readonly readJobCode: (job: T) => ZohoAnalyticsJobCode;
|
|
108
|
+
/**
|
|
109
|
+
* Milliseconds to wait between status checks.
|
|
110
|
+
*
|
|
111
|
+
* Defaults to {@link DEFAULT_ZOHO_ANALYTICS_JOB_POLL_WAIT}.
|
|
112
|
+
*/
|
|
113
|
+
readonly pollWait?: Milliseconds;
|
|
114
|
+
/**
|
|
115
|
+
* Maximum number of status checks before returning the last observed job.
|
|
116
|
+
*
|
|
117
|
+
* Defaults to {@link DEFAULT_ZOHO_ANALYTICS_JOB_MAX_POLLS}.
|
|
118
|
+
*/
|
|
119
|
+
readonly maxPolls?: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Polls an asynchronous Zoho Analytics job until it reaches a terminal state.
|
|
123
|
+
*
|
|
124
|
+
* Resolves with the last observed job, whether it completed, errored, or the poll budget ran out.
|
|
125
|
+
* Inspect the returned job's code with {@link isZohoAnalyticsJobComplete} and
|
|
126
|
+
* {@link isZohoAnalyticsJobError} — a job still pending on return means the budget was exhausted
|
|
127
|
+
* rather than that it failed.
|
|
128
|
+
*
|
|
129
|
+
* @param config - The job loader, status reader, and polling budget.
|
|
130
|
+
* @returns The last observed job status.
|
|
131
|
+
*/
|
|
132
|
+
export declare function pollZohoAnalyticsJob<T>(config: PollZohoAnalyticsJobConfig<T>): Promise<T>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type ZohoRateLimitedFetchHandler, type ZohoRateLimitedFetchHandlerConfig } from '../zoho.limit';
|
|
3
|
+
/**
|
|
4
|
+
* Overall Zoho Analytics API request limit per minute, across every API type.
|
|
5
|
+
*
|
|
6
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-frequency.html
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_ZOHO_ANALYTICS_API_RATE_LIMIT = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Per-minute request limit for Zoho Analytics bulk (import/export) operations.
|
|
11
|
+
*
|
|
12
|
+
* Pass this as `maxRateLimit` for a client dedicated to bulk work.
|
|
13
|
+
*
|
|
14
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-frequency.html
|
|
15
|
+
*/
|
|
16
|
+
export declare const ZOHO_ANALYTICS_BULK_API_RATE_LIMIT = 40;
|
|
17
|
+
/**
|
|
18
|
+
* Per-minute request limit for Zoho Analytics metadata operations.
|
|
19
|
+
*
|
|
20
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-frequency.html
|
|
21
|
+
*/
|
|
22
|
+
export declare const ZOHO_ANALYTICS_METADATA_API_RATE_LIMIT = 60;
|
|
23
|
+
/**
|
|
24
|
+
* Per-minute request limit for Zoho Analytics DML (row-level) operations.
|
|
25
|
+
*
|
|
26
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-frequency.html
|
|
27
|
+
*/
|
|
28
|
+
export declare const ZOHO_ANALYTICS_DML_API_RATE_LIMIT = 100;
|
|
29
|
+
/**
|
|
30
|
+
* Reset period for the Zoho Analytics request frequency limit.
|
|
31
|
+
*/
|
|
32
|
+
export declare const ZOHO_ANALYTICS_API_RATE_LIMIT_RESET_PERIOD: number;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a {@link ZohoRateLimitedFetchHandler} configured for Zoho Analytics' documented request
|
|
35
|
+
* frequency limit.
|
|
36
|
+
*
|
|
37
|
+
* Zoho Analytics documents a fixed limit but returns no rate limit headers at all, and does not
|
|
38
|
+
* document a status code for a throttled request — throttling is reported as error code `6045`
|
|
39
|
+
* (per-minute) or `6043`/`6044` (daily unit quota) inside the response body, which this handler
|
|
40
|
+
* cannot inspect without consuming it. The limiter therefore runs in self-counting mode via
|
|
41
|
+
* `enabledWithoutRateLimitDetails`, pacing requests against {@link DEFAULT_ZOHO_ANALYTICS_API_RATE_LIMIT}
|
|
42
|
+
* rather than synchronizing with the server.
|
|
43
|
+
*
|
|
44
|
+
* The standard `X-RATELIMIT-*` reader is still supplied so that the limiter synchronizes
|
|
45
|
+
* automatically should Analytics begin returning those headers.
|
|
46
|
+
*
|
|
47
|
+
* Throttling that does slip through is surfaced to callers as a `ZohoTooManyRequestsError` by
|
|
48
|
+
* the Analytics error parser.
|
|
49
|
+
*
|
|
50
|
+
* @param config - Optional configuration for rate limit, reset period, and 429 handling.
|
|
51
|
+
* @returns A rate-limited fetch handler with the underlying rate limiter accessible via `_rateLimiter`
|
|
52
|
+
*
|
|
53
|
+
* @see https://www.zoho.com/analytics/api/v2/api-limits-pricing/api-frequency.html
|
|
54
|
+
*/
|
|
55
|
+
export declare function zohoAnalyticsRateLimitedFetchHandler(config?: Maybe<ZohoRateLimitedFetchHandlerConfig>): ZohoRateLimitedFetchHandler;
|