@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.
Files changed (35) hide show
  1. package/cli/index.js +7 -5
  2. package/cli/package.json +7 -7
  3. package/index.esm.js +3354 -556
  4. package/nestjs/docs/analytics-testing.md +202 -0
  5. package/nestjs/index.esm.js +867 -268
  6. package/nestjs/package.json +5 -5
  7. package/nestjs/src/lib/analytics/analytics.api.d.ts +236 -0
  8. package/nestjs/src/lib/analytics/analytics.config.d.ts +24 -0
  9. package/nestjs/src/lib/analytics/analytics.module.d.ts +65 -0
  10. package/nestjs/src/lib/analytics/index.d.ts +3 -0
  11. package/nestjs/src/lib/index.d.ts +1 -0
  12. package/package.json +8 -8
  13. package/src/lib/analytics/analytics.api.export.d.ts +167 -0
  14. package/src/lib/analytics/analytics.api.import.d.ts +252 -0
  15. package/src/lib/analytics/analytics.api.modeling.d.ts +106 -0
  16. package/src/lib/analytics/analytics.api.orgs.d.ts +36 -0
  17. package/src/lib/analytics/analytics.api.rows.d.ts +214 -0
  18. package/src/lib/analytics/analytics.api.views.d.ts +104 -0
  19. package/src/lib/analytics/analytics.api.workspaces.d.ts +96 -0
  20. package/src/lib/analytics/analytics.config.d.ts +92 -0
  21. package/src/lib/analytics/analytics.d.ts +86 -0
  22. package/src/lib/analytics/analytics.data.d.ts +74 -0
  23. package/src/lib/analytics/analytics.diff.d.ts +178 -0
  24. package/src/lib/analytics/analytics.error.api.d.ts +150 -0
  25. package/src/lib/analytics/analytics.export.d.ts +91 -0
  26. package/src/lib/analytics/analytics.factory.d.ts +56 -0
  27. package/src/lib/analytics/analytics.import.d.ts +176 -0
  28. package/src/lib/analytics/analytics.job.d.ts +132 -0
  29. package/src/lib/analytics/analytics.limit.d.ts +55 -0
  30. package/src/lib/analytics/analytics.org.d.ts +51 -0
  31. package/src/lib/analytics/analytics.param.d.ts +70 -0
  32. package/src/lib/analytics/analytics.view.d.ts +99 -0
  33. package/src/lib/analytics/index.d.ts +20 -0
  34. package/src/lib/index.d.ts +1 -0
  35. package/src/lib/zoho.limit.d.ts +14 -1
