@applicaster/zapp-react-native-utils 15.1.11-alpha.2710844646 → 15.1.11-alpha.5011222544

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 (69) hide show
  1. package/actionsExecutor/ActionExecutor.ts +2 -40
  2. package/actionsExecutor/ActionExecutorContext.tsx +32 -70
  3. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  4. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  5. package/actionsExecutor/actions/goBack.ts +60 -0
  6. package/actionsExecutor/actions/goHome.ts +31 -0
  7. package/actionsExecutor/actions/index.ts +3 -3
  8. package/actionsExecutor/actions/refreshComponent.ts +0 -6
  9. package/actionsExecutor/actions/sendCloudEvent.ts +1 -6
  10. package/actionsExecutor/consts.ts +0 -23
  11. package/actionsExecutor/types.ts +1 -1
  12. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +2 -5
  13. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +2 -55
  14. package/appUtils/playerManager/OverlayObserver/utils.ts +20 -51
  15. package/arrayUtils/index.ts +0 -79
  16. package/configurationUtils/manifestKeyParser.ts +9 -38
  17. package/manifestUtils/_internals/index.js +8 -3
  18. package/manifestUtils/defaultManifestConfigurations/player.js +1 -22
  19. package/manifestUtils/index.js +0 -3
  20. package/modalState/index.ts +83 -30
  21. package/package.json +2 -2
  22. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
  23. package/playerUtils/getPlayerActionButtons.ts +17 -0
  24. package/playerUtils/index.ts +1 -17
  25. package/reactHooks/actions/index.ts +2 -67
  26. package/reactHooks/usePluginConfiguration.ts +3 -6
  27. package/uiActionsRegistrator/index.ts +203 -25
  28. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +0 -22
  29. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +0 -88
  30. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +0 -76
  31. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +0 -100
  32. package/actionsExecutor/actions/dismissBottomSheet.ts +0 -22
  33. package/actionsExecutor/actions/openBottomSheet.ts +0 -320
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +0 -4
  35. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +0 -4
  36. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +0 -11
  37. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +0 -4
  38. package/arrayUtils/__tests__/reorderByIds.test.ts +0 -50
  39. package/configurationUtils/__tests__/modalBlocksParser.test.ts +0 -107
  40. package/configurationUtils/modalBlocksParser.ts +0 -178
  41. package/entryActions/__tests__/buildEntryActions.test.ts +0 -156
  42. package/entryActions/aliasPresentation.ts +0 -124
  43. package/entryActions/buildEntryActions.ts +0 -166
  44. package/entryActions/index.ts +0 -17
  45. package/entryActions/types.ts +0 -39
  46. package/manifestUtils/modalBlocks.js +0 -304
  47. package/modalState/ContentViewModel.ts +0 -113
  48. package/modalState/EditableCollection.ts +0 -17
  49. package/modalState/EditableCollectionRegistry.ts +0 -51
  50. package/modalState/ModalOrchestrator.ts +0 -199
  51. package/modalState/RemoteEditableCollection.ts +0 -227
  52. package/modalState/__tests__/ContentViewModel.editable.test.ts +0 -69
  53. package/modalState/__tests__/ContentViewModel.test.ts +0 -165
  54. package/modalState/__tests__/EditableCollectionRegistry.test.ts +0 -112
  55. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +0 -47
  56. package/modalState/__tests__/RemoteEditableCollection.test.ts +0 -326
  57. package/modalState/__tests__/useBottomSheetContent.test.ts +0 -349
  58. package/modalState/store.ts +0 -102
  59. package/modalState/types.ts +0 -133
  60. package/modalState/useBottomSheetContent.ts +0 -102
  61. package/playerUtils/__tests__/resolvePlayerActions.test.ts +0 -138
  62. package/playerUtils/resolvePlayerActions.ts +0 -71
  63. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +0 -93
  64. package/uiActionsRegistrator/__tests__/subscribe.test.ts +0 -107
  65. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +0 -52
  66. package/uiActionsRegistrator/registry.ts +0 -335
  67. package/uiActionsRegistrator/resolveActionIdentifiers.ts +0 -100
  68. package/uiActionsRegistrator/usableActionItems.ts +0 -66
  69. /package/reactHooks/actions/__tests__/{index.test.tsx → index.test.js} +0 -0
