digital-tools 2.0.2 → 2.1.1
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/CHANGELOG.md +17 -0
- package/package.json +3 -4
- package/src/define.js +267 -0
- package/src/entities/advertising.js +999 -0
- package/src/entities/ai.js +756 -0
- package/src/entities/analytics.js +1588 -0
- package/src/entities/automation.js +601 -0
- package/src/entities/communication.js +1150 -0
- package/src/entities/crm.js +1386 -0
- package/src/entities/design.js +546 -0
- package/src/entities/development.js +2212 -0
- package/src/entities/document.js +874 -0
- package/src/entities/ecommerce.js +1429 -0
- package/src/entities/experiment.js +1039 -0
- package/src/entities/finance.js +3478 -0
- package/src/entities/forms.js +1892 -0
- package/src/entities/hr.js +661 -0
- package/src/entities/identity.js +997 -0
- package/src/entities/index.js +282 -0
- package/src/entities/infrastructure.js +1153 -0
- package/src/entities/knowledge.js +1438 -0
- package/src/entities/marketing.js +1610 -0
- package/src/entities/media.js +1634 -0
- package/src/entities/notification.js +1199 -0
- package/src/entities/presentation.js +1274 -0
- package/src/entities/productivity.js +1317 -0
- package/src/entities/project-management.js +1136 -0
- package/src/entities/recruiting.js +736 -0
- package/src/entities/shipping.js +509 -0
- package/src/entities/signature.js +1102 -0
- package/src/entities/site.js +222 -0
- package/src/entities/spreadsheet.js +1341 -0
- package/src/entities/storage.js +1198 -0
- package/src/entities/support.js +1166 -0
- package/src/entities/video-conferencing.js +1750 -0
- package/src/entities/video.js +950 -0
- package/src/entities.js +1663 -0
- package/src/index.js +74 -0
- package/src/providers/analytics/index.js +17 -0
- package/src/providers/analytics/mixpanel.js +255 -0
- package/src/providers/calendar/cal-com.js +303 -0
- package/src/providers/calendar/google-calendar.js +335 -0
- package/src/providers/calendar/index.js +20 -0
- package/src/providers/crm/hubspot.js +566 -0
- package/src/providers/crm/index.js +17 -0
- package/src/providers/development/github.js +472 -0
- package/src/providers/development/index.js +17 -0
- package/src/providers/ecommerce/index.js +17 -0
- package/src/providers/ecommerce/shopify.js +378 -0
- package/src/providers/email/index.js +20 -0
- package/src/providers/email/resend.js +258 -0
- package/src/providers/email/sendgrid.js +161 -0
- package/src/providers/finance/index.js +17 -0
- package/src/providers/finance/stripe.js +549 -0
- package/src/providers/forms/index.js +17 -0
- package/src/providers/forms/typeform.js +500 -0
- package/src/providers/index.js +123 -0
- package/src/providers/knowledge/index.js +17 -0
- package/src/providers/knowledge/notion.js +389 -0
- package/src/providers/marketing/index.js +17 -0
- package/src/providers/marketing/mailchimp.js +443 -0
- package/src/providers/media/cloudinary.js +318 -0
- package/src/providers/media/index.js +17 -0
- package/src/providers/messaging/index.js +20 -0
- package/src/providers/messaging/slack.js +393 -0
- package/src/providers/messaging/twilio-sms.js +249 -0
- package/src/providers/project-management/index.js +17 -0
- package/src/providers/project-management/linear.js +575 -0
- package/src/providers/registry.js +86 -0
- package/src/providers/spreadsheet/google-sheets.js +375 -0
- package/src/providers/spreadsheet/index.js +20 -0
- package/src/providers/spreadsheet/xlsx.js +423 -0
- package/src/providers/storage/index.js +24 -0
- package/src/providers/storage/s3.js +419 -0
- package/src/providers/support/index.js +17 -0
- package/src/providers/support/zendesk.js +373 -0
- package/src/providers/tasks/index.js +17 -0
- package/src/providers/tasks/todoist.js +286 -0
- package/src/providers/types.js +9 -0
- package/src/providers/video-conferencing/google-meet.js +286 -0
- package/src/providers/video-conferencing/index.js +31 -0
- package/src/providers/video-conferencing/jitsi.js +254 -0
- package/src/providers/video-conferencing/teams.js +270 -0
- package/src/providers/video-conferencing/zoom.js +332 -0
- package/src/registry.js +128 -0
- package/src/tools/communication.js +184 -0
- package/src/tools/data.js +205 -0
- package/src/tools/index.js +11 -0
- package/src/tools/web.js +137 -0
- package/src/types.js +10 -0
- package/test/define.test.js +306 -0
- package/test/registry.test.js +357 -0
- package/test/tools.test.js +363 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zendesk Support Provider
|
|
3
|
+
*
|
|
4
|
+
* Concrete implementation of SupportProvider using Zendesk API v2.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { defineProvider } from '../registry.js';
|
|
9
|
+
/**
|
|
10
|
+
* Zendesk provider info
|
|
11
|
+
*/
|
|
12
|
+
export const zendeskInfo = {
|
|
13
|
+
id: 'support.zendesk',
|
|
14
|
+
name: 'Zendesk',
|
|
15
|
+
description: 'Zendesk customer support and ticketing platform',
|
|
16
|
+
category: 'support',
|
|
17
|
+
website: 'https://www.zendesk.com',
|
|
18
|
+
docsUrl: 'https://developer.zendesk.com/api-reference/',
|
|
19
|
+
requiredConfig: ['subdomain', 'apiKey', 'email'],
|
|
20
|
+
optionalConfig: ['apiVersion'],
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Create Zendesk support provider
|
|
24
|
+
*/
|
|
25
|
+
export function createZendeskProvider(config) {
|
|
26
|
+
let subdomain;
|
|
27
|
+
let apiKey;
|
|
28
|
+
let email;
|
|
29
|
+
let baseUrl;
|
|
30
|
+
return {
|
|
31
|
+
info: zendeskInfo,
|
|
32
|
+
async initialize(cfg) {
|
|
33
|
+
subdomain = cfg.subdomain;
|
|
34
|
+
apiKey = cfg.apiKey;
|
|
35
|
+
email = cfg.email;
|
|
36
|
+
if (!subdomain || !apiKey || !email) {
|
|
37
|
+
throw new Error('Zendesk subdomain, API key, and email are required');
|
|
38
|
+
}
|
|
39
|
+
baseUrl = `https://${subdomain}.zendesk.com/api/v2`;
|
|
40
|
+
},
|
|
41
|
+
async healthCheck() {
|
|
42
|
+
const start = Date.now();
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(`${baseUrl}/users/me.json`, {
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
healthy: response.ok,
|
|
52
|
+
latencyMs: Date.now() - start,
|
|
53
|
+
message: response.ok ? 'Connected' : `HTTP ${response.status}`,
|
|
54
|
+
checkedAt: new Date(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return {
|
|
59
|
+
healthy: false,
|
|
60
|
+
latencyMs: Date.now() - start,
|
|
61
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
62
|
+
checkedAt: new Date(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
async dispose() {
|
|
67
|
+
// No cleanup needed
|
|
68
|
+
},
|
|
69
|
+
async createTicket(ticket) {
|
|
70
|
+
const body = {
|
|
71
|
+
ticket: {
|
|
72
|
+
subject: ticket.subject,
|
|
73
|
+
comment: { body: ticket.description },
|
|
74
|
+
priority: ticket.priority || 'normal',
|
|
75
|
+
type: ticket.type || 'question',
|
|
76
|
+
...(ticket.requesterId && { requester_id: ticket.requesterId }),
|
|
77
|
+
...(ticket.assigneeId && { assignee_id: ticket.assigneeId }),
|
|
78
|
+
...(ticket.tags && { tags: ticket.tags }),
|
|
79
|
+
...(ticket.customFields && { custom_fields: ticket.customFields }),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(`${baseUrl}/tickets.json`, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: {
|
|
86
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
87
|
+
'Content-Type': 'application/json',
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify(body),
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
const error = await response.json().catch(() => ({}));
|
|
93
|
+
throw new Error(error?.error || `HTTP ${response.status}`);
|
|
94
|
+
}
|
|
95
|
+
const data = (await response.json());
|
|
96
|
+
return mapZendeskTicket(data.ticket);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new Error(`Failed to create ticket: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
async getTicket(ticketId) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(`${baseUrl}/tickets/${ticketId}.json`, {
|
|
105
|
+
headers: {
|
|
106
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
if (response.status === 404)
|
|
112
|
+
return null;
|
|
113
|
+
throw new Error(`HTTP ${response.status}`);
|
|
114
|
+
}
|
|
115
|
+
const data = (await response.json());
|
|
116
|
+
return mapZendeskTicket(data.ticket);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
async updateTicket(ticketId, updates) {
|
|
123
|
+
const body = {
|
|
124
|
+
ticket: {
|
|
125
|
+
...(updates.subject && { subject: updates.subject }),
|
|
126
|
+
...(updates.priority && { priority: updates.priority }),
|
|
127
|
+
...(updates.type && { type: updates.type }),
|
|
128
|
+
...(updates.assigneeId && { assignee_id: updates.assigneeId }),
|
|
129
|
+
...(updates.tags && { tags: updates.tags }),
|
|
130
|
+
...(updates.customFields && { custom_fields: updates.customFields }),
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
// Add comment if description is provided
|
|
134
|
+
if (updates.description) {
|
|
135
|
+
body.ticket.comment = { body: updates.description };
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const response = await fetch(`${baseUrl}/tickets/${ticketId}.json`, {
|
|
139
|
+
method: 'PUT',
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
},
|
|
144
|
+
body: JSON.stringify(body),
|
|
145
|
+
});
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
const error = await response.json().catch(() => ({}));
|
|
148
|
+
throw new Error(error?.error || `HTTP ${response.status}`);
|
|
149
|
+
}
|
|
150
|
+
const data = (await response.json());
|
|
151
|
+
return mapZendeskTicket(data.ticket);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throw new Error(`Failed to update ticket: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
async listTickets(options) {
|
|
158
|
+
const params = new URLSearchParams();
|
|
159
|
+
if (options?.limit)
|
|
160
|
+
params.append('per_page', options.limit.toString());
|
|
161
|
+
if (options?.cursor)
|
|
162
|
+
params.append('page[after]', options.cursor);
|
|
163
|
+
if (options?.status)
|
|
164
|
+
params.append('status', options.status);
|
|
165
|
+
if (options?.priority)
|
|
166
|
+
params.append('priority', options.priority);
|
|
167
|
+
if (options?.assigneeId)
|
|
168
|
+
params.append('assignee_id', options.assigneeId);
|
|
169
|
+
if (options?.requesterId)
|
|
170
|
+
params.append('requester_id', options.requesterId);
|
|
171
|
+
const url = `${baseUrl}/tickets.json${params.toString() ? `?${params.toString()}` : ''}`;
|
|
172
|
+
try {
|
|
173
|
+
const response = await fetch(url, {
|
|
174
|
+
headers: {
|
|
175
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
176
|
+
'Content-Type': 'application/json',
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
throw new Error(`HTTP ${response.status}`);
|
|
181
|
+
}
|
|
182
|
+
const data = (await response.json());
|
|
183
|
+
const tickets = (data.tickets || []).map(mapZendeskTicket);
|
|
184
|
+
return {
|
|
185
|
+
items: tickets,
|
|
186
|
+
total: data.count,
|
|
187
|
+
hasMore: data.next_page !== null,
|
|
188
|
+
nextCursor: data.after_cursor,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throw new Error(`Failed to list tickets: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
async closeTicket(ticketId) {
|
|
196
|
+
try {
|
|
197
|
+
const response = await fetch(`${baseUrl}/tickets/${ticketId}.json`, {
|
|
198
|
+
method: 'PUT',
|
|
199
|
+
headers: {
|
|
200
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
201
|
+
'Content-Type': 'application/json',
|
|
202
|
+
},
|
|
203
|
+
body: JSON.stringify({
|
|
204
|
+
ticket: {
|
|
205
|
+
status: 'closed',
|
|
206
|
+
},
|
|
207
|
+
}),
|
|
208
|
+
});
|
|
209
|
+
return response.ok;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
async addTicketComment(ticketId, body, isPublic = true) {
|
|
216
|
+
try {
|
|
217
|
+
const response = await fetch(`${baseUrl}/tickets/${ticketId}.json`, {
|
|
218
|
+
method: 'PUT',
|
|
219
|
+
headers: {
|
|
220
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
221
|
+
'Content-Type': 'application/json',
|
|
222
|
+
},
|
|
223
|
+
body: JSON.stringify({
|
|
224
|
+
ticket: {
|
|
225
|
+
comment: {
|
|
226
|
+
body,
|
|
227
|
+
public: isPublic,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
}),
|
|
231
|
+
});
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
const error = await response.json().catch(() => ({}));
|
|
234
|
+
throw new Error(error?.error || `HTTP ${response.status}`);
|
|
235
|
+
}
|
|
236
|
+
const data = (await response.json());
|
|
237
|
+
const audit = data.audit || {};
|
|
238
|
+
const comment = audit.events?.find((e) => e.type === 'Comment');
|
|
239
|
+
return {
|
|
240
|
+
id: audit.id?.toString() || '',
|
|
241
|
+
ticketId,
|
|
242
|
+
body,
|
|
243
|
+
authorId: audit.author_id?.toString() || '',
|
|
244
|
+
isPublic,
|
|
245
|
+
createdAt: new Date(audit.created_at || Date.now()),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
throw new Error(`Failed to add comment: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
async listTicketComments(ticketId) {
|
|
253
|
+
try {
|
|
254
|
+
const response = await fetch(`${baseUrl}/tickets/${ticketId}/comments.json`, {
|
|
255
|
+
headers: {
|
|
256
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
257
|
+
'Content-Type': 'application/json',
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
throw new Error(`HTTP ${response.status}`);
|
|
262
|
+
}
|
|
263
|
+
const data = (await response.json());
|
|
264
|
+
return (data.comments || []).map((comment) => ({
|
|
265
|
+
id: comment.id.toString(),
|
|
266
|
+
ticketId,
|
|
267
|
+
body: comment.body || comment.plain_body || '',
|
|
268
|
+
authorId: comment.author_id?.toString() || '',
|
|
269
|
+
isPublic: comment.public !== false,
|
|
270
|
+
createdAt: new Date(comment.created_at),
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
throw new Error(`Failed to list comments: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
async getUser(userId) {
|
|
278
|
+
try {
|
|
279
|
+
const response = await fetch(`${baseUrl}/users/${userId}.json`, {
|
|
280
|
+
headers: {
|
|
281
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
282
|
+
'Content-Type': 'application/json',
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
if (!response.ok) {
|
|
286
|
+
if (response.status === 404)
|
|
287
|
+
return null;
|
|
288
|
+
throw new Error(`HTTP ${response.status}`);
|
|
289
|
+
}
|
|
290
|
+
const data = (await response.json());
|
|
291
|
+
return mapZendeskUser(data.user);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
async searchUsers(query) {
|
|
298
|
+
try {
|
|
299
|
+
const params = new URLSearchParams({ query });
|
|
300
|
+
const response = await fetch(`${baseUrl}/users/search.json?${params.toString()}`, {
|
|
301
|
+
headers: {
|
|
302
|
+
Authorization: `Basic ${Buffer.from(`${email}/token:${apiKey}`).toString('base64')}`,
|
|
303
|
+
'Content-Type': 'application/json',
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
if (!response.ok) {
|
|
307
|
+
throw new Error(`HTTP ${response.status}`);
|
|
308
|
+
}
|
|
309
|
+
const data = (await response.json());
|
|
310
|
+
return (data.users || []).map(mapZendeskUser);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
throw new Error(`Failed to search users: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Map Zendesk ticket to TicketData
|
|
320
|
+
*/
|
|
321
|
+
function mapZendeskTicket(ticket) {
|
|
322
|
+
return {
|
|
323
|
+
id: ticket.id.toString(),
|
|
324
|
+
subject: ticket.subject || '',
|
|
325
|
+
description: ticket.description || '',
|
|
326
|
+
status: mapZendeskStatus(ticket.status),
|
|
327
|
+
priority: ticket.priority || 'normal',
|
|
328
|
+
type: ticket.type,
|
|
329
|
+
requesterId: ticket.requester_id?.toString(),
|
|
330
|
+
assigneeId: ticket.assignee_id?.toString(),
|
|
331
|
+
tags: ticket.tags || [],
|
|
332
|
+
createdAt: new Date(ticket.created_at),
|
|
333
|
+
updatedAt: new Date(ticket.updated_at),
|
|
334
|
+
solvedAt: ticket.solved_at ? new Date(ticket.solved_at) : undefined,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Map Zendesk status to standard status
|
|
339
|
+
*/
|
|
340
|
+
function mapZendeskStatus(status) {
|
|
341
|
+
switch (status) {
|
|
342
|
+
case 'new':
|
|
343
|
+
return 'new';
|
|
344
|
+
case 'open':
|
|
345
|
+
return 'open';
|
|
346
|
+
case 'pending':
|
|
347
|
+
return 'pending';
|
|
348
|
+
case 'hold':
|
|
349
|
+
return 'hold';
|
|
350
|
+
case 'solved':
|
|
351
|
+
return 'solved';
|
|
352
|
+
case 'closed':
|
|
353
|
+
return 'closed';
|
|
354
|
+
default:
|
|
355
|
+
return 'open';
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Map Zendesk user to SupportUserData
|
|
360
|
+
*/
|
|
361
|
+
function mapZendeskUser(user) {
|
|
362
|
+
return {
|
|
363
|
+
id: user.id.toString(),
|
|
364
|
+
name: user.name || '',
|
|
365
|
+
email: user.email || '',
|
|
366
|
+
role: user.role || 'end-user',
|
|
367
|
+
createdAt: new Date(user.created_at),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Zendesk provider definition
|
|
372
|
+
*/
|
|
373
|
+
export const zendeskProvider = defineProvider(zendeskInfo, async (config) => createZendeskProvider(config));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Providers
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { todoistInfo, todoistProvider, createTodoistProvider } from './todoist.js';
|
|
7
|
+
import { todoistProvider } from './todoist.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register all task providers
|
|
10
|
+
*/
|
|
11
|
+
export function registerTaskProviders() {
|
|
12
|
+
todoistProvider.register();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* All task providers
|
|
16
|
+
*/
|
|
17
|
+
export const taskProviders = [todoistProvider];
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todoist Task Provider
|
|
3
|
+
*
|
|
4
|
+
* Concrete implementation of TaskProvider using Todoist REST API v2.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { defineProvider } from '../registry.js';
|
|
9
|
+
const TODOIST_API_URL = 'https://api.todoist.com/rest/v2';
|
|
10
|
+
/**
|
|
11
|
+
* Todoist provider info
|
|
12
|
+
*/
|
|
13
|
+
export const todoistInfo = {
|
|
14
|
+
id: 'tasks.todoist',
|
|
15
|
+
name: 'Todoist',
|
|
16
|
+
description: 'Todoist task management service',
|
|
17
|
+
category: 'tasks',
|
|
18
|
+
website: 'https://todoist.com',
|
|
19
|
+
docsUrl: 'https://developer.todoist.com/rest/v2',
|
|
20
|
+
requiredConfig: ['apiKey'],
|
|
21
|
+
optionalConfig: [],
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create Todoist task provider
|
|
25
|
+
*/
|
|
26
|
+
export function createTodoistProvider(config) {
|
|
27
|
+
let apiKey;
|
|
28
|
+
/**
|
|
29
|
+
* Make authenticated request to Todoist API
|
|
30
|
+
*/
|
|
31
|
+
async function todoistRequest(endpoint, options = {}) {
|
|
32
|
+
const response = await fetch(`${TODOIST_API_URL}${endpoint}`, {
|
|
33
|
+
...options,
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
Authorization: `Bearer ${apiKey}`,
|
|
37
|
+
...options.headers,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errorText = await response.text();
|
|
42
|
+
throw new Error(`Todoist API error (${response.status}): ${errorText}`);
|
|
43
|
+
}
|
|
44
|
+
// Handle 204 No Content responses
|
|
45
|
+
if (response.status === 204) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return response.json();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Convert Todoist project to ProjectData
|
|
52
|
+
*/
|
|
53
|
+
function toProjectData(project) {
|
|
54
|
+
return {
|
|
55
|
+
id: project.id,
|
|
56
|
+
name: project.name,
|
|
57
|
+
color: project.color,
|
|
58
|
+
parentId: project.parent_id,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert Todoist task to TaskData
|
|
63
|
+
*/
|
|
64
|
+
function toTaskData(task) {
|
|
65
|
+
let dueDate;
|
|
66
|
+
if (task.due?.datetime) {
|
|
67
|
+
dueDate = new Date(task.due.datetime);
|
|
68
|
+
}
|
|
69
|
+
else if (task.due?.date) {
|
|
70
|
+
dueDate = new Date(task.due.date);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
id: task.id,
|
|
74
|
+
content: task.content,
|
|
75
|
+
description: task.description,
|
|
76
|
+
projectId: task.project_id,
|
|
77
|
+
parentId: task.parent_id,
|
|
78
|
+
priority: task.priority,
|
|
79
|
+
dueDate,
|
|
80
|
+
completed: task.is_completed,
|
|
81
|
+
labels: task.labels,
|
|
82
|
+
createdAt: new Date(task.created_at),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convert Todoist comment to CommentData
|
|
87
|
+
*/
|
|
88
|
+
function toCommentData(comment) {
|
|
89
|
+
return {
|
|
90
|
+
id: comment.id,
|
|
91
|
+
taskId: comment.task_id || '',
|
|
92
|
+
content: comment.content,
|
|
93
|
+
authorId: '', // Todoist doesn't provide author_id in v2 API
|
|
94
|
+
createdAt: new Date(comment.posted_at),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
info: todoistInfo,
|
|
99
|
+
async initialize(cfg) {
|
|
100
|
+
apiKey = cfg.apiKey;
|
|
101
|
+
if (!apiKey) {
|
|
102
|
+
throw new Error('Todoist API key is required');
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
async healthCheck() {
|
|
106
|
+
const start = Date.now();
|
|
107
|
+
try {
|
|
108
|
+
// Try to fetch projects to verify connectivity
|
|
109
|
+
await todoistRequest('/projects');
|
|
110
|
+
return {
|
|
111
|
+
healthy: true,
|
|
112
|
+
latencyMs: Date.now() - start,
|
|
113
|
+
message: 'Connected',
|
|
114
|
+
checkedAt: new Date(),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return {
|
|
119
|
+
healthy: false,
|
|
120
|
+
latencyMs: Date.now() - start,
|
|
121
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
122
|
+
checkedAt: new Date(),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
async dispose() {
|
|
127
|
+
// No cleanup needed
|
|
128
|
+
},
|
|
129
|
+
async listProjects() {
|
|
130
|
+
const projects = await todoistRequest('/projects');
|
|
131
|
+
return projects.map(toProjectData);
|
|
132
|
+
},
|
|
133
|
+
async createTask(task) {
|
|
134
|
+
const body = {
|
|
135
|
+
content: task.content,
|
|
136
|
+
};
|
|
137
|
+
if (task.description) {
|
|
138
|
+
body.description = task.description;
|
|
139
|
+
}
|
|
140
|
+
if (task.projectId) {
|
|
141
|
+
body.project_id = task.projectId;
|
|
142
|
+
}
|
|
143
|
+
if (task.parentId) {
|
|
144
|
+
body.parent_id = task.parentId;
|
|
145
|
+
}
|
|
146
|
+
if (task.priority) {
|
|
147
|
+
body.priority = task.priority;
|
|
148
|
+
}
|
|
149
|
+
if (task.dueDate) {
|
|
150
|
+
body.due_date = task.dueDate.toISOString().split('T')[0];
|
|
151
|
+
}
|
|
152
|
+
else if (task.dueString) {
|
|
153
|
+
body.due_string = task.dueString;
|
|
154
|
+
}
|
|
155
|
+
if (task.labels && task.labels.length > 0) {
|
|
156
|
+
body.labels = task.labels;
|
|
157
|
+
}
|
|
158
|
+
if (task.assigneeId) {
|
|
159
|
+
body.assignee_id = task.assigneeId;
|
|
160
|
+
}
|
|
161
|
+
const created = await todoistRequest('/tasks', {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
body: JSON.stringify(body),
|
|
164
|
+
});
|
|
165
|
+
return toTaskData(created);
|
|
166
|
+
},
|
|
167
|
+
async getTask(taskId) {
|
|
168
|
+
try {
|
|
169
|
+
const task = await todoistRequest(`/tasks/${taskId}`);
|
|
170
|
+
return toTaskData(task);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
// Return null if task not found
|
|
174
|
+
if (error instanceof Error && error.message.includes('404')) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
async updateTask(taskId, updates) {
|
|
181
|
+
const body = {};
|
|
182
|
+
if (updates.content !== undefined) {
|
|
183
|
+
body.content = updates.content;
|
|
184
|
+
}
|
|
185
|
+
if (updates.description !== undefined) {
|
|
186
|
+
body.description = updates.description;
|
|
187
|
+
}
|
|
188
|
+
if (updates.priority !== undefined) {
|
|
189
|
+
body.priority = updates.priority;
|
|
190
|
+
}
|
|
191
|
+
if (updates.dueDate) {
|
|
192
|
+
body.due_date = updates.dueDate.toISOString().split('T')[0];
|
|
193
|
+
}
|
|
194
|
+
else if (updates.dueString) {
|
|
195
|
+
body.due_string = updates.dueString;
|
|
196
|
+
}
|
|
197
|
+
if (updates.labels !== undefined) {
|
|
198
|
+
body.labels = updates.labels;
|
|
199
|
+
}
|
|
200
|
+
if (updates.assigneeId !== undefined) {
|
|
201
|
+
body.assignee_id = updates.assigneeId;
|
|
202
|
+
}
|
|
203
|
+
await todoistRequest(`/tasks/${taskId}`, {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
body: JSON.stringify(body),
|
|
206
|
+
});
|
|
207
|
+
// Fetch and return the updated task
|
|
208
|
+
const updated = await todoistRequest(`/tasks/${taskId}`);
|
|
209
|
+
return toTaskData(updated);
|
|
210
|
+
},
|
|
211
|
+
async deleteTask(taskId) {
|
|
212
|
+
try {
|
|
213
|
+
await todoistRequest(`/tasks/${taskId}`, {
|
|
214
|
+
method: 'DELETE',
|
|
215
|
+
});
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
async completeTask(taskId) {
|
|
223
|
+
try {
|
|
224
|
+
await todoistRequest(`/tasks/${taskId}/close`, {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
});
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
async reopenTask(taskId) {
|
|
234
|
+
try {
|
|
235
|
+
await todoistRequest(`/tasks/${taskId}/reopen`, {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
});
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
async listTasks(options) {
|
|
245
|
+
const params = new URLSearchParams();
|
|
246
|
+
if (options?.projectId) {
|
|
247
|
+
params.append('project_id', options.projectId);
|
|
248
|
+
}
|
|
249
|
+
if (options?.filter) {
|
|
250
|
+
params.append('filter', options.filter);
|
|
251
|
+
}
|
|
252
|
+
const queryString = params.toString();
|
|
253
|
+
const endpoint = `/tasks${queryString ? `?${queryString}` : ''}`;
|
|
254
|
+
const tasks = await todoistRequest(endpoint);
|
|
255
|
+
// Filter by completed status if specified
|
|
256
|
+
let filteredTasks = tasks;
|
|
257
|
+
if (options?.completed !== undefined) {
|
|
258
|
+
filteredTasks = tasks.filter((t) => t.is_completed === options.completed);
|
|
259
|
+
}
|
|
260
|
+
// Apply pagination
|
|
261
|
+
const limit = options?.limit || 50;
|
|
262
|
+
const offset = options?.offset || 0;
|
|
263
|
+
const paginatedTasks = filteredTasks.slice(offset, offset + limit);
|
|
264
|
+
return {
|
|
265
|
+
items: paginatedTasks.map(toTaskData),
|
|
266
|
+
total: filteredTasks.length,
|
|
267
|
+
hasMore: offset + limit < filteredTasks.length,
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
async addComment(taskId, content) {
|
|
271
|
+
const body = {
|
|
272
|
+
task_id: taskId,
|
|
273
|
+
content,
|
|
274
|
+
};
|
|
275
|
+
const comment = await todoistRequest('/comments', {
|
|
276
|
+
method: 'POST',
|
|
277
|
+
body: JSON.stringify(body),
|
|
278
|
+
});
|
|
279
|
+
return toCommentData(comment);
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Todoist provider definition
|
|
285
|
+
*/
|
|
286
|
+
export const todoistProvider = defineProvider(todoistInfo, async (config) => createTodoistProvider(config));
|