← back to Marketing Command Center

scripts/norma-auth-check.js

17 lines

#!/usr/bin/env node
// Read-only check that ig-activity's Norma auth path works (TK-12342).
// GET /api/posts/oc-status via the shared ordered-auth helper (lib/norma-auth.js).
// Exit 0 = authenticated 2xx; exit 1 = auth rejected by every source / not configured /
// non-2xx; exit 2 = Norma unreachable. Prints the winning SOURCE name only — never a secret.
const { normaBase, normaFetch } = require('../lib/norma-auth.js');
(async () => {
  try {
    const a = await normaFetch('/api/posts/oc-status', {}, 20000, { tag: 'norma-auth-check' });
    if (!a.ok) { console.error(`FAIL ${normaBase()}: ${a.error}`); process.exit(1); }
    if (!a.res.ok) { console.error(`FAIL ${normaBase()}: HTTP ${a.res.status} ${a.json.error || ''}`); process.exit(1); }
    console.log(`PASS ${normaBase()} HTTP ${a.res.status} via ${a.source} loggedIn=${!!a.json.loggedIn}`);
  } catch (e) {
    console.error(`FAIL ${normaBase()}: unreachable: ${e.message}`); process.exit(2);
  }
})();