@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 14.0.0-rc.91

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.
Files changed (142) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +60 -84
  2. package/actionsExecutor/ScreenActions.ts +164 -0
  3. package/actionsExecutor/StorageActions.ts +110 -0
  4. package/actionsExecutor/feedDecorator.ts +171 -0
  5. package/actionsExecutor/screenResolver.ts +11 -0
  6. package/analyticsUtils/AnalyticPlayerListener.ts +5 -2
  7. package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
  8. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  9. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  10. package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
  11. package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
  12. package/analyticsUtils/events.ts +8 -0
  13. package/analyticsUtils/index.tsx +3 -4
  14. package/analyticsUtils/manager.ts +1 -1
  15. package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
  16. package/appUtils/HooksManager/Hook.ts +4 -4
  17. package/appUtils/HooksManager/index.ts +11 -1
  18. package/appUtils/accessibilityManager/const.ts +13 -0
  19. package/appUtils/accessibilityManager/hooks.ts +35 -1
  20. package/appUtils/accessibilityManager/index.ts +154 -30
  21. package/appUtils/accessibilityManager/utils.ts +24 -0
  22. package/appUtils/contextKeysManager/contextResolver.ts +42 -1
  23. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +8 -0
  24. package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
  25. package/appUtils/focusManager/events.ts +2 -0
  26. package/appUtils/focusManager/index.ios.ts +27 -0
  27. package/appUtils/focusManager/index.ts +86 -11
  28. package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
  29. package/appUtils/focusManagerAux/utils/index.ts +112 -3
  30. package/appUtils/focusManagerAux/utils/utils.ios.ts +35 -0
  31. package/appUtils/platform/platformUtils.ts +33 -3
  32. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +91 -16
  33. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  34. package/appUtils/playerManager/conts.ts +21 -0
  35. package/appUtils/playerManager/useChapterMarker.tsx +0 -1
  36. package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
  37. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  38. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  39. package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
  40. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  41. package/arrayUtils/index.ts +13 -3
  42. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
  43. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
  44. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
  45. package/audioPlayerUtils/assets/index.ts +2 -0
  46. package/audioPlayerUtils/index.ts +242 -0
  47. package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
  48. package/componentsUtils/index.ts +4 -1
  49. package/conf/player/__tests__/selectors.test.ts +34 -0
  50. package/conf/player/selectors.ts +10 -0
  51. package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
  52. package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
  53. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
  54. package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
  55. package/configurationUtils/index.ts +64 -35
  56. package/configurationUtils/manifestKeyParser.ts +57 -32
  57. package/focusManager/FocusManager.ts +104 -20
  58. package/focusManager/Tree.ts +25 -21
  59. package/focusManager/__tests__/FocusManager.test.ts +50 -8
  60. package/focusManager/aux/index.ts +98 -0
  61. package/focusManager/utils.ts +12 -6
  62. package/index.d.ts +1 -10
  63. package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
  64. package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
  65. package/manifestUtils/createConfig.js +4 -1
  66. package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
  67. package/manifestUtils/index.js +4 -0
  68. package/manifestUtils/keys.js +33 -0
  69. package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
  70. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
  71. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  72. package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
  73. package/navigationUtils/index.ts +26 -21
  74. package/package.json +2 -3
  75. package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
  76. package/playerUtils/PlayerTTS/index.ts +1 -0
  77. package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
  78. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
  79. package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
  80. package/playerUtils/_internals/index.ts +1 -0
  81. package/playerUtils/_internals/utils.ts +31 -0
  82. package/playerUtils/configurationUtils.ts +0 -44
  83. package/playerUtils/getPlayerActionButtons.ts +17 -0
  84. package/playerUtils/index.ts +53 -0
  85. package/playerUtils/usePlayerTTS.ts +21 -0
  86. package/playerUtils/useValidatePlayerConfig.tsx +22 -19
  87. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
  88. package/reactHooks/cell-click/__tests__/index.test.js +3 -0
  89. package/reactHooks/cell-click/index.ts +8 -1
  90. package/reactHooks/debugging/__tests__/index.test.js +0 -1
  91. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
  92. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
  93. package/reactHooks/feed/index.ts +2 -0
  94. package/reactHooks/feed/useBatchLoading.ts +17 -10
  95. package/reactHooks/feed/useFeedLoader.tsx +36 -43
  96. package/reactHooks/feed/useInflatedUrl.ts +23 -29
  97. package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
  98. package/reactHooks/feed/usePipesCacheReset.ts +3 -3
  99. package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
  100. package/reactHooks/layout/__tests__/index.test.tsx +3 -1
  101. package/reactHooks/layout/index.ts +1 -1
  102. package/reactHooks/layout/isTablet/index.ts +12 -5
  103. package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
  104. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
  105. package/reactHooks/layout/useLayoutVersion.ts +5 -5
  106. package/reactHooks/navigation/index.ts +7 -5
  107. package/reactHooks/navigation/useIsScreenActive.ts +9 -5
  108. package/reactHooks/navigation/useRoute.ts +7 -2
  109. package/reactHooks/navigation/useScreenStateStore.ts +8 -0
  110. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
  111. package/reactHooks/screen/useScreenContext.ts +1 -1
  112. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
  113. package/reactHooks/state/index.ts +1 -1
  114. package/reactHooks/state/useHomeRiver.ts +4 -2
  115. package/reactHooks/state/useRivers.ts +7 -8
  116. package/riverComponetsMeasurementProvider/index.tsx +1 -1
  117. package/screenPickerUtils/index.ts +13 -0
  118. package/services/js2native.ts +1 -0
  119. package/storage/ScreenSingleValueProvider.ts +204 -0
  120. package/storage/ScreenStateMultiSelectProvider.ts +293 -0
  121. package/storage/StorageMultiSelectProvider.ts +192 -0
  122. package/storage/StorageSingleSelectProvider.ts +108 -0
  123. package/testUtils/index.tsx +7 -8
  124. package/time/BackgroundTimer.ts +6 -4
  125. package/utils/__tests__/endsWith.test.ts +30 -0
  126. package/utils/__tests__/find.test.ts +36 -0
  127. package/utils/__tests__/mapAccum.test.ts +73 -0
  128. package/utils/__tests__/omit.test.ts +19 -0
  129. package/utils/__tests__/path.test.ts +33 -0
  130. package/utils/__tests__/pathOr.test.ts +37 -0
  131. package/utils/__tests__/startsWith.test.ts +30 -0
  132. package/utils/__tests__/take.test.ts +40 -0
  133. package/utils/endsWith.ts +9 -0
  134. package/utils/find.ts +3 -0
  135. package/utils/index.ts +38 -1
  136. package/utils/mapAccum.ts +23 -0
  137. package/utils/omit.ts +5 -0
  138. package/utils/path.ts +5 -0
  139. package/utils/pathOr.ts +5 -0
  140. package/utils/startsWith.ts +9 -0
  141. package/utils/take.ts +5 -0
  142. package/playerUtils/configurationGenerator.ts +0 -2572
