@eka-care/ekascribe-ts-sdk 1.4.42 → 1.4.43

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.
@@ -0,0 +1,6 @@
1
+ import { TPostV1FileUploadResponse } from '../constants/types';
2
+ declare function postV1FileUpload({ txn_id, action, }: {
3
+ txn_id: string;
4
+ action: string;
5
+ }): Promise<TPostV1FileUploadResponse>;
6
+ export default postV1FileUpload;
@@ -0,0 +1,29 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_HOST } from '../fetch-client/helper';
4
+ async function postV1FileUpload({ txn_id, action, }) {
5
+ try {
6
+ const headers = new Headers();
7
+ headers.append('Content-Type', 'application/json');
8
+ const options = {
9
+ method: 'POST',
10
+ headers,
11
+ body: JSON.stringify({}),
12
+ };
13
+ const response = await fetchWrapper(`${GET_EKA_HOST()}/v1/file-upload?txn_id=${txn_id}&action=${action}`, options);
14
+ let res = await response.json();
15
+ res = {
16
+ ...res,
17
+ code: response.status,
18
+ };
19
+ return res;
20
+ }
21
+ catch (error) {
22
+ console.log('%c getPresignedUrl -> error', 'color:#f5ce50', error);
23
+ return {
24
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
25
+ message: `Something went wrong! ${error}`,
26
+ };
27
+ }
28
+ }
29
+ export default postV1FileUpload;
@@ -1,3 +1,3 @@
1
1
  import { TPostTransactionInitRequest, TPostTransactionResponse } from '../../constants/types';
2
- declare function postTransactionInit({ mode, txnId, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, }: TPostTransactionInitRequest): Promise<TPostTransactionResponse>;
2
+ declare function postTransactionInit({ mode, txn_id, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, model_type, version, flavour, }: TPostTransactionInitRequest): Promise<TPostTransactionResponse>;
3
3
  export default postTransactionInit;
@@ -1,7 +1,7 @@
1
1
  import { SDK_STATUS_CODE } from '../../constants/constant';
2
2
  import fetchWrapper from '../../fetch-client';
3
3
  import { GET_EKA_VOICE_HOST_V2 } from '../../fetch-client/helper';
