@zerohash-sdk/profile-react 0.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 +82 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +39 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# @zerohash-sdk/profile-react
|
|
2
|
+
|
|
3
|
+
A React SDK that enables frontend React applications to seamlessly integrate with the Connect Profile product.
|
|
4
|
+
|
|
5
|
+
Connect Profile provides a secure, customizable flow for managing user profile information 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/profile-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
Follow these simple steps to integrate Connect Profile into your React application:
|
|
21
|
+
|
|
22
|
+
### 1. Import the Profile Component
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { Profile } from '@zerohash-sdk/profile-react';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Add the Profile Component to Your App
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
function App() {
|
|
32
|
+
const jwt = 'your-jwt-token'; // Obtain this from your backend
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Profile
|
|
36
|
+
jwt={jwt}
|
|
37
|
+
env="prod" // or "cert" for testing
|
|
38
|
+
theme="auto" // 'auto' (default), 'light', or 'dark'
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Configure Event Callbacks (Optional)
|
|
45
|
+
|
|
46
|
+
Listen to events from the Profile SDK to handle user interactions:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
function App() {
|
|
50
|
+
const jwt = 'your-jwt-token';
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Profile
|
|
54
|
+
jwt={jwt}
|
|
55
|
+
env="prod"
|
|
56
|
+
theme="auto"
|
|
57
|
+
onLoaded={() => console.log('Profile widget loaded and ready')}
|
|
58
|
+
onClose={() => console.log('Profile widget closed')}
|
|
59
|
+
onError={({ errorCode, reason }) => console.error('Error:', errorCode, reason)}
|
|
60
|
+
onEvent={(event) => console.log('Event:', event)}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API Reference
|
|
67
|
+
|
|
68
|
+
### Profile Component Props
|
|
69
|
+
|
|
70
|
+
| Prop | Type | Required | Default | Description |
|
|
71
|
+
| ---------- | -------------------------------------- | -------- | -------- | ---------------------------------- |
|
|
72
|
+
| `jwt` | `string` | Yes | - | JWT token for authentication |
|
|
73
|
+
| `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
|
|
74
|
+
| `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
|
|
75
|
+
| `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
|
|
76
|
+
| `onClose` | `() => void` | No | - | Callback when the widget is closed |
|
|
77
|
+
| `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
|
|
78
|
+
| `onLoaded` | `() => void` | No | - | Callback when the widget is loaded |
|
|
79
|
+
|
|
80
|
+
## More Information & Support
|
|
81
|
+
|
|
82
|
+
For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
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 Profile service.
|
|
17
|
+
*
|
|
18
|
+
* - `"local"` - Local development environment
|
|
19
|
+
* - `"dev"` - Development environment for early-stage testing
|
|
20
|
+
* - `"cert"` - Certificate/staging environment for integration testing
|
|
21
|
+
* - `"prod"` - Live production environment for real applications
|
|
22
|
+
*/
|
|
23
|
+
declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generic error codes for all Connect applications
|
|
27
|
+
*/
|
|
28
|
+
declare enum ErrorCode {
|
|
29
|
+
/** Network connectivity error */
|
|
30
|
+
NETWORK_ERROR = 'network_error',
|
|
31
|
+
/** Authentication or session expired error */
|
|
32
|
+
AUTH_ERROR = 'auth_error',
|
|
33
|
+
/** Resource not found error */
|
|
34
|
+
NOT_FOUND_ERROR = 'not_found_error',
|
|
35
|
+
/** Validation error from user input */
|
|
36
|
+
VALIDATION_ERROR = 'validation_error',
|
|
37
|
+
/** Server error (5xx) */
|
|
38
|
+
SERVER_ERROR = 'server_error',
|
|
39
|
+
/** Client error (4xx) */
|
|
40
|
+
CLIENT_ERROR = 'client_error',
|
|
41
|
+
/** Unknown or unexpected error */
|
|
42
|
+
UNKNOWN_ERROR = 'unknown_error',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generic error payload structure for error callbacks
|
|
47
|
+
*/
|
|
48
|
+
declare type ErrorPayload = {
|
|
49
|
+
/** Error code indicating the type of error */
|
|
50
|
+
errorCode: ErrorCode;
|
|
51
|
+
/** Human-readable reason for the error */
|
|
52
|
+
reason: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A React wrapper component for the Connect Profile product.
|
|
57
|
+
*/
|
|
58
|
+
export declare const Profile: default_2.FC<ProfileProps>;
|
|
59
|
+
|
|
60
|
+
declare type ProfileEvent = AppEvent<ProfileEventType>;
|
|
61
|
+
|
|
62
|
+
declare type ProfileEventType = string;
|
|
63
|
+
|
|
64
|
+
declare interface ProfileProps {
|
|
65
|
+
/**
|
|
66
|
+
* JWT token used for authentication with the Connect Profile service.
|
|
67
|
+
*/
|
|
68
|
+
jwt: string;
|
|
69
|
+
/**
|
|
70
|
+
* Target environment for the Connect Profile service.
|
|
71
|
+
*
|
|
72
|
+
* @default "prod"
|
|
73
|
+
*/
|
|
74
|
+
env?: Environment;
|
|
75
|
+
/**
|
|
76
|
+
* Theme mode for the Connect Profile interface.
|
|
77
|
+
*
|
|
78
|
+
* @default "auto"
|
|
79
|
+
*/
|
|
80
|
+
theme?: Theme;
|
|
81
|
+
/**
|
|
82
|
+
* Callback invoked when an error occurs during the profile flow.
|
|
83
|
+
*/
|
|
84
|
+
onError?: (error: ErrorPayload) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Callback invoked when the user closes the profile widget.
|
|
87
|
+
*/
|
|
88
|
+
onClose?: () => void;
|
|
89
|
+
/**
|
|
90
|
+
* Callback invoked when the profile widget has finished loading and is ready.
|
|
91
|
+
*/
|
|
92
|
+
onLoaded?: () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Callback invoked for general application events during the profile flow.
|
|
95
|
+
*/
|
|
96
|
+
onEvent?: (event: ProfileEvent) => void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Theme mode for the Connect Profile interface.
|
|
101
|
+
*
|
|
102
|
+
* - `"auto"` - Automatically detect system preference (light/dark mode)
|
|
103
|
+
* - `"light"` - Force light theme
|
|
104
|
+
* - `"dark"` - Force dark theme
|
|
105
|
+
*/
|
|
106
|
+
declare type Theme = 'auto' | 'light' | 'dark';
|
|
107
|
+
|
|
108
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import m, { useRef as u, useEffect as l } from "react";
|
|
2
|
+
const x = {
|
|
3
|
+
local: "http://localhost:5173/profile-web/index.js",
|
|
4
|
+
dev: "https://connect-sdk.dev.0hash.com/profile-web/index.js",
|
|
5
|
+
cert: "https://sdk.sandbox.connect.xyz/profile-web/index.js",
|
|
6
|
+
prod: "https://sdk.connect.xyz/profile-web/index.js"
|
|
7
|
+
}, b = "zerohash-profile-script", f = "zerohash-profile", y = (o = "prod") => x[o], R = ({
|
|
8
|
+
jwt: o,
|
|
9
|
+
env: r = "prod",
|
|
10
|
+
theme: h,
|
|
11
|
+
onError: c,
|
|
12
|
+
onClose: s,
|
|
13
|
+
onLoaded: n,
|
|
14
|
+
onEvent: i,
|
|
15
|
+
...a
|
|
16
|
+
}) => {
|
|
17
|
+
const p = u(null);
|
|
18
|
+
return l(() => {
|
|
19
|
+
const e = p.current;
|
|
20
|
+
e && (c && (e.onError = c), s && (e.onClose = s), n && (e.onLoaded = n), i && (e.onEvent = i));
|
|
21
|
+
}, [c, s, n, i]), l(() => {
|
|
22
|
+
const e = y(r), d = `${b}-${r}`;
|
|
23
|
+
if (document.getElementById(d))
|
|
24
|
+
return;
|
|
25
|
+
const t = document.createElement("script");
|
|
26
|
+
t.id = d, t.src = e, t.type = "module", t.async = !0, t.onerror = () => {
|
|
27
|
+
console.error(`Failed to load the script for ${f} from ${r} environment.`);
|
|
28
|
+
}, document.head.appendChild(t);
|
|
29
|
+
}, [r]), m.createElement(f, {
|
|
30
|
+
ref: p,
|
|
31
|
+
jwt: o,
|
|
32
|
+
env: r,
|
|
33
|
+
theme: h,
|
|
34
|
+
...a
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
R as Profile
|
|
39
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerohash-sdk/profile-react",
|
|
3
|
+
"version": "0.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": "profile-react"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0",
|
|
27
|
+
"react-dom": ">=18.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|