@@ -5,6 +5,7 @@ import { createLogger, utilsLogger } from "../../../logger";
5
5
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
6
6
  import {
7
7
  findPluginByIdentifier,
8
+ loadFeedEntry,
8
9
  loadFeedAndPrefetchThumbnailImage,
9
10
  parseTimeToSeconds,
10
11
  retrieveFeedUrl,
@@ -18,13 +19,6 @@ export const { log_verbose, log_debug, log_info, log_error } = createLogger({
18
19
  parent: utilsLogger,
19
20
  });
20
21
 
21
- type ActionChapter = {
22
- type: string;
23
- options?: {
24
- title: string;
25
- };
26
- };
27
-
28
22
  type ChapterMarkerOriginal = {
29
23
  id: string;
30
24
  title: string;
@@ -33,12 +27,17 @@ type ChapterMarkerOriginal = {
33
27
  actions: ActionChapter[];
34
28
  };
35
29
 
36
- export type ChapterMarkerEvent = {
37
- id: string;
30
+ export type LiveMetadataEvent = {
31
+ programId: string;
32
+ assetId: string;
38
33
  title: string;
39
- start_time: number;
40
- end_time: number;
41
- actions: ActionChapter[];
34
+ programStartTime: string;
35
+ programEndTime: string;
36
+ };
37
+
38
+ export type LiveMetadataConfig = {
39
+ updateUrl: string;
40
+ updateInterval: number;
42
41
  };
43
42
 
44
43
  export type TitleSummaryEvent = {
@@ -65,11 +64,13 @@ export type PlayNextState = PlayNextConfig & {
65
64
  export class OverlaysObserver {
66
65
  readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
67
66
  private playNextSubject: BehaviorSubject<PlayNextState>;
67
+ private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
68
68
  private titleSummarySubject: BehaviorSubject<TitleSummaryEvent>;
69
69
  private feedUrl: string;
70
70
  private reloadData: () => void;
71
71
  private updateTitleAndDescription: (data: any) => void;
72
72
  private feedDataInterval: any;
73
+ private liveMetadataUpdateInterval: any;
73
74
  private releasePlayerObserver?: () => void;
74
75
  readonly entry: ZappEntry;
75
76
  private chapterMarkerEvents: ChapterMarkerEvent[];
@@ -81,13 +82,17 @@ export class OverlaysObserver {
81
82
  this.chapterSubject = new BehaviorSubject(null);
82
83
  this.playNextSubject = new BehaviorSubject(null);
83
84
 
85
+ this.player = player;
86
+ this.entry = player.getEntry();
87
+
84
88
  this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
85
- title: player.getEntry()?.title || "",
86
- summary: player.getEntry()?.summary || "",
89
+ title: this.entry?.title || "",
90
+ summary: this.entry?.summary || "",
87
91
  });
88
92
 
89
- this.entry = player.getEntry();
90
- this.player = player;
93
+ this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
94
+ this.entry?.extensions?.liveMetadata || null
95
+ );
91
96
 
92
97
  this.chapterMarkerEvents = this.prepareChapterMarkers();
93
98
  this.releasePlayerObserver = this.subscribeToPlayerEvents();
@@ -95,7 +100,9 @@ export class OverlaysObserver {
95
100
  this.reloadData = () => {};
96
101
  this.updateTitleAndDescription = () => {};
97
102
  this.feedDataInterval = null;
103
+ this.liveMetadataUpdateInterval = null;
98
104
  void this.preparePlayNext();
105
+ void this.prepareLiveMetadata();
99
106
  }
100
107
 
101
108
  private setupFeedDataInterval(interval: number) {
@@ -113,6 +120,13 @@ export class OverlaysObserver {
113
120
  }
114
121
  }
115
122
 
123
+ public clearLiveMetadataUpdateInterval() {
124
+ if (this.liveMetadataUpdateInterval) {
125
+ clearInterval(this.liveMetadataUpdateInterval);
126
+ this.liveMetadataUpdateInterval = null;
127
+ }
128
+ }
129
+
116
130
  public setFeedDataHandlers(
117
131
  feedUrl: string,
118
132
  reloadData: () => void,
@@ -212,6 +226,48 @@ export class OverlaysObserver {
212
226
  }
213
227
  };
214
228
 
229
+ prepareLiveMetadata = async () => {
230
+ if (!this.player?.isLive?.()) {
231
+ log_debug("prepareLiveMetadata: Player is not live. Skipping...");
232
+
233
+ return;
234
+ }
235
+
236
+ const config: LiveMetadataConfig =
237
+ this.entry?.extensions?.liveMetadataConfig;
238
+
239
+ if (!config?.updateUrl || !config?.updateInterval) {
240
+ log_debug(
241
+ "prepareLiveMetadata: Live metadata configuration is not available. Skipping...",
242
+ { config }
243
+ );
244
+
245
+ return;
246
+ }
247
+
248
+ const reloadData = async () => {
249
+ try {
250
+ const entry = await loadFeedEntry(config.updateUrl, this.entry);
251
+
252
+ this.onLiveMetadataUpdated(entry?.extensions?.liveMetadata || null);
253
+ } catch (error) {
254
+ log_error("prepareLiveMetadata: Metadata fetching failed", {
255
+ error,
256
+ config,
257
+ });
258
+ }
259
+ };
260
+
261
+ log_debug("prepareLiveMetadata: Setting up live metadata observer update", {
262
+ config,
263
+ });
264
+
265
+ const interval = Number(config?.updateInterval) || 60;
266
+
267
+ this.clearLiveMetadataUpdateInterval();
268
+ this.liveMetadataUpdateInterval = setInterval(reloadData, interval * 1000);
269
+ };
270
+
215
271
  // TODO: Hack for video end, will be replaced with playlist prev/next in the future
216
272
  getPlayNextEntry = () =>
217
273
  !this.isCanceledByUser ? this.playNextConfig?.entry : null;
@@ -332,9 +388,11 @@ export class OverlaysObserver {
332
388
  onPlayerClose = () => {
333
389
  this.chapterSubject.complete();
334
390
  this.playNextSubject.complete();
391
+ this.liveMetadataSubject.complete();
335
392
  this.titleSummarySubject.complete();
336
393
  this.releasePlayerObserver?.();
337
394
  this.clearFeedDataInterval();
395
+ this.clearLiveMetadataUpdateInterval();
338
396
  this.releasePlayerObserver = null;
339
397
  };
340
398
 
@@ -367,4 +425,21 @@ export class OverlaysObserver {
367
425
  (prev, curr) => prev?.triggerTime === curr?.triggerTime
368
426
  )
369
427
  );
428
+
429
+ private onLiveMetadataUpdated = (liveMetadataEvent: LiveMetadataEvent) => {
430
+ this.liveMetadataSubject.next(liveMetadataEvent);
431
+ };
432
+
433
+ public getLiveMetadataObservable = (): Observable<LiveMetadataEvent> => {
434
+ return this.liveMetadataSubject.pipe(
435
+ distinctUntilChanged(
436
+ (prev, curr) =>
437
+ prev?.programId === curr?.programId && prev?.assetId === curr?.assetId
438
+ )
439
+ );
440
+ };
441
+
442
+ public getLiveMetadataValue = (): LiveMetadataEvent => {
443
+ return this.liveMetadataSubject.value;
444
+ };
370
445
  }
@@ -92,22 +92,26 @@ export const prefetchImage = (playableItem: ZappEntry, config: any = {}) => {
92
92
  }
93
93
  };
94
94
 
95
- export const loadFeedAndPrefetchThumbnailImage = async (
96
- playNextFeedUrl: string,
97
- entry: ZappEntry,
98
- playNextPlugin
99
- ) => {
95
+ /**
96
+ * Loads a feed entry from the given feed URL using the provided Zapp entry as context.
97
+ *
98
+ * @param {string} feedUrl - The URL of the feed to load the entry from.
99
+ * @param {ZappEntry} entry - The Zapp entry to use as context for the request.
100
+ * @returns {Promise<ZappEntry>} A promise that resolves to the loaded Zapp entry.
101
+ * @throws {Error} If the feed loading fails or no entry is found in the response.
102
+ */
103
+ export const loadFeedEntry = async (feedUrl: string, entry: ZappEntry) => {
100
104
  const requestBuilder = new RequestBuilder()
101
105
  .setEntryContext(entry)
102
106
  .setScreenContext({} as ZappRiver)
103
- .setUrl(playNextFeedUrl);
107
+ .setUrl(feedUrl);
104
108
 
105
109
  const responseObject = await requestBuilder.call<ZappEntry>();
106
110
  const responseHelper = new PipesClientResponseHelper(responseObject);
107
111
 
108
112
  if (responseHelper.error) {
109
113
  log_error(
110
- `loadFeedAndPrefetchThumbnailImage: loading failed with error: ${responseHelper.error.message}. Play next observer, will not be executed`,
114
+ `loadFeedEntry: loading failed with error: ${responseHelper.error.message}. Observer will not be executed`,
111
115
  {
112
116
  response: responseHelper.getLogsData(),
113
117
  }
@@ -116,29 +120,37 @@ export const loadFeedAndPrefetchThumbnailImage = async (
116
120
  throw responseHelper.error;
117
121
  } else {
118
122
  log_info(
119
- `loadFeedAndPrefetchThumbnailImage: Play next url was successfully loaded for url: ${playNextFeedUrl}. Prefetching image`,
123
+ `loadFeedEntry: Feed was successfully loaded for url: ${feedUrl}`,
120
124
  responseHelper.getLogsData()
121
125
  );
122
126
 
123
- const playNextEntry = responseHelper.responseData?.entry[0];
127
+ const entry = responseHelper.responseData?.entry[0];
124
128
 
125
- if (!playNextEntry) {
126
- log_error(
127
- "loadFeedAndPrefetchThumbnailImage: Can not retrieve play next entry, feed was loaded but no entry was found",
128
- responseHelper.getLogsData()
129
- );
129
+ if (!entry) {
130
+ const error =
131
+ "loadFeedEntry: Can not retrieve entry, feed was loaded but no entry was found";
130
132
 
131
- throw new Error(
132
- "Can not retrieve play next entry, feed was loaded but no entry was found"
133
- );
134
- }
133
+ log_error(error, responseHelper.getLogsData());
135
134
 
136
- prefetchImage(playNextEntry, playNextPlugin?.configuration);
135
+ throw new Error(error);
136
+ }
137
137
 
138
- return playNextEntry;
138
+ return entry;
139
139
  }
140
140
  };
141
141
 
142
+ export const loadFeedAndPrefetchThumbnailImage = async (
143
+ playNextFeedUrl: string,
144
+ entry: ZappEntry,
145
+ playNextPlugin
146
+ ) => {
147
+ const playNextEntry = await loadFeedEntry(playNextFeedUrl, entry);
148
+
149
+ prefetchImage(playNextEntry, playNextPlugin?.configuration);
150
+
151
+ return playNextEntry;
152
+ };
153
+
142
154
  export const findPluginByIdentifier = (
143
155
  identifier: string,
144
156
  plugins: ZappPlugin[]
@@ -2,6 +2,27 @@ export const userPreferencesNamespace = "user_preferences";
2
2
 
3
3
  export const skipActionType = "show_skip";
4
4
 
5
+ export class PlayerError
6
+ extends Error
7
+ implements QuickBrickPlayer.PlayerErrorI
8
+ {
9
+ description: string;
10
+
11
+ constructor(message: string, description: string) {
12
+ super(message);
13
+ this.description = description;
14
+
15
+ Object.setPrototypeOf(this, PlayerError.prototype);
16
+ }
17
+
18
+ toObject() {
19
+ return {
20
+ error: this.message,
21
+ message: this.description,
22
+ };
23
+ }
24
+ }
25
+
5
26
  export enum SharedPlayerCallBacksKeys {
6
27
  OnPlayerResume = "onPlayerResume",
7
28
  OnPlayerPause = "onPlayerPause",
@@ -1,4 +1,3 @@
1
- import { ChapterMarkerEvent } from "./OverlayObserver/OverlaysObserver";
2
1
  import { usePlayer } from "./usePlayer";
3
2
  import * as React from "react";
4
3
 
@@ -5,6 +5,9 @@ import { playerManager } from "./index";
5
5
  import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
6
6
  import { PlayerRole } from "./conts";
7
7
  import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
8
+ import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
9
+ import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
10
+ import { isTV } from "../../reactUtils";
8
11
 
9
12
  // TODO: Rename to ControllerType
10
13
  export const usePlayerControllerSetup = ({
@@ -76,5 +79,18 @@ export const usePlayerControllerSetup = ({
76
79
  };
77
80
  }, [playerId, playerController]);
78
81
 
82
+ useEffect(() => {
83
+ if (!isTV()) {
84
+ return;
85
+ }
86
+
87
+ if (playerController) {
88
+ const seekController = new TVSeekController(playerController);
89
+ playerController.seekController = seekController;
90
+
91
+ return KeyInputHandler.getInstance().addListener(seekController);
92
+ }
93
+ }, [playerController]);
94
+
79
95
  return playerController;
80
96
  };
@@ -0,0 +1,24 @@
1
+ import { allTruthy } from "..";
2
+
3
+ describe("allTruthy", () => {
4
+ it("should return true when all values are true", () => {
5
+ expect(allTruthy([true, true, true])).toBe(true);
6
+ });
7
+
8
+ it("should return false when at least one value is false", () => {
9
+ expect(allTruthy([true, false, true])).toBe(false);
10
+ });
11
+
12
+ it("should return false when all values are false", () => {
13
+ expect(allTruthy([false, false, false])).toBe(false);
14
+ });
15
+
16
+ it("should return false for an empty array", () => {
17
+ expect(allTruthy([])).toBe(false);
18
+ });
19
+
20
+ it("should handle single-element arrays correctly", () => {
21
+ expect(allTruthy([true])).toBe(true);
22
+ expect(allTruthy([false])).toBe(false);
23
+ });
24
+ });
@@ -0,0 +1,24 @@
1
+ import { anyTruthy } from "..";
2
+
3
+ describe("anyTruthy", () => {
4
+ it("should return true when at least one value is true", () => {
5
+ expect(anyTruthy([false, true, false])).toBe(true);
6
+ });
7
+
8
+ it("should return false when all values are false", () => {
9
+ expect(anyTruthy([false, false, false])).toBe(false);
10
+ });
11
+
12
+ it("should return true when all values are true", () => {
13
+ expect(anyTruthy([true, true, true])).toBe(true);
14
+ });
15
+
16
+ it("should return false for an empty array", () => {
17
+ expect(anyTruthy([])).toBe(false);
18
+ });
19
+
20
+ it("should handle single-element arrays correctly", () => {
21
+ expect(anyTruthy([true])).toBe(true);
22
+ expect(anyTruthy([false])).toBe(false);
23
+ });
24
+ });
@@ -0,0 +1,63 @@
1
+ import { isEmptyArray } from "..";
2
+
3
+ describe("isEmptyArray", () => {
4
+ it("non-empty array is not empty", () => {
5
+ const value = [1, 2, 3];
6
+
7
+ expect(isEmptyArray(value)).toBe(false);
8
+ });
9
+
10
+ it("empty array is empty", () => {
11
+ const value = [];
12
+
13
+ expect(isEmptyArray(value)).toBe(true);
14
+ });
15
+
16
+ it("number is not array", () => {
17
+ const value = 123;
18
+
19
+ expect(isEmptyArray(value)).toBe(false);
20
+ });
21
+
22
+ it("string is not array", () => {
23
+ const value = "vfnjdk";
24
+
25
+ expect(isEmptyArray(value)).toBe(false);
26
+ });
27
+
28
+ it("empty string is not array", () => {
29
+ const value = "";
30
+
31
+ expect(isEmptyArray(value)).toBe(false);
32
+ });
33
+
34
+ it("NaN is not array", () => {
35
+ const value = NaN;
36
+
37
+ expect(isEmptyArray(value)).toBe(false);
38
+ });
39
+
40
+ it("object is not array", () => {
41
+ const value = { test: 1 };
42
+
43
+ expect(isEmptyArray(value)).toBe(false);
44
+ });
45
+
46
+ it("empty object is not array", () => {
47
+ const value = {};
48
+
49
+ expect(isEmptyArray(value)).toBe(false);
50
+ });
51
+
52
+ it("undefined is not array", () => {
53
+ const value = undefined;
54
+
55
+ expect(isEmptyArray(value)).toBe(false);
56
+ });
57
+
58
+ it("null is not array", () => {
59
+ const value = null;
60
+
61
+ expect(isEmptyArray(value)).toBe(false);
62
+ });
63
+ });
@@ -32,7 +32,7 @@ describe("isFilledArray", () => {
32
32
  });
33
33
 
34
34
  it("NaN is not array", () => {
35
- const value = "";
35
+ const value = NaN;
36
36
 
37
37
  expect(isFilledArray(value)).toBe(false);
38
38
  });
@@ -93,21 +93,31 @@ export const isIndexInRange = (index: number, length: number): boolean => {
93
93
  export const makeListOfIndexes = (size: number): number[] =>
94
94
  Array.from({ length: size }, (_, index) => index);
95
95
 
96
- export const makeListOf = (value: unknown, size: number): number[] => {
96
+ export const makeListOf = <T>(value: T, size: number): T[] => {
97
97
  return Array(size).fill(value);
98
98
  };
99
99
 
100
100
  /** Checks if a value is a non-empty array */
101
101
  export function isFilledArray(value: unknown): boolean {
102
- return R.is(Array, value) && R.length(value) > 0;
102
+ return Array.isArray(value) && value.length > 0;
103
+ }
104
+
105
+ /** Checks if a value is a empty array */
106
+ export function isEmptyArray(value: unknown): boolean {
107
+ return Array.isArray(value) && value.length === 0;
103
108
  }
104
109
 
105
110
  // get random item from the list
106
111
  export const sample = (xs: unknown[]): unknown => {
107
- invariant(R.is(Array, xs), `input value is not a array: ${xs}`);
112
+ invariant(Array.isArray(xs), `input value is not an array: ${xs}`);
108
113
  invariant(isFilledArray(xs), `input array is empty: ${xs}`);
109
114
 
110
115
  const index = Math.floor(Math.random() * xs.length);
111
116
 
112
117
  return xs[index];
113
118
  };
119
+
120
+ export const allTruthy = (xs: boolean[]) =>
121
+ isFilledArray(xs) && xs.every(Boolean);
122
+
123
+ export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
@@ -0,0 +1,144 @@
1
+ import { getArtworkImage } from "..";
2
+ import { DEFAULT_IMAGE } from "../assets";
3
+
4
+ describe("getArtworkImage", () => {
5
+ const entryWithImage = {
6
+ media_group: [
7
+ {
8
+ type: "image",
9
+ media_item: [
10
+ { key: "artwork_key", src: "image_from_entry" },
11
+ { key: "other_key", src: "other_image" },
12
+ ],
13
+ },
14
+ ],
15
+ extensions: {
16
+ artwork_key: "artwork_key",
17
+ },
18
+ };
19
+
20
+ const entryWithoutImage = {
21
+ media_group: [
22
+ {
23
+ type: "image",
24
+ media_item: [{ key: "other_key", src: "other_image" }],
25
+ },
26
+ ],
27
+ extensions: {
28
+ artwork_key: "artwork_key",
29
+ },
30
+ };
31
+
32
+ const pluginConfigWithImage = {
33
+ artwork_key: "plugin_artwork_key",
34
+ };
35
+
36
+ it("returns image from entry extensions key", () => {
37
+ const result = getArtworkImage({
38
+ key: "artwork_key",
39
+ entry: entryWithImage,
40
+ plugin_configuration: {},
41
+ });
42
+
43
+ expect(result).toBe("image_from_entry");
44
+ });
45
+
46
+ it("returns image from plugin configuration key if not in entry", () => {
47
+ const entryNoMatch = {
48
+ ...entryWithoutImage,
49
+ extensions: { artwork_key: "not_found_key" },
50
+ };
51
+
52
+ const pluginConfig = {
53
+ artwork_key: "plugin_artwork_key",
54
+ };
55
+
56
+ const entryWithPluginImage = {
57
+ ...entryNoMatch,
58
+ media_group: [
59
+ {
60
+ type: "image",
61
+ media_item: [{ key: "plugin_artwork_key", src: "image_from_plugin" }],
62
+ },
63
+ ],
64
+ };
65
+
66
+ const result = getArtworkImage({
67
+ key: "artwork_key",
68
+ entry: entryWithPluginImage,
69
+ plugin_configuration: pluginConfig,
70
+ });
71
+
72
+ expect(result).toBe("image_from_plugin");
73
+ });
74
+
75
+ it("returns DEFAULT_IMAGE if neither entry nor plugin configuration has image", () => {
76
+ const entryNoImage = {
77
+ media_group: [
78
+ {
79
+ type: "image",
80
+ media_item: [{ key: "other_key", src: "other_image" }],
81
+ },
82
+ ],
83
+ extensions: { artwork_key: "not_found_key" },
84
+ };
85
+
86
+ const pluginConfig = { artwork_key: "not_found_key" };
87
+
88
+ const result = getArtworkImage({
89
+ key: "artwork_key",
90
+ entry: entryNoImage,
91
+ plugin_configuration: pluginConfig,
92
+ });
93
+
94
+ expect(result).toBe(DEFAULT_IMAGE);
95
+ });
96
+
97
+ it("handles undefined key gracefully", () => {
98
+ const result = getArtworkImage({
99
+ key: undefined,
100
+ entry: entryWithImage,
101
+ plugin_configuration: pluginConfigWithImage,
102
+ });
103
+
104
+ expect(result).toBe(DEFAULT_IMAGE);
105
+ });
106
+
107
+ it("handles missing entry or plugin_configuration gracefully", () => {
108
+ const result = getArtworkImage({
109
+ key: "artwork_key",
110
+ entry: undefined,
111
+ plugin_configuration: undefined,
112
+ });
113
+
114
+ expect(result).toBe(DEFAULT_IMAGE);
115
+ });
116
+
117
+ it("handles empty media_group", () => {
118
+ const entryEmptyMedia = {
119
+ media_group: [],
120
+ extensions: { artwork_key: "artwork_key" },
121
+ };
122
+
123
+ const result = getArtworkImage({
124
+ key: "artwork_key",
125
+ entry: entryEmptyMedia,
126
+ plugin_configuration: pluginConfigWithImage,
127
+ });
128
+
129
+ expect(result).toBe(DEFAULT_IMAGE);
130
+ });
131
+
132
+ it("handles missing extensions/config keys", () => {
133
+ const entryNoExt = { media_group: [], extensions: {} };
134
+ const pluginConfig = {};
135
+
136
+ const result = getArtworkImage({
137
+ key: "artwork_key",
138
+ entry: entryNoExt,
139
+ plugin_configuration: pluginConfig,
140
+ });
141
+
142
+ expect(result).toBe(DEFAULT_IMAGE);
143
+ });
144
+ });