@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,202 @@
|
|
|
1
|
+
# Zoho Analytics — Test Workspace Setup
|
|
2
|
+
|
|
3
|
+
How to set up the Zoho Analytics workspace and credentials that
|
|
4
|
+
`src/lib/analytics/analytics.api.live.spec.ts` runs against.
|
|
5
|
+
|
|
6
|
+
The live suite is **opt-in**. Without the environment variables below it is skipped entirely, so
|
|
7
|
+
`nx test zoho-nestjs` stays green on a machine with no Analytics account.
|
|
8
|
+
|
|
9
|
+
## 1. Create a throwaway workspace
|
|
10
|
+
|
|
11
|
+
In [Zoho Analytics](https://analytics.zoho.com), create a workspace dedicated to testing — for
|
|
12
|
+
example `dbx-components Test`.
|
|
13
|
+
|
|
14
|
+
This MUST NOT be a workspace holding real data. The suite truncates its test table before nearly
|
|
15
|
+
every test, and `truncateadd` replaces a table's entire contents.
|
|
16
|
+
|
|
17
|
+
Nothing has to be created inside the workspace. The suite provisions its own `DbxComponentsLiveTest`
|
|
18
|
+
table on first run (via `importDataInNewTable`) and reuses it on later runs.
|
|
19
|
+
|
|
20
|
+
## 2. Create a dedicated OAuth client
|
|
21
|
+
|
|
22
|
+
Analytics is in `ZOHO_CLI_DEDICATED_CLIENT_PRODUCTS`: its scopes are not assumed to be grantable
|
|
23
|
+
alongside the recruit/crm/desk client, so it gets its own self-client at
|
|
24
|
+
[api-console.zoho.com](https://api-console.zoho.com/).
|
|
25
|
+
|
|
26
|
+
Scopes (the CLI requests exactly these for `--product analytics`):
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
ZohoAnalytics.data.all
|
|
30
|
+
ZohoAnalytics.metadata.all
|
|
31
|
+
ZohoAnalytics.modeling.all
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`modeling.all` is required because the suite creates and deletes its own tables.
|
|
35
|
+
|
|
36
|
+
**Grant all three, and check what you actually got.** Zoho issues exactly the scopes the
|
|
37
|
+
authorization URL asked for, and the granular ones do not imply each other — a token holding
|
|
38
|
+
`ZohoAnalytics.modeling.create` can create a table but not delete one, and every delete fails with
|
|
39
|
+
error **8540** ("This API request cannot be processed using the provided token"), which names a
|
|
40
|
+
scope problem but not which scope. The grant is only visible on a token exchange, so read it back:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
curl -s -X POST https://accounts.zoho.com/oauth/v2/token \
|
|
44
|
+
-d "refresh_token=$ZOHO_ANALYTICS_ACCOUNTS_REFRESH_TOKEN" \
|
|
45
|
+
-d "client_id=$ZOHO_ANALYTICS_ACCOUNTS_CLIENT_ID" \
|
|
46
|
+
-d "client_secret=$ZOHO_ANALYTICS_ACCOUNTS_CLIENT_SECRET" \
|
|
47
|
+
-d "grant_type=refresh_token" | jq .scope
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If `ZohoAnalytics.modeling.delete` (or `.all`) is missing, redo step 3 — the modeling tests cannot
|
|
51
|
+
pass without it.
|
|
52
|
+
|
|
53
|
+
## 3. Get a refresh token
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# step 1 — prints the authorization URL (--scopes defaults to the --product value)
|
|
57
|
+
npx zoho-cli auth setup --product analytics --client-id 1000.XXX --client-secret YYY
|
|
58
|
+
|
|
59
|
+
# step 2 — paste back the code, or the whole redirect URL
|
|
60
|
+
npx zoho-cli auth setup --product analytics --code "http://localhost/oauth?code=1000.ZZZ"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or set an existing refresh token directly:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx zoho-cli auth set --product analytics --client-id 1000.XXX --client-secret YYY --refresh-token 1000.ZZZ
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 4. Discover the org id and workspace id
|
|
70
|
+
|
|
71
|
+
The org id is required by every Analytics endpoint except `GET /orgs`, which is how it is found:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npx zoho-cli analytics orgs list
|
|
75
|
+
npx zoho-cli auth set --product analytics --client-id 1000.XXX --client-secret YYY --refresh-token 1000.ZZZ --org-id 1234567
|
|
76
|
+
|
|
77
|
+
npx zoho-cli analytics workspaces list
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Take the `workspaceId` of the test workspace from the last command.
|
|
81
|
+
|
|
82
|
+
## 5. Set the environment variables
|
|
83
|
+
|
|
84
|
+
Put them in the repo-root `.env.local`, which is gitignored. The committed `.env` holds
|
|
85
|
+
`placeholder` values, and the suite treats `placeholder` as "not set".
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
ZOHO_ANALYTICS_ACCOUNTS_CLIENT_ID=1000.XXX
|
|
89
|
+
ZOHO_ANALYTICS_ACCOUNTS_CLIENT_SECRET=YYY
|
|
90
|
+
ZOHO_ANALYTICS_ACCOUNTS_REFRESH_TOKEN=1000.ZZZ
|
|
91
|
+
ZOHO_ANALYTICS_ORG_ID=1234567
|
|
92
|
+
ZOHO_ANALYTICS_TEST_WORKSPACE_ID=9876543
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`ZOHO_ANALYTICS_API_URL` is optional and falls back to `ZOHO_API_URL`; use it only to target a
|
|
96
|
+
non-US data center (`https://analyticsapi.zoho.eu/restapi/v2`, `.in`, `.com.au`, `.jp`, `.sa`,
|
|
97
|
+
`analyticsapi.zohocloud.ca`).
|
|
98
|
+
|
|
99
|
+
The service-specific `ZOHO_ANALYTICS_ACCOUNTS_*` names fall back to the shared `ZOHO_ACCOUNTS_*`
|
|
100
|
+
ones. Set the service-specific names — sharing the recruit/crm/desk client is exactly what
|
|
101
|
+
step 2 assumes is not possible.
|
|
102
|
+
|
|
103
|
+
## 6. Run it
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pnpm nx test zoho-nestjs --skip-nx-cache
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`--skip-nx-cache` matters: nx caches test results and no environment variable is part of the cache
|
|
110
|
+
key, so a cached "passed" from a credential-less run would otherwise be replayed.
|
|
111
|
+
|
|
112
|
+
## What the suite does to the workspace
|
|
113
|
+
|
|
114
|
+
- creates `DbxComponentsLiveTest` once, with columns `Region` / `Rep` / `Amount`
|
|
115
|
+
- resets that table to three baseline rows before each test that asserts an absolute row count,
|
|
116
|
+
and once more after the suite
|
|
117
|
+
- creates `DbxComponentsNewTableSync` and `DbxComponentsNewTableAsync` in the `modeling` group and
|
|
118
|
+
deletes each one again inside the same test
|
|
119
|
+
- creates async import/export jobs, which count against the org's daily API-unit allowance
|
|
120
|
+
- never touches any other view in the workspace, and never deletes the workspace itself
|
|
121
|
+
|
|
122
|
+
Imports are the most expensive thing the suite does, so the tests are grouped by whether they need
|
|
123
|
+
a known starting point:
|
|
124
|
+
|
|
125
|
+
| group | resets the baseline | holds |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| `writes` | before each test | the tests asserting an exact row count after a write |
|
|
128
|
+
| `no-op writes` | no | writes expected to affect zero rows |
|
|
129
|
+
| `failures` | no | writes expected to be rejected, which land nothing |
|
|
130
|
+
| `errors` | no | read-only not-found and bad-criteria calls |
|
|
131
|
+
| `modeling` | no | the delete operations, which create and destroy their own tables |
|
|
132
|
+
|
|
133
|
+
Adding a test that only needs a failure or a zero-row result belongs in one of the latter groups,
|
|
134
|
+
which cost no import.
|
|
135
|
+
|
|
136
|
+
If the table's schema ever drifts (a stray column, a changed type), delete the
|
|
137
|
+
`DbxComponentsLiveTest` table — `zoho-cli analytics views delete <workspaceId> <viewId>`, or by
|
|
138
|
+
hand in the UI — and the next run recreates it from the baseline rows.
|
|
139
|
+
|
|
140
|
+
### Rate limiting
|
|
141
|
+
|
|
142
|
+
Analytics allows 100 requests per minute overall and 60/min for metadata, and the full suite runs
|
|
143
|
+
close enough to that ceiling that a run started right after another one fails with error **6045** on
|
|
144
|
+
whichever tests happen to be in flight. That failure is collateral, not a regression — the giveaway
|
|
145
|
+
is several unrelated tests all asserting `'6045'` where they expected their own error code. Wait a
|
|
146
|
+
minute and re-run before investigating.
|
|
147
|
+
|
|
148
|
+
## Driving the CLI against the same workspace
|
|
149
|
+
|
|
150
|
+
The live suite reads credentials from `.env.local`, while `zoho-cli` reads its own
|
|
151
|
+
`~/.zoho-cli/config.json` — configuring one does NOT configure the other. To point the CLI at the
|
|
152
|
+
same account without going through the browser OAuth flow, hand it the values already in
|
|
153
|
+
`.env.local`:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
zoho-cli auth set --product analytics \
|
|
157
|
+
--client-id "$ZOHO_ANALYTICS_ACCOUNTS_CLIENT_ID" \
|
|
158
|
+
--client-secret "$ZOHO_ANALYTICS_ACCOUNTS_CLIENT_SECRET" \
|
|
159
|
+
--refresh-token "$ZOHO_ANALYTICS_ACCOUNTS_REFRESH_TOKEN" \
|
|
160
|
+
--org-id "$ZOHO_ANALYTICS_ORG_ID"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`auth setup` is the interactive alternative, and is only needed when there is no refresh token yet —
|
|
164
|
+
it prints an authorization URL to open in a browser and takes the returned code back.
|
|
165
|
+
|
|
166
|
+
Then, against the throwaway workspace:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
zoho-cli analytics orgs list
|
|
170
|
+
zoho-cli analytics views list $ZOHO_ANALYTICS_TEST_WORKSPACE_ID
|
|
171
|
+
zoho-cli analytics import data $WS $VIEW -f rows.csv # sync
|
|
172
|
+
zoho-cli analytics import data $WS $VIEW -f rows.csv --async # bulk job
|
|
173
|
+
zoho-cli analytics export data $WS $VIEW --format json
|
|
174
|
+
zoho-cli analytics views delete $WS $VIEW # drop a table created above
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Checking a file against a table first
|
|
178
|
+
|
|
179
|
+
`analytics diff schema` compares a file's columns against the target table's column metadata and
|
|
180
|
+
reports what an import would lose, without writing anything:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
zoho-cli analytics diff schema $WS $VIEW -f rows.csv
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
It reports four things: columns only in the file (an import discards these silently, since Zoho
|
|
187
|
+
matches data to columns by name), columns only in the table, names that match except for case, and
|
|
188
|
+
values that do not fit their column's declared type. It exits non-zero when it finds any of them, so
|
|
189
|
+
it can gate an import:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
zoho-cli analytics diff schema $WS $VIEW -f rows.csv --quiet \
|
|
193
|
+
&& zoho-cli analytics import data $WS $VIEW -f rows.csv
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
A nullable column the file omits is reported but is not treated as drift, since that is what a
|
|
197
|
+
partial `append` import looks like; pass `--strict` to fail on it too.
|
|
198
|
+
|
|
199
|
+
`zoho-cli analytics import new-table` leaves a table behind; `analytics views delete` is how to drop
|
|
200
|
+
it. The delete is irreversible and Zoho has no recycle bin, so check the id against
|
|
201
|
+
`analytics views list` first. Deleting a whole workspace additionally requires repeating its id:
|
|
202
|
+
`analytics workspaces delete $WS --confirm $WS`.
|