@applicaster/zapp-react-native-utils 16.0.0-rc.9 → 16.0.0-rc.90

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 (201) hide show
  1. package/actionsExecutor/ActionExecutor.ts +57 -12
  2. package/actionsExecutor/ActionExecutorContext.tsx +113 -314
  3. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  4. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  9. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
  12. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  13. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  14. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  15. package/actionsExecutor/actions/appRestart.ts +24 -0
  16. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  17. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  18. package/actionsExecutor/actions/goBack.ts +60 -0
  19. package/actionsExecutor/actions/goHome.ts +31 -0
  20. package/actionsExecutor/actions/index.ts +42 -0
  21. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  22. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  23. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  24. package/actionsExecutor/actions/navigateToScreen.ts +137 -0
  25. package/actionsExecutor/actions/openBottomSheet.ts +329 -0
  26. package/actionsExecutor/actions/presentScreen.ts +78 -0
  27. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  28. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  29. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  30. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  31. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  32. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  33. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  34. package/actionsExecutor/actions/showAlert.ts +51 -0
  35. package/actionsExecutor/actions/showToast.ts +87 -0
  36. package/actionsExecutor/actions/switchLayout.ts +40 -0
  37. package/actionsExecutor/consts.ts +27 -0
  38. package/actionsExecutor/feedDecorator.ts +6 -6
  39. package/actionsExecutor/types.ts +59 -0
  40. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  41. package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
  42. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  43. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  44. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  45. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  46. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  47. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  48. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  49. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  50. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  51. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  52. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  53. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  54. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  55. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  56. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  57. package/analyticsUtils/analyticsMapper.ts +4 -1
  58. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  59. package/appUtils/HooksManager/index.ts +12 -8
  60. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  61. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  62. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  63. package/appUtils/contextKeysManager/index.ts +1 -1
  64. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  65. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  66. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  67. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  68. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  69. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  70. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  71. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  72. package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
  73. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  74. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  75. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  76. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  77. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  78. package/appUtils/playerManager/index.ts +1 -1
  79. package/appUtils/playerManager/player.ts +115 -3
  80. package/appUtils/playerManager/playerFactory.ts +1 -1
  81. package/appUtils/playerManager/playerNative.ts +6 -4
  82. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  83. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  84. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  85. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  86. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  87. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  88. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  89. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  90. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  91. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  92. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  93. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  94. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  95. package/arrayUtils/__tests__/sample.test.ts +61 -0
  96. package/arrayUtils/index.ts +136 -20
  97. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  98. package/bottomSheet/index.ts +17 -0
  99. package/cellUtils/index.ts +33 -8
  100. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  101. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  102. package/colorUtils/index.ts +50 -0
  103. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  104. package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
  105. package/configurationUtils/manifestKeyParser.ts +50 -10
  106. package/configurationUtils/modalBlocksParser.ts +296 -0
  107. package/entryActions/__tests__/buildEntryActions.test.ts +195 -0
  108. package/entryActions/aliasPresentation.ts +124 -0
  109. package/entryActions/buildEntryActions.ts +167 -0
  110. package/entryActions/index.ts +17 -0
  111. package/entryActions/types.ts +39 -0
  112. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  113. package/manifestUtils/_internals/index.js +14 -3
  114. package/manifestUtils/defaultManifestConfigurations/generalContent.js +41 -0
  115. package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
  116. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  117. package/manifestUtils/fieldUtils/index.js +125 -0
  118. package/manifestUtils/index.js +3 -0
  119. package/manifestUtils/keys.js +9 -0
  120. package/manifestUtils/mobileAction/button/index.js +16 -0
  121. package/manifestUtils/mobileAction/container/index.js +3 -1
  122. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  123. package/manifestUtils/modalBlocks.js +304 -0
  124. package/manifestUtils/platformIsTV.js +1 -0
  125. package/modalState/ContentViewModel.ts +113 -0
  126. package/modalState/EditableCollection.ts +17 -0
  127. package/modalState/EditableCollectionRegistry.ts +51 -0
  128. package/modalState/ModalOrchestrator.ts +211 -0
  129. package/modalState/RemoteEditableCollection.ts +235 -0
  130. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  131. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  132. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  133. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  134. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  135. package/modalState/__tests__/index.test.ts +30 -1
  136. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  137. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  138. package/modalState/index.ts +35 -83
  139. package/modalState/store.ts +109 -0
  140. package/modalState/types.ts +160 -0
  141. package/modalState/useBottomSheetContent.ts +109 -0
  142. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  143. package/numberUtils/__tests__/isZero.test.ts +27 -0
  144. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  145. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  146. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  147. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  148. package/numberUtils/index.ts +27 -8
  149. package/package.json +2 -2
  150. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  151. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  152. package/pipesUtils/index.ts +1 -0
  153. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  154. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  155. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  156. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  157. package/playerUtils/contentDataKeys.ts +134 -0
  158. package/playerUtils/index.ts +41 -18
  159. package/playerUtils/isAudioItem.ts +26 -0
  160. package/playerUtils/resolvePlayerActions.ts +71 -0
  161. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  162. package/reactHooks/actions/index.ts +117 -2
  163. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  164. package/reactHooks/cell-click/index.ts +39 -24
  165. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  166. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  167. package/reactHooks/feed/index.ts +5 -1
  168. package/reactHooks/feed/useBatchLoading.ts +9 -1
  169. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  170. package/reactHooks/index.ts +2 -0
  171. package/reactHooks/layout/index.ts +1 -1
  172. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  173. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  174. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  175. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  176. package/reactHooks/navigation/index.ts +3 -1
  177. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  178. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  179. package/reactHooks/navigation/useRoute.ts +22 -5
  180. package/reactHooks/state/useComponentScreenState.ts +1 -1
  181. package/reactHooks/usePluginConfiguration.ts +4 -1
  182. package/reactHooks/utils/__tests__/index.test.js +22 -2
  183. package/reactHooks/utils/index.ts +13 -2
  184. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  185. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  186. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  187. package/stringUtils/index.ts +2 -2
  188. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  189. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  190. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  191. package/uiActionsRegistrator/index.ts +25 -0
  192. package/uiActionsRegistrator/registry.ts +335 -0
  193. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  194. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  195. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  196. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  197. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  198. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  199. package/playerUtils/getPlayerActionButtons.ts +0 -17
  200. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  201. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,42 @@
