ouisys-engine 3.0.3 → 3.0.7

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 (198) hide show
  1. package/.babelrc +4 -8
  2. package/.eslintrc.js +1 -1
  3. package/.nvmrc +1 -1
  4. package/.prettierignore +2 -1
  5. package/README.md +2 -4
  6. package/dist/api/index.d.ts +5 -5
  7. package/dist/api/index.js +76 -76
  8. package/dist/common-types/AppThunk.d.ts +11 -12
  9. package/dist/common-types/IOptInFlowName.d.ts +1 -1
  10. package/dist/common-types/ITracker.js +1 -2
  11. package/dist/common-types/RemoteDataState.d.ts +4 -4
  12. package/dist/common-types/RemoteDataState.js +17 -17
  13. package/dist/flows/click2smsFlow.d.ts +2 -2
  14. package/dist/flows/moFlow.d.ts +2 -2
  15. package/dist/flows/moRedirFlow.d.ts +2 -2
  16. package/dist/flows/oneClickFlow.d.ts +2 -2
  17. package/dist/flows/pinFlow.d.ts +2 -2
  18. package/dist/flows/pinFlow.js +2 -0
  19. package/dist/flows/strategy.d.ts +8 -8
  20. package/dist/flows/ussdFlow.d.ts +2 -2
  21. package/dist/ips/tryGetIPRangeName.d.ts +1 -1
  22. package/dist/ips/tryGetIPRangeName.js +7 -5
  23. package/dist/jest.config.js +1 -1
  24. package/dist/pacman/index.d.ts +2 -2
  25. package/dist/pacman/index.js +41 -41
  26. package/dist/pacman/queryString.js +11 -9
  27. package/dist/reducers/click2smsFlow/Click2smsTypes.d.ts +19 -19
  28. package/dist/reducers/click2smsFlow/IClick2smsConstants.d.ts +1 -1
  29. package/dist/reducers/click2smsFlow/index.d.ts +2 -2
  30. package/dist/reducers/click2smsFlow/index.js +24 -24
  31. package/dist/reducers/click2smsFlow/utils.d.ts +1 -1
  32. package/dist/reducers/click2smsFlow/utils.js +30 -30
  33. package/dist/reducers/moFlow/IMoConstants.d.ts +1 -1
  34. package/dist/reducers/moFlow/MoTypes.d.ts +13 -13
  35. package/dist/reducers/moFlow/index.d.ts +3 -3
  36. package/dist/reducers/moFlow/index.js +27 -27
  37. package/dist/reducers/moFlow/utils.d.ts +1 -2
  38. package/dist/reducers/moFlow/utils.js +28 -26
  39. package/dist/reducers/moRedirFlow/IMoRedirConstants.d.ts +1 -1
  40. package/dist/reducers/moRedirFlow/MoRedirTypes.d.ts +13 -13
  41. package/dist/reducers/moRedirFlow/index.d.ts +3 -3
  42. package/dist/reducers/moRedirFlow/index.js +27 -27
  43. package/dist/reducers/moRedirFlow/utils.d.ts +1 -1
  44. package/dist/reducers/moRedirFlow/utils.js +17 -17
  45. package/dist/reducers/oneClickFlow/IOneClickConstants.d.ts +1 -1
  46. package/dist/reducers/oneClickFlow/OneClickTypes.d.ts +10 -10
  47. package/dist/reducers/oneClickFlow/index.d.ts +3 -3
  48. package/dist/reducers/oneClickFlow/index.js +75 -68
  49. package/dist/reducers/oneClickFlow/utils.d.ts +2 -2
  50. package/dist/reducers/oneClickFlow/utils.js +38 -38
  51. package/dist/reducers/pinFlow/IPinConstants.d.ts +1 -1
  52. package/dist/reducers/pinFlow/PinTypes.d.ts +23 -23
  53. package/dist/reducers/pinFlow/index.d.ts +3 -3
  54. package/dist/reducers/pinFlow/index.js +76 -76
  55. package/dist/reducers/pinFlow/utils.d.ts +1 -1
  56. package/dist/reducers/pinFlow/utils.js +61 -65
  57. package/dist/reducers/strategy/IStategyActionContants.d.ts +1 -1
  58. package/dist/reducers/strategy/StrategyTypes.d.ts +56 -56
  59. package/dist/reducers/strategy/index.d.ts +2 -2
  60. package/dist/reducers/strategy/index.js +99 -99
  61. package/dist/reducers/strategy/strategies/ask_mobile_number.d.ts +2 -2
  62. package/dist/reducers/strategy/strategies/ask_mobile_number.js +78 -78
  63. package/dist/reducers/strategy/strategies/ask_operator.d.ts +2 -2
  64. package/dist/reducers/strategy/strategies/ask_operator.js +64 -68
  65. package/dist/reducers/strategy/strategies/detect_operator_by_ip.d.ts +2 -2
  66. package/dist/reducers/strategy/strategies/detect_operator_by_ip.js +97 -97
  67. package/dist/reducers/strategy/strategies/header_enrichment.d.ts +2 -2
  68. package/dist/reducers/strategy/strategies/header_enrichment.js +116 -120
  69. package/dist/reducers/strategy/utils.d.ts +3 -3
  70. package/dist/reducers/strategy/utils.js +115 -111
  71. package/dist/reducers/ussdFlow/IUssdConstants.d.ts +1 -1
  72. package/dist/reducers/ussdFlow/UssdTypes.d.ts +13 -13
  73. package/dist/reducers/ussdFlow/index.d.ts +3 -3
  74. package/dist/reducers/ussdFlow/index.js +27 -27
  75. package/dist/reducers/ussdFlow/utils.d.ts +1 -2
  76. package/dist/reducers/ussdFlow/utils.js +19 -17
  77. package/dist/store/index.d.ts +8 -8
  78. package/dist/store/index.js +87 -83
  79. package/dist/store/reducers.d.ts +7 -7
  80. package/dist/store/reducers.js +4 -4
  81. package/dist/utilities/handleSubmitNumber.d.ts +7 -3
  82. package/dist/utilities/handleSubmitNumber.js +15 -18
  83. package/dist/utilities/index.d.ts +1 -1
  84. package/dist/utilities/index.js +13 -11
  85. package/dist/utilities/loadScriptInnerHtml.js +0 -1
  86. package/index.html +21 -28
  87. package/package.json +23 -15
  88. package/setupJest.js +1 -1
  89. package/tsconfig.json +2 -2
  90. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  91. package/.idea/modules.xml +0 -8
  92. package/.idea/ouisys-engine.iml +0 -12
  93. package/.idea/vcs.xml +0 -6
  94. package/.vscode/settings.json +0 -6
  95. package/dist/api/click2sms.js +0 -357
  96. package/dist/api/mo.js +0 -274
  97. package/dist/api/moRedir.js +0 -186
  98. package/dist/api/oneClick.js +0 -366
  99. package/dist/api/pin.js +0 -493
  100. package/dist/api/strategies.js +0 -704
  101. package/dist/api/ussd.js +0 -1
  102. package/dist/app/store.js +0 -35
  103. package/dist/features/strategies/categories/askMobileNumber.js +0 -395
  104. package/dist/features/strategies/categories/askOperator.js +0 -311
  105. package/dist/features/strategies/categories/detectOperatorByIp.js +0 -606
  106. package/dist/features/strategies/categories/headerEnrichment.js +0 -670
  107. package/dist/features/strategies/categories/typings/click2smsSliceTypes.js +0 -12
  108. package/dist/features/strategies/categories/typings/identifySliceTypes.js +0 -22
  109. package/dist/features/strategies/categories/typings/moFlowSliceTypes.js +0 -22
  110. package/dist/features/strategies/categories/typings/moRedirFlowSliceTypes.js +0 -21
  111. package/dist/features/strategies/categories/typings/oneClickSliceTypes.js +0 -13
  112. package/dist/features/strategies/categories/typings/pinFlowSliceTypes.js +0 -13
  113. package/dist/features/strategies/click2smsFlowSlice.js +0 -172
  114. package/dist/features/strategies/identifySlice.js +0 -455
  115. package/dist/features/strategies/moFlowSlice.js +0 -196
  116. package/dist/features/strategies/moRedirFlowSlice.js +0 -190
  117. package/dist/features/strategies/oneClickFlowSlice.js +0 -277
  118. package/dist/features/strategies/pinFlowSlice.js +0 -313
  119. package/dist/features/strategies/ussdFlowSlice.js +0 -1
  120. package/dist/flows/tpayHeFlow.d.ts +0 -7
  121. package/dist/flows/tpayHeFlow.js +0 -23
  122. package/dist/mockServer/browser.js +0 -48
  123. package/dist/mockServer/handlers.js +0 -22
  124. package/dist/mockServer/server.js +0 -48
  125. package/dist/reducers/tpayHeFlow/ITpayHeConstants.d.ts +0 -2
  126. package/dist/reducers/tpayHeFlow/ITpayHeConstants.js +0 -1
  127. package/dist/reducers/tpayHeFlow/TpayHeTypes.d.ts +0 -114
  128. package/dist/reducers/tpayHeFlow/TpayHeTypes.js +0 -1
  129. package/dist/reducers/tpayHeFlow/index.d.ts +0 -7
  130. package/dist/reducers/tpayHeFlow/index.js +0 -331
  131. package/dist/reducers/tpayHeFlow/utils.d.ts +0 -20
  132. package/dist/reducers/tpayHeFlow/utils.js +0 -510
  133. package/dist/test/setup.js +0 -24
  134. package/dist/test/test-utils.js +0 -51
  135. package/mockData/config.json +0 -28
  136. package/prettier.config.js +0 -7
  137. package/src/@types/react-tracker.d.ts +0 -16
  138. package/src/@types/redux-cli-logger.d.ts +0 -1
  139. package/src/@types/tiny-async-pool.d.ts +0 -3
  140. package/src/@types/window.d.ts +0 -74
  141. package/src/api/index.ts +0 -225
  142. package/src/common-types/AppThunk.ts +0 -19
  143. package/src/common-types/Either.ts +0 -3
  144. package/src/common-types/IError.ts +0 -5
  145. package/src/common-types/IOptInFlowName.ts +0 -1
  146. package/src/common-types/ITracker.ts +0 -10
  147. package/src/common-types/IVisitor.ts +0 -16
  148. package/src/common-types/RemoteDataState.ts +0 -88
  149. package/src/flows/click2smsFlow.ts +0 -18
  150. package/src/flows/moFlow.ts +0 -20
  151. package/src/flows/moRedirFlow.ts +0 -20
  152. package/src/flows/oneClickFlow.ts +0 -20
  153. package/src/flows/pinFlow.ts +0 -25
  154. package/src/flows/strategy.ts +0 -51
  155. package/src/flows/ussdFlow.ts +0 -20
  156. package/src/index.ts +0 -3
  157. package/src/ips/tryGetIPRangeName.ts +0 -22
  158. package/src/jest.config.js +0 -194
  159. package/src/pacman/index.ts +0 -71
  160. package/src/pacman/queryString.ts +0 -24
  161. package/src/reducers/click2smsFlow/Click2smsTypes.ts +0 -93
  162. package/src/reducers/click2smsFlow/IClick2smsConstants.ts +0 -4
  163. package/src/reducers/click2smsFlow/index.ts +0 -105
  164. package/src/reducers/click2smsFlow/utils.ts +0 -126
  165. package/src/reducers/moFlow/IMoConstants.ts +0 -7
  166. package/src/reducers/moFlow/MoTypes.ts +0 -125
  167. package/src/reducers/moFlow/index.ts +0 -150
  168. package/src/reducers/moFlow/utils.ts +0 -135
  169. package/src/reducers/moRedirFlow/IMoRedirConstants.ts +0 -7
  170. package/src/reducers/moRedirFlow/MoRedirTypes.ts +0 -99
  171. package/src/reducers/moRedirFlow/index.ts +0 -137
  172. package/src/reducers/moRedirFlow/utils.ts +0 -78
  173. package/src/reducers/oneClickFlow/IOneClickConstants.ts +0 -3
  174. package/src/reducers/oneClickFlow/OneClickTypes.ts +0 -108
  175. package/src/reducers/oneClickFlow/index.ts +0 -268
  176. package/src/reducers/oneClickFlow/utils.ts +0 -219
  177. package/src/reducers/pinFlow/IPinConstants.ts +0 -9
  178. package/src/reducers/pinFlow/PinTypes.ts +0 -190
  179. package/src/reducers/pinFlow/index.ts +0 -331
  180. package/src/reducers/pinFlow/utils.ts +0 -232
  181. package/src/reducers/strategy/IStategyActionContants.ts +0 -17
  182. package/src/reducers/strategy/StrategyTypes.ts +0 -376
  183. package/src/reducers/strategy/index.ts +0 -322
  184. package/src/reducers/strategy/strategies/ask_mobile_number.ts +0 -366
  185. package/src/reducers/strategy/strategies/ask_operator.ts +0 -195
  186. package/src/reducers/strategy/strategies/detect_operator_by_ip.ts +0 -414
  187. package/src/reducers/strategy/strategies/header_enrichment.ts +0 -489
  188. package/src/reducers/strategy/utils.ts +0 -357
  189. package/src/reducers/ussdFlow/IUssdConstants.ts +0 -7
  190. package/src/reducers/ussdFlow/UssdTypes.ts +0 -112
  191. package/src/reducers/ussdFlow/index.ts +0 -146
  192. package/src/reducers/ussdFlow/utils.ts +0 -88
  193. package/src/store/index.ts +0 -150
  194. package/src/store/reducers.ts +0 -37
  195. package/src/utilities/handleSubmitNumber.ts +0 -65
  196. package/src/utilities/index.ts +0 -114
  197. package/src/utilities/loadScriptInnerHtml.ts +0 -14
  198. package/src/utilities/loadScriptSrc.ts +0 -26
@@ -1,190 +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
- operator?: string;
41
- }
42
- export type IMsisnSubmitActionPayload = {
43
- type:"MSISDNEntry";
44
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
45
- data:IMsisdnSumbitNextData;
46
- }
47
-
48
-
49
- export type IMsisdnSubmitErrorPayload = {
50
- type:"MSISDNEntry",
51
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
52
- }
53
-
54
- export type IPinSubmitPayload = {
55
- type: "PINEntry";
56
- result: RDS.RemoteDataState<PINEntryFailure, PINEntrySuccess>;
57
- actualPIN?: string;
58
- }
59
-
60
- export type IPinErrorPayload = {
61
- type:"PINEntry",
62
- result: RDS.RemoteDataState<PINEntryFailure, PINEntrySuccess>;
63
- }
64
-
65
-
66
- export type IBackToStartPayload = {
67
- type: "MSISDNEntry";
68
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
69
- }
70
- export type IPinActions =
71
- {
72
- type: "PIN_FLOW_MSISDN_SUBMIT";
73
- payload:IMsisnSubmitActionPayload;
74
-
75
- }
76
- |
77
- {
78
- type: "PIN_FLOW_MSISDN_SUBMIT_ERROR";
79
- payload:IMsisdnSubmitErrorPayload;
80
-
81
- }
82
- |
83
- {
84
- type: "PIN_SUBMIT";
85
- payload:IPinSubmitPayload
86
- }
87
- |
88
- {
89
- type: "BACK_TO_START";
90
- payload:IBackToStartPayload;
91
- }
92
- |
93
- {
94
- type:"PIN_SUBMIT_ERROR";
95
- payload:IPinErrorPayload;
96
- }
97
- |
98
- {
99
- type:"MOCK_PIN_FLOW_STATE";
100
- payload:IPinFlowCurrentState;
101
- }
102
-
103
-
104
-
105
-
106
-
107
- export interface IPinFlowReducerState {
108
- currentState:IPinFlowCurrentState
109
- }
110
-
111
-
112
- //import { getConfig, ConfigDetails} from "./config"
113
- export type IConfig = {
114
- offer?: number,
115
- slug?: string;
116
- country?: string;
117
- host?:string;
118
- device?: "smart" | "feature";
119
- automaticallySubmitAllOperators?: boolean;
120
- operators?: string[];
121
- }
122
-
123
- export type IMSISDNSubmissionResult = {
124
- success: true
125
- rockman_id: string
126
- pin: string
127
- product_url?: string
128
- operator:string
129
- } | {
130
- success: false
131
- rockman_id: string
132
- message: string
133
- product_url?: string
134
- }
135
-
136
- export type IPINSubmissionResult = {
137
- success: true
138
- rockman_id: string
139
- product_url?: string
140
- async?: boolean;
141
- message?: string;
142
- } | {
143
- success: false
144
- rockman_id: string
145
- message: string
146
- }
147
-
148
- export type ICheckSubscriptionResult = {
149
- success: false;
150
- rockman_id: string;
151
- message: string;
152
- } | {
153
- success: true;
154
- msisdn: string;
155
- product_url?: string;
156
- rockman_id: string;
157
- }
158
-
159
- export interface IHash {
160
- [key: string]: string;
161
- }
162
-
163
- export type SingleMSISDNSubmissionResult = {
164
- type: "SingleMSISDNSubmissionResult",
165
- operator:string,
166
- pin?: string,
167
- uniqidResult?:string,
168
- }
169
-
170
- export type MultiOperatorMSISDNSubmissionResult = {
171
- type: "MultiOperatorMSISDNSubmissionResult",
172
- }
173
-
174
- export type IMcpShieldResult = {
175
- success: true;
176
- rockman_id: string;
177
- source: string;
178
- uniqid: string;
179
- } | {
180
- success: false;
181
- rockman_id: string;
182
- message: string;
183
- }
184
-
185
- export type IMockPinFlowStates = "msisdn-state" | "pin-state" | "completed-state" | "msisdn-failure-state"
186
-
187
- export type IPinFlowActionMaps = {
188
- submitMSISDNAction:(msisdn:string, extraParams?:IHash)=>AppThunk;
189
- submitPinAction:(msisdn:string, pin:string, extraParams?:{[key: string]: string})=>AppThunk;
190
- }
@@ -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
- }