Closer/scratchpad/d1_probe2.js

43 lines
1.9 KiB
JavaScript
Raw Normal View History

// D1 deep probe: dump FIELD NAMES + per-string enc-status/length (NEVER values).
const admin = require('firebase-admin')
const path = require('path')
const SA = process.env.SA_JSON || path.join(__dirname, '..', 'closer-app-22014-firebase-adminsdk-fbsvc-ed20bf6003.json')
const COUPLE = process.env.COUPLE_ID || 'Xal3Kw3gjSdn0niERYKJ'
admin.initializeApp({ credential: admin.credential.cert(require(SA)) })
const db = admin.firestore()
const CIPHER = /^(enc:v1:|sealed:v1:)/
const MEDIA = /^(01|AAAA|CiQ|Ei)/ // tink/base64-ish prefixes seen for media
function fieldReport(d) {
return Object.entries(d).map(([k, v]) => {
if (typeof v === 'string') {
const tag = CIPHER.test(v) ? 'enc✓' : (v.length > 40 ? `RAWSTR?(${v.length})` : `meta(${v.length})`)
return `${k}:${tag}`
}
if (Array.isArray(v)) return `${k}:[${v.length}]${v.every(x => typeof x === 'string' && CIPHER.test(x)) && v.length ? 'enc✓' : ''}`
if (v && typeof v === 'object') return `${k}:{${Object.keys(v).join(',')}}`
return `${k}:${typeof v}`
}).join(' ')
}
async function dump(ref, label, n = 2) {
try {
const s = await ref.limit(n).get()
if (s.empty) return console.log(`[${label}] empty`)
s.docs.slice(0, n).forEach(doc => console.log(`[${label}] ${doc.id}\n ${fieldReport(doc.data())}`))
} catch (e) { console.log(`[${label}] ERR ${e.code || e.message}`) }
}
(async () => {
const c = db.collection('couples').doc(COUPLE)
// messages nested under each conversation
const convs = await c.collection('conversations').limit(3).get()
for (const cv of convs.docs) {
await dump(cv.ref.collection('messages'), `conv:${cv.id}/messages`, 2)
}
for (const g of ['this_or_that','desire_sync','how_well','wheel','date_swipes','sessions']) {
await dump(c.collection(g), g, 1)
}
process.exit(0)
})().catch(e => { console.error('FATAL', e); process.exit(1) })