sticky-note-cli 3.1.12 → 3.1.13
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 +31 -5
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -3045,6 +3045,10 @@ function provisionCloudBackend() {
|
|
|
3045
3045
|
if (namespaceId) {
|
|
3046
3046
|
const tomlPath = path.join(serverDir, "wrangler.toml");
|
|
3047
3047
|
let toml = fs.readFileSync(tomlPath, "utf-8");
|
|
3048
|
+
// Reset any previously-written ID back to placeholder first, then patch.
|
|
3049
|
+
// This makes re-runs idempotent even when provisionCloudBackend is called
|
|
3050
|
+
// multiple times in the same init (e.g. after auto-installing wrangler).
|
|
3051
|
+
toml = toml.replace(/id\s*=\s*"[^"]*"/, 'id = "PLACEHOLDER_KV_NAMESPACE_ID"');
|
|
3048
3052
|
toml = toml.replace("PLACEHOLDER_KV_NAMESPACE_ID", namespaceId);
|
|
3049
3053
|
fs.writeFileSync(tomlPath, toml);
|
|
3050
3054
|
print(" [OK] wrangler.toml updated with namespace ID");
|
|
@@ -3066,7 +3070,20 @@ function provisionCloudBackend() {
|
|
|
3066
3070
|
|
|
3067
3071
|
const urlMatch = deployResult.match(/(https:\/\/[^\s]+\.workers\.dev)/);
|
|
3068
3072
|
const workerUrl = urlMatch ? urlMatch[1] : null;
|
|
3069
|
-
|
|
3073
|
+
|
|
3074
|
+
// Reuse an existing API key from .env.sticky if present — prevents divergence
|
|
3075
|
+
// when init is re-run on an already-provisioned repo. Only generate a new key
|
|
3076
|
+
// if there isn't one already.
|
|
3077
|
+
const envPath = path.join(process.cwd(), ".env.sticky");
|
|
3078
|
+
let apiKey = null;
|
|
3079
|
+
try {
|
|
3080
|
+
const existing = fs.readFileSync(envPath, "utf-8");
|
|
3081
|
+
const m = existing.match(/^STICKY_API_KEY=(.+)$/m);
|
|
3082
|
+
if (m && m[1].trim()) apiKey = m[1].trim();
|
|
3083
|
+
} catch (_) { /* no existing .env.sticky */ }
|
|
3084
|
+
if (!apiKey) {
|
|
3085
|
+
apiKey = require("crypto").randomBytes(24).toString("base64url");
|
|
3086
|
+
}
|
|
3070
3087
|
|
|
3071
3088
|
if (workerUrl) {
|
|
3072
3089
|
print(` [OK] Worker deployed: ${workerUrl}`);
|
|
@@ -3074,7 +3091,7 @@ function provisionCloudBackend() {
|
|
|
3074
3091
|
print(" [OK] Worker deployed (URL not detected — check wrangler output)");
|
|
3075
3092
|
}
|
|
3076
3093
|
|
|
3077
|
-
// Step 3: Set API key
|
|
3094
|
+
// Step 3: Set API key on Worker — always sync so Worker and .env.sticky agree
|
|
3078
3095
|
print(" Step 3: Setting API key on Worker...");
|
|
3079
3096
|
let secretSet = false;
|
|
3080
3097
|
try {
|
|
@@ -3091,11 +3108,20 @@ function provisionCloudBackend() {
|
|
|
3091
3108
|
if (workerUrl) print(` Set it manually: echo '${apiKey}' | wrangler secret put STICKY_API_KEY --name ${workerName}`);
|
|
3092
3109
|
}
|
|
3093
3110
|
|
|
3094
|
-
// Write .env.sticky
|
|
3095
|
-
|
|
3096
|
-
|
|
3111
|
+
// Write .env.sticky only after the secret is confirmed set on the Worker,
|
|
3112
|
+
// so the local key always matches what the Worker expects.
|
|
3113
|
+
if (workerUrl && secretSet) {
|
|
3097
3114
|
fs.writeFileSync(envPath, `STICKY_URL=${workerUrl}\nSTICKY_API_KEY=${apiKey}\n`, "utf-8");
|
|
3098
3115
|
print(" [OK] .env.sticky written with STICKY_URL and STICKY_API_KEY");
|
|
3116
|
+
} else if (workerUrl && !secretSet) {
|
|
3117
|
+
// Secret set failed — still write .env.sticky with the key we tried,
|
|
3118
|
+
// and tell the user to set it manually so both sides match.
|
|
3119
|
+
fs.writeFileSync(envPath, `STICKY_URL=${workerUrl}\nSTICKY_API_KEY=${apiKey}\n`, "utf-8");
|
|
3120
|
+
print(" [WARN] .env.sticky written but STICKY_API_KEY was NOT set on the Worker.");
|
|
3121
|
+
print(` Sync manually: echo '${apiKey}' | wrangler secret put STICKY_API_KEY --name ${workerName}`);
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
if (workerUrl) {
|
|
3099
3125
|
|
|
3100
3126
|
// Write sticky_url to committed config so teammates get it on git pull
|
|
3101
3127
|
const configPath = path.join(process.cwd(), ".sticky-note", "sticky-note-config.json");
|