@applicaster/zapp-react-native-utils 14.0.0-alpha.7900711229 → 14.0.0-alpha.9567513212

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 (47) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +83 -60
  2. package/appUtils/contextKeysManager/contextResolver.ts +1 -14
  3. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  4. package/arrayUtils/index.ts +2 -7
  5. package/configurationUtils/__tests__/configurationUtils.test.js +31 -0
  6. package/configurationUtils/index.ts +34 -63
  7. package/manifestUtils/{_internals/index.js → _internals.js} +25 -2
  8. package/manifestUtils/createConfig.js +1 -4
  9. package/manifestUtils/defaultManifestConfigurations/player.js +200 -1231
  10. package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +30 -0
  11. package/package.json +2 -2
  12. package/playerUtils/__tests__/configurationUtils.test.ts +65 -1
  13. package/playerUtils/configurationGenerator.ts +2572 -0
  14. package/playerUtils/configurationUtils.ts +44 -0
  15. package/playerUtils/index.ts +51 -2
  16. package/playerUtils/useValidatePlayerConfig.tsx +19 -22
  17. package/reactHooks/cell-click/index.ts +1 -8
  18. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +0 -20
  19. package/reactHooks/feed/useBatchLoading.ts +2 -2
  20. package/reactHooks/feed/useFeedLoader.tsx +5 -12
  21. package/reactHooks/navigation/useRoute.ts +2 -7
  22. package/utils/index.ts +1 -12
  23. package/actionsExecutor/ScreenActions.ts +0 -163
  24. package/actionsExecutor/StorageActions.ts +0 -110
  25. package/actionsExecutor/feedDecorator.ts +0 -171
  26. package/actionsExecutor/screenResolver.ts +0 -11
  27. package/arrayUtils/__tests__/isEmptyArray.test.ts +0 -63
  28. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +0 -144
  29. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +0 -72
  30. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +0 -110
  31. package/audioPlayerUtils/assets/index.ts +0 -2
  32. package/audioPlayerUtils/index.ts +0 -242
  33. package/conf/player/__tests__/selectors.test.ts +0 -34
  34. package/conf/player/selectors.ts +0 -10
  35. package/configurationUtils/__tests__/getMediaItems.test.ts +0 -65
  36. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +0 -34
  37. package/manifestUtils/_internals/getDefaultConfiguration.js +0 -28
  38. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  39. package/playerUtils/_internals/__tests__/utils.test.ts +0 -71
  40. package/playerUtils/_internals/index.ts +0 -1
  41. package/playerUtils/_internals/utils.ts +0 -31
  42. package/playerUtils/getPlayerActionButtons.ts +0 -17
  43. package/reactHooks/navigation/useScreenStateStore.ts +0 -11
  44. package/storage/ScreenSingleValueProvider.ts +0 -197
  45. package/storage/ScreenStateMultiSelectProvider.ts +0 -282
  46. package/storage/StorageMultiSelectProvider.ts +0 -192
  47. package/storage/StorageSingleSelectProvider.ts +0 -108
@@ -16,6 +16,7 @@ import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickB
16
16
  import { showConfirmationDialog } from "../alertUtils";
17
17
  import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
18
18
  import { createLogger } from "../logger";
19
+ import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
19
20
  import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
20
21
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
21
22
  import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
@@ -24,19 +25,15 @@ import {
24
25
  resolveObjectValues,
25
26
  } from "../appUtils/contextKeysManager/contextResolver";
26
27
  import { useNavigation } from "../reactHooks";
28
+ import { get } from "lodash";
27
29
 
28
30
  import {
29
31
  useContentTypes,
30
32
  usePickFromState,
31
33
  } from "@applicaster/zapp-react-native-redux/hooks";
32
- import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
34
+ import { TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT } from "./consts";
35
+ import { postEvent, useSubscriberFor } from "../reactHooks/useSubscriberFor";
33
36
  import { APP_EVENTS } from "../appUtils/events";
34
- import {
35
- localStorageToggleFlag,
36
- sessionStorageToggleFlag,
37
- } from "./StorageActions";
38
-
39
- import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
40
37
 
