@datashift/sdk 0.2.0 → 0.3.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 +58 -14
- package/dist/index.d.mts +46 -1
- package/dist/index.d.ts +46 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -177,8 +177,13 @@ app.post('/webhook/datashift',
|
|
|
177
177
|
const event = parseWebhookEvent<WebhookEvent>(req.body);
|
|
178
178
|
|
|
179
179
|
if (event.event === 'task.reviewed') {
|
|
180
|
-
const {
|
|
181
|
-
|
|
180
|
+
const {task, queue, reviews} = event.data;
|
|
181
|
+
console.log(`Task ${task.id} in queue ${queue.key} reviewed`);
|
|
182
|
+
console.log(`Result: ${reviews[0].result}`);
|
|
183
|
+
console.log(`Reviewer: ${reviews[0].reviewer.name}`);
|
|
184
|
+
} else if (event.event === 'task.created') {
|
|
185
|
+
const {task, queue} = event.data;
|
|
186
|
+
console.log(`Task ${task.id} created in queue ${queue.key}`);
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
res.status(200).send('OK');
|
|
@@ -190,22 +195,61 @@ app.post('/webhook/datashift',
|
|
|
190
195
|
|
|
191
196
|
| Event | Description |
|
|
192
197
|
|------------------|--------------------------------|
|
|
193
|
-
| `task.
|
|
198
|
+
| `task.created` | A new task was submitted for review |
|
|
199
|
+
| `task.reviewed` | A task has been reviewed (includes all reviews) |
|
|
194
200
|
|
|
195
|
-
### Webhook
|
|
201
|
+
### Webhook Payloads
|
|
196
202
|
|
|
197
203
|
```typescript
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
// task.created
|
|
205
|
+
interface TaskCreatedWebhookEvent {
|
|
206
|
+
event: 'task.created';
|
|
207
|
+
timestamp: string;
|
|
201
208
|
data: {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
state: string;
|
|
205
|
-
result: string[];
|
|
206
|
-
review?: Review;
|
|
209
|
+
task: WebhookTaskData;
|
|
210
|
+
queue: WebhookQueueData;
|
|
207
211
|
};
|
|
208
212
|
}
|
|
213
|
+
|
|
214
|
+
// task.reviewed
|
|
215
|
+
interface TaskReviewedWebhookEvent {
|
|
216
|
+
event: 'task.reviewed';
|
|
217
|
+
timestamp: string;
|
|
218
|
+
data: {
|
|
219
|
+
task: WebhookTaskData;
|
|
220
|
+
queue: WebhookQueueData;
|
|
221
|
+
reviews: WebhookReviewData[]; // All reviews (supports two-step workflows)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
interface WebhookTaskData {
|
|
226
|
+
id: string;
|
|
227
|
+
external_id: string | null;
|
|
228
|
+
state: string;
|
|
229
|
+
summary: string | null;
|
|
230
|
+
data: Record<string, unknown>;
|
|
231
|
+
metadata: Record<string, unknown>;
|
|
232
|
+
sla_deadline: string | null;
|
|
233
|
+
reviewed_at: string | null;
|
|
234
|
+
created_at: string;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
interface WebhookQueueData {
|
|
238
|
+
key: string;
|
|
239
|
+
name: string;
|
|
240
|
+
review_type: string;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
interface WebhookReviewData {
|
|
244
|
+
result: string[];
|
|
245
|
+
data: Record<string, unknown>;
|
|
246
|
+
comment: string | null;
|
|
247
|
+
reviewer: { name: string; type: string };
|
|
248
|
+
created_at: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Union type for all webhook events
|
|
252
|
+
type WebhookEvent = TaskCreatedWebhookEvent | TaskReviewedWebhookEvent;
|
|
209
253
|
```
|
|
210
254
|
|
|
211
255
|
## Types
|
|
@@ -383,10 +427,10 @@ app.post('/webhook/datashift',
|
|
|
383
427
|
const event = parseWebhookEvent<WebhookEvent>(req.body);
|
|
384
428
|
|
|
385
429
|
if (event.event === 'task.reviewed') {
|
|
386
|
-
const resolver = pendingTasks.get(event.data.
|
|
430
|
+
const resolver = pendingTasks.get(event.data.task.id);
|
|
387
431
|
if (resolver) {
|
|
388
432
|
resolver(event.data);
|
|
389
|
-
pendingTasks.delete(event.data.
|
|
433
|
+
pendingTasks.delete(event.data.task.id);
|
|
390
434
|
}
|
|
391
435
|
}
|
|
392
436
|
|
package/dist/index.d.mts
CHANGED
|
@@ -91,6 +91,51 @@ interface ReviewResult {
|
|
|
91
91
|
reviewed_at: string;
|
|
92
92
|
review: Review;
|
|
93
93
|
}
|
|
94
|
+
type WebhookEventType = 'task.created' | 'task.reviewed';
|
|
95
|
+
interface WebhookTaskData {
|
|
96
|
+
id: string;
|
|
97
|
+
external_id: string | null;
|
|
98
|
+
state: string;
|
|
99
|
+
summary: string | null;
|
|
100
|
+
data: Record<string, unknown>;
|
|
101
|
+
metadata: Record<string, unknown>;
|
|
102
|
+
sla_deadline: string | null;
|
|
103
|
+
reviewed_at: string | null;
|
|
104
|
+
created_at: string;
|
|
105
|
+
}
|
|
106
|
+
interface WebhookQueueData {
|
|
107
|
+
key: string;
|
|
108
|
+
name: string;
|
|
109
|
+
review_type: string;
|
|
110
|
+
}
|
|
111
|
+
interface WebhookReviewData {
|
|
112
|
+
result: string[];
|
|
113
|
+
data: Record<string, unknown>;
|
|
114
|
+
comment: string | null;
|
|
115
|
+
reviewer: {
|
|
116
|
+
name: string;
|
|
117
|
+
type: string;
|
|
118
|
+
};
|
|
119
|
+
created_at: string;
|
|
120
|
+
}
|
|
121
|
+
interface TaskCreatedWebhookEvent {
|
|
122
|
+
event: 'task.created';
|
|
123
|
+
timestamp: string;
|
|
124
|
+
data: {
|
|
125
|
+
task: WebhookTaskData;
|
|
126
|
+
queue: WebhookQueueData;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
interface TaskReviewedWebhookEvent {
|
|
130
|
+
event: 'task.reviewed';
|
|
131
|
+
timestamp: string;
|
|
132
|
+
data: {
|
|
133
|
+
task: WebhookTaskData;
|
|
134
|
+
queue: WebhookQueueData;
|
|
135
|
+
reviews: WebhookReviewData[];
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
type WebhookEvent = TaskCreatedWebhookEvent | TaskReviewedWebhookEvent;
|
|
94
139
|
|
|
95
140
|
declare class TaskResource {
|
|
96
141
|
private client;
|
|
@@ -229,4 +274,4 @@ declare class ServerError extends DatashiftError {
|
|
|
229
274
|
constructor(message?: string);
|
|
230
275
|
}
|
|
231
276
|
|
|
232
|
-
export { type AssignmentStrategy, AuthenticationError, DatashiftError, DatashiftRestClient, type ListReviewsFilters, NotFoundError, type Queue, RateLimitError, type RestClientConfig, type Review, type ReviewOption, type ReviewResult, type ReviewType, ServerError, type SubmitTaskInput, type Task, type TaskState, type TaskStatus, TimeoutError, ValidationError, type WaitOptions };
|
|
277
|
+
export { type AssignmentStrategy, AuthenticationError, DatashiftError, DatashiftRestClient, type ListReviewsFilters, NotFoundError, type Queue, RateLimitError, type RestClientConfig, type Review, type ReviewOption, type ReviewResult, type ReviewType, ServerError, type SubmitTaskInput, type Task, type TaskCreatedWebhookEvent, type TaskReviewedWebhookEvent, type TaskState, type TaskStatus, TimeoutError, ValidationError, type WaitOptions, type WebhookEvent, type WebhookEventType, type WebhookQueueData, type WebhookReviewData, type WebhookTaskData };
|
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,51 @@ interface ReviewResult {
|
|
|
91
91
|
reviewed_at: string;
|
|
92
92
|
review: Review;
|
|
93
93
|
}
|
|
94
|
+
type WebhookEventType = 'task.created' | 'task.reviewed';
|
|
95
|
+
interface WebhookTaskData {
|
|
96
|
+
id: string;
|
|
97
|
+
external_id: string | null;
|
|
98
|
+
state: string;
|
|
99
|
+
summary: string | null;
|
|
100
|
+
data: Record<string, unknown>;
|
|
101
|
+
metadata: Record<string, unknown>;
|
|
102
|
+
sla_deadline: string | null;
|
|
103
|
+
reviewed_at: string | null;
|
|
104
|
+
created_at: string;
|
|
105
|
+
}
|
|
106
|
+
interface WebhookQueueData {
|
|
107
|
+
key: string;
|
|
108
|
+
name: string;
|
|
109
|
+
review_type: string;
|
|
110
|
+
}
|
|
111
|
+
interface WebhookReviewData {
|
|
112
|
+
result: string[];
|
|
113
|
+
data: Record<string, unknown>;
|
|
114
|
+
comment: string | null;
|
|
115
|
+
reviewer: {
|
|
116
|
+
name: string;
|
|
117
|
+
type: string;
|
|
118
|
+
};
|
|
119
|
+
created_at: string;
|
|
120
|
+
}
|
|
121
|
+
interface TaskCreatedWebhookEvent {
|
|
122
|
+
event: 'task.created';
|
|
123
|
+
timestamp: string;
|
|
124
|
+
data: {
|
|
125
|
+
task: WebhookTaskData;
|
|
126
|
+
queue: WebhookQueueData;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
interface TaskReviewedWebhookEvent {
|
|
130
|
+
event: 'task.reviewed';
|
|
131
|
+
timestamp: string;
|
|
132
|
+
data: {
|
|
133
|
+
task: WebhookTaskData;
|
|
134
|
+
queue: WebhookQueueData;
|
|
135
|
+
reviews: WebhookReviewData[];
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
type WebhookEvent = TaskCreatedWebhookEvent | TaskReviewedWebhookEvent;
|
|
94
139
|
|
|
95
140
|
declare class TaskResource {
|
|
96
141
|
private client;
|
|
@@ -229,4 +274,4 @@ declare class ServerError extends DatashiftError {
|
|
|
229
274
|
constructor(message?: string);
|
|
230
275
|
}
|
|
231
276
|
|
|
232
|
-
export { type AssignmentStrategy, AuthenticationError, DatashiftError, DatashiftRestClient, type ListReviewsFilters, NotFoundError, type Queue, RateLimitError, type RestClientConfig, type Review, type ReviewOption, type ReviewResult, type ReviewType, ServerError, type SubmitTaskInput, type Task, type TaskState, type TaskStatus, TimeoutError, ValidationError, type WaitOptions };
|
|
277
|
+
export { type AssignmentStrategy, AuthenticationError, DatashiftError, DatashiftRestClient, type ListReviewsFilters, NotFoundError, type Queue, RateLimitError, type RestClientConfig, type Review, type ReviewOption, type ReviewResult, type ReviewType, ServerError, type SubmitTaskInput, type Task, type TaskCreatedWebhookEvent, type TaskReviewedWebhookEvent, type TaskState, type TaskStatus, TimeoutError, ValidationError, type WaitOptions, type WebhookEvent, type WebhookEventType, type WebhookQueueData, type WebhookReviewData, type WebhookTaskData };
|