@tap-payments/connect 1.3.5 → 1.3.9

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)
@@ -44,11 +42,14 @@ const ConnectExpressComponent = () => {
44
42
  scope={'merchant'}
45
43
  // optional (Lead Id can be passed in case of you already created a lead using our API )
46
44
  lead={'led_xxxxxxxxxxxxxxxxxxxxxx'}
47
- // required (Decide the maturity of the TapConnect library)
45
+ // required (Decide the mode of connect `normal` or `express`)
48
46
  mature={false}
49
47
  // optional (show/hide board screen after creating an account)
50
48
  board={true}
49
+ // optional ( Decide the board maturity )
51
50
  boardMaturity={false}
51
+ // optional ( Decide to show connect as a `popup` or `page` to our connect domain. Default value is `popup` )
52
+ mode={'popup'}
52
53
  // required (boolean to open/close the connect element)
53
54
  open={true}
54
55
  // optional (The POST Method URL used to push te data from our server to the merchant server)
@@ -66,35 +67,6 @@ const ConnectExpressComponent = () => {
66
67
  />
67
68
  )
68
69
  }
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
70
  ```
99
71
 
100
72
  ### Vanilla JS
@@ -109,7 +81,7 @@ const ConnectFullComponent = () => {
109
81
  content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no"
110
82
  />
111
83
  <title>Auth-JsConnect</title>
112
- <script src="https://connect-auth.b-cdn.net/build-1.3.5/main.js"></script>
84
+ <script src="https://tap-sdks.b-cdn.net/connect/build-1.3.9/main.js"></script>
113
85
  </head>
114
86
  <body>
115
87
  <div id="root"></div>
@@ -129,6 +101,7 @@ const ConnectFullComponent = () => {
129
101
  mature: false,
130
102
  board: true,
131
103
  boardMaturity: false,
104
+ mode: "popup",
132
105
  open: true,
133
106
  postURL: 'https://api.example.com/post',
134
107
  onReady: () => console.log('onReady'),
@@ -167,7 +140,7 @@ const ConnectFullComponent = () => {
167
140
  | scope `required` | `string` | the scope of the merchant |
168
141
  | lead `optional` | `string` | Lead Id can be passed in case of you already created a lead using our API |
169
142
  | 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 |
143
+ | mature `required` | `boolean` | Decide the mode of connect `normal` or `express` |
171
144
  | board `optional` | `string` | Show/Hide board screens |
172
145
  | open `required` | `boolean` | Open/Close the connect library |
173
146
  | boardMaturity `optional` | `boolean` | Decide the board maturity |
@@ -1,4 +1,12 @@
1
1
  import { GetResult } from '@fingerprintjs/fingerprintjs';
2
2
  import { TokenParams } from '../@types';
3
3
  export declare const getFingerPrint: () => Promise<GetResult>;
4
- export declare const generateConfigToken: (data: TokenParams) => Promise<any>;
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) {
@@ -36,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
47
  };
37
48
  import axios from 'axios';
38
49
  import FingerprintJS from '@fingerprintjs/fingerprintjs';
39
- import { CONNECT_MW_URL } from '../constants';
50
+ import { getBaseUrl } from '../utils';
40
51
  export var getFingerPrint = function () {
41
52
  return FingerprintJS.load().then(function (fp) {
42
53
  return fp.get().then(function (result) {
@@ -45,39 +56,50 @@ export var getFingerPrint = function () {
45
56
  });
46
57
  };
47
58
  export var generateConfigToken = function (data) { return __awaiter(void 0, void 0, void 0, function () {
48
- var visitorId, response, error_1;
49
- return __generator(this, function (_a) {
50
- 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) {
51
63
  case 0:
52
- _a.trys.push([0, 4, , 5]);
64
+ _d.trys.push([0, 4, , 5]);
53
65
  return [4, getFingerPrint()];
54
66
  case 1:
55
- visitorId = (_a.sent()).visitorId;
56
- return [4, axios.post("".concat(CONNECT_MW_URL, "init"), data, {
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, {
57
71
  headers: {
58
72
  'Content-Type': 'application/json',
59
73
  'Access-Control-Allow-Headers': true,
60
74
  authorization: data.public_key,
61
75
  bi: visitorId || '',
76
+ cu: window.location.href,
62
77
  mdn: window.location.origin
63
78
  }
64
79
  })];
65
80
  case 2:
66
- _a.sent();
67
- return [4, axios.post("".concat(CONNECT_MW_URL, "connect"), data, {
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, {
68
89
  headers: {
69
90
  'Content-Type': 'application/json',
70
91
  'Access-Control-Allow-Headers': true,
71
- authorization: data.public_key,
92
+ authorization: publicKey,
72
93
  bi: visitorId || '',
94
+ cu: window.location.href,
73
95
  mdn: window.location.origin
74
96
  }
75
97
  })];
76
98
  case 3:
77
- response = _a.sent();
78
- return [2, response.data];
99
+ response = _d.sent();
100
+ return [2, { data: response.data, publicKey: publicKey }];
79
101
  case 4:
80
- error_1 = _a.sent();
102
+ error_1 = _d.sent();
81
103
  return [2, { error: error_1 }];
82
104
  case 5: return [2];
83
105
  }
@@ -1,4 +1,4 @@
1
- export declare const CDN_LIBRARY_BASE_URL = "https://auth-jsconnect.b-cdn.net/build-2.3.4";
1
+ export declare const CDN_LIBRARY_BASE_URL = "https://tap-sdks.b-cdn.net/connect/build-1.3.9";
2
2
  export declare const Maturity: {
3
3
  readonly FULL: "full";
4
4
  readonly EXPRESS: "express";
@@ -8,4 +8,7 @@ export declare const Language: {
8
8
  readonly AR: "ar";
9
9
  };
10
10
  export declare const CONNECT_URL = "https://connect.tap.company/";
11
+ export declare const CONNECT_DEV_URL = "https://connect.dev.tap.company/";
11
12
  export declare const CONNECT_MW_URL = "https://connect-mw.tap.company/middleware/";
13
+ export declare const CONNECT_DEV_MW_URL = "https://connect-mw.dev.tap.company/middleware/";
14
+ 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.3.4';
1
+ export var CDN_LIBRARY_BASE_URL = 'https://tap-sdks.b-cdn.net/connect/build-1.3.9';
2
2
  export var Maturity = {
3
3
  FULL: 'full',
4
4
  EXPRESS: 'express'
@@ -8,4 +8,7 @@ export var Language = {
8
8
  AR: 'ar'
9
9
  };
10
10
  export var CONNECT_URL = 'https://connect.tap.company/';
11
+ export var CONNECT_DEV_URL = 'https://connect.dev.tap.company/';
11
12
  export var CONNECT_MW_URL = 'https://connect-mw.tap.company/middleware/';
13
+ export var CONNECT_DEV_MW_URL = 'https://connect-mw.dev.tap.company/middleware/';
14
+ export var CONNECT_SANDBOX_MW_URL = 'https://connect-mw.sandbox.tap.company/middleware/';
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import { ConnectProps as ConnectAttrs } from '../../@types';
3
3
  export type ConnectProps = Omit<ConnectAttrs, 'elementId'>;
4
- export declare const TapConnect: React.MemoExoticComponent<(props: ConnectAttrs) => JSX.Element>;
4
+ export declare const TapConnect: React.MemoExoticComponent<(props: ConnectAttrs) => import("react/jsx-runtime").JSX.Element>;
5
5
  export declare const renderTapConnect: (props: ConnectProps, elementId: string) => Promise<any>;
@@ -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,9 +87,9 @@ 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, payload, _a, data, publicKeyValue, _b, token, redirect, baseUrl, leadId, showBoard, url_1, countryCode, url, el, root, unmount;
91
+ return __generator(this, function (_c) {
92
+ switch (_c.label) {
93
93
  case 0:
94
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;
95
95
  if (!(mode === 'page')) return [3, 2];
@@ -103,22 +103,23 @@ export var renderTapConnect = function (props, elementId) { return __awaiter(voi
103
103
  }));
104
104
  return [4, generateConfigToken(payload)];
105
105
  case 1:
106
- data = _b.sent();
106
+ _a = _c.sent(), data = _a.data, publicKeyValue = _a.publicKey;
107
107
  if (data === null || data === void 0 ? void 0 : data.error) {
108
108
  onError === null || onError === void 0 ? void 0 : onError(data.error);
109
109
  return [2];
110
110
  }
111
- _a = data || {}, token = _a.token, redirect = _a.redirect;
111
+ _b = data || {}, token = _b.token, redirect = _b.redirect;
112
+ baseUrl = getRedirectBaseUrl(publicKeyValue || '');
112
113
  if (!mature) {
113
114
  leadId = lead;
114
115
  showBoard = board;
115
116
  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);
117
+ "".concat(baseUrl, "express/?config_token=").concat(token, "leadId=").concat(leadId, "&showBoard=").concat(showBoard, "&boardMaturity=").concat(boardMaturity);
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:
@@ -0,0 +1,2 @@
1
+ export declare const getBaseUrl: (publicKey: string) => "https://connect-mw.tap.company/middleware/" | "https://connect-mw.sandbox.tap.company/middleware/";
2
+ export declare const getRedirectBaseUrl: (publicKey: string) => "https://connect.tap.company/" | "https://connect.dev.tap.company/";
@@ -0,0 +1,16 @@
1
+ import { CONNECT_MW_URL, CONNECT_SANDBOX_MW_URL, CONNECT_DEV_URL, CONNECT_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_URL;
8
+ }
9
+ return CONNECT_SANDBOX_MW_URL;
10
+ };
11
+ export var getRedirectBaseUrl = function (publicKey) {
12
+ if (isProd(publicKey)) {
13
+ return CONNECT_URL;
14
+ }
15
+ return CONNECT_DEV_URL;
16
+ };
@@ -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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/connect",
3
- "version": "1.3.5",
3
+ "version": "1.3.9",
4
4
  "description": "Tap Connect",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",