@superdurable/connector-clickup 0.1.2 → 0.1.3
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 +2 -2
- package/dex-connector.json +357 -9
- package/dist/{chunk-PAUZSKGN.js → chunk-PQCNNSDL.js} +35 -13
- package/dist/{connection-BB-IGLLD.d.ts → connection-CyZGpZRT.d.ts} +8 -2
- package/dist/index.d.ts +31 -19
- package/dist/index.js +282 -111
- package/dist/mock.d.ts +1 -1
- package/dist/mock.js +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
CreateTaskInputSchema,
|
|
23
23
|
CreateTaskMetadata,
|
|
24
24
|
CreateTaskOutputSchema,
|
|
25
|
+
CredentialMaterialError,
|
|
25
26
|
CustomFieldInputSchema,
|
|
26
27
|
CustomFieldValueSchema,
|
|
27
28
|
FindMemberByEmailBranch,
|
|
@@ -78,10 +79,11 @@ import {
|
|
|
78
79
|
UpdateTaskTagsOutputSchema,
|
|
79
80
|
UserSchema,
|
|
80
81
|
decodeCredentials,
|
|
82
|
+
isCredentialMaterialError,
|
|
81
83
|
newConnection,
|
|
82
84
|
newConnectionWithOperations,
|
|
83
85
|
newProjectConnection
|
|
84
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-PQCNNSDL.js";
|
|
85
87
|
|
|
86
88
|
// src/generated/steps.ts
|
|
87
89
|
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
@@ -119,7 +121,7 @@ function newCreateTaskStep(configuration) {
|
|
|
119
121
|
] });
|
|
120
122
|
}
|
|
121
123
|
function newUpdateTaskStep(configuration) {
|
|
122
|
-
const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
124
|
+
const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
|
|
123
125
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
124
126
|
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateTask(), connection: connection.reference, branches: [
|
|
125
127
|
goToBranch("updated", updated),
|
|
@@ -130,7 +132,7 @@ function newUpdateTaskStep(configuration) {
|
|
|
130
132
|
] });
|
|
131
133
|
}
|
|
132
134
|
function newUpdateTaskTagsStep(configuration) {
|
|
133
|
-
const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
135
|
+
const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
|
|
134
136
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
135
137
|
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateTaskTags(), connection: connection.reference, branches: [
|
|
136
138
|
goToBranch("updated", updated),
|
|
@@ -168,11 +170,13 @@ import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
|
168
170
|
import { z } from "zod";
|
|
169
171
|
|
|
170
172
|
// src/client.ts
|
|
171
|
-
import { BodyTooLargeError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
172
|
-
import { SecretString } from "@superdurable/connectors-sdk";
|
|
173
|
+
import { BodyTooLargeError, ProviderStalledError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
174
|
+
import { ReauthorizationRequiredError, SecretString } from "@superdurable/connectors-sdk";
|
|
175
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
173
176
|
|
|
174
177
|
// src/operations.ts
|
|
175
|
-
import { newMutationBranch, newMutationRetry, newMutationUncertain, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
178
|
+
import { definitionMaxSends, newMutationBranch, newMutationRetry, newMutationUncertain, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
179
|
+
import { newFence } from "@superdurable/connectors-sdk/singledispatch";
|
|
176
180
|
var taskIdPattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
177
181
|
var numericIdPattern = /^[0-9]{1,20}$/;
|
|
178
182
|
var zeroTask = { id: "", name: "", status: { name: "" }, assignees: [], tags: [] };
|
|
@@ -193,6 +197,26 @@ function mutationExchange(exchange, output, receipt2, hasInvalidResponse = true)
|
|
|
193
197
|
const branch = exchange.kind === "notFound" ? "notFound" : exchange.kind === "invalid" && hasInvalidResponse ? "invalidResponse" : exchange.kind === "defect" ? "defect" : "providerRejected";
|
|
194
198
|
return newMutationBranch(branch, output, receipt2, exchange.failure);
|
|
195
199
|
}
|
|
200
|
+
var definiteWriteRefusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
|
|
201
|
+
function classifyWrite(exchange) {
|
|
202
|
+
if (exchange.kind === "succeeded") return "accepted";
|
|
203
|
+
if (exchange.kind === "notSent" || exchange.kind === "rateLimited") return "notApplied";
|
|
204
|
+
if (exchange.kind === "defect") return "defect";
|
|
205
|
+
if (exchange.status >= 200 && exchange.status < 300) return "acceptedUnreadable";
|
|
206
|
+
if (exchange.kind === "invalid") return "unknown";
|
|
207
|
+
if (exchange.status === 503) return "notApplied";
|
|
208
|
+
if (exchange.isErrorBodyTooLarge) return "unknown";
|
|
209
|
+
if (exchange.kind === "notFound" && exchange.status !== 410) return "notFound";
|
|
210
|
+
if (exchange.kind === "rejected" && definiteWriteRefusalStatuses.has(exchange.status)) return "rejected";
|
|
211
|
+
return "unknown";
|
|
212
|
+
}
|
|
213
|
+
function repeatableWriteFailure(exchange, output, receipt2) {
|
|
214
|
+
const outcome = classifyWrite(exchange);
|
|
215
|
+
if (outcome === "notFound") return newMutationBranch("notFound", output, receipt2, exchange.failure);
|
|
216
|
+
if (outcome === "rejected") return newMutationBranch("providerRejected", output, receipt2, exchange.failure);
|
|
217
|
+
if (outcome === "defect") return newMutationBranch("defect", output, receipt2, exchange.failure);
|
|
218
|
+
return newMutationRetry(exchange.failure, exchange.retryAfterMs);
|
|
219
|
+
}
|
|
196
220
|
function defect(operation, output, message) {
|
|
197
221
|
const cause = failure("VALIDATION", operation, message);
|
|
198
222
|
return newQueryBranch("defect", output, {}, cause);
|
|
@@ -509,11 +533,11 @@ var UpdateTaskOperation = class {
|
|
|
509
533
|
if (input.addAssigneeIds?.length || input.removeAssigneeIds?.length) payload.assignees = { add: input.addAssigneeIds ?? [], rem: input.removeAssigneeIds ?? [] };
|
|
510
534
|
const result = await this.client.exchange(call, "updateTask", "PUT", path(input.taskId), void 0, payload);
|
|
511
535
|
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
512
|
-
if (result.kind !== "succeeded") return
|
|
536
|
+
if (result.kind !== "succeeded") return repeatableWriteFailure(result, output, responseReceipt);
|
|
513
537
|
try {
|
|
514
538
|
return newMutationBranch("updated", { task: taskBody(result.response.body, false) }, responseReceipt);
|
|
515
539
|
} catch {
|
|
516
|
-
return
|
|
540
|
+
return newMutationRetry(failure("PROTOCOL", "updateTask", "ClickUp accepted the update but returned an invalid task"));
|
|
517
541
|
}
|
|
518
542
|
}
|
|
519
543
|
};
|
|
@@ -551,35 +575,152 @@ var UpdateTaskTagsOperation = class {
|
|
|
551
575
|
output.appliedChanges++;
|
|
552
576
|
continue;
|
|
553
577
|
}
|
|
554
|
-
return
|
|
578
|
+
return repeatableWriteFailure(result2, output, responseReceipt);
|
|
555
579
|
}
|
|
556
580
|
const result = await this.client.exchange(call, "updateTaskTags", "GET", path(input.taskId), void 0, void 0, operationSignal);
|
|
581
|
+
if (result.kind === "invalid") return newMutationRetry(result.failure);
|
|
557
582
|
if (result.kind !== "succeeded") return mutationExchange(result, output, responseReceipt);
|
|
558
583
|
try {
|
|
559
584
|
output.tags = taskBody(result.response.body, false).tags;
|
|
560
585
|
return newMutationBranch("updated", output, responseReceipt);
|
|
561
586
|
} catch {
|
|
562
|
-
return
|
|
587
|
+
return newMutationRetry(failure("PROTOCOL", "updateTaskTags", "ClickUp applied the tag changes but returned an invalid task"));
|
|
563
588
|
}
|
|
564
589
|
}
|
|
565
590
|
};
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const value = call.context.getLastHeartbeatValue();
|
|
569
|
-
if (value === null) return void 0;
|
|
570
|
-
if (!value || typeof value !== "object") return { clickupDispatchedCallId: call.id, clickupDispatchedAt: 0 };
|
|
571
|
-
const marker = value;
|
|
572
|
-
return { clickupDispatchedCallId: String(marker.clickupDispatchedCallId ?? ""), clickupDispatchedAt: Number(marker.clickupDispatchedAt ?? 0) };
|
|
573
|
-
}
|
|
574
|
-
async function clearDispatch(call) {
|
|
575
|
-
try {
|
|
576
|
-
await call.context.recordHeartbeat(void 0);
|
|
577
|
-
} catch {
|
|
578
|
-
}
|
|
579
|
-
}
|
|
591
|
+
var writeReconciliationSkewMs = 3e5;
|
|
592
|
+
var unknownWriteSettleMs = 5e3;
|
|
580
593
|
function matchText(value) {
|
|
581
594
|
return value.trim().replace(/\s+/g, " ");
|
|
582
595
|
}
|
|
596
|
+
function readBackCreatedSince(call) {
|
|
597
|
+
const context = call.context;
|
|
598
|
+
const firstAttemptAt = context.firstAttemptAt instanceof Date ? context.firstAttemptAt : context.flowStartedAt;
|
|
599
|
+
if (!(firstAttemptAt instanceof Date)) return 0;
|
|
600
|
+
const since = firstAttemptAt.getTime() - writeReconciliationSkewMs;
|
|
601
|
+
return since > 0 ? since : 0;
|
|
602
|
+
}
|
|
603
|
+
var FencedWrite = class _FencedWrite {
|
|
604
|
+
constructor(operation, fence, decision) {
|
|
605
|
+
this.operation = operation;
|
|
606
|
+
this.fence = fence;
|
|
607
|
+
this.decision = decision;
|
|
608
|
+
this.hasPossibleEarlierSend = (decision.priorSendUpperBound ?? 0) > 0;
|
|
609
|
+
this.providerId = decision.marker?.providerId ?? "";
|
|
610
|
+
}
|
|
611
|
+
operation;
|
|
612
|
+
fence;
|
|
613
|
+
decision;
|
|
614
|
+
/** Whether an earlier send of this call may have taken effect. */
|
|
615
|
+
hasPossibleEarlierSend;
|
|
616
|
+
/** The identity an earlier accepted send saved, or an empty string. */
|
|
617
|
+
providerId;
|
|
618
|
+
/** Decide whether this attempt may send, or return the attempt that forbids it. */
|
|
619
|
+
static start(call, definition, operation, output) {
|
|
620
|
+
let fence;
|
|
621
|
+
try {
|
|
622
|
+
fence = newFence(call, 3e4, { maxSends: definitionMaxSends(definition) });
|
|
623
|
+
} catch {
|
|
624
|
+
return newMutationBranch("defect", output, {}, failure("LOCAL_DEFECT", operation, "ClickUp dispatch fence could not be constructed"));
|
|
625
|
+
}
|
|
626
|
+
const decision = fence.decide();
|
|
627
|
+
if (decision.kind === "failClosed") return newMutationRetry(failure("AVAILABILITY", operation, "the ClickUp dispatch checkpoint is unreadable, so nothing was sent in this attempt"));
|
|
628
|
+
return new _FencedWrite(operation, fence, decision);
|
|
629
|
+
}
|
|
630
|
+
/** Whether an earlier send may have taken effect, so this attempt reads back first; sendAllowed after canResend can carry earlier sends. */
|
|
631
|
+
get needsReadBack() {
|
|
632
|
+
return this.decision.kind !== "sendAllowed" || this.hasPossibleEarlierSend || this.providerId !== "";
|
|
633
|
+
}
|
|
634
|
+
/** Send once behind the fence, or return the Retry when the fence refuses to send. */
|
|
635
|
+
async dispatch(send) {
|
|
636
|
+
try {
|
|
637
|
+
return { exchange: await this.fence.dispatch(send) };
|
|
638
|
+
} catch {
|
|
639
|
+
return { attempt: newMutationRetry(failure("AVAILABILITY", this.operation, "the ClickUp dispatch checkpoint or request budget is unavailable, so nothing was sent")) };
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
/** Map a sent write without a 2xx; an unknown outcome retries so the next attempt reads back. */
|
|
643
|
+
async unaccepted(exchange, output, responseReceipt) {
|
|
644
|
+
const outcome = classifyWrite(exchange);
|
|
645
|
+
if (outcome === "notApplied") {
|
|
646
|
+
try {
|
|
647
|
+
await this.fence.recordCanResend();
|
|
648
|
+
} catch {
|
|
649
|
+
return newMutationRetry(failure("AVAILABILITY", this.operation, "ClickUp retry checkpoint could not be recorded"), exchange.retryAfterMs);
|
|
650
|
+
}
|
|
651
|
+
return newMutationRetry(exchange.failure, exchange.retryAfterMs);
|
|
652
|
+
}
|
|
653
|
+
if (outcome === "defect") {
|
|
654
|
+
try {
|
|
655
|
+
await this.fence.recordCanResend();
|
|
656
|
+
} catch {
|
|
657
|
+
}
|
|
658
|
+
if (!this.hasPossibleEarlierSend) return newMutationBranch("defect", output, responseReceipt, exchange.failure);
|
|
659
|
+
if (exchange.failure.kind === "AUTHENTICATION") return this.terminalCredentialFailure(output, exchange.failure);
|
|
660
|
+
return newMutationUncertain(output, exchange.failure, responseReceipt);
|
|
661
|
+
}
|
|
662
|
+
if (outcome === "notFound" || outcome === "rejected") {
|
|
663
|
+
if (this.hasPossibleEarlierSend) return newMutationUncertain(output, exchange.failure, responseReceipt);
|
|
664
|
+
try {
|
|
665
|
+
await this.fence.recordCanResend();
|
|
666
|
+
} catch {
|
|
667
|
+
return newMutationRetry(failure("AVAILABILITY", this.operation, "ClickUp rejection checkpoint could not be recorded"));
|
|
668
|
+
}
|
|
669
|
+
return newMutationBranch(outcome === "notFound" ? "notFound" : "providerRejected", output, responseReceipt, exchange.failure);
|
|
670
|
+
}
|
|
671
|
+
if (outcome === "acceptedUnreadable") {
|
|
672
|
+
return newMutationUncertain(output, failure(exchange.failure.kind, this.operation, `ClickUp accepted the write but its response is unusable, so it is not sent again: ${exchange.failure.message}`), responseReceipt);
|
|
673
|
+
}
|
|
674
|
+
return newMutationRetry(exchange.failure, Math.max(exchange.retryAfterMs, unknownWriteSettleMs));
|
|
675
|
+
}
|
|
676
|
+
/** Save the accepted identity so a replayed attempt never resends it. */
|
|
677
|
+
async recordAccepted(providerId) {
|
|
678
|
+
try {
|
|
679
|
+
await this.fence.recordProviderId(providerId);
|
|
680
|
+
} catch {
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
/** Retry an unusable 2xx only when its ID is saved, so the next attempt reads it back; otherwise select uncertain. */
|
|
684
|
+
async retryAcceptedReadBackOrSelectUncertain(providerId, output, responseReceipt, message) {
|
|
685
|
+
if (providerId) {
|
|
686
|
+
try {
|
|
687
|
+
await this.fence.recordProviderId(providerId);
|
|
688
|
+
return newMutationRetry(failure("PROTOCOL", this.operation, `${message}, so the next attempt reads it back`), unknownWriteSettleMs);
|
|
689
|
+
} catch {
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return newMutationUncertain(output, failure("PROTOCOL", this.operation, `${message}, so it is not sent again`), responseReceipt);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Select uncertain for a terminal credential failure after a possible earlier send, without recording notSent.
|
|
696
|
+
* A transient credential failure arrives as `notSent` and retries instead.
|
|
697
|
+
*/
|
|
698
|
+
terminalCredentialFailure(output, cause) {
|
|
699
|
+
return newMutationUncertain(output, failure(cause.kind, this.operation, `an earlier attempt of this Step may have sent the write and the connection credentials cannot read it back: ${cause.message}`), {});
|
|
700
|
+
}
|
|
701
|
+
/** Permit one send when the fence allows it after a read-back that confirmed nothing, and otherwise select uncertain. */
|
|
702
|
+
missingReadBack(output, responseReceipt, subject, cause) {
|
|
703
|
+
if ((this.decision.kind === "readBackThenResendAllowed" || this.decision.kind === "sendAllowed") && !this.providerId) return void 0;
|
|
704
|
+
const confirmed = subject === "create" ? "task" : subject;
|
|
705
|
+
return newMutationUncertain(output, failure(cause.kind, this.operation, `earlier attempts of this Step sent the ${subject} up to the send cap or were accepted, and read-back cannot confirm the ${confirmed}, so it is not sent again: ${cause.message}`), responseReceipt);
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
function createTaskPayload(input) {
|
|
709
|
+
const payload = { name: input.name };
|
|
710
|
+
if (input.isCreatorNotified) payload.notify_all = true;
|
|
711
|
+
if (input.markdownDescription) payload.markdown_content = input.markdownDescription;
|
|
712
|
+
if (input.status) payload.status = input.status;
|
|
713
|
+
if (input.priority) payload.priority = input.priority;
|
|
714
|
+
if (input.dueAt) {
|
|
715
|
+
payload.due_date = dateMilliseconds(input.dueAt);
|
|
716
|
+
payload.due_date_time = true;
|
|
717
|
+
}
|
|
718
|
+
if (input.assigneeIds?.length) payload.assignees = input.assigneeIds;
|
|
719
|
+
if (input.tags?.length) payload.tags = input.tags;
|
|
720
|
+
if (input.parentTaskId) payload.parent = input.parentTaskId;
|
|
721
|
+
if (input.customFields?.length) payload.custom_fields = input.customFields.map((field) => ({ id: field.id, value: field.value }));
|
|
722
|
+
return payload;
|
|
723
|
+
}
|
|
583
724
|
var CreateTaskOperation = class {
|
|
584
725
|
/** Bind a client. */
|
|
585
726
|
constructor(client) {
|
|
@@ -594,7 +735,7 @@ var CreateTaskOperation = class {
|
|
|
594
735
|
idempotencyKey(callId) {
|
|
595
736
|
return callId;
|
|
596
737
|
}
|
|
597
|
-
/** Create or
|
|
738
|
+
/** Create, read back, or resend one task. */
|
|
598
739
|
async invoke(call, input) {
|
|
599
740
|
const output = { listId: input.listId, name: input.name, task: zeroTask };
|
|
600
741
|
try {
|
|
@@ -612,66 +753,79 @@ var CreateTaskOperation = class {
|
|
|
612
753
|
} catch (error) {
|
|
613
754
|
return defect("createTask", output, String(error));
|
|
614
755
|
}
|
|
615
|
-
const
|
|
616
|
-
if (
|
|
617
|
-
|
|
618
|
-
await
|
|
619
|
-
|
|
620
|
-
return newMutationRetry(failure("AVAILABILITY", "createTask", "Dex did not record the dispatch checkpoint; nothing was sent"));
|
|
621
|
-
}
|
|
622
|
-
const payload = { name: input.name };
|
|
623
|
-
if (input.isCreatorNotified) payload.notify_all = true;
|
|
624
|
-
if (input.markdownDescription) payload.markdown_content = input.markdownDescription;
|
|
625
|
-
if (input.status) payload.status = input.status;
|
|
626
|
-
if (input.priority) payload.priority = input.priority;
|
|
627
|
-
if (input.dueAt) {
|
|
628
|
-
payload.due_date = dateMilliseconds(input.dueAt);
|
|
629
|
-
payload.due_date_time = true;
|
|
756
|
+
const write = FencedWrite.start(call, CreateTaskDefinition, "createTask", output);
|
|
757
|
+
if (!(write instanceof FencedWrite)) return write;
|
|
758
|
+
if (write.needsReadBack) {
|
|
759
|
+
const reconciled = await this.reconcile(call, input, output, write);
|
|
760
|
+
if (reconciled) return reconciled;
|
|
630
761
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (
|
|
634
|
-
|
|
635
|
-
const result = await this.client.exchange(call, "createTask", "POST", `/list/${input.listId}/task`, void 0, payload);
|
|
762
|
+
const payload = createTaskPayload(input);
|
|
763
|
+
const sent = await write.dispatch((signal) => this.client.exchange(call, "createTask", "POST", `/list/${input.listId}/task`, void 0, payload, signal));
|
|
764
|
+
if ("attempt" in sent) return sent.attempt;
|
|
765
|
+
const result = sent.exchange;
|
|
636
766
|
const responseReceipt = receipt(this.client, call, input.listId);
|
|
637
|
-
if (result.kind !== "succeeded")
|
|
638
|
-
|
|
639
|
-
await clearDispatch(call);
|
|
640
|
-
return newMutationRetry(result.failure, result.retryAfterMs);
|
|
641
|
-
}
|
|
642
|
-
if (result.kind === "unconfirmed" || result.kind === "invalid") return newMutationRetry(result.failure, result.retryAfterMs);
|
|
643
|
-
if (result.kind === "defect") await clearDispatch(call);
|
|
644
|
-
return newMutationBranch(result.kind === "notFound" ? "notFound" : result.kind === "defect" ? "defect" : "providerRejected", output, responseReceipt, result.failure);
|
|
645
|
-
}
|
|
767
|
+
if (result.kind !== "succeeded") return write.unaccepted(result, output, responseReceipt);
|
|
768
|
+
let task;
|
|
646
769
|
try {
|
|
647
|
-
|
|
648
|
-
return newMutationBranch("created", { ...output, task }, receipt(this.client, call, task.id));
|
|
770
|
+
task = taskBody(result.response.body, false);
|
|
649
771
|
} catch {
|
|
650
|
-
return
|
|
772
|
+
return write.retryAcceptedReadBackOrSelectUncertain(createdTaskReference(result.response.body), output, responseReceipt, "ClickUp accepted the task but returned an invalid task");
|
|
651
773
|
}
|
|
774
|
+
await write.recordAccepted(task.id);
|
|
775
|
+
return newMutationBranch("created", { ...output, task }, receipt(this.client, call, task.id));
|
|
652
776
|
}
|
|
653
|
-
|
|
654
|
-
|
|
777
|
+
/** Never send; return undefined when read-back confirmed nothing and the fence permits a resend. */
|
|
778
|
+
async reconcile(call, input, output, write) {
|
|
779
|
+
const responseReceipt = receipt(this.client, call, input.listId);
|
|
780
|
+
if (write.providerId) {
|
|
781
|
+
const result2 = await this.client.exchange(call, "createTask", "GET", path(write.providerId));
|
|
782
|
+
if (result2.kind !== "succeeded") {
|
|
783
|
+
if (isRetryable(result2)) return newMutationRetry(result2.failure, result2.retryAfterMs);
|
|
784
|
+
if (result2.kind === "defect") return write.terminalCredentialFailure(output, result2.failure);
|
|
785
|
+
return write.missingReadBack(output, responseReceipt, "create", result2.failure);
|
|
786
|
+
}
|
|
787
|
+
let task2;
|
|
788
|
+
try {
|
|
789
|
+
task2 = taskBody(result2.response.body, false);
|
|
790
|
+
if (task2.id !== write.providerId) throw new TypeError("another task");
|
|
791
|
+
} catch {
|
|
792
|
+
return write.missingReadBack(output, responseReceipt, "create", failure("PROTOCOL", "createTask", "the accepted task read back is invalid"));
|
|
793
|
+
}
|
|
794
|
+
return newMutationBranch("created", { ...output, task: task2, wasAlreadyApplied: true }, receipt(this.client, call, task2.id));
|
|
795
|
+
}
|
|
796
|
+
const since = readBackCreatedSince(call);
|
|
655
797
|
const query = new URLSearchParams({ include_closed: "true", subtasks: "true", page: "0" });
|
|
656
798
|
if (since > 0) query.set("date_created_gt", String(since));
|
|
657
799
|
const result = await this.client.exchange(call, "createTask", "GET", `/list/${input.listId}/task`, query);
|
|
658
|
-
const responseReceipt = receipt(this.client, call, input.listId);
|
|
659
800
|
if (result.kind !== "succeeded") {
|
|
660
801
|
if (isRetryable(result)) return newMutationRetry(result.failure, result.retryAfterMs);
|
|
661
|
-
if (result.kind === "
|
|
662
|
-
|
|
802
|
+
if (result.kind === "defect") return write.terminalCredentialFailure(output, result.failure);
|
|
803
|
+
if (result.kind === "notFound") return unreadableParentAfterPossibleSend("createTask", "created the task", "List", output, responseReceipt, result.failure);
|
|
804
|
+
return write.missingReadBack(output, responseReceipt, "create", result.failure);
|
|
663
805
|
}
|
|
664
806
|
let matches;
|
|
665
807
|
try {
|
|
666
808
|
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));
|
|
667
809
|
} catch {
|
|
668
|
-
return
|
|
810
|
+
return write.missingReadBack(output, responseReceipt, "create", failure("PROTOCOL", "createTask", "the List read back is invalid"));
|
|
669
811
|
}
|
|
670
|
-
if (matches.length
|
|
812
|
+
if (!matches.length) return write.missingReadBack(output, responseReceipt, "create", failure("TRANSPORT", "createTask", "the List shows no task with the name created since"));
|
|
813
|
+
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);
|
|
671
814
|
const task = matches[0];
|
|
672
815
|
return newMutationBranch("created", { ...output, task, wasAlreadyApplied: true }, receipt(this.client, call, task.id));
|
|
673
816
|
}
|
|
674
817
|
};
|
|
818
|
+
function unreadableParentAfterPossibleSend(operation, effect, parent, output, responseReceipt, cause) {
|
|
819
|
+
return newMutationUncertain(output, failure(cause.kind, operation, `an earlier attempt of this Step may have ${effect}, and the ${parent} can no longer be read back, so it is not sent again: ${cause.message}`), responseReceipt);
|
|
820
|
+
}
|
|
821
|
+
function createdTaskReference(body) {
|
|
822
|
+
try {
|
|
823
|
+
const id = decodeObject(body).id;
|
|
824
|
+
return typeof id === "string" && taskIdPattern.test(id) ? id : "";
|
|
825
|
+
} catch {
|
|
826
|
+
return "";
|
|
827
|
+
}
|
|
828
|
+
}
|
|
675
829
|
var AddCommentOperation = class {
|
|
676
830
|
/** Bind a client. */
|
|
677
831
|
constructor(client) {
|
|
@@ -686,7 +840,7 @@ var AddCommentOperation = class {
|
|
|
686
840
|
idempotencyKey(callId) {
|
|
687
841
|
return callId;
|
|
688
842
|
}
|
|
689
|
-
/** Add or
|
|
843
|
+
/** Add, read back, or resend one comment. */
|
|
690
844
|
async invoke(call, input) {
|
|
691
845
|
const output = { taskId: input.taskId };
|
|
692
846
|
try {
|
|
@@ -695,52 +849,54 @@ var AddCommentOperation = class {
|
|
|
695
849
|
} catch (error) {
|
|
696
850
|
return defect("addComment", output, String(error));
|
|
697
851
|
}
|
|
698
|
-
const
|
|
699
|
-
if (
|
|
700
|
-
|
|
701
|
-
await
|
|
702
|
-
|
|
703
|
-
return newMutationRetry(failure("AVAILABILITY", "addComment", "Dex did not record the dispatch checkpoint; nothing was sent"));
|
|
852
|
+
const write = FencedWrite.start(call, AddCommentDefinition, "addComment", output);
|
|
853
|
+
if (!(write instanceof FencedWrite)) return write;
|
|
854
|
+
if (write.needsReadBack) {
|
|
855
|
+
const reconciled = await this.reconcile(call, input, output, write);
|
|
856
|
+
if (reconciled) return reconciled;
|
|
704
857
|
}
|
|
705
|
-
const
|
|
858
|
+
const sent = await write.dispatch((signal) => this.client.exchange(call, "addComment", "POST", `${path(input.taskId)}/comment`, void 0, { comment_text: input.text, notify_all: input.isCreatorNotified ?? false }, signal));
|
|
859
|
+
if ("attempt" in sent) return sent.attempt;
|
|
860
|
+
const result = sent.exchange;
|
|
706
861
|
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
707
|
-
if (result.kind !== "succeeded")
|
|
708
|
-
|
|
709
|
-
await clearDispatch(call);
|
|
710
|
-
return newMutationRetry(result.failure, result.retryAfterMs);
|
|
711
|
-
}
|
|
712
|
-
if (result.kind === "unconfirmed" || result.kind === "invalid") return newMutationRetry(result.failure, result.retryAfterMs);
|
|
713
|
-
if (result.kind === "defect") await clearDispatch(call);
|
|
714
|
-
return newMutationBranch(result.kind === "notFound" ? "notFound" : result.kind === "defect" ? "defect" : "providerRejected", output, responseReceipt, result.failure);
|
|
715
|
-
}
|
|
862
|
+
if (result.kind !== "succeeded") return write.unaccepted(result, output, responseReceipt);
|
|
863
|
+
let id = "", createdAt;
|
|
716
864
|
try {
|
|
717
865
|
const data = decodeObject(result.response.body);
|
|
718
|
-
|
|
719
|
-
if (!taskIdPattern.test(id))
|
|
720
|
-
|
|
721
|
-
|
|
866
|
+
id = identifier(data.id);
|
|
867
|
+
if (!taskIdPattern.test(id)) {
|
|
868
|
+
id = "";
|
|
869
|
+
throw new TypeError("invalid comment ID");
|
|
870
|
+
}
|
|
871
|
+
createdAt = milliseconds(data.date);
|
|
722
872
|
} catch {
|
|
723
|
-
return
|
|
873
|
+
return write.retryAcceptedReadBackOrSelectUncertain(id, output, responseReceipt, "ClickUp accepted the comment but returned an invalid comment");
|
|
724
874
|
}
|
|
875
|
+
await write.recordAccepted(id);
|
|
876
|
+
return newMutationBranch("added", { ...output, commentId: id, ...createdAt ? { createdAt } : {} }, { ...responseReceipt, metadata: { commentId: id } });
|
|
725
877
|
}
|
|
726
|
-
|
|
878
|
+
/** Never send; return undefined when read-back confirmed nothing and the fence permits a resend. */
|
|
879
|
+
async reconcile(call, input, output, write) {
|
|
727
880
|
const result = await this.client.exchange(call, "addComment", "GET", `${path(input.taskId)}/comment`);
|
|
728
881
|
const responseReceipt = receipt(this.client, call, input.taskId);
|
|
729
882
|
if (result.kind !== "succeeded") {
|
|
730
883
|
if (isRetryable(result)) return newMutationRetry(result.failure, result.retryAfterMs);
|
|
731
|
-
if (result.kind === "
|
|
732
|
-
|
|
884
|
+
if (result.kind === "defect") return write.terminalCredentialFailure(output, result.failure);
|
|
885
|
+
if (result.kind === "notFound") return unreadableParentAfterPossibleSend("addComment", "added the comment", "task", output, responseReceipt, result.failure);
|
|
886
|
+
return write.missingReadBack(output, responseReceipt, "comment", result.failure);
|
|
733
887
|
}
|
|
734
888
|
let matches;
|
|
735
889
|
try {
|
|
736
890
|
const data = decodeObject(result.response.body);
|
|
737
891
|
if (!Array.isArray(data.comments)) throw new TypeError("missing comments");
|
|
738
|
-
const since =
|
|
739
|
-
|
|
892
|
+
const since = readBackCreatedSince(call);
|
|
893
|
+
const isSentByThisStep = (value) => write.providerId ? identifier(value.id) === write.providerId : matchText(String(value.comment_text ?? "")) === matchText(input.text) && (!since || milliseconds(value.date) !== void 0 && Date.parse(milliseconds(value.date)) >= since);
|
|
894
|
+
matches = data.comments.map((value) => object(value)).filter(isSentByThisStep).map((value) => ({ id: identifier(value.id), ...milliseconds(value.date) ? { createdAt: milliseconds(value.date) } : {} }));
|
|
740
895
|
} catch {
|
|
741
|
-
return
|
|
896
|
+
return write.missingReadBack(output, responseReceipt, "comment", failure("PROTOCOL", "addComment", "the comments read back are invalid"));
|
|
742
897
|
}
|
|
743
|
-
if (matches.length
|
|
898
|
+
if (matches.length > 1) 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);
|
|
899
|
+
if (!matches.length || !taskIdPattern.test(matches[0].id)) return write.missingReadBack(output, responseReceipt, "comment", failure("TRANSPORT", "addComment", "the task shows no matching comment"));
|
|
744
900
|
const match = matches[0];
|
|
745
901
|
return newMutationBranch("added", { ...output, commentId: match.id, ...match.createdAt ? { createdAt: match.createdAt } : {}, wasAlreadyApplied: true }, { ...responseReceipt, metadata: { commentId: match.id } });
|
|
746
902
|
}
|
|
@@ -809,15 +965,15 @@ var ClickUpClient = class {
|
|
|
809
965
|
}
|
|
810
966
|
/** Send a bounded API request and classify its response; signal can bound a multi-request operation. */
|
|
811
967
|
async exchange(call, operation, method, path2, query, payload, signal = call.context.cancellationSignal) {
|
|
812
|
-
let
|
|
968
|
+
let credentials;
|
|
813
969
|
try {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
} catch {
|
|
819
|
-
return this.outcome("defect", operation, "AUTHENTICATION", "ClickUp connection credentials are unavailable");
|
|
970
|
+
credentials = await this.credentials.resolve(call, signal);
|
|
971
|
+
} catch (error) {
|
|
972
|
+
if (isTerminalCredentialError(error)) return this.outcome("defect", operation, "AUTHENTICATION", "ClickUp connection credentials are missing or need reauthorization");
|
|
973
|
+
return this.outcome("notSent", operation, "AVAILABILITY", "ClickUp connection credentials could not be read, so nothing was sent");
|
|
820
974
|
}
|
|
975
|
+
const token = credentials.apiToken instanceof SecretString ? credentials.apiToken.reveal() : "";
|
|
976
|
+
if (!isHeaderSafeCredential(token) || !token.startsWith("pk_") || token.length <= 3) return this.outcome("defect", operation, "AUTHENTICATION", "ClickUp connection credentials are invalid");
|
|
821
977
|
let body;
|
|
822
978
|
try {
|
|
823
979
|
if (payload !== void 0) body = Buffer.from(JSON.stringify(payload));
|
|
@@ -837,26 +993,36 @@ var ClickUpClient = class {
|
|
|
837
993
|
signal
|
|
838
994
|
});
|
|
839
995
|
} catch (error) {
|
|
840
|
-
|
|
996
|
+
const status = error instanceof BodyTooLargeError || error instanceof ProviderTransportError || error instanceof ProviderStalledError ? error.status ?? 0 : 0;
|
|
997
|
+
const isSuccessStatus = status >= 200 && status < 300;
|
|
998
|
+
if (error instanceof BodyTooLargeError && (isSuccessStatus || status === 0)) return this.outcome("invalid", operation, "RESPONSE_TOO_LARGE", "ClickUp response exceeds the configured maxResponseBytes limit", 0, status);
|
|
999
|
+
if (error instanceof BodyTooLargeError) {
|
|
1000
|
+
const classified = this.classifyFailureStatus(operation, { status, headers: error.headers ?? {}, body: new Uint8Array() });
|
|
1001
|
+
return classified.kind === "succeeded" ? classified : { ...classified, isErrorBodyTooLarge: true };
|
|
1002
|
+
}
|
|
841
1003
|
if (error instanceof ProviderTransportError && error.isProvablyNotSent) return this.outcome("notSent", operation, "TRANSPORT", "ClickUp could not be reached; no request was sent");
|
|
1004
|
+
if (isSuccessStatus) return this.outcome("unconfirmed", operation, "TRANSPORT", "ClickUp response could not be read", 0, status);
|
|
842
1005
|
return this.outcome("unconfirmed", operation, "TRANSPORT", "ClickUp request failed before a response arrived");
|
|
843
1006
|
}
|
|
844
1007
|
if (response.status >= 200 && response.status < 300) {
|
|
845
|
-
if (Buffer.from(response.body).includes(Buffer.from(token))) return this.outcome("invalid", operation, "PROTOCOL", "ClickUp response reflected the connection credential");
|
|
1008
|
+
if (Buffer.from(response.body).includes(Buffer.from(token))) return this.outcome("invalid", operation, "PROTOCOL", "ClickUp response reflected the connection credential", 0, response.status);
|
|
846
1009
|
return { kind: "succeeded", response };
|
|
847
1010
|
}
|
|
1011
|
+
return this.classifyFailureStatus(operation, response);
|
|
1012
|
+
}
|
|
1013
|
+
classifyFailureStatus(operation, response) {
|
|
848
1014
|
const status = response.status;
|
|
849
1015
|
const code = readErrorCode(response.body);
|
|
850
1016
|
const withCode = (message) => message + (code ? ` [${code}]` : "");
|
|
851
|
-
if (status === 429) return this.outcome("rateLimited", operation, "RATE_LIMIT", withCode("ClickUp rate limited the token (HTTP 429)"), this.rateLimitDelay(response));
|
|
852
|
-
if (status === 408 || status >= 500) return this.outcome("unconfirmed", operation, "AVAILABILITY", withCode(`ClickUp could not complete the request (HTTP ${status})`));
|
|
853
|
-
if (status === 404 || status === 410) return this.outcome("notFound", operation, "NOT_FOUND", withCode(`ClickUp found no such resource (HTTP ${status})`));
|
|
1017
|
+
if (status === 429) return this.outcome("rateLimited", operation, "RATE_LIMIT", withCode("ClickUp rate limited the token (HTTP 429)"), this.rateLimitDelay(response), status);
|
|
1018
|
+
if (status === 408 || status >= 500) return this.outcome("unconfirmed", operation, "AVAILABILITY", withCode(`ClickUp could not complete the request (HTTP ${status})`), 0, status);
|
|
1019
|
+
if (status === 404 || status === 410) return this.outcome("notFound", operation, "NOT_FOUND", withCode(`ClickUp found no such resource (HTTP ${status})`), 0, status);
|
|
854
1020
|
if (status === 401 && ["OAUTH_023", "OAUTH_026", "OAUTH_027", ...Array.from({ length: 17 }, (_, index) => `OAUTH_${String(index + 29).padStart(3, "0")}`)].includes(code))
|
|
855
|
-
return this.outcome("notFound", operation, "AUTHORIZATION", withCode("ClickUp reports that the resource's Workspace is not authorized for the token (HTTP 401)"));
|
|
856
|
-
if (status >= 300 && status < 400) return this.outcome("rejected", operation, "PROTOCOL", `ClickUp redirected the request (HTTP ${status})
|
|
857
|
-
if (status === 401) return this.outcome("rejected", operation, "AUTHENTICATION", withCode("ClickUp rejected the personal API token (HTTP 401)"));
|
|
1021
|
+
return this.outcome("notFound", operation, "AUTHORIZATION", withCode("ClickUp reports that the resource's Workspace is not authorized for the token (HTTP 401)"), 0, status);
|
|
1022
|
+
if (status >= 300 && status < 400) return this.outcome("rejected", operation, "PROTOCOL", `ClickUp redirected the request (HTTP ${status})`, 0, status);
|
|
1023
|
+
if (status === 401) return this.outcome("rejected", operation, "AUTHENTICATION", withCode("ClickUp rejected the personal API token (HTTP 401)"), 0, status);
|
|
858
1024
|
const kind = status === 403 ? "AUTHORIZATION" : status === 409 ? "CONFLICT" : [400, 422].includes(status) ? "VALIDATION" : "PROVIDER_REJECTION";
|
|
859
|
-
return this.outcome("rejected", operation, kind, withCode(`ClickUp rejected the request (HTTP ${status})`));
|
|
1025
|
+
return this.outcome("rejected", operation, kind, withCode(`ClickUp rejected the request (HTTP ${status})`), 0, status);
|
|
860
1026
|
}
|
|
861
1027
|
rateLimitDelay(response) {
|
|
862
1028
|
const header = (name) => {
|
|
@@ -868,10 +1034,13 @@ var ClickUpClient = class {
|
|
|
868
1034
|
const reset = Number(header("x-ratelimit-reset"));
|
|
869
1035
|
return Number.isSafeInteger(reset) && reset > 0 ? Math.min(6e4, Math.max(1e3, reset * 1e3 - this.now().getTime())) : 0;
|
|
870
1036
|
}
|
|
871
|
-
outcome(kind, operation, failureKind, message, retryAfterMs = 0) {
|
|
872
|
-
return { kind, failure: { kind: failureKind, provider: "clickup", operation, message }, retryAfterMs };
|
|
1037
|
+
outcome(kind, operation, failureKind, message, retryAfterMs = 0, status = 0) {
|
|
1038
|
+
return { kind, failure: { kind: failureKind, provider: "clickup", operation, message }, retryAfterMs, status };
|
|
873
1039
|
}
|
|
874
1040
|
};
|
|
1041
|
+
function isTerminalCredentialError(error) {
|
|
1042
|
+
return error instanceof ReauthorizationRequiredError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || error instanceof ObjectNotFoundError || isCredentialMaterialError(error);
|
|
1043
|
+
}
|
|
875
1044
|
function readErrorCode(body) {
|
|
876
1045
|
try {
|
|
877
1046
|
const value = JSON.parse(Buffer.from(body).toString());
|
|
@@ -925,6 +1094,7 @@ export {
|
|
|
925
1094
|
CreateTaskMetadata,
|
|
926
1095
|
CreateTaskOperation,
|
|
927
1096
|
CreateTaskOutputSchema,
|
|
1097
|
+
CredentialMaterialError,
|
|
928
1098
|
CustomFieldInputSchema,
|
|
929
1099
|
CustomFieldValueSchema,
|
|
930
1100
|
FindMemberByEmailBranch,
|
|
@@ -986,6 +1156,7 @@ export {
|
|
|
986
1156
|
UpdateTaskTagsOutputSchema,
|
|
987
1157
|
UserSchema,
|
|
988
1158
|
decodeCredentials,
|
|
1159
|
+
isCredentialMaterialError,
|
|
989
1160
|
newAddCommentStep,
|
|
990
1161
|
newConnection,
|
|
991
1162
|
newConnectionWithOperations,
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
2
|
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
-
import { O as Operations, C as Connection, S as SearchTasksInput, d as SearchTasksOutput, G as GetTaskInput, T as Task, b as CreateTaskInput, c as CreateTaskOutput, U as UpdateTaskInput, e as UpdateTaskOutput, f as UpdateTaskTagsInput, g as UpdateTaskTagsOutput, A as AddCommentInput, a as AddCommentOutput, F as FindMemberByEmailInput, M as Member,
|
|
3
|
+
import { O as Operations, C as Connection, S as SearchTasksInput, d as SearchTasksOutput, G as GetTaskInput, T as Task, b as CreateTaskInput, c as CreateTaskOutput, U as UpdateTaskInput, e as UpdateTaskOutput, f as UpdateTaskTagsInput, g as UpdateTaskTagsOutput, A as AddCommentInput, a as AddCommentOutput, F as FindMemberByEmailInput, M as Member, q as CustomFieldInput, s as CustomFieldValue, B as TaskStatus, K as User } from './connection-CyZGpZRT.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/** Go zero value for SearchTasksInput in scripted cases. */
|
package/dist/mock.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
UpdateTaskTagsOutputSchema,
|
|
28
28
|
UserSchema,
|
|
29
29
|
newConnectionWithOperations
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-PQCNNSDL.js";
|
|
31
31
|
|
|
32
32
|
// src/generated/mock.ts
|
|
33
33
|
import { branchCase, retryCase, uncertainCase, newMutation, newQuery } from "@superdurable/connectors-sdk/connectormock";
|