// Executor for `profiles.get`. // // `p['ssn']` is PLAINTEXT here — the store middleware decrypted the // `.encrypted()` column on the way out, and the handler never sees the // `enc:v1:…` ciphertext. That is the round-trip this template exists to show, // and the last-four projection below is what proves it happened. // // The projection is not decoration: the column is `.serverOnly()`, so the full // value must not reach a client. Deriving the suffix HERE — rather than sending // the whole string and trimming it in the browser — is the difference between a // value that never left the server and one that did. import type { AppContext } from '@voltro/runtime' import { eq } from '@voltro/database' import { database } from '../database/schema' /** Last four characters, or '' when there is nothing to show. Never throws on a * short or empty value — a masked field is not a place to fail a read. */ const last4 = (value: string): string => (value.length >= 4 ? value.slice(-4) : '') const execute = async (input: { id: string }, ctx: AppContext) => { const rows = await ctx.store.query(database.profiles.where(eq('id', input.id)).descriptor) const p = rows[0] if (!p) return null return { id: p['id'] as string, name: p['name'] as string, email: p['email'] as string, // Decrypted by the store middleware, then narrowed to what may leave. ssnLast4: last4(p['ssn'] as string), } } export default execute