@tap-payments/auth-jsconnect 2.4.57-test → 2.4.59-test

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.
@@ -593,4 +593,11 @@ export interface CountryTrackingData extends CommonDataLayer {
593
593
  export interface LeadIdentificationData extends CommonDataLayer {
594
594
  lead_ID?: string;
595
595
  }
596
+ export type VerifyExpressTokenParams = {
597
+ public_key: string;
598
+ post: {
599
+ url: string;
600
+ };
601
+ lead_id: string;
602
+ };
596
603
  export {};
@@ -1,10 +1,12 @@
1
1
  import { RootState } from './store';
2
- import { ActionState, LanguageMode, SharedState, ThemeMode, ScreenStepNavigation, DeviceInfo, LibConfig, CountryCode, MerchantInfo } from '../@types';
2
+ import { ActionState, LanguageMode, SharedState, ThemeMode, ScreenStepNavigation, DeviceInfo, LibConfig, CountryCode, MerchantInfo, VerifyExpressTokenParams } from '../@types';
3
3
  interface SettingParams {
4
4
  disableCountries?: boolean;
5
5
  disableLocale?: boolean;
6
6
  mdn: string;
7
7
  maturity?: 'full' | 'express';
8
+ expressToken?: string;
9
+ onExpressVerifyTokenSuccess?: (data: VerifyExpressTokenParams) => Promise<void>;
8
10
  }
9
11
  export declare const fetchAppSettingsSync: import("@reduxjs/toolkit").AsyncThunk<any, SettingParams, {
10
12
  state?: unknown;
@@ -53,22 +53,43 @@ import i18n from '../i18n';
53
53
  import { updateLocale } from '../utils/locale';
54
54
  import API, { setAxiosGlobalHeaders } from '../api';
55
55
  export var fetchAppSettingsSync = createAsyncThunk('fetchAppSettingsSync', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
56
- var settings, _a, appConfig, language, _b, client, device, os, disableLocale, maturity, disableCountries, _c, visitorId, locale, initPayload, _d, country_list, ip_info, merchant, operator, list, _e, ip, latitude, longitude, deviceInfo, isValidOperator, countries, countryCode, isKWOrSA, businessCountry;
56
+ var settings, _a, appConfig, language, _b, client, device, os, disableLocale, maturity, disableCountries, expressToken, onExpressVerifyTokenSuccess, _c, visitorId, locale, publicKey, payload, data, public_key, initPayload, _d, country_list, ip_info, merchant, operator, list, _e, ip, latitude, longitude, deviceInfo, isValidOperator, countries, countryCode, isKWOrSA, businessCountry;
57
57
  return __generator(this, function (_f) {
58
58
  switch (_f.label) {
59
59
  case 0:
60
60
  settings = thunkApi.getState().settings;
61
61
  _a = settings.data, appConfig = _a.appConfig, language = _a.language;
62
62
  _b = getBrowserInfo(), client = _b.client, device = _b.device, os = _b.os;
63
- disableLocale = params.disableLocale, maturity = params.maturity, disableCountries = params.disableCountries;
63
+ disableLocale = params.disableLocale, maturity = params.maturity, disableCountries = params.disableCountries, expressToken = params.expressToken, onExpressVerifyTokenSuccess = params.onExpressVerifyTokenSuccess;
64
64
  return [4, Promise.all([getFingerPrint(), API.firebaseService.getLocale(disableLocale)])];
65
65
  case 1:
66
66
  _c = _f.sent(), visitorId = _c[0].visitorId, locale = _c[1];
67
+ publicKey = appConfig.publicKey;
67
68
  setAxiosGlobalHeaders({
68
69
  bi: visitorId || '',
69
70
  mdn: encryptString(params.mdn || window.location.origin),
70
- authorization: encryptString(appConfig.publicKey)
71
+ authorization: encryptString(publicKey)
71
72
  });
73
+ if (!expressToken) return [3, 3];
74
+ payload = {
75
+ token: expressToken
76
+ };
77
+ return [4, API.leadService.verifyExpressLeadToken(payload)];
78
+ case 2:
79
+ data = _f.sent();
80
+ onExpressVerifyTokenSuccess === null || onExpressVerifyTokenSuccess === void 0 ? void 0 : onExpressVerifyTokenSuccess(data);
81
+ public_key = (data || {}).public_key;
82
+ if (public_key) {
83
+ publicKey = public_key;
84
+ setAxiosGlobalHeaders({
85
+ bi: visitorId || '',
86
+ mdn: encryptString(params.mdn || window.location.origin),
87
+ authorization: encryptString(publicKey)
88
+ });
89
+ thunkApi.dispatch(handlePublicKey(publicKey));
90
+ }
91
+ _f.label = 3;
92
+ case 3:
72
93
  initPayload = {
73
94
  type: 'website',
74
95
  app_client_version: 'js-auth-connect',
@@ -80,7 +101,7 @@ export var fetchAppSettingsSync = createAsyncThunk('fetchAppSettingsSync', funct
80
101
  }
81
102
  };
82
103
  return [4, API.initService.getInitialData(initPayload)];
83
- case 2:
104
+ case 4:
84
105
  _d = _f.sent(), country_list = _d.country_list, ip_info = _d.ip_info, merchant = _d.merchant, operator = _d.operator;
85
106
  list = (country_list || { list: [] }).list;
86
107
  _e = ip_info || {}, ip = _e.ip, latitude = _e.latitude, longitude = _e.longitude;
@@ -115,13 +136,15 @@ export var fetchAppSettingsSync = createAsyncThunk('fetchAppSettingsSync', funct
115
136
  },
116
137
  source: 'browser'
117
138
  };
118
- setAxiosGlobalHeaders(__assign(__assign(__assign({}, getRequestHeaders(deviceInfo)), { authorization: encryptString(appConfig.publicKey), mdn: encryptString(params.mdn || window.location.origin), cu: window.location.href }), (maturity && { maturity: maturity })));
139
+ setAxiosGlobalHeaders(__assign(__assign(__assign({}, getRequestHeaders(deviceInfo)), { authorization: encryptString(publicKey), mdn: encryptString(params.mdn || window.location.origin), cu: window.location.href }), (maturity && { maturity: maturity })));
119
140
  isValidOperator = operator === 'valid';
120
141
  countries = sortCountries(list);
121
142
  countryCode = appConfig.businessCountryCode;
143
+ if (maturity === 'express' && (merchant === null || merchant === void 0 ? void 0 : merchant.country_code))
144
+ countryCode = merchant === null || merchant === void 0 ? void 0 : merchant.country_code;
122
145
  isKWOrSA = isKW(countryCode) || isSA(countryCode);
123
146
  if (!isKWOrSA)
124
- countryCode = 'SA';
147
+ countryCode = 'KW';
125
148
  businessCountry = findCountryByIso2(countries, countryCode);
126
149
  if (!businessCountry)
127
150
  throw new Error('Business country not found, you have to pass a valid business country code in the lib config');
@@ -1,22 +1,6 @@
1
1
  import { RootState } from '../../../app/store';
2
2
  import { MobileFormValues, NIDFormValues, CivilFormValues, OTPFormValues, IndividualFormValues, SharedState, FlowsTypes, ActionState, CountryCode, AuthForType, BusinessDataFormValues, AsyncThunkParams } from '../../../@types';
3
3
  import { CancelToken } from 'axios';
4
- interface VerifyLeadTokenProps {
5
- token: string;
6
- }
7
- export declare const verifyLeadToken: import("@reduxjs/toolkit").AsyncThunk<{
8
- data: any;
9
- token: string;
10
- }, VerifyLeadTokenProps, {
11
- state?: unknown;
12
- dispatch?: import("redux").Dispatch<import("redux").AnyAction> | undefined;
13
- extra?: unknown;
14
- rejectValue?: unknown;
15
- serializedErrorType?: unknown;
16
- pendingMeta?: unknown;
17
- fulfilledMeta?: unknown;
18
- rejectedMeta?: unknown;
19
- }>;
20
4
  export declare const retrieveLeadIdentityByIdAsync: import("@reduxjs/toolkit").AsyncThunk<{
21
5
  data: any;
22
6
  countryCode: CountryCode;
@@ -56,45 +56,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
56
  };
57
57
  var _a;
58
58
  import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
59
- import { handleNextScreenStep, handleCurrentActiveScreen, handleOpen, handlePublicKey } from '../../../app/settings';
59
+ import { handleNextScreenStep, handleCurrentActiveScreen, handleOpen } from '../../../app/settings';
60
60
  import { FlowsTypes, AuthForType, BusinessType, LicenseType } from '../../../@types';
61
61
  import API from '../../../api';
62
62
  import { CONNECT_EXPRESS_STEP_NAMES, IDENTIFICATION_TYPE, OTHER_CR_LICENSE, OTHER_FL_LICENSE } from '../../../constants';
63
63
  import { defaultCountry } from '../../../constants';
64
64
  import { getIndividualName, capitalizeTheFirstLetterOfEachWord, sleep, findCountryByIddPrefix, concatenateObjectValues, isSA } from '../../../utils';
65
- export var verifyLeadToken = createAsyncThunk('expressVerifyLeadToken', function (_a, thunkApi) {
66
- var token = _a.token;
67
- return __awaiter(void 0, void 0, void 0, function () {
68
- var payload, data, _b, lead_id, post, public_key;
69
- return __generator(this, function (_c) {
70
- switch (_c.label) {
71
- case 0:
72
- payload = {
73
- token: token
74
- };
75
- return [4, API.leadService.verifyExpressLeadToken(payload)];
76
- case 1:
77
- data = _c.sent();
78
- _b = data || {}, lead_id = _b.lead_id, post = _b.post, public_key = _b.public_key;
79
- if (public_key)
80
- thunkApi.dispatch(handlePublicKey(public_key));
81
- if (post === null || post === void 0 ? void 0 : post.url)
82
- thunkApi.dispatch(setPostUrl(post.url));
83
- if (!lead_id) return [3, 3];
84
- thunkApi.dispatch(setIsLeadIdPassed(true));
85
- thunkApi.dispatch(setLeadId(lead_id));
86
- return [4, thunkApi.dispatch(retrieveLeadIdentityByIdAsync(lead_id))];
87
- case 2:
88
- _c.sent();
89
- _c.label = 3;
90
- case 3: return [2, {
91
- data: data,
92
- token: token
93
- }];
94
- }
95
- });
96
- });
97
- });
98
65
  export var retrieveLeadIdentityByIdAsync = createAsyncThunk('expressConnect/retrieveLeadIdentityByIdAsync', function (leadId, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
99
66
  var _a, settings, connectExpress, countryCode, showBoard, data, phone, status, board_id, board_info_id, isRegistered, _b, boardInfo, boardData, error_1;
100
67
  var _c, _d;
@@ -839,17 +806,6 @@ export var connectSlice = createSlice({
839
806
  },
840
807
  extraReducers: function (builder) {
841
808
  builder
842
- .addCase(verifyLeadToken.pending, function (state) {
843
- state.customLoading = true;
844
- state.error = null;
845
- })
846
- .addCase(verifyLeadToken.fulfilled, function (state, action) {
847
- state.customLoading = false;
848
- })
849
- .addCase(verifyLeadToken.rejected, function (state, action) {
850
- state.customLoading = false;
851
- state.error = action.error.message;
852
- })
853
809
  .addCase(retrieveLeadIdentityByIdAsync.pending, function (state) {
854
810
  state.error = null;
855
811
  state.customLoading = true;
@@ -9,6 +9,42 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
12
48
  var __rest = (this && this.__rest) || function (s, e) {
13
49
  var t = {};
14
50
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -28,7 +64,7 @@ import { useAppTheme, useAppSelector, useAppConfig, useErrorListener, useStepSta
28
64
  import { handleCurrentActiveScreen, handleLanguage, settingsSelector } from '../../app/settings';
29
65
  import AnimationFlow from '../../components/AnimationFlow';
30
66
  import { store } from '../../app/store';
31
- import { connectExpressSelector, setIsLeadIdPassed, setPostUrl, setLeadId, retrieveLeadIdentityByIdAsync, setShowBoard, verifyLeadToken } from '../app/connectExpress/connectExpressStore';
67
+ import { connectExpressSelector, setIsLeadIdPassed, setPostUrl, setLeadId, retrieveLeadIdentityByIdAsync, setShowBoard } from '../app/connectExpress/connectExpressStore';
32
68
  import { ReduxProvider, ThemeProvider } from '../../components/Providers';
33
69
  import Collapse from '../../components/Collapse';
34
70
  import { isKW, findOrCreateElementAndInject, getParameterByName } from '../../utils';
@@ -40,8 +76,23 @@ var ConnectExpress = memo(function (_a) {
40
76
  var theme = useAppTheme().theme;
41
77
  var dispatch = useAppDispatch();
42
78
  var _b = useAppSelector(settingsSelector), data = _b.data, error = _b.error, settingLoading = _b.loading;
43
- var _c = useAppSelector(connectExpressSelector), connectExpressError = _c.error, loading = _c.loading, customLoading = _c.customLoading;
44
- useAppConfig(__assign({ navigation: CONNECT_EXPRESS_SCREENS_NAVIGATION, maturity: 'express' }, props));
79
+ var _c = useAppSelector(connectExpressSelector), connectExpressError = _c.error, loading = _c.loading, customLoading = _c.customLoading, connectData = _c.data;
80
+ var onExpressVerifyTokenSuccess = verifyToken
81
+ ? function (data) { return __awaiter(void 0, void 0, void 0, function () {
82
+ var _a, post, lead_id;
83
+ return __generator(this, function (_b) {
84
+ _a = data || {}, post = _a.post, lead_id = _a.lead_id;
85
+ if (post === null || post === void 0 ? void 0 : post.url)
86
+ dispatch(setPostUrl(post.url));
87
+ if (lead_id) {
88
+ dispatch(setIsLeadIdPassed(true));
89
+ dispatch(setLeadId(lead_id));
90
+ }
91
+ return [2];
92
+ });
93
+ }); }
94
+ : undefined;
95
+ useAppConfig(__assign(__assign({ navigation: CONNECT_EXPRESS_SCREENS_NAVIGATION, maturity: 'express' }, props), { expressToken: verifyToken, onExpressVerifyTokenSuccess: onExpressVerifyTokenSuccess }));
45
96
  useErrorListener(connectExpressError || error);
46
97
  useStepStartedListener();
47
98
  var activeScreen = data.activeScreen, isTapOrigin = data.isTapOrigin, open = data.open, merchant = data.merchant;
@@ -60,7 +111,8 @@ var ConnectExpress = memo(function (_a) {
60
111
  var lang = getParameterByName('lang');
61
112
  if (lang)
62
113
  dispatch(handleLanguage(lang));
63
- dispatch(verifyLeadToken({ token: verifyToken }));
114
+ if (connectData.leadId)
115
+ dispatch(retrieveLeadIdentityByIdAsync(connectData.leadId));
64
116
  return;
65
117
  }
66
118
  if (leadId) {
@@ -1,10 +1,12 @@
1
- import { LibConfig, ScreenStepNavigation } from '../@types';
1
+ import { LibConfig, ScreenStepNavigation, VerifyExpressTokenParams } from '../@types';
2
2
  interface AppConfigProps extends LibConfig {
3
3
  navigation: ScreenStepNavigation[];
4
4
  disableCountries?: boolean;
5
5
  disableLocale?: boolean;
6
6
  disableSettingFetching?: boolean;
7
7
  maturity?: 'full' | 'express';
8
+ expressToken?: string;
9
+ onExpressVerifyTokenSuccess?: (data: VerifyExpressTokenParams) => Promise<void>;
8
10
  }
9
- export declare const useAppConfig: ({ appInfo, navigation, publicKey, disableCountries, disableLocale, disableSettingFetching, maturity, boardMaturity, ...rest }: AppConfigProps) => void;
11
+ export declare const useAppConfig: ({ appInfo, navigation, publicKey, disableCountries, disableLocale, disableSettingFetching, maturity, boardMaturity, expressToken, onExpressVerifyTokenSuccess, ...rest }: AppConfigProps) => void;
10
12
  export {};
@@ -28,7 +28,7 @@ import { axiosInstance } from '../api';
28
28
  import { isTapDomain, removeRequestHeaders } from '../utils';
29
29
  import { ENDPOINT_PATHS } from '../constants';
30
30
  export var useAppConfig = function (_a) {
31
- var appInfo = _a.appInfo, navigation = _a.navigation, publicKey = _a.publicKey, disableCountries = _a.disableCountries, disableLocale = _a.disableLocale, disableSettingFetching = _a.disableSettingFetching, maturity = _a.maturity, boardMaturity = _a.boardMaturity, rest = __rest(_a, ["appInfo", "navigation", "publicKey", "disableCountries", "disableLocale", "disableSettingFetching", "maturity", "boardMaturity"]);
31
+ var appInfo = _a.appInfo, navigation = _a.navigation, publicKey = _a.publicKey, disableCountries = _a.disableCountries, disableLocale = _a.disableLocale, disableSettingFetching = _a.disableSettingFetching, maturity = _a.maturity, boardMaturity = _a.boardMaturity, expressToken = _a.expressToken, onExpressVerifyTokenSuccess = _a.onExpressVerifyTokenSuccess, rest = __rest(_a, ["appInfo", "navigation", "publicKey", "disableCountries", "disableLocale", "disableSettingFetching", "maturity", "boardMaturity", "expressToken", "onExpressVerifyTokenSuccess"]);
32
32
  var dispatch = useAppDispatch();
33
33
  var data = useAppSelector(settingsSelector).data;
34
34
  var setBaseUrl = function () {
@@ -63,6 +63,6 @@ export var useAppConfig = function (_a) {
63
63
  if (!data.isMaturityExpress)
64
64
  dispatch(handleLanguage(rest.language));
65
65
  if (!disableSettingFetching)
66
- dispatch(fetchAppSettingsSync({ disableCountries: disableCountries, disableLocale: disableLocale, mdn: rest.merchantDomain, maturity: maturity }));
66
+ dispatch(fetchAppSettingsSync({ disableCountries: disableCountries, disableLocale: disableLocale, mdn: rest.merchantDomain, maturity: maturity, expressToken: expressToken, onExpressVerifyTokenSuccess: onExpressVerifyTokenSuccess }));
67
67
  }, []);
68
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "2.4.57-test",
3
+ "version": "2.4.59-test",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",