@applicaster/zapp-react-native-utils 16.0.0-rc.6 → 16.0.0-rc.61

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 (161) hide show
  1. package/actionsExecutor/ActionExecutor.ts +47 -11
  2. package/actionsExecutor/ActionExecutorContext.tsx +87 -316
  3. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -0
  4. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  5. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  6. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +130 -0
  7. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  8. package/actionsExecutor/actions/appRestart.ts +24 -0
  9. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  10. package/actionsExecutor/actions/dismissBottomSheet.ts +22 -0
  11. package/actionsExecutor/actions/index.ts +34 -0
  12. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  13. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  14. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  15. package/actionsExecutor/actions/navigateToScreen.ts +123 -0
  16. package/actionsExecutor/actions/openBottomSheet.ts +322 -0
  17. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  18. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  19. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  20. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  21. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  22. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  23. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  24. package/actionsExecutor/actions/showToast.ts +87 -0
  25. package/actionsExecutor/actions/switchLayout.ts +40 -0
  26. package/actionsExecutor/consts.ts +23 -0
  27. package/actionsExecutor/types.ts +59 -0
  28. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  29. package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
  30. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  31. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  32. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  33. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  34. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  35. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  36. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  37. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  38. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  39. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  40. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  41. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  42. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  43. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  44. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  45. package/analyticsUtils/analyticsMapper.ts +4 -1
  46. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  47. package/appUtils/HooksManager/index.ts +12 -8
  48. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  49. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  50. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  51. package/appUtils/contextKeysManager/index.ts +1 -1
  52. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  53. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  54. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  55. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  56. package/appUtils/playerManager/OverlayObserver/utils.ts +49 -20
  57. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  58. package/appUtils/playerManager/__tests__/playerFactory.test.ts +150 -0
  59. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  60. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  61. package/appUtils/playerManager/index.ts +1 -1
  62. package/appUtils/playerManager/player.ts +115 -3
  63. package/appUtils/playerManager/playerFactory.ts +18 -35
  64. package/appUtils/playerManager/playerNative.ts +1 -1
  65. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  66. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  67. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  68. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  69. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  70. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  71. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  72. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  73. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  74. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  75. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  76. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  77. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  78. package/arrayUtils/__tests__/sample.test.ts +61 -0
  79. package/arrayUtils/index.ts +136 -20
  80. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  81. package/bottomSheet/index.ts +17 -0
  82. package/cellUtils/index.ts +3 -5
  83. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  84. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  85. package/colorUtils/index.ts +50 -0
  86. package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
  87. package/configurationUtils/manifestKeyParser.ts +38 -9
  88. package/configurationUtils/modalBlocksParser.ts +178 -0
  89. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  90. package/manifestUtils/_internals/index.js +6 -0
  91. package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
  92. package/manifestUtils/defaultManifestConfigurations/player.js +327 -19
  93. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  94. package/manifestUtils/fieldUtils/index.js +125 -0
  95. package/manifestUtils/index.js +3 -0
  96. package/manifestUtils/keys.js +9 -0
  97. package/manifestUtils/mobileAction/button/index.js +16 -0
  98. package/manifestUtils/mobileAction/container/index.js +3 -1
  99. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  100. package/manifestUtils/modalBlocks.js +304 -0
  101. package/manifestUtils/platformIsTV.js +1 -0
  102. package/modalState/ContentViewModel.ts +113 -0
  103. package/modalState/EditableCollection.ts +17 -0
  104. package/modalState/EditableCollectionRegistry.ts +51 -0
  105. package/modalState/ModalOrchestrator.ts +201 -0
  106. package/modalState/RemoteEditableCollection.ts +227 -0
  107. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  108. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  109. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  110. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +55 -0
  111. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  112. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  113. package/modalState/index.ts +30 -83
  114. package/modalState/store.ts +102 -0
  115. package/modalState/types.ts +137 -0
  116. package/modalState/useBottomSheetContent.ts +102 -0
  117. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  118. package/numberUtils/__tests__/isZero.test.ts +27 -0
  119. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  120. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  121. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  122. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  123. package/numberUtils/index.ts +27 -8
  124. package/package.json +2 -2
  125. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  126. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  127. package/pipesUtils/index.ts +1 -0
  128. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  129. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  130. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  131. package/playerUtils/contentDataKeys.ts +134 -0
  132. package/playerUtils/index.ts +41 -14
  133. package/playerUtils/isAudioItem.ts +26 -0
  134. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  135. package/reactHooks/actions/index.ts +51 -1
  136. package/reactHooks/cell-click/index.ts +18 -10
  137. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  138. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  139. package/reactHooks/feed/index.ts +5 -1
  140. package/reactHooks/feed/useBatchLoading.ts +9 -1
  141. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  142. package/reactHooks/index.ts +2 -0
  143. package/reactHooks/layout/index.ts +1 -1
  144. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  145. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  146. package/reactHooks/navigation/index.ts +1 -1
  147. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  148. package/reactHooks/state/useComponentScreenState.ts +1 -1
  149. package/reactHooks/usePluginConfiguration.ts +4 -1
  150. package/reactHooks/utils/__tests__/index.test.js +22 -2
  151. package/reactHooks/utils/index.ts +13 -2
  152. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  153. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  154. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  155. package/stringUtils/index.ts +2 -2
  156. package/uiActionsRegistrator/index.ts +203 -0
  157. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  158. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  159. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  160. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  161. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,76 @@
