@zerohash-sdk/csp-crypto-sell-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 ADDED
@@ -0,0 +1,116 @@
1
+ # @zerohash-sdk/csp-crypto-sell-react
2
+
3
+ A React SDK that enables frontend React applications to seamlessly integrate with the Connect CSP Crypto Sell product.
4
+
5
+ Connect CSP Crypto Sell provides a secure, customizable flow for selling crypto assets 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/csp-crypto-sell-react
16
+ ```
17
+
18
+ ## Getting Started
19
+
20
+ ### 1. Import the CspCryptoSell Component
21
+
22
+ ```tsx
23
+ import { CspCryptoSell } from '@zerohash-sdk/csp-crypto-sell-react';
24
+ ```
25
+
26
+ ### 2. Add the CspCryptoSell 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
+ <CspCryptoSell
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
+ <CspCryptoSell
50
+ jwt={jwt}
51
+ env="prod"
52
+ theme="auto"
53
+ onCompleted={({ assetSymbol, amountSold }) => {
54
+ console.log('Sell completed:', amountSold, assetSymbol);
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 { CspCryptoSell } from '@zerohash-sdk/csp-crypto-sell-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
+ <CspCryptoSell
81
+ jwt={jwt}
82
+ env="prod"
83
+ theme="auto"
84
+ onCompleted={({ assetSymbol, amountSold }) => {
85
+ console.log('Sold:', amountSold, assetSymbol);
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
+ ### CspCryptoSell 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` | `({ assetSymbol, amountSold }) => void` | No | - | Callback when the sell flow 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/).
@@ -0,0 +1,160 @@
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
+ * A React wrapper component for the Connect CSP Crypto Sell product.
17
+ *
18
+ * @param props - Component properties
19
+ * @param jwt - JWT token for authentication (required)
20
+ * @param env - Target environment ("local" | "dev" | "cert" | "prod", defaults to "prod")
21
+ * @param theme - Theme mode ("auto" | "light" | "dark", defaults to "auto")
22
+ * @param onCompleted - Callback invoked when the sell flow is successfully completed
23
+ * @param onError - Callback invoked when an error occurs
24
+ * @param onClose - Callback invoked when the user closes the widget
25
+ * @param onLoaded - Callback invoked when the widget has finished loading
26
+ * @param onEvent - Callback invoked for general application events
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * <CspCryptoSell
31
+ * jwt="your-jwt-token"
32
+ * theme="auto"
33
+ * onLoaded={() => console.log('CSP Crypto Sell loaded and ready')}
34
+ * onCompleted={({ amountSold, assetSymbol }) => console.log('Sold', amountSold, assetSymbol)}
35
+ * onClose={() => console.log('CSP Crypto Sell closed')}
36
+ * onError={({ errorCode, reason }) => console.error('Error:', errorCode, reason)}
37
+ * onEvent={(event) => console.log('Event:', event)}
38
+ * />
39
+ * ```
40
+ *
41
+ * @returns React component that renders the Connect CSP Crypto Sell interface
42
+ */
43
+ export declare const CspCryptoSell: default_2.FC<CspCryptoSellProps>;
44
+
45
+ declare type CspCryptoSellCompletedData = {
46
+ /** Symbol of the asset that was sold (e.g. 'BTC.BITCOIN') */
47
+ assetSymbol: string;
48
+ /** Quantity sold as a string */
49
+ amountSold: string;
50
+ };
51
+
52
+ /**
53
+ * CSP Crypto sell event structure
54
+ */
55
+ declare type CspCryptoSellEvent = AppEvent<CspCryptoSellEventType>;
56
+
57
+ /**
58
+ * CSP Crypto sell event type literals
59
+ */
60
+ declare type CspCryptoSellEventType = string;
61
+
62
+ declare interface CspCryptoSellProps {
63
+ /**
64
+ * JWT token used for authentication with the Connect CSP Crypto Sell service.
65
+ * This token should be obtained from your backend and contain the necessary
66
+ * claims for user identification and authorization.
67
+ *
68
+ * @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
69
+ */
70
+ jwt: string;
71
+ /**
72
+ * Target environment for the Connect CSP Crypto Sell service.
73
+ *
74
+ * @default "prod"
75
+ */
76
+ env?: Environment;
77
+ /**
78
+ * Theme mode for the Connect CSP Crypto Sell interface.
79
+ *
80
+ * @default "auto"
81
+ */
82
+ theme?: Theme;
83
+ /**
84
+ * Callback invoked when the CSP crypto sell flow is successfully completed.
85
+ *
86
+ * @param data - Details about the completed sell, including amount sold and asset symbol
87
+ */
88
+ onCompleted?: (data: CspCryptoSellCompletedData) => void;
89
+ /**
90
+ * Callback invoked when an error occurs during the CSP crypto sell flow.
91
+ *
92
+ * @param error - Error details including error code and reason
93
+ */
94
+ onError?: (error: ErrorPayload) => void;
95
+ /**
96
+ * Callback invoked when the user closes the CSP crypto sell widget.
97
+ */
98
+ onClose?: () => void;
99
+ /**
100
+ * Callback invoked when the CSP crypto sell widget has finished loading and is ready.
101
+ */
102
+ onLoaded?: () => void;
103
+ /**
104
+ * Callback invoked for general application events during the CSP crypto sell flow.
105
+ *
106
+ * @param event - Event object containing the event type and associated data
107
+ */
108
+ onEvent?: (event: CspCryptoSellEvent) => void;
109
+ }
110
+
111
+ /**
112
+ * Available environments for the Connect CSP Crypto Sell service.
113
+ *
114
+ * - `"local"` - Local development environment (http://localhost:4206)
115
+ * - `"dev"` - Development environment for early-stage testing
116
+ * - `"cert"` - Certificate/staging environment for integration testing
117
+ * - `"prod"` - Live production environment for real applications
118
+ */
119
+ declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
120
+
121
+ /**
122
+ * Generic error codes for all Connect applications
123
+ */
124
+ declare enum ErrorCode {
125
+ /** Network connectivity error */
126
+ NETWORK_ERROR = 'network_error',
127
+ /** Authentication or session expired error */
128
+ AUTH_ERROR = 'auth_error',
129
+ /** Resource not found error */
130
+ NOT_FOUND_ERROR = 'not_found_error',
131
+ /** Validation error from user input */
132
+ VALIDATION_ERROR = 'validation_error',
133
+ /** Server error (5xx) */
134
+ SERVER_ERROR = 'server_error',
135
+ /** Client error (4xx) */
136
+ CLIENT_ERROR = 'client_error',
137
+ /** Unknown or unexpected error */
138
+ UNKNOWN_ERROR = 'unknown_error',
139
+ }
140
+
141
+ /**
142
+ * Generic error payload structure for error callbacks
143
+ */
144
+ declare type ErrorPayload = {
145
+ /** Error code indicating the type of error */
146
+ errorCode: ErrorCode;
147
+ /** Human-readable reason for the error */
148
+ reason: string;
149
+ };
150
+
151
+ /**
152
+ * Theme mode for the Connect CSP Crypto Sell interface.
153
+ *
154
+ * - `"auto"` - Automatically detect system preference (light/dark mode)
155
+ * - `"light"` - Force light theme
156
+ * - `"dark"` - Force dark theme
157
+ */
158
+ declare type Theme = 'auto' | 'light' | 'dark';
159
+
160
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import m, { useRef as y, useEffect as f } from "react";
2
+ const x = {
3
+ local: "http://localhost:5173/csp-crypto-sell-web/index.js",
4
+ dev: "https://connect-sdk.dev.0hash.com/csp-crypto-sell-web/index.js",
5
+ cert: "https://sdk.sandbox.connect.xyz/csp-crypto-sell-web/index.js",
6
+ prod: "https://sdk.connect.xyz/csp-crypto-sell-web/index.js"
7
+ }, b = "zerohash-csp-crypto-sell-script", h = "zerohash-csp-crypto-sell", I = (s = "prod") => x[s], S = ({
8
+ jwt: s,
9
+ env: c = "prod",
10
+ theme: a,
11
+ onCompleted: r,
12
+ onError: o,
13
+ onClose: p,
14
+ onLoaded: n,
15
+ onEvent: l,
16
+ ...u
17
+ }) => {
18
+ const i = y(null);
19
+ return f(() => {
20
+ const t = i.current;
21
+ t && (r && (t.onCompleted = r), o && (t.onError = o), p && (t.onClose = p), n && (t.onLoaded = n), l && (t.onEvent = l));
22
+ }, [r, o, p, n, l]), f(() => {
23
+ const t = I(c), d = `${b}-${c}`;
24
+ if (document.getElementById(d))
25
+ return;
26
+ const e = document.createElement("script");
27
+ e.id = d, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
28
+ console.error(`Failed to load the script for ${h} from ${c} environment.`);
29
+ }, document.head.appendChild(e);
30
+ }, [c]), m.createElement(h, {
31
+ ref: i,
32
+ jwt: s,
33
+ env: c,
34
+ theme: a,
35
+ ...u
36
+ });
37
+ };
38
+ export {
39
+ S as CspCryptoSell
40
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@zerohash-sdk/csp-crypto-sell-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": "csp-crypto-sell-react"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "react-dom": ">=18.0.0"
28
+ }
29
+ }