ouisys-engine 2.1.19 → 2.1.24

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 (65) hide show
  1. package/dist/api/click2sms.js +357 -0
  2. package/dist/api/index.d.ts +1 -3
  3. package/dist/api/index.js +93 -169
  4. package/dist/api/mo.js +274 -0
  5. package/dist/api/moRedir.js +186 -0
  6. package/dist/api/oneClick.js +366 -0
  7. package/dist/api/pin.js +493 -0
  8. package/dist/api/strategies.js +704 -0
  9. package/dist/api/ussd.js +1 -0
  10. package/dist/app/store.js +35 -0
  11. package/dist/common-types/AppThunk.d.ts +1 -2
  12. package/dist/features/strategies/categories/askMobileNumber.js +395 -0
  13. package/dist/features/strategies/categories/askOperator.js +311 -0
  14. package/dist/features/strategies/categories/detectOperatorByIp.js +606 -0
  15. package/dist/features/strategies/categories/headerEnrichment.js +670 -0
  16. package/dist/features/strategies/categories/typings/click2smsSliceTypes.js +12 -0
  17. package/dist/features/strategies/categories/typings/identifySliceTypes.js +22 -0
  18. package/dist/features/strategies/categories/typings/moFlowSliceTypes.js +22 -0
  19. package/dist/features/strategies/categories/typings/moRedirFlowSliceTypes.js +21 -0
  20. package/dist/features/strategies/categories/typings/oneClickSliceTypes.js +13 -0
  21. package/dist/features/strategies/categories/typings/pinFlowSliceTypes.js +13 -0
  22. package/dist/features/strategies/click2smsFlowSlice.js +172 -0
  23. package/dist/features/strategies/identifySlice.js +455 -0
  24. package/dist/features/strategies/moFlowSlice.js +196 -0
  25. package/dist/features/strategies/moRedirFlowSlice.js +190 -0
  26. package/dist/features/strategies/oneClickFlowSlice.js +277 -0
  27. package/dist/features/strategies/pinFlowSlice.js +313 -0
  28. package/dist/features/strategies/ussdFlowSlice.js +1 -0
  29. package/dist/flows/strategy.d.ts +1 -2
  30. package/dist/flows/strategy.js +1 -5
  31. package/dist/ips/tryGetIPRangeName.js +14 -13
  32. package/dist/mockServer/browser.js +48 -0
  33. package/dist/mockServer/handlers.js +22 -0
  34. package/dist/mockServer/server.js +48 -0
  35. package/dist/pacman/index.js +0 -1
  36. package/dist/reducers/click2smsFlow/utils.js +1 -3
  37. package/dist/reducers/oneClickFlow/utils.js +8 -7
  38. package/dist/reducers/pinFlow/utils.js +16 -15
  39. package/dist/reducers/strategy/strategies/header_enrichment.js +31 -25
  40. package/dist/reducers/strategy/utils.js +11 -12
  41. package/dist/reducers/tpayHeFlow/utils.js +1 -1
  42. package/dist/store/index.d.ts +1 -2
  43. package/dist/store/reducers.d.ts +0 -2
  44. package/dist/store/reducers.js +1 -4
  45. package/dist/test/setup.js +24 -0
  46. package/dist/test/test-utils.js +51 -0
  47. package/package.json +1 -1
  48. package/src/@types/window.d.ts +1 -0
  49. package/src/api/index.ts +4 -37
  50. package/src/common-types/AppThunk.ts +1 -2
  51. package/src/flows/strategy.ts +1 -5
  52. package/src/ips/tryGetIPRangeName.ts +3 -2
  53. package/src/pacman/index.ts +1 -1
  54. package/src/reducers/click2smsFlow/utils.ts +0 -3
  55. package/src/reducers/oneClickFlow/utils.ts +3 -2
  56. package/src/reducers/pinFlow/utils.ts +3 -1
  57. package/src/reducers/strategy/strategies/header_enrichment.ts +14 -11
  58. package/src/reducers/strategy/utils.ts +1 -2
  59. package/src/store/index.ts +1 -2
  60. package/src/store/reducers.ts +1 -5
  61. package/src/flows/tpayHeFlow.ts +0 -20
  62. package/src/reducers/tpayHeFlow/ITpayHeConstants.ts +0 -7
  63. package/src/reducers/tpayHeFlow/TpayHeTypes.ts +0 -135
  64. package/src/reducers/tpayHeFlow/index.ts +0 -207
  65. package/src/reducers/tpayHeFlow/utils.ts +0 -311