@@ -0,0 +1,104 @@
1
+ import { type ZohoAnalyticsResponse, type ZohoAnalyticsViewId, type ZohoAnalyticsWorkspaceId } from './analytics';
2
+ import { type ZohoAnalyticsContext } from './analytics.config';
3
+ import { type ZohoAnalyticsColumn, type ZohoAnalyticsView, type ZohoAnalyticsViewDetails } from './analytics.view';
4
+ /**
5
+ * Input for listing the views of a workspace.
6
+ */
7
+ export interface ZohoAnalyticsGetViewsInput {
8
+ readonly workspaceId: ZohoAnalyticsWorkspaceId;
9
+ }
10
+ /**
11
+ * Payload of a {@link ZohoAnalyticsGetViewsResponse}.
12
+ */
13
+ export interface ZohoAnalyticsGetViewsResponseData {
14
+ readonly views: ZohoAnalyticsView[];
15
+ }
16
+ /**
17
+ * Response for `GET /workspaces/{workspaceId}/views`.
18
+ */
19
+ export type ZohoAnalyticsGetViewsResponse = ZohoAnalyticsResponse<ZohoAnalyticsGetViewsResponseData>;
20
+ /**
21
+ * Lists the views of a workspace.
22
+ */
23
+ export type ZohoAnalyticsGetViewsFunction = (input: ZohoAnalyticsGetViewsInput) => Promise<ZohoAnalyticsGetViewsResponse>;
24
+ /**
25
+ * Creates a {@link ZohoAnalyticsGetViewsFunction} bound to the given context.
26
+ *
27
+ * This endpoint is not paginated — Zoho's OpenAPI specification declares no parameters for it, so
28
+ * the full set of views is always returned.
29
+ *
30
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
31
+ * @returns Function that lists every view in a workspace.
32
+ *
33
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/get-views.html
34
+ */
35
+ export declare function zohoAnalyticsGetViews(context: ZohoAnalyticsContext): ZohoAnalyticsGetViewsFunction;
36
+ /**
37
+ * Input for retrieving a single view's details.
38
+ */
39
+ export interface ZohoAnalyticsGetViewDetailsInput {
40
+ readonly viewId: ZohoAnalyticsViewId;
41
+ }
42
+ /**
43
+ * Payload of a {@link ZohoAnalyticsGetViewDetailsResponse}.
44
+ *
45
+ * The key is plural but holds a single view object.
46
+ */
47
+ export interface ZohoAnalyticsGetViewDetailsResponseData {
48
+ readonly views: ZohoAnalyticsViewDetails;
49
+ }
50
+ /**
51
+ * Response for `GET /views/{viewId}`.
52
+ */
53
+ export type ZohoAnalyticsGetViewDetailsResponse = ZohoAnalyticsResponse<ZohoAnalyticsGetViewDetailsResponseData>;
54
+ /**
55
+ * Retrieves the details of a single view.
56
+ */
57
+ export type ZohoAnalyticsGetViewDetailsFunction = (input: ZohoAnalyticsGetViewDetailsInput) => Promise<ZohoAnalyticsGetViewDetailsResponse>;
58
+ /**
59
+ * Creates a {@link ZohoAnalyticsGetViewDetailsFunction} bound to the given context.
60
+ *
61
+ * Unlike the view listing, this endpoint is not workspace-scoped: view ids are globally unique, so
62
+ * the path is `/views/{viewId}` rather than `/workspaces/{workspaceId}/views/{viewId}`. It returns a
63
+ * different field set than the listing rather than a superset — see {@link ZohoAnalyticsViewDetails}.
64
+ * Both endpoints report `viewType` in the same mixed case (`'Table'`), verified live.
65
+ *
66
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
67
+ * @returns Function that retrieves a view by id.
68
+ *
69
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/view-details.html
70
+ */
71
+ export declare function zohoAnalyticsGetViewDetails(context: ZohoAnalyticsContext): ZohoAnalyticsGetViewDetailsFunction;
72
+ /**
73
+ * Input for retrieving the column metadata of a table.
74
+ */
75
+ export interface ZohoAnalyticsGetTableMetadataInput {
76
+ readonly workspaceId: ZohoAnalyticsWorkspaceId;
77
+ readonly viewId: ZohoAnalyticsViewId;
78
+ }
79
+ /**
80
+ * Payload of a {@link ZohoAnalyticsGetTableMetadataResponse}.
81
+ */
82
+ export interface ZohoAnalyticsGetTableMetadataResponseData {
83
+ readonly columns: ZohoAnalyticsColumn[];
84
+ }
85
+ /**
86
+ * Response for `GET /workspaces/{workspaceId}/views/{viewId}/metadata`.
87
+ */
88
+ export type ZohoAnalyticsGetTableMetadataResponse = ZohoAnalyticsResponse<ZohoAnalyticsGetTableMetadataResponseData>;
89
+ /**
90
+ * Retrieves the column metadata of a table.
91
+ */
92
+ export type ZohoAnalyticsGetTableMetadataFunction = (input: ZohoAnalyticsGetTableMetadataInput) => Promise<ZohoAnalyticsGetTableMetadataResponse>;
93
+ /**
94
+ * Creates a {@link ZohoAnalyticsGetTableMetadataFunction} bound to the given context.
95
+ *
96
+ * Use this before an import to confirm the target table's column names, since an import matches
97
+ * incoming data to columns by name.
98
+ *
99
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
100
+ * @returns Function that retrieves a table's column metadata.
101
+ *
102
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/get-table-metadata.html
103
+ */
104
+ export declare function zohoAnalyticsGetTableMetadata(context: ZohoAnalyticsContext): ZohoAnalyticsGetTableMetadataFunction;
@@ -0,0 +1,96 @@
1
+ import { type ZohoAnalyticsResponse, type ZohoAnalyticsWorkspaceId } from './analytics';
2
+ import { type ZohoAnalyticsContext } from './analytics.config';
3
+ import { type ZohoAnalyticsWorkspace, type ZohoAnalyticsWorkspaceSummary } from './analytics.org';
4
+ /**
5
+ * Payload of a {@link ZohoAnalyticsGetAllWorkspacesResponse}.
6
+ *
7
+ * `GET /workspaces` splits its result into owned and shared workspaces, unlike the
8
+ * `/workspaces/owned` and `/workspaces/shared` endpoints which each return a single
9
+ * `workspaces` array.
10
+ */
11
+ export interface ZohoAnalyticsGetAllWorkspacesResponseData {
12
+ readonly ownedWorkspaces: ZohoAnalyticsWorkspaceSummary[];
13
+ readonly sharedWorkspaces: ZohoAnalyticsWorkspaceSummary[];
14
+ }
15
+ /**
16
+ * Response for `GET /workspaces`.
17
+ */
18
+ export type ZohoAnalyticsGetAllWorkspacesResponse = ZohoAnalyticsResponse<ZohoAnalyticsGetAllWorkspacesResponseData>;
19
+ /**
20
+ * Lists every workspace the authenticated user can access, grouped by ownership.
21
+ */
22
+ export type ZohoAnalyticsGetAllWorkspacesFunction = () => Promise<ZohoAnalyticsGetAllWorkspacesResponse>;
23
+ /**
24
+ * Creates a {@link ZohoAnalyticsGetAllWorkspacesFunction} bound to the given context.
25
+ *
26
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
27
+ * @returns Function that lists all accessible workspaces, grouped into owned and shared.
28
+ *
29
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/all-workspace.html
30
+ */
31
+ export declare function zohoAnalyticsGetAllWorkspaces(context: ZohoAnalyticsContext): ZohoAnalyticsGetAllWorkspacesFunction;
32
+ /**
33
+ * Payload of a workspace listing that returns a single flat array.
34
+ */
35
+ export interface ZohoAnalyticsGetWorkspacesResponseData {
36
+ readonly workspaces: ZohoAnalyticsWorkspaceSummary[];
37
+ }
38
+ /**
39
+ * Response for `GET /workspaces/owned` and `GET /workspaces/shared`.
40
+ */
41
+ export type ZohoAnalyticsGetWorkspacesResponse = ZohoAnalyticsResponse<ZohoAnalyticsGetWorkspacesResponseData>;
42
+ /**
43
+ * Lists a single category of workspaces.
44
+ */
45
+ export type ZohoAnalyticsGetWorkspacesFunction = () => Promise<ZohoAnalyticsGetWorkspacesResponse>;
46
+ /**
47
+ * Creates a {@link ZohoAnalyticsGetWorkspacesFunction} for the workspaces owned by the
48
+ * authenticated user.
49
+ *
50
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
51
+ * @returns Function that lists the owned workspaces.
52
+ *
53
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/owned-workspace.html
54
+ */
55
+ export declare function zohoAnalyticsGetOwnedWorkspaces(context: ZohoAnalyticsContext): ZohoAnalyticsGetWorkspacesFunction;
56
+ /**
57
+ * Creates a {@link ZohoAnalyticsGetWorkspacesFunction} for the workspaces shared with the
58
+ * authenticated user.
59
+ *
60
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
61
+ * @returns Function that lists the shared workspaces.
62
+ *
63
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/shared-workspace.html
64
+ */
65
+ export declare function zohoAnalyticsGetSharedWorkspaces(context: ZohoAnalyticsContext): ZohoAnalyticsGetWorkspacesFunction;
66
+ /**
67
+ * Input for retrieving a single workspace's details.
68
+ */
69
+ export interface ZohoAnalyticsGetWorkspaceDetailsInput {
70
+ readonly workspaceId: ZohoAnalyticsWorkspaceId;
71
+ }
72
+ /**
73
+ * Payload of a {@link ZohoAnalyticsGetWorkspaceDetailsResponse}.
74
+ *
75
+ * The key is plural but holds a single workspace object.
76
+ */
77
+ export interface ZohoAnalyticsGetWorkspaceDetailsResponseData {
78
+ readonly workspaces: ZohoAnalyticsWorkspace;
79
+ }
80
+ /**
81
+ * Response for `GET /workspaces/{workspaceId}`.
82
+ */
83
+ export type ZohoAnalyticsGetWorkspaceDetailsResponse = ZohoAnalyticsResponse<ZohoAnalyticsGetWorkspaceDetailsResponseData>;
84
+ /**
85
+ * Retrieves the details of a single workspace.
86
+ */
87
+ export type ZohoAnalyticsGetWorkspaceDetailsFunction = (input: ZohoAnalyticsGetWorkspaceDetailsInput) => Promise<ZohoAnalyticsGetWorkspaceDetailsResponse>;
88
+ /**
89
+ * Creates a {@link ZohoAnalyticsGetWorkspaceDetailsFunction} bound to the given context.
90
+ *
91
+ * @param context - Authenticated Zoho Analytics context providing fetch and rate limiting.
92
+ * @returns Function that retrieves a workspace by id.
93
+ *
94
+ * @see https://www.zoho.com/analytics/api/v2/metadata-api/workspace-details.html
95
+ */
96
+ export declare function zohoAnalyticsGetWorkspaceDetails(context: ZohoAnalyticsContext): ZohoAnalyticsGetWorkspaceDetailsFunction;
@@ -0,0 +1,92 @@
1
+ import { type FactoryWithRequiredInput, type Maybe } from '@dereekb/util';
2
+ import { type ConfiguredFetch, type FetchJsonFunction } from '@dereekb/util/fetch';
3
+ import { type ZohoApiUrl, type ZohoApiUrlKey, type ZohoConfig, type ZohoApiServiceName } from '../zoho.config';
4
+ import { type ZohoAccessTokenStringFactory, type ZohoServiceAccessTokenKey } from '../accounts';
5
+ import { type ZohoRateLimiterRef } from '../zoho.limit';
6
+ import { type ZohoAnalyticsOrgId } from './analytics';
7
+ /**
8
+ * Service identifier used for Zoho Analytics API access token resolution and service routing.
9
+ */
10
+ export declare const ZOHO_ANALYTICS_SERVICE_NAME: ZohoApiServiceName | ZohoServiceAccessTokenKey;
11
+ /**
12
+ * Header that carries the {@link ZohoAnalyticsOrgId} on Zoho Analytics API requests.
13
+ *
14
+ * Required by every endpoint except `GET /orgs`.
15
+ *
16
+ * @see https://www.zoho.com/analytics/api/v2/api-specification.html
17
+ */
18
+ export declare const ZOHO_ANALYTICS_ORG_ID_HEADER = "ZANALYTICS-ORGID";
19
+ /**
20
+ * Full base URL for the Zoho Analytics API.
21
+ */
22
+ export type ZohoAnalyticsApiUrl = ZohoApiUrl;
23
+ /**
24
+ * Well-known environment key for selecting a Zoho Analytics API endpoint.
25
+ *
26
+ * Zoho Analytics has no documented sandbox environment, so only 'production' is a known key.
27
+ * Custom URLs — including the regional variants below — can be passed directly.
28
+ *
29
+ * Zoho Analytics is served from eight data centers, each with its own host:
30
+ * `analyticsapi.zoho.com` (US), `.eu`, `.in`, `.com.au`, `.com.cn`, `.jp`, `.sa`, and
31
+ * `analyticsapi.zohocloud.ca` (CA). Pass the full URL for any non-US data center.
32
+ *
33
+ * @see https://www.zoho.com/analytics/api/v2/api-specification.html
34
+ */
35
+ export type ZohoAnalyticsApiUrlKey = ZohoApiUrlKey;
36
+ /**
37
+ * Accepts either a well-known environment key or a custom full URL, allowing callers to target
38
+ * production or an arbitrary Analytics endpoint (e.g., regional variants).
39
+ */
40
+ export type ZohoAnalyticsConfigApiUrlInput = ZohoAnalyticsApiUrlKey | ZohoAnalyticsApiUrl;
41
+ /**
42
+ * Resolves an Analytics API URL input to its full base URL. The 'production' key maps to the
43
+ * primary US Zoho Analytics endpoint; custom URLs pass through unchanged.
44
+ *
45
+ * @param input - A well-known environment key or a custom Analytics API URL.
46
+ * @returns The resolved full Zoho Analytics API base URL.
47
+ */
48
+ export declare function zohoAnalyticsConfigApiUrl(input: ZohoAnalyticsConfigApiUrlInput): ZohoApiUrl;
49
+ /**
50
+ * Configuration for a Zoho Analytics service instance, including the target API URL and organization ID.
51
+ *
52
+ * Unlike Zoho Desk — where the org id is required — the Analytics org id is optional, because
53
+ * `GET /orgs` is the bootstrap call that discovers it and is the one endpoint that does not
54
+ * require the {@link ZOHO_ANALYTICS_ORG_ID_HEADER}.
55
+ */
56
+ export interface ZohoAnalyticsConfig extends ZohoConfig {
57
+ /**
58
+ * Organization ID sent as the `ZANALYTICS-ORGID` header.
59
+ *
60
+ * Optional so that a client can be created before the org id is known; every endpoint other
61
+ * than `GET /orgs` will fail without it.
62
+ */
63
+ readonly orgId?: Maybe<ZohoAnalyticsOrgId>;
64
+ }
65
+ /**
66
+ * Input provided to an Analytics fetch factory to construct an authenticated fetch instance for a specific API base URL.
67
+ */
68
+ export interface ZohoAnalyticsFetchFactoryParams {
69
+ readonly apiUrl: ZohoAnalyticsApiUrl;
70
+ readonly orgId?: Maybe<ZohoAnalyticsOrgId>;
71
+ }
72
+ /**
73
+ * Factory that produces a pre-configured fetch instance bound to a specific Zoho Analytics API URL and organization.
74
+ */
75
+ export type ZohoAnalyticsFetchFactory = FactoryWithRequiredInput<ConfiguredFetch, ZohoAnalyticsFetchFactoryParams>;
76
+ /**
77
+ * Core context for making authenticated Zoho Analytics API calls. Bundles the configured fetch,
78
+ * JSON parsing, access token management, rate limiting, and service configuration needed
79
+ * by all Analytics operations.
80
+ */
81
+ export interface ZohoAnalyticsContext extends ZohoRateLimiterRef {
82
+ readonly fetch: ConfiguredFetch;
83
+ readonly fetchJson: FetchJsonFunction;
84
+ readonly accessTokenStringFactory: ZohoAccessTokenStringFactory;
85
+ readonly config: ZohoAnalyticsConfig;
86
+ }
87
+ /**
88
+ * Reference wrapper providing access to a {@link ZohoAnalyticsContext}. Used for dependency injection across Analytics service consumers.
89
+ */
90
+ export interface ZohoAnalyticsContextRef {
91
+ readonly analyticsContext: ZohoAnalyticsContext;
92
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Identifier of a Zoho Analytics organization.
3
+ *
4
+ * Sent as the `ZANALYTICS-ORGID` header on every request except `GET /orgs`, which is
5
+ * the bootstrap call used to discover it.
6
+ */
7
+ export type ZohoAnalyticsOrgId = string;
8
+ /**
9
+ * Generic identifier in Zoho Analytics.
10
+ */
11
+ export type ZohoAnalyticsId = string;
12
+ /**
13
+ * Identifier of a workspace in Zoho Analytics.
14
+ */
15
+ export type ZohoAnalyticsWorkspaceId = string;
16
+ /**
17
+ * Identifier of a view in Zoho Analytics.
18
+ *
19
+ * A view is any of a table, query table, dashboard, or report. View ids are globally
20
+ * unique, which is why `GET /views/{viewId}` is not workspace-scoped.
21
+ */
22
+ export type ZohoAnalyticsViewId = string;
23
+ /**
24
+ * Identifier of a column within a Zoho Analytics view.
25
+ */
26
+ export type ZohoAnalyticsColumnId = string;
27
+ /**
28
+ * Identifier of a folder in a Zoho Analytics workspace.
29
+ */
30
+ export type ZohoAnalyticsFolderId = string;
31
+ /**
32
+ * Identifier of an asynchronous import or export job in Zoho Analytics.
33
+ */
34
+ export type ZohoAnalyticsJobId = string;
35
+ /**
36
+ * Key that chains together the requests of a batch import.
37
+ *
38
+ * The first request of a batch sends the literal `'start'`, and the response returns the
39
+ * generated key that every subsequent request in the batch must echo back.
40
+ */
41
+ export type ZohoAnalyticsBatchKey = string;
42
+ /**
43
+ * Sentinel {@link ZohoAnalyticsBatchKey} that begins a new batch import.
44
+ */
45
+ export declare const ZOHO_ANALYTICS_BATCH_KEY_START: ZohoAnalyticsBatchKey;
46
+ /**
47
+ * Name of a table or column in Zoho Analytics.
48
+ */
49
+ export type ZohoAnalyticsName = string;
50
+ /**
51
+ * A row of data in a Zoho Analytics table, keyed by column name.
52
+ */
53
+ export type ZohoAnalyticsRow = Record<ZohoAnalyticsName, unknown>;
54
+ /**
55
+ * A raw filter expression evaluated by Zoho Analytics against a view.
56
+ *
57
+ * The syntax is a SQL-like boolean expression over quoted table and column names, for
58
+ * example `"Sales"."Region"='West'`. There is no structured alternative, so callers build
59
+ * and escape this string themselves.
60
+ *
61
+ * @see https://www.zoho.com/analytics/api/v2/bulk-api/export-data.html
62
+ */
63
+ export type ZohoAnalyticsCriteria = string;
64
+ /**
65
+ * Standard envelope wrapping every Zoho Analytics API response.
66
+ *
67
+ * Successful responses carry `status: 'success'`; failures use the same envelope with
68
+ * `status: 'failure'` and are converted into thrown errors by the Analytics error parser.
69
+ *
70
+ * @see https://www.zoho.com/analytics/api/v2/api-specification.html
71
+ */
72
+ export interface ZohoAnalyticsResponse<T> {
73
+ /**
74
+ * `'success'` on a successful call.
75
+ */
76
+ readonly status: string;
77
+ /**
78
+ * Human-readable description of the operation performed, e.g. `'Get all workspaces'`.
79
+ */
80
+ readonly summary: string;
81
+ readonly data: T;
82
+ }
83
+ /**
84
+ * Epoch milliseconds returned by Zoho Analytics as a string, e.g. `'1548914379156'`.
85
+ */
86
+ export type ZohoAnalyticsTimestampString = string;
@@ -0,0 +1,74 @@
1
+ import { type Maybe } from '@dereekb/util';
2
+ import { type ZohoAnalyticsName, type ZohoAnalyticsRow } from './analytics';
3
+ import { type ZohoAnalyticsImportFileType } from './analytics.import';
4
+ /**
5
+ * Rows of import data alongside the column names the data declares.
6
+ *
7
+ * The column names are tracked separately from the rows because the two can disagree: a CSV header
8
+ * can declare a column that no row populates, and JSON rows are free to omit keys. An import is
9
+ * matched against the declared names, so a diff has to see them even when no row carries a value.
10
+ */
11
+ export interface ZohoAnalyticsRowData {
12
+ /**
13
+ * Column names the data declares, in the order they appear.
14
+ */
15
+ readonly columnNames: ZohoAnalyticsName[];
16
+ /**
17
+ * The parsed rows.
18
+ */
19
+ readonly rows: ZohoAnalyticsRow[];
20
+ }
21
+ /**
22
+ * Field delimiter of the CSV being read. Defaults to a comma.
23
+ */
24
+ export type ZohoAnalyticsCsvDelimiter = string;
25
+ /**
26
+ * Reads CSV text into {@link ZohoAnalyticsRowData}, taking the first row as the header.
27
+ *
28
+ * Duplicate header names collapse into one column, matching what an import does: the later value
29
+ * wins. Trailing cells beyond the header's width are dropped rather than given a synthetic name,
30
+ * since an import has no column to put them in either.
31
+ *
32
+ * @param content - The CSV text to read.
33
+ * @param delimiter - Field delimiter of the CSV. Defaults to a comma.
34
+ * @returns The declared column names and parsed rows. Both are empty for blank content.
35
+ */
36
+ export declare function zohoAnalyticsRowDataFromCsv(content: string, delimiter?: Maybe<ZohoAnalyticsCsvDelimiter>): ZohoAnalyticsRowData;
37
+ /**
38
+ * Reads JSON import text into {@link ZohoAnalyticsRowData}.
39
+ *
40
+ * Zoho Analytics expects a JSON import to be an array of row objects, so that is what this accepts;
41
+ * a lone object is treated as a single row for convenience.
42
+ *
43
+ * The declared column names are the union of the rows' keys in first-seen order, since JSON rows are
44
+ * free to omit keys and no separate header declares them.
45
+ *
46
+ * @param content - The JSON text to read.
47
+ * @returns The declared column names and parsed rows.
48
+ * @throws {Error} When the text is not valid JSON, or is neither an array of objects nor an object.
49
+ */
50
+ export declare function zohoAnalyticsRowDataFromJson(content: string): ZohoAnalyticsRowData;
51
+ /**
52
+ * Input for reading the contents of an import file into rows.
53
+ */
54
+ export interface ZohoAnalyticsRowDataFromFileContentInput {
55
+ /**
56
+ * The file's text.
57
+ */
58
+ readonly content: string;
59
+ /**
60
+ * Format of the text.
61
+ */
62
+ readonly fileType: ZohoAnalyticsImportFileType;
63
+ /**
64
+ * Field delimiter, for a CSV. Defaults to a comma.
65
+ */
66
+ readonly delimiter?: Maybe<ZohoAnalyticsCsvDelimiter>;
67
+ }
68
+ /**
69
+ * Reads the contents of an import file into {@link ZohoAnalyticsRowData}, dispatching on its format.
70
+ *
71
+ * @param input - The file's text and format.
72
+ * @returns The declared column names and parsed rows.
73
+ */
74
+ export declare function zohoAnalyticsRowDataFromFileContent(input: ZohoAnalyticsRowDataFromFileContentInput): ZohoAnalyticsRowData;
@@ -0,0 +1,178 @@
1
+ import { type Maybe } from '@dereekb/util';
2
+ import { type ZohoAnalyticsName } from './analytics';
3
+ import { type ZohoAnalyticsColumn, type ZohoAnalyticsColumnDataType } from './analytics.view';
4
+ import { type ZohoAnalyticsRowData } from './analytics.data';
5
+ /**
6
+ * Default number of offending values kept per conflict, so a column that is wrong in every row
7
+ * reports a usable example rather than a copy of the file.
8
+ */
9
+ export declare const DEFAULT_ZOHO_ANALYTICS_SCHEMA_DIFF_MAX_SAMPLES = 3;
10
+ /**
11
+ * Why an incoming value does not fit the column it was matched to.
12
+ *
13
+ * - `notANumber` the value is not numeric at all.
14
+ * - `notAnInteger` the value is numeric but has a fractional part a whole-number column truncates.
15
+ * - `negative` the value is negative in a column that only accepts positives.
16
+ * - `notADate` the value is neither parseable as a date nor shaped like one.
17
+ * - `notABoolean` the value is not one of the recognized true/false spellings.
18
+ * - `notAnEmail` the value is not shaped like an email address.
19
+ * - `notAUrl` the value is not shaped like a URL.
20
+ * - `tooLong` the value is longer than the column's `columnMaxSize`.
21
+ * - `emptyInNonNullable` the value is blank in a column that is not nullable and has no default.
22
+ */
23
+ export type ZohoAnalyticsSchemaDiffConflictReason = 'notANumber' | 'notAnInteger' | 'negative' | 'notADate' | 'notABoolean' | 'notAnEmail' | 'notAUrl' | 'tooLong' | 'emptyInNonNullable';
24
+ /**
25
+ * One offending value, kept as an example of a conflict.
26
+ */
27
+ export interface ZohoAnalyticsSchemaDiffConflictSample {
28
+ /**
29
+ * 1-based position of the row within the data.
30
+ *
31
+ * A CSV header is not counted, so row 1 is the first row of values — one line lower in the file.
32
+ */
33
+ readonly row: number;
34
+ /**
35
+ * The offending value, as text.
36
+ */
37
+ readonly value: string;
38
+ }
39
+ /**
40
+ * A matched column carrying values that do not fit its declared data type.
41
+ *
42
+ * Reported once per column and reason, so a column that is wrong in two different ways appears
43
+ * twice rather than merging the counts.
44
+ */
45
+ export interface ZohoAnalyticsSchemaDiffConflict {
46
+ readonly columnName: ZohoAnalyticsName;
47
+ readonly dataType: ZohoAnalyticsColumnDataType;
48
+ readonly reason: ZohoAnalyticsSchemaDiffConflictReason;
49
+ /**
50
+ * How many rows hit this conflict, which can exceed the number of samples kept.
51
+ */
52
+ readonly conflictCount: number;
53
+ readonly samples: ZohoAnalyticsSchemaDiffConflictSample[];
54
+ }
55
+ /**
56
+ * A column the data declares that the target table does not have.
57
+ *
58
+ * An import matches data to columns by name, so nothing is written for these — the values are
59
+ * silently discarded rather than reported as an error.
60
+ */
61
+ export interface ZohoAnalyticsSchemaDiffDroppedColumn {
62
+ readonly columnName: ZohoAnalyticsName;
63
+ /**
64
+ * How many rows carry a non-blank value for it, i.e. how much data the import would discard.
65
+ */
66
+ readonly valueCount: number;
67
+ }
68
+ /**
69
+ * A column the target table has that the data does not declare.
70
+ *
71
+ * An `append` or `updateadd` import leaves these at their default; a `truncateadd` import blanks the
72
+ * column across the whole table, since it deletes every existing row first.
73
+ */
74
+ export interface ZohoAnalyticsSchemaDiffEmptyColumn {
75
+ readonly columnName: ZohoAnalyticsName;
76
+ readonly dataType?: ZohoAnalyticsColumnDataType;
77
+ readonly isNullable?: boolean;
78
+ /**
79
+ * Whether omitting the column is expected to fail rather than just leave a gap: it is explicitly
80
+ * not nullable and carries no default value.
81
+ */
82
+ readonly required: boolean;
83
+ }
84
+ /**
85
+ * A column whose name matches a table column except for case or surrounding whitespace.
86
+ *
87
+ * Reported on its own rather than as a dropped column because whether Zoho matches these has not
88
+ * been verified against the live API: if it does not, the data is discarded, and if it does, the
89
+ * import succeeds. Either way the mismatch is worth fixing before finding out.
90
+ */
91
+ export interface ZohoAnalyticsSchemaDiffCaseMismatch {
92
+ readonly dataColumnName: ZohoAnalyticsName;
93
+ readonly tableColumnName: ZohoAnalyticsName;
94
+ }
95
+ /**
96
+ * The difference between a set of rows about to be imported and the table receiving them.
97
+ *
98
+ * Purely descriptive: every category is reported and none is weighted against another. Use
99
+ * {@link isZohoAnalyticsSchemaDiffClean} to reduce it to a pass/fail verdict.
100
+ */
101
+ export interface ZohoAnalyticsSchemaDiff {
102
+ /**
103
+ * Names matched exactly between the data and the table.
104
+ */
105
+ readonly matchedColumns: ZohoAnalyticsName[];
106
+ readonly droppedColumns: ZohoAnalyticsSchemaDiffDroppedColumn[];
107
+ readonly emptyColumns: ZohoAnalyticsSchemaDiffEmptyColumn[];
108
+ readonly caseMismatchedColumns: ZohoAnalyticsSchemaDiffCaseMismatch[];
109
+ readonly conflicts: ZohoAnalyticsSchemaDiffConflict[];
110
+ /**
111
+ * How many rows were compared.
112
+ */
113
+ readonly rowCount: number;
114
+ }
115
+ /**
116
+ * Input for comparing rows against a table's columns.
117
+ */
118
+ export interface ZohoAnalyticsSchemaDiffInput extends ZohoAnalyticsRowData {
119
+ /**
120
+ * The target table's column metadata, as returned by `getTableMetadata()`.
121
+ */
122
+ readonly columns: ZohoAnalyticsColumn[];
123
+ /**
124
+ * How many offending values to keep per conflict. Defaults to
125
+ * {@link DEFAULT_ZOHO_ANALYTICS_SCHEMA_DIFF_MAX_SAMPLES}.
126
+ */
127
+ readonly maxSamples?: Maybe<number>;
128
+ }
129
+ /**
130
+ * Compares rows about to be imported against the columns of the table receiving them.
131
+ *
132
+ * Answers the question an import cannot: what of this data has nowhere to land, what the table
133
+ * expects that the data does not carry, and which values will not survive their column's type. An
134
+ * import reports none of that up front — a name that matches no column is discarded silently, since
135
+ * Zoho matches data to columns by name.
136
+ *
137
+ * Comparison is by exact name, with case-and-whitespace-only near misses split out into
138
+ * {@link ZohoAnalyticsSchemaDiff.caseMismatchedColumns} rather than counted as dropped or empty.
139
+ *
140
+ * @param input - The rows, their declared column names, and the table's column metadata.
141
+ * @returns The difference between the two.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const { data } = await api.getTableMetadata({ workspaceId, viewId });
146
+ * const diff = zohoAnalyticsSchemaDiff({ ...zohoAnalyticsRowDataFromCsv(csv), columns: data.columns });
147
+ *
148
+ * if (!isZohoAnalyticsSchemaDiffClean(diff)) {
149
+ * throw new Error(`${diff.droppedColumns.length} columns would be dropped.`);
150
+ * }
151
+ * ```
152
+ */
153
+ export declare function zohoAnalyticsSchemaDiff(input: ZohoAnalyticsSchemaDiffInput): ZohoAnalyticsSchemaDiff;
154
+ /**
155
+ * Options for reducing a {@link ZohoAnalyticsSchemaDiff} to a verdict.
156
+ */
157
+ export interface IsZohoAnalyticsSchemaDiffCleanOptions {
158
+ /**
159
+ * Also treat a nullable column the data omits as drift.
160
+ *
161
+ * Off by default: omitting a nullable column is how a partial `append` import is supposed to look,
162
+ * so counting it would make the common case fail. A column that is not nullable and has no default
163
+ * counts as drift either way.
164
+ */
165
+ readonly strict?: Maybe<boolean>;
166
+ }
167
+ /**
168
+ * Decides whether a diff found anything that would change or lose data on import.
169
+ *
170
+ * Drift is: a dropped column, a case-mismatched column, a value that does not fit its column, or an
171
+ * omitted column the table requires. A nullable column the data omits is reported by the diff but is
172
+ * not drift unless `strict` is set.
173
+ *
174
+ * @param diff - The diff to judge.
175
+ * @param options - Whether to also count omitted nullable columns; see {@link IsZohoAnalyticsSchemaDiffCleanOptions}.
176
+ * @returns True when the data can be imported without loss or surprise.
177
+ */
178
+ export declare function isZohoAnalyticsSchemaDiffClean(diff: ZohoAnalyticsSchemaDiff, options?: Maybe<IsZohoAnalyticsSchemaDiffCleanOptions>): boolean;