@abaxx_tech/v-integration-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.
Files changed (2) hide show
  1. package/README.md +324 -0
  2. package/package.json +66 -0
package/README.md ADDED
@@ -0,0 +1,324 @@
1
+ # v-integration-react
2
+ `v-integration-react` is an npm library that provides React components for handling Verifier+ authentication UI.
3
+ <br/><br/>
4
+
5
+ ## Features
6
+ - **Verifier Authentication**: Pre-built authentication UI component with complete login flow.
7
+ - **Modular Components**: Separate QR code and email authentication components.
8
+ - **Token Management**: Provides authentication token through React Context.
9
+ - **Real-time Authentication**: Server-Sent Events (SSE) for real-time authentication status updates.
10
+ - **PKCE Flow**: Implements OAuth 2.0 PKCE (Proof Key for Code Exchange) for secure authentication.
11
+ - **Error Handling**: Comprehensive error handling and user feedback.
12
+ - **Customizable Styling**: Full control over colors, sizes, and text with support for both Tailwind classes and hex colors.
13
+ - **Background Authentication Service**: Automatic token management and authentication flow handling.
14
+ <br/><br/>
15
+
16
+ ## Installation
17
+ Install the package via npm or yarn:
18
+ ```sh
19
+ npm install @abaxxtech/v-integration-react@1.1.0
20
+ # or
21
+ yarn add @abaxxtech/v-integration-react@1.1.0
22
+ ```
23
+ <br/><br/>
24
+
25
+ ## Usage
26
+ ### 1. Wrap your app with `VerifierProvider`
27
+ Wrap your application with `VerifierProvider` to manage authentication. The provider automatically handles PKCE generation, SSE connections, and token management through the `AuthService`.
28
+ ```ts
29
+ import { VerifierProvider } from "@abaxxtech/v-integration-react";
30
+
31
+ const App = () => {
32
+ return (
33
+ <VerifierProvider
34
+ appId={Number(import.meta.env.VITE_APP_ID)}
35
+ apiUrl={import.meta.env.VITE_API_URL}
36
+ clientId={import.meta.env.VITE_CLIENT_ID}
37
+ >
38
+ {/* Your app goes here */}
39
+ </VerifierProvider>
40
+ );
41
+ };
42
+
43
+ export default App;
44
+ ```
45
+
46
+ ### 2. Choose your authentication component
47
+
48
+ #### Complete Authentication UI (`VerifierAuth`)
49
+ ```ts
50
+ import { VerifierAuth } from "@abaxxtech/v-integration-react";
51
+ import "v-integration-react/index.css";
52
+
53
+ const LoginPage = () => {
54
+ return <VerifierAuth title="Abaxx Drive" />;
55
+ };
56
+
57
+ export default LoginPage;
58
+ ```
59
+
60
+ #### QR Code Only (`VerifierAuthQr`)
61
+ ```ts
62
+ import { VerifierAuthQr } from "@abaxxtech/v-integration-react";
63
+ import "v-integration-react/index.css";
64
+
65
+ const QRLoginAuth = () => {
66
+ return (
67
+ <VerifierAuthQr
68
+ size={150}
69
+ qrColor="#e60100"
70
+ checkmarkColor="#0b981"
71
+ showStatus={true}
72
+ />
73
+ );
74
+ };
75
+
76
+ export default QRLoginAuth;
77
+ ```
78
+
79
+ #### Email Input Only (`VerifierAuthEmail`)
80
+ ```ts
81
+ import { VerifierAuthEmail } from "@abaxxtech/v-integration-react";
82
+ import "v-integration-react/index.css";
83
+
84
+ const EmailLoginAuth = () => {
85
+ return (
86
+ <VerifierAuthEmail
87
+ inputPlaceholder="Enter your email"
88
+ buttonText="Sign In"
89
+ buttonBackgroundColor="#0b981"
90
+ checkmarkColor="#0b981"
91
+ />
92
+ );
93
+ };
94
+
95
+ export default EmailLoginAuth;
96
+ ```
97
+
98
+ * Import `v-integration-react/index.css` for the login UI styling.
99
+ * All components provide authentication UI for Verifier+.
100
+ * Each component can be customized with different props.
101
+
102
+ ### 3. Access authentication data through Context
103
+ ```ts
104
+ import { useContext } from 'react';
105
+ import { VContext } from 'v-integration-react';
106
+
107
+ const MyComponent = () => {
108
+ const {
109
+ token,
110
+ identity,
111
+ isAuthenticating,
112
+ authRequestId,
113
+ authRequestIdExpires,
114
+ codeChallenge,
115
+ authError
116
+ } = useContext(VContext);
117
+
118
+ if (isAuthenticating) {
119
+ return <div>Authenticating...</div>;
120
+ }
121
+
122
+ if (authError) {
123
+ return <div>Authentication Error: {authError}</div>;
124
+ }
125
+
126
+ if (token) {
127
+ return <div>Authenticated! Token: {token}</div>;
128
+ }
129
+
130
+ return <div>Not authenticated</div>;
131
+ };
132
+ ```
133
+ <br/><br/>
134
+
135
+ ## Components
136
+
137
+ ### `VerifierProvider`
138
+ The main provider component that wraps your application and manages the authentication context. It automatically includes the `AuthService` component for handling background authentication processes.
139
+
140
+ #### Props:
141
+ | Prop | Type | Description |
142
+ | ------------- | ------------- | ------------- |
143
+ | `appId` | `string \| number` | Unique application ID |
144
+ | `apiUrl` | `string` | API URL for authentication |
145
+ | `clientId` | `string` | Client identifier |
146
+ | `children` | `ReactNode` | Child components to be wrapped |
147
+
148
+ #### Features:
149
+ - Automatically generates PKCE code verifier and challenge
150
+ - Establishes SSE connection for real-time authentication updates
151
+ - Manages authentication state and token lifecycle
152
+ - Handles authentication errors and provides error context
153
+
154
+ ### `VerifierAuth`
155
+ Complete authentication UI with QR code and email input. This component provides a full-screen authentication experience with background image and branding.
156
+
157
+ #### Props:
158
+ | Prop | Type | Description |
159
+ | ------------- | ------------- | ------------- |
160
+ | `title` | `string` | Title displayed in the login UI |
161
+ | `containerClass` | `string` | Additional CSS classes for the container |
162
+
163
+ #### Features:
164
+ - Full-screen authentication layout with background image
165
+ - QR code generation with Abaxx branding
166
+ - Email/Abaxx ID input field
167
+ - Real-time authentication status updates
168
+ - Loading states and error handling
169
+ - Responsive design with grid layout
170
+
171
+ ### `VerifierAuthQr`
172
+ QR code authentication component only. Displays a QR code that users can scan with the Verifier+ app for authentication.
173
+
174
+ #### Props:
175
+ | Prop | Type | Default | Description |
176
+ | ------------- | ------------- | ------------- | ------------- |
177
+ | `size` | `number` | `130` | QR code size in pixels |
178
+ | `qrColor` | `string` | `"#e60100"` | QR code foreground color |
179
+ | `logoImage` | `string` | `"https://content.abaxx.com/assets/static/qr-logo.png"` | Logo URL to display in QR center |
180
+ | `logoWidth` | `number` | `40` | Logo width in pixels |
181
+ | `logoHeight` | `number` | `20` | Logo height in pixels |
182
+ | `quietZone` | `number` | `0` | Quiet zone around QR code |
183
+ | `containerClass` | `string` | `""` | Additional CSS classes for container |
184
+ | `showStatus` | `boolean` | `true` | Whether to show authentication status (success/pending) |
185
+ | `checkmarkColor` | `string` | `"#c40808"` | Color of the checkmark icon (hex color) |
186
+
187
+ #### Features:
188
+ - Dynamic QR code generation with authentication parameters
189
+ - Loading spinner while QR code is being generated
190
+ - Optional status display with success/pending states
191
+ - Customizable styling and branding
192
+ - Automatic QR code updates when authentication parameters change
193
+
194
+ ### `VerifierAuthEmail`
195
+ Email input authentication component only. Provides a standalone email/Abaxx ID input field with authentication functionality.
196
+
197
+ #### Props:
198
+ | Prop | Type | Default | Description |
199
+ | ------------- | ------------- | ------------- | ------------- |
200
+ | `inputPlaceholder` | `string` | `"Enter Email or Abaxx ID"` | Placeholder text for the input field |
201
+ | `buttonText` | `string` | `"Sign In"` | Text displayed on the button |
202
+ | `inputHeight` | `string` | `"v-h-10"` | Height class for the input field |
203
+ | `inputWidth` | `string` | `"v-w-full"` | Width class for the input field |
204
+ | `inputTextColor` | `string` | `"v-text-gray-600"` | Text color for the input field (Tailwind class or hex color) |
205
+ | `inputBorderColor` | `string` | `"v-border-gray-400"` | Border color for the input field (Tailwind class or hex color) |
206
+ | `inputBackgroundColor` | `string` | `"v-bg-transparent"` | Background color for the input field (Tailwind class or hex color) |
207
+ | `buttonHeight` | `string` | `"v-h-10"` | Height class for the button |
208
+ | `buttonWidth` | `string` | `"v-w-full"` | Width class for the button |
209
+ | `buttonBackgroundColor` | `string` | `"v-bg-red"` | Background color for the button (Tailwind class or hex color) |
210
+ | `buttonTextColor` | `string` | `"v-text-white"` | Text color for the button (Tailwind class or hex color) |
211
+ | `containerClass` | `string` | `""` | Additional CSS classes for the container |
212
+ | `checkmarkColor` | `string` | `"#c40808"` | Color of the checkmark icon (hex color) |
213
+
214
+ #### Features:
215
+ - Email/Abaxx ID input validation
216
+ - Loading states with spinner animation
217
+ - Real-time authentication status updates
218
+ - Customizable styling with support for both Tailwind classes and hex colors
219
+ - Error handling with user feedback
220
+ - Success state with checkmark icon
221
+
222
+ ## Context API
223
+
224
+ ### `VContext`
225
+ The authentication context provides access to all authentication-related state and functions.
226
+
227
+ #### Available Properties:
228
+ | Property | Type | Description |
229
+ | ------------- | ------------- | ------------- |
230
+ | `appId` | `string \| number` | Application ID |
231
+ | `apiUrl` | `string` | API base URL |
232
+ | `clientId` | `string` | Client identifier |
233
+ | `identity` | `string` | User identity after authentication |
234
+ | `authRequestId` | `string` | Current authentication request ID |
235
+ | `authRequestIdExpires` | `Date` | Expiration time for the auth request |
236
+ | `isAuthenticating` | `boolean` | Whether authentication is in progress |
237
+ | `codeVerifier` | `string` | PKCE code verifier |
238
+ | `codeChallenge` | `string` | PKCE code challenge |
239
+ | `authCode` | `string` | Authorization code from successful auth |
240
+ | `token` | `string \| null` | Authentication token |
241
+ | `authError` | `string \| null` | Authentication error message |
242
+
243
+ ## Authentication Flow
244
+
245
+ The library implements a complete OAuth 2.0 PKCE flow with the following steps:
246
+
247
+ 1. **PKCE Generation**: Automatically generates code verifier and challenge
248
+ 2. **SSE Connection**: Establishes Server-Sent Events connection for real-time updates
249
+ 3. **QR Code Generation**: Creates QR code with authentication parameters
250
+ 4. **User Authentication**: User scans QR code or enters email/Abaxx ID
251
+ 5. **Authorization**: Verifier+ app approves the authentication request
252
+ 6. **Token Exchange**: Exchanges authorization code for access token
253
+ 7. **State Management**: Updates authentication state throughout the process
254
+
255
+ ## Usage Examples
256
+
257
+ ### Custom Styling with Hex Colors
258
+ ```tsx
259
+ // Custom green theme
260
+ <VerifierAuthEmail
261
+ inputPlaceholder="Enter your email address"
262
+ buttonText="Login Now"
263
+ inputHeight="v-h-12"
264
+ inputWidth="v-w-80"
265
+ inputTextColor="#0b981"
266
+ inputBorderColor="#0b981"
267
+ inputBackgroundColor="#f0f9ff"
268
+ buttonHeight="v-h-12"
269
+ buttonWidth="v-w-80"
270
+ buttonBackgroundColor="#0b981"
271
+ buttonTextColor="#ffffff"
272
+ checkmarkColor="#0b981"
273
+ containerClass="flex justify-center"
274
+ />
275
+
276
+ // Custom QR with green theme
277
+ <VerifierAuthQr
278
+ size={150}
279
+ qrColor="#0b981"
280
+ checkmarkColor="#0b981"
281
+ showStatus={true}
282
+ containerClass="flex justify-center"
283
+ />
284
+ ```
285
+
286
+ ### Using Tailwind Classes
287
+ ```tsx
288
+ // Tailwind-based styling
289
+ <VerifierAuthEmail
290
+ inputPlaceholder="Enter your email address"
291
+ buttonText="Login Now"
292
+ inputHeight="v-h-12"
293
+ inputWidth="v-w-80"
294
+ inputTextColor="v-text-blue-600"
295
+ inputBorderColor="v-border-blue-400"
296
+ inputBackgroundColor="v-bg-blue-50"
297
+ buttonHeight="v-h-12"
298
+ buttonWidth="v-w-80"
299
+ buttonBackgroundColor="v-bg-blue-600"
300
+ buttonTextColor="v-text-white"
301
+ containerClass="flex justify-center"
302
+ />
303
+ ```
304
+
305
+ <br/>
306
+
307
+ ## 🔧 Environment Variables
308
+ Make sure you define your environment variables in a `.env` file:
309
+ ```ini
310
+ VITE_APP_ID="your-app-id"
311
+ VITE_API_URL="your-api-url"
312
+ VITE_CLIENT_ID="your-client-id"
313
+ ```
314
+
315
+ **Note**: `VITE_APP_ID` can be either a string or number, and will be automatically converted to the appropriate type when passed to the `VerifierProvider`.
316
+ <br/><br/>
317
+
318
+ ## 🛠 Development
319
+ 1. Clone the repo.
320
+ 2. Run `npm install` or `yarn install`.
321
+ 3. Start development:
322
+ ```sh
323
+ npm run dev
324
+ ```
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@abaxx_tech/v-integration-react",
3
+ "version": "1.1.0",
4
+ "publishConfig": {
5
+ "registry": "https://registry.npmjs.org"
6
+ },
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/abaxxtech/v-integration-react.git"
10
+ },
11
+ "type": "module",
12
+ "license": "GPL-3.0-or-later",
13
+ "author": "Abaxx Technologies <developer@abaxx.tech>",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "main": "./dist/v-integration-react.umd.cjs",
18
+ "module": "./dist/v-integration-react.js",
19
+ "types": "./dist/v-integration-react.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/v-integration-react.d.ts",
23
+ "styles": "./dist/v-integration-react.css",
24
+ "import": "./dist/v-integration-react.js",
25
+ "require": "./dist/v-integration-react.umd.cjs"
26
+ },
27
+ "./index.css": {
28
+ "import": "./dist/v-integration-react.css",
29
+ "require": "./dist/v-integration-react.css"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "dev": "vite",
34
+ "prebuild": "rm -rf dist",
35
+ "build": "tsc -b && vite build",
36
+ "dev:watch": "vite build --watch",
37
+ "lint": "eslint .",
38
+ "preview": "vite preview"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=18.0.0 <19",
42
+ "react-dom": ">=18.0.0 <19",
43
+ "uuid": ">=9.0.1"
44
+ },
45
+ "devDependencies": {
46
+ "@eslint/js": "^9.21.0",
47
+ "@tailwindcss/vite": "^4.0.9",
48
+ "@types/node": "^22.13.5",
49
+ "@types/react": "^18.0.10",
50
+ "@types/react-dom": "^18.0.4",
51
+ "@vitejs/plugin-react": "^4.3.4",
52
+ "eslint": "^9.21.0",
53
+ "eslint-plugin-react-hooks": "^5.0.0",
54
+ "eslint-plugin-react-refresh": "^0.4.19",
55
+ "globals": "^15.15.0",
56
+ "rollup-plugin-typescript2": "^0.36.0",
57
+ "tailwindcss": "^4.0.9",
58
+ "typescript": "~5.7.2",
59
+ "typescript-eslint": "^8.24.1",
60
+ "vite": "^6.2.0",
61
+ "vite-plugin-dts": "^4.5.3"
62
+ },
63
+ "dependencies": {
64
+ "react-qrcode-logo": "^3.0.0"
65
+ }
66
+ }