@applicaster/zapp-react-native-utils 16.0.0-alpha.9183418480 → 16.0.0-alpha.9506982263

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 (126) hide show
  1. package/actionsExecutor/ActionExecutor.ts +8 -10
  2. package/actionsExecutor/ActionExecutorContext.tsx +43 -326
  3. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  4. package/actionsExecutor/actions/appRestart.ts +24 -0
  5. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  6. package/actionsExecutor/actions/index.ts +30 -0
  7. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  8. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  9. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  10. package/actionsExecutor/actions/navigateToScreen.ts +123 -0
  11. package/actionsExecutor/actions/refreshComponent.ts +79 -0
  12. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  13. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  14. package/actionsExecutor/actions/sendCloudEvent.ts +88 -0
  15. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  16. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  17. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  18. package/actionsExecutor/actions/showToast.ts +87 -0
  19. package/actionsExecutor/actions/switchLayout.ts +40 -0
  20. package/actionsExecutor/types.ts +59 -0
  21. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  22. package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
  23. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  24. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  25. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  26. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  27. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  28. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  29. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  30. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  31. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  32. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  33. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  34. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  35. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  36. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  37. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  38. package/analyticsUtils/analyticsMapper.ts +4 -1
  39. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  40. package/appUtils/HooksManager/index.ts +3 -8
  41. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  42. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  43. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  44. package/appUtils/contextKeysManager/index.ts +1 -1
  45. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  46. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +138 -51
  47. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  48. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  49. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  50. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  51. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  52. package/appUtils/playerManager/index.ts +1 -1
  53. package/appUtils/playerManager/player.ts +115 -3
  54. package/appUtils/playerManager/playerFactory.ts +1 -1
  55. package/appUtils/playerManager/playerNative.ts +1 -1
  56. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  57. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  58. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  59. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  60. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  61. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  62. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  63. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  64. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  65. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  66. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  67. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  68. package/arrayUtils/__tests__/sample.test.ts +61 -0
  69. package/arrayUtils/index.ts +57 -20
  70. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  71. package/bottomSheet/index.ts +17 -0
  72. package/cellUtils/index.ts +3 -5
  73. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  74. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  75. package/colorUtils/index.ts +50 -0
  76. package/manifestUtils/_internals/index.js +6 -0
  77. package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
  78. package/manifestUtils/defaultManifestConfigurations/player.js +185 -19
  79. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  80. package/manifestUtils/fieldUtils/index.js +125 -0
  81. package/manifestUtils/keys.js +9 -0
  82. package/manifestUtils/mobileAction/button/index.js +16 -0
  83. package/manifestUtils/mobileAction/container/index.js +3 -1
  84. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  85. package/manifestUtils/platformIsTV.js +1 -0
  86. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  87. package/numberUtils/__tests__/isZero.test.ts +27 -0
  88. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  89. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  90. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  91. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  92. package/numberUtils/index.ts +27 -8
  93. package/package.json +2 -2
  94. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  95. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  96. package/pipesUtils/index.ts +1 -0
  97. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  98. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  99. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  100. package/playerUtils/contentDataKeys.ts +134 -0
  101. package/playerUtils/index.ts +24 -17
  102. package/playerUtils/isAudioItem.ts +26 -0
  103. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  104. package/reactHooks/actions/index.ts +51 -1
  105. package/reactHooks/cell-click/index.ts +18 -10
  106. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  107. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  108. package/reactHooks/feed/index.ts +5 -1
  109. package/reactHooks/feed/useBatchLoading.ts +9 -1
  110. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  111. package/reactHooks/layout/index.ts +1 -1
  112. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  113. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  114. package/reactHooks/navigation/index.ts +1 -1
  115. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  116. package/reactHooks/state/useComponentScreenState.ts +1 -1
  117. package/reactHooks/utils/index.ts +3 -2
  118. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  119. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  120. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  121. package/stringUtils/index.ts +2 -2
  122. package/uiActionsRegistrator/index.ts +203 -0
  123. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  124. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  125. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  126. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
