pangea-server 3.3.172 → 3.3.174
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/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/mercado-pago.helpers.d.ts +35 -0
- package/dist/helpers/mercado-pago.helpers.js +73 -0
- package/dist/router/app-router.class.js +6 -3
- package/dist/router/call-controller.d.ts +2 -2
- package/dist/router/call-controller.js +4 -2
- package/dist/router/router.types.d.ts +4 -4
- package/package.json +3 -1
package/dist/helpers/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './html-sanitize.helpers';
|
|
|
10
10
|
export * from './instagram.helpers';
|
|
11
11
|
export * from './job.helpers';
|
|
12
12
|
export * from './mailer.helpers';
|
|
13
|
+
export * from './mercado-pago.helpers';
|
|
13
14
|
export * from './multer.helpers';
|
|
14
15
|
export * from './pass.helpers';
|
|
15
16
|
export * from './print.helpers';
|
package/dist/helpers/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./html-sanitize.helpers"), exports);
|
|
|
26
26
|
__exportStar(require("./instagram.helpers"), exports);
|
|
27
27
|
__exportStar(require("./job.helpers"), exports);
|
|
28
28
|
__exportStar(require("./mailer.helpers"), exports);
|
|
29
|
+
__exportStar(require("./mercado-pago.helpers"), exports);
|
|
29
30
|
__exportStar(require("./multer.helpers"), exports);
|
|
30
31
|
__exportStar(require("./pass.helpers"), exports);
|
|
31
32
|
__exportStar(require("./print.helpers"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type CreatePreferenceOptions = {
|
|
2
|
+
title: string;
|
|
3
|
+
description: string;
|
|
4
|
+
currency: string;
|
|
5
|
+
amount: number;
|
|
6
|
+
backUrls: {
|
|
7
|
+
success: string;
|
|
8
|
+
failure: string;
|
|
9
|
+
pending: string;
|
|
10
|
+
};
|
|
11
|
+
notificationUrl: string;
|
|
12
|
+
externalReference: string;
|
|
13
|
+
expiresInMs: number;
|
|
14
|
+
};
|
|
15
|
+
export declare class MercadoPagoApi {
|
|
16
|
+
private __preference;
|
|
17
|
+
private __payment;
|
|
18
|
+
constructor(config: {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
});
|
|
21
|
+
static ValidateWebhookSignature(xRequestId: string | undefined, xSignature: string | undefined, secret: string, dataId: string): void;
|
|
22
|
+
createPreference(options: CreatePreferenceOptions): Promise<{
|
|
23
|
+
id: string | undefined;
|
|
24
|
+
initPoint: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
getPayment(id: string): Promise<{
|
|
27
|
+
id: number | undefined;
|
|
28
|
+
status: string | undefined;
|
|
29
|
+
statusDetail: string | undefined;
|
|
30
|
+
externalReference: string | undefined;
|
|
31
|
+
payerEmail: string | undefined;
|
|
32
|
+
amount: number | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
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.MercadoPagoApi = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const mercadopago_1 = require("mercadopago");
|
|
9
|
+
// helpers
|
|
10
|
+
const helpers_1 = require("../helpers");
|
|
11
|
+
class MercadoPagoApi {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
const client = new mercadopago_1.MercadoPagoConfig({ accessToken: config.accessToken });
|
|
14
|
+
this.__preference = new mercadopago_1.Preference(client);
|
|
15
|
+
this.__payment = new mercadopago_1.Payment(client);
|
|
16
|
+
}
|
|
17
|
+
// class methods
|
|
18
|
+
static ValidateWebhookSignature(xRequestId, xSignature, secret, dataId) {
|
|
19
|
+
if (!xSignature || !xRequestId)
|
|
20
|
+
helpers_1.AppError.ThrowInvalidCredentials();
|
|
21
|
+
let ts = '';
|
|
22
|
+
let hash = '';
|
|
23
|
+
for (const part of xSignature.split(',')) {
|
|
24
|
+
const [key, value = ''] = part.split('=').map((s) => s.trim());
|
|
25
|
+
if (key === 'ts')
|
|
26
|
+
ts = value;
|
|
27
|
+
if (key === 'v1')
|
|
28
|
+
hash = value;
|
|
29
|
+
}
|
|
30
|
+
if (!ts || !hash)
|
|
31
|
+
helpers_1.AppError.ThrowInvalidCredentials();
|
|
32
|
+
const manifest = `id:${dataId.toLowerCase()};request-id:${xRequestId};ts:${ts};`;
|
|
33
|
+
const sha = crypto_1.default.createHmac('sha256', secret).update(manifest).digest('hex');
|
|
34
|
+
if (sha !== hash)
|
|
35
|
+
helpers_1.AppError.ThrowInvalidCredentials();
|
|
36
|
+
}
|
|
37
|
+
// methods
|
|
38
|
+
async createPreference(options) {
|
|
39
|
+
const item = {
|
|
40
|
+
id: options.externalReference,
|
|
41
|
+
title: options.title,
|
|
42
|
+
description: options.description,
|
|
43
|
+
quantity: 1,
|
|
44
|
+
currency_id: options.currency,
|
|
45
|
+
unit_price: options.amount,
|
|
46
|
+
};
|
|
47
|
+
const now = new Date();
|
|
48
|
+
const body = {
|
|
49
|
+
items: [item],
|
|
50
|
+
back_urls: options.backUrls,
|
|
51
|
+
notification_url: options.notificationUrl,
|
|
52
|
+
auto_return: 'approved',
|
|
53
|
+
external_reference: options.externalReference,
|
|
54
|
+
expires: true,
|
|
55
|
+
expiration_date_from: now.toISOString(),
|
|
56
|
+
expiration_date_to: new Date(now.getTime() + options.expiresInMs).toISOString(),
|
|
57
|
+
};
|
|
58
|
+
const res = await this.__preference.create({ body });
|
|
59
|
+
return { id: res.id, initPoint: res.init_point };
|
|
60
|
+
}
|
|
61
|
+
async getPayment(id) {
|
|
62
|
+
const res = await this.__payment.get({ id });
|
|
63
|
+
return {
|
|
64
|
+
id: res.id,
|
|
65
|
+
status: res.status,
|
|
66
|
+
statusDetail: res.status_detail,
|
|
67
|
+
externalReference: res.external_reference,
|
|
68
|
+
payerEmail: res.payer?.email,
|
|
69
|
+
amount: res.transaction_amount,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.MercadoPagoApi = MercadoPagoApi;
|
|
@@ -10,9 +10,12 @@ function getAppRouter(appVersion, authConfig) {
|
|
|
10
10
|
app.use(basePath, this.router);
|
|
11
11
|
}
|
|
12
12
|
setRoute(method, path, validate, ...args) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
13
|
+
const lastArg = args[args.length - 1];
|
|
14
|
+
const options = (typeof lastArg === 'function' ? undefined : lastArg);
|
|
15
|
+
const rest = options ? args.slice(0, -1) : args;
|
|
16
|
+
const middlewares = rest.slice(0, -1);
|
|
17
|
+
const controller = rest[rest.length - 1];
|
|
18
|
+
this.router[method](path, ...middlewares, (0, call_controller_1.callController)(controller, validate, appVersion, authConfig, options));
|
|
16
19
|
}
|
|
17
20
|
get(path, validate, ...args) {
|
|
18
21
|
this.setRoute('get', path, validate, ...args);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseAuth } from '../auth';
|
|
2
2
|
import type { AuthMap, AuthUsers } from '../auth/auth.types';
|
|
3
3
|
import type { RouteValidator, RouteValidate } from '../validator/validator.types';
|
|
4
|
-
import type { Controller, AuthConfig } from './router.types';
|
|
5
|
-
export declare function callController<V extends RouteValidator, AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>, IR extends any>(controller: Controller<V, AM, BA>, validate: RouteValidate<V>, appVersion: string, authConfig: AuthConfig<AM, AU, BA, IR
|
|
4
|
+
import type { Controller, AuthConfig, RouteOptions } from './router.types';
|
|
5
|
+
export declare function callController<V extends RouteValidator, AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>, IR extends any>(controller: Controller<V, AM, BA>, validate: RouteValidate<V>, appVersion: string, authConfig: AuthConfig<AM, AU, BA, IR>, options?: RouteOptions): (req: Req, res: Res) => Promise<void>;
|
|
@@ -11,11 +11,13 @@ const database_1 = require("../database");
|
|
|
11
11
|
const auth_1 = require("../auth");
|
|
12
12
|
// validator
|
|
13
13
|
const validate_request_1 = require("../validator/validate-request");
|
|
14
|
-
function callController(controller, validate, appVersion, authConfig) {
|
|
14
|
+
function callController(controller, validate, appVersion, authConfig, options) {
|
|
15
15
|
const { authMap, authCtor, initAuthCtor, accessToken } = authConfig;
|
|
16
16
|
return async function (req, res) {
|
|
17
17
|
const headers = req.headers;
|
|
18
|
-
if (
|
|
18
|
+
if (!options?.skipAppVersionCheck &&
|
|
19
|
+
(0, helpers_1.getEnvStr)('ENVIRONMENT') !== 'development' &&
|
|
20
|
+
appVersion !== headers['x-app-version']) {
|
|
19
21
|
helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'APP_VERSION_MISMATCH' });
|
|
20
22
|
}
|
|
21
23
|
const inputs = (0, validate_request_1.validateRequest)(validate, req);
|
|
@@ -3,10 +3,10 @@ import type { AuthMap, AuthUsers, AuthCtor } from '../auth/auth.types';
|
|
|
3
3
|
import type { RouteValidator } from '../validator/validator.types';
|
|
4
4
|
export type Middleware = (req: Req, res: Res, next: Next) => void;
|
|
5
5
|
export type Controller<V extends RouteValidator, AM extends AuthMap, BA extends BaseAuth<AM>> = (ctx: Ctx<V>, db: Db, auth: BA) => unknown;
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
];
|
|
6
|
+
export type RouteOptions = {
|
|
7
|
+
skipAppVersionCheck?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type SetRouteArgs<V extends RouteValidator, AM extends AuthMap, BA extends BaseAuth<AM>> = [...Middleware[], Controller<V, AM, BA>] | [...Middleware[], Controller<V, AM, BA>, RouteOptions];
|
|
10
10
|
export type AuthConfig<AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>, IR extends any> = {
|
|
11
11
|
authMap: AM;
|
|
12
12
|
authCtor: AuthCtor<AM, AU, BA, IR>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pangea-server",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.174",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "22.14.0"
|
|
7
7
|
},
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"http-status-codes": "2.3.0",
|
|
55
55
|
"jsdom": "26.0.0",
|
|
56
56
|
"jsonwebtoken": "9.0.2",
|
|
57
|
+
"mercadopago": "3.2.0",
|
|
57
58
|
"morgan": "1.10.0",
|
|
58
59
|
"multer": "1.4.5-lts.2",
|
|
59
60
|
"mysql2": "3.14.0",
|
|
@@ -76,6 +77,7 @@
|
|
|
76
77
|
"@types/helmet": "4.0.0",
|
|
77
78
|
"@types/jsdom": "21.1.7",
|
|
78
79
|
"@types/jsonwebtoken": "9.0.6",
|
|
80
|
+
"@types/mercadopago": "1.5.11",
|
|
79
81
|
"@types/morgan": "1.9.9",
|
|
80
82
|
"@types/multer": "1.4.12",
|
|
81
83
|
"@types/node": "20.2.5",
|