1
+ // Export action handlers
2
+ export { localStorageSetAction } from "./localStorageSet";
3
+
4
+ export { sessionStorageSetAction } from "./sessionStorageSet";
5
+
6
+ export { localStorageRemoveAction } from "./localStorageRemove";
7
+
8
+ export { sessionStorageRemoveAction } from "./sessionStorageRemove";
9
+
10
+ export { refreshComponentAction } from "./refreshComponent";
11
+
12
+ export { switchLayoutAction } from "./switchLayout";
13
+
14
+ export { appRestartAction } from "./appRestart";
15
+
16
+ export { confirmDialogAction } from "./confirmDialog";
17
+
18
+ export { showAlertAction } from "./showAlert";
19
+
20
+ export { sendCloudEventAction } from "./sendCloudEvent";
21
+
22
+ export { sessionStorageToggleFlagAction } from "./sessionStorageToggleFlag";
23
+
24
+ export { localStorageToggleFlagAction } from "./localStorageToggleFlag";
25
+
26
+ export { screenSetVariableAction } from "./screenSetVariable";
27
+
28
+ export { screenToggleFlagAction } from "./screenToggleFlag";
29
+
30
+ export { createNavigateToScreenAction } from "./navigateToScreen";
31
+
32
+ export { createPresentScreenAction } from "./presentScreen";
33
+
34
+ export { createGoBackAction } from "./goBack";
35
+
36
+ export { createGoHomeAction } from "./goHome";
37
+
38
+ export { showToastAction } from "./showToast";
39
+
40
+ export { openBottomSheetAction } from "./openBottomSheet";
41
+
42
+ export { dismissBottomSheetAction } from "./dismissBottomSheet";
@@ -0,0 +1,27 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
+ import { batchRemoveFromStorage } from "../../zappFrameworkUtils/localStorageHelper";
4
+ import { ActionResult } from "../ActionExecutor";
5
+ import { ActionHandler } from "../types";
6
+ import { StorageValuesToRemove } from "../../zappFrameworkUtils/types";
7
+
8
+ /**
9
+ * Options for localStorage/sessionStorage remove actions.
10
+ */
11
+ export interface StorageRemoveOptions {
12
+ /** The keys to remove, organized by namespace */
13
+ content: StorageValuesToRemove;
14
+ }
15
+
16
+ /**
17
+ * Removes values from local storage organized by namespaces.
18
+ */
19
+ export const localStorageRemoveAction: ActionHandler<
20
+ StorageRemoveOptions
21
+ > = async (action): Promise<ActionResult> => {
22
+ const namespaces = action.options.content;
23
+ await batchRemoveFromStorage(namespaces, localStorage);
24
+ // TODO: Add support for ownershipKey and ownershipNamespace
25
+
26
+ return ActionResult.Success;
27
+ };
@@ -0,0 +1,28 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
+ import { batchSave } from "../../zappFrameworkUtils/localStorageHelper";
4
+ import { ActionResult } from "../ActionExecutor";
5
+ import { ActionHandler } from "../types";
6
+ import { StorageValuesToAdd } from "../../zappFrameworkUtils/types";
7
+
8
+ /**
9
+ * Options for localStorage/sessionStorage set actions.
10
+ */
11
+ export interface StorageSetOptions {
12
+ /** The values to save, organized by namespace */
13
+ content: StorageValuesToAdd;
14
+ }
15
+
16
+ /**
17
+ * Saves values to local storage organized by namespaces.
18
+ * The values persist across app sessions.
19
+ */
20
+ export const localStorageSetAction: ActionHandler<StorageSetOptions> = async (
21
+ action
22
+ ): Promise<ActionResult> => {
23
+ const namespaces = action.options.content;
24
+ await batchSave(namespaces, localStorage);
25
+ // TODO: Add support for ownershipKey and ownershipNamespace
26
+
27
+ return ActionResult.Success;
28
+ };
@@ -0,0 +1,28 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { localStorageToggleFlag } from "../StorageActions";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler, ActionExecutionContext } from "../types";
5
+
6
+ /**
7
+ * Options for storage toggle flag actions (localStorage/sessionStorage).
8
+ */
9
+ export interface StorageToggleFlagOptions {
10
+ /** The key/namespace for storing the flag */
11
+ key: string;
12
+
13
+ /** Path to extract the tag from entry */
14
+ selector?: string;
15
+
16
+ /** Maximum number of items that can be selected */
17
+ max_items?: number;
18
+ }
19
+
20
+ /**
21
+ * Toggles a flag in local storage (adds or removes an item from a collection).
22
+ * Used for features like favorites, watchlists, etc.
23
+ */
24
+ export const localStorageToggleFlagAction: ActionHandler<
25
+ StorageToggleFlagOptions
26
+ > = async (action, context?: ActionExecutionContext): Promise<ActionResult> => {
27
+ return await localStorageToggleFlag(context, action);
28
+ };
@@ -0,0 +1,137 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler, ActionExecutionContext } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info, log_error } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Options for the navigateToScreen action.
13
+ */
14
+ export interface NavigateToScreenOptions {
15
+ /** The screen type to navigate to (from content types mapping) */
16
+ typeMapping: string;
17
+
18
+ /** Navigation action: push adds to history, replace replaces current screen */
19
+ navigationAction?: "push" | "replace";
20
+
21
+ /**
22
+ * Entry to navigate with. Can be:
23
+ * - "@{entry/}" to use the context entry
24
+ * - A ZappEntry object
25
+ * - undefined to navigate to screen without entry
26
+ */
27
+ entry?: "@{entry/}" | ZappEntry;
28
+
29
+ /**
30
+ * Arbitrary values passed through to the destination screen.
31
+ *
32
+ * They are stored on the navigation route as `NavigationScreenData.options`
33
+ * and read on the target screen via `useNavigation().data?.options`. Use this
34
+ * to hand per-navigation parameters to a screen instead of routing them
35
+ * through module-level state.
36
+ *
37
+ * Note: `legacyScreenData()` does not carry these values, so they are not
38
+ * visible through `useCurrentScreenData()` / `useRoute()`.
39
+ */
40
+ navigationOptions?: Record<string, unknown>;
41
+ }
42
+
43
+ /**
44
+ * Creates a navigation action handler with the provided dependencies.
45
+ * This factory pattern allows the action to access navigation state at runtime.
46
+ *
47
+ * @param navigator - The app navigator for push/replace operations
48
+ * @param rivers - Map of screen IDs to river definitions
49
+ * @param contentTypes - Map of content type names to screen configurations
50
+ * @returns An action handler that performs screen navigation
51
+ */
52
+ export function createNavigateToScreenAction(
53
+ navigator: QuickBrickAppNavigator,
54
+ rivers: Record<string, ZappRiver>,
55
+ contentTypes: ZappContentTypes
56
+ ): ActionHandler<NavigateToScreenOptions> {
57
+ return async function navigateToScreenAction(
58
+ action,
59
+ context?: ActionExecutionContext
60
+ ): Promise<ActionResult> {
61
+ const screenType = action.options?.typeMapping;
62
+
63
+ if (!screenType) {
64
+ log_error("navigateToScreen: typeMapping option is missing");
65
+
66
+ return ActionResult.Error;
67
+ }
68
+
69
+ const navigationAction = action.options?.navigationAction;
70
+ const entrySource = action.options?.entry;
71
+ const navigationOptions = action.options?.navigationOptions;
72
+
73
+ const entry = entrySource
74
+ ? entrySource === "@{entry/}"
75
+ ? context?.entry
76
+ : entrySource
77
+ : null;
78
+
79
+ if (entry) {
80
+ if (typeof entry !== "object") {
81
+ log_error(
82
+ `navigateToScreen: entry option is not an object, entry: ${entry}`
83
+ );
84
+
85
+ return ActionResult.Error;
86
+ }
87
+
88
+ log_info(
89
+ `navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
90
+ );
91
+
92
+ const overriddenEntry: ZappEntry = {
93
+ ...entry,
94
+ type: {
95
+ value: screenType,
96
+ },
97
+ };
98
+
99
+ if (navigationAction === "push") {
100
+ navigator.push(overriddenEntry, navigationOptions);
101
+ } else {
102
+ // Use replaceTop for entries since replace() only accepts ZappRiver
103
+ navigator.replaceTop(overriddenEntry, navigationOptions);
104
+ }
105
+
106
+ return ActionResult.Success;
107
+ }
108
+
109
+ const screenId = contentTypes?.[screenType]?.screen_id || null;
110
+
111
+ if (!screenId) {
112
+ log_error(
113
+ `navigateToScreen: can not resolve screen type mapping: ${screenType}`
114
+ );
115
+
116
+ return ActionResult.Error;
117
+ }
118
+
119
+ const river = rivers[screenId];
120
+
121
+ if (!river) {
122
+ log_error("navigateToScreen: can not resolve river");
123
+
124
+ return ActionResult.Error;
125
+ }
126
+
127
+ context?.callback?.({ success: false, error: null, abort: true });
128
+
129
+ if (navigationAction === "push") {
130
+ navigator.push(river, navigationOptions);
131
+ } else {
132
+ navigator.replace(river, navigationOptions);
133
+ }
134
+
135
+ return ActionResult.Success;
136
+ };
137
+ }
@@ -0,0 +1,329 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import {
3
+ PipesClientResponseHelper,
4
+ RequestBuilder,
5
+ } from "@applicaster/zapp-pipes-v2-client";
6
+ import uuidv4 from "uuid/v4";
7
+ import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
8
+ import { openBottomSheetModal } from "../../modalState/store";
9
+ import {
10
+ DynamicCollectionOptions,
11
+ getMenuItemActions,
12
+ isPresentSubMenuAction,
13
+ Menu,
14
+ MenuItem,
15
+ Operation,
16
+ SelectionBehavior,
17
+ } from "../../modalState/types";
18
+ import { actionExecutor, ActionResult } from "../ActionExecutor";
19
+ import { createLogger } from "../../logger";
20
+
21
+ const { log_info, log_error } = createLogger({
22
+ subsystem: "ActionExecutorContext",
23
+ category: "General",
24
+ });
25
+
26
+ export type LoadedSheetContent = {
27
+ items: MenuItem[];
28
+ role?: string;
29
+ behavior?: SelectionBehavior;
30
+ dynamicCollection?: DynamicCollectionOptions;
31
+ };
32
+
33
+ /**
34
+ * Parse a raw `dynamic_collection_options` block (feed or inline content) into
35
+ * the typed `DynamicCollectionOptions`. `operations` accepts either a CSV
36
+ * string (feed) or an array (already parsed).
37
+ */
38
+ export function parseDynamicCollectionOptions(
39
+ raw:
40
+ | {
41
+ operations?: string | string[];
42
+ postUrl?: string;
43
+ provider?: string;
44
+ events?: Record<string, any[]>;
45
+ }
46
+ | undefined
47
+ ): DynamicCollectionOptions | undefined {
48
+ if (!raw) {
49
+ return undefined;
50
+ }
51
+
52
+ const operations = Array.isArray(raw.operations)
53
+ ? (raw.operations as Operation[])
54
+ : ((raw.operations || "").split(",").filter(Boolean) as Operation[]);
55
+
56
+ return {
57
+ operations,
58
+ postUrl: raw.postUrl,
59
+ provider: raw.provider,
60
+ events: raw.events,
61
+ };
62
+ }
63
+
64
+ /**
65
+ * Converts a ZappEntry from a pipes feed into a MenuItem.
66
+ * - Icon: first src found in the image media_group.
67
+ * - Primary action: taken from tap_actions.actions[0].
68
+ * - isSelected: true when entry.id is in currentSelection.
69
+ */
70
+ export function entryToMenuItem(
71
+ entry: ZappEntry,
72
+ currentSelection: string[] = []
73
+ ): MenuItem {
74
+ const imageGroup = entry.media_group?.find((g) => g.type === "image");
75
+
76
+ const firstImage = Array.isArray(imageGroup?.media_item)
77
+ ? imageGroup.media_item[0]
78
+ : imageGroup?.media_item;
79
+
80
+ // Primary action — first tap_action on the entry
81
+ const tapActions = entry.extensions?.tap_actions?.actions || [];
82
+ const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
83
+
84
+ const summary = entry.summary as string;
85
+
86
+ const itemId = String(entry.id ?? entry.title ?? uuidv4());
87
+
88
+ return {
89
+ id: itemId,
90
+ title: entry.title as string,
91
+ summary,
92
+ icon: firstImage?.src,
93
+ isSelected: currentSelection.includes(itemId),
94
+ action: primaryAction,
95
+ actions: tapActions,
96
+ entryActions: entry.extensions?.entry_action || [],
97
+ };
98
+ }
99
+
100
+ function parseCurrentSelection(rawSelection: unknown): string[] {
101
+ if (Array.isArray(rawSelection)) {
102
+ return (rawSelection as any[]).map(String);
103
+ }
104
+
105
+ if (rawSelection !== undefined && rawSelection !== null) {
106
+ return [String(rawSelection)];
107
+ }
108
+
109
+ return [];
110
+ }
111
+
112
+ function parseBehaviorFromFeed(
113
+ feed: ZappFeed | undefined,
114
+ currentSelection: string[]
115
+ ): SelectionBehavior | undefined {
116
+ const raw = feed?.extensions?.behavior;
117
+
118
+ if (!raw && currentSelection.length === 0) {
119
+ return undefined;
120
+ }
121
+
122
+ return {
123
+ selectMode: raw?.select_mode,
124
+ currentSelection,
125
+ selector: raw?.selector,
126
+ };
127
+ }
128
+
129
+ function parseBehaviorFromContentOptions(
130
+ content: Record<string, any> | undefined
131
+ ): SelectionBehavior | undefined {
132
+ const raw = content?.behavior ?? content?.extensions?.behavior;
133
+
134
+ if (!raw) {
135
+ return undefined;
136
+ }
137
+
138
+ return {
139
+ selectMode: raw.selectMode ?? raw.select_mode,
140
+ currentSelection: parseCurrentSelection(
141
+ raw.currentSelection ?? raw.current_selection
142
+ ),
143
+ selector: raw.selector,
144
+ };
145
+ }
146
+
147
+ // Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
148
+ export async function loadItemsFromSource(
149
+ source: string,
150
+ context?: Record<string, any>
151
+ ): Promise<LoadedSheetContent> {
152
+ const requestBuilder = new RequestBuilder()
153
+ .setEntryContext(context?.entry || {})
154
+ .setScreenContext(context?.screenData || {})
155
+ .setUrl(source);
156
+
157
+ await requestBuilder.buildAxiosRequest();
158
+
159
+ const responseData = await requestBuilder.call<ZappFeed>();
160
+
161
+ const responseHelper = new PipesClientResponseHelper(responseData);
162
+
163
+ if (responseHelper.error) {
164
+ throw responseHelper.error;
165
+ }
166
+
167
+ const feed = responseData?.response as ZappFeed;
168
+
169
+ const currentSelection = parseCurrentSelection(
170
+ feed?.extensions?.behavior?.current_selection
171
+ );
172
+
173
+ const items = (feed?.entry || []).map((entry) =>
174
+ entryToMenuItem(entry, currentSelection)
175
+ );
176
+
177
+ const dynamicCollectionOptions = feed?.extensions?.dynamic_collection_options;
178
+
179
+ const dynamicCollection = parseDynamicCollectionOptions(
180
+ dynamicCollectionOptions
181
+ );
182
+
183
+ return {
184
+ items,
185
+ role: feed?.extensions?.role,
186
+ behavior: parseBehaviorFromFeed(feed, currentSelection),
187
+ dynamicCollection,
188
+ };
189
+ }
190
+
191
+ export async function openBottomSheetAction(
192
+ action: ActionType,
193
+ context?: Record<string, any>
194
+ ): Promise<ActionResult> {
195
+ try {
196
+ const { content, header, themePluginId, styleOverrides } =
197
+ action.options || {};
198
+
199
+ // Custom body component — keep default ModalComponent so standard header
200
+ // (dismiss x) is used; content.component is body-only (e.g. TextInputContent).
201
+ if (content?.component) {
202
+ log_info("openBottomSheet: using custom content component");
203
+
204
+ openBottomSheetModal({
205
+ modalBottomSheetContentProps: {
206
+ title: header?.title,
207
+ summary: header?.subtitle,
208
+ items: [],
209
+ onPress: () => {},
210
+ contentComponent: content.component,
211
+ contentComponentProps: {
212
+ ...(content.props || {}),
213
+ actionContext: context,
214
+ },
215
+ },
216
+ });
217
+
218
+ return ActionResult.Success;
219
+ }
220
+
221
+ const inlineItems: ZappEntry[] = content?.items;
222
+ const itemsUrl: string = content?.itemsUrl;
223
+
224
+ let items: MenuItem[];
225
+ let role: string | undefined;
226
+ let behavior: SelectionBehavior | undefined;
227
+
228
+ let dynamicCollection: DynamicCollectionOptions | undefined;
229
+
230
+ if (Array.isArray(inlineItems) && inlineItems.length > 0) {
231
+ log_info("openBottomSheet: using inline items from action options", {
232
+ count: inlineItems.length,
233
+ });
234
+
235
+ role = content?.role ?? content?.extensions?.role;
236
+ behavior = parseBehaviorFromContentOptions(content);
237
+
238
+ items = inlineItems.map((entry) =>
239
+ entryToMenuItem(entry, behavior?.currentSelection ?? [])
240
+ );
241
+
242
+ dynamicCollection = parseDynamicCollectionOptions(
243
+ content?.dynamicCollection ??
244
+ content?.extensions?.dynamic_collection_options
245
+ );
246
+ } else if (itemsUrl) {
247
+ log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
248
+
249
+ const loaded = await loadItemsFromSource(itemsUrl, context);
250
+ items = loaded.items;
251
+ role = loaded.role ?? content?.role ?? content?.extensions?.role;
252
+ behavior = loaded.behavior ?? parseBehaviorFromContentOptions(content);
253
+ dynamicCollection = loaded.dynamicCollection;
254
+
255
+ log_info(
256
+ `openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
257
+ );
258
+ } else {
259
+ log_error(
260
+ "openBottomSheet: no itemsUrl, items, or content.component provided in action options"
261
+ );
262
+
263
+ return ActionResult.Error;
264
+ }
265
+
266
+ const menu: Menu = {
267
+ header: header
268
+ ? {
269
+ title: header.title,
270
+ subtitle: header.subtitle,
271
+ icon: header.icon,
272
+ }
273
+ : undefined,
274
+ content: {
275
+ title: content?.title ?? "",
276
+ items,
277
+ itemsUrl, // stored so the component can reload after an action
278
+ role,
279
+ behavior,
280
+ dynamicCollection,
281
+ themePluginId,
282
+ styleOverrides: styleOverrides ?? content?.styleOverrides,
283
+ context,
284
+ },
285
+ };
286
+
287
+ /**
288
+ * Called when the user taps a menu item.
289
+ *
290
+ * - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
291
+ * - Any other Action type → forwarded to the action executor, keeping the
292
+ * original execution context so screen/entry data is available to handlers.
293
+ * The pressed item is also added as `entry` so downstream actions can
294
+ * reference it.
295
+ */
296
+ const onItemPress = async (item: MenuItem): Promise<void> => {
297
+ const actions = getMenuItemActions(item);
298
+
299
+ const executableActions = actions.filter(
300
+ (action) => !isPresentSubMenuAction(action)
301
+ );
302
+
303
+ if (executableActions.length > 0) {
304
+ await actionExecutor.handleActions(
305
+ executableActions as ActionType[],
306
+ {
307
+ ...context,
308
+ entry: item as any,
309
+ } as any
310
+ );
311
+ }
312
+ };
313
+
314
+ if (action.options?.replace) {
315
+ modalOrchestrator.replace(menu, onItemPress);
316
+ } else {
317
+ modalOrchestrator.open(menu, onItemPress);
318
+ }
319
+
320
+ return ActionResult.Success;
321
+ } catch (error) {
322
+ log_error("openBottomSheet: failed to open bottom sheet", {
323
+ error,
324
+ action,
325
+ });
326
+
327
+ return ActionResult.Error;
328
+ }
329
+ }
@@ -0,0 +1,78 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler, ActionExecutionContext } from "../types";
4
+ import type { PresentScreenFn } from "../../reactHooks/navigation/usePresentScreen";
5
+ import { createLogger } from "../../logger";
6
+
7
+ const { log_error } = createLogger({
8
+ subsystem: "ActionExecutorContext",
9
+ category: "General",
10
+ });
11
+
12
+ /**
13
+ * Options for the presentScreen action.
14
+ */
15
+ export interface PresentScreenOptions {
16
+ /** The screen type to present (from content types mapping) */
17
+ typeMapping: string;
18
+
19
+ /**
20
+ * Entry to present the screen with. Can be:
21
+ * - "@{entry/}" to use the context entry
22
+ * - A ZappEntry object
23
+ * - undefined to present the screen without an entry
24
+ */
25
+ entry?: "@{entry/}" | ZappEntry;
26
+ }
27
+
28
+ /**
29
+ * Creates a present-screen action handler with the provided dependencies.
30
+ *
31
+ * Unlike navigateToScreen, this action does not return until the presented
32
+ * screen reports a result, so a screen that gates the flow (a parental lock,
33
+ * for example) can stop the remaining actions by being cancelled.
34
+ *
35
+ * @param presentScreen - Presents a screen as a modal and resolves with its result
36
+ * @returns An action handler that presents a screen and awaits its outcome
37
+ */
38
+ export function createPresentScreenAction(
39
+ presentScreen: PresentScreenFn
40
+ ): ActionHandler<PresentScreenOptions> {
41
+ return async function presentScreenAction(
42
+ action,
43
+ context?: ActionExecutionContext
44
+ ): Promise<ActionResult> {
45
+ const typeMapping = action.options?.typeMapping;
46
+
47
+ if (!typeMapping) {
48
+ log_error("presentScreen: typeMapping option is missing");
49
+
50
+ return ActionResult.Error;
51
+ }
52
+
53
+ const entrySource = action.options?.entry;
54
+
55
+ const entry = entrySource
56
+ ? entrySource === "@{entry/}"
57
+ ? context?.entry
58
+ : entrySource
59
+ : undefined;
60
+
61
+ if (entry && typeof entry !== "object") {
62
+ log_error(
63
+ `presentScreen: entry option is not an object, entry: ${entry}`
64
+ );
65
+
66
+ return ActionResult.Error;
67
+ }
68
+
69
+ const result = await presentScreen({ typeMapping, entry });
70
+
71
+ if (result.error) {
72
+ return ActionResult.Error;
73
+ }
74
+
75
+ // Anything short of success stops the remaining actions in the chain.
76
+ return result.success ? ActionResult.Success : ActionResult.Cancel;
77
+ };
78
+ }