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

Function fetchAdSlot

packages/shared/src/lib/ads.ts:221–246  ·  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

219};
220
221const fetchAdSlot = async (
222 options: Parameters<typeof fetchAdRequest>[0],
223 {
224 onTransition,
225 throwOnError = false,
226 }: {
227 onTransition?: FetchAdByPlacementOptions['onTransition'];
228 throwOnError?: boolean;
229 } = {},
230): Promise<Ad | null> => {
231 onTransition?.({ type: 'pre-fetch' });
232 let result: Awaited<ReturnType<typeof fetchAdRequest>>;
233 try {
234 result = await fetchAdRequest({ ...options, throwOnError });
235 } catch (error) {
236 onTransition?.({ type: 'fetch-error' });
237 throw error;
238 }
239 const { ad, failed } = result;
240 if (failed) {
241 onTransition?.({ type: 'fetch-error' });
242 } else {
243 onTransition?.(ad ? { type: 'post-fetch', ad } : { type: 'no-fill' });
244 }
245 return ad;
246};
247
248export const resolveAdFetchOptions = ({
249 placement = AdPlacement.Feed,

Callers 2

fetchSlotFunction · 0.85
fetchAdFunction · 0.85

Calls 1

fetchAdRequestFunction · 0.85

Tested by

no test coverage detected