MCPcopy Create free account
hub / github.com/dailydotdev/apps / fetchAdSlot

Function fetchAdSlot

packages/shared/src/lib/ads.ts:198–223  ·  view source on GitHub ↗
(
  options: Parameters<typeof fetchAdRequest>[0],
  {
    onTransition,
    throwOnError = false,
  }: {
    onTransition?: FetchAdByPlacementOptions['onTransition'];
    throwOnError?: boolean;
  } = {},
)

Source from the content-addressed store, hash-verified

196};
197
198const fetchAdSlot = async (
199 options: Parameters<typeof fetchAdRequest>[0],
200 {
201 onTransition,
202 throwOnError = false,
203 }: {
204 onTransition?: FetchAdByPlacementOptions['onTransition'];
205 throwOnError?: boolean;
206 } = {},
207): Promise<Ad | null> => {
208 onTransition?.({ type: 'pre-fetch' });
209 let result: Awaited<ReturnType<typeof fetchAdRequest>>;
210 try {
211 result = await fetchAdRequest({ ...options, throwOnError });
212 } catch (error) {
213 onTransition?.({ type: 'fetch-error' });
214 throw error;
215 }
216 const { ad, failed } = result;
217 if (failed) {
218 onTransition?.({ type: 'fetch-error' });
219 } else {
220 onTransition?.(ad ? { type: 'post-fetch', ad } : { type: 'no-fill' });
221 }
222 return ad;
223};
224
225export const resolveAdFetchOptions = ({
226 placement = AdPlacement.Feed,

Callers 2

fetchSlotFunction · 0.85
fetchAdFunction · 0.85

Calls 1

fetchAdRequestFunction · 0.85

Tested by

no test coverage detected