@zerohash-sdk/fiat-account-link-react 1.1.0
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 +116 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +40 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @zerohash-sdk/fiat-account-link-react
|
|
2
|
+
|
|
3
|
+
A React SDK that enables frontend React applications to seamlessly integrate with the Connect Fiat Account Link product.
|
|
4
|
+
|
|
5
|
+
Connect Fiat Account Link provides a secure, customizable flow for linking external bank accounts directly within your application.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- React 18.0.0 or higher
|
|
10
|
+
- React DOM 18.0.0 or higher
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @zerohash-sdk/fiat-account-link-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
### 1. Import the FiatAccountLink Component
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { FiatAccountLink } from '@zerohash-sdk/fiat-account-link-react';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Add the FiatAccountLink Component to Your App
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
function App() {
|
|
30
|
+
const jwt = 'your-jwt-token'; // Obtain this from your backend
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<FiatAccountLink
|
|
34
|
+
jwt={jwt}
|
|
35
|
+
env="prod" // or "cert" for testing
|
|
36
|
+
theme="auto" // 'auto' (default), 'light', or 'dark'
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3. Configure Event Callbacks (Optional)
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
function App() {
|
|
46
|
+
const jwt = 'your-jwt-token';
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<FiatAccountLink
|
|
50
|
+
jwt={jwt}
|
|
51
|
+
env="prod"
|
|
52
|
+
theme="auto"
|
|
53
|
+
onCompleted={({ externalAccountId, institutionName }) => {
|
|
54
|
+
console.log('Account linked:', externalAccountId, institutionName);
|
|
55
|
+
}}
|
|
56
|
+
onError={({ errorCode, reason }) => {
|
|
57
|
+
console.log('Error:', errorCode, 'Reason:', reason);
|
|
58
|
+
}}
|
|
59
|
+
onClose={() => console.log('Widget closed')}
|
|
60
|
+
onEvent={({ type, data }) => console.log('Event:', type, data)}
|
|
61
|
+
onLoaded={() => console.log('Widget loaded and ready')}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Complete Example
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import React from 'react';
|
|
71
|
+
import { FiatAccountLink } from '@zerohash-sdk/fiat-account-link-react';
|
|
72
|
+
|
|
73
|
+
function App() {
|
|
74
|
+
const jwt = 'your-jwt-token';
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div className="App">
|
|
78
|
+
<h1>My App</h1>
|
|
79
|
+
|
|
80
|
+
<FiatAccountLink
|
|
81
|
+
jwt={jwt}
|
|
82
|
+
env="prod"
|
|
83
|
+
theme="auto"
|
|
84
|
+
onCompleted={({ externalAccountId, institutionName }) => {
|
|
85
|
+
console.log('Linked:', externalAccountId, institutionName);
|
|
86
|
+
}}
|
|
87
|
+
onError={({ errorCode, reason }) => console.log('Error:', errorCode, reason)}
|
|
88
|
+
onClose={() => console.log('Widget closed')}
|
|
89
|
+
onEvent={({ type, data }) => console.log('Event type:', type, 'Event data:', data)}
|
|
90
|
+
onLoaded={() => console.log('Widget loaded and ready')}
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default App;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## API Reference
|
|
100
|
+
|
|
101
|
+
### FiatAccountLink Component Props
|
|
102
|
+
|
|
103
|
+
| Prop | Type | Required | Default | Description |
|
|
104
|
+
| ------------- | -------------------------------------------------- | -------- | -------- | ---------------------------------------------------- |
|
|
105
|
+
| `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
|
|
106
|
+
| `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
|
|
107
|
+
| `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
|
|
108
|
+
| `onCompleted` | `({ externalAccountId, institutionName }) => void` | No | - | Callback when account linking completes successfully |
|
|
109
|
+
| `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
|
|
110
|
+
| `onClose` | `() => void` | No | - | Callback when the widget is closed |
|
|
111
|
+
| `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
|
|
112
|
+
| `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
|
|
113
|
+
|
|
114
|
+
## More Information & Support
|
|
115
|
+
|
|
116
|
+
For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generic app event structure
|
|
5
|
+
* @template TType - Event type string
|
|
6
|
+
* @template TData - Event data payload
|
|
7
|
+
*/
|
|
8
|
+
declare type AppEvent<TType extends string = string, TData = Record<string, unknown>> = {
|
|
9
|
+
/** The type of event that occurred */
|
|
10
|
+
type: TType;
|
|
11
|
+
/** Data associated with the event */
|
|
12
|
+
data: TData;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Available environments for the Connect Fiat Account Link service.
|
|
17
|
+
*/
|
|
18
|
+
declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generic error codes for all Connect applications
|
|
22
|
+
*/
|
|
23
|
+
declare enum ErrorCode {
|
|
24
|
+
/** Network connectivity error */
|
|
25
|
+
NETWORK_ERROR = 'network_error',
|
|
26
|
+
/** Authentication or session expired error */
|
|
27
|
+
AUTH_ERROR = 'auth_error',
|
|
28
|
+
/** Resource not found error */
|
|
29
|
+
NOT_FOUND_ERROR = 'not_found_error',
|
|
30
|
+
/** Validation error from user input */
|
|
31
|
+
VALIDATION_ERROR = 'validation_error',
|
|
32
|
+
/** Server error (5xx) */
|
|
33
|
+
SERVER_ERROR = 'server_error',
|
|
34
|
+
/** Client error (4xx) */
|
|
35
|
+
CLIENT_ERROR = 'client_error',
|
|
36
|
+
/** Unknown or unexpected error */
|
|
37
|
+
UNKNOWN_ERROR = 'unknown_error',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generic error payload structure for error callbacks
|
|
42
|
+
*/
|
|
43
|
+
declare type ErrorPayload = {
|
|
44
|
+
/** Error code indicating the type of error */
|
|
45
|
+
errorCode: ErrorCode;
|
|
46
|
+
/** Human-readable reason for the error */
|
|
47
|
+
reason: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A React wrapper component for the Connect Fiat Account Link product.
|
|
52
|
+
*/
|
|
53
|
+
export declare const FiatAccountLink: default_2.FC<FiatAccountLinkProps>;
|
|
54
|
+
|
|
55
|
+
declare type FiatAccountLinkCompletedData = {
|
|
56
|
+
/** The external account ID returned after successful linking */
|
|
57
|
+
externalAccountId: string;
|
|
58
|
+
/** The name of the institution linked */
|
|
59
|
+
institutionName: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
declare type FiatAccountLinkEvent = AppEvent<FiatAccountLinkEventType>;
|
|
63
|
+
|
|
64
|
+
declare type FiatAccountLinkEventType = string;
|
|
65
|
+
|
|
66
|
+
declare interface FiatAccountLinkProps {
|
|
67
|
+
/** JWT token used for authentication */
|
|
68
|
+
jwt: string;
|
|
69
|
+
/** Target environment. Defaults to "prod" */
|
|
70
|
+
env?: Environment;
|
|
71
|
+
/** Theme mode. Defaults to "auto" */
|
|
72
|
+
theme?: Theme;
|
|
73
|
+
/** Called when the account is successfully linked */
|
|
74
|
+
onCompleted?: (data: FiatAccountLinkCompletedData) => void;
|
|
75
|
+
/** Called when an error occurs */
|
|
76
|
+
onError?: (error: ErrorPayload) => void;
|
|
77
|
+
/** Called when the user closes the widget */
|
|
78
|
+
onClose?: () => void;
|
|
79
|
+
/** Called when the widget has finished loading */
|
|
80
|
+
onLoaded?: () => void;
|
|
81
|
+
/** Called for general application events */
|
|
82
|
+
onEvent?: (event: FiatAccountLinkEvent) => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Theme mode for the Connect Fiat Account Link interface.
|
|
87
|
+
*/
|
|
88
|
+
declare type Theme = 'auto' | 'light' | 'dark';
|
|
89
|
+
|
|
90
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import m, { useRef as k, useEffect as f } from "react";
|
|
2
|
+
const x = {
|
|
3
|
+
local: "http://localhost:4208/fiat-account-link-web/index.js",
|
|
4
|
+
dev: "https://connect-sdk.dev.0hash.com/fiat-account-link-web/index.js",
|
|
5
|
+
cert: "https://sdk.sandbox.connect.xyz/fiat-account-link-web/index.js",
|
|
6
|
+
prod: "https://sdk.connect.xyz/fiat-account-link-web/index.js"
|
|
7
|
+
}, b = "zerohash-fiat-account-link-script", u = "zerohash-fiat-account-link", y = (n = "prod") => x[n], R = ({
|
|
8
|
+
jwt: n,
|
|
9
|
+
env: e = "prod",
|
|
10
|
+
theme: p,
|
|
11
|
+
onCompleted: r,
|
|
12
|
+
onError: o,
|
|
13
|
+
onClose: i,
|
|
14
|
+
onLoaded: s,
|
|
15
|
+
onEvent: a,
|
|
16
|
+
...h
|
|
17
|
+
}) => {
|
|
18
|
+
const d = k(null);
|
|
19
|
+
return f(() => {
|
|
20
|
+
const t = d.current;
|
|
21
|
+
t && (r && (t.onCompleted = r), o && (t.onError = o), i && (t.onClose = i), s && (t.onLoaded = s), a && (t.onEvent = a));
|
|
22
|
+
}, [r, o, i, s, a]), f(() => {
|
|
23
|
+
const t = y(e), l = `${b}-${e}`;
|
|
24
|
+
if (document.getElementById(l))
|
|
25
|
+
return;
|
|
26
|
+
const c = document.createElement("script");
|
|
27
|
+
c.id = l, c.src = t, c.type = "module", c.async = !0, c.onerror = () => {
|
|
28
|
+
console.error(`Failed to load the script for ${u} from ${e} environment.`);
|
|
29
|
+
}, document.head.appendChild(c);
|
|
30
|
+
}, [e]), m.createElement(u, {
|
|
31
|
+
ref: d,
|
|
32
|
+
jwt: n,
|
|
33
|
+
env: e,
|
|
34
|
+
theme: p,
|
|
35
|
+
...h
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
R as FiatAccountLink
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerohash-sdk/fiat-account-link-react",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!**/*.tsbuildinfo"
|
|
21
|
+
],
|
|
22
|
+
"nx": {
|
|
23
|
+
"name": "fiat-account-link-react"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0",
|
|
27
|
+
"react-dom": ">=18.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|