From e249a5d0f82197839af4221ce5c2a43e80869e6c Mon Sep 17 00:00:00 2001 From: serfersac Date: Wed, 29 Apr 2026 22:04:53 +0000 Subject: [PATCH] feat: standardize payout metadata schema and validation --- src/utils/payout.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/utils/payout.ts diff --git a/src/utils/payout.ts b/src/utils/payout.ts new file mode 100644 index 0000000..7e3a463 --- /dev/null +++ b/src/utils/payout.ts @@ -0,0 +1,26 @@ + +export interface PayoutMetadata { + contributor_id: string; + pr_url: string; + amount_usdc: number; + timestamp: number; +} + +export function validateMetadata(metadata: any): PayoutMetadata { + if (typeof metadata !== 'object' || metadata === null) { + throw new Error('Metadata must be an object.'); + } + if (typeof metadata.contributor_id !== 'string') { + throw new Error('contributor_id must be a string.'); + } + if (typeof metadata.pr_url !== 'string') { + throw new Error('pr_url must be a string.'); + } + if (typeof metadata.amount_usdc !== 'number') { + throw new Error('amount_usdc must be a number.'); + } + if (typeof metadata.timestamp !== 'number') { + throw new Error('timestamp must be a number.'); + } + return metadata as PayoutMetadata; +}