@applicaster/zapp-react-native-utils 13.0.0-alpha.9433330286 → 13.0.0-rc.10

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 (37) hide show
  1. package/appUtils/HooksManager/{Hook.ts → Hook.js} +23 -35
  2. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +2 -4
  3. package/appUtils/HooksManager/__tests__/hook.test.js +184 -196
  4. package/appUtils/HooksManager/__tests__/hooksManager.test.js +99 -96
  5. package/appUtils/HooksManager/{constants.ts → constants.js} +1 -1
  6. package/appUtils/HooksManager/{index.ts → index.js} +112 -121
  7. package/appUtils/RiverFocusManager/index.js +12 -17
  8. package/appUtils/focusManager/treeDataStructure/Tree/index.js +3 -2
  9. package/appUtils/focusManager/treeDataStructure/Utils/index.js +3 -1
  10. package/appUtils/{index.ts → index.js} +1 -1
  11. package/appUtils/keyCodes/__tests__/keyCodes.test.js +3 -3
  12. package/appUtils/keyCodes/{index.ts → index.js} +0 -2
  13. package/appUtils/keyCodes/{keys/keyEventMapper.ts → keys.android.js} +19 -0
  14. package/appUtils/keyCodes/keys.ios.js +46 -0
  15. package/appUtils/platform/platformUtils.ts +14 -0
  16. package/appUtils/playerManager/index.ts +6 -2
  17. package/domUtils/{cookieManager.ts → cookieManager.js} +2 -1
  18. package/functionUtils/index.ts +11 -15
  19. package/modalState/index.ts +5 -1
  20. package/navigationUtils/index.ts +5 -14
  21. package/package.json +2 -2
  22. package/reactHooks/navigation/index.ts +4 -7
  23. package/reactUtils/index.ts +14 -0
  24. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -693
  25. package/appUtils/HooksManager/types.ts +0 -116
  26. package/appUtils/keyCodes/keys/index.ts +0 -3
  27. package/appUtils/keyCodes/keys/keys.android.ts +0 -18
  28. package/appUtils/keyCodes/keys/keys.ios.ts +0 -25
  29. package/appUtils/keyCodes/keys/keys.ts +0 -15
  30. package/appUtils/keyCodes/keysByPlatform.ts +0 -8
  31. /package/appUtils/HooksManager/{logger.ts → logger.js} +0 -0
  32. /package/appUtils/{directionHelper.ts → directionHelper.js} +0 -0
  33. /package/appUtils/keyCodes/{androidTVKeys.ts → androidTVKeys.js} +0 -0
  34. /package/appUtils/keyCodes/{keys/keys.web.ts → keys.web.js} +0 -0
  35. /package/appUtils/keyCodes/{keys/keysByPlatform.ts → keysByPlatform.js} +0 -0
  36. /package/appUtils/{localizationsHelper.ts → localizationsHelper.js} +0 -0
  37. /package/domUtils/{logger.ts → logger.js} +0 -0
