@streamlayer/feature-advertisement 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -6,7 +6,8 @@ declare module '@streamlayer/sdk-web-interfaces' {
6
6
  }
7
7
  export { type ExternalAdStore, type ExternalPauseAdStore, type SsaiMonitorOptions } from './advertisement';
8
8
  export { type GAMStaticCore, type PauseAdTemplate, isFullbleedVideoTemplate } from './units/external-pause-ad';
9
- export { type PauseAdCard, type PauseAdStore } from './units/pause-ad';
9
+ export { INSIGHT_BODY_MAX_LENGTH, type PauseAdCard, type PauseAdKind, type PauseAdMediaMode, } from './units/pause-ad-card';
10
+ export { type PauseAdStore } from './units/pause-ad';
10
11
  export { type AdStore, type AdData, type AdCompanion, type AdNonLinear } from './units/external-ad';
11
12
  export { gam, type GamNonceResult, type PalNonceManager } from './units/gam';
12
13
  export { createCompanionTracker, createVastTracker, resolveVastTrackerTarget, type VastTrackerTarget, } from './units/vast-tracker';
package/lib/index.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import { Advertisement } from './advertisement';
2
2
  export { isFullbleedVideoTemplate } from './units/external-pause-ad';
3
+ // Card shapes come straight from the pure module rather than through `units/pause-ad`. NOT a bundle
4
+ // guarantee for barrel consumers — this file value-imports `Advertisement` on line 3, which imports
5
+ // the store module anyway, and the package declares no `sideEffects: false`. What it does buy: the
6
+ // unit spec and any deep importer get the card shapes without the store, and dropping the
7
+ // `export *` keeps `units/pause-ad` from silently re-exporting `parsePauseAdCards`.
8
+ export { INSIGHT_BODY_MAX_LENGTH, } from './units/pause-ad-card';
3
9
  export { gam } from './units/gam';
4
10
  export { createCompanionTracker, createVastTracker, resolveVastTrackerTarget, } from './units/vast-tracker';
5
11
  export { DEFAULT_CREATIVE_API_BASE, } from './units/ssai-creative';
