{"version":3,"file":"idempotency.mjs","names":["IdempotencyError","message","code","encoder","canonicalConvexBytes","bound","bounds","invalid","ancestors","nodes","bytes","spend","amount","textBytes","text","visit","depth","current","item","prototype","keys","key","descriptor","value","project","output","convexToJson","encoded","versionFields","invocationBytes","captureIdempotencyInvocation","capture","identity","versions","validIdentity","validVersions","retainedIdempotencyReceipt","rows","receipt","candidate","invocation","idempotencyCanonicalInput","idempotencyFingerprint","transactionalIdempotency","configuration","canonical","retained","fingerprint","claim","wire","result","field"],"sources":["../../../src/modules/contracts/idempotency.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters, anti-slop/no-runtime-typeof -- Canonical transport and retained receipts are explicit untrusted value boundaries. */\nimport { convexToJson, type Value, type JSONValue } from 'convex/values'\nimport type { ContractInput, ContractOutput, NeutralSchema } from './contract'\n\nexport type IdempotencyErrorCode =\n\t| 'unsupported-binding'\n\t| 'invalid-input'\n\t| 'corrupt'\n\t| 'ambiguous'\n\t| 'pending'\n\t| 'stale'\n\t| 'conflict'\nexport class IdempotencyError extends Error {\n\treadonly _tag = 'IdempotencyError'\n\tconstructor(\n\t\treadonly code: IdempotencyErrorCode,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message)\n\t\tthis.name = 'IdempotencyError'\n\t}\n}\nexport interface IdempotencyIdentity {\n\treadonly operation: string\n\t/** Stable trusted tenant/principal or delegated-capability scope, supplied by the host. */\n\treadonly scope: string\n\treadonly key: string\n}\nexport interface IdempotencyVersions {\n\treadonly operation: string\n\treadonly contract: string\n\treadonly binding: string\n\treadonly fingerprintPolicy: string\n}\nexport interface IdempotencyReceipt {\n\treadonly versions: IdempotencyVersions\n\treadonly fingerprint: string\n\treadonly state: 'pending' | 'completed'\n\treadonly result?: unknown\n}\nexport interface CanonicalConvexBounds {\n\treadonly maxDepth: number\n\treadonly maxNodes: number\n\treadonly maxBytes: number\n\treadonly maxArrayLength: number\n\treadonly maxObjectFields: number\n}\n\nconst encoder = new TextEncoder()\n/** Bounded transport encoding, using the pinned Convex integer/binary/float representation. */\nexport function canonicalConvexBytes(value: unknown, bounds: CanonicalConvexBounds): string {\n\tfor (const bound of [\n\t\tbounds.maxDepth,\n\t\tbounds.maxNodes,\n\t\tbounds.maxBytes,\n\t\tbounds.maxArrayLength,\n\t\tbounds.maxObjectFields,\n\t])\n\t\tif (!Number.isSafeInteger(bound) || bound < 1)\n\t\t\tinvalid('Canonical bounds must be positive safe integers')\n\tconst ancestors = new Set<object>()\n\tlet nodes = 0\n\tlet bytes = 0\n\tfunction spend(amount: number) {\n\t\tbytes += amount\n\t\tif (bytes > bounds.maxBytes) invalid('Canonical input exceeds byte bound')\n\t}\n\tfunction textBytes(text: string) {\n\t\tif (text.length > bounds.maxBytes) invalid('Canonical input exceeds byte bound')\n\t\treturn encoder.encode(text).length\n\t}\n\tfunction visit(current: unknown, depth: number): void {\n\t\tif (++nodes > bounds.maxNodes || depth > bounds.maxDepth)\n\t\t\tinvalid('Canonical input exceeds traversal bound')\n\t\tif (current === null || typeof current === 'boolean') {\n\t\t\tspend(1)\n\t\t\treturn\n\t\t}\n\t\tif (typeof current === 'number') {\n\t\t\tspend(9)\n\t\t\treturn\n\t\t}\n\t\tif (typeof current === 'bigint') {\n\t\t\tif (current < -(1n << 63n) || current > (1n << 63n) - 1n)\n\t\t\t\tinvalid('Convex integer exceeds signed int64')\n\t\t\tspend(9)\n\t\t\treturn\n\t\t}\n\t\tif (typeof current === 'string') {\n\t\t\tspend(2 + textBytes(current))\n\t\t\treturn\n\t\t}\n\t\tif (current instanceof ArrayBuffer) {\n\t\t\tspend(2 + current.byteLength)\n\t\t\treturn\n\t\t}\n\t\tif (typeof current !== 'object') invalid('Unsupported canonical Convex value')\n\t\tif (ancestors.has(current)) invalid('Cyclic canonical input')\n\t\tancestors.add(current)\n\t\ttry {\n\t\t\tif (Array.isArray(current)) {\n\t\t\t\tif (current.length > bounds.maxArrayLength) invalid('Canonical array exceeds length bound')\n\t\t\t\tspend(2)\n\t\t\t\tfor (const item of current) visit(item, depth + 1)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst prototype = Object.getPrototypeOf(current)\n\t\t\tif (prototype !== Object.prototype && prototype !== null)\n\t\t\t\tinvalid('Canonical input requires plain objects')\n\t\t\tif (Object.getOwnPropertySymbols(current).length) invalid('Unsupported canonical symbol keys')\n\t\t\tconst keys = Object.keys(current)\n\t\t\tif (keys.length > bounds.maxObjectFields) invalid('Canonical object exceeds field bound')\n\t\t\tspend(2)\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (key.length > 1024 || key.startsWith('$') || /[^\\x20-\\x7e]/.test(key))\n\t\t\t\t\tinvalid('Invalid Convex object key')\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(current, key)!\n\t\t\t\tif (!('value' in descriptor)) invalid('Canonical input cannot contain accessors')\n\t\t\t\tif (descriptor.value === undefined) continue\n\t\t\t\tspend(textBytes(key) + 1)\n\t\t\t\tvisit(descriptor.value, depth + 1)\n\t\t\t}\n\t\t} finally {\n\t\t\tancestors.delete(current)\n\t\t}\n\t}\n\tvisit(value, 0)\n\t// Object projection retains own __proto__ keys which the SDK's assignment-based object converter drops.\n\t// Scalars still use the pinned SDK's exact integer/binary/float representation.\n\tfunction project(current: Value): JSONValue {\n\t\tif (Array.isArray(current)) return current.map(project)\n\t\tif (current !== null && typeof current === 'object' && !(current instanceof ArrayBuffer)) {\n\t\t\tconst output: Record<string, JSONValue> = Object.create(null)\n\t\t\tfor (const key of Object.keys(current).sort()) {\n\t\t\t\t// SAFETY: prior bounded traversal excluded every object type except plain Convex dictionaries.\n\t\t\t\tconst item = (current as Record<string, Value | undefined>)[key]\n\t\t\t\tif (item !== undefined) output[key] = project(item)\n\t\t\t}\n\t\t\treturn output\n\t\t}\n\t\treturn convexToJson(current)\n\t}\n\t// SAFETY: the traversal validates the bounded supported Convex value subset before SDK conversion.\n\tconst encoded = JSON.stringify(project(value as Value))\n\tif (encoder.encode(encoded).length > bounds.maxBytes)\n\t\tinvalid('Canonical encoding exceeds byte bound')\n\treturn encoded\n}\n\nconst versionFields = ['operation', 'contract', 'binding', 'fingerprintPolicy'] as const\nconst invocationBytes: unique symbol = Symbol('idempotency invocation bytes')\nexport interface IdempotencyInvocation {\n\treadonly identity: IdempotencyIdentity\n\treadonly versions: IdempotencyVersions\n\treadonly [invocationBytes]: string\n}\nexport interface IdempotencyCapture {\n\treadonly binding: { readonly kind: 'mutation'; readonly atomicity: 'same-mutation' }\n\treadonly identity: IdempotencyIdentity\n\treadonly versions: IdempotencyVersions\n\treadonly rawInput: unknown\n\treadonly canonical: {\n\t\treadonly bounds: CanonicalConvexBounds\n\t\t/** Explicit deterministic equivalence; the host versions this policy in fingerprintPolicy. */\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- The explicit normalized transport policy is validated by canonicalConvexBytes before capture.\n\t\treadonly normalize?: (raw: unknown) => unknown\n\t}\n}\n/** Call at the trusted native handler before domain decoding, once per invocation (including nested calls). */\nexport function captureIdempotencyInvocation(capture: IdempotencyCapture): IdempotencyInvocation {\n\tif (capture.binding.kind !== 'mutation' || capture.binding.atomicity !== 'same-mutation')\n\t\tthrow new IdempotencyError(\n\t\t\t'unsupported-binding',\n\t\t\t'Idempotency requires the current native mutation transaction',\n\t\t)\n\tconst identity = Object.freeze({\n\t\toperation: capture.identity.operation,\n\t\tscope: capture.identity.scope,\n\t\tkey: capture.identity.key,\n\t})\n\tconst versions = Object.freeze({\n\t\toperation: capture.versions.operation,\n\t\tcontract: capture.versions.contract,\n\t\tbinding: capture.versions.binding,\n\t\tfingerprintPolicy: capture.versions.fingerprintPolicy,\n\t})\n\tif (!validIdentity(identity) || !validVersions(versions))\n\t\tinvalid('Invalid trusted idempotency metadata')\n\tconst bytes = canonicalConvexBytes(\n\t\tcapture.canonical.normalize ? capture.canonical.normalize(capture.rawInput) : capture.rawInput,\n\t\tcapture.canonical.bounds,\n\t)\n\treturn Object.freeze({ identity, versions, [invocationBytes]: bytes })\n}\n/** Shared protocol checks have no Effect dependency and never decode final wire data. */\nexport function retainedIdempotencyReceipt(\n\trows: readonly unknown[],\n\tinvocation: IdempotencyInvocation,\n): IdempotencyReceipt | undefined {\n\tif (!Array.isArray(rows)) throw new IdempotencyError('corrupt', 'Receipt lookup must return rows')\n\tif (rows.length > 1)\n\t\tthrow new IdempotencyError('ambiguous', 'Multiple receipts match the stable identity')\n\tif (rows.length === 0) return undefined\n\tconst receipt = rows[0]\n\tif (\n\t\ttypeof receipt !== 'object' ||\n\t\treceipt === null ||\n\t\t!Object.hasOwn(receipt, 'versions') ||\n\t\t!Object.hasOwn(receipt, 'fingerprint') ||\n\t\t!Object.hasOwn(receipt, 'state')\n\t)\n\t\tthrow new IdempotencyError('corrupt', 'Malformed retained receipt')\n\t// SAFETY: this temporary retained-row view is fully checked below before returning or using metadata.\n\tconst candidate = receipt as IdempotencyReceipt\n\tif (\n\t\t!validVersions(candidate.versions) ||\n\t\ttypeof candidate.fingerprint !== 'string' ||\n\t\t!['pending', 'completed'].includes(candidate.state) ||\n\t\t(candidate.state === 'completed' && !Object.hasOwn(candidate, 'result'))\n\t)\n\t\tthrow new IdempotencyError('corrupt', 'Malformed retained receipt')\n\tif (versionFields.some((key) => candidate.versions[key] !== invocation.versions[key]))\n\t\tthrow new IdempotencyError(\n\t\t\t'stale',\n\t\t\t'Retained receipt version differs from the current operation',\n\t\t)\n\tif (candidate.state === 'pending')\n\t\tthrow new IdempotencyError('pending', 'Retained receipt is incomplete')\n\treturn candidate\n}\nexport function idempotencyCanonicalInput(invocation: IdempotencyInvocation): string {\n\tif (!Object.hasOwn(invocation, invocationBytes))\n\t\tthrow new IdempotencyError('unsupported-binding', 'Missing trusted invocation capture')\n\treturn invocation[invocationBytes]\n}\nexport function idempotencyFingerprint(value: string, receipt?: IdempotencyReceipt): string {\n\tif (typeof value !== 'string' || value.length === 0)\n\t\tthrow new IdempotencyError('invalid-input', 'Fingerprint policy must return a nonempty string')\n\tif (receipt && receipt.fingerprint !== value)\n\t\tthrow new IdempotencyError('conflict', 'Caller key was already used with different input')\n\treturn value\n}\nexport type IdempotencyPreparation<Result> =\n\t| { readonly kind: 'replay'; readonly result: unknown }\n\t| { readonly kind: 'execute'; readonly complete: (result: Result) => Promise<void> }\ntype NeutralValue<A> = A | PromiseLike<A>\n/** Host callbacks close over the same secured mutation writer; native OCC/rollback remains host-owned. */\nexport function transactionalIdempotency<const Replay extends NeutralSchema, Claim>(configuration: {\n\treadonly final: {\n\t\treadonly replayResult: Replay\n\t\treadonly encode: (result: ContractOutput<Replay>) => NeutralValue<ContractInput<Replay>>\n\t}\n\treadonly authorize: (invocation: IdempotencyInvocation) => NeutralValue<void>\n\treadonly lookup: (identity: IdempotencyIdentity) => NeutralValue<readonly unknown[]>\n\treadonly fingerprint: (canonicalBytes: string) => NeutralValue<string>\n\treadonly claim: (\n\t\tidentity: IdempotencyIdentity,\n\t\treceipt: IdempotencyReceipt,\n\t) => NeutralValue<Claim>\n\treadonly complete: (claim: Claim, receipt: IdempotencyReceipt) => NeutralValue<void>\n}) {\n\treturn {\n\t\treplayResult: configuration.final.replayResult,\n\t\tasync prepare(\n\t\t\tinvocation: IdempotencyInvocation,\n\t\t): Promise<IdempotencyPreparation<ContractOutput<Replay>>> {\n\t\t\tconst canonical = idempotencyCanonicalInput(invocation)\n\t\t\tawait configuration.authorize(invocation)\n\t\t\tconst retained = retainedIdempotencyReceipt(\n\t\t\t\tawait configuration.lookup(invocation.identity),\n\t\t\t\tinvocation,\n\t\t\t)\n\t\t\tconst fingerprint = idempotencyFingerprint(\n\t\t\t\tawait configuration.fingerprint(canonical),\n\t\t\t\tretained,\n\t\t\t)\n\t\t\tif (retained) return { kind: 'replay', result: retained.result }\n\t\t\tconst claim = await configuration.claim(invocation.identity, {\n\t\t\t\tstate: 'pending',\n\t\t\t\tversions: invocation.versions,\n\t\t\t\tfingerprint,\n\t\t\t})\n\t\t\treturn {\n\t\t\t\tkind: 'execute',\n\t\t\t\tcomplete: async (result) => {\n\t\t\t\t\tconst wire = await configuration.final.encode(result)\n\t\t\t\t\tawait configuration.complete(claim, {\n\t\t\t\t\t\tstate: 'completed',\n\t\t\t\t\t\tversions: invocation.versions,\n\t\t\t\t\t\tfingerprint,\n\t\t\t\t\t\tresult: wire,\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\nfunction invalid(message: string): never {\n\tthrow new IdempotencyError('invalid-input', message)\n}\nfunction validIdentity(value: IdempotencyIdentity): boolean {\n\treturn [value.operation, value.scope, value.key].every(\n\t\t(field) => typeof field === 'string' && field.length > 0,\n\t)\n}\nfunction validVersions(value: unknown): value is IdempotencyVersions {\n\tif (typeof value !== 'object' || value === null) return false\n\t// SAFETY: this temporary metadata view is checked field by field before the predicate certifies it.\n\tconst candidate = value as Partial<IdempotencyVersions>\n\treturn versionFields.every((field) => {\n\t\tconst item = candidate[field]\n\t\treturn Object.hasOwn(candidate, field) && typeof item === 'string' && item.length > 0\n\t})\n}\n"],"mappings":"6CAYA,IAAaA,EAAb,cAAsC,KAAM,CAGjC,KAFV,KAAgB,mBAChB,YACC,EACA,EACC,CACD,MAAMC,CAAO,EAHJ,KAAA,KAAAC,EAIT,KAAK,KAAO,kBACb,CACD,EA2BA,MAAMC,EAAU,IAAI,YAEpB,SAAgBC,EAAqB,EAAgB,EAAuC,CAC3F,IAAK,IAAMC,IAAS,CACnBC,EAAO,SACPA,EAAO,SACPA,EAAO,SACPA,EAAO,eACPA,EAAO,eACR,GACK,CAAC,OAAO,cAAcD,CAAK,GAAKA,EAAQ,IAC3CE,EAAQ,iDAAiD,EAC3D,IAAMC,kBAAY,IAAI,IAClBC,EAAQ,EACRC,EAAQ,EACZ,SAASC,EAAM,EAAgB,CAC9B,GAASC,EACLF,EAAQJ,EAAO,UAAUC,EAAQ,oCAAoC,CAC1E,CACA,SAASM,EAAU,EAAc,CAEhC,OADIC,EAAK,OAASR,EAAO,UAAUC,EAAQ,oCAAoC,EACxEJ,EAAQ,OAAOW,CAA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