@applicaster/zapp-react-native-utils 16.0.0-rc.10 → 16.0.0-rc.100

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 (202) 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 +300 -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 +338 -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/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  65. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  66. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  67. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -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 +24 -0
  71. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  72. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -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 +63 -0
  95. package/arrayUtils/__tests__/sample.test.ts +61 -0
  96. package/arrayUtils/index.ts +119 -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 +269 -0
  105. package/configurationUtils/manifestKeyParser.ts +50 -10
  106. package/configurationUtils/modalBlocksParser.ts +214 -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 +212 -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 +63 -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 +162 -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/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  163. package/pluginUtils/index.ts +29 -0
  164. package/reactHooks/actions/index.ts +117 -2
  165. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  166. package/reactHooks/cell-click/index.ts +39 -24
  167. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  168. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  169. package/reactHooks/feed/index.ts +5 -1
  170. package/reactHooks/feed/useBatchLoading.ts +9 -1
  171. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  172. package/reactHooks/index.ts +2 -0
  173. package/reactHooks/layout/index.ts +1 -1
  174. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  175. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  176. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  177. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  178. package/reactHooks/navigation/index.ts +3 -1
  179. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  180. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  181. package/reactHooks/navigation/useRoute.ts +22 -5
  182. package/reactHooks/state/useComponentScreenState.ts +1 -1
  183. package/reactHooks/usePluginConfiguration.ts +4 -1
  184. package/reactHooks/utils/__tests__/index.test.js +22 -2
  185. package/reactHooks/utils/index.ts +13 -2
  186. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  187. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  188. package/stringUtils/index.ts +2 -2
  189. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  190. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  191. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  192. package/uiActionsRegistrator/index.ts +25 -0
  193. package/uiActionsRegistrator/registry.ts +335 -0
  194. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  195. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  196. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  197. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  198. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  199. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  200. package/playerUtils/getPlayerActionButtons.ts +0 -17
  201. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  202. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,214 @@
