MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / normalize

Function normalize

web/src/lib/ad-providers/zeroclick.ts:65–92  ·  view source on GitHub ↗
(raw: ZeroClickOffer, servedId: string)

Source from the content-addressed store, hash-verified

63}
64
65function 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
94export function createZeroClickProvider(config: {
95 apiKey: string

Callers 1

createZeroClickProviderFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected