ouisys-engine 3.0.1 → 3.0.5

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 (195) hide show
  1. package/.babelrc +4 -8
  2. package/.eslintrc.js +1 -1
  3. package/.husky/pre-commit +4 -0
  4. package/.nvmrc +1 -1
  5. package/.prettierignore +2 -1
  6. package/.vscode/settings.json +1 -1
  7. package/README.md +2 -4
  8. package/dist/api/index.d.ts +5 -5
  9. package/dist/api/index.js +76 -76
  10. package/dist/common-types/AppThunk.d.ts +11 -12
  11. package/dist/common-types/IOptInFlowName.d.ts +1 -1
  12. package/dist/common-types/ITracker.js +1 -2
  13. package/dist/common-types/RemoteDataState.d.ts +4 -4
  14. package/dist/common-types/RemoteDataState.js +17 -17
  15. package/dist/flows/click2smsFlow.d.ts +2 -2
  16. package/dist/flows/moFlow.d.ts +2 -2
  17. package/dist/flows/moRedirFlow.d.ts +2 -2
  18. package/dist/flows/oneClickFlow.d.ts +2 -2
  19. package/dist/flows/pinFlow.d.ts +2 -2
  20. package/dist/flows/pinFlow.js +2 -0
  21. package/dist/flows/strategy.d.ts +8 -8
  22. package/dist/flows/ussdFlow.d.ts +2 -2
  23. package/dist/ips/tryGetIPRangeName.d.ts +1 -1
  24. package/dist/ips/tryGetIPRangeName.js +7 -5
  25. package/dist/jest.config.js +1 -1
  26. package/dist/pacman/index.d.ts +2 -2
  27. package/dist/pacman/index.js +41 -41
  28. package/dist/pacman/queryString.js +11 -9
  29. package/dist/reducers/click2smsFlow/Click2smsTypes.d.ts +19 -19
  30. package/dist/reducers/click2smsFlow/IClick2smsConstants.d.ts +1 -1
  31. package/dist/reducers/click2smsFlow/index.d.ts +2 -2
  32. package/dist/reducers/click2smsFlow/index.js +24 -24
  33. package/dist/reducers/click2smsFlow/utils.d.ts +1 -1
  34. package/dist/reducers/click2smsFlow/utils.js +30 -30
  35. package/dist/reducers/moFlow/IMoConstants.d.ts +1 -1
  36. package/dist/reducers/moFlow/MoTypes.d.ts +13 -13
  37. package/dist/reducers/moFlow/index.d.ts +3 -3
  38. package/dist/reducers/moFlow/index.js +27 -27
  39. package/dist/reducers/moFlow/utils.d.ts +1 -2
  40. package/dist/reducers/moFlow/utils.js +28 -26
  41. package/dist/reducers/moRedirFlow/IMoRedirConstants.d.ts +1 -1
  42. package/dist/reducers/moRedirFlow/MoRedirTypes.d.ts +13 -13
  43. package/dist/reducers/moRedirFlow/index.d.ts +3 -3
  44. package/dist/reducers/moRedirFlow/index.js +27 -27
  45. package/dist/reducers/moRedirFlow/utils.d.ts +1 -1
  46. package/dist/reducers/moRedirFlow/utils.js +17 -17
  47. package/dist/reducers/oneClickFlow/IOneClickConstants.d.ts +1 -1
  48. package/dist/reducers/oneClickFlow/OneClickTypes.d.ts +10 -10
  49. package/dist/reducers/oneClickFlow/index.d.ts +3 -3
  50. package/dist/reducers/oneClickFlow/index.js +75 -68
  51. package/dist/reducers/oneClickFlow/utils.d.ts +2 -2
  52. package/dist/reducers/oneClickFlow/utils.js +70 -69
  53. package/dist/reducers/pinFlow/IPinConstants.d.ts +1 -1
  54. package/dist/reducers/pinFlow/PinTypes.d.ts +24 -23
  55. package/dist/reducers/pinFlow/index.d.ts +3 -3
  56. package/dist/reducers/pinFlow/index.js +76 -76
  57. package/dist/reducers/pinFlow/utils.d.ts +1 -1
  58. package/dist/reducers/pinFlow/utils.js +61 -65
  59. package/dist/reducers/strategy/IStategyActionContants.d.ts +1 -1
  60. package/dist/reducers/strategy/StrategyTypes.d.ts +56 -56
  61. package/dist/reducers/strategy/index.d.ts +2 -2
  62. package/dist/reducers/strategy/index.js +99 -99
  63. package/dist/reducers/strategy/strategies/ask_mobile_number.d.ts +3 -2
  64. package/dist/reducers/strategy/strategies/ask_mobile_number.js +132 -74
  65. package/dist/reducers/strategy/strategies/ask_operator.d.ts +2 -2
  66. package/dist/reducers/strategy/strategies/ask_operator.js +64 -68
  67. package/dist/reducers/strategy/strategies/detect_operator_by_ip.d.ts +2 -2
  68. package/dist/reducers/strategy/strategies/detect_operator_by_ip.js +97 -97
  69. package/dist/reducers/strategy/strategies/header_enrichment.d.ts +2 -2
  70. package/dist/reducers/strategy/strategies/header_enrichment.js +116 -120
  71. package/dist/reducers/strategy/utils.d.ts +3 -3
  72. package/dist/reducers/strategy/utils.js +115 -111
  73. package/dist/reducers/ussdFlow/IUssdConstants.d.ts +1 -1
  74. package/dist/reducers/ussdFlow/UssdTypes.d.ts +13 -13
  75. package/dist/reducers/ussdFlow/index.d.ts +3 -3
  76. package/dist/reducers/ussdFlow/index.js +27 -27
  77. package/dist/reducers/ussdFlow/utils.d.ts +1 -2
  78. package/dist/reducers/ussdFlow/utils.js +19 -17
  79. package/dist/store/index.d.ts +8 -8
  80. package/dist/store/index.js +87 -83
  81. package/dist/store/reducers.d.ts +7 -7
  82. package/dist/store/reducers.js +4 -4
  83. package/dist/utilities/handleSubmitNumber.d.ts +7 -3
  84. package/dist/utilities/handleSubmitNumber.js +15 -18
  85. package/dist/utilities/index.d.ts +1 -1
  86. package/dist/utilities/index.js +13 -11
  87. package/dist/utilities/loadScriptInnerHtml.js +0 -1
  88. package/index.html +21 -28
  89. package/mockData/config.json +1 -1
  90. package/package.json +23 -15
  91. package/setupJest.js +1 -1
  92. package/tsconfig.json +2 -2
  93. package/dist/api/click2sms.js +0 -357
  94. package/dist/api/mo.js +0 -274
  95. package/dist/api/moRedir.js +0 -186
  96. package/dist/api/oneClick.js +0 -366
  97. package/dist/api/pin.js +0 -493
  98. package/dist/api/strategies.js +0 -704
  99. package/dist/api/ussd.js +0 -1
  100. package/dist/app/store.js +0 -35
  101. package/dist/features/strategies/categories/askMobileNumber.js +0 -395
  102. package/dist/features/strategies/categories/askOperator.js +0 -311
  103. package/dist/features/strategies/categories/detectOperatorByIp.js +0 -606
  104. package/dist/features/strategies/categories/headerEnrichment.js +0 -670
  105. package/dist/features/strategies/categories/typings/click2smsSliceTypes.js +0 -12
  106. package/dist/features/strategies/categories/typings/identifySliceTypes.js +0 -22
  107. package/dist/features/strategies/categories/typings/moFlowSliceTypes.js +0 -22
  108. package/dist/features/strategies/categories/typings/moRedirFlowSliceTypes.js +0 -21
  109. package/dist/features/strategies/categories/typings/oneClickSliceTypes.js +0 -13
  110. package/dist/features/strategies/categories/typings/pinFlowSliceTypes.js +0 -13
  111. package/dist/features/strategies/click2smsFlowSlice.js +0 -172
  112. package/dist/features/strategies/identifySlice.js +0 -455
  113. package/dist/features/strategies/moFlowSlice.js +0 -196
  114. package/dist/features/strategies/moRedirFlowSlice.js +0 -190
  115. package/dist/features/strategies/oneClickFlowSlice.js +0 -277
  116. package/dist/features/strategies/pinFlowSlice.js +0 -313
  117. package/dist/features/strategies/ussdFlowSlice.js +0 -1
  118. package/dist/flows/tpayHeFlow.d.ts +0 -7
  119. package/dist/flows/tpayHeFlow.js +0 -23
  120. package/dist/mockServer/browser.js +0 -48
  121. package/dist/mockServer/handlers.js +0 -22
  122. package/dist/mockServer/server.js +0 -48
  123. package/dist/reducers/tpayHeFlow/ITpayHeConstants.d.ts +0 -2
  124. package/dist/reducers/tpayHeFlow/ITpayHeConstants.js +0 -1
  125. package/dist/reducers/tpayHeFlow/TpayHeTypes.d.ts +0 -114
  126. package/dist/reducers/tpayHeFlow/TpayHeTypes.js +0 -1
  127. package/dist/reducers/tpayHeFlow/index.d.ts +0 -7
  128. package/dist/reducers/tpayHeFlow/index.js +0 -331
  129. package/dist/reducers/tpayHeFlow/utils.d.ts +0 -20
  130. package/dist/reducers/tpayHeFlow/utils.js +0 -510
  131. package/dist/test/setup.js +0 -24
  132. package/dist/test/test-utils.js +0 -51
  133. package/prettier.config.js +0 -7
  134. package/src/@types/react-tracker.d.ts +0 -16
  135. package/src/@types/redux-cli-logger.d.ts +0 -1
  136. package/src/@types/tiny-async-pool.d.ts +0 -3
  137. package/src/@types/window.d.ts +0 -74
  138. package/src/api/index.ts +0 -225
  139. package/src/common-types/AppThunk.ts +0 -19
  140. package/src/common-types/Either.ts +0 -3
  141. package/src/common-types/IError.ts +0 -5
  142. package/src/common-types/IOptInFlowName.ts +0 -1
  143. package/src/common-types/ITracker.ts +0 -10
  144. package/src/common-types/IVisitor.ts +0 -16
  145. package/src/common-types/RemoteDataState.ts +0 -88
  146. package/src/flows/click2smsFlow.ts +0 -18
  147. package/src/flows/moFlow.ts +0 -20
  148. package/src/flows/moRedirFlow.ts +0 -20
  149. package/src/flows/oneClickFlow.ts +0 -20
  150. package/src/flows/pinFlow.ts +0 -25
  151. package/src/flows/strategy.ts +0 -51
  152. package/src/flows/ussdFlow.ts +0 -20
  153. package/src/index.ts +0 -3
  154. package/src/ips/tryGetIPRangeName.ts +0 -22
  155. package/src/jest.config.js +0 -194
  156. package/src/pacman/index.ts +0 -71
  157. package/src/pacman/queryString.ts +0 -24
  158. package/src/reducers/click2smsFlow/Click2smsTypes.ts +0 -93
  159. package/src/reducers/click2smsFlow/IClick2smsConstants.ts +0 -4
  160. package/src/reducers/click2smsFlow/index.ts +0 -105
  161. package/src/reducers/click2smsFlow/utils.ts +0 -126
  162. package/src/reducers/moFlow/IMoConstants.ts +0 -7
  163. package/src/reducers/moFlow/MoTypes.ts +0 -125
  164. package/src/reducers/moFlow/index.ts +0 -150
  165. package/src/reducers/moFlow/utils.ts +0 -135
  166. package/src/reducers/moRedirFlow/IMoRedirConstants.ts +0 -7
  167. package/src/reducers/moRedirFlow/MoRedirTypes.ts +0 -99
  168. package/src/reducers/moRedirFlow/index.ts +0 -137
  169. package/src/reducers/moRedirFlow/utils.ts +0 -78
  170. package/src/reducers/oneClickFlow/IOneClickConstants.ts +0 -3
  171. package/src/reducers/oneClickFlow/OneClickTypes.ts +0 -108
  172. package/src/reducers/oneClickFlow/index.ts +0 -268
  173. package/src/reducers/oneClickFlow/utils.ts +0 -217
  174. package/src/reducers/pinFlow/IPinConstants.ts +0 -9
  175. package/src/reducers/pinFlow/PinTypes.ts +0 -189
  176. package/src/reducers/pinFlow/index.ts +0 -331
  177. package/src/reducers/pinFlow/utils.ts +0 -232
  178. package/src/reducers/strategy/IStategyActionContants.ts +0 -17
  179. package/src/reducers/strategy/StrategyTypes.ts +0 -375
  180. package/src/reducers/strategy/index.ts +0 -321
  181. package/src/reducers/strategy/strategies/ask_mobile_number.ts +0 -316
  182. package/src/reducers/strategy/strategies/ask_operator.ts +0 -195
  183. package/src/reducers/strategy/strategies/detect_operator_by_ip.ts +0 -414
  184. package/src/reducers/strategy/strategies/header_enrichment.ts +0 -489
  185. package/src/reducers/strategy/utils.ts +0 -357
  186. package/src/reducers/ussdFlow/IUssdConstants.ts +0 -7
  187. package/src/reducers/ussdFlow/UssdTypes.ts +0 -112
  188. package/src/reducers/ussdFlow/index.ts +0 -146
  189. package/src/reducers/ussdFlow/utils.ts +0 -88
  190. package/src/store/index.ts +0 -150
  191. package/src/store/reducers.ts +0 -37
  192. package/src/utilities/handleSubmitNumber.ts +0 -65
  193. package/src/utilities/index.ts +0 -114
  194. package/src/utilities/loadScriptInnerHtml.ts +0 -14
  195. package/src/utilities/loadScriptSrc.ts +0 -26
