← back to Marketing Command Center

drafts/glitter-sequin-exclusive/kamatera-create.sh

40 lines

#!/usr/bin/env bash
# Glitter & Sequin — create the REAL Constant Contact draft on Kamatera.
# Robust, single-run: verifies payload + auth, POSTs to the MCC, and if the MCC
# is in mock mode it discovers Connie's own create routes so we can finish.
# READ + DRAFT only. Does NOT send/schedule anything.
set +e
PAYLOAD=/tmp/gs-draft.json
PASS="${CC_PASS:-DWSecure2024!}"        # override: CC_PASS=... bash kamatera-create.sh
MCC=http://127.0.0.1:9661
CONNIE=http://127.0.0.1:9820

line(){ printf '\n== %s ==\n' "$1"; }

line "payload"
if [ -s "$PAYLOAD" ]; then
  echo "bytes: $(wc -c <"$PAYLOAD")"
  head -c 180 "$PAYLOAD"; echo " ..."
else
  echo "MISSING or EMPTY: $PAYLOAD  (re-scp the payload before continuing)"
fi

line "auth check (pass=${PASS:0:3}***)"
echo "MCC    /api/constant-contact/campaigns -> $(curl -s -o /dev/null -w '%{http_code}' --max-time 6 -u admin:"$PASS" "$MCC/api/constant-contact/campaigns")"
echo "Connie /api/campaigns                  -> $(curl -s -o /dev/null -w '%{http_code}' --max-time 6 -u admin:"$PASS" "$CONNIE/api/campaigns")"

line "create draft via MCC (POST /api/constant-contact/draft)"
curl -s -w '\nHTTP:%{http_code}\n' --max-time 20 -u admin:"$PASS" \
  -H 'Content-Type: application/json' -X POST \
  "$MCC/api/constant-contact/draft" --data @"$PAYLOAD"

line "Connie cc-agent location + create routes (for direct-post fallback)"
CWD=$(pm2 jlist 2>/dev/null | node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{try{const a=JSON.parse(d);const p=a.find(x=>/connie|cc-?agent/i.test((x.name||"")+" "+((x.pm2_env||{}).pm_cwd||"")));process.stdout.write(p?((p.pm2_env||{}).pm_cwd||""):"")}catch(e){}})' 2>/dev/null)
echo "connie cwd: ${CWD:-<not found via pm2>}"
if [ -n "$CWD" ]; then
  grep -rhoE "(app|router)\.(get|post|put)\(['\"][^'\"]+" "$CWD" --include=*.js 2>/dev/null \
    | sed -E "s/.*\((['\"])//" \
    | grep -iE 'camp|draft|generate|email|create|product' | sort -u | head -30
fi
line "done (nothing sent)"