@tap-payments/connect 0.0.11-test → 0.0.13-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.
package/README.md CHANGED
@@ -60,6 +60,8 @@ const ConnectExpressComponent = () => {
60
60
  onClose={() => console.log('onClose')}
61
61
  // optional (Callback function to handle the error)
62
62
  onError={(err) => console.log('onError', err)}
63
+ // optional (Callback function runs after finishing all the flows)
64
+ onBoardCompleted={() => console.log('onBoardCompleted')}
63
65
  />
64
66
  )
65
67
  }
@@ -106,7 +108,7 @@ const ConnectFullComponent = () => {
106
108
  content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no"
107
109
  />
108
110
  <title>Auth-JsConnect</title>
109
- <script src="https://connect-auth.b-cdn.net/build-0.0.11-test/main.js"></script>
111
+ <script src="https://connect-auth.b-cdn.net/build-0.0.13-test/main.js"></script>
110
112
  </head>
111
113
  <body>
112
114
  <div id="root"></div>
@@ -131,6 +133,7 @@ const ConnectFullComponent = () => {
131
133
  onCreated: (data) => console.log('onCreated', data),
132
134
  onError: (err) => console.log('onError', err),
133
135
  onClose: () => console.log('onClose'),
136
+ onBoardCompleted: () => console.log('onBoardCompleted'),
134
137
 
135
138
  },
136
139
  'root'
@@ -153,22 +156,23 @@ const ConnectFullComponent = () => {
153
156
 
154
157
  ## Properties
155
158
 
156
- | name | type | description |
157
- | -------------------- | ----------- | -------------------------------------------------------------------------------------------- |
158
- | publicKey `required` | `string` | Public key of the merchant account provided by Tap Payments |
159
- | domain `required` | `string` | Domain of the merchant |
160
- | language `required` | `Languages` | language flag to control the language of the connect element and only accept [ar,en] |
161
- | country `required` | `string` | Country ISO2 of the merchant |
162
- | scope `required` | `string` | the scope of the merchant |
163
- | lead `optional` | `string` | Lead Id can be passed in case of you already created a lead using our API |
164
- | mature `required` | `boolean` | Decide the mode of connect |
165
- | board `optional` | `string` | Show/Hide board screens |
166
- | open `required` | `boolean` | Open/Close the connect library |
167
- | postURL `optional` | `string` | The POST Method URL used to push te data from our server to the merchant server and |
168
- | | | it's required only if `mature` is `false` |
169
- | onReady `optional` | `function` | Callback function to handle the ready state of the `TapConnect` |
170
- | onCreated `optional` | `function` | Callback function to called the the account created successfully |
171
- | | | it calls only if `mature` is `false` |
172
- | onSuccess `optional` | `function` | Callback function to handle the success response, it will run after the user finish the flow |
173
- | onError `optional` | `function` | Callback function to handle the error response, it will run if the user face any error |
174
- | onClose `optional` | `function` | Callback function to called when `TapConnect` get close |
159
+ | name | type | description |
160
+ | --------------------------- | ----------- | -------------------------------------------------------------------------------------------- |
161
+ | publicKey `required` | `string` | Public key of the merchant account provided by Tap Payments |
162
+ | domain `required` | `string` | Domain of the merchant |
163
+ | language `required` | `Languages` | language flag to control the language of the connect element and only accept [ar,en] |
164
+ | country `required` | `string` | Country ISO2 of the merchant |
165
+ | scope `required` | `string` | the scope of the merchant |
166
+ | lead `optional` | `string` | Lead Id can be passed in case of you already created a lead using our API |
167
+ | mature `required` | `boolean` | Decide the mode of connect |
168
+ | board `optional` | `string` | Show/Hide board screens |
169
+ | open `required` | `boolean` | Open/Close the connect library |
170
+ | postURL `optional` | `string` | The POST Method URL used to push te data from our server to the merchant server and |
171
+ | | | it's required only if `mature` is `false` |
172
+ | onReady `optional` | `function` | Callback function to handle the ready state of the `TapConnect` |
173
+ | onCreated `optional` | `function` | Callback function to called the the account created successfully |
174
+ | | | it calls only if `mature` is `false` |
175
+ | onSuccess `optional` | `function` | Callback function to handle the success response, it will run after the user finish the flow |
176
+ | onError `optional` | `function` | Callback function to handle the error response, it will run if the user face any error |
177
+ | onClose `optional` | `function` | Callback function to called when `TapConnect` get close |
178
+ | onBoardCompleted `optional` | `function` | Callback function to called when you complete all flows |
@@ -1,8 +1,9 @@
1
1
  import { Language } from '../constants';
2
2
  export interface ConnectProps {
3
+ elementId: string;
3
4
  publicKey: string;
4
5
  domain: string;
5
- language: typeof Language[keyof typeof Language];
6
+ language: (typeof Language)[keyof typeof Language];
6
7
  country: string;
7
8
  scope: string;
8
9
  lead?: string;
@@ -15,6 +16,7 @@ export interface ConnectProps {
15
16
  onClose?: () => void;
16
17
  onCreated?: (res: object) => void;
17
18
  onSuccess?: (res: object) => void;
19
+ onBoardCompleted?: () => void;
18
20
  }
19
21
  export interface OriginalConnectProps {
20
22
  publicKey: string;
@@ -36,4 +38,5 @@ export interface OriginalConnectProps {
36
38
  onBoardButtonClick?: (data: Record<string, any>) => void;
37
39
  onCreated?: (res: Record<string, any>) => void;
38
40
  onClose?: () => void;
41
+ onBoardCompleted?: () => void;
39
42
  }
@@ -1,4 +1,4 @@
1
- export declare const CDN_LIBRARY_BASE_URL = "https://auth-jsconnect.b-cdn.net/build-2.1.74-test";
1
+ export declare const CDN_LIBRARY_BASE_URL = "https://auth-jsconnect.b-cdn.net/build-2.1.97-test";
2
2
  export declare const Maturity: {
3
3
  readonly FULL: "full";
4
4
  readonly EXPRESS: "express";
@@ -1,4 +1,4 @@
1
- export var CDN_LIBRARY_BASE_URL = 'https://auth-jsconnect.b-cdn.net/build-2.1.74-test';
1
+ export var CDN_LIBRARY_BASE_URL = 'https://auth-jsconnect.b-cdn.net/build-2.1.97-test';
2
2
  export var Maturity = {
3
3
  FULL: 'full',
4
4
  EXPRESS: 'express'
@@ -1,7 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ConnectProps } from '../../@types';
3
- export type { ConnectProps };
4
- export declare const TapConnect: React.MemoExoticComponent<(props: ConnectProps) => JSX.Element>;
5
- export declare const renderTapConnect: (props: ConnectProps, elementId: string) => {
6
- unmount: () => void;
7
- };
2
+ import { ConnectProps as ConnectAttrs } from '../../@types';
3
+ export type ConnectProps = Omit<ConnectAttrs, 'elementId'>;
4
+ export declare const TapConnect: React.MemoExoticComponent<(props: ConnectAttrs) => JSX.Element>;
5
+ export declare const renderTapConnect: (props: ConnectProps, elementId: string) => any;
@@ -9,15 +9,27 @@ 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
+ };
12
23
  import { jsx as _jsx } from "react/jsx-runtime";
13
24
  import * as React from 'react';
14
25
  import { createRoot } from 'react-dom/client';
15
- import { createElementAndInject, validateConnectProps } from '../../utils';
26
+ import { findOrCreateElementAndInject, validateConnectProps } from '../../utils';
16
27
  import { useScript, useStyle } from '../../hooks';
17
28
  import { CDN_LIBRARY_BASE_URL } from '../../constants';
18
29
  import ConnectFull from './ConnectFull';
19
30
  import ConnectExpress from './ConnectExpress';
20
- var Connect = function (props) {
31
+ var Connect = function (_a) {
32
+ var elementId = _a.elementId, props = __rest(_a, ["elementId"]);
21
33
  useStyle("".concat(CDN_LIBRARY_BASE_URL, "/main.css"));
22
34
  var status = useScript("".concat(CDN_LIBRARY_BASE_URL, "/main.js"));
23
35
  React.useEffect(function () {
@@ -29,17 +41,25 @@ var Connect = function (props) {
29
41
  if (status !== 'ready')
30
42
  return null;
31
43
  if (!props.mature)
32
- return _jsx(ConnectExpress, __assign({}, props));
33
- return _jsx(ConnectFull, __assign({}, props));
44
+ return _jsx(ConnectExpress, __assign({}, props, { elementId: elementId }));
45
+ return _jsx(ConnectFull, __assign({}, props, { elementId: elementId }));
34
46
  };
35
47
  export var TapConnect = React.memo(function (props) {
36
48
  validateConnectProps(props);
37
49
  return _jsx(Connect, __assign({}, props));
38
50
  });
51
+ var tapConnectInstance = null;
39
52
  export var renderTapConnect = function (props, elementId) {
40
- var el = createElementAndInject(elementId);
53
+ if (tapConnectInstance) {
54
+ return tapConnectInstance;
55
+ }
56
+ var el = findOrCreateElementAndInject(elementId);
41
57
  var root = createRoot(el);
42
- root.render(_jsx(TapConnect, __assign({}, props)));
43
- var unmount = function () { return root.unmount(); };
44
- return { unmount: unmount };
58
+ root.render(_jsx(TapConnect, __assign({}, props, { elementId: elementId })));
59
+ var unmount = function () {
60
+ root.unmount();
61
+ tapConnectInstance = null;
62
+ };
63
+ tapConnectInstance = { unmount: unmount };
64
+ return tapConnectInstance;
45
65
  };
@@ -31,32 +31,46 @@ var ConnectExpress = function (props) {
31
31
  setName(name);
32
32
  };
33
33
  var _c = window['TapAuth'], renderConnectExpressLib = _c.renderConnectExpressLib, renderIndividualLib = _c.renderIndividualLib, renderBankLib = _c.renderBankLib, renderTaxLib = _c.renderTaxLib, renderEntityLib = _c.renderEntityLib, renderBrandLib = _c.renderBrandLib;
34
- var elementId = 'tap-connect-sdk-lib';
34
+ var elementId = props.elementId;
35
+ var unmountComponent = function () { };
35
36
  React.useEffect(function () {
36
37
  console.log('rendering: ', name);
37
38
  var config = wrapLibConfig(__assign(__assign({}, props), { verifyToken: token, onBoardButtonClick: onButtonClick }));
38
39
  switch (name) {
39
40
  case 'brand':
40
- renderBrandLib(config, elementId);
41
+ unmountComponent();
42
+ var unmountBrand = renderBrandLib(config, elementId).unmount;
43
+ unmountComponent = unmountBrand;
41
44
  break;
42
45
  case 'tax':
43
- renderTaxLib(config, elementId);
46
+ unmountComponent();
47
+ var unmountTax = renderTaxLib(config, elementId).unmount;
48
+ unmountComponent = unmountTax;
44
49
  break;
45
50
  case 'bank':
46
- renderBankLib(config, elementId);
51
+ unmountComponent();
52
+ var unmountBank = renderBankLib(config, elementId).unmount;
53
+ unmountComponent = unmountBank;
47
54
  break;
48
55
  case 'individual':
49
- renderIndividualLib(config, elementId);
56
+ unmountComponent();
57
+ var unmountIndiv = renderIndividualLib(config, elementId).unmount;
58
+ unmountComponent = unmountIndiv;
50
59
  break;
51
60
  case 'entity':
52
- renderEntityLib(config, elementId);
61
+ unmountComponent();
62
+ var unmountEntity = renderEntityLib(config, elementId).unmount;
63
+ unmountComponent = unmountEntity;
53
64
  break;
54
65
  default:
66
+ unmountComponent();
55
67
  var onSuccess = props.onSuccess, rest = __rest(props, ["onSuccess"]);
56
68
  var configAttrs = wrapLibConfig(__assign(__assign({}, rest), { verifyToken: token, onBoardButtonClick: onButtonClick }));
57
- renderConnectExpressLib(configAttrs, elementId);
69
+ var unmountExpress = renderConnectExpressLib(configAttrs, elementId).unmount;
70
+ unmountComponent = unmountExpress;
58
71
  break;
59
72
  }
73
+ return function () { return unmountComponent(); };
60
74
  }, [
61
75
  name,
62
76
  token,
@@ -2,10 +2,11 @@ import * as React from 'react';
2
2
  import { wrapLibConfig } from '../../utils';
3
3
  var ConnectFull = function (props) {
4
4
  var renderConnectLib = window['TapAuth'].renderConnectLib;
5
- var id = 'tap-connect-sdk-lib';
5
+ var id = props.elementId;
6
6
  React.useEffect(function () {
7
7
  var config = wrapLibConfig(props);
8
- renderConnectLib(config, id);
8
+ var unmount = renderConnectLib(config, id).unmount;
9
+ return function () { return unmount(); };
9
10
  }, [renderConnectLib, props]);
10
11
  return null;
11
12
  };
@@ -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 }: ConnectProps & ExtraProps) => OriginalConnectProps;
6
+ export declare const wrapLibConfig: ({ publicKey, open, language, country, scope, lead, postURL, onError, onReady, onSuccess, board, verifyToken, domain, onBoardButtonClick, onClose, onCreated, onBoardCompleted }: ConnectProps & ExtraProps) => OriginalConnectProps;
7
7
  export {};
@@ -1,8 +1,8 @@
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;
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;
3
3
  return {
4
4
  appInfo: {
5
- name: window.location.hostname
5
+ name: window.location.hostname || window.location.origin
6
6
  },
7
7
  businessCountryCode: country,
8
8
  language: language,
@@ -32,6 +32,9 @@ export var wrapLibConfig = function (_a) {
32
32
  onClose: function () {
33
33
  onClose && onClose();
34
34
  },
35
+ onBoardCompleted: function () {
36
+ onBoardCompleted && onBoardCompleted();
37
+ },
35
38
  onStepCompleted: function (name, info) { },
36
39
  onStepStarted: function (name) { }
37
40
  };
@@ -1 +1 @@
1
- export declare const createElementAndInject: (id: string) => HTMLDivElement;
1
+ export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
@@ -1,4 +1,7 @@
1
- export var createElementAndInject = function (id) {
1
+ export var findOrCreateElementAndInject = function (id) {
2
+ var elementExist = document.getElementById(id);
3
+ if (elementExist)
4
+ return elementExist;
2
5
  var element = document.createElement('div');
3
6
  element.setAttribute('id', id || 'tap-connect-sdk-lib');
4
7
  document.body.prepend(element);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/connect",
3
- "version": "0.0.11-test",
3
+ "version": "0.0.13-test",
4
4
  "description": "Tap Connect",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",