@integraciones_doc24/sdk 0.39.5 → 0.39.7

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 (43) hide show
  1. package/lib/baseSdk/diagnostica.d.ts +54 -0
  2. package/lib/baseSdk/diagnostica.js +82 -0
  3. package/lib/baseSdk/external.d.ts +177 -0
  4. package/lib/baseSdk/external.js +96 -0
  5. package/lib/baseSdk/index.d.ts +2 -0
  6. package/lib/baseSdk/index.js +74 -0
  7. package/lib/baseSdk/user.d.ts +91 -0
  8. package/lib/baseSdk/user.js +136 -0
  9. package/lib/index.d.ts +365 -0
  10. package/lib/index.js +22 -0
  11. package/lib/request/index.d.ts +3 -0
  12. package/lib/request/index.js +26 -0
  13. package/lib/request/token.d.ts +2 -0
  14. package/lib/request/token.js +34 -0
  15. package/lib/request/validation.d.ts +10 -0
  16. package/lib/request/validation.js +28 -0
  17. package/lib/schemas.d.ts +1816 -0
  18. package/lib/schemas.js +420 -0
  19. package/lib/types.d.ts +146 -0
  20. package/lib/types.js +2 -0
  21. package/lib/userSdk/chat.d.ts +57 -0
  22. package/lib/userSdk/chat.js +98 -0
  23. package/lib/userSdk/external.d.ts +34 -0
  24. package/lib/userSdk/external.js +72 -0
  25. package/lib/userSdk/index.d.ts +2 -0
  26. package/lib/userSdk/index.js +30 -0
  27. package/lib/userSdk/patients.d.ts +38 -0
  28. package/lib/userSdk/patients.js +67 -0
  29. package/lib/userSdk/schedule.d.ts +47 -0
  30. package/lib/userSdk/schedule.js +81 -0
  31. package/lib/userSdk/specialties.d.ts +7 -0
  32. package/lib/userSdk/specialties.js +19 -0
  33. package/lib/userSdk/videoVisit.d.ts +113 -0
  34. package/lib/userSdk/videoVisit.js +154 -0
  35. package/lib/utils.d.ts +2 -0
  36. package/lib/utils.js +16 -0
  37. package/lib/webhook/index.d.ts +2 -0
  38. package/lib/webhook/index.js +56 -0
  39. package/lib/webhook/responses.d.ts +35 -0
  40. package/lib/webhook/responses.js +42 -0
  41. package/lib/webhook/token.d.ts +2 -0
  42. package/lib/webhook/token.js +23 -0
  43. package/package.json +1 -1
@@ -0,0 +1,136 @@
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 declareUser = async ({ user, channel, code, }) => {
12
+ var _a;
13
+ const path = '/user';
14
+ const mappedUser = {
15
+ lastname: user.lastName,
16
+ firstname: user.firstName,
17
+ identification_type: user.identificationType,
18
+ identification_value: user.identificationValue,
19
+ birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
20
+ gender: (_a = user.gender) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
21
+ phone: user.phone,
22
+ email: user.email,
23
+ country_id: user.countryId,
24
+ };
25
+ const parsedChannel = channel ? parseInt(channel) : channel;
26
+ const response = await makeRequest('POST', path, {
27
+ user_data: mappedUser,
28
+ channel: parsedChannel,
29
+ code,
30
+ });
31
+ const data = response.data;
32
+ if (data.ask_code)
33
+ return { askCode: true, userInfo: data.user_info };
34
+ return {
35
+ askCode: false,
36
+ userId: response.data.user_id,
37
+ patientId: response.data.patient_id,
38
+ };
39
+ };
40
+ const getUserId = async (user) => {
41
+ var _a;
42
+ const path = '/search-user';
43
+ const mappedUser = {
44
+ lastname: user.lastName,
45
+ firstname: user.firstName,
46
+ identification_type: user.identificationType,
47
+ identification_value: user.identificationValue,
48
+ birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
49
+ gender: (_a = user.gender) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
50
+ phone: user.phone,
51
+ email: user.email,
52
+ country_id: user.countryId,
53
+ };
54
+ const response = await makeRequest('POST', path, {
55
+ user_data: mappedUser,
56
+ });
57
+ return response.data.user_id;
58
+ };
59
+ const sendVerificationCode = async (params) => {
60
+ const path = '/send-verification-code';
61
+ const mappedParams = {
62
+ identification_type: params.identificationType,
63
+ identification_value: params.identificationValue,
64
+ channel: parseInt(params.channel),
65
+ };
66
+ await makeRequest('POST', path, mappedParams);
67
+ };
68
+ const getUserInstance = async (user) => {
69
+ const userId = typeof user === 'number' ? user : await getUserId(user);
70
+ return userSdk_1.userSdk(url, credentials, userId);
71
+ };
72
+ const enroll = async (params) => {
73
+ var _a;
74
+ const path = `/enrollment`;
75
+ const mappedUser = {
76
+ firstname: params.firstName,
77
+ lastname: params.lastName,
78
+ gender: (_a = params.gender) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
79
+ identification_number: params.identificationNumber,
80
+ birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
81
+ email: params.email,
82
+ plan: params.plan,
83
+ start_date: date_fns_1.format(params.startDate, 'yyyy-MM-dd'),
84
+ };
85
+ await makeRequest('POST', path, {
86
+ user_data: mappedUser,
87
+ });
88
+ };
89
+ const getCoverageInfo = async (identificationValue) => {
90
+ const path = `/info-coverage/${identificationValue}`;
91
+ const response = await makeRequest('GET', path);
92
+ const raw = response.data.info;
93
+ if (!raw)
94
+ return null;
95
+ const mappedCoverageInfo = {
96
+ financerId: raw.id_financiador,
97
+ defaultAffiliationId: raw.id_afiliacion_default,
98
+ plan: raw.plan,
99
+ identificationNumber: raw.nro_documento,
100
+ credentialNumber: raw.nro_credencial,
101
+ lastName: raw.apellido,
102
+ firstName: raw.nombre,
103
+ birthdate: utils_1.parseDate(raw.fecha_nacimiento),
104
+ financerPlanId: raw.id_financiador_plan,
105
+ gender: raw.sexo.toLowerCase(),
106
+ brand: raw.brand,
107
+ holderIdentificationNumber: raw.nro_documento_titular,
108
+ copaymentValue: raw.valor_copago,
109
+ mobilePhone: raw.telefono_movil,
110
+ company: raw.empresa,
111
+ email: raw.email,
112
+ dischargeDate: raw.fecha_alta ? utils_1.parseDateTime(raw.fecha_alta) : null,
113
+ leavingDate: raw.fecha_baja ? utils_1.parseDateTime(raw.fecha_baja) : null,
114
+ identificacion_tributaria: raw.identificacion_tributaria,
115
+ deregistrationDate: raw.fecha_baja_padron
116
+ ? utils_1.parseDateTime(raw.fecha_baja_padron)
117
+ : null,
118
+ authorizationCode: raw.codigo_autorizacion,
119
+ authorizationCodeExpiration: raw.codigo_autorizacion_vencimiento
120
+ ? utils_1.parseDateTime(raw.codigo_autorizacion_vencimiento)
121
+ : null,
122
+ };
123
+ return mappedCoverageInfo;
124
+ };
125
+ return {
126
+ declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.declareUserParams]), schemas_1.doc24Schemas.declareUserResponse, declareUser),
127
+ getUserId: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
128
+ sendVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.sendVerificationCodeParams]), zod_1.void(), sendVerificationCode),
129
+ getUserInstance: validation_1.validateFunction(zod_1.tuple([zod_1.union([schemas_1.doc24Schemas.user, zod_1.number()])]),
130
+ // TODO: validate?
131
+ zod_1.any(), getUserInstance),
132
+ enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), enroll),
133
+ getCoverageInfo: validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, getCoverageInfo),
134
+ };
135
+ };
136
+ exports.getUserMethods = getUserMethods;
package/lib/index.d.ts ADDED
@@ -0,0 +1,365 @@
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: (params: {
9
+ user: {
10
+ identificationType?: number | undefined;
11
+ identificationValue?: string | undefined;
12
+ gender?: "m" | "f" | "o" | undefined;
13
+ phone?: string | undefined;
14
+ firstName: string;
15
+ lastName: string;
16
+ countryId: string;
17
+ birthdate: Date;
18
+ email: string;
19
+ };
20
+ } & {
21
+ code?: string | undefined;
22
+ channel?: "1" | "2" | undefined;
23
+ }) => Promise<{
24
+ askCode: true;
25
+ userInfo: {
26
+ phone: string;
27
+ email: string;
28
+ };
29
+ } | {
30
+ patientId: number | null;
31
+ askCode: false;
32
+ userId: number;
33
+ }>;
34
+ getUserId: (user: {
35
+ identificationType?: number | undefined;
36
+ identificationValue?: string | undefined;
37
+ gender?: "m" | "f" | "o" | undefined;
38
+ phone?: string | undefined;
39
+ firstName: string;
40
+ lastName: string;
41
+ countryId: string;
42
+ birthdate: Date;
43
+ email: string;
44
+ }) => Promise<number>;
45
+ getUserInstance: (user: number | {
46
+ identificationType?: number | undefined;
47
+ identificationValue?: string | undefined;
48
+ gender?: "m" | "f" | "o" | undefined;
49
+ phone?: string | undefined;
50
+ firstName: string;
51
+ lastName: string;
52
+ countryId: string;
53
+ birthdate: Date;
54
+ email: string;
55
+ }) => Promise<Doc24.UserSdk>;
56
+ getProfessional: (professionalId: number) => Promise<{
57
+ gender?: "m" | "f" | "o" | undefined;
58
+ consultation_value?: string | null | undefined;
59
+ firstName: string;
60
+ lastName: string;
61
+ birthdate: Date;
62
+ phone: string | null;
63
+ email: string;
64
+ id: number;
65
+ logoUrl: string;
66
+ specialties: {
67
+ id: number;
68
+ description: string;
69
+ }[];
70
+ matriculation: {
71
+ number: string;
72
+ type: string;
73
+ }[];
74
+ degree: string;
75
+ languages: string[];
76
+ resume: {
77
+ link: string;
78
+ brief: string;
79
+ };
80
+ }>;
81
+ getAvailableScheduleClinics: () => Promise<{
82
+ specialties: {
83
+ id: number;
84
+ description: string;
85
+ }[];
86
+ specialtiesER: {
87
+ id: number;
88
+ description: string;
89
+ }[];
90
+ professionals: {
91
+ id: number;
92
+ fullName: string;
93
+ clinicId: number;
94
+ specialties: {
95
+ id: number;
96
+ description: string;
97
+ }[];
98
+ }[];
99
+ }>;
100
+ enroll: (params: {
101
+ gender?: "m" | "f" | "o" | undefined;
102
+ firstName: string;
103
+ lastName: string;
104
+ birthdate: Date;
105
+ email: string;
106
+ identificationNumber: string;
107
+ startDate: Date;
108
+ plan: string;
109
+ }) => Promise<void>;
110
+ getCoverageInfo: (identificationValue: string) => Promise<{
111
+ gender?: "m" | "f" | "o" | undefined;
112
+ firstName: string | null;
113
+ lastName: string | null;
114
+ birthdate: Date;
115
+ email: string | null;
116
+ identificationNumber: string;
117
+ plan: string | null;
118
+ financerId: number | null;
119
+ defaultAffiliationId: number | null;
120
+ credentialNumber: string | null;
121
+ financerPlanId: number | null;
122
+ brand: number | null;
123
+ holderIdentificationNumber: string | null;
124
+ copaymentValue: number | null;
125
+ mobilePhone: string | null;
126
+ company: string | null;
127
+ dischargeDate: Date | null;
128
+ leavingDate: Date | null;
129
+ identificacion_tributaria: string | null;
130
+ deregistrationDate: Date | null;
131
+ authorizationCode: string | null;
132
+ authorizationCodeExpiration: Date | null;
133
+ } | null>;
134
+ sendVerificationCode: (params: {
135
+ identificationType: number;
136
+ identificationValue: string;
137
+ channel: "1" | "2";
138
+ }) => Promise<void>;
139
+ getDiagnosticaHistory: (patient: {
140
+ gender?: "m" | "f" | "o" | undefined;
141
+ identificationType: "DNI";
142
+ identificationValue: string;
143
+ }, from: Date, to: Date) => Promise<{
144
+ date: Date;
145
+ location: string;
146
+ exams: string[];
147
+ deepLink: string;
148
+ }[]>;
149
+ getDiagnosticaDeepLink: (kiosk: string, user: {
150
+ gender?: "m" | "f" | "o" | undefined;
151
+ firstName: string;
152
+ lastName: string;
153
+ identificationType: "DNI";
154
+ identificationValue: string;
155
+ phone: string;
156
+ email: string;
157
+ language: string;
158
+ birthday: Date;
159
+ }, patient: {
160
+ gender?: "m" | "f" | "o" | undefined;
161
+ firstName: string;
162
+ lastName: string;
163
+ identificationType: "DNI";
164
+ identificationValue: string;
165
+ birthday: Date;
166
+ }) => Promise<{
167
+ forwardingRequired: true;
168
+ deepLink: string;
169
+ } | {
170
+ forwardingRequired: false;
171
+ }>;
172
+ getDiagnosticaAccess: (kiosk: string, user: {
173
+ gender?: "m" | "f" | "o" | undefined;
174
+ firstName: string;
175
+ lastName: string;
176
+ identificationType: "DNI";
177
+ identificationValue: string;
178
+ phone: string;
179
+ email: string;
180
+ language: string;
181
+ birthday: Date;
182
+ }, patient: {
183
+ gender?: "m" | "f" | "o" | undefined;
184
+ firstName: string;
185
+ lastName: string;
186
+ identificationType: "DNI";
187
+ identificationValue: string;
188
+ birthday: Date;
189
+ }) => Promise<void>;
190
+ externalLogin: (params: {
191
+ user: string;
192
+ password: string;
193
+ }) => Promise<{
194
+ gender?: "m" | "f" | "o" | undefined;
195
+ firstName: string;
196
+ lastName: string;
197
+ countryId: string;
198
+ phone: string;
199
+ email: string;
200
+ birthday: Date;
201
+ identificationNumber: string;
202
+ }>;
203
+ preExternalEnrollment: (params: ({
204
+ birthdate: Date;
205
+ identificationNumber: string;
206
+ } & {
207
+ phone: string;
208
+ email: string;
209
+ }) | ({
210
+ birthdate: Date;
211
+ identificationNumber: string;
212
+ } & {
213
+ phone?: undefined;
214
+ email: string;
215
+ }) | ({
216
+ birthdate: Date;
217
+ identificationNumber: string;
218
+ } & {
219
+ email?: undefined;
220
+ phone: string;
221
+ })) => Promise<void>;
222
+ externalEnrollment: (params: ({
223
+ birthdate: Date;
224
+ identificationNumber: string;
225
+ } & {
226
+ phone: string;
227
+ email: string;
228
+ } & {
229
+ password: string;
230
+ } & {
231
+ emailCode: string;
232
+ phoneCode: string;
233
+ }) | ({
234
+ birthdate: Date;
235
+ identificationNumber: string;
236
+ } & {
237
+ phone: string;
238
+ email: string;
239
+ } & {
240
+ password: string;
241
+ } & {
242
+ phoneCode?: undefined;
243
+ emailCode: string;
244
+ }) | ({
245
+ birthdate: Date;
246
+ identificationNumber: string;
247
+ } & {
248
+ phone: string;
249
+ email: string;
250
+ } & {
251
+ password: string;
252
+ } & {
253
+ emailCode?: undefined;
254
+ phoneCode: string;
255
+ }) | ({
256
+ birthdate: Date;
257
+ identificationNumber: string;
258
+ } & {
259
+ phone?: undefined;
260
+ email: string;
261
+ } & {
262
+ password: string;
263
+ } & {
264
+ emailCode: string;
265
+ phoneCode: string;
266
+ }) | ({
267
+ birthdate: Date;
268
+ identificationNumber: string;
269
+ } & {
270
+ phone?: undefined;
271
+ email: string;
272
+ } & {
273
+ password: string;
274
+ } & {
275
+ phoneCode?: undefined;
276
+ emailCode: string;
277
+ }) | ({
278
+ birthdate: Date;
279
+ identificationNumber: string;
280
+ } & {
281
+ phone?: undefined;
282
+ email: string;
283
+ } & {
284
+ password: string;
285
+ } & {
286
+ emailCode?: undefined;
287
+ phoneCode: string;
288
+ }) | ({
289
+ birthdate: Date;
290
+ identificationNumber: string;
291
+ } & {
292
+ email?: undefined;
293
+ phone: string;
294
+ } & {
295
+ password: string;
296
+ } & {
297
+ emailCode: string;
298
+ phoneCode: string;
299
+ }) | ({
300
+ birthdate: Date;
301
+ identificationNumber: string;
302
+ } & {
303
+ email?: undefined;
304
+ phone: string;
305
+ } & {
306
+ password: string;
307
+ } & {
308
+ phoneCode?: undefined;
309
+ emailCode: string;
310
+ }) | ({
311
+ birthdate: Date;
312
+ identificationNumber: string;
313
+ } & {
314
+ email?: undefined;
315
+ phone: string;
316
+ } & {
317
+ password: string;
318
+ } & {
319
+ emailCode?: undefined;
320
+ phoneCode: string;
321
+ })) => Promise<{
322
+ gender?: "m" | "f" | "o" | undefined;
323
+ firstName: string;
324
+ lastName: string;
325
+ countryId: string;
326
+ phone: string;
327
+ email: string;
328
+ birthday: Date;
329
+ identificationNumber: string;
330
+ }>;
331
+ sendExternalVerificationCode: (params: {
332
+ birthdate: Date;
333
+ channel: "1" | "2";
334
+ identificationNumber: string;
335
+ }) => Promise<void>;
336
+ verifyExternalVerificationCode: (params: {
337
+ code: string;
338
+ birthdate: Date;
339
+ channel: "1" | "2";
340
+ identificationNumber: string;
341
+ }) => Promise<any>;
342
+ externalResetPassword: (params: ({
343
+ birthdate: Date;
344
+ password: string;
345
+ identificationNumber: string;
346
+ } & {
347
+ emailCode: string;
348
+ phoneCode: string;
349
+ }) | ({
350
+ birthdate: Date;
351
+ password: string;
352
+ identificationNumber: string;
353
+ } & {
354
+ phoneCode?: undefined;
355
+ emailCode: string;
356
+ }) | ({
357
+ birthdate: Date;
358
+ password: string;
359
+ identificationNumber: string;
360
+ } & {
361
+ emailCode?: undefined;
362
+ phoneCode: string;
363
+ })) => Promise<any>;
364
+ }>;
365
+ export type { Doc24 } from './types';
package/lib/index.js ADDED
@@ -0,0 +1,22 @@
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;
@@ -0,0 +1,3 @@
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>;
@@ -0,0 +1,26 @@
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;
@@ -0,0 +1,2 @@
1
+ import { Doc24 } from '../types';
2
+ export declare const getToken: (credentials: Doc24.SdkCredentials, bodyAsJson?: string | undefined, userId?: number | undefined) => Promise<string>;
@@ -0,0 +1,34 @@
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
+ };
@@ -0,0 +1,10 @@
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>;
@@ -0,0 +1,28 @@
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;