1
+ import { openBottomSheetAction } from "../openBottomSheet";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+ import { openBottomSheetModal } from "../../../modalState/store";
4
+ import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
5
+
6
+ jest.mock("../../../modalState/store", () => ({
7
+ openBottomSheetModal: jest.fn(),
8
+ }));
9
+
10
+ jest.mock("../../../modalState/ModalOrchestrator", () => ({
11
+ modalOrchestrator: {
12
+ open: jest.fn(),
13
+ },
14
+ isPresentSubMenuAction: jest.requireActual("../../../modalState/types")
15
+ .isPresentSubMenuAction,
16
+ }));
17
+
18
+ describe("openBottomSheetAction custom content", () => {
19
+ beforeEach(() => {
20
+ jest.clearAllMocks();
21
+ });
22
+
23
+ it("opens default sheet with contentComponent body props", async () => {
24
+ const CustomContent = function CustomContent() {
25
+ return null;
26
+ };
27
+
28
+ const result = await openBottomSheetAction({
29
+ type: "openBottomSheet",
30
+ options: {
31
+ header: { title: "Create Playlist" },
32
+ content: {
33
+ component: CustomContent,
34
+ props: {
35
+ inputLabel: "Name your playlist",
36
+ buttonLabel: "Create",
37
+ defaultValue: "",
38
+ submitAction: { type: "sendCloudEvent", options: {} },
39
+ },
40
+ },
41
+ },
42
+ } as any);
43
+
44
+ expect(result).toBe(ActionResult.Success);
45
+ expect(openBottomSheetModal).toHaveBeenCalledTimes(1);
46
+ expect(modalOrchestrator.open).not.toHaveBeenCalled();
47
+
48
+ const args = (openBottomSheetModal as jest.Mock).mock.calls[0][0];
49
+ // Default ModalComponent provides the standard header
50
+ expect(args.ModalBottomSheetContent).toBeUndefined();
51
+
52
+ expect(args.modalBottomSheetContentProps).toMatchObject({
53
+ title: "Create Playlist",
54
+ contentComponent: CustomContent,
55
+ contentComponentProps: {
56
+ inputLabel: "Name your playlist",
57
+ buttonLabel: "Create",
58
+ defaultValue: "",
59
+ },
60
+ });
61
+ });
62
+
63
+ it("returns Error when neither list data nor content.component is provided", async () => {
64
+ const result = await openBottomSheetAction({
65
+ type: "openBottomSheet",
66
+ options: {
67
+ header: { title: "Empty" },
68
+ content: {},
69
+ },
70
+ } as any);
71
+
72
+ expect(result).toBe(ActionResult.Error);
73
+ expect(openBottomSheetModal).not.toHaveBeenCalled();
74
+ expect(modalOrchestrator.open).not.toHaveBeenCalled();
75
+ });
76
+ });
@@ -0,0 +1,130 @@
1
+ import { openBottomSheetAction } from "../openBottomSheet";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+ import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
4
+
5
+ jest.mock("../../../modalState/store", () => ({
6
+ openBottomSheetModal: jest.fn(),
7
+ }));
8
+
9
+ jest.mock("../../../modalState/ModalOrchestrator", () => ({
10
+ modalOrchestrator: {
11
+ open: jest.fn(),
12
+ replace: jest.fn(),
13
+ stackSize: 0,
14
+ },
15
+ isPresentSubMenuAction: jest.requireActual("../../../modalState/types")
16
+ .isPresentSubMenuAction,
17
+ }));
18
+
19
+ describe("openBottomSheetAction inline items", () => {
20
+ const HeaderComponent = function HeaderComponent() {
21
+ return null;
22
+ };
23
+
24
+ beforeEach(() => {
25
+ jest.clearAllMocks();
26
+ (modalOrchestrator as any).stackSize = 0;
27
+ });
28
+
29
+ const speedSheetAction = {
30
+ type: "openBottomSheet",
31
+ options: {
32
+ header: { title: "Playback Speed" },
33
+ content: {
34
+ role: "collection_selector",
35
+ behavior: {
36
+ selectMode: "single",
37
+ currentSelection: ["1"],
38
+ },
39
+ items: [
40
+ {
41
+ id: "0.8",
42
+ title: "0.8x",
43
+ extensions: {
44
+ tap_actions: {
45
+ actions: [
46
+ { type: "setPlaybackSpeed", options: { value: 0.8 } },
47
+ ],
48
+ },
49
+ },
50
+ },
51
+ {
52
+ id: "1",
53
+ title: "1x",
54
+ extensions: {
55
+ tap_actions: {
56
+ actions: [{ type: "setPlaybackSpeed", options: { value: 1 } }],
57
+ },
58
+ },
59
+ },
60
+ ],
61
+ },
62
+ },
63
+ } as any;
64
+
65
+ it("opens orchestrator with inline items and marks current selection", async () => {
66
+ const result = await openBottomSheetAction(speedSheetAction);
67
+
68
+ expect(result).toBe(ActionResult.Success);
69
+ expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
70
+ expect(modalOrchestrator.replace).not.toHaveBeenCalled();
71
+
72
+ const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
73
+
74
+ expect(menu.content.items[0].isSelected).toBe(false);
75
+
76
+ expect(menu.content.items[1]).toMatchObject({
77
+ id: "1",
78
+ title: "1x",
79
+ isSelected: true,
80
+ action: { type: "setPlaybackSpeed", options: { value: 1 } },
81
+ });
82
+ });
83
+
84
+ it("pushes a new sheet by default even when another sheet is already open", async () => {
85
+ (modalOrchestrator as any).stackSize = 1;
86
+
87
+ await openBottomSheetAction(speedSheetAction);
88
+
89
+ expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
90
+ expect(modalOrchestrator.replace).not.toHaveBeenCalled();
91
+ });
92
+
93
+ it("replaces the current sheet when options.replace is true", async () => {
94
+ (modalOrchestrator as any).stackSize = 1;
95
+
96
+ await openBottomSheetAction({
97
+ ...speedSheetAction,
98
+ options: { ...speedSheetAction.options, replace: true },
99
+ });
100
+
101
+ expect(modalOrchestrator.replace).toHaveBeenCalledTimes(1);
102
+ expect(modalOrchestrator.open).not.toHaveBeenCalled();
103
+ });
104
+
105
+ it("forwards a custom header component and its props onto the menu", async () => {
106
+ await openBottomSheetAction({
107
+ type: "openBottomSheet",
108
+ options: {
109
+ header: {
110
+ title: "Sleep Timer",
111
+ component: HeaderComponent,
112
+ componentProps: { timerDate: 123 },
113
+ },
114
+ content: {
115
+ items: [{ id: "5", title: "5 minutes" }],
116
+ },
117
+ },
118
+ } as any);
119
+
120
+ const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
121
+
122
+ expect(menu.header).toEqual({
123
+ title: "Sleep Timer",
124
+ subtitle: undefined,
125
+ icon: undefined,
126
+ component: HeaderComponent,
127
+ componentProps: { timerDate: 123 },
128
+ });
129
+ });
130
+ });
@@ -0,0 +1,88 @@
1
+ import { showToastAction } from "../showToast";
2
+ import { postEvent } from "../../../reactHooks/useSubscriberFor";
3
+ import { ActionResult } from "../../ActionExecutor";
4
+
5
+ jest.mock("../../../reactHooks/useSubscriberFor", () => ({
6
+ postEvent: jest.fn(),
7
+ }));
8
+
9
+ describe("showToastAction", () => {
10
+ beforeEach(() => {
11
+ jest.clearAllMocks();
12
+ });
13
+
14
+ it("calls postEvent with confirmation source, default timeout, and returns Success", async () => {
15
+ const action = {
16
+ type: "showToast",
17
+ options: {
18
+ id: "toast-1",
19
+ message: "Added to queue",
20
+ extraMessage: "Extra info",
21
+ },
22
+ };
23
+
24
+ const result = await showToastAction(action);
25
+
26
+ expect(postEvent).toHaveBeenCalledTimes(1);
27
+
28
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
29
+ {
30
+ id: "toast-1",
31
+ message: "Added to queue",
32
+ extraMessage: "Extra info",
33
+ style: undefined,
34
+ timeout: 1000,
35
+ source: "confirmation",
36
+ },
37
+ ]);
38
+
39
+ expect(result).toBe(ActionResult.Success);
40
+ });
41
+
42
+ it("preserves an explicit timeout and style override", async () => {
43
+ const action = {
44
+ type: "showToast",
45
+ options: {
46
+ message: "Playlist created",
47
+ timeout: 3000,
48
+ style: { backgroundColor: "#00FF00" },
49
+ },
50
+ };
51
+
52
+ await showToastAction(action);
53
+
54
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
55
+ {
56
+ id: undefined,
57
+ message: "Playlist created",
58
+ extraMessage: undefined,
59
+ style: { backgroundColor: "#00FF00" },
60
+ timeout: 3000,
61
+ source: "confirmation",
62
+ },
63
+ ]);
64
+ });
65
+
66
+ it("handles missing or empty options without throwing", async () => {
67
+ const action = {
68
+ type: "showToast",
69
+ };
70
+
71
+ const result = await showToastAction(action);
72
+
73
+ expect(postEvent).toHaveBeenCalledTimes(1);
74
+
75
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
76
+ {
77
+ id: undefined,
78
+ message: undefined,
79
+ extraMessage: undefined,
80
+ style: undefined,
81
+ timeout: 1000,
82
+ source: "confirmation",
83
+ },
84
+ ]);
85
+
86
+ expect(result).toBe(ActionResult.Success);
87
+ });
88
+ });
@@ -0,0 +1,24 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
3
+ import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
4
+ import { ActionResult } from "../ActionExecutor";
5
+ import { ActionHandler } from "../types";
6
+ import { createLogger } from "../../logger";
7
+
8
+ const { log_info } = createLogger({
9
+ subsystem: "ActionExecutorContext",
10
+ category: "General",
11
+ });
12
+
13
+ /**
14
+ * Restarts the application by triggering a force reload event.
15
+ * This action does not require any options or context.
16
+ */
17
+ export const appRestartAction: ActionHandler =
18
+ async (): Promise<ActionResult> => {
19
+ log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
20
+
21
+ QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
22
+
23
+ return ActionResult.Success;
24
+ };
@@ -0,0 +1,53 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { showConfirmationDialog } from "../../alertUtils";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler } from "../types";
5
+ import { createLogger } from "../../logger";
6
+
7
+ const { log_info } = createLogger({
8
+ subsystem: "ActionExecutorContext",
9
+ category: "General",
10
+ });
11
+
12
+ /**
13
+ * Options for the confirmDialog action.
14
+ */
15
+ export interface ConfirmDialogOptions {
16
+ /** Dialog title (required) */
17
+ title: string;
18
+
19
+ /** Dialog message */
20
+ message?: string;
21
+
22
+ /** Confirm button text */
23
+ okButtonText?: string;
24
+
25
+ /** Cancel button text */
26
+ cancelButtonText?: string;
27
+
28
+ /** Callback when confirmed (deprecated - use action result) */
29
+ confirmCompletion?: () => void;
30
+
31
+ /** Callback when cancelled (deprecated - use action result) */
32
+ cancelCompletion?: () => void;
33
+ }
34
+
35
+ /**
36
+ * Shows a confirmation dialog to the user.
37
+ * Resolves to Success if user confirms, Cancel if user dismisses.
38
+ */
39
+ export const confirmDialogAction: ActionHandler<ConfirmDialogOptions> = async (
40
+ action
41
+ ): Promise<ActionResult> => {
42
+ log_info("handleAction: confirmDialog event");
43
+
44
+ const options = action.options as ConfirmDialogOptions;
45
+
46
+ return new Promise<ActionResult>((resolve) => {
47
+ showConfirmationDialog({
48
+ ...options,
49
+ confirmCompletion: () => resolve(ActionResult.Success),
50
+ cancelCompletion: () => resolve(ActionResult.Cancel),
51
+ });
52
+ });
53
+ };
@@ -0,0 +1,22 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { dismissModal } from "../../modalState";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler } from "../types";
5
+ import { createLogger } from "../../logger";
6
+
7
+ const { log_info } = createLogger({
8
+ subsystem: "ActionExecutorContext",
9
+ category: "General",
10
+ });
11
+
12
+ /**
13
+ * Dismisses the active bottom sheet / modal.
14
+ */
15
+ export const dismissBottomSheetAction: ActionHandler<
16
+ any
17
+ > = async (): Promise<ActionResult> => {
18
+ log_info("handleAction: dismissBottomSheet");
19
+ dismissModal();
20
+
21
+ return ActionResult.Success;
22
+ };
@@ -0,0 +1,34 @@
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 { sendCloudEventAction } from "./sendCloudEvent";
19
+
20
+ export { sessionStorageToggleFlagAction } from "./sessionStorageToggleFlag";
21
+
22
+ export { localStorageToggleFlagAction } from "./localStorageToggleFlag";
23
+
24
+ export { screenSetVariableAction } from "./screenSetVariable";
25
+
26
+ export { screenToggleFlagAction } from "./screenToggleFlag";
27
+
28
+ export { createNavigateToScreenAction } from "./navigateToScreen";
29
+
30
+ export { showToastAction } from "./showToast";
31
+
32
+ export { openBottomSheetAction } from "./openBottomSheet";
33
+
34
+ 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,123 @@
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
+ /**
31
+ * Creates a navigation action handler with the provided dependencies.
32
+ * This factory pattern allows the action to access navigation state at runtime.
33
+ *
34
+ * @param navigator - The app navigator for push/replace operations
35
+ * @param rivers - Map of screen IDs to river definitions
36
+ * @param contentTypes - Map of content type names to screen configurations
37
+ * @returns An action handler that performs screen navigation
38
+ */
39
+ export function createNavigateToScreenAction(
40
+ navigator: QuickBrickAppNavigator,
41
+ rivers: Record<string, ZappRiver>,
42
+ contentTypes: ZappContentTypes
43
+ ): ActionHandler<NavigateToScreenOptions> {
44
+ return async function navigateToScreenAction(
45
+ action,
46
+ context?: ActionExecutionContext
47
+ ): Promise<ActionResult> {
48
+ const screenType = action.options?.typeMapping;
49
+
50
+ if (!screenType) {
51
+ log_error("navigateToScreen: typeMapping option is missing");
52
+
53
+ return ActionResult.Error;
54
+ }
55
+
56
+ const navigationAction = action.options?.navigationAction;
57
+ const entrySource = action.options?.entry;
58
+
59
+ const entry = entrySource
60
+ ? entrySource === "@{entry/}"
61
+ ? context?.entry
62
+ : entrySource
63
+ : null;
64
+
65
+ if (entry) {
66
+ if (typeof entry !== "object") {
67
+ log_error(
68
+ `navigateToScreen: entry option is not an object, entry: ${entry}`
69
+ );
70
+
71
+ return ActionResult.Error;
72
+ }
73
+
74
+ log_info(
75
+ `navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
76
+ );
77
+
78
+ const overriddenEntry: ZappEntry = {
79
+ ...entry,
80
+ type: {
81
+ value: screenType,
82
+ },
83
+ };
84
+
85
+ if (navigationAction === "push") {
86
+ navigator.push(overriddenEntry);
87
+ } else {
88
+ // Use replaceTop for entries since replace() only accepts ZappRiver
89
+ navigator.replaceTop(overriddenEntry);
90
+ }
91
+
92
+ return ActionResult.Success;
93
+ }
94
+
95
+ const screenId = contentTypes?.[screenType]?.screen_id || null;
96
+
97
+ if (!screenId) {
98
+ log_error(
99
+ `navigateToScreen: can not resolve screen type mapping: ${screenType}`
100
+ );
101
+
102
+ return ActionResult.Error;
103
+ }
104
+
105
+ const river = rivers[screenId];
106
+
107
+ if (!river) {
108
+ log_error("navigateToScreen: can not resolve river");
109
+
110
+ return ActionResult.Error;
111
+ }
112
+
113
+ context?.callback?.({ success: false, error: null, abort: true });
114
+
115
+ if (navigationAction === "push") {
116
+ navigator.push(river);
117
+ } else {
118
+ navigator.replace(river);
119
+ }
120
+
121
+ return ActionResult.Success;
122
+ };
123
+ }