@tap-payments/connect 0.0.0-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 +159 -0
- package/build/@types/index.d.ts +38 -0
- package/build/@types/index.js +1 -0
- package/build/constants/index.d.ts +5 -0
- package/build/constants/index.js +5 -0
- package/build/features/connect/Connect.d.ts +7 -0
- package/build/features/connect/Connect.js +45 -0
- package/build/features/connect/ConnectExpress.d.ts +4 -0
- package/build/features/connect/ConnectExpress.js +63 -0
- package/build/features/connect/ConnectFull.d.ts +4 -0
- package/build/features/connect/ConnectFull.js +28 -0
- package/build/features/connect/index.d.ts +3 -0
- package/build/features/connect/index.js +2 -0
- package/build/hooks/index.d.ts +2 -0
- package/build/hooks/index.js +2 -0
- package/build/hooks/useScript.d.ts +1 -0
- package/build/hooks/useScript.js +39 -0
- package/build/hooks/useStyle.d.ts +1 -0
- package/build/hooks/useStyle.js +13 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +7 -0
- package/build/utils/config.d.ts +10 -0
- package/build/utils/config.js +22 -0
- package/build/utils/html.d.ts +1 -0
- package/build/utils/html.js +6 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.js +3 -0
- package/build/utils/validation.d.ts +2 -0
- package/build/utils/validation.js +43 -0
- package/package.json +104 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# ConnectAuth
|
|
2
|
+
|
|
3
|
+
Handling user onboarding and authentication for Tap Payments.
|
|
4
|
+
|
|
5
|
+
## Installs
|
|
6
|
+
|
|
7
|
+
This is a [React](https://reactjs.org/) module available through the
|
|
8
|
+
[npm registry](https://www.npmjs.com/). Installation is done using the
|
|
9
|
+
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
|
10
|
+
|
|
11
|
+
```console
|
|
12
|
+
npm install @tap-payments/connect-auth
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---------------------------- OR -------------------------
|
|
16
|
+
|
|
17
|
+
```console
|
|
18
|
+
yarn add @tap-payments/connect-auth
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Examples
|
|
22
|
+
|
|
23
|
+
### Connect Library
|
|
24
|
+
|
|
25
|
+
### ES6
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { ConnectElement, Maturity } from '@tap-payments/connect-auth'
|
|
29
|
+
|
|
30
|
+
// we have two ways to use the connect element
|
|
31
|
+
// 1- full flow
|
|
32
|
+
const ConnectComponent = () => {
|
|
33
|
+
return (
|
|
34
|
+
<ConnectElement
|
|
35
|
+
// required (the public key of the merchant account provided by Tap Payments)
|
|
36
|
+
publicKey={'pk_test_lat64TEDSvHrUOYAxVRe28PQ'}
|
|
37
|
+
// required (boolean to open/close the connect element)
|
|
38
|
+
open={true}
|
|
39
|
+
// required (the country ISO2 of the merchant)
|
|
40
|
+
country={'SA'}
|
|
41
|
+
// required (Language flag to control the language of the connect element and only we support [en,ar])
|
|
42
|
+
language={'en'}
|
|
43
|
+
// required (Decide the maturity of the connect element and only we support [FULL,EXPRESS])
|
|
44
|
+
maturity={Maturity.FULL}
|
|
45
|
+
// required (the domain of the merchant)
|
|
46
|
+
merchantDomain={'https://example.com'}
|
|
47
|
+
// required (the scope of the merchant)
|
|
48
|
+
scope={'merchant'}
|
|
49
|
+
// required (callback function to handle the success response, it will run after the user finish the flow)
|
|
50
|
+
onSuccess={(data) => console.log('onSuccess', data)}
|
|
51
|
+
// optional (callback function to handle the error response, it will run if the user face any error)
|
|
52
|
+
onError={(err) => console.log('onError', err)}
|
|
53
|
+
//optional (callback function to handle the ready state of the connect element)
|
|
54
|
+
onReady={() => console.log('onReady')}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
// 2- express flow
|
|
59
|
+
const ConnectExpressComponent = () => {
|
|
60
|
+
return (
|
|
61
|
+
<ConnectElement
|
|
62
|
+
// required (the public key of the merchant account provided by Tap Payments)
|
|
63
|
+
publicKey={'pk_test_lat64TEDSvHrUOYAxVRe28PQ'}
|
|
64
|
+
// required (boolean to open/close the connect element)
|
|
65
|
+
open={true}
|
|
66
|
+
// required (the country ISO2 of the merchant)
|
|
67
|
+
country={'SA'}
|
|
68
|
+
// required (Language flag to control the language of the connect element and only we support [en,ar])
|
|
69
|
+
language={'en'}
|
|
70
|
+
// required (Decide the maturity of the connect element and only we support [FULL,EXPRESS])
|
|
71
|
+
maturity={Maturity.EXPRESS}
|
|
72
|
+
// required (the domain of the merchant)
|
|
73
|
+
merchantDomain={'https://example.com'}
|
|
74
|
+
// required (the scope of the merchant)
|
|
75
|
+
scope={'merchant'}
|
|
76
|
+
// optional (Lead Id can be passed in case of you already created a lead using our API )
|
|
77
|
+
leadId={'led_6KOZ10239353ps316c20712'}
|
|
78
|
+
// required (The POST Method URL used to push te data from our server to the merchant server)
|
|
79
|
+
postURL={'https://example.com'}
|
|
80
|
+
// required (callback function to handle the success response, it will run after the user finish the flow)
|
|
81
|
+
onSuccess={(data) => console.log('onSuccess', data)}
|
|
82
|
+
// optional (callback function to handle the error response, it will run if the user face any error)
|
|
83
|
+
onError={(err) => console.log('onError', err)}
|
|
84
|
+
//optional (callback function to handle the ready state of the connect element)
|
|
85
|
+
onReady={() => console.log('onReady')}
|
|
86
|
+
/>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Vanilla JS
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
<!DOCTYPE html>
|
|
95
|
+
<html lang="en">
|
|
96
|
+
<head>
|
|
97
|
+
<meta charset="utf-8" />
|
|
98
|
+
<meta
|
|
99
|
+
name="viewport"
|
|
100
|
+
content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no"
|
|
101
|
+
/>
|
|
102
|
+
<title>Auth-JsConnect</title>
|
|
103
|
+
<script src="https://connect-auth.b-cdn.net/build-0.0.5-test/main.js"></script>
|
|
104
|
+
</head>
|
|
105
|
+
<body>
|
|
106
|
+
<div id="root"></div>
|
|
107
|
+
<script>
|
|
108
|
+
// one our cdn script is loaded we can use the window.Connect object
|
|
109
|
+
const { renderConnect, Maturity } = window.Connect
|
|
110
|
+
let unmountConnect = null
|
|
111
|
+
const startConnectAuth = () => {
|
|
112
|
+
const { unmount } = renderConnect(
|
|
113
|
+
{
|
|
114
|
+
publicKey: 'pk_test_lat64TEDSvHrUOYAxVRe28PQ',
|
|
115
|
+
open: true,
|
|
116
|
+
country: 'SA',
|
|
117
|
+
language: 'en',
|
|
118
|
+
maturity: Maturity.EXPRESS,
|
|
119
|
+
merchantDomain: 'https://example.com',
|
|
120
|
+
scope: 'merchant',
|
|
121
|
+
postURL: 'https://example.com',
|
|
122
|
+
onSuccess: (data) => console.log('onSuccess', data),
|
|
123
|
+
onError: (err) => console.log('onError', err),
|
|
124
|
+
onReady: () => console.log('onReady')
|
|
125
|
+
},
|
|
126
|
+
'root'
|
|
127
|
+
)
|
|
128
|
+
// save the unmount function to be able to unmount the component
|
|
129
|
+
unmountConnect = unmount
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const stopConnectAuth = () => {
|
|
133
|
+
unmountConnect?.('root')
|
|
134
|
+
}
|
|
135
|
+
</script>
|
|
136
|
+
<button onclick="startConnectAuth()">Start</button>
|
|
137
|
+
<button onclick="stopConnectAuth()">Stop</button>
|
|
138
|
+
</body>
|
|
139
|
+
</html>
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Properties
|
|
144
|
+
|
|
145
|
+
| name | type | description |
|
|
146
|
+
| ------------------------- | ---------- | -------------------------------------------------------------------------------------------- | --- |
|
|
147
|
+
| publicKey `required` | `string` | the public key of the merchant account provided by Tap Payments |
|
|
148
|
+
| open `required` | `boolean` | boolean to open/close the connect element |
|
|
149
|
+
| country `required` | `string` | the country ISO2 of the merchant |
|
|
150
|
+
| language `required` | `string` | Language flag to control the language of the connect element and only accept [ar,en] |
|
|
151
|
+
| maturity `required` | `Maturity` | Decide the maturity of the connect element and only accept [FULL,EXPRESS] |
|
|
152
|
+
| merchantDomain `required` | `string` | the domain of the merchant |
|
|
153
|
+
| scope `required` | `string` | the scope of the merchant |
|
|
154
|
+
| leadId `optional` | `string` | Lead Id can be passed in case of you already created a lead using our API |
|
|
155
|
+
| postURL `required` | `string` | The POST Method URL used to push te data from our server to the merchant server |
|
|
156
|
+
| | | `postURL` is required only if `Maturity.EXPRESS` |
|
|
157
|
+
| onSuccess `required` | `function` | callback function to handle the success response, it will run after the user finish the flow |
|
|
158
|
+
| onError `optional` | `function` | callback function to handle the error response, it will run if the user face any error |
|
|
159
|
+
| onReady `optional` | `function` | callback function to handle the ready state of the connect element | s |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Maturity } from '../constants';
|
|
2
|
+
export interface ConnectProps {
|
|
3
|
+
publicKey: string;
|
|
4
|
+
open: boolean;
|
|
5
|
+
country: string;
|
|
6
|
+
language: string;
|
|
7
|
+
maturity: typeof Maturity[keyof typeof Maturity];
|
|
8
|
+
scope: string;
|
|
9
|
+
merchantDomain: string;
|
|
10
|
+
leadId?: string;
|
|
11
|
+
postURL?: string;
|
|
12
|
+
showBoard?: boolean;
|
|
13
|
+
onReady?: () => void;
|
|
14
|
+
onError?: (error: string) => void;
|
|
15
|
+
onSuccess: (res: any) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface OriginalConnectProps {
|
|
18
|
+
publicKey: string;
|
|
19
|
+
open: boolean;
|
|
20
|
+
merchantDomain: string;
|
|
21
|
+
language: string;
|
|
22
|
+
appInfo: Record<string, string>;
|
|
23
|
+
businessCountryCode: string;
|
|
24
|
+
scope: string;
|
|
25
|
+
leadId?: string;
|
|
26
|
+
postURL: string;
|
|
27
|
+
showBoard?: boolean;
|
|
28
|
+
verifyToken?: string;
|
|
29
|
+
onFlowCompleted: (res: object, headers?: Record<string, string>) => void;
|
|
30
|
+
onError: (err: any) => void;
|
|
31
|
+
onStepCompleted?: (name: string, info: any) => void;
|
|
32
|
+
onReady?: () => void;
|
|
33
|
+
onStepStarted?: (name: string) => void;
|
|
34
|
+
onFlowButtonClick?: (item: {
|
|
35
|
+
name: string;
|
|
36
|
+
token: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ConnectProps } from '../../@types';
|
|
3
|
+
export type { ConnectProps };
|
|
4
|
+
export declare const ConnectElement: React.MemoExoticComponent<(props: ConnectProps) => JSX.Element>;
|
|
5
|
+
export declare const renderConnect: (props: ConnectProps, elementId: string) => {
|
|
6
|
+
unmount: () => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { createRoot } from 'react-dom/client';
|
|
15
|
+
import { createElementAndInject, validateConnectProps } from '../../utils';
|
|
16
|
+
import { useScript, useStyle } from '../../hooks';
|
|
17
|
+
import { Maturity, CDN_LIBRARY_BASE_URL } from '../../constants';
|
|
18
|
+
import ConnectFull from './ConnectFull';
|
|
19
|
+
import ConnectExpress from './ConnectExpress';
|
|
20
|
+
var Connect = function (props) {
|
|
21
|
+
useStyle("".concat(CDN_LIBRARY_BASE_URL, "/main.css"));
|
|
22
|
+
var status = useScript("".concat(CDN_LIBRARY_BASE_URL, "/main.js"));
|
|
23
|
+
React.useEffect(function () {
|
|
24
|
+
if (status === 'ready')
|
|
25
|
+
console.info('connect-auth-js is ready!');
|
|
26
|
+
if (status === 'error')
|
|
27
|
+
console.error('connect-auth-js failed to load!');
|
|
28
|
+
}, [status]);
|
|
29
|
+
if (status !== 'ready')
|
|
30
|
+
return null;
|
|
31
|
+
if (props.maturity === Maturity.EXPRESS)
|
|
32
|
+
return _jsx(ConnectExpress, __assign({}, props));
|
|
33
|
+
return _jsx(ConnectFull, __assign({}, props));
|
|
34
|
+
};
|
|
35
|
+
export var ConnectElement = React.memo(function (props) {
|
|
36
|
+
validateConnectProps(props);
|
|
37
|
+
return _jsx(Connect, __assign({}, props));
|
|
38
|
+
});
|
|
39
|
+
export var renderConnect = function (props, elementId) {
|
|
40
|
+
var el = createElementAndInject(elementId);
|
|
41
|
+
var root = createRoot(el);
|
|
42
|
+
root.render(_jsx(ConnectElement, __assign({}, props)));
|
|
43
|
+
var unmount = function () { return root.unmount(); };
|
|
44
|
+
return { unmount: unmount };
|
|
45
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
};
|
|
12
|
+
import * as React from 'react';
|
|
13
|
+
import { wrapLibConfig } from '../../utils';
|
|
14
|
+
var ConnectExpress = function (props) {
|
|
15
|
+
var _a = React.useState(''), token = _a[0], setToken = _a[1];
|
|
16
|
+
var _b = React.useState('express'), name = _b[0], setName = _b[1];
|
|
17
|
+
var onButtonClick = function (_a) {
|
|
18
|
+
var name = _a.name, token = _a.token;
|
|
19
|
+
setToken(token);
|
|
20
|
+
setName(name);
|
|
21
|
+
};
|
|
22
|
+
var _c = window['TapAuth'], renderConnectExpressLib = _c.renderConnectExpressLib, renderIndividualLib = _c.renderIndividualLib, renderBankLib = _c.renderBankLib, renderTaxLib = _c.renderTaxLib, renderEntityLib = _c.renderEntityLib, renderBrandLib = _c.renderBrandLib;
|
|
23
|
+
var elementId = 'tap-connect-sdk-lib';
|
|
24
|
+
React.useEffect(function () {
|
|
25
|
+
console.log('rendering: ', name);
|
|
26
|
+
var config = wrapLibConfig(__assign(__assign({}, props), { verifyToken: token, onFlowButtonClick: onButtonClick }));
|
|
27
|
+
switch (name) {
|
|
28
|
+
case 'brand':
|
|
29
|
+
renderBrandLib(config, elementId);
|
|
30
|
+
break;
|
|
31
|
+
case 'tax':
|
|
32
|
+
renderTaxLib(config, elementId);
|
|
33
|
+
break;
|
|
34
|
+
case 'bank':
|
|
35
|
+
renderBankLib(config, elementId);
|
|
36
|
+
break;
|
|
37
|
+
case 'individual':
|
|
38
|
+
renderIndividualLib(config, elementId);
|
|
39
|
+
break;
|
|
40
|
+
case 'entity':
|
|
41
|
+
renderEntityLib(config, elementId);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
renderConnectExpressLib(config, elementId);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}, [
|
|
48
|
+
name,
|
|
49
|
+
token,
|
|
50
|
+
renderConnectExpressLib,
|
|
51
|
+
renderIndividualLib,
|
|
52
|
+
renderBankLib,
|
|
53
|
+
renderTaxLib,
|
|
54
|
+
renderEntityLib,
|
|
55
|
+
renderBrandLib,
|
|
56
|
+
props,
|
|
57
|
+
elementId,
|
|
58
|
+
onButtonClick,
|
|
59
|
+
wrapLibConfig
|
|
60
|
+
]);
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
export default React.memo(ConnectExpress);
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { createElementAndInject } from '../../utils';
|
|
15
|
+
var ConnectFull = function (props) {
|
|
16
|
+
var renderConnectLib = window['TapAuth'].renderConnectLib;
|
|
17
|
+
var id = 'tap-connect-sdk-lib';
|
|
18
|
+
React.useEffect(function () {
|
|
19
|
+
var config = __assign(__assign({}, props), { appInfo: { name: window.location.hostname } });
|
|
20
|
+
if (!renderConnectLib)
|
|
21
|
+
return;
|
|
22
|
+
var el = createElementAndInject(id);
|
|
23
|
+
var unmount = renderConnectLib(el, props).unmount;
|
|
24
|
+
return function () { return unmount(); };
|
|
25
|
+
}, [renderConnectLib]);
|
|
26
|
+
return _jsx("div", { id: id });
|
|
27
|
+
};
|
|
28
|
+
export default React.memo(ConnectFull);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScript(src: string, async?: boolean): "ready" | "loading" | "idle" | "error";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export function useScript(src, async) {
|
|
3
|
+
if (async === void 0) { async = true; }
|
|
4
|
+
var _a = useState(src ? 'loading' : 'idle'), status = _a[0], setStatus = _a[1];
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
if (!src) {
|
|
7
|
+
setStatus('idle');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var script = document.querySelector("script[src=\"".concat(src, "\"]"));
|
|
11
|
+
if (!script) {
|
|
12
|
+
script = document.createElement('script');
|
|
13
|
+
script.src = src;
|
|
14
|
+
script.async = async;
|
|
15
|
+
script.setAttribute('data-status', 'loading');
|
|
16
|
+
document.body.appendChild(script);
|
|
17
|
+
var setAttributeFromEvent = function (event) {
|
|
18
|
+
script.setAttribute('data-status', event.type === 'load' ? 'ready' : 'error');
|
|
19
|
+
};
|
|
20
|
+
script.addEventListener('load', setAttributeFromEvent);
|
|
21
|
+
script.addEventListener('error', setAttributeFromEvent);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
setStatus(script.getAttribute('data-status'));
|
|
25
|
+
}
|
|
26
|
+
var setStateFromEvent = function (event) {
|
|
27
|
+
setStatus(event.type === 'load' ? 'ready' : 'error');
|
|
28
|
+
};
|
|
29
|
+
script.addEventListener('load', setStateFromEvent);
|
|
30
|
+
script.addEventListener('error', setStateFromEvent);
|
|
31
|
+
return function () {
|
|
32
|
+
if (script) {
|
|
33
|
+
script.removeEventListener('load', setStateFromEvent);
|
|
34
|
+
script.removeEventListener('error', setStateFromEvent);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, [src]);
|
|
38
|
+
return status;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useStyle: (url: string) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export var useStyle = function (url) {
|
|
3
|
+
useEffect(function () {
|
|
4
|
+
var link = document.createElement('link');
|
|
5
|
+
link.href = url;
|
|
6
|
+
link.rel = 'stylesheet';
|
|
7
|
+
link.type = 'text/css';
|
|
8
|
+
document.head.appendChild(link);
|
|
9
|
+
return function () {
|
|
10
|
+
document.head.removeChild(link);
|
|
11
|
+
};
|
|
12
|
+
}, [url]);
|
|
13
|
+
};
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConnectProps, OriginalConnectProps } from '../@types';
|
|
2
|
+
type ExtraProps = {
|
|
3
|
+
verifyToken?: string;
|
|
4
|
+
onFlowButtonClick?: (item: {
|
|
5
|
+
name: string;
|
|
6
|
+
token: string;
|
|
7
|
+
}) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const wrapLibConfig: ({ country, language, merchantDomain, onSuccess, open, publicKey, scope, leadId, onError, onReady, postURL, showBoard, verifyToken, onFlowButtonClick }: ConnectProps & ExtraProps) => OriginalConnectProps;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export var wrapLibConfig = function (_a) {
|
|
2
|
+
var country = _a.country, language = _a.language, merchantDomain = _a.merchantDomain, onSuccess = _a.onSuccess, open = _a.open, publicKey = _a.publicKey, scope = _a.scope, leadId = _a.leadId, onError = _a.onError, onReady = _a.onReady, postURL = _a.postURL, showBoard = _a.showBoard, verifyToken = _a.verifyToken, onFlowButtonClick = _a.onFlowButtonClick;
|
|
3
|
+
return {
|
|
4
|
+
publicKey: publicKey,
|
|
5
|
+
open: open,
|
|
6
|
+
language: language,
|
|
7
|
+
merchantDomain: merchantDomain,
|
|
8
|
+
appInfo: {
|
|
9
|
+
name: window.location.hostname
|
|
10
|
+
},
|
|
11
|
+
businessCountryCode: country,
|
|
12
|
+
scope: scope,
|
|
13
|
+
leadId: leadId,
|
|
14
|
+
postURL: postURL,
|
|
15
|
+
showBoard: showBoard,
|
|
16
|
+
verifyToken: verifyToken,
|
|
17
|
+
onFlowCompleted: function (res) { return onSuccess(res); },
|
|
18
|
+
onError: function (err) { return onError === null || onError === void 0 ? void 0 : onError(err); },
|
|
19
|
+
onReady: function () { return onReady === null || onReady === void 0 ? void 0 : onReady(); },
|
|
20
|
+
onFlowButtonClick: function (item) { return onFlowButtonClick === null || onFlowButtonClick === void 0 ? void 0 : onFlowButtonClick(item); }
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createElementAndInject: (id: string) => HTMLDivElement;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Maturity } from '../constants';
|
|
2
|
+
export var validateConnectProps = function (props) {
|
|
3
|
+
var publicKey = props.publicKey, maturity = props.maturity, country = props.country, language = props.language, scope = props.scope, open = props.open, onSuccess = props.onSuccess, leadId = props.leadId, merchantDomain = props.merchantDomain, onError = props.onError, onReady = props.onReady, postURL = props.postURL;
|
|
4
|
+
if (!publicKey) {
|
|
5
|
+
throw new Error('publicKey is required');
|
|
6
|
+
}
|
|
7
|
+
if (!maturity) {
|
|
8
|
+
throw new Error('maturity is required');
|
|
9
|
+
}
|
|
10
|
+
if (![Maturity.EXPRESS, Maturity.FULL].includes(maturity)) {
|
|
11
|
+
throw new Error('maturity is invalid');
|
|
12
|
+
}
|
|
13
|
+
if (!country) {
|
|
14
|
+
throw new Error('country is required');
|
|
15
|
+
}
|
|
16
|
+
if (!language) {
|
|
17
|
+
throw new Error('language is required');
|
|
18
|
+
}
|
|
19
|
+
if (!scope) {
|
|
20
|
+
throw new Error('scope is required');
|
|
21
|
+
}
|
|
22
|
+
if (!merchantDomain) {
|
|
23
|
+
throw new Error('merchantDomain is required');
|
|
24
|
+
}
|
|
25
|
+
if (typeof open !== 'boolean') {
|
|
26
|
+
throw new Error('open is required, and must be a boolean');
|
|
27
|
+
}
|
|
28
|
+
if (typeof onSuccess !== 'function') {
|
|
29
|
+
throw new Error('onSuccess is required, and must be a function');
|
|
30
|
+
}
|
|
31
|
+
if (leadId && typeof leadId !== 'string') {
|
|
32
|
+
throw new Error('leadId must be a string');
|
|
33
|
+
}
|
|
34
|
+
if (postURL && typeof postURL !== 'string') {
|
|
35
|
+
throw new Error('postURL must be a string');
|
|
36
|
+
}
|
|
37
|
+
if (onError && typeof onError !== 'function') {
|
|
38
|
+
throw new Error('onError must be a function');
|
|
39
|
+
}
|
|
40
|
+
if (onReady && typeof onReady !== 'function') {
|
|
41
|
+
throw new Error('onReady must be a function');
|
|
42
|
+
}
|
|
43
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tap-payments/connect",
|
|
3
|
+
"version": "0.0.0-test",
|
|
4
|
+
"description": "Tap Connect",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"module": "build/index.js",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"build",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"husky:setup": "npx husky install",
|
|
14
|
+
"prettier": "prettier --list-different \"src/**/*.{md,mdx,ts,js,tsx,jsx,json}\" *.json *.js",
|
|
15
|
+
"prettier:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md,css,json}\" *.json *.js",
|
|
16
|
+
"lint": "eslint src --color --ext .js,.jsx,.ts,.tsx,.json",
|
|
17
|
+
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
18
|
+
"start": "cross-env NODE_ENV=development webpack serve",
|
|
19
|
+
"build": "cross-env NODE_ENV=production webpack",
|
|
20
|
+
"copy:files": "copyfiles -u 1 src/**/*.css build/",
|
|
21
|
+
"tsc:alias": "tsc-alias -p tsconfig.json",
|
|
22
|
+
"ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
|
|
23
|
+
"push": "npm publish --access public"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Ahmed Elsharkawy",
|
|
28
|
+
"email": "a.elsharkawy@tap.company"
|
|
29
|
+
},
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@babel/core": "^7.18.6",
|
|
33
|
+
"@babel/preset-env": "^7.18.6",
|
|
34
|
+
"@babel/preset-react": "^7.18.6",
|
|
35
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
36
|
+
"@types/crypto-js": "^4.1.1",
|
|
37
|
+
"@types/react": "^18.0.15",
|
|
38
|
+
"@types/react-dom": "^18.0.6",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
40
|
+
"@typescript-eslint/parser": "^5.30.5",
|
|
41
|
+
"babel-loader": "^8.2.5",
|
|
42
|
+
"copyfiles": "^2.4.1",
|
|
43
|
+
"cross-env": "^7.0.3",
|
|
44
|
+
"css-loader": "^6.7.1",
|
|
45
|
+
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
46
|
+
"eslint": "^8.19.0",
|
|
47
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
48
|
+
"eslint-config-prettier": "^8.5.0",
|
|
49
|
+
"eslint-plugin-import": "^2.26.0",
|
|
50
|
+
"eslint-plugin-jsx-a11y": "^6.6.0",
|
|
51
|
+
"eslint-plugin-node": "^11.1.0",
|
|
52
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
53
|
+
"eslint-plugin-react": "^7.30.1",
|
|
54
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
55
|
+
"file-loader": "^6.2.0",
|
|
56
|
+
"fork-ts-checker-webpack-plugin": "^7.2.12",
|
|
57
|
+
"html-loader": "^3.1.2",
|
|
58
|
+
"html-webpack-plugin": "^5.5.0",
|
|
59
|
+
"husky": "^8.0.1",
|
|
60
|
+
"lint-staged": "^13.0.3",
|
|
61
|
+
"mini-css-extract-plugin": "^2.6.1",
|
|
62
|
+
"prettier": "^2.7.1",
|
|
63
|
+
"sass": "^1.53.0",
|
|
64
|
+
"sass-loader": "^13.0.2",
|
|
65
|
+
"style-loader": "^3.3.1",
|
|
66
|
+
"terser-webpack-plugin": "^5.3.3",
|
|
67
|
+
"tsc-alias": "^1.6.11",
|
|
68
|
+
"typescript": "^4.7.4",
|
|
69
|
+
"webpack": "^5.73.0",
|
|
70
|
+
"webpack-cli": "^4.10.0",
|
|
71
|
+
"webpack-dev-server": "^4.9.3",
|
|
72
|
+
"webpack-merge": "^5.8.0"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@tap-payments/auth-jsconnect": "2.1.23-test",
|
|
76
|
+
"react": "^18.2.0",
|
|
77
|
+
"react-dom": "^18.2.0"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"@types/react": ">=18.0.15",
|
|
81
|
+
"@types/react-dom": ">=18.0.6",
|
|
82
|
+
"react": ">=18.2.0",
|
|
83
|
+
"react-dom": ">=18.2.0"
|
|
84
|
+
},
|
|
85
|
+
"lint-staged": {
|
|
86
|
+
"src/**/*.{ts,tsx,json,js,jsx}": [
|
|
87
|
+
"yarn run prettier:fix",
|
|
88
|
+
"yarn run lint",
|
|
89
|
+
"git add ."
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"browserslist": {
|
|
93
|
+
"production": [
|
|
94
|
+
">0.2%",
|
|
95
|
+
"not dead",
|
|
96
|
+
"not op_mini all"
|
|
97
|
+
],
|
|
98
|
+
"development": [
|
|
99
|
+
"last 1 chrome version",
|
|
100
|
+
"last 1 firefox version",
|
|
101
|
+
"last 1 safari version"
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
}
|