@eka-care/ekascribe-ts-sdk 1.5.11 → 1.5.13

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.
@@ -1,4 +1,4 @@
1
- import { TAudioChunksInfo, TFileUploadProgressCallback } from '../constants/types';
1
+ import { TAudioChunksInfo } from '../constants/types';
2
2
  type TUploadAudioChunkParams = {
3
3
  audioFrames: Float32Array;
4
4
  fileName: string;
@@ -14,7 +14,6 @@ declare class AudioFileManager {
14
14
  audioChunks: TAudioChunksInfo[];
15
15
  private uploadPromises;
16
16
  private successfulUploads;
17
- private onProgressCallback?;
18
17
  private totalRawSamples;
19
18
  private totalRawFrames;
20
19
  private totalInsertedSamples;
@@ -42,10 +41,6 @@ declare class AudioFileManager {
42
41
  totalInsertedSamples: number;
43
42
  totalInsertedFrames: number;
44
43
  };
45
- /**
46
- * Set callback for upload progress updates
47
- */
48
- setProgressCallback(callback: TFileUploadProgressCallback): void;
49
44
  /**
50
45
  * Update audio information array, this will update the audio chunks info
51
46
  * (+ the latest chunk , affects the length of chunks data struct)
@@ -2,8 +2,9 @@ import { AUDIO_EXTENSION_TYPE_MAP, OUTPUT_FORMAT } from '../constants/constant';
2
2
  import pushFileToS3 from '../aws-services/upload-file-to-s3';
3
3
  import postCogInit from '../api/post-cog-init';
4
4
  import { configureAWS } from '../aws-services/configure-aws';
5
- import { SHARED_WORKER_ACTION } from '../constants/enums';
5
+ import { CALLBACK_TYPE, SHARED_WORKER_ACTION } from '../constants/enums';
6
6
  import compressAudioToMp3 from '../utils/compress-mp3-audio';
7
+ import EkaScribeStore from '../store/store';
7
8
  class AudioFileManager {
8
9
  initialiseClassInstance() {
9
10
  this.audioChunks = [];
@@ -49,12 +50,6 @@ class AudioFileManager {
49
50
  writable: true,
50
51
  value: []
51
52
  });
52
- Object.defineProperty(this, "onProgressCallback", {
53
- enumerable: true,
54
- configurable: true,
55
- writable: true,
56
- value: void 0
57
- });
58
53
  Object.defineProperty(this, "totalRawSamples", {
59
54
  enumerable: true,
60
55
  configurable: true,
@@ -127,12 +122,6 @@ class AudioFileManager {
127
122
  totalInsertedFrames: this.totalInsertedFrames,
128
123
  };
129
124
  }
130
- /**
131
- * Set callback for upload progress updates
132
- */
133
- setProgressCallback(callback) {
134
- this.onProgressCallback = callback;
135
- }
136
125
  /**
137
126
  * Update audio information array, this will update the audio chunks info
138
127
  * (+ the latest chunk , affects the length of chunks data struct)
@@ -146,26 +135,44 @@ class AudioFileManager {
146
135
  // new URL(relativeOrAbsolutePath, baseUrl)
147
136
  const worker = new SharedWorker(new URL('../shared-worker/s3-file-upload.js', import.meta.url));
148
137
  this.sharedWorkerInstance = worker;
138
+ const onEventCallback = EkaScribeStore.eventCallback;
149
139
  this.sharedWorkerInstance.port.onmessage = async (event) => {
150
140
  const workerResponse = event.data;
151
141
  switch (workerResponse.action) {
152
142
  case SHARED_WORKER_ACTION.CONFIGURE_AWS_SUCCESS: {
153
- // Callback
143
+ if (onEventCallback) {
144
+ onEventCallback({
145
+ callback_type: CALLBACK_TYPE.AWS_CONFIGURE_STATUS,
146
+ status: 'success',
147
+ message: workerResponse.message,
148
+ timestamp: new Date().toISOString(),
149
+ });
150
+ }
154
151
  return;
155
152
  }
156
153
  case SHARED_WORKER_ACTION.CONFIGURE_AWS_ERROR: {
157
- // Callback
154
+ if (onEventCallback) {
155
+ onEventCallback({
156
+ callback_type: CALLBACK_TYPE.AWS_CONFIGURE_STATUS,
157
+ status: 'error',
158
+ message: workerResponse.message,
159
+ timestamp: new Date().toISOString(),
160
+ });
161
+ }
158
162
  return;
159
163
  }
160
164
  case SHARED_WORKER_ACTION.UPLOAD_FILE_WITH_WORKER_SUCCESS: {
161
- // Callback
162
165
  const { fileCount: fileName, chunkIndex, fileBlob, compressedAudioBuffer, } = workerResponse.requestBody;
163
- if (this.onProgressCallback && compressedAudioBuffer) {
164
- this.onProgressCallback({
165
- success: this.successfulUploads.length,
166
- total: this.audioChunks.length,
167
- fileName,
168
- chunkData: compressedAudioBuffer,
166
+ if (onEventCallback && compressedAudioBuffer) {
167
+ onEventCallback({
168
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
169
+ status: 'info',
170
+ message: 'Audioframes of chunk to store in IDB',
171
+ timestamp: new Date().toISOString(),
172
+ data: {
173
+ fileName,
174
+ chunkData: compressedAudioBuffer,
175
+ },
169
176
  });
170
177
  }
171
178
  if (workerResponse.response.success) {
@@ -180,24 +187,31 @@ class AudioFileManager {
180
187
  response: workerResponse.response.success,
181
188
  };
182
189
  }
183
- if (this.onProgressCallback) {
184
- this.onProgressCallback({
185
- success: this.successfulUploads.length,
186
- total: this.audioChunks.length,
187
- is_uploaded: true,
190
+ if (onEventCallback) {
191
+ onEventCallback({
192
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
193
+ status: 'success',
194
+ message: workerResponse.response.success,
195
+ timestamp: new Date().toISOString(),
196
+ data: {
197
+ success: this.successfulUploads.length,
198
+ total: this.audioChunks.length,
199
+ is_uploaded: true,
200
+ },
188
201
  });
189
202
  }
190
203
  }
191
204
  else {
192
- if (this.onProgressCallback) {
193
- this.onProgressCallback({
194
- success: this.successfulUploads.length,
195
- total: this.audioChunks.length,
196
- fileName,
197
- is_uploaded: false,
205
+ if (onEventCallback) {
206
+ onEventCallback({
207
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
208
+ status: 'error',
209
+ message: workerResponse.response.error || 'Upload failed',
210
+ timestamp: new Date().toISOString(),
198
211
  error: {
199
212
  code: workerResponse.response.code,
200
- msg: 'Tokens expired.',
213
+ msg: workerResponse.response.error,
214
+ details: workerResponse.response.errorCode,
201
215
  },
202
216
  });
203
217
  }
@@ -273,12 +287,19 @@ class AudioFileManager {
273
287
  const audioBlob = new Blob(compressedAudioBuffer, {
274
288
  type: AUDIO_EXTENSION_TYPE_MAP[OUTPUT_FORMAT],
275
289
  });
276
- if (this.onProgressCallback) {
277
- this.onProgressCallback({
278
- success: this.successfulUploads.length,
279
- total: this.audioChunks.length,
280
- fileName,
281
- chunkData: compressedAudioBuffer,
290
+ const onEventCallback = EkaScribeStore.eventCallback;
291
+ if (onEventCallback) {
292
+ onEventCallback({
293
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
294
+ status: 'info',
295
+ message: 'Audio chunks count to display success/total file count and to store chunks in IDB',
296
+ timestamp: new Date().toISOString(),
297
+ data: {
298
+ success: this.successfulUploads.length,
299
+ total: this.audioChunks.length,
300
+ fileName,
301
+ chunkData: compressedAudioBuffer,
302
+ },
282
303
  });
283
304
  }
284
305
  // Push upload promise to track status
@@ -302,11 +323,17 @@ class AudioFileManager {
302
323
  response: response.success,
303
324
  };
304
325
  }
305
- if (this.onProgressCallback) {
306
- this.onProgressCallback({
307
- success: this.successfulUploads.length,
308
- total: this.audioChunks.length,
309
- is_uploaded: true,
326
+ if (onEventCallback) {
327
+ onEventCallback({
328
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
329
+ status: 'success',
330
+ message: response.success,
331
+ timestamp: new Date().toISOString(),
332
+ data: {
333
+ success: this.successfulUploads.length,
334
+ total: this.audioChunks.length,
335
+ is_uploaded: true,
336
+ },
310
337
  });
311
338
  }
312
339
  }
@@ -320,15 +347,16 @@ class AudioFileManager {
320
347
  response: response.error || 'Upload failed',
321
348
  };
322
349
  }
323
- if (this.onProgressCallback) {
324
- this.onProgressCallback({
325
- success: this.successfulUploads.length,
326
- total: this.audioChunks.length,
327
- fileName,
328
- is_uploaded: false,
350
+ if (onEventCallback) {
351
+ onEventCallback({
352
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
353
+ status: 'error',
354
+ message: response.error || 'Upload failed',
355
+ timestamp: new Date().toISOString(),
329
356
  error: {
330
357
  code: response.code || 500,
331
- msg: 'Tokens expired.',
358
+ msg: response.error || 'Upload failed',
359
+ details: response.errorCode,
332
360
  },
333
361
  });
334
362
  }
@@ -346,10 +374,17 @@ class AudioFileManager {
346
374
  */
347
375
  async uploadAudioChunkInWorker({ audioFrames, fileName, chunkIndex, }) {
348
376
  const s3FileName = `${this.filePath}/${fileName}`;
349
- if (this.onProgressCallback) {
350
- this.onProgressCallback({
351
- success: this.successfulUploads.length,
352
- total: this.audioChunks.length,
377
+ const onEventCallback = EkaScribeStore.eventCallback;
378
+ if (onEventCallback) {
379
+ onEventCallback({
380
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
381
+ status: 'info',
382
+ message: 'Audio chunks count to display success/total file count',
383
+ timestamp: new Date().toISOString(),
384
+ data: {
385
+ success: this.successfulUploads.length,
386
+ total: this.audioChunks.length,
387
+ },
353
388
  });
354
389
  }
355
390
  this.sharedWorkerInstance?.port.postMessage({
@@ -495,6 +530,7 @@ class AudioFileManager {
495
530
  if (failedFiles.length === 0) {
496
531
  return [];
497
532
  }
533
+ const onEventCallback = EkaScribeStore.eventCallback;
498
534
  if (this.sharedWorkerInstance) {
499
535
  this.audioChunks.forEach((chunk, index) => {
500
536
  const { fileName, fileBlob, status, audioFrames } = chunk;
@@ -517,10 +553,16 @@ class AudioFileManager {
517
553
  }
518
554
  else {
519
555
  this.uploadPromises = []; // Reset upload promises for retries
520
- if (this.onProgressCallback) {
521
- this.onProgressCallback({
522
- success: this.successfulUploads.length,
523
- total: this.audioChunks.length,
556
+ if (onEventCallback) {
557
+ onEventCallback({
558
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
559
+ status: 'info',
560
+ message: 'Audio chunks count to display success/total file count',
561
+ timestamp: new Date().toISOString(),
562
+ data: {
563
+ success: this.successfulUploads.length,
564
+ total: this.audioChunks.length,
565
+ },
524
566
  });
525
567
  }
526
568
  this.audioChunks.forEach((chunk, index) => {
@@ -547,10 +589,16 @@ class AudioFileManager {
547
589
  }).then((response) => {
548
590
  if (response.success) {
549
591
  this.successfulUploads.push(fileName);
550
- if (this.onProgressCallback) {
551
- this.onProgressCallback({
552
- success: this.successfulUploads.length,
553
- total: this.audioChunks.length,
592
+ if (onEventCallback) {
593
+ onEventCallback({
594
+ callback_type: CALLBACK_TYPE.FILE_UPLOAD_STATUS,
595
+ status: 'info',
596
+ message: 'Audio chunks count to display success/total file count',
597
+ timestamp: new Date().toISOString(),
598
+ data: {
599
+ success: this.successfulUploads.length,
600
+ total: this.audioChunks.length,
601
+ },
554
602
  });
555
603
  }
556
604
  this.audioChunks[index] = {
@@ -593,7 +641,6 @@ class AudioFileManager {
593
641
  this.filePath = '';
594
642
  this.businessID = '';
595
643
  this.isAWSConfigured = false;
596
- this.onProgressCallback = undefined;
597
644
  }
598
645
  }
599
646
  export default AudioFileManager;
@@ -48,3 +48,12 @@ export declare enum SHARED_WORKER_ACTION {
48
48
  WAIT_FOR_ALL_UPLOADS_SUCCESS = "wait_for_all_uploads_success",
49
49
  WAIT_FOR_ALL_UPLOADS_ERROR = "wait_for_all_uploads_error"
50
50
  }
51
+ export declare enum CALLBACK_TYPE {
52
+ AWS_CONFIGURE_STATUS = "aws_configure_status",
53
+ FILE_UPLOAD_STATUS = "file_upload_status",
54
+ TRANSACTION_STATUS = "transaction_status",
55
+ TEMPLATE_OPERATION_STATUS = "template_operation_status",
56
+ AUTHENTICATION_STATUS = "authentication_status",
57
+ NETWORK_STATUS = "network_status",
58
+ STORAGE_STATUS = "storage_status"
59
+ }
@@ -53,3 +53,13 @@ export var SHARED_WORKER_ACTION;
53
53
  SHARED_WORKER_ACTION["WAIT_FOR_ALL_UPLOADS_SUCCESS"] = "wait_for_all_uploads_success";
54
54
  SHARED_WORKER_ACTION["WAIT_FOR_ALL_UPLOADS_ERROR"] = "wait_for_all_uploads_error";
55
55
  })(SHARED_WORKER_ACTION || (SHARED_WORKER_ACTION = {}));
56
+ export var CALLBACK_TYPE;
57
+ (function (CALLBACK_TYPE) {
58
+ CALLBACK_TYPE["AWS_CONFIGURE_STATUS"] = "aws_configure_status";
59
+ CALLBACK_TYPE["FILE_UPLOAD_STATUS"] = "file_upload_status";
60
+ CALLBACK_TYPE["TRANSACTION_STATUS"] = "transaction_status";
61
+ CALLBACK_TYPE["TEMPLATE_OPERATION_STATUS"] = "template_operation_status";
62
+ CALLBACK_TYPE["AUTHENTICATION_STATUS"] = "authentication_status";
63
+ CALLBACK_TYPE["NETWORK_STATUS"] = "network_status";
64
+ CALLBACK_TYPE["STORAGE_STATUS"] = "storage_status";
65
+ })(CALLBACK_TYPE || (CALLBACK_TYPE = {}));
@@ -1,4 +1,4 @@
1
- import { ERROR_CODE } from './enums';
1
+ import { ERROR_CODE, CALLBACK_TYPE } from './enums';
2
2
  export type TGetConfigV2Response = {
3
3
  data?: {
4
4
  supported_languages: TGetConfigItem[];
@@ -244,17 +244,31 @@ export type TSessionStatus = {
244
244
  };
245
245
  };
246
246
  };
247
- export type TFileUploadProgressCallback = (args: {
248
- success: number;
249
- total: number;
250
- is_uploaded?: boolean;
251
- fileName?: string;
252
- chunkData?: Uint8Array<ArrayBufferLike>[];
247
+ export type TEventCallback = (args: {
248
+ callback_type: CALLBACK_TYPE;
249
+ status: 'success' | 'error' | 'progress' | 'info';
250
+ message: string;
253
251
  error?: {
254
252
  code: number;
255
253
  msg: string;
254
+ details?: unknown;
256
255
  };
256
+ data?: TFileUploadCallbackData | TTransactionCallbackData;
257
+ timestamp: string;
258
+ metadata?: Record<string, unknown>;
257
259
  }) => void;
260
+ export type TFileUploadCallbackData = {
261
+ success?: number;
262
+ total?: number;
263
+ is_uploaded?: boolean;
264
+ fileName?: string;
265
+ chunkData?: Uint8Array<ArrayBufferLike>[];
266
+ };
267
+ export type TTransactionCallbackData = {
268
+ txn_id?: string;
269
+ request?: unknown;
270
+ response?: unknown;
271
+ };
258
272
  export interface TPostV1TemplateRequest {
259
273
  title: string;
260
274
  desc?: string;
@@ -1,10 +1,10 @@
1
1
  const DEV = {
2
- COG_HOST: 'https://cog.dev.eka.care',
3
- EKA_VOICE_HOST_V1: 'https://v2rxbe.dev.eka.care/voice/api/v1',
4
- EKA_VOICE_HOST_V2: 'https://v2rxbe.dev.eka.care/voice/api/v2',
5
- EKA_VOICE_HOST_V3: 'https://v2rxbe.dev.eka.care/voice/api/v3',
6
- COOK_V1: ' https://deepthought-genai.dev.eka.care/api/v1',
7
- EKA_HOST: 'https://api.dev.eka.care',
2
+ COG_HOST: 'https://app.dev.ekascribe.ai/',
3
+ EKA_VOICE_HOST_V1: 'https://app.dev.ekascribe.ai/voice/api/v1',
4
+ EKA_VOICE_HOST_V2: 'https://app.dev.ekascribe.ai/voice/api/v2',
5
+ EKA_VOICE_HOST_V3: 'https://app.dev.ekascribe.ai/voice/api/v3',
6
+ COOK_V1: ' https://app.dev.ekascribe.ai/api/v1',
7
+ EKA_HOST: 'https://app.dev.ekascribe.ai',
8
8
  };
9
9
  const PROD = {
10
10
  COG_HOST: 'https://cog.eka.care',
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TGetStatusResponse } from './api/transaction/get-voice-api-v3-status';
2
- import { TEndRecordingResponse, TErrorCallback, TFileUploadProgressCallback, TGetTransactionHistoryResponse, TPatchTransactionRequest, TPatchVoiceApiV2ConfigRequest, TPatchVoiceApiV3StatusRequest, TPostTransactionResponse, TPostV1ConvertToTemplateRequest, TPostV1TemplateRequest, TPostV1TemplateSectionRequest, TPostV1UploadAudioFilesRequest, TStartRecordingRequest } from './constants/types';
2
+ import { TEndRecordingResponse, TErrorCallback, TEventCallback, TGetTransactionHistoryResponse, TPatchTransactionRequest, TPatchVoiceApiV2ConfigRequest, TPatchVoiceApiV3StatusRequest, TPostTransactionResponse, TPostV1ConvertToTemplateRequest, TPostV1TemplateRequest, TPostV1TemplateSectionRequest, TPostV1UploadAudioFilesRequest, TStartRecordingRequest } from './constants/types';
3
3
  import { TSearchSessionsByPatientRequest } from './utils/search-sessions-by-patient-name';
4
4
  declare class EkaScribe {
5
5
  private static instance;
@@ -43,7 +43,7 @@ declare class EkaScribe {
43
43
  resetEkaScribe(): void;
44
44
  onError(callback: TErrorCallback): void;
45
45
  onUserSpeechCallback(callback: (isSpeech: boolean) => void): void;
46
- onFileUploadProgressCallback(callback: TFileUploadProgressCallback): void;
46
+ onEventCallback(callback: TEventCallback): void;
47
47
  configureVadConstants({ pref_length, desp_length, max_length, sr, frame_size, pre_speech_pad_frames, short_thsld, long_thsld, }: {
48
48
  pref_length: number;
49
49
  desp_length: number;
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import AudioBufferManager from './audio-chunker/audio-buffer-manager';
7
7
  import AudioFileManager from './audio-chunker/audio-file-manager';
8
8
  import VadWebClient from './audio-chunker/vad-web';
9
9
  import { AUDIO_BUFFER_SIZE_IN_S, DESP_CHUNK_LENGTH, FRAME_RATE, MAX_CHUNK_LENGTH, PREF_CHUNK_LENGTH, SAMPLING_RATE, SDK_STATUS_CODE, } from './constants/constant';
10
- import { ERROR_CODE } from './constants/enums';
10
+ import { CALLBACK_TYPE, ERROR_CODE } from './constants/enums';
11
11
  import setEnv from './fetch-client/helper';
12
12
  import endVoiceRecording from './main/end-recording';
13
13
  import pauseVoiceRecording from './main/pause-recording';
@@ -126,12 +126,21 @@ class EkaScribe {
126
126
  }
127
127
  async patchSessionStatus({ sessionId, processing_status, processing_error, }) {
128
128
  try {
129
+ const onEventCallback = EkaScribeStore.eventCallback;
129
130
  this.vadInstance.pauseVad();
130
131
  const patchTransactionResponse = await patchTransactionStatus({
131
132
  sessionId,
132
133
  processing_status,
133
134
  processing_error,
134
135
  });
136
+ if (onEventCallback) {
137
+ onEventCallback({
138
+ callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
139
+ status: 'info',
140
+ message: `Transaction cancel status: ${patchTransactionResponse.code}`,
141
+ timestamp: new Date().toISOString(),
142
+ });
143
+ }
135
144
  this.resetEkaScribe();
136
145
  return patchTransactionResponse;
137
146
  }
@@ -145,6 +154,7 @@ class EkaScribe {
145
154
  async commitTransactionCall() {
146
155
  try {
147
156
  const txnID = EkaScribeStore.txnID;
157
+ const onEventCallback = EkaScribeStore.eventCallback;
148
158
  let txnCommitMsg = '';
149
159
  if (EkaScribeStore.sessionStatus[txnID].api?.status === 'stop' ||
150
160
  EkaScribeStore.sessionStatus[txnID].api?.status === 'commit') {
@@ -155,6 +165,17 @@ class EkaScribe {
155
165
  txnId: EkaScribeStore.txnID,
156
166
  });
157
167
  txnCommitMsg = message;
168
+ if (onEventCallback) {
169
+ onEventCallback({
170
+ callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
171
+ status: 'info',
172
+ message: `Transaction commit status: ${txnCommitStatusCode}`,
173
+ timestamp: new Date().toISOString(),
174
+ data: {
175
+ request: audioFiles,
176
+ },
177
+ });
178
+ }
158
179
  if (txnCommitStatusCode != 200) {
159
180
  return {
160
181
  error_code: ERROR_CODE.TXN_COMMIT_FAILED,
@@ -248,8 +269,9 @@ class EkaScribe {
248
269
  onUserSpeechCallback(callback) {
249
270
  EkaScribeStore.userSpeechCallback = callback;
250
271
  }
251
- onFileUploadProgressCallback(callback) {
252
- this.audioFileManagerInstance.setProgressCallback(callback);
272
+ onEventCallback(callback) {
273
+ EkaScribeStore.eventCallback = callback;
274
+ // this.audioFileManagerInstance.setProgressCallback(callback);
253
275
  }
254
276
  configureVadConstants({ pref_length, desp_length, max_length, sr, frame_size, pre_speech_pad_frames, short_thsld, long_thsld, }) {
255
277
  return this.vadInstance.configureVadConstants({
@@ -1,7 +1,7 @@
1
1
  import postTransactionCommit from '../api/transaction/post-transaction-commit';
2
2
  import postTransactionStop from '../api/transaction/post-transaction-stop';
3
3
  import { OUTPUT_FORMAT, SDK_STATUS_CODE } from '../constants/constant';
4
- import { ERROR_CODE } from '../constants/enums';
4
+ import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
5
5
  import EkaScribeStore from '../store/store';
6
6
  const endVoiceRecording = async () => {
7
7
  try {
@@ -9,6 +9,7 @@ const endVoiceRecording = async () => {
9
9
  const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
10
10
  const vadInstance = EkaScribeStore.vadInstance;
11
11
  const txnID = EkaScribeStore.txnID;
12
+ const onEventCallback = EkaScribeStore.eventCallback;
12
13
  if (!fileManagerInstance || !audioBufferInstance || !vadInstance) {
13
14
  throw new Error('Class instances are not initialized');
14
15
  }
@@ -54,6 +55,17 @@ const endVoiceRecording = async () => {
54
55
  audioFiles,
55
56
  txnId: txnID,
56
57
  });
58
+ if (onEventCallback) {
59
+ onEventCallback({
60
+ callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
61
+ status: 'info',
62
+ message: `Transaction stop status: ${txnStopStatusCode}`,
63
+ timestamp: new Date().toISOString(),
64
+ data: {
65
+ request: audioFiles,
66
+ },
67
+ });
68
+ }
57
69
  if (txnStopStatusCode != 200) {
58
70
  return {
59
71
  error_code: ERROR_CODE.TXN_STOP_FAILED,
@@ -101,6 +113,17 @@ const endVoiceRecording = async () => {
101
113
  txnId: txnID,
102
114
  audioFiles,
103
115
  });
116
+ if (onEventCallback) {
117
+ onEventCallback({
118
+ callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
119
+ status: 'info',
120
+ message: `Transaction commit status: ${txnCommitStatusCode}`,
121
+ timestamp: new Date().toISOString(),
122
+ data: {
123
+ request: audioFiles,
124
+ },
125
+ });
126
+ }
104
127
  if (txnCommitStatusCode != 200) {
105
128
  return {
106
129
  error_code: ERROR_CODE.TXN_COMMIT_FAILED,
@@ -1,12 +1,13 @@
1
1
  import postTransactionInit from '../api/transaction/post-transaction-init';
2
2
  import { S3_BUCKET_NAME, SDK_STATUS_CODE } from '../constants/constant';
3
- import { ERROR_CODE } from '../constants/enums';
3
+ import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
4
4
  import EkaScribeStore from '../store/store';
5
5
  const initialiseTransaction = async (request) => {
6
6
  try {
7
7
  const { txn_id } = request;
8
8
  const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
9
9
  const sessionStatus = EkaScribeStore.sessionStatus;
10
+ const onEventCallback = EkaScribeStore.eventCallback;
10
11
  let businessID = '';
11
12
  let userOID = '';
12
13
  let userUUID = '';
@@ -28,6 +29,14 @@ const initialiseTransaction = async (request) => {
28
29
  s3Url: `s3://${S3_BUCKET_NAME}/${filePath}`,
29
30
  });
30
31
  const { code: txnInitStatusCode, b_id: businessId, oid, uuid, message: txnInitMessage, error: txnInitError, } = txnInitResponse;
32
+ if (onEventCallback) {
33
+ onEventCallback({
34
+ callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
35
+ status: 'info',
36
+ message: `Transaction init status: ${txnInitStatusCode}`,
37
+ timestamp: new Date().toISOString(),
38
+ });
39
+ }
31
40
  if (txnInitStatusCode === 400 && txnInitError?.code === ERROR_CODE.TXN_LIMIT_EXCEEDED) {
32
41
  return {
33
42
  error_code: ERROR_CODE.TXN_LIMIT_EXCEEDED,
@@ -1,10 +1,11 @@
1
1
  import postTransactionCommit from '../api/transaction/post-transaction-commit';
2
2
  import { SDK_STATUS_CODE } from '../constants/constant';
3
- import { ERROR_CODE } from '../constants/enums';
3
+ import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
4
4
  import EkaScribeStore from '../store/store';
5
5
  const retryUploadFailedFiles = async ({ force_commit, }) => {
6
6
  try {
7
7
  const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
8
+ const onEventCallback = EkaScribeStore.eventCallback;
8
9
  if (!fileManagerInstance) {
9
10
  throw new Error('Class instances are not initialized');
10
11
  }
@@ -28,6 +29,17 @@ const retryUploadFailedFiles = async ({ force_commit, }) => {
28
29
  txnId: EkaScribeStore.txnID,
29
30
  audioFiles,
30
31
  });
32
+ if (onEventCallback) {
33
+ onEventCallback({
34
+ callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
35
+ status: 'info',
36
+ message: `Transaction commit status: ${txnCommitStatusCode}`,
37
+ timestamp: new Date().toISOString(),
38
+ data: {
39
+ request: audioFiles,
40
+ },
41
+ });
42
+ }
31
43
  if (txnCommitStatusCode != 200) {
32
44
  return {
33
45
  error_code: ERROR_CODE.TXN_COMMIT_FAILED,
@@ -1,7 +1,7 @@
1
1
  import AudioBufferManager from '../audio-chunker/audio-buffer-manager';
2
2
  import AudioFileManager from '../audio-chunker/audio-file-manager';
3
3
  import VadWebClient from '../audio-chunker/vad-web';
4
- import { TErrorCallback, TSessionStatus } from '../constants/types';
4
+ import { TErrorCallback, TEventCallback, TSessionStatus } from '../constants/types';
5
5
  declare class EkaScribeStore {
6
6
  private static instance;
7
7
  private _txnID;
@@ -12,6 +12,7 @@ declare class EkaScribeStore {
12
12
  private _sessionStatus;
13
13
  private _errorCallback;
14
14
  private _userSpeechCallback;
15
+ private _eventCallback;
15
16
  static getInstance(): EkaScribeStore;
16
17
  get vadInstance(): VadWebClient | null;
17
18
  set vadInstance(value: VadWebClient);
@@ -29,6 +30,8 @@ declare class EkaScribeStore {
29
30
  set errorCallback(callback: TErrorCallback | null);
30
31
  get userSpeechCallback(): ((isSpeech: boolean) => void) | null;
31
32
  set userSpeechCallback(callback: ((isSpeech: boolean) => void) | null);
33
+ get eventCallback(): TEventCallback | null;
34
+ set eventCallback(callback: TEventCallback | null);
32
35
  resetStore(): void;
33
36
  }
34
37
  declare const _default: EkaScribeStore;
@@ -48,6 +48,12 @@ class EkaScribeStore {
48
48
  writable: true,
49
49
  value: null
50
50
  });
51
+ Object.defineProperty(this, "_eventCallback", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: null
56
+ });
51
57
  }
52
58
  static getInstance() {
53
59
  if (!EkaScribeStore.instance) {
@@ -111,6 +117,13 @@ class EkaScribeStore {
111
117
  set userSpeechCallback(callback) {
112
118
  this._userSpeechCallback = callback;
113
119
  }
120
+ // Event Callback
121
+ get eventCallback() {
122
+ return this._eventCallback;
123
+ }
124
+ set eventCallback(callback) {
125
+ this._eventCallback = callback;
126
+ }
114
127
  // Reset store to initial state
115
128
  resetStore() {
116
129
  this._txnID = '';
@@ -119,6 +132,7 @@ class EkaScribeStore {
119
132
  // Clear callbacks
120
133
  this._errorCallback = null;
121
134
  this._userSpeechCallback = null;
135
+ this._eventCallback = null;
122
136
  }
123
137
  }
124
138
  export default EkaScribeStore.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/ekascribe-ts-sdk",
3
- "version": "1.5.11",
3
+ "version": "1.5.13",
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>",