@panoptic-it-solutions/zoho-projects-client 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/README.md +231 -0
- package/dist/auth/token-manager.d.ts +59 -0
- package/dist/auth/token-manager.d.ts.map +1 -0
- package/dist/auth/token-manager.js +120 -0
- package/dist/auth/token-manager.js.map +1 -0
- package/dist/client.d.ts +193 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +357 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +61 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +113 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/types/common.d.ts +173 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +56 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/projects.d.ts +3671 -0
- package/dist/types/projects.d.ts.map +1 -0
- package/dist/types/projects.js +94 -0
- package/dist/types/projects.js.map +1 -0
- package/dist/types/tasks.d.ts +2612 -0
- package/dist/types/tasks.d.ts.map +1 -0
- package/dist/types/tasks.js +127 -0
- package/dist/types/tasks.js.map +1 -0
- package/dist/types/timelogs.d.ts +13623 -0
- package/dist/types/timelogs.d.ts.map +1 -0
- package/dist/types/timelogs.js +115 -0
- package/dist/types/timelogs.js.map +1 -0
- package/dist/types/users.d.ts +695 -0
- package/dist/types/users.d.ts.map +1 -0
- package/dist/types/users.js +65 -0
- package/dist/types/users.js.map +1 -0
- package/dist/utils/pagination.d.ts +59 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +84 -0
- package/dist/utils/pagination.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +33 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +92 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/package.json +53 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { TokenManager } from "./auth/token-manager.js";
|
|
4
|
+
import { parseAxiosError, ZohoProjectsError, ZohoResponseValidationError, } from "./errors.js";
|
|
5
|
+
import { ProjectSchema, ProjectListResponseSchema, TaskSchema, TaskListResponseSchema, TimeLogListResponseSchema, UserSchema, UserListResponseSchema, } from "./types/index.js";
|
|
6
|
+
import { createRateLimiter } from "./utils/rate-limiter.js";
|
|
7
|
+
import { autoPaginate, collectAll, DEFAULT_PAGE_SIZE, } from "./utils/pagination.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default API URL (US region)
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_API_URL = "https://projectsapi.zoho.com";
|
|
12
|
+
/**
|
|
13
|
+
* Default accounts URL (US region)
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_ACCOUNTS_URL = "https://accounts.zoho.com";
|
|
16
|
+
/**
|
|
17
|
+
* Create a Zoho Projects API client
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const client = createZohoProjectsClient({
|
|
22
|
+
* clientId: process.env.ZOHO_CLIENT_ID!,
|
|
23
|
+
* clientSecret: process.env.ZOHO_CLIENT_SECRET!,
|
|
24
|
+
* portalId: process.env.ZOHO_PORTAL_ID!,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // List all projects
|
|
28
|
+
* const projects = await client.projects.list();
|
|
29
|
+
*
|
|
30
|
+
* // Get all projects with auto-pagination
|
|
31
|
+
* const allProjects = await client.projects.listAll();
|
|
32
|
+
*
|
|
33
|
+
* // Stream projects with async iteration
|
|
34
|
+
* for await (const project of client.projects.iterate()) {
|
|
35
|
+
* console.log(project.name);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function createZohoProjectsClient(config) {
|
|
40
|
+
const { clientId, clientSecret, refreshToken, portalId, apiUrl = DEFAULT_API_URL, accountsUrl = DEFAULT_ACCOUNTS_URL, timeout = 30000, redis, } = config;
|
|
41
|
+
// Initialize token manager
|
|
42
|
+
const tokenManagerConfig = {
|
|
43
|
+
clientId,
|
|
44
|
+
clientSecret,
|
|
45
|
+
refreshToken,
|
|
46
|
+
accountsUrl,
|
|
47
|
+
};
|
|
48
|
+
const tokenManager = new TokenManager(tokenManagerConfig);
|
|
49
|
+
// Initialize rate limiter
|
|
50
|
+
const rateLimiter = createRateLimiter({ redis });
|
|
51
|
+
// Initialize HTTP client
|
|
52
|
+
const httpClient = axios.create({
|
|
53
|
+
baseURL: apiUrl,
|
|
54
|
+
timeout,
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
// Add auth interceptor
|
|
60
|
+
httpClient.interceptors.request.use(async (config) => {
|
|
61
|
+
const token = await tokenManager.getValidToken();
|
|
62
|
+
config.headers.Authorization = `Zoho-oauthtoken ${token}`;
|
|
63
|
+
return config;
|
|
64
|
+
});
|
|
65
|
+
// Add error handling interceptor
|
|
66
|
+
httpClient.interceptors.response.use((response) => response, (error) => {
|
|
67
|
+
if (axios.isAxiosError(error)) {
|
|
68
|
+
// Invalidate token on 401
|
|
69
|
+
if (error.response?.status === 401) {
|
|
70
|
+
tokenManager.invalidate();
|
|
71
|
+
}
|
|
72
|
+
throw parseAxiosError(error);
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Make a rate-limited API request
|
|
78
|
+
*/
|
|
79
|
+
async function request(path, config) {
|
|
80
|
+
return rateLimiter.schedule(async () => {
|
|
81
|
+
const response = await httpClient.request({
|
|
82
|
+
url: path,
|
|
83
|
+
...config,
|
|
84
|
+
});
|
|
85
|
+
return response.data;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Make a request and validate response with Zod schema
|
|
90
|
+
*/
|
|
91
|
+
async function requestWithValidation(path, schema, config) {
|
|
92
|
+
const data = await request(path, config);
|
|
93
|
+
const result = schema.safeParse(data);
|
|
94
|
+
if (!result.success) {
|
|
95
|
+
throw new ZohoResponseValidationError(`Invalid API response structure: ${result.error.message}`, result.error.errors, data);
|
|
96
|
+
}
|
|
97
|
+
return result.data;
|
|
98
|
+
}
|
|
99
|
+
// Base path for portal-specific endpoints
|
|
100
|
+
const basePath = `/restapi/portal/${portalId}`;
|
|
101
|
+
return {
|
|
102
|
+
/**
|
|
103
|
+
* Projects API
|
|
104
|
+
*/
|
|
105
|
+
projects: {
|
|
106
|
+
/**
|
|
107
|
+
* List projects with pagination
|
|
108
|
+
*/
|
|
109
|
+
async list(params) {
|
|
110
|
+
const response = await requestWithValidation(`${basePath}/projects/`, ProjectListResponseSchema, {
|
|
111
|
+
params: {
|
|
112
|
+
index: params?.index ?? 0,
|
|
113
|
+
range: params?.range ?? DEFAULT_PAGE_SIZE,
|
|
114
|
+
sort_column: params?.sort_column,
|
|
115
|
+
sort_order: params?.sort_order,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
data: response.projects,
|
|
120
|
+
pageInfo: response.page_info,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Get all projects with auto-pagination
|
|
125
|
+
*/
|
|
126
|
+
async listAll(options) {
|
|
127
|
+
return collectAll(this.iterate(options));
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Iterate over all projects with auto-pagination
|
|
131
|
+
*/
|
|
132
|
+
iterate(options) {
|
|
133
|
+
return autoPaginate((index, range) => this.list({ index, range }), options);
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Get a single project by ID
|
|
137
|
+
*/
|
|
138
|
+
async get(projectId) {
|
|
139
|
+
const response = await requestWithValidation(`${basePath}/projects/${projectId}/`, z.object({ projects: z.array(ProjectSchema) }));
|
|
140
|
+
if (response.projects.length === 0) {
|
|
141
|
+
throw new ZohoProjectsError(`Project not found: ${projectId}`, 404);
|
|
142
|
+
}
|
|
143
|
+
return response.projects[0];
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
/**
|
|
147
|
+
* Tasks API
|
|
148
|
+
*/
|
|
149
|
+
tasks: {
|
|
150
|
+
/**
|
|
151
|
+
* List tasks for a project with pagination
|
|
152
|
+
*/
|
|
153
|
+
async list(projectId, params) {
|
|
154
|
+
const response = await requestWithValidation(`${basePath}/projects/${projectId}/tasks/`, TaskListResponseSchema, {
|
|
155
|
+
params: {
|
|
156
|
+
index: params?.index ?? 0,
|
|
157
|
+
range: params?.range ?? DEFAULT_PAGE_SIZE,
|
|
158
|
+
sort_column: params?.sort_column,
|
|
159
|
+
sort_order: params?.sort_order,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
data: response.tasks,
|
|
164
|
+
pageInfo: response.page_info,
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* Get all tasks for a project with auto-pagination
|
|
169
|
+
*/
|
|
170
|
+
async listAll(projectId, options) {
|
|
171
|
+
return collectAll(this.iterate(projectId, options));
|
|
172
|
+
},
|
|
173
|
+
/**
|
|
174
|
+
* Iterate over all tasks for a project with auto-pagination
|
|
175
|
+
*/
|
|
176
|
+
iterate(projectId, options) {
|
|
177
|
+
return autoPaginate((index, range) => this.list(projectId, { index, range }), options);
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Get a single task by ID
|
|
181
|
+
*/
|
|
182
|
+
async get(projectId, taskId) {
|
|
183
|
+
const response = await requestWithValidation(`${basePath}/projects/${projectId}/tasks/${taskId}/`, z.object({ tasks: z.array(TaskSchema) }));
|
|
184
|
+
if (response.tasks.length === 0) {
|
|
185
|
+
throw new ZohoProjectsError(`Task not found: ${taskId}`, 404);
|
|
186
|
+
}
|
|
187
|
+
return response.tasks[0];
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* List all tasks across all projects
|
|
191
|
+
* Note: This fetches all projects first, then tasks for each
|
|
192
|
+
*/
|
|
193
|
+
async listAllAcrossProjects(options) {
|
|
194
|
+
const projects = await this._getProjectsRef().listAll();
|
|
195
|
+
const allTasks = [];
|
|
196
|
+
for (const project of projects) {
|
|
197
|
+
const tasks = await this.listAll(project.id_string, options);
|
|
198
|
+
allTasks.push(...tasks);
|
|
199
|
+
}
|
|
200
|
+
return allTasks;
|
|
201
|
+
},
|
|
202
|
+
// Internal reference to projects API
|
|
203
|
+
_getProjectsRef: () => client.projects,
|
|
204
|
+
},
|
|
205
|
+
/**
|
|
206
|
+
* Time Logs API
|
|
207
|
+
*/
|
|
208
|
+
timelogs: {
|
|
209
|
+
/**
|
|
210
|
+
* List time logs for a project
|
|
211
|
+
*/
|
|
212
|
+
async list(projectId, params) {
|
|
213
|
+
// Make the request - may return 204 No Content if no logs
|
|
214
|
+
const rawResponse = await request(`${basePath}/projects/${projectId}/logs/`, {
|
|
215
|
+
params: {
|
|
216
|
+
index: params.index ?? 0,
|
|
217
|
+
range: params.range ?? DEFAULT_PAGE_SIZE,
|
|
218
|
+
users_list: params.users_list,
|
|
219
|
+
view_type: params.view_type,
|
|
220
|
+
date: params.date,
|
|
221
|
+
bill_status: params.bill_status,
|
|
222
|
+
component_type: params.component_type,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
// Handle 204 No Content (empty string response)
|
|
226
|
+
if (!rawResponse || rawResponse === "") {
|
|
227
|
+
return { data: [], pageInfo: undefined };
|
|
228
|
+
}
|
|
229
|
+
// Validate response structure
|
|
230
|
+
const result = TimeLogListResponseSchema.safeParse(rawResponse);
|
|
231
|
+
if (!result.success) {
|
|
232
|
+
throw new ZohoResponseValidationError(`Invalid API response structure: ${result.error.message}`, result.error.errors, rawResponse);
|
|
233
|
+
}
|
|
234
|
+
const response = result.data;
|
|
235
|
+
// Flatten the nested date structure into a simple array
|
|
236
|
+
const logs = [];
|
|
237
|
+
if (response.timelogs?.date) {
|
|
238
|
+
for (const dateGroup of response.timelogs.date) {
|
|
239
|
+
if (dateGroup.tasklogs)
|
|
240
|
+
logs.push(...dateGroup.tasklogs);
|
|
241
|
+
if (dateGroup.buglogs)
|
|
242
|
+
logs.push(...dateGroup.buglogs);
|
|
243
|
+
if (dateGroup.generallogs)
|
|
244
|
+
logs.push(...dateGroup.generallogs);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Also handle flat structure
|
|
248
|
+
if (response.tasklogs)
|
|
249
|
+
logs.push(...response.tasklogs);
|
|
250
|
+
if (response.buglogs)
|
|
251
|
+
logs.push(...response.buglogs);
|
|
252
|
+
if (response.generallogs)
|
|
253
|
+
logs.push(...response.generallogs);
|
|
254
|
+
return {
|
|
255
|
+
data: logs,
|
|
256
|
+
pageInfo: response.page_info,
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* Get all time logs for a project with auto-pagination
|
|
261
|
+
*/
|
|
262
|
+
async listAll(projectId, params, options) {
|
|
263
|
+
return collectAll(this.iterate(projectId, params, options));
|
|
264
|
+
},
|
|
265
|
+
/**
|
|
266
|
+
* Iterate over all time logs for a project with auto-pagination
|
|
267
|
+
*/
|
|
268
|
+
iterate(projectId, params, options) {
|
|
269
|
+
return autoPaginate((index, range) => this.list(projectId, { ...params, index, range }), options);
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* List all time logs across all projects
|
|
273
|
+
*/
|
|
274
|
+
async listAllAcrossProjects(params, options) {
|
|
275
|
+
const projects = await this._getProjectsRef().listAll();
|
|
276
|
+
const allLogs = [];
|
|
277
|
+
for (const project of projects) {
|
|
278
|
+
const logs = await this.listAll(project.id_string, params, options);
|
|
279
|
+
allLogs.push(...logs);
|
|
280
|
+
}
|
|
281
|
+
return allLogs;
|
|
282
|
+
},
|
|
283
|
+
// Internal reference to projects API
|
|
284
|
+
_getProjectsRef: () => client.projects,
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* Users API
|
|
288
|
+
*/
|
|
289
|
+
users: {
|
|
290
|
+
/**
|
|
291
|
+
* List all users in the portal
|
|
292
|
+
*/
|
|
293
|
+
async list(params) {
|
|
294
|
+
const response = await requestWithValidation(`${basePath}/users/`, UserListResponseSchema, {
|
|
295
|
+
params: {
|
|
296
|
+
index: params?.index ?? 0,
|
|
297
|
+
range: params?.range ?? DEFAULT_PAGE_SIZE,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
data: response.users,
|
|
302
|
+
pageInfo: response.page_info,
|
|
303
|
+
};
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* Get all users with auto-pagination
|
|
307
|
+
*/
|
|
308
|
+
async listAll(options) {
|
|
309
|
+
return collectAll(this.iterate(options));
|
|
310
|
+
},
|
|
311
|
+
/**
|
|
312
|
+
* Iterate over all users with auto-pagination
|
|
313
|
+
*/
|
|
314
|
+
iterate(options) {
|
|
315
|
+
return autoPaginate((index, range) => this.list({ index, range }), options);
|
|
316
|
+
},
|
|
317
|
+
/**
|
|
318
|
+
* Get a single user by ID
|
|
319
|
+
*/
|
|
320
|
+
async get(userId) {
|
|
321
|
+
const response = await requestWithValidation(`${basePath}/users/${userId}/`, z.object({ users: z.array(UserSchema) }));
|
|
322
|
+
if (response.users.length === 0) {
|
|
323
|
+
throw new ZohoProjectsError(`User not found: ${userId}`, 404);
|
|
324
|
+
}
|
|
325
|
+
return response.users[0];
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* List users for a specific project
|
|
329
|
+
*/
|
|
330
|
+
async listForProject(projectId, params) {
|
|
331
|
+
const response = await requestWithValidation(`${basePath}/projects/${projectId}/users/`, UserListResponseSchema, {
|
|
332
|
+
params: {
|
|
333
|
+
index: params?.index ?? 0,
|
|
334
|
+
range: params?.range ?? DEFAULT_PAGE_SIZE,
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
return {
|
|
338
|
+
data: response.users,
|
|
339
|
+
pageInfo: response.page_info,
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
/**
|
|
344
|
+
* Get the underlying token manager for advanced use cases
|
|
345
|
+
*/
|
|
346
|
+
getTokenManager: () => tokenManager,
|
|
347
|
+
/**
|
|
348
|
+
* Get the underlying rate limiter for monitoring
|
|
349
|
+
*/
|
|
350
|
+
getRateLimiter: () => rateLimiter,
|
|
351
|
+
};
|
|
352
|
+
// Store reference for internal use
|
|
353
|
+
const client = {
|
|
354
|
+
projects: {},
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsD,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAA2B,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EAEtB,yBAAyB,EACzB,UAAU,EACV,sBAAsB,GAOvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAA0B,MAAM,yBAAyB,CAAC;AACpF,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,GAGlB,MAAM,uBAAuB,CAAC;AAwB/B;;GAEG;AACH,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAEvD;;GAEG;AACH,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AAEzD;;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C1C;iBACF,CACF,CAAC;gBACF,OAAO;oBACL,IAAI,EAAE,QAAQ,CAAC,KAAK;oBACpB,QAAQ,EAAE,QAAQ,CAAC,SAAS;iBAC7B,CAAC;YACJ,CAAC;SACF;QAED;;WAEG;QACH,eAAe,EAAE,GAAG,EAAE,CAAC,YAAY;QAEnC;;WAEG;QACH,cAAc,EAAE,GAAG,EAAE,CAAC,WAAW;KAClC,CAAC;IAEF,mCAAmC;IACnC,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,EAA6D;KACxE,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AxiosError } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* Base error class for Zoho Projects API errors
|
|
4
|
+
*/
|
|
5
|
+
export declare class ZohoProjectsError extends Error {
|
|
6
|
+
readonly code?: number | undefined;
|
|
7
|
+
readonly cause?: Error | undefined;
|
|
8
|
+
constructor(message: string, code?: number | undefined, cause?: Error | undefined);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when authentication fails
|
|
12
|
+
*/
|
|
13
|
+
export declare class ZohoAuthenticationError extends ZohoProjectsError {
|
|
14
|
+
constructor(message: string, cause?: Error);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when rate limit is exceeded
|
|
18
|
+
* Includes lockout duration for the 30-minute lockout period
|
|
19
|
+
*/
|
|
20
|
+
export declare class ZohoRateLimitError extends ZohoProjectsError {
|
|
21
|
+
readonly lockoutDurationMs: number;
|
|
22
|
+
constructor(message: string, lockoutDurationMs?: number, // 30 minutes default
|
|
23
|
+
cause?: Error);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when a resource is not found
|
|
27
|
+
*/
|
|
28
|
+
export declare class ZohoNotFoundError extends ZohoProjectsError {
|
|
29
|
+
readonly resourceType?: string | undefined;
|
|
30
|
+
readonly resourceId?: string | undefined;
|
|
31
|
+
constructor(message: string, resourceType?: string | undefined, resourceId?: string | undefined, cause?: Error);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when request validation fails
|
|
35
|
+
*/
|
|
36
|
+
export declare class ZohoValidationError extends ZohoProjectsError {
|
|
37
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
38
|
+
constructor(message: string, details?: Record<string, unknown> | undefined, cause?: Error);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Error thrown when Zod validation of API response fails
|
|
42
|
+
* Indicates the API returned unexpected data structure
|
|
43
|
+
*/
|
|
44
|
+
export declare class ZohoResponseValidationError extends ZohoProjectsError {
|
|
45
|
+
readonly zodErrors?: unknown | undefined;
|
|
46
|
+
readonly rawResponse?: unknown | undefined;
|
|
47
|
+
constructor(message: string, zodErrors?: unknown | undefined, rawResponse?: unknown | undefined);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse Axios error into appropriate Zoho error class
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseAxiosError(error: AxiosError): ZohoProjectsError;
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if error is a Zoho rate limit error
|
|
55
|
+
*/
|
|
56
|
+
export declare function isRateLimitError(error: unknown): error is ZohoRateLimitError;
|
|
57
|
+
/**
|
|
58
|
+
* Type guard to check if error is a Zoho authentication error
|
|
59
|
+
*/
|
|
60
|
+
export declare function isAuthError(error: unknown): error is ZohoAuthenticationError;
|
|
61
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAExC;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,IAAI,CAAC,EAAE,MAAM;aACb,KAAK,CAAC,EAAE,KAAK;gBAF7B,OAAO,EAAE,M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CAE7B;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,uBAAuB,CAElC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for Zoho Projects API errors
|
|
3
|
+
*/
|
|
4
|
+
export class ZohoProjectsError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
cause;
|
|
7
|
+
constructor(message, code, cause) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.cause = cause;
|
|
11
|
+
this.name = "ZohoProjectsError";
|
|
12
|
+
Object.setPrototypeOf(this, ZohoProjectsError.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when authentication fails
|
|
17
|
+
*/
|
|
18
|
+
export class ZohoAuthenticationError extends ZohoProjectsError {
|
|
19
|
+
constructor(message, cause) {
|
|
20
|
+
super(message, 401, cause);
|
|
21
|
+
this.name = "ZohoAuthenticationError";
|
|
22
|
+
Object.setPrototypeOf(this, ZohoAuthenticationError.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when rate limit is exceeded
|
|
27
|
+
* Includes lockout duration for the 30-minute lockout period
|
|
28
|
+
*/
|
|
29
|
+
export class ZohoRateLimitError extends ZohoProjectsError {
|
|
30
|
+
lockoutDurationMs;
|
|
31
|
+
constructor(message, lockoutDurationMs = 30 * 60 * 1000, // 30 minutes default
|
|
32
|
+
cause) {
|
|
33
|
+
super(message, 429, cause);
|
|
34
|
+
this.lockoutDurationMs = lockoutDurationMs;
|
|
35
|
+
this.name = "ZohoRateLimitError";
|
|
36
|
+
Object.setPrototypeOf(this, ZohoRateLimitError.prototype);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Error thrown when a resource is not found
|
|
41
|
+
*/
|
|
42
|
+
export class ZohoNotFoundError extends ZohoProjectsError {
|
|
43
|
+
resourceType;
|
|
44
|
+
resourceId;
|
|
45
|
+
constructor(message, resourceType, resourceId, cause) {
|
|
46
|
+
super(message, 404, cause);
|
|
47
|
+
this.resourceType = resourceType;
|
|
48
|
+
this.resourceId = resourceId;
|
|
49
|
+
this.name = "ZohoNotFoundError";
|
|
50
|
+
Object.setPrototypeOf(this, ZohoNotFoundError.prototype);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Error thrown when request validation fails
|
|
55
|
+
*/
|
|
56
|
+
export class ZohoValidationError extends ZohoProjectsError {
|
|
57
|
+
details;
|
|
58
|
+
constructor(message, details, cause) {
|
|
59
|
+
super(message, 400, cause);
|
|
60
|
+
this.details = details;
|
|
61
|
+
this.name = "ZohoValidationError";
|
|
62
|
+
Object.setPrototypeOf(this, ZohoValidationError.prototype);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Error thrown when Zod validation of API response fails
|
|
67
|
+
* Indicates the API returned unexpected data structure
|
|
68
|
+
*/
|
|
69
|
+
export class ZohoResponseValidationError extends ZohoProjectsError {
|
|
70
|
+
zodErrors;
|
|
71
|
+
rawResponse;
|
|
72
|
+
constructor(message, zodErrors, rawResponse) {
|
|
73
|
+
super(message, undefined);
|
|
74
|
+
this.zodErrors = zodErrors;
|
|
75
|
+
this.rawResponse = rawResponse;
|
|
76
|
+
this.name = "ZohoResponseValidationError";
|
|
77
|
+
Object.setPrototypeOf(this, ZohoResponseValidationError.prototype);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parse Axios error into appropriate Zoho error class
|
|
82
|
+
*/
|
|
83
|
+
export function parseAxiosError(error) {
|
|
84
|
+
const status = error.response?.status;
|
|
85
|
+
const data = error.response?.data;
|
|
86
|
+
const message = data?.error?.message || error.message;
|
|
87
|
+
switch (status) {
|
|
88
|
+
case 401:
|
|
89
|
+
case 403:
|
|
90
|
+
return new ZohoAuthenticationError(message, error);
|
|
91
|
+
case 404:
|
|
92
|
+
return new ZohoNotFoundError(message, undefined, undefined, error);
|
|
93
|
+
case 429:
|
|
94
|
+
return new ZohoRateLimitError(message, 30 * 60 * 1000, error);
|
|
95
|
+
case 400:
|
|
96
|
+
return new ZohoValidationError(message, data?.error, error);
|
|
97
|
+
default:
|
|
98
|
+
return new ZohoProjectsError(message, status, error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Type guard to check if error is a Zoho rate limit error
|
|
103
|
+
*/
|
|
104
|
+
export function isRateLimitError(error) {
|
|
105
|
+
return error instanceof ZohoRateLimitError;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Type guard to check if error is a Zoho authentication error
|
|
109
|
+
*/
|
|
110
|
+
export function isAuthError(error) {
|
|
111
|
+
return error instanceof ZohoAuthenticationError;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAGxB;IACA;IAHlB,YACE,OAAe,EACC,IAAa,EACb,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAS;QACb,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAC5D,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,yBAAyB,C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AAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,KAAc;IAEd,OAAO,KAAK,YAAY,uBAAuB,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./types/index.js";
|
|
2
|
+
export { ZohoProjectsError, ZohoAuthenticationError, ZohoRateLimitError, ZohoNotFoundError, ZohoValidationError, ZohoResponseValidationError, parseAxiosError, isRateLimitError, isAuthError, } from "./errors.js";
|
|
3
|
+
export { createZohoProjectsClient, type ZohoProjectsConfig, type ZohoProjectsClient, } from "./client.js";
|
|
4
|
+
export { autoPaginate, collectAll, DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, type PaginatedResponse, type AutoPaginateOptions, } from "./utils/pagination.js";
|
|
5
|
+
export { createRateLimiter, getRateLimiterStats, type RateLimiterConfig, } from "./utils/rate-limiter.js";
|
|
6
|
+
export { TokenManager, type TokenManagerConfig } from "./auth/token-manager.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,EAChB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
export * from "./types/index.js";
|
|
3
|
+
// Errors
|
|
4
|
+
export { ZohoProjectsError, ZohoAuthenticationError, ZohoRateLimitError, ZohoNotFoundError, ZohoValidationError, ZohoResponseValidationError, parseAxiosError, isRateLimitError, isAuthError, } from "./errors.js";
|
|
5
|
+
// Client
|
|
6
|
+
export { createZohoProjectsClient, } from "./client.js";
|
|
7
|
+
// Utilities
|
|
8
|
+
export { autoPaginate, collectAll, DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, } from "./utils/pagination.js";
|
|
9
|
+
export { createRateLimiter, getRateLimiterStats, } from "./utils/rate-limiter.js";
|
|
10
|
+
export { TokenManager } from "./auth/token-manager.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,SAAS;AACT,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,EAChB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,SAAS;AACT,OAAO,EACL,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AAErB,YAAY;AACZ,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,aAAa,GAGd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAA2B,MAAM,yBAAyB,CAAC"}
|