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

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 +208 -0
  105. package/configurationUtils/manifestKeyParser.ts +50 -10
  106. package/configurationUtils/modalBlocksParser.ts +200 -0
  107. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  108. package/entryActions/aliasPresentation.ts +108 -0
  109. package/entryActions/buildEntryActions.ts +167 -0
  110. package/entryActions/index.ts +15 -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,235 @@
1
+ import { buildEntryActions } from "../buildEntryActions";
2
+
3
+ describe("buildEntryActions - alias & label resolution", () => {
4
+ const mockDeps = {
5
+ actionExecutor: { handleActions: jest.fn() } as any,
6
+ actionContext: {},
7
+ };
8
+
9
+ const resolveEntryActions = (entry: ZappEntry) =>
10
+ buildEntryActions(entry, mockDeps);
11
+
12
+ it("resolves entry action with explicit button title", () => {
13
+ const entry = {
14
+ id: "entry-1",
15
+ extensions: {
16
+ entry_action: [
17
+ {
18
+ button: {
19
+ title: "Custom Action Title",
20
+ iconURL: "http://example.com/icon.png",
21
+ },
22
+ actions: [{ type: "test" }],
23
+ dismiss_on_action: true,
24
+ },
25
+ ],
26
+ },
27
+ };
28
+
29
+ const actions = resolveEntryActions(entry as any);
30
+
31
+ expect(actions).toHaveLength(1);
32
+ expect(actions[0].identifier).toBe("entry_action_0");
33
+
34
+ const state = actions[0].action.initialEntryState(entry as any);
35
+
36
+ expect(state).toEqual({
37
+ state: 0,
38
+ label: "Custom Action Title",
39
+ asset: "http://example.com/icon.png",
40
+ });
41
+ });
42
+
43
+ it("resolves entry action with button label property", () => {
44
+ const entry = {
45
+ id: "entry-2",
46
+ extensions: {
47
+ entry_action: [
48
+ {
49
+ button: { label: "Label Property Action" },
50
+ actions: [{ type: "test" }],
51
+ },
52
+ ],
53
+ },
54
+ };
55
+
56
+ const actions = resolveEntryActions(entry as any);
57
+
58
+ expect(actions).toHaveLength(1);
59
+ const state = actions[0].action.initialEntryState(entry as any);
60
+ expect(state.label).toBe("Label Property Action");
61
+ });
62
+
63
+ it("humanizes an un-overridden alias and falls back to the placeholder asset", () => {
64
+ const entry = {
65
+ id: "entry-3",
66
+ extensions: {
67
+ entry_action: [
68
+ {
69
+ button: { alias: "add_all_to_queue" },
70
+ actions: [{ type: "test" }],
71
+ dismiss_on_action: true,
72
+ },
73
+ {
74
+ button: { alias: "custom_unknown_action" },
75
+ actions: [{ type: "test" }],
76
+ },
77
+ ],
78
+ },
79
+ };
80
+
81
+ const actions = resolveEntryActions(entry as any);
82
+
83
+ expect(actions).toHaveLength(2);
84
+
85
+ // No built-in alias vocabulary any more: underscores become spaces and
86
+ // only the first letter is capitalized, so "queue" stays lowercase.
87
+ expect(actions[0].action.initialEntryState(entry as any)).toMatchObject({
88
+ state: 0,
89
+ label: "Add all to queue",
90
+ });
91
+
92
+ expect(actions[1].action.initialEntryState(entry as any)).toMatchObject({
93
+ state: 0,
94
+ label: "Custom unknown action",
95
+ });
96
+
97
+ // The asset has no such fallback: without an override it is the red-box
98
+ // placeholder, so a missing Studio icon is visible rather than absent.
99
+ for (const action of actions) {
100
+ expect(action.action.initialEntryState(entry as any)).toMatchObject({
101
+ asset: expect.stringMatching(/^data:image\/png;base64,/),
102
+ });
103
+ }
104
+ });
105
+
106
+ it("prefers aliasPresentation overrides over the humanized fallbacks", () => {
107
+ const deps = {
108
+ actionExecutor: { handleActions: jest.fn() } as any,
109
+ actionContext: {},
110
+ aliasPresentation: {
111
+ labels: { add_all_to_queue: "Add all to Queue" },
112
+ assets: { add_all_to_queue: "http://example.com/queue.png" },
113
+ },
114
+ };
115
+
116
+ const entry = {
117
+ id: "entry-4",
118
+ extensions: {
119
+ entry_action: [
120
+ {
121
+ button: { alias: "add_all_to_queue" },
122
+ actions: [{ type: "test" }],
123
+ },
124
+ {
125
+ button: { alias: "not_overridden" },
126
+ actions: [{ type: "test" }],
127
+ },
128
+ ],
129
+ },
130
+ };
131
+
132
+ const actions = buildEntryActions(entry as any, deps);
133
+
134
+ expect(actions[0].action.initialEntryState(entry as any)).toMatchObject({
135
+ label: "Add all to Queue",
136
+ asset: "http://example.com/queue.png",
137
+ });
138
+
139
+ // Overrides are per-alias, so an alias absent from the map still humanizes.
140
+ expect(actions[1].action.initialEntryState(entry as any)).toMatchObject({
141
+ label: "Not overridden",
142
+ });
143
+ });
144
+
145
+ it("returns no asset when the button has neither iconURL nor alias", () => {
146
+ const entry = {
147
+ id: "entry-5",
148
+ extensions: {
149
+ entry_action: [
150
+ {
151
+ button: { label: "Plain Label" },
152
+ actions: [{ type: "test" }],
153
+ },
154
+ ],
155
+ },
156
+ };
157
+
158
+ const actions = resolveEntryActions(entry as any);
159
+ const state = actions[0].action.initialEntryState(entry as any);
160
+
161
+ expect(state.label).toBe("Plain Label");
162
+ expect(state.asset).toBeUndefined();
163
+ });
164
+
165
+ it("uses actionExecutor.getActionState for plugin-provided label and asset", () => {
166
+ mockDeps.actionExecutor.getActionState = jest.fn(() => ({
167
+ label: "From Plugin",
168
+ asset: "plugin_asset",
169
+ }));
170
+
171
+ const entry = {
172
+ id: "entry-plugin-state",
173
+ extensions: {
174
+ entry_action: [
175
+ {
176
+ button: { alias: "custom_plugin_action" },
177
+ actions: [{ type: "plugin-action" }],
178
+ },
179
+ ],
180
+ },
181
+ };
182
+
183
+ const actions = resolveEntryActions(entry as any);
184
+ const state = actions[0].action.initialEntryState(entry as any);
185
+
186
+ expect(mockDeps.actionExecutor.getActionState).toHaveBeenCalledWith(
187
+ "plugin-action",
188
+ entry
189
+ );
190
+
191
+ expect(state).toMatchObject({
192
+ label: "From Plugin",
193
+ asset: "plugin_asset",
194
+ });
195
+ });
196
+ });
197
+
198
+ describe("buildEntryActions - invokeAction execution context", () => {
199
+ it("forwards the List component from invoke options into handleActions", async () => {
200
+ const handleActions = jest.fn();
201
+
202
+ const component = {
203
+ id: "list-1",
204
+ data: { source: "https://example.com/user/collections/abc" },
205
+ };
206
+
207
+ const deps = {
208
+ actionExecutor: { handleActions } as any,
209
+ actionContext: { screenData: { id: "playlist-screen" } },
210
+ };
211
+
212
+ const entry = {
213
+ id: "entry-1",
214
+ extensions: {
215
+ entry_action: [
216
+ {
217
+ button: { title: "Edit Name" },
218
+ actions: [{ type: "refreshComponent" }],
219
+ },
220
+ ],
221
+ },
222
+ };
223
+
224
+ const [action] = buildEntryActions(entry as any, deps);
225
+
226
+ await action.action.invokeAction(entry as any, { component });
227
+
228
+ expect(handleActions).toHaveBeenCalledWith([{ type: "refreshComponent" }], {
229
+ entry,
230
+ entryContext: entry,
231
+ screenData: { id: "playlist-screen" },
232
+ component,
233
+ });
234
+ });
235
+ });
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Presentation fallbacks for backend action aliases.
3
+ *
4
+ * Entries may declare an action by `alias` alone, without a label or an icon.
5
+ * There is no built-in alias vocabulary: a label falls back to a humanized
6
+ * version of the alias itself, and an icon falls back to an inline placeholder
7
+ * that is deliberately conspicuous, so a missing asset reads as unconfigured
8
+ * rather than as a deliberate blank.
9
+ *
10
+ * Both are last resorts, not a framework guarantee: an app that speaks its own
11
+ * alias vocabulary or needs other languages passes labels and assets through
12
+ * `EntryActionDeps.aliasPresentation`, which is consulted per alias.
13
+ */
14
+
15
+ import { EntryAction } from "./types";
16
+
17
+ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
18
+
19
+ const logger = createLogger({
20
+ category: "zapp-react-native-utils:aliasPresentation",
21
+ });
22
+
23
+ const PLACEHOLDER_RED_BOX =
24
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJ0lEQVR4nO3NMQEAAAjDsIF/z2ACvlRAU5NMHuvPOQAAAAAAAMBdC/07Ai5sNw+CAAAAAElFTkSuQmCC";
25
+
26
+ /** Per-app labels and icons, keyed by alias, that outrank the fallbacks. */
27
+ export type AliasPresentation = {
28
+ labels?: Record<string, string>;
29
+ assets?: Record<string, string>;
30
+ };
31
+
32
+ function formatAliasLabel(
33
+ alias: string,
34
+ overrides?: AliasPresentation
35
+ ): string {
36
+ const label = overrides?.labels?.[alias];
37
+
38
+ if (label) {
39
+ return label;
40
+ }
41
+
42
+ const formatted = alias.replace(/_/g, " ");
43
+
44
+ return formatted.charAt(0).toUpperCase() + formatted.slice(1);
45
+ }
46
+
47
+ const nonEmptyString = (value: unknown): value is string =>
48
+ typeof value === "string" && value.length > 0;
49
+
50
+ /**
51
+ * Label the backend stated outright, if any. Distinct from
52
+ * {@link resolveButtonLabel} because an explicit label outranks the executor's
53
+ * action state, while the alias fallback does not.
54
+ */
55
+ export function resolveExplicitLabel(
56
+ button: EntryAction["button"]
57
+ ): string | undefined {
58
+ if (nonEmptyString(button?.title)) {
59
+ return button.title;
60
+ }
61
+
62
+ if (nonEmptyString(button?.label)) {
63
+ return button.label;
64
+ }
65
+
66
+ return undefined;
67
+ }
68
+
69
+ /** Label to show for an entry action: explicit title/label, else the alias. */
70
+ export function resolveButtonLabel(
71
+ button: EntryAction["button"],
72
+ overrides?: AliasPresentation
73
+ ): string {
74
+ const explicit = resolveExplicitLabel(button);
75
+
76
+ if (explicit) {
77
+ return explicit;
78
+ }
79
+
80
+ if (nonEmptyString(button?.alias)) {
81
+ return formatAliasLabel(button.alias, overrides);
82
+ }
83
+
84
+ return "";
85
+ }
86
+
87
+ /** Icon to show for an entry action: explicit iconURL, matching alias asset or fallback to red box. */
88
+ export function resolveButtonAsset(
89
+ button: EntryAction["button"],
90
+ overrides?: AliasPresentation
91
+ ): string | undefined {
92
+ if (button?.iconURL) {
93
+ return button.iconURL;
94
+ }
95
+
96
+ if (!button?.alias) {
97
+ return undefined;
98
+ }
99
+
100
+ if (!overrides?.assets?.[button.alias]) {
101
+ logger.log_warning(
102
+ `Entry action alias '${button.alias}' was not resolved by any plugin feedDecorator or app override. Falling back to placeholder red box.`,
103
+ { data: { button } }
104
+ );
105
+ }
106
+
107
+ return overrides?.assets?.[button.alias] ?? PLACEHOLDER_RED_BOX;
108
+ }
@@ -0,0 +1,167 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { createLogger } from "../logger";
3
+ import { ActionExecutionContext } from "../actionsExecutor/types";
4
+ import { RegisteredAction } from "../uiActionsRegistrator";
5
+
6
+ import {
7
+ resolveButtonAsset,
8
+ resolveButtonLabel,
9
+ resolveExplicitLabel,
10
+ } from "./aliasPresentation";
11
+ import { EntryAction, EntryActionDeps } from "./types";
12
+
13
+ const { log_info, log_warning, log_error } = createLogger({
14
+ subsystem: "EntryActions",
15
+ category: "EntryAction",
16
+ });
17
+
18
+ const ENTRY_ACTION_IDENTIFIER_PREFIX = "entry_action";
19
+
20
+ /** True for actions inflated from `entry.extensions.entry_action`. */
21
+ export function isEntryAction(item: RegisteredAction): boolean {
22
+ return item?.source === "entry";
23
+ }
24
+
25
+ function isValidEntryAction(value: unknown): value is EntryAction {
26
+ if (typeof value !== "object" || value === null) {
27
+ return false;
28
+ }
29
+
30
+ const { button, actions } = value as EntryAction;
31
+
32
+ return (
33
+ (typeof button?.title === "string" ||
34
+ typeof button?.label === "string" ||
35
+ typeof button?.alias === "string") &&
36
+ Array.isArray(actions)
37
+ );
38
+ }
39
+
40
+ function createEntryAction(
41
+ entryAction: EntryAction,
42
+ index: number,
43
+ entry: ZappEntry | ZappFeed,
44
+ deps: EntryActionDeps
45
+ ): RegisteredAction {
46
+ const { button, actions, dismiss_on_action } = entryAction;
47
+
48
+ const identifier = `${ENTRY_ACTION_IDENTIFIER_PREFIX}_${index}`;
49
+ const primaryAction = actions.length > 0 ? actions[0] : null;
50
+
51
+ const actionState = primaryAction
52
+ ? deps.actionExecutor?.getActionState?.(primaryAction.type, entry)
53
+ : null;
54
+
55
+ // An explicit title/label outranks the executor's action state; the
56
+ // alias-derived defaults only fill in when neither produced anything.
57
+ const label: CellActionEntryState["label"] =
58
+ resolveExplicitLabel(button) ||
59
+ actionState?.label ||
60
+ resolveButtonLabel(button, deps.aliasPresentation);
61
+
62
+ const asset: CellActionEntryState["asset"] =
63
+ button?.iconURL ||
64
+ actionState?.asset ||
65
+ resolveButtonAsset(button, deps.aliasPresentation);
66
+
67
+ const initialState = { state: 0, label, asset };
68
+
69
+ return {
70
+ identifier,
71
+ source: "entry",
72
+ action: {
73
+ initialEntryState: () => initialState,
74
+ invokeAction: async (
75
+ invokedEntry: ZappEntry,
76
+ options: InvokeArgsOptions = {}
77
+ ) => {
78
+ if (dismiss_on_action === true) {
79
+ options.dismiss?.();
80
+ }
81
+
82
+ log_info(
83
+ `invokeAction: entry action "${identifier}" triggered for entry "${invokedEntry?.id}"`,
84
+ { identifier, entryId: invokedEntry?.id, actionCount: actions.length }
85
+ );
86
+
87
+ // Both of these leave the user with a button that does nothing when
88
+ // tapped, and neither throws, so they would otherwise be invisible.
89
+ if (actions.length === 0) {
90
+ log_warning(
91
+ `invokeAction: entry action "${identifier}" on entry "${invokedEntry?.id}" declares no actions - the tap does nothing`,
92
+ { identifier, entryId: invokedEntry?.id }
93
+ );
94
+ }
95
+
96
+ if (typeof deps.actionExecutor?.handleActions !== "function") {
97
+ log_warning(
98
+ `invokeAction: no action executor available for entry action "${identifier}" - the tap does nothing`,
99
+ { identifier, entryId: invokedEntry?.id }
100
+ );
101
+ }
102
+
103
+ try {
104
+ await deps.actionExecutor?.handleActions(actions, {
105
+ entry: invokedEntry,
106
+ entryContext: invokedEntry,
107
+ ...deps.actionContext,
108
+ ...(options.component ? { component: options.component } : {}),
109
+ } as ActionExecutionContext);
110
+ } catch (error) {
111
+ log_error(
112
+ `invokeAction: entry action "${identifier}" failed for entry "${invokedEntry?.id}"`,
113
+ {
114
+ identifier,
115
+ entryId: invokedEntry?.id,
116
+ // Types only - the action payloads are backend supplied and may
117
+ // carry user data.
118
+ actionTypes: actions.map((action) => action?.type),
119
+ error,
120
+ }
121
+ );
122
+ }
123
+ },
124
+ },
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Builds the list of actions declared on an entry via
130
+ * `entry.extensions.entry_action`.
131
+ */
132
+ export function buildEntryActions(
133
+ entry: ZappEntry | ZappFeed,
134
+ deps: EntryActionDeps
135
+ ): RegisteredAction[] {
136
+ const entryId = (entry as ZappEntry)?.id;
137
+ const raw = (entry as any)?.extensions?.entry_action;
138
+
139
+ // Most entries simply declare no actions. This provider is resolved for
140
+ // every entry on every render, so saying so would drown everything else.
141
+ if (raw === undefined || raw === null) {
142
+ return [];
143
+ }
144
+
145
+ if (!Array.isArray(raw)) {
146
+ log_warning(
147
+ `buildEntryActions: entry "${entryId}" has extensions.entry_action of type ${typeof raw} instead of an array - no entry actions will be shown`,
148
+ { entryId, receivedType: typeof raw }
149
+ );
150
+
151
+ return [];
152
+ }
153
+
154
+ const valid = raw.filter(isValidEntryAction);
155
+ const invalid = raw.length - valid.length;
156
+
157
+ if (invalid > 0) {
158
+ log_warning(
159
+ `buildEntryActions: ${invalid} invalid entry action(s) skipped for entry "${entryId}"`,
160
+ { entryId, total: raw.length, invalid }
161
+ );
162
+ }
163
+
164
+ return valid.map((entryAction, index) =>
165
+ createEntryAction(entryAction, index, entry, deps)
166
+ );
167
+ }
@@ -0,0 +1,15 @@
1
+ export { buildEntryActions, isEntryAction } from "./buildEntryActions";
2
+
3
+ export {
4
+ resolveButtonAsset,
5
+ resolveButtonLabel,
6
+ resolveExplicitLabel,
7
+ } from "./aliasPresentation";
8
+
9
+ export type {
10
+ EntryAction,
11
+ EntryActionDeps,
12
+ EntryActionExecutionContext,
13
+ } from "./types";
14
+
15
+ export type { AliasPresentation } from "./aliasPresentation";
@@ -0,0 +1,39 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import type { ActionExecutorContextType } from "../actionsExecutor/ActionExecutorContext";
3
+ import type { AliasPresentation } from "./aliasPresentation";
4
+
5
+ /**
6
+ * A single action declared by the backend on an entry, under
7
+ * `entry.extensions.entry_action`.
8
+ */
9
+ export type EntryAction = {
10
+ button: {
11
+ title?: string;
12
+ label?: string;
13
+ alias?: string;
14
+ iconURL?: string;
15
+ };
16
+ actions: ZappActionType[];
17
+ dismiss_on_action?: boolean;
18
+ };
19
+
20
+ /**
21
+ * Everything `buildEntryActions` needs from the surrounding React tree in order
22
+ * to execute an entry action. Supplied lazily so the registered provider always
23
+ * reads the freshest screen context.
24
+ */
25
+ export type EntryActionDeps = {
26
+ actionExecutor: ActionExecutorContextType;
27
+ actionContext: EntryActionExecutionContext;
28
+ /** App-supplied labels/icons for backend aliases; defaults are used without it. */
29
+ aliasPresentation?: AliasPresentation;
30
+ };
31
+
32
+ /** The screen the action is executed against, spread into the execution context. */
33
+ export type EntryActionExecutionContext = {
34
+ screenData?: unknown;
35
+ screenState?: unknown;
36
+ screenRoute?: string;
37
+ screenStateStore?: unknown;
38
+ screenEntry?: unknown;
39
+ };