pangea-server 3.3.171 → 3.3.173

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.
@@ -4,6 +4,7 @@ type ColStrOptions = ColGeneralOptions & {
4
4
  minLength?: StringLength | number;
5
5
  maxLength: StringLength | number;
6
6
  regex?: RegExp;
7
+ caseSensitive?: boolean;
7
8
  };
8
9
  export declare function ColStr(options: ColStrOptions): (target: any, propertyName: string) => void;
9
10
  export declare function ColText(options?: Partial<ColStrOptions>): (target: any, propertyName: string) => void;
@@ -40,7 +40,7 @@ const column_1 = require("./column");
40
40
  // resources
41
41
  const resources_1 = require("../../../resources");
42
42
  function ColStr(options) {
43
- return getStrColumn(seq.DataType.STRING(getLength(255, options.maxLength)), options);
43
+ return getStrColumn(seq.DataType.STRING({ length: getLength(255, options.maxLength), binary: options.caseSensitive }), options);
44
44
  }
45
45
  function ColText(options) {
46
46
  return getStrColumn('TEXT', options);
@@ -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';
@@ -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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.171",
4
+ "version": "3.3.173",
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",