@integraciones_doc24/sdk 1.16.22 → 1.16.24

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/lib/types.d.ts CHANGED
@@ -135,6 +135,7 @@ export declare namespace Doc24 {
135
135
  status: StatusChangeEventStatus;
136
136
  vcToken?: string;
137
137
  changeDate: Date;
138
+ body: any;
138
139
  };
139
140
  type ChatUpdateEvent = {
140
141
  id: number;
package/lib/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const parseDate: (str: string, timeZone?: string | null | undefined) => Date;
2
2
  export declare const parseDateTime: (str: string, timeZone?: string | null | undefined) => Date;
3
+ export declare const normalizeTimezoneOffset: (raw?: string | undefined, defualtTimezone?: number) => string | undefined;
package/lib/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDateTime = exports.parseDate = void 0;
3
+ exports.normalizeTimezoneOffset = exports.parseDateTime = exports.parseDate = void 0;
4
4
  const date_fns_1 = require("date-fns");
5
5
  // import {Doc24} from '.';
6
6
  const defaultTimeZone = '-03';
@@ -8,6 +8,33 @@ const parseDate = (str, timeZone) => exports.parseDateTime(`${str} 00:00:00`, ti
8
8
  exports.parseDate = parseDate;
9
9
  const parseDateTime = (str, timeZone) => date_fns_1.parse(`${str} ${timeZone !== null && timeZone !== void 0 ? timeZone : defaultTimeZone}`, 'yyyy-MM-dd HH:mm:ss X', new Date());
10
10
  exports.parseDateTime = parseDateTime;
11
+ const normalizeTimezoneOffset = (raw, defualtTimezone = -3) => {
12
+ if (!raw)
13
+ return;
14
+ if (typeof raw !== 'string') {
15
+ throw new Error(`Invalid timezone format: ${raw}`);
16
+ }
17
+ const match = raw.trim().match(/([+-]?\d+(?:[.,]\d+)?)/);
18
+ if (!match) {
19
+ throw new Error(`Invalid timezone format: ${raw}`);
20
+ }
21
+ const numStr = match[1].replace(',', '.');
22
+ const rawHours = Number(numStr);
23
+ if (Number.isNaN(rawHours)) {
24
+ throw new Error(`Invalid numeric timezone value: ${numStr}`);
25
+ }
26
+ const rawMinutes = Math.round(rawHours * 60);
27
+ const argentinaMinutes = Math.round(defualtTimezone * 60);
28
+ const targetMinutes = argentinaMinutes + rawMinutes;
29
+ const sign = targetMinutes >= 0 ? '+' : '-';
30
+ const absMinutes = Math.abs(targetMinutes);
31
+ const hh = Math.floor(absMinutes / 60)
32
+ .toString()
33
+ .padStart(2, '0');
34
+ const mm = (absMinutes % 60).toString().padStart(2, '0');
35
+ return mm === '00' ? `${sign}${hh}` : `${sign}${hh}:${mm}`;
36
+ };
37
+ exports.normalizeTimezoneOffset = normalizeTimezoneOffset;
11
38
  // export const getIdetificationTypeId = (type: Doc24.IdentificationType) => {
12
39
  // if (type === 'ndi') return 6;
13
40
  // if (type === 'passport') return 5;
@@ -28,7 +28,8 @@ const handleEvent = async (body, _baseSdk, eventHandlers) => {
28
28
  vcToken: body.vc_token,
29
29
  patientId: body.id_paciente !== undefined ? Number(body.id_paciente) : undefined,
30
30
  });
31
- if (body.tipo === 'invitacion')
31
+ if (body.tipo === 'invitacion') {
32
+ const normalizedTimeZone = utils_1.normalizeTimezoneOffset(body.user_time_zone);
32
33
  return (_b = eventHandlers.onInvitationStatusChange) === null || _b === void 0 ? void 0 : _b.call(eventHandlers, {
33
34
  status: body.id_estado,
34
35
  changeDate: date,
@@ -41,17 +42,19 @@ const handleEvent = async (body, _baseSdk, eventHandlers) => {
41
42
  identificationValue: body.valor_identificacion,
42
43
  idSharedVc: body.id_shared_vc,
43
44
  specialtyId: body.id_especialidad,
44
- date: utils_1.parseDateTime(`${body.fecha_turno} ${body.hora_turno}`, body.user_time_zone),
45
+ date: utils_1.parseDateTime(`${body.fecha_turno} ${body.hora_turno}`, normalizedTimeZone),
45
46
  appointmentDate: body.fecha_turno,
46
47
  appointmentTime: body.hora_turno,
47
48
  userTimeZone: body.user_time_zone,
48
49
  });
50
+ }
49
51
  if (body.tipo === 'turno')
50
52
  return (_c = eventHandlers.onAppointmentStatusChange) === null || _c === void 0 ? void 0 : _c.call(eventHandlers, {
51
53
  id: Number(body.id_turno),
52
54
  status: body.id_estado,
53
55
  vcToken: body.vc_token,
54
56
  changeDate: date,
57
+ body: body,
55
58
  });
56
59
  if (body.tipo === 'chat')
57
60
  return (_d = eventHandlers.onChatUpdate) === null || _d === void 0 ? void 0 : _d.call(eventHandlers, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integraciones_doc24/sdk",
3
- "version": "1.16.22",
3
+ "version": "1.16.24",
4
4
  "publishConfig": {
5
5
  "tag": "latest"
6
6
  },