@eka-care/abha-stg 0.1.34 → 0.1.35

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 (116) hide show
  1. package/README.md +369 -101
  2. package/{dist/index.html → index.html} +1 -2
  3. package/package/styles/pds2/border.ts +69 -0
  4. package/package/styles/pds2/colors.ts +70 -0
  5. package/package/styles/pds2/spacing.ts +1007 -0
  6. package/package/tailwind/tailwind.config.ts +124 -0
  7. package/package.json +9 -8
  8. package/postcss.config.js +6 -0
  9. package/scripts/build-purged-css.cjs +70 -0
  10. package/src/App.css +0 -0
  11. package/src/App.tsx +43 -0
  12. package/src/api-queries/aorta-go/v3/get-profile-patient.ts +32 -0
  13. package/src/api-queries/aorta-go/v3/get-profiles-phr-user.ts +26 -0
  14. package/src/api-queries/aorta-go/v3/post-auth-init-v2.ts +34 -0
  15. package/src/api-queries/aorta-go/v3/post-auth-logout-v2.ts +32 -0
  16. package/src/api-queries/aorta-go/v3/post-auth-verify-v2.ts +38 -0
  17. package/src/api-queries/aorta-go/v3/post-profile-switch.ts +39 -0
  18. package/src/api-queries/ndhm/get-abdm-register-suggest.ts +37 -0
  19. package/src/api-queries/ndhm/get-pincode-details.ts +28 -0
  20. package/src/api-queries/ndhm/post-abdm-login-init.ts +37 -0
  21. package/src/api-queries/ndhm/post-abdm-login-phr.ts +37 -0
  22. package/src/api-queries/ndhm/post-abdm-login-verify.ts +37 -0
  23. package/src/api-queries/ndhm/post-abdm-profile-eka-link-phr.ts +40 -0
  24. package/src/api-queries/ndhm/post-abdm-profile-eka.ts +66 -0
  25. package/src/api-queries/ndhm/post-abdm-register-abha-number-create-phr.ts +37 -0
  26. package/src/api-queries/ndhm/post-abdm-register-mobile-create-phr.ts +66 -0
  27. package/src/api-queries/ndhm/post-abdm-register-mobile-resend-otp.ts +32 -0
  28. package/src/api-queries/ndhm/post-abdm-register-mobile-verify.ts +38 -0
  29. package/src/api-queries/ndhm/post-abdm-register-phr-check.ts +34 -0
  30. package/src/api-queries/ndhm/post-register-aadhaar-create-phr.ts +37 -0
  31. package/src/api-queries/ndhm/post-register-aadhaar-init.ts +34 -0
  32. package/src/api-queries/ndhm/post-register-aadhaar-mobile-resend-otp.ts +34 -0
  33. package/src/api-queries/ndhm/post-register-aadhaar-mobile-verify.ts +37 -0
  34. package/src/api-queries/ndhm/post-register-aadhaar-resend-otp.ts +34 -0
  35. package/src/api-queries/ndhm/post-register-aadhaar-verify.ts +40 -0
  36. package/src/api-queries/ndhm/post-register-mobile-init.ts +34 -0
  37. package/src/api-queries/use-get-profiles-patient.ts +12 -0
  38. package/src/api-queries/use-get-profiles-phr-user.ts +28 -0
  39. package/src/api-queries/use-post-abdm-login-verify-v1.ts +26 -0
  40. package/src/api-queries/use-post-auth-verify-v2.ts +50 -0
  41. package/src/api-queries/use-post-profile-switch.ts +58 -0
  42. package/src/api-queries/use-post-register-mobile-create-phr.ts +39 -0
  43. package/src/api-queries/user-post-abdm-profile-login-phr.ts +26 -0
  44. package/src/assets/Success.json +1 -0
  45. package/src/assets/react.svg +1 -0
  46. package/src/atoms/button/custom-button.tsx +32 -0
  47. package/src/atoms/button/index.tsx +40 -0
  48. package/src/atoms/button/types.d.ts +31 -0
  49. package/src/atoms/header.tsx +25 -0
  50. package/src/atoms/input-field/index.tsx +63 -0
  51. package/src/atoms/input-field/patient-input-field.tsx +16 -0
  52. package/src/atoms/input-field/types.ts +24 -0
  53. package/src/atoms/pds2-otp-input/index.tsx +35 -0
  54. package/src/atoms/pds2-otp-input/types.d.ts +3 -0
  55. package/src/atoms/single-input-chip/index.tsx +32 -0
  56. package/src/atoms/single-input-chip/types.ts +6 -0
  57. package/src/atoms/spinner.tsx +33 -0
  58. package/src/atoms/text-separator.tsx +11 -0
  59. package/src/atoms/ui/spinner.tsx +75 -0
  60. package/src/constants/constants.ts +376 -0
  61. package/src/fetch-client/index.ts +164 -0
  62. package/src/index.css +152 -0
  63. package/src/main.tsx +374 -0
  64. package/src/molecules/abha/bottom-sheet/bottom-sheet-wrapper.tsx +40 -0
  65. package/src/molecules/abha/bottom-sheet/index.tsx +66 -0
  66. package/src/molecules/abha/spaced-input-component.tsx +168 -0
  67. package/src/molecules/copyright-year.tsx +16 -0
  68. package/src/molecules/exit-popup/index.tsx +101 -0
  69. package/src/molecules/pds2-otp-component/index.tsx +147 -0
  70. package/src/organisms/abha/abha-header.tsx +25 -0
  71. package/src/organisms/abha/abha-stepper.tsx +83 -0
  72. package/src/organisms/abha/error-bottom-sheet.tsx +27 -0
  73. package/src/organisms/abha/otp-card.tsx +99 -0
  74. package/src/organisms/abha/verification-status.tsx +30 -0
  75. package/src/organisms/choose-language/choose-language.tsx +53 -0
  76. package/src/organisms/choose-language/types.ts +10 -0
  77. package/src/organisms/screen-switcher/screen-switcher.tsx +80 -0
  78. package/src/routes/abha-aadhaar-verification-status-screen.tsx +246 -0
  79. package/src/routes/abha-created-screen.tsx +45 -0
  80. package/src/routes/abha-login-otp-verify-screen.tsx +519 -0
  81. package/src/routes/abha-mobile-linking-status-screen.tsx +267 -0
  82. package/src/routes/abha-otp-and-mobile-screen.tsx +435 -0
  83. package/src/routes/abha-phone-number-verification-screen.tsx +388 -0
  84. package/src/routes/create-abha-address-screen.tsx +928 -0
  85. package/src/routes/create-abha-with-aadhaar-screen.tsx +986 -0
  86. package/src/routes/create-eka-profile-screen.tsx +831 -0
  87. package/src/routes/get-all-profiles-screen.tsx +161 -0
  88. package/src/routes/login-or-create-abha-address-screen.tsx +1056 -0
  89. package/src/routes/login-with-abha-screen.tsx +454 -0
  90. package/src/routes/select-abha-from-list-screen.tsx +792 -0
  91. package/src/routes/select-eka-profile-screen.tsx +446 -0
  92. package/src/routes/utils/trackAbhaEvent.ts +41 -0
  93. package/src/stores/auth-abha-store/index.ts +152 -0
  94. package/src/stores/auth-abha-store/types.ts +217 -0
  95. package/src/utils/mock-auth-response.ts +29 -0
  96. package/src/utils/send-event-utils.ts +76 -0
  97. package/src/utils/validations.ts +89 -0
  98. package/src/vite-env.d.ts +1 -0
  99. package/tailwind.config.ts +9 -0
  100. package/tsconfig.json +25 -0
  101. package/tsconfig.node.json +10 -0
  102. package/tsconfig.node.tsbuildinfo +1 -0
  103. package/tsconfig.tsbuildinfo +1 -0
  104. package/vite.config.d.ts +2 -0
  105. package/vite.config.js +30 -0
  106. package/vite.config.ts +35 -0
  107. package/dist/sdk/abha/css/abha.css +0 -1
  108. package/dist/sdk/abha/js/abha.js +0 -146
  109. /package/{dist → public}/images/adhaar.webp +0 -0
  110. /package/{dist → public}/images/at-the-rate.webp +0 -0
  111. /package/{dist → public}/images/avatar.webp +0 -0
  112. /package/{dist → public}/images/ayushman-bharat.webp +0 -0
  113. /package/{dist → public}/images/circle-checkmark.webp +0 -0
  114. /package/{dist → public}/images/link-abha.webp +0 -0
  115. /package/{dist → public}/images/national-authority.webp +0 -0
  116. /package/{dist → public}/images/three-dots.webp +0 -0
@@ -0,0 +1,11 @@
1
+ const TextSeparator = ({ title }: { title: string }) => {
2
+ return (
3
+ <div className="pds2-relative pds2-flex pds2-flex-row pds2-items-center pds2-gap-16">
4
+ <div className="pds2-w-full pds2-h-1 pds2-bg-border-03"></div>
5
+ <div className="pds2-text-text-04 Body2Regular pds2-text-center pds2-min-w-max">{title}</div>
6
+ <div className="pds2-w-full pds2-h-1 pds2-bg-border-03"></div>
7
+ </div>
8
+ );
9
+ };
10
+
11
+ export default TextSeparator;
@@ -0,0 +1,75 @@
1
+ type TSpinner = {
2
+ className?: string;
3
+ size?: number;
4
+ };
5
+
6
+ const Spinner = ({ className = "", size = 40 }: TSpinner): JSX.Element => {
7
+ return (
8
+ <div
9
+ className={`pds2-w-full pds2-flex pds2-justify-center pds2-items-center ${className}`}
10
+ >
11
+ <svg
12
+ className="pds2-animate-spin"
13
+ id="svg-spinner"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ width={size}
16
+ height={size}
17
+ viewBox="0 0 48 48"
18
+ fill="currentColor"
19
+ >
20
+ <circle cx="24" cy="4" r="2.5" className="fill-current opacity-100" />
21
+ <circle
22
+ cx="12.19"
23
+ cy="7.86"
24
+ r="2.5"
25
+ className="fill-current opacity-90"
26
+ />
27
+ <circle
28
+ cx="5.02"
29
+ cy="17.68"
30
+ r="2.5"
31
+ className="fill-current opacity-80"
32
+ />
33
+ <circle
34
+ cx="5.02"
35
+ cy="30.32"
36
+ r="2.5"
37
+ className="fill-current opacity-70"
38
+ />
39
+ <circle
40
+ cx="12.19"
41
+ cy="40.14"
42
+ r="2.5"
43
+ className="fill-current opacity-60"
44
+ />
45
+ <circle cx="24" cy="44" r="2.5" className="fill-current opacity-50" />
46
+ <circle
47
+ cx="35.81"
48
+ cy="40.14"
49
+ r="2.5"
50
+ className="fill-current opacity-40"
51
+ />
52
+ <circle
53
+ cx="42.98"
54
+ cy="30.32"
55
+ r="2.5"
56
+ className="fill-current opacity-30"
57
+ />
58
+ <circle
59
+ cx="42.98"
60
+ cy="17.68"
61
+ r="2.5"
62
+ className="fill-current opacity-20"
63
+ />
64
+ <circle
65
+ cx="35.81"
66
+ cy="7.86"
67
+ r="2.5"
68
+ className="fill-current opacity-10"
69
+ />
70
+ </svg>
71
+ </div>
72
+ );
73
+ };
74
+
75
+ export default Spinner;
@@ -0,0 +1,376 @@
1
+ export enum ABHA_V3_SKIP_STATES {
2
+ ABHA_END = "abha_end",
3
+ CONFIRM_MOBILE_OTP = "confirm_mobile_otp",
4
+ ABHA_CREATE = "abha_create",
5
+ ABHA_SELECT = "abha_select",
6
+ }
7
+
8
+ export enum ABHA_AUTH_FLOW_METHOD {
9
+ PHR_ADDRESS = "phr_address",
10
+ MOBILE = "mobile",
11
+ ABHA_NUMBER = "abha_number",
12
+ AADHAR_NUMBER = "aadhaar_number",
13
+ REGISTRATION_TYPE = "registration_type",
14
+ }
15
+
16
+ // new enum for registration type
17
+ export enum REGISTRATION_TYPE {
18
+ LOGIN = "login",
19
+ CREATE = "create",
20
+ }
21
+
22
+ export type TProfileRecord = {
23
+ fln: string;
24
+ fn: string;
25
+ mn?: string;
26
+ ln?: string;
27
+ gen?: "M" | "F" | "O" | "U" | undefined; // 'male' | 'female' | 'other' | 'unknown'
28
+ dob?: string;
29
+ mobile?: string;
30
+ email?: string;
31
+ uuid?: string;
32
+ bloodgroup?: "" | "A+" | "A-" | "B+" | "B-" | "O+" | "O-" | "AB+" | "AB-";
33
+ pic?: string;
34
+ as?: string;
35
+ "dob-valid"?: boolean;
36
+ "is-d"?: boolean;
37
+ "is-d-s"?: boolean;
38
+ "is-p"?: boolean;
39
+ oid: string;
40
+ at: string;
41
+ type?: 1 | 2 | 3 | 4 | 5 | 6;
42
+ "health-ids"?: Array<string>;
43
+ abha_number?: string;
44
+ };
45
+
46
+ export enum LOADING_STATE {
47
+ IDLE = "IDLE",
48
+ LOADING = "LOADING",
49
+ RESOLVED = "RESOLVED",
50
+ REJECTED = "REJECTED",
51
+ }
52
+
53
+ export enum AUTH_METHOD {
54
+ EMAIL = 1,
55
+ MOBILE = 2,
56
+ ABHA = 7,
57
+ }
58
+
59
+ export type TAuthVerifyV2Response = {
60
+ skip_state: number;
61
+ method: AUTH_METHOD;
62
+ data?: {
63
+ tokens: {
64
+ sess: string;
65
+ refresh: string;
66
+ };
67
+ profile: TProfileRecord;
68
+ };
69
+ txn_id: string;
70
+ error?: {
71
+ code: number;
72
+ message: string;
73
+ };
74
+ };
75
+
76
+
77
+ type TNdhmErrorStructure = {
78
+ error: string;
79
+ code: string;
80
+ action?: {
81
+ title: string;
82
+ description: string;
83
+ img: string;
84
+ cta: {
85
+ title: string;
86
+ pid: string;
87
+ params: string | null;
88
+ };
89
+ };
90
+ };
91
+
92
+ export interface TGetProfilePhrUserResponse extends TNdhmErrorStructure {
93
+ txn_id?: string;
94
+ hint?: string;
95
+ skip_state?: ABHA_V3_SKIP_STATES;
96
+ profiles: TProfileRecord[];
97
+ abha_profiles?: Array<{
98
+ name: string;
99
+ abha_address: string;
100
+ oid: string;
101
+ }>;
102
+ eka?: {
103
+ min_token: string;
104
+ oid?: string;
105
+ };
106
+ }
107
+
108
+ export interface TPostRegisterVerifyResponse extends TNdhmErrorStructure {
109
+ txn_id?: string;
110
+ hint?: string;
111
+ skip_state?: ABHA_V3_SKIP_STATES;
112
+ profile?: {
113
+ abha_address: string;
114
+ abha_number: string;
115
+ first_name: string;
116
+ middle_name?: string;
117
+ last_name: string;
118
+ year_of_birth: number;
119
+ month_of_birth: number;
120
+ day_of_birth: number;
121
+ gender: string;
122
+ pincode: string;
123
+ address: string;
124
+ mobile: string;
125
+ kyc_verified: boolean;
126
+ };
127
+ abha_profiles?: Array<{
128
+ name: string;
129
+ abha_address: string;
130
+ oid: string;
131
+ }>;
132
+ eka?: {
133
+ min_token: string;
134
+ oid?: string;
135
+ };
136
+ }
137
+
138
+ export type TPostAbdmLoginVerifyResponse = TPostRegisterVerifyResponse;
139
+
140
+ export type TGetProfilesPhrResponse = TProfileRecord[];
141
+
142
+ export type TGetProfilesPatientResponse = TProfileRecord;
143
+
144
+ export type TAuthVerifyV2Request = {
145
+ txn_id: string;
146
+ } & (
147
+ | { code: string; token?: never }
148
+ | {
149
+ code?: never;
150
+ token: string;
151
+ }
152
+ );
153
+
154
+ export type TProfileSwitchResponse = {
155
+ sess: string;
156
+ refresh: string;
157
+ profile: TProfileRecord;
158
+ txn_id: string;
159
+ error?: {
160
+ code: number;
161
+ message: string;
162
+ };
163
+ skip_state: number;
164
+ method: AUTH_METHOD;
165
+ };
166
+
167
+ export interface TPostRegisterVerifyResponse extends TNdhmErrorStructure {
168
+ txn_id?: string;
169
+ hint?: string;
170
+ skip_state?: ABHA_V3_SKIP_STATES;
171
+ profile?: {
172
+ abha_address: string;
173
+ abha_number: string;
174
+ first_name: string;
175
+ middle_name?: string;
176
+ last_name: string;
177
+ year_of_birth: number;
178
+ month_of_birth: number;
179
+ day_of_birth: number;
180
+ gender: string;
181
+ pincode: string;
182
+ address: string;
183
+ mobile: string;
184
+ kyc_verified: boolean;
185
+ };
186
+ abha_profiles?: Array<{
187
+ name: string;
188
+ abha_address: string;
189
+ oid: string;
190
+ }>;
191
+ eka?: {
192
+ min_token: string;
193
+ oid?: string;
194
+ };
195
+ }
196
+
197
+ export interface TPostRegisterInitResponse extends TNdhmErrorStructure {
198
+ txn_id?: string;
199
+ hint?: string;
200
+ }
201
+
202
+ export interface TPostAbdmRegisterPhrResponse extends TNdhmErrorStructure {
203
+ txn_id?: string;
204
+ hint?: string;
205
+ skip_state?: ABHA_V3_SKIP_STATES;
206
+ exists?: boolean;
207
+ suggestions?: Array<string>;
208
+ eka?: {
209
+ min_token: string;
210
+ oid?: string;
211
+ };
212
+ }
213
+ export interface TPincodeResponse {
214
+ dist_code: string;
215
+ dist_name: string;
216
+ state_name: string;
217
+ state_code: string;
218
+ pincode: string;
219
+ error?: string;
220
+ code?: string;
221
+ }
222
+
223
+ export type TPostAbdmRegisterCreatePhrResponse = TPostRegisterVerifyResponse;
224
+ export type TPostAbdmLoginInitResponse = TPostRegisterInitResponse;
225
+ export type TPostAbdmProfileLoginPhrResponse = TPostRegisterVerifyResponse;
226
+ export type TGetAbdmRegisterSuggestResponse = TPostAbdmRegisterPhrResponse;
227
+ export type TPostAbdmProfileEkaLinkPhrResponse = TPostRegisterVerifyResponse;
228
+ export type TPostAbdmRegisterPhrCheckResponse = TPostAbdmRegisterPhrResponse;
229
+ export type TPostRegisterAddressCreatePhrResponse = TPostRegisterVerifyResponse;
230
+ export type TGetAbdhmPincodeDetailsResponse = TPincodeResponse;
231
+
232
+
233
+ export type TAuthInitV2Response = {
234
+ method: AUTH_METHOD;
235
+ message?: string;
236
+ txn_id: string;
237
+ error?: {
238
+ code: number;
239
+ message: string;
240
+ };
241
+ next_otp_request: string;
242
+ };
243
+
244
+ const PROD = {
245
+ AORTA_HOST: "https://auth.eka.care",
246
+ AORTA_GO_HOST: "https://aortago.eka.care",
247
+ TRYST_HOST: "https://tryst.eka.care",
248
+ AXON_HOST: "https://axon.eka.care",
249
+ PARCHI_HOST: "https://parchi.eka.care",
250
+ CURIO_HOST: "https://eka.care",
251
+ AVATAR_HOST: "https://a.eka.care",
252
+ PTDIR_HOST: "https://ptdir.eka.care",
253
+ TELE_HOST: "https://mweb.eka.care",
254
+ METROLPOLIS_HOST: "https://consultation.metropolisindia.com",
255
+ LUCID_WS_HOST: "https://lucid-ws.eka.care",
256
+ LUCID_HOST: "https://lucid.eka.care",
257
+ DEEPTHOUGHT_HOST: "https://deepthought.eka.care",
258
+ NDHM_HOST: "https://api.eka.care",
259
+ LOGIN_HOST: "https://login.eka.care",
260
+ HUB: "https://hub.eka.care",
261
+ RECEIPT_DOMAIN: "https://doc-receipts.eka.care",
262
+ };
263
+
264
+ const DEV = {
265
+ AORTA_HOST: "https://aorta.dev.eka.care",
266
+ AORTA_GO_HOST: "https://aortago.dev.eka.care",
267
+ // AORTA_GO_HOST: "https://aortago.eka.care",
268
+ // AORTA_GO_HOST: "https://aortago-pp.eka.care",
269
+ TRYST_HOST: "https://tryst.dev.eka.care",
270
+ AXON_HOST: "https://axon.dev.eka.care",
271
+ PARCHI_HOST: "https://parchi.dev.eka.care",
272
+ CURIO_HOST: "https://curio.dev.eka.care",
273
+ AVATAR_HOST: "https://eka-avatar.dev.eka.care",
274
+ PTDIR_HOST: "https://ptdir.dev.eka.care",
275
+ TELE_HOST: "https://mweb.dev.eka.care",
276
+ METROLPOLIS_HOST: "https://consultation.metropolisindia.com",
277
+ LUCID_WS_HOST: "https://lucid-ws.dev.eka.care",
278
+ LUCID_HOST: "https://lucid.dev.eka.care",
279
+ DEEPTHOUGHT_HOST: "https://deepthought.dev.eka.care",
280
+ NDHM_HOST: "https://api.dev.eka.care",
281
+ LOGIN_HOST: "https://login.dev.eka.care",
282
+ HUB: "https://hub.dev.eka.care",
283
+ RECEIPT_DOMAIN: "https://doc-receipt.s3.ap-south-1.amazonaws.com",
284
+ };
285
+
286
+ let envVar = DEV;
287
+ let client_id = "";
288
+ let extraHeaders: Record<string, string> | null = null;
289
+
290
+ type TSetEnvParams = {
291
+ env: "PROD" | "DEV";
292
+ clientId: string;
293
+ extraHeaders?: Record<string, string>;
294
+ };
295
+
296
+ const setEnv = ({
297
+ env,
298
+ clientId,
299
+ extraHeaders: newExtraHeaders,
300
+ }: TSetEnvParams) => {
301
+ envVar = env === "PROD" ? PROD : DEV;
302
+ client_id = clientId;
303
+ if (newExtraHeaders) {
304
+ extraHeaders = newExtraHeaders;
305
+ }
306
+ };
307
+
308
+ export const setIndividualEnv = ({
309
+ clientId: newClientId,
310
+ env: newEnv,
311
+ extraHeaders: newExtraHeaders,
312
+ }: Partial<TSetEnvParams>) => {
313
+ if (newClientId) {
314
+ client_id = newClientId;
315
+ }
316
+ if (newEnv) {
317
+ envVar = newEnv === "PROD" ? PROD : DEV;
318
+ }
319
+ if (newExtraHeaders) {
320
+ extraHeaders = { ...extraHeaders, ...newExtraHeaders };
321
+ }
322
+ };
323
+
324
+ export const GET_AORTA_HOST = () => envVar.AORTA_HOST;
325
+ export const GET_AORTA_GO_HOST = () => envVar.AORTA_GO_HOST;
326
+ export const GET_TRYST_HOST = () => envVar.TRYST_HOST;
327
+ export const GET_AXON_HOST = () => envVar.AXON_HOST;
328
+ export const GET_PARCHI_HOST = () => envVar.PARCHI_HOST;
329
+ export const GET_CURIO_HOST = () => envVar.CURIO_HOST;
330
+ export const GET_AVATAR_HOST = () => envVar.AVATAR_HOST;
331
+ export const GET_PTDIR_HOST = () => envVar.PTDIR_HOST;
332
+ export const GET_TELE_HOST = () => envVar.TELE_HOST;
333
+ export const GET_METROPOLIS_HOST = () => envVar.METROLPOLIS_HOST;
334
+ export const GET_LUCID_WS_HOST = () => envVar.LUCID_WS_HOST;
335
+ export const GET_LUCID_HOST = () => envVar.LUCID_HOST;
336
+ export const GET_DEEPTHOUGHT_HOST = () => envVar.DEEPTHOUGHT_HOST;
337
+ export const GET_NDHM_HOST = () => envVar.NDHM_HOST;
338
+ export const GET_LOGIN_HOST = () => envVar.LOGIN_HOST;
339
+ export const GET_HUB_HOST = () => envVar.HUB;
340
+ export const GET_CLIENT_ID = () => client_id;
341
+ export const GET_EXTRA_HEADERS = () => extraHeaders;
342
+ export default setEnv;
343
+
344
+
345
+ export type Contacts = Array<{
346
+ firstName: string;
347
+ id: string;
348
+ lastName: string;
349
+ phoneNumbers: string[];
350
+ }>;
351
+
352
+ export interface IBridge {
353
+ openPdf: ((url: string) => void) | undefined;
354
+ print: ((url: string) => void) | undefined;
355
+ showToast: ((message: string) => void) | undefined;
356
+ back: () => void;
357
+ openBottomWebview: ((url: string) => void) | undefined;
358
+ share: ((message: string) => void) | undefined;
359
+ logout: (() => void) | undefined;
360
+ closeActivity: (() => void) | undefined;
361
+ sendEvent: ((data: string) => void) | undefined;
362
+ logHandler: ((obj: any) => void) | undefined;
363
+ isRNCompatible:
364
+ | (() => { isRNPresent: boolean; isRNActiveForUser: boolean })
365
+ | (() => "");
366
+ mixPanel?: ((data: string) => void) | undefined;
367
+ openSupport?: (() => void) | undefined;
368
+ contacts?: ({
369
+ limit,
370
+ }: {
371
+ limit?: number;
372
+ }) => Promise<{ contacts: Contacts }> | void;
373
+ navigate:
374
+ | ((params: { pid: string; pageId: string | number; params: any }) => void)
375
+ | undefined;
376
+ }
@@ -0,0 +1,164 @@
1
+
2
+ import { Contacts, GET_AORTA_GO_HOST, GET_CLIENT_ID, GET_EXTRA_HEADERS, IBridge } from "../constants/constants";
3
+ import { sendApiFailedEvent } from "../utils/send-event-utils";
4
+
5
+ export async function refreshToken() {
6
+ const refreshOnNative = await updateToken();
7
+ if (refreshOnNative) {
8
+ return true;
9
+ }
10
+ const myHeaders = new Headers();
11
+ myHeaders.append("Content-Type", "application/json");
12
+ myHeaders.set("client-id", GET_CLIENT_ID());
13
+ const raw = JSON.stringify({});
14
+
15
+ const requestOptions: RequestInit = {
16
+ method: "POST",
17
+ headers: myHeaders,
18
+ body: raw,
19
+ redirect: "follow",
20
+ credentials: "include",
21
+ mode: "cors",
22
+ };
23
+ try {
24
+ const AORTA_GO_HOST = GET_AORTA_GO_HOST();
25
+ const response = await fetch(`${AORTA_GO_HOST}/emr/v3/auth/refresh`, {
26
+ ...requestOptions,
27
+ body: JSON.stringify({}),
28
+ });
29
+ if (response.status === 401) {
30
+ return false;
31
+ }
32
+ } catch (error) {
33
+ return false;
34
+ }
35
+ return true;
36
+ }
37
+
38
+ export default async function fetchWrapper(
39
+ url: RequestInfo,
40
+ options: RequestInit | undefined = {},
41
+ retry: boolean = true,
42
+ omitClientId: boolean = false
43
+ ): Promise<Response> {
44
+ try {
45
+ const fallbackAuth = window?.Eka?.getSessionToken?.() || "";
46
+ const newHeaders = new Headers(options.headers);
47
+
48
+ let clientId;
49
+
50
+ let currentPathname;
51
+
52
+ if (!newHeaders.get("client-id") && !omitClientId) {
53
+ newHeaders.set("client-id", GET_CLIENT_ID());
54
+ }
55
+
56
+ if (fallbackAuth && !newHeaders.get("auth")) {
57
+ newHeaders.set("auth", fallbackAuth);
58
+ }
59
+
60
+ // if (!newHeaders.get("x-eka-pt-oid")) {
61
+ // newHeaders.set("x-eka-pt-oid", GET_EKA_OID());
62
+ // }
63
+
64
+ const extraHeaders = GET_EXTRA_HEADERS();
65
+ if (extraHeaders) {
66
+ Object.keys(extraHeaders).forEach((key) => {
67
+ newHeaders.set(key, extraHeaders[key]);
68
+ });
69
+ }
70
+
71
+ const response: Response = await fetch(url, {
72
+ ...options,
73
+ headers: newHeaders,
74
+ });
75
+ if (!!window) {
76
+ currentPathname = window.location.pathname;
77
+ clientId = newHeaders.get("client-id");
78
+ }
79
+ if (response.status === 401 && retry) {
80
+ const loginSuccess = await refreshToken();
81
+ if (loginSuccess) {
82
+ return await fetchWrapper(url, options, false);
83
+ }
84
+ }
85
+ if (response.status > 401) {
86
+ sendApiFailedEvent({
87
+ url: url as string,
88
+ params: { responseStatus: response.status },
89
+ });
90
+ }
91
+ return response;
92
+ } catch (error: any) {
93
+ sendApiFailedEvent({
94
+ url: url as string,
95
+ params: { error: `${error.message || error}` },
96
+ });
97
+ console.error(error);
98
+ throw error;
99
+ }
100
+ }
101
+
102
+ let androidRefreshCB: Function[] = [];
103
+
104
+ async function refreshCallback(arg: any) {
105
+ // updateEkaHeaders();
106
+ androidRefreshCB.forEach((res) => res(true));
107
+ androidRefreshCB = [];
108
+ }
109
+
110
+ export async function updateToken() {
111
+ if (typeof window !== "undefined") {
112
+ if (typeof window?.Eka?.updateToken === "function") {
113
+ window.parent?.postMessage({ type: "REFRESH_TOKEN" }, "*");
114
+ window.refreshCallback = window.refreshCallback || refreshCallback;
115
+ return new Promise((res) => {
116
+ androidRefreshCB.push(res);
117
+ window?.Eka?.updateToken("refreshCallback");
118
+ });
119
+ }
120
+
121
+ if (
122
+ typeof window?.webkit?.messageHandlers?.statusCodeHandler?.postMessage ===
123
+ "function"
124
+ ) {
125
+ window.parent?.postMessage({ type: "REFRESH_TOKEN" }, "*");
126
+ window.refreshCallback = window.refreshCallback || refreshCallback;
127
+ return new Promise((res) => {
128
+ androidRefreshCB.push(res);
129
+ window?.webkit?.messageHandlers?.statusCodeHandler?.postMessage(
130
+ JSON.stringify({ status: 401 })
131
+ );
132
+ });
133
+ }
134
+ }
135
+ return false;
136
+ }
137
+
138
+ declare global {
139
+ interface Window {
140
+ Eka?: IBridge & {
141
+ getSessionToken: () => string;
142
+ updateToken: (callbackFunctionName: string) => void;
143
+ getHeaders: () => string;
144
+ isRNCompatible: () => string;
145
+ getContacts: (
146
+ contactSuccessCallback: string,
147
+ contactErrorCallback: string,
148
+ limit: number
149
+ ) => Contacts | void;
150
+ navigateTo: (pid: string, params: string) => void;
151
+ refreshCallback: Record<string, any>;
152
+ closeActivity: () => void;
153
+ };
154
+ webkit?: {
155
+ messageHandlers: {
156
+ [Property in keyof IBridge]: { postMessage: Function };
157
+ } & {
158
+ statusCodeHandler: { postMessage: Function };
159
+ supportChat: { postMessage: Function };
160
+ };
161
+ };
162
+ refreshCallback?: (arg: any) => void;
163
+ }
164
+ }