@applicaster/zapp-react-native-utils 15.0.0-rc.12 → 15.0.0-rc.121

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 (159) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +3 -6
  3. package/actionsExecutor/feedDecorator.ts +6 -6
  4. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  5. package/adsUtils/index.ts +2 -2
  6. package/analyticsUtils/README.md +1 -1
  7. package/analyticsUtils/analyticsMapper.ts +10 -2
  8. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  9. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  10. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  11. package/appUtils/HooksManager/index.ts +10 -10
  12. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  13. package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
  14. package/appUtils/accessibilityManager/const.ts +4 -0
  15. package/appUtils/accessibilityManager/hooks.ts +20 -13
  16. package/appUtils/accessibilityManager/index.ts +28 -1
  17. package/appUtils/accessibilityManager/utils.ts +59 -8
  18. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  19. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  20. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  21. package/appUtils/contextKeysManager/index.ts +65 -10
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +4 -0
  23. package/appUtils/focusManager/index.ios.ts +59 -3
  24. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  26. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  27. package/appUtils/focusManagerAux/utils/index.ts +21 -5
  28. package/appUtils/focusManagerAux/utils/utils.ios.ts +234 -0
  29. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  30. package/appUtils/localizationsHelper.ts +4 -0
  31. package/appUtils/orientationHelper.ts +2 -4
  32. package/appUtils/platform/platformUtils.ts +117 -18
  33. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  34. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  35. package/appUtils/playerManager/player.ts +4 -0
  36. package/appUtils/playerManager/playerNative.ts +31 -17
  37. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  38. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  39. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  40. package/arrayUtils/index.ts +5 -0
  41. package/cellUtils/index.ts +32 -0
  42. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  43. package/cloudEventsUtils/index.ts +65 -1
  44. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  45. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  46. package/configurationUtils/index.ts +17 -11
  47. package/dateUtils/__tests__/dayjs.test.ts +330 -0
  48. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  49. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  50. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  51. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  52. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  53. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  54. package/errorUtils/__tests__/invariant.test.ts +112 -0
  55. package/focusManager/aux/index.ts +1 -1
  56. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  57. package/headersUtils/index.ts +2 -1
  58. package/manifestUtils/defaultManifestConfigurations/player.js +115 -11
  59. package/manifestUtils/keys.js +21 -0
  60. package/manifestUtils/platformIsTV.js +13 -0
  61. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  62. package/manifestUtils/tvAction/container/index.js +1 -1
  63. package/navigationUtils/index.ts +15 -5
  64. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  65. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  66. package/numberUtils/index.ts +23 -1
  67. package/package.json +4 -4
  68. package/playerUtils/usePlayerTTS.ts +8 -3
  69. package/pluginUtils/index.ts +4 -0
  70. package/reactHooks/advertising/index.ts +2 -2
  71. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  72. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  73. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  74. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  75. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  76. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  77. package/reactHooks/connection/__tests__/index.test.js +1 -1
  78. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  79. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  80. package/reactHooks/device/useIsTablet.tsx +14 -19
  81. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  82. package/reactHooks/events/index.ts +20 -0
  83. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  84. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  85. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  86. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  87. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  88. package/reactHooks/feed/index.ts +0 -2
  89. package/reactHooks/feed/useBatchLoading.ts +7 -1
  90. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  91. package/reactHooks/feed/useInflatedUrl.ts +44 -18
  92. package/reactHooks/feed/usePipesCacheReset.ts +3 -1
  93. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  94. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  95. package/reactHooks/index.ts +2 -0
  96. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  97. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  98. package/reactHooks/layout/index.ts +1 -1
  99. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  100. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  101. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  102. package/reactHooks/navigation/index.ts +27 -11
  103. package/reactHooks/navigation/useRoute.ts +11 -7
  104. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  105. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  106. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  107. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  108. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  109. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  110. package/reactHooks/resolvers/useComponentResolver.ts +19 -3
  111. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  112. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  113. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  114. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  115. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  116. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  117. package/reactHooks/state/index.ts +2 -0
  118. package/reactHooks/state/useComponentScreenState.ts +45 -0
  119. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  120. package/reactHooks/state/useRivers.ts +1 -1
  121. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  122. package/reactHooks/usePluginConfiguration.ts +2 -2
  123. package/reactHooks/utils/__tests__/index.test.js +1 -1
  124. package/rectUtils/__tests__/index.test.ts +549 -0
  125. package/rectUtils/index.ts +2 -2
  126. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +161 -0
  127. package/refreshUtils/RefreshCoordinator/index.ts +216 -0
  128. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  129. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  130. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  131. package/screenPickerUtils/index.ts +5 -0
  132. package/screenState/__tests__/index.test.ts +1 -1
  133. package/screenUtils/index.ts +3 -0
  134. package/searchUtils/const.ts +7 -0
  135. package/searchUtils/index.ts +3 -0
  136. package/services/storageServiceSync.web.ts +1 -1
  137. package/stringUtils/index.ts +1 -1
  138. package/testUtils/index.tsx +30 -21
  139. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  140. package/time/__tests__/Timer.test.ts +236 -0
  141. package/typeGuards/__tests__/isString.test.ts +21 -0
  142. package/typeGuards/index.ts +4 -0
  143. package/utils/__tests__/clone.test.ts +158 -0
  144. package/utils/__tests__/mapAccum.test.ts +73 -0
  145. package/utils/__tests__/mergeRight.test.ts +48 -0
  146. package/utils/__tests__/path.test.ts +7 -0
  147. package/utils/__tests__/selectors.test.ts +124 -0
  148. package/utils/clone.ts +7 -0
  149. package/utils/index.ts +22 -1
  150. package/utils/mapAccum.ts +23 -0
  151. package/utils/mergeRight.ts +5 -0
  152. package/utils/path.ts +6 -3
  153. package/utils/pathOr.ts +5 -1
  154. package/utils/selectors.ts +46 -0
  155. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +49 -12
  156. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  157. package/reactHooks/componentsMap/index.ts +0 -55
  158. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  159. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -0,0 +1,113 @@
