@tap-payments/connect 0.0.18-test → 1.0.0-beta

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/README.md CHANGED
@@ -27,9 +27,7 @@ yarn add @tap-payments/connect
27
27
  ```js
28
28
  import { TapConnect, Language } from '@tap-payments/connect'
29
29
 
30
- // we have two ways to use the connect element
31
- // 1- express flow
32
- const ConnectExpressComponent = () => {
30
+ const ConnectComponent = () => {
33
31
  return (
34
32
  <TapConnect
35
33
  // required (the public key of the merchant account provided by Tap Payments)
@@ -42,17 +40,24 @@ const ConnectExpressComponent = () => {
42
40
  country={'SA'}
43
41
  // required (the scope of the merchant)
44
42
  scope={'merchant'}
43
+ // merchant data array `ex: [operator]`
44
+ data={[]}
45
45
  // optional (Lead Id can be passed in case of you already created a lead using our API )
46
46
  lead={'led_xxxxxxxxxxxxxxxxxxxxxx'}
47
- // required (Decide the maturity of the TapConnect library)
47
+ // required (Decide the mode of connect `normal` or `express`)
48
48
  mature={false}
49
49
  // optional (show/hide board screen after creating an account)
50
50
  board={true}
51
+ // optional ( Decide the board maturity )
51
52
  boardMaturity={false}
53
+ // optional ( Decide to show connect as a `popup` or `page` to our connect domain. Default value is `popup` )
54
+ mode={'popup'}
52
55
  // required (boolean to open/close the connect element)
53
56
  open={true}
54
57
  // optional (The POST Method URL used to push te data from our server to the merchant server)
55
58
  postURL={'https://api.example.com/post'}
59
+ // This redirect url after verify authentication go to merchant website
60
+ redirectUrl={''}
56
61
  //optional (Callback function to handle the ready state of the TapConnect )
57
62
  onReady={() => console.log('onReady')}
58
63
  // optional (Callback function runs after creating an account)
@@ -66,35 +71,6 @@ const ConnectExpressComponent = () => {
66
71
  />
67
72
  )
68
73
  }
69
- // 2- full flow
70
- const ConnectFullComponent = () => {
71
- return (
72
- <TapConnect
73
- // required (the public key of the merchant account provided by Tap Payments)
74
- publicKey={'pk_test_XXXXXXXXXXXXXXXXXXXXXXX'}
75
- // required (the domain of the merchant)
76
- domain={'https://example.com'}
77
- // required (Language flag to control the language of the connect element and only we support [en,ar])
78
- language={Language.EN}
79
- // required (the country ISO2 of the merchant)
80
- country={'SA'}
81
- // required (the scope of the merchant)
82
- scope={'merchant'}
83
- // required (Decide the maturity of the TapConnect library)
84
- mature={true}
85
- // required (boolean to open/close the connect element)
86
- open={true}
87
- //optional (Callback function to handle the ready state of the TapConnect )
88
- onReady={() => console.log('onReady')}
89
- // optional (Callback function runs after finishing the flow)
90
- onSuccess={(data) => console.log('onSuccess', data)}
91
- // optional (Callback function runs when the user close TaConnect)
92
- onClose={() => console.log('onClose')}
93
- // optional (Callback function to handle the error)
94
- onError={(err) => console.log('onError', err)}
95
- />
96
- )
97
- }
98
74
  ```
99
75
 
100
76
  ### Vanilla JS
