webitel-sdk 26.4.43 → 26.4.44

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/index.cjs CHANGED
@@ -66734,7 +66734,7 @@ _defineProperty(SipPhone$1, "userAgent", `Webitel-Phone/${version$1}`);
66734
66734
  _defineProperty(SipPhone$1, "sipVersion", version$1);
66735
66735
  //#endregion
66736
66736
  //#region src/version.ts
66737
- const version = "26.4.43";
66737
+ const version = "26.4.44";
66738
66738
  //#endregion
66739
66739
  //#region src/socket/errors.ts
66740
66740
  /**
@@ -67644,6 +67644,59 @@ function formFields(fields) {
67644
67644
  }
67645
67645
  //#endregion
67646
67646
  //#region src/socket/agent.ts
67647
+ let WaitingCallSortField = /* @__PURE__ */ function(WaitingCallSortField) {
67648
+ WaitingCallSortField["Name"] = "name";
67649
+ WaitingCallSortField["DateTime"] = "joined_at";
67650
+ WaitingCallSortField["Duration"] = "duration";
67651
+ WaitingCallSortField["Queue"] = "queue";
67652
+ return WaitingCallSortField;
67653
+ }({});
67654
+ const DEFAULT_WAITING_CALLS_SIZE = 20;
67655
+ const nameCollator = new Intl.Collator(void 0, {
67656
+ numeric: true,
67657
+ sensitivity: "base"
67658
+ });
67659
+ const waitingCallSortFields = new Set(Object.values(WaitingCallSortField));
67660
+ const isWaitingCallSortField = (value) => waitingCallSortFields.has(value);
67661
+ const parseSort = (sort) => {
67662
+ if (!sort) return null;
67663
+ const first = sort.charAt(0);
67664
+ const field = (first === "+" || first === "-" || first === " " ? sort.slice(1) : sort).trim();
67665
+ if (!isWaitingCallSortField(field)) return null;
67666
+ return {
67667
+ field,
67668
+ direction: first === "-" ? -1 : 1
67669
+ };
67670
+ };
67671
+ const getQueueName = (queue) => queue && "name" in queue && typeof queue.name === "string" ? queue.name : "";
67672
+ const parseContact = (value) => {
67673
+ if (typeof value !== "object" || value === null) return void 0;
67674
+ const { id, name } = value;
67675
+ if (id === void 0 || id === null || id === "" || id === 0) return void 0;
67676
+ return {
67677
+ id: typeof id === "number" ? id : 0,
67678
+ name: typeof name === "string" ? name : ""
67679
+ };
67680
+ };
67681
+ const normalizeSize = (value) => Number.isFinite(value) ? Math.max(1, Math.floor(value)) : DEFAULT_WAITING_CALLS_SIZE;
67682
+ const waitingCallComparators = {
67683
+ ["name"]: (a, b) => nameCollator.compare(a.displayName, b.displayName),
67684
+ ["joined_at"]: (a, b) => a.joinedAt - b.joinedAt,
67685
+ ["duration"]: (a, b) => b.joinedAt - a.joinedAt,
67686
+ ["queue"]: (a, b) => nameCollator.compare(getQueueName(a.queue), getQueueName(b.queue))
67687
+ };
67688
+ const PHONE_QUERY_PATTERN = /^[\d\s+()\-.]+$/;
67689
+ const filterWaitingCalls = (calls, q) => {
67690
+ const text = q.trim().toLocaleLowerCase();
67691
+ if (text === "") return calls;
67692
+ const digits = PHONE_QUERY_PATTERN.test(text) ? text.replace(/\D/g, "") : "";
67693
+ return calls.filter((call) => call.displayName.toLocaleLowerCase().includes(text) || call.displayNumber.toLocaleLowerCase().includes(text) || digits !== "" && call.displayNumber.replace(/\D/g, "").includes(digits));
67694
+ };
67695
+ const sortWaitingCalls = (calls, sort) => {
67696
+ if (!sort) return [...calls];
67697
+ const compare = waitingCallComparators[sort.field];
67698
+ return [...calls].sort((a, b) => compare(a, b) * sort.direction || a.attemptId - b.attemptId);
67699
+ };
67647
67700
  /**
67648
67701
  * Перелік статусів агента.
67649
67702
  * @enum {string}
@@ -67783,6 +67836,15 @@ var Agent = class {
67783
67836
  _defineProperty(this, "_listOfflineMembers", void 0);
67784
67837
  _defineProperty(this, "lastStatusChange", void 0);
67785
67838
  _defineProperty(this, "_waitingChatsSize", 0);
67839
+ _defineProperty(this, "_waitingCalls", []);
67840
+ _defineProperty(this, "_waitingCallsQuery", {
67841
+ q: "",
67842
+ size: DEFAULT_WAITING_CALLS_SIZE,
67843
+ sort: null
67844
+ });
67845
+ _defineProperty(this, "_waitingCallsVisible", DEFAULT_WAITING_CALLS_SIZE);
67846
+ _defineProperty(this, "_waitingCallsTotal", 0);
67847
+ _defineProperty(this, "_waitingCallsAll", 0);
67786
67848
  this.task = /* @__PURE__ */ new Map();
