Skip to content

Commit e7e3e67

Browse files
refactor: fix delivery api ad schedule typings
1 parent de75eb7 commit e7e3e67

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

packages/common/src/services/ApiService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { filterMediaOffers } from '../utils/entitlements';
88
import { useConfigStore as ConfigStore } from '../stores/ConfigStore';
99
import type { GetPlaylistParams, Playlist, PlaylistItem } from '../../types/playlist';
1010
import type { ContentList, GetContentSearchParams } from '../../types/content-list';
11-
import type { AdSchedule } from '../../types/ad-schedule';
11+
import type { DeliveryAdSchedule } from '../../types/ad-schedule';
1212
import type { EpisodeInSeries, EpisodesRes, EpisodesWithPagination, GetSeriesParams, Series } from '../../types/series';
1313
import env from '../env';
1414
import { logError } from '../logger';
@@ -255,15 +255,15 @@ export default class ApiService {
255255
return this.transformEpisodes(episodesRes, seasonNumber);
256256
};
257257

258-
getAdSchedule = async (id: string | undefined | null): Promise<AdSchedule | undefined> => {
258+
getAdSchedule = async (id: string | undefined | null): Promise<DeliveryAdSchedule | undefined> => {
259259
if (!id) {
260260
throw new Error('Ad Schedule ID is required');
261261
}
262262

263263
const url = env.APP_API_BASE_URL + `/v2/advertising/schedules/${id}.json`;
264264
const response = await fetch(url, { credentials: 'omit' });
265265

266-
return (await getDataOrThrow(response)) as AdSchedule;
266+
return (await getDataOrThrow(response)) as DeliveryAdSchedule;
267267
};
268268

269269
/**

packages/common/src/services/ConfigService.ts

-12
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { AppError } from '../utils/error';
77
import type { Config } from '../../types/config';
88
import env from '../env';
99

10-
import ApiService from './ApiService';
11-
1210
/**
1311
* Set config setup changes in both config.service.ts and config.d.ts
1412
* */
@@ -35,12 +33,6 @@ export default class ConfigService {
3533
features: {},
3634
};
3735

38-
private readonly apiService: ApiService;
39-
40-
constructor(apiService: ApiService) {
41-
this.apiService = apiService;
42-
}
43-
4436
private enrichConfig = (config: Config): Config => {
4537
const { content, siteName } = config;
4638
const updatedContent = content.map((content) => Object.assign({ featured: false }, content));
@@ -70,10 +62,6 @@ export default class ConfigService {
7062
return source;
7163
};
7264

73-
loadAdSchedule = async (adScheduleId: string | undefined | null) => {
74-
return this.apiService.getAdSchedule(adScheduleId);
75-
};
76-
7765
loadConfig = async (configLocation: string | undefined) => {
7866
const i18n = getI18n();
7967

packages/common/types/ad-schedule.ts

+55
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,58 @@ export type AdScheduleUrls = {
1010
};
1111

1212
export type AdDeliveryMethod = 'csai' | 'ssai';
13+
14+
type DeliverySchedule = {
15+
tag: string[];
16+
type: 'linear' | 'nonlinear';
17+
offset: 'pre' | 'post' | string; // seconds, timestamp, percentage
18+
skipoffset?: number;
19+
};
20+
21+
type DeliveryRules = {
22+
startOnSeek: 'pre' | 'none' | 'mid';
23+
timeBetweenAds: number;
24+
startOn?: number;
25+
frequency?: number;
26+
};
27+
28+
type DeliveryBids = {
29+
settings: {
30+
bidTimeout: number;
31+
floorPriceCents: number;
32+
mediationLayerAdServer: 'dfp' | 'jwp' | 'jwpdfp' | 'jwpspotx';
33+
disableConsentManagementOnNoCmp?: boolean;
34+
sendAllBids: boolean;
35+
buckets: { min?: number; max?: number; increment?: number }[]; // anyOf
36+
consentManagement: {
37+
usp: {
38+
cmpApi: 'iab' | 'static';
39+
timeout: number;
40+
};
41+
gdpr: {
42+
cmpApi: 'iab' | 'static';
43+
timeout: number;
44+
defaultGdprScope: boolean;
45+
allowAuctionWithoutConsent: boolean;
46+
rules?: {
47+
purpose: 'basicAds' | 'storage' | 'measurement';
48+
enforcePurpose: boolean;
49+
enforceVendor: boolean;
50+
vendorExceptions?: string[];
51+
}[];
52+
};
53+
};
54+
};
55+
ortbParams: {
56+
plcmt: number;
57+
};
58+
};
59+
60+
export type DeliveryAdSchedule = {
61+
rules: DeliveryRules;
62+
schedule: DeliverySchedule[];
63+
bids: DeliveryBids;
64+
client: 'vast' | 'googima';
65+
vpaidmode?: 'enabled' | 'disabled' | 'insecure';
66+
adscheduleid: string;
67+
};

packages/hooks-react/src/useAds.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
33
import ApiService from '@jwp/ott-common/src/services/ApiService';
44
import { getModule } from '@jwp/ott-common/src/modules/container';
55
import { createURL } from '@jwp/ott-common/src/utils/urlFormatting';
6+
import type { AdSchedule } from '@jwp/ott-common/types/ad-schedule';
67

78
const CACHE_TIME = 60 * 1000 * 20;
89

@@ -33,12 +34,12 @@ export const useAds = ({ mediaId }: { mediaId: string }) => {
3334

3435
const { data: adSchedule, isLoading: isAdScheduleLoading } = useLegacyStandaloneAds({ adScheduleId, enabled: !!adScheduleId });
3536
const adConfig = useAdConfigFlow
36-
? {
37+
? ({
3738
client: 'vast',
3839
schedule: createURL(adScheduleUrls?.xml || '', {
3940
media_id: mediaId,
4041
}),
41-
}
42+
} as AdSchedule)
4243
: undefined;
4344

4445
return {

packages/ui-react/src/components/Player/Player.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
2-
import type { AdSchedule } from '@jwp/ott-common/types/ad-schedule';
2+
import type { AdSchedule, DeliveryAdSchedule } from '@jwp/ott-common/types/ad-schedule';
33
import type { PlaylistItem } from '@jwp/ott-common/types/playlist';
44
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
55
import { deepCopy } from '@jwp/ott-common/src/utils/collection';
@@ -20,7 +20,7 @@ type Props = {
2020
item: PlaylistItem;
2121
startTime?: number;
2222
autostart?: boolean;
23-
adsData?: AdSchedule;
23+
adsData?: AdSchedule | DeliveryAdSchedule;
2424
onReady?: (player?: JWPlayer) => void;
2525
onPlay?: () => void;
2626
onPause?: () => void;

0 commit comments

Comments
 (0)