ouisys-engine 3.0.3 → 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 +38 -38
  53. package/dist/reducers/pinFlow/IPinConstants.d.ts +1 -1
  54. package/dist/reducers/pinFlow/PinTypes.d.ts +23 -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 +2 -2
  64. package/dist/reducers/strategy/strategies/ask_mobile_number.js +78 -78
  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 -219
  174. package/src/reducers/pinFlow/IPinConstants.ts +0 -9
  175. package/src/reducers/pinFlow/PinTypes.ts +0 -190
  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 -376
  180. package/src/reducers/strategy/index.ts +0 -322
  181. package/src/reducers/strategy/strategies/ask_mobile_number.ts +0 -366
  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,357 +0,0 @@
1
- import { IStrategy, IFlow, IStrategyReducerState, IConfig, IIdentifyResult, IStrategyIDentifyUserResult } from "./StrategyTypes";
2
- import IError from "../../common-types/IError";
3
- import tryGetIPRangeName from "../../ips/tryGetIPRangeName";
4
-
5
- import { ILinkExtraParams } from "../oneClickFlow/OneClickTypes";
6
- import Either from "../../common-types/Either";
7
-
8
-
9
-
10
- export const wait = (ms: number) =>
11
- //@ts-ignore
12
- new Promise(resolve => setTimeout(() => resolve(), ms));
13
-
14
- export const loop = async <I extends {}, R extends {}>(
15
- f: () => Promise<R>,
16
- max: number,
17
- stop: (r: R) => boolean,
18
- i: number
19
- ): Promise<R> => {
20
- const r = await f();
21
- if (stop(r) || i >= max) {
22
- return r;
23
- } else {
24
- await wait(1000);
25
- return loop(f, max, stop, i + 1);
26
- }
27
- };
28
-
29
-
30
- export function right<L, R>(r: R) {
31
- return {type: 'right', value: r} as Either<L, R>
32
- }
33
- export function left<L, R>(l: L) {
34
- return { type: 'left', value: l } as Either<L, R>
35
- }
36
-
37
- export const getConfig = ():IStrategy=>{
38
- try {
39
-
40
- if(process.env.testing == "true"){
41
-
42
- const configs:IStrategy = require("../../../mockData/config.json");
43
- //@ts-ignore
44
- return configs;
45
- }else{
46
- const configs:IStrategy = require("../../../../../config.json");
47
- return configs;
48
- }
49
- } catch (ex) {
50
- throw "config.json not found";
51
- }
52
- };
53
-
54
- const configs = getConfig();
55
- const defaultFlowConfig = configs.strategyConfigs.default;
56
- const operatorsConfig = configs.strategyConfigs.operators;
57
-
58
- export const searchToObject = ()=> {
59
- if(typeof window !== "undefined"){
60
- return window.location.search.substring(1).split("&")
61
- .filter(x => !!x && x.length > 0)
62
- .map(kv => kv.split('='))
63
- .reduce((a, b) => ({...a, [b[0]]: b[1]}), {})
64
- } else {
65
- return {}
66
- }
67
- }
68
-
69
- export async function determineFlowByMsidn (internationalMSISDN: string):Promise<IFlow>{
70
- if (!internationalMSISDN ) {
71
- const submissionError = new Error(`Error in submitMSISDN() trigger-pin action`) as IError
72
- submissionError['type'] = "SEInvalidMSISDN";
73
- throw submissionError
74
- }
75
- const msisdn = internationalMSISDN.match(/\d+/gi).join('') // tallyman API expects international msisdn without any special character
76
-
77
- try{
78
- const indentifyFlow = async():Promise<IIdentifyResult>=>{
79
- const config = defaultFlowConfig.flowConfig;
80
- const { slug, country, device, host } = config;
81
- const rockmanId = window.pac_analytics.visitor.rockmanId
82
- const offer = window.pac_analytics.visitor.offer;
83
- const flowOperatorResult:IIdentifyResult = await window.tallymanApi.identify(host, slug, country, msisdn, device, offer, rockmanId);
84
- return flowOperatorResult;
85
- };
86
- const theResult = await indentifyFlow();
87
-
88
- const flow = operatorsConfig[theResult.operator] ? operatorsConfig[theResult.operator] : null;
89
- const cannotDetect = theResult.success === false && theResult.message === "Operator could not be found for the given MSISDN";
90
- const hlrError = theResult.success === false && theResult.message.indexOf("HLR did not find the operator for given MSISDN") !== -1;
91
-
92
-
93
- if(cannotDetect || hlrError){
94
- const submissionError = new Error(`Error in submitMSISDN() identify flow`) as IError & {msisdn:string}
95
- submissionError['type'] = "FlowDetectFailed";
96
- submissionError['msisdn'] = msisdn;
97
- throw submissionError
98
- }else if(flow !== null){
99
- const flowObj = {operator:theResult.operator, default:defaultFlowConfig, ...flow};
100
- return flowObj
101
- }else if(flow === null){
102
- const flowObj = {operator:theResult.operator, ...defaultFlowConfig};
103
- return flowObj
104
- }else{
105
- const submissionError = new Error(`Error in submitMSISDN() trigger-pin action`) as IError
106
- submissionError['type'] = "SEInvalidMSISDN";
107
- throw submissionError
108
- }
109
- }catch(err){
110
- throw err;
111
- }
112
- }
113
-
114
- export function determineFlowByOperator (operator: string):IFlow{
115
- const flowObj = {operator,default:defaultFlowConfig, ...operatorsConfig[operator]};
116
- return flowObj
117
- }
118
-
119
-
120
- export async function determineFlowByOperatorFromIp (isStrict?:boolean):Promise<IFlow>{
121
- const operator = await tryGetIPRangeName(window.pac_analytics.visitor);
122
- const flowObj = determineFlowByOperator(operator ? operator.toUpperCase() : "");
123
- return flowObj;
124
- }
125
-
126
-
127
- //if operator from server
128
- //no need for this
129
-
130
- export function getOperators (): Array<string> {
131
- const operators = Object.keys(operatorsConfig);
132
- return operators
133
- }
134
-
135
- const fetchJsonp: <T>(_url:string)=>Promise<T> = (_url:string)=>{
136
- let url = _url;
137
- let ouisys_callback_function = "ouisys_callback_function" + Math.floor(Math.random() * 10000)
138
- return new Promise((resolve, reject) => {
139
-
140
- //@ts-ignore
141
- window[ouisys_callback_function] = (arg:any)=>{
142
- resolve(arg);
143
- }
144
-
145
- url += (url.indexOf('?') === -1) ? '?' : '&';
146
- url += `jsonp=${ouisys_callback_function}`
147
- const script = document.createElement("script");
148
- script.src = url;
149
- script.id = ouisys_callback_function;
150
- document.body.appendChild(script)
151
-
152
- // Caught if got 404/500
153
- script.onerror = () => {
154
- reject(new Error(`JSONP request to ${_url} failed`));
155
- };
156
- });
157
- }
158
-
159
- export const identifyUser = async(extraParams?:ILinkExtraParams):
160
- Promise<{
161
- msisdn:string;
162
- operator:string;
163
- subscription_url?:string;
164
- redirect_url?:string;
165
- action?:()=>Promise<string>;
166
- }> => {
167
- if (typeof window == "undefined") {
168
- throw "javascript: console.error('SSR'); void 6"
169
- } else {
170
- const config = defaultFlowConfig.flowConfig;
171
-
172
- const { host, country, slug, queryString, device } = config
173
- const bupperizeCountry = (c:string) => c == 'gb' ? 'uk' : c;
174
- const offer = window.pac_analytics.visitor.offer
175
- const rockmanId = window.pac_analytics.visitor.rockmanId
176
- const s = window.location.search.substr(1)
177
- const search = (!!s && s.length > 0 ? [s] : []).concat((queryString || []).map(([k, v]) => `${k}=${v}`)).join('&')
178
- const extraParamsQs = !extraParams ? '' : '&' + Object.keys(extraParams).map(k => `${k}=${extraParams[k]}`).join('&')
179
-
180
- const isDMB = (window.pac_analytics.visitor.xaid != null && (window.pac_analytics.visitor.xaid.toLowerCase().indexOf("dmb") != -1 || window.pac_analytics.visitor.xaid.toLowerCase().indexOf("amb")) != -1) ? true : false;
181
- const newHost = isDMB ? "de.tallymans.com" : host;
182
-
183
- const searchObj = searchToObject() as IStrategyIDentifyUserResult;
184
-
185
-
186
- if(!!searchObj["redirect-back"] && searchObj["redirect-back"] == "1" && !!searchObj.success){
187
-
188
- const isSuccess = (searchObj.success as any) == "true" ? true : false;
189
-
190
- if(false == isSuccess){
191
-
192
- //@ts-ignore
193
- const identifyError = new Error(`Error in getRedirectUrl() identify-user action:\n${searchObj.message || "NotOn3g"}`) as IError & {type:string; next_action:string;}
194
- identifyError['type'] = "NotOn3g";
195
- //identifyError['next_action'] = result.next_action;
196
- throw identifyError
197
- }else{
198
-
199
- if(searchObj.subscription_url){
200
- const subscription_url = window.atob(searchObj.subscription_url);
201
-
202
- const newUrl = new URL(subscription_url);
203
- const queryString = newUrl.search;
204
- const urlParams = new URLSearchParams(queryString);
205
- const msisdn = urlParams.get("msisdn") || null;
206
- const operator = urlParams.get("operator") || null;
207
-
208
- return {subscription_url, action:()=>subscribe(subscription_url), msisdn:msisdn, operator:operator}
209
- }else if(searchObj.redirect_url){
210
-
211
- const url2 = `https://de.tallymans.com/tallyman/v1/?action=redirect&country=${bupperizeCountry(country)}&slug=${slug}&device=${"smart"}&offerId=${offer}&rockman_id=${rockmanId}&auto-redirect=1&${extraParamsQs}`
212
- // const result2 = await fetch(url2).then(x => x.json())
213
-
214
- const redirect_url = window.atob(searchObj.redirect_url);
215
-
216
- const newUrl = new URL(redirect_url);
217
- const queryString = newUrl.search;
218
- const urlParams = new URLSearchParams(queryString);
219
- const msisdn = urlParams.get("msisdn") || null;
220
- const operator = urlParams.get("operator") || null;
221
-
222
- if(msisdn != null){
223
- return {subscription_url:url2, msisdn:msisdn, operator:operator}
224
- }else{
225
- return {redirect_url, msisdn:msisdn, operator:operator}
226
- }
227
- }else{
228
- const newUrl = new URL(window.location.href);
229
- const queryString = newUrl.search;
230
- const urlParams = new URLSearchParams(queryString);
231
- const msisdn = urlParams.get("msisdn") || null;
232
- const operator = urlParams.get("operator") || null;
233
- return { msisdn, operator}
234
-
235
- }
236
-
237
- }
238
- }else{
239
- const url = `https://${newHost}/tallyman/v1/?action=identify-user&country=${bupperizeCountry(country)}&slug=${slug}&device=${device}&offerId=${offer}&page=${window.location.href}&pixel_url=${encodeURIComponent(`http://${window.location.host}/pixels?xcid=${window.location.pathname.replace("/", "")}&xaid=${window.pac_analytics.visitor.xaid}&country=${bupperizeCountry(country)}`)}&rockman_id=${rockmanId}${extraParamsQs}&${search}`
240
-
241
- const result = await fetchJsonp<IStrategyIDentifyUserResult>(url);
242
- if(false === result.success){
243
- const identifyError = new Error(`Error in getRedirectUrl() identify-user action:\n${result.message}`) as IError & {type:string; next_action:string;}
244
- identifyError['type'] = "NotOn3g";
245
- //identifyError['next_action'] = result.next_action;
246
- throw identifyError
247
- }else{
248
- return {subscription_url:result.subscription_url || result.redirect_url, action:()=>subscribe(result.subscription_url), msisdn:result.msisdn, operator:result.operator}
249
- }
250
- }
251
- }
252
- }
253
-
254
- export const subscribe:(url:string)=>Promise<string> = async(url:string)=>{
255
-
256
- // const result:ISubscribeResult = await fetch(url + "&operator=kw_viva").then((x)=>x.json())
257
-
258
- // if(false === result.success){
259
- // const subscribeError = new Error(`Error in subscribe() one-click-subscribe action:\n${result.message}`) as IError & {type:string;}
260
- // subscribeError['type'] = "SubscriptionError";
261
- // throw subscribeError
262
- // }else{
263
- return "/mock-product-url"
264
- //}
265
-
266
- }
267
-
268
- export function mockConfig(flow:string):IConfig{
269
- const configs = getConfig();
270
- const defaultFlowConfig = configs.strategyConfigs.default;
271
- const operatorsConfig = configs.strategyConfigs.operators;
272
-
273
- const opArr = Object.keys(operatorsConfig);
274
- const r = opArr.filter((o)=>operatorsConfig[o].flow === flow);
275
- const operator = r[0];
276
- const flowObj = {offer:1,operator,default:defaultFlowConfig, ...operatorsConfig[operator]};
277
-
278
- return flowObj;
279
- }
280
-
281
-
282
- export const mockedPinFlow : IStrategyReducerState = {
283
- currentState:{
284
- type: "PIN",
285
- result: {
286
- nextAction:"submitMSISDNAction",
287
- config:mockConfig("pin")
288
- }
289
- }
290
- }
291
-
292
- export const mockedMoFlow : IStrategyReducerState = {
293
- currentState:{
294
- type: "MO",
295
- result: {
296
- nextAction:"submitMSISDNAction",
297
- config:mockConfig("mo")
298
- }
299
- }
300
- }
301
-
302
-
303
- export const mockedUssdFlow : IStrategyReducerState = {
304
- currentState:{
305
- type: "USSD",
306
- result: {
307
- nextAction:"submitMSISDNAction",
308
- config:mockConfig("ussd")
309
- }
310
- }
311
- }
312
-
313
-
314
- export const mockedMoRdirFlow : IStrategyReducerState = {
315
- currentState:{
316
- type: "MO_REDIR",
317
- result: {
318
- nextAction:"submitMSISDNAction",
319
- config:mockConfig("moRedir")
320
- }
321
- }
322
- }
323
-
324
- export const mockedClick2smsFlow : IStrategyReducerState = {
325
- currentState:{
326
- type: "CLICK2SMS",
327
- result: {
328
- nextAction:"loadOc2sms",
329
- config:mockConfig("click2sms")
330
- }
331
- }
332
- }
333
-
334
-
335
- export const mockedOneClickFlow : IStrategyReducerState = {
336
- currentState:{
337
- type: "ONE_CLICK",
338
- result: {
339
- nextAction:"getRedirectUrlAction",
340
- config:mockConfig("oneClick")
341
- }
342
- }
343
- }
344
-
345
- export const mockedTPayFlow : IStrategyReducerState = {
346
- currentState:{
347
- type: "TPAY_HE",
348
- result: {
349
- nextAction:"loadTpayAction",
350
- config:mockConfig("tpayHe")
351
- }
352
- }
353
- }
354
- // export const mockedMOFlow : State = { type: "MO", result:moFlow(mockTracker, mockConfig("mo"))}
355
- // export const mockedOneClickFlow : State = { type: "ONECLICK", result:oneClickFlow(mockTracker, mockConfig("oneClick"), {"testextraparams":"1"})}
356
- // export const mockedClick2smsFlow : State = { type: "CLICK2SMS", result:click2smsFlow(mockTracker, mockConfig("click2sms"))}
357
- // export const mockedMORedirFlow : State = { type: "MOREDIR", result:moRedirFlow(mockTracker, mockConfig("moRedir"))}
@@ -1,7 +0,0 @@
1
- type IUssdConstants =
2
- "USSD_MSISDN_SUBMIT"
3
- | "USSD_MSISDN_SUBMIT_ERROR"
4
- | "USSD_BACK_TO_START"
5
- | "MOCK_USSD_FLOW_STATE"
6
-
7
- export default IUssdConstants
@@ -1,112 +0,0 @@
1
- import * as RDS from "../../common-types/RemoteDataState";
2
- import { AppThunk } from "../../common-types/AppThunk";
3
-
4
- export type IUssdFlowCurrentState =
5
- | {
6
- type: "MSISDNEntry";
7
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
8
- }
9
-
10
- export type MSISDNEntryErrorTypes =
11
- | "AlreadySubscribed"
12
- | "UnknownError"
13
- | "InvalidMSISDN"
14
- | "UnexpectedState";
15
- export type MSISDNEntryFailure = {
16
- errorType: MSISDNEntryErrorTypes;
17
- error: any;
18
- productUrl?:string;
19
- };
20
- export type MSISDNEntrySuccess = IKeywordShortcode
21
- type ACompType =
22
- React.ComponentType<{ children: React.ReactNode } & React.HTMLAttributes<HTMLAnchorElement> & { keyword?: string, shortcode?: string }>
23
-
24
- export type IMsisnSubmitActionPayload = {
25
- type:"MSISDNEntry";
26
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
27
- }
28
-
29
-
30
-
31
- export interface IUssdFlowReducerState {
32
- currentState:IUssdFlowCurrentState
33
- }
34
-
35
-
36
- export type IConfig = {
37
- offer?: number,
38
- slug?: string;
39
- country?: string;
40
- host?:string;
41
- device?: "smart" | "feature";
42
- operators?: string[];
43
- }
44
-
45
- export type IKeywordShortcode = {
46
- keyword : string,
47
- shortcode : string,
48
- }
49
-
50
- export type IMSISDNSubmissionResult = {
51
- success: true
52
- rockman_id: string,
53
- keyword: string,
54
- shortcode: string,
55
- } | {
56
- success: false,
57
- rockman_id: string,
58
- message: string,
59
- }
60
-
61
- export type ICheckSubscriptionResult = {
62
- success: false;
63
- rockman_id: string;
64
- message: string;
65
- } | {
66
- success: true;
67
- msisdn: string;
68
- product_url?: string;
69
- rockman_id: string;
70
- }
71
-
72
-
73
-
74
- export type IBackToStartPayload = {
75
- type: "MSISDNEntry";
76
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
77
- }
78
-
79
- export type IUssdActions =
80
- {
81
- type: "USSD_MSISDN_SUBMIT";
82
- payload:IMsisnSubmitActionPayload;
83
-
84
- }
85
- |
86
- {
87
- type: "USSD_MSISDN_SUBMIT_ERROR";
88
- payload:IMsisdnSubmitErrorPayload;
89
-
90
- }
91
- |
92
- {
93
- type: "USSD_BACK_TO_START";
94
- payload:IBackToStartPayload;
95
- }|
96
- {
97
- type:"MOCK_USSD_FLOW_STATE";
98
- payload:IUssdFlowCurrentState;
99
- }
100
-
101
-
102
- export type IMsisdnSubmitErrorPayload = {
103
- type:"MSISDNEntry";
104
- result: RDS.RemoteDataState<MSISDNEntryFailure, MSISDNEntrySuccess>;
105
- }
106
-
107
-
108
- export type IUssdFlowActionMaps = {
109
- submitMSISDNAction:(msisdn:string)=>AppThunk;
110
- }
111
-
112
- export type IMockUssdFlowStates = "msisdn-entry-success-state" | "msisdn-entry-failure-state"
@@ -1,146 +0,0 @@
1
- // LIBRARIES
2
- import * as RDS from "../../common-types/RemoteDataState";
3
-
4
- import { MSISDNEntryFailure, MSISDNEntryErrorTypes, IUssdFlowReducerState, MSISDNEntrySuccess, IMsisnSubmitActionPayload, IBackToStartPayload, IMsisdnSubmitErrorPayload, IUssdActions, IUssdFlowActionMaps, IMockUssdFlowStates } from "./UssdTypes";
5
- import { AppThunk } from "../../common-types/AppThunk";
6
- import submitMSISDN, { checkSubscription, mockedMSISDNEntryFailure, mockedMSISDNEntrySuccess } from "./utils";
7
- import { genericHandler, tracker } from "../strategy";
8
-
9
- //ACTION CREATORS
10
- export function submitMSISDNAction(msisdn:string):AppThunk{
11
- return async (dispatch, store)=>{
12
- const {currentState} = store().strategy
13
- if(currentState.type === "USSD"){
14
- const config = currentState.result.config;
15
-
16
- try {
17
-
18
- dispatch({
19
- type: "USSD_MSISDN_SUBMIT",
20
- payload:{
21
- type:"MSISDNEntry",
22
- result: RDS.Loading()
23
- }
24
- })
25
- tracker.advancedInFlow('tallyman.v1-ussd', 'msisdn-submitted', { msisdn })
26
-
27
- const keywordAndShortcode = await submitMSISDN(
28
- window,
29
- config,
30
- msisdn
31
- );
32
- tracker.advancedInFlow('tallyman.v1-ussd', 'msisdn-submission-success', { msisdn })
33
-
34
- dispatch({
35
- type: "USSD_MSISDN_SUBMIT",
36
- payload:{
37
- type:"MSISDNEntry",
38
- result: RDS.Success<MSISDNEntryFailure, MSISDNEntrySuccess>({...keywordAndShortcode})
39
- }
40
- })
41
-
42
- try{
43
- checkSubscription(window, config)
44
- .then((product_url)=>{
45
-
46
- tracker.advancedInFlow('tallyman.v1-ussd', 'sale', { msisdn });
47
- setTimeout(() => {
48
- window.location.href = product_url
49
- }, 1000);
50
- })
51
- }catch(err){
52
- throw err;
53
- }
54
- } catch (ex) {
55
- console.warn(ex)
56
- const errorType: MSISDNEntryErrorTypes =
57
- "SEAlreadySubscribed" === ex.type
58
- ? "AlreadySubscribed"
59
- : "SEInvalidMSISDN" == ex.type
60
- ? "InvalidMSISDN"
61
- : "UnknownError";
62
- tracker.recedeInFlow('tallyman.v1-ussd', 'msisdn-submission-failure', { msisdn, errorType: errorType || 'UnknownError' })
63
-
64
- dispatch({
65
- type: "USSD_MSISDN_SUBMIT_ERROR",
66
- payload:{
67
- type:"MSISDNEntry",
68
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({
69
- errorType: errorType,
70
- error: ex,
71
- productUrl: ex.productUrl
72
- })
73
- }
74
- });
75
- }
76
- }else{
77
- dispatch({
78
- type: "USSD_MSISDN_SUBMIT_ERROR",
79
- payload:{
80
- type:"MSISDNEntry",
81
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({
82
- errorType: "UnexpectedState",
83
- error: null
84
- })
85
- }
86
- });
87
- throw "Unexpected state"
88
- }
89
- }
90
- }
91
-
92
- export function mockUssdFlow(mockState:IMockUssdFlowStates):AppThunk {
93
- return (dispatch)=>{
94
- if(mockState !== undefined){
95
- switch (mockState) {
96
- case "msisdn-entry-failure-state":
97
- return dispatch({
98
- type:"MOCK_USSD_FLOW_STATE",
99
- payload:mockedMSISDNEntryFailure.currentState
100
- })
101
- case "msisdn-entry-success-state":
102
- return dispatch({
103
- type:"MOCK_USSD_FLOW_STATE",
104
- payload:mockedMSISDNEntrySuccess.currentState
105
- })
106
- default:
107
- throw "Mock Flow not supported";
108
- }
109
- }
110
- }
111
- }
112
- export function backToStart(){
113
- return {
114
- type:"USSD_BACK_TO_START",
115
- payload:{
116
- type: "MSISDNEntry",
117
- result: RDS.NothingYet<MSISDNEntryFailure, MSISDNEntrySuccess>()
118
- }
119
- };
120
- }
121
- const initialState:IUssdFlowReducerState = {
122
- currentState:{
123
- type: "MSISDNEntry",
124
- result: RDS.NothingYet<MSISDNEntryFailure, MSISDNEntrySuccess>()
125
- }
126
- };
127
-
128
- export const UssdFlowActionMaps:IUssdFlowActionMaps = {
129
- submitMSISDNAction:submitMSISDNAction
130
- }
131
-
132
- export default function UssdFlowReducer(state = initialState, action:IUssdActions) {
133
- switch (action.type) {
134
- case "USSD_MSISDN_SUBMIT":
135
- return genericHandler<IUssdFlowReducerState, IMsisnSubmitActionPayload>(state, action.payload)
136
- case "USSD_BACK_TO_START":
137
- return genericHandler<IUssdFlowReducerState, IBackToStartPayload>(state, action.payload)
138
- case "USSD_MSISDN_SUBMIT_ERROR":
139
- return genericHandler<IUssdFlowReducerState, IMsisdnSubmitErrorPayload>(state, action.payload)
140
- case "MOCK_USSD_FLOW_STATE":
141
- return genericHandler<IUssdFlowReducerState, any>(state, action.payload)
142
-
143
- default:
144
- return state;
145
- }
146
- }