@applicaster/zapp-react-native-utils 14.0.0-alpha.1235043154 → 14.0.0-alpha.1355728993

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 (40) hide show
  1. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  2. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +1 -2
  3. package/analyticsUtils/index.tsx +4 -3
  4. package/analyticsUtils/manager.ts +1 -1
  5. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  6. package/arrayUtils/index.ts +2 -7
  7. package/configurationUtils/__tests__/configurationUtils.test.js +31 -0
  8. package/configurationUtils/index.ts +34 -63
  9. package/manifestUtils/{_internals/index.js → _internals.js} +25 -2
  10. package/manifestUtils/createConfig.js +1 -4
  11. package/manifestUtils/defaultManifestConfigurations/player.js +200 -1231
  12. package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +30 -0
  13. package/package.json +2 -2
  14. package/playerUtils/__tests__/configurationUtils.test.ts +65 -1
  15. package/playerUtils/configurationGenerator.ts +2572 -0
  16. package/playerUtils/configurationUtils.ts +44 -0
  17. package/playerUtils/index.ts +51 -2
  18. package/playerUtils/useValidatePlayerConfig.tsx +19 -22
  19. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +13 -12
  20. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +88 -39
  21. package/reactHooks/feed/useBatchLoading.ts +2 -2
  22. package/reactHooks/navigation/index.ts +2 -2
  23. package/testUtils/index.tsx +8 -7
  24. package/utils/index.ts +1 -12
  25. package/arrayUtils/__tests__/isEmptyArray.test.ts +0 -63
  26. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +0 -144
  27. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +0 -72
  28. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +0 -110
  29. package/audioPlayerUtils/assets/index.ts +0 -2
  30. package/audioPlayerUtils/index.ts +0 -242
  31. package/conf/player/__tests__/selectors.test.ts +0 -34
  32. package/conf/player/selectors.ts +0 -10
  33. package/configurationUtils/__tests__/getMediaItems.test.ts +0 -65
  34. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +0 -34
  35. package/manifestUtils/_internals/getDefaultConfiguration.js +0 -28
  36. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  37. package/playerUtils/_internals/__tests__/utils.test.ts +0 -71
  38. package/playerUtils/_internals/index.ts +0 -1
  39. package/playerUtils/_internals/utils.ts +0 -31
  40. package/playerUtils/getPlayerActionButtons.ts +0 -17
@@ -4,7 +4,7 @@ import { postAnalyticEvent } from "../manager";
4
4
  import { ANALYTICS_CORE_EVENTS } from "../events";
5
5
 