1
+ import { getAllSpecificStyles } from "./manifestKeyParser";
2
+
3
+ export type ModalBlocksConfig = {
4
+ header: {
5
+ container: Record<string, any>;
6
+ title: Record<string, any>;
7
+ closeButton: Record<string, any>;
8
+ actionButtons: Record<string, any>;
9
+ };
10
+ /**
11
+ * Queue Section Header (BB Variant 3) — shared by Next in Queue / Next Up.
12
+ * Separate from Theme modal `header` so top-title styles do not collide.
13
+ */
14
+ sectionHeader: {
15
+ title: Record<string, any>;
16
+ actionButtons: Record<string, any>;
17
+ };
18
+ action: {
19
+ background: Record<string, any>;
20
+ title: Record<string, any>;
21
+ icons: Record<string, any>;
22
+ leadingIcon: Record<string, any>;
23
+ trailingIcon: Record<string, any>;
24
+ };
25
+ item: {
26
+ background: Record<string, any>;
27
+ image: Record<string, any>;
28
+ nowPlayingContainer: Record<string, any>;
29
+ nowPlayingAsset: Record<string, any>;
30
+ nowPlayingLabel: Record<string, any>;
31
+ textLabel1: Record<string, any>;
32
+ textLabel2: Record<string, any>;
33
+ buttonsContainer: Record<string, any>;
34
+ button1: Record<string, any>;
35
+ button2: Record<string, any>;
36
+ /** Studio item.checkbox_asset / item.checked_checkbox_asset */
37
+ checkbox?: Record<string, any>;
38
+ /** Studio reorder/remove icons for Edit Order rows */
39
+ actionButtons?: Record<string, any>;
40
+ };
41
+ nowPlayingItem?: {
42
+ background: Record<string, any>;
43
+ image: Record<string, any>;
44
+ nowPlayingContainer: Record<string, any>;
45
+ nowPlayingAsset: Record<string, any>;
46
+ nowPlayingLabel: Record<string, any>;
47
+ textLabel1: Record<string, any>;
48
+ textLabel2: Record<string, any>;
49
+ buttonsContainer: Record<string, any>;
50
+ button1: Record<string, any>;
51
+ button2: Record<string, any>;
52
+ checkbox?: Record<string, any>;
53
+ actionButtons?: Record<string, any>;
54
+ };
55
+ button: {
56
+ background: Record<string, any>;
57
+ title: Record<string, any>;
58
+ icons: Record<string, any>;
59
+ leadingIcon: Record<string, any>;
60
+ };
61
+ };
62
+
63
+ export const getEmptyModalBlocksStructure = (): ModalBlocksConfig => {
64
+ const result: ModalBlocksConfig = {
65
+ header: {
66
+ container: {},
67
+ title: {},
68
+ closeButton: {},
69
+ actionButtons: {},
70
+ },
71
+ sectionHeader: {
72
+ title: {},
73
+ actionButtons: {},
74
+ },
75
+ action: {
76
+ background: {},
77
+ title: {},
78
+ icons: {},
79
+ leadingIcon: {},
80
+ trailingIcon: {},
81
+ },
82
+ item: {
83
+ background: {},
84
+ image: {},
85
+ nowPlayingContainer: {},
86
+ nowPlayingAsset: {},
87
+ nowPlayingLabel: {},
88
+ textLabel1: {},
89
+ textLabel2: {},
90
+ buttonsContainer: {},
91
+ button1: {},
92
+ button2: {},
93
+ checkbox: {},
94
+ actionButtons: {},
95
+ },
96
+ nowPlayingItem: {
97
+ background: {},
98
+ image: {},
99
+ nowPlayingContainer: {},
100
+ nowPlayingAsset: {},
101
+ nowPlayingLabel: {},
102
+ textLabel1: {},
103
+ textLabel2: {},
104
+ buttonsContainer: {},
105
+ button1: {},
106
+ button2: {},
107
+ checkbox: {},
108
+ actionButtons: {},
109
+ },
110
+ button: {
111
+ background: {},
112
+ title: {},
113
+ icons: {},
114
+ leadingIcon: {},
115
+ },
116
+ };
117
+
118
+ return result;
119
+ };
120
+
121
+ export const parseModalBlocksConfiguration = (
122
+ configuration: Record<string, any>,
123
+ componentName: string
124
+ ): ModalBlocksConfig => {
125
+ const result = getEmptyModalBlocksStructure();
126
+
127
+ if (!configuration || !componentName) {
128
+ return result;
129
+ }
130
+
131
+ const normalizedComponentName = componentName.replace(/-/g, "_");
132
+
133
+ // Helper to parse sub-components for a block
134
+ const parseBlock = (blockName: string, subComponents: string[]) => {
135
+ subComponents.forEach((subComponent) => {
136
+ // e.g. header_container
137
+ const fullSubComponentName = `${blockName}_${subComponent}`;
138
+
139
+ // e.g. result.header.container
140
+ const camelSubComponent = subComponent.replace(/_([a-z0-9])/g, (g) =>
141
+ g[1].toUpperCase()
142
+ );
143
+
144
+ const camelBlockName = (blockName as string).replace(
145
+ /_([a-z0-9])/g,
146
+ (g) => g[1].toUpperCase()
147
+ ) as keyof ModalBlocksConfig;
148
+
149
+ getAllSpecificStyles({
150
+ configuration,
151
+ componentName: normalizedComponentName,
152
+ subComponentName: fullSubComponentName,
153
+ styleSeparator: "",
154
+ outStyles:
155
+ result[camelBlockName]![
156
+ camelSubComponent as keyof (typeof result)[typeof camelBlockName]
157
+ ],
158
+ });
159
+ });
160
+ };
161
+
162
+ parseBlock("header", [
163
+ "container",
164
+ "title",
165
+ "close_button",
166
+ "action_buttons",
167
+ ]);
168
+
169
+ parseBlock("section_header", ["title", "action_buttons"]);
170
+
171
+ parseBlock("action", [
172
+ "background",
173
+ "title",
174
+ "icons",
175
+ "leading_icon",
176
+ "trailing_icon",
177
+ ]);
178
+
179
+ parseBlock("item", [
180
+ "background",
181
+ "image",
182
+ "now_playing_container",
183
+ "now_playing_asset",
184
+ "now_playing_label",
185
+ // Underscored form (QB convention) and Studio/manifest-generator form
186
+ // without the underscore before the digit (text_label1).
187
+ "text_label_1",
188
+ "text_label_2",
189
+ "text_label1",
190
+ "text_label2",
191
+ "buttons_container",
192
+ "button_1",
193
+ "button_2",
194
+ ]);
195
+
196
+ parseBlock("now_playing_item", [
197
+ "background",
198
+ "image",
199
+ "now_playing_container",
200
+ "now_playing_asset",
201
+ "now_playing_label",
202
+ "text_label_1",
203
+ "text_label_2",
204
+ "text_label1",
205
+ "text_label2",
206
+ "buttons_container",
207
+ "button_1",
208
+ "button_2",
209
+ ]);
210
+
211
+ parseBlock("button", ["background", "title", "icons", "leading_icon"]);
212
+
213
+ return result;
214
+ };
@@ -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
+ }