@@ -1,311 +0,0 @@
1
- import { IConfig, ILOADTPAYFailure, ILOADTPAYSuccess, IRedirectResult, ITpayHeFlowReducerState, ITpaySubscribeResult } from "./TpayHeTypes";
2
-
3
- import * as RDS from "../../common-types/RemoteDataState";
4
- import IError from "../../common-types/IError";
5
- import { ITpayConsentResult } from "./TpayHeTypes";
6
- import { searchToObject } from "../strategy/utils";
7
-
8
-
9
- export const additionalQueryString = `msisdnSubmitted=Y&legalCheckbox=Y&incentivizedCheckbox=Y&op_confirmCheckbox=N`
10
-
11
- export default class ScriptLoader {
12
- private src: string;
13
- private global: string;
14
- private protocol: string;
15
- private isLoaded: boolean;
16
-
17
-
18
- constructor (options:{src:string, global:string, protocol?:string}) {
19
- const { src, global, protocol = document.location.protocol } = options
20
- this.src = src
21
- this.global = global
22
- this.protocol = protocol
23
- this.isLoaded = false
24
- }
25
-
26
- loadScript () {
27
- return new Promise((resolve, reject) => {
28
- // Create script element and set attributes
29
- const script = document.createElement('script')
30
- script.type = 'text/javascript'
31
- script.async = true
32
- script.src = `${this.protocol}//${this.src}`
33
-
34
- // Append the script to the DOM
35
- const el = document.getElementsByTagName('script')[0]
36
- el.parentNode.insertBefore(script, el)
37
-
38
- // Resolve the promise once the script is loaded
39
- script.addEventListener('load', () => {
40
- this.isLoaded = true
41
- resolve(script)
42
- })
43
-
44
- // Catch any errors while loading the script
45
- script.addEventListener('error', () => {
46
- reject(new Error(`${this.src} failed to load.`))
47
- })
48
- })
49
- }
50
-
51
- load () {
52
- return new Promise(async (resolve, reject) => {
53
- if (!this.isLoaded) {
54
- try {
55
- await this.loadScript()
56
- //@ts-ignore
57
- resolve(window[this.global])
58
- } catch (e) {
59
- reject(e)
60
- }
61
- } else {
62
- //@ts-ignore
63
- resolve(window[this.global])
64
- }
65
- })
66
- }
67
- }
68
-
69
- export const getTpayConfig = async(window:Window, maybeConfig: IConfig): Promise<ITpayConsentResult> => {
70
- if (typeof window == "undefined") {
71
- throw "javascript: console.error('SSR'); void 6"
72
- } else {
73
- const { host, country, slug, queryString, device} = maybeConfig
74
- const offer = window.pac_analytics.visitor.offer
75
- const s = window.location.search.substr(1)
76
- const search = (!!s && s.length > 0 ? [s] : []).concat((queryString || []).map(([k, v]) => `${k}=${v}`)).join('&')
77
- const rockmanId = window.pac_analytics.visitor.rockmanId
78
- const result: ITpayConsentResult = await window.tallymanApi.tpayConsentConfig(host, country, slug, device, offer, rockmanId, search)
79
- if (false == result.success) {
80
- const error = new Error(`Error in getTpayConfig() tpay-consent-config action:\n${result.message}`) as IError & {type:string; productUrl:string;}
81
- error['type'] = result.message == 'ALREADY SUBSCRIBED' ? "AlreadySubscribed" : "NotSupported";
82
- console.error(error)
83
- throw error
84
- } else {
85
- return result;
86
- }
87
- }
88
- }
89
-
90
- // export const addLookUpTpay = async(tpayConfig:ITpayConsentResult, theme?:string, locale?:string):Promise<boolean>=>{
91
- // if(tpayConfig.success != false){
92
- // const { config } = tpayConfig;
93
- // const s = document.createElement("script");
94
- // const currentDate = moment().utc().format()
95
- // const digest = ()=>{
96
- // const d = currentDate + locale + theme;
97
- // const hash = HmacSHA256(d, config.private);
98
- // window.tPayhash = hash.toString();
99
- // const base64 = config.public + ":" + hash.toString();
100
- // return base64
101
- // }
102
-
103
- // try{
104
- // const loader = new ScriptLoader({
105
- // src: `lookup.tpay.me/idxml.ashx/js?date=${currentDate}&lang=${locale}&theme=${theme}&digest=${digest()}`,
106
- // global: 'TPay'
107
- // });
108
-
109
-
110
- // await loader.load();
111
- // const operatorCode = window.TPay.HeaderEnrichment.operatorCode();
112
- // console.log("operatorCode", operatorCode)
113
- // if(operatorCode != ""){
114
- // return true;
115
- // }else{
116
- // const error = new Error(`Error in addLookUpTpay() :\n MSISDN Not Detected!`) as IError & {type:string;}
117
- // error['type'] = "3GConnectionError";
118
- // console.error(error)
119
- // throw error
120
- // }
121
- // }catch(err){
122
- // const error = new Error(`Error in addLookUpTpay() :\n Failed To Load Script ${JSON.stringify(err)}`) as IError & {type:string;}
123
- // error['type'] = "InvalidConfig";
124
- // console.error(error)
125
- // throw error
126
- // }
127
- // }else{
128
- // return false;
129
- // }
130
- // }
131
-
132
-
133
-
134
- const subscribe:(url:string)=>Promise<string> = async(url:string)=>{
135
-
136
- const result:ITpaySubscribeResult = await fetch(url).then((x)=>x.json())
137
-
138
- if(false === result.success){
139
- const subscribeError = new Error(`Error in subscribe() one-click-subscribe action:\n${result.message}`) as IError;
140
- subscribeError['type'] = "SubscriptionError";
141
- throw subscribeError
142
- }else{
143
- return result.product_url
144
- }
145
- }
146
-
147
- export const confirmTPayCheck = async():Promise<string | null>=>{
148
- const search = searchToObject() as IRedirectResult;
149
- try{
150
- if(search){
151
- if(search["Status"] == "Error"){
152
- throw search["Details"]
153
- }
154
- if(search["Status"] == "Success"){
155
- const { Msisdn, SessionToken, ReferenceCode, Status, Details, subscription_url } = search;
156
- const url = `${decodeURIComponent(subscription_url)}&msisdn=${Msisdn}&tpaySessionToken=${SessionToken}&heReferenceCode=${ReferenceCode}&heStatus=${Status}&heErrorDetails=${Details}`;
157
- const product_url = await subscribe(url);
158
- return product_url.replace('<%LANG%>', search.language_code);
159
- }
160
- }
161
- return null;
162
- }catch(err){
163
- const error = new Error(`Error in confirmTPayCheck() :\n ${JSON.stringify(search)}`) as IError & {type:string;}
164
- error['type'] = "SubscriptionFailed";
165
- console.error(error)
166
- throw error
167
- }
168
-
169
- }
170
-
171
- export const confirmTPay = (window:Window, tpayConfig:ITpayConsentResult, locale:string, redirectUrl?:string)=>{
172
- //@ts-ignore
173
- if(typeof window.browser == "undefined"){
174
- //@ts-ignore
175
- window.browser = window.chrome
176
- }
177
- if(tpayConfig == null || tpayConfig.success != true){
178
- const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment`) as IError & {type:string;}
179
- error['type'] = "InvalidConfig";
180
- console.error(error)
181
- throw error
182
- }
183
-
184
- const { config , prodSku } = tpayConfig;
185
- const operatorCode = window.TPay.HeaderEnrichment.operatorCode();
186
- const sessionId = window.TPay.HeaderEnrichment.sessionId();
187
-
188
-
189
- const catName = config["catalog_name"][operatorCode];
190
-
191
- const subscriptionPlanId = config["subscription_plan_id"];
192
- const lang = locale;
193
- const rockmanId = window.pac_analytics.visitor.rockmanId
194
- let operatorFQN = 'EG_ORANGE';
195
- if (operatorCode == 60202) {
196
- operatorFQN = 'EG_VODAFONE';
197
- } else if (operatorCode == 60303) {
198
- operatorFQN = 'DZ_OOREDOO';
199
- }
200
-
201
- console.log("operatorFQN", operatorFQN);
202
-
203
- const availableRdrl = redirectUrl ? redirectUrl : window.location.origin + window.location.pathname;
204
-
205
- const rUrl = `${availableRdrl}?subscription_url=${encodeURIComponent(`${tpayConfig.subscription_url}operator=${operatorFQN}&language_code=${locale}`)}&rockman_id=${rockmanId}&language_code=${locale}&`
206
-
207
-
208
- console.log("Redirect url", rUrl)
209
-
210
- const hash = window.tPayhash;
211
-
212
- console.log("Operator Code: " + operatorCode);
213
- console.log("Session Id: " + sessionId);
214
- console.log("Product Catalog: " + catName);
215
- console.log("Subscription Plan :" + subscriptionPlanId);
216
-
217
- window.TPay.HeaderEnrichment.hasSubscription(prodSku, function(hasSub, subId){
218
- if (hasSub) {
219
- console.log("hasSubscription")
220
- // User has already a subscription, go to returnSubscription
221
- console.log('User is already subscribed');
222
- let productUrl = config['product_url'];
223
-
224
- if (config["replace_uid"] != undefined && config['replace_uid'] == true) {
225
- console.log('sub id ' + subId);
226
- productUrl = config['product_full_access'];
227
- fetch(`http://de-mcb-api.sam-media.com/api/v2/validate-access/?domain=${config.domain}&sub_id=${subId}&country=${tpayConfig.country}&gateway=tpay`).then((response:any)=>{
228
- if (response.payload.token) {
229
- productUrl = config['product_url'].replace('<%UID%>', response.payload.token);
230
- }
231
- }).catch((err)=>{
232
- console.warn('validate-access' + err );
233
- });
234
- }
235
-
236
- console.log("productUrl", productUrl)
237
-
238
-
239
- setTimeout(() => {
240
- window.location.href = productUrl;
241
- }, 1000);
242
-
243
- console.log("productUrl", productUrl)
244
- const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment.hasSubscription action:\n${'ALREADY SUBSCRIBED'}`) as IError & {type:string; productUrl:string;}
245
- error['type'] = "AlreadySubscribed";
246
- error['productUrl'] = productUrl;
247
- console.error(error)
248
- throw error
249
- } else {
250
- console.log("NOT ACTIVE")
251
- if(config.flow != "consent"){
252
- try{
253
- //@ts-ignore
254
- window.TPay.HeaderEnrichment.confirm(
255
- subscriptionPlanId,
256
- catName,
257
- prodSku,
258
- sessionId,
259
- rUrl,
260
- rockmanId,
261
- lang,
262
- hash
263
- )
264
- }catch(err){
265
- const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment.confirm action:\n${JSON.stringify(err)}`) as IError & {type:string;}
266
- error['type'] = "ConfirmError";
267
- console.error(error)
268
- }
269
- }else{
270
-
271
- // user is not active subscriber, proceed with subscription(redirect to tpay pin page)
272
- try{
273
- window.TPay.HeaderEnrichment.consent(
274
- subscriptionPlanId,
275
- catName,
276
- prodSku,
277
- sessionId,
278
- rUrl,
279
- rockmanId,
280
- lang,
281
- hash
282
- )
283
-
284
- }catch(err){
285
- const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment.consent action:\n${JSON.stringify(err)}`) as IError & {type:string;}
286
- error['type'] = "ConfirmError";
287
- console.error(error)
288
- }
289
- }
290
- }
291
- });
292
- }
293
-
294
- // export const mockedSuccessState : IOneClickCurrentState = {
295
- // type: "LOAD_TPAY_HE",
296
- // result: RDS.Success<ILOADTPAYFailure, ILOADTPAYSuccess>({
297
- // redirectUrl: 'https://www.yahoo.com/',
298
- // nextAction:"getRedirectUrlAction"
299
- // })
300
- // }
301
-
302
- export const mockedConfirmState : ITpayHeFlowReducerState = {
303
- currentState:{
304
- type: "LOAD_TPAY_HE",
305
- //@ts-ignore
306
- result: RDS.Success<ILOADTPAYFailure, ILOADTPAYSuccess>({}),
307
- //@ts-ignore
308
- tpayConfig:{}
309
-
310
- }
311
- }