41
38
  export const { log_error, log_info, log_debug } = createLogger({
42
39
  subsystem: "ActionExecutorContext",
@@ -85,6 +82,19 @@ function findParentComponent(
85
82
  return null;
86
83
  }
87
84
 
85
+ // send all data just in case (like for message string formatting)
86
+ // Type is not exported for now
87
+ type MaxTagsReachedEvent = {
88
+ selectedItems: string[];
89
+ maxItems: number;
90
+ tag: string;
91
+ keyNamespace: string;
92
+ };
93
+
94
+ async function onMaxTagsReached(data: MaxTagsReachedEvent) {
95
+ postEvent(TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT, [data]);
96
+ }
97
+
88
98
  const prepareDefaultActions = (actionExecutor) => {
89
99
  actionExecutor.registerAction("localStorageSet", async (action) => {
90
100
  const namespaces = action.options.content;
@@ -168,15 +178,10 @@ const prepareDefaultActions = (actionExecutor) => {
168
178
 
169
179
  const entry = context?.entry || {};
170
180
  const entryResolver = new EntryResolver(entry);
171
- const screenData = context?.screenStateStore.getState().data || {};
172
- const screenResolver = new EntryResolver(screenData || {});
173
181
 
174
182
  const data =
175
183
  options?.data && options.inflateData
176
- ? await resolveObjectValues(options.data, {
177
- entry: entryResolver,
178
- screen: screenResolver,
179
- })
184
+ ? await resolveObjectValues(options.data, { entry: entryResolver })
180
185
  : options?.data || entry;
181
186
 
182
187
  const cloudEvent = await createCloudEvent({
@@ -210,63 +215,81 @@ const prepareDefaultActions = (actionExecutor) => {
210
215
  return ActionResult.Error;
211
216
  });
212
217
 
213
- actionExecutor.registerAction(
214
- "sessionStorageToggleFlag",
215
- async (
216
- action: ActionType,
217
- context?: Record<string, any>
218
- ): Promise<ActionResult> => {
219
- return await sessionStorageToggleFlag(context, action);
220
- }
221
- );
222
-
223
218
  actionExecutor.registerAction(
224
219
  "localStorageToggleFlag",
225
220
  async (
226
221
  action: ActionType,
227
222
  context?: Record<string, any>
228
223
  ): Promise<ActionResult> => {
229
- return await localStorageToggleFlag(context, action);
230
- }
231
- );
224
+ if (!context) {
225
+ log_error(
226
+ "handleAction: localStorageToggleFlag action missing context"
227
+ );
232
228
 
233
- actionExecutor.registerAction(
234
- "screenSetVariable",
235
- async (
236
- action: ActionType,
237
- context?: Record<string, any>
238
- ): Promise<ActionResult> => {
239
- const route = context?.screenRoute;
240
- const screenStateStore = context?.screenStateStore;
241
-
242
- await screenSetVariable(
243
- route,
244
- screenStateStore,
245
- { entry: context?.entry, options: action.options },
246
- action
247
- );
229
+ return ActionResult.Error;
230
+ }
248
231
 
249
- return Promise.resolve(ActionResult.Success);
250
- }
251
- );
232
+ const entry = context?.entry as ZappEntry;
252
233
 
253
- actionExecutor.registerAction(
254
- "screenToggleFlag",
255
- async (
256
- action: ActionType,
257
- context?: Record<string, any>
258
- ): Promise<ActionResult> => {
259
- const screenRoute = context?.screenRoute;
260
- const screenStateStore = context?.screenStateStore;
261
-
262
- await screenToggleFlag(
263
- screenRoute,
264
- screenStateStore,
265
- { entry: context?.entry, options: action.options },
266
- action
267
- );
234
+ if (!entry) {
235
+ log_error(
236
+ "handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
237
+ );
238
+
239
+ return ActionResult.Error;
240
+ }
241
+
242
+ const tag = action.options?.selector
243
+ ? get(entry, action.options.selector)
244
+ : (entry.extensions?.tag ?? entry.id);
245
+
246
+ const keyNamespace = action.options?.key;
247
+
248
+ if (keyNamespace && tag) {
249
+ const multiSelectProvider =
250
+ StorageMultiSelectProvider.getProvider(keyNamespace);
251
+
252
+ const selectedItems = await multiSelectProvider.getSelectedAsync();
253
+ const isTagInSelectedItems = selectedItems.includes(tag);
268
254
 
269
- return Promise.resolve(ActionResult.Success);
255
+ log_info(
256
+ `handleAction: localStorageToggleFlag event will ${
257
+ isTagInSelectedItems ? "remove" : "add"
258
+ } tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
259
+ );
260
+
261
+ if (selectedItems.includes(tag)) {
262
+ await multiSelectProvider.removeItem(tag);
263
+ } else {
264
+ const maxItems = action.options?.max_items;
265
+
266
+ if (maxItems && selectedItems.length >= maxItems) {
267
+ log_info(
268
+ `handleAction: localStorageToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
269
+ );
270
+
271
+ await onMaxTagsReached({
272
+ selectedItems,
273
+ maxItems,
274
+ tag,
275
+ keyNamespace,
276
+ });
277
+
278
+ return ActionResult.Cancel;
279
+ }
280
+
281
+ await multiSelectProvider.addItem(tag);
282
+ }
283
+ } else {
284
+ log_error(
285
+ "handleAction: localStorageToggleFlag event missing keyNamespace or tag",
286
+ { keyNamespace, tag }
287
+ );
288
+
289
+ return ActionResult.Error;
290
+ }
291
+
292
+ return ActionResult.Success;
270
293
  }
271
294
  );
272
295
  };
@@ -1,11 +1,10 @@
1
1
  import { ContextKeysManager } from "./index";
2
2
  import * as R from "ramda";
3
3
 
4
- export interface IResolver {
4
+ interface IResolver {
5
5
  resolve: (string) => Promise<string | number | object>;
6
6
  }
7
7
 
8
- // TODO: Rename to ObjectKeyResolver or similar
9
8
  export class EntryResolver implements IResolver {
10
9
  entry: ZappEntry;
11
10
 
@@ -22,18 +21,6 @@ export class EntryResolver implements IResolver {
22
21
  }
23
22
  }
24
23
 
25
- // TODO: Move to proper place
26
-
27
- export class ScreenStateResolver implements IResolver {
28
- constructor(private screenStateStore: ScreenStateStore) {}
29
-
30
- async resolve(key: string) {
31
- const screenState = this.screenStateStore.getState().data;
32
-
33
- return screenState?.[key];
34
- }
35
- }
36
-
37
24
  export class ContextResolver implements IResolver {
38
25
  resolve = async (compositeKey: string) =>
39
26
  ContextKeysManager.instance.getKey(compositeKey);
@@ -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)));