@tap-payments/connect-v2 0.0.1-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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/build/App.d.ts +2 -0
  4. package/build/App.js +24 -0
  5. package/build/components/loader/Loader.d.ts +9 -0
  6. package/build/components/loader/Loader.js +24 -0
  7. package/build/components/loader/index.d.ts +2 -0
  8. package/build/components/loader/index.js +2 -0
  9. package/build/connect/Connect.d.ts +4 -0
  10. package/build/connect/Connect.js +24 -0
  11. package/build/connect/ConnectIFrame.d.ts +5 -0
  12. package/build/connect/ConnectIFrame.js +16 -0
  13. package/build/connect/index.d.ts +3 -0
  14. package/build/connect/index.js +3 -0
  15. package/build/connect/renderConnectElement.d.ts +5 -0
  16. package/build/connect/renderConnectElement.js +12 -0
  17. package/build/constants.d.ts +3 -0
  18. package/build/constants.js +5 -0
  19. package/build/context/index.d.ts +15 -0
  20. package/build/context/index.js +14 -0
  21. package/build/hooks/index.d.ts +5 -0
  22. package/build/hooks/index.js +5 -0
  23. package/build/hooks/useConfig.d.ts +4 -0
  24. package/build/hooks/useConfig.js +50 -0
  25. package/build/hooks/useEventListener.d.ts +2 -0
  26. package/build/hooks/useEventListener.js +38 -0
  27. package/build/hooks/usePostEvents.d.ts +5 -0
  28. package/build/hooks/usePostEvents.js +11 -0
  29. package/build/hooks/useStopScrolling.d.ts +2 -0
  30. package/build/hooks/useStopScrolling.js +16 -0
  31. package/build/index.d.ts +4 -0
  32. package/build/index.js +2 -0
  33. package/build/main.d.ts +1 -0
  34. package/build/main.js +4 -0
  35. package/build/types/app.d.ts +67 -0
  36. package/build/types/app.js +16 -0
  37. package/build/types/events.d.ts +7 -0
  38. package/build/types/events.js +8 -0
  39. package/build/types/index.d.ts +4 -0
  40. package/build/types/index.js +4 -0
  41. package/build/types/searchParams.d.ts +5 -0
  42. package/build/types/searchParams.js +6 -0
  43. package/build/types/theme.d.ts +18 -0
  44. package/build/types/theme.js +22 -0
  45. package/build/utils.d.ts +1 -0
  46. package/build/utils.js +9 -0
  47. package/build/vite.config.d.ts +2 -0
  48. package/build/vite.config.js +38 -0
  49. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tap Payments
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## Expanding the ESLint configuration
11
+
12
+ If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13
+
14
+ - Configure the top-level `parserOptions` property like this:
15
+
16
+ ```js
17
+ export default tseslint.config({
18
+ languageOptions: {
19
+ // other options...
20
+ parserOptions: {
21
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
22
+ tsconfigRootDir: import.meta.dirname,
23
+ },
24
+ },
25
+ });
26
+ ```
27
+
28
+ - Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29
+ - Optionally add `...tseslint.configs.stylisticTypeChecked`
30
+ - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
31
+
32
+ ```js
33
+ // eslint.config.js
34
+ import react from 'eslint-plugin-react';
35
+
36
+ export default tseslint.config({
37
+ // Set the react version
38
+ settings: { react: { version: '18.3' } },
39
+ plugins: {
40
+ // Add the react plugin
41
+ react,
42
+ },
43
+ rules: {
44
+ // other rules...
45
+ // Enable its recommended rules
46
+ ...react.configs.recommended.rules,
47
+ ...react.configs['jsx-runtime'].rules,
48
+ },
49
+ });
50
+ ```
package/build/App.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function App(): import("react/jsx-runtime").JSX.Element;
2
+ export default App;
package/build/App.js ADDED
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { ConnectMode, ConnectScope, DialogTransition, ThemeMode } from './types';
4
+ import { ConnectElement } from './connect';
5
+ function App() {
6
+ const [open, setOpen] = React.useState(true);
7
+ return (_jsx(ConnectElement, { open: open, mode: ConnectMode.POPUP, publicKey: 'pk_test_lat64TEDSvHrUOYAxVRe28PQ', merchantDomain: 'https://connect.dev.tap.company', appInfo: { name: 'SDK V2' }, scope: ConnectScope.MERCHANT, theme: ThemeMode.LIGHT, features: {
8
+ closeButton: true,
9
+ poweredBy: true,
10
+ merchantLogo: false,
11
+ dialogStartTransition: DialogTransition.UP,
12
+ dialogEndTransition: DialogTransition.DOWN,
13
+ }, postURL: 'https://203zq.wiremockapi.cloud/json', showBoard: true, boardMaturity: true, onClose: () => {
14
+ console.log('onClose');
15
+ setOpen(false);
16
+ }, onError: (err) => {
17
+ console.log('error', err);
18
+ setOpen(false);
19
+ }, onSuccess: (res) => {
20
+ console.log('success', res);
21
+ setOpen(false);
22
+ } }));
23
+ }
24
+ export default App;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ type LoaderProps = {
3
+ outerColor?: string;
4
+ innerColor?: string;
5
+ duration?: number;
6
+ toggleAnimation?: boolean;
7
+ };
8
+ declare const _default: React.MemoExoticComponent<({ outerColor, innerColor, duration, toggleAnimation }: LoaderProps) => import("react/jsx-runtime").JSX.Element>;
9
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ const Loader = ({ outerColor = 'white', innerColor = 'white', duration = 3, toggleAnimation = false }) => {
4
+ return (_jsx("div", { style: {
5
+ position: 'absolute',
6
+ display: 'flex',
7
+ justifyContent: 'center',
8
+ alignItems: 'center',
9
+ width: '100%',
10
+ height: '100%',
11
+ background: 'rgba(0,0,0,0.75)',
12
+ }, children: _jsx("div", { style: {
13
+ position: 'relative',
14
+ width: '60px',
15
+ height: '60px',
16
+ }, children: _jsxs("svg", { viewBox: "25 25 50 50", style: {
17
+ transformOrigin: 'center center',
18
+ position: 'absolute',
19
+ top: 0,
20
+ left: 0,
21
+ margin: 'auto',
22
+ }, children: [_jsx("circle", { cx: "50", cy: "50", r: "20", fill: "none", stroke: outerColor, strokeWidth: "3.6px", strokeLinecap: "round", strokeDasharray: "125, 124", children: toggleAnimation && (_jsxs(_Fragment, { children: [_jsx("animateTransform", { attributeName: "transform", type: "rotate", from: "0 50 50", to: "360 50 50", dur: `${duration || 0 / 3}s`, repeatCount: "indefinite" }), _jsx("animate", { attributeName: "stroke-dashoffset", values: "0; 122; 122; 0; 0", keyTimes: "0; 0.45; 0.55; 0.9; 1", dur: `${duration}s`, repeatCount: "indefinite" })] })) }), _jsx("circle", { cx: "50", cy: "50", r: "14", fill: "none", stroke: innerColor, strokeWidth: "3.6px", strokeLinecap: "round", strokeDasharray: "88, 124", children: toggleAnimation && (_jsxs(_Fragment, { children: [_jsx("animateTransform", { attributeName: "transform", type: "rotate", from: "360 50 50", to: "0 50 50", dur: `${duration || 0 / 3}s`, repeatCount: "indefinite" }), _jsx("animate", { attributeName: "stroke-dashoffset", values: "0; -85; -85; 0; 0", keyTimes: "0; 0.45; 0.55; 0.9; 1", dur: `${duration}s`, repeatCount: "indefinite" })] })) })] }) }) }));
23
+ };
24
+ export default React.memo(Loader);
@@ -0,0 +1,2 @@
1
+ import Loader from './Loader';
2
+ export default Loader;
@@ -0,0 +1,2 @@
1
+ import Loader from './Loader';
2
+ export default Loader;
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { ConnectProps } from '../types';
3
+ declare const _default: React.MemoExoticComponent<(props: ConnectProps) => import("react/jsx-runtime").JSX.Element>;
4
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import ConnectIFrame from './ConnectIFrame';
4
+ import ConnectContextProvider from '../context';
5
+ import { useEventListener, useConfig } from '../hooks';
6
+ const Connect = () => {
7
+ const { connectLink } = useConfig();
8
+ useEventListener();
9
+ return (_jsx("div", { id: "tap-connect-main-container", style: {
10
+ display: 'flex',
11
+ alignItems: 'center',
12
+ justifyContent: 'center',
13
+ background: 'rgba(0, 0, 0, 0.6)',
14
+ position: 'fixed',
15
+ top: 0,
16
+ left: 0,
17
+ width: '100%',
18
+ height: '100%',
19
+ }, children: _jsx(ConnectIFrame, { src: connectLink }) }));
20
+ };
21
+ const ConnectElement = (props) => {
22
+ return _jsx(ConnectContextProvider, { props: props, children: props.open && _jsx(Connect, {}) });
23
+ };
24
+ export default React.memo(ConnectElement);
@@ -0,0 +1,5 @@
1
+ type props = {
2
+ src: string;
3
+ };
4
+ declare const ConnectIFrame: ({ src }: props) => import("react/jsx-runtime").JSX.Element;
5
+ export default ConnectIFrame;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Loader from '../components/loader';
3
+ import { useConnectContext } from '../context';
4
+ import { CONNECT_IFRAME_ID } from '../constants';
5
+ const ConnectIFrame = ({ src }) => {
6
+ const { loading } = useConnectContext();
7
+ return (_jsxs(_Fragment, { children: [loading && _jsx(Loader, { toggleAnimation: true }), src && (_jsx("iframe", { id: CONNECT_IFRAME_ID, title: "connect", src: src, style: {
8
+ width: '100%',
9
+ height: '100%',
10
+ border: 'none',
11
+ position: 'absolute',
12
+ top: 0,
13
+ left: 0,
14
+ } }))] }));
15
+ };
16
+ export default ConnectIFrame;
@@ -0,0 +1,3 @@
1
+ import ConnectElement from './Connect';
2
+ import renderConnectElement from './renderConnectElement';
3
+ export { ConnectElement, renderConnectElement };
@@ -0,0 +1,3 @@
1
+ import ConnectElement from './Connect';
2
+ import renderConnectElement from './renderConnectElement';
3
+ export { ConnectElement, renderConnectElement };
@@ -0,0 +1,5 @@
1
+ import { ConnectProps } from '../types';
2
+ declare const renderConnectElement: (elementId: string, config: ConnectProps) => {
3
+ unmount: () => void;
4
+ };
5
+ export default renderConnectElement;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createRoot } from 'react-dom/client';
3
+ import ConnectElement from './Connect';
4
+ import { findOrCreateElementAndInject } from '../utils';
5
+ const renderConnectElement = (elementId, config) => {
6
+ const element = findOrCreateElementAndInject(elementId);
7
+ const root = createRoot(element);
8
+ root.render(_jsx(ConnectElement, { ...config }));
9
+ const unmount = () => root.unmount();
10
+ return { unmount };
11
+ };
12
+ export default renderConnectElement;
@@ -0,0 +1,3 @@
1
+ export declare const CONNECT_CONFIG_URL = "https://68b564fae5dc090291aeddd7.mockapi.io/api/config";
2
+ export declare const CONNECT_IFRAME_ID = "tap-connect-sdk-iframe";
3
+ export declare const CONNECT_ORIGIN: string;
@@ -0,0 +1,5 @@
1
+ // TODO: Add URL (should it be env variables based on the enviornment?)
2
+ // Added mock up api until api ready from Backend
3
+ export const CONNECT_CONFIG_URL = 'https://68b564fae5dc090291aeddd7.mockapi.io/api/config';
4
+ export const CONNECT_IFRAME_ID = 'tap-connect-sdk-iframe';
5
+ export const CONNECT_ORIGIN = import.meta.env.VITE_CONNECT_ORIGIN ?? 'https://connect.alpha.tap.company';
@@ -0,0 +1,15 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ConnectProps } from '../types';
3
+ type ConnectContextProps = ConnectProps & {
4
+ onLoaded: () => void;
5
+ loading: boolean;
6
+ onLoadingHandler: (val: boolean) => void;
7
+ };
8
+ export declare const ConnectContext: React.Context<ConnectContextProps>;
9
+ export declare const useConnectContext: () => ConnectContextProps;
10
+ type ConnectContextProvider = {
11
+ children: ReactNode;
12
+ props: ConnectProps;
13
+ };
14
+ export default function ConnectContextProvider({ children, props }: ConnectContextProvider): import("react/jsx-runtime").JSX.Element;
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ export const ConnectContext = React.createContext({});
4
+ export const useConnectContext = () => React.useContext(ConnectContext);
5
+ export default function ConnectContextProvider({ children, props }) {
6
+ const [loading, setLoading] = React.useState(false);
7
+ const onLoadingHandler = (val) => {
8
+ setLoading(val);
9
+ };
10
+ const onLoaded = () => {
11
+ setLoading(false);
12
+ };
13
+ return (_jsx(ConnectContext.Provider, { value: { ...props, onLoadingHandler, loading, onLoaded }, children: children }));
14
+ }
@@ -0,0 +1,5 @@
1
+ import useConfig from './useConfig';
2
+ import useStopScrolling from './useStopScrolling';
3
+ import useEventListener from './useEventListener';
4
+ import usePostEvents from './usePostEvents';
5
+ export { useStopScrolling, useEventListener, useConfig, usePostEvents };
@@ -0,0 +1,5 @@
1
+ import useConfig from './useConfig';
2
+ import useStopScrolling from './useStopScrolling';
3
+ import useEventListener from './useEventListener';
4
+ import usePostEvents from './usePostEvents';
5
+ export { useStopScrolling, useEventListener, useConfig, usePostEvents };
@@ -0,0 +1,4 @@
1
+ declare const useConfig: () => {
2
+ connectLink: string;
3
+ };
4
+ export default useConfig;
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import { WebErrorHandler } from '@tap-payments/web-error-handing';
3
+ import { ConnectMode, SearchParams } from '../types';
4
+ import { useConnectContext } from '../context';
5
+ import { CONNECT_CONFIG_URL, CONNECT_ORIGIN } from '../constants';
6
+ const useConfig = () => {
7
+ const [connectLink, setConnectLink] = React.useState('');
8
+ const { onError, onLoadingHandler, ...config } = useConnectContext();
9
+ const generateConfig = async () => {
10
+ onLoadingHandler(true);
11
+ try {
12
+ // TODO: Do we need further headers/data for the iframe scenario
13
+ // TODO: Add proper type for the response
14
+ const response = await fetch(CONNECT_CONFIG_URL, {
15
+ method: 'POST',
16
+ headers: {
17
+ 'Content-Type': 'application/json',
18
+ },
19
+ body: JSON.stringify(config),
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(`${response.status}::${response.statusText}`);
23
+ }
24
+ const data = await response.json();
25
+ // TODO: Adding for testing only
26
+ if (!data.redirect_url) {
27
+ const params = new URLSearchParams();
28
+ if (config?.theme)
29
+ params.append(SearchParams.THEME, config.theme);
30
+ if (config?.language)
31
+ params.append(SearchParams.LANGUAGE, config.language);
32
+ params.append(SearchParams.PROFILE_TOKEN, data.id);
33
+ data.redirect_url = `${CONNECT_ORIGIN}?${params.toString()}`;
34
+ }
35
+ if (config.mode !== ConnectMode.PAGE)
36
+ return setConnectLink(data.redirect_url);
37
+ window.location.href = data.redirect_url;
38
+ }
39
+ catch (error) {
40
+ const customError = new WebErrorHandler(error);
41
+ onError?.(customError.getClientError());
42
+ onLoadingHandler(false);
43
+ }
44
+ };
45
+ React.useEffect(() => {
46
+ generateConfig();
47
+ }, []);
48
+ return { connectLink };
49
+ };
50
+ export default useConfig;
@@ -0,0 +1,2 @@
1
+ declare const useEventListener: () => void;
2
+ export default useEventListener;
@@ -0,0 +1,38 @@
1
+ import * as React from 'react';
2
+ import { ConnectEvents } from '../types';
3
+ import { CONNECT_ORIGIN } from '../constants';
4
+ import { useConnectContext } from '../context';
5
+ const useEventListener = () => {
6
+ const { onSuccess, onClose, onError, onReady, onLoaded } = useConnectContext();
7
+ const handleEvent = React.useCallback(async (message) => {
8
+ if (message.origin !== CONNECT_ORIGIN)
9
+ return;
10
+ const { data, event } = message.data;
11
+ switch (event) {
12
+ case ConnectEvents.ON_CLOSE:
13
+ onClose?.();
14
+ break;
15
+ case ConnectEvents.ON_ERROR:
16
+ onError?.(data);
17
+ break;
18
+ case ConnectEvents.ON_SUCCESS:
19
+ onSuccess(data);
20
+ break;
21
+ case ConnectEvents.ON_LOADED:
22
+ onLoaded();
23
+ break;
24
+ case ConnectEvents.ON_READY:
25
+ onReady?.();
26
+ break;
27
+ default:
28
+ break;
29
+ }
30
+ }, [onClose, onError, onLoaded, onReady, onSuccess]);
31
+ React.useEffect(() => {
32
+ window.addEventListener('message', handleEvent, false);
33
+ return () => {
34
+ window.removeEventListener('message', handleEvent);
35
+ };
36
+ }, [handleEvent]);
37
+ };
38
+ export default useEventListener;
@@ -0,0 +1,5 @@
1
+ import { ConnectEvents } from '../types';
2
+ declare const usePostEvents: () => {
3
+ send: <T>(event: ConnectEvents, data: T) => void;
4
+ };
5
+ export default usePostEvents;
@@ -0,0 +1,11 @@
1
+ import { CONNECT_IFRAME_ID } from '../constants';
2
+ const usePostEvents = () => {
3
+ const send = (event, data) => {
4
+ const iframeEl = document.getElementById(CONNECT_IFRAME_ID);
5
+ if (!iframeEl)
6
+ return;
7
+ iframeEl.contentWindow?.postMessage({ event, data });
8
+ };
9
+ return { send };
10
+ };
11
+ export default usePostEvents;
@@ -0,0 +1,2 @@
1
+ declare const useStopScrolling: () => void;
2
+ export default useStopScrolling;
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ const useStopScrolling = () => {
3
+ const stopScrolling = () => {
4
+ document.body.style.overflow = 'hidden';
5
+ };
6
+ const startScrolling = () => {
7
+ document.body.style.overflow = 'auto';
8
+ };
9
+ React.useEffect(() => {
10
+ stopScrolling();
11
+ return () => {
12
+ startScrolling();
13
+ };
14
+ }, []);
15
+ };
16
+ export default useStopScrolling;
@@ -0,0 +1,4 @@
1
+ import { ConnectProps, ConnectMode, ThemeMode, LanguageMode, AppInfo, ConnectScope, PaymentProvider, DialogTransition, DialogEdgeFormat, SDKNotification, PASSWORD_OPERATION_TYPE } from './types';
2
+ import { ConnectElement, renderConnectElement } from './connect';
3
+ export type { ConnectProps, ConnectMode, ThemeMode, LanguageMode, AppInfo, ConnectScope, PaymentProvider, DialogTransition, DialogEdgeFormat, SDKNotification, PASSWORD_OPERATION_TYPE, };
4
+ export { ConnectElement, renderConnectElement };
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { ConnectElement, renderConnectElement } from './connect';
2
+ export { ConnectElement, renderConnectElement };
@@ -0,0 +1 @@
1
+ export {};
package/build/main.js ADDED
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createRoot } from 'react-dom/client';
3
+ import App from './App';
4
+ createRoot(document.getElementById('root')).render(_jsx(App, {}));
@@ -0,0 +1,67 @@
1
+ import { DialogEdgeFormat, DialogTransition, LanguageMode, ThemeMode } from './theme';
2
+ export type CustomError = {
3
+ code: string;
4
+ message: string;
5
+ };
6
+ export type AppInfo = {
7
+ name: string;
8
+ identifier?: string;
9
+ version?: string;
10
+ };
11
+ export type PaymentProvider = {
12
+ technology_id: string;
13
+ settlement_by: string;
14
+ };
15
+ export type SDKNotification = {
16
+ email: boolean;
17
+ mobile?: boolean;
18
+ };
19
+ export declare enum ConnectMode {
20
+ PAGE = "page",
21
+ POPUP = "popup",
22
+ CONTENT = "content"
23
+ }
24
+ export declare enum ConnectScope {
25
+ AUTH = "auth",
26
+ MERCHANT = "merchant"
27
+ }
28
+ export declare enum PASSWORD_OPERATION_TYPE {
29
+ SET_PASSWORD = "set_password",
30
+ RESET_PASSWORD = "reset_password"
31
+ }
32
+ export type ConnectProps = {
33
+ onClose?: () => void;
34
+ onSuccess: (res: Record<string, string | number>) => void;
35
+ onError?: (error: CustomError) => void;
36
+ onReady?: () => void;
37
+ open: boolean;
38
+ theme?: ThemeMode;
39
+ language?: LanguageMode;
40
+ publicKey: string;
41
+ merchantDomain: string;
42
+ appInfo: AppInfo;
43
+ businessCountryCode?: string;
44
+ scope: ConnectScope;
45
+ showBoard?: boolean;
46
+ platforms?: Array<string>;
47
+ paymentProvider?: PaymentProvider;
48
+ features?: {
49
+ poweredBy?: boolean;
50
+ merchantLogo?: boolean;
51
+ closeButton?: boolean;
52
+ dialogStartTransition?: DialogTransition;
53
+ dialogEndTransition?: DialogTransition;
54
+ dialogEdgeFormat?: DialogEdgeFormat;
55
+ };
56
+ postURL?: string;
57
+ redirectUrl?: string;
58
+ data?: Array<string>;
59
+ mode?: ConnectMode;
60
+ notification?: SDKNotification;
61
+ boardMaturity?: boolean;
62
+ boardId?: string;
63
+ boardInfoId?: string;
64
+ userId?: string;
65
+ userType?: string;
66
+ operationType?: PASSWORD_OPERATION_TYPE;
67
+ };
@@ -0,0 +1,16 @@
1
+ export var ConnectMode;
2
+ (function (ConnectMode) {
3
+ ConnectMode["PAGE"] = "page";
4
+ ConnectMode["POPUP"] = "popup";
5
+ ConnectMode["CONTENT"] = "content";
6
+ })(ConnectMode || (ConnectMode = {}));
7
+ export var ConnectScope;
8
+ (function (ConnectScope) {
9
+ ConnectScope["AUTH"] = "auth";
10
+ ConnectScope["MERCHANT"] = "merchant";
11
+ })(ConnectScope || (ConnectScope = {}));
12
+ export var PASSWORD_OPERATION_TYPE;
13
+ (function (PASSWORD_OPERATION_TYPE) {
14
+ PASSWORD_OPERATION_TYPE["SET_PASSWORD"] = "set_password";
15
+ PASSWORD_OPERATION_TYPE["RESET_PASSWORD"] = "reset_password";
16
+ })(PASSWORD_OPERATION_TYPE || (PASSWORD_OPERATION_TYPE = {}));
@@ -0,0 +1,7 @@
1
+ export declare enum ConnectEvents {
2
+ ON_CLOSE = "connect:onClose",
3
+ ON_ERROR = "connect:onError",
4
+ ON_SUCCESS = "connect:onSuccess",
5
+ ON_READY = "connect:onReady",
6
+ ON_LOADED = "connect:onLoaded"
7
+ }
@@ -0,0 +1,8 @@
1
+ export var ConnectEvents;
2
+ (function (ConnectEvents) {
3
+ ConnectEvents["ON_CLOSE"] = "connect:onClose";
4
+ ConnectEvents["ON_ERROR"] = "connect:onError";
5
+ ConnectEvents["ON_SUCCESS"] = "connect:onSuccess";
6
+ ConnectEvents["ON_READY"] = "connect:onReady";
7
+ ConnectEvents["ON_LOADED"] = "connect:onLoaded";
8
+ })(ConnectEvents || (ConnectEvents = {}));
@@ -0,0 +1,4 @@
1
+ export * from './app';
2
+ export * from './theme';
3
+ export * from './events';
4
+ export * from './searchParams';
@@ -0,0 +1,4 @@
1
+ export * from './app';
2
+ export * from './theme';
3
+ export * from './events';
4
+ export * from './searchParams';
@@ -0,0 +1,5 @@
1
+ export declare enum SearchParams {
2
+ PROFILE_TOKEN = "profile_token",
3
+ THEME = "theme",
4
+ LANGUAGE = "lang"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var SearchParams;
2
+ (function (SearchParams) {
3
+ SearchParams["PROFILE_TOKEN"] = "profile_token";
4
+ SearchParams["THEME"] = "theme";
5
+ SearchParams["LANGUAGE"] = "lang";
6
+ })(SearchParams || (SearchParams = {}));
@@ -0,0 +1,18 @@
1
+ export declare enum ThemeMode {
2
+ DARK = "dark",
3
+ LIGHT = "light"
4
+ }
5
+ export declare enum LanguageMode {
6
+ AR = "ar",
7
+ EN = "en"
8
+ }
9
+ export declare enum DialogEdgeFormat {
10
+ STRAIGHT = "straight",
11
+ CURVED = "curved"
12
+ }
13
+ export declare enum DialogTransition {
14
+ LEFT = "left",
15
+ RIGHT = "right",
16
+ UP = "up",
17
+ DOWN = "down"
18
+ }
@@ -0,0 +1,22 @@
1
+ export var ThemeMode;
2
+ (function (ThemeMode) {
3
+ ThemeMode["DARK"] = "dark";
4
+ ThemeMode["LIGHT"] = "light";
5
+ })(ThemeMode || (ThemeMode = {}));
6
+ export var LanguageMode;
7
+ (function (LanguageMode) {
8
+ LanguageMode["AR"] = "ar";
9
+ LanguageMode["EN"] = "en";
10
+ })(LanguageMode || (LanguageMode = {}));
11
+ export var DialogEdgeFormat;
12
+ (function (DialogEdgeFormat) {
13
+ DialogEdgeFormat["STRAIGHT"] = "straight";
14
+ DialogEdgeFormat["CURVED"] = "curved";
15
+ })(DialogEdgeFormat || (DialogEdgeFormat = {}));
16
+ export var DialogTransition;
17
+ (function (DialogTransition) {
18
+ DialogTransition["LEFT"] = "left";
19
+ DialogTransition["RIGHT"] = "right";
20
+ DialogTransition["UP"] = "up";
21
+ DialogTransition["DOWN"] = "down";
22
+ })(DialogTransition || (DialogTransition = {}));
@@ -0,0 +1 @@
1
+ export declare const findOrCreateElementAndInject: (id?: string) => HTMLElement;
package/build/utils.js ADDED
@@ -0,0 +1,9 @@
1
+ export const findOrCreateElementAndInject = (id = 'tap-connect-sdk-element') => {
2
+ const elementExist = document.getElementById(id);
3
+ if (elementExist)
4
+ return elementExist;
5
+ const element = document.createElement('div');
6
+ element.setAttribute('id', id);
7
+ document.body.prepend(element);
8
+ return element;
9
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { defineConfig } from 'vite';
2
+ import { resolve } from 'path';
3
+ import react from '@vitejs/plugin-react';
4
+ import dts from 'vite-plugin-dts';
5
+ import replace from 'rollup-plugin-replace';
6
+ import tsconfigPaths from 'vite-tsconfig-paths';
7
+ // https://vite.dev/config/
8
+ export default defineConfig({
9
+ plugins: [
10
+ react(),
11
+ tsconfigPaths(),
12
+ dts({
13
+ insertTypesEntry: true,
14
+ }),
15
+ ],
16
+ server: {
17
+ port: 3001,
18
+ },
19
+ build: {
20
+ outDir: `build-${process.env.npm_package_version}`,
21
+ lib: {
22
+ entry: resolve(__dirname, 'src/index.ts'),
23
+ name: 'TapConnectSdkV2',
24
+ fileName: 'index',
25
+ formats: ['umd', 'cjs', 'es'],
26
+ },
27
+ rollupOptions: {
28
+ output: {
29
+ entryFileNames: 'main.js',
30
+ },
31
+ plugins: [
32
+ replace({
33
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
34
+ }),
35
+ ],
36
+ },
37
+ },
38
+ });
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@tap-payments/connect-v2",
3
+ "private": false,
4
+ "version": "0.0.1-test",
5
+ "type": "module",
6
+ "main": "build/index.js",
7
+ "module": "build/index.js",
8
+ "files": [
9
+ "build",
10
+ "readme.md"
11
+ ],
12
+ "scripts": {
13
+ "clean": "rm -rf build*",
14
+ "dev": "vite",
15
+ "tsc:alias": "tsc-alias -p tsconfig.app.json",
16
+ "build": "yarn clean && tsc -b && yarn tsc:alias && vite build",
17
+ "lint": "eslint .",
18
+ "lint:fix": "eslint . --fix",
19
+ "preview": "vite preview",
20
+ "prettier": "prettier . --check",
21
+ "prettier:fix": "prettier . --write",
22
+ "prepare": "husky"
23
+ },
24
+ "dependencies": {
25
+ "@tap-payments/web-error-handing": "^1.0.1"
26
+ },
27
+ "peerDependencies": {
28
+ "react": "^18.0.0",
29
+ "react-dom": "^18.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "react": "^18.3.1",
33
+ "react-dom": "^18.3.1",
34
+ "@eslint/js": "^9.13.0",
35
+ "@types/node": "^22.9.0",
36
+ "@types/react": "^18.3.12",
37
+ "@types/react-dom": "^18.3.1",
38
+ "@vitejs/plugin-react": "^4.3.3",
39
+ "eslint": "^9.13.0",
40
+ "eslint-plugin-react-hooks": "^5.0.0",
41
+ "eslint-plugin-react-refresh": "^0.4.14",
42
+ "globals": "^15.11.0",
43
+ "husky": "^9.1.6",
44
+ "lint-staged": "^15.2.10",
45
+ "prettier": "^3.3.3",
46
+ "rollup-plugin-replace": "^2.2.0",
47
+ "typescript": "~5.6.2",
48
+ "typescript-eslint": "^8.11.0",
49
+ "vite": "^5.4.10",
50
+ "vite-plugin-dts": "^4.3.0",
51
+ "vite-tsconfig-paths": "^5.1.4"
52
+ },
53
+ "lint-staged": {
54
+ "*.{js,ts,tsx,json,css,yml}": [
55
+ "prettier --write",
56
+ "eslint"
57
+ ]
58
+ }
59
+ }