import { v1 } from '@authzed/authzed-node'; export function createActiveAtCaveatContext(at?: string): v1.PbStruct { return { fields: { at: { kind: { oneofKind: 'stringValue', stringValue: at ?? new Date().toISOString() } } } }; } export function createTargetingCaveatContext(attributes?: Record, now?: string): v1.PbStruct { return { fields: { user_context: { kind: { oneofKind: 'structValue', structValue: { fields: { now: { kind: { oneofKind: 'stringValue', stringValue: now ?? new Date().toISOString() } }, ...Object.entries(attributes ?? {}).reduce< Record >((acc, [attrName, attrValue]) => { acc[attrName] = { kind: { oneofKind: 'stringValue', stringValue: String(attrValue) } }; return acc; }, {}) } } } } } }; }