@@ -0,0 +1,49 @@
1
+ import { type Question } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
2
+ export type PauseAdLayout = 'left' | 'center' | 'image';
3
+ /**
4
+ * Which full-bleed renderer draws the card. Absent === `'standard'`.
5
+ *
6
+ * - `'standard'` — the Standard/Image pause ad (promotion card).
7
+ * - `'insight'` — the Insight Pause Ad (factoid card): sponsor logo, heading and a
8
+ * single-column body beside an optional media image (SC-353).
9
+ */
10
+ export type PauseAdKind = 'standard' | 'insight';
11
+ /** How the Insight media image is cropped — mirrors Studio's Media switcher. */
12
+ export type PauseAdMediaMode = 'image' | 'circle' | 'none';
13
+ /**
14
+ * Insight body cap (SC-353). Studio enforces it on the Additional Content field; the
15
+ * SDK clamps as well so a card authored before the limit landed cannot overflow the
16
+ * screen — the format is explicitly designed to fit without scrolling.
17
+ */
18
+ export declare const INSIGHT_BODY_MAX_LENGTH = 600;
19
+ export type PauseAdCard = {
20
+ id: string;
21
+ parentId: string;
22
+ /** Optional: a video-only card (programmatic VAST, SC-322) has no image. */
23
+ backgroundImageSrc?: string;
24
+ /** Linear MP4 from VAST → renders full-bleed `<video>` instead of the image (SC-322). */
25
+ backgroundVideoSrc?: string;
26
+ layout: PauseAdLayout;
27
+ isInteractive: boolean;
28
+ logoSrc?: string;
29
+ title?: string;
30
+ description?: string;
31
+ ctaLabel?: string;
32
+ ctaUrl?: string;
33
+ qrCodeUrl?: string;
34
+ qrCodeLabel?: string;
35
+ /** Absent === `'standard'`. */
36
+ kind?: PauseAdKind;
37
+ /** Insight only: the Media image (`FactoidOptions.image`). */
38
+ mediaSrc?: string;
39
+ /** Insight only: how `mediaSrc` is cropped. */
40
+ mediaMode?: PauseAdMediaMode;
41
+ };
42
+ /**
43
+ * The `pauseAdList` response, shaped for the renderers: keep the cards the SDK has chrome for,
44
+ * turn each into a `PauseAdCard`, drop the ones that cannot be drawn.
45
+ *
46
+ * Pure on purpose — `pause-ad.ts` owns the store and the transport, this owns the card shapes,
47
+ * and only this half needs unit tests.
48
+ */
49
+ export declare const parsePauseAdCards: (questions: Question[]) => PauseAdCard[];
@@ -0,0 +1,130 @@
1
+ import { CardFormat, FactoidMediaMode, NotificationSponsorLogoMode, PauseAdLayout as PauseAdLayoutProto, PromotionButtonType, PromotionFormat, QRCode, UseGeneralLogo, UserAccountInfo, } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
2
+ /**
3
+ * Insight body cap (SC-353). Studio enforces it on the Additional Content field; the
4
+ * SDK clamps as well so a card authored before the limit landed cannot overflow the
5
+ * screen — the format is explicitly designed to fit without scrolling.
6
+ */
7
+ export const INSIGHT_BODY_MAX_LENGTH = 600;
8
+ /**
9
+ * Sponsor logo for a factoid card. Same General-tab opt-in as the promotion path below,
10
+ * but the logo lives on `question.promotion.sponsor` (a factoid card carries no
11
+ * `PromotionOptions`) and Studio writes the uploaded file to `logo`, not `centerLogo`.
12
+ *
13
+ * `logo` therefore WINS over `centerLogo`: the latter is an optional field carried over from the
14
+ * notification/header surfaces, so a card that kept a stale `centerLogo` from an earlier revision
15
+ * would otherwise render it instead of the Insight logo the author just uploaded.
16
+ */
17
+ const resolveInsightSponsorLogo = (question) => {
18
+ const sponsor = question.promotion?.sponsor;
19
+ if (sponsor?.logoPosition === NotificationSponsorLogoMode.NOTIFICATION_SPONSOR_LOGO_NONE) {
20
+ return undefined;
21
+ }
22
+ return sponsor?.useGeneralLogo === UseGeneralLogo.ENABLED
23
+ ? question.promotion?.generalTabMetadata?.advertiserTransparentLogo || undefined
24
+ : sponsor?.logo || sponsor?.centerLogo || undefined;
25
+ };
26
+ const MEDIA_MODE_BY_PROTO = {
27
+ [FactoidMediaMode.IMAGE]: 'image',
28
+ [FactoidMediaMode.CIRCLE]: 'circle',
29
+ };
30
+ /**
31
+ * Insight Pause Ad, Full Bleed (SC-353). A factoid card, so none of the promotion
32
+ * plumbing above applies: the heading is the question subject, the body is
33
+ * `FactoidOptions.body`, and the sponsor logo comes off `question.promotion.sponsor`.
34
+ *
35
+ * `FACTOID_MEDIA_MODE_VIDEO` is deliberately treated as "no media": the full-bleed
36
+ * format has no player chrome and no way to start playback, unlike the sidebar variant.
37
+ */
38
+ const parseInsightPauseAdCard = (question) => {
39
+ const factoidOptions = question.options?.options.case === 'factoid' ? question.options.options.value : undefined;
40
+ if (!factoidOptions) {
41
+ return null;
42
+ }
43
+ const mediaMode = MEDIA_MODE_BY_PROTO[factoidOptions.mode] ?? 'none';
44
+ const body = factoidOptions.body.slice(0, INSIGHT_BODY_MAX_LENGTH);
45
+ return {
46
+ id: question.id,
47
+ parentId: question.eventId || question.id,
48
+ // `landscapeUrl` ONLY. `portraitUrl` keeps stale artwork from earlier revisions of the
49
+ // card that Studio no longer shows in its Background Image slot, so falling back to it
50
+ // paints a background the author has already removed. Unlike the standard card, an
51
+ // Insight one renders fine with no background at all — its copy is the ad.
52
+ backgroundImageSrc: question.backgroundImage?.landscapeUrl || undefined,
53
+ kind: 'insight',
54
+ layout: 'left',
55
+ isInteractive: false,
56
+ logoSrc: resolveInsightSponsorLogo(question),
57
+ title: question.subject || undefined,
58
+ description: body || undefined,
59
+ mediaSrc: mediaMode === 'none' ? undefined : factoidOptions.image || undefined,
60
+ mediaMode,
61
+ };
62
+ };
63
+ const parsePauseAdCard = (question) => {
64
+ if (question.options?.options.case === 'factoid') {
65
+ return parseInsightPauseAdCard(question);
66
+ }
67
+ const backgroundImageSrc = question.backgroundImage?.landscapeUrl;
68
+ if (!backgroundImageSrc) {
69
+ return null;
70
+ }
71
+ const promotionOptions = question.options?.options.case === 'promotion' ? question.options.options.value : undefined;
72
+ const pauseAdOptions = promotionOptions?.pauseAdOptions;
73
+ const optionsSponsor = promotionOptions?.sponsor;
74
+ const layoutProto = pauseAdOptions?.layout ?? PauseAdLayoutProto.UNSET;
75
+ const layout = layoutProto === PauseAdLayoutProto.CENTER ? 'center' : layoutProto === PauseAdLayoutProto.IMAGE ? 'image' : 'left';
76
+ const isInteractive = promotionOptions?.buttonType === PromotionButtonType.SEND_TO_USER;
77
+ const hasQr = pauseAdOptions?.qrCode === QRCode.QR_CODE_ENABLED && !!pauseAdOptions?.qrCodeUrl;
78
+ let ctaLabel;
79
+ let ctaUrl;
80
+ if (isInteractive && promotionOptions?.buttonOptions.case === 'sendToUserOptions') {
81
+ const accountInfo = promotionOptions.buttonOptions.value.userAccountInfo;
82
+ const isPhone = accountInfo === UserAccountInfo.PHONE;
83
+ ctaUrl = isPhone ? 'sendToPhone:' : 'sendToEmail:';
84
+ ctaLabel = isPhone ? 'Send info to account phone' : 'Send info to account email';
85
+ }
86
+ const logoSrc = optionsSponsor?.logoPosition === NotificationSponsorLogoMode.NOTIFICATION_SPONSOR_LOGO_NONE
87
+ ? undefined
88
+ : optionsSponsor?.useGeneralLogo === UseGeneralLogo.ENABLED
89
+ ? question.promotion?.generalTabMetadata?.advertiserTransparentLogo || undefined
90
+ : optionsSponsor?.centerLogo || undefined;
91
+ return {
92
+ id: question.id,
93
+ parentId: question.eventId || question.id,
94
+ backgroundImageSrc,
95
+ layout,
96
+ logoSrc,
97
+ title: promotionOptions?.banner?.title || undefined,
98
+ description: promotionOptions?.banner?.body || undefined,
99
+ isInteractive,
100
+ ctaLabel: ctaLabel || undefined,
101
+ ctaUrl: ctaUrl || undefined,
102
+ qrCodeUrl: hasQr ? (pauseAdOptions?.qrCodeUrl ?? undefined) : undefined,
103
+ qrCodeLabel: hasQr ? (pauseAdOptions?.qrCodeLabel ?? undefined) : undefined,
104
+ };
105
+ };
106
+ /**
107
+ * Which cards from `pauseAdList` the SDK can actually draw. Both renderers are full bleed; a
108
+ * Sidebar-format pause ad has no chrome yet and is skipped.
109
+ */
110
+ const isFullBleedPauseAd = (question) => {
111
+ if (question.options?.options.case === 'factoid') {
112
+ // Insight Pause Ad (SC-353). Studio does not write `CardFormat` on these cards yet
113
+ // (SLW-7062), so an UNSET format is taken as Full Bleed — the only Insight pause-ad chrome
114
+ // the SDK has. An explicit Sidebar stays out. Drop the UNSET arm once Studio sets the field.
115
+ return question.format === CardFormat.FULL_BLEED || question.format === CardFormat.UNSET;
116
+ }
117
+ const promotionOptions = question.options?.options.case === 'promotion' ? question.options.options.value : undefined;
118
+ return promotionOptions?.format === PromotionFormat.FULL_BLEED || question.format === CardFormat.FULL_BLEED;
119
+ };
120
+ /**
121
+ * The `pauseAdList` response, shaped for the renderers: keep the cards the SDK has chrome for,
122
+ * turn each into a `PauseAdCard`, drop the ones that cannot be drawn.
123
+ *
124
+ * Pure on purpose — `pause-ad.ts` owns the store and the transport, this owns the card shapes,
125
+ * and only this half needs unit tests.
126
+ */
127
+ export const parsePauseAdCards = (questions) => questions
128
+ .filter(isFullBleedPauseAd)
129
+ .map(parsePauseAdCard)
130
+ .filter((card) => card !== null);
@@ -1,24 +1,7 @@
1
1
  import { createSingleStore, StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
2
2
  import '@streamlayer/sdk-web-api';
3
3
  import '@streamlayer/sdk-web-core/store';
4
- export type PauseAdLayout = 'left' | 'center' | 'image';
5
- export type PauseAdCard = {
6
- id: string;
7
- parentId: string;
8
- /** Optional: a video-only card (programmatic VAST, SC-322) has no image. */
9
- backgroundImageSrc?: string;
10
- /** Linear MP4 from VAST → renders full-bleed `<video>` instead of the image (SC-322). */
11
- backgroundVideoSrc?: string;
12
- layout: PauseAdLayout;
13
- isInteractive: boolean;
14
- logoSrc?: string;
15
- title?: string;
16
- description?: string;
17
- ctaLabel?: string;
18
- ctaUrl?: string;
19
- qrCodeUrl?: string;
20
- qrCodeLabel?: string;
21
- };
4
+ import { type PauseAdCard } from './pause-ad-card';
22
5
  export type PauseAdListOptions = {
23
6
  refetchInterval: number;
24
7
  $enabled: boolean;
@@ -2,49 +2,9 @@ import { createLogger } from '@streamlayer/sdk-web-logger';
2
2
  import { atom } from 'nanostores';
3
3
  import '@streamlayer/sdk-web-api';
4
4
  import '@streamlayer/sdk-web-core/store';
5
- import { CardFormat, NotificationSponsorLogoMode, PauseAdLayout as PauseAdLayoutProto, PromotionButtonType, PromotionFormat, QRCode, UseGeneralLogo, UserAccountInfo, } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
6
5
  import { Feed } from '@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb';
6
+ import { parsePauseAdCards } from './pause-ad-card';
7
7
  const log = createLogger('advertisement:pause-ad');
8
- const parsePauseAdCard = (question) => {
9
- const backgroundImageSrc = question.backgroundImage?.landscapeUrl;
10
- if (!backgroundImageSrc) {
11
- return null;
12
- }
13
- const promotionOptions = question.options?.options.case === 'promotion' ? question.options.options.value : undefined;
14
- const pauseAdOptions = promotionOptions?.pauseAdOptions;
15
- const optionsSponsor = promotionOptions?.sponsor;
16
- const layoutProto = pauseAdOptions?.layout ?? PauseAdLayoutProto.UNSET;
17
- const layout = layoutProto === PauseAdLayoutProto.CENTER ? 'center' : layoutProto === PauseAdLayoutProto.IMAGE ? 'image' : 'left';
18
- const isInteractive = promotionOptions?.buttonType === PromotionButtonType.SEND_TO_USER;
19
- const hasQr = pauseAdOptions?.qrCode === QRCode.QR_CODE_ENABLED && !!pauseAdOptions?.qrCodeUrl;
20
- let ctaLabel;
21
- let ctaUrl;
22
- if (isInteractive && promotionOptions?.buttonOptions.case === 'sendToUserOptions') {
23
- const accountInfo = promotionOptions.buttonOptions.value.userAccountInfo;
24
- const isPhone = accountInfo === UserAccountInfo.PHONE;
25
- ctaUrl = isPhone ? 'sendToPhone:' : 'sendToEmail:';
26
- ctaLabel = isPhone ? 'Send info to account phone' : 'Send info to account email';
27
- }
28
- const logoSrc = optionsSponsor?.logoPosition === NotificationSponsorLogoMode.NOTIFICATION_SPONSOR_LOGO_NONE
29
- ? undefined
30
- : optionsSponsor?.useGeneralLogo === UseGeneralLogo.ENABLED
31
- ? question.promotion?.generalTabMetadata?.advertiserTransparentLogo || undefined
32
- : optionsSponsor?.centerLogo || undefined;
33
- return {
34
- id: question.id,
35
- parentId: question.eventId || question.id,
36
- backgroundImageSrc,
37
- layout,
38
- logoSrc,
39
- title: promotionOptions?.banner?.title || undefined,
40
- description: promotionOptions?.banner?.body || undefined,
41
- isInteractive,
42
- ctaLabel: ctaLabel || undefined,
43
- ctaUrl: ctaUrl || undefined,
44
- qrCodeUrl: hasQr ? (pauseAdOptions?.qrCodeUrl ?? undefined) : undefined,
45
- qrCodeLabel: hasQr ? (pauseAdOptions?.qrCodeLabel ?? undefined) : undefined,
46
- };
47
- };
48
8
  export const pauseAdListStore = (instance) => {
49
9
  const $slStreamId = instance.stores.slStreamId.getAtomStore();
50
10
  return ($enabled, options) => {
@@ -61,14 +21,7 @@ export const pauseAdListStore = (instance) => {
61
21
  }
62
22
  log.debug({ eventId }, 'fetching pause ad list');
63
23
  const res = await client.pauseAdList({ eventId });
64
- const questions = res.data ?? [];
65
- const cards = questions
66
- .filter((q) => {
67
- const opts = q.options?.options.case === 'promotion' ? q.options.options.value : undefined;
68
- return opts?.format === PromotionFormat.FULL_BLEED || q.format === CardFormat.FULL_BLEED;
69
- })
70
- .map((q) => parsePauseAdCard(q))
71
- .filter((c) => c !== null);
24
+ const cards = parsePauseAdCards(res.data ?? []);
72
25
  log.debug({ count: cards.length }, 'parsed %d fullbleed pause ad cards');
73
26
  return cards;
74
27
  },
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-advertisement",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "peerDependencies": {
5
- "@dailymotion/vast-client": "^6.4.2",
5
+ "@dailymotion/vast-client": "^6.4.5",
6
6
  "@streamlayer/sl-eslib": "^5.268.1",
7
7
  "uuid": "^11.1.0",
8
8
  "nanostores": "^1.1.0",
9
- "@streamlayer/sdk-web-core": "^1.23.0",
10
- "@streamlayer/sdk-web-api": "^1.18.0",
11
- "@streamlayer/sdk-web-interfaces": "^1.11.0",
12
- "@streamlayer/sdk-web-types": "^2.0.0",
13
- "@streamlayer/sdk-web-logger": "^1.2.0",
14
- "@streamlayer/sdk-web-storage": "^1.2.0"
9
+ "@streamlayer/sdk-web-core": "^1.23.1",
10
+ "@streamlayer/sdk-web-api": "^1.18.1",
11
+ "@streamlayer/sdk-web-interfaces": "^1.11.1",
12
+ "@streamlayer/sdk-web-types": "^2.0.1",
13
+ "@streamlayer/sdk-web-logger": "^1.2.1",
14
+ "@streamlayer/sdk-web-storage": "^1.2.1"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/vast-client": "^3.0.4"