@@ -1,189 +0,0 @@
1
- import * as RDS from "../../common-types/RemoteDataState";
2
- import { AppThunk } from "../../common-types/AppThunk";
3
-
4
- export type IPinFlowCurrentState =
5
- | {
6
- type: "MSISDNEntry";
7
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
8
- }
9
- | {
10
- type: "PINEntry";
11
- result: RDS.RemoteDataState<PINEntryFailure, PINEntrySuccess>;
12
- data:IMsisdnSumbitNextData;
13
- }
14
-
15
- export type MSISDNEntryErrorTypes =
16
- | "AlreadySubscribed"
17
- | "UnknownError"
18
- | "InvalidMSISDN";
19
- export type MSISDNEntryFailure = {
20
- errorType: MSISDNEntryErrorTypes;
21
- error: any;
22
- productUrl?:string;
23
- };
24
- export type MSISDNEntrySuccess = {
25
- type: "PINEntry";
26
- result: RDS.RemoteDataState<PINEntryFailure, PINEntrySuccess>;
27
- };
28
- export type PINEntryFailure = {
29
- errorType: PINEntryErrorTypes;
30
- error?: Error;
31
- };
32
- export type PINEntrySuccess = { finalUrl: string, msisdn?:string, isAlreadySubscribed?:boolean, };
33
- export type PINEntryErrorTypes = "UnknownError" | "TooEarly" | "InvalidPIN" | "UnexpectedState" | "SessionBlocked";
34
-
35
- export type IMsisdnSumbitNextData = {
36
- actualPIN: string;
37
- nextAction:"submitPinAction";
38
- msisdn:string;
39
- pinMaxLength?:number | null;
40
- }
41
- export type IMsisnSubmitActionPayload = {
42
- type:"MSISDNEntry";
43
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
44
- data:IMsisdnSumbitNextData;
45
- }
46
-
47
-
48
- export type IMsisdnSubmitErrorPayload = {
49
- type:"MSISDNEntry",
50
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
51
- }
52
-
53
- export type IPinSubmitPayload = {
54
- type: "PINEntry";
55
- result: RDS.RemoteDataState<PINEntryFailure, PINEntrySuccess>;
56
- actualPIN?: string;
57
- }
58
-
59
- export type IPinErrorPayload = {
60
- type:"PINEntry",
61
- result: RDS.RemoteDataState<PINEntryFailure, PINEntrySuccess>;
62
- }
63
-
64
-
65
- export type IBackToStartPayload = {
66
- type: "MSISDNEntry";
67
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
68
- }
69
- export type IPinActions =
70
- {
71
- type: "PIN_FLOW_MSISDN_SUBMIT";
72
- payload:IMsisnSubmitActionPayload;
73
-
74
- }
75
- |
76
- {
77
- type: "PIN_FLOW_MSISDN_SUBMIT_ERROR";
78
- payload:IMsisdnSubmitErrorPayload;
79
-
80
- }
81
- |
82
- {
83
- type: "PIN_SUBMIT";
84
- payload:IPinSubmitPayload
85
- }
86
- |
87
- {
88
- type: "BACK_TO_START";
89
- payload:IBackToStartPayload;
90
- }
91
- |
92
- {
93
- type:"PIN_SUBMIT_ERROR";
94
- payload:IPinErrorPayload;
95
- }
96
- |
97
- {
98
- type:"MOCK_PIN_FLOW_STATE";
99
- payload:IPinFlowCurrentState;
100
- }
101
-
102
-
103
-
104
-
105
-
106
- export interface IPinFlowReducerState {
107
- currentState:IPinFlowCurrentState
108
- }
109
-
110
-
111
- //import { getConfig, ConfigDetails} from "./config"
112
- export type IConfig = {
113
- offer?: number,
114
- slug?: string;
115
- country?: string;
116
- host?:string;
117
- device?: "smart" | "feature";
118
- automaticallySubmitAllOperators?: boolean;
119
- operators?: string[];
120
- }
121
-
122
- export type IMSISDNSubmissionResult = {
123
- success: true
124
- rockman_id: string
125
- pin: string
126
- product_url?: string
127
- operator:string
128
- } | {
129
- success: false
130
- rockman_id: string
131
- message: string
132
- product_url?: string
133
- }
134
-
135
- export type IPINSubmissionResult = {
136
- success: true
137
- rockman_id: string
138
- product_url?: string
139
- async?: boolean;
140
- message?: string;
141
- } | {
142
- success: false
143
- rockman_id: string
144
- message: string
145
- }
146
-
147
- export type ICheckSubscriptionResult = {
148
- success: false;
149
- rockman_id: string;
150
- message: string;
151
- } | {
152
- success: true;
153
- msisdn: string;
154
- product_url?: string;
155
- rockman_id: string;
156
- }
157
-
158
- export interface IHash {
159
- [key: string]: string;
160
- }
161
-
162
- export type SingleMSISDNSubmissionResult = {
163
- type: "SingleMSISDNSubmissionResult",
164
- operator:string,
165
- pin?: string,
166
- uniqidResult?:string,
167
- }
168
-
169
- export type MultiOperatorMSISDNSubmissionResult = {
170
- type: "MultiOperatorMSISDNSubmissionResult",
171
- }
172
-
173
- export type IMcpShieldResult = {
174
- success: true;
175
- rockman_id: string;
176
- source: string;
177
- uniqid: string;
178
- } | {
179
- success: false;
180
- rockman_id: string;
181
- message: string;
182
- }
183
-
184
- export type IMockPinFlowStates = "msisdn-state" | "pin-state" | "completed-state" | "msisdn-failure-state"
185
-
186
- export type IPinFlowActionMaps = {
187
- submitMSISDNAction:(msisdn:string, extraParams?:IHash)=>AppThunk;
188
- submitPinAction:(msisdn:string, pin:string, extraParams?:{[key: string]: string})=>AppThunk;
189
- }
@@ -1,331 +0,0 @@
1
- // LIBRARIES
2
- import * as RDS from "../../common-types/RemoteDataState";
3
-
4
- import { MSISDNEntryFailure, MSISDNEntryErrorTypes, PINEntryFailure, PINEntrySuccess, PINEntryErrorTypes, IPinFlowReducerState, IPinActions, MSISDNEntrySuccess, IMsisnSubmitActionPayload, IBackToStartPayload, IPinSubmitPayload, IPinErrorPayload, IPinFlowActionMaps, IMsisdnSubmitErrorPayload, IHash, IMockPinFlowStates } from "./PinTypes";
5
- import { AppThunk } from "../../common-types/AppThunk";
6
- import submitMSISDN, { mockedCompletedState, mockedMSISDNEntryFailure, mockedPINState, submitPIN } from "./utils";
7
- import { genericHandler, tracker } from "../strategy";
8
- import { getSAOperatorByMsisdnPrefix } from "../../utilities";
9
- import { determineFlowByOperator } from "../strategy/utils";
10
-
11
-
12
- const getConfigByMsisdnPrefix = (msisdn:string)=>{
13
- const operatorByPrefix = getSAOperatorByMsisdnPrefix(msisdn);
14
- const flowObj = determineFlowByOperator(operatorByPrefix);
15
- return flowObj.flowConfig;
16
- }
17
-
18
- //ACTION CREATORS
19
- export function submitMSISDNAction(msisdn:string, extraParams?:IHash):AppThunk{
20
- return async (dispatch, store)=>{
21
- const {currentState} = store().strategy;
22
- const pinFlowCurrentState = store().pinFlow.currentState;
23
- if(currentState.type === "PIN"){
24
- const { config: configByStrategy, isUseMsisdnPrefix } = currentState.result;
25
-
26
- const config = isUseMsisdnPrefix ? getConfigByMsisdnPrefix(msisdn) : configByStrategy;
27
-
28
- const pinMaxLengthByOp:{[key:string]:number} = {
29
- "SA_MOBILY":6,
30
- "SA_STC":4,
31
- "SA_ZAIN":6
32
- }
33
- try {
34
- dispatch({
35
- type: "PIN_FLOW_MSISDN_SUBMIT",
36
- payload:{
37
- ...pinFlowCurrentState,
38
- type: "MSISDNEntry",
39
- result: RDS.Loading()
40
- }
41
- });
42
- tracker.advancedInFlow('tallyman.v1-pin', 'msisdn-submitted',{msisdn})
43
- const msisdnSubmissionResult = await submitMSISDN(
44
- window,
45
- config,
46
- msisdn,
47
- extraParams
48
- );
49
-
50
- const operator:string = msisdnSubmissionResult.type == "SingleMSISDNSubmissionResult" ? msisdnSubmissionResult.operator : "";
51
-
52
- dispatch({
53
- type: "PIN_FLOW_MSISDN_SUBMIT",
54
- payload:{
55
- ...pinFlowCurrentState,
56
- type: "MSISDNEntry",
57
- result: RDS.Success({})
58
- }
59
- });
60
- tracker.advancedInFlow('tallyman.v1-pin', 'msisdn-submission-success',{msisdn})
61
- dispatch({
62
- type: "PIN_FLOW_MSISDN_SUBMIT",
63
- payload:{
64
- ...pinFlowCurrentState,
65
- type: "PINEntry",
66
- result: RDS.NothingYet(),
67
- data:{
68
- actualPIN: msisdnSubmissionResult.type == "SingleMSISDNSubmissionResult" ? msisdnSubmissionResult.pin : null,
69
- nextAction:"submitPinAction",
70
- msisdn,
71
- operator,
72
- pinMaxLength:(operator != "" && pinMaxLengthByOp[operator]) ? pinMaxLengthByOp[operator] : null
73
- }
74
- }
75
- })
76
- } catch (ex) {
77
- console.warn(ex)
78
- const errorType: MSISDNEntryErrorTypes =
79
- "AlreadySubscribed" === ex.type
80
- ? "AlreadySubscribed"
81
- : "InvalidMSISDN" === ex.type
82
- ? "InvalidMSISDN"
83
- : "UnknownError";
84
- tracker.recedeInFlow('tallyman.v1-pin', 'msisdn-submission-failure',{msisdn, errorType: errorType || 'UnknownError'})
85
- dispatch({
86
- type: "PIN_FLOW_MSISDN_SUBMIT_ERROR",
87
- payload:{
88
- ...pinFlowCurrentState,
89
- type:"MSISDNEntry",
90
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({
91
- errorType: errorType,
92
- error: ex,
93
- productUrl: ex.productUrl
94
- })
95
- }
96
- });
97
- }
98
- }else{
99
- dispatch({
100
- type: "PIN_FLOW_MSISDN_SUBMIT_ERROR",
101
- payload:{
102
- ...pinFlowCurrentState,
103
- type:"MSISDNEntry",
104
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({
105
- errorType: "UnknownError",
106
- error: null
107
- })
108
- }
109
- });
110
- tracker.recedeInFlow('tallyman.v1-pin', 'msisdn-submission-failure',{msisdn, errorType: 'UnexpectedState'})
111
- throw "Unexpected state"
112
- }
113
- }
114
- }
115
-
116
- export function reSubmitMSISDNAction(msisdn:string, extraParams?:IHash):AppThunk{
117
- return async (dispatch, store)=>{
118
- const {currentState} = store().strategy;
119
- const pinFlowCurrentState = store().pinFlow.currentState;
120
- if(currentState.type === "PIN"){
121
- const config = currentState.result.config;
122
- try {
123
- // dispatch({
124
- // type: "PIN_FLOW_MSISDN_SUBMIT",
125
- // payload:{
126
- // type: "MSISDNEntry",
127
- // result: RDS.Loading()
128
- // }
129
- // });
130
- tracker.recedeInFlow('tallyman.v1-pin', 'msisdn-resubmission',{msisdn})
131
-
132
- tracker.advancedInFlow('tallyman.v1-pin', 'msisdn-submitted',{msisdn})
133
- const msisdnSubmissionResult = await submitMSISDN(
134
- window,
135
- config,
136
- msisdn,
137
- extraParams
138
- );
139
- dispatch({
140
- type: "PIN_FLOW_MSISDN_SUBMIT",
141
- payload:{
142
- ...pinFlowCurrentState,
143
- type: "MSISDNEntry",
144
- result: RDS.Success({})
145
- }
146
- });
147
- tracker.advancedInFlow('tallyman.v1-pin', 'msisdn-submission-success',{msisdn})
148
- dispatch({
149
- type: "PIN_FLOW_MSISDN_SUBMIT",
150
- payload:{
151
- ...pinFlowCurrentState,
152
- type: "PINEntry",
153
- result: RDS.NothingYet(),
154
- data:{
155
- actualPIN: msisdnSubmissionResult.type == "SingleMSISDNSubmissionResult" ? msisdnSubmissionResult.pin : null,
156
- nextAction:"submitPinAction",
157
- msisdn
158
- }
159
- }
160
- })
161
- } catch (ex) {
162
- console.warn(ex)
163
- const errorType: MSISDNEntryErrorTypes =
164
- "AlreadySubscribed" === ex.type
165
- ? "AlreadySubscribed"
166
- : "InvalidMSISDN" === ex.type
167
- ? "InvalidMSISDN"
168
- : "UnknownError";
169
- tracker.recedeInFlow('tallyman.v1-pin', 'msisdn-submission-failure',{msisdn, errorType: errorType || 'UnknownError'})
170
- dispatch({
171
- type: "PIN_FLOW_MSISDN_SUBMIT_ERROR",
172
- payload:{
173
- ...pinFlowCurrentState,
174
- type:"MSISDNEntry",
175
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({
176
- errorType: errorType,
177
- error: ex,
178
- productUrl: ex.productUrl
179
- })
180
- }
181
- });
182
- }
183
- }else{
184
- dispatch({
185
- type: "PIN_FLOW_MSISDN_SUBMIT_ERROR",
186
- payload:{
187
- ...pinFlowCurrentState,
188
- type:"MSISDNEntry",
189
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({
190
- errorType: "UnknownError",
191
- error: null
192
- })
193
- }
194
- });
195
- tracker.recedeInFlow('tallyman.v1-pin', 'msisdn-submission-failure',{msisdn, errorType: 'UnexpectedState'})
196
- throw "Unexpected state"
197
- }
198
- }
199
- }
200
- export function submitPinAction(msisdn:string, pin:string, extraParams?:{[key: string]: string}):AppThunk{
201
- return async (dispatch, store)=>{
202
- const {currentState} = store().strategy
203
-
204
- const pinFlowCurrentState = store().pinFlow.currentState;
205
- try {
206
- dispatch({
207
- type: "PIN_SUBMIT",
208
- payload:{
209
- ...pinFlowCurrentState,
210
- type: "PINEntry",
211
- result: RDS.Loading()
212
- }
213
- });
214
- tracker.advancedInFlow('tallyman.v1-pin', 'pin-submitted',{msisdn, pin})
215
-
216
- if(currentState.type === "PIN"){
217
- const config = currentState.result.config;
218
- const result = await submitPIN(window, pin, config, extraParams)
219
- tracker.advancedInFlow('tallyman.v1-pin', 'pin-submission-success',{msisdn, pin, finalUrl: result})
220
-
221
- dispatch({
222
- type: "PIN_SUBMIT",
223
- payload:{
224
- ...pinFlowCurrentState,
225
- type:"PINEntry",
226
- result: RDS.Success<PINEntryFailure, PINEntrySuccess>({
227
- finalUrl: result.productUrl,
228
- isAlreadySubscribed: result.isAlreadySubscribed || false
229
-
230
- })
231
- }
232
- })
233
- }else{
234
- tracker.recedeInFlow('tallyman.v1-pin', 'pin-submission-failure',{msisdn, pin})
235
- dispatch({
236
- type: "PIN_SUBMIT_ERROR",
237
- payload:{
238
- ...pinFlowCurrentState,
239
- type:"PINEntry",
240
- result: RDS.Failure<PINEntryFailure, PINEntrySuccess>({errorType: "UnexpectedState"})
241
- }
242
- })
243
- throw "Unexpected state"
244
- }
245
- } catch(ex) {
246
-
247
- console.error(ex)
248
- const errorType: PINEntryErrorTypes = ex.type || "UnknownError";
249
- tracker.recedeInFlow('tallyman.v1-pin', 'pin-submission-failure',{msisdn, pin})
250
-
251
- dispatch({
252
- type: "PIN_SUBMIT_ERROR",
253
- payload:{
254
- ...pinFlowCurrentState,
255
- type:"PINEntry",
256
- result: RDS.Failure<PINEntryFailure, PINEntrySuccess>({errorType: errorType})
257
- }
258
- })
259
-
260
- }
261
- }
262
- }
263
-
264
- export function mockPinFlow(mockState:IMockPinFlowStates):AppThunk {
265
- return (dispatch)=>{
266
- if(mockState !== undefined){
267
- switch (mockState) {
268
- case "msisdn-failure-state":
269
- return dispatch({
270
- type:"MOCK_PIN_FLOW_STATE",
271
- payload:mockedMSISDNEntryFailure.currentState
272
- })
273
- case "pin-state":
274
- return dispatch({
275
- type:"MOCK_PIN_FLOW_STATE",
276
- payload:mockedPINState.currentState
277
- })
278
- case "completed-state":
279
- return dispatch({
280
- type:"MOCK_PIN_FLOW_STATE",
281
- payload:mockedCompletedState.currentState
282
- })
283
- default:
284
- throw "Mock Flow not supported";
285
- }
286
- }
287
- }
288
- }
289
-
290
- export function backToStart(){
291
- tracker.recedeInFlow("tallyman.v1-pin", "pin-submission-backtostart", "requested to change phone number")
292
-
293
- return {
294
- type:"BACK_TO_START",
295
- payload:{
296
- type: "MSISDNEntry",
297
- result: RDS.NothingYet<MSISDNEntryFailure, MSISDNEntrySuccess>()
298
- }
299
- };
300
- }
301
-
302
- const initialState:IPinFlowReducerState = {
303
- currentState:{
304
- type: "MSISDNEntry",
305
- result: RDS.NothingYet<MSISDNEntryFailure, MSISDNEntrySuccess>()
306
- }
307
- };
308
-
309
- export const PinFlowActionMaps:IPinFlowActionMaps = {
310
- submitMSISDNAction:submitMSISDNAction,
311
- submitPinAction:submitPinAction
312
- }
313
- export default function PinFlowReducer(state = initialState, action:IPinActions) {
314
- switch (action.type) {
315
- case "PIN_FLOW_MSISDN_SUBMIT":
316
- return genericHandler<IPinFlowReducerState,IMsisnSubmitActionPayload>(state, action.payload)
317
- case "PIN_FLOW_MSISDN_SUBMIT_ERROR":
318
- return genericHandler<IPinFlowReducerState, IMsisdnSubmitErrorPayload>(state, action.payload)
319
- case "PIN_SUBMIT":
320
- return genericHandler<IPinFlowReducerState, IPinSubmitPayload>(state, action.payload)
321
- case "BACK_TO_START":
322
- return genericHandler<IPinFlowReducerState,IBackToStartPayload>(state, action.payload)
323
- case "PIN_SUBMIT_ERROR":
324
- return genericHandler<IPinFlowReducerState, IPinErrorPayload>(state, action.payload)
325
- case "MOCK_PIN_FLOW_STATE":
326
- //@ts-ignore
327
- return genericHandler<IPinFlowReducerState, any>(state, action.payload)
328
- default:
329
- return state;
330
- }
331
- }