@eka-care/ekascribe-ts-sdk 2.0.37 → 2.0.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.
package/dist/index.d.ts CHANGED
@@ -67,6 +67,7 @@ declare class EkaScribe {
67
67
  onEventCallback(callback: TEventCallback): void;
68
68
  onVadFramesCallback(callback: TVadFramesCallback): void;
69
69
  onVadFrameProcessedCallback(callback: TVadFrameProcessedCallback): void;
70
+ onPartialResultCallback(callback: TPartialResultCallback): void;
70
71
  configureVadConstants({ pref_length, desp_length, max_length, sr, frame_size, pre_speech_pad_frames, short_thsld, long_thsld, }: {
71
72
  pref_length: number;
72
73
  desp_length: number;
@@ -261,7 +262,7 @@ declare type TGetConfigV2Response = {
261
262
  onboarding_step?: string;
262
263
  };
263
264
  message?: string;
264
- code?: number;
265
+ code: number;
265
266
  };
266
267
 
267
268
  declare type TGetStatusApiResponse = {
@@ -337,6 +338,14 @@ declare type TOutputSummary = {
337
338
  warnings?: TTemplateMessage[];
338
339
  };
339
340
 
341
+ declare type TPartialResultCallback = (data: {
342
+ txn_id: string;
343
+ response: TGetStatusApiResponse;
344
+ status_code: number;
345
+ message: string;
346
+ poll_status: 'in-progress' | 'completed' | 'failed' | 'timeout';
347
+ }) => void;
348
+
340
349
  declare type TPatchTransactionError = {
341
350
  error: {
342
351
  type: string;
package/dist/index.mjs CHANGED
@@ -11130,7 +11130,7 @@ const setEnv = ({
11130
11130
  }, GET_S3_BUCKET_NAME = () => envVar.S3_BUCKET_NAME, GET_CLIENT_ID = () => client_id, GET_AUTH_TOKEN = () => auth, GET_EKA_VOICE_HOST_V1 = () => envVar.EKA_VOICE_HOST_V1, GET_EKA_VOICE_HOST_V2 = () => envVar.EKA_VOICE_HOST_V2, GET_EKA_VOICE_HOST_V3 = () => envVar.EKA_VOICE_HOST_V3, GET_COOK_HOST_V1 = () => envVar.COOK_V1, GET_EKA_HOST = () => envVar.EKA_HOST;
11131
11131
  class EkaScribeStore {
11132
11132
  constructor() {
11133
- this._txnID = "", this._sessionBucketPath = "", this._vadInstance = null, this._audioFileManagerInstance = null, this._audioBufferInstance = null, this._sessionStatus = {}, this._userSpeechCallback = null, this._eventCallback = null, this._vadFramesCallback = null, this._vadFrameProcessedCallback = null;
11133
+ this._txnID = "", this._sessionBucketPath = "", this._vadInstance = null, this._audioFileManagerInstance = null, this._audioBufferInstance = null, this._sessionStatus = {}, this._userSpeechCallback = null, this._eventCallback = null, this._vadFramesCallback = null, this._vadFrameProcessedCallback = null, this._partialResultCallback = null;
11134
11134
  }
11135
11135
  static getInstance() {
11136
11136
  return EkaScribeStore.instance || (EkaScribeStore.instance = new EkaScribeStore()), EkaScribeStore.instance;
@@ -11205,9 +11205,16 @@ class EkaScribeStore {
11205
11205
  set vadFrameProcessedCallback(a) {
11206
11206
  this._vadFrameProcessedCallback = a;
11207
11207
  }
11208
+ // Partial Result Callback
11209
+ get partialResultCallback() {
11210
+ return this._partialResultCallback;
11211
+ }
11212
+ set partialResultCallback(a) {
11213
+ this._partialResultCallback = a;
11214
+ }
11208
11215
  // Reset store to initial state
11209
11216
  resetStore() {
11210
- this._txnID = "", this._sessionBucketPath = "", this._sessionStatus = {}, this._vadInstance = null, this._audioFileManagerInstance = null, this._audioBufferInstance = null, this._userSpeechCallback = null, this._eventCallback = null, this._vadFramesCallback = null, this._vadFrameProcessedCallback = null;
11217
+ this._txnID = "", this._sessionBucketPath = "", this._sessionStatus = {}, this._vadInstance = null, this._audioFileManagerInstance = null, this._audioBufferInstance = null, this._userSpeechCallback = null, this._eventCallback = null, this._vadFramesCallback = null, this._vadFrameProcessedCallback = null, this._partialResultCallback = null;
11211
11218
  }
11212
11219
  }
11213
11220
  const EkaScribeStore$1 = EkaScribeStore.getInstance();
@@ -54179,7 +54186,7 @@ const decodeApiResponse = (i) => {
54179
54186
  method: "GET",
54180
54187
  headers: a
54181
54188
  }, n = await fetchWrapper(
54182
- `${GET_EKA_VOICE_HOST_V3()}/status/transcript/${i}`,
54189
+ `${GET_EKA_VOICE_HOST_V3()}/status/${i}?transcript=true`,
54183
54190
  s,
54184
54191
  16e3
54185
54192
  ), r = await n.json();
@@ -54198,47 +54205,59 @@ const decodeApiResponse = (i) => {
54198
54205
  max_polling_time: a = 120 * 1e3
54199
54206
  }) => {
54200
54207
  try {
54201
- const n = (/* @__PURE__ */ new Date()).getTime() + a;
54202
- let r = 0;
54203
- const c = async () => {
54208
+ const n = (/* @__PURE__ */ new Date()).getTime() + a, r = EkaScribeStore$1.partialResultCallback;
54209
+ let c = 0;
54210
+ const u = async () => {
54204
54211
  try {
54205
- const u = await getVoiceApiV3Status({ txnId: i }), { status_code: m, response: y } = u;
54212
+ const m = await getVoiceApiV3Status({ txnId: i }), { status_code: y, response: l } = m;
54206
54213
  if ((/* @__PURE__ */ new Date()).getTime() >= n)
54207
54214
  return {
54208
54215
  status_code: 500,
54209
54216
  errorMessage: "We encountered an error while fetching analysis results due to timeout. Please try again."
54210
54217
  };
54211
- if (m === 401 || m === 403)
54218
+ if (y === 401 || y === 403)
54212
54219
  return {
54213
- response: y,
54214
- status_code: m,
54220
+ response: l,
54221
+ status_code: y,
54215
54222
  errorMessage: "Unauthorized or Forbidden"
54216
54223
  };
54217
- if (m === 202 || m === 400 || m >= 500) {
54218
- if (m >= 400) {
54219
- if (r++, r >= 3)
54224
+ if (y === 202 || y === 400 || y >= 500) {
54225
+ if (y === 202 && l && r?.({
54226
+ txn_id: i,
54227
+ response: l,
54228
+ status_code: y,
54229
+ message: "Partial result received",
54230
+ poll_status: "in-progress"
54231
+ }), y >= 400) {
54232
+ if (c++, c >= 3)
54220
54233
  return {
54221
- response: y,
54222
- status_code: m,
54223
- errorMessage: y?.error?.msg || "We encountered a backend error while fetching results. Please try again."
54234
+ response: l,
54235
+ status_code: y,
54236
+ errorMessage: l?.error?.msg || "We encountered a backend error while fetching results. Please try again."
54224
54237
  };
54225
54238
  } else
54226
- r = 0;
54227
- return c();
54239
+ c = 0;
54240
+ return u();
54228
54241
  }
54229
- return {
54230
- response: y,
54231
- status_code: m
54242
+ return l && r?.({
54243
+ txn_id: i,
54244
+ response: l,
54245
+ status_code: y,
54246
+ message: "Template results generated successfully. Polling for this session is complete.",
54247
+ poll_status: "completed"
54248
+ }), {
54249
+ response: l,
54250
+ status_code: y
54232
54251
  };
54233
- } catch (u) {
54252
+ } catch (m) {
54234
54253
  return {
54235
54254
  status_code: -1,
54236
54255
  // -1: non-https status_code to distinguish backend's 500 status_code
54237
- errorMessage: `Something went wrong from inside catch block. ${u}`
54256
+ errorMessage: `Something went wrong from inside catch block. ${m}`
54238
54257
  };
54239
54258
  }
54240
54259
  };
54241
- return c();
54260
+ return u();
54242
54261
  } catch (s) {
54243
54262
  return s instanceof Error && s.name === "AbortError" ? {
54244
54263
  status_code: -1,
@@ -54274,7 +54293,30 @@ function getSharedWorkerUrl() {
54274
54293
  }
54275
54294
  return console.log("getSharedWorkerUrl: default package path"), "@eka-care/ekascribe-ts-sdk/dist/shared-worker/s3-file-upload.js";
54276
54295
  }
54277
- const INTERNET_TIMEOUT = 5e3, WORKER_TIMEOUT = 2e3, UPLOAD_TIMEOUT = 1e4, COMPATIBILITY_TEST_FOLDER = "system-compatibility-test";
54296
+ const getConfigV2Timezone = async ({
54297
+ timezone: i
54298
+ }) => {
54299
+ try {
54300
+ const a = {
54301
+ method: "GET",
54302
+ headers: {
54303
+ "Content-Type": "application/json"
54304
+ }
54305
+ }, s = await fetchWrapper(
54306
+ `${GET_EKA_VOICE_HOST_V2()}/config/?timezone=${i}`,
54307
+ a
54308
+ );
54309
+ return {
54310
+ ...await s.json(),
54311
+ code: s.status
54312
+ };
54313
+ } catch (a) {
54314
+ return console.error("Error in getConfigV2Timezone api: ", a), {
54315
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
54316
+ message: `Failed to fetch timezone configurations, ${a}`
54317
+ };
54318
+ }
54319
+ }, INTERNET_TIMEOUT = 5e3, WORKER_TIMEOUT = 2e3, UPLOAD_TIMEOUT = 1e4, COMPATIBILITY_TEST_FOLDER = "system-compatibility-test";
54278
54320
  class SystemCompatibilityManager {
54279
54321
  constructor(a) {
54280
54322
  this.testSharedWorker = null, this.microphoneStream = null, this.awsConfigured = !1, this.clientEndpoint = a || getSharedWorkerUrl(), console.log(this.clientEndpoint, "client endpoint");
@@ -54400,16 +54442,14 @@ class SystemCompatibilityManager {
54400
54442
  */
54401
54443
  async validateTimezone() {
54402
54444
  try {
54403
- const a = Intl.DateTimeFormat().resolvedOptions().timeZone, s = await fetchWrapper(
54404
- `${GET_EKA_HOST()}/voice/sys/time?timezone=${a}`,
54405
- {
54406
- method: "GET"
54407
- }
54408
- );
54409
- if (!s.ok)
54445
+ const a = Intl.DateTimeFormat().resolvedOptions().timeZone, s = await getConfigV2Timezone({ timezone: a });
54446
+ if (s.code >= 400)
54447
+ return "Failed to validate timezone against system time";
54448
+ const n = s.current_time_utc;
54449
+ if (!n)
54410
54450
  return "Failed to validate timezone against system time";
54411
- const r = (await s.json()).time, c = new Date(r), u = /* @__PURE__ */ new Date(), m = Math.abs(c.getTime() - u.getTime()), y = 600 * 1e3;
54412
- return m > y ? `System time and server time differ by ${Math.round(m / 6e4)} minutes. Maximum allowed difference is 10 minutes.` : null;
54451
+ const r = new Date(n), c = /* @__PURE__ */ new Date(), u = Math.abs(r.getTime() - c.getTime()), m = 600 * 1e3;
54452
+ return u > m ? `System time is invalid. It differs from server time by ${Math.round(u / 6e4)} minutes.` : null;
54413
54453
  } catch {
54414
54454
  return "Failed to validate timezone against system time";
54415
54455
  }
@@ -54980,6 +55020,9 @@ const Ur = class Ur {
54980
55020
  onVadFrameProcessedCallback(a) {
54981
55021
  EkaScribeStore$1.vadFrameProcessedCallback = a;
54982
55022
  }
55023
+ onPartialResultCallback(a) {
55024
+ EkaScribeStore$1.partialResultCallback = a;
55025
+ }
54983
55026
  configureVadConstants({
54984
55027
  pref_length: a,
54985
55028
  desp_length: s,