feat(audit-csv): Phase 690 audit-csv-mixin, spans, and mod digest clear
Add audit-csv-mixin gossip dedupe and partition heal; extend getAuditExportCsvExport and pushAuditExportCsvToMesh audit.csv spans; clearModDigestNotifyPrefs and auditExportCsvDuplicateAt view flag; openAuditCsv deep link field. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
Application facade: one `PearcordPlatform` class that wires identity, database, guild mesh, DMs, invites, voice, discovery, bots, and dozens of feature modules for the Pearcord desktop sidecar and companion.
|
||||
|
||||
**Phase 690 (v0.8.665):** Audit CSV mesh push & mod digest notify — `audit-csv-mixin.js`, `audit.csv` spans (`guildCsvExportCount`), CSV gossip dedupe, `_healAuditCsvExportCursorOnPartition` + `_healModDigestNotifyCursorOnPartition`, `clearModDigestNotifyPrefs`, deep link `openAuditCsv`. Bundle: `npm run test:ci-phase690`.
|
||||
|
||||
**Phase 689 (v0.8.664):** Integration health dashboard — `health-mixin.js`, `automation.health` spans (`guildHealthRowCount`), digest relay handoff gossip dedupe, `_healScheduleDashboardOnPartition` + `_healArchivePeerCursorOnPartition`, `clearDigestRelayHandoffs`, deep link `openHealth`. Bundle: `npm run test:ci-phase689`.
|
||||
|
||||
**Phase 688 (v0.8.663):** Hook delivery receipts & failure digest — `delivery-mixin.js`, receipt gossip dedupe, `_healReceiptRegistryOnPartition` + `_healFailureDigestCursorOnPartition`, `guildReceiptCount`/`bridgeKind` span metadata, `clearAutomationDeliveryReceipts`, deep link `openReceipts`. Bundle: `npm run test:ci-phase688`.
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
'use strict'
|
||||
|
||||
const auditCsvMixin = {
|
||||
_auditExportCsvGossipKeys: null,
|
||||
_auditCsvHealWatermark: null,
|
||||
_modDigestNotifyHealWatermark: null,
|
||||
|
||||
_initAuditCsvMixinState () {
|
||||
if (!this._auditExportCsvGossipKeys) {
|
||||
this._auditExportCsvGossipKeys = new Set()
|
||||
}
|
||||
},
|
||||
|
||||
_shouldGossipAuditExportCsv (slice) {
|
||||
this._initAuditCsvMixinState()
|
||||
if (!slice?.guildId || !slice?.signature) return true
|
||||
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}:${slice.filter || ''}`
|
||||
if (this._auditExportCsvGossipKeys.has(hash)) return false
|
||||
this._auditExportCsvGossipKeys.add(hash)
|
||||
if (this._auditExportCsvGossipKeys.size > 8192) {
|
||||
const first = this._auditExportCsvGossipKeys.values().next().value
|
||||
if (first) this._auditExportCsvGossipKeys.delete(first)
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
async _healAuditCsvExportCursorOnPartition (guildId) {
|
||||
const gid = guildId || this.guild?.guild?.id || null
|
||||
const span = this.log.time('audit.csv', {
|
||||
spanKind: 'audit.csv',
|
||||
guildId: gid,
|
||||
context: 'heal.export'
|
||||
})
|
||||
try {
|
||||
if (!gid || !this.deliveryReceipts) {
|
||||
span.end({ relisted: 0, skipped: true, guildCsvExportCount: 0 })
|
||||
return { relisted: 0, skipped: true }
|
||||
}
|
||||
await this._initDeliveryReceipts(gid)
|
||||
const rows = await this.deliveryReceipts.listAuditExportCsvExports(64)
|
||||
let relisted = 0
|
||||
for (const row of rows) {
|
||||
if (this._shouldGossipAuditExportCsv(row)) relisted++
|
||||
}
|
||||
const watermark = Date.now()
|
||||
this._auditCsvHealWatermark = watermark
|
||||
span.end({
|
||||
relisted,
|
||||
watermark,
|
||||
guildCsvExportCount: rows.length,
|
||||
bridgeKind: 'audit.csv'
|
||||
})
|
||||
return { relisted, watermark, guildCsvExportCount: rows.length }
|
||||
} catch (err) {
|
||||
this.log.error('audit.csv error', {
|
||||
guildId: gid,
|
||||
context: 'heal.export',
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
return { relisted: 0, error: err?.message || String(err) }
|
||||
}
|
||||
},
|
||||
|
||||
async _healModDigestNotifyCursorOnPartition (guildId) {
|
||||
const gid = guildId || this.guild?.guild?.id || null
|
||||
const span = this.log.time('audit.csv', {
|
||||
spanKind: 'audit.csv',
|
||||
guildId: gid,
|
||||
context: 'heal.modDigest'
|
||||
})
|
||||
try {
|
||||
if (!gid) {
|
||||
span.end({ relisted: 0, skipped: true, guildCsvExportCount: 0 })
|
||||
return { relisted: 0, skipped: true }
|
||||
}
|
||||
await this._initDeliveryReceipts(gid)
|
||||
const prefs = await this.deliveryReceipts.getHookFailureDigestNotifyPrefs()
|
||||
const watermark = Date.now()
|
||||
this._modDigestNotifyHealWatermark = watermark
|
||||
span.end({
|
||||
relisted: prefs.modDigestGroupDmEnabled ? 1 : 0,
|
||||
watermark,
|
||||
guildCsvExportCount: 0,
|
||||
modDigestEnabled: !!prefs.modDigestGroupDmEnabled,
|
||||
bridgeKind: 'audit.csv'
|
||||
})
|
||||
return {
|
||||
relisted: prefs.modDigestGroupDmEnabled ? 1 : 0,
|
||||
watermark,
|
||||
modDigestEnabled: !!prefs.modDigestGroupDmEnabled
|
||||
}
|
||||
} catch (err) {
|
||||
this.log.error('audit.csv error', {
|
||||
guildId: gid,
|
||||
context: 'heal.modDigest',
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
return { relisted: 0, error: err?.message || String(err) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { auditCsvMixin }
|
||||
@@ -1626,6 +1626,12 @@ class PearcordPlatform extends EventEmitter {
|
||||
const archivePeerHeal = await this._healArchivePeerCursorOnPartition(gid).catch(() => ({
|
||||
relisted: 0
|
||||
}))
|
||||
const auditCsvExportHeal = await this._healAuditCsvExportCursorOnPartition(gid).catch(() => ({
|
||||
relisted: 0
|
||||
}))
|
||||
const modDigestNotifyHeal = await this._healModDigestNotifyCursorOnPartition(gid).catch(() => ({
|
||||
relisted: 0
|
||||
}))
|
||||
return {
|
||||
voiceApplied,
|
||||
emojiSlots,
|
||||
@@ -1670,7 +1676,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
receiptRegistryHeal,
|
||||
failureDigestHeal,
|
||||
scheduleDashboardHeal,
|
||||
archivePeerHeal
|
||||
archivePeerHeal,
|
||||
auditCsvExportHeal,
|
||||
modDigestNotifyHeal
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9848,10 +9856,15 @@ class PearcordPlatform extends EventEmitter {
|
||||
}
|
||||
if (payload.auditExportCsvExport) {
|
||||
await this._initDeliveryReceipts(payload.guildId)
|
||||
await this.deliveryReceipts.ingestAuditExportCsvSlice(
|
||||
const slice = payload.auditExportCsvExport
|
||||
this._shouldGossipAuditExportCsv(slice)
|
||||
const ingested = await this.deliveryReceipts.ingestAuditExportCsvSlice(
|
||||
payload.guildId,
|
||||
payload.auditExportCsvExport
|
||||
slice
|
||||
)
|
||||
if (ingested?.duplicate) {
|
||||
this._auditExportCsvDuplicateAt = ingested.exportedAt || slice.exportedAt || null
|
||||
}
|
||||
}
|
||||
if (payload.archiveHealthPrefs) {
|
||||
await this._initDeliveryReceipts(payload.guildId)
|
||||
@@ -11709,15 +11722,56 @@ class PearcordPlatform extends EventEmitter {
|
||||
}
|
||||
|
||||
async getAuditExportCsvExport () {
|
||||
if (!this.guild?.guild) return null
|
||||
await this._initDeliveryReceipts(this.guild.guild.id)
|
||||
const row = await this.deliveryReceipts.getAuditExportCsvExport()
|
||||
if (!row?.signature) return row
|
||||
const verified = verifyAuditExportCsv(row.csvBody, row.signature, {
|
||||
guildId: this.guild.guild.id,
|
||||
relaySecret: this.guild.guild.id
|
||||
const gid = this.guild?.guild?.id || null
|
||||
const span = this.log.time('audit.csv', {
|
||||
spanKind: 'audit.csv',
|
||||
guildId: gid,
|
||||
context: 'read'
|
||||
})
|
||||
return { ...row, signatureValid: verified.ok }
|
||||
try {
|
||||
if (!this.guild?.guild) {
|
||||
span.end({ guildCsvExportCount: 0, skipped: true })
|
||||
return null
|
||||
}
|
||||
await this._initDeliveryReceipts(this.guild.guild.id)
|
||||
const row = await this.deliveryReceipts.getAuditExportCsvExport()
|
||||
if (!row?.signature) {
|
||||
span.end({ guildCsvExportCount: row ? 1 : 0, hasSignature: false, bridgeKind: 'audit.csv' })
|
||||
return row
|
||||
}
|
||||
const verified = verifyAuditExportCsv(row.csvBody, row.signature, {
|
||||
guildId: this.guild.guild.id,
|
||||
relaySecret: this.guild.guild.id
|
||||
})
|
||||
const out = { ...row, signatureValid: verified.ok }
|
||||
span.end({
|
||||
guildCsvExportCount: 1,
|
||||
hasSignature: true,
|
||||
signatureValid: verified.ok,
|
||||
bridgeKind: 'audit.csv'
|
||||
})
|
||||
return out
|
||||
} catch (err) {
|
||||
this.log.error('audit.csv error', {
|
||||
guildId: gid,
|
||||
context: 'read',
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async clearModDigestNotifyPrefs () {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const roles = await this._memberRoles()
|
||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||
throw new Error('no permission to manage mod digest notify')
|
||||
}
|
||||
await this._initDeliveryReceipts(this.guild.guild.id)
|
||||
const removed = await this.deliveryReceipts.clearModDigestNotifyPrefs()
|
||||
this.emit('mod-digest-notify-cleared', { removed })
|
||||
return { removed }
|
||||
}
|
||||
|
||||
async _onAuditExportSnapshotGossip (payload) {
|
||||
@@ -17224,7 +17278,8 @@ class PearcordPlatform extends EventEmitter {
|
||||
openAutomation: !!parsed.openAutomation,
|
||||
openWorkers: !!parsed.openWorkers,
|
||||
openReceipts: !!parsed.openReceipts,
|
||||
openHealth: !!parsed.openHealth
|
||||
openHealth: !!parsed.openHealth,
|
||||
openAuditCsv: !!parsed.openAuditCsv
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20607,13 +20662,20 @@ class PearcordPlatform extends EventEmitter {
|
||||
}
|
||||
|
||||
async pushAuditExportCsvToMesh (opts = {}) {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const roles = await this._memberRoles()
|
||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||
throw new Error('no permission to sync audit export CSV')
|
||||
}
|
||||
const filter = await this._resolveAuditExportFilter(opts.filter)
|
||||
const exported = await this.exportAuditLog({
|
||||
const gid = this.guild?.guild?.id || null
|
||||
const span = this.log.time('audit.csv', {
|
||||
spanKind: 'audit.csv',
|
||||
guildId: gid,
|
||||
context: 'mesh.push'
|
||||
})
|
||||
try {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const roles = await this._memberRoles()
|
||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||
throw new Error('no permission to sync audit export CSV')
|
||||
}
|
||||
const filter = await this._resolveAuditExportFilter(opts.filter)
|
||||
const exported = await this.exportAuditLog({
|
||||
format: 'csv',
|
||||
filter,
|
||||
limit: opts.limit || 200,
|
||||
@@ -20639,17 +20701,36 @@ class PearcordPlatform extends EventEmitter {
|
||||
lastCsvMeshPushAt: exported.exportedAt || Date.now()
|
||||
})
|
||||
this.emit('audit-export-csv-sync', payload)
|
||||
span.end({
|
||||
guildCsvExportCount: 1,
|
||||
meshPushed: true,
|
||||
filter,
|
||||
bridgeKind: 'audit.csv'
|
||||
})
|
||||
return exported
|
||||
} catch (err) {
|
||||
this.log.error('audit.csv error', {
|
||||
guildId: gid,
|
||||
context: 'mesh.push',
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async _onAuditExportCsvGossip (payload) {
|
||||
if (!payload?.guildId || !payload?.csvBody || !payload?.signature) return null
|
||||
if (this.guild?.guild?.id !== payload.guildId) return null
|
||||
await this._initDeliveryReceipts(payload.guildId)
|
||||
this._shouldGossipAuditExportCsv(payload)
|
||||
const row = await this.deliveryReceipts.ingestAuditExportCsvSlice(
|
||||
payload.guildId,
|
||||
payload
|
||||
)
|
||||
if (row?.duplicate) {
|
||||
this._auditExportCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
|
||||
}
|
||||
if (row) this.emit('audit-export-csv-sync', payload)
|
||||
return row
|
||||
}
|
||||
@@ -25495,6 +25576,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
let automationDigestExportSnapshots = []
|
||||
let auditExportArchives = []
|
||||
let auditExportCsvMeta = null
|
||||
let auditExportCsvRows = []
|
||||
let automationScheduleDashboard = null
|
||||
let automationHealthDashboard = null
|
||||
let automationDigestNotifyPrefs = null
|
||||
@@ -25511,6 +25593,15 @@ class PearcordPlatform extends EventEmitter {
|
||||
automationDigestExportSnapshots = await this.listAutomationDigestExportSnapshots(3)
|
||||
auditExportArchives = await this.listAuditExportArchives(6)
|
||||
auditExportCsvMeta = await this.getAuditExportCsvExport().catch(() => null)
|
||||
const csvHistory = await this.deliveryReceipts.listAuditExportCsvExports(32)
|
||||
auditExportCsvRows = csvHistory.map((row) => {
|
||||
if (!row?.signature || !guild?.id) return row
|
||||
const verified = verifyAuditExportCsv(row.csvBody, row.signature, {
|
||||
guildId: guild.id,
|
||||
relaySecret: guild.id
|
||||
})
|
||||
return { ...row, signatureValid: verified.ok }
|
||||
})
|
||||
automationHealthDashboard = await this.getAutomationHealthDashboard()
|
||||
automationScheduleDashboard = automationHealthDashboard
|
||||
automationDigestNotifyPrefs = await this.getAutomationDigestNotifyPrefs()
|
||||
@@ -25808,6 +25899,8 @@ class PearcordPlatform extends EventEmitter {
|
||||
this._deliveryReceiptDuplicateId = null
|
||||
const digestRelayHandoffDuplicateAt = this._digestRelayHandoffDuplicateAt || null
|
||||
this._digestRelayHandoffDuplicateAt = null
|
||||
const auditExportCsvDuplicateAt = this._auditExportCsvDuplicateAt || null
|
||||
this._auditExportCsvDuplicateAt = null
|
||||
return {
|
||||
onboarded: this.onboarded,
|
||||
sessionReady: this._sessionReady,
|
||||
@@ -25937,6 +26030,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
deliveryReceiptRows,
|
||||
deliveryReceiptDuplicateId,
|
||||
digestRelayHandoffDuplicateAt,
|
||||
auditExportCsvDuplicateAt,
|
||||
automationDeliveryMetrics,
|
||||
automationReceiptRetention,
|
||||
hookFailurePrefs,
|
||||
@@ -25948,6 +26042,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
automationDigestExportSnapshots,
|
||||
auditExportArchives,
|
||||
auditExportCsvMeta,
|
||||
auditExportCsvRows,
|
||||
automationScheduleDashboard,
|
||||
automationHealthDashboard,
|
||||
automationDigestNotifyPrefs,
|
||||
@@ -26548,6 +26643,7 @@ const { automationMixin } = require('./automation-mixin')
|
||||
const { workersMixin } = require('./workers-mixin')
|
||||
const { deliveryMixin } = require('./delivery-mixin')
|
||||
const { healthMixin } = require('./health-mixin')
|
||||
const { auditCsvMixin } = require('./audit-csv-mixin')
|
||||
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
|
||||
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
|
||||
Object.assign(PearcordPlatform.prototype, userSettingsMixin)
|
||||
@@ -26564,3 +26660,4 @@ Object.assign(PearcordPlatform.prototype, automationMixin)
|
||||
Object.assign(PearcordPlatform.prototype, workersMixin)
|
||||
Object.assign(PearcordPlatform.prototype, deliveryMixin)
|
||||
Object.assign(PearcordPlatform.prototype, healthMixin)
|
||||
Object.assign(PearcordPlatform.prototype, auditCsvMixin)
|
||||
|
||||
Reference in New Issue
Block a user