@integraciones_doc24/sdk 1.16.37 → 1.16.38
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/README.md +225 -206
- package/lib/baseSdk/diagnostica.d.ts +54 -54
- package/lib/baseSdk/diagnostica.js +82 -82
- package/lib/baseSdk/external.d.ts +177 -177
- package/lib/baseSdk/external.js +96 -96
- package/lib/baseSdk/index.d.ts +2 -2
- package/lib/baseSdk/index.js +76 -77
- package/lib/baseSdk/user.d.ts +112 -112
- package/lib/baseSdk/user.js +136 -136
- package/lib/index.d.ts +400 -400
- package/lib/index.js +22 -22
- package/lib/request/index.d.ts +4 -4
- package/lib/request/index.js +32 -32
- package/lib/request/token.d.ts +2 -2
- package/lib/request/token.js +34 -34
- package/lib/request/validation.d.ts +10 -10
- package/lib/request/validation.js +28 -28
- package/lib/schemas.d.ts +2482 -2703
- package/lib/schemas.js +540 -573
- package/lib/types.d.ts +170 -174
- package/lib/types.js +2 -2
- package/lib/userSdk/binah.d.ts +21 -21
- package/lib/userSdk/binah.js +20 -20
- package/lib/userSdk/chat.d.ts +57 -57
- package/lib/userSdk/chat.js +98 -98
- package/lib/userSdk/external.d.ts +34 -34
- package/lib/userSdk/external.js +72 -72
- package/lib/userSdk/index.d.ts +2 -2
- package/lib/userSdk/index.js +33 -33
- package/lib/userSdk/patients.d.ts +58 -58
- package/lib/userSdk/patients.js +89 -89
- package/lib/userSdk/schedule.d.ts +58 -59
- package/lib/userSdk/schedule.js +89 -90
- package/lib/userSdk/specialties.d.ts +19 -19
- package/lib/userSdk/specialties.js +48 -48
- package/lib/userSdk/videoVisit.d.ts +175 -225
- package/lib/userSdk/videoVisit.js +242 -283
- package/lib/utils.d.ts +3 -4
- package/lib/utils.js +43 -68
- package/lib/webhook/index.d.ts +2 -2
- package/lib/webhook/index.js +67 -67
- package/lib/webhook/responses.d.ts +35 -35
- package/lib/webhook/responses.js +42 -42
- package/lib/webhook/token.d.ts +2 -2
- package/lib/webhook/token.js +23 -23
- package/package.json +37 -37
package/lib/utils.js
CHANGED
|
@@ -1,68 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeTimezoneOffset = exports.
|
|
4
|
-
const date_fns_1 = require("date-fns");
|
|
5
|
-
// import {Doc24} from '.';
|
|
6
|
-
const defaultTimeZone = '-03';
|
|
7
|
-
const parseDate = (str, timeZone) => exports.parseDateTime(`${str} 00:00:00`, timeZone);
|
|
8
|
-
exports.parseDate = parseDate;
|
|
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
|
-
exports.parseDateTime = parseDateTime;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
throw new Error(`Invalid timezone format: ${raw}`);
|
|
45
|
-
}
|
|
46
|
-
const numStr = match[1].replace(',', '.');
|
|
47
|
-
const rawHours = Number(numStr);
|
|
48
|
-
if (Number.isNaN(rawHours)) {
|
|
49
|
-
throw new Error(`Invalid numeric timezone value: ${numStr}`);
|
|
50
|
-
}
|
|
51
|
-
const rawMinutes = Math.round(rawHours * 60);
|
|
52
|
-
const argentinaMinutes = Math.round(defualtTimezone * 60);
|
|
53
|
-
const targetMinutes = argentinaMinutes + rawMinutes;
|
|
54
|
-
const sign = targetMinutes >= 0 ? '+' : '-';
|
|
55
|
-
const absMinutes = Math.abs(targetMinutes);
|
|
56
|
-
const hh = Math.floor(absMinutes / 60)
|
|
57
|
-
.toString()
|
|
58
|
-
.padStart(2, '0');
|
|
59
|
-
const mm = (absMinutes % 60).toString().padStart(2, '0');
|
|
60
|
-
return mm === '00' ? `${sign}${hh}` : `${sign}${hh}:${mm}`;
|
|
61
|
-
};
|
|
62
|
-
exports.normalizeTimezoneOffset = normalizeTimezoneOffset;
|
|
63
|
-
// export const getIdetificationTypeId = (type: Doc24.IdentificationType) => {
|
|
64
|
-
// if (type === 'ndi') return 6;
|
|
65
|
-
// if (type === 'passport') return 5;
|
|
66
|
-
// if (type === 'credential') return 999;
|
|
67
|
-
// throw new Error('Invalid identificationType');
|
|
68
|
-
// };
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeTimezoneOffset = exports.parseDateTime = exports.parseDate = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
// import {Doc24} from '.';
|
|
6
|
+
const defaultTimeZone = '-03';
|
|
7
|
+
const parseDate = (str, timeZone) => exports.parseDateTime(`${str} 00:00:00`, timeZone);
|
|
8
|
+
exports.parseDate = parseDate;
|
|
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
|
+
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;
|
|
38
|
+
// export const getIdetificationTypeId = (type: Doc24.IdentificationType) => {
|
|
39
|
+
// if (type === 'ndi') return 6;
|
|
40
|
+
// if (type === 'passport') return 5;
|
|
41
|
+
// if (type === 'credential') return 999;
|
|
42
|
+
// throw new Error('Invalid identificationType');
|
|
43
|
+
// };
|
package/lib/webhook/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Doc24 } from '../types';
|
|
2
|
-
export declare const getRequestHandler: (credentials: Doc24.SdkCredentials, baseSdk: Doc24.BaseSdk, eventHandlers: Doc24.Webhook.Events) => Doc24.Webhook.Handler;
|
|
1
|
+
import { Doc24 } from '../types';
|
|
2
|
+
export declare const getRequestHandler: (credentials: Doc24.SdkCredentials, baseSdk: Doc24.BaseSdk, eventHandlers: Doc24.Webhook.Events) => Doc24.Webhook.Handler;
|
package/lib/webhook/index.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRequestHandler = void 0;
|
|
4
|
-
const token_1 = require("./token");
|
|
5
|
-
const responses_1 = require("./responses");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const getRequestHandler = (credentials, baseSdk, eventHandlers) => async (request) => {
|
|
8
|
-
const tokenPayload = await token_1.getWebhookToken(request, credentials);
|
|
9
|
-
if (!tokenPayload)
|
|
10
|
-
return responses_1.unauthorizedErrorResponse();
|
|
11
|
-
const body = request.body;
|
|
12
|
-
const error = await handleEvent(body, baseSdk, eventHandlers);
|
|
13
|
-
if (error)
|
|
14
|
-
return responses_1.unexpectedErrorResponse(error);
|
|
15
|
-
return responses_1.successResponse();
|
|
16
|
-
return responses_1.notFoundErrorResponse();
|
|
17
|
-
};
|
|
18
|
-
exports.getRequestHandler = getRequestHandler;
|
|
19
|
-
const handleEvent = async (body, _baseSdk, eventHandlers) => {
|
|
20
|
-
var _a, _b, _c, _d;
|
|
21
|
-
const date = utils_1.parseDateTime(body.fecha_estado);
|
|
22
|
-
if (body.tipo === 'consulta')
|
|
23
|
-
return (_a = eventHandlers.onConsultationStatusChange) === null || _a === void 0 ? void 0 : _a.call(eventHandlers, {
|
|
24
|
-
id: Number(body.id_consulta_virtual),
|
|
25
|
-
invitationId: Number(body.id_invitacion),
|
|
26
|
-
status: body.id_estado,
|
|
27
|
-
changeDate: date,
|
|
28
|
-
vcToken: body.vc_token,
|
|
29
|
-
patientId: body.id_paciente !== undefined ? Number(body.id_paciente) : undefined,
|
|
30
|
-
});
|
|
31
|
-
if (body.tipo === 'invitacion') {
|
|
32
|
-
const normalizedTimeZone = utils_1.normalizeTimezoneOffset(body.user_time_zone);
|
|
33
|
-
return (_b = eventHandlers.onInvitationStatusChange) === null || _b === void 0 ? void 0 : _b.call(eventHandlers, {
|
|
34
|
-
status: body.id_estado,
|
|
35
|
-
changeDate: date,
|
|
36
|
-
vcToken: body.vc_token,
|
|
37
|
-
appointmentId: Number(body.id_turno),
|
|
38
|
-
patientId: Number(body.id_persona),
|
|
39
|
-
professionalId: Number(body.id_profesional),
|
|
40
|
-
docPatientId: body.id_paciente,
|
|
41
|
-
identificationType: body.tipo_identificacion,
|
|
42
|
-
identificationValue: body.valor_identificacion,
|
|
43
|
-
idSharedVc: body.id_shared_vc,
|
|
44
|
-
specialtyId: body.id_especialidad,
|
|
45
|
-
date: utils_1.parseDateTime(`${body.fecha_turno} ${body.hora_turno}`, normalizedTimeZone),
|
|
46
|
-
appointmentDate: body.fecha_turno,
|
|
47
|
-
appointmentTime: body.hora_turno,
|
|
48
|
-
userTimeZone: body.user_time_zone,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (body.tipo === 'turno')
|
|
52
|
-
return (_c = eventHandlers.onAppointmentStatusChange) === null || _c === void 0 ? void 0 : _c.call(eventHandlers, {
|
|
53
|
-
id: Number(body.id_turno),
|
|
54
|
-
status: body.id_estado,
|
|
55
|
-
vcTokens: body.vc_tokens,
|
|
56
|
-
changeDate: date,
|
|
57
|
-
});
|
|
58
|
-
if (body.tipo === 'chat')
|
|
59
|
-
return (_d = eventHandlers.onChatUpdate) === null || _d === void 0 ? void 0 : _d.call(eventHandlers, {
|
|
60
|
-
id: Number(body.id_consulta_chat),
|
|
61
|
-
status: body.estado_chat === 'A' ? 'active' : 'ended',
|
|
62
|
-
patientId: Number(body.id_paciente),
|
|
63
|
-
professionalId: Number(body.id_profesional),
|
|
64
|
-
date,
|
|
65
|
-
});
|
|
66
|
-
return 'message_not_understood';
|
|
67
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequestHandler = void 0;
|
|
4
|
+
const token_1 = require("./token");
|
|
5
|
+
const responses_1 = require("./responses");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const getRequestHandler = (credentials, baseSdk, eventHandlers) => async (request) => {
|
|
8
|
+
const tokenPayload = await token_1.getWebhookToken(request, credentials);
|
|
9
|
+
if (!tokenPayload)
|
|
10
|
+
return responses_1.unauthorizedErrorResponse();
|
|
11
|
+
const body = request.body;
|
|
12
|
+
const error = await handleEvent(body, baseSdk, eventHandlers);
|
|
13
|
+
if (error)
|
|
14
|
+
return responses_1.unexpectedErrorResponse(error);
|
|
15
|
+
return responses_1.successResponse();
|
|
16
|
+
return responses_1.notFoundErrorResponse();
|
|
17
|
+
};
|
|
18
|
+
exports.getRequestHandler = getRequestHandler;
|
|
19
|
+
const handleEvent = async (body, _baseSdk, eventHandlers) => {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
const date = utils_1.parseDateTime(body.fecha_estado);
|
|
22
|
+
if (body.tipo === 'consulta')
|
|
23
|
+
return (_a = eventHandlers.onConsultationStatusChange) === null || _a === void 0 ? void 0 : _a.call(eventHandlers, {
|
|
24
|
+
id: Number(body.id_consulta_virtual),
|
|
25
|
+
invitationId: Number(body.id_invitacion),
|
|
26
|
+
status: body.id_estado,
|
|
27
|
+
changeDate: date,
|
|
28
|
+
vcToken: body.vc_token,
|
|
29
|
+
patientId: body.id_paciente !== undefined ? Number(body.id_paciente) : undefined,
|
|
30
|
+
});
|
|
31
|
+
if (body.tipo === 'invitacion') {
|
|
32
|
+
const normalizedTimeZone = utils_1.normalizeTimezoneOffset(body.user_time_zone);
|
|
33
|
+
return (_b = eventHandlers.onInvitationStatusChange) === null || _b === void 0 ? void 0 : _b.call(eventHandlers, {
|
|
34
|
+
status: body.id_estado,
|
|
35
|
+
changeDate: date,
|
|
36
|
+
vcToken: body.vc_token,
|
|
37
|
+
appointmentId: Number(body.id_turno),
|
|
38
|
+
patientId: Number(body.id_persona),
|
|
39
|
+
professionalId: Number(body.id_profesional),
|
|
40
|
+
docPatientId: body.id_paciente,
|
|
41
|
+
identificationType: body.tipo_identificacion,
|
|
42
|
+
identificationValue: body.valor_identificacion,
|
|
43
|
+
idSharedVc: body.id_shared_vc,
|
|
44
|
+
specialtyId: body.id_especialidad,
|
|
45
|
+
date: utils_1.parseDateTime(`${body.fecha_turno} ${body.hora_turno}`, normalizedTimeZone),
|
|
46
|
+
appointmentDate: body.fecha_turno,
|
|
47
|
+
appointmentTime: body.hora_turno,
|
|
48
|
+
userTimeZone: body.user_time_zone,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (body.tipo === 'turno')
|
|
52
|
+
return (_c = eventHandlers.onAppointmentStatusChange) === null || _c === void 0 ? void 0 : _c.call(eventHandlers, {
|
|
53
|
+
id: Number(body.id_turno),
|
|
54
|
+
status: body.id_estado,
|
|
55
|
+
vcTokens: body.vc_tokens,
|
|
56
|
+
changeDate: date,
|
|
57
|
+
});
|
|
58
|
+
if (body.tipo === 'chat')
|
|
59
|
+
return (_d = eventHandlers.onChatUpdate) === null || _d === void 0 ? void 0 : _d.call(eventHandlers, {
|
|
60
|
+
id: Number(body.id_consulta_chat),
|
|
61
|
+
status: body.estado_chat === 'A' ? 'active' : 'ended',
|
|
62
|
+
patientId: Number(body.id_paciente),
|
|
63
|
+
professionalId: Number(body.id_profesional),
|
|
64
|
+
date,
|
|
65
|
+
});
|
|
66
|
+
return 'message_not_understood';
|
|
67
|
+
};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export declare const notFoundErrorResponse: () => {
|
|
2
|
-
status: {
|
|
3
|
-
code: number;
|
|
4
|
-
message: string;
|
|
5
|
-
};
|
|
6
|
-
data: {
|
|
7
|
-
error: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare const unauthorizedErrorResponse: () => {
|
|
11
|
-
status: {
|
|
12
|
-
code: number;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
|
-
data: {
|
|
16
|
-
error: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare const unexpectedErrorResponse: (details?: unknown) => {
|
|
20
|
-
status: {
|
|
21
|
-
code: number;
|
|
22
|
-
message: string;
|
|
23
|
-
};
|
|
24
|
-
data: {
|
|
25
|
-
error: string;
|
|
26
|
-
details: unknown;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export declare const successResponse: (data?: unknown) => {
|
|
30
|
-
status: {
|
|
31
|
-
code: number;
|
|
32
|
-
message: string;
|
|
33
|
-
};
|
|
34
|
-
data: unknown;
|
|
35
|
-
};
|
|
1
|
+
export declare const notFoundErrorResponse: () => {
|
|
2
|
+
status: {
|
|
3
|
+
code: number;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
data: {
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const unauthorizedErrorResponse: () => {
|
|
11
|
+
status: {
|
|
12
|
+
code: number;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
data: {
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const unexpectedErrorResponse: (details?: unknown) => {
|
|
20
|
+
status: {
|
|
21
|
+
code: number;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
data: {
|
|
25
|
+
error: string;
|
|
26
|
+
details: unknown;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare const successResponse: (data?: unknown) => {
|
|
30
|
+
status: {
|
|
31
|
+
code: number;
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
data: unknown;
|
|
35
|
+
};
|
package/lib/webhook/responses.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.successResponse = exports.unexpectedErrorResponse = exports.unauthorizedErrorResponse = exports.notFoundErrorResponse = void 0;
|
|
4
|
-
const notFoundErrorResponse = () => ({
|
|
5
|
-
status: {
|
|
6
|
-
code: 404,
|
|
7
|
-
message: 'Not Found',
|
|
8
|
-
},
|
|
9
|
-
data: {
|
|
10
|
-
error: 'not_found',
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
exports.notFoundErrorResponse = notFoundErrorResponse;
|
|
14
|
-
const unauthorizedErrorResponse = () => ({
|
|
15
|
-
status: {
|
|
16
|
-
code: 401,
|
|
17
|
-
message: 'Unauthorized',
|
|
18
|
-
},
|
|
19
|
-
data: {
|
|
20
|
-
error: 'unauthorized',
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
exports.unauthorizedErrorResponse = unauthorizedErrorResponse;
|
|
24
|
-
const unexpectedErrorResponse = (details) => ({
|
|
25
|
-
status: {
|
|
26
|
-
code: 500,
|
|
27
|
-
message: 'Unhandled Error',
|
|
28
|
-
},
|
|
29
|
-
data: {
|
|
30
|
-
error: 'unhandled_error',
|
|
31
|
-
details,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
exports.unexpectedErrorResponse = unexpectedErrorResponse;
|
|
35
|
-
const successResponse = (data) => ({
|
|
36
|
-
status: {
|
|
37
|
-
code: 200,
|
|
38
|
-
message: 'Success',
|
|
39
|
-
},
|
|
40
|
-
data,
|
|
41
|
-
});
|
|
42
|
-
exports.successResponse = successResponse;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.successResponse = exports.unexpectedErrorResponse = exports.unauthorizedErrorResponse = exports.notFoundErrorResponse = void 0;
|
|
4
|
+
const notFoundErrorResponse = () => ({
|
|
5
|
+
status: {
|
|
6
|
+
code: 404,
|
|
7
|
+
message: 'Not Found',
|
|
8
|
+
},
|
|
9
|
+
data: {
|
|
10
|
+
error: 'not_found',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
exports.notFoundErrorResponse = notFoundErrorResponse;
|
|
14
|
+
const unauthorizedErrorResponse = () => ({
|
|
15
|
+
status: {
|
|
16
|
+
code: 401,
|
|
17
|
+
message: 'Unauthorized',
|
|
18
|
+
},
|
|
19
|
+
data: {
|
|
20
|
+
error: 'unauthorized',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
exports.unauthorizedErrorResponse = unauthorizedErrorResponse;
|
|
24
|
+
const unexpectedErrorResponse = (details) => ({
|
|
25
|
+
status: {
|
|
26
|
+
code: 500,
|
|
27
|
+
message: 'Unhandled Error',
|
|
28
|
+
},
|
|
29
|
+
data: {
|
|
30
|
+
error: 'unhandled_error',
|
|
31
|
+
details,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
exports.unexpectedErrorResponse = unexpectedErrorResponse;
|
|
35
|
+
const successResponse = (data) => ({
|
|
36
|
+
status: {
|
|
37
|
+
code: 200,
|
|
38
|
+
message: 'Success',
|
|
39
|
+
},
|
|
40
|
+
data,
|
|
41
|
+
});
|
|
42
|
+
exports.successResponse = successResponse;
|
package/lib/webhook/token.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Doc24 } from '../types';
|
|
2
|
-
export declare const getWebhookToken: (request: Doc24.Webhook.Request, credentials: Doc24.SdkCredentials) => Promise<Record<string, unknown> | undefined>;
|
|
1
|
+
import { Doc24 } from '../types';
|
|
2
|
+
export declare const getWebhookToken: (request: Doc24.Webhook.Request, credentials: Doc24.SdkCredentials) => Promise<Record<string, unknown> | undefined>;
|
package/lib/webhook/token.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getWebhookToken = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const getWebhookToken = async (request, credentials) => {
|
|
9
|
-
if (request.headers.authentication === undefined)
|
|
10
|
-
return;
|
|
11
|
-
const decoded = await decodeJwt(request.headers.authentication, credentials.key);
|
|
12
|
-
if (!decoded || decoded.iss !== credentials.iss)
|
|
13
|
-
return;
|
|
14
|
-
return decoded;
|
|
15
|
-
};
|
|
16
|
-
exports.getWebhookToken = getWebhookToken;
|
|
17
|
-
const decodeJwt = (token, key) => new Promise((resolve, reject) => {
|
|
18
|
-
jsonwebtoken_1.default.verify(token, key, (err, result) => {
|
|
19
|
-
if (!result || err)
|
|
20
|
-
return reject(err);
|
|
21
|
-
resolve(result);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWebhookToken = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const getWebhookToken = async (request, credentials) => {
|
|
9
|
+
if (request.headers.authentication === undefined)
|
|
10
|
+
return;
|
|
11
|
+
const decoded = await decodeJwt(request.headers.authentication, credentials.key);
|
|
12
|
+
if (!decoded || decoded.iss !== credentials.iss)
|
|
13
|
+
return;
|
|
14
|
+
return decoded;
|
|
15
|
+
};
|
|
16
|
+
exports.getWebhookToken = getWebhookToken;
|
|
17
|
+
const decodeJwt = (token, key) => new Promise((resolve, reject) => {
|
|
18
|
+
jsonwebtoken_1.default.verify(token, key, (err, result) => {
|
|
19
|
+
if (!result || err)
|
|
20
|
+
return reject(err);
|
|
21
|
+
resolve(result);
|
|
22
|
+
});
|
|
23
|
+
});
|
package/package.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@integraciones_doc24/sdk",
|
|
3
|
-
"version": "1.16.
|
|
4
|
-
"publishConfig": {
|
|
5
|
-
"tag": "latest"
|
|
6
|
-
},
|
|
7
|
-
"description": "",
|
|
8
|
-
"main": "lib/index.js",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"prepublish": "npm run build",
|
|
12
|
-
"test": "npx tsx test"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"axios": "^0.21.0",
|
|
19
|
-
"date-fns": "^2.16.1",
|
|
20
|
-
"form-data": "^4.0.5",
|
|
21
|
-
"jsonwebtoken": "^8.5.1",
|
|
22
|
-
"zod": "^3.8.1"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"@types/debug": "^4.1.7",
|
|
26
|
-
"@types/jsonwebtoken": "^8.5.0",
|
|
27
|
-
"debug": "^4.3.4",
|
|
28
|
-
"typescript": "^4.1.3"
|
|
29
|
-
},
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"debug": "*"
|
|
32
|
-
},
|
|
33
|
-
"types": "lib/index.d.ts",
|
|
34
|
-
"files": [
|
|
35
|
-
"lib"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@integraciones_doc24/sdk",
|
|
3
|
+
"version": "1.16.38",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"tag": "latest"
|
|
6
|
+
},
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"prepublish": "npm run build",
|
|
12
|
+
"test": "npx tsx test"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^0.21.0",
|
|
19
|
+
"date-fns": "^2.16.1",
|
|
20
|
+
"form-data": "^4.0.5",
|
|
21
|
+
"jsonwebtoken": "^8.5.1",
|
|
22
|
+
"zod": "^3.8.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/debug": "^4.1.7",
|
|
26
|
+
"@types/jsonwebtoken": "^8.5.0",
|
|
27
|
+
"debug": "^4.3.4",
|
|
28
|
+
"typescript": "^4.1.3"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"debug": "*"
|
|
32
|
+
},
|
|
33
|
+
"types": "lib/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"lib"
|
|
36
|
+
]
|
|
37
|
+
}
|