@playpilot/tpi 8.1.1 → 8.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.1.1",
3
+ "version": "8.1.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -30,16 +30,16 @@
30
30
  "eslint-plugin-svelte": "^3.15.0",
31
31
  "globals": "^15.0.0",
32
32
  "happy-dom": "^16.8.1",
33
- "prettier": "^3.8.1",
33
+ "prettier": "^3.8.3",
34
34
  "prettier-plugin-svelte": "^3.2.6",
35
35
  "sass": "^1.99.0",
36
36
  "svelte": "5.44.1",
37
37
  "svelte-check": "^4.0.0",
38
38
  "svelte-preprocess": "^6.0.3",
39
39
  "svelte-tiny-slider": "^2.7.0",
40
- "typescript": "^5.0.0",
41
- "typescript-eslint": "^8.32.1",
42
- "vite": "^5.0.3",
40
+ "typescript": "^5.9.3",
41
+ "typescript-eslint": "^8.59.2",
42
+ "vite": "^5.4.21",
43
43
  "vite-plugin-css-injected-by-js": "^4.0.1",
44
44
  "vitest": "^2.1.9"
45
45
  }
@@ -75,6 +75,16 @@ export type ConfigResponse = {
75
75
  */
76
76
  allow_user_id_tracking?: boolean
77
77
 
78
+ /**
79
+ * The sid for the current domain, used for tracking
80
+ */
81
+ domain_sid?: string
82
+
83
+ /**
84
+ * The sid for the organization the domain belongs to, used for tracking. Can be empty.
85
+ */
86
+ organization_sid?: string
87
+
78
88
  /**
79
89
  * The following options are all relevant for in text disclaimers, which renders as a disclaimer text within the article,
80
90
  * rather than only inside of title cards.
@@ -39,6 +39,7 @@
39
39
  <nav data-sveltekit-reload>
40
40
  <a href="/" class:active={page.url.pathname === '/'}>Test article</a>
41
41
  <a href="/elements" class:active={page.url.pathname === '/elements'}>Elements</a>
42
+ <a href="/explore" class:active={page.url.pathname === '/explore'}>Explore</a>
42
43
  </nav>
43
44
 
44
45
  {#if page.error}
@@ -79,6 +79,7 @@
79
79
  if (config?.custom_style) insertCustomStyle(config.custom_style || '')
80
80
  if (config?.explore_navigation_selector) insertExploreIntoNavigation()
81
81
  if (config?.no_affiliate) window.PlayPilotLinkInjections.no_affiliate = true
82
+ if (config?.domain_sid) setTrackingSids({ organizationSid: config.organization_sid, domainSid: config.domain_sid })
82
83
 
83
84
  isUrlExcluded = isUrlExcludedViaConfig(config)
84
85
  if (isUrlExcluded) return
@@ -3,7 +3,10 @@
3
3
  import { exploreParentSelector, useExploreRouter } from '$lib/explore'
4
4
  import { t } from '$lib/localization'
5
5
  import type { ExploreRoute } from '$lib/types/explore'
6
- import type { Snippet } from 'svelte'
6
+ import { track } from '$lib/tracking'
7
+ import { TrackingEvent } from '$lib/enums/TrackingEvent'
8
+ import { fetchAds } from '$lib/api/ads'
9
+ import { onMount, type Snippet } from 'svelte'
7
10
  import Search from './Filter/Search.svelte'
8
11
  import Button from '../Button.svelte'
9
12
 
@@ -25,6 +28,12 @@
25
28
  // allow our element to be scrollable, rather than the parent needing to be scrollable.
26
29
  height = element?.closest<HTMLElement>(exploreParentSelector)?.style.height || null
27
30
  })
31
+
32
+ onMount(async () => {
33
+ track(TrackingEvent.ExplorePageView)
34
+
35
+ if (!window.PlayPilotLinkInjections.ads?.length) window.PlayPilotLinkInjections.ads = await fetchAds()
36
+ })
28
37
  </script>
29
38
 
30
39
  <div class="explore playpilot-styled-scrollbar" bind:this={element} style:height>
@@ -1,5 +1,4 @@
1
1
  <script lang="ts">
2
- import { fetchAds } from '$lib/api/ads'
3
2
  import { fetchTitles } from '$lib/api/titles'
4
3
  import { MetaEvent, TrackingEvent } from '$lib/enums/TrackingEvent'
5
4
  import { openModal } from '$lib/modal'
@@ -9,7 +8,6 @@
9
8
  import type { TitleData } from '$lib/types/title'
10
9
  import { hasConsentedTo } from '$lib/consent'
11
10
  import { trackViaPixel } from '@playpilot/retargeting-tracking'
12
- import { onMount } from 'svelte'
13
11
  import { t } from '$lib/localization'
14
12
  import Button from '../../Button.svelte'
15
13
  import GridTitle from '../../GridTitle.svelte'
@@ -48,12 +46,6 @@
48
46
  if (searchQuery) search(searchQuery)
49
47
  })
50
48
 
51
- onMount(async () => {
52
- track(TrackingEvent.ExplorePageView)
53
-
54
- if (!window.PlayPilotLinkInjections.ads?.length) window.PlayPilotLinkInjections.ads = await fetchAds()
55
- })
56
-
57
49
  async function getTitlesForFilter(): Promise<APIPaginatedResult<TitleData>> {
58
50
  latestRequestId += 1
59
51
  const requestId = latestRequestId
@@ -150,6 +150,9 @@
150
150
 
151
151
  .arrow {
152
152
  --offset: #{margin(-2)};
153
+ --scale: 1;
154
+ cursor: pointer;
155
+ z-index: 2;
153
156
  display: flex;
154
157
  align-items: center;
155
158
  justify-content: center;
@@ -160,11 +163,10 @@
160
163
  height: margin(3);
161
164
  border: 1px solid theme(rail-modal-item-border, content);
162
165
  border-radius: 50%;
163
- transform: translateY(-50%);
166
+ transform: translateY(-50%) scale(var(--scale));
167
+ transition: transform 50ms;
164
168
  background: theme(rail-modal-arrow-background, lighter);
165
169
  box-shadow: theme(rail-modal-arrow-shadow, 0 margin(0.25) margin(0.5) rgba(0, 0, 0, 0.35));
166
- z-index: 2;
167
- cursor: pointer;
168
170
  color: theme(rail-modal-arrow-color, text-color);
169
171
 
170
172
  @media (min-width: 800px) {
@@ -176,6 +178,14 @@
176
178
  filter: brightness(1.2);
177
179
  }
178
180
 
181
+ &:hover {
182
+ --scale: 1.05;
183
+ }
184
+
185
+ &:active {
186
+ --scale: 0.97;
187
+ }
188
+
179
189
  &.right {
180
190
  left: auto;
181
191
  right: var(--offset);
@@ -119,7 +119,7 @@
119
119
  <Rail
120
120
  bind:slider
121
121
  {heading}
122
- onchange={(index) => setTimeout(() => openTitle(null, titles, index), 250)}
122
+ onchange={(index) => { if (expandable) setTimeout(() => openTitle(null, titles, index), 250) }}
123
123
  onresize={() => slider?.reposition()}>
124
124
  {#each titles as title, index}
125
125
  {@const expanded = isExpanded(title)}
@@ -133,7 +133,6 @@
133
133
 
134
134
  <h2>TitlesRailModal</h2>
135
135
 
136
-
137
136
  {#await fetchSimilarTitles(title) then titles}
138
137
  <button onclick={() => openModal({ type: 'titles-rail', data: titles })}>Show titles rail modal</button>
139
138
  <button onclick={() => openModal({ type: 'titles-rail', data: titles, props: { initialIndex: 3 } })}>Show titles rail modal start at index 3</button>
@@ -14,7 +14,7 @@
14
14
  token: 'ZoAL14yqzevMyQiwckbvyetOkeIUeEDN',
15
15
  config: {
16
16
  explore_navigation_selector: 'nav a:last-child',
17
- explore_navigation_label: 'Streaming guide',
17
+ explore_navigation_label: 'Streaming guide (inserted)',
18
18
  explore_navigation_path: '/explore',
19
19
  explore_custom_style: 'main { border: 2px solid white }',
20
20
  explore_use_router: true,
@@ -564,6 +564,17 @@ describe('$routes/+page.svelte', () => {
564
564
 
565
565
  expect(queryByTitle('Show PlayPilot TPI editor')).not.toBeTruthy()
566
566
  })
567
+
568
+ it('Should set tracking sids from config', async () => {
569
+ // @ts-ignore
570
+ vi.mocked(fetchConfig).mockResolvedValueOnce({ domain_sid: 'some-domain', organization_sid: 'some-organization' })
571
+
572
+ render(page)
573
+
574
+ await waitFor(() => {
575
+ expect(setTrackingSids).toHaveBeenCalledWith({ domainSid: 'some-domain', organizationSid: 'some-organization' })
576
+ })
577
+ })
567
578
  })
568
579
 
569
580
  describe('disable_public_injections', () => {
@@ -4,6 +4,9 @@ import { expect, describe, it, vi, beforeEach } from 'vitest'
4
4
  import ExploreLayout from '../../../../routes/components/Explore/ExploreLayout.svelte'
5
5
  import { createRawSnippet } from 'svelte'
6
6
  import { exploreParentSelector } from '$lib/explore'
7
+ import { track } from '$lib/tracking'
8
+ import { TrackingEvent } from '$lib/enums/TrackingEvent'
9
+ import { fetchAds } from '$lib/api/ads'
7
10
 
8
11
  const children = createRawSnippet(() => ({ render: () => '<div></div>' }))
9
12
 
@@ -19,8 +22,18 @@ const routes = [
19
22
  },
20
23
  ]
21
24
 
25
+ vi.mock('$lib/tracking', () => ({
26
+ track: vi.fn(),
27
+ }))
28
+
29
+ vi.mock('$lib/api/ads', () => ({
30
+ fetchAds: vi.fn(),
31
+ }))
32
+
22
33
  describe('ExploreLayout.svelte', () => {
23
34
  beforeEach(() => {
35
+ vi.resetAllMocks()
36
+
24
37
  // @ts-ignore
25
38
  window.PlayPilotLinkInjections = { config: { explore_use_router: true } }
26
39
  })
@@ -54,4 +67,20 @@ describe('ExploreLayout.svelte', () => {
54
67
  expect(container.querySelector('.explore')?.getAttribute('style')).toBe('height: 500px;')
55
68
  })
56
69
  })
70
+
71
+ it('Should call tracking event and fetchAds on mount', () => {
72
+ render(ExploreLayout, { routes, currentRoute: routes[0], children })
73
+
74
+ expect(track).toHaveBeenCalledWith(TrackingEvent.ExplorePageView)
75
+ expect(fetchAds).toHaveBeenCalled()
76
+ })
77
+
78
+ it('Should not call fetchAds on mount if ads are already present', () => {
79
+ // @ts-ignore
80
+ window.PlayPilotLinkInjections.ads = ['a']
81
+
82
+ render(ExploreLayout, { routes, currentRoute: routes[0], children })
83
+
84
+ expect(fetchAds).not.toHaveBeenCalled()
85
+ })
57
86
  })
@@ -6,7 +6,6 @@ import { fetchTitles } from '$lib/api/titles'
6
6
  import { title } from '$lib/fakeData'
7
7
  import { TrackingEvent } from '$lib/enums/TrackingEvent'
8
8
  import { track } from '$lib/tracking'
9
- import { fetchAds } from '$lib/api/ads'
10
9
 
11
10
  vi.mock('$lib/api/titles', () => ({
12
11
  fetchTitles: vi.fn(),
@@ -20,10 +19,6 @@ vi.mock('$lib/tracking', () => ({
20
19
  track: vi.fn(),
21
20
  }))
22
21
 
23
- vi.mock('$lib/api/ads', () => ({
24
- fetchAds: vi.fn(),
25
- }))
26
-
27
22
  describe('ExploreResults.svelte', () => {
28
23
  beforeEach(() => {
29
24
  // @ts-ignore
@@ -38,25 +33,6 @@ describe('ExploreResults.svelte', () => {
38
33
  expect(fetchTitles).toHaveBeenCalledWith({ page_size: 24, page: 1 })
39
34
  })
40
35
 
41
- it('Should call tracking event and fetchAds on mount', () => {
42
- render(ExploreResults)
43
-
44
- expect(track).toHaveBeenCalledWith(TrackingEvent.ExplorePageView)
45
- expect(fetchAds).toHaveBeenCalled()
46
- })
47
-
48
- it('Should not call fetchAds on mount if ads are already present', () => {
49
- // @ts-ignore
50
- window.PlayPilotLinkInjections = {
51
- // @ts-ignore
52
- ads: ['a'],
53
- }
54
-
55
- render(ExploreResults)
56
-
57
- expect(fetchAds).not.toHaveBeenCalled()
58
- })
59
-
60
36
  it('Should render all returned titles', async () => {
61
37
  vi.mocked(fetchTitles).mockResolvedValueOnce({ results: [title, title, title], next: null, previous: null })
62
38
 
@@ -156,4 +156,15 @@ describe('TitlesRail.svelte', () => {
156
156
  expect(getAllByTestId('title')[0].classList).not.toContain('expanded')
157
157
  })
158
158
  })
159
+
160
+ it('Should not call openModal after changing if expandable is false', async () => {
161
+ const titles = [{ ...title }, { ...title, sid: 'some-other-sid' }]
162
+
163
+ const { getByLabelText } = render(TitlesRail, { titles, expandable: false })
164
+
165
+ await fireEvent.click(getByLabelText('Next'))
166
+ await new Promise(res => setTimeout(res, 500))
167
+
168
+ expect(openModal).not.toHaveBeenCalled()
169
+ })
159
170
  })