@@ -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
+ }
@@ -0,0 +1,79 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
3
+ import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
4
+ import {
5
+ getInflatedDataSourceUrl,
6
+ getSearchContext,
7
+ } from "../../reactHooks/feed/useInflatedUrl";
8
+ import { ActionResult } from "../ActionExecutor";
9
+ import { ActionHandler, ActionExecutionContext } from "../types";
10
+ import { createLogger } from "../../logger";
11
+
12
+ const { log_info } = createLogger({
13
+ subsystem: "ActionExecutorContext",
14
+ category: "General",
15
+ });
16
+
17
+ /** Prefer component data.source, otherwise direct UIComponentContext parent. */
18
+ function getComponentFeedData(component) {
19
+ if (component?.data?.source) {
20
+ return component.data;
21
+ }
22
+
23
+ if (component?.parent?.data?.source) {
24
+ return component.parent.data;
25
+ }
26
+
27
+ return null;
28
+ }
29
+
30
+ /**
31
+ * Refreshes a component's data by reloading its data source.
32
+ * Supports URL inflation with context variables.
33
+ */
34
+ export const refreshComponentAction: ActionHandler = async (
35
+ _action,
36
+ context?: ActionExecutionContext
37
+ ): Promise<ActionResult> => {
38
+ const dispatch = appStore.getDispatch();
39
+
40
+ const componentData = getComponentFeedData(context?.component);
41
+
42
+ const source = componentData?.source;
43
+ const mapping = componentData?.mapping;
44
+
45
+ let dataSource = source;
46
+
47
+ if (source && mapping) {
48
+ dataSource =
49
+ getInflatedDataSourceUrl({
50
+ source,
51
+ contexts: {
52
+ entry: context?.screenEntry,
53
+ screen: context?.screenData,
54
+ search: getSearchContext(null, mapping),
55
+ },
56
+ mapping,
57
+ }) || source;
58
+ }
59
+
60
+ log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
61
+ source,
62
+ inflatedUrl: dataSource,
63
+ mapping,
64
+ entryContextId: context?.entryContext?.id,
65
+ entryId: context?.entry?.id,
66
+ });
67
+
68
+ // TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
69
+ // TODO: handle focused item removal
70
+ dispatch(
71
+ loadPipesData(dataSource, {
72
+ silentRefresh: false,
73
+ clearCache: true,
74
+ riverId: context?.screenData?.id,
75
+ })
76
+ );
77
+
78
+ return ActionResult.Success;
79
+ };
@@ -0,0 +1,35 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { screenSetVariable } from "../ScreenActions";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler, ActionExecutionContext } from "../types";
5
+
6
+ /**
7
+ * Options for screenSetVariable action.
8
+ */
9
+ export interface ScreenSetVariableOptions {
10
+ /** The key/namespace for storing the variable */
11
+ key: string;
12
+
13
+ /** Path to extract the value from entry */
14
+ selector?: string;
15
+ }
16
+
17
+ /**
18
+ * Sets a variable in screen state storage.
19
+ * The value is extracted from the entry using the selector option.
20
+ */
21
+ export const screenSetVariableAction: ActionHandler<
22
+ ScreenSetVariableOptions
23
+ > = async (action, context?: ActionExecutionContext): Promise<ActionResult> => {
24
+ const route = context?.screenRoute;
25
+ const screenStateStore = context?.screenStateStore;
26
+
27
+ await screenSetVariable(
28
+ route,
29
+ screenStateStore,
30
+ { entry: context?.entry, options: action.options },
31
+ action
32
+ );
33
+
34
+ return ActionResult.Success;
35
+ };
@@ -0,0 +1,38 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { screenToggleFlag } from "../ScreenActions";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler, ActionExecutionContext } from "../types";
5
+
6
+ /**
7
+ * Options for screenToggleFlag action.
8
+ */
9
+ export interface ScreenToggleFlagOptions {
10
+ /** The key/namespace for storing the flag */
11
+ key: string;
12
+
13
+ /** Path to extract the tag from entry (e.g., "extensions.tag") */
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 screen state storage (adds or removes an item from a collection).
22
+ * Useful for screen-level multi-select functionality.
23
+ */
24
+ export const screenToggleFlagAction: ActionHandler<
25
+ ScreenToggleFlagOptions
26
+ > = async (action, context?: ActionExecutionContext): Promise<ActionResult> => {
27
+ const screenRoute = context?.screenRoute;
28
+ const screenStateStore = context?.screenStateStore;
29
+
30
+ await screenToggleFlag(
31
+ screenRoute,
32
+ screenStateStore,
33
+ { entry: context?.entry, options: action.options },
34
+ action
35
+ );
36
+
37
+ return ActionResult.Success;
38
+ };
@@ -0,0 +1,88 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { createCloudEvent, sendCloudEvent } from "../../cloudEventsUtils";
3
+ import {
4
+ EntryResolver,
5
+ resolveObjectValues,
6
+ } from "../../appUtils/contextKeysManager/contextResolver";
7
+ import { ActionResult } from "../ActionExecutor";
8
+ import { ActionHandler, ActionExecutionContext } from "../types";
9
+ import { createLogger } from "../../logger";
10
+
11
+ const { log_info, log_error } = createLogger({
12
+ subsystem: "ActionExecutorContext",
13
+ category: "General",
14
+ });
15
+
16
+ /**
17
+ * Options for the sendCloudEvent action.
18
+ */
19
+ export interface SendCloudEventOptions {
20
+ /** The cloud event type (defaults to "com.applicaster.selector.action.v1") */
21
+ type?: string;
22
+
23
+ /** The event data payload */
24
+ data?: Record<string, any>;
25
+
26
+ /** The event subject (defaults to entry.id) */
27
+ subject?: string;
28
+
29
+ /** The URL endpoint to send the event to */
30
+ url: string;
31
+
32
+ /** Whether to inflate data with context variables */
33
+ inflateData?: boolean;
34
+ }
35
+
36
+ /**
37
+ * Sends a cloud event to a remote endpoint.
38
+ * Supports data inflation using context variables from entry and screen.
39
+ */
40
+ export const sendCloudEventAction: ActionHandler<
41
+ SendCloudEventOptions
42
+ > = async (action, context?: ActionExecutionContext): Promise<ActionResult> => {
43
+ try {
44
+ const options = action.options as SendCloudEventOptions;
45
+
46
+ const entry = context?.entry || {};
47
+ const entryResolver = new EntryResolver(entry as ZappEntry);
48
+ const screenData = context?.screenStateStore?.getState?.()?.data || {};
49
+ const screenResolver = new EntryResolver(screenData as ZappEntry);
50
+
51
+ const data =
52
+ options?.data && options.inflateData
53
+ ? await resolveObjectValues(options.data, {
54
+ entry: entryResolver,
55
+ screen: screenResolver,
56
+ })
57
+ : options?.data || entry;
58
+
59
+ const cloudEvent = await createCloudEvent({
60
+ type: options.type || "com.applicaster.selector.action.v1",
61
+ data,
62
+ subject: options.subject || String((entry as ZappEntry)?.id || ""),
63
+ });
64
+
65
+ log_info("handleAction: sendCloudEvent event", { cloudEvent });
66
+
67
+ const { error, code } = await sendCloudEvent(cloudEvent, options.url);
68
+
69
+ if (error) {
70
+ log_error("sendCloudEvent: error sending cloud event", { error });
71
+
72
+ return ActionResult.Error;
73
+ }
74
+
75
+ if (code && code >= 200 && code < 300 && !error) {
76
+ log_info("sendCloudEvent: cloud event sent successfully");
77
+
78
+ return ActionResult.Success;
79
+ }
80
+ } catch (error) {
81
+ log_error("sendCloudEvent: error sending cloud event", {
82
+ action,
83
+ error,
84
+ });
85
+ }
86
+
87
+ return ActionResult.Error;
88
+ };
@@ -0,0 +1,19 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
3
+ import { batchRemoveFromStorage } from "../../zappFrameworkUtils/localStorageHelper";
4
+ import { ActionResult } from "../ActionExecutor";
5
+ import { ActionHandler } from "../types";
6
+ import { StorageRemoveOptions } from "./localStorageRemove";
7
+
8
+ /**
9
+ * Removes values from session storage organized by namespaces.
10
+ */
11
+ export const sessionStorageRemoveAction: ActionHandler<
12
+ StorageRemoveOptions
13
+ > = async (action): Promise<ActionResult> => {
14
+ const namespaces = action.options.content;
15
+ await batchRemoveFromStorage(namespaces, sessionStorage);
16
+ // TODO: Add support for ownershipKey and ownershipNamespace
17
+
18
+ return ActionResult.Success;
19
+ };
@@ -0,0 +1,20 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
3
+ import { batchSave } from "../../zappFrameworkUtils/localStorageHelper";
4
+ import { ActionResult } from "../ActionExecutor";
5
+ import { ActionHandler } from "../types";
6
+ import { StorageSetOptions } from "./localStorageSet";
7
+
8
+ /**
9
+ * Saves values to session storage organized by namespaces.
10
+ * The values persist only for the current app session.
11
+ */
12
+ export const sessionStorageSetAction: ActionHandler<StorageSetOptions> = async (
13
+ action
14
+ ): Promise<ActionResult> => {
15
+ const namespaces = (action.options as StorageSetOptions).content;
16
+ await batchSave(namespaces, sessionStorage);
17
+ // TODO: Add support for ownershipKey and ownershipNamespace
18
+
19
+ return ActionResult.Success;
20
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { sessionStorageToggleFlag } from "../StorageActions";
3
+ import { ActionResult } from "../ActionExecutor";
4
+ import { ActionHandler, ActionExecutionContext } from "../types";
5
+ import { StorageToggleFlagOptions } from "./localStorageToggleFlag";
6
+
7
+ /**
8
+ * Toggles a flag in session storage (adds or removes an item from a collection).
9
+ * Values persist only for the current app session.
10
+ */
11
+ export const sessionStorageToggleFlagAction: ActionHandler<
12
+ StorageToggleFlagOptions
13
+ > = async (action, context?: ActionExecutionContext): Promise<ActionResult> => {
14
+ return await sessionStorageToggleFlag(context, action);
15
+ };
@@ -0,0 +1,87 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { postEvent } from "../../reactHooks/useSubscriberFor";
5
+
6
+ export const CONFIRMATION_TOAST_SOURCE = "confirmation";
7
+
8
+ export const CONFIRMATION_TOAST_DEFAULT_TIMEOUT = 1000;
9
+
10
+ /**
11
+ * Shows a mobile confirmation toast with Theme defaults from
12
+ * `Confirmation Toast / Message` in the base theme plugin.
13
+ *
14
+ * This action is confirmation-only by design: it always stamps
15
+ * `source: "confirmation"` (so Theme confirmation styles apply) and defaults
16
+ * `timeout` to 1000 ms. Non-confirmation toasts (e.g. Offline Experience)
17
+ * must post on the shared `"showToast"` event bus directly and omit `source`.
18
+ * Callers may override individual style fields; Theme supplies the rest.
19
+ *
20
+ * @example From React via ActionExecutorContext
21
+ * ```tsx
22
+ * import React, { useContext } from "react";
23
+ * import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
24
+ *
25
+ * function QueueButton() {
26
+ * const { handleAction } = useContext(ActionExecutorContext);
27
+ *
28
+ * const onPress = () => {
29
+ * void handleAction({
30
+ * type: "showToast",
31
+ * options: { message: "Added to queue" },
32
+ * });
33
+ * };
34
+ *
35
+ * return <Button onPress={onPress} title="Add to queue" />;
36
+ * }
37
+ * ```
38
+ *
39
+ * @example From code via the actionExecutor singleton
40
+ * ```ts
41
+ * import { actionExecutor } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
42
+ *
43
+ * await actionExecutor.handleAction({
44
+ * type: "showToast",
45
+ * options: {
46
+ * message: "Playlist created",
47
+ * style: { backgroundColor: "#00AA55" }, // optional partial override
48
+ * },
49
+ * });
50
+ * ```
51
+ *
52
+ * @example From entry / pipes actions JSON
53
+ * ```json
54
+ * {
55
+ * "type": "showToast",
56
+ * "options": {
57
+ * "message": "Item removed from playlist"
58
+ * }
59
+ * }
60
+ * ```
61
+ */
62
+ export interface ShowToastActionOptions {
63
+ id?: string;
64
+ message?: string;
65
+ extraMessage?: string;
66
+ style?: any;
67
+ timeout?: number;
68
+ }
69
+
70
+ export const showToastAction: ActionHandler<ShowToastActionOptions> = async (
71
+ action
72
+ ): Promise<ActionResult> => {
73
+ const options = action?.options;
74
+
75
+ postEvent("showToast", [
76
+ {
77
+ id: options?.id,
78
+ message: options?.message,
79
+ extraMessage: options?.extraMessage,
80
+ style: options?.style,
81
+ timeout: options?.timeout ?? CONFIRMATION_TOAST_DEFAULT_TIMEOUT,
82
+ source: CONFIRMATION_TOAST_SOURCE,
83
+ },
84
+ ]);
85
+
86
+ return ActionResult.Success;
87
+ };
@@ -0,0 +1,40 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
+ import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
4
+ import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
5
+ import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
6
+ import { ActionResult } from "../ActionExecutor";
7
+ import { ActionHandler } from "../types";
8
+ import { createLogger } from "../../logger";
9
+
10
+ const { log_info } = createLogger({
11
+ subsystem: "ActionExecutorContext",
12
+ category: "General",
13
+ });
14
+
15
+ /**
16
+ * Options for the switchLayout action.
17
+ */
18
+ export interface SwitchLayoutOptions {
19
+ /** The ID of the layout to switch to */
20
+ layoutId: string;
21
+ }
22
+
23
+ /**
24
+ * Switches the active layout and triggers an app reload.
25
+ * Saves the new layout ID to local storage before reloading.
26
+ */
27
+ export const switchLayoutAction: ActionHandler<SwitchLayoutOptions> = async (
28
+ action
29
+ ): Promise<ActionResult> => {
30
+ log_info("handleAction: switchLayout event");
31
+
32
+ await localStorage.setItem(
33
+ ACTIVE_LAYOUT_ID_STORAGE_KEY,
34
+ action.options.layoutId
35
+ );
36
+
37
+ QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
38
+
39
+ return ActionResult.Success;
40
+ };