ouisys-engine 5.1.82 → 5.1.84

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.
package/dist/pinFlow.js CHANGED
@@ -538,19 +538,35 @@ var defaultInitialState = {
538
538
  * @return {PinFlowState} The initial state of the pin flow.
539
539
  */
540
540
  var setInitialState = function (window) {
541
- var _a;
541
+ var _a, _b;
542
542
  var search = searchToObject(window);
543
543
  var pinPageEvent = new Event('onPinPage');
544
544
  var isPinEntryStep = (search.ui_show_pin_entry && search.ui_show_pin_entry === '1') ||
545
545
  (search['show-pin-entry'] && search['show-pin-entry'] === '1');
546
546
  var isShowThankYouStep = search['show-thank-you'] && search['show-thank-you'] === '1';
547
547
  var isShowCustomError = (search === null || search === void 0 ? void 0 : search.show_custom_error) === '1';
548
+ // Set by the CA branch of submitPinAction on a blocking error code. Lives in the url so the block
549
+ // survives a refresh instead of handing the form back.
550
+ var isBlocked = (search === null || search === void 0 ? void 0 : search.ui_blocked) === '1';
548
551
  var rawParam = (_a = search === null || search === void 0 ? void 0 : search.ui_error_message) !== null && _a !== void 0 ? _a : '';
549
552
  var normalizedParam = rawParam.replace(/\+/g, '%20');
550
553
  var errorMsg = decodeURIComponent(normalizedParam);
551
554
  var mapParamError = {
552
555
  'This mobile number is blacklisted': 'BlacklistedNumber'
553
556
  };
557
+ /**
558
+ * Error type carried over by a reload (see the CA branch of submitPinAction). Passed through as-is
559
+ * so any error code normaliseErrorCode() knows about survives the round trip, only smoothing over
560
+ * the two spellings the same error can arrive with (error_code 21/22 give InvalidPin/ExpiredPin,
561
+ * the message fallback in main.ts gives InvalidPIN/ExpiredPIN).
562
+ * Defaults to InvalidPIN for reloads that predate the param.
563
+ */
564
+ var rawErrorType = (_b = search === null || search === void 0 ? void 0 : search.ui_error_type) !== null && _b !== void 0 ? _b : '';
565
+ var mapPinParamErrorType = {
566
+ invalidpin: 'InvalidPIN',
567
+ expiredpin: 'ExpiredPIN'
568
+ };
569
+ var pinErrorType = mapPinParamErrorType[rawErrorType.toLowerCase()] || (rawErrorType || 'InvalidPIN');
554
570
  var msisdnError = {
555
571
  currentState: {
556
572
  type: 'MSISDNEntry',
@@ -584,6 +600,25 @@ var setInitialState = function (window) {
584
600
  }
585
601
  }
586
602
  };
603
+ var blockedState = {
604
+ currentState: {
605
+ type: 'PINEntry',
606
+ result: Failure({
607
+ errorType: pinErrorType,
608
+ error: new Error(errorMsg)
609
+ }),
610
+ // @ts-ignore
611
+ data: {
612
+ isBlocked: true,
613
+ msisdn: (search === null || search === void 0 ? void 0 : search.msisdn) || '',
614
+ operator: (search === null || search === void 0 ? void 0 : search.operator) || ''
615
+ }
616
+ }
617
+ };
618
+ // Ahead of the step checks: a blocked visitor gets the error page whatever else the url asks for.
619
+ if (isBlocked) {
620
+ return blockedState;
621
+ }
587
622
  if (isPinEntryStep) {
588
623
  // Needed for shemroo the handler is injected on server
589
624
  window === null || window === void 0 ? void 0 : window.dispatchEvent(pinPageEvent);
@@ -592,7 +627,7 @@ var setInitialState = function (window) {
592
627
  currentState: {
593
628
  type: 'PINEntry',
594
629
  result: Failure({
595
- errorType: 'InvalidPIN',
630
+ errorType: pinErrorType,
596
631
  error: new Error(errorMsg)
597
632
  }),
598
633
  data: {
@@ -636,7 +671,7 @@ var submitMSISDNAction = createAsyncThunk('pinFlow/submitMSISDNAction', function
636
671
  var window = _a.window, msisdn = _a.msisdn, extraParams = _a.extraParams;
637
672
  var getState = _b.getState, dispatch = _b.dispatch, rejectWithValue = _b.rejectWithValue;
638
673
  return __awaiter(void 0, void 0, void 0, function () {
639
- var state, _c, config, isHeaderEnrichmentSuccess, pinFlowCurrentState, searchObj, prefix, jsLinkResult, errorMsg_1, errorMsg, msisdnSubmissionResult, isComp, _d, operator, pinMaxLengthByOp, u, u, pinPageEvent, ex_1, errorType, pinPageEvent;
674
+ var state, _c, config, isHeaderEnrichmentSuccess, pinFlowCurrentState, searchObj, prefix, jsLinkResult, errorMsg_1, errorMsg, msisdnSubmissionResult, isComp, _d, operator, u, u, pinPageEvent, ex_1, errorType, pinPageEvent;
640
675
  var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
641
676
  return __generator(this, function (_z) {
642
677
  switch (_z.label) {
@@ -753,11 +788,6 @@ var submitMSISDNAction = createAsyncThunk('pinFlow/submitMSISDNAction', function
753
788
  _z.label = 9;
754
789
  case 9:
755
790
  operator = (msisdnSubmissionResult === null || msisdnSubmissionResult === void 0 ? void 0 : msisdnSubmissionResult.type) === 'SingleMSISDNSubmissionResult' ? msisdnSubmissionResult === null || msisdnSubmissionResult === void 0 ? void 0 : msisdnSubmissionResult.operator : '';
756
- pinMaxLengthByOp = {
757
- SA_MOBILY: 6,
758
- SA_STC: 4,
759
- SA_ZAIN: 4
760
- };
761
791
  if (((_m = config === null || config === void 0 ? void 0 : config.country) === null || _m === void 0 ? void 0 : _m.toLowerCase()) === 'om' && window.operator === 'OM_OOREDOO') {
762
792
  try {
763
793
  window.msisdn = msisdn;
@@ -807,7 +837,7 @@ var submitMSISDNAction = createAsyncThunk('pinFlow/submitMSISDNAction', function
807
837
  }
808
838
  pinPageEvent = new Event('onPinPage');
809
839
  window === null || window === void 0 ? void 0 : window.dispatchEvent(pinPageEvent);
810
- return [2 /*return*/, __assign(__assign({}, pinFlowCurrentState), { type: 'PINEntry', result: NothingYet(), data: __assign({ isComp: isComp, actualPIN: msisdnSubmissionResult.type === 'SingleMSISDNSubmissionResult' ? msisdnSubmissionResult.pin : null, msisdn: msisdn, operator: operator, pinMaxLength: operator !== '' && pinMaxLengthByOp[operator] ? pinMaxLengthByOp[operator] : null, isHeaderEnrichmentSuccess: isHeaderEnrichmentSuccess }, (msisdnSubmissionResult.type === 'SingleMSISDNSubmissionResult' && (msisdnSubmissionResult === null || msisdnSubmissionResult === void 0 ? void 0 : msisdnSubmissionResult.userType)
840
+ return [2 /*return*/, __assign(__assign({}, pinFlowCurrentState), { type: 'PINEntry', result: NothingYet(), data: __assign({ isComp: isComp, actualPIN: msisdnSubmissionResult.type === 'SingleMSISDNSubmissionResult' ? msisdnSubmissionResult.pin : null, msisdn: msisdn, operator: operator, pinMaxLength: null, isHeaderEnrichmentSuccess: isHeaderEnrichmentSuccess }, (msisdnSubmissionResult.type === 'SingleMSISDNSubmissionResult' && (msisdnSubmissionResult === null || msisdnSubmissionResult === void 0 ? void 0 : msisdnSubmissionResult.userType)
811
841
  ? { userType: msisdnSubmissionResult.userType }
812
842
  : {})) })];
813
843
  case 10:
@@ -851,14 +881,38 @@ var submitMSISDNAction = createAsyncThunk('pinFlow/submitMSISDNAction', function
851
881
  });
852
882
  });
853
883
  });
884
+ /**
885
+ * CA only. Backend error codes the operator spec wants a fresh Empello token for: the user stays on
886
+ * PIN entry and retries, so the page is reloaded to re-issue the token. Every other code either
887
+ * blocks the flow or redirects, and keeps the normal error handling.
888
+ * 21 ExpiredPin, 22 InvalidPin, 23 PinLimitExceeded, 32 InvalidMSISDN, 33 InvalidSubscriptionId,
889
+ * 35 ValidationIssue.
890
+ */
891
+ var caTokenRefreshErrorCodes = ['21', '22', '23', '32', '33', '35'];
892
+ /**
893
+ * CA only. Backend error codes the operator spec wants the subscription flow blocked for: request pin
894
+ * and submit both stay disabled. The page is reloaded with ui_blocked so the block lives in the url and
895
+ * survives a refresh, and setInitialState hands the theme a state to render as a full page error.
896
+ * 11 BlacklistedMsisdn, 30 UnsportedFlow, 31 InactiveOperator, 34 NotEligibleMsisdn,
897
+ * 36 InsufficientBalance, 37 AntiFraudError, 38 VasBlocked, 39 AccountSuspended, 40 SalesCapReached,
898
+ * 50 SubscriptionApiFailure, 75 ReSubscriptionBlocked, 76 ReLeadBlocked, 99 UnspecifiedError.
899
+ */
900
+ var caBlockedErrorCodes = ['11', '30', '31', '34', '36', '37', '38', '39', '40', '50', '75', '76', '99'];
901
+ /**
902
+ * Matched case-insensitively: the same error arrives as InvalidPin/ExpiredPin when the api returns an
903
+ * error_code and as InvalidPIN/ExpiredPIN when it falls back to the message match in main.ts.
904
+ */
905
+ var matchesErrorCode = function (codes, errorType) {
906
+ return !!errorType && codes.some(function (code) { return normaliseErrorCode(code).toLowerCase() === errorType.toLowerCase(); });
907
+ };
854
908
  var submitPinAction = createAsyncThunk('pinFlow/submitPinAction', function (_a, _b) {
855
909
  var window = _a.window, msisdn = _a.msisdn, pin = _a.pin, extraParams = _a.extraParams;
856
910
  var getState = _b.getState, rejectWithValue = _b.rejectWithValue;
857
911
  return __awaiter(void 0, void 0, void 0, function () {
858
- var state, config, pinFlowCurrentState, result, ex_2, errorType, isCaWrongPin, u;
859
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
860
- return __generator(this, function (_w) {
861
- switch (_w.label) {
912
+ var state, config, pinFlowCurrentState, result, ex_2, errorType, isCa, u, isCaTokenRefreshError, u;
913
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
914
+ return __generator(this, function (_x) {
915
+ switch (_x.label) {
862
916
  case 0:
863
917
  state = getState();
864
918
  if (!((_e = (_d = (_c = state === null || state === void 0 ? void 0 : state.strategy) === null || _c === void 0 ? void 0 : _c.currentState) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.config)) {
@@ -878,13 +932,13 @@ var submitPinAction = createAsyncThunk('pinFlow/submitPinAction', function (_a,
878
932
  }
879
933
  config = state.strategy.currentState.data.config;
880
934
  pinFlowCurrentState = (_r = state.pinFlow) === null || _r === void 0 ? void 0 : _r.currentState;
881
- _w.label = 1;
935
+ _x.label = 1;
882
936
  case 1:
883
- _w.trys.push([1, 5, , 6]);
937
+ _x.trys.push([1, 5, , 6]);
884
938
  tracker.advancedInFlow('tallyman.v1-pin', 'pin-submitted', { msisdn: msisdn, pin: pin });
885
939
  return [4 /*yield*/, submitPIN(window, pin, config, extraParams)];
886
940
  case 2:
887
- result = _w.sent();
941
+ result = _x.sent();
888
942
  tracker.advancedInFlow('tallyman.v1-pin', 'pin-submission-success', {
889
943
  msisdn: msisdn,
890
944
  pin: pin,
@@ -919,8 +973,8 @@ var submitPinAction = createAsyncThunk('pinFlow/submitPinAction', function (_a,
919
973
  tracker.customEvent('Flow', 'advance-auto', 'msisdn-stored-error', error);
920
974
  })];
921
975
  case 3:
922
- _w.sent();
923
- _w.label = 4;
976
+ _x.sent();
977
+ _x.label = 4;
924
978
  case 4:
925
979
  // End store msisdn
926
980
  return [2 /*return*/, __assign(__assign({}, pinFlowCurrentState), { type: 'PINEntry', result: Success({
@@ -928,7 +982,7 @@ var submitPinAction = createAsyncThunk('pinFlow/submitPinAction', function (_a,
928
982
  isAlreadySubscribed: result.isAlreadySubscribed || false
929
983
  }) })];
930
984
  case 5:
931
- ex_2 = _w.sent();
985
+ ex_2 = _x.sent();
932
986
  console.warn(ex_2);
933
987
  errorType = ex_2.type;
934
988
  tracker.recedeInFlow('tallyman.v1-pin', 'pin-submission-failure', {
@@ -939,15 +993,41 @@ var submitPinAction = createAsyncThunk('pinFlow/submitPinAction', function (_a,
939
993
  message: ex_2.message,
940
994
  productUrl: ex_2.productUrl
941
995
  });
942
- isCaWrongPin = ((_s = config === null || config === void 0 ? void 0 : config.country) === null || _s === void 0 ? void 0 : _s.toLowerCase()) === 'ca' &&
943
- ((errorType === null || errorType === void 0 ? void 0 : errorType.toLowerCase()) === 'invalidpin' || ((_t = ex_2.message) === null || _t === void 0 ? void 0 : _t.includes('pin does not match')));
944
- if (isCaWrongPin) {
996
+ isCa = ((_s = config === null || config === void 0 ? void 0 : config.country) === null || _s === void 0 ? void 0 : _s.toLowerCase()) === 'ca';
997
+ // CA: block the subscription flow. Reload with ui_blocked so the block is part of the url and a
998
+ // refresh cannot hand the form back. No product url check here, blocking wins over any url returned.
999
+ if (isCa && matchesErrorCode(caBlockedErrorCodes, errorType)) {
1000
+ try {
1001
+ u = new URL(window.location.href);
1002
+ u.searchParams.set('rockman_id', ((_u = (_t = window === null || window === void 0 ? void 0 : window.pac_analytics) === null || _t === void 0 ? void 0 : _t.visitor) === null || _u === void 0 ? void 0 : _u.rockmanId) || '');
1003
+ u.searchParams.set('show_custom_error', '1');
1004
+ u.searchParams.set('ui_blocked', '1');
1005
+ u.searchParams.set('ui_error_message', ex_2.message || errorType || 'UnknownError');
1006
+ u.searchParams.set('ui_error_type', errorType || 'UnknownError');
1007
+ window.history.replaceState({}, '', u.toString());
1008
+ setTimeout(function () {
1009
+ window.location.reload();
1010
+ }, 0);
1011
+ return [2 /*return*/, rejectWithValue({
1012
+ errorType: errorType,
1013
+ error: ex_2.toString(),
1014
+ message: ex_2.message,
1015
+ productUrl: ex_2.productUrl
1016
+ })];
1017
+ }
1018
+ catch (e) {
1019
+ console.error('CA blocked error reload failed', e);
1020
+ }
1021
+ }
1022
+ isCaTokenRefreshError = isCa && !ex_2.productUrl && matchesErrorCode(caTokenRefreshErrorCodes, errorType);
1023
+ if (isCaTokenRefreshError) {
945
1024
  try {
946
1025
  u = new URL(window.location.href);
947
1026
  u.searchParams.set('show-pin-entry', '1');
948
- u.searchParams.set('rockman_id', ((_v = (_u = window === null || window === void 0 ? void 0 : window.pac_analytics) === null || _u === void 0 ? void 0 : _u.visitor) === null || _v === void 0 ? void 0 : _v.rockmanId) || '');
1027
+ u.searchParams.set('rockman_id', ((_w = (_v = window === null || window === void 0 ? void 0 : window.pac_analytics) === null || _v === void 0 ? void 0 : _v.visitor) === null || _w === void 0 ? void 0 : _w.rockmanId) || '');
949
1028
  u.searchParams.set('show_custom_error', '1');
950
- u.searchParams.set('ui_error_message', ex_2.message || 'InvalidPin');
1029
+ u.searchParams.set('ui_error_message', ex_2.message || errorType || 'UnknownError');
1030
+ u.searchParams.set('ui_error_type', errorType || 'UnknownError');
951
1031
  window.history.replaceState({}, '', u.toString());
952
1032
  setTimeout(function () {
953
1033
  window.location.reload();