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,78 +0,0 @@
1
- import { IConfig, IMSISDNSubmissionResult, MSISDNEntryFailure, MSISDNEntrySuccess, IMoRedirFlowReducerState } from "./MoRedirTypes";
2
- import IError from "../../common-types/IError";
3
- import tryGetIPRangeName from "../../ips/tryGetIPRangeName";
4
- import * as RDS from "../../common-types/RemoteDataState";
5
- import loadScriptSrc from "../../utilities/loadScriptSrc";
6
- import { getHost, isDMBCheck } from "../../utilities";
7
- import loadScriptInnerHtml from "../../utilities/loadScriptInnerHtml";
8
- import { getConfig } from "../strategy/utils";
9
-
10
-
11
- export default async function submitMSISDN(window: Window, maybeConfig: IConfig, internationalMSISDN: string, extraParams?: {[key: string]: string}): Promise<string> {
12
- const config: IConfig = {offer:window.pac_analytics.visitor.offer, ...(maybeConfig||{})}
13
- return submitMSISDNWithConfig(window, config, internationalMSISDN, extraParams)
14
- }
15
-
16
- export async function submitMSISDNWithConfig(window: Window, config: IConfig, internationalMSISDN: string, extraParams?: { [key: string]: string }): Promise<string> {
17
- const { slug, country, device, offer, host } = config
18
- const search = window.location.search.substr(1) || '';
19
- const extraParamsQs = !extraParams ? '' : '&' + Object.keys(extraParams).map(k => `${k}=${extraParams[k]}`).join('&')
20
- const msisdn = internationalMSISDN.match(/\d+/gi).join('')
21
- const visitor = window.pac_analytics.visitor;
22
- const rockmanId = visitor.rockmanId;
23
-
24
- const ip_range_name = country == "ci" ? await tryGetIPRangeName(visitor) : null;
25
-
26
- const result: IMSISDNSubmissionResult = await window.tallymanApi.redirect(host, slug, country, msisdn, device, offer, rockmanId, ip_range_name, search, extraParamsQs)
27
-
28
- if (false === result.success) {
29
- const type = result.message == 'ALREADY SUBSCRIBED' ? "AlreadySubscribed" : "InvalidMSISDN";
30
- const error = new Error(`${type}:\n${result.message}`) as IError & {type:string}
31
- error['type'] = type;
32
- console.error(error)
33
- throw error
34
- } else {
35
- return result.redirect_url
36
-
37
- }
38
- }
39
-
40
- export const startEvinaAgency = (config: IConfig)=>{
41
- try{
42
- const configs = getConfig();
43
- const defaultFlowConfig = configs.strategyConfigs.default;
44
-
45
- const { host } = !!config ? config : defaultFlowConfig.flowConfig;
46
- const newHost = getHost({host});
47
- const rockmanId = window.pac_analytics.visitor.rockmanId;
48
- const url = `https://${newHost}/tallyman/helper/?action=mi-agency&process=a2-du-evina-start&rockman_id=${rockmanId}`;
49
-
50
- fetch(url).then((x)=>x.text()).then((txt)=>loadScriptInnerHtml(txt)).then(()=>{
51
- console.log('Ev ready');
52
- let event = new Event('DCBProtectRun');
53
- if(typeof window != "undefined"){
54
- document.dispatchEvent(event);
55
- }
56
- });
57
- }catch(err){
58
- console.error("startEvinaAgency ERROR", err)
59
- }
60
-
61
- }
62
-
63
- export const mockedMSISDNEntrySuccess : IMoRedirFlowReducerState = {
64
- currentState:{
65
- type: "MSISDNEntry",
66
- result: RDS.Success<MSISDNEntryFailure, MSISDNEntrySuccess>({
67
- href: '/mock-product-url'
68
- })
69
- }
70
- }
71
-
72
-
73
- export const mockedMSISDNEntryFailure : IMoRedirFlowReducerState = {
74
- currentState:{
75
- type: "MSISDNEntry",
76
- result: RDS.Failure<MSISDNEntryFailure, MSISDNEntrySuccess>({ errorType: "InvalidMSISDN", error: "Invalid Mobile Number" })
77
- }
78
- }
@@ -1,3 +0,0 @@
1
- type IOneClickConstants = "GET_REDIRECT_URL" | "SUBCRIBE_AJAX";
2
-
3
- export default IOneClickConstants
@@ -1,108 +0,0 @@
1
- import * as RDS from "../../common-types/RemoteDataState";
2
- import { AppThunk } from "../../common-types/AppThunk";
3
-
4
- export type IGETREDIRECTURLFailure = {
5
- errorType:string;
6
- }
7
- export type IGETREDIRECTURLSuccess = {
8
- redirectUrl:string;
9
- nextAction:"getRedirectUrlAction";
10
- }
11
- export type SubscribeUserErrorTypes = "SubscriptionError" | "UnknownError" | "AlreadySubscribed";
12
- export type SubscribeSuccess = {
13
- productUrl:string;
14
- };
15
-
16
- export type SubscribeFailure = {
17
- errorType: SubscribeUserErrorTypes;
18
- error: Error;
19
- productUrl?:string;
20
- };
21
- export type IOneClickCurrentState = {
22
- type: "GET_REDIRECT_URL",
23
- result:RDS.RemoteDataState<IGETREDIRECTURLFailure, IGETREDIRECTURLSuccess>
24
- }
25
- |
26
- {
27
- type: "SUBCRIBE_AJAX",
28
- result:RDS.RemoteDataState<SubscribeFailure, SubscribeSuccess>
29
- }
30
-
31
- export type IOneClickFlowReducerState =
32
- {
33
- currentState:IOneClickCurrentState;
34
- };
35
-
36
- export type IGetRedirectUrlPayload = {
37
- type:"GET_REDIRECT_URL",
38
- result:RDS.RemoteDataState<IGETREDIRECTURLFailure, IGETREDIRECTURLSuccess>
39
- }
40
-
41
- export type IOneClickFlowActionMaps = {
42
- getRedirectUrlAction:(extraParams?:ILinkExtraParams, autoRedirect?:boolean)=>AppThunk
43
- }
44
-
45
- export type IOneClickActions = {
46
- type:"GET_REDIRECT_URL";
47
- payload:IGetRedirectUrlPayload;
48
- }
49
-
50
-
51
-
52
- export interface ILinkExtraParams {
53
- [key: string]: string
54
- }
55
-
56
-
57
-
58
-
59
- ///
60
-
61
- export type IClickActionTypes = "he" | "redirect" | "identify-user";
62
- export type IConfig = {
63
- host?: string, country?: string, slug?: string, queryString?: Array<[string, string]>, device?:string, apiAction?:IClickActionTypes,
64
- }
65
-
66
- export type IIDentifyUserResult = {
67
- success:true;
68
- rockman_id: string;
69
- subscription_url?:string;
70
- redirect_url?:string;
71
- } |
72
- {
73
- success: false;
74
- rockman_id: string;
75
- message: string;
76
- }
77
-
78
- export type IHEResult = {
79
- success:true;
80
- rockman_id: string;
81
- redirectUrlWithReplacedUniqid?:string;
82
- source:string;
83
- oldUniqid: string;
84
- newUniqid: string;
85
- } |
86
- {
87
- success: false;
88
- rockman_id: string;
89
- message: string;
90
- }
91
-
92
- export type ISubscribeResult = {
93
- success:true;
94
- rockman_id: string;
95
- product_url:string;
96
- redirect_url?:string;
97
- } |
98
- {
99
- success: false;
100
- rockman_id: string;
101
- message: string;
102
- product_url?:string;
103
- }
104
-
105
- export type IMockOneClickFlowStates = "redirect-url-success-state" | "subscribe-ajax-state"
106
-
107
-
108
-
@@ -1,268 +0,0 @@
1
- // LIBRARIES
2
- import * as RDS from "../../common-types/RemoteDataState";
3
-
4
- import { IOneClickFlowReducerState, IOneClickActions, IOneClickFlowActionMaps, ILinkExtraParams, IGETREDIRECTURLFailure, IGETREDIRECTURLSuccess, IGetRedirectUrlPayload, SubscribeUserErrorTypes, SubscribeFailure, SubscribeSuccess, IMockOneClickFlowStates } from "./OneClickTypes";
5
- import { AppThunk } from "../../common-types/AppThunk";
6
- import { getRedirectUrl, getRedirectUrlBupperWay, mockedRedirectUrlSuccessState, mockedSubscribeAjaxState, subscribe } from "./utils";
7
- import { genericHandler, tracker } from "../strategy";
8
- import { IHash } from "../strategy/StrategyTypes";
9
-
10
-
11
-
12
-
13
- //ACTION CREATORS
14
- export function getRedirectUrlAction({extraParams, autoRedirect = false, isGetRedirectBupperWay = false}:{extraParams?:ILinkExtraParams, autoRedirect?:boolean, isGetRedirectBupperWay?:boolean}):AppThunk{
15
- return async (dispatch, store)=>{
16
- const {currentState} = store().strategy
17
- if(currentState.type === "ONE_CLICK"){
18
-
19
-
20
- const {config, subscription_url, redirect_url} = currentState.result;
21
- try {
22
- dispatch({
23
- type: "GET_REDIRECT_URL",
24
- payload:{
25
- type: "GET_REDIRECT_URL",
26
- result: RDS.Loading()
27
- }
28
- })
29
-
30
- if(isGetRedirectBupperWay == true){
31
- const redirectUrl = await getRedirectUrlBupperWay(
32
- window,
33
- config,
34
- {...(currentState.result.operator && {operator:currentState.result.operator}),...extraParams})
35
-
36
-
37
- tracker.customEvent('Flow', 'advance-auto', 'redirect-success', {redirect_url:redirectUrl})
38
- if(autoRedirect == true || window.isAutoFraudScreener === true){
39
-
40
- if(process.env.NODE_ENV === "production"){
41
- // Wait for Evina to Check Fraud First
42
- const timer = setInterval(() => {
43
- if(window.isEvinaSessionChecked){
44
- clearInterval(timer);
45
- tracker.advancedInFlow('tallyman.v1-one-click', 'click-redirect-url', {redirect_url:redirectUrl});
46
- setTimeout(() => {
47
- window.location.href = redirectUrl;
48
- }, 0);
49
- }
50
- }, 100);
51
- }else{
52
- tracker.advancedInFlow('tallyman.v1-one-click', 'click-redirect-url', {redirect_url:redirectUrl});
53
- setTimeout(() => {
54
- window.location.href = redirectUrl;
55
- }, 0);
56
- }
57
-
58
-
59
-
60
- }else{
61
- dispatch({
62
- type: "GET_REDIRECT_URL",
63
- payload:{
64
- type: "GET_REDIRECT_URL",
65
- result: RDS.Success({
66
- redirectUrl
67
- })
68
- }
69
- })
70
- }
71
- }else{
72
- if(subscription_url && subscription_url != null){
73
-
74
- return dispatch({
75
- type: "GET_REDIRECT_URL",
76
- payload:{
77
- type: "SUBCRIBE_AJAX",
78
- result: RDS.NothingYet()
79
- }
80
- })
81
-
82
- }else if(redirect_url && redirect_url != null){
83
- tracker.customEvent('Flow', 'advance-auto', 'redirect-success', {redirect_url})
84
- return dispatch({
85
- type: "GET_REDIRECT_URL",
86
- payload:{
87
- type: "GET_REDIRECT_URL",
88
- result: RDS.Success({
89
- redirectUrl:redirect_url
90
- })
91
- }
92
- })
93
- }else{
94
- const {redirect_url } = await getRedirectUrl(
95
- window,
96
- config,
97
- {...(currentState.result.operator && {operator:currentState.result.operator}),...extraParams}
98
- );
99
-
100
- tracker.customEvent('Flow', 'advance-auto', 'redirect-success', {redirect_url})
101
-
102
- if(autoRedirect == true || window.isAutoFraudScreener === true){
103
- tracker.advancedInFlow('tallyman.v1-one-click', 'click-redirect-url', {redirect_url});
104
-
105
- setTimeout(() => {
106
- window.location.href = redirect_url;
107
- }, 0);
108
- }else{
109
- dispatch({
110
- type: "GET_REDIRECT_URL",
111
- payload:{
112
- type: "GET_REDIRECT_URL",
113
- result: RDS.Success({
114
- redirectUrl:redirect_url
115
- })
116
- }
117
- })
118
- }
119
- }
120
- }
121
- } catch (ex) {
122
- console.warn(ex)
123
- console.log("Falling back to bupper")
124
- if(autoRedirect != true){
125
- dispatch({
126
- type: "GET_REDIRECT_URL",
127
- payload:{
128
- type: "GET_REDIRECT_URL",
129
- result: RDS.Failure({
130
- errorType:"UnknownError"
131
- })
132
- }
133
- })
134
- }
135
- }
136
- }else{
137
- dispatch({
138
- type: "GET_REDIRECT_URL",
139
- payload:{
140
- type: "GET_REDIRECT_URL",
141
- result: RDS.Failure({
142
- errorType:"UnexpectedState"
143
- })
144
- }
145
- })
146
- throw "Unexpected state";
147
-
148
- }
149
- }
150
- }
151
-
152
- export function subscribeUrlAction(autoRedirect?:boolean, extraParams?:IHash):AppThunk{
153
-
154
- return async (dispatch, store)=>{
155
- const {currentState} = store().strategy
156
- if(currentState.type === "ONE_CLICK"){
157
- const {subscription_url} = currentState.result;
158
- try {
159
- dispatch({
160
- type: "GET_REDIRECT_URL",
161
- payload:{
162
- type: "SUBCRIBE_AJAX",
163
- result: RDS.Loading()
164
- }
165
- })
166
- tracker.advancedInFlow('tallyman.v1-one-click', 'click-subscribe');
167
-
168
-
169
- //STILL NEED TO SUPPORT SUBCRIBE AJAX
170
- const product_url = await subscribe(subscription_url,extraParams)
171
-
172
- tracker.advancedInFlow('tallyman.v1-one-click', 'click-subscribe-success', {product_url});
173
-
174
-
175
- if(autoRedirect == true){
176
- tracker.customEvent('Flow','advance-auto', 'click-product-url', {product_url});
177
-
178
- window.location.href = product_url;
179
- }else{
180
- dispatch({
181
- type: "GET_REDIRECT_URL",
182
- payload:{
183
- type: "SUBCRIBE_AJAX",
184
- result: RDS.Success({
185
- productUrl:product_url
186
- })
187
- }
188
- })
189
- }
190
-
191
- } catch (ex) {
192
- console.warn(ex)
193
- const errorType: SubscribeUserErrorTypes =
194
- "AlreadySubscribed" === ex.type
195
- ? "AlreadySubscribed"
196
- : "SubscriptionError" === ex.type
197
- ? "SubscriptionError"
198
- : "UnknownError";
199
- tracker.recedeInFlow('tallyman.v1-one-click', 'click-subscribe-failure', {error:ex.toString()});
200
- dispatch({
201
- type: "GET_REDIRECT_URL",
202
- payload:{
203
- type: "SUBCRIBE_AJAX",
204
- result: RDS.Failure<SubscribeFailure, SubscribeSuccess>({
205
- errorType: errorType,
206
- error: ex,
207
- productUrl: ex.productUrl
208
- })
209
- }
210
- })
211
- }
212
- }else{
213
- tracker.recedeInFlow('tallyman.v1-one-click', 'click-subscribe-failure', {error:"UnexpectedState"});
214
-
215
- dispatch({
216
- type: "GET_REDIRECT_URL",
217
- payload:{
218
- type: "SUBCRIBE_AJAX",
219
- result: RDS.Failure({
220
- errorType:"UnexpectedState"
221
- })
222
- }
223
- })
224
- throw "Unexpected state";
225
- }
226
- }
227
- }
228
-
229
-
230
- export function mockOneClickFlow(mockState:IMockOneClickFlowStates):AppThunk {
231
- return (dispatch)=>{
232
- if(mockState !== undefined){
233
- switch (mockState) {
234
- case "redirect-url-success-state":
235
- return dispatch({
236
- type:"GET_REDIRECT_URL",
237
- payload:mockedRedirectUrlSuccessState.currentState
238
- })
239
-
240
- case "subscribe-ajax-state":
241
- return dispatch({
242
- type:"GET_REDIRECT_URL",
243
- payload:mockedSubscribeAjaxState.currentState
244
- })
245
- default:
246
- throw "Mock Flow not supported";
247
- }
248
- }
249
- }
250
- }
251
-
252
- const initialState:IOneClickFlowReducerState = {
253
- currentState:{
254
- type: "GET_REDIRECT_URL",
255
- result: RDS.NothingYet<IGETREDIRECTURLFailure, IGETREDIRECTURLSuccess>()
256
- }
257
- };
258
- export const OneClickFlowActionMaps:IOneClickFlowActionMaps = {
259
- getRedirectUrlAction:getRedirectUrlAction
260
- }
261
- export default function OneClickFlowReducer(state = initialState, action:IOneClickActions) {
262
- switch (action.type) {
263
- case "GET_REDIRECT_URL":
264
- return genericHandler<IOneClickFlowReducerState, IGetRedirectUrlPayload>(state, action.payload)
265
- default:
266
- return state;
267
- }
268
- }
@@ -1,219 +0,0 @@
1
- import { IConfig, ILinkExtraParams, IGETREDIRECTURLFailure, IGETREDIRECTURLSuccess, IOneClickCurrentState, IIDentifyUserResult, ISubscribeResult, IOneClickFlowReducerState } from "./OneClickTypes";
2
-
3
- import * as RDS from "../../common-types/RemoteDataState";
4
- import IError from "../../common-types/IError";
5
- import { IHash } from "../strategy/StrategyTypes";
6
- import loadScriptInnerHtml from "../../utilities/loadScriptInnerHtml";
7
- import { IMcpShieldResult } from "../pinFlow/PinTypes";
8
-
9
- export const additionalQueryString = `msisdnSubmitted=Y&legalCheckbox=Y&incentivizedCheckbox=Y&op_confirmCheckbox=N`
10
-
11
- const fetchJsonp: <T>(_url:string)=>Promise<T> = (_url:string)=>{
12
- let url = _url;
13
- let ouisys_callback_function = "ouisys_callback_function" + Math.floor(Math.random() * 10000)
14
- return new Promise((resolve, reject) => {
15
-
16
- //@ts-ignore
17
- window[ouisys_callback_function] = (arg)=>{
18
- resolve(arg);
19
- }
20
-
21
- url += (url.indexOf('?') === -1) ? '?' : '&';
22
- url += `jsonp=${ouisys_callback_function}`
23
- const script = document.createElement("script");
24
- script.src = url;
25
- script.id = ouisys_callback_function;
26
- document.body.appendChild(script)
27
-
28
- // Caught if got 404/500
29
- script.onerror = () => {
30
- reject(new Error(`JSONP request to ${_url} failed`));
31
- };
32
- });
33
- }
34
-
35
- let uniqidResult;
36
- export const getRedirectUrl = async(window:Window, maybeConfig: IConfig, extraParams?:ILinkExtraParams): Promise<{
37
- subscription_url?:string;
38
- redirect_url?:string;
39
- action?:()=>Promise<string>;
40
- }> => {
41
- if (typeof window == "undefined") {
42
- throw "javascript: console.error('SSR'); void 6"
43
- } else {
44
- const { host, country, slug, queryString, device, apiAction} = maybeConfig
45
- const customDomain = slug === "evina-test-handle" ? "dev.ng.eu.ngrok.io" : "de-ads.tallymans.com";
46
-
47
- const bupperizeCountry = (c:string) => c == 'gb' ? 'uk' : c;
48
- const offer = window.pac_analytics.visitor.offer
49
- const s = window.location.search.substr(1)
50
- const search = (!!s && s.length > 0 ? [s] : []).concat((queryString || []).map(([k, v]) => `${k}=${v}`)).join('&')
51
- const extraParamsQs = !extraParams ? '' : '&' + Object.keys(extraParams).map(k => `${k}=${extraParams[k]}`).join('&')
52
- const rockmanId = window.pac_analytics.visitor.rockmanId
53
-
54
- if(apiAction == "identify-user"){
55
-
56
- const url = `https://de.tallymans.com/tallyman/v1/?action=identify-user&country=${bupperizeCountry(country)}&slug=${slug}&device=${"smart"}&offerId=${offer}&rockman_id=${rockmanId}${extraParamsQs}&${search}`
57
- const result = await fetchJsonp<IIDentifyUserResult>(url);
58
- if(false === result.success){
59
- const identifyError = new Error(`Error in getRedirectUrl() identify-user action:\n${result.message}`) as IError;
60
- identifyError['type'] = "NotOn3g";
61
- throw identifyError
62
- }else{
63
- return {subscription_url:result.subscription_url || result.redirect_url, action:()=>subscribe(result.subscription_url)}
64
- }
65
-
66
- }else if(apiAction == "he"){
67
- const url = `https://de.tallymans.com/tallyman/v1/?action=he&country=${bupperizeCountry(country)}&slug=${slug}&device=${"smart"}&offerId=${offer}&rockman_id=${rockmanId}${extraParamsQs}&${search}`
68
- const result = await fetch(url).then(x => x.json());
69
- if(false === result.success){
70
- const identifyError = new Error(`Error in getRedirectUrl() identify-user action:\n${result.message}`) as IError;
71
- identifyError['type'] = "NotOn3g";
72
- throw identifyError
73
- }else{
74
- loadScriptInnerHtml(result.source)
75
- return {redirect_url:result.redirectUrlWithReplacedUniqid}
76
- }
77
- }else{
78
- if(country.toLowerCase() === "za" && slug !== 'evina-test-handle'){
79
- try{
80
- const mcpShieldResult: IMcpShieldResult = await window.tallymanApi.mcpShield(host, country, slug, device, offer, rockmanId)
81
- if(false == mcpShieldResult.success){
82
- console.warn(mcpShieldResult.message);
83
- }else{
84
- loadScriptInnerHtml(mcpShieldResult.source);
85
- uniqidResult = mcpShieldResult.uniqid;
86
- const mcpSessionCheckWithBlock = `
87
-
88
- document.addEventListener('click', function (event) {
89
-
90
- event.preventDefault();
91
- try{
92
- if (!event.target.matches('.mcp')) return;
93
- if (!window.isMcpSessionChecked) {
94
-
95
- var url = "https://de-ads.tallymans.com/tallyman/v1/?action=mcp-session-check&slug=${slug}&country=${country}&device=${device}&rockman_id=${rockmanId}&mcpUniqid=${uniqidResult}";
96
-
97
- fetch(url).then(function(res) {
98
- return res.json()
99
- }).then(function(resJson) {
100
- window.isMcpSessionChecked = true;
101
- console.log('MCP');
102
-
103
- if (resJson["should-block"] == true) {
104
- document.body.innerHTML = ""
105
-
106
- var div = document.createElement("div");
107
- div.setAttribute("id", "page_blocked")
108
- div.style.width = "100%";
109
- div.style.height = "100%";
110
- div.style.background = "#fff";
111
- div.style.color = "#000";
112
- div.style.position = "fixed";
113
- div.style.display = "flex";
114
- div.style.justifyContent = "center";
115
- div.style.alignItems = "center";
116
- div.style.fontSize = "40px";
117
- div.style.top = "0";
118
- div.style.bottom = "0";
119
- div.style.left = "0";
120
- div.style.right = "0";
121
- div.innerHTML = "Offer Expired";
122
- document.body.appendChild(div);
123
- }else{
124
- const target = event.target || event.srcElement;
125
-
126
- while (target) {
127
- if (target instanceof HTMLAnchorElement) {
128
- console.log(target.getAttribute('href'));
129
- window.location.href = target.getAttribute('href')
130
- break;
131
- }
132
-
133
- target = target.parentNode;
134
- }
135
- }
136
- });
137
- }
138
- }catch(err){
139
- console.error(err);
140
- }
141
- },false)
142
- `
143
- loadScriptInnerHtml(mcpSessionCheckWithBlock);
144
- }
145
- }catch(err){
146
- console.warn(err)
147
- }
148
- }
149
- const url = `https://${customDomain}/tallyman/v1/?action=redirect&country=${bupperizeCountry(country)}&slug=${slug}&device=${"smart"}&offerId=${offer}&rockman_id=${rockmanId}${extraParamsQs}&${search}`
150
- const result = await fetch(url).then(x => x.json())
151
-
152
- if(false === result.success){
153
- const identifyError = new Error(`Error in getRedirectUrl() identify-user action:\n${result.message}`) as IError;
154
- identifyError['type'] = "NotOn3g";
155
- throw identifyError
156
- }else{
157
- return {redirect_url:result.redirect_url}
158
- }
159
-
160
- }
161
- }
162
- }
163
-
164
-
165
- export const subscribe:(url:string, extraParams?:IHash)=>Promise<string> = async(url:string, extraParams?:IHash)=>{
166
- const evinaTid = (typeof window != "undefined" && window.tid) ? window.tid : "";
167
- const extraParamsQs = !extraParams ? '' : '&' + Object.keys(extraParams).map(k => `${k}=${extraParams[k]}`).join('&')
168
-
169
- const isCleanTraffic = (typeof window != "undefined" && window.shouldBlock === true) ? '&is-clean-traffic=false' : '&is-clean-traffic=true';
170
-
171
- const result:ISubscribeResult = await fetch(`${url}&sam_evina_tid=${evinaTid}${isCleanTraffic}${extraParamsQs}`).then((x)=>x.json())
172
-
173
- if(false === result.success){
174
- const subscribeError = new Error(`Error in subscribe() one-click-subscribe action:\n${result.message}`) as {productUrl:string} & IError;
175
- subscribeError['type'] = result.message == 'ALREADY SUBSCRIBED' ? "AlreadySubscribed" : "SubscriptionError";
176
- subscribeError['productUrl'] = result.product_url ? result.product_url : "";
177
- throw subscribeError
178
-
179
- }else{
180
- return result.product_url || result.redirect_url
181
- }
182
-
183
- }
184
-
185
-
186
- export const getRedirectUrlBupperWay = async(window:Window, maybeConfig: IConfig, extraParams?:ILinkExtraParams): Promise<string> => {
187
- if (typeof window == "undefined") {
188
- return "javascript: console.error('SSR'); void 6"
189
- } else {
190
- const { host, country, slug, queryString } = maybeConfig;
191
- const bupperizeCountry = (c:string) => c == 'gb' ? 'uk' : c;
192
- const offer = window.pac_analytics.visitor.offer
193
- const s = window.location.search.substr(1)
194
- const search = (!!s && s.length > 0 ? [s] : []).concat((queryString || []).map(([k, v]) => `${k}=${v}`)).join('&')
195
- const extraParamsQs = !extraParams ? '' : '&' + Object.keys(extraParams).map(k => `${k}=${extraParams[k]}`).join('&')
196
-
197
- // one click flow must use http not https
198
- const xcid = window.location.href.split("/")[3].split('?')[0];
199
- return `http://${host}/${bupperizeCountry(country)}/${slug}?offer=${offer}&atmobirun=1&rockman_id=${window.pac_analytics.visitor.rockmanId}&redirPixels=${window.location.host}&x-xcid=${xcid}${extraParamsQs}${search}`
200
- }
201
- }
202
-
203
-
204
- export const mockedRedirectUrlSuccessState : IOneClickFlowReducerState = {
205
- currentState:{
206
- type: "GET_REDIRECT_URL",
207
- //@ts-ignore
208
- result: RDS.Success<IGETREDIRECTURLFailure, IGETREDIRECTURLSuccess>({redirectUrl: '/mock-product-url'})
209
- }
210
- }
211
-
212
- export const mockedSubscribeAjaxState : IOneClickFlowReducerState = {
213
- currentState:{
214
- type: "SUBCRIBE_AJAX",
215
- //@ts-ignore
216
- result: RDS.NothingYet()
217
- }
218
- }
219
-
@@ -1,9 +0,0 @@
1
- type IPinConstants =
2
- "PIN_FLOW_MSISDN_SUBMIT"
3
- | "PIN_FLOW_MSISDN_SUBMIT_ERROR"
4
- | "PIN_SUBMIT"
5
- | "BACK_TO_START"
6
- | "PIN_SUBMIT_ERROR"
7
- | "MOCK_PIN_FLOW_STATE"
8
-
9
- export default IPinConstants