67787
67849
  this._channels = /* @__PURE__ */ new Map();
67788
67850
  this.initChannels(info.channels);
@@ -67830,6 +67892,15 @@ var Agent = class {
67830
67892
  get statusComment() {
67831
67893
  return this.info.status_comment;
67832
67894
  }
67895
+ get waitingCallsTotal() {
67896
+ return this._waitingCallsTotal;
67897
+ }
67898
+ get hasMoreWaitingCalls() {
67899
+ return this._waitingCallsVisible < this._waitingCallsTotal;
67900
+ }
67901
+ get waitingCallsQuery() {
67902
+ return this._waitingCallsQuery;
67903
+ }
67833
67904
  /**
67834
67905
  * Метод, що повертає, чи є агент адміністратором.
67835
67906
  * @method
@@ -67862,6 +67933,9 @@ var Agent = class {
67862
67933
  get supervisor() {
67863
67934
  return this.info.supervisor;
67864
67935
  }
67936
+ get waitingCallsAllCount() {
67937
+ return this._waitingCallsAll;
67938
+ }
67865
67939
  /**
67866
67940
  * Метод, що повертає аудитора агента.
67867
67941
  * @method
@@ -67904,19 +67978,26 @@ var Agent = class {
67904
67978
  */
67905
67979
  setWaitingList(e) {
67906
67980
  if (e) {
67907
- this.waitingListCalls.length = 0;
67981
+ this._waitingCalls.length = 0;
67908
67982
  this.waitingListChats.length = 0;
67909
67983
  this._waitingChatsSize = 0;
67910
- if (this.status !== "online") return;
67911
- for (const el of e.calls || []) this.waitingListCalls.push({
67984
+ if (this.status !== "online") {
67985
+ this.refreshWaitingCalls();
67986
+ return;
67987
+ }
67988
+ const now = Date.now();
67989
+ for (const el of e.calls || []) this._waitingCalls.push({
67912
67990
  displayName: el.communication.name || "",
67913
67991
  displayNumber: el.communication.destination || "",
67914
67992
  attemptId: el.attempt_id,
67915
67993
  sessionId: el.session_id,
67916
67994
  deadline: el.deadline,
67917
67995
  queue: el.queue,
67918
- wait: el.wait
67996
+ wait: el.wait,
67997
+ joinedAt: now - el.wait * 1e3,
67998
+ contact: parseContact(el.contact)
67919
67999
  });
68000
+ this.refreshWaitingCalls();
67920
68001
  if (Array.isArray(e.chats)) this._waitingChatsSize = e.chats.length;
67921
68002
  for (const el of e.chats || []) {
67922
68003
  this.waitingListChats.push({
@@ -67941,11 +68022,13 @@ var Agent = class {
67941
68022
  * @param {keyable | undefined} e - Об'єкт зі списком членів, які очікують на відповідь.
67942
68023
  */
67943
68024
  deleteWaitingAttempt(e) {
67944
- if (e) {
67945
- const attemptId = e.attempt_id;
67946
- if (removeWaitingList(this.waitingListCalls, attemptId)) return;
67947
- if (removeWaitingList(this.waitingListChats, attemptId)) this._waitingChatsSize--;
68025
+ if (!e) return;
68026
+ const attemptId = e.attempt_id;
68027
+ if (removeWaitingList(this._waitingCalls, attemptId)) {
68028
+ this.refreshWaitingCalls();
68029
+ return;
67948
68030
  }
68031
+ if (removeWaitingList(this.waitingListChats, attemptId)) this._waitingChatsSize--;
67949
68032
  }
67950
68033
  /**
67951
68034
  * Метод, що перехоплює спробу.
@@ -68146,7 +68229,8 @@ var Agent = class {
68146
68229
  this.info.on_demand = e.on_demand || false;
68147
68230
  this.initChannels(e.channels);
68148
68231
  } else {
68149
- this.waitingListCalls.length = 0;
68232
+ this._waitingCalls.length = 0;
68233
+ this.refreshWaitingCalls();
68150
68234
  this.waitingListChats.length = 0;
68151
68235
  this._waitingChatsSize = 0;
68152
68236
  }
@@ -68197,6 +68281,29 @@ var Agent = class {
68197
68281
  hasTask(task) {
68198
68282
  return this.task.has(task.id);
68199
68283
  }
68284
+ setWaitingCallsQuery(patch) {
68285
+ const next = {
68286
+ ...this._waitingCallsQuery,
68287
+ ...patch
68288
+ };
68289
+ next.size = normalizeSize(next.size);
68290
+ this._waitingCallsQuery = next;
68291
+ this._waitingCallsVisible = next.size;
68292
+ this.refreshWaitingCalls();
68293
+ }
68294
+ loadMoreWaitingCalls() {
68295
+ if (!this.hasMoreWaitingCalls) return false;
68296
+ this._waitingCallsVisible += this._waitingCallsQuery.size;
68297
+ this.refreshWaitingCalls();
68298
+ return true;
68299
+ }
68300
+ refreshWaitingCalls() {
68301
+ const { q, sort } = this._waitingCallsQuery;
68302
+ const result = sortWaitingCalls(filterWaitingCalls(this._waitingCalls, q), parseSort(sort));
68303
+ this._waitingCallsTotal = result.length;
68304
+ this._waitingCallsAll = this._waitingCalls.length;
68305
+ this.waitingListCalls.splice(0, this.waitingListCalls.length, ...result.slice(0, this._waitingCallsVisible));
68306
+ }
68200
68307
  initChannels(channels) {
68201
68308
  for (const c of channels) this._channels.set(c.channel, c);
68202
68309
  }
@@ -71953,6 +72060,7 @@ exports.VariablesApiFactory = VariablesApiFactory;
71953
72060
  exports.VariablesApiFp = VariablesApiFp;
71954
72061
  exports.VideoMediaFlow = VideoMediaFlow;
71955
72062
  exports.WEBSOCKET_EVENT_CALL_MEDIA_METRIC = WEBSOCKET_EVENT_CALL_MEDIA_METRIC;
72063
+ exports.WaitingCallSortField = WaitingCallSortField;
71956
72064
  exports.WebHookServiceApi = WebHookServiceApi;
71957
72065
  exports.WebHookServiceApiAxiosParamCreator = WebHookServiceApiAxiosParamCreator;
71958
72066
  exports.WebHookServiceApiFactory = WebHookServiceApiFactory;