4
- async function postTransactionInit({ mode, txnId, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, }) {
4
+ async function postTransactionInit({ mode, txn_id, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, model_type, version, flavour, }) {
5
5
  try {
6
6
  const headers = new Headers();
7
7
  headers.append('Content-Type', 'application/json');
@@ -15,13 +15,16 @@ async function postTransactionInit({ mode, txnId, s3Url, input_language, output_
15
15
  transfer,
16
16
  system_info,
17
17
  patient_details,
18
+ model_type,
19
+ version,
20
+ flavour,
18
21
  };
19
22
  const options = {
20
23
  method: 'POST',
21
24
  headers,
22
25
  body: JSON.stringify(raw),
23
26
  };
24
- const response = await fetchWrapper(`${GET_EKA_VOICE_HOST_V2()}/transaction/init/${txnId}`, options);
27
+ const response = await fetchWrapper(`${GET_EKA_VOICE_HOST_V2()}/transaction/init/${txn_id}`, options);
25
28
  let res = await response.json();
26
29
  res = {
27
30
  ...res,
@@ -0,0 +1,10 @@
1
+ import { TPostV1FileUploadResponse } from '../constants/types';
2
+ type TUploadFilesResponse = {
3
+ code: number;
4
+ message: string;
5
+ };
6
+ declare function uploadFilesWithPresignedUrl({ audioFiles, presignedUrlResponse, }: {
7
+ audioFiles: File[] | Blob[];
8
+ presignedUrlResponse: TPostV1FileUploadResponse;
9
+ }): Promise<TUploadFilesResponse>;
10
+ export default uploadFilesWithPresignedUrl;
@@ -0,0 +1,60 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ async function uploadSingleFile(uploadData, folderPath, file, fileName) {
3
+ try {
4
+ const updatedFields = {
5
+ ...uploadData.fields,
6
+ key: folderPath + fileName,
7
+ };
8
+ const formData = new FormData();
9
+ Object.entries(updatedFields).forEach(([key, value]) => {
10
+ formData.append(key, value);
11
+ });
12
+ formData.append('file', file);
13
+ const response = await fetch(uploadData.url, {
14
+ method: 'POST',
15
+ body: formData,
16
+ });
17
+ if (response.status === 204) {
18
+ // S3 returns 204 No Content on successful upload
19
+ return {
20
+ key: folderPath + fileName,
21
+ size: file.size,
22
+ success: true,
23
+ };
24
+ }
25
+ else {
26
+ throw new Error(`Upload failed with status: ${response.status}`);
27
+ }
28
+ }
29
+ catch (error) {
30
+ console.error('uploadSingleFile error:', error);
31
+ return {
32
+ success: false,
33
+ error: `Upload failed: ${error}`,
34
+ };
35
+ }
36
+ }
37
+ async function uploadFilesWithPresignedUrl({ audioFiles, presignedUrlResponse, }) {
38
+ try {
39
+ const uploadPromises = audioFiles.map((file, index) => {
40
+ const fileName = `audio_${index + 1}`;
41
+ return uploadSingleFile({ ...presignedUrlResponse.uploadData }, presignedUrlResponse.folderPath, file, fileName);
42
+ });
43
+ const results = await Promise.all(uploadPromises);
44
+ const failedUploads = results.filter((result) => !result.success);
45
+ const successfulUploads = results.filter((result) => result.success);
46
+ // TODO: presigned url expiry handling and failed files handling
47
+ return {
48
+ code: failedUploads.length > 0 ? 207 : 200, // 207 for partial success, 200 for all success
49
+ message: `Upload completed. ${successfulUploads.length}/${results.length} files uploaded successfully.`,
50
+ };
51
+ }
52
+ catch (error) {
53
+ console.error('uploadAudioFilesWithPresignedUrl error:', error);
54
+ return {
55
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
56
+ message: `Upload failed: ${error}`,
57
+ };
58
+ }
59
+ }
60
+ export default uploadFilesWithPresignedUrl;
@@ -24,7 +24,8 @@ export declare enum ERROR_CODE {
24
24
  NO_AUDIO_CAPTURE = "no_audio_capture",
25
25
  SPEECH_DETECTED = "speech_detected",
26
26
  TXN_STATUS_MISMATCH = "txn_status_mismatch",
27
- LONG_SILENCE = "long_silence"
27
+ LONG_SILENCE = "long_silence",
28
+ GET_PRESIGNED_URL_FAILED = "get_presigned_url_failed"
28
29
  }
29
30
  export declare enum PROCESSING_STATUS {
30
31
  SUCCESS = "success",
@@ -28,6 +28,7 @@ export var ERROR_CODE;
28
28
  ERROR_CODE["SPEECH_DETECTED"] = "speech_detected";
29
29
  ERROR_CODE["TXN_STATUS_MISMATCH"] = "txn_status_mismatch";
30
30
  ERROR_CODE["LONG_SILENCE"] = "long_silence";
31
+ ERROR_CODE["GET_PRESIGNED_URL_FAILED"] = "get_presigned_url_failed";
31
32
  })(ERROR_CODE || (ERROR_CODE = {}));
32
33
  export var PROCESSING_STATUS;
33
34
  (function (PROCESSING_STATUS) {
@@ -56,6 +56,9 @@ export type TStartRecordingRequest = {
56
56
  transfer: string;
57
57
  system_info: TSystemInfo;
58
58
  patient_details?: TPatientDetails;
59
+ model_type: string;
60
+ version?: string;
61
+ flavour?: string;
59
62
  };
60
63
  export type Gender = 'M' | 'F' | 'O';
61
64
  export type TPatientDetails = {
@@ -105,7 +108,7 @@ export type TEndRecordingResponse = {
105
108
  export type TPostTransactionInitRequest = {
106
109
  mode: string;
107
110
  s3Url: string;
108
- txnId: string;
111
+ txn_id: string;
109
112
  input_language: string[];
110
113
  output_format_template: {
111
114
  template_id: string;
@@ -115,6 +118,9 @@ export type TPostTransactionInitRequest = {
115
118
  model_training_consent: boolean;
116
119
  system_info: TSystemInfo;
117
120
  patient_details?: TPatientDetails;
121
+ model_type: string;
122
+ version?: string;
123
+ flavour?: string;
118
124
  };
119
125
  export type TPostTransactionCommitRequest = {
120
126
  audioFiles: string[];
@@ -338,3 +344,26 @@ export type TPostV1ConvertToTemplateResponse = {
338
344
  display_message: string;
339
345
  };
340
346
  };
347
+ export type TV1FileUploadFields = {
348
+ 'x-amz-meta-mode': string;
349
+ key: string;
350
+ 'x-amz-algorithm': string;
351
+ 'x-amz-credential': string;
352
+ 'x-amz-date': string;
353
+ policy: string;
354
+ 'x-amz-signature': string;
355
+ };
356
+ export type TPostV1FileUploadResponse = {
357
+ uploadData: {
358
+ url: string;
359
+ fields: TV1FileUploadFields;
360
+ };
361
+ folderPath: string;
362
+ txn_id: string;
363
+ code?: number;
364
+ message?: string;
365
+ error?: {
366
+ code: string;
367
+ message: string;
368
+ };
369
+ };
@@ -10,4 +10,5 @@ export declare const GET_EKA_VOICE_HOST_V2: () => string;
10
10
  export declare const GET_EKA_VOICE_HOST_V3: () => string;
11
11
  export declare const GET_COOK_HOST_V1: () => string;
12
12
  export declare const GET_COG_HOST: () => string;
13
+ export declare const GET_EKA_HOST: () => string;
13
14
  export default setEnv;
@@ -4,6 +4,7 @@ const DEV = {
4
4
  EKA_VOICE_HOST_V2: 'https://v2rxbe.dev.eka.care/voice/api/v2',
5
5
  EKA_VOICE_HOST_V3: 'https://v2rxbe.dev.eka.care/voice/api/v3',
6
6
  COOK_V1: ' https://deepthought-genai.dev.eka.care/api/v1',
7
+ EKA_HOST: 'https://api.dev.eka.care',
7
8
  };
8
9
  const PROD = {
9
10
  COG_HOST: 'https://cog.eka.care',
@@ -11,6 +12,7 @@ const PROD = {
11
12
  EKA_VOICE_HOST_V2: 'https://api.eka.care/voice/api/v2',
12
13
  EKA_VOICE_HOST_V3: 'https://api.eka.care/voice/api/v3',
13
14
  COOK_V1: ' https://cook.eka.care/api/v1',
15
+ EKA_HOST: 'https://api.eka.care',
14
16
  };
15
17
  let envVar = PROD;
16
18
  let client_id = 'doc-web';
@@ -33,4 +35,5 @@ export const GET_EKA_VOICE_HOST_V2 = () => envVar.EKA_VOICE_HOST_V2;
33
35
  export const GET_EKA_VOICE_HOST_V3 = () => envVar.EKA_VOICE_HOST_V3;
34
36
  export const GET_COOK_HOST_V1 = () => envVar.COOK_V1;
35
37
  export const GET_COG_HOST = () => envVar.COG_HOST;
38
+ export const GET_EKA_HOST = () => envVar.EKA_HOST;
36
39
  export default setEnv;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { TGetStatusResponse } from './api/transaction/get-voice-api-v3-status';
2
2
  import { TEndRecordingResponse, TErrorCallback, TFileUploadProgressCallback, TGetTransactionHistoryResponse, TPatchTransactionRequest, TPatchVoiceApiV2ConfigRequest, TPostTransactionResponse, TPostV1ConvertToTemplateRequest, TPostV1TemplateRequest, TPostV1TemplateSectionRequest, TStartRecordingRequest } from './constants/types';
3
3
  import { TSearchSessionsByPatientRequest } from './utils/search-sessions-by-patient-name';
4
+ import { TFullAudioRequest } from './main/upload-full-audio-with-presigned-url';
4
5
  declare class EkaScribe {
5
6
  private static instance;
6
7
  private vadInstance;
@@ -64,6 +65,7 @@ declare class EkaScribe {
64
65
  deleteTemplateSection(section_id: string): Promise<import("./constants/types").TPostV1TemplateSectionResponse>;
65
66
  postTransactionConvertToTemplate({ txn_id, template_id }: TPostV1ConvertToTemplateRequest): Promise<import("./constants/types").TPostV1ConvertToTemplateResponse>;
66
67
  searchSessionsByPatientName(request: TSearchSessionsByPatientRequest): Promise<unknown>;
68
+ uploadAudioWithPresignedUrl(request: TFullAudioRequest): Promise<import("./main/upload-full-audio-with-presigned-url").TFullAudioUploadResponse>;
67
69
  }
68
70
  export declare const getEkaScribeInstance: ({ access_token, env, clientId, }: {
69
71
  access_token?: string;
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ import patchVoiceApiV2Config from './api/config/patch-voice-api-v2-config';
29
29
  import cookV1MediaAiCreateTemplate from './api/templates/cook-v1-medai-ai-create-template';
30
30
  import postV1ConvertToTemplate from './api/templates/post-transaction-convert-to-template';
31
31
  import searchSessionsByPatient from './utils/search-sessions-by-patient-name';
32
+ import { postV1UploadAudioFiles, } from './main/upload-full-audio-with-presigned-url';
32
33
  class EkaScribe {
33
34
  // Private constructor to prevent direct instantiation
34
35
  constructor() {
@@ -317,6 +318,10 @@ class EkaScribe {
317
318
  const searchSessionsByPatientNameResponse = await searchSessionsByPatient(request);
318
319
  return searchSessionsByPatientNameResponse;
319
320
  }
321
+ async uploadAudioWithPresignedUrl(request) {
322
+ const uploadAudioFilesResponse = await postV1UploadAudioFiles(request);
323
+ return uploadAudioFilesResponse;
324
+ }
320
325
  }
321
326
  Object.defineProperty(EkaScribe, "instance", {
322
327
  enumerable: true,
@@ -1,3 +1,3 @@
1
1
  import { TStartRecordingRequest, TStartRecordingResponse } from '../constants/types';
2
- declare const initialiseTransaction: ({ mode, input_language, output_format_template, txn_id, auto_download, model_training_consent, transfer, system_info, patient_details, }: TStartRecordingRequest) => Promise<TStartRecordingResponse>;
2
+ declare const initialiseTransaction: (request: TStartRecordingRequest) => Promise<TStartRecordingResponse>;
3
3
  export default initialiseTransaction;
@@ -2,8 +2,9 @@ import postTransactionInit from '../api/transaction/post-transaction-init';
2
2
  import { S3_BUCKET_NAME, SDK_STATUS_CODE } from '../constants/constant';
3
3
  import { ERROR_CODE } from '../constants/enums';
4
4
  import EkaScribeStore from '../store/store';
5
- const initialiseTransaction = async ({ mode, input_language, output_format_template, txn_id, auto_download, model_training_consent, transfer, system_info, patient_details, }) => {
5
+ const initialiseTransaction = async (request) => {
6
6
  try {
7
+ const { txn_id } = request;
7
8
  const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
8
9
  const sessionStatus = EkaScribeStore.sessionStatus;
9
10
  let businessID = '';
@@ -23,16 +24,8 @@ const initialiseTransaction = async ({ mode, input_language, output_format_templ
23
24
  const filePath = `${year}${month}${day}/${txn_id}`;
24
25
  EkaScribeStore.sessionBucketPath = filePath;
25
26
  const txnInitResponse = await postTransactionInit({
26
- mode,
27
- txnId: txn_id,
27
+ ...request,
28
28
  s3Url: `s3://${S3_BUCKET_NAME}/${filePath}`,
29
- input_language,
30
- output_format_template,
31
- transfer,
32
- auto_download,
33
- model_training_consent,
34
- system_info,
35
- patient_details,
36
29
  });
37
30
  const { code: txnInitStatusCode, b_id: businessId, oid, uuid, message: txnInitMessage, error: txnInitError, } = txnInitResponse;
38
31
  if (txnInitStatusCode === 400 && txnInitError?.code === ERROR_CODE.TXN_LIMIT_EXCEEDED) {
@@ -0,0 +1,12 @@
1
+ import { ERROR_CODE } from '../constants/enums';
2
+ export type TFullAudioUploadResponse = {
3
+ error_code?: ERROR_CODE;
4
+ status_code: number;
5
+ message: string;
6
+ };
7
+ export type TFullAudioRequest = {
8
+ txn_id: string;
9
+ action: string;
10
+ audioFiles: File[] | Blob[];
11
+ };
12
+ export declare function postV1UploadAudioFiles({ audioFiles, txn_id, action, }: TFullAudioRequest): Promise<TFullAudioUploadResponse>;
@@ -0,0 +1,41 @@
1
+ import postV1FileUpload from '../api/post-v1-file-upload';
2
+ import uploadFilesWithPresignedUrl from '../api/upload-audio-with-presigned-url';
3
+ import { SDK_STATUS_CODE } from '../constants/constant';
4
+ import { ERROR_CODE } from '../constants/enums';
5
+ export async function postV1UploadAudioFiles({ audioFiles, txn_id, action, }) {
6
+ try {
7
+ if (!audioFiles || audioFiles.length === 0) {
8
+ return {
9
+ error_code: ERROR_CODE.INVALID_REQUEST,
10
+ status_code: SDK_STATUS_CODE.BAD_REQUEST,
11
+ message: 'No audio files provided',
12
+ };
13
+ }
14
+ // Step 1: Get presigned URL
15
+ const presignedUrlResponse = await postV1FileUpload({ txn_id, action });
16
+ if (presignedUrlResponse.code !== 200) {
17
+ return {
18
+ error_code: ERROR_CODE.GET_PRESIGNED_URL_FAILED,
19
+ status_code: presignedUrlResponse.code || SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
20
+ message: presignedUrlResponse.message || 'Get presigned URL failed',
21
+ };
22
+ }
23
+ // Step 2: Upload files using the presigned URL
24
+ const uploadResponse = await uploadFilesWithPresignedUrl({
25
+ audioFiles,
26
+ presignedUrlResponse,
27
+ });
28
+ return {
29
+ status_code: uploadResponse.code || SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
30
+ message: uploadResponse.message || 'File uploaded.',
31
+ };
32
+ }
33
+ catch (error) {
34
+ console.error('getPresignedUrlAndUploadFiles error:', error);
35
+ return {
36
+ error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
37
+ status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
38
+ message: `Complete upload workflow failed: ${error}`,
39
+ };
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/ekascribe-ts-sdk",
3
- "version": "1.4.42",
3
+ "version": "1.4.43",
4
4
  "main": "dist/index.js",
5
5
  "repository": "git@github.com:eka-care/eka-js-sdk.git",
6
6
  "author": "Sanikagoyal28 <sanikagoyal9@gmail.com>",