@applicaster/zapp-react-native-utils 16.0.0-alpha.8901714553 → 16.0.0-alpha.9530606740

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 (60) hide show
  1. package/actionsExecutor/ActionExecutor.ts +8 -10
  2. package/actionsExecutor/ActionExecutorContext.tsx +41 -325
  3. package/actionsExecutor/actions/appRestart.ts +24 -0
  4. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  5. package/actionsExecutor/actions/index.ts +30 -0
  6. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  7. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  8. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  9. package/actionsExecutor/actions/navigateToScreen.ts +123 -0
  10. package/actionsExecutor/actions/openBottomSheet.ts +177 -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/switchLayout.ts +40 -0
  19. package/actionsExecutor/types.ts +59 -0
  20. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  21. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  22. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  23. package/appUtils/contextKeysManager/index.ts +1 -1
  24. package/cellUtils/index.ts +3 -5
  25. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  26. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  27. package/colorUtils/index.ts +50 -0
  28. package/manifestUtils/_internals/index.js +6 -0
  29. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  30. package/manifestUtils/fieldUtils/index.js +125 -0
  31. package/manifestUtils/keys.js +9 -0
  32. package/manifestUtils/mobileAction/button/index.js +16 -0
  33. package/manifestUtils/mobileAction/container/index.js +3 -1
  34. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  35. package/manifestUtils/platformIsTV.js +1 -0
  36. package/modalState/ContentViewModel.ts +59 -0
  37. package/modalState/ModalOrchestrator.ts +204 -0
  38. package/modalState/__tests__/ContentViewModel.test.ts +107 -0
  39. package/modalState/components/ActionItem.tsx +155 -0
  40. package/modalState/components/BottomSheetHeader.tsx +245 -0
  41. package/modalState/components/PrimaryButton.tsx +54 -0
  42. package/modalState/components/TrackItem.tsx +241 -0
  43. package/modalState/index.ts +25 -74
  44. package/modalState/store.ts +102 -0
  45. package/modalState/types.ts +55 -0
  46. package/package.json +2 -2
  47. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  48. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  49. package/pipesUtils/index.ts +1 -0
  50. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  51. package/reactHooks/actions/index.ts +51 -1
  52. package/reactHooks/cell-click/index.ts +3 -3
  53. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  54. package/reactHooks/feed/index.ts +5 -1
  55. package/reactHooks/feed/useBatchLoading.ts +9 -1
  56. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  57. package/reactHooks/utils/index.ts +3 -2
  58. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  59. package/uiActionsRegistrator/index.ts +203 -0
  60. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
