CompanyModule · library/organization/src/organizations.ts:107

OrgCacheRepo

component

No JSDoc comment in source yet.

API

@Component()
export class OrgCacheRepo implements OrgCache {
  @Use() private readonly db!: Db;
  deskSessions(projectId: string, orgId: string): OrgSessionRow[];
  syncDeskSessions(projectId: string, orgId: string, rows: Array<{ sessionId: string; agentId: string; current: boolean }>): void;
  ticketSessions(projectId: string, orgId: string): OrgTicketSessionRow[];
  syncTicketSessions(projectId: string, orgId: string, rows: Array<{ ticketId: string; sessionId: string; agentId: string }>): void;
  addTicketSession(projectId: string, orgId: string, ticketId: string, sessionId: string, agentId: string): void;
  ownerOfSession(sessionId: string): OrgSessionOwner | null;
  orgIdsOfProject(projectId: string): Map<string, string>;
  setTriggerHop(sessionId: string, hop: number): void;
  findCalendar(projectId: string, orgId: string, agentId: string, name: string): OrgCalendarStateRow | null;
  listCalendar(projectId: string, orgId: string): OrgCalendarStateRow[];
  registerCalendar(args: {
    projectId: string;
    orgId: string;
    agentId: string;
    name: string;
    startAtMs: number;
    defHash: string;
  }): { row: OrgCalendarStateRow; fresh: boolean };
  markCalendarSlot(projectId: string, orgId: string, agentId: string, name: string, slotMs: number | null): void;
  markCalendarFired(projectId: string, orgId: string, agentId: string, name: string, firedAt: string, oneShot: boolean): void;
  markCalendarMissed(projectId: string, orgId: string, agentId: string, name: string): void;
  markCalendarOutcome(projectId: string, orgId: string, agentId: string, name: string, outcome: OrgCalendarOutcome): void;
  deleteMissingCalendar(projectId: string, orgId: string, present: Array<{ agentId: string; name: string }>): void;
  deleteCalendar(projectId: string, orgId: string, agentId: string, name: string): void;
  findTicketState(projectId: string, orgId: string, ticketId: string): OrgTicketStateRow | null;
  upsertTicketState(row: OrgTicketStateRow): void;
  deleteMissingTicketState(projectId: string, orgId: string, presentIds: string[]): void;
  channelOffset(projectId: string, orgId: string, channelId: string, date: string): number;
  setChannelOffset(projectId: string, orgId: string, channelId: string, date: string, offset: number): void;
  readCursor(projectId: string, orgId: string, channelId: string, userId: string): string | null;
  setReadCursor(projectId: string, orgId: string, channelId: string, userId: string, lastReadId: string): void;
  budgetState(projectId: string, orgId: string, agentId: string, period: string): OrgBudgetStateRow | null;
  listBudgetStates(projectId: string, orgId: string, period: string): OrgBudgetStateRow[];
  markBudget(projectId: string, orgId: string, agentId: string, period: string, patch: { warnedAt?: string | null; pausedAt?: string | null }): void;
  queueDeskNotice(row: Omit<OrgDeskNoticeRow, "seq">): void;
  takeDeskNotices(projectId: string, orgId: string, agentId: string): OrgDeskNoticeRow[];
  deleteDeskNotices(projectId: string, orgId: string, agentId: string): void;
  deleteOrg(projectId: string, orgId: string): void;
  deleteProject(projectId: string): void;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (1)
db: Db

Methods (32)

deskSessions

deskSessions(projectId: string, orgId: string): OrgSessionRow[]
@paramprojectIdstring
@paramorgIdstring
@returnsOrgSessionRow[]

syncDeskSessions

syncDeskSessions(projectId: string, orgId: string, rows: Array<{ sessionId: string; agentId: string; current: boolean }>): void

Makes the table match the ledger: unknown rows are added, rows for sessions no longer in it removed, hops kept.

@paramprojectIdstring
@paramorgIdstring
@paramrowsArray<{ sessionId: string; agentId: string; current: boolean }>
@returnsvoid

ticketSessions

ticketSessions(projectId: string, orgId: string): OrgTicketSessionRow[]
@paramprojectIdstring
@paramorgIdstring
@returnsOrgTicketSessionRow[]

syncTicketSessions

syncTicketSessions(projectId: string, orgId: string, rows: Array<{ ticketId: string; sessionId: string; agentId: string }>): void
@paramprojectIdstring
@paramorgIdstring
@paramrowsArray<{ ticketId: string; sessionId: string; agentId: string }>
@returnsvoid

addTicketSession

addTicketSession(projectId: string, orgId: string, ticketId: string, sessionId: string, agentId: string): void
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramsessionIdstring
@paramagentIdstring
@returnsvoid

ownerOfSession

ownerOfSession(sessionId: string): OrgSessionOwner | null

Which organization a session belongs to (desk first, then ticket), or null.

@paramsessionIdstring
@returnsOrgSessionOwner | null

orgIdsOfProject

orgIdsOfProject(projectId: string): Map<string, string>

Every organization-owned session of a Project, session id -> organization id, desk and ticket sessions together. Two queries for the whole Project, so a session list can stamp SessionInfo.orgId on its rows without a lookup per row; ownerOfSession stays the point query for the single-session GET. Desk rows win a collision, as they do there.

@paramprojectIdstring
@returnsMap<string, string>

setTriggerHop

setTriggerHop(sessionId: string, hop: number): void

Records the hop of the trigger just delivered to a session (both tables, whichever holds it).

@paramsessionIdstring
@paramhopnumber
@returnsvoid

findCalendar

findCalendar(projectId: string, orgId: string, agentId: string, name: string): OrgCalendarStateRow | null
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@returnsOrgCalendarStateRow | null

listCalendar

listCalendar(projectId: string, orgId: string): OrgCalendarStateRow[]
@paramprojectIdstring
@paramorgIdstring
@returnsOrgCalendarStateRow[]

registerCalendar

registerCalendar(args: { projectId: string; orgId: string; agentId: string; name: string; startAtMs: number; defHash: string; }): { row: OrgCalendarStateRow; fresh: boolean }

Same identity rule as schedules: a start_at change resets the run state, a content change only clears the invalid mark.

@paramargs{ projectId: string; orgId: string; agentId: string; name: string; startAtMs: number; defHash: string; }
@returns{ row: OrgCalendarStateRow; fresh: boolean }

markCalendarSlot

markCalendarSlot(projectId: string, orgId: string, agentId: string, name: string, slotMs: number | null): void
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@paramslotMsnumber | null
@returnsvoid

markCalendarFired

markCalendarFired(projectId: string, orgId: string, agentId: string, name: string, firedAt: string, oneShot: boolean): void
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@paramfiredAtstring
@paramoneShotboolean
@returnsvoid

markCalendarMissed

markCalendarMissed(projectId: string, orgId: string, agentId: string, name: string): void
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@returnsvoid

markCalendarOutcome

markCalendarOutcome(projectId: string, orgId: string, agentId: string, name: string, outcome: OrgCalendarOutcome): void
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@paramoutcomeOrgCalendarOutcome
@returnsvoid

deleteMissingCalendar

deleteMissingCalendar(projectId: string, orgId: string, present: Array<{ agentId: string; name: string }>): void

Reconciliation cleanup: rows whose file is gone.

@paramprojectIdstring
@paramorgIdstring
@parampresentArray<{ agentId: string; name: string }>
@returnsvoid

deleteCalendar

deleteCalendar(projectId: string, orgId: string, agentId: string, name: string): void
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@returnsvoid

findTicketState

findTicketState(projectId: string, orgId: string, ticketId: string): OrgTicketStateRow | null
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@returnsOrgTicketStateRow | null

upsertTicketState

upsertTicketState(row: OrgTicketStateRow): void
@paramrowOrgTicketStateRow
@returnsvoid

deleteMissingTicketState

deleteMissingTicketState(projectId: string, orgId: string, presentIds: string[]): void
@paramprojectIdstring
@paramorgIdstring
@parampresentIdsstring[]
@returnsvoid

channelOffset

channelOffset(projectId: string, orgId: string, channelId: string, date: string): number
@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramdatestring
@returnsnumber

setChannelOffset

setChannelOffset(projectId: string, orgId: string, channelId: string, date: string, offset: number): void
@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramdatestring
@paramoffsetnumber
@returnsvoid

readCursor

readCursor(projectId: string, orgId: string, channelId: string, userId: string): string | null
@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramuserIdstring
@returnsstring | null

setReadCursor

setReadCursor(projectId: string, orgId: string, channelId: string, userId: string, lastReadId: string): void
@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramuserIdstring
@paramlastReadIdstring
@returnsvoid

budgetState

budgetState(projectId: string, orgId: string, agentId: string, period: string): OrgBudgetStateRow | null
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramperiodstring
@returnsOrgBudgetStateRow | null

listBudgetStates

listBudgetStates(projectId: string, orgId: string, period: string): OrgBudgetStateRow[]
@paramprojectIdstring
@paramorgIdstring
@paramperiodstring
@returnsOrgBudgetStateRow[]

markBudget

markBudget(projectId: string, orgId: string, agentId: string, period: string, patch: { warnedAt?: string | null; pausedAt?: string | null }): void
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramperiodstring
@parampatch{ warnedAt?: string | null; pausedAt?: string | null }
@returnsvoid

queueDeskNotice

queueDeskNotice(row: Omit<OrgDeskNoticeRow, "seq">): void

Records a ticket change for an employee. Nothing is sent: the next sweep carries it.

@paramrowOmit<OrgDeskNoticeRow, "seq">
@returnsvoid

takeDeskNotices

takeDeskNotices(projectId: string, orgId: string, agentId: string): OrgDeskNoticeRow[]

The employee's queued changes in delivery order, removed as they are read: one transaction, so a sweep never carries a notice a second sweep also carries.

@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@returnsOrgDeskNoticeRow[]

deleteDeskNotices

deleteDeskNotices(projectId: string, orgId: string, agentId: string): void

An employee that left takes its undelivered notices with it: no sweep will ever carry them.

@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@returnsvoid

deleteOrg

deleteOrg(projectId: string, orgId: string): void
@paramprojectIdstring
@paramorgIdstring
@returnsvoid

deleteProject

deleteProject(projectId: string): void
@paramprojectIdstring
@returnsvoid