6
6
  type SendHeaderClickEventProps = {
7
- extraProps: Record<string, any>;
7
+ extraProps: ExtraProps;
8
8
  component?: ZappUIComponent;
9
9
  zappPipesData?: ZappPipesData;
10
10
  item?: ZappEntry;
@@ -1,11 +1,10 @@
1
- /// <reference types="../../" />
2
1
  import { log_error, log_debug } from "../logger";
3
2
  import { replaceAnalyticsPropsNils } from "./helper";
4
3
  import { postAnalyticEvent } from "../manager";
5
4
 
6
5
  import { ANALYTICS_CORE_EVENTS } from "../events";
7
6
 
8
- type AnalyticsDefaultHelperProperties = {
7
+ declare type AnalyticsDefaultHelperProperties = {
9
8
  analyticsScreenData: AnalyticsScreenProperties;
10
9
  extraProps: any;
11
10
  props;
@@ -1,3 +1,4 @@
1
+ /// <reference types="@applicaster/zapp-react-native-utils" />
1
2
  import * as R from "ramda";
2
3
  import * as React from "react";
3
4
  import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
@@ -30,7 +31,7 @@ import { ANALYTICS_CORE_EVENTS } from "./events";
30
31
  import { noop } from "../functionUtils";
31
32
 
32
33
  type ComponentWithChildrenProps = {
33
- children: React.ReactElement;
34
+ children: React.ReactChildren;
34
35
  };
35
36
 
36
37
  export function sendSelectCellEvent(item, component, headerTitle, itemIndex) {
@@ -119,11 +120,11 @@ export function getAnalyticsFunctions({
119
120
  export const AnalyticsContext =
120
121
  React.createContext<GetAnalyticsFunctions>(noop);
121
122
 
122
- export function AnalyticsProvider({ children }: ComponentWithChildrenProps) {
123
+ export function AnalyticsProvider(props: ComponentWithChildrenProps) {
123
124
  return (
124
125
  // @ts-ignore - this is a valid context provider
125
126
  <AnalyticsContext.Provider value={getAnalyticsFunctions}>
126
- {children}
127
+ {props?.children}
127
128
  </AnalyticsContext.Provider>
128
129
  );
129
130
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
2
  import * as R from "ramda";
3
3
  import { NativeModules } from "react-native";
4
- import { ANALYTICS_CORE_EVENTS } from "./events";
4
+ import { ANALYTICS_CORE_EVENTS } from "@applicaster/zapp-react-native-utils/analyticsUtils/events";
5
5
 
6
6
  import { analyticsUtilsLogger } from "./logger";
7
7
 
@@ -32,7 +32,7 @@ describe("isFilledArray", () => {
32
32
  });
33
33
 
34
34
  it("NaN is not array", () => {
35
- const value = NaN;
35
+ const value = "";
36
36
 
37
37
  expect(isFilledArray(value)).toBe(false);
38
38
  });
@@ -99,17 +99,12 @@ export const makeListOf = (value: unknown, size: number): number[] => {
99
99
 
100
100
  /** Checks if a value is a non-empty array */
101
101
  export function isFilledArray(value: unknown): boolean {
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;
102
+ return R.is(Array, value) && R.length(value) > 0;
108
103
  }
109
104
 
110
105
  // get random item from the list
111
106
  export const sample = (xs: unknown[]): unknown => {
112
- invariant(Array.isArray(xs), `input value is not an array: ${xs}`);
107
+ invariant(R.is(Array, xs), `input value is not a array: ${xs}`);
113
108
  invariant(isFilledArray(xs), `input array is empty: ${xs}`);
114
109
 
115
110
  const index = Math.floor(Math.random() * xs.length);
@@ -1,8 +1,11 @@
1
+ import * as R from "ramda";
1
2
  import {
2
3
  populateConfigurationValues,
4
+ imageSrcFromMediaItem,
3
5
  getBoolFromConfigValue,
4
6
  remapUpdatedKeys,
5
7
  } from "../";
8
+ import { entry } from "./testEntry";
6
9
 
7
10
  describe("getBoolFromConfigValue", () => {
8
11
  it('returns true if value is "true" string', () => {
@@ -54,6 +57,34 @@ describe("getBoolFromConfigValue", () => {
54
57
  });
55
58
  });
56
59
 
60
+ describe("imageSrcFromMediaItem", () => {
61
+ describe("returns the src value of first media_item", () => {
62
+ it("when the matching key is found and the src is not empty", () => {
63
+ const result = imageSrcFromMediaItem(entry, ["logo_thumbnail"]);
64
+
65
+ expect(result).toEqual(entry.media_group[1].media_item[0].src);
66
+ expect(result).not.toEqual("");
67
+ });
68
+ });
69
+
70
+ it("returns a media item with the 'image_base' key as a fallback", () => {
71
+ const result = imageSrcFromMediaItem(entry, ["does_not_exist"]);
72
+ const fallback = entry.media_group[0].media_item[0];
73
+ expect(result).toEqual(fallback.src);
74
+ expect(fallback.key).toBe("image_base");
75
+ });
76
+
77
+ it("returns undefined if the key was found but the source was empty", () => {
78
+ const badEntry = R.set(
79
+ R.lensPath(["media_group", 0, "media_item", 0, "src"]),
80
+ "",
81
+ entry
82
+ );
83
+
84
+ expect(imageSrcFromMediaItem(badEntry, ["image_base"])).toBeUndefined();
85
+ });
86
+ });
87
+
57
88
  describe("populateConfigurationValues", () => {
58
89
  it("transforms and returns the valid values", () => {
59
90
  const fields = [
@@ -1,12 +1,6 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import * as R from "ramda";
3
3
  import { Platform } from "react-native";
4
- import {
5
- isFilledArray,
6
- isEmptyArray,
7
- } from "@applicaster/zapp-react-native-utils/arrayUtils";
8
- import { isEmpty } from "@applicaster/zapp-react-native-utils/utils";
9
-
10
4
  import { applyTransform } from "../transform";
11
5
  import { ManifestField } from "../types";
12
6
  import { isNilOrEmpty } from "../reactUtils/helpers";
@@ -128,77 +122,54 @@ export function flattenFields(
128
122
  }
129
123
 
130
124
  /**
131
- * Retrieves all media items from the entry's media_group that are of type "image" or "thumbnail".
132
- *
133
- * @param {ZappEntry} entry - The entry object containing the media_group array.
134
- * @returns {Option<ZappMediaItem[]>} An array of media items of type "image" or "thumbnail", or undefined if no media_group is present.
135
- */
136
- export function getMediaItems(entry: ZappEntry): Option<ZappMediaItem[]> {
137
- const mediaGroup = entry?.media_group || [];
138
-
139
- if (isEmptyArray(mediaGroup)) {
140
- return undefined;
141
- }
142
-
143
- const mediaItems = mediaGroup
144
- .filter((group) => ["image", "thumbnail"].includes(group.type))
145
- .flatMap((group) =>
146
- Array.isArray(group.media_item) ? group.media_item : [group.media_item]
147
- );
148
-
149
- if (isFilledArray(mediaItems)) {
150
- return mediaItems;
151
- }
152
-
153
- return undefined;
154
- }
155
-
156
- /**
157
- * Retrieves the "src" value from a media item in the entry's media group,
158
- * based on a provided key, with fallback logic.
159
- *
160
- * Fallback order:
161
- * 1. Attempts to find a media item with the specified key (or "image_base" if none provided).
162
- * 2. If not found, attempts to find a media item with the key "image_base".
163
- * 3. If still not found, falls back to the first available media item.
164
- *
165
- * Special handling: If the resolved item's "src" is an empty string, returns undefined,
166
- * since empty URIs are invalid in some platforms (e.g., React Native).
167
- *
168
- * @param {ZappEntry} entry - The entry object containing a media group.
169
- * @param {string[] | unknown} arg - A single-element array containing the key to look up, or any unknown value.
170
- * @returns {?string} The "src" URI from the matched media item, or undefined if not found or empty.
125
+ * Retrieves the value of the "src" in the first media_item
126
+ * that has the matching key provided in args.
127
+ * Fallbacks: "image_base" key, or first media_item that has any "src"
128
+ * @param {Object} entry Single entry from a feed
129
+ * @param {Array} arg Array with a single element - the key of the media item
130
+ * from which the "src" should be retrieved
131
+ * @returns {?String} Value of "src", usually a URI
171
132
  */
172
133
  export function imageSrcFromMediaItem(
173
134
  entry: ZappEntry,
174
135
  arg: string[] | unknown
175
- ): Option<string> {
136
+ ) {
176
137
  const args: unknown = R.unless(Array.isArray, Array)(arg || []);
177
138
  const imageKey: string = args?.[0] || "image_base"; // always a single key in this function
139
+ const mediaGroup = R.path<ZappMediaGroup[]>(["media_group"], entry);
178
140
 
179
- const mediaItems = getMediaItems(entry);
180
-
181
- if (!mediaItems) {
141
+ if (!mediaGroup) {
182
142
  return undefined;
183
143
  }
184
144
 
185
- // Try to find the item with the given key
186
- let foundItem = mediaItems.find((item) => item.key === imageKey);
145
+ const hasTypeImageOrThumbnail = R.either(
146
+ R.propEq("type", "image"),
147
+ R.propEq("type", "thumbnail")
148
+ );
149
+
150
+ const pickMediaItemProp = R.prop<ZappMediaItem>("media_item");
187
151
 
188
- // If not found and key was not "image_base", try to find "image_base"
189
- if (!foundItem && imageKey !== "image_base") {
190
- foundItem = mediaItems.find((item) => item.key === "image_base");
191
- }
152
+ const mediaItems = R.compose(
153
+ R.flatten,
154
+ R.map(pickMediaItemProp),
155
+ R.filter(hasTypeImageOrThumbnail)
156
+ )(mediaGroup);
192
157
 
193
- // If still not found, default to first item
194
- if (!foundItem) {
195
- foundItem = mediaItems[0];
158
+ if (!mediaItems) {
159
+ return undefined;
196
160
  }
197
161
 
198
- const src = foundItem?.src;
199
-
200
- // React Native quirk: empty string is invalid for URIs
201
- return isEmpty(src) ? undefined : src;
162
+ const src = R.compose(
163
+ R.prop("src"),
164
+ R.defaultTo(R.head(mediaItems)),
165
+ R.when(R.isNil, () => R.find(R.propEq("key", "image_base"), mediaItems)),
166
+ R.find(R.propEq("key", imageKey))
167
+ )(mediaItems);
168
+
169
+ // Special case for react native - uri cannot be an empty string (yellow warning).
170
+ // R.isEmpty is tailored specifically for checks like these,
171
+ // it returns false for undefined values.
172
+ return R.isEmpty(src) ? undefined : src;
202
173
  }
203
174
 
204
175
  /**
@@ -1,7 +1,6 @@
1
1
  const R = require("ramda");
2
2
  const camelize = require("camelize");
3
-
4
- const { getDefaultConfiguration } = require("./getDefaultConfiguration");
3
+ const { defaultConfigurations } = require("./defaultManifestConfigurations");
5
4
 
6
5
  const toSnakeCase = R.compose(R.replace(/\s/g, "_"), R.toLower, R.trim);
7
6
 
@@ -174,6 +173,30 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
174
173
  )(fields);
175
174
  }
176
175
 
176
+ /**
177
+ * returns default configuration keys for provided plugin type
178
+ * @param {('general-content'|'player')} pluginType
179
+ * @param options manifest generator information
180
+ * @param {string} options.version manifest version
181
+ * @param {string} options.platform qb platform value
182
+ */
183
+ function getDefaultConfiguration(pluginType, options) {
184
+ const defConfig = R.compose(
185
+ R.unless(R.isNil, (fn) => fn(options)),
186
+ R.propOr(null, pluginType)
187
+ )(defaultConfigurations);
188
+
189
+ if (!defConfig) {
190
+ const availableKeys = R.keys(defaultConfigurations);
191
+
192
+ const message = `Requested key "${pluginType}" doesn't exist in the default configuration\nAvailable keys: ${availableKeys}`;
193
+ // eslint-disable-next-line no-console
194
+ console.warn(message);
195
+ }
196
+
197
+ return defConfig;
198
+ }
199
+
177
200
  module.exports = {
178
201
  toSnakeCase,
179
202
  toCamelCase,
@@ -1,8 +1,5 @@
1
1
  const R = require("ramda");
2
-
3
- const {
4
- getDefaultConfiguration,
5
- } = require("./_internals/getDefaultConfiguration");
2
+ const { getDefaultConfiguration } = require("./_internals");
6
3
 
7
4
  const indexByKey = R.indexBy((obj) => R.prop(obj.group ? "label" : "key", obj));
8
5
  const propIfExist = R.curry((prop) => R.when(R.prop(prop), R.prop(prop)));