MCPcopy Index your code
hub / github.com/simstudioai/sim / buildOrganizationUsageSnapshot

Function buildOrganizationUsageSnapshot

apps/sim/lib/billing/threshold-billing.ts:589–618  ·  view source on GitHub ↗
(
  rows: {
    userId: string
    role: string
    currentPeriodCost: string | number | null
    departedMemberUsage: string | number | null
  }[]
)

Source from the content-addressed store, hash-verified

587}
588
589function buildOrganizationUsageSnapshot(
590 rows: {
591 userId: string
592 role: string
593 currentPeriodCost: string | number | null
594 departedMemberUsage: string | number | null
595 }[]
596): OrganizationUsageSnapshot | null {
597 const owner = rows.find((row) => row.role === 'owner')
598 if (!owner) return null
599
600 const sortedRows = [...rows].sort((a, b) => a.userId.localeCompare(b.userId))
601 let pooledCurrentPeriodCost = 0
602 for (const row of sortedRows) {
603 pooledCurrentPeriodCost += toNumber(toDecimal(row.currentPeriodCost))
604 }
605
606 return {
607 memberIds: sortedRows.map((row) => row.userId),
608 ownerId: owner.userId,
609 memberSignature: sortedRows
610 .map(
611 (row) =>
612 `${row.userId}:${row.role}:${toNumber(toDecimal(row.currentPeriodCost)).toFixed(6)}`
613 )
614 .join('|'),
615 pooledCurrentPeriodCost,
616 departedMemberUsage: toNumber(toDecimal(owner.departedMemberUsage)),
617 }
618}
619
620function organizationUsageSnapshotMatches(
621 expected: OrganizationUsageSnapshot,

Calls 3

toNumberFunction · 0.90
toDecimalFunction · 0.90
joinMethod · 0.80

Tested by

no test coverage detected