@clickraft/cli 0.8.5 → 0.8.6

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/dist/index.js CHANGED
@@ -636,6 +636,47 @@ function errorMessage(err) {
636
636
  if (err instanceof Error) return err.message;
637
637
  return String(err);
638
638
  }
639
+ async function applyWorkflowWithRetry(params) {
640
+ try {
641
+ return await patch(params);
642
+ } catch (err) {
643
+ if (!(err instanceof ApiError)) throw err;
644
+ const isRevConflict = err.code === "CANVAS_REV_MISMATCH" || err.meta.status === 409 && err.meta.details != null;
645
+ if (!isRevConflict || !params.autoRev) throw err;
646
+ const snapshot = await params.client.request({
647
+ method: "GET",
648
+ path: `/workflows/${encodeURIComponent(params.id)}`,
649
+ responseSchema: params.schemas.detail,
650
+ signal: params.signal
651
+ });
652
+ const retryResult = await patch({
653
+ ...params,
654
+ canvasRev: snapshot.canvas_rev,
655
+ // Fresh key — the body changed (different canvas_rev), so reusing the
656
+ // caller's key would trigger IDEMPOTENCY_KEY_CONFLICT.
657
+ idempotencyKey: void 0
658
+ });
659
+ return { ...retryResult, retriedWithRev: snapshot.canvas_rev };
660
+ }
661
+ }
662
+ async function patch(params) {
663
+ const data = await params.client.request({
664
+ method: "PATCH",
665
+ path: `/workflows/${encodeURIComponent(params.id)}`,
666
+ body: {
667
+ canvas_rev: params.canvasRev,
668
+ operations: params.operations
669
+ },
670
+ idempotencyKey: params.idempotencyKey,
671
+ responseSchema: params.schemas.mutate,
672
+ signal: params.signal
673
+ });
674
+ return {
675
+ canvasRev: data.canvas_rev,
676
+ applied: data.applied,
677
+ workflow: data.workflow
678
+ };
679
+ }
639
680
 
640
681
  // src/errors/codes.ts
641
682
  var LOGIN_HINT = "Run `clickraft login` to authenticate.";
@@ -3087,54 +3128,19 @@ async function buildWorkflowClient(opts) {
3087
3128
  });
3088
3129
  }
3089
3130
 
3090
- // src/commands/workflow/get.ts
3091
- async function getWorkflow(opts) {
3092
- const client = opts.client ?? await buildWorkflowClient(opts);
3093
- return client.request({
3094
- method: "GET",
3095
- path: `/workflows/${encodeURIComponent(opts.id)}`,
3096
- responseSchema: WorkflowDetailSchema,
3097
- signal: opts.signal
3098
- });
3099
- }
3100
-
3101
3131
  // src/commands/workflow/apply.ts
3102
3132
  async function applyWorkflow(opts) {
3103
3133
  const client = opts.client ?? await buildWorkflowClient(opts);
3104
- try {
3105
- return await patchWorkflow(client, opts);
3106
- } catch (err) {
3107
- if (!(err instanceof ApiError)) throw err;
3108
- const isRevConflict = err.code === "CANVAS_REV_MISMATCH" || err.meta.status === 409 && err.meta.details != null;
3109
- if (!isRevConflict || !opts.autoRev) throw err;
3110
- const snapshot = await getWorkflow({ id: opts.id, client, signal: opts.signal });
3111
- const retryResult = await patchWorkflow(client, {
3112
- ...opts,
3113
- canvasRev: snapshot.canvas_rev,
3114
- // Fresh key — the body changed (different canvas_rev), so reusing
3115
- // the caller's key would trigger IDEMPOTENCY_KEY_CONFLICT.
3116
- idempotencyKey: void 0
3117
- });
3118
- return { ...retryResult, retriedWithRev: snapshot.canvas_rev };
3119
- }
3120
- }
3121
- async function patchWorkflow(client, opts) {
3122
- const data = await client.request({
3123
- method: "PATCH",
3124
- path: `/workflows/${encodeURIComponent(opts.id)}`,
3125
- body: {
3126
- canvas_rev: opts.canvasRev,
3127
- operations: opts.operations
3128
- },
3134
+ return applyWorkflowWithRetry({
3135
+ client,
3136
+ id: opts.id,
3137
+ canvasRev: opts.canvasRev,
3138
+ operations: opts.operations,
3129
3139
  idempotencyKey: opts.idempotencyKey,
3130
- responseSchema: WorkflowMutateResponseSchema,
3131
- signal: opts.signal
3140
+ autoRev: opts.autoRev,
3141
+ signal: opts.signal,
3142
+ schemas: { mutate: WorkflowMutateResponseSchema, detail: WorkflowDetailSchema }
3132
3143
  });
3133
- return {
3134
- canvasRev: data.canvas_rev,
3135
- applied: data.applied,
3136
- workflow: data.workflow
3137
- };
3138
3144
  }
3139
3145
 
3140
3146
  // src/commands/workflow/create.ts
@@ -3165,6 +3171,17 @@ async function createWorkflow(opts) {
3165
3171
  });
3166
3172
  }
3167
3173
 
3174
+ // src/commands/workflow/get.ts
3175
+ async function getWorkflow(opts) {
3176
+ const client = opts.client ?? await buildWorkflowClient(opts);
3177
+ return client.request({
3178
+ method: "GET",
3179
+ path: `/workflows/${encodeURIComponent(opts.id)}`,
3180
+ responseSchema: WorkflowDetailSchema,
3181
+ signal: opts.signal
3182
+ });
3183
+ }
3184
+
3168
3185
  // src/commands/workflow/list.ts
3169
3186
  async function listWorkflows(opts) {
3170
3187
  const client = opts.client ?? await buildWorkflowClient(opts);