@eka-care/ekascribe-ts-sdk 2.0.13 → 2.0.15

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 (2) hide show
  1. package/README.md +106 -29
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -302,7 +302,8 @@ const response = await ekascribe.endRecording();
302
302
 
303
303
  **Error handling:**
304
304
 
305
- - Possible Error Codes, `error_code`
305
+ Possible Error Codes in `error_code`:
306
+
306
307
  - `txn_stop_failed`: Call `endRecording` again.
307
308
  - `audio_upload_failed`: Use `retryUploadRecording` (step 9).
308
309
  - `txn_commit_failed`: Call `commitTransactionCall` (step 11).
@@ -347,10 +348,10 @@ const res = await ekascribe.pollSessionOutput({
347
348
 
348
349
  Status codes to handle:
349
350
 
351
+ - `200`: Success; all templates processed.
350
352
  - `202`: Templates are still processing; poll again (or let `pollSessionOutput` continue).
351
- - `500`: All template processing failed, or internal server error; stop and surface error.
352
353
  - `206`: Partial success; some templates not processed fully.
353
- - `200`: Success; all templates processed.
354
+ - `500`: All template processing failed, or internal server error; stop and surface error.
354
355
 
355
356
  - #### Response type:
356
357
 
@@ -1047,53 +1048,129 @@ Use this method to completely destroy the VAD instance and free up resources.
1047
1048
  ekaScribe.destroyVad();
1048
1049
  ```
1049
1050
 
1051
+ ### 8. Update Authentication Tokens
1052
+
1053
+ Use this method to update the access token when it expires (e.g., when you receive a 401 error).
1054
+
1055
+ ```ts
1056
+ ekascribe.updateAuthTokens({ access_token: 'new_access_token' });
1057
+ ```
1058
+
1059
+ **When to use:**
1060
+
1061
+ - When any API method returns `status_code: 401`
1062
+ - When `eventCallback` returns `error.code: 401` in `file_upload_status`
1063
+ - Before token expiration to prevent upload failures
1064
+
1050
1065
  ## Generic Callbacks
1051
1066
 
1052
1067
  ### 1. Event callback
1053
1068
 
1054
- This is a comprehensive callback that provides information about SDK operations, including success events, errors, progress updates, and system status. Use this callback to monitor all SDK activities and handle events globally in your application.
1055
-
1056
- ```ts
1057
- ekaScribe.onEventCallback((eventData) => {
1058
- console.log('Event callback triggered:', eventData);
1069
+ This callback provides information about SDK operations. Use it to monitor file uploads, transaction status, AWS configuration, and authentication errors.
1070
+
1071
+ ```ts
1072
+ ekascribe.onEventCallback((eventData) => {
1073
+ console.log('Event callback:', eventData);
1074
+
1075
+ // Handle different callback types
1076
+ switch (eventData.callback_type) {
1077
+ case 'file_upload_status':
1078
+ // Track audio chunk upload progress
1079
+ console.log(`Uploaded ${eventData.data?.success}/${eventData.data?.total} chunks`);
1080
+ break;
1081
+ case 'transaction_status':
1082
+ // Monitor transaction lifecycle (init, stop, commit, cancel)
1083
+ console.log('Transaction update:', eventData.message);
1084
+ break;
1085
+ case 'aws_configure_status':
1086
+ // AWS S3 configuration status
1087
+ console.log('AWS config:', eventData.status);
1088
+ break;
1089
+ case 'authentication_status':
1090
+ // API authentication errors
1091
+ console.error('Auth error:', eventData.message);
1092
+ break;
1093
+ }
1059
1094
  });
1060
1095
  ```
1061
1096
 
1062
- - #### Sample Callback Data:
1097
+ - #### Callback Structure:
1063
1098
 
1064
1099
  ```ts
1065
1100
  {
1066
- callback_type: 'AUDIO_UPLOAD' | 'TRANSACTION_STATUS' | 'VAD_STATUS' | 'RECORDING_STATUS',
1067
- status: 'success' | 'error' | 'progress' | 'info',
1068
- message: 'Audio file uploaded successfully',
1101
+ callback_type: 'file_upload_status' | 'transaction_status' | 'aws_configure_status' | 'authentication_status',
1102
+ status: 'success' | 'error' | 'info',
1103
+ message: string,
1104
+ timestamp: string, // ISO timestamp
1069
1105
  error?: {
1070
- code: 500,
1071
- msg: 'Upload failed',
1072
- details: { fileName: 'audio_chunk_1.mp3' }
1106
+ code: number,
1107
+ msg: string,
1108
+ details: any
1073
1109
  },
1074
1110
  data?: {
1075
- success: 3,
1076
- total: 4,
1077
- is_uploaded: true,
1078
- fileName: 'audio_chunk_1.mp3',
1079
- request: { txn_id: 'abc-123' },
1080
- response: { status: 'uploaded' }
1081
- },
1082
- timestamp: '2024-01-15T10:30:45.123Z',
1083
- metadata?: {
1084
- txn_id: 'abc-123',
1085
- chunk_index: 1
1111
+ success?: number, // Number of successfully uploaded chunks
1112
+ total?: number, // Total number of chunks
1113
+ is_uploaded?: boolean, // Whether current chunk uploaded successfully
1114
+ fileName?: string, // Current file name
1115
+ chunkData?: Uint8Array[], // Audio chunk data for current audiofile
1116
+ request?: any, // API request details
1117
+ response?: any // API response details
1086
1118
  }
1087
1119
  }
1088
1120
  ```
1089
1121
 
1122
+ - #### Callback Types Explained:
1123
+
1124
+ **`file_upload_status`** - Track audio chunk upload progress
1125
+
1126
+ Use this to monitor upload progress of audio chunks:
1127
+
1128
+ - `status: 'info'` - Audio chunk info
1129
+
1130
+ - `data.success`: Count of successfully uploaded chunks
1131
+ - `data.total`: Total chunks generated
1132
+ - `data.fileName`: Current chunk file name
1133
+ - `data.chunkData`: Audio data for current chunk
1134
+
1135
+ - `status: 'success'` - Chunk uploaded successfully
1136
+
1137
+ - `data.success`: Updated successful upload count
1138
+ - `data.total`: Total chunks
1139
+ - `data.is_uploaded`: true
1140
+
1141
+ - `status: 'error'` - Chunk upload failed
1142
+
1143
+ - `error.code`: HTTP error code
1144
+ - `error.msg`: Error message
1145
+ - `error.details`: Additional error details
1146
+
1147
+ - Status codes to handle:
1148
+
1149
+ If `error.code === 401`, it means your access token has expired. Update tokens immediately:
1150
+
1151
+ ```ts
1152
+ ekascribe.onEventCallback((eventData) => {
1153
+ if (eventData.callback_type === 'file_upload_status' && eventData.status === 'error') {
1154
+ if (eventData.error?.code === 401) {
1155
+ // Token expired - update it
1156
+ sdkConfig.access_token = '<new_access_token>';
1157
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
1158
+ }
1159
+ }
1160
+ });
1161
+ ```
1162
+
1090
1163
  ### 2. User speech callback
1091
1164
 
1092
- This callback will return a boolean indicating whether the user is speaking or not.
1165
+ Triggered by Voice Activity Detection (VAD) when user starts or stops speaking.
1093
1166
 
1094
1167
  ```ts
1095
- ekaScribe.onUserSpeechCallback((isSpeech) => {
1096
- console.log(isSpeech ? 'User is speaking' : 'User is not speaking');
1168
+ ekascribe.onUserSpeechCallback((isSpeech) => {
1169
+ if (isSpeech) {
1170
+ console.log('User started speaking');
1171
+ } else {
1172
+ console.log('User stopped speaking');
1173
+ }
1097
1174
  });
1098
1175
  ```
1099
1176
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/ekascribe-ts-sdk",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "EkaScribe TypeScript SDK - Modern ES2020 build",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",
@@ -33,7 +33,6 @@
33
33
  },
34
34
  "files": [
35
35
  "dist",
36
- "README.md",
37
- "LICENSE"
36
+ "README.md"
38
37
  ]
39
38
  }