1
+ import { MissingPluginError } from "../MissingPluginError";
2
+ import * as ERROR_CODES from "../errorCodes";
3
+
4
+ describe("MissingPluginError", () => {
5
+ it("should create error with plugin identifier", () => {
6
+ const identifier = "com.example.myplugin";
7
+ const error = new MissingPluginError(identifier);
8
+
9
+ expect(error).toBeInstanceOf(Error);
10
+ expect(error).toBeInstanceOf(MissingPluginError);
11
+ expect(error.message).toContain(identifier);
12
+ expect(error.code).toBe(ERROR_CODES.MISSING_PLUGIN);
13
+ });
14
+
15
+ it("should include error code in message", () => {
16
+ const identifier = "video-player";
17
+ const error = new MissingPluginError(identifier);
18
+
19
+ expect(error.message).toContain(ERROR_CODES.MISSING_PLUGIN);
20
+ expect(error.message).toContain("Error code:");
21
+ });
22
+
23
+ it("should include descriptive message", () => {
24
+ const identifier = "analytics-plugin";
25
+ const error = new MissingPluginError(identifier);
26
+
27
+ expect(error.message).toContain("Cannot find");
28
+ expect(error.message).toContain("plugin");
29
+
30
+ expect(error.message).toContain(
31
+ "Please make sure the plugin is properly added"
32
+ );
33
+ });
34
+
35
+ it("should have correct error code property", () => {
36
+ const error = new MissingPluginError("test-plugin");
37
+
38
+ expect(error.code).toBe("MISSING_PLUGIN");
39
+ expect(error.code).toBe(ERROR_CODES.MISSING_PLUGIN);
40
+ });
41
+
42
+ it("should be throwable and catchable", () => {
43
+ const identifier = "missing-plugin";
44
+
45
+ expect(() => {
46
+ throw new MissingPluginError(identifier);
47
+ }).toThrow(MissingPluginError);
48
+
49
+ try {
50
+ throw new MissingPluginError(identifier);
51
+ } catch (error) {
52
+ expect(error).toBeInstanceOf(MissingPluginError);
53
+
54
+ expect((error as MissingPluginError).code).toBe(
55
+ ERROR_CODES.MISSING_PLUGIN
56
+ );
57
+ }
58
+ });
59
+
60
+ it("should handle various identifier formats", () => {
61
+ const identifiers = [
62
+ "com.applicaster.plugin",
63
+ "my-plugin-123",
64
+ "plugin_name",
65
+ "Plugin Name With Spaces",
66
+ "123",
67
+ ];
68
+
69
+ identifiers.forEach((identifier) => {
70
+ const error = new MissingPluginError(identifier);
71
+ expect(error.message).toContain(identifier);
72
+ expect(error.code).toBe(ERROR_CODES.MISSING_PLUGIN);
73
+ });
74
+ });
75
+
76
+ it("should maintain stack trace", () => {
77
+ const error = new MissingPluginError("stack-test-plugin");
78
+
79
+ expect(error.stack).toBeDefined();
80
+ expect(error.stack).toContain("stack-test-plugin");
81
+ });
82
+
83
+ it("should handle null identifier", () => {
84
+ const error = new MissingPluginError(null as any);
85
+
86
+ expect(error.message).toContain("null");
87
+ expect(error.code).toBe(ERROR_CODES.MISSING_PLUGIN);
88
+ });
89
+
90
+ it("should handle undefined identifier", () => {
91
+ const error = new MissingPluginError(undefined as any);
92
+
93
+ expect(error.message).toContain("undefined");
94
+ expect(error.code).toBe(ERROR_CODES.MISSING_PLUGIN);
95
+ });
96
+
97
+ it("should handle empty string identifier", () => {
98
+ const error = new MissingPluginError("");
99
+
100
+ expect(error.message).toBeDefined();
101
+ expect(error.code).toBe(ERROR_CODES.MISSING_PLUGIN);
102
+ });
103
+
104
+ it("should be distinguishable from other errors", () => {
105
+ const missingPluginError = new MissingPluginError("test");
106
+ const regularError = new Error("test");
107
+ const customError = { code: "MISSING_PLUGIN", message: "test" };
108
+
109
+ expect(missingPluginError).toBeInstanceOf(MissingPluginError);
110
+ expect(regularError).not.toBeInstanceOf(MissingPluginError);
111
+ expect(customError).not.toBeInstanceOf(MissingPluginError);
112
+ });
113
+ });
@@ -0,0 +1,202 @@
1
+ import { NetworkError } from "../NetworkError";
2
+ import { HttpStatusCode } from "../HttpStatusCode";
3
+
4
+ describe("NetworkError", () => {
5
+ describe("constructor", () => {
6
+ it("should create network error with message and status code", () => {
7
+ const message = "Request failed";
8
+ const statusCode = 404;
9
+ const error = new NetworkError(message, statusCode);
10
+
11
+ expect(error).toBeInstanceOf(Error);
12
+ expect(error).toBeInstanceOf(NetworkError);
13
+ expect(error.originalMessage).toBe(message);
14
+ expect(error.statusCode).toBe(statusCode);
15
+ expect(error.message).toContain("404");
16
+ expect(error.message).toContain(message);
17
+ });
18
+
19
+ it("should format readable log message", () => {
20
+ const message = "Not found";
21
+ const statusCode = 404;
22
+ const error = new NetworkError(message, statusCode);
23
+
24
+ expect(error.message).toContain("statusCode:");
25
+ expect(error.message).toContain("message:");
26
+ expect(error.message).toContain("readableStatus:");
27
+ });
28
+
29
+ it("should handle null message", () => {
30
+ const error = new NetworkError(null as any, 500);
31
+
32
+ expect(error.originalMessage).toBeNull();
33
+ expect(error.message).toContain("No error message available");
34
+ });
35
+
36
+ it("should handle undefined message", () => {
37
+ const error = new NetworkError(undefined as any, 500);
38
+
39
+ expect(error.originalMessage).toBeUndefined();
40
+ expect(error.message).toContain("No error message available");
41
+ });
42
+
43
+ it("should handle custom status codes", () => {
44
+ const message = "Custom error";
45
+ const statusCode = 999;
46
+ const error = new NetworkError(message, statusCode);
47
+
48
+ expect(error.statusCode).toBe(statusCode);
49
+ expect(error.message).toContain("999");
50
+ });
51
+ });
52
+
53
+ describe("isNetworkError static method", () => {
54
+ it("should return true for NetworkError instance", () => {
55
+ const error = new NetworkError("Test", 500);
56
+
57
+ expect(NetworkError.isNetworkError(error)).toBe(true);
58
+ });
59
+
60
+ it("should return false for regular Error", () => {
61
+ const error = new Error("Regular error");
62
+
63
+ expect(NetworkError.isNetworkError(error)).toBe(false);
64
+ });
65
+
66
+ it("should return false for other error types", () => {
67
+ class CustomError extends Error {}
68
+ const error = new CustomError("Custom");
69
+
70
+ expect(NetworkError.isNetworkError(error)).toBe(false);
71
+ });
72
+ });
73
+
74
+ describe("httpStatusCode getter", () => {
75
+ it("should return correct HttpStatusCode for 401", () => {
76
+ const error = new NetworkError("Unauthorized", 401);
77
+
78
+ expect(error.httpStatusCode).toBe(HttpStatusCode.Unauthorized);
79
+ });
80
+
81
+ it("should return correct HttpStatusCode for 403", () => {
82
+ const error = new NetworkError("Forbidden", 403);
83
+
84
+ expect(error.httpStatusCode).toBe(HttpStatusCode.Forbidden);
85
+ });
86
+
87
+ it("should return correct HttpStatusCode for 402", () => {
88
+ const error = new NetworkError("Payment Required", 402);
89
+
90
+ expect(error.httpStatusCode).toBe(HttpStatusCode.PaymentRequired);
91
+ });
92
+
93
+ it("should return correct HttpStatusCode for 500", () => {
94
+ const error = new NetworkError("Server Error", 500);
95
+
96
+ expect(error.httpStatusCode).toBe(HttpStatusCode.InternalServerError);
97
+ });
98
+
99
+ it("should handle unknown status codes", () => {
100
+ const error = new NetworkError("Unknown", 999);
101
+
102
+ expect(error.httpStatusCode).toBe(999);
103
+ });
104
+ });
105
+
106
+ describe("isTokenExpired", () => {
107
+ it("should return true for 401 status code", () => {
108
+ const error = new NetworkError("Unauthorized", 401);
109
+
110
+ expect(error.isTokenExpired()).toBe(true);
111
+ });
112
+
113
+ it("should return false for non-401 status codes", () => {
114
+ expect(new NetworkError("Forbidden", 403).isTokenExpired()).toBe(false);
115
+ expect(new NetworkError("Not Found", 404).isTokenExpired()).toBe(false);
116
+
117
+ expect(new NetworkError("Server Error", 500).isTokenExpired()).toBe(
118
+ false
119
+ );
120
+ });
121
+ });
122
+
123
+ describe("isNoAccess", () => {
124
+ it("should return true for 403 status code", () => {
125
+ const error = new NetworkError("Forbidden", 403);
126
+
127
+ expect(error.isNoAccess()).toBe(true);
128
+ });
129
+
130
+ it("should return false for non-403 status codes", () => {
131
+ expect(new NetworkError("Unauthorized", 401).isNoAccess()).toBe(false);
132
+ expect(new NetworkError("Not Found", 404).isNoAccess()).toBe(false);
133
+ expect(new NetworkError("Server Error", 500).isNoAccess()).toBe(false);
134
+ });
135
+ });
136
+
137
+ describe("isPaymentRequired", () => {
138
+ it("should return true for 402 status code", () => {
139
+ const error = new NetworkError("Payment Required", 402);
140
+
141
+ expect(error.isPaymentRequired()).toBe(true);
142
+ });
143
+
144
+ it("should return false for non-402 status codes", () => {
145
+ expect(new NetworkError("Unauthorized", 401).isPaymentRequired()).toBe(
146
+ false
147
+ );
148
+
149
+ expect(new NetworkError("Forbidden", 403).isPaymentRequired()).toBe(
150
+ false
151
+ );
152
+
153
+ expect(new NetworkError("Not Found", 404).isPaymentRequired()).toBe(
154
+ false
155
+ );
156
+ });
157
+ });
158
+
159
+ describe("error handling scenarios", () => {
160
+ it("should be throwable and catchable", () => {
161
+ const message = "Test throw";
162
+ const statusCode = 500;
163
+
164
+ expect(() => {
165
+ throw new NetworkError(message, statusCode);
166
+ }).toThrow(NetworkError);
167
+
168
+ try {
169
+ throw new NetworkError(message, statusCode);
170
+ } catch (error) {
171
+ expect(error).toBeInstanceOf(NetworkError);
172
+ expect((error as NetworkError).originalMessage).toBe(message);
173
+ expect((error as NetworkError).statusCode).toBe(statusCode);
174
+ }
175
+ });
176
+
177
+ it("should maintain stack trace", () => {
178
+ const error = new NetworkError("Stack test", 500);
179
+
180
+ expect(error.stack).toBeDefined();
181
+ expect(error.stack).toContain("Error data:");
182
+ });
183
+
184
+ it("should handle multiple error scenarios", () => {
185
+ const unauthorizedError = new NetworkError("Token expired", 401);
186
+ const forbiddenError = new NetworkError("Access denied", 403);
187
+ const paymentError = new NetworkError("Subscription required", 402);
188
+
189
+ expect(unauthorizedError.isTokenExpired()).toBe(true);
190
+ expect(unauthorizedError.isNoAccess()).toBe(false);
191
+ expect(unauthorizedError.isPaymentRequired()).toBe(false);
192
+
193
+ expect(forbiddenError.isTokenExpired()).toBe(false);
194
+ expect(forbiddenError.isNoAccess()).toBe(true);
195
+ expect(forbiddenError.isPaymentRequired()).toBe(false);
196
+
197
+ expect(paymentError.isTokenExpired()).toBe(false);
198
+ expect(paymentError.isNoAccess()).toBe(false);
199
+ expect(paymentError.isPaymentRequired()).toBe(true);
200
+ });
201
+ });
202
+ });
@@ -0,0 +1,188 @@
1
+ import { getParsedResponse } from "../index";
2
+ import { RESPONSES } from "../errorCodes";
3
+
4
+ describe("getParsedResponse", () => {
5
+ it("should parse error with response status code from response.data", () => {
6
+ const err = {
7
+ response: {
8
+ data: {
9
+ statusCode: 404,
10
+ message: "Resource not found",
11
+ },
12
+ config: {
13
+ url: "https://api.example.com/data",
14
+ params: { id: 123 },
15
+ },
16
+ },
17
+ name: "AxiosError",
18
+ context: { userId: "user123" },
19
+ };
20
+
21
+ const result = getParsedResponse(err);
22
+
23
+ expect(result.message).toBe("Error: Resource not found");
24
+ expect(result.data.statusCode).toBe("404");
25
+ expect(result.data.url).toBe("https://api.example.com/data");
26
+ expect(result.data.params).toEqual({ id: 123 });
27
+ expect(result.data.context).toEqual({ userId: "user123" });
28
+ expect(result.data.name).toBe("AxiosError");
29
+ expect(result.jsOnly).toBe(false);
30
+ expect(result.exception).toBe(result.message);
31
+ });
32
+
33
+ it("should parse error with response status code from response.status", () => {
34
+ const err = {
35
+ response: {
36
+ status: 500,
37
+ config: {
38
+ url: "https://api.example.com/data",
39
+ },
40
+ },
41
+ };
42
+
43
+ const result = getParsedResponse(err);
44
+
45
+ expect(result.message).toBe(`Error: ${RESPONSES[500]}`);
46
+ expect(result.data.statusCode).toBe("500");
47
+ });
48
+
49
+ it("should handle error with request but no response", () => {
50
+ const err = {
51
+ request: {},
52
+ message: "Network timeout",
53
+ config: {
54
+ url: "https://api.example.com/data",
55
+ params: { test: "value" },
56
+ },
57
+ name: "NetworkError",
58
+ context: { app: "test" },
59
+ };
60
+
61
+ const result = getParsedResponse(err);
62
+
63
+ expect(result.message).toBe("Error: Network timeout");
64
+ expect(result.data.url).toBe("https://api.example.com/data");
65
+ expect(result.data.params).toEqual({ test: "value" });
66
+ expect(result.data.name).toBe("NetworkError");
67
+ expect(result.data.context).toEqual({ app: "test" });
68
+ expect(result.jsOnly).toBe(false);
69
+ });
70
+
71
+ it("should handle error with request but no response and no message", () => {
72
+ const err = {
73
+ request: {},
74
+ config: {
75
+ url: "https://api.example.com/data",
76
+ },
77
+ };
78
+
79
+ const result = getParsedResponse(err);
80
+
81
+ expect(result.message).toBe(`Error: ${RESPONSES.noResponse}`);
82
+ });
83
+
84
+ it("should handle error with neither response nor request", () => {
85
+ const err = {
86
+ message: "Failed to set up request",
87
+ config: {
88
+ url: "https://api.example.com/data",
89
+ },
90
+ };
91
+
92
+ const result = getParsedResponse(err);
93
+
94
+ expect(result.message).toBe("Error: Failed to set up request");
95
+ });
96
+
97
+ it("should handle error with neither response nor request and no message", () => {
98
+ const err = {
99
+ config: {
100
+ url: "https://api.example.com/data",
101
+ },
102
+ };
103
+
104
+ const result = getParsedResponse(err);
105
+
106
+ expect(result.message).toBe(`Error: ${RESPONSES.unknown}`);
107
+ });
108
+
109
+ it("should handle null error", () => {
110
+ const err = null;
111
+
112
+ const result = getParsedResponse(err);
113
+
114
+ expect(result.message).toBe(`Error: ${RESPONSES.unknown}`);
115
+
116
+ expect(result.data).toEqual({
117
+ context: undefined,
118
+ name: undefined,
119
+ params: undefined,
120
+ url: undefined,
121
+ });
122
+ });
123
+
124
+ it("should handle undefined error", () => {
125
+ const err = undefined;
126
+
127
+ const result = getParsedResponse(err);
128
+
129
+ expect(result.message).toBe(`Error: ${RESPONSES.unknown}`);
130
+ });
131
+
132
+ it("should extract params from err.config when response is not present", () => {
133
+ const err = {
134
+ request: {},
135
+ message: "Request failed",
136
+ config: {
137
+ url: "https://api.example.com/data",
138
+ params: { key: "value" },
139
+ },
140
+ };
141
+
142
+ const result = getParsedResponse(err);
143
+
144
+ expect(result.data.params).toEqual({ key: "value" });
145
+ expect(result.data.url).toBe("https://api.example.com/data");
146
+ });
147
+
148
+ it("should prioritize response config over error config", () => {
149
+ const err = {
150
+ response: {
151
+ status: 404,
152
+ config: {
153
+ url: "https://api.example.com/response-url",
154
+ params: { from: "response" },
155
+ },
156
+ },
157
+ config: {
158
+ url: "https://api.example.com/error-url",
159
+ params: { from: "error" },
160
+ },
161
+ };
162
+
163
+ const result = getParsedResponse(err);
164
+
165
+ expect(result.data.url).toBe("https://api.example.com/response-url");
166
+ expect(result.data.params).toEqual({ from: "response" });
167
+ });
168
+
169
+ it("should handle response with custom status codes", () => {
170
+ const err = {
171
+ response: {
172
+ data: {
173
+ statusCode: 418,
174
+ message: "I'm a teapot",
175
+ },
176
+ status: 418,
177
+ config: {
178
+ url: "https://api.example.com/coffee",
179
+ },
180
+ },
181
+ };
182
+
183
+ const result = getParsedResponse(err);
184
+
185
+ expect(result.message).toBe("Error: I'm a teapot");
186
+ expect(result.data.statusCode).toBe("418");
187
+ });
188
+ });
@@ -0,0 +1,112 @@
1
+ import { invariant } from "../index";
2
+
3
+ // Mock __DEV__ global
4
+ declare global {
5
+ var __DEV__: boolean;
6
+ }
7
+
8
+ describe("invariant", () => {
9
+ const originalDev = global.__DEV__;
10
+
11
+ afterEach(() => {
12
+ global.__DEV__ = originalDev;
13
+ });
14
+
15
+ describe("in development mode", () => {
16
+ beforeEach(() => {
17
+ global.__DEV__ = true;
18
+ });
19
+
20
+ it("should not throw when condition is true", () => {
21
+ expect(() => {
22
+ invariant(true, "This should not throw");
23
+ }).not.toThrow();
24
+ });
25
+
26
+ it("should throw when condition is false", () => {
27
+ expect(() => {
28
+ invariant(false, "This should throw");
29
+ }).toThrow("This should throw");
30
+ });
31
+
32
+ it("should throw with correct error message", () => {
33
+ const errorMessage = "Custom error message";
34
+
35
+ expect(() => {
36
+ invariant(false, errorMessage);
37
+ }).toThrow(errorMessage);
38
+ });
39
+
40
+ it("should not throw when condition is truthy value", () => {
41
+ expect(() => {
42
+ invariant(1 as any, "Should not throw");
43
+ }).not.toThrow();
44
+
45
+ expect(() => {
46
+ invariant("string" as any, "Should not throw");
47
+ }).not.toThrow();
48
+
49
+ expect(() => {
50
+ invariant({} as any, "Should not throw");
51
+ }).not.toThrow();
52
+
53
+ expect(() => {
54
+ invariant([] as any, "Should not throw");
55
+ }).not.toThrow();
56
+ });
57
+
58
+ it("should throw when condition is falsy value", () => {
59
+ expect(() => {
60
+ invariant(0 as any, "Should throw for 0");
61
+ }).toThrow("Should throw for 0");
62
+
63
+ expect(() => {
64
+ invariant("" as any, "Should throw for empty string");
65
+ }).toThrow("Should throw for empty string");
66
+
67
+ expect(() => {
68
+ invariant(null as any, "Should throw for null");
69
+ }).toThrow("Should throw for null");
70
+
71
+ expect(() => {
72
+ invariant(undefined as any, "Should throw for undefined");
73
+ }).toThrow("Should throw for undefined");
74
+
75
+ expect(() => {
76
+ invariant(NaN as any, "Should throw for NaN");
77
+ }).toThrow("Should throw for NaN");
78
+ });
79
+ });
80
+
81
+ describe("in production mode", () => {
82
+ beforeEach(() => {
83
+ global.__DEV__ = false;
84
+ });
85
+
86
+ it("should not throw when condition is true", () => {
87
+ expect(() => {
88
+ invariant(true, "This should not throw");
89
+ }).not.toThrow();
90
+ });
91
+
92
+ it("should not throw when condition is false", () => {
93
+ expect(() => {
94
+ invariant(false, "This should not throw in production");
95
+ }).not.toThrow();
96
+ });
97
+
98
+ it("should not throw for any condition", () => {
99
+ expect(() => {
100
+ invariant(0 as any, "Should not throw in production");
101
+ }).not.toThrow();
102
+
103
+ expect(() => {
104
+ invariant(null as any, "Should not throw in production");
105
+ }).not.toThrow();
106
+
107
+ expect(() => {
108
+ invariant(undefined as any, "Should not throw in production");
109
+ }).not.toThrow();
110
+ });
111
+ });
112
+ });
@@ -49,7 +49,7 @@ export const findSelectedMenuId = (
49
49
  ) => {
50
50
  const sectionName = QUICK_BRICK_NAVBAR_SECTIONS[sectionKey];
51
51
 
52
- return pathOr(
52
+ return pathOr<string | undefined>(
53
53
  undefined,
54
54
  ["children", index, "id"],
55
55
  focusableTree.find(sectionName)
@@ -1,6 +1,15 @@
1
1
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
2
2
  import { getAppDataHeaders } from "../index";
3
3
 
4
+ const mockUILanguage = "en-US";
5
+
6
+ jest.mock(
7
+ "@applicaster/zapp-react-native-utils/appUtils/localizationsHelper",
8
+ () => ({
9
+ getUILanguage: jest.fn(() => mockUILanguage),
10
+ })
11
+ );
12
+
4
13
  describe("getAppDataHeaders", () => {
5
14
  const mockAppData = {
6
15
  riversConfigurationId: "test-layout",
@@ -25,7 +34,7 @@ describe("getAppDataHeaders", () => {
25
34
  const expectedHeaders = {
26
35
  "x-applicaster-layout-id": mockAppData.riversConfigurationId,
27
36
  "x-applicaster-screen-id": screenId,
28
- "x-applicaster-language-code": mockAppData.languageCode,
37
+ "x-applicaster-language-code": mockUILanguage,
29
38
  "x-applicaster-version-number": mockAppData.version_name,
30
39
  "x-applicaster-platform": mockAppData.platform,
31
40
  "x-applicaster-country-code": mockAppData.countryCode,
@@ -33,6 +42,7 @@ describe("getAppDataHeaders", () => {
33
42
  mockAppData.signedDeviceInfoToken,
34
43
  "x-applicaster-device-make": mockAppData.deviceMake,
35
44
  "x-applicaster-device-model": mockAppData.deviceModel,
45
+ "x-applicaster-uuid": undefined,
36
46
  };
37
47
 
38
48
  const headers = getAppDataHeaders(screenId);
@@ -1,6 +1,7 @@
1
1
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
2
2
  import { getPlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
3
3
  import { utilsLogger } from "../logger";
4
+ import { getUILanguage } from "../localizationUtils";
4
5
 
5
6
  const logger = utilsLogger.addSubsystem("headersUtils");
6
7
 
@@ -21,7 +22,7 @@ export const getAppDataHeaders = (screenId: string) => {
21
22
  "x-applicaster-layout-id":
22
23
  appData.riversConfigurationId || appData.rivers_configuration_id,
23
24
  "x-applicaster-screen-id": screenId,
24
- "x-applicaster-language-code": appData.languageCode,
25
+ "x-applicaster-language-code": getUILanguage(),
25
26
  "x-applicaster-version-number": appData.version_name || appData.versionName,
26
27
  "x-applicaster-platform": (platform || appData.platform).toLowerCase(),
27
28
  "x-applicaster-country-code": appData.countryCode,