@@ -109,7 +85,7 @@ const ConnectFullComponent = () => {
109
85
  content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no"
110
86
  />
111
87
  <title>Auth-JsConnect</title>
112
- <script src="https://connect-auth.b-cdn.net/build-0.0.16-test/main.js"></script>
88
+ <script src="https://tap-sdks.b-cdn.net/connect/build-1.0.0-beta/main.js"></script>
113
89
  </head>
114
90
  <body>
115
91
  <div id="root"></div>
@@ -125,12 +101,15 @@ const ConnectFullComponent = () => {
125
101
  domain: 'https://example.com',
126
102
  country: 'SA',
127
103
  scope: 'merchant',
104
+ data: [],
128
105
  lead: 'led_xxxxxxxxxxxxxxxxxxxxxx',
129
106
  mature: false,
130
107
  board: true,
131
108
  boardMaturity: false,
109
+ mode: "popup",
132
110
  open: true,
133
111
  postURL: 'https://api.example.com/post',
112
+ redirectUrl: '',
134
113
  onReady: () => console.log('onReady'),
135
114
  onCreated: (data) => console.log('onCreated', data),
136
115
  onError: (err) => console.log('onError', err),
@@ -158,25 +137,28 @@ const ConnectFullComponent = () => {
158
137
 
159
138
  ## Properties
160
139
 
161
- | name | type | description |
162
- | --------------------------- | ----------- | --------------------------------------------------------------------------------------------- |
163
- | publicKey `required` | `string` | Public key of the merchant account provided by Tap Payments |
164
- | domain `required` | `string` | Domain of the merchant |
165
- | language `required` | `Languages` | language flag to control the language of the connect element and only accept [ar,en] |
166
- | country `required` | `string` | Country ISO2 of the merchant |
167
- | scope `required` | `string` | the scope of the merchant |
168
- | lead `optional` | `string` | Lead Id can be passed in case of you already created a lead using our API |
169
- | mode `required` | `string` | Decide to show connect as a `popup` or `page` to our connect domain. Default value is `popup` |
170
- | mature `required` | `boolean` | Decide the mode of connect |
171
- | board `optional` | `string` | Show/Hide board screens |
172
- | open `required` | `boolean` | Open/Close the connect library |
173
- | boardMaturity `optional` | `boolean` | Decide the board maturity |
174
- | postURL `optional` | `string` | The POST Method URL used to push te data from our server to the merchant server and |
175
- | | | it's required only if `mature` is `false` |
176
- | onReady `optional` | `function` | Callback function to handle the ready state of the `TapConnect` |
177
- | onCreated `optional` | `function` | Callback function to called the the account created successfully |
178
- | | | it calls only if `mature` is `false` |
179
- | onSuccess `optional` | `function` | Callback function to handle the success response, it will run after the user finish the flow |
180
- | onError `optional` | `function` | Callback function to handle the error response, it will run if the user face any error |
181
- | onClose `optional` | `function` | Callback function to called when `TapConnect` get close |
182
- | onBoardCompleted `optional` | `function` | Callback function to called when you complete all flows |
140
+ | name | type | description |
141
+ | --------------------------- | --------------- | --------------------------------------------------------------------------------------------- |
142
+ | publicKey `required` | `string` | Public key of the merchant account provided by Tap Payments |
143
+ | domain `required` | `string` | Domain of the merchant |
144
+ | language `required` | `Languages` | language flag to control the language of the connect element and only accept [ar,en] |
145
+ | country `required` | `string` | Country ISO2 of the merchant |
146
+ | scope `required` | `string` | the scope of the merchant available values [merchant, auth] |
147
+ | data `optional` | `Array<string>` | Merchant data array `ex: [operator]` |
148
+ | lead `optional` | `string` | Lead Id can be passed in case of you already created a lead using our API |
149
+ | mode `required` | `string` | Decide to show connect as a `popup` or `page` to our connect domain. Default value is `popup` |
150
+ | mature `required` | `boolean` | Decide the mode of connect `normal` or `express` |
151
+ | board `optional` | `string` | Show/Hide board screens |
152
+ | open `required` | `boolean` | Open/Close the connect library |
153
+ | boardMaturity `optional` | `boolean` | Decide the board maturity |
154
+ | postURL `optional` | `string` | The POST Method URL used to push te data from our server to the merchant server and |
155
+ | | | it's required only if `mature` is `false` |
156
+ | redirectUrl `optional` | `string` | This redirect url after verify authentication go to merchant website |
157
+ | | | It is `required` if scope is `auth` and mode is `page` |
158
+ | onReady `optional` | `function` | Callback function to handle the ready state of the `TapConnect` |
159
+ | onCreated `optional` | `function` | Callback function to called the the account created successfully |
160
+ | | | it calls only if `mature` is `false` |
161
+ | onSuccess `optional` | `function` | Callback function to handle the success response, it will run after the user finish the flow |
162
+ | onError `optional` | `function` | Callback function to handle the error response, it will run if the user face any error |
163
+ | onClose `optional` | `function` | Callback function to called when `TapConnect` get close |
164
+ | onBoardCompleted `optional` | `function` | Callback function to called when you complete all flows |
@@ -8,11 +8,13 @@ export interface ConnectProps {
8
8
  scope: string;
9
9
  lead?: string;
10
10
  mature: boolean;
11
- mode: 'popup' | 'page';
11
+ mode?: 'popup' | 'page';
12
12
  board?: boolean;
13
13
  boardMaturity?: boolean;
14
14
  open: boolean;
15
15
  postURL?: string;
16
+ redirectUrl?: string;
17
+ data?: Array<string>;
16
18
  onError?: (err: Error) => void;
17
19
  onReady?: () => void;
18
20
  onClose?: () => void;
@@ -22,6 +24,7 @@ export interface ConnectProps {
22
24
  }
23
25
  export interface OriginalConnectProps {
24
26
  publicKey: string;
27
+ mode?: 'popup' | 'page';
25
28
  open: boolean;
26
29
  merchantDomain: string;
27
30
  language: string;
@@ -30,6 +33,8 @@ export interface OriginalConnectProps {
30
33
  scope: string;
31
34
  leadId?: string;
32
35
  postURL?: string;
36
+ redirectUrl?: string;
37
+ data?: Array<string>;
33
38
  showBoard?: boolean;
34
39
  boardMaturity?: boolean;
35
40
  verifyToken?: string;
@@ -60,6 +65,8 @@ export type TokenParams = {
60
65
  post?: {
61
66
  url: string;
62
67
  };
68
+ redirect_url?: string;
69
+ data?: Array<string>;
63
70
  };
64
71
  export interface TokenResponseParams extends TokenParams {
65
72
  id: string;
@@ -1,2 +1,12 @@
1
+ import { GetResult } from '@fingerprintjs/fingerprintjs';
1
2
  import { TokenParams } from '../@types';
2
- export declare const generateConfigToken: (data: TokenParams) => Promise<any>;
3
+ export declare const getFingerPrint: () => Promise<GetResult>;
4
+ export declare const generateConfigToken: (data: TokenParams) => Promise<{
5
+ data: any;
6
+ publicKey: string;
7
+ error?: undefined;
8
+ } | {
9
+ error: unknown;
10
+ data?: undefined;
11
+ publicKey?: undefined;
12
+ }>;
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,27 +46,62 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
46
  }
36
47
  };
37
48
  import axios from 'axios';
38
- import { CONNECT_MW_URL } from '../constants';
49
+ import FingerprintJS from '@fingerprintjs/fingerprintjs';
50
+ import { getBaseUrl } from '../utils';
51
+ export var getFingerPrint = function () {
52
+ return FingerprintJS.load().then(function (fp) {
53
+ return fp.get().then(function (result) {
54
+ return result;
55
+ });
56
+ });
57
+ };
39
58
  export var generateConfigToken = function (data) { return __awaiter(void 0, void 0, void 0, function () {
40
- var response, error_1;
41
- return __generator(this, function (_a) {
42
- switch (_a.label) {
59
+ var visitorId, baseUrl, publicKey, res, public_key, payload, response, error_1;
60
+ var _a, _b, _c;
61
+ return __generator(this, function (_d) {
62
+ switch (_d.label) {
43
63
  case 0:
44
- _a.trys.push([0, 2, , 3]);
45
- return [4, axios.post("".concat(CONNECT_MW_URL, "connect"), data, {
64
+ _d.trys.push([0, 4, , 5]);
65
+ return [4, getFingerPrint()];
66
+ case 1:
67
+ visitorId = (_d.sent()).visitorId;
68
+ baseUrl = getBaseUrl(data.public_key);
69
+ publicKey = data.public_key;
70
+ return [4, axios.post("".concat(baseUrl, "init"), data, {
46
71
  headers: {
47
72
  'Content-Type': 'application/json',
48
73
  'Access-Control-Allow-Headers': true,
49
- authorization: data.public_key
74
+ authorization: data.public_key,
75
+ bi: visitorId || '',
76
+ cu: window.location.href,
77
+ mdn: window.location.origin
50
78
  }
51
79
  })];
52
- case 1:
53
- response = _a.sent();
54
- return [2, response.data];
55
80
  case 2:
56
- error_1 = _a.sent();
81
+ res = _d.sent();
82
+ public_key = (((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.config) || {}).public_key;
83
+ if (public_key) {
84
+ publicKey = public_key;
85
+ baseUrl = getBaseUrl(public_key);
86
+ }
87
+ payload = __assign(__assign({}, data), (((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.config) && ((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.config)));
88
+ return [4, axios.post("".concat(baseUrl, "connect"), payload, {
89
+ headers: {
90
+ 'Content-Type': 'application/json',
91
+ 'Access-Control-Allow-Headers': true,
92
+ authorization: publicKey,
93
+ bi: visitorId || '',
94
+ cu: window.location.href,
95
+ mdn: window.location.origin
96
+ }
97
+ })];
98
+ case 3:
99
+ response = _d.sent();
100
+ return [2, { data: response.data, publicKey: publicKey }];
101
+ case 4:
102
+ error_1 = _d.sent();
57
103
  return [2, { error: error_1 }];
58
- case 3: return [2];
104
+ case 5: return [2];
59
105
  }
60
106
  });
61
107
  }); };
@@ -1,4 +1,4 @@
1
- export declare const CDN_LIBRARY_BASE_URL = "https://auth-jsconnect.b-cdn.net/build-2.4.77-test/";
1
+ export declare const CDN_LIBRARY_BASE_URL = "https://auth-jsconnect.b-cdn.net/build-1.0.0-beta";
2
2
  export declare const Maturity: {
3
3
  readonly FULL: "full";
4
4
  readonly EXPRESS: "express";
@@ -7,5 +7,10 @@ export declare const Language: {
7
7
  readonly EN: "en";
8
8
  readonly AR: "ar";
9
9
  };
10
- export declare const CONNECT_URL = "https://connect.dev.tap.company/";
11
- export declare const CONNECT_MW_URL = "https://connect-mw.dev.tap.company/middleware/";
10
+ export declare const CONNECT_URL = "https://connect.tap.company/";
11
+ export declare const CONNECT_BETA_URL = "https://connect.beta.tap.company/";
12
+ export declare const CONNECT_DEV_URL = "https://connect.dev.tap.company/";
13
+ export declare const CONNECT_MW_URL = "https://connect-mw.tap.company/middleware/";
14
+ export declare const CONNECT_MW_BETA_URL = "https://connect-mw.beta.tap.company/middleware/";
15
+ export declare const CONNECT_DEV_MW_URL = "https://connect-mw.dev.tap.company/middleware/";
16
+ export declare const CONNECT_SANDBOX_MW_URL = "https://connect-mw.sandbox.tap.company/middleware/";
@@ -1,4 +1,4 @@
1
- export var CDN_LIBRARY_BASE_URL = 'https://auth-jsconnect.b-cdn.net/build-2.4.77-test/';
1
+ export var CDN_LIBRARY_BASE_URL = 'https://auth-jsconnect.b-cdn.net/build-1.0.0-beta';
2
2
  export var Maturity = {
3
3
  FULL: 'full',
4
4
  EXPRESS: 'express'
@@ -7,5 +7,10 @@ export var Language = {
7
7
  EN: 'en',
8
8
  AR: 'ar'
9
9
  };
10
- export var CONNECT_URL = 'https://connect.dev.tap.company/';
11
- export var CONNECT_MW_URL = 'https://connect-mw.dev.tap.company/middleware/';
10
+ export var CONNECT_URL = 'https://connect.tap.company/';
11
+ export var CONNECT_BETA_URL = 'https://connect.beta.tap.company/';
12
+ export var CONNECT_DEV_URL = 'https://connect.dev.tap.company/';
13
+ export var CONNECT_MW_URL = 'https://connect-mw.tap.company/middleware/';
14
+ export var CONNECT_MW_BETA_URL = 'https://connect-mw.beta.tap.company/middleware/';
15
+ export var CONNECT_DEV_MW_URL = 'https://connect-mw.dev.tap.company/middleware/';
16
+ export var CONNECT_SANDBOX_MW_URL = 'https://connect-mw.sandbox.tap.company/middleware/';
@@ -59,9 +59,9 @@ var __rest = (this && this.__rest) || function (s, e) {
59
59
  import { jsx as _jsx } from "react/jsx-runtime";
60
60
  import * as React from 'react';
61
61
  import { createRoot } from 'react-dom/client';
62
- import { findOrCreateElementAndInject, validateConnectProps } from '../../utils';
62
+ import { findOrCreateElementAndInject, getRedirectBaseUrl, validateConnectProps } from '../../utils';
63
63
  import { useScript, useStyle } from '../../hooks';
64
- import { CDN_LIBRARY_BASE_URL, CONNECT_URL } from '../../constants';
64
+ import { CDN_LIBRARY_BASE_URL } from '../../constants';
65
65
  import { generateConfigToken } from '../../api';
66
66
  import ConnectFull from './ConnectFull';
67
67
  import ConnectExpress from './ConnectExpress';
@@ -87,38 +87,39 @@ export var TapConnect = React.memo(function (props) {
87
87
  });
88
88
  var tapConnectInstance = null;
89
89
  export var renderTapConnect = function (props, elementId) { return __awaiter(void 0, void 0, void 0, function () {
90
- var mode, board, publicKey, boardMaturity, domain, language, country, scope, lead, postURL, mature, onError, payload, data, _a, token, redirect, leadId, showBoard, url_1, countryCode, url, el, root, unmount;
91
- return __generator(this, function (_b) {
92
- switch (_b.label) {
90
+ var mode, board, publicKey, boardMaturity, domain, language, country, scope, lead, postURL, mature, onError, redirectUrl, AuthData, payload, _a, data, publicKeyValue, _b, token, redirect, baseUrl, url_1, countryCode, url, el, root, unmount;
91
+ return __generator(this, function (_c) {
92
+ switch (_c.label) {
93
93
  case 0:
94
- mode = props.mode, board = props.board, publicKey = props.publicKey, boardMaturity = props.boardMaturity, domain = props.domain, language = props.language, country = props.country, scope = props.scope, lead = props.lead, postURL = props.postURL, mature = props.mature, onError = props.onError;
94
+ props.mode = props.mode || 'popup';
95
+ mode = props.mode, board = props.board, publicKey = props.publicKey, boardMaturity = props.boardMaturity, domain = props.domain, language = props.language, country = props.country, scope = props.scope, lead = props.lead, postURL = props.postURL, mature = props.mature, onError = props.onError, redirectUrl = props.redirectUrl, AuthData = props.data;
95
96
  if (!(mode === 'page')) return [3, 2];
96
- payload = __assign({ board: board, public_key: publicKey, board_maturity: boardMaturity, domain: domain, language: language, country: country, scope: scope, lead_id: lead, maturity: mature, notification: {
97
- email: true,
98
- sms: true
99
- } }, (postURL && {
100
- post: {
97
+ payload = __assign({ board: board, public_key: publicKey, board_maturity: boardMaturity, domain: domain, language: language, country: country, scope: scope, lead_id: lead, maturity: scope === 'auth' ? false : mature, notification: {
98
+ email: scope !== 'auth',
99
+ sms: scope !== 'auth'
100
+ } }, (postURL && __assign(__assign({ post: {
101
101
  url: postURL
102
- }
103
- }));
102
+ } }, (redirectUrl && {
103
+ platform_redirect_url: redirectUrl
104
+ })), (AuthData && {
105
+ data: AuthData
106
+ }))));
104
107
  return [4, generateConfigToken(payload)];
105
108
  case 1:
106
- data = _b.sent();
109
+ _a = _c.sent(), data = _a.data, publicKeyValue = _a.publicKey;
107
110
  if (data === null || data === void 0 ? void 0 : data.error) {
108
111
  onError === null || onError === void 0 ? void 0 : onError(data.error);
109
112
  return [2];
110
113
  }
111
- _a = data || {}, token = _a.token, redirect = _a.redirect;
112
- if (!mature) {
113
- leadId = lead;
114
- showBoard = board;
115
- url_1 = (redirect === null || redirect === void 0 ? void 0 : redirect.url) ||
116
- "".concat(CONNECT_URL, "express/?config_token=").concat(token, "leadId=").concat(leadId, "&showBoard=").concat(showBoard, "&boardMaturity=").concat(boardMaturity);
114
+ _b = data || {}, token = _b.token, redirect = _b.redirect;
115
+ baseUrl = getRedirectBaseUrl(publicKeyValue || '');
116
+ if (!mature || scope === 'auth') {
117
+ url_1 = (redirect === null || redirect === void 0 ? void 0 : redirect.url) || "".concat(baseUrl, "?config_token=").concat(token);
117
118
  window.location.href = url_1;
118
119
  return [2];
119
120
  }
120
121
  countryCode = country.toLowerCase();
121
- url = (redirect === null || redirect === void 0 ? void 0 : redirect.url) || "".concat(CONNECT_URL).concat(countryCode, "?config_token=").concat(token);
122
+ url = (redirect === null || redirect === void 0 ? void 0 : redirect.url) || "".concat(baseUrl).concat(countryCode, "?config_token=").concat(token);
122
123
  window.location.href = url;
123
124
  return [2];
124
125
  case 2:
@@ -9,17 +9,6 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
12
  import * as React from 'react';
24
13
  import { wrapLibConfig } from '../../utils';
25
14
  var ConnectExpress = function (props) {
@@ -64,8 +53,7 @@ var ConnectExpress = function (props) {
64
53
  break;
65
54
  default:
66
55
  unmountComponent();
67
- var onSuccess = props.onSuccess, rest = __rest(props, ["onSuccess"]);
68
- var configAttrs = wrapLibConfig(__assign(__assign({}, rest), { verifyToken: token, onBoardButtonClick: onButtonClick }));
56
+ var configAttrs = wrapLibConfig(__assign(__assign({}, props), { verifyToken: token, onBoardButtonClick: onButtonClick }));
69
57
  var unmountExpress = renderConnectExpressLib(configAttrs, elementId).unmount;
70
58
  unmountComponent = unmountExpress;
71
59
  break;
@@ -0,0 +1,2 @@
1
+ export declare const getBaseUrl: (publicKey: string) => "https://connect-mw.beta.tap.company/middleware/" | "https://connect-mw.sandbox.tap.company/middleware/";
2
+ export declare const getRedirectBaseUrl: (publicKey: string) => "https://connect.beta.tap.company/" | "https://connect.dev.tap.company/";
@@ -0,0 +1,16 @@
1
+ import { CONNECT_SANDBOX_MW_URL, CONNECT_DEV_URL, CONNECT_BETA_URL, CONNECT_MW_BETA_URL } from '../constants';
2
+ var isProd = function (publicKey) {
3
+ return publicKey.includes('pk_live');
4
+ };
5
+ export var getBaseUrl = function (publicKey) {
6
+ if (isProd(publicKey)) {
7
+ return CONNECT_MW_BETA_URL;
8
+ }
9
+ return CONNECT_SANDBOX_MW_URL;
10
+ };
11
+ export var getRedirectBaseUrl = function (publicKey) {
12
+ if (isProd(publicKey)) {
13
+ return CONNECT_BETA_URL;
14
+ }
15
+ return CONNECT_DEV_URL;
16
+ };
@@ -3,5 +3,5 @@ type ExtraProps = {
3
3
  verifyToken?: string;
4
4
  onBoardButtonClick?: (data: Record<string, string>) => void;
5
5
  };
6
- export declare const wrapLibConfig: ({ publicKey, open, language, country, scope, lead, postURL, onError, onReady, onSuccess, board, verifyToken, domain, onBoardButtonClick, onClose, onCreated, onBoardCompleted, boardMaturity }: ConnectProps & ExtraProps) => OriginalConnectProps;
6
+ export declare const wrapLibConfig: ({ publicKey, open, mode, language, country, scope, lead, postURL, onError, onReady, onSuccess, board, verifyToken, domain, onBoardButtonClick, onClose, onCreated, onBoardCompleted, boardMaturity, data, redirectUrl }: ConnectProps & ExtraProps) => OriginalConnectProps;
7
7
  export {};
@@ -1,5 +1,5 @@
1
1
  export var wrapLibConfig = function (_a) {
2
- var publicKey = _a.publicKey, open = _a.open, language = _a.language, country = _a.country, scope = _a.scope, lead = _a.lead, postURL = _a.postURL, onError = _a.onError, onReady = _a.onReady, onSuccess = _a.onSuccess, board = _a.board, verifyToken = _a.verifyToken, domain = _a.domain, onBoardButtonClick = _a.onBoardButtonClick, onClose = _a.onClose, onCreated = _a.onCreated, onBoardCompleted = _a.onBoardCompleted, boardMaturity = _a.boardMaturity;
2
+ var publicKey = _a.publicKey, open = _a.open, mode = _a.mode, language = _a.language, country = _a.country, scope = _a.scope, lead = _a.lead, postURL = _a.postURL, onError = _a.onError, onReady = _a.onReady, onSuccess = _a.onSuccess, board = _a.board, verifyToken = _a.verifyToken, domain = _a.domain, onBoardButtonClick = _a.onBoardButtonClick, onClose = _a.onClose, onCreated = _a.onCreated, onBoardCompleted = _a.onBoardCompleted, boardMaturity = _a.boardMaturity, data = _a.data, redirectUrl = _a.redirectUrl;
3
3
  return {
4
4
  appInfo: {
5
5
  name: window.location.hostname || window.location.origin
@@ -8,9 +8,12 @@ export var wrapLibConfig = function (_a) {
8
8
  language: language,
9
9
  merchantDomain: domain,
10
10
  open: open,
11
+ mode: mode,
11
12
  postURL: postURL,
12
13
  publicKey: publicKey,
13
14
  scope: scope,
15
+ data: data,
16
+ redirectUrl: redirectUrl,
14
17
  leadId: lead,
15
18
  showBoard: board,
16
19
  boardMaturity: boardMaturity,
@@ -1,3 +1,4 @@
1
1
  export * from './html';
2
2
  export * from './validation';
3
3
  export * from './config';
4
+ export * from './common';
@@ -1,3 +1,4 @@
1
1
  export * from './html';
2
2
  export * from './validation';
3
3
  export * from './config';
4
+ export * from './common';
@@ -1,6 +1,12 @@
1
1
  import { Language } from '../constants';
2
2
  export var validateConnectProps = function (props) {
3
- var publicKey = props.publicKey, mature = props.mature, country = props.country, language = props.language, scope = props.scope, open = props.open, domain = props.domain, board = props.board, lead = props.lead, onClose = props.onClose, onCreated = props.onCreated, onError = props.onError, onReady = props.onReady, onSuccess = props.onSuccess, postURL = props.postURL;
3
+ var mode = props.mode, publicKey = props.publicKey, mature = props.mature, country = props.country, language = props.language, scope = props.scope, open = props.open, domain = props.domain, board = props.board, lead = props.lead, onClose = props.onClose, onCreated = props.onCreated, onError = props.onError, onReady = props.onReady, onSuccess = props.onSuccess, postURL = props.postURL, redirectUrl = props.redirectUrl;
4
+ if (!mode) {
5
+ throw new Error('mode is required');
6
+ }
7
+ if (!['page', 'popup'].includes(mode)) {
8
+ throw new Error('you can only use page or popup for mode');
9
+ }
4
10
  if (!publicKey) {
5
11
  throw new Error('publicKey is required');
6
12
  }
@@ -11,11 +17,14 @@ export var validateConnectProps = function (props) {
11
17
  throw new Error('language is required');
12
18
  }
13
19
  if (![Language.AR, Language.EN].includes(language)) {
14
- throw new Error('You can only use AR or EN for language');
20
+ throw new Error('you can only use AR or EN for language');
15
21
  }
16
22
  if (!scope) {
17
23
  throw new Error('scope is required');
18
24
  }
25
+ if (scope === 'auth' && mode === 'page' && !redirectUrl) {
26
+ throw new Error('redirectUrl is required');
27
+ }
19
28
  if (!domain) {
20
29
  throw new Error('domain is required');
21
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/connect",
3
- "version": "0.0.18-test",
3
+ "version": "1.0.0-beta",
4
4
  "description": "Tap Connect",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",
@@ -20,7 +20,7 @@
20
20
  "copy:files": "copyfiles -u 1 src/**/*.css build/",
21
21
  "tsc:alias": "tsc-alias -p tsconfig.json",
22
22
  "ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
23
- "push": "npm publish --access public"
23
+ "push": "npm publish --access public --tag beta"
24
24
  },
25
25
  "keywords": [],
26
26
  "author": {
@@ -33,6 +33,7 @@
33
33
  "@babel/preset-env": "^7.18.6",
34
34
  "@babel/preset-react": "^7.18.6",
35
35
  "@babel/preset-typescript": "^7.18.6",
36
+ "@types/axios": "^0.14.0",
36
37
  "@types/crypto-js": "^4.1.1",
37
38
  "@types/react": "^18.0.15",
38
39
  "@types/react-dom": "^18.0.6",
@@ -72,9 +73,10 @@
72
73
  "webpack-merge": "^5.8.0"
73
74
  },
74
75
  "dependencies": {
76
+ "@fingerprintjs/fingerprintjs": "^3.4.1",
75
77
  "axios": "^1.4.0",
76
- "react": "^18.2.0",
77
- "react-dom": "^18.2.0"
78
+ "react": ">=18.2.0",
79
+ "react-dom": ">=18.2.0"
78
80
  },
79
81
  "peerDependencies": {
80
82
  "@types/react": ">=18.0.15",