@eka-care/ekascribe-ts-sdk 1.5.87 → 1.5.89

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 (57) hide show
  1. package/dist/api/config/get-voice-api-v2-config-my-templates.js +22 -12
  2. package/dist/api/config/get-voice-api-v2-config.js +22 -12
  3. package/dist/api/config/patch-voice-api-v2-config.js +21 -13
  4. package/dist/api/post-cog-init.js +28 -15
  5. package/dist/api/post-v1-file-upload.js +38 -28
  6. package/dist/api/template-sections/delete-v1-template-section.js +37 -27
  7. package/dist/api/template-sections/get-v1-template-sections.js +37 -27
  8. package/dist/api/template-sections/patch-v1-template-section.js +46 -36
  9. package/dist/api/template-sections/post-v1-template-section.js +45 -35
  10. package/dist/api/templates/cook-v1-medai-ai-create-template.js +35 -25
  11. package/dist/api/templates/delete-v1-template.js +37 -27
  12. package/dist/api/templates/get-v1-templates.js +37 -27
  13. package/dist/api/templates/patch-v1-template.js +44 -33
  14. package/dist/api/templates/post-convert-transcription-to-template.js +41 -31
  15. package/dist/api/templates/post-transaction-convert-to-template.js +38 -28
  16. package/dist/api/templates/post-v1-template.js +43 -33
  17. package/dist/api/transaction/get-transaction-history.js +20 -9
  18. package/dist/api/transaction/get-voice-api-v3-status-transcript.js +21 -8
  19. package/dist/api/transaction/get-voice-api-v3-status.js +21 -8
  20. package/dist/api/transaction/patch-transaction-status.js +23 -14
  21. package/dist/api/transaction/patch-voice-api-v3-status.js +22 -12
  22. package/dist/api/transaction/post-transaction-commit.js +41 -31
  23. package/dist/api/transaction/post-transaction-init.js +52 -47
  24. package/dist/api/transaction/post-transaction-stop.js +41 -31
  25. package/dist/api/upload-audio-with-presigned-url.js +67 -55
  26. package/dist/audio-chunker/audio-buffer-manager.js +5 -3
  27. package/dist/audio-chunker/audio-file-manager.js +353 -350
  28. package/dist/audio-chunker/vad-web.js +116 -97
  29. package/dist/aws-services/configure-aws.js +5 -2
  30. package/dist/aws-services/get-files-s3.js +20 -7
  31. package/dist/aws-services/s3-retry-wrapper.js +44 -31
  32. package/dist/aws-services/translate-text-to-target-language.js +28 -15
  33. package/dist/aws-services/upload-file-to-s3.js +17 -6
  34. package/dist/constants/constant.js +22 -19
  35. package/dist/constants/enums.js +15 -12
  36. package/dist/constants/setup-config.js +10 -7
  37. package/dist/constants/types.d.ts +1 -1
  38. package/dist/constants/types.js +2 -1
  39. package/dist/fetch-client/helper.js +24 -11
  40. package/dist/fetch-client/index.js +61 -52
  41. package/dist/index.js +321 -254
  42. package/dist/main/end-recording.js +56 -53
  43. package/dist/main/init-transaction.js +36 -27
  44. package/dist/main/pause-recording.js +17 -18
  45. package/dist/main/poll-output-summary.js +21 -7
  46. package/dist/main/resume-recording.js +13 -14
  47. package/dist/main/retry-upload-recording.js +39 -30
  48. package/dist/main/start-recording.js +34 -26
  49. package/dist/main/upload-full-audio-with-presigned-url.js +84 -69
  50. package/dist/shared-worker/s3-file-upload.js +88 -79
  51. package/dist/shared-worker/s3-file-upload.ts +1 -1
  52. package/dist/store/store.js +3 -1
  53. package/dist/utils/compress-mp3-audio.d.ts +1 -1
  54. package/dist/utils/compress-mp3-audio.js +6 -4
  55. package/dist/utils/get-worker-url.js +12 -7
  56. package/dist/utils/search-past-sessions.js +23 -9
  57. package/package.json +1 -1
