@superdurable/connector-clickup 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +29 -2
- package/dex-connector.json +277 -0
- package/dist/chunk-5MZPRO45.js +426 -0
- package/dist/connection-DYuseKLI.d.ts +603 -0
- package/dist/index.d.ts +457 -0
- package/dist/index.js +997 -0
- package/dist/mock.d.ts +197 -0
- package/dist/mock.js +479 -0
- package/package.json +59 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddCommentBranch,
|
|
3
|
+
AddCommentBranchAdded,
|
|
4
|
+
AddCommentBranchDefect,
|
|
5
|
+
AddCommentBranchNotFound,
|
|
6
|
+
AddCommentBranchProviderRejected,
|
|
7
|
+
AddCommentBranchUncertain,
|
|
8
|
+
AddCommentDefinition,
|
|
9
|
+
AddCommentInputSchema,
|
|
10
|
+
AddCommentMetadata,
|
|
11
|
+
AddCommentOutputSchema,
|
|
12
|
+
ConfigSchema,
|
|
13
|
+
Connection,
|
|
14
|
+
ConnectorID,
|
|
15
|
+
CreateTaskBranch,
|
|
16
|
+
CreateTaskBranchCreated,
|
|
17
|
+
CreateTaskBranchDefect,
|
|
18
|
+
CreateTaskBranchNotFound,
|
|
19
|
+
CreateTaskBranchProviderRejected,
|
|
20
|
+
CreateTaskBranchUncertain,
|
|
21
|
+
CreateTaskDefinition,
|
|
22
|
+
CreateTaskInputSchema,
|
|
23
|
+
CreateTaskMetadata,
|
|
24
|
+
CreateTaskOutputSchema,
|
|
25
|
+
CustomFieldInputSchema,
|
|
26
|
+
CustomFieldValueSchema,
|
|
27
|
+
FindMemberByEmailBranch,
|
|
28
|
+
FindMemberByEmailBranchDefect,
|
|
29
|
+
FindMemberByEmailBranchFound,
|
|
30
|
+
FindMemberByEmailBranchInvalidResponse,
|
|
31
|
+
FindMemberByEmailBranchNotFound,
|
|
32
|
+
FindMemberByEmailBranchProviderRejected,
|
|
33
|
+
FindMemberByEmailDefinition,
|
|
34
|
+
FindMemberByEmailInputSchema,
|
|
35
|
+
FindMemberByEmailMetadata,
|
|
36
|
+
GetTaskBranch,
|
|
37
|
+
GetTaskBranchDefect,
|
|
38
|
+
GetTaskBranchFound,
|
|
39
|
+
GetTaskBranchInvalidResponse,
|
|
40
|
+
GetTaskBranchNotFound,
|
|
41
|
+
GetTaskBranchProviderRejected,
|
|
42
|
+
GetTaskDefinition,
|
|
43
|
+
GetTaskInputSchema,
|
|
44
|
+
GetTaskMetadata,
|
|
45
|
+
MemberSchema,
|
|
46
|
+
ProviderID,
|
|
47
|
+
SearchTasksBranch,
|
|
48
|
+
SearchTasksBranchDefect,
|
|
49
|
+
SearchTasksBranchInvalidResponse,
|
|
50
|
+
SearchTasksBranchNotFound,
|
|
51
|
+
SearchTasksBranchProviderRejected,
|
|
52
|
+
SearchTasksBranchSearched,
|
|
53
|
+
SearchTasksDefinition,
|
|
54
|
+
SearchTasksInputSchema,
|
|
55
|
+
SearchTasksMetadata,
|
|
56
|
+
SearchTasksOutputSchema,
|
|
57
|
+
TaskSchema,
|
|
58
|
+
TaskStatusSchema,
|
|
59
|
+
UpdateTaskBranch,
|
|
60
|
+
UpdateTaskBranchDefect,
|
|
61
|
+
UpdateTaskBranchInvalidResponse,
|
|
62
|
+
UpdateTaskBranchNotFound,
|
|
63
|
+
UpdateTaskBranchProviderRejected,
|
|
64
|
+
UpdateTaskBranchUpdated,
|
|
65
|
+
UpdateTaskDefinition,
|
|
66
|
+
UpdateTaskInputSchema,
|
|
67
|
+
UpdateTaskMetadata,
|
|
68
|
+
UpdateTaskOutputSchema,
|
|
69
|
+
UpdateTaskTagsBranch,
|
|
70
|
+
UpdateTaskTagsBranchDefect,
|
|
71
|
+
UpdateTaskTagsBranchInvalidResponse,
|
|
72
|
+
UpdateTaskTagsBranchNotFound,
|
|
73
|
+
UpdateTaskTagsBranchProviderRejected,
|
|
74
|
+
UpdateTaskTagsBranchUpdated,
|
|
75
|
+
UpdateTaskTagsDefinition,
|
|
76
|
+
UpdateTaskTagsInputSchema,
|
|
77
|
+
UpdateTaskTagsMetadata,
|
|
78
|
+
UpdateTaskTagsOutputSchema,
|
|
79
|
+
UserSchema,
|
|
80
|
+
newConnection,
|
|
81
|
+
newConnectionWithOperations,
|
|
82
|
+
newProjectConnection
|
|
83
|
+
} from "./chunk-5MZPRO45.js";
|
|
84
|
+
|
|
85
|
+
// src/generated/steps.ts
|
|
86
|
+
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
87
|
+
function newSearchTasksStep(configuration) {
|
|
88
|
+
const { connection, connectionName, searched, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
89
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
90
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.searchTasks(), connection: connection.reference, branches: [
|
|
91
|
+
goToBranch("searched", searched),
|
|
92
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
93
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
94
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
95
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
96
|
+
] });
|
|
97
|
+
}
|
|
98
|
+
function newGetTaskStep(configuration) {
|
|
99
|
+
const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
100
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
101
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getTask(), connection: connection.reference, branches: [
|
|
102
|
+
goToBranch("found", found),
|
|
103
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
104
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
105
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
106
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
107
|
+
] });
|
|
108
|
+
}
|
|
109
|
+
function newCreateTaskStep(configuration) {
|
|
110
|
+
const { connection, connectionName, created, notFound, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
|
|
111
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
112
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.createTask(), connection: connection.reference, branches: [
|
|
113
|
+
goToBranch("created", created),
|
|
114
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
115
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
116
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : [],
|
|
117
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
118
|
+
] });
|
|
119
|
+
}
|
|
120
|
+
function newUpdateTaskStep(configuration) {
|
|
121
|
+
const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
122
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
123
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateTask(), connection: connection.reference, branches: [
|
|
124
|
+
goToBranch("updated", updated),
|
|
125
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
126
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
127
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
128
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
129
|
+
] });
|
|
130
|
+
}
|
|
131
|
+
function newUpdateTaskTagsStep(configuration) {
|
|
132
|
+
const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
133
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
134
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateTaskTags(), connection: connection.reference, branches: [
|
|
135
|
+
goToBranch("updated", updated),
|
|
136
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
137
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
138
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
139
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
140
|
+
] });
|
|
141
|
+
}
|
|
142
|
+
function newAddCommentStep(configuration) {
|
|
143
|
+
const { connection, connectionName, added, notFound, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
|
|
144
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
145
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.addComment(), connection: connection.reference, branches: [
|
|
146
|
+
goToBranch("added", added),
|
|
147
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
148
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
149
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : [],
|
|
150
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
151
|
+
] });
|
|
152
|
+
}
|
|
153
|
+
function newFindMemberByEmailStep(configuration) {
|
|
154
|
+
const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
155
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
156
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.findMemberByEmail(), connection: connection.reference, branches: [
|
|
157
|
+
goToBranch("found", found),
|
|
158
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
159
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
160
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
161
|
+
...defect2 ? [goToBranch("defect", defect2)] : []
|
|
162
|
+
] });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/project.ts
|
|
166
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
167
|
+
import { z } from "zod";
|
|
168
|
+
|
|
169
|
+
// src/client.ts
|
|
170
|
+
import { BodyTooLargeError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
171
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
172
|
+
|
|
173
|
+
// src/operations.ts
|
|
174
|
+
import { newMutationBranch, newMutationRetry, newMutationUncertain, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
175
|
+
var taskIdPattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
176
|
+
var numericIdPattern = /^[0-9]{1,20}$/;
|
|
177
|
+
var zeroTask = { id: "", name: "", status: { name: "" }, assignees: [], tags: [] };
|
|
178
|
+
var zeroMember = { id: 0, email: "", workspaceId: "" };
|
|
179
|
+
function failure(kind, operation, message) {
|
|
180
|
+
return { kind, provider: "clickup", operation, message };
|
|
181
|
+
}
|
|
182
|
+
function isRetryable(exchange) {
|
|
183
|
+
return exchange.kind === "notSent" || exchange.kind === "rateLimited" || exchange.kind === "unconfirmed";
|
|
184
|
+
}
|
|
185
|
+
function queryExchange(exchange, output, receipt2) {
|
|
186
|
+
if (isRetryable(exchange)) return newQueryRetry(exchange.failure, exchange.retryAfterMs);
|
|
187
|
+
const branch = exchange.kind === "notFound" ? "notFound" : exchange.kind === "invalid" ? "invalidResponse" : exchange.kind === "defect" ? "defect" : "providerRejected";
|
|
188
|
+
return newQueryBranch(branch, output, receipt2, exchange.failure);
|
|
189
|
+
}
|
|
190
|
+
function mutationExchange(exchange, output, receipt2, hasInvalidResponse = true) {
|
|
191
|
+
if (isRetryable(exchange)) return newMutationRetry(exchange.failure, exchange.retryAfterMs);
|
|
192
|
+
const branch = exchange.kind === "notFound" ? "notFound" : exchange.kind === "invalid" && hasInvalidResponse ? "invalidResponse" : exchange.kind === "defect" ? "defect" : "providerRejected";
|
|
193
|
+
return newMutationBranch(branch, output, receipt2, exchange.failure);
|
|
194
|
+
}
|
|
195
|
+
function defect(operation, output, message) {
|
|
196
|
+
const cause = failure("VALIDATION", operation, message);
|
|
197
|
+
return newQueryBranch("defect", output, {}, cause);
|
|
198
|
+
}
|
|
199
|
+
function decodeObject(body) {
|
|
200
|
+
const decoded = JSON.parse(Buffer.from(body).toString("utf8"));
|
|
201
|
+
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) throw new TypeError("not an object");
|
|
202
|
+
return decoded;
|
|
203
|
+
}
|
|
204
|
+
function object(value) {
|
|
205
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
206
|
+
}
|
|
207
|
+
function identifier(value) {
|
|
208
|
+
return typeof value === "string" ? value : typeof value === "number" && Number.isSafeInteger(value) ? String(value) : "";
|
|
209
|
+
}
|
|
210
|
+
function milliseconds(value) {
|
|
211
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
212
|
+
const numeric = Number(value);
|
|
213
|
+
if (!Number.isSafeInteger(numeric) || numeric < 0) throw new TypeError("invalid Unix milliseconds");
|
|
214
|
+
return numeric > 0 ? new Date(numeric).toISOString().replace(/\.000Z$/, "Z") : void 0;
|
|
215
|
+
}
|
|
216
|
+
function taskFromWire(wire, shouldIncludeDetails) {
|
|
217
|
+
const data = object(wire);
|
|
218
|
+
if (typeof data.id !== "string" || data.name !== void 0 && typeof data.name !== "string" || data.status !== void 0 && (typeof data.status !== "object" || data.status === null || Array.isArray(data.status)) || data.assignees !== void 0 && data.assignees !== null && !Array.isArray(data.assignees) || data.tags !== void 0 && data.tags !== null && !Array.isArray(data.tags)) throw new TypeError("invalid task fields");
|
|
219
|
+
const id = data.id;
|
|
220
|
+
if (!taskIdPattern.test(id)) throw new TypeError("task has no valid ID");
|
|
221
|
+
const status = object(data.status);
|
|
222
|
+
const priorityWire = data.priority;
|
|
223
|
+
const priorityObject = object(priorityWire);
|
|
224
|
+
const priority = priorityWire === void 0 || priorityWire === null ? 0 : Number(typeof priorityWire === "object" ? priorityObject.id : priorityWire);
|
|
225
|
+
if (priority !== 0 && (![1, 2, 3, 4].includes(priority) || !Number.isInteger(priority))) throw new TypeError("invalid priority");
|
|
226
|
+
const assignees = Array.isArray(data.assignees) ? data.assignees.map((value) => {
|
|
227
|
+
const user = object(value);
|
|
228
|
+
const userId = Number(user.id);
|
|
229
|
+
if (!Number.isSafeInteger(userId) || userId <= 0) throw new TypeError("invalid assignee");
|
|
230
|
+
return { id: userId, ...typeof user.username === "string" && user.username ? { username: user.username } : {} };
|
|
231
|
+
}) : [];
|
|
232
|
+
const tags = Array.isArray(data.tags) ? data.tags.map((value) => String(object(value).name ?? "")) : [];
|
|
233
|
+
const result = {
|
|
234
|
+
id,
|
|
235
|
+
name: String(data.name ?? ""),
|
|
236
|
+
status: { name: String(status.status ?? ""), ...status.type ? { type: String(status.type) } : {} },
|
|
237
|
+
assignees,
|
|
238
|
+
tags,
|
|
239
|
+
...data.url ? { url: String(data.url) } : {},
|
|
240
|
+
...priority ? { priority } : {},
|
|
241
|
+
...priorityObject.priority ? { priorityName: String(priorityObject.priority) } : {},
|
|
242
|
+
...milliseconds(data.due_date) ? { dueAt: milliseconds(data.due_date) } : {},
|
|
243
|
+
...milliseconds(data.start_date) ? { startAt: milliseconds(data.start_date) } : {},
|
|
244
|
+
...milliseconds(data.date_created) ? { createdAt: milliseconds(data.date_created) } : {},
|
|
245
|
+
...milliseconds(data.date_updated) ? { updatedAt: milliseconds(data.date_updated) } : {},
|
|
246
|
+
...milliseconds(data.date_closed) ? { closedAt: milliseconds(data.date_closed) } : {},
|
|
247
|
+
...data.archived ? { isArchived: true } : {},
|
|
248
|
+
...identifier(data.team_id) ? { workspaceId: identifier(data.team_id) } : {},
|
|
249
|
+
...identifier(object(data.list).id) ? { listId: identifier(object(data.list).id) } : {},
|
|
250
|
+
...object(data.list).name ? { listName: String(object(data.list).name) } : {},
|
|
251
|
+
...identifier(object(data.folder).id) ? { folderId: identifier(object(data.folder).id) } : {},
|
|
252
|
+
...identifier(object(data.space).id) ? { spaceId: identifier(object(data.space).id) } : {},
|
|
253
|
+
...data.custom_id !== void 0 && data.custom_id !== null ? { customId: String(data.custom_id) } : {},
|
|
254
|
+
...data.parent !== void 0 && data.parent !== null ? { parentTaskId: String(data.parent) } : {}
|
|
255
|
+
};
|
|
256
|
+
const creator = object(data.creator);
|
|
257
|
+
if (Number(creator.id) > 0) result.creator = { id: Number(creator.id), ...creator.username ? { username: String(creator.username) } : {} };
|
|
258
|
+
if (shouldIncludeDetails) {
|
|
259
|
+
const description = typeof data.markdown_description === "string" ? data.markdown_description : typeof data.description === "string" ? data.description : void 0;
|
|
260
|
+
if (description !== void 0) {
|
|
261
|
+
const bytes = Buffer.from(description);
|
|
262
|
+
const isTruncated = bytes.length > 65536;
|
|
263
|
+
result.markdownDescription = isTruncated ? new TextDecoder("utf-8", { fatal: false }).decode(bytes.subarray(0, 65536)).replace(/\uFFFD$/, "") : description;
|
|
264
|
+
if (isTruncated) result.isDescriptionTruncated = true;
|
|
265
|
+
}
|
|
266
|
+
if (data.custom_fields !== void 0 && data.custom_fields !== null && !Array.isArray(data.custom_fields)) throw new TypeError("invalid custom fields");
|
|
267
|
+
if (Array.isArray(data.custom_fields)) result.customFields = data.custom_fields.slice(0, 100).map((value) => {
|
|
268
|
+
const field = object(value);
|
|
269
|
+
const fieldId = identifier(field.id);
|
|
270
|
+
if (!taskIdPattern.test(fieldId)) throw new TypeError("invalid custom field ID");
|
|
271
|
+
return { id: fieldId, name: String(field.name ?? ""), type: String(field.type ?? ""), ...field.value === void 0 || field.value === null ? {} : { value: field.value } };
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
function taskBody(body, shouldIncludeDetails) {
|
|
277
|
+
return taskFromWire(decodeObject(body), shouldIncludeDetails);
|
|
278
|
+
}
|
|
279
|
+
function searchPage(body, page) {
|
|
280
|
+
const data = decodeObject(body);
|
|
281
|
+
if (!Array.isArray(data.tasks) || data.tasks.length > 100 || data.last_page !== void 0 && data.last_page !== null && typeof data.last_page !== "boolean") throw new TypeError("invalid tasks array");
|
|
282
|
+
const tasks = data.tasks.map((value) => taskFromWire(value, false));
|
|
283
|
+
const hasMore = typeof data.last_page === "boolean" ? !data.last_page && tasks.length > 0 : tasks.length === 100;
|
|
284
|
+
return { tasks, page, ...hasMore ? { nextPage: page + 1 } : {} };
|
|
285
|
+
}
|
|
286
|
+
function validateTaskId(id) {
|
|
287
|
+
if (!taskIdPattern.test(id)) throw new TypeError("taskId must be a ClickUp task ID");
|
|
288
|
+
}
|
|
289
|
+
function validateNumericId(id) {
|
|
290
|
+
if (!numericIdPattern.test(id)) throw new TypeError("ID must be numeric");
|
|
291
|
+
}
|
|
292
|
+
function dateMilliseconds(value) {
|
|
293
|
+
if (!value) return void 0;
|
|
294
|
+
if (!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(value)) throw new TypeError("date must be RFC 3339");
|
|
295
|
+
const ms = Date.parse(value);
|
|
296
|
+
if (!Number.isSafeInteger(ms) || ms <= 0) throw new TypeError("date must be after the Unix epoch");
|
|
297
|
+
return ms;
|
|
298
|
+
}
|
|
299
|
+
function validatePriority(value) {
|
|
300
|
+
if (value && ![1, 2, 3, 4].includes(value)) throw new TypeError("priority must be 1 through 4");
|
|
301
|
+
}
|
|
302
|
+
function hasDuplicate(values) {
|
|
303
|
+
return values !== void 0 && new Set(values).size !== values.length;
|
|
304
|
+
}
|
|
305
|
+
function isValidUnicode(value) {
|
|
306
|
+
return Buffer.from(value).toString("utf8") === value;
|
|
307
|
+
}
|
|
308
|
+
function validateUserIds(values) {
|
|
309
|
+
if ((values?.length ?? 0) > 50 || values?.some((value) => !Number.isSafeInteger(value) || value <= 0) || hasDuplicate(values)) throw new TypeError("invalid user ID");
|
|
310
|
+
}
|
|
311
|
+
function validateTags(values) {
|
|
312
|
+
if (values?.some((tag) => !tag || tag.trim() !== tag || Buffer.byteLength(tag) > 100 || !isValidUnicode(tag) || tag.includes("/") || /[\0\r\n\t]/.test(tag) || tag === "." || tag === "..") || hasDuplicate(values)) throw new TypeError("invalid tag name");
|
|
313
|
+
}
|
|
314
|
+
function validateStatusName(status) {
|
|
315
|
+
if (status && (!status.trim() || Buffer.byteLength(status) > 255 || !isValidUnicode(status))) throw new TypeError("invalid status name");
|
|
316
|
+
}
|
|
317
|
+
function isJSONValue(value, seen = /* @__PURE__ */ new Set()) {
|
|
318
|
+
if (value === null || typeof value === "boolean") return true;
|
|
319
|
+
if (typeof value === "string") return isValidUnicode(value);
|
|
320
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
321
|
+
if (typeof value !== "object" || seen.has(value)) return false;
|
|
322
|
+
seen.add(value);
|
|
323
|
+
const valid = Array.isArray(value) ? value.every((item) => isJSONValue(item, seen)) : Object.getPrototypeOf(value) === Object.prototype && Object.entries(value).every(([key, item]) => isValidUnicode(key) && isJSONValue(item, seen));
|
|
324
|
+
seen.delete(value);
|
|
325
|
+
return valid;
|
|
326
|
+
}
|
|
327
|
+
function validateName(name) {
|
|
328
|
+
if (!name.trim() || Buffer.byteLength(name) > 1024) throw new TypeError("invalid task name");
|
|
329
|
+
}
|
|
330
|
+
function receipt(client, call, objectId) {
|
|
331
|
+
return client.receipt(call, objectId);
|
|
332
|
+
}
|
|
333
|
+
function pathEscape(value) {
|
|
334
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(?:24|26|2B|3A|3D|40)/g, (escape) => String.fromCharCode(Number.parseInt(escape.slice(1), 16)));
|
|
335
|
+
}
|
|
336
|
+
function path(id) {
|
|
337
|
+
return `/task/${pathEscape(id)}`;
|
|
338
|
+
}
|
|
339
|
+
function failedDecode(operation, output, responseReceipt) {
|
|
340
|
+
const cause = failure("PROTOCOL", operation, `ClickUp returned an invalid ${operation === "searchTasks" ? "page of tasks" : operation === "findMemberByEmail" ? "list of Workspaces" : "task"}`);
|
|
341
|
+
return newQueryBranch("invalidResponse", output, responseReceipt, cause);
|
|
342
|
+
}
|
|
343
|
+
var SearchTasksOperation = class {
|
|
344
|
+
/** Bind a client. */
|
|
345
|
+
constructor(client) {
|
|
346
|
+
this.client = client;
|
|
347
|
+
}
|
|
348
|
+
client;
|
|
349
|
+
/** Return the generated definition. */
|
|
350
|
+
definition() {
|
|
351
|
+
return SearchTasksDefinition;
|
|
352
|
+
}
|
|
353
|
+
/** Validate filters, search, and decode the page. */
|
|
354
|
+
async invoke(call, input) {
|
|
355
|
+
const output = { tasks: [], page: input.page ?? 0 };
|
|
356
|
+
try {
|
|
357
|
+
validateNumericId(input.workspaceId);
|
|
358
|
+
for (const ids of [input.listIds, input.folderIds, input.spaceIds]) {
|
|
359
|
+
if ((ids?.length ?? 0) > 50) throw new TypeError("too many IDs");
|
|
360
|
+
ids?.forEach(validateNumericId);
|
|
361
|
+
}
|
|
362
|
+
if ([input.statuses, input.assigneeIds, input.tags].some((values) => (values?.length ?? 0) > 50)) throw new TypeError("too many filters");
|
|
363
|
+
validateUserIds(input.assigneeIds);
|
|
364
|
+
validateTags(input.tags);
|
|
365
|
+
input.statuses?.forEach(validateStatusName);
|
|
366
|
+
if (input.orderBy && !["created", "updated", "due_date", "id"].includes(input.orderBy)) throw new TypeError("invalid orderBy");
|
|
367
|
+
if (!Number.isInteger(output.page) || output.page < 0 || output.page > 1e3) throw new TypeError("invalid page");
|
|
368
|
+
dateMilliseconds(input.updatedAfter);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
return defect("searchTasks", output, String(error));
|
|
371
|
+
}
|
|
372
|
+
const query = new URLSearchParams({ page: String(output.page) });
|
|
373
|
+
for (const [name, values] of [["list_ids[]", input.listIds], ["project_ids[]", input.folderIds], ["space_ids[]", input.spaceIds], ["statuses[]", input.statuses], ["assignees[]", input.assigneeIds?.map(String)], ["tags[]", input.tags]]) values?.forEach((value) => query.append(name, value));
|
|
374
|
+
if (input.updatedAfter) query.set("date_updated_gt", String(dateMilliseconds(input.updatedAfter)));
|
|
375
|
+
if (input.isClosedIncluded) query.set("include_closed", "true");
|
|
376
|
+
if (input.areSubtasksIncluded) query.set("subtasks", "true");
|
|
377
|
+
if (input.orderBy) query.set("order_by", input.orderBy);
|
|
378
|
+
if (input.isReverse) query.set("reverse", "true");
|
|
379
|
+
const result = await this.client.exchange(call, "searchTasks", "GET", `/team/${input.workspaceId}/task`, query);
|
|
380
|
+
const responseReceipt = receipt(this.client, call, input.workspaceId);
|
|
381
|
+
if (result.kind !== "succeeded") return queryExchange(result, output, responseReceipt);
|
|
382
|
+
try {
|
|
383
|
+
return newQueryBranch("searched", searchPage(result.response.body, output.page), responseReceipt);
|
|
384
|
+
} catch {
|
|
385
|
+
return failedDecode("searchTasks", output, responseReceipt);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var GetTaskOperation = class {
|
|
390
|
+
/** Bind a client. */
|
|
391
|
+
constructor(client) {
|
|
392
|
+
this.client = client;
|
|
393
|
+
}
|
|
394
|
+
client;
|
|
395
|
+
/** Return the generated definition. */
|
|
396
|
+
definition() {
|
|
397
|
+
return GetTaskDefinition;
|
|
398
|
+
}
|
|
399
|
+
/** Validate, read, and decode one task. */
|
|
400
|
+
async invoke(call, input) {
|
|
401
|
+
try {
|
|
402
|
+
validateTaskId(input.taskId);
|
|
403
|
+
if (input.isCustomTaskId) validateNumericId(input.workspaceId ?? "");
|
|
404
|
+
else if (input.workspaceId) throw new TypeError("workspaceId requires isCustomTaskId");
|
|
405
|
+
} catch (error) {
|
|
406
|
+
return defect("getTask", zeroTask, String(error));
|
|
407
|
+
}
|
|
408
|
+
const query = new URLSearchParams({ include_markdown_description: "true" });
|
|
409
|
+
if (input.isCustomTaskId) {
|
|
410
|
+
query.set("custom_task_ids", "true");
|
|
411
|
+
query.set("team_id", input.workspaceId);
|
|
412
|
+
}
|
|
413
|
+
const result = await this.client.exchange(call, "getTask", "GET", path(input.taskId), query);
|
|
414
|
+
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
415
|
+
if (result.kind !== "succeeded") return queryExchange(result, zeroTask, responseReceipt);
|
|
416
|
+
try {
|
|
417
|
+
const task = taskBody(result.response.body, true);
|
|
418
|
+
return newQueryBranch("found", task, receipt(this.client, call, task.id));
|
|
419
|
+
} catch {
|
|
420
|
+
return failedDecode("getTask", zeroTask, responseReceipt);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
var FindMemberByEmailOperation = class {
|
|
425
|
+
/** Bind a client. */
|
|
426
|
+
constructor(client) {
|
|
427
|
+
this.client = client;
|
|
428
|
+
}
|
|
429
|
+
client;
|
|
430
|
+
/** Return the generated definition. */
|
|
431
|
+
definition() {
|
|
432
|
+
return FindMemberByEmailDefinition;
|
|
433
|
+
}
|
|
434
|
+
/** Read Workspace members and compare email addresses. */
|
|
435
|
+
async invoke(call, input) {
|
|
436
|
+
try {
|
|
437
|
+
validateNumericId(input.workspaceId);
|
|
438
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(input.email)) throw new TypeError("email must be a bare address");
|
|
439
|
+
} catch (error) {
|
|
440
|
+
return defect("findMemberByEmail", zeroMember, String(error));
|
|
441
|
+
}
|
|
442
|
+
const result = await this.client.exchange(call, "findMemberByEmail", "GET", "/team");
|
|
443
|
+
const responseReceipt = receipt(this.client, call, input.workspaceId);
|
|
444
|
+
if (result.kind !== "succeeded") return result.kind === "notFound" ? newQueryBranch("providerRejected", zeroMember, responseReceipt, result.failure) : queryExchange(result, zeroMember, responseReceipt);
|
|
445
|
+
try {
|
|
446
|
+
const data = decodeObject(result.response.body);
|
|
447
|
+
if (!Array.isArray(data.teams)) throw new TypeError("missing Workspaces");
|
|
448
|
+
for (const value of data.teams) {
|
|
449
|
+
const team = object(value);
|
|
450
|
+
if (identifier(team.id) !== input.workspaceId) continue;
|
|
451
|
+
if (team.members !== void 0 && team.members !== null && !Array.isArray(team.members)) throw new TypeError("invalid members");
|
|
452
|
+
for (const entry of Array.isArray(team.members) ? team.members : []) {
|
|
453
|
+
const member = object(object(entry).user);
|
|
454
|
+
if (String(member.email ?? "").trim().toLowerCase() !== input.email.toLowerCase()) continue;
|
|
455
|
+
const id = Number(member.id);
|
|
456
|
+
if (!Number.isSafeInteger(id) || id <= 0) throw new TypeError("invalid member");
|
|
457
|
+
const resultMember = { id, email: String(member.email).trim(), workspaceId: input.workspaceId, ...member.username ? { username: String(member.username) } : {}, ...member.role ? { role: Number(member.role) } : {} };
|
|
458
|
+
return newQueryBranch("found", resultMember, receipt(this.client, call, String(id)));
|
|
459
|
+
}
|
|
460
|
+
return newQueryBranch("notFound", zeroMember, responseReceipt, failure("NOT_FOUND", "findMemberByEmail", "no member of the Workspace has the email address"));
|
|
461
|
+
}
|
|
462
|
+
return newQueryBranch("notFound", zeroMember, responseReceipt, failure("NOT_FOUND", "findMemberByEmail", "the token's user is not a member of the Workspace"));
|
|
463
|
+
} catch {
|
|
464
|
+
return failedDecode("findMemberByEmail", zeroMember, responseReceipt);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
var UpdateTaskOperation = class {
|
|
469
|
+
/** Bind a client. */
|
|
470
|
+
constructor(client) {
|
|
471
|
+
this.client = client;
|
|
472
|
+
}
|
|
473
|
+
client;
|
|
474
|
+
/** Return the generated definition. */
|
|
475
|
+
definition() {
|
|
476
|
+
return UpdateTaskDefinition;
|
|
477
|
+
}
|
|
478
|
+
/** Correlate this mutation with the Dex Call ID. */
|
|
479
|
+
idempotencyKey(callId) {
|
|
480
|
+
return callId;
|
|
481
|
+
}
|
|
482
|
+
/** Validate, update, and decode the task. */
|
|
483
|
+
async invoke(call, input) {
|
|
484
|
+
const output = { task: zeroTask };
|
|
485
|
+
try {
|
|
486
|
+
validateTaskId(input.taskId);
|
|
487
|
+
if (input.name === void 0 && input.markdownDescription === void 0 && !input.status && !input.priority && !input.dueAt && !(input.addAssigneeIds?.length || input.removeAssigneeIds?.length)) throw new TypeError("no changes");
|
|
488
|
+
if (input.name !== void 0) validateName(input.name);
|
|
489
|
+
if (input.markdownDescription !== void 0 && Buffer.byteLength(input.markdownDescription) > 65536) throw new TypeError("description too long");
|
|
490
|
+
validateStatusName(input.status);
|
|
491
|
+
validatePriority(input.priority);
|
|
492
|
+
dateMilliseconds(input.dueAt);
|
|
493
|
+
validateUserIds(input.addAssigneeIds);
|
|
494
|
+
validateUserIds(input.removeAssigneeIds);
|
|
495
|
+
if ((input.addAssigneeIds?.length ?? 0) + (input.removeAssigneeIds?.length ?? 0) > 50 || input.addAssigneeIds?.some((id) => input.removeAssigneeIds?.includes(id))) throw new TypeError("invalid assignees");
|
|
496
|
+
} catch (error) {
|
|
497
|
+
return defect("updateTask", output, String(error));
|
|
498
|
+
}
|
|
499
|
+
const payload = {};
|
|
500
|
+
if (input.name !== void 0) payload.name = input.name;
|
|
501
|
+
if (input.markdownDescription !== void 0) payload[input.markdownDescription ? "markdown_content" : "description"] = input.markdownDescription || " ";
|
|
502
|
+
if (input.status) payload.status = input.status;
|
|
503
|
+
if (input.priority) payload.priority = input.priority;
|
|
504
|
+
if (input.dueAt) {
|
|
505
|
+
payload.due_date = dateMilliseconds(input.dueAt);
|
|
506
|
+
payload.due_date_time = true;
|
|
507
|
+
}
|
|
508
|
+
if (input.addAssigneeIds?.length || input.removeAssigneeIds?.length) payload.assignees = { add: input.addAssigneeIds ?? [], rem: input.removeAssigneeIds ?? [] };
|
|
509
|
+
const result = await this.client.exchange(call, "updateTask", "PUT", path(input.taskId), void 0, payload);
|
|
510
|
+
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
511
|
+
if (result.kind !== "succeeded") return mutationExchange(result, output, responseReceipt);
|
|
512
|
+
try {
|
|
513
|
+
return newMutationBranch("updated", { task: taskBody(result.response.body, false) }, responseReceipt);
|
|
514
|
+
} catch {
|
|
515
|
+
return failedDecode("updateTask", output, responseReceipt);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
var UpdateTaskTagsOperation = class {
|
|
520
|
+
/** Bind a client. */
|
|
521
|
+
constructor(client) {
|
|
522
|
+
this.client = client;
|
|
523
|
+
}
|
|
524
|
+
client;
|
|
525
|
+
/** Return the generated definition. */
|
|
526
|
+
definition() {
|
|
527
|
+
return UpdateTaskTagsDefinition;
|
|
528
|
+
}
|
|
529
|
+
/** Correlate this mutation with the Dex Call ID. */
|
|
530
|
+
idempotencyKey(callId) {
|
|
531
|
+
return callId;
|
|
532
|
+
}
|
|
533
|
+
/** Apply repeat safe tag membership changes. */
|
|
534
|
+
async invoke(call, input) {
|
|
535
|
+
const output = { taskId: input.taskId, tags: [], appliedChanges: 0 };
|
|
536
|
+
try {
|
|
537
|
+
validateTaskId(input.taskId);
|
|
538
|
+
const tags = [...input.addTags ?? [], ...input.removeTags ?? []];
|
|
539
|
+
if (!tags.length || tags.length > 10) throw new TypeError("invalid tag changes");
|
|
540
|
+
validateTags(tags);
|
|
541
|
+
} catch (error) {
|
|
542
|
+
return defect("updateTaskTags", output, String(error));
|
|
543
|
+
}
|
|
544
|
+
const changes = [...(input.addTags ?? []).map((tag) => ({ method: "POST", tag })), ...(input.removeTags ?? []).map((tag) => ({ method: "DELETE", tag }))];
|
|
545
|
+
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
546
|
+
const operationSignal = AbortSignal.any([call.context.cancellationSignal, AbortSignal.timeout(25e3)]);
|
|
547
|
+
for (const change of changes) {
|
|
548
|
+
const result2 = await this.client.exchange(call, "updateTaskTags", change.method, `${path(input.taskId)}/tag/${pathEscape(change.tag)}`, void 0, void 0, operationSignal);
|
|
549
|
+
if (result2.kind === "succeeded" || result2.kind === "invalid") {
|
|
550
|
+
output.appliedChanges++;
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
return mutationExchange(result2, output, responseReceipt);
|
|
554
|
+
}
|
|
555
|
+
const result = await this.client.exchange(call, "updateTaskTags", "GET", path(input.taskId), void 0, void 0, operationSignal);
|
|
556
|
+
if (result.kind !== "succeeded") return mutationExchange(result, output, responseReceipt);
|
|
557
|
+
try {
|
|
558
|
+
output.tags = taskBody(result.response.body, false).tags;
|
|
559
|
+
return newMutationBranch("updated", output, responseReceipt);
|
|
560
|
+
} catch {
|
|
561
|
+
return failedDecode("updateTaskTags", output, responseReceipt);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
function previousDispatch(call) {
|
|
566
|
+
if (!call.context.hasLastHeartbeatValue()) return void 0;
|
|
567
|
+
const value = call.context.getLastHeartbeatValue();
|
|
568
|
+
if (value === null) return void 0;
|
|
569
|
+
if (!value || typeof value !== "object") return { clickupDispatchedCallId: call.id, clickupDispatchedAt: 0 };
|
|
570
|
+
const marker = value;
|
|
571
|
+
return { clickupDispatchedCallId: String(marker.clickupDispatchedCallId ?? ""), clickupDispatchedAt: Number(marker.clickupDispatchedAt ?? 0) };
|
|
572
|
+
}
|
|
573
|
+
async function clearDispatch(call) {
|
|
574
|
+
try {
|
|
575
|
+
await call.context.recordHeartbeat(null);
|
|
576
|
+
} catch {
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function matchText(value) {
|
|
580
|
+
return value.trim().replace(/\s+/g, " ");
|
|
581
|
+
}
|
|
582
|
+
var CreateTaskOperation = class {
|
|
583
|
+
/** Bind a client. */
|
|
584
|
+
constructor(client) {
|
|
585
|
+
this.client = client;
|
|
586
|
+
}
|
|
587
|
+
client;
|
|
588
|
+
/** Return the generated definition. */
|
|
589
|
+
definition() {
|
|
590
|
+
return CreateTaskDefinition;
|
|
591
|
+
}
|
|
592
|
+
/** Correlate the checkpoint with the Dex Call ID. */
|
|
593
|
+
idempotencyKey(callId) {
|
|
594
|
+
return callId;
|
|
595
|
+
}
|
|
596
|
+
/** Create or reconcile one task. */
|
|
597
|
+
async invoke(call, input) {
|
|
598
|
+
const output = { listId: input.listId, name: input.name, task: zeroTask };
|
|
599
|
+
try {
|
|
600
|
+
validateNumericId(input.listId);
|
|
601
|
+
validateName(input.name);
|
|
602
|
+
if (Buffer.byteLength(input.markdownDescription ?? "") > 65536) throw new TypeError("description too long");
|
|
603
|
+
validateStatusName(input.status);
|
|
604
|
+
validatePriority(input.priority);
|
|
605
|
+
dateMilliseconds(input.dueAt);
|
|
606
|
+
validateUserIds(input.assigneeIds);
|
|
607
|
+
validateTags(input.tags);
|
|
608
|
+
if ((input.tags?.length ?? 0) > 20 || (input.customFields?.length ?? 0) > 50) throw new TypeError("too many values");
|
|
609
|
+
if (input.parentTaskId) validateTaskId(input.parentTaskId);
|
|
610
|
+
if (input.customFields?.some((field) => !taskIdPattern.test(field.id) || !isJSONValue(field.value)) || hasDuplicate(input.customFields?.map((field) => field.id))) throw new TypeError("invalid custom field");
|
|
611
|
+
} catch (error) {
|
|
612
|
+
return defect("createTask", output, String(error));
|
|
613
|
+
}
|
|
614
|
+
const prior = previousDispatch(call);
|
|
615
|
+
if (prior) return this.reconcile(call, input, output, prior);
|
|
616
|
+
try {
|
|
617
|
+
await call.context.recordHeartbeat({ clickupDispatchedCallId: call.id, clickupDispatchedAt: this.client.currentTime().getTime() });
|
|
618
|
+
} catch {
|
|
619
|
+
return newMutationRetry(failure("AVAILABILITY", "createTask", "Dex did not record the dispatch checkpoint; nothing was sent"));
|
|
620
|
+
}
|
|
621
|
+
const payload = { name: input.name };
|
|
622
|
+
if (input.isCreatorNotified) payload.notify_all = true;
|
|
623
|
+
if (input.markdownDescription) payload.markdown_content = input.markdownDescription;
|
|
624
|
+
if (input.status) payload.status = input.status;
|
|
625
|
+
if (input.priority) payload.priority = input.priority;
|
|
626
|
+
if (input.dueAt) {
|
|
627
|
+
payload.due_date = dateMilliseconds(input.dueAt);
|
|
628
|
+
payload.due_date_time = true;
|
|
629
|
+
}
|
|
630
|
+
if (input.assigneeIds?.length) payload.assignees = input.assigneeIds;
|
|
631
|
+
if (input.tags?.length) payload.tags = input.tags;
|
|
632
|
+
if (input.parentTaskId) payload.parent = input.parentTaskId;
|
|
633
|
+
if (input.customFields?.length) payload.custom_fields = input.customFields.map((field) => ({ id: field.id, value: field.value }));
|
|
634
|
+
const result = await this.client.exchange(call, "createTask", "POST", `/list/${input.listId}/task`, void 0, payload);
|
|
635
|
+
const responseReceipt = receipt(this.client, call, input.listId);
|
|
636
|
+
if (result.kind !== "succeeded") {
|
|
637
|
+
if (result.kind === "notSent" || result.kind === "rateLimited") {
|
|
638
|
+
await clearDispatch(call);
|
|
639
|
+
return newMutationRetry(result.failure, result.retryAfterMs);
|
|
640
|
+
}
|
|
641
|
+
if (result.kind === "unconfirmed" || result.kind === "invalid") return newMutationRetry(result.failure, result.retryAfterMs);
|
|
642
|
+
if (result.kind === "defect") await clearDispatch(call);
|
|
643
|
+
return newMutationBranch(result.kind === "notFound" ? "notFound" : result.kind === "defect" ? "defect" : "providerRejected", output, responseReceipt, result.failure);
|
|
644
|
+
}
|
|
645
|
+
try {
|
|
646
|
+
const task = taskBody(result.response.body, false);
|
|
647
|
+
return newMutationBranch("created", { ...output, task }, receipt(this.client, call, task.id));
|
|
648
|
+
} catch {
|
|
649
|
+
return newMutationRetry(failure("PROTOCOL", "createTask", "ClickUp accepted the task but returned an invalid task, so the next attempt reads the List back"));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
async reconcile(call, input, output, marker) {
|
|
653
|
+
const since = marker.clickupDispatchedAt > 0 ? marker.clickupDispatchedAt - 3e5 : 0;
|
|
654
|
+
const query = new URLSearchParams({ include_closed: "true", subtasks: "true", page: "0" });
|
|
655
|
+
if (since > 0) query.set("date_created_gt", String(since));
|
|
656
|
+
const result = await this.client.exchange(call, "createTask", "GET", `/list/${input.listId}/task`, query);
|
|
657
|
+
const responseReceipt = receipt(this.client, call, input.listId);
|
|
658
|
+
if (result.kind !== "succeeded") {
|
|
659
|
+
if (isRetryable(result)) return newMutationRetry(result.failure, result.retryAfterMs);
|
|
660
|
+
if (result.kind === "notFound") return newMutationBranch("notFound", output, responseReceipt, result.failure);
|
|
661
|
+
return newMutationUncertain(output, failure(result.failure.kind, "createTask", "an earlier attempt of this Step sent the create, and the List could not be read back: " + result.failure.message), responseReceipt);
|
|
662
|
+
}
|
|
663
|
+
let matches;
|
|
664
|
+
try {
|
|
665
|
+
matches = (searchPage(result.response.body, 0).tasks ?? []).filter((task2) => task2.name.trim() === input.name.trim() && (task2.parentTaskId ?? "") === (input.parentTaskId ?? "") && (!since || task2.createdAt !== void 0 && Date.parse(task2.createdAt) >= since));
|
|
666
|
+
} catch {
|
|
667
|
+
return newMutationUncertain(output, failure("PROTOCOL", "createTask", "an earlier attempt of this Step sent the create, and the List read back is invalid"), responseReceipt);
|
|
668
|
+
}
|
|
669
|
+
if (matches.length !== 1) return newMutationUncertain(output, failure("TRANSPORT", "createTask", `an earlier attempt of this Step sent the create without a confirmed outcome, and the List shows ${matches.length} tasks with the name created since, so it is not sent again`), responseReceipt);
|
|
670
|
+
const task = matches[0];
|
|
671
|
+
return newMutationBranch("created", { ...output, task, wasAlreadyApplied: true }, receipt(this.client, call, task.id));
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
var AddCommentOperation = class {
|
|
675
|
+
/** Bind a client. */
|
|
676
|
+
constructor(client) {
|
|
677
|
+
this.client = client;
|
|
678
|
+
}
|
|
679
|
+
client;
|
|
680
|
+
/** Return the generated definition. */
|
|
681
|
+
definition() {
|
|
682
|
+
return AddCommentDefinition;
|
|
683
|
+
}
|
|
684
|
+
/** Correlate the checkpoint with the Dex Call ID. */
|
|
685
|
+
idempotencyKey(callId) {
|
|
686
|
+
return callId;
|
|
687
|
+
}
|
|
688
|
+
/** Add or reconcile one comment. */
|
|
689
|
+
async invoke(call, input) {
|
|
690
|
+
const output = { taskId: input.taskId };
|
|
691
|
+
try {
|
|
692
|
+
validateTaskId(input.taskId);
|
|
693
|
+
if (!input.text.trim() || Buffer.byteLength(input.text) > 32768) throw new TypeError("invalid comment text");
|
|
694
|
+
} catch (error) {
|
|
695
|
+
return defect("addComment", output, String(error));
|
|
696
|
+
}
|
|
697
|
+
const prior = previousDispatch(call);
|
|
698
|
+
if (prior) return this.reconcile(call, input, output, prior);
|
|
699
|
+
try {
|
|
700
|
+
await call.context.recordHeartbeat({ clickupDispatchedCallId: call.id, clickupDispatchedAt: this.client.currentTime().getTime() });
|
|
701
|
+
} catch {
|
|
702
|
+
return newMutationRetry(failure("AVAILABILITY", "addComment", "Dex did not record the dispatch checkpoint; nothing was sent"));
|
|
703
|
+
}
|
|
704
|
+
const result = await this.client.exchange(call, "addComment", "POST", `${path(input.taskId)}/comment`, void 0, { comment_text: input.text, notify_all: input.isCreatorNotified ?? false });
|
|
705
|
+
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
706
|
+
if (result.kind !== "succeeded") {
|
|
707
|
+
if (result.kind === "notSent" || result.kind === "rateLimited") {
|
|
708
|
+
await clearDispatch(call);
|
|
709
|
+
return newMutationRetry(result.failure, result.retryAfterMs);
|
|
710
|
+
}
|
|
711
|
+
if (result.kind === "unconfirmed" || result.kind === "invalid") return newMutationRetry(result.failure, result.retryAfterMs);
|
|
712
|
+
if (result.kind === "defect") await clearDispatch(call);
|
|
713
|
+
return newMutationBranch(result.kind === "notFound" ? "notFound" : result.kind === "defect" ? "defect" : "providerRejected", output, responseReceipt, result.failure);
|
|
714
|
+
}
|
|
715
|
+
try {
|
|
716
|
+
const data = decodeObject(result.response.body);
|
|
717
|
+
const id = identifier(data.id);
|
|
718
|
+
if (!taskIdPattern.test(id)) throw new TypeError("invalid comment ID");
|
|
719
|
+
const createdAt = milliseconds(data.date);
|
|
720
|
+
return newMutationBranch("added", { ...output, commentId: id, ...createdAt ? { createdAt } : {} }, { ...responseReceipt, metadata: { commentId: id } });
|
|
721
|
+
} catch {
|
|
722
|
+
return newMutationRetry(failure("PROTOCOL", "addComment", "ClickUp accepted the comment but returned no valid comment ID, so the next attempt reads the comments back"));
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
async reconcile(call, input, output, marker) {
|
|
726
|
+
const result = await this.client.exchange(call, "addComment", "GET", `${path(input.taskId)}/comment`);
|
|
727
|
+
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
728
|
+
if (result.kind !== "succeeded") {
|
|
729
|
+
if (isRetryable(result)) return newMutationRetry(result.failure, result.retryAfterMs);
|
|
730
|
+
if (result.kind === "notFound") return newMutationBranch("notFound", output, responseReceipt, result.failure);
|
|
731
|
+
return newMutationUncertain(output, failure(result.failure.kind, "addComment", "an earlier attempt of this Step sent the comment, and the task's comments could not be read back: " + result.failure.message), responseReceipt);
|
|
732
|
+
}
|
|
733
|
+
let matches;
|
|
734
|
+
try {
|
|
735
|
+
const data = decodeObject(result.response.body);
|
|
736
|
+
if (!Array.isArray(data.comments)) throw new TypeError("missing comments");
|
|
737
|
+
const since = marker.clickupDispatchedAt > 0 ? marker.clickupDispatchedAt - 3e5 : 0;
|
|
738
|
+
matches = data.comments.map((value) => object(value)).filter((value) => matchText(String(value.comment_text ?? "")) === matchText(input.text) && (!since || milliseconds(value.date) !== void 0 && Date.parse(milliseconds(value.date)) >= since)).map((value) => ({ id: identifier(value.id), ...milliseconds(value.date) ? { createdAt: milliseconds(value.date) } : {} }));
|
|
739
|
+
} catch {
|
|
740
|
+
return newMutationUncertain(output, failure("PROTOCOL", "addComment", "an earlier attempt of this Step sent the comment, and the comments read back are invalid"), responseReceipt);
|
|
741
|
+
}
|
|
742
|
+
if (matches.length !== 1 || !taskIdPattern.test(matches[0].id)) return newMutationUncertain(output, failure("TRANSPORT", "addComment", `an earlier attempt of this Step sent the comment without a confirmed outcome, and the task shows ${matches.length} matching comments since, so it is not sent again`), responseReceipt);
|
|
743
|
+
const match = matches[0];
|
|
744
|
+
return newMutationBranch("added", { ...output, commentId: match.id, ...match.createdAt ? { createdAt: match.createdAt } : {}, wasAlreadyApplied: true }, { ...responseReceipt, metadata: { commentId: match.id } });
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
// src/client.ts
|
|
749
|
+
var apiBaseURL = "https://api.clickup.com/api/v2";
|
|
750
|
+
var defaultMaxResponseBytes = 4194304;
|
|
751
|
+
var ClickUpClient = class {
|
|
752
|
+
endpoint;
|
|
753
|
+
maxResponseBytes;
|
|
754
|
+
credentials;
|
|
755
|
+
send;
|
|
756
|
+
now;
|
|
757
|
+
/** Validate the client configuration without contacting ClickUp. */
|
|
758
|
+
constructor(config, credentials, options = {}) {
|
|
759
|
+
if (!credentials) throw new TypeError("ClickUp credential provider is required");
|
|
760
|
+
this.endpoint = validateBaseURL(options.apiBaseURL ?? apiBaseURL);
|
|
761
|
+
this.maxResponseBytes = config.maxResponseBytes ?? defaultMaxResponseBytes;
|
|
762
|
+
if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("ClickUp maxResponseBytes must be positive");
|
|
763
|
+
this.credentials = credentials;
|
|
764
|
+
this.send = options.send ?? sendProviderRequest;
|
|
765
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
766
|
+
}
|
|
767
|
+
/** Bind the Workspace task search. */
|
|
768
|
+
searchTasks() {
|
|
769
|
+
return new SearchTasksOperation(this);
|
|
770
|
+
}
|
|
771
|
+
/** Bind the task read. */
|
|
772
|
+
getTask() {
|
|
773
|
+
return new GetTaskOperation(this);
|
|
774
|
+
}
|
|
775
|
+
/** Bind the task creation. */
|
|
776
|
+
createTask() {
|
|
777
|
+
return new CreateTaskOperation(this);
|
|
778
|
+
}
|
|
779
|
+
/** Bind the task update. */
|
|
780
|
+
updateTask() {
|
|
781
|
+
return new UpdateTaskOperation(this);
|
|
782
|
+
}
|
|
783
|
+
/** Bind the task tag update. */
|
|
784
|
+
updateTaskTags() {
|
|
785
|
+
return new UpdateTaskTagsOperation(this);
|
|
786
|
+
}
|
|
787
|
+
/** Bind the comment creation. */
|
|
788
|
+
addComment() {
|
|
789
|
+
return new AddCommentOperation(this);
|
|
790
|
+
}
|
|
791
|
+
/** Bind the Workspace member lookup. */
|
|
792
|
+
findMemberByEmail() {
|
|
793
|
+
return new FindMemberByEmailOperation(this);
|
|
794
|
+
}
|
|
795
|
+
/** Create a secret safe receipt. */
|
|
796
|
+
receipt(call, objectId = "") {
|
|
797
|
+
return {
|
|
798
|
+
callId: call.id,
|
|
799
|
+
provider: "clickup",
|
|
800
|
+
observedAt: this.now().toISOString(),
|
|
801
|
+
...call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {},
|
|
802
|
+
...objectId ? { providerObjectId: objectId } : {}
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
/** Return the current time for retry and reconciliation decisions. */
|
|
806
|
+
currentTime() {
|
|
807
|
+
return this.now();
|
|
808
|
+
}
|
|
809
|
+
/** Send a bounded API request and classify its response; signal can bound a multi-request operation. */
|
|
810
|
+
async exchange(call, operation, method, path2, query, payload, signal = call.context.cancellationSignal) {
|
|
811
|
+
let token;
|
|
812
|
+
try {
|
|
813
|
+
const credentials = await this.credentials.resolve(call, signal);
|
|
814
|
+
if (!(credentials.apiToken instanceof SecretString)) throw new TypeError("missing token");
|
|
815
|
+
token = credentials.apiToken.reveal();
|
|
816
|
+
if (!isHeaderSafeCredential(token) || !token.startsWith("pk_") || token.length <= 3) throw new TypeError("invalid token");
|
|
817
|
+
} catch {
|
|
818
|
+
return this.outcome("defect", operation, "AUTHENTICATION", "ClickUp connection credentials are unavailable");
|
|
819
|
+
}
|
|
820
|
+
let body;
|
|
821
|
+
try {
|
|
822
|
+
if (payload !== void 0) body = Buffer.from(JSON.stringify(payload));
|
|
823
|
+
} catch {
|
|
824
|
+
return this.outcome("defect", operation, "LOCAL_DEFECT", "ClickUp request could not be built");
|
|
825
|
+
}
|
|
826
|
+
let response;
|
|
827
|
+
try {
|
|
828
|
+
response = await this.send({
|
|
829
|
+
url: this.endpoint + path2 + (query?.size ? `?${query}` : ""),
|
|
830
|
+
method,
|
|
831
|
+
headers: { Authorization: token, Accept: "application/json", ...body ? { "Content-Type": "application/json" } : {} },
|
|
832
|
+
...body ? { body } : {},
|
|
833
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
834
|
+
addressPolicy: this.endpoint === apiBaseURL ? "publicHTTPS" : "privateNetworkHTTP",
|
|
835
|
+
timeoutMs: 9e3,
|
|
836
|
+
signal
|
|
837
|
+
});
|
|
838
|
+
} catch (error) {
|
|
839
|
+
if (error instanceof BodyTooLargeError) return this.outcome("invalid", operation, "RESPONSE_TOO_LARGE", "ClickUp response exceeds the configured maxResponseBytes limit");
|
|
840
|
+
if (error instanceof ProviderTransportError && error.isProvablyNotSent) return this.outcome("notSent", operation, "TRANSPORT", "ClickUp could not be reached; no request was sent");
|
|
841
|
+
return this.outcome("unconfirmed", operation, "TRANSPORT", "ClickUp request failed before a response arrived");
|
|
842
|
+
}
|
|
843
|
+
if (response.status >= 200 && response.status < 300) {
|
|
844
|
+
if (Buffer.from(response.body).includes(Buffer.from(token))) return this.outcome("invalid", operation, "PROTOCOL", "ClickUp response reflected the connection credential");
|
|
845
|
+
return { kind: "succeeded", response };
|
|
846
|
+
}
|
|
847
|
+
const status = response.status;
|
|
848
|
+
const code = readErrorCode(response.body);
|
|
849
|
+
const withCode = (message) => message + (code ? ` [${code}]` : "");
|
|
850
|
+
if (status === 429) return this.outcome("rateLimited", operation, "RATE_LIMIT", withCode("ClickUp rate limited the token (HTTP 429)"), this.rateLimitDelay(response));
|
|
851
|
+
if (status === 408 || status >= 500) return this.outcome("unconfirmed", operation, "AVAILABILITY", withCode(`ClickUp could not complete the request (HTTP ${status})`));
|
|
852
|
+
if (status === 404 || status === 410) return this.outcome("notFound", operation, "NOT_FOUND", withCode(`ClickUp found no such resource (HTTP ${status})`));
|
|
853
|
+
if (status === 401 && ["OAUTH_023", "OAUTH_026", "OAUTH_027", ...Array.from({ length: 17 }, (_, index) => `OAUTH_${String(index + 29).padStart(3, "0")}`)].includes(code))
|
|
854
|
+
return this.outcome("notFound", operation, "AUTHORIZATION", withCode("ClickUp reports that the resource's Workspace is not authorized for the token (HTTP 401)"));
|
|
855
|
+
if (status >= 300 && status < 400) return this.outcome("rejected", operation, "PROTOCOL", `ClickUp redirected the request (HTTP ${status})`);
|
|
856
|
+
if (status === 401) return this.outcome("rejected", operation, "AUTHENTICATION", withCode("ClickUp rejected the personal API token (HTTP 401)"));
|
|
857
|
+
const kind = status === 403 ? "AUTHORIZATION" : status === 409 ? "CONFLICT" : [400, 422].includes(status) ? "VALIDATION" : "PROVIDER_REJECTION";
|
|
858
|
+
return this.outcome("rejected", operation, kind, withCode(`ClickUp rejected the request (HTTP ${status})`));
|
|
859
|
+
}
|
|
860
|
+
rateLimitDelay(response) {
|
|
861
|
+
const header = (name) => {
|
|
862
|
+
const value = response.headers[name];
|
|
863
|
+
return Array.isArray(value) ? value[0] ?? "" : value ?? "";
|
|
864
|
+
};
|
|
865
|
+
const retryAfter = parseRetryAfter(header("retry-after"), this.now());
|
|
866
|
+
if (retryAfter > 0) return Math.min(retryAfter, 6e4);
|
|
867
|
+
const reset = Number(header("x-ratelimit-reset"));
|
|
868
|
+
return Number.isSafeInteger(reset) && reset > 0 ? Math.min(6e4, Math.max(1e3, reset * 1e3 - this.now().getTime())) : 0;
|
|
869
|
+
}
|
|
870
|
+
outcome(kind, operation, failureKind, message, retryAfterMs = 0) {
|
|
871
|
+
return { kind, failure: { kind: failureKind, provider: "clickup", operation, message }, retryAfterMs };
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
function readErrorCode(body) {
|
|
875
|
+
try {
|
|
876
|
+
const value = JSON.parse(Buffer.from(body).toString());
|
|
877
|
+
if (value && typeof value === "object" && "ECODE" in value && typeof value.ECODE === "string" && /^[A-Z][A-Z0-9]{0,15}_[0-9]{1,6}$/.test(value.ECODE)) return value.ECODE;
|
|
878
|
+
} catch {
|
|
879
|
+
}
|
|
880
|
+
return "";
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// src/project.ts
|
|
884
|
+
function newProjectConnection2(project, connectionName) {
|
|
885
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
886
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "clickup" && entry.connectionName === name);
|
|
887
|
+
if (!selected) throw new TypeError("ClickUp project connection is not configured");
|
|
888
|
+
const config = z.object({ maxResponseBytes: z.number().int().optional(), webhookMaxBodyBytes: z.number().int().optional() }).parse(selected.configuration);
|
|
889
|
+
const credentials = {
|
|
890
|
+
async resolve(call, signal) {
|
|
891
|
+
void call;
|
|
892
|
+
const fields = await loadedProject.resolveCredential("clickup", name, signal);
|
|
893
|
+
const decoded = z.object({ api_token: z.string().min(1), webhook_secret: z.string().optional() }).parse(fields);
|
|
894
|
+
return { apiToken: new SecretString2(decoded.api_token), ...decoded.webhook_secret ? { webhookSecret: new SecretString2(decoded.webhook_secret) } : {} };
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
return new ClickUpClient(config, credentials);
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
export {
|
|
901
|
+
AddCommentBranch,
|
|
902
|
+
AddCommentBranchAdded,
|
|
903
|
+
AddCommentBranchDefect,
|
|
904
|
+
AddCommentBranchNotFound,
|
|
905
|
+
AddCommentBranchProviderRejected,
|
|
906
|
+
AddCommentBranchUncertain,
|
|
907
|
+
AddCommentDefinition,
|
|
908
|
+
AddCommentInputSchema,
|
|
909
|
+
AddCommentMetadata,
|
|
910
|
+
AddCommentOperation,
|
|
911
|
+
AddCommentOutputSchema,
|
|
912
|
+
ClickUpClient,
|
|
913
|
+
ConfigSchema,
|
|
914
|
+
Connection,
|
|
915
|
+
ConnectorID,
|
|
916
|
+
CreateTaskBranch,
|
|
917
|
+
CreateTaskBranchCreated,
|
|
918
|
+
CreateTaskBranchDefect,
|
|
919
|
+
CreateTaskBranchNotFound,
|
|
920
|
+
CreateTaskBranchProviderRejected,
|
|
921
|
+
CreateTaskBranchUncertain,
|
|
922
|
+
CreateTaskDefinition,
|
|
923
|
+
CreateTaskInputSchema,
|
|
924
|
+
CreateTaskMetadata,
|
|
925
|
+
CreateTaskOperation,
|
|
926
|
+
CreateTaskOutputSchema,
|
|
927
|
+
CustomFieldInputSchema,
|
|
928
|
+
CustomFieldValueSchema,
|
|
929
|
+
FindMemberByEmailBranch,
|
|
930
|
+
FindMemberByEmailBranchDefect,
|
|
931
|
+
FindMemberByEmailBranchFound,
|
|
932
|
+
FindMemberByEmailBranchInvalidResponse,
|
|
933
|
+
FindMemberByEmailBranchNotFound,
|
|
934
|
+
FindMemberByEmailBranchProviderRejected,
|
|
935
|
+
FindMemberByEmailDefinition,
|
|
936
|
+
FindMemberByEmailInputSchema,
|
|
937
|
+
FindMemberByEmailMetadata,
|
|
938
|
+
FindMemberByEmailOperation,
|
|
939
|
+
GetTaskBranch,
|
|
940
|
+
GetTaskBranchDefect,
|
|
941
|
+
GetTaskBranchFound,
|
|
942
|
+
GetTaskBranchInvalidResponse,
|
|
943
|
+
GetTaskBranchNotFound,
|
|
944
|
+
GetTaskBranchProviderRejected,
|
|
945
|
+
GetTaskDefinition,
|
|
946
|
+
GetTaskInputSchema,
|
|
947
|
+
GetTaskMetadata,
|
|
948
|
+
GetTaskOperation,
|
|
949
|
+
MemberSchema,
|
|
950
|
+
ProviderID,
|
|
951
|
+
SearchTasksBranch,
|
|
952
|
+
SearchTasksBranchDefect,
|
|
953
|
+
SearchTasksBranchInvalidResponse,
|
|
954
|
+
SearchTasksBranchNotFound,
|
|
955
|
+
SearchTasksBranchProviderRejected,
|
|
956
|
+
SearchTasksBranchSearched,
|
|
957
|
+
SearchTasksDefinition,
|
|
958
|
+
SearchTasksInputSchema,
|
|
959
|
+
SearchTasksMetadata,
|
|
960
|
+
SearchTasksOperation,
|
|
961
|
+
SearchTasksOutputSchema,
|
|
962
|
+
TaskSchema,
|
|
963
|
+
TaskStatusSchema,
|
|
964
|
+
UpdateTaskBranch,
|
|
965
|
+
UpdateTaskBranchDefect,
|
|
966
|
+
UpdateTaskBranchInvalidResponse,
|
|
967
|
+
UpdateTaskBranchNotFound,
|
|
968
|
+
UpdateTaskBranchProviderRejected,
|
|
969
|
+
UpdateTaskBranchUpdated,
|
|
970
|
+
UpdateTaskDefinition,
|
|
971
|
+
UpdateTaskInputSchema,
|
|
972
|
+
UpdateTaskMetadata,
|
|
973
|
+
UpdateTaskOperation,
|
|
974
|
+
UpdateTaskOutputSchema,
|
|
975
|
+
UpdateTaskTagsBranch,
|
|
976
|
+
UpdateTaskTagsBranchDefect,
|
|
977
|
+
UpdateTaskTagsBranchInvalidResponse,
|
|
978
|
+
UpdateTaskTagsBranchNotFound,
|
|
979
|
+
UpdateTaskTagsBranchProviderRejected,
|
|
980
|
+
UpdateTaskTagsBranchUpdated,
|
|
981
|
+
UpdateTaskTagsDefinition,
|
|
982
|
+
UpdateTaskTagsInputSchema,
|
|
983
|
+
UpdateTaskTagsMetadata,
|
|
984
|
+
UpdateTaskTagsOperation,
|
|
985
|
+
UpdateTaskTagsOutputSchema,
|
|
986
|
+
UserSchema,
|
|
987
|
+
newAddCommentStep,
|
|
988
|
+
newConnection,
|
|
989
|
+
newConnectionWithOperations,
|
|
990
|
+
newCreateTaskStep,
|
|
991
|
+
newFindMemberByEmailStep,
|
|
992
|
+
newGetTaskStep,
|
|
993
|
+
newProjectConnection2 as newProjectConnection,
|
|
994
|
+
newSearchTasksStep,
|
|
995
|
+
newUpdateTaskStep,
|
|
996
|
+
newUpdateTaskTagsStep
|
|
997
|
+
};
|