@@ -12,7 +12,7 @@ const { log_error, log_debug, log_info } = createLogger({
12
12
  category: "General",
13
13
  });
14
14
 
15
- export class ActionExecutor {
15
+ class ActionExecutor {
16
16
  private registeredActions: Record<string, ActionHandler> = {};
17
17
 
18
18
  // TODO: Remove context
@@ -101,8 +101,7 @@ export class ActionExecutor {
101
101
 
102
102
  registerAction = <TOptions = Record<string, any>>(
103
103
  type: string,
104
- handler: ActionHandler<TOptions>,
105
- stateResolver?: (entry?: ZappEntry) => any
104
+ handler: ActionHandler<TOptions>
106
105
  ) => {
107
106
  if (this.registeredActions[type]) {
108
107
  log_error(`registerAction: action type: ${type} already registered`);
@@ -113,48 +112,11 @@ export class ActionExecutor {
113
112
  this.registeredActions[type] = handler;
114
113
  log_debug(`registerAction: action type: ${type} registered`);
115
114
 
116
- let unregisterState = () => {};
117
-
118
- if (stateResolver) {
119
- unregisterState = this.registerActionState(type, stateResolver);
120
- }
121
-
122
115
  return () => {
123
116
  this.unregisterAction(type);
124
- unregisterState();
125
117
  log_debug(`registerAction: action type: ${type} un-registered`);
126
118
  };
127
119
  };
128
-
129
- private actionStates: Record<string, (entry?: ZappEntry) => any> = {};
130
-
131
- registerActionState = (
132
- type: string,
133
- stateResolver: (entry?: ZappEntry) => any
134
- ) => {
135
- if (this.actionStates[type]) {
136
- log_error(
137
- `registerActionState: action type state: ${type} already registered`
138
- );
139
-
140
- return () => {};
141
- }
142
-
143
- this.actionStates[type] = stateResolver;
144
- log_debug(`registerActionState: action type state: ${type} registered`);
145
-
146
- return () => {
147
- delete this.actionStates[type];
148
-
149
- log_debug(
150
- `registerActionState: action type state: ${type} un-registered`
151
- );
152
- };
153
- };
154
-
155
- getActionState = (type: string, entry?: ZappEntry) => {
156
- return this.actionStates[type]?.(entry);
157
- };
158
120
  }
159
121
 
160
122
  export const actionExecutor = new ActionExecutor();
@@ -18,12 +18,12 @@ import { createLogger } from "../logger";
18
18
  import {
19
19
  appRestartAction,
20
20
  confirmDialogAction,
21
+ createGoBackAction,
22
+ createGoHomeAction,
21
23
  createNavigateToScreenAction,
22
- dismissBottomSheetAction,
23
24
  localStorageRemoveAction,
24
25
  localStorageSetAction,
25
26
  localStorageToggleFlagAction,
26
- openBottomSheetAction,
27
27
  refreshComponentAction,
28
28
  screenSetVariableAction,
29
29
  screenToggleFlagAction,
@@ -35,8 +35,6 @@ import {
35
35
  showToastAction,
36
36
  } from "./actions";
37
37
 
38
- import { ACTION_TYPES } from "./consts";
39
-
40
38
  export const { log_error, log_info, log_debug } = createLogger({
41
39
  subsystem: "ActionExecutorContext",
42
40
  category: "General",
@@ -45,15 +43,9 @@ export const { log_error, log_info, log_debug } = createLogger({
45
43
  export type ActionExecutorContextType = {
46
44
  registerAction: <TOptions = Record<string, any>>(
47
45
  type: string,
48
- handler: ActionHandler<TOptions>,
49
- stateResolver?: (entry?: ZappEntry) => any
46
+ handler: ActionHandler<TOptions>
50
47
  ) => void;
51
48
  unregisterAction: (type: string) => void;
52
- registerActionState: (
53
- type: string,
54
- stateResolver: (entry?: ZappEntry) => any
55
- ) => () => void;
56
- getActionState: (type: string, entry?: ZappEntry) => any;
57
49
  handleAction: (
58
50
  action: ActionType,
59
51
  context?: ActionExecutionContext
@@ -73,76 +65,34 @@ type Props = {
73
65
  };
74
66
 
75
67
  const prepareDefaultActions = (actionExecutor) => {
76
- actionExecutor.registerAction(
77
- ACTION_TYPES.LOCAL_STORAGE_SET,
78
- localStorageSetAction
79
- );
80
-
81
- actionExecutor.registerAction(
82
- ACTION_TYPES.SESSION_STORAGE_SET,
83
- sessionStorageSetAction
84
- );
85
-
86
- actionExecutor.registerAction(
87
- ACTION_TYPES.LOCAL_STORAGE_REMOVE,
88
- localStorageRemoveAction
89
- );
68
+ actionExecutor.registerAction("localStorageSet", localStorageSetAction);
69
+ actionExecutor.registerAction("sessionStorageSet", sessionStorageSetAction);
70
+ actionExecutor.registerAction("localStorageRemove", localStorageRemoveAction);
90
71
 
91
72
  actionExecutor.registerAction(
92
- ACTION_TYPES.SESSION_STORAGE_REMOVE,
73
+ "sessionStorageRemove",
93
74
  sessionStorageRemoveAction
94
75
  );
95
76
 
96
- actionExecutor.registerAction(
97
- ACTION_TYPES.REFRESH_COMPONENT,
98
- refreshComponentAction
99
- );
100
-
101
- actionExecutor.registerAction(ACTION_TYPES.SWITCH_LAYOUT, switchLayoutAction);
102
-
103
- actionExecutor.registerAction(ACTION_TYPES.APP_RESTART, appRestartAction);
104
-
105
- actionExecutor.registerAction(
106
- ACTION_TYPES.CONFIRM_DIALOG,
107
- confirmDialogAction
108
- );
109
-
110
- actionExecutor.registerAction(
111
- ACTION_TYPES.SEND_CLOUD_EVENT,
112
- sendCloudEventAction
113
- );
77
+ actionExecutor.registerAction("refreshComponent", refreshComponentAction);
78
+ actionExecutor.registerAction("switchLayout", switchLayoutAction);
79
+ actionExecutor.registerAction("appRestart", appRestartAction);
80
+ actionExecutor.registerAction("confirmDialog", confirmDialogAction);
81
+ actionExecutor.registerAction("sendCloudEvent", sendCloudEventAction);
114
82
 
115
83
  actionExecutor.registerAction(
116
- ACTION_TYPES.SESSION_STORAGE_TOGGLE_FLAG,
84
+ "sessionStorageToggleFlag",
117
85
  sessionStorageToggleFlagAction
118
86
  );
119
87
 
120
88
  actionExecutor.registerAction(
121
- ACTION_TYPES.LOCAL_STORAGE_TOGGLE_FLAG,
89
+ "localStorageToggleFlag",
122
90
  localStorageToggleFlagAction
123
91
  );
124
92
 
125
- actionExecutor.registerAction(
126
- ACTION_TYPES.SCREEN_SET_VARIABLE,
127
- screenSetVariableAction
128
- );
129
-
130
- actionExecutor.registerAction(
131
- ACTION_TYPES.SCREEN_TOGGLE_FLAG,
132
- screenToggleFlagAction
133
- );
134
-
135
- actionExecutor.registerAction(
136
- ACTION_TYPES.OPEN_BOTTOM_SHEET,
137
- openBottomSheetAction
138
- );
139
-
140
- actionExecutor.registerAction(
141
- ACTION_TYPES.DISMISS_BOTTOM_SHEET,
142
- dismissBottomSheetAction
143
- );
144
-
145
- actionExecutor.registerAction(ACTION_TYPES.SHOW_TOAST, showToastAction);
93
+ actionExecutor.registerAction("screenSetVariable", screenSetVariableAction);
94
+ actionExecutor.registerAction("screenToggleFlag", screenToggleFlagAction);
95
+ actionExecutor.registerAction("showToast", showToastAction);
146
96
  };
147
97
 
148
98
  export const ActionExecutorContext =
@@ -160,8 +110,6 @@ export function withActionExecutor(Component) {
160
110
  return {
161
111
  unregisterAction: _actionExecutor.unregisterAction,
162
112
  registerAction: _actionExecutor.registerAction,
163
- registerActionState: _actionExecutor.registerActionState,
164
- getActionState: _actionExecutor.getActionState,
165
113
  handleAction: _actionExecutor.handleAction,
166
114
  handleActions: _actionExecutor.handleActions,
167
115
  handleEntryActions: _actionExecutor.handleEntryActions,
@@ -184,11 +132,25 @@ export function withActionExecutor(Component) {
184
132
 
185
133
  useEffect(() => {
186
134
  return _actionExecutor.registerAction(
187
- ACTION_TYPES.NAVIGATE_TO_SCREEN,
135
+ "navigateToScreen",
188
136
  createNavigateToScreenAction(navigator, rivers, contentTypes)
189
137
  );
190
138
  }, [navigator, rivers, contentTypes]);
191
139
 
140
+ useEffect(() => {
141
+ return _actionExecutor.registerAction(
142
+ "goBack",
143
+ createGoBackAction(navigator)
144
+ );
145
+ }, [navigator]);
146
+
147
+ useEffect(() => {
148
+ return _actionExecutor.registerAction(
149
+ "goHome",
150
+ createGoHomeAction(navigator)
151
+ );
152
+ }, [navigator]);
153
+
192
154
  return (
193
155
  <ActionExecutorContext.Provider value={handlers}>
194
156
  <Component {...props} />
@@ -0,0 +1,62 @@
1
+ import { createGoBackAction } from "../goBack";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+
4
+ function createNavigator(canGoBack = true) {
5
+ return {
6
+ goBack: jest.fn(),
7
+ canGoBack: jest.fn().mockReturnValue(canGoBack),
8
+ } as unknown as QuickBrickAppNavigator;
9
+ }
10
+
11
+ describe("goBack", () => {
12
+ it("goes back with fallbackToHome enabled when no options are provided", async () => {
13
+ const navigator = createNavigator();
14
+
15
+ const result = await createGoBackAction(navigator)({ type: "goBack" });
16
+
17
+ expect(navigator.goBack).toHaveBeenCalledWith(true, false, false);
18
+ expect(result).toBe(ActionResult.Success);
19
+ });
20
+
21
+ it("forwards backToTop", async () => {
22
+ const navigator = createNavigator();
23
+
24
+ const action = {
25
+ type: "goBack",
26
+ options: { backToTop: true },
27
+ };
28
+
29
+ const result = await createGoBackAction(navigator)(action);
30
+
31
+ expect(navigator.goBack).toHaveBeenCalledWith(true, false, true);
32
+ expect(result).toBe(ActionResult.Success);
33
+ });
34
+
35
+ it("goes back without falling back to home when the stack allows it", async () => {
36
+ const navigator = createNavigator(true);
37
+
38
+ const action = {
39
+ type: "goBack",
40
+ options: { fallbackToHome: false },
41
+ };
42
+
43
+ const result = await createGoBackAction(navigator)(action);
44
+
45
+ expect(navigator.goBack).toHaveBeenCalledWith(false, false, false);
46
+ expect(result).toBe(ActionResult.Success);
47
+ });
48
+
49
+ it("does nothing when there is nothing to go back to and fallbackToHome is off", async () => {
50
+ const navigator = createNavigator(false);
51
+
52
+ const action = {
53
+ type: "goBack",
54
+ options: { fallbackToHome: false },
55
+ };
56
+
57
+ const result = await createGoBackAction(navigator)(action);
58
+
59
+ expect(navigator.goBack).not.toHaveBeenCalled();
60
+ expect(result).toBe(ActionResult.Error);
61
+ });
62
+ });
@@ -0,0 +1,19 @@
1
+ import { createGoHomeAction } from "../goHome";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+
4
+ function createNavigator() {
5
+ return {
6
+ goHome: jest.fn(),
7
+ } as unknown as QuickBrickAppNavigator;
8
+ }
9
+
10
+ describe("goHome", () => {
11
+ it("navigates to the home screen", async () => {
12
+ const navigator = createNavigator();
13
+
14
+ const result = await createGoHomeAction(navigator)({ type: "goHome" });
15
+
16
+ expect(navigator.goHome).toHaveBeenCalledWith();
17
+ expect(result).toBe(ActionResult.Success);
18
+ });
19
+ });
@@ -0,0 +1,60 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Options for the goBack action.
13
+ */
14
+ export interface GoBackOptions {
15
+ /**
16
+ * Navigate to the home screen when there is no screen to go back to.
17
+ * Defaults to true.
18
+ */
19
+ fallbackToHome?: boolean;
20
+
21
+ /**
22
+ * Go back to the first screen of the stack instead of the previous one.
23
+ * Defaults to false.
24
+ */
25
+ backToTop?: boolean;
26
+ }
27
+
28
+ /**
29
+ * Creates a go back action handler with the provided dependencies.
30
+ * This factory pattern allows the action to access navigation state at runtime.
31
+ *
32
+ * @param navigator - The app navigator performing the back navigation
33
+ * @returns An action handler that navigates back
34
+ */
35
+ export function createGoBackAction(
36
+ navigator: QuickBrickAppNavigator
37
+ ): ActionHandler<GoBackOptions> {
38
+ return async function goBackAction(action): Promise<ActionResult> {
39
+ const fallbackToHome = action.options?.fallbackToHome ?? true;
40
+ const backToTop = action.options?.backToTop ?? false;
41
+
42
+ // With fallbackToHome on, the navigator goes home on an empty stack by
43
+ // itself. The guard only matters when the caller opted out of that.
44
+ if (!fallbackToHome && !navigator.canGoBack()) {
45
+ log_info(
46
+ "goBack: no screen to go back to and fallbackToHome is disabled, ignoring"
47
+ );
48
+
49
+ return ActionResult.Error;
50
+ }
51
+
52
+ log_info(
53
+ `goBack: navigating back, fallbackToHome: ${fallbackToHome}, backToTop: ${backToTop}`
54
+ );
55
+
56
+ navigator.goBack(fallbackToHome, false, backToTop);
57
+
58
+ return ActionResult.Success;
59
+ };
60
+ }
@@ -0,0 +1,31 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Creates a go home action handler with the provided dependencies.
13
+ * This factory pattern allows the action to access navigation state at runtime.
14
+ *
15
+ * The navigator's `initialLaunch` flag is intentionally not exposed: it selects
16
+ * the offline home river during app bootstrap and is not a per-action choice.
17
+ *
18
+ * @param navigator - The app navigator performing the navigation
19
+ * @returns An action handler that navigates to the home screen
20
+ */
21
+ export function createGoHomeAction(
22
+ navigator: QuickBrickAppNavigator
23
+ ): ActionHandler {
24
+ return async function goHomeAction(): Promise<ActionResult> {
25
+ log_info("goHome: navigating to the home screen");
26
+
27
+ navigator.goHome();
28
+
29
+ return ActionResult.Success;
30
+ };
31
+ }
@@ -27,8 +27,8 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
27
27
 
28
28
  export { createNavigateToScreenAction } from "./navigateToScreen";
29
29
 
30
- export { showToastAction } from "./showToast";
30
+ export { createGoBackAction } from "./goBack";
31
31
 
32
- export { openBottomSheetAction } from "./openBottomSheet";
32
+ export { createGoHomeAction } from "./goHome";
33
33
 
34
- export { dismissBottomSheetAction } from "./dismissBottomSheet";
34
+ export { showToastAction } from "./showToast";
@@ -82,12 +82,6 @@ export const refreshComponentAction: ActionHandler = async (
82
82
  }) || source;
83
83
  }
84
84
 
85
- if (!dataSource) {
86
- log_info("handleAction: refreshComponent skipped: no dataSource found");
87
-
88
- return ActionResult.Success;
89
- }
90
-
91
85
  log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
92
86
  source,
93
87
  inflatedUrl: dataSource,
@@ -62,15 +62,10 @@ export const sendCloudEventAction: ActionHandler<
62
62
  subject: options.subject || String((entry as ZappEntry)?.id || ""),
63
63
  });
64
64
 
65
- log_info("handleAction: sending sendCloudEvent to URL", {
66
- url: options.url,
67
- cloudEvent,
68
- });
65
+ log_info("handleAction: sendCloudEvent event", { cloudEvent });
69
66
 
70
67
  const { error, code } = await sendCloudEvent(cloudEvent, options.url);
71
68
 
72
- log_info("handleAction: sendCloudEvent result", { code, error });
73
-
74
69
  if (error) {
75
70
  log_error("sendCloudEvent: error sending cloud event", { error });
76
71
 
@@ -2,26 +2,3 @@ export const TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT =
2
2
  "action.localStorageToggleFlag.maxItemsReached";
3
3
 
4
4
  export const ACTION_EXECUTOR_EVENT_SOURCE = "ActionExecutor";
5
-
6
- export const ACTION_TYPES = {
7
- OPEN_BOTTOM_SHEET: "openBottomSheet",
8
- DISMISS_BOTTOM_SHEET: "dismissBottomSheet",
9
- PRESENT_SUB_MENU: "presentSubMenu",
10
- SEND_CLOUD_EVENT: "sendCloudEvent",
11
- NAVIGATE_TO_SCREEN: "navigateToScreen",
12
- SHOW_TOAST: "showToast",
13
- LOCAL_STORAGE_SET: "localStorageSet",
14
- LOCAL_STORAGE_REMOVE: "localStorageRemove",
15
- LOCAL_STORAGE_TOGGLE_FLAG: "localStorageToggleFlag",
16
- SESSION_STORAGE_SET: "sessionStorageSet",
17
- SESSION_STORAGE_REMOVE: "sessionStorageRemove",
18
- SESSION_STORAGE_TOGGLE_FLAG: "sessionStorageToggleFlag",
19
- REFRESH_COMPONENT: "refreshComponent",
20
- SWITCH_LAYOUT: "switchLayout",
21
- APP_RESTART: "appRestart",
22
- CONFIRM_DIALOG: "confirmDialog",
23
- SCREEN_SET_VARIABLE: "screenSetVariable",
24
- SCREEN_TOGGLE_FLAG: "screenToggleFlag",
25
- } as const;
26
-
27
- export type KnownActionType = (typeof ACTION_TYPES)[keyof typeof ACTION_TYPES];
@@ -31,7 +31,7 @@ export interface ActionExecutionContext {
31
31
  /** Callback function for action completion */
32
32
  callback?: (result: { success: boolean; error: any; abort: boolean }) => void;
33
33
 
34
- screenState?: Record<any, any>;
34
+ screenState: Record<any, any>;
35
35
  }
36
36
 
37
37
  /**
@@ -3,8 +3,8 @@ import { distinctUntilChanged } from "rxjs/operators";
3
3
  import { Player } from "../player";
4
4
  import { createLogger, utilsLogger } from "../../../logger";
5
5
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
6
- import { findPluginByIdentifier } from "../../../pluginUtils";
7
6
  import {
7
+ findPluginByIdentifier,
8
8
  loadFeedEntry,
9
9
  loadFeedAndPrefetchThumbnailImage,
10
10
  parseTimeToSeconds,
@@ -252,10 +252,7 @@ export class OverlaysObserver {
252
252
  return;
253
253
  }
254
254
 
255
- const playNextFeedUrl: string = await retrieveFeedUrl(
256
- this.entry,
257
- plugins
258
- );
255
+ const playNextFeedUrl: string = retrieveFeedUrl(this.entry);
259
256
 
260
257
  if (!playNextFeedUrl || typeof playNextFeedUrl !== "string") {
261
258
  log_debug(
@@ -1,66 +1,13 @@
1
- const mockGetUpcomingQueue = jest.fn();
2
-
3
- jest.mock("../getUpcomingQueue", () => ({
4
- getUpcomingQueue: (...args: unknown[]) => mockGetUpcomingQueue(...args),
5
- }));
6
-
7
1
  import { retrieveFeedUrl, retrievePlayPreviousFeedUrl } from "../utils";
8
2
 
9
3
  const entryWith = (extensions: Record<string, unknown>): ZappEntry =>
10
4
  ({ id: "1", type: { value: "video" }, extensions }) as ZappEntry;
11
5
 
12
- const queuePlugin = { identifier: "queue-action" } as ZappPlugin;
13
-
14
6
  describe("playlist feed url accessors", () => {
15
- beforeEach(() => {
16
- mockGetUpcomingQueue.mockReset();
17
- });
18
-
19
- it("returns the next feed url when present", async () => {
20
- const entry = entryWith({ play_next_feed_url: "https://feeds/next.json" });
21
-
22
- await expect(retrieveFeedUrl(entry, [])).resolves.toBe(
23
- "https://feeds/next.json"
24
- );
25
- });
26
-
27
- it("resolves to null for a missing entry", async () => {
28
- await expect(
29
- retrieveFeedUrl(undefined as unknown as ZappEntry, [])
30
- ).resolves.toBeNull();
31
- });
32
-
33
- it("returns a queue play-next url when upcoming items exist", async () => {
34
- mockGetUpcomingQueue.mockResolvedValue([{ id: "next-item" }]);
35
-
36
- const entry = entryWith({
37
- play_next_feed_url: "https://feeds/next.json",
38
- queueItemId: "queue-1",
39
- });
40
-
41
- await expect(retrieveFeedUrl(entry, [queuePlugin])).resolves.toBe(
42
- "pipesv2://queue-action/play-next?queueItemId=queue-1"
43
- );
44
- });
45
-
46
- it("falls back to the next feed url when the upcoming queue is empty", async () => {
47
- mockGetUpcomingQueue.mockResolvedValue([]);
48
-
49
- const entry = entryWith({ play_next_feed_url: "https://feeds/next.json" });
50
-
51
- await expect(retrieveFeedUrl(entry, [queuePlugin])).resolves.toBe(
52
- "https://feeds/next.json"
53
- );
54
- });
55
-
56
- it("falls back to the next feed url when QueueManager cannot be resolved", async () => {
57
- mockGetUpcomingQueue.mockRejectedValue(new Error("not available"));
58
-
7
+ it("returns the next feed url when present", () => {
59
8
  const entry = entryWith({ play_next_feed_url: "https://feeds/next.json" });
60
9
 
61
- await expect(retrieveFeedUrl(entry, [queuePlugin])).resolves.toBe(
62
- "https://feeds/next.json"
63
- );
10
+ expect(retrieveFeedUrl(entry)).toBe("https://feeds/next.json");
64
11
  });
65
12
 
66
13
  it("returns the previous feed url when present", () => {
@@ -3,13 +3,10 @@ import {
3
3
  PipesClientResponseHelper,
4
4
  RequestBuilder,
5
5
  } from "@applicaster/zapp-pipes-v2-client";
6
- import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
7
6
  import { log_error, log_info } from "./OverlaysObserver";
7
+ import * as R from "ramda";
8
8
  import { toNumber, toNumberWithDefault } from "../../../numberUtils";
9
9
 
10
- import { findPluginByIdentifier } from "../../../pluginUtils";
11
- import { getUpcomingQueue } from "./getUpcomingQueue";
12
-
13
10
  export const parseTimeToSeconds = (timeStr: string): number => {
14
11
  const validationError = new Error("Invalid time format");
15
12
 
@@ -43,58 +40,14 @@ export const parseTimeToSeconds = (timeStr: string): number => {
43
40
  }
44
41
  };
45
42
 
46
- /**
47
- * HACK / TEMPORARY WORKAROUND:
48
- * Resolves the play_next_feed_url dynamically for OverlaysObserver.
49
- *
50
- * WHY THIS IS HACKED HERE:
51
- * OverlaysObserver was originally designed as a Recommendation Overlay engine (fetching static
52
- * play_next_feed_url for overlay UI visuals). However, for dynamic queue & continuous audio playback,
53
- * modifying feeds via `decorateFeed` at load time doesn't work (due to feed caching and mid-playback queue mutations).
54
- * To avoid mutating feed payloads across the app, we temporarily intercept play_next_feed_url here
55
- * at runtime to check if QueueManager has active/upcoming queue items.
56
- *
57
- * FUTURE ARCHITECTURE / TODO:
58
- * Move queue/playlist resolution into a dedicated Player/Queue Provider module (or Handler Chain)
59
- * on playerManager, decoupling Queue playback logic entirely from OverlaysObserver (which should
60
- * strictly focus on recommendation visuals and chapter markers).
61
- */
62
- export const retrieveFeedUrl = async (
63
- entry: ZappEntry,
64
- plugins?: ZappPlugin[]
65
- ): Promise<string> => {
66
- if (!entry) return null;
67
-
68
- const availablePlugins = plugins || appStore.get("plugins");
69
-
70
- const queuePlugin = findPluginByIdentifier(
71
- "queue-action",
72
- availablePlugins,
73
- true
74
- );
75
-
76
- if (queuePlugin) {
77
- try {
78
- const upcomingQueue = await getUpcomingQueue(queuePlugin);
79
-
80
- if (upcomingQueue && upcomingQueue.length > 0) {
81
- const queueItemId = entry?.extensions?.queueItemId || entry?.id;
82
-
83
- return `pipesv2://queue-action/play-next?queueItemId=${queueItemId}`;
84
- }
85
- } catch (e) {
86
- log_error("retrieveFeedUrl: Failed to resolve QueueManager", e);
87
- }
88
- }
89
-
90
- return entry?.extensions?.play_next_feed_url;
91
- };
43
+ export const retrieveFeedUrl = (entry: ZappEntry) =>
44
+ entry?.extensions?.play_next_feed_url;
92
45
 
93
46
  export const retrievePlayPreviousFeedUrl = (entry: ZappEntry) =>
94
47
  entry?.extensions?.play_previous_feed_url;
95
48
 
96
49
  export const retrieveOverlayDuration = (plugin) =>
97
- toNumberWithDefault(15, plugin?.configuration?.overlay_duration);
50
+ toNumberWithDefault(plugin?.configuration?.overlay_duration, 15);
98
51
 
99
52
  export const retrieveOverlayTriggerOffset = (item: ZappEntry) => {
100
53
  return item && item.extensions && item.extensions.overlay_timestamp
@@ -200,3 +153,19 @@ export const loadFeedAndPrefetchThumbnailImage = async (
200
153
 
201
154
  return playNextEntry;
202
155
  };
156
+
157
+ export const findPluginByIdentifier = (
158
+ identifier: string,
159
+ plugins: ZappPlugin[]
160
+ ): ZappPlugin => {
161
+ if (!identifier) {
162
+ return undefined;
163
+ }
164
+
165
+ const plugin = R.compose(
166
+ R.find(R.propEq("identifier", identifier)),
167
+ R.values
168
+ )(plugins);
169
+
170
+ return plugin;
171
+ };