@@ -1,30 +1,39 @@
1
- import postTransactionCommit from '../api/transaction/post-transaction-commit';
2
- import postTransactionStop from '../api/transaction/post-transaction-stop';
3
- import { OUTPUT_FORMAT, SDK_STATUS_CODE } from '../constants/constant';
4
- import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
5
- import EkaScribeStore from '../store/store';
6
- const endVoiceRecording = async () => {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const post_transaction_commit_1 = require("../api/transaction/post-transaction-commit");
13
+ const post_transaction_stop_1 = require("../api/transaction/post-transaction-stop");
14
+ const constant_1 = require("../constants/constant");
15
+ const enums_1 = require("../constants/enums");
16
+ const store_1 = require("../store/store");
17
+ const endVoiceRecording = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ var _a, _b, _c, _d;
7
19
  try {
8
- const audioBufferInstance = EkaScribeStore.audioBufferInstance;
9
- const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
10
- const vadInstance = EkaScribeStore.vadInstance;
11
- const txnID = EkaScribeStore.txnID;
12
- const onEventCallback = EkaScribeStore.eventCallback;
20
+ const audioBufferInstance = store_1.default.audioBufferInstance;
21
+ const fileManagerInstance = store_1.default.audioFileManagerInstance;
22
+ const vadInstance = store_1.default.vadInstance;
23
+ const txnID = store_1.default.txnID;
24
+ const onEventCallback = store_1.default.eventCallback;
13
25
  if (!fileManagerInstance || !audioBufferInstance || !vadInstance) {
14
26
  throw new Error('Class instances are not initialized');
15
27
  }
16
28
  vadInstance.pauseVad();
17
- EkaScribeStore.sessionStatus[txnID] = {
18
- ...EkaScribeStore.sessionStatus[txnID],
19
- vad: {
29
+ store_1.default.sessionStatus[txnID] = Object.assign(Object.assign({}, store_1.default.sessionStatus[txnID]), { vad: {
20
30
  status: 'stop',
21
- },
22
- };
31
+ } });
23
32
  // upload last audio chunk
24
33
  if (audioBufferInstance.getCurrentSampleLength() > 0) {
25
34
  const audioFrames = audioBufferInstance.getAudioData();
26
35
  const filenumber = (fileManagerInstance.audioChunks.length || 0) + 1;
27
- const fileName = `${filenumber}.${OUTPUT_FORMAT}`;
36
+ const fileName = `${filenumber}.${constant_1.OUTPUT_FORMAT}`;
28
37
  const rawSampleDetails = fileManagerInstance.getRawSampleDetails();
29
38
  const chunkTimestamps = audioBufferInstance.calculateChunkTimestamps(rawSampleDetails.totalRawSamples);
30
39
  const chunkInfo = {
@@ -37,27 +46,27 @@ const endVoiceRecording = async () => {
37
46
  audioFrames,
38
47
  };
39
48
  const audioChunkLength = fileManagerInstance.updateAudioInfo(chunkInfo);
40
- fileManagerInstance?.incrementInsertedSamples(audioBufferInstance.getCurrentSampleLength(), audioBufferInstance.getCurrentFrameLength());
49
+ fileManagerInstance === null || fileManagerInstance === void 0 ? void 0 : fileManagerInstance.incrementInsertedSamples(audioBufferInstance.getCurrentSampleLength(), audioBufferInstance.getCurrentFrameLength());
41
50
  audioBufferInstance.resetBufferState();
42
- await fileManagerInstance.uploadAudioToS3({
51
+ yield fileManagerInstance.uploadAudioToS3({
43
52
  audioFrames,
44
53
  fileName,
45
54
  chunkIndex: audioChunkLength - 1,
46
55
  });
47
56
  }
48
- await fileManagerInstance.waitForAllUploads();
49
- const audioInfo = fileManagerInstance?.audioChunks;
57
+ yield fileManagerInstance.waitForAllUploads();
58
+ const audioInfo = fileManagerInstance === null || fileManagerInstance === void 0 ? void 0 : fileManagerInstance.audioChunks;
50
59
  const audioFiles = audioInfo.map((audio) => audio.fileName);
51
60
  console.log(audioInfo, 'audio files in end recording - SDK');
52
61
  // call stop txn api
53
- if (EkaScribeStore.sessionStatus[txnID].api?.status === 'init') {
54
- const { message: txnStopMsg, code: txnStopStatusCode } = await postTransactionStop({
62
+ if (((_a = store_1.default.sessionStatus[txnID].api) === null || _a === void 0 ? void 0 : _a.status) === 'init') {
63
+ const { message: txnStopMsg, code: txnStopStatusCode } = yield (0, post_transaction_stop_1.default)({
55
64
  audioFiles,
56
65
  txnId: txnID,
57
66
  });
58
67
  if (onEventCallback) {
59
68
  onEventCallback({
60
- callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
69
+ callback_type: enums_1.CALLBACK_TYPE.TRANSACTION_STATUS,
61
70
  status: 'info',
62
71
  message: `Transaction stop status: ${txnStopStatusCode}`,
63
72
  timestamp: new Date().toISOString(),
@@ -68,25 +77,22 @@ const endVoiceRecording = async () => {
68
77
  }
69
78
  if (txnStopStatusCode != 200) {
70
79
  return {
71
- error_code: ERROR_CODE.TXN_STOP_FAILED,
80
+ error_code: enums_1.ERROR_CODE.TXN_STOP_FAILED,
72
81
  status_code: txnStopStatusCode,
73
82
  message: txnStopMsg || 'Transaction stop failed.',
74
83
  };
75
84
  }
76
- EkaScribeStore.sessionStatus[txnID] = {
77
- ...EkaScribeStore.sessionStatus[txnID],
78
- api: {
85
+ store_1.default.sessionStatus[txnID] = Object.assign(Object.assign({}, store_1.default.sessionStatus[txnID]), { api: {
79
86
  status: 'stop',
80
87
  code: txnStopStatusCode,
81
88
  response: txnStopMsg,
82
- },
83
- };
89
+ } });
84
90
  }
85
- else if (EkaScribeStore.sessionStatus[txnID].api?.status === 'na') {
91
+ else if (((_b = store_1.default.sessionStatus[txnID].api) === null || _b === void 0 ? void 0 : _b.status) === 'na') {
86
92
  // transaction is not initialised
87
93
  return {
88
- error_code: ERROR_CODE.TXN_STATUS_MISMATCH,
89
- status_code: SDK_STATUS_CODE.TXN_ERROR,
94
+ error_code: enums_1.ERROR_CODE.TXN_STATUS_MISMATCH,
95
+ status_code: constant_1.SDK_STATUS_CODE.TXN_ERROR,
90
96
  message: 'Transaction is not initialized. Cannot end recording.',
91
97
  };
92
98
  }
@@ -94,28 +100,28 @@ const endVoiceRecording = async () => {
94
100
  let retryFailedFiles = [];
95
101
  // retry upload once if there are any failed uploads
96
102
  if (failedFiles.length > 0) {
97
- retryFailedFiles = await fileManagerInstance.retryFailedUploads();
103
+ retryFailedFiles = yield fileManagerInstance.retryFailedUploads();
98
104
  }
99
105
  // if there are still failed uploads after retry, return error
100
106
  if (retryFailedFiles.length > 0) {
101
107
  return {
102
- error_code: ERROR_CODE.AUDIO_UPLOAD_FAILED,
103
- status_code: SDK_STATUS_CODE.AUDIO_ERROR,
108
+ error_code: enums_1.ERROR_CODE.AUDIO_UPLOAD_FAILED,
109
+ status_code: constant_1.SDK_STATUS_CODE.AUDIO_ERROR,
104
110
  message: 'Audio upload failed for some files after retry.',
105
111
  failed_files: retryFailedFiles,
106
112
  total_audio_files: audioFiles,
107
113
  };
108
114
  }
109
115
  // call commit transaction api
110
- if (EkaScribeStore.sessionStatus[txnID].api?.status === 'stop' ||
111
- EkaScribeStore.sessionStatus[txnID].api?.status === 'commit') {
112
- const { message: txnCommitMsg, code: txnCommitStatusCode } = await postTransactionCommit({
116
+ if (((_c = store_1.default.sessionStatus[txnID].api) === null || _c === void 0 ? void 0 : _c.status) === 'stop' ||
117
+ ((_d = store_1.default.sessionStatus[txnID].api) === null || _d === void 0 ? void 0 : _d.status) === 'commit') {
118
+ const { message: txnCommitMsg, code: txnCommitStatusCode } = yield (0, post_transaction_commit_1.default)({
113
119
  txnId: txnID,
114
120
  audioFiles,
115
121
  });
116
122
  if (onEventCallback) {
117
123
  onEventCallback({
118
- callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
124
+ callback_type: enums_1.CALLBACK_TYPE.TRANSACTION_STATUS,
119
125
  status: 'info',
120
126
  message: `Transaction commit status: ${txnCommitStatusCode}`,
121
127
  timestamp: new Date().toISOString(),
@@ -126,40 +132,37 @@ const endVoiceRecording = async () => {
126
132
  }
127
133
  if (txnCommitStatusCode != 200) {
128
134
  return {
129
- error_code: ERROR_CODE.TXN_COMMIT_FAILED,
135
+ error_code: enums_1.ERROR_CODE.TXN_COMMIT_FAILED,
130
136
  status_code: txnCommitStatusCode,
131
137
  message: txnCommitMsg || 'Transaction stop failed.',
132
138
  };
133
139
  }
134
- EkaScribeStore.sessionStatus[txnID] = {
135
- ...EkaScribeStore.sessionStatus[txnID],
136
- api: {
140
+ store_1.default.sessionStatus[txnID] = Object.assign(Object.assign({}, store_1.default.sessionStatus[txnID]), { api: {
137
141
  status: 'commit',
138
142
  code: txnCommitStatusCode,
139
143
  response: txnCommitMsg,
140
- },
141
- };
144
+ } });
142
145
  }
143
146
  else {
144
147
  // transaction is not stopped or committed
145
148
  return {
146
- error_code: ERROR_CODE.TXN_STATUS_MISMATCH,
147
- status_code: SDK_STATUS_CODE.TXN_ERROR,
149
+ error_code: enums_1.ERROR_CODE.TXN_STATUS_MISMATCH,
150
+ status_code: constant_1.SDK_STATUS_CODE.TXN_ERROR,
148
151
  message: 'Transaction is not initialised or stopped. Cannot end recording.',
149
152
  };
150
153
  }
151
154
  return {
152
- status_code: SDK_STATUS_CODE.SUCCESS,
155
+ status_code: constant_1.SDK_STATUS_CODE.SUCCESS,
153
156
  message: 'Recording ended successfully.',
154
157
  };
155
158
  }
156
159
  catch (error) {
157
160
  console.error('Error ending recording: ', error);
158
161
  return {
159
- error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
160
- status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
162
+ error_code: enums_1.ERROR_CODE.INTERNAL_SERVER_ERROR,
163
+ status_code: constant_1.SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
161
164
  message: `An error occurred while ending the recording: ${error}`,
162
165
  };
163
166
  }
164
- };
165
- export default endVoiceRecording;
167
+ });
168
+ exports.default = endVoiceRecording;
@@ -1,21 +1,33 @@
1
- import postTransactionInit from '../api/transaction/post-transaction-init';
2
- import { SDK_STATUS_CODE } from '../constants/constant';
3
- import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
4
- import { GET_S3_BUCKET_NAME } from '../fetch-client/helper';
5
- import EkaScribeStore from '../store/store';
6
- const initialiseTransaction = async (request) => {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const post_transaction_init_1 = require("../api/transaction/post-transaction-init");
13
+ const constant_1 = require("../constants/constant");
14
+ const enums_1 = require("../constants/enums");
15
+ const helper_1 = require("../fetch-client/helper");
16
+ const store_1 = require("../store/store");
17
+ const initialiseTransaction = (request) => __awaiter(void 0, void 0, void 0, function* () {
18
+ var _a;
7
19
  try {
8
20
  const { txn_id } = request;
9
- const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
10
- const sessionStatus = EkaScribeStore.sessionStatus;
11
- const onEventCallback = EkaScribeStore.eventCallback;
21
+ const fileManagerInstance = store_1.default.audioFileManagerInstance;
22
+ const sessionStatus = store_1.default.sessionStatus;
23
+ const onEventCallback = store_1.default.eventCallback;
12
24
  let businessID = '';
13
25
  let userOID = '';
14
26
  let userUUID = '';
15
27
  if (!sessionStatus[txn_id] ||
16
28
  Object.keys(sessionStatus[txn_id]).length === 0 ||
17
- sessionStatus[txn_id].api?.status === 'na') {
18
- EkaScribeStore.txnID = txn_id;
29
+ ((_a = sessionStatus[txn_id].api) === null || _a === void 0 ? void 0 : _a.status) === 'na') {
30
+ store_1.default.txnID = txn_id;
19
31
  // File path calculation
20
32
  const date = new Date();
21
33
  // Format date to YYYYMMDD
@@ -24,35 +36,32 @@ const initialiseTransaction = async (request) => {
24
36
  const year = date.getFullYear().toString().substring(2);
25
37
  // s3 file path format: <date>/txnID
26
38
  const filePath = `${year}${month}${day}/${txn_id}`;
27
- EkaScribeStore.sessionBucketPath = filePath;
28
- const txnInitResponse = await postTransactionInit({
29
- ...request,
30
- s3Url: `s3://${GET_S3_BUCKET_NAME()}/${filePath}`,
31
- });
39
+ store_1.default.sessionBucketPath = filePath;
40
+ const txnInitResponse = yield (0, post_transaction_init_1.default)(Object.assign(Object.assign({}, request), { s3Url: `s3://${(0, helper_1.GET_S3_BUCKET_NAME)()}/${filePath}` }));
32
41
  const { code: txnInitStatusCode, b_id: businessId, oid, uuid, message: txnInitMessage, error: txnInitError, } = txnInitResponse;
33
42
  if (onEventCallback) {
34
43
  onEventCallback({
35
- callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
44
+ callback_type: enums_1.CALLBACK_TYPE.TRANSACTION_STATUS,
36
45
  status: 'info',
37
46
  message: `Transaction init status: ${txnInitStatusCode}`,
38
47
  timestamp: new Date().toISOString(),
39
48
  });
40
49
  }
41
- if (txnInitStatusCode === 400 && txnInitError?.code === ERROR_CODE.TXN_LIMIT_EXCEEDED) {
50
+ if (txnInitStatusCode === 400 && (txnInitError === null || txnInitError === void 0 ? void 0 : txnInitError.code) === enums_1.ERROR_CODE.TXN_LIMIT_EXCEEDED) {
42
51
  return {
43
- error_code: ERROR_CODE.TXN_LIMIT_EXCEEDED,
52
+ error_code: enums_1.ERROR_CODE.TXN_LIMIT_EXCEEDED,
44
53
  status_code: txnInitStatusCode,
45
54
  message: txnInitMessage || 'Transaction limit exceeded.',
46
55
  };
47
56
  }
48
57
  if (txnInitStatusCode >= 400) {
49
58
  return {
50
- error_code: ERROR_CODE.TXN_INIT_FAILED,
59
+ error_code: enums_1.ERROR_CODE.TXN_INIT_FAILED,
51
60
  status_code: txnInitStatusCode,
52
61
  message: txnInitMessage || 'Transaction initialization failed.',
53
62
  };
54
63
  }
55
- EkaScribeStore.sessionStatus[txn_id] = {
64
+ store_1.default.sessionStatus[txn_id] = {
56
65
  api: {
57
66
  status: 'init',
58
67
  code: txnInitStatusCode,
@@ -62,7 +71,7 @@ const initialiseTransaction = async (request) => {
62
71
  businessID = businessId;
63
72
  userOID = oid;
64
73
  userUUID = uuid;
65
- fileManagerInstance?.setSessionInfo({
74
+ fileManagerInstance === null || fileManagerInstance === void 0 ? void 0 : fileManagerInstance.setSessionInfo({
66
75
  sessionId: txn_id,
67
76
  filePath: filePath,
68
77
  businessID: businessId,
@@ -70,7 +79,7 @@ const initialiseTransaction = async (request) => {
70
79
  }
71
80
  return {
72
81
  message: 'Transaction initialized successfully.',
73
- status_code: SDK_STATUS_CODE.SUCCESS,
82
+ status_code: constant_1.SDK_STATUS_CODE.SUCCESS,
74
83
  business_id: businessID,
75
84
  oid: userOID,
76
85
  uuid: userUUID,
@@ -80,10 +89,10 @@ const initialiseTransaction = async (request) => {
80
89
  catch (err) {
81
90
  console.error('%c Line:102 🍇 initialiseTransaction err', 'color:#b03734', err);
82
91
  return {
83
- error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
84
- status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
92
+ error_code: enums_1.ERROR_CODE.INTERNAL_SERVER_ERROR,
93
+ status_code: constant_1.SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
85
94
  message: `An error occurred in initializing the transaction: ${err}`,
86
95
  };
87
96
  }
88
- };
89
- export default initialiseTransaction;
97
+ });
98
+ exports.default = initialiseTransaction;
@@ -1,26 +1,25 @@
1
- import { OUTPUT_FORMAT, SDK_STATUS_CODE } from '../constants/constant';
2
- import { ERROR_CODE } from '../constants/enums';
3
- import EkaScribeStore from '../store/store';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constant_1 = require("../constants/constant");
4
+ const enums_1 = require("../constants/enums");
5
+ const store_1 = require("../store/store");
4
6
  const pauseVoiceRecording = () => {
5
7
  try {
6
- const audioBufferInstance = EkaScribeStore.audioBufferInstance;
7
- const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
8
- const vadInstance = EkaScribeStore.vadInstance;
8
+ const audioBufferInstance = store_1.default.audioBufferInstance;
9
+ const fileManagerInstance = store_1.default.audioFileManagerInstance;
10
+ const vadInstance = store_1.default.vadInstance;
9
11
  if (!fileManagerInstance || !audioBufferInstance || !vadInstance) {
10
12
  throw new Error('Class instances are not initialized');
11
13
  }
12
14
  vadInstance.pauseVad();
13
- const txn_id = EkaScribeStore.txnID;
14
- EkaScribeStore.sessionStatus[txn_id] = {
15
- ...EkaScribeStore.sessionStatus[txn_id],
16
- vad: {
15
+ const txn_id = store_1.default.txnID;
16
+ store_1.default.sessionStatus[txn_id] = Object.assign(Object.assign({}, store_1.default.sessionStatus[txn_id]), { vad: {
17
17
  status: 'pause',
18
- },
19
- };
18
+ } });
20
19
  if (audioBufferInstance.getCurrentSampleLength() > 0) {
21
20
  const audioFrames = audioBufferInstance.getAudioData();
22
21
  const filenumber = (fileManagerInstance.audioChunks.length || 0) + 1;
23
- const fileName = `${filenumber}.${OUTPUT_FORMAT}`;
22
+ const fileName = `${filenumber}.${constant_1.OUTPUT_FORMAT}`;
24
23
  const rawSampleDetails = fileManagerInstance.getRawSampleDetails();
25
24
  const chunkTimestamps = audioBufferInstance.calculateChunkTimestamps(rawSampleDetails.totalRawSamples);
26
25
  const chunkInfo = {
@@ -33,7 +32,7 @@ const pauseVoiceRecording = () => {
33
32
  audioFrames,
34
33
  };
35
34
  const audioChunkLength = fileManagerInstance.updateAudioInfo(chunkInfo);
36
- fileManagerInstance?.incrementInsertedSamples(audioBufferInstance.getCurrentSampleLength(), audioBufferInstance.getCurrentFrameLength());
35
+ fileManagerInstance === null || fileManagerInstance === void 0 ? void 0 : fileManagerInstance.incrementInsertedSamples(audioBufferInstance.getCurrentSampleLength(), audioBufferInstance.getCurrentFrameLength());
37
36
  audioBufferInstance.resetBufferState();
38
37
  fileManagerInstance.uploadAudioToS3({
39
38
  audioFrames,
@@ -42,7 +41,7 @@ const pauseVoiceRecording = () => {
42
41
  });
43
42
  }
44
43
  return {
45
- status_code: SDK_STATUS_CODE.SUCCESS,
44
+ status_code: constant_1.SDK_STATUS_CODE.SUCCESS,
46
45
  message: 'Recording paused successfully',
47
46
  is_paused: true,
48
47
  };
@@ -50,10 +49,10 @@ const pauseVoiceRecording = () => {
50
49
  catch (error) {
51
50
  console.log('%c Line:7 🍔 pauseRecording error', 'color:#3f7cff', error);
52
51
  return {
53
- error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
54
- status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
52
+ error_code: enums_1.ERROR_CODE.INTERNAL_SERVER_ERROR,
53
+ status_code: constant_1.SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
55
54
  message: `An error occurred while starting the recording: ${error}`,
56
55
  };
57
56
  }
58
57
  };
59
- export default pauseVoiceRecording;
58
+ exports.default = pauseVoiceRecording;
@@ -1,13 +1,26 @@
1
- import { getVoiceApiV3Status } from '../api/transaction/get-voice-api-v3-status';
2
- export const pollOutputSummary = async ({ txn_id, max_polling_time = 5 * 60 * 1000, }) => {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.pollOutputSummary = void 0;
13
+ const get_voice_api_v3_status_1 = require("../api/transaction/get-voice-api-v3-status");
14
+ const pollOutputSummary = (_a) => __awaiter(void 0, [_a], void 0, function* ({ txn_id, max_polling_time = 5 * 60 * 1000, }) {
3
15
  try {
4
16
  const time = new Date().getTime();
5
17
  const maxPollingTimeout = time + max_polling_time;
6
18
  let failedCount = 0;
7
- const getSummary = async () => {
19
+ const getSummary = () => __awaiter(void 0, void 0, void 0, function* () {
20
+ var _a;
8
21
  // this try-catch block is needed to handle the errors of this recursive call
9
22
  try {
10
- const getResponse = await getVoiceApiV3Status({ txnId: txn_id });
23
+ const getResponse = yield (0, get_voice_api_v3_status_1.getVoiceApiV3Status)({ txnId: txn_id });
11
24
  const { status_code, response } = getResponse;
12
25
  const currentTime = new Date().getTime();
13
26
  if (currentTime >= maxPollingTimeout) {
@@ -31,7 +44,7 @@ export const pollOutputSummary = async ({ txn_id, max_polling_time = 5 * 60 * 10
31
44
  return {
32
45
  response,
33
46
  status_code,
34
- errorMessage: response?.error?.msg ||
47
+ errorMessage: ((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.msg) ||
35
48
  `We encountered a backend error while fetching results. Please try again.`,
36
49
  };
37
50
  }
@@ -53,7 +66,7 @@ export const pollOutputSummary = async ({ txn_id, max_polling_time = 5 * 60 * 10
53
66
  errorMessage: `Something went wrong from inside catch block. ${error}`,
54
67
  };
55
68
  }
56
- };
69
+ });
57
70
  return getSummary();
58
71
  }
59
72
  catch (error) {
@@ -68,4 +81,5 @@ export const pollOutputSummary = async ({ txn_id, max_polling_time = 5 * 60 * 10
68
81
  errorMessage: `Something went wrong from outer catch block, ${error}`,
69
82
  };
70
83
  }
71
- };
84
+ });
85
+ exports.pollOutputSummary = pollOutputSummary;
@@ -1,22 +1,21 @@
1
- import { SDK_STATUS_CODE } from '../constants/constant';
2
- import { ERROR_CODE } from '../constants/enums';
3
- import EkaScribeStore from '../store/store';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constant_1 = require("../constants/constant");
4
+ const enums_1 = require("../constants/enums");
5
+ const store_1 = require("../store/store");
4
6
  const resumeVoiceRecording = () => {
5
7
  try {
6
- const vadInstance = EkaScribeStore.vadInstance;
8
+ const vadInstance = store_1.default.vadInstance;
7
9
  if (!vadInstance) {
8
10
  throw new Error('VAD instance is not initialized');
9
11
  }
10
12
  vadInstance.startVad();
11
- const txn_id = EkaScribeStore.txnID;
12
- EkaScribeStore.sessionStatus[txn_id] = {
13
- ...EkaScribeStore.sessionStatus[txn_id],
14
- vad: {
13
+ const txn_id = store_1.default.txnID;
14
+ store_1.default.sessionStatus[txn_id] = Object.assign(Object.assign({}, store_1.default.sessionStatus[txn_id]), { vad: {
15
15
  status: 'resume',
16
- },
17
- };
16
+ } });
18
17
  return {
19
- status_code: SDK_STATUS_CODE.SUCCESS,
18
+ status_code: constant_1.SDK_STATUS_CODE.SUCCESS,
20
19
  message: 'Recording resumed successfully',
21
20
  is_paused: false,
22
21
  };
@@ -24,10 +23,10 @@ const resumeVoiceRecording = () => {
24
23
  catch (error) {
25
24
  console.error('Error resuming recording:', error);
26
25
  return {
27
- error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
28
- status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
26
+ error_code: enums_1.ERROR_CODE.INTERNAL_SERVER_ERROR,
27
+ status_code: constant_1.SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
29
28
  message: `Failed to resume recording: ${error}`,
30
29
  };
31
30
  }
32
31
  };
33
- export default resumeVoiceRecording;
32
+ exports.default = resumeVoiceRecording;
@@ -1,37 +1,49 @@
1
- import postTransactionCommit from '../api/transaction/post-transaction-commit';
2
- import { SDK_STATUS_CODE } from '../constants/constant';
3
- import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
4
- import EkaScribeStore from '../store/store';
5
- const retryUploadFailedFiles = async ({ force_commit, }) => {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const post_transaction_commit_1 = require("../api/transaction/post-transaction-commit");
13
+ const constant_1 = require("../constants/constant");
14
+ const enums_1 = require("../constants/enums");
15
+ const store_1 = require("../store/store");
16
+ const retryUploadFailedFiles = (_a) => __awaiter(void 0, [_a], void 0, function* ({ force_commit, }) {
17
+ var _b, _c;
6
18
  try {
7
- const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
8
- const onEventCallback = EkaScribeStore.eventCallback;
19
+ const fileManagerInstance = store_1.default.audioFileManagerInstance;
20
+ const onEventCallback = store_1.default.eventCallback;
9
21
  if (!fileManagerInstance) {
10
22
  throw new Error('Class instances are not initialized');
11
23
  }
12
- const failedFiles = (await fileManagerInstance.retryFailedUploads()) || [];
13
- const audioInfo = fileManagerInstance?.audioChunks;
24
+ const failedFiles = (yield fileManagerInstance.retryFailedUploads()) || [];
25
+ const audioInfo = fileManagerInstance === null || fileManagerInstance === void 0 ? void 0 : fileManagerInstance.audioChunks;
14
26
  const audioFiles = audioInfo.map((audio) => audio.fileName);
15
27
  if (failedFiles.length > 0 && !force_commit) {
16
28
  return {
17
- error_code: ERROR_CODE.AUDIO_UPLOAD_FAILED,
18
- status_code: SDK_STATUS_CODE.AUDIO_ERROR,
29
+ error_code: enums_1.ERROR_CODE.AUDIO_UPLOAD_FAILED,
30
+ status_code: constant_1.SDK_STATUS_CODE.AUDIO_ERROR,
19
31
  message: 'Audio upload failed for some files after retry.',
20
32
  failed_files: failedFiles,
21
33
  total_audio_files: audioFiles,
22
34
  };
23
35
  }
24
36
  // call commit transaction api
25
- const txnID = EkaScribeStore.txnID;
26
- if (EkaScribeStore.sessionStatus[txnID].api?.status === 'stop' ||
27
- EkaScribeStore.sessionStatus[txnID].api?.status === 'commit') {
28
- const { message: txnCommitMsg, code: txnCommitStatusCode } = await postTransactionCommit({
29
- txnId: EkaScribeStore.txnID,
37
+ const txnID = store_1.default.txnID;
38
+ if (((_b = store_1.default.sessionStatus[txnID].api) === null || _b === void 0 ? void 0 : _b.status) === 'stop' ||
39
+ ((_c = store_1.default.sessionStatus[txnID].api) === null || _c === void 0 ? void 0 : _c.status) === 'commit') {
40
+ const { message: txnCommitMsg, code: txnCommitStatusCode } = yield (0, post_transaction_commit_1.default)({
41
+ txnId: store_1.default.txnID,
30
42
  audioFiles,
31
43
  });
32
44
  if (onEventCallback) {
33
45
  onEventCallback({
34
- callback_type: CALLBACK_TYPE.TRANSACTION_STATUS,
46
+ callback_type: enums_1.CALLBACK_TYPE.TRANSACTION_STATUS,
35
47
  status: 'info',
36
48
  message: `Transaction commit status: ${txnCommitStatusCode}`,
37
49
  timestamp: new Date().toISOString(),
@@ -42,40 +54,37 @@ const retryUploadFailedFiles = async ({ force_commit, }) => {
42
54
  }
43
55
  if (txnCommitStatusCode != 200) {
44
56
  return {
45
- error_code: ERROR_CODE.TXN_COMMIT_FAILED,
57
+ error_code: enums_1.ERROR_CODE.TXN_COMMIT_FAILED,
46
58
  status_code: txnCommitStatusCode,
47
59
  message: txnCommitMsg || 'Transaction stop failed.',
48
60
  };
49
61
  }
50
- EkaScribeStore.sessionStatus[txnID] = {
51
- ...EkaScribeStore.sessionStatus[txnID],
52
- api: {
62
+ store_1.default.sessionStatus[txnID] = Object.assign(Object.assign({}, store_1.default.sessionStatus[txnID]), { api: {
53
63
  status: 'commit',
54
64
  code: txnCommitStatusCode,
55
65
  response: txnCommitMsg,
56
- },
57
- };
66
+ } });
58
67
  }
59
68
  else {
60
69
  // transaction is not stopped or committed
61
70
  return {
62
- error_code: ERROR_CODE.TXN_STATUS_MISMATCH,
63
- status_code: SDK_STATUS_CODE.TXN_ERROR,
71
+ error_code: enums_1.ERROR_CODE.TXN_STATUS_MISMATCH,
72
+ status_code: constant_1.SDK_STATUS_CODE.TXN_ERROR,
64
73
  message: 'Transaction is not initialised or stopped. Cannot end recording.',
65
74
  };
66
75
  }
67
76
  return {
68
- status_code: SDK_STATUS_CODE.SUCCESS,
77
+ status_code: constant_1.SDK_STATUS_CODE.SUCCESS,
69
78
  message: 'All recordings uploaded successfully.',
70
79
  };
71
80
  }
72
81
  catch (error) {
73
82
  console.error('Error retrying upload: ', error);
74
83
  return {
75
- error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
76
- status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
84
+ error_code: enums_1.ERROR_CODE.INTERNAL_SERVER_ERROR,
85
+ status_code: constant_1.SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
77
86
  message: `An error occurred while retrying failed upload: ${error}`,
78
87
  };
79
88
  }
80
- };
81
- export default retryUploadFailedFiles;
89
+ });
90
+ exports.default = retryUploadFailedFiles;