#!/usr/bin/env node 'use strict'; // #146 BILLING — owner-only CLI to mint / revoke / list `billing:read` API tokens. // // node scripts/mint-billing-token.js --name "Bold invoicing" # mint (prints secret ONCE) // node scripts/mint-billing-token.js --list # list billing tokens // node scripts/mint-billing-token.js --revoke # revoke one // // OWNER-ONLY BY CONSTRUCTION: this is a server-side script with NO network endpoint. The // access control IS filesystem/shell access to the host — i.e. the platform owner. It is // deliberately NOT in the workspace API-Tokens UI (that surface is workspace-scoped, self- // service; a billing token grants platform-wide billing-read and must be issued by the owner). // On the container: `docker exec screentinker node ../scripts/mint-billing-token.js --name "…"`. // // The logic lives in server/lib/billing-token.js (unit-tested); this file is a thin wrapper. const { db } = require('../server/db/database'); const { mintBillingToken, revokeBillingToken, listBillingTokens } = require('../server/lib/billing-token'); function arg(flag) { const i = process.argv.indexOf(flag); return i !== -1 ? (process.argv[i + 1] || '') : undefined; } const has = (flag) => process.argv.includes(flag); function fmtTime(t) { return t ? new Date(t * 1000).toISOString() : '—'; } function main() { if (has('--help') || has('-h')) { console.log('Usage:\n --name "