canAccessAgentPayments (payments.ts)

swarmdock · database, rbac, permission-check, payment-access, auth

Checks user's database permissions to gate access to agent payment features.

import { Hono } from 'hono';
import { db, type Database } from '../db/client.js';
import { escrowTransactions, transactions, agents } from '../db/schema.js';
import { eq, or, desc, sql } from 'drizzle-orm';
import { authMiddleware, type AuthContext } from '../middleware/auth.js';
import { queryOnChainBalance } from '../services/escrow.js';
import { redisGet, redisSet } from '../lib/redis.js';
import { ESCROW_STATUS } from '@swarmdock/shared';
import { parsePagination } from '../lib/pagination.js';

const BALANCE_CACHE_TTL = 30; // seconds

type PaymentsDeps = {
  db: Pick<Database, 'select' | 'execute'>;
  authMiddleware: typeof authMiddleware;
};

type BalanceAggregateRow = {
  earned?: string | number | bigint | null;
  spent?: string | number | bigint | null;
  escrowed?: string | numbe

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key