@integraciones_doc24/sdk 0.39.4 → 0.39.5

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 (44) hide show
  1. package/README.md +93 -83
  2. package/package.json +1 -1
  3. package/lib/baseSdk/diagnostica.d.ts +0 -54
  4. package/lib/baseSdk/diagnostica.js +0 -79
  5. package/lib/baseSdk/external.d.ts +0 -177
  6. package/lib/baseSdk/external.js +0 -96
  7. package/lib/baseSdk/index.d.ts +0 -2
  8. package/lib/baseSdk/index.js +0 -70
  9. package/lib/baseSdk/user.d.ts +0 -41
  10. package/lib/baseSdk/user.js +0 -88
  11. package/lib/index.d.ts +0 -159
  12. package/lib/index.js +0 -22
  13. package/lib/request/index.d.ts +0 -3
  14. package/lib/request/index.js +0 -26
  15. package/lib/request/token.d.ts +0 -2
  16. package/lib/request/token.js +0 -34
  17. package/lib/request/validation.d.ts +0 -10
  18. package/lib/request/validation.js +0 -28
  19. package/lib/schemas.d.ts +0 -1125
  20. package/lib/schemas.js +0 -307
  21. package/lib/types.d.ts +0 -118
  22. package/lib/types.js +0 -2
  23. package/lib/userSdk/chat.d.ts +0 -57
  24. package/lib/userSdk/chat.js +0 -98
  25. package/lib/userSdk/external.d.ts +0 -34
  26. package/lib/userSdk/external.js +0 -71
  27. package/lib/userSdk/index.d.ts +0 -2
  28. package/lib/userSdk/index.js +0 -27
  29. package/lib/userSdk/patients.d.ts +0 -24
  30. package/lib/userSdk/patients.js +0 -46
  31. package/lib/userSdk/schedule.d.ts +0 -44
  32. package/lib/userSdk/schedule.js +0 -76
  33. package/lib/userSdk/specialties.d.ts +0 -7
  34. package/lib/userSdk/specialties.js +0 -19
  35. package/lib/userSdk/videoVisit.d.ts +0 -111
  36. package/lib/userSdk/videoVisit.js +0 -147
  37. package/lib/utils.d.ts +0 -4
  38. package/lib/utils.js +0 -27
  39. package/lib/webhook/index.d.ts +0 -2
  40. package/lib/webhook/index.js +0 -55
  41. package/lib/webhook/responses.d.ts +0 -35
  42. package/lib/webhook/responses.js +0 -42
  43. package/lib/webhook/token.d.ts +0 -2
  44. package/lib/webhook/token.js +0 -23
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBaseSdk = void 0;
4
- const zod_1 = require("zod");
5
- const request_1 = require("../request");
6
- const validation_1 = require("../request/validation");
7
- const schemas_1 = require("../schemas");
8
- const utils_1 = require("../utils");
9
- const diagnostica_1 = require("./diagnostica");
10
- const user_1 = require("./user");
11
- const getBaseSdk = async (url, credentials) => {
12
- const makeRequest = await request_1.getRequestFactory(url, credentials);
13
- const diagnosticaMethods = diagnostica_1.getDiagnosticaMethods(makeRequest);
14
- const userMethods = user_1.getUserMethods(makeRequest, url, credentials);
15
- const baseSdk = {
16
- ...diagnosticaMethods,
17
- ...userMethods,
18
- getProfessional: validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.professional, async (professionalId) => {
19
- const path = `/professional/${professionalId}`;
20
- const response = await makeRequest('GET', path);
21
- const raw = response.data;
22
- return {
23
- id: raw.professional_id,
24
- firstName: raw.name,
25
- lastName: raw.lastname,
26
- birthdate: utils_1.parseDate(raw.birthdate),
27
- gender: raw.gender.toLowerCase(),
28
- email: raw.email,
29
- phone: raw.phone,
30
- logoUrl: raw.image,
31
- matriculation: raw.matriculation,
32
- specialties: raw.specialties.map((s) => ({
33
- id: s.specialty_id,
34
- description: s.specialty,
35
- })),
36
- degree: raw.degree,
37
- languages: raw.languages.map((l) => l.languages),
38
- resume: {
39
- link: raw.resume_link,
40
- brief: raw.resume_brief,
41
- },
42
- };
43
- }),
44
- getAvailableScheduleClinics: validation_1.validateFunction(zod_1.tuple([]), schemas_1.doc24Schemas.availableScheduleClinics, async () => {
45
- const path = `/schedule/clinics`;
46
- const response = await makeRequest('GET', path);
47
- const mapSpeciality = (s) => ({
48
- id: s.id_especialidad,
49
- description: s.especialidad,
50
- });
51
- const mapSpecialityER = (s) => ({
52
- id: s.specialty_id,
53
- description: s.specialty,
54
- });
55
- const mapped = {
56
- specialties: response.data.specialties.map(mapSpeciality),
57
- specialtiesER: response.data.specialties_er.map(mapSpecialityER),
58
- professionals: response.data.professionals.map((p) => ({
59
- id: p.id_profesional,
60
- fullName: p.denominacion,
61
- clinicId: p.id_consultorio,
62
- specialties: p.especialidades.map(mapSpeciality),
63
- })),
64
- };
65
- return mapped;
66
- }),
67
- };
68
- return baseSdk;
69
- };
70
- exports.getBaseSdk = getBaseSdk;
@@ -1,41 +0,0 @@
1
- import { RequestMaker } from '../request';
2
- import { Doc24 } from '../types';
3
- export declare const getUserMethods: (makeRequest: RequestMaker, url: string, credentials: Doc24.SdkCredentials) => {
4
- declareUser: (user: {
5
- firstName: string;
6
- lastName: string;
7
- identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
8
- identificationValue: string;
9
- gender: "m" | "f";
10
- phone: string;
11
- email: string;
12
- countryId: string;
13
- birthdate: Date;
14
- }) => Promise<any>;
15
- getUserInstance: (...params: any) => Promise<any>;
16
- enroll: (...params: any) => Promise<void>;
17
- getConverageInfo: (identificationValue: string) => Promise<{
18
- firstName: string | null;
19
- lastName: string | null;
20
- gender: "m" | "f";
21
- email: string | null;
22
- birthdate: Date;
23
- identificationNumber: string;
24
- plan: string | null;
25
- financerId: number | null;
26
- defaultAffiliationId: number | null;
27
- credentialNumber: string | null;
28
- financerPlanId: number | null;
29
- brand: number | null;
30
- holderIdentificationNumber: string | null;
31
- copaymentValue: number | null;
32
- mobilePhone: string | null;
33
- company: string | null;
34
- dischargeDate: Date | null;
35
- leavingDate: Date | null;
36
- identificacion_tributaria: string | null;
37
- deregistrationDate: Date | null;
38
- authorizationCode: string | null;
39
- authorizationCodeExpiration: Date | null;
40
- } | null>;
41
- };
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserMethods = void 0;
4
- const date_fns_1 = require("date-fns");
5
- const zod_1 = require("zod");
6
- const validation_1 = require("../request/validation");
7
- const schemas_1 = require("../schemas");
8
- const userSdk_1 = require("../userSdk");
9
- const utils_1 = require("../utils");
10
- const getUserMethods = (makeRequest, url, credentials) => {
11
- const getUserId = async (user) => {
12
- const mappedUser = {
13
- lastname: user.lastName,
14
- firstname: user.firstName,
15
- identification_type: utils_1.getIndetificationTypeId(user.identificationType),
16
- identification_value: user.identificationValue,
17
- birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
18
- gender: user.gender.toUpperCase(),
19
- phone: user.phone,
20
- email: user.email,
21
- country_id: user.countryId,
22
- };
23
- const response = await makeRequest('POST', '/user', {
24
- user_data: mappedUser,
25
- });
26
- return response.data.user_id;
27
- };
28
- const getConverageInfo = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, async (identificationValue) => {
29
- const path = `/info-coverage/${identificationValue}`;
30
- const response = await makeRequest('GET', path);
31
- const raw = response.data.info;
32
- const mappedCoverageInfo = {
33
- financerId: raw.id_financiador,
34
- defaultAffiliationId: raw.id_afiliacion_default,
35
- plan: raw.plan,
36
- identificationNumber: raw.nro_documento,
37
- credentialNumber: raw.nro_credencial,
38
- lastName: raw.apellido,
39
- firstName: raw.nombre,
40
- birthdate: utils_1.parseDate(raw.fecha_nacimiento),
41
- financerPlanId: raw.id_financiador_plan,
42
- gender: raw.sexo.toLowerCase(),
43
- brand: raw.brand,
44
- holderIdentificationNumber: raw.nro_documento_titular,
45
- copaymentValue: raw.valor_copago,
46
- mobilePhone: raw.telefono_movil,
47
- company: raw.empresa,
48
- email: raw.email,
49
- dischargeDate: raw.fecha_alta ? utils_1.parseDateTime(raw.fecha_alta) : null,
50
- leavingDate: raw.fecha_baja ? utils_1.parseDateTime(raw.fecha_baja) : null,
51
- identificacion_tributaria: raw.identificacion_tributaria,
52
- deregistrationDate: raw.fecha_baja_padron
53
- ? utils_1.parseDateTime(raw.fecha_baja_padron)
54
- : null,
55
- authorizationCode: raw.codigo_autorizacion,
56
- authorizationCodeExpiration: raw.codigo_autorizacion_vencimiento
57
- ? utils_1.parseDateTime(raw.codigo_autorizacion_vencimiento)
58
- : null,
59
- };
60
- return mappedCoverageInfo;
61
- });
62
- return {
63
- declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
64
- getUserInstance: validation_1.validateFunction(zod_1.tuple([zod_1.union([schemas_1.doc24Schemas.user, zod_1.number()])]),
65
- // TODO: validate?
66
- zod_1.any(), async (user) => {
67
- const userId = typeof user === 'number' ? user : await getUserId(user);
68
- return userSdk_1.userSdk(url, credentials, userId);
69
- }),
70
- enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), async (params) => {
71
- const path = `/enrollment`;
72
- await makeRequest('POST', path, {
73
- user_data: {
74
- firstname: params.firstName,
75
- lastname: params.lastName,
76
- gender: params.gender.toUpperCase(),
77
- identification_number: params.identificationNumber,
78
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
79
- email: params.email,
80
- plan: params.plan,
81
- start_date: date_fns_1.format(params.startDate, 'yyyy-MM-dd'),
82
- },
83
- });
84
- }),
85
- getConverageInfo,
86
- };
87
- };
88
- exports.getUserMethods = getUserMethods;
package/lib/index.d.ts DELETED
@@ -1,159 +0,0 @@
1
- import { Doc24 } from './types';
2
- export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
3
- getRequestHandler: (params: {
4
- credentials: Doc24.SdkCredentials;
5
- eventHandlers: Doc24.Webhook.Events;
6
- baseAddress: string;
7
- }) => Promise<Doc24.Webhook.Handler>;
8
- declareUser: (user: {
9
- firstName: string;
10
- lastName: string;
11
- identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
12
- identificationValue: string;
13
- gender: "m" | "f";
14
- phone: string;
15
- email: string;
16
- countryId: string;
17
- birthdate: Date;
18
- }) => Promise<number>;
19
- getUserInstance: (user: number | {
20
- firstName: string;
21
- lastName: string;
22
- identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
23
- identificationValue: string;
24
- gender: "m" | "f";
25
- phone: string;
26
- email: string;
27
- countryId: string;
28
- birthdate: Date;
29
- }) => Promise<Doc24.UserSdk>;
30
- getProfessional: (professionalId: number) => Promise<{
31
- id: number;
32
- logoUrl: string;
33
- firstName: string;
34
- lastName: string;
35
- gender: "m" | "f";
36
- phone: string | null;
37
- email: string;
38
- birthdate: Date;
39
- specialties: {
40
- id: number;
41
- description: string;
42
- }[];
43
- matriculation: {
44
- number: string;
45
- type: string;
46
- }[];
47
- degree: string;
48
- languages: string[];
49
- resume: {
50
- link: string;
51
- brief: string;
52
- };
53
- }>;
54
- getAvailableScheduleClinics: () => Promise<{
55
- specialties: {
56
- id: number;
57
- description: string;
58
- }[];
59
- specialtiesER: {
60
- id: number;
61
- description: string;
62
- }[];
63
- professionals: {
64
- id: number;
65
- fullName: string;
66
- clinicId: number;
67
- specialties: {
68
- id: number;
69
- description: string;
70
- }[];
71
- }[];
72
- }>;
73
- enroll: (params: {
74
- firstName: string;
75
- lastName: string;
76
- gender: "m" | "f";
77
- email: string;
78
- birthdate: Date;
79
- startDate: Date;
80
- identificationNumber: string;
81
- plan: string;
82
- }) => Promise<void>;
83
- getConverageInfo: (identificationValue: string) => Promise<{
84
- firstName: string | null;
85
- lastName: string | null;
86
- gender: "m" | "f";
87
- email: string | null;
88
- birthdate: Date;
89
- identificationNumber: string;
90
- plan: string | null;
91
- financerId: number | null;
92
- defaultAffiliationId: number | null;
93
- credentialNumber: string | null;
94
- financerPlanId: number | null;
95
- brand: number | null;
96
- holderIdentificationNumber: string | null;
97
- copaymentValue: number | null;
98
- mobilePhone: string | null;
99
- company: string | null;
100
- dischargeDate: Date | null;
101
- leavingDate: Date | null;
102
- identificacion_tributaria: string | null;
103
- deregistrationDate: Date | null;
104
- authorizationCode: string | null;
105
- authorizationCodeExpiration: Date | null;
106
- } | null>;
107
- getDiagnosticaHistory: (patient: {
108
- identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
109
- identificationValue: string;
110
- gender: "m" | "f";
111
- }, from: Date, to: Date) => Promise<{
112
- date: Date;
113
- location: string;
114
- exams: string[];
115
- deepLink: string;
116
- }[]>;
117
- getDiagnosticaDeepLink: (kiosk: string, user: {
118
- language: string;
119
- firstName: string;
120
- lastName: string;
121
- birthday: Date;
122
- identificationType: "dni";
123
- identificationValue: string;
124
- gender: "m" | "f";
125
- phone: string;
126
- email: string;
127
- }, patient: {
128
- firstName: string;
129
- lastName: string;
130
- birthday: Date;
131
- identificationType: "dni";
132
- identificationValue: string;
133
- gender: "m" | "f";
134
- }) => Promise<{
135
- forwardingRequired: true;
136
- deepLink: string;
137
- } | {
138
- forwardingRequired: false;
139
- }>;
140
- getDiagnosticaAccess: (kiosk: string, user: {
141
- language: string;
142
- firstName: string;
143
- lastName: string;
144
- birthday: Date;
145
- identificationType: "dni";
146
- identificationValue: string;
147
- gender: "m" | "f";
148
- phone: string;
149
- email: string;
150
- }, patient: {
151
- firstName: string;
152
- lastName: string;
153
- birthday: Date;
154
- identificationType: "dni";
155
- identificationValue: string;
156
- gender: "m" | "f";
157
- }) => Promise<void>;
158
- }>;
159
- export type { Doc24 } from './types';
package/lib/index.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doc24Sdk = void 0;
4
- const webhook_1 = require("./webhook");
5
- const baseSdk_1 = require("./baseSdk");
6
- const request_1 = require("./request");
7
- const doc24Sdk = async (params) => {
8
- const baseSdk = await baseSdk_1.getBaseSdk(params.url, params.credentials);
9
- const makeRequest = await request_1.getRequestFactory(params.url, params.credentials);
10
- return {
11
- ...baseSdk,
12
- getRequestHandler: async (params) => {
13
- await makeRequest('PUT', '/webhook', {
14
- url: params.baseAddress,
15
- issuer: params.credentials.iss,
16
- secret: params.credentials.key,
17
- });
18
- return webhook_1.getRequestHandler(params.credentials, baseSdk, params.eventHandlers);
19
- },
20
- };
21
- };
22
- exports.doc24Sdk = doc24Sdk;
@@ -1,3 +0,0 @@
1
- import { Doc24 } from '../types';
2
- export declare const getRequestFactory: (url: string, credentials: Doc24.SdkCredentials, userId?: number | undefined) => Promise<RequestMaker>;
3
- export declare type RequestMaker = (method: 'POST' | 'GET' | 'PUT' | 'DELETE', path: string, body?: object) => Promise<any>;
@@ -1,26 +0,0 @@
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.getRequestFactory = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const token_1 = require("./token");
9
- const debug_1 = __importDefault(require("debug"));
10
- const debugRequest = debug_1.default('doc24Sdk:request');
11
- const getRequestFactory = async (url, credentials, userId) => {
12
- const makeRequest = async (method, path, body) => {
13
- const token = await token_1.getToken(credentials, body ? JSON.stringify(body) : undefined, userId);
14
- const fullUrl = url + path;
15
- const result = await axios_1.default({
16
- method,
17
- url: fullUrl,
18
- headers: { Authentication: token },
19
- data: body,
20
- });
21
- debugRequest({ url: fullUrl, response: result.data, body });
22
- return result.data;
23
- };
24
- return makeRequest;
25
- };
26
- exports.getRequestFactory = getRequestFactory;
@@ -1,2 +0,0 @@
1
- import { Doc24 } from '../types';
2
- export declare const getToken: (credentials: Doc24.SdkCredentials, bodyAsJson?: string | undefined, userId?: number | undefined) => Promise<string>;
@@ -1,34 +0,0 @@
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.getToken = void 0;
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- const crypto_1 = __importDefault(require("crypto"));
9
- const tokenLifeTimeInSeconds = 500 * 60;
10
- const getToken = async (credentials, bodyAsJson, userId) => {
11
- const tokenData = {
12
- msg_sig: createSignature(credentials.key, bodyAsJson),
13
- user_id: userId,
14
- };
15
- const encodedToken = await makeJwt(tokenData, credentials.key, {
16
- expiresIn: tokenLifeTimeInSeconds,
17
- issuer: credentials.iss,
18
- });
19
- return encodedToken;
20
- };
21
- exports.getToken = getToken;
22
- const makeJwt = (payload, key, options = {}) => new Promise((resolve, reject) => jsonwebtoken_1.default.sign(payload, key, options, (err, token) => {
23
- if (err || !token)
24
- return reject(err);
25
- resolve(token);
26
- }));
27
- const createSignature = (secret, bodyAsJson) => {
28
- //TODO: verify this, seems wrong
29
- const realSecret = bodyAsJson ? secret : 'true';
30
- const realBody = bodyAsJson !== null && bodyAsJson !== void 0 ? bodyAsJson : secret;
31
- const hmac = crypto_1.default.createHmac('sha256', realSecret);
32
- hmac.update(realBody);
33
- return hmac.digest('base64');
34
- };
@@ -1,10 +0,0 @@
1
- import { ZodError, ZodType } from 'zod';
2
- export declare class ParametersValidationError extends Error {
3
- details: ZodError;
4
- constructor(details: ZodError);
5
- }
6
- export declare class ResponseValidationError extends Error {
7
- details: ZodError;
8
- constructor(details: ZodError);
9
- }
10
- export declare const validateFunction: <TParams extends unknown[], TResponse>(inValidation: ZodType<TParams, import("zod").ZodTypeDef, TParams>, outValidation: ZodType<TResponse, import("zod").ZodTypeDef, TResponse>, fn: (...params: TParams) => Promise<TResponse>) => (...params: TParams) => Promise<TResponse>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateFunction = exports.ResponseValidationError = exports.ParametersValidationError = void 0;
4
- class ParametersValidationError extends Error {
5
- constructor(details) {
6
- super('Invalid parameters supplied to function');
7
- this.details = details;
8
- }
9
- }
10
- exports.ParametersValidationError = ParametersValidationError;
11
- class ResponseValidationError extends Error {
12
- constructor(details) {
13
- super('Invalid response returned from function');
14
- this.details = details;
15
- }
16
- }
17
- exports.ResponseValidationError = ResponseValidationError;
18
- const validateFunction = (inValidation, outValidation, fn) => async (...params) => {
19
- const validationResult = inValidation.safeParse(params);
20
- if (!validationResult.success)
21
- throw new ParametersValidationError(validationResult.error);
22
- const out = await fn(...validationResult.data);
23
- const responseValidationResult = outValidation.safeParse(out);
24
- if (!responseValidationResult.success)
25
- throw new ResponseValidationError(responseValidationResult.error);
26
- return responseValidationResult.data;
27
- };
28
- exports.validateFunction = validateFunction;