@@ -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,177 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import {
3
+ PipesClientResponseHelper,
4
+ RequestBuilder,
5
+ } from "@applicaster/zapp-pipes-v2-client";
6
+ import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
7
+ import { isPresentSubMenuAction, Menu, MenuItem } from "../../modalState/types";
8
+ import { actionExecutor, ActionResult } from "../ActionExecutor";
9
+ import { createLogger } from "../../logger";
10
+
11
+ const { log_info, log_error } = createLogger({
12
+ subsystem: "ActionExecutorContext",
13
+ category: "General",
14
+ });
15
+
16
+ /**
17
+ * Converts a ZappEntry from a pipes feed into a MenuItem.
18
+ * - Icon: first src found in the image media_group.
19
+ * - Primary action: taken from tap_actions.actions[0].
20
+ * - isSelected: true when entry.id is in currentSelection.
21
+ */
22
+ export function entryToMenuItem(
23
+ entry: ZappEntry,
24
+ currentSelection: string[] = []
25
+ ): MenuItem {
26
+ const imageGroup = entry.media_group?.find((g) => g.type === "image");
27
+
28
+ const firstImage = Array.isArray(imageGroup?.media_item)
29
+ ? imageGroup.media_item[0]
30
+ : imageGroup?.media_item;
31
+
32
+ // Primary action — first tap_action on the entry
33
+ const tapActions = entry.extensions?.tap_actions?.actions || [];
34
+ const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
35
+
36
+ let summary = entry.summary as string;
37
+
38
+ // TODO: remove just a small logic for debugging
39
+
40
+ if (
41
+ !summary &&
42
+ entry.extensions &&
43
+ typeof entry.extensions.item_count === "number"
44
+ ) {
45
+ const count = entry.extensions.item_count;
46
+ summary = `${count} ${count === 1 ? "Item" : "Items"}`;
47
+ }
48
+
49
+ return {
50
+ title: entry.title as string,
51
+ summary,
52
+ icon: firstImage?.src,
53
+ isSelected: currentSelection.includes(String(entry.id)),
54
+ action: primaryAction,
55
+ };
56
+ }
57
+
58
+ // Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
59
+ export async function loadItemsFromSource(
60
+ source: string,
61
+ context?: Record<string, any>
62
+ ): Promise<MenuItem[]> {
63
+ const requestBuilder = new RequestBuilder()
64
+ .setEntryContext(context?.entry || {})
65
+ .setScreenContext(context?.screenData || {})
66
+ .setUrl(source);
67
+
68
+ await requestBuilder.buildAxiosRequest();
69
+
70
+ const responseData = await requestBuilder.call<ZappFeed>();
71
+
72
+ const responseHelper = new PipesClientResponseHelper(responseData);
73
+
74
+ if (responseHelper.error) {
75
+ throw responseHelper.error;
76
+ }
77
+
78
+ const feed = responseData?.response as ZappFeed;
79
+
80
+ const rawSelection = feed?.extensions?.behavior?.current_selection;
81
+
82
+ const currentSelection: string[] = Array.isArray(rawSelection)
83
+ ? (rawSelection as any).map(String)
84
+ : rawSelection !== undefined && rawSelection !== null
85
+ ? [String(rawSelection)]
86
+ : [];
87
+
88
+ return (feed?.entry || []).map((entry) =>
89
+ entryToMenuItem(entry, currentSelection)
90
+ );
91
+ }
92
+
93
+ export async function openBottomSheetAction(
94
+ action: ActionType,
95
+ context?: Record<string, any>
96
+ ): Promise<ActionResult> {
97
+ try {
98
+ const { content, header } = action.options || {};
99
+
100
+ const inlineItems: ZappEntry[] = content?.items;
101
+ const itemsUrl: string = content?.itemsUrl;
102
+
103
+ let items: MenuItem[];
104
+
105
+ if (Array.isArray(inlineItems) && inlineItems.length > 0) {
106
+ log_info("openBottomSheet: using inline items from action options", {
107
+ count: inlineItems.length,
108
+ });
109
+
110
+ items = inlineItems.map((entry) => entryToMenuItem(entry));
111
+ } else if (itemsUrl) {
112
+ log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
113
+
114
+ items = await loadItemsFromSource(itemsUrl, context);
115
+
116
+ log_info(
117
+ `openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
118
+ );
119
+ } else {
120
+ log_error(
121
+ "openBottomSheet: no itemsUrl or items provided in action options"
122
+ );
123
+
124
+ return ActionResult.Error;
125
+ }
126
+
127
+ const menu: Menu = {
128
+ header: header
129
+ ? {
130
+ title: header.title,
131
+ subtitle: header.subtitle,
132
+ icon: header.icon,
133
+ }
134
+ : undefined,
135
+ content: {
136
+ title: content?.title ?? "",
137
+ items,
138
+ itemsUrl, // stored so the component can reload after an action
139
+ },
140
+ };
141
+
142
+ /**
143
+ * Called when the user taps a menu item.
144
+ *
145
+ * - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
146
+ * - Any other Action type → forwarded to the action executor, keeping the
147
+ * original execution context so screen/entry data is available to handlers.
148
+ * The pressed item is also added as `entry` so downstream actions can
149
+ * reference it.
150
+ */
151
+ const onItemPress = async (item: MenuItem): Promise<void> => {
152
+ if (!item.action || isPresentSubMenuAction(item.action)) {
153
+ // Submenu navigation is handled internally by the orchestrator
154
+ return;
155
+ }
156
+
157
+ await actionExecutor.handleAction(
158
+ item.action as ActionType,
159
+ {
160
+ ...context,
161
+ entry: item as any,
162
+ } as any
163
+ );
164
+ };
165
+
166
+ modalOrchestrator.open(menu, onItemPress);
167
+
168
+ return ActionResult.Success;
169
+ } catch (error) {
170
+ log_error("openBottomSheet: failed to open bottom sheet", {
171
+ error,
172
+ action,
173
+ });
174
+
175
+ return ActionResult.Error;
176
+ }
177
+ }
@@ -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,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
+ };