@elobdev/zoho-projects-wrapper 0.0.0-stage → 0.1.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/.codex +0 -0
- package/README.md +52 -2
- package/docs/zoho- +0 -0
- package/docs/zoho-projects-api-matrix.md +368 -0
- package/package.json +23 -4
- package/src/client.ts +75 -0
- package/src/errors.ts +34 -0
- package/src/http.ts +166 -0
- package/src/index.ts +19 -0
- package/src/oauth.ts +121 -0
- package/src/query.ts +51 -0
- package/src/resource-base.ts +59 -0
- package/src/resources/custom-fields.ts +27 -0
- package/src/resources/issues.ts +166 -0
- package/src/resources/module-meta.ts +1 -0
- package/src/resources/phases.ts +68 -0
- package/src/resources/portals.ts +46 -0
- package/src/resources/project-groups.ts +24 -0
- package/src/resources/projects.ts +56 -0
- package/src/resources/records.ts +40 -0
- package/src/resources/settings.ts +132 -0
- package/src/resources/tasklists.ts +94 -0
- package/src/resources/tasks.ts +43 -0
- package/src/resources/time-logs.ts +274 -0
- package/src/tools.ts +741 -0
- package/src/types.ts +546 -0
- package/test/helpers.ts +28 -0
- package/test/http.test.ts +49 -0
- package/test/node-shims.d.ts +9 -0
- package/test/oauth.test.ts +72 -0
- package/test/path-alias-hooks.js +10 -0
- package/test/query.test.ts +46 -0
- package/test/register-path-alias.js +3 -0
- package/test/resources.test.ts +504 -0
- package/test/tools.test.ts +30 -0
- package/tsconfig.json +20 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
export type RecordId = string;
|
|
2
|
+
|
|
3
|
+
export type ProjectType = 'active' | 'template' | 'archived';
|
|
4
|
+
export type TaskPriority = 'none' | 'low' | 'medium' | 'high';
|
|
5
|
+
export type BillingType = 'none' | 'billable' | 'non_billable';
|
|
6
|
+
export type TaskListFlag = 'internal' | 'external';
|
|
7
|
+
export type ModuleName = 'projects' | 'phases' | 'tasklists' | 'tasks' | 'issues';
|
|
8
|
+
export type SortOrder = 'ASC' | 'DESC';
|
|
9
|
+
|
|
10
|
+
export interface ZohoEntityRef {
|
|
11
|
+
id?: RecordId | number;
|
|
12
|
+
zpuid?: RecordId | number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ZohoNamedRef extends ZohoEntityRef {
|
|
16
|
+
name?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ZohoStatusRef extends ZohoEntityRef {
|
|
20
|
+
status?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ZohoOwnerRef extends ZohoEntityRef {
|
|
24
|
+
full_name?: string;
|
|
25
|
+
first_name?: string;
|
|
26
|
+
last_name?: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
is_client_user?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ZohoPortal {
|
|
32
|
+
id?: RecordId | number;
|
|
33
|
+
name?: string;
|
|
34
|
+
org_name?: string;
|
|
35
|
+
timezone?: string;
|
|
36
|
+
logo_url?: string;
|
|
37
|
+
is_customdomain_enabled?: boolean;
|
|
38
|
+
owner?: ZohoOwnerRef;
|
|
39
|
+
business_details?: Record<string, unknown>;
|
|
40
|
+
plan_details?: Record<string, unknown>;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ZohoPortalDetails extends ZohoPortal {
|
|
45
|
+
portal_details?: ZohoPortal;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ZohoPortalExportStatus {
|
|
49
|
+
id?: RecordId | number;
|
|
50
|
+
status?: string;
|
|
51
|
+
download_url?: string;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ZohoModule {
|
|
56
|
+
id?: RecordId | number;
|
|
57
|
+
api_name?: string;
|
|
58
|
+
singular_name?: string;
|
|
59
|
+
plural_name?: string;
|
|
60
|
+
icon_class?: string;
|
|
61
|
+
type?: string;
|
|
62
|
+
status?: string;
|
|
63
|
+
is_global_module?: boolean;
|
|
64
|
+
is_all_projects?: boolean;
|
|
65
|
+
is_all_profiles?: boolean;
|
|
66
|
+
is_overview_needed?: boolean;
|
|
67
|
+
overviewNeeded?: boolean;
|
|
68
|
+
tabName?: string;
|
|
69
|
+
module_property?: {
|
|
70
|
+
search_module_id?: string;
|
|
71
|
+
is_indexed_module?: boolean;
|
|
72
|
+
default_layout_type?: string;
|
|
73
|
+
};
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ZohoCustomField {
|
|
78
|
+
id?: RecordId | number;
|
|
79
|
+
api_name?: string;
|
|
80
|
+
field_name?: string;
|
|
81
|
+
field_type?: string;
|
|
82
|
+
data_type?: string;
|
|
83
|
+
is_mandatory?: boolean;
|
|
84
|
+
is_default?: boolean;
|
|
85
|
+
is_renamed?: boolean;
|
|
86
|
+
is_unassociated?: boolean;
|
|
87
|
+
is_association_info_needed?: boolean;
|
|
88
|
+
is_formula_based_list?: boolean;
|
|
89
|
+
[key: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface ZohoFieldOption {
|
|
93
|
+
id?: RecordId | number;
|
|
94
|
+
name?: string;
|
|
95
|
+
value?: string;
|
|
96
|
+
[key: string]: unknown;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ZohoProject {
|
|
100
|
+
id?: RecordId | number;
|
|
101
|
+
name?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
project_type?: ProjectType;
|
|
104
|
+
owner?: ZohoOwnerRef;
|
|
105
|
+
is_public_project?: boolean;
|
|
106
|
+
start_date?: string;
|
|
107
|
+
end_date?: string;
|
|
108
|
+
completed_time?: string;
|
|
109
|
+
status?: ZohoStatusRef;
|
|
110
|
+
layout?: ZohoNamedRef;
|
|
111
|
+
added_via?: string;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface ZohoProjectGroup {
|
|
116
|
+
id?: RecordId | number;
|
|
117
|
+
name?: string;
|
|
118
|
+
type?: 'public' | 'private';
|
|
119
|
+
prefix?: string;
|
|
120
|
+
sequence?: string | number;
|
|
121
|
+
associated_projects?: string | number;
|
|
122
|
+
has_edit_access?: boolean;
|
|
123
|
+
is_default?: boolean;
|
|
124
|
+
created_on?: string;
|
|
125
|
+
updated_on?: string;
|
|
126
|
+
created_by?: ZohoOwnerRef;
|
|
127
|
+
updated_by?: ZohoOwnerRef;
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface ZohoTaskList {
|
|
132
|
+
id?: RecordId | number;
|
|
133
|
+
name?: string;
|
|
134
|
+
milestone?: ZohoNamedRef;
|
|
135
|
+
flag?: TaskListFlag;
|
|
136
|
+
status?: string;
|
|
137
|
+
tags?: Array<{ id?: RecordId | number; add?: Array<{ id?: RecordId | number }>; remove?: Array<{ id?: RecordId | number }> }>;
|
|
138
|
+
color?: string;
|
|
139
|
+
[key: string]: unknown;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface ZohoDuration {
|
|
143
|
+
value: string;
|
|
144
|
+
type: 'days' | 'hours';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ZohoOwnerWorkAssignment {
|
|
148
|
+
zpuid?: RecordId | number;
|
|
149
|
+
work_values?: string;
|
|
150
|
+
[key: string]: unknown;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ZohoTask {
|
|
154
|
+
id?: RecordId | number;
|
|
155
|
+
tasklist?: ZohoNamedRef;
|
|
156
|
+
parental_info?: {
|
|
157
|
+
parent_task_id?: RecordId | number;
|
|
158
|
+
};
|
|
159
|
+
name?: string;
|
|
160
|
+
description?: string;
|
|
161
|
+
status?: ZohoStatusRef;
|
|
162
|
+
priority?: TaskPriority;
|
|
163
|
+
start_date?: string;
|
|
164
|
+
end_date?: string;
|
|
165
|
+
duration?: ZohoDuration;
|
|
166
|
+
completion_percentage?: number;
|
|
167
|
+
billing_type?: BillingType;
|
|
168
|
+
attachments?: Array<RecordId | number>;
|
|
169
|
+
owners_and_work?: {
|
|
170
|
+
owners?: Array<ZohoOwnerWorkAssignment>;
|
|
171
|
+
add?: Array<ZohoOwnerWorkAssignment>;
|
|
172
|
+
remove?: Array<ZohoOwnerWorkAssignment>;
|
|
173
|
+
work_type?: string;
|
|
174
|
+
unit?: string;
|
|
175
|
+
copy_task_duration?: boolean;
|
|
176
|
+
refresh_business_hours?: boolean;
|
|
177
|
+
};
|
|
178
|
+
recurrence?: ZohoTaskRecurrence;
|
|
179
|
+
budget_info?: ZohoTaskBudgetInfo;
|
|
180
|
+
tags?: Array<{
|
|
181
|
+
id?: RecordId | number;
|
|
182
|
+
add?: Array<{ id?: RecordId | number }>;
|
|
183
|
+
remove?: Array<{ id?: RecordId | number }>;
|
|
184
|
+
}>;
|
|
185
|
+
teams?: Array<{
|
|
186
|
+
id?: RecordId | number;
|
|
187
|
+
add?: Array<{ id?: RecordId | number }>;
|
|
188
|
+
remove?: Array<{ id?: RecordId | number }>;
|
|
189
|
+
}>;
|
|
190
|
+
[key: string]: unknown;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface ZohoTaskUpsertBody {
|
|
194
|
+
tasklist?: ZohoNamedRef;
|
|
195
|
+
parental_info?: {
|
|
196
|
+
parent_task_id?: RecordId | number;
|
|
197
|
+
};
|
|
198
|
+
name?: string;
|
|
199
|
+
description?: string;
|
|
200
|
+
status?: ZohoStatusRef;
|
|
201
|
+
priority?: TaskPriority | '-';
|
|
202
|
+
start_date?: string;
|
|
203
|
+
end_date?: string;
|
|
204
|
+
duration?: ZohoDuration;
|
|
205
|
+
completion_percentage?: number | '-';
|
|
206
|
+
billing_type?: BillingType | '-';
|
|
207
|
+
attachments?: Array<RecordId | number>;
|
|
208
|
+
owners_and_work?: {
|
|
209
|
+
owners?: Array<ZohoOwnerWorkAssignment & {
|
|
210
|
+
add?: Array<{ zpuid?: RecordId | number; work_values?: string }>;
|
|
211
|
+
remove?: Array<{ zpuid?: RecordId | number }>;
|
|
212
|
+
}>;
|
|
213
|
+
work_type?: string;
|
|
214
|
+
unit?: string;
|
|
215
|
+
copy_task_duration?: boolean | '-';
|
|
216
|
+
refresh_business_hours?: boolean | '-';
|
|
217
|
+
};
|
|
218
|
+
tags?: Array<{
|
|
219
|
+
id?: RecordId | number;
|
|
220
|
+
add?: Array<{ id?: RecordId | number }>;
|
|
221
|
+
remove?: Array<{ id?: RecordId | number }>;
|
|
222
|
+
}>;
|
|
223
|
+
teams?: Array<{
|
|
224
|
+
id?: RecordId | number;
|
|
225
|
+
add?: Array<{ id?: RecordId | number }>;
|
|
226
|
+
remove?: Array<{ id?: RecordId | number }>;
|
|
227
|
+
}>;
|
|
228
|
+
recurrence?: ZohoTaskRecurrence;
|
|
229
|
+
budget_info?: ZohoTaskBudgetInfo;
|
|
230
|
+
[key: string]: unknown;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export type TimeLogBillStatus = 'All' | 'Billable' | 'Non Billable' | 'all' | 'billable' | 'non_billable';
|
|
234
|
+
export type TimeLogViewType = 'day' | 'week' | 'month' | 'custom_date';
|
|
235
|
+
export type TimeLogComponentType = 'task' | 'bug' | 'general';
|
|
236
|
+
export type TimeLogApproval = 'approve' | 'pending' | 'reject';
|
|
237
|
+
|
|
238
|
+
export interface ZohoTimeLogListParams extends ZohoPageParams {
|
|
239
|
+
users_list?: string | number;
|
|
240
|
+
view_type?: TimeLogViewType;
|
|
241
|
+
date?: string;
|
|
242
|
+
custom_date?: {
|
|
243
|
+
start_date?: string;
|
|
244
|
+
end_date?: string;
|
|
245
|
+
};
|
|
246
|
+
bill_status?: TimeLogBillStatus;
|
|
247
|
+
component_type?: TimeLogComponentType;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface ZohoTimeLogBody {
|
|
251
|
+
date: string;
|
|
252
|
+
owner?: string | number;
|
|
253
|
+
bill_status: Exclude<TimeLogBillStatus, 'All' | 'all'>;
|
|
254
|
+
hours: string;
|
|
255
|
+
notes?: string;
|
|
256
|
+
custom_fields?: Record<string, unknown>;
|
|
257
|
+
cost_per_hour?: number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface ZohoGeneralTimeLogBody extends ZohoTimeLogBody {
|
|
261
|
+
name: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface ZohoTimeLogApprovalBody {
|
|
265
|
+
approval: TimeLogApproval;
|
|
266
|
+
reason?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface ZohoTimeSheetLayout {
|
|
270
|
+
[key: string]: unknown;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface ZohoTimeSheetCustomField {
|
|
274
|
+
id?: RecordId | number;
|
|
275
|
+
unique_column?: string;
|
|
276
|
+
field_name?: string;
|
|
277
|
+
data_type?: string;
|
|
278
|
+
[key: string]: unknown;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface ZohoTimeLogReportParams extends ZohoPageParams {
|
|
282
|
+
report_type?: 'user' | 'module';
|
|
283
|
+
view_type?: 'day' | 'week' | 'month';
|
|
284
|
+
start_date?: string;
|
|
285
|
+
filter?: ZohoFilter;
|
|
286
|
+
view_id?: RecordId | number;
|
|
287
|
+
timelog_group_id?: RecordId | number;
|
|
288
|
+
frompage?: string;
|
|
289
|
+
custom_range?: {
|
|
290
|
+
start_date?: string;
|
|
291
|
+
end_date?: string;
|
|
292
|
+
};
|
|
293
|
+
module?: { id?: RecordId | number; type?: 'task' | 'issue' | 'general' };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface ZohoTimeLogSettings {
|
|
297
|
+
[key: string]: unknown;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface ZohoTimeLogActionBody {
|
|
301
|
+
notes?: string;
|
|
302
|
+
type?: 'task' | 'issue' | 'general';
|
|
303
|
+
log_id?: RecordId | number;
|
|
304
|
+
entity_id?: RecordId | number;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface ZohoTimeLogCreateBody {
|
|
308
|
+
item_id?: RecordId | number;
|
|
309
|
+
log_name?: string;
|
|
310
|
+
date: string;
|
|
311
|
+
project_id?: string | number;
|
|
312
|
+
type: 'task' | 'issue' | 'general';
|
|
313
|
+
hours?: string;
|
|
314
|
+
start_time?: string;
|
|
315
|
+
end_time?: string;
|
|
316
|
+
bill_status: string;
|
|
317
|
+
notes?: string;
|
|
318
|
+
owner_zpuid?: RecordId | number;
|
|
319
|
+
approver?: RecordId | number;
|
|
320
|
+
module?: { id?: RecordId | number; type?: 'task' | 'issue' | 'general' } | string;
|
|
321
|
+
custom_fields?: Record<string, unknown>;
|
|
322
|
+
extra_data?: Record<string, unknown>;
|
|
323
|
+
cost_rate_per_hour?: number | string;
|
|
324
|
+
sprints_logid?: string | number;
|
|
325
|
+
status?: string;
|
|
326
|
+
for_timer?: boolean | string;
|
|
327
|
+
is_draft?: boolean | string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface ZohoTimeLogUpdateBody extends ZohoTimeLogCreateBody {
|
|
331
|
+
id: RecordId | number;
|
|
332
|
+
approval_status?: string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface ZohoTaskRecurrence {
|
|
336
|
+
trigger_type?: 'on_schedule' | 'on_complete' | 'first_to_occur';
|
|
337
|
+
retain_config?: {
|
|
338
|
+
comments?: boolean;
|
|
339
|
+
billing_type?: boolean;
|
|
340
|
+
followers?: boolean;
|
|
341
|
+
description?: boolean;
|
|
342
|
+
subtasks?: boolean;
|
|
343
|
+
tags?: boolean;
|
|
344
|
+
attachments?: boolean;
|
|
345
|
+
teams?: boolean;
|
|
346
|
+
};
|
|
347
|
+
date_based?: {
|
|
348
|
+
field_name?: string;
|
|
349
|
+
repetative_type?: 'once' | 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
350
|
+
time_span?: number;
|
|
351
|
+
ends_after_type?: 'none' | 'date' | 'count';
|
|
352
|
+
ends_after_value?: string | number;
|
|
353
|
+
skip_type?: 'skip' | 'execute' | 'prepone' | 'postpone';
|
|
354
|
+
duration_type?: string;
|
|
355
|
+
no_of_duration?: number;
|
|
356
|
+
};
|
|
357
|
+
scheduler_based?: {
|
|
358
|
+
repetative_type?: 'once' | 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
359
|
+
time_span?: number;
|
|
360
|
+
ends_after_type?: 'none' | 'date' | 'count';
|
|
361
|
+
ends_after_value?: string | number;
|
|
362
|
+
skip_type?: 'skip' | 'execute' | 'prepone' | 'postpone';
|
|
363
|
+
time?: string;
|
|
364
|
+
days_of_week?: number[];
|
|
365
|
+
months_of_year?: number[];
|
|
366
|
+
repeat_on_type?: number;
|
|
367
|
+
repeat_on_value?: string | number;
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface ZohoTaskBudgetInfo {
|
|
372
|
+
rate_per_hour?: number;
|
|
373
|
+
budget?: string;
|
|
374
|
+
threshold?: string;
|
|
375
|
+
revenue_budget?: number;
|
|
376
|
+
cost_rate_per_hour?: number;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface ZohoIssue {
|
|
380
|
+
id?: RecordId | number;
|
|
381
|
+
name?: string;
|
|
382
|
+
description?: string;
|
|
383
|
+
status?: ZohoStatusRef;
|
|
384
|
+
layout?: ZohoNamedRef;
|
|
385
|
+
project?: ZohoNamedRef;
|
|
386
|
+
is_closed?: boolean;
|
|
387
|
+
is_external?: boolean;
|
|
388
|
+
[key: string]: unknown;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface ZohoComment {
|
|
392
|
+
id?: RecordId | number;
|
|
393
|
+
comment?: string;
|
|
394
|
+
attachments?: Array<RecordId | number>;
|
|
395
|
+
[key: string]: unknown;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface ZohoListResponse<T> {
|
|
399
|
+
data?: T[];
|
|
400
|
+
items?: T[];
|
|
401
|
+
portals?: T[];
|
|
402
|
+
projects?: T[];
|
|
403
|
+
tasklists?: T[];
|
|
404
|
+
tasks?: T[];
|
|
405
|
+
issues?: T[];
|
|
406
|
+
comments?: T[];
|
|
407
|
+
fields?: T[];
|
|
408
|
+
modules?: T[];
|
|
409
|
+
options?: T[];
|
|
410
|
+
[key: string]: unknown;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface ZohoPageInfo {
|
|
414
|
+
per_page?: number;
|
|
415
|
+
page?: number;
|
|
416
|
+
count?: number;
|
|
417
|
+
has_next_page?: boolean;
|
|
418
|
+
[key: string]: unknown;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export interface ZohoFollower {
|
|
422
|
+
id?: RecordId | number;
|
|
423
|
+
zpuid?: RecordId | number;
|
|
424
|
+
name?: string;
|
|
425
|
+
full_name?: string;
|
|
426
|
+
first_name?: string;
|
|
427
|
+
last_name?: string;
|
|
428
|
+
email?: string;
|
|
429
|
+
is_client_user?: boolean;
|
|
430
|
+
[key: string]: unknown;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface ZohoCommentPage<T> {
|
|
434
|
+
comments?: T[];
|
|
435
|
+
page_info?: ZohoPageInfo;
|
|
436
|
+
[key: string]: unknown;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface ZohoPageParams {
|
|
440
|
+
page?: number;
|
|
441
|
+
per_page?: number;
|
|
442
|
+
index?: number;
|
|
443
|
+
range?: number;
|
|
444
|
+
[key: string]: unknown;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface ZohoCriteria {
|
|
448
|
+
field_name?: string;
|
|
449
|
+
api_name?: string;
|
|
450
|
+
criteria_condition?: string;
|
|
451
|
+
value?: unknown[];
|
|
452
|
+
cfid?: RecordId | number;
|
|
453
|
+
offset?: number;
|
|
454
|
+
unit?: 'days' | 'hours';
|
|
455
|
+
prior?: 'before' | 'after' | 'add' | 'subtract';
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export interface ZohoFilter {
|
|
459
|
+
criteria?: ZohoCriteria[];
|
|
460
|
+
pattern?: string;
|
|
461
|
+
is_mandatory?: boolean;
|
|
462
|
+
is_renamed?: boolean;
|
|
463
|
+
is_default?: boolean;
|
|
464
|
+
is_unassociated?: boolean;
|
|
465
|
+
is_association_info_needed?: boolean;
|
|
466
|
+
is_formula_based_list?: boolean;
|
|
467
|
+
layout_id?: RecordId | number;
|
|
468
|
+
project_id?: RecordId | number;
|
|
469
|
+
field_ids?: Array<RecordId | number>;
|
|
470
|
+
fields?: string[];
|
|
471
|
+
search_term?: string;
|
|
472
|
+
relative_columns?: Array<ZohoCriteria>;
|
|
473
|
+
[key: string]: unknown;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export interface PortalTrashRequest {
|
|
477
|
+
module: ModuleName;
|
|
478
|
+
items: Array<RecordId | number>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface ModuleBulkOptionsRequest {
|
|
482
|
+
values?: Array<string | number | Record<string, unknown>>;
|
|
483
|
+
[key: string]: unknown;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface ZohoOAuthTokens {
|
|
487
|
+
access_token: string;
|
|
488
|
+
refresh_token?: string;
|
|
489
|
+
api_domain?: string;
|
|
490
|
+
token_type?: string;
|
|
491
|
+
expires_in?: number;
|
|
492
|
+
[key: string]: unknown;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export interface ZohoOAuthConfig {
|
|
496
|
+
clientId: string;
|
|
497
|
+
clientSecret?: string | undefined;
|
|
498
|
+
redirectUri?: string | undefined;
|
|
499
|
+
accountsBaseUrl?: string | undefined;
|
|
500
|
+
scope?: string | string[] | undefined;
|
|
501
|
+
accessType?: 'offline' | 'online' | undefined;
|
|
502
|
+
prompt?: 'consent' | 'login' | undefined;
|
|
503
|
+
state?: string | undefined;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export interface ZohoClientConfig {
|
|
507
|
+
accessToken?: string | undefined;
|
|
508
|
+
apiBaseUrl?: string | undefined;
|
|
509
|
+
accountsBaseUrl?: string | undefined;
|
|
510
|
+
clientId?: string | undefined;
|
|
511
|
+
clientSecret?: string | undefined;
|
|
512
|
+
redirectUri?: string | undefined;
|
|
513
|
+
scope?: string | string[] | undefined;
|
|
514
|
+
fetch?: typeof fetch | undefined;
|
|
515
|
+
userAgent?: string | undefined;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export interface RequestOptions {
|
|
519
|
+
method?: string | undefined;
|
|
520
|
+
query?: Record<string, unknown> | undefined;
|
|
521
|
+
headers?: HeadersInit | undefined;
|
|
522
|
+
body?: unknown;
|
|
523
|
+
formData?: FormData | undefined;
|
|
524
|
+
retry?: number | undefined;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export interface RequestContext {
|
|
528
|
+
baseUrl: string;
|
|
529
|
+
accessToken?: string | undefined;
|
|
530
|
+
userAgent: string;
|
|
531
|
+
fetchImpl: typeof fetch;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export interface ZohoErrorPayload {
|
|
535
|
+
error?: string;
|
|
536
|
+
message?: string;
|
|
537
|
+
code?: string | number;
|
|
538
|
+
[key: string]: unknown;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export interface ZohoApiErrorInfo {
|
|
542
|
+
status: number;
|
|
543
|
+
requestId?: string | undefined;
|
|
544
|
+
retryable: boolean;
|
|
545
|
+
responseBody: unknown;
|
|
546
|
+
}
|
package/test/helpers.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type FetchCall = {
|
|
2
|
+
input: RequestInfo | URL;
|
|
3
|
+
init?: RequestInit | undefined;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export function makeFetchStub(responses: Response[] = []) {
|
|
7
|
+
const calls: FetchCall[] = [];
|
|
8
|
+
const fetchStub = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
9
|
+
calls.push({ input, init });
|
|
10
|
+
const response = responses.shift();
|
|
11
|
+
if (!response) {
|
|
12
|
+
throw new Error('No stubbed response available');
|
|
13
|
+
}
|
|
14
|
+
return response;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return { calls, fetchStub };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function jsonResponse(body: unknown, init: ResponseInit = {}): Response {
|
|
21
|
+
return new Response(JSON.stringify(body), {
|
|
22
|
+
...init,
|
|
23
|
+
headers: {
|
|
24
|
+
'content-type': 'application/json',
|
|
25
|
+
...(init.headers ?? {}),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { ZohoProjectsClient } from '@/client.ts';
|
|
4
|
+
import { AuthenticationError, RateLimitError, ServerError } from '@/errors.ts';
|
|
5
|
+
import { makeFetchStub, jsonResponse } from './helpers.ts';
|
|
6
|
+
|
|
7
|
+
test('request appends query params and auth headers', async () => {
|
|
8
|
+
const { fetchStub, calls } = makeFetchStub([jsonResponse({ ok: true })]);
|
|
9
|
+
const client = new ZohoProjectsClient({ accessToken: 'abc', fetch: fetchStub });
|
|
10
|
+
|
|
11
|
+
const result = await client.request<{ ok: boolean }>('portal/123', {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
query: { page: 1, filter: { pattern: 'alpha' } },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
assert.deepEqual(result, { ok: true });
|
|
17
|
+
assert.equal(String(calls[0].input), 'https://projectsapi.zoho.com/api/v3/portal/123?page=1&filter=%7B%22pattern%22%3A%22alpha%22%7D');
|
|
18
|
+
assert.equal(calls[0].init?.headers instanceof Headers, true);
|
|
19
|
+
const headers = calls[0].init?.headers as Headers;
|
|
20
|
+
assert.equal(headers.get('Authorization'), 'Zoho-oauthtoken abc');
|
|
21
|
+
assert.equal(headers.get('User-Agent'), 'zoho-projects-wrapper/0.1.0');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('request serializes JSON bodies', async () => {
|
|
25
|
+
const { fetchStub, calls } = makeFetchStub([jsonResponse({ ok: true })]);
|
|
26
|
+
const client = new ZohoProjectsClient({ accessToken: 'abc', fetch: fetchStub });
|
|
27
|
+
|
|
28
|
+
await client.request('portal/123/trash', {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body: { module: 'tasks', items: ['1', '2'] },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
assert.equal(calls[0].init?.body, JSON.stringify({ module: 'tasks', items: ['1', '2'] }));
|
|
34
|
+
const headers = calls[0].init?.headers as Headers;
|
|
35
|
+
assert.equal(headers.get('Content-Type'), 'application/json');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('request maps auth, rate limit, and server failures to typed errors', async () => {
|
|
39
|
+
const { fetchStub } = makeFetchStub([
|
|
40
|
+
jsonResponse({ message: 'nope' }, { status: 401 }),
|
|
41
|
+
jsonResponse({ error: 'too many requests' }, { status: 429 }),
|
|
42
|
+
jsonResponse({ message: 'boom' }, { status: 500 }),
|
|
43
|
+
]);
|
|
44
|
+
const client = new ZohoProjectsClient({ accessToken: 'abc', fetch: fetchStub });
|
|
45
|
+
|
|
46
|
+
await assert.rejects(client.request('portal/123', { method: 'GET' }), AuthenticationError);
|
|
47
|
+
await assert.rejects(client.request('portal/123', { method: 'GET' }), RateLimitError);
|
|
48
|
+
await assert.rejects(client.request('portal/123', { method: 'GET' }), ServerError);
|
|
49
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { ZohoOAuthClient } from '@/oauth.ts';
|
|
4
|
+
import { makeFetchStub, jsonResponse } from './helpers.ts';
|
|
5
|
+
|
|
6
|
+
test('authorizationUrl builds the Zoho auth URL with default offline access', () => {
|
|
7
|
+
const oauth = new ZohoOAuthClient({
|
|
8
|
+
clientId: 'client-123',
|
|
9
|
+
redirectUri: 'https://example.com/callback',
|
|
10
|
+
scope: ['ZohoProjects.projects.READ', 'ZohoProjects.tasks.READ'],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const url = new URL(oauth.authorizationUrl());
|
|
14
|
+
assert.equal(url.origin, 'https://accounts.zoho.com');
|
|
15
|
+
assert.equal(url.pathname, '/oauth/v2/auth');
|
|
16
|
+
assert.equal(url.searchParams.get('client_id'), 'client-123');
|
|
17
|
+
assert.equal(url.searchParams.get('redirect_uri'), 'https://example.com/callback');
|
|
18
|
+
assert.equal(url.searchParams.get('response_type'), 'code');
|
|
19
|
+
assert.equal(url.searchParams.get('access_type'), 'offline');
|
|
20
|
+
assert.equal(url.searchParams.get('scope'), 'ZohoProjects.projects.READ,ZohoProjects.tasks.READ');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('exchangeCode posts form data to the Zoho token endpoint', async () => {
|
|
24
|
+
const { fetchStub, calls } = makeFetchStub([
|
|
25
|
+
jsonResponse({ access_token: 'access', refresh_token: 'refresh', expires_in: 3600 }),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
const oauth = new ZohoOAuthClient(
|
|
29
|
+
{
|
|
30
|
+
clientId: 'client-123',
|
|
31
|
+
clientSecret: 'secret-456',
|
|
32
|
+
redirectUri: 'https://example.com/callback',
|
|
33
|
+
},
|
|
34
|
+
fetchStub,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const tokens = await oauth.exchangeCode({ code: 'code-abc' });
|
|
38
|
+
assert.equal(tokens.access_token, 'access');
|
|
39
|
+
assert.equal(calls.length, 1);
|
|
40
|
+
assert.equal(String(calls[0].input), 'https://accounts.zoho.com/oauth/v2/token');
|
|
41
|
+
assert.equal(calls[0].init?.method, 'POST');
|
|
42
|
+
|
|
43
|
+
const body = calls[0].init?.body as URLSearchParams;
|
|
44
|
+
assert.equal(body.get('grant_type'), 'authorization_code');
|
|
45
|
+
assert.equal(body.get('code'), 'code-abc');
|
|
46
|
+
assert.equal(body.get('client_id'), 'client-123');
|
|
47
|
+
assert.equal(body.get('client_secret'), 'secret-456');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('refreshAccessToken and revokeToken use the accounts base URL', async () => {
|
|
51
|
+
const { fetchStub, calls } = makeFetchStub([
|
|
52
|
+
jsonResponse({ access_token: 'new-access', expires_in: 3600 }),
|
|
53
|
+
jsonResponse({ status: 'success' }),
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const oauth = new ZohoOAuthClient(
|
|
57
|
+
{
|
|
58
|
+
clientId: 'client-123',
|
|
59
|
+
clientSecret: 'secret-456',
|
|
60
|
+
accountsBaseUrl: 'https://accounts.zoho.eu',
|
|
61
|
+
},
|
|
62
|
+
fetchStub,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const refreshed = await oauth.refreshAccessToken({ refreshToken: 'refresh-token' });
|
|
66
|
+
assert.equal(refreshed.access_token, 'new-access');
|
|
67
|
+
assert.equal(String(calls[0].input), 'https://accounts.zoho.eu/oauth/v2/token');
|
|
68
|
+
|
|
69
|
+
const revoked = await oauth.revokeToken({ token: 'refresh-token' });
|
|
70
|
+
assert.equal(revoked.status, 'success');
|
|
71
|
+
assert.equal(String(calls[1].input), 'https://accounts.zoho.eu/oauth/v2/token/revoke?token=refresh-token');
|
|
72
|
+
});
|