ardent-cli 0.0.49 → 0.0.50
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 +39 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,9 @@ import { Command as Command8 } from "commander";
|
|
|
6
6
|
// src/commands/branch/index.ts
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
|
|
9
|
+
// src/commands/branch/create.ts
|
|
10
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
11
|
+
|
|
9
12
|
// src/lib/config.ts
|
|
10
13
|
import { existsSync, mkdirSync, readFileSync as readFileSync2, writeFileSync, unlinkSync } from "fs";
|
|
11
14
|
import { homedir } from "os";
|
|
@@ -137,6 +140,24 @@ function getCacheEntry(key) {
|
|
|
137
140
|
const config = loadConfig();
|
|
138
141
|
return config.cache?.[key];
|
|
139
142
|
}
|
|
143
|
+
function getPendingBranchCreateKey(scopeKey) {
|
|
144
|
+
return getConfig("pendingBranchCreateKeys")?.[scopeKey];
|
|
145
|
+
}
|
|
146
|
+
function setPendingBranchCreateKey(scopeKey, idempotencyKey) {
|
|
147
|
+
const config = loadConfig();
|
|
148
|
+
if (!config.pendingBranchCreateKeys) {
|
|
149
|
+
config.pendingBranchCreateKeys = {};
|
|
150
|
+
}
|
|
151
|
+
config.pendingBranchCreateKeys[scopeKey] = idempotencyKey;
|
|
152
|
+
saveConfig(config);
|
|
153
|
+
}
|
|
154
|
+
function clearPendingBranchCreateKey(scopeKey) {
|
|
155
|
+
const config = loadConfig();
|
|
156
|
+
if (config.pendingBranchCreateKeys && scopeKey in config.pendingBranchCreateKeys) {
|
|
157
|
+
delete config.pendingBranchCreateKeys[scopeKey];
|
|
158
|
+
saveConfig(config);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
140
161
|
function formatIdle(lastActivityIso) {
|
|
141
162
|
if (!lastActivityIso) {
|
|
142
163
|
return "unknown";
|
|
@@ -316,11 +337,14 @@ var ApiClient = class {
|
|
|
316
337
|
});
|
|
317
338
|
return this.handleResponse(response);
|
|
318
339
|
}
|
|
319
|
-
async post(path, body) {
|
|
340
|
+
async post(path, body, extraHeaders = {}) {
|
|
320
341
|
const url = `${getApiUrl()}${path}`;
|
|
321
342
|
const response = await fetch(url, {
|
|
322
343
|
method: "POST",
|
|
323
|
-
headers:
|
|
344
|
+
headers: {
|
|
345
|
+
...this.getHeaders(),
|
|
346
|
+
...extraHeaders
|
|
347
|
+
},
|
|
324
348
|
body: JSON.stringify(body)
|
|
325
349
|
});
|
|
326
350
|
return this.handleResponse(response);
|
|
@@ -681,16 +705,24 @@ async function createAction(name, options) {
|
|
|
681
705
|
console.error(`\u2717 ${message}`);
|
|
682
706
|
process.exit(1);
|
|
683
707
|
}
|
|
708
|
+
let idempotencyScopeKey;
|
|
684
709
|
try {
|
|
685
710
|
const startTime = performance.now();
|
|
686
711
|
const connectorId = await resolveCurrentConnectorId();
|
|
712
|
+
idempotencyScopeKey = `${connectorId}:${options.service}:${name}`;
|
|
713
|
+
let idempotencyKey = getPendingBranchCreateKey(idempotencyScopeKey);
|
|
714
|
+
if (!idempotencyKey) {
|
|
715
|
+
idempotencyKey = randomUUID2();
|
|
716
|
+
setPendingBranchCreateKey(idempotencyScopeKey, idempotencyKey);
|
|
717
|
+
}
|
|
687
718
|
const createResponse = await api.post(
|
|
688
719
|
"/v1/branch/create",
|
|
689
720
|
{
|
|
690
721
|
connector_id: connectorId,
|
|
691
722
|
service_type: options.service,
|
|
692
723
|
name
|
|
693
|
-
}
|
|
724
|
+
},
|
|
725
|
+
{ "X-Idempotency-Key": idempotencyKey }
|
|
694
726
|
);
|
|
695
727
|
const warning = createResponse?.warning;
|
|
696
728
|
const response = await api.get(`/v1/cli/branches?connector_id=${connectorId}`);
|
|
@@ -746,6 +778,7 @@ async function createAction(name, options) {
|
|
|
746
778
|
cachedBranches.push(branch);
|
|
747
779
|
setCacheEntry("branches", cachedBranches);
|
|
748
780
|
setCurrentBranch(name);
|
|
781
|
+
clearPendingBranchCreateKey(idempotencyScopeKey);
|
|
749
782
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(1);
|
|
750
783
|
trackEvent("CLI: branch create succeeded", {
|
|
751
784
|
service_type: options.service,
|
|
@@ -794,6 +827,9 @@ ${url}`);
|
|
|
794
827
|
console.error("\u2717 Cannot create branch while offline");
|
|
795
828
|
process.exit(1);
|
|
796
829
|
}
|
|
830
|
+
if (idempotencyScopeKey) {
|
|
831
|
+
clearPendingBranchCreateKey(idempotencyScopeKey);
|
|
832
|
+
}
|
|
797
833
|
trackEvent("CLI: branch create failed", { reason: "api_error", output_mode: mode });
|
|
798
834
|
const message = err instanceof Error ? err.message : String(err);
|
|
799
835
|
if (mode === "json") {
|