@eka-care/abha 0.1.49 → 0.1.50
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 +101 -372
- package/dist/sdk/abha/js/abha.js +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,385 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Login Frontend App for Eka Care
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This application is in early development mode.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## How to Use Login Frontend App
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Follow these steps to use the `window.initAuthApp` function from the `main.tsx` file:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
1. **Include the Required Scripts and Styles**:
|
|
10
|
+
Ensure that you have included the necessary scripts and styles in your HTML file.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
```html
|
|
13
|
+
<link rel="stylesheet" href="https://login.eka.care/assets/css/index.css" />
|
|
14
|
+
<script type="module" src="https://login.eka.care/assets/js/lo-fe-main.js"></script>
|
|
15
|
+
```
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
2. **Prepare the Container Element**:
|
|
18
|
+
Create a container element in your HTML where the React app will be mounted.
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- A valid HTML container element where the SDK will mount.
|
|
20
|
+
```html
|
|
21
|
+
<div id="lofe_root"></div>
|
|
22
|
+
```
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
3. **Implement Callback Functions**:
|
|
25
|
+
Define the `onSuccess` and `onError` callback functions to handle authentication outcomes.
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
**onSuccess**: This function is called when the authentication is successful. Use it to process the authenticated user's data or redirect them within your application.
|
|
24
28
|
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
```javascript
|
|
30
|
+
function onSuccess(params) {
|
|
31
|
+
// Handle successful authentication
|
|
32
|
+
console.log('Authentication successful:', params);
|
|
33
|
+
// Redirect user or update UI accordingly
|
|
34
|
+
}
|
|
35
|
+
```
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
<link
|
|
33
|
-
rel="stylesheet"
|
|
34
|
-
href="https://unpkg.com/@eka-care/abha/dist/sdk/abha/css/abha.css"
|
|
35
|
-
/>
|
|
36
|
-
</head>
|
|
37
|
-
<body>
|
|
38
|
-
<h1>ABHA SDK Demo</h1>
|
|
37
|
+
- @param params - An object containing authentication tokens and the user's profile information.
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<script>
|
|
54
|
-
function mountABHASDK() {
|
|
55
|
-
window.initAbhaApp({
|
|
56
|
-
containerId: "sdk_container",
|
|
57
|
-
|
|
58
|
-
// Pass access token and oid
|
|
59
|
-
data: {
|
|
60
|
-
accessToken: "<your_access_token>", // Pass the access token you have
|
|
61
|
-
oid: "<your_oid_if_available>", // Pass if you have the OID
|
|
62
|
-
orgIcon: "<url_of_your_org_icon>", // Pass the url to your organisation icon which starts with for ex: https://cdn.eka.care/vagus/cl56w6zg3001f0scsaqrh16is.jpg
|
|
63
|
-
linkToOrgIcon: "<url_of_image_to_link_abha_to_your_org>", // Pass the url of an image which depicts linking abha to your organisation for ex https://cdn.eka.care/vagus/cm6agrs5000090tfwfz984x5b.webp
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
// Success callback
|
|
67
|
-
onSuccess: async (params) => {
|
|
68
|
-
console.log("ABHA flow completed successfully:", params);
|
|
69
|
-
// Example: Store ABHA data in your app
|
|
70
|
-
dispatch({
|
|
71
|
-
type: "set-only-healthid-data",
|
|
72
|
-
healthIdData: formatter(params.response.data),
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
// Error callback
|
|
77
|
-
onError: (params) => {
|
|
78
|
-
console.error("ABHA flow failed:", params);
|
|
79
|
-
if (window.EkaAbha) {
|
|
80
|
-
window.EkaAbha.onAbhaFailure(JSON.stringify(params));
|
|
39
|
+
```javascript
|
|
40
|
+
{
|
|
41
|
+
response: {
|
|
42
|
+
txn_id: "Transaction id string",
|
|
43
|
+
skip_state: 1,
|
|
44
|
+
method: 2,
|
|
45
|
+
data: {
|
|
46
|
+
tokens: {
|
|
47
|
+
sess: "A string representing the session token.",
|
|
48
|
+
refresh: "A string representing the refresh token.",
|
|
49
|
+
},
|
|
50
|
+
profile: "The user's profile.",
|
|
81
51
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
skip_state: number;
|
|
146
|
-
method: AUTH_METHOD;
|
|
147
|
-
data?: {
|
|
148
|
-
tokens: {
|
|
149
|
-
sess: string;
|
|
150
|
-
refresh: string;
|
|
151
|
-
};
|
|
152
|
-
profile: TProfileRecord;
|
|
153
|
-
};
|
|
154
|
-
txn_id: string;
|
|
155
|
-
error?: {
|
|
156
|
-
code: number;
|
|
157
|
-
message: string;
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
**Parameters**
|
|
163
|
-
| Key | Type | Description |
|
|
164
|
-
| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
165
|
-
| `response` | `TAuthVerifyV2Response` | The complete ABHA verification response, containing session tokens, user profile, and transaction details. |
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
**Example:**
|
|
170
|
-
|
|
171
|
-
```javascript
|
|
172
|
-
const onSuccess = (params) => {
|
|
173
|
-
console.log("ABHA Success:", params.response);
|
|
174
|
-
|
|
175
|
-
const abhaNumber = params.response.data?.profile?.abha_number;
|
|
176
|
-
const userName = params.response.data?.profile?.name;
|
|
177
|
-
|
|
178
|
-
alert(`Welcome ${userName}! Your ABHA Number: ${abhaNumber}`);
|
|
179
|
-
|
|
180
|
-
// Optionally pass data to native bridge
|
|
181
|
-
if (window.EkaAbha) {
|
|
182
|
-
window.EkaAbha.onAbhaSuccess(JSON.stringify(params));
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### onError Callback
|
|
188
|
-
The onError callback is triggered whenever an ABHA flow fails or is interrupted.
|
|
189
|
-
It provides details about the failure through structured parameters, allowing you to handle or forward the error appropriately (for example, to native apps or monitoring tools).
|
|
190
|
-
|
|
191
|
-
**Callback Signature:**
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
onError: (params: TOnAbhaFailureParams) => void;
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
**Type Definitions**
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
type TOnAbhaFailureParams = {
|
|
201
|
-
error?: string;
|
|
202
|
-
response?: TAuthVerifyV2Response;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export type TAuthVerifyV2Response = {
|
|
206
|
-
skip_state: number;
|
|
207
|
-
method: AUTH_METHOD;
|
|
208
|
-
data?: {
|
|
209
|
-
tokens: {
|
|
210
|
-
sess: string;
|
|
211
|
-
refresh: string;
|
|
212
|
-
};
|
|
213
|
-
profile: TProfileRecord;
|
|
214
|
-
};
|
|
215
|
-
txn_id: string;
|
|
216
|
-
error?: {
|
|
217
|
-
code: number;
|
|
218
|
-
message: string;
|
|
219
|
-
};
|
|
220
|
-
};
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
**Parameters**
|
|
224
|
-
| Key | Type | Description |
|
|
225
|
-
| ---------- | ------------------------ | ---------------------------------------------------------------- |
|
|
226
|
-
| `error` | `string?` | Short description of the failure or error message. |
|
|
227
|
-
| `response` | `TAuthVerifyV2Response?` | Partial or full API response object returned from ABHA services. |
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
**Example:**
|
|
231
|
-
|
|
232
|
-
```javascript
|
|
233
|
-
const onError = (params) => {
|
|
234
|
-
console.error("ABHA Error:", params);
|
|
235
|
-
|
|
236
|
-
if (params.response?.error?.code === 1001) {
|
|
237
|
-
alert("Authentication failed. Please try again.");
|
|
238
|
-
} else if (params.error === "NETWORK_ERROR") {
|
|
239
|
-
alert("Please check your internet connection.");
|
|
240
|
-
} else {
|
|
241
|
-
alert("Something went wrong. Please retry.");
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Forward the error to native handler if available
|
|
245
|
-
if (window.EkaAbha) {
|
|
246
|
-
window.EkaAbha.onAbhaFailure(JSON.stringify(params));
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
**Suggest Handling**
|
|
252
|
-
-Always log the full error response (params) for debugging.
|
|
253
|
-
-Display friendly error messages for known error.code values.
|
|
254
|
-
-If params.response is present, inspect response.error.message for more detail.
|
|
255
|
-
-If integrating with native apps, forward the serialized error object:
|
|
256
|
-
```javascript
|
|
257
|
-
window.EkaAbha.onAbhaFailure(JSON.stringify(params));
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Container Styling
|
|
261
|
-
Ensure your container has sufficient space:
|
|
262
|
-
```html
|
|
263
|
-
<div
|
|
264
|
-
id="sdk_container"
|
|
265
|
-
style="width: 100%; height: 600px; border: 1px solid #ddd;"
|
|
266
|
-
></div>
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
## Complete Implementation Example
|
|
270
|
-
|
|
271
|
-
```html
|
|
272
|
-
<!DOCTYPE html>
|
|
273
|
-
<html>
|
|
274
|
-
<head>
|
|
275
|
-
<title>ABHA SDK Complete Example</title>
|
|
276
|
-
<link
|
|
277
|
-
rel="stylesheet"
|
|
278
|
-
href="https://unpkg.com/@eka-care/abha/dist/sdk/abha/css/abha.css"
|
|
279
|
-
/>
|
|
280
|
-
</head>
|
|
281
|
-
<body>
|
|
282
|
-
<h1>ABHA SDK Demo</h1>
|
|
283
|
-
|
|
284
|
-
<button onclick="mountABHASDK()">Launch ABHA SDK</button>
|
|
285
|
-
|
|
286
|
-
<div
|
|
287
|
-
id="sdk_container"
|
|
288
|
-
style="width: 100%; height: 600px; border: 1px solid #ccc;"
|
|
289
|
-
></div>
|
|
290
|
-
|
|
291
|
-
<script
|
|
292
|
-
type="module"
|
|
293
|
-
async
|
|
294
|
-
src="https://unpkg.com/@eka-care/abha/dist/sdk/abha/js/abha.js"
|
|
295
|
-
></script>
|
|
296
|
-
|
|
297
|
-
<script>
|
|
298
|
-
function mountABHASDK() {
|
|
299
|
-
window.initAbhaApp({
|
|
300
|
-
containerId: "sdk_container",
|
|
301
|
-
data: {
|
|
302
|
-
accessToken: "<your_access_token>",
|
|
303
|
-
oid: "<your_oid_if_available>",
|
|
304
|
-
orgIcon: "<url_of_your_org_icon>",
|
|
305
|
-
linkToOrgIcon: "<url_of_image_to_link_abha_to_your_org>",
|
|
306
|
-
},
|
|
307
|
-
onSuccess: (params) => {
|
|
308
|
-
console.log("ABHA flow completed successfully:", params);
|
|
309
|
-
},
|
|
310
|
-
onError: (params) => {
|
|
311
|
-
console.error("ABHA flow failed:", params);
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
</script>
|
|
316
|
-
</body>
|
|
317
|
-
</html>
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
## Type Definitions
|
|
321
|
-
|
|
322
|
-
```typescript
|
|
323
|
-
interface InitAbhaAppParams {
|
|
324
|
-
containerId: string;
|
|
325
|
-
data?: {
|
|
326
|
-
accessToken: string;
|
|
327
|
-
oid?: string;
|
|
328
|
-
orgIcon?: string;
|
|
329
|
-
linkToOrgIcon?: string;
|
|
330
|
-
};
|
|
331
|
-
onSuccess: (params: AbhaSuccessParams) => void;
|
|
332
|
-
onError: (params: AbhaErrorParams) => void;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
interface AbhaSuccessParams {
|
|
336
|
-
response: {
|
|
337
|
-
data: {
|
|
338
|
-
abha_number?: string;
|
|
339
|
-
abha_address?: string;
|
|
340
|
-
name?: string;
|
|
341
|
-
gender?: string;
|
|
342
|
-
yearOfBirth?: string;
|
|
343
|
-
mobile?: string;
|
|
344
|
-
};
|
|
345
|
-
};
|
|
346
|
-
message: string;
|
|
347
|
-
status: "SUCCESS";
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
interface AbhaErrorParams {
|
|
351
|
-
status: "FAILED";
|
|
352
|
-
message: string;
|
|
353
|
-
error_code?: string;
|
|
354
|
-
details?: any;
|
|
355
|
-
}
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
## Troubleshooting
|
|
359
|
-
|
|
360
|
-
### Common Issues
|
|
361
|
-
|
|
362
|
-
#### 1. SDK Not Rendering
|
|
363
|
-
|
|
364
|
-
**Problem**: Nothing appears in the container.
|
|
365
|
-
|
|
366
|
-
**Solution**:
|
|
367
|
-
- Ensure containerId matches an existing HTML element.
|
|
368
|
-
- Verify the SDK JS and CSS are correctly loaded.
|
|
369
|
-
- Check browser console for errors.
|
|
370
|
-
|
|
371
|
-
#### 2. Callback Not Triggered
|
|
372
|
-
|
|
373
|
-
**Problem**: onSuccess or onError isn’t firing.
|
|
374
|
-
|
|
375
|
-
**Solution**:
|
|
376
|
-
- Make sure both callbacks are passed as valid functions.
|
|
377
|
-
- Avoid race conditions (e.g., calling before SDK fully loads).
|
|
378
|
-
|
|
379
|
-
#### 3. Styling Issues
|
|
380
|
-
|
|
381
|
-
**Problem**: SDK content appears misaligned or clipped.
|
|
382
|
-
|
|
383
|
-
**Solution**:
|
|
384
|
-
- Give your container a fixed height (e.g., 600px).
|
|
385
|
-
- Ensure no parent element uses overflow: hidden.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**onError**: This function is invoked when there is an error during authentication. Use it to handle errors, display error messages, or perform logging.
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
function onError(params) {
|
|
60
|
+
// Handle authentication error
|
|
61
|
+
console.error('Authentication error:', params);
|
|
62
|
+
// Display error message to the user or take corrective action
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- @param params - An object containing authentication error.
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
{
|
|
70
|
+
error: 'Error message';
|
|
71
|
+
response: {
|
|
72
|
+
txn_id: "Transaction id string",
|
|
73
|
+
skip_state: 1,
|
|
74
|
+
method: 2,
|
|
75
|
+
error: 'error message from api'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
4. **Initialize the App**:
|
|
81
|
+
Call the `window.initAuthApp` function with the required parameters.
|
|
82
|
+
|
|
83
|
+
```html
|
|
84
|
+
<script>
|
|
85
|
+
window.onload = function () {
|
|
86
|
+
window.initAuthApp({
|
|
87
|
+
clientId: 'your_client_id',
|
|
88
|
+
containerId: 'lofe_root',
|
|
89
|
+
workspaceName: 'your_workspace_name', // Optional
|
|
90
|
+
urlParams: { next_url: 'next_url' }, // Optional
|
|
91
|
+
method: 'email_mobile', // Optional
|
|
92
|
+
onSuccess: function (params) {
|
|
93
|
+
// Handle success
|
|
94
|
+
},
|
|
95
|
+
onError: function (params) {
|
|
96
|
+
// Handle error
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
</script>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`window.initAuthApp` returns an unmount function to remove the Login app.
|
|
104
|
+
|
|
105
|
+
5. **Close the App**:
|
|
106
|
+
To unmount the Lofe app and clear the store, call the `window.closeAuthApp` function or the function that is returned by `window.initAuthApp`
|
|
107
|
+
|
|
108
|
+
```html
|
|
109
|
+
<script>
|
|
110
|
+
window.closeAuthApp();
|
|
111
|
+
</script>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
By following these steps, you can successfully initialize and use the login frontend app for Eka Care.
|