const i = require("blind-pairing-core"),
{ InvitationSchema: t } = require("@holepunchto/keet-core-schemas"),
{
AddInvitationOperationV1: e,
AddInvitationOperationV2: n,
RemoveInvitationOperation: a,
} = t.Operations
function s(i, t) {
return t & i
}
module.exports = class {
static Operations = new Set([e.TYPE, n.TYPE, a.TYPE])
constructor(i) {
;((this.view = i), (this.members = null), (this.invitations = null))
}
initialize() {
;((this.members = this.view.members), (this.invitations = this.view.collections.invitations))
}
async _applyAddInvitationOperation(i, { id: t }) {
const [e, n] = await Promise.all([
this.members.getMemberForDeviceKey(t.key),
this.members.isDeviceMuted(t.key),
])
if (n || !e) return
const a = i.value,
o = s(e.capabilities, a.capabilities)
await this.invitations.update(a.id, { ...a, capabilities: o }, { upsert: !0 })
}
async _applyRemoveInvitationOperation(i, t) {}
async getInvitation(i) {
const t = await this.invitations.get(i)
return t?.value
}
updateInvitation(i, t) {
return this.invitations.update(i, t, { upsert: !0 })
}
autobaseApply(i, t) {
switch (i.type) {
case e.TYPE:
case n.TYPE:
return this._applyAddInvitationOperation(i, t)
case a.TYPE:
return this._applyRemoveInvitationOperation(i, t)
}
}
static verifyReceipt(t, e, { checkExpiration: n = !0 } = {}) {
return (
!(!t || !e) &&
!(n && t.expiration && t.expiration < Date.now()) &&
!(!t.reusable && t.uses >= 1) &&
i.verifyReceipt(e, t.publicKey)
)
}
}