@@ -62,9 +62,9 @@ describe("HooksManager", () => {
62
62
  const successHandler = jest.fn();
63
63
 
64
64
  it("invokes the success handler directly", () => {
65
- hooksManager.subscriber.on(HOOKS_EVENTS.COMPLETE, successHandler);
66
-
67
- hooksManager.handleHooks(payload);
65
+ hooksManager
66
+ .on(HOOKS_EVENTS.COMPLETE, successHandler)
67
+ .handleHooks(payload);
68
68
 
69
69
  expect(successHandler).toHaveBeenCalledTimes(1);
70
70
 
@@ -103,12 +103,11 @@ describe("HooksManager", () => {
103
103
  const presentScreenHandler = jest.fn();
104
104
 
105
105
  it("executes the player hook", () => {
106
- hooksManager.subscriber
106
+ hooksManager
107
107
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, presentScreenHandler)
108
108
  .on(HOOKS_EVENTS.SUCCESS, successHandler)
109
- .on(HOOKS_EVENTS.COMPLETE, completeHandler);
110
-
111
- hooksManager.handleHooks(payload);
109
+ .on(HOOKS_EVENTS.COMPLETE, completeHandler)
110
+ .handleHooks(payload);
112
111
 
113
112
  expect(headlessPlayerHook.module.run).toHaveBeenCalledWith(
114
113
  payload,
@@ -116,14 +115,20 @@ describe("HooksManager", () => {
116
115
  headlessPlayerHook.configuration
117
116
  );
118
117
 
119
- expect(successHandler.mock.calls[0]).toMatchSnapshot();
118
+ expect(successHandler).toHaveBeenCalledWith(
119
+ { hookPlugin: expect.objectContaining(headlessPlayerHook), payload },
120
+ expect.any(Function)
121
+ );
120
122
 
121
- expect(completeHandler.mock.calls[0]).toMatchSnapshot();
123
+ expect(completeHandler).toHaveBeenCalledWith(
124
+ { hookPlugin: expect.objectContaining(headlessPlayerHook), payload },
125
+ expect.any(Function)
126
+ );
122
127
  });
123
128
  });
124
129
 
125
130
  describe("when there are preload hooks", () => {
126
- it("hook with screen: executes", () => {
131
+ describe("hook with screen", () => {
127
132
  const hookScreenId = "6e15fcbf-9414-4ea8-b7db-a287593ab6bd";
128
133
  const pluginScreenId = "1bb8ad39-a42e-4096-a134-56aadbd35c83";
129
134
 
@@ -152,29 +157,36 @@ describe("HooksManager", () => {
152
157
  }
153
158
  );
154
159
 
155
- hooksManager.subscriber
156
- .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, presentScreenHandler)
157
- .on(HOOKS_EVENTS.SUCCESS, successHandler)
158
- .on(HOOKS_EVENTS.COMPLETE, completeHandler);
160
+ it("executes the hook", () => {
161
+ hooksManager
162
+ .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, presentScreenHandler)
163
+ .on(HOOKS_EVENTS.SUCCESS, successHandler)
164
+ .on(HOOKS_EVENTS.COMPLETE, completeHandler)
165
+ .handleHooks(payload);
159
166
 
160
- hooksManager.handleHooks(payload);
161
-
162
- expect(presentScreenHandler).toHaveBeenCalledWith(
163
- {
164
- route: `/hooks/${pluginScreenId}`,
165
- hookPlugin: expect.objectContaining(hookScreen),
166
- payload: {
167
- payload,
167
+ expect(presentScreenHandler).toHaveBeenCalledWith(
168
+ {
169
+ route: `/hooks/${pluginScreenId}`,
168
170
  hookPlugin: expect.objectContaining(hookScreen),
169
- callback: expect.any(Function),
171
+ payload: {
172
+ payload,
173
+ hookPlugin: expect.objectContaining(hookScreen),
174
+ callback: expect.any(Function),
175
+ },
170
176
  },
171
- },
172
- expect.any(Function)
173
- );
174
-
175
- expect(successHandler.mock.calls[0]).toMatchSnapshot();
176
-
177
- expect(completeHandler.mock.calls[0]).toMatchSnapshot();
177
+ expect.any(Function)
178
+ );
179
+
180
+ expect(successHandler).toHaveBeenCalledWith(
181
+ { payload, hookPlugin: expect.objectContaining(hookScreen) },
182
+ expect.any(Function)
183
+ );
184
+
185
+ expect(completeHandler).toHaveBeenCalledWith(
186
+ { payload, hookPlugin: expect.objectContaining(hookScreen) },
187
+ expect.any(Function)
188
+ );
189
+ });
178
190
  });
179
191
  });
180
192
 
@@ -214,12 +226,11 @@ describe("HooksManager", () => {
214
226
  });
215
227
 
216
228
  it("executes the hook", () => {
217
- hooksManager.subscriber
229
+ hooksManager
218
230
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, presentScreenHandler)
219
231
  .on(HOOKS_EVENTS.SUCCESS, successHandler)
220
- .on(HOOKS_EVENTS.COMPLETE, completeHandler);
221
-
222
- hooksManager.handleHooks(payload);
232
+ .on(HOOKS_EVENTS.COMPLETE, completeHandler)
233
+ .handleHooks(payload);
223
234
 
224
235
  expect(presentScreenHandler).toHaveBeenCalledTimes(2);
225
236
 
@@ -330,13 +341,12 @@ describe("HooksManager", () => {
330
341
  );
331
342
 
332
343
  it("stops the flow", () => {
333
- hooksManager.subscriber
344
+ hooksManager
334
345
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, presentScreenHandler)
335
346
  .on(HOOKS_EVENTS.CANCEL, cancelHandler)
336
347
  .on(HOOKS_EVENTS.SUCCESS, successHandler)
337
- .on(HOOKS_EVENTS.COMPLETE, completeHandler);
338
-
339
- hooksManager.handleHooks(payload);
348
+ .on(HOOKS_EVENTS.COMPLETE, completeHandler)
349
+ .handleHooks(payload);
340
350
 
341
351
  expect(cancelHandler).toHaveBeenCalledWith(
342
352
  { hookPlugin: expect.any(Object), payload },
@@ -360,28 +370,25 @@ describe("HooksManager", () => {
360
370
  const payload = { foo: "bar" };
361
371
 
362
372
  it("executes the hook", () => {
363
- hooksManager.subscriber
373
+ hooksManager
364
374
  .on(HOOKS_EVENTS.SUCCESS, successHandler)
365
- .on(HOOKS_EVENTS.COMPLETE, completeHandler);
366
-
367
- hooksManager.handleHooks(payload);
368
-
369
- expect(successHandler.mock.calls[0][0].payload).toMatchObject({
370
- ...payload,
371
- identifier: "hook_plugin",
372
- });
375
+ .on(HOOKS_EVENTS.COMPLETE, completeHandler)
376
+ .handleHooks(payload);
373
377
 
374
- expect(successHandler.mock.calls[0][0].hookPlugin).toMatchObject(
375
- hookPlugin
378
+ expect(successHandler).toHaveBeenCalledWith(
379
+ {
380
+ payload: { ...payload, identifier: "hook_plugin" },
381
+ hookPlugin: expect.objectContaining(hookPlugin),
382
+ },
383
+ expect.any(Function)
376
384
  );
377
385
 
378
- expect(completeHandler.mock.calls[0][0].payload).toMatchObject({
379
- ...payload,
380
- identifier: "hook_plugin",
381
- });
382
-
383
- expect(completeHandler.mock.calls[0][0].hookPlugin).toMatchObject(
384
- hookPlugin
386
+ expect(completeHandler).toHaveBeenCalledWith(
387
+ {
388
+ payload: { ...payload, identifier: "hook_plugin" },
389
+ hookPlugin: expect.objectContaining(hookPlugin),
390
+ },
391
+ expect.any(Function)
385
392
  );
386
393
  });
387
394
  });
@@ -403,12 +410,11 @@ describe("HooksManager", () => {
403
410
  const hooksManager = HooksManager({ rivers, targetScreen, plugins });
404
411
 
405
412
  it("invokes the error handler but not the success handler", () => {
406
- hooksManager.subscriber
413
+ hooksManager
407
414
  .on(HOOKS_EVENTS.SUCCESS, successHandler)
408
415
  .on(HOOKS_EVENTS.COMPLETE, completeHandler)
409
- .on(HOOKS_EVENTS.ERROR, errorHandler);
410
-
411
- hooksManager.handleHooks(payload);
416
+ .on(HOOKS_EVENTS.ERROR, errorHandler)
417
+ .handleHooks(payload);
412
418
 
413
419
  expect(successHandler).not.toHaveBeenCalled();
414
420
 
@@ -441,13 +447,12 @@ describe("HooksManager", () => {
441
447
  const hooksManager = HooksManager({ rivers, targetScreen, plugins });
442
448
 
443
449
  it("invokes the error handler, and stops the flow", () => {
444
- hooksManager.subscriber
450
+ hooksManager
445
451
  .on(HOOKS_EVENTS.SUCCESS, successHandler)
446
452
  .on(HOOKS_EVENTS.COMPLETE, completeHandler)
447
453
  .on(HOOKS_EVENTS.ERROR, errorHandler)
448
- .on(HOOKS_EVENTS.CANCEL, cancelHandler);
449
-
450
- hooksManager.handleHooks(payload);
454
+ .on(HOOKS_EVENTS.CANCEL, cancelHandler)
455
+ .handleHooks(payload);
451
456
 
452
457
  expect(errorHandler).toHaveBeenCalledWith(
453
458
  {
@@ -502,50 +507,48 @@ describe("HooksManager", () => {
502
507
  const hooksManager = HooksManager({ rivers, targetScreen, plugins });
503
508
 
504
509
  it("executes the hook", () => {
505
- hooksManager.subscriber
510
+ hooksManager
506
511
  .on(HOOKS_EVENTS.COMPLETE, completeHandler)
507
- .on(HOOKS_EVENTS.SUCCESS, successHandler);
508
-
509
- hooksManager.handleHooks(payload);
512
+ .on(HOOKS_EVENTS.SUCCESS, successHandler)
513
+ .handleHooks(payload);
510
514
 
511
515
  expect(successHandler).toHaveBeenCalledTimes(3);
512
516
 
513
- expect(successHandler.mock.calls[0][0].payload).toMatchObject({
514
- ...payload,
515
- identifier: "hook_plugin",
516
- });
517
-
518
- expect(successHandler.mock.calls[0][0].hookPlugin).toMatchObject(
519
- hookPlugin
517
+ expect(successHandler).toHaveBeenNthCalledWith(
518
+ 1,
519
+ {
520
+ payload: { ...payload, identifier: "hook_plugin" },
521
+ hookPlugin: expect.objectContaining(hookPlugin),
522
+ },
523
+ expect.any(Function)
520
524
  );
521
525
 
522
- expect(successHandler.mock.calls[1][0].payload).toMatchObject({
523
- ...payload,
524
- identifier: "hook_plugin_2",
525
- });
526
-
527
- expect(successHandler.mock.calls[1][0].hookPlugin).toMatchObject(
528
- hookPlugin2
526
+ expect(successHandler).toHaveBeenNthCalledWith(
527
+ 2,
528
+ {
529
+ payload: { ...payload, identifier: "hook_plugin_2" },
530
+ hookPlugin: expect.objectContaining(hookPlugin2),
531
+ },
532
+ expect.any(Function)
529
533
  );
530
534
 
531
- expect(successHandler.mock.calls[2][0].payload).toMatchObject({
532
- ...payload,
533
- identifier: "hook_plugin_3",
534
- });
535
-
536
- expect(successHandler.mock.calls[2][0].hookPlugin).toMatchObject(
537
- hookPlugin3
535
+ expect(successHandler).toHaveBeenNthCalledWith(
536
+ 3,
537
+ {
538
+ payload: { ...payload, identifier: "hook_plugin_3" },
539
+ hookPlugin: expect.objectContaining(hookPlugin3),
540
+ },
541
+ expect.any(Function)
538
542
  );
539
543
 
540
544
  expect(completeHandler).toHaveBeenCalledTimes(1);
541
545
 
542
- expect(completeHandler.mock.calls[0][0].payload).toMatchObject({
543
- ...payload,
544
- identifier: "hook_plugin_3",
545
- });
546
-
547
- expect(completeHandler.mock.calls[0][0].hookPlugin).toMatchObject(
548
- hookPlugin3
546
+ expect(completeHandler).toHaveBeenCalledWith(
547
+ {
548
+ payload: { ...payload, identifier: "hook_plugin_3" },
549
+ hookPlugin: expect.objectContaining(hookPlugin3),
550
+ },
551
+ expect.any(Function)
549
552
  );
550
553
 
551
554
  expect(hookPlugin.module.run).toHaveBeenCalledWith(
@@ -12,7 +12,7 @@ export const HOOKS_EVENTS = {
12
12
  CANCEL: "cancel",
13
13
  SUCCESS: "success",
14
14
  COMPLETE: "complete",
15
- } as const;
15
+ };
16
16
 
17
17
  export const HOOKS_TRANSITION_TYPE = {
18
18
  PUSH: "push",
@@ -10,72 +10,14 @@ import { Hook } from "./Hook";
10
10
  import { HOOKS_EVENTS, HOOKS_TYPE } from "./constants";
11
11
 
12
12
  import { hooksManagerLogger } from "./logger";
13
- import { HookManager, HookManagerArgs } from "./types";
14
-
15
- /**
16
- * orders the hooks according to their weight
17
- * @param {Array<object>} hooks to sort out
18
- * @returns {Array<object>} sorted hooks
19
- */
20
- function orderHooksByWeight(hooks: Hook[]) {
21
- return R.sortBy(R.compose(Number, R.prop("weight")), hooks);
22
- }
23
-
24
- function executeOnNextHook(
25
- hooks: Hook[],
26
- payload: object,
27
- callback: (hookPlugin: Hook, restOfHooks: Hook[], payload: object) => void
28
- ) {
29
- const [nextHook, ...restOfHooks] = orderHooksByWeight(hooks);
30
-
31
- if (nextHook) {
32
- nextHook.execute(payload, callback(nextHook, restOfHooks, payload));
33
- }
34
- }
35
-
36
- /**
37
- * tells wether the current river is related to a player plugin, or the default player
38
- * @param {Object} river
39
- * @returns {boolean}
40
- */
41
- function riverIsPlayer(river, plugins) {
42
- const { screenType, plugin_type } = river;
43
-
44
- if (screenType || plugin_type) {
45
- return screenType === "playable" || plugin_type === "player";
46
- }
47
-
48
- const { type } = river;
49
-
50
- return R.compose(
51
- R.propEq("type", "player"),
52
- R.defaultTo({}),
53
- R.find(R.propEq("identifier", type))
54
- )(plugins);
55
- }
56
-
57
- /**
58
- * Injects the hooks for the player
59
- * @param _hookType type of hook
60
- * @param plugins plugins
61
- * @returns {Array<Object>}
62
- */
63
- function injectPlayerHooks(_hookType: string, plugins): Hook[] {
64
- const playerhooks: Hook[] = R.compose(
65
- R.sortBy(R.prop("weight")),
66
- R.map((plugin) => ({
67
- identifier: plugin.identifier,
68
- weight: R.path(["module", "weight"], plugin) || 1,
69
- })),
70
- R.filter(R.pathEq(["module", "hasPlayerHook"], true))
71
- )(plugins);
72
-
73
- return playerhooks;
74
- }
75
13
 
76
14
  /**
77
15
  * creates a hooksManager object to handle the hooks process.
78
16
  * it is based on the `subscriber` object
17
+ * @param {object} options
18
+ * @param {object} rivers map of rivers in the app
19
+ * @param {object} targetScreen rivers which we are navigating to
20
+ * @param {Array<object>} plugins array of plugins in the app
79
21
  * @returns {object} hooksManager object - see Navigator for usage
80
22
  */
81
23
  export function HooksManager({
@@ -83,7 +25,7 @@ export function HooksManager({
83
25
  targetScreen,
84
26
  plugins,
85
27
  startUpHooksData = {},
86
- }: HookManagerArgs): HookManager {
28
+ }) {
87
29
  hooksManagerLogger.addContext({ targetScreen });
88
30
 
89
31
  function logHookEvent(func, message, data) {
@@ -93,8 +35,7 @@ export function HooksManager({
93
35
  });
94
36
  }
95
37
 
96
- const hooksManager: Partial<HookManager> = {};
97
- hooksManager.subscriber = subscriber();
38
+ const hooksManager = subscriber();
98
39
 
99
40
  /**
100
41
  * attaches the screen data to the hook object if the hook
@@ -159,6 +100,15 @@ export function HooksManager({
159
100
  };
160
101
  }
161
102
 
103
+ /**
104
+ * orders the hooks according to their weight
105
+ * @param {Array<object>} hooks to sort out
106
+ * @returns {Array<object>} sorted hooks
107
+ */
108
+ function orderHooksByWeight(hooks) {
109
+ return R.sortBy(R.compose(Number, R.prop("weight")), hooks);
110
+ }
111
+
162
112
  /**
163
113
  * extracts the hooks form the target river. returns null if there are none
164
114
  * if there are hooks, gathers all required data and constructs a Hook object
@@ -167,10 +117,10 @@ export function HooksManager({
167
117
  * @returns {Array<Hooks>} list of hooks to go through
168
118
  */
169
119
  function getHooks(hookType, river) {
170
- const playerhooks: Hook[] = [];
120
+ const playerhooks = [];
171
121
 
172
- if (riverIsPlayer(river, plugins)) {
173
- playerhooks.push(...injectPlayerHooks(hookType, plugins));
122
+ if (riverIsPlayer(river)) {
123
+ playerhooks.push(...injectPlayerHooks(hookType));
174
124
  }
175
125
 
176
126
  let hooks = R.concat(playerhooks, R.pathOr([], ["hooks", hookType], river));
@@ -180,10 +130,8 @@ export function HooksManager({
180
130
  const { startUpHooks, setStartUpHooks } = startUpHooksData;
181
131
 
182
132
  if (startUpHooks && startUpHooks !== "in_process") {
183
- if (Array.isArray(startUpHooks)) {
184
- hooks.unshift(...startUpHooks);
185
- setStartUpHooks("in_process");
186
- }
133
+ hooks.unshift(...startUpHooks);
134
+ setStartUpHooks("in_process");
187
135
  }
188
136
 
189
137
  if (!R.length(hooks)) {
@@ -210,6 +158,45 @@ export function HooksManager({
210
158
  )(hooks);
211
159
  }
212
160
 
161
+ /**
162
+ * tells wether the current river is related to a player plugin, or the default player
163
+ * @param {Object} river
164
+ * @returns {boolean}
165
+ */
166
+ function riverIsPlayer(river) {
167
+ const { screenType, plugin_type } = river;
168
+
169
+ if (screenType || plugin_type) {
170
+ return screenType === "playable" || plugin_type === "player";
171
+ }
172
+
173
+ const { type } = river;
174
+
175
+ return R.compose(
176
+ R.propEq("type", "player"),
177
+ R.defaultTo({}),
178
+ R.find(R.propEq("identifier", type))
179
+ )(plugins);
180
+ }
181
+
182
+ /**
183
+ * Injects the hooks for the player
184
+ * @param {String} hookType type of hook
185
+ * @returns {Array<Object>}
186
+ */
187
+ function injectPlayerHooks(_hookType) {
188
+ const playerhooks = R.compose(
189
+ R.sortBy(R.prop("weight")),
190
+ R.map((plugin) => ({
191
+ identifier: plugin.identifier,
192
+ weight: R.path(["module", "weight"], plugin) || 1,
193
+ })),
194
+ R.filter(R.pathEq(["module", "hasPlayerHook"], true))
195
+ )(plugins);
196
+
197
+ return playerhooks;
198
+ }
199
+
213
200
  /**
214
201
  * tells wether the given hook is the last one or not
215
202
  * @param {Hook} hookPlugin
@@ -222,32 +209,6 @@ export function HooksManager({
222
209
  return hookPlugin.lastHook;
223
210
  }
224
211
 
225
- /**
226
- * flags a hook as succeeded, and pass hook data along
227
- * @param {Hook} hookPlugin
228
- * @param {object} payload returned by the hook plugin
229
- */
230
- function completeHook(hookPlugin, payload, callback) {
231
- logHookEvent(
232
- hooksManagerLogger.info,
233
- `completeHook: hook sequence completed successfully: ${hookPlugin["identifier"]}`,
234
- {
235
- payload,
236
- hook: hookPlugin,
237
- }
238
- );
239
-
240
- // eslint-disable-next-line
241
- // TODO: Temporary hack to pass getLoginProtocol to other plugins to refresh in case token expired, need be deleted later
242
- delete payload.getLoginProtocol;
243
-
244
- hookPlugin.setStateAndNotify(HOOKS_EVENTS.COMPLETE, {
245
- hookPlugin,
246
- payload,
247
- callback,
248
- });
249
- }
250
-
251
212
  /**
252
213
  * creates the callback to invoke in order to proceed to the next hook
253
214
  * covers the scenarios of failure & flow blocking
@@ -267,11 +228,9 @@ export function HooksManager({
267
228
  success,
268
229
  error,
269
230
  payload = initialPayload,
270
- callback: callbackArg,
231
+ callback,
271
232
  cancelled,
272
233
  }) {
273
- let callback = callbackArg;
274
-
275
234
  if (error) {
276
235
  logHookEvent(
277
236
  hooksManagerLogger.error,
@@ -313,9 +272,7 @@ export function HooksManager({
313
272
  const isHookInHomescreen = payload?.home;
314
273
 
315
274
  const isHookFlowBlocker =
316
- typeof hookPlugin?.module?.isFlowBlocker === "function"
317
- ? hookPlugin?.module?.isFlowBlocker()
318
- : hookPlugin?.module?.isFlowBlocker;
275
+ hookPlugin?.module?.isFlowBlocker?.() ?? false;
319
276
 
320
277
  // TODO: We technically need to also support the case where there is more than one hook in the stack,
321
278
  // if needed we could add differentiation explicit user cancellation (when we should go to background) and other types of cancellation
@@ -344,18 +301,6 @@ export function HooksManager({
344
301
  }
345
302
  );
346
303
 
347
- if (!callback) {
348
- logHookEvent(
349
- hooksManagerLogger.warn,
350
- `hookCallback: ${hookPlugin["identifier"]} is missing \`callback\`, using hookCallback(default one)`,
351
- {
352
- hookPlugin,
353
- }
354
- );
355
-
356
- callback = hookCallback;
357
- }
358
-
359
304
  hookPlugin.setStateAndNotify(HOOKS_EVENTS.SUCCESS, {
360
305
  hookPlugin,
361
306
  payload,
@@ -364,11 +309,37 @@ export function HooksManager({
364
309
 
365
310
  isLastHook(hookPlugin, restOfHooks)
366
311
  ? completeHook(hookPlugin, payload, callback)
367
- : executeOnNextHook(restOfHooks, payload, callback);
312
+ : handleNextHook(restOfHooks, payload);
368
313
  }
369
314
  };
370
315
  }
371
316
 
317
+ /**
318
+ * flags a hook as succeeded, and pass hook data along
319
+ * @param {Hook} hookPlugin
320
+ * @param {object} payload returned by the hook plugin
321
+ */
322
+ function completeHook(hookPlugin, payload, callback) {
323
+ logHookEvent(
324
+ hooksManagerLogger.info,
325
+ `completeHook: hook sequence completed successfully: ${hookPlugin["identifier"]}`,
326
+ {
327
+ payload,
328
+ hook: hookPlugin,
329
+ }
330
+ );
331
+
332
+ // eslint-disable-next-line
333
+ // TODO: Temporary hack to pass getLoginProtocol to other plugins to refresh in case token expired, need be deleted later
334
+ delete payload.getLoginProtocol;
335
+
336
+ hookPlugin.setStateAndNotify(HOOKS_EVENTS.COMPLETE, {
337
+ hookPlugin,
338
+ payload,
339
+ callback,
340
+ });
341
+ }
342
+
372
343
  /**
373
344
  * presents a screen hook by triggering an event invoking the handler with
374
345
  * the appropriate route & payload
@@ -405,6 +376,9 @@ export function HooksManager({
405
376
 
406
377
  /**
407
378
  * executes a headless hook
379
+ * @param {Hook} hookPlugin to present
380
+ * @param {object} payload to pass to the hook module
381
+ * @param {function} callback to invoke when the hook is successful
408
382
  */
409
383
  hooksManager.executeHook = function (hookPlugin, payload, callback) {
410
384
  logHookEvent(
@@ -470,13 +444,30 @@ export function HooksManager({
470
444
  }
471
445
  };
472
446
 
447
+ /**
448
+ * handles the next hook in the list of provided hooks, passing the payload along
449
+ * @param {Array<Hook>} hooks to process
450
+ * @param {object} payload to pass to the hook
451
+ */
452
+ function handleNextHook(hooks, payload) {
453
+ const [hookPlugin, ...restOfHooks] = orderHooksByWeight(hooks);
454
+
455
+ /**
456
+ * Commenting out part of the code which is trying to run the next hook
457
+ * in parallel - it's not in use, and it's creating unexpected side
458
+ * effects
459
+ * */
460
+
461
+ hookPlugin.execute(payload, hookCallback(hookPlugin, restOfHooks, payload));
462
+ }
463
+
473
464
  /**
474
465
  * function exposes on the hooks manager to trigger the handling of the hooks for
475
466
  * the given targetScreen
476
467
  * @param {object} payload to send to the hooks
477
468
  * @returns {object} returns the hooks manager so methods can be chained
478
469
  */
479
- hooksManager.handleHooks = function (payload: object) {
470
+ hooksManager.handleHooks = function (payload) {
480
471
  const preloadHooks = getHooks(HOOKS_TYPE.PRELOAD, targetScreen);
481
472
 
482
473
  if (preloadHooks?.length) {
@@ -491,9 +482,9 @@ export function HooksManager({
491
482
  }
492
483
  );
493
484
 
494
- executeOnNextHook(preloadHooks, payload, hookCallback);
485
+ handleNextHook(preloadHooks, payload);
495
486
  } else {
496
- hooksManager.subscriber.invokeHandler(HOOKS_EVENTS.COMPLETE, {
487
+ hooksManager.invokeHandler(HOOKS_EVENTS.COMPLETE, {
497
488
  hookPlugin: { lastHook: true },
498
489
  payload,
499
490
  });
@@ -502,5 +493,5 @@ export function HooksManager({
502
493
  return hooksManager;
503
494
  };
504
495
 
505
- return hooksManager as HookManager;
496
+ return hooksManager;
506
497
  }