@eka-care/ekascribe-ts-sdk 1.4.39

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 (71) hide show
  1. package/README.md +437 -0
  2. package/dist/api/get-transaction-history.d.ts +5 -0
  3. package/dist/api/get-transaction-history.js +28 -0
  4. package/dist/api/get-voice-api-v2-config.d.ts +2 -0
  5. package/dist/api/get-voice-api-v2-config.js +26 -0
  6. package/dist/api/get-voice-api-v2-status.d.ts +51 -0
  7. package/dist/api/get-voice-api-v2-status.js +25 -0
  8. package/dist/api/get-voice-api-v3-status.d.ts +51 -0
  9. package/dist/api/get-voice-api-v3-status.js +26 -0
  10. package/dist/api/patch-transaction-status.d.ts +4 -0
  11. package/dist/api/patch-transaction-status.js +43 -0
  12. package/dist/api/post-cog-init.d.ts +3 -0
  13. package/dist/api/post-cog-init.js +15 -0
  14. package/dist/api/post-transaction-commit.d.ts +3 -0
  15. package/dist/api/post-transaction-commit.js +32 -0
  16. package/dist/api/post-transaction-init.d.ts +3 -0
  17. package/dist/api/post-transaction-init.js +40 -0
  18. package/dist/api/post-transaction-stop.d.ts +3 -0
  19. package/dist/api/post-transaction-stop.js +32 -0
  20. package/dist/audio-chunker/__tests__/audio-file-manager.test.d.ts +1 -0
  21. package/dist/audio-chunker/__tests__/audio-file-manager.test.js +5 -0
  22. package/dist/audio-chunker/audio-buffer-manager.d.ts +53 -0
  23. package/dist/audio-chunker/audio-buffer-manager.js +136 -0
  24. package/dist/audio-chunker/audio-file-manager.d.ts +96 -0
  25. package/dist/audio-chunker/audio-file-manager.js +579 -0
  26. package/dist/audio-chunker/vad-web.d.ts +90 -0
  27. package/dist/audio-chunker/vad-web.js +389 -0
  28. package/dist/aws-services/configure-aws.d.ts +5 -0
  29. package/dist/aws-services/configure-aws.js +13 -0
  30. package/dist/aws-services/get-files-s3.d.ts +10 -0
  31. package/dist/aws-services/get-files-s3.js +30 -0
  32. package/dist/aws-services/s3-retry-wrapper.d.ts +2 -0
  33. package/dist/aws-services/s3-retry-wrapper.js +38 -0
  34. package/dist/aws-services/translate-text-to-target-language.d.ts +6 -0
  35. package/dist/aws-services/translate-text-to-target-language.js +18 -0
  36. package/dist/aws-services/upload-file-to-s3.d.ts +13 -0
  37. package/dist/aws-services/upload-file-to-s3.js +48 -0
  38. package/dist/constants/constant.d.ts +27 -0
  39. package/dist/constants/constant.js +33 -0
  40. package/dist/constants/enums.d.ts +46 -0
  41. package/dist/constants/enums.js +51 -0
  42. package/dist/constants/setup-config.d.ts +14 -0
  43. package/dist/constants/setup-config.js +31 -0
  44. package/dist/constants/types.d.ts +224 -0
  45. package/dist/constants/types.js +1 -0
  46. package/dist/fetch-client/helper.d.ts +11 -0
  47. package/dist/fetch-client/helper.js +28 -0
  48. package/dist/fetch-client/index.d.ts +1 -0
  49. package/dist/fetch-client/index.js +36 -0
  50. package/dist/index.d.ts +60 -0
  51. package/dist/index.js +267 -0
  52. package/dist/main/end-recording.d.ts +3 -0
  53. package/dist/main/end-recording.js +141 -0
  54. package/dist/main/init-transaction.d.ts +3 -0
  55. package/dist/main/init-transaction.js +86 -0
  56. package/dist/main/pause-recording.d.ts +3 -0
  57. package/dist/main/pause-recording.js +59 -0
  58. package/dist/main/resume-recording.d.ts +3 -0
  59. package/dist/main/resume-recording.js +33 -0
  60. package/dist/main/retry-upload-recording.d.ts +5 -0
  61. package/dist/main/retry-upload-recording.js +69 -0
  62. package/dist/main/start-recording.d.ts +3 -0
  63. package/dist/main/start-recording.js +55 -0
  64. package/dist/shared-worker/s3-file-upload.d.ts +1 -0
  65. package/dist/shared-worker/s3-file-upload.js +109 -0
  66. package/dist/shared-worker/s3-file-upload.ts +126 -0
  67. package/dist/store/store.d.ts +35 -0
  68. package/dist/store/store.js +121 -0
  69. package/dist/utils/compress-mp3-audio.d.ts +2 -0
  70. package/dist/utils/compress-mp3-audio.js +24 -0
  71. package/package.json +53 -0
package/README.md ADDED
@@ -0,0 +1,437 @@
1
+ # Eka Care Ekascribe Typescript SDK Integration
2
+
3
+ This guide explains how to integrate the Eka Care Ekascribe Typescript SDK into your application.
4
+
5
+ ## Overview
6
+
7
+ The Eka Care Ekascribe SDK allows you to capture and process audio, generating structured medical documentation using Eka Care's voice transcription API.
8
+
9
+ ## Documentation
10
+
11
+ [Visit the documentation site](https://developer.eka.care/api-reference/general-tools/medical/voice/SDKs/TS-sdk)
12
+
13
+ ## Prerequisites
14
+
15
+ Before getting started, ensure you have:
16
+
17
+ - Node 14 or higher
18
+ - `npm` or `yarn` for dependency management
19
+ - Access and refresh tokens from Eka Care (optional for some methods)
20
+ - Microphone access via browser permissions
21
+ - Stable network connectivity
22
+
23
+ ## Installation
24
+
25
+ Install the SDK using `npm` or `yarn`:
26
+
27
+ ```bash
28
+ npm install ekascribe-ts-sdk
29
+ # or
30
+ yarn add ekascribe-ts-sdk
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### 1. Initialize Ekascribe
36
+
37
+ Before using any other method, initialize the SDK with access and refresh tokens.
38
+
39
+ ```ts
40
+ initEkascribe({
41
+ access_token: '<your_access_token>',
42
+ refresh_token: '<your_refresh_token>',
43
+ });
44
+ ```
45
+
46
+ ### 2. Fetch configurations list
47
+
48
+ Get supported input languages, output formats, and consultation modes.
49
+
50
+ ```ts
51
+ getEkascribeConfig();
52
+ ```
53
+
54
+ - #### Response type:
55
+
56
+ ```ts
57
+ {
58
+ data?: {
59
+ supported_languages: [
60
+ { id: '1', name: 'EN' },
61
+ { id: '2', name: 'HI' }
62
+ ];
63
+ supported_output_formats: [
64
+ { id: 'eka-emr-template', name: 'Eka EMR Format' },
65
+ { id: 'clinical-notes-template', name: 'Clinical Notes' }
66
+ ];
67
+ consultation_modes: [
68
+ {
69
+ id: 'consultation',
70
+ name: 'Consultation',
71
+ desc: 'Eka Scribe will listen to your conversation and create clinical notes'
72
+ },
73
+ {
74
+ id: 'dictation',
75
+ name: 'Dictation',
76
+ desc: 'Dictate your notes to Eka Scribe and create clinical notes'
77
+ }
78
+ ];
79
+ max_selection: {
80
+ languages: 2;
81
+ output_formats: 2;
82
+ consultation_mode: 2;
83
+ };
84
+ };
85
+ message?: string;
86
+ code?: number;
87
+ }
88
+ ```
89
+
90
+ ### 3. Init transaction
91
+
92
+ Use this method to init a transaction before starting recording.
93
+
94
+ ```ts
95
+ await initTransaction({
96
+ mode: 'consultation',
97
+ input_language: ['te', 'en'],
98
+ output_format_template: [{ template_id: 'eka_emr_template' }],
99
+ txn_id: 'abc-123',
100
+ });
101
+ ```
102
+
103
+ - #### Response type:
104
+
105
+ ```ts
106
+ {
107
+ error_code?: ERROR_CODE;
108
+ status_code: number;
109
+ message: string;
110
+ business_id?: string;
111
+ txn_id?: string;
112
+ oid?: string;
113
+ uuid?: string;
114
+ };
115
+ ```
116
+
117
+ ### 4. Start recording
118
+
119
+ Start recording with user-selected options.
120
+
121
+ ```ts
122
+ await startRecording();
123
+ ```
124
+
125
+ - #### Response type:
126
+
127
+ ```ts
128
+ {
129
+ error_code?: ERROR_CODE;
130
+ status_code: number;
131
+ message: string;
132
+ txn_id?: string;
133
+ };
134
+ ```
135
+
136
+ ### 5. Pause recording
137
+
138
+ Use the method to pause voice recording
139
+
140
+ ```ts
141
+ await pauseRecording();
142
+ ```
143
+
144
+ - #### Response type:
145
+
146
+ ```ts
147
+ {
148
+ error_code?: ERROR_CODE;
149
+ status_code: number;
150
+ message: string;
151
+ is_paused?: boolean;
152
+ };
153
+ ```
154
+
155
+ ### 6. Resume recording
156
+
157
+ Use the method to resume voice recording
158
+
159
+ ```ts
160
+ await resumeRecording();
161
+ ```
162
+
163
+ - #### Response type:
164
+
165
+ ```ts
166
+ {
167
+ error_code?: ERROR_CODE;
168
+ status_code: number;
169
+ message: string;
170
+ is_paused?: boolean;
171
+ };
172
+ ```
173
+
174
+ ### 7. End recording
175
+
176
+ Use the method to end voice recording
177
+
178
+ ```ts
179
+ await endRecording();
180
+ ```
181
+
182
+ - #### Response type:
183
+
184
+ ```ts
185
+ {
186
+ error_code?: ERROR_CODE;
187
+ status_code: number;
188
+ message: string;
189
+ failed_files?: ['1.mp3', '2.mp3']; // if there are any failed files
190
+ total_audio_files?: ['1.mp3', '2.mp3', '3.mp3', '4.mp3']; // list of all audio files generated
191
+ };
192
+ ```
193
+
194
+ ### 8. Retry upload recording
195
+
196
+ Use this method to retry uploading failed audio files.
197
+
198
+ ```ts
199
+ await retryUploadRecording({ force_commit: true / false });
200
+ ```
201
+
202
+ - #### Response type:
203
+
204
+ ```ts
205
+ {
206
+ error_code?: ERROR_CODE;
207
+ status_code: number;
208
+ message: string;
209
+ failed_files?: ['1.mp3', '2.mp3'];
210
+ total_audio_files?: ['1.mp3', '2.mp3', '3.mp3', '4.mp3'];
211
+ };
212
+ ```
213
+
214
+ `force_commit` behavior
215
+
216
+ -- If `force_commit` is set to `true`, the SDK will call the commit API even if some audio files still fail to upload after retrying once.
217
+
218
+ -- If `force_commit` is set to `false`, the SDK will wait until **all audio files** are uploaded successfully before making the commit request.
219
+
220
+ ### 9. Patch recording session status
221
+
222
+ Use the method to cancel a recording session.
223
+
224
+ ```ts
225
+ await patchSessionStatus({
226
+ sessionId: 'abc-123',
227
+ processing_status: 'cancelled',
228
+ processing_error: {
229
+ error: {
230
+ type: '',
231
+ code: 'cancelled_by_user',
232
+ msg: 'Cancelled_by_user',
233
+ },
234
+ },
235
+ });
236
+ ```
237
+
238
+ - #### Response type:
239
+
240
+ ```ts
241
+ {
242
+ status: string;
243
+ message: string;
244
+ code: number;
245
+ error?: {
246
+ code: string;
247
+ message: string;
248
+ display_message: string;
249
+ };
250
+ }
251
+ ```
252
+
253
+ ### 10. Commit transaction
254
+
255
+ Use this method to commit a transaction that is not yet committed or returned a "commit failed" error in a previous step.
256
+
257
+ ```ts
258
+ await commitTransactionCall();
259
+ ```
260
+
261
+ - #### Response type:
262
+
263
+ ```ts
264
+ {
265
+ error_code?: ERROR_CODE;
266
+ status_code: number;
267
+ message: string;
268
+ };
269
+ ```
270
+
271
+ ### 11. Stop transaction
272
+
273
+ Use this method to stop a transaction that has not yet been stopped or returned a "stop failed" error in a previous step.
274
+
275
+ ```ts
276
+ await stopTransactionCall();
277
+ ```
278
+
279
+ - #### Response type:
280
+
281
+ ```ts
282
+ {
283
+ error_code?: ERROR_CODE;
284
+ status_code: number;
285
+ message: string;
286
+ };
287
+ ```
288
+
289
+ ### 12. Get output template prescriptions
290
+
291
+ Use this method to fetch the final generated prescription output for a session.
292
+
293
+ ```ts
294
+ await getTemplateOutput({ txn_id: 'abc-123' });
295
+ ```
296
+
297
+ ### 13. Get previous sessions
298
+
299
+ Use this method to retrieve all the previous sessions for a specific doctor ID
300
+
301
+ ```ts
302
+ const sessions = await getSessionHistory({ txn_count: 10 });
303
+ ```
304
+
305
+ - #### Response type:
306
+
307
+ ```ts
308
+ {
309
+ data: [
310
+ {
311
+ "created_at": "string",
312
+ "b_id": "string",
313
+ "user_status": "string",
314
+ "processing_status": "string",
315
+ "txn_id": "string",
316
+ "mode": "string",
317
+ "uuid": "string",
318
+ "oid": "string"
319
+ }
320
+ ],
321
+ status: "string",
322
+ code: "number",
323
+ message: "string",
324
+ retrieved_count: "number"
325
+ }
326
+ ```
327
+
328
+ ### 14. Get total uploaded files
329
+
330
+ Use this method to retrieve all the audio files generated for a specific session.
331
+
332
+ ```ts
333
+ const files = await getTotalAudioFiles();
334
+ ```
335
+
336
+ - #### Response type:
337
+
338
+ ```ts
339
+ ['1.mp3', '2.mp3', '3.mp3', '4.mp3'];
340
+ ```
341
+
342
+ ### 15. Get successfully uploaded files
343
+
344
+ Use this method to retrieve all the audio files that were uploaded successfully.
345
+
346
+ ```ts
347
+ const successFiles = await getSuccessfullyUploadedFiles();
348
+ ```
349
+
350
+ - #### Response type:
351
+
352
+ ```ts
353
+ ['3.mp3', '4.mp3'];
354
+ ```
355
+
356
+ ### 16. Get failed audio files
357
+
358
+ Use this method to retrieve all the audio files that failed to upload.
359
+
360
+ ```ts
361
+ const failedFiles = await getFailedFiles();
362
+ ```
363
+
364
+ - #### Response type:
365
+
366
+ ```ts
367
+ ['1.mp3', '2.mp3'];
368
+ ```
369
+
370
+ ## Generic Callbacks
371
+
372
+ ### 1. Error callback
373
+
374
+ Whenever an error occurs in the SDK during voice recording, the following callback will be triggered. You can listen to this to handle errors globally.
375
+
376
+ ```ts
377
+ onError(({ error_code, status_code, message }) => {
378
+ console.error('Ekascribe SDK Error:', { error_code, status_code, message });
379
+ });
380
+ ```
381
+
382
+ ### 2. User speech callback
383
+
384
+ This callback will return a boolean indicating whether the user is speaking or not.
385
+
386
+ ```ts
387
+ onUserSpeechCallback((isSpeech) => {
388
+ console.error(isSpeech ? 'User is speaking' : 'User is not speaking');
389
+ });
390
+ ```
391
+
392
+ ### 3. File upload progress callback
393
+
394
+ This callback provides the number of successfully uploaded files, the total number of files, the filename, and the chunk data for a particular file.
395
+
396
+ ```ts
397
+ onFileUploadProgressCallback(({ success, total, fileName, chunkData }) => {
398
+ console.error('Progress till now: ', { success, total, fileName, chunkData });
399
+ });
400
+ ```
401
+
402
+ ### Error codes
403
+
404
+ | Error Code | Description |
405
+ | --------------------- | ----------------------------------------------------------- |
406
+ | `microphone` | Microphone access error (permission denied or unavailable) |
407
+ | `txn_init_failed` | Failed to initialize transaction |
408
+ | `txn_limit_exceeded` | Maximum number of concurrent transactions exceeded |
409
+ | `unknown_error` | An unknown or unclassified error occurred |
410
+ | `txn_stop_failed` | Error occurred while stopping the transaction |
411
+ | `audio_upload_failed` | Audio file upload to server failed |
412
+ | `txn_commit_failed` | Commit call failed for the current transaction |
413
+ | `invalid_request` | Request to SDK was malformed or missing required parameters |
414
+ | `vad_not_initialized` | Voice activity detection engine was not initialized |
415
+ | `no_audio_capture` | No audio was captured during the recording session |
416
+ | `txn_status_mismatch` | Invalid operation due to mismatched transaction status |
417
+
418
+ ## Contribution Guidelines
419
+
420
+ This is a continually updated, open source project.
421
+ Contributions are welcome!
422
+
423
+ ## Tips
424
+
425
+ - The SDK internally handles shared worker logic to reduce load on the main thread. Try to execute these functions in the main thread to avoid unnecessary issues.
426
+
427
+ ## Advanced Usage (for later use)
428
+
429
+ - Maximum retries for file upload in case of failure.
430
+ - Update VAD configurations
431
+
432
+ ## Under Development
433
+
434
+ - Opus compression of audio files
435
+ - Test cases
436
+
437
+ Refer [Ekascribe](https://github.com/eka-care/v2rx-extension) for SDK implementations.
@@ -0,0 +1,5 @@
1
+ import { TGetTransactionHistoryResponse } from '../constants/types';
2
+ declare const getTransactionHistory: ({ txn_count, }: {
3
+ txn_count: number;
4
+ }) => Promise<TGetTransactionHistoryResponse>;
5
+ export default getTransactionHistory;
@@ -0,0 +1,28 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V2 } from '../fetch-client/helper';
4
+ // TODO: pagination changes
5
+ const getTransactionHistory = async ({ txn_count, }) => {
6
+ try {
7
+ const headers = new Headers();
8
+ headers.append('Content-Type', 'application/json');
9
+ const options = {
10
+ method: 'GET',
11
+ headers,
12
+ };
13
+ const responseJson = await fetchWrapper(`${GET_EKA_V2RX_HOST_V2()}/transaction/history?count=${txn_count}`, options);
14
+ const response = await responseJson.json();
15
+ return {
16
+ data: response.data,
17
+ status_code: responseJson.status,
18
+ message: `Past ${txn_count} transactions fetched successfully.`,
19
+ };
20
+ }
21
+ catch (error) {
22
+ return {
23
+ status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
24
+ message: `Something went wrong in fetching transactions. ${error}`,
25
+ };
26
+ }
27
+ };
28
+ export default getTransactionHistory;
@@ -0,0 +1,2 @@
1
+ import { TGetConfigV2Response } from '../constants/types';
2
+ export declare const getConfigV2: () => Promise<TGetConfigV2Response>;
@@ -0,0 +1,26 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V2 } from '../fetch-client/helper';
4
+ export const getConfigV2 = async () => {
5
+ try {
6
+ const options = {
7
+ method: 'GET',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ },
11
+ };
12
+ const response = await fetchWrapper(`${GET_EKA_V2RX_HOST_V2()}/config/`, options);
13
+ const res = await response.json();
14
+ return {
15
+ ...res,
16
+ code: response.status,
17
+ };
18
+ }
19
+ catch (error) {
20
+ console.log('Error in getConfigV2 api: ', error);
21
+ return {
22
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
23
+ message: `Failed to fetch initial configurations, ${error}`,
24
+ };
25
+ }
26
+ };
@@ -0,0 +1,51 @@
1
+ export type TTemplateMessage = {
2
+ type: 'warning' | 'error';
3
+ code?: string;
4
+ msg: string;
5
+ };
6
+ export type TOutputSummary = {
7
+ template_id: string;
8
+ value?: string | null;
9
+ type: string;
10
+ name: string;
11
+ status: TTemplateStatus;
12
+ errors?: TTemplateMessage[];
13
+ warnings?: TTemplateMessage[];
14
+ };
15
+ export type TTemplateStatus = 'success' | 'partial_success' | 'failure';
16
+ type TAdditionalData = {
17
+ doctor: {
18
+ _id: string;
19
+ profile: {
20
+ personal: {
21
+ name: {
22
+ l: string;
23
+ f: string;
24
+ };
25
+ };
26
+ };
27
+ };
28
+ };
29
+ type TApiResponse = {
30
+ data: {
31
+ output?: TOutputSummary[];
32
+ additional_data?: TAdditionalData;
33
+ meta_data?: {
34
+ total_resources?: number;
35
+ total_parsed_resources?: number;
36
+ };
37
+ };
38
+ error?: {
39
+ code: string;
40
+ msg: string;
41
+ };
42
+ };
43
+ export type TGetStatusResponse = {
44
+ response?: TApiResponse | null;
45
+ code: number;
46
+ message?: string;
47
+ };
48
+ export declare const getVoiceApiV2Status: ({ txnId, }: {
49
+ txnId: string;
50
+ }) => Promise<TGetStatusResponse>;
51
+ export {};
@@ -0,0 +1,25 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V3 } from '../fetch-client/helper';
4
+ export const getVoiceApiV2Status = async ({ txnId, }) => {
5
+ try {
6
+ const headers = new Headers();
7
+ headers.append('Content-Type', 'application/json');
8
+ const options = {
9
+ method: 'GET',
10
+ headers,
11
+ };
12
+ const getResponse = await fetchWrapper(`${GET_EKA_V2RX_HOST_V3()}/status/${txnId}`, options);
13
+ const response = await getResponse.json();
14
+ return {
15
+ response,
16
+ code: getResponse.status,
17
+ };
18
+ }
19
+ catch (error) {
20
+ return {
21
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
22
+ message: `Something went wrong! ${error}`,
23
+ };
24
+ }
25
+ };
@@ -0,0 +1,51 @@
1
+ export type TTemplateMessage = {
2
+ type: 'warning' | 'error';
3
+ code?: string;
4
+ msg: string;
5
+ };
6
+ export type TOutputSummary = {
7
+ template_id: string;
8
+ value?: string | null;
9
+ type: string;
10
+ name: string;
11
+ status: TTemplateStatus;
12
+ errors?: TTemplateMessage[];
13
+ warnings?: TTemplateMessage[];
14
+ };
15
+ export type TTemplateStatus = 'success' | 'partial_success' | 'failure';
16
+ type TAdditionalData = {
17
+ doctor: {
18
+ _id: string;
19
+ profile: {
20
+ personal: {
21
+ name: {
22
+ l: string;
23
+ f: string;
24
+ };
25
+ };
26
+ };
27
+ };
28
+ };
29
+ type TApiResponse = {
30
+ data: {
31
+ output?: TOutputSummary[];
32
+ additional_data?: TAdditionalData;
33
+ meta_data?: {
34
+ total_resources?: number;
35
+ total_parsed_resources?: number;
36
+ };
37
+ };
38
+ error?: {
39
+ code: string;
40
+ msg: string;
41
+ };
42
+ };
43
+ export type TGetStatusResponse = {
44
+ response?: TApiResponse | null;
45
+ status_code: number;
46
+ message?: string;
47
+ };
48
+ export declare const getVoiceApiV3Status: ({ txnId, }: {
49
+ txnId: string;
50
+ }) => Promise<TGetStatusResponse>;
51
+ export {};
@@ -0,0 +1,26 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V3 } from '../fetch-client/helper';
4
+ export const getVoiceApiV3Status = async ({ txnId, }) => {
5
+ try {
6
+ const headers = new Headers();
7
+ headers.append('Content-Type', 'application/json');
8
+ const options = {
9
+ method: 'GET',
10
+ headers,
11
+ };
12
+ // Use custom timeout for this API (16 seconds instead of default 5 seconds)
13
+ const getResponse = await fetchWrapper(`${GET_EKA_V2RX_HOST_V3()}/status/${txnId}`, options, 16000);
14
+ const response = await getResponse.json();
15
+ return {
16
+ response,
17
+ status_code: getResponse.status,
18
+ };
19
+ }
20
+ catch (error) {
21
+ return {
22
+ status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
23
+ message: `Something went wrong! ${error}`,
24
+ };
25
+ }
26
+ };
@@ -0,0 +1,4 @@
1
+ import { TPatchTransactionError, TPatchTransactionRequest, TPostTransactionResponse } from '../constants/types';
2
+ export declare const processingError: TPatchTransactionError;
3
+ declare const patchTransactionStatus: ({ sessionId, processing_status, processing_error, }: TPatchTransactionRequest) => Promise<TPostTransactionResponse>;
4
+ export default patchTransactionStatus;
@@ -0,0 +1,43 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V2 } from '../fetch-client/helper';
4
+ export const processingError = {
5
+ error: {
6
+ type: '',
7
+ code: 'cancelled_by_user',
8
+ msg: 'Cancelled_by_user',
9
+ },
10
+ };
11
+ const patchTransactionStatus = async ({ sessionId, processing_status, processing_error, }) => {
12
+ try {
13
+ const headers = new Headers();
14
+ headers.append('Content-Type', 'application/json');
15
+ const raw = {
16
+ processing_status,
17
+ processing_error,
18
+ };
19
+ const options = {
20
+ method: 'PATCH',
21
+ headers,
22
+ body: JSON.stringify(raw),
23
+ };
24
+ const response = await fetchWrapper(`${GET_EKA_V2RX_HOST_V2()}/transaction/${sessionId}`, options);
25
+ if (!response.ok) {
26
+ throw new Error(`Error: ${response.statusText}`);
27
+ }
28
+ let res = await response.json();
29
+ res = {
30
+ ...res,
31
+ code: response.status,
32
+ };
33
+ return res;
34
+ }
35
+ catch (error) {
36
+ console.error('Patch transaction status api failed', error);
37
+ return {
38
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
39
+ message: `Something went wrong! ${error}`,
40
+ };
41
+ }
42
+ };
43
+ export default patchTransactionStatus;