sticky-note-cli 3.1.12 → 3.1.14
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/bin/cli.js +38 -5
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -847,6 +847,9 @@ async function cmdInit() {
|
|
|
847
847
|
configTemplate.inject_token_budget = injectTokenBudgetResolved;
|
|
848
848
|
configTemplate.hook_version = VERSION;
|
|
849
849
|
configTemplate.min_version = VERSION;
|
|
850
|
+
// When cloud is configured, default auto_push to true so threads reach
|
|
851
|
+
// GitHub even when Cloudflare KV hits its daily write limit.
|
|
852
|
+
if (cloudProvisionedUrl || configStickyUrl) configTemplate.auto_push = true;
|
|
850
853
|
fs.writeFileSync(configDest, JSON.stringify(configTemplate, null, 2) + "\n");
|
|
851
854
|
} else {
|
|
852
855
|
// Update existing config with new settings
|
|
@@ -859,6 +862,10 @@ async function cmdInit() {
|
|
|
859
862
|
existing.hook_version = VERSION;
|
|
860
863
|
existing.min_version = bumpMinVersion(existing.min_version, VERSION);
|
|
861
864
|
if (cloudProvisionedUrl) existing.sticky_url = cloudProvisionedUrl;
|
|
865
|
+
// Enable auto_push when cloud is configured (if not already explicitly set)
|
|
866
|
+
if ((cloudProvisionedUrl || configStickyUrl) && existing.auto_push === false) {
|
|
867
|
+
existing.auto_push = true;
|
|
868
|
+
}
|
|
862
869
|
fs.writeFileSync(configDest, JSON.stringify(existing, null, 2) + "\n");
|
|
863
870
|
}
|
|
864
871
|
print(" [OK] .sticky-note/sticky-note-config.json");
|
|
@@ -3045,6 +3052,10 @@ function provisionCloudBackend() {
|
|
|
3045
3052
|
if (namespaceId) {
|
|
3046
3053
|
const tomlPath = path.join(serverDir, "wrangler.toml");
|
|
3047
3054
|
let toml = fs.readFileSync(tomlPath, "utf-8");
|
|
3055
|
+
// Reset any previously-written ID back to placeholder first, then patch.
|
|
3056
|
+
// This makes re-runs idempotent even when provisionCloudBackend is called
|
|
3057
|
+
// multiple times in the same init (e.g. after auto-installing wrangler).
|
|
3058
|
+
toml = toml.replace(/id\s*=\s*"[^"]*"/, 'id = "PLACEHOLDER_KV_NAMESPACE_ID"');
|
|
3048
3059
|
toml = toml.replace("PLACEHOLDER_KV_NAMESPACE_ID", namespaceId);
|
|
3049
3060
|
fs.writeFileSync(tomlPath, toml);
|
|
3050
3061
|
print(" [OK] wrangler.toml updated with namespace ID");
|
|
@@ -3066,7 +3077,20 @@ function provisionCloudBackend() {
|
|
|
3066
3077
|
|
|
3067
3078
|
const urlMatch = deployResult.match(/(https:\/\/[^\s]+\.workers\.dev)/);
|
|
3068
3079
|
const workerUrl = urlMatch ? urlMatch[1] : null;
|
|
3069
|
-
|
|
3080
|
+
|
|
3081
|
+
// Reuse an existing API key from .env.sticky if present — prevents divergence
|
|
3082
|
+
// when init is re-run on an already-provisioned repo. Only generate a new key
|
|
3083
|
+
// if there isn't one already.
|
|
3084
|
+
const envPath = path.join(process.cwd(), ".env.sticky");
|
|
3085
|
+
let apiKey = null;
|
|
3086
|
+
try {
|
|
3087
|
+
const existing = fs.readFileSync(envPath, "utf-8");
|
|
3088
|
+
const m = existing.match(/^STICKY_API_KEY=(.+)$/m);
|
|
3089
|
+
if (m && m[1].trim()) apiKey = m[1].trim();
|
|
3090
|
+
} catch (_) { /* no existing .env.sticky */ }
|
|
3091
|
+
if (!apiKey) {
|
|
3092
|
+
apiKey = require("crypto").randomBytes(24).toString("base64url");
|
|
3093
|
+
}
|
|
3070
3094
|
|
|
3071
3095
|
if (workerUrl) {
|
|
3072
3096
|
print(` [OK] Worker deployed: ${workerUrl}`);
|
|
@@ -3074,7 +3098,7 @@ function provisionCloudBackend() {
|
|
|
3074
3098
|
print(" [OK] Worker deployed (URL not detected — check wrangler output)");
|
|
3075
3099
|
}
|
|
3076
3100
|
|
|
3077
|
-
// Step 3: Set API key
|
|
3101
|
+
// Step 3: Set API key on Worker — always sync so Worker and .env.sticky agree
|
|
3078
3102
|
print(" Step 3: Setting API key on Worker...");
|
|
3079
3103
|
let secretSet = false;
|
|
3080
3104
|
try {
|
|
@@ -3091,11 +3115,20 @@ function provisionCloudBackend() {
|
|
|
3091
3115
|
if (workerUrl) print(` Set it manually: echo '${apiKey}' | wrangler secret put STICKY_API_KEY --name ${workerName}`);
|
|
3092
3116
|
}
|
|
3093
3117
|
|
|
3094
|
-
// Write .env.sticky
|
|
3095
|
-
|
|
3096
|
-
|
|
3118
|
+
// Write .env.sticky only after the secret is confirmed set on the Worker,
|
|
3119
|
+
// so the local key always matches what the Worker expects.
|
|
3120
|
+
if (workerUrl && secretSet) {
|
|
3097
3121
|
fs.writeFileSync(envPath, `STICKY_URL=${workerUrl}\nSTICKY_API_KEY=${apiKey}\n`, "utf-8");
|
|
3098
3122
|
print(" [OK] .env.sticky written with STICKY_URL and STICKY_API_KEY");
|
|
3123
|
+
} else if (workerUrl && !secretSet) {
|
|
3124
|
+
// Secret set failed — still write .env.sticky with the key we tried,
|
|
3125
|
+
// and tell the user to set it manually so both sides match.
|
|
3126
|
+
fs.writeFileSync(envPath, `STICKY_URL=${workerUrl}\nSTICKY_API_KEY=${apiKey}\n`, "utf-8");
|
|
3127
|
+
print(" [WARN] .env.sticky written but STICKY_API_KEY was NOT set on the Worker.");
|
|
3128
|
+
print(` Sync manually: echo '${apiKey}' | wrangler secret put STICKY_API_KEY --name ${workerName}`);
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
if (workerUrl) {
|
|
3099
3132
|
|
|
3100
3133
|
// Write sticky_url to committed config so teammates get it on git pull
|
|
3101
3134
|
const configPath = path.join(process.cwd(), ".sticky-note", "sticky-note-config.json");
|