waitad 0.0.5 → 0.0.7

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/cli.js CHANGED
@@ -15551,19 +15551,33 @@ printf '{"event_id":"%s","user_id":"%s","campaign_id":"%s","ts":"%s","agent":"cl
15551
15551
 
15552
15552
  exit 0
15553
15553
  `;
15554
- function makeSyncSh(apiBase, installKey, installKeyId) {
15554
+ function makeSyncSh() {
15555
15555
  return `#!/usr/bin/env bash
15556
15556
  # waitad sync \u2014 refreshes ad cache and flushes impression queue.
15557
15557
  # Runs every 5 minutes via launchd (macOS) or cron (Linux).
15558
15558
  set -uo pipefail
15559
15559
 
15560
- API_BASE="${apiBase}"
15561
- INSTALL_KEY="${installKey}"
15562
- INSTALL_KEY_ID="${installKeyId}"
15560
+ CONFIG="$HOME/.waitad/config.json"
15563
15561
  CACHE="$HOME/.waitad/cache.json"
15564
15562
  QUEUE="$HOME/.waitad/queue.ndjson"
15565
15563
  LOG="$HOME/.waitad/sync.log"
15566
15564
 
15565
+ # Read credentials from config at runtime so key rotations take effect immediately
15566
+ if ! command -v jq &>/dev/null; then
15567
+ printf '[%s] jq not found \u2014 cannot run sync\\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$LOG"
15568
+ exit 1
15569
+ fi
15570
+ [ -f "$CONFIG" ] || { printf '[%s] config not found\\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$LOG"; exit 1; }
15571
+
15572
+ API_BASE=$(jq -r '.api_base // "https://waitad.vercel.app"' "$CONFIG")
15573
+ INSTALL_KEY=$(jq -r '.install_key // empty' "$CONFIG")
15574
+ INSTALL_KEY_ID=$(jq -r '.install_key_id // empty' "$CONFIG")
15575
+
15576
+ if [ -z "$INSTALL_KEY" ] || [ -z "$INSTALL_KEY_ID" ]; then
15577
+ printf '[%s] Missing credentials in config \u2014 run waitad login\\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$LOG"
15578
+ exit 1
15579
+ fi
15580
+
15567
15581
  log() { printf '[%s] %s\\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*" >> "$LOG"; }
15568
15582
 
15569
15583
  # \u2500\u2500 1. Refresh ad cache \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
@@ -15618,18 +15632,18 @@ PAYLOAD=$(jq -n \\
15618
15632
  --argjson events "$EVENTS" \\
15619
15633
  '{"events": $events, "signature": $sig, "install_key_id": $kid}')
15620
15634
 
15621
- RESULT=$(curl -sf --max-time 15 \\
15635
+ RESULT=$(curl -s --max-time 15 \\
15622
15636
  -X POST \\
15623
15637
  -H "Content-Type: application/json" \\
15624
15638
  -d "$PAYLOAD" \\
15625
15639
  "$API_BASE/api/events/impression" 2>>"$LOG" || true)
15626
15640
 
15627
- if [ -n "$RESULT" ]; then
15641
+ if printf '%s' "$RESULT" | grep -q '"ok":true'; then
15628
15642
  EVENT_COUNT=$(printf '%s' "$EVENTS" | jq 'length')
15629
15643
  log "Flushed $EVENT_COUNT events: $RESULT"
15630
15644
  rm -f "$FLUSH"
15631
15645
  else
15632
- log "Flush failed \u2014 restoring queue"
15646
+ log "Flush failed: $RESULT"
15633
15647
  cat "$FLUSH" >> "$QUEUE"
15634
15648
  rm -f "$FLUSH"
15635
15649
  fi
@@ -15662,7 +15676,7 @@ var installCommand = new import_commander2.Command("install").description("Wire
15662
15676
  console.warn(" Could not reach API \u2014 will retry on first sync.");
15663
15677
  }
15664
15678
  import_fs3.default.writeFileSync(STATUSLINE_SCRIPT, STATUSLINE_SH, { mode: 493 });
15665
- import_fs3.default.writeFileSync(SYNC_SCRIPT, makeSyncSh(cfg.api_base, cfg.install_key, cfg.install_key_id), {
15679
+ import_fs3.default.writeFileSync(SYNC_SCRIPT, makeSyncSh(), {
15666
15680
  mode: 493
15667
15681
  });
15668
15682
  console.log(`\u2713 Scripts written to ~/.waitad/`);
@@ -15824,7 +15838,7 @@ Queue: ${lines} pending impression(s)`);
15824
15838
  });
15825
15839
 
15826
15840
  // package.json
15827
- var version2 = "0.0.4";
15841
+ var version2 = "0.0.6";
15828
15842
 
15829
15843
  // src/index.ts
15830
15844
  var program = new import_commander5.Command().name("waitad").version(version2).description("Status-line ad marketplace for CLI coding agents");