(raw: ZeroClickOffer, servedId: string)
| 63 | } |
| 64 | |
| 65 | function normalize(raw: ZeroClickOffer, servedId: string): NormalizedAd | null { |
| 66 | if (!raw.id || !raw.clickUrl) return null |
| 67 | |
| 68 | const title = |
| 69 | raw.brand?.name?.trim() || |
| 70 | raw.title?.trim() || |
| 71 | raw.product?.title?.trim() || |
| 72 | 'Sponsored' |
| 73 | const content = raw.content?.trim() || raw.subtitle?.trim() || '' |
| 74 | |
| 75 | return { |
| 76 | adText: content || title, |
| 77 | title, |
| 78 | cta: raw.cta?.trim() || 'Learn more', |
| 79 | url: raw.brand?.url?.trim() || '', |
| 80 | favicon: |
| 81 | raw.imageUrl?.trim() || |
| 82 | raw.product?.image?.trim() || |
| 83 | raw.brand?.iconUrl?.trim() || |
| 84 | '', |
| 85 | clickUrl: raw.clickUrl, |
| 86 | // Keep this URL-shaped so existing client/server validation can identify |
| 87 | // the served ad. The actual ZeroClick impression is a client-side POST using |
| 88 | // impressionIds, so do not put provider tracking IDs in this local key. |
| 89 | impUrl: `https://codebuff.com/ads/zeroclick-impression/${servedId}`, |
| 90 | impressionIds: [raw.id], |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | export function createZeroClickProvider(config: { |
| 95 | apiKey: string |
no outgoing calls
no test coverage detected