@infrab4a/connect 5.3.0-beta.3 → 5.3.0-beta.31
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/index.cjs.js +3018 -435
- package/index.esm.js +2980 -419
- package/package.json +3 -2
- package/src/domain/catalog/models/category-brand.d.ts +17 -0
- package/src/domain/catalog/models/category.d.ts +12 -0
- package/src/domain/catalog/models/enums/shops.enum.d.ts +2 -0
- package/src/domain/catalog/models/index.d.ts +4 -0
- package/src/domain/catalog/models/product-base.d.ts +10 -0
- package/src/domain/catalog/models/product-group.d.ts +12 -0
- package/src/domain/catalog/models/product-price-log.d.ts +25 -0
- package/src/domain/catalog/models/product-review.d.ts +2 -0
- package/src/domain/catalog/models/product-stock-entry.d.ts +16 -0
- package/src/domain/catalog/models/product.d.ts +1 -0
- package/src/domain/catalog/models/types/brands-shop-menu.type.d.ts +13 -0
- package/src/domain/catalog/models/types/index.d.ts +2 -0
- package/src/domain/catalog/models/types/product-competitors-price.d.ts +6 -0
- package/src/domain/catalog/repositories/category-brand.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/category-product.repository.d.ts +2 -0
- package/src/domain/catalog/repositories/category.repository.d.ts +1 -0
- package/src/domain/catalog/repositories/index.d.ts +5 -0
- package/src/domain/catalog/repositories/product-catalog.repository.d.ts +17 -0
- package/src/domain/catalog/repositories/product-group.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/product-price-log.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/product-stock-entry.repository.d.ts +4 -0
- package/src/domain/shop-settings/enums/shop-page-name.enum.d.ts +2 -1
- package/src/domain/shop-settings/models/home.d.ts +2 -1
- package/src/domain/shop-settings/models/index.d.ts +2 -1
- package/src/domain/shop-settings/models/shop-configs.d.ts +18 -0
- package/src/domain/shop-settings/models/{shop-settings.d.ts → shop-page-settings.d.ts} +4 -1
- package/src/domain/shop-settings/models/types/index.d.ts +3 -0
- package/src/domain/shop-settings/models/types/limit-orders.type.d.ts +7 -0
- package/src/domain/shop-settings/models/types/shipping-thresholds.type.d.ts +17 -0
- package/src/domain/shop-settings/models/types/shop-error-messages.type.d.ts +10 -0
- package/src/domain/shop-settings/models/types/shop-page-section.type.d.ts +140 -0
- package/src/domain/shop-settings/repositories/index.d.ts +1 -0
- package/src/domain/shop-settings/repositories/shop-configs.repository.d.ts +4 -0
- package/src/domain/shop-settings/repositories/shop-settings.repository.d.ts +1 -1
- package/src/domain/shopping/enums/index.d.ts +3 -0
- package/src/domain/shopping/enums/order-payment-status.enum.d.ts +10 -0
- package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
- package/src/domain/shopping/enums/payment-providers.enum.d.ts +2 -1
- package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +5 -0
- package/src/domain/shopping/factories/index.d.ts +1 -0
- package/src/domain/shopping/factories/mercado-pago-payment-method.factory.d.ts +11 -0
- package/src/domain/shopping/factories/payment-provider.factory.d.ts +2 -0
- package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +10 -2
- package/src/domain/shopping/models/checkout.d.ts +2 -0
- package/src/domain/shopping/models/enums/index.d.ts +3 -0
- package/src/domain/shopping/models/enums/order-status.enum.d.ts +2 -1
- package/src/domain/shopping/models/enums/shopping-recurrence-cycle.enum.d.ts +5 -0
- package/src/domain/shopping/models/enums/shopping-recurrence-edition-status.enum.d.ts +11 -0
- package/src/domain/shopping/models/enums/shopping-recurrence-status.enum.d.ts +7 -0
- package/src/domain/shopping/models/index.d.ts +1 -0
- package/src/domain/shopping/models/line-item.d.ts +5 -0
- package/src/domain/shopping/models/order-blocked.d.ts +5 -0
- package/src/domain/shopping/models/order.d.ts +20 -0
- package/src/domain/shopping/models/payment-transaction.d.ts +19 -2
- package/src/domain/shopping/models/payment.d.ts +3 -1
- package/src/domain/shopping/models/recurrence/index.d.ts +3 -0
- package/src/domain/shopping/models/recurrence/shopping-recurrence-edition.d.ts +18 -0
- package/src/domain/shopping/models/recurrence/shopping-recurrence-error-log.d.ts +9 -0
- package/src/domain/shopping/models/recurrence/shopping-recurrence.d.ts +45 -0
- package/src/domain/shopping/models/shipping-method.d.ts +2 -0
- package/src/domain/shopping/models/types/index.d.ts +1 -0
- package/src/domain/shopping/models/types/line-item-recurrence.type.d.ts +2 -0
- package/src/domain/shopping/repositories/index.d.ts +1 -0
- package/src/domain/shopping/repositories/order-blocked.repository.d.ts +5 -0
- package/src/domain/shopping/repositories/recurrence/index.d.ts +3 -0
- package/src/domain/shopping/repositories/recurrence/shopping-recurrence-edition.repository.d.ts +4 -0
- package/src/domain/shopping/repositories/recurrence/shopping-recurrence-error-log.repository.d.ts +4 -0
- package/src/domain/shopping/repositories/recurrence/shopping-recurrence.repository.d.ts +9 -0
- package/src/domain/shopping/services/antifraud-card.service.d.ts +2 -0
- package/src/domain/shopping/types/card-info.type.d.ts +1 -0
- package/src/domain/shopping/types/checkout-paylod-request.type.d.ts +2 -7
- package/src/domain/shopping/types/create-recurrency-payload.type.d.ts +6 -0
- package/src/domain/shopping/types/index.d.ts +5 -0
- package/src/domain/shopping/types/mercado-pago-card.type.d.ts +14 -0
- package/src/domain/shopping/types/mercado-pago-credentials.type.d.ts +5 -0
- package/src/domain/shopping/types/pagarme-card.type.d.ts +9 -3
- package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
- package/src/domain/shopping/types/pagarme-credentials.type.d.ts +9 -3
- package/src/domain/shopping/types/payment-card-info.type.d.ts +6 -1
- package/src/domain/shopping/types/shopping-recurrence-update-payloads.type.d.ts +35 -0
- package/src/domain/users/models/user-payment-method.d.ts +2 -0
- package/src/domain/users/models/user.d.ts +1 -0
- package/src/errors/enum/error.enum.d.ts +14 -0
- package/src/errors/enum/index.d.ts +1 -0
- package/src/errors/fraud-validation.error.d.ts +1 -1
- package/src/errors/index.d.ts +2 -0
- package/src/errors/invalid-checkout.error.d.ts +7 -0
- package/src/errors/not-found.error.d.ts +1 -0
- package/src/errors/payment.error.d.ts +1 -1
- package/src/infra/cache/index.d.ts +1 -0
- package/src/infra/cache/resolve-cache-config.d.ts +2 -0
- package/src/infra/cache/restcache.adapter.d.ts +3 -0
- package/src/infra/firebase/firestore/repositories/catalog/category-brand-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/catalog/index.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/shop-settings/index.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/shop-settings/shop-configs-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +3 -0
- package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/shopping/shopping-recurrence-edition-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/shopping/shopping-recurrence-error-log-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/shopping/shopping-recurrence-firestore.repository.d.ts +10 -0
- package/src/infra/hasura-graphql/models/index.d.ts +2 -0
- package/src/infra/hasura-graphql/models/product-catalog-hasura-graphql.d.ts +16 -0
- package/src/infra/hasura-graphql/models/product-stock-entry-hasura-graphql.d.ts +3 -0
- package/src/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +2 -0
- package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +4 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-catalog-hasura-graphql.repository.d.ts +22 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-group-hasura-graphql.repository.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-price-log-hasura-graphql.repository.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-stock-entry-hasura-graphql.repository.d.ts +8 -0
- package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/index.d.ts +1 -0
- package/src/infra/mercado-pago/adapters/index.d.ts +3 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-base-axios.d.ts +11 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-boleto-payment-axios.adapter.d.ts +8 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-card-payment-axios.adapter.d.ts +22 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-pix-payment-axios.adapter.d.ts +8 -0
- package/src/infra/mercado-pago/enums/index.d.ts +2 -0
- package/src/infra/mercado-pago/enums/mercado-pago-status-detail.enum.d.ts +33 -0
- package/src/infra/mercado-pago/enums/mercado-pago-status.enum.d.ts +10 -0
- package/src/infra/mercado-pago/helpers/index.d.ts +3 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-errors.helper.d.ts +3 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-request.helper.d.ts +60 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-response.helper.d.ts +10 -0
- package/src/infra/mercado-pago/index.d.ts +4 -0
- package/src/infra/mercado-pago/types/index.d.ts +3 -0
- package/src/infra/mercado-pago/types/mercado-pago-request.type.d.ts +1 -0
- package/src/infra/mercado-pago/types/mercado-pago-response.type.d.ts +211 -0
- package/src/infra/mercado-pago/types/mercado-pago-status-detail.type.d.ts +2 -0
- package/src/infra/mercado-pago/types/mercado-pago-status.type.d.ts +2 -0
- package/src/infra/pagarme/adapters/helpers/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-blocked-order.helper.d.ts +7 -2
- package/src/infra/pagarme/adapters/helpers/pagarme-errors.helper.d.ts +3 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +13 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +10 -0
- package/src/infra/pagarme/adapters/index.d.ts +2 -3
- package/src/infra/pagarme/adapters/v4/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/{pagarme-bank-slip-payment-axios.adapter.d.ts → v4/pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/{pagarme-card-payment-axios.adapter.d.ts → v4/pagarme-card-payment-axios.adapter.d.ts} +7 -6
- package/src/infra/pagarme/adapters/{pagarme-pix-payment-axios.adapter.d.ts → v4/pagarme-pix-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/v5/index.d.ts +4 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-base-axios.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +25 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/index.d.ts +1 -0
- package/src/infra/pagarme/types/index.d.ts +1 -0
- package/src/infra/pagarme/types/v5/index.d.ts +4 -0
- package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +19 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +91 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +241 -0
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
- package/src/utils/index.d.ts +4 -2
- package/src/utils/to-cents.d.ts +5 -0
package/index.cjs.js
CHANGED
|
@@ -6,6 +6,7 @@ require('reflect-metadata');
|
|
|
6
6
|
var tslib = require('tslib');
|
|
7
7
|
var classTransformer = require('class-transformer');
|
|
8
8
|
var dateFns = require('date-fns');
|
|
9
|
+
var dateFnsTz = require('date-fns-tz');
|
|
9
10
|
var lodash = require('lodash');
|
|
10
11
|
var debug = require('debug');
|
|
11
12
|
var serializeJavascript = require('serialize-javascript');
|
|
@@ -19,25 +20,7 @@ var storage = require('firebase/storage');
|
|
|
19
20
|
|
|
20
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
if (e && e.__esModule) return e;
|
|
24
|
-
var n = Object.create(null);
|
|
25
|
-
if (e) {
|
|
26
|
-
Object.keys(e).forEach(function (k) {
|
|
27
|
-
if (k !== 'default') {
|
|
28
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
29
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () { return e[k]; }
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
n["default"] = e;
|
|
37
|
-
return Object.freeze(n);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var serializeJavascript__namespace = /*#__PURE__*/_interopNamespace(serializeJavascript);
|
|
23
|
+
var serializeJavascript__default = /*#__PURE__*/_interopDefaultLegacy(serializeJavascript);
|
|
41
24
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
42
25
|
|
|
43
26
|
exports.AntifraudProviders = void 0;
|
|
@@ -61,6 +44,18 @@ exports.OrderBlockedType = void 0;
|
|
|
61
44
|
OrderBlockedType["Boleto"] = "Boleto";
|
|
62
45
|
})(exports.OrderBlockedType || (exports.OrderBlockedType = {}));
|
|
63
46
|
|
|
47
|
+
exports.OrderPaymentStatus = void 0;
|
|
48
|
+
(function (OrderPaymentStatus) {
|
|
49
|
+
OrderPaymentStatus["Em processamento"] = "processing";
|
|
50
|
+
OrderPaymentStatus["Autorizada"] = "authorized";
|
|
51
|
+
OrderPaymentStatus["Pago"] = "paid";
|
|
52
|
+
OrderPaymentStatus["Estornada"] = "refunded";
|
|
53
|
+
OrderPaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
54
|
+
OrderPaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
55
|
+
OrderPaymentStatus["Recusada/N\u00E3o autorizada"] = "refused";
|
|
56
|
+
OrderPaymentStatus["Chargedback"] = "chargedback";
|
|
57
|
+
})(exports.OrderPaymentStatus || (exports.OrderPaymentStatus = {}));
|
|
58
|
+
|
|
64
59
|
exports.PagarmePaymentStatus = void 0;
|
|
65
60
|
(function (PagarmePaymentStatus) {
|
|
66
61
|
PagarmePaymentStatus["Em processamento"] = "processing";
|
|
@@ -73,6 +68,33 @@ exports.PagarmePaymentStatus = void 0;
|
|
|
73
68
|
PagarmePaymentStatus["Chargedback"] = "chargedback";
|
|
74
69
|
})(exports.PagarmePaymentStatus || (exports.PagarmePaymentStatus = {}));
|
|
75
70
|
|
|
71
|
+
exports.PagarMeV5PaymentStatus = void 0;
|
|
72
|
+
(function (PagarMeV5PaymentStatus) {
|
|
73
|
+
PagarMeV5PaymentStatus["Em processamento"] = "processing";
|
|
74
|
+
PagarMeV5PaymentStatus["Gerado"] = "generated";
|
|
75
|
+
PagarMeV5PaymentStatus["Visualizado"] = "viewed";
|
|
76
|
+
PagarMeV5PaymentStatus["Pago a menor"] = "underpaid";
|
|
77
|
+
PagarMeV5PaymentStatus["Pago a maior"] = "overpaid";
|
|
78
|
+
PagarMeV5PaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
79
|
+
PagarMeV5PaymentStatus["Pago"] = "paid";
|
|
80
|
+
PagarMeV5PaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
81
|
+
PagarMeV5PaymentStatus["Autorizada pendente de captura"] = "authorized_pending_capture";
|
|
82
|
+
PagarMeV5PaymentStatus["N\u00E3o autorizada"] = "not_authorized";
|
|
83
|
+
PagarMeV5PaymentStatus["Capturada"] = "captured";
|
|
84
|
+
PagarMeV5PaymentStatus["Aguardando captura"] = "waiting_capture";
|
|
85
|
+
PagarMeV5PaymentStatus["Com erro"] = "with_error";
|
|
86
|
+
PagarMeV5PaymentStatus["Estornado"] = "refunded";
|
|
87
|
+
PagarMeV5PaymentStatus["Cancelado"] = "voided";
|
|
88
|
+
PagarMeV5PaymentStatus["Falha"] = "failed";
|
|
89
|
+
})(exports.PagarMeV5PaymentStatus || (exports.PagarMeV5PaymentStatus = {}));
|
|
90
|
+
exports.PagarMeV5OrderStatus = void 0;
|
|
91
|
+
(function (PagarMeV5OrderStatus) {
|
|
92
|
+
PagarMeV5OrderStatus["Pendente"] = "pending";
|
|
93
|
+
PagarMeV5OrderStatus["Pago"] = "paid";
|
|
94
|
+
PagarMeV5OrderStatus["Cancelado"] = "canceled";
|
|
95
|
+
PagarMeV5OrderStatus["Falha"] = "failed";
|
|
96
|
+
})(exports.PagarMeV5OrderStatus || (exports.PagarMeV5OrderStatus = {}));
|
|
97
|
+
|
|
76
98
|
exports.PaymentMethods = void 0;
|
|
77
99
|
(function (PaymentMethods) {
|
|
78
100
|
PaymentMethods["CARD"] = "card";
|
|
@@ -86,8 +108,16 @@ exports.PaymentProviders = void 0;
|
|
|
86
108
|
PaymentProviders["PAGARME"] = "pagarMe";
|
|
87
109
|
PaymentProviders["ADYEN"] = "adyen";
|
|
88
110
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
111
|
+
PaymentProviders["MERCADOPAGO"] = "mercadoPago";
|
|
89
112
|
})(exports.PaymentProviders || (exports.PaymentProviders = {}));
|
|
90
113
|
|
|
114
|
+
exports.TransactionPaymentMethods = void 0;
|
|
115
|
+
(function (TransactionPaymentMethods) {
|
|
116
|
+
TransactionPaymentMethods["CARD"] = "credit_card";
|
|
117
|
+
TransactionPaymentMethods["BANKSLIP"] = "boleto";
|
|
118
|
+
TransactionPaymentMethods["PIX"] = "pix";
|
|
119
|
+
})(exports.TransactionPaymentMethods || (exports.TransactionPaymentMethods = {}));
|
|
120
|
+
|
|
91
121
|
class BasePaymentMethodFactory {
|
|
92
122
|
constructor(methods) {
|
|
93
123
|
this.methods = methods;
|
|
@@ -112,6 +142,9 @@ class AntifraudProviderFactory {
|
|
|
112
142
|
class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
|
|
113
143
|
}
|
|
114
144
|
|
|
145
|
+
class MercadoPagoPaymentMethodFactory extends BasePaymentMethodFactory {
|
|
146
|
+
}
|
|
147
|
+
|
|
115
148
|
class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
|
|
116
149
|
}
|
|
117
150
|
|
|
@@ -609,9 +642,22 @@ const deserialize = (data) => {
|
|
|
609
642
|
return eval('(' + data + ')');
|
|
610
643
|
};
|
|
611
644
|
const serialize = (data) => {
|
|
612
|
-
return
|
|
645
|
+
return serializeJavascript__default["default"](data);
|
|
613
646
|
};
|
|
614
647
|
|
|
648
|
+
/**
|
|
649
|
+
* Converts a BRL major-unit amount (e.g. 10.5) to integer cents (1050).
|
|
650
|
+
* Uses fixed 2-decimal normalization to avoid IEEE-754 artifacts like 19.99 * 100.
|
|
651
|
+
*/
|
|
652
|
+
function toCents(amount) {
|
|
653
|
+
if (!Number.isFinite(amount)) {
|
|
654
|
+
throw new Error(`Invalid amount: ${amount}`);
|
|
655
|
+
}
|
|
656
|
+
const sign = amount < 0 ? -1 : 1;
|
|
657
|
+
const [whole, fraction = '0'] = Math.abs(amount).toFixed(2).split('.');
|
|
658
|
+
return sign * (Number(whole) * 100 + Number(fraction));
|
|
659
|
+
}
|
|
660
|
+
|
|
615
661
|
class BaseModel {
|
|
616
662
|
get identifier() {
|
|
617
663
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
@@ -664,6 +710,8 @@ exports.Shops = void 0;
|
|
|
664
710
|
Shops["MENSMARKET"] = "mensmarket";
|
|
665
711
|
Shops["GLAMSHOP"] = "Glamshop";
|
|
666
712
|
Shops["GLAMPOINTS"] = "Glampoints";
|
|
713
|
+
Shops["GLAMBEAUTY"] = "Glambeauty";
|
|
714
|
+
Shops["ELLA"] = "ella";
|
|
667
715
|
Shops["ALL"] = "ALL";
|
|
668
716
|
})(exports.Shops || (exports.Shops = {}));
|
|
669
717
|
|
|
@@ -698,12 +746,36 @@ class Category extends BaseModel {
|
|
|
698
746
|
image: null,
|
|
699
747
|
};
|
|
700
748
|
}
|
|
749
|
+
get glamBeautyImages() {
|
|
750
|
+
return this.images?.[exports.Shops.GLAMBEAUTY]
|
|
751
|
+
? this.images[exports.Shops.GLAMBEAUTY]
|
|
752
|
+
: {
|
|
753
|
+
brandBanner: null,
|
|
754
|
+
brandBannerMobile: null,
|
|
755
|
+
image: null,
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
get ellaImages() {
|
|
759
|
+
return this.images?.[exports.Shops.ELLA]
|
|
760
|
+
? this.images[exports.Shops.ELLA]
|
|
761
|
+
: {
|
|
762
|
+
brandBanner: null,
|
|
763
|
+
brandBannerMobile: null,
|
|
764
|
+
image: null,
|
|
765
|
+
};
|
|
766
|
+
}
|
|
701
767
|
get glamMetadata() {
|
|
702
768
|
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.GLAMSHOP);
|
|
703
769
|
}
|
|
704
770
|
get mensMetadata() {
|
|
705
771
|
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
|
|
706
772
|
}
|
|
773
|
+
get glamBeautyMetadata() {
|
|
774
|
+
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.GLAMBEAUTY);
|
|
775
|
+
}
|
|
776
|
+
get ellaMetadata() {
|
|
777
|
+
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.ELLA);
|
|
778
|
+
}
|
|
707
779
|
getMostRelevantByShop(shop) {
|
|
708
780
|
return this.mostRelevants?.[shop] || [];
|
|
709
781
|
}
|
|
@@ -722,6 +794,30 @@ tslib.__decorate([
|
|
|
722
794
|
], Category.prototype, "filters", void 0);
|
|
723
795
|
registerClass('Category', Category);
|
|
724
796
|
|
|
797
|
+
class BrandCategory extends BaseModel {
|
|
798
|
+
get glamImages() {
|
|
799
|
+
return this.images?.[exports.Shops.GLAMSHOP]
|
|
800
|
+
? this.images[exports.Shops.GLAMSHOP]
|
|
801
|
+
: {
|
|
802
|
+
brandBanner: null,
|
|
803
|
+
brandBannerMobile: null,
|
|
804
|
+
image: null,
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
get mensImages() {
|
|
808
|
+
return this.images?.[exports.Shops.MENSMARKET]
|
|
809
|
+
? this.images[exports.Shops.MENSMARKET]
|
|
810
|
+
: {
|
|
811
|
+
brandBanner: null,
|
|
812
|
+
brandBannerMobile: null,
|
|
813
|
+
image: null,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
static get identifiersFields() {
|
|
817
|
+
return ['id'];
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
725
821
|
class CategoryCollectionChildren extends BaseModel {
|
|
726
822
|
static get identifiersFields() {
|
|
727
823
|
return ['collectionId', 'categoryId'];
|
|
@@ -795,6 +891,11 @@ class ProductReview extends BaseModel {
|
|
|
795
891
|
return ['id'];
|
|
796
892
|
}
|
|
797
893
|
}
|
|
894
|
+
tslib.__decorate([
|
|
895
|
+
classTransformer.Type(resolveClass('Product')),
|
|
896
|
+
tslib.__metadata("design:type", Function)
|
|
897
|
+
], ProductReview.prototype, "product", void 0);
|
|
898
|
+
registerClass('ProductReview', ProductReview);
|
|
798
899
|
|
|
799
900
|
class ProductBase extends BaseModel {
|
|
800
901
|
get evaluation() {
|
|
@@ -859,28 +960,6 @@ tslib.__decorate([
|
|
|
859
960
|
tslib.__metadata("design:type", Object)
|
|
860
961
|
], ProductErrors.prototype, "product", void 0);
|
|
861
962
|
|
|
862
|
-
class ProductStockNotification extends BaseModel {
|
|
863
|
-
static get identifiersFields() {
|
|
864
|
-
return ['id'];
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
class Wishlist extends Category {
|
|
869
|
-
static get identifiersFields() {
|
|
870
|
-
return ['id'];
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
class Buy2Win extends BaseModel {
|
|
875
|
-
static get identifiersFields() {
|
|
876
|
-
return ['id'];
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
tslib.__decorate([
|
|
880
|
-
classTransformer.Type(() => Category),
|
|
881
|
-
tslib.__metadata("design:type", Array)
|
|
882
|
-
], Buy2Win.prototype, "categories", void 0);
|
|
883
|
-
|
|
884
963
|
exports.Where = void 0;
|
|
885
964
|
(function (Where) {
|
|
886
965
|
Where["EQUALS"] = "==";
|
|
@@ -907,6 +986,46 @@ exports.UpdateOptionActions = void 0;
|
|
|
907
986
|
UpdateOptionActions["NULL"] = "null";
|
|
908
987
|
})(exports.UpdateOptionActions || (exports.UpdateOptionActions = {}));
|
|
909
988
|
|
|
989
|
+
class ProductGroup extends BaseModel {
|
|
990
|
+
static get identifiersFields() {
|
|
991
|
+
return ['id'];
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
class ProductPriceLog extends BaseModel {
|
|
996
|
+
static get identifiersFields() {
|
|
997
|
+
return ['id'];
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
class ProductStockEntry extends BaseModel {
|
|
1002
|
+
static get identifiersFields() {
|
|
1003
|
+
return ['id'];
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
class ProductStockNotification extends BaseModel {
|
|
1008
|
+
static get identifiersFields() {
|
|
1009
|
+
return ['id'];
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
class Wishlist extends Category {
|
|
1014
|
+
static get identifiersFields() {
|
|
1015
|
+
return ['id'];
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
class Buy2Win extends BaseModel {
|
|
1020
|
+
static get identifiersFields() {
|
|
1021
|
+
return ['id'];
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
tslib.__decorate([
|
|
1025
|
+
classTransformer.Type(() => Category),
|
|
1026
|
+
tslib.__metadata("design:type", Array)
|
|
1027
|
+
], Buy2Win.prototype, "categories", void 0);
|
|
1028
|
+
|
|
910
1029
|
class CampaignDashboard extends BaseModel {
|
|
911
1030
|
static get identifiersFields() {
|
|
912
1031
|
return ['id'];
|
|
@@ -1593,8 +1712,38 @@ exports.OrderStatus = void 0;
|
|
|
1593
1712
|
OrderStatus["ENTREGUE"] = "Entregue";
|
|
1594
1713
|
OrderStatus["CANCELADO"] = "Cancelado";
|
|
1595
1714
|
OrderStatus["PENDENTE_REENVIO"] = "Pendente reenvio";
|
|
1715
|
+
OrderStatus["AGUARDANDO_STOCK_REENVIO"] = "Aguardando stock para reenvio";
|
|
1596
1716
|
})(exports.OrderStatus || (exports.OrderStatus = {}));
|
|
1597
1717
|
|
|
1718
|
+
exports.ShoppingRecurrenceCycle = void 0;
|
|
1719
|
+
(function (ShoppingRecurrenceCycle) {
|
|
1720
|
+
ShoppingRecurrenceCycle[ShoppingRecurrenceCycle["MONTHLY"] = 1] = "MONTHLY";
|
|
1721
|
+
ShoppingRecurrenceCycle[ShoppingRecurrenceCycle["BIMONTHLY"] = 2] = "BIMONTHLY";
|
|
1722
|
+
ShoppingRecurrenceCycle[ShoppingRecurrenceCycle["QUARTERLY"] = 3] = "QUARTERLY";
|
|
1723
|
+
})(exports.ShoppingRecurrenceCycle || (exports.ShoppingRecurrenceCycle = {}));
|
|
1724
|
+
|
|
1725
|
+
exports.ShoppingRecurrenceEditionStatus = void 0;
|
|
1726
|
+
(function (ShoppingRecurrenceEditionStatus) {
|
|
1727
|
+
ShoppingRecurrenceEditionStatus["SCHEDULED"] = "scheduled";
|
|
1728
|
+
ShoppingRecurrenceEditionStatus["PAUSED"] = "paused";
|
|
1729
|
+
ShoppingRecurrenceEditionStatus["SKIPPED"] = "skipped";
|
|
1730
|
+
ShoppingRecurrenceEditionStatus["PROCESSING"] = "processing";
|
|
1731
|
+
ShoppingRecurrenceEditionStatus["FINISHED"] = "finished";
|
|
1732
|
+
ShoppingRecurrenceEditionStatus["PAYMENT_FAIL"] = "payment_fail";
|
|
1733
|
+
ShoppingRecurrenceEditionStatus["AWAITING_PAYMENT"] = "awaiting_payment";
|
|
1734
|
+
ShoppingRecurrenceEditionStatus["STOCK_VALIDATION"] = "stock_validation";
|
|
1735
|
+
ShoppingRecurrenceEditionStatus["CANCELLED"] = "cancelled";
|
|
1736
|
+
})(exports.ShoppingRecurrenceEditionStatus || (exports.ShoppingRecurrenceEditionStatus = {}));
|
|
1737
|
+
|
|
1738
|
+
exports.ShoppingRecurrenceStatus = void 0;
|
|
1739
|
+
(function (ShoppingRecurrenceStatus) {
|
|
1740
|
+
ShoppingRecurrenceStatus["ACTIVE"] = "active";
|
|
1741
|
+
ShoppingRecurrenceStatus["PAUSED"] = "paused";
|
|
1742
|
+
ShoppingRecurrenceStatus["CANCELLED"] = "cancelled";
|
|
1743
|
+
ShoppingRecurrenceStatus["PAYMENT_FAILED"] = "payment_failed";
|
|
1744
|
+
ShoppingRecurrenceStatus["WAITING_STOCK"] = "waiting_stock";
|
|
1745
|
+
})(exports.ShoppingRecurrenceStatus || (exports.ShoppingRecurrenceStatus = {}));
|
|
1746
|
+
|
|
1598
1747
|
class Order extends Checkout {
|
|
1599
1748
|
}
|
|
1600
1749
|
tslib.__decorate([
|
|
@@ -1608,6 +1757,44 @@ class OrderBlocked extends BaseModel {
|
|
|
1608
1757
|
}
|
|
1609
1758
|
}
|
|
1610
1759
|
|
|
1760
|
+
class ShoppingRecurrence extends BaseModel {
|
|
1761
|
+
static get identifiersFields() {
|
|
1762
|
+
return ['id'];
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
tslib.__decorate([
|
|
1766
|
+
classTransformer.Type(() => User),
|
|
1767
|
+
tslib.__metadata("design:type", User)
|
|
1768
|
+
], ShoppingRecurrence.prototype, "user", void 0);
|
|
1769
|
+
tslib.__decorate([
|
|
1770
|
+
classTransformer.Type(() => UserAddress),
|
|
1771
|
+
tslib.__metadata("design:type", UserAddress)
|
|
1772
|
+
], ShoppingRecurrence.prototype, "shippingAddress", void 0);
|
|
1773
|
+
tslib.__decorate([
|
|
1774
|
+
classTransformer.Type(() => UserAddress),
|
|
1775
|
+
tslib.__metadata("design:type", UserAddress)
|
|
1776
|
+
], ShoppingRecurrence.prototype, "billingAddress", void 0);
|
|
1777
|
+
tslib.__decorate([
|
|
1778
|
+
classTransformer.Type(() => ShippingMethod),
|
|
1779
|
+
tslib.__metadata("design:type", ShippingMethod)
|
|
1780
|
+
], ShoppingRecurrence.prototype, "shipping", void 0);
|
|
1781
|
+
tslib.__decorate([
|
|
1782
|
+
classTransformer.Type(() => Coupon),
|
|
1783
|
+
tslib.__metadata("design:type", Coupon)
|
|
1784
|
+
], ShoppingRecurrence.prototype, "coupon", void 0);
|
|
1785
|
+
|
|
1786
|
+
class ShoppingRecurrenceEdition extends BaseModel {
|
|
1787
|
+
static get identifiersFields() {
|
|
1788
|
+
return ['id'];
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
class ShoppingRecurrenceErrorLog extends BaseModel {
|
|
1793
|
+
static get identifiersFields() {
|
|
1794
|
+
return ['id'];
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1611
1798
|
class CheckoutSubscription extends BaseModel {
|
|
1612
1799
|
static get identifiersFields() {
|
|
1613
1800
|
return ['id'];
|
|
@@ -1630,11 +1817,27 @@ tslib.__decorate([
|
|
|
1630
1817
|
tslib.__metadata("design:type", Coupon)
|
|
1631
1818
|
], CheckoutSubscription.prototype, "coupon", void 0);
|
|
1632
1819
|
|
|
1820
|
+
exports.ErrorsCode = void 0;
|
|
1821
|
+
(function (ErrorsCode) {
|
|
1822
|
+
ErrorsCode["genericError"] = "generic-error";
|
|
1823
|
+
ErrorsCode["businessError"] = "business-error";
|
|
1824
|
+
ErrorsCode["invalidCheckoutError"] = "invalid-checkout";
|
|
1825
|
+
ErrorsCode["stockLimit"] = "stock-limit";
|
|
1826
|
+
ErrorsCode["stockOut"] = "stock-out";
|
|
1827
|
+
ErrorsCode["notFound"] = "not-found";
|
|
1828
|
+
ErrorsCode["fraudPreventionInternal"] = "fraud-prevention-internal";
|
|
1829
|
+
ErrorsCode["fraudPreventionExternal"] = "fraud-prevention-external";
|
|
1830
|
+
ErrorsCode["invalidCardError"] = "invalid-card-error";
|
|
1831
|
+
ErrorsCode["insufficientFundsError"] = "insufficient-funds-error";
|
|
1832
|
+
ErrorsCode["paymentNotAuthorizedError"] = "payment-not-authorized-error";
|
|
1833
|
+
ErrorsCode["paymentError"] = "payment-error";
|
|
1834
|
+
})(exports.ErrorsCode || (exports.ErrorsCode = {}));
|
|
1835
|
+
|
|
1633
1836
|
class BusinessError extends tsCustomError.CustomError {
|
|
1634
|
-
constructor(message, additionalData, type
|
|
1837
|
+
constructor(message, additionalData, type) {
|
|
1635
1838
|
super(message);
|
|
1636
1839
|
this.additionalData = additionalData;
|
|
1637
|
-
this.type = type;
|
|
1840
|
+
this.type = type || exports.ErrorsCode.businessError;
|
|
1638
1841
|
}
|
|
1639
1842
|
}
|
|
1640
1843
|
|
|
@@ -1645,10 +1848,10 @@ class DuplicatedResultsError extends tsCustomError.CustomError {
|
|
|
1645
1848
|
}
|
|
1646
1849
|
|
|
1647
1850
|
class FraudValidationError extends tsCustomError.CustomError {
|
|
1648
|
-
constructor(message, additionalData) {
|
|
1851
|
+
constructor(message, type, additionalData) {
|
|
1649
1852
|
super(message);
|
|
1650
1853
|
this.additionalData = additionalData;
|
|
1651
|
-
this.type =
|
|
1854
|
+
this.type = type;
|
|
1652
1855
|
}
|
|
1653
1856
|
}
|
|
1654
1857
|
|
|
@@ -1658,17 +1861,26 @@ class InvalidArgumentError extends tsCustomError.CustomError {
|
|
|
1658
1861
|
}
|
|
1659
1862
|
}
|
|
1660
1863
|
|
|
1864
|
+
class InvalidCheckoutError extends tsCustomError.CustomError {
|
|
1865
|
+
constructor(message, additionalData) {
|
|
1866
|
+
super(message);
|
|
1867
|
+
this.additionalData = additionalData;
|
|
1868
|
+
this.type = exports.ErrorsCode.invalidCheckoutError;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1661
1872
|
class NotFoundError extends tsCustomError.CustomError {
|
|
1662
1873
|
constructor(message) {
|
|
1663
1874
|
super(message);
|
|
1875
|
+
this.type = exports.ErrorsCode.notFound;
|
|
1664
1876
|
}
|
|
1665
1877
|
}
|
|
1666
1878
|
|
|
1667
1879
|
class PaymentError extends tsCustomError.CustomError {
|
|
1668
|
-
constructor(message, additionalData) {
|
|
1880
|
+
constructor(message, type, additionalData) {
|
|
1669
1881
|
super(message);
|
|
1670
1882
|
this.additionalData = additionalData;
|
|
1671
|
-
this.type =
|
|
1883
|
+
this.type = type;
|
|
1672
1884
|
}
|
|
1673
1885
|
}
|
|
1674
1886
|
|
|
@@ -1683,14 +1895,14 @@ class RequiredArgumentError extends tsCustomError.CustomError {
|
|
|
1683
1895
|
class StockLimitError extends BusinessError {
|
|
1684
1896
|
constructor(message, additionalData) {
|
|
1685
1897
|
super(message, additionalData);
|
|
1686
|
-
this.type =
|
|
1898
|
+
this.type = exports.ErrorsCode.stockLimit;
|
|
1687
1899
|
}
|
|
1688
1900
|
}
|
|
1689
1901
|
|
|
1690
1902
|
class StockOutError extends BusinessError {
|
|
1691
1903
|
constructor(message, additionalData) {
|
|
1692
1904
|
super(message, additionalData);
|
|
1693
|
-
this.type =
|
|
1905
|
+
this.type = exports.ErrorsCode.stockOut;
|
|
1694
1906
|
}
|
|
1695
1907
|
}
|
|
1696
1908
|
|
|
@@ -1707,7 +1919,7 @@ class AntifraudBankSlipService {
|
|
|
1707
1919
|
type: 'Boleto',
|
|
1708
1920
|
limiteRange: 'day',
|
|
1709
1921
|
});
|
|
1710
|
-
throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
|
|
1922
|
+
throw new FraudValidationError('Boleto não autorizado para cliente não assinante', exports.ErrorsCode.fraudPreventionInternal, {
|
|
1711
1923
|
checkoutId: checkout.id,
|
|
1712
1924
|
userEmail: checkout.user.email,
|
|
1713
1925
|
info: {
|
|
@@ -1725,19 +1937,58 @@ class AntifraudCardService {
|
|
|
1725
1937
|
constructor(orderRepository, orderBlockedRepository) {
|
|
1726
1938
|
this.orderRepository = orderRepository;
|
|
1727
1939
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
1728
|
-
this.LIMIT_ORDERS_DAY =
|
|
1729
|
-
this.LIMIT_ORDERS_WEEK =
|
|
1730
|
-
this.LIMIT_BLOCKED_ORDERS_DAY = 5;
|
|
1940
|
+
this.LIMIT_ORDERS_DAY = null;
|
|
1941
|
+
this.LIMIT_ORDERS_WEEK = null;
|
|
1731
1942
|
}
|
|
1732
1943
|
async validate(checkout, card) {
|
|
1944
|
+
this.setLimitsByUserType(checkout.user.isSubscriber);
|
|
1733
1945
|
await this.validateBlockedOrderAttempts(checkout, card);
|
|
1734
1946
|
await this.validateDayAndWeekOrderLimits(checkout, card);
|
|
1735
1947
|
return true;
|
|
1736
1948
|
}
|
|
1949
|
+
setLimitsByUserType(isSubscriber) {
|
|
1950
|
+
this.LIMIT_ORDERS_DAY = {
|
|
1951
|
+
subscriber: {
|
|
1952
|
+
cpf: 4,
|
|
1953
|
+
email: 4,
|
|
1954
|
+
phone: 4,
|
|
1955
|
+
card: 4,
|
|
1956
|
+
zip: 4,
|
|
1957
|
+
},
|
|
1958
|
+
nonSubscriber: {
|
|
1959
|
+
cpf: 2,
|
|
1960
|
+
email: 2,
|
|
1961
|
+
phone: 2,
|
|
1962
|
+
card: 2,
|
|
1963
|
+
zip: 2,
|
|
1964
|
+
},
|
|
1965
|
+
};
|
|
1966
|
+
this.LIMIT_ORDERS_WEEK = {
|
|
1967
|
+
subscriber: {
|
|
1968
|
+
cpf: 12,
|
|
1969
|
+
email: 12,
|
|
1970
|
+
phone: 12,
|
|
1971
|
+
card: 12,
|
|
1972
|
+
zip: Infinity,
|
|
1973
|
+
},
|
|
1974
|
+
nonSubscriber: {
|
|
1975
|
+
cpf: 7,
|
|
1976
|
+
email: 7,
|
|
1977
|
+
phone: 7,
|
|
1978
|
+
card: 7,
|
|
1979
|
+
zip: Infinity,
|
|
1980
|
+
},
|
|
1981
|
+
};
|
|
1982
|
+
this.LIMIT_BLOCKED_ORDERS_DAY = isSubscriber ? 7 : 5;
|
|
1983
|
+
}
|
|
1984
|
+
getLimitsByUserType(type, isSubscriber) {
|
|
1985
|
+
const limits = type === 'day' ? this.LIMIT_ORDERS_DAY : this.LIMIT_ORDERS_WEEK;
|
|
1986
|
+
return isSubscriber ? limits['subscriber'] : limits['nonSubscriber'];
|
|
1987
|
+
}
|
|
1737
1988
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1738
1989
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1739
1990
|
if (!isValid) {
|
|
1740
|
-
throw new FraudValidationError(
|
|
1991
|
+
throw new FraudValidationError(`Cliente com mais de ${this.LIMIT_BLOCKED_ORDERS_DAY} compras negadas/bloqueadas no dia`, exports.ErrorsCode.fraudPreventionInternal, {
|
|
1741
1992
|
checkoutId: checkout.id,
|
|
1742
1993
|
userEmail: checkout.user.email,
|
|
1743
1994
|
info: {
|
|
@@ -1751,7 +2002,7 @@ class AntifraudCardService {
|
|
|
1751
2002
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1752
2003
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1753
2004
|
if (!isValid) {
|
|
1754
|
-
throw new FraudValidationError('Cliente tentando comprar mais
|
|
2005
|
+
throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', exports.ErrorsCode.fraudPreventionInternal, {
|
|
1755
2006
|
checkoutId: checkout.id,
|
|
1756
2007
|
userEmail: checkout.user.email,
|
|
1757
2008
|
info: {
|
|
@@ -1770,7 +2021,7 @@ class AntifraudCardService {
|
|
|
1770
2021
|
await this.createBlockedOrderRecord({
|
|
1771
2022
|
checkout,
|
|
1772
2023
|
card,
|
|
1773
|
-
reason:
|
|
2024
|
+
reason: `More than ${this.LIMIT_BLOCKED_ORDERS_DAY} attempts have failed`,
|
|
1774
2025
|
key: 'Failed attempts',
|
|
1775
2026
|
period: 'day',
|
|
1776
2027
|
});
|
|
@@ -1779,15 +2030,17 @@ class AntifraudCardService {
|
|
|
1779
2030
|
return true;
|
|
1780
2031
|
}
|
|
1781
2032
|
getTodayDateRange() {
|
|
1782
|
-
const
|
|
1783
|
-
const
|
|
1784
|
-
|
|
2033
|
+
const timeZone = 'America/Sao_Paulo';
|
|
2034
|
+
const today = dateFnsTz.utcToZonedTime(new Date(), timeZone);
|
|
2035
|
+
const day = dateFns.startOfDay(today);
|
|
2036
|
+
const endOfDay = dateFns.endOfDay(today);
|
|
2037
|
+
return { day: dateFns.addHours(day, 3), endOfDay: dateFns.addHours(endOfDay, 3) };
|
|
1785
2038
|
}
|
|
1786
2039
|
async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
|
|
1787
2040
|
const { day, endOfDay } = dateRange;
|
|
1788
2041
|
const dateFilter = [
|
|
1789
|
-
{ operator: exports.Where.GTE, value:
|
|
1790
|
-
{ operator: exports.Where.LTE, value:
|
|
2042
|
+
{ operator: exports.Where.GTE, value: day },
|
|
2043
|
+
{ operator: exports.Where.LTE, value: endOfDay },
|
|
1791
2044
|
];
|
|
1792
2045
|
const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
|
|
1793
2046
|
this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
|
|
@@ -1889,26 +2142,28 @@ class AntifraudCardService {
|
|
|
1889
2142
|
}
|
|
1890
2143
|
async validateDayOrderLimits(checkout, params) {
|
|
1891
2144
|
const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
|
|
2145
|
+
const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
|
|
1892
2146
|
return this.checkOrderLimitsAndBlock({
|
|
1893
2147
|
checkout,
|
|
1894
2148
|
orderCounts: ordersPerDay,
|
|
1895
|
-
limit:
|
|
2149
|
+
limit: limits,
|
|
1896
2150
|
period: 'day',
|
|
1897
2151
|
});
|
|
1898
2152
|
}
|
|
1899
2153
|
async validateWeekOrderLimits(checkout, params) {
|
|
1900
2154
|
const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
|
|
2155
|
+
const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
|
|
1901
2156
|
return this.checkOrderLimitsAndBlock({
|
|
1902
2157
|
checkout,
|
|
1903
2158
|
orderCounts: ordersPerWeek,
|
|
1904
|
-
limit:
|
|
2159
|
+
limit: limits,
|
|
1905
2160
|
period: 'week',
|
|
1906
2161
|
});
|
|
1907
2162
|
}
|
|
1908
2163
|
async checkOrderLimitsAndBlock(params) {
|
|
1909
2164
|
const { checkout, orderCounts, limit, period } = params;
|
|
1910
2165
|
for (const key in orderCounts) {
|
|
1911
|
-
if (orderCounts[key] >= limit) {
|
|
2166
|
+
if (orderCounts[key] >= limit[key]) {
|
|
1912
2167
|
await this.createBlockedOrderRecord({
|
|
1913
2168
|
checkout,
|
|
1914
2169
|
card: null,
|
|
@@ -2174,6 +2429,7 @@ exports.ShopPageName = void 0;
|
|
|
2174
2429
|
ShopPageName["LP_GLAMQUEENS"] = "LP_GLAMQUEENS";
|
|
2175
2430
|
ShopPageName["LP_INVITE"] = "LP_INVITE";
|
|
2176
2431
|
ShopPageName["LP_LIVELO"] = "LP_LIVELO";
|
|
2432
|
+
ShopPageName["GLAM_NEW_HOME"] = "GLAM_NEW_HOME";
|
|
2177
2433
|
})(exports.ShopPageName || (exports.ShopPageName = {}));
|
|
2178
2434
|
|
|
2179
2435
|
class BeautyQuestionsHelper {
|
|
@@ -2239,16 +2495,100 @@ class Home extends BaseModel {
|
|
|
2239
2495
|
}
|
|
2240
2496
|
}
|
|
2241
2497
|
|
|
2498
|
+
class ShopConfigs extends BaseModel {
|
|
2499
|
+
static get identifiersFields() {
|
|
2500
|
+
return ['id'];
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2242
2504
|
class ShopMenu extends BaseModel {
|
|
2243
2505
|
static get identifiersFields() {
|
|
2244
2506
|
return ['id'];
|
|
2245
2507
|
}
|
|
2246
2508
|
}
|
|
2247
2509
|
|
|
2510
|
+
var ShopPageSectionType;
|
|
2511
|
+
(function (ShopPageSectionType) {
|
|
2512
|
+
ShopPageSectionType["LIVE"] = "LIVE";
|
|
2513
|
+
ShopPageSectionType["CAROUSEL"] = "CAROUSEL";
|
|
2514
|
+
ShopPageSectionType["BANNER"] = "BANNER";
|
|
2515
|
+
ShopPageSectionType["INFOBARS"] = "INFOBARS";
|
|
2516
|
+
ShopPageSectionType["HIGHLIGHTS"] = "HIGHLIGHTS";
|
|
2517
|
+
ShopPageSectionType["SUBSCRIBER_INFO"] = "SUBSCRIBER_INFO";
|
|
2518
|
+
ShopPageSectionType["COLLECTION"] = "COLLECTION";
|
|
2519
|
+
ShopPageSectionType["BEAUTY_PROFILE_COLLECTION"] = "BEAUTY_PROFILE_COLLECTION";
|
|
2520
|
+
ShopPageSectionType["PLANS"] = "PLANS";
|
|
2521
|
+
ShopPageSectionType["SINGLE_PLAN"] = "SINGLE_PLAN";
|
|
2522
|
+
ShopPageSectionType["BRANDS"] = "BRANDS";
|
|
2523
|
+
ShopPageSectionType["NEWSLETTER"] = "NEWSLETTER";
|
|
2524
|
+
})(ShopPageSectionType || (ShopPageSectionType = {}));
|
|
2525
|
+
|
|
2526
|
+
/* eslint-disable max-lines-per-function */
|
|
2248
2527
|
class ShopSettings extends BaseModel {
|
|
2249
2528
|
static get identifiersFields() {
|
|
2250
2529
|
return ['id'];
|
|
2251
2530
|
}
|
|
2531
|
+
getPageSections(displayRules) {
|
|
2532
|
+
const now = new Date();
|
|
2533
|
+
return (Array.isArray(this.sections) ? this.sections : [])
|
|
2534
|
+
.map((section) => {
|
|
2535
|
+
// Filtra banners dentro de carrousel
|
|
2536
|
+
if (section.type === ShopPageSectionType.CAROUSEL && Array.isArray(section.banners)) {
|
|
2537
|
+
const filteredBanners = section.banners.filter((banner) => {
|
|
2538
|
+
// Filtra por displayRules
|
|
2539
|
+
const rulesMatch = banner.displayRules.length
|
|
2540
|
+
? banner.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2541
|
+
: true;
|
|
2542
|
+
// Filtra por publishDate e expirationDate
|
|
2543
|
+
const publishOk = !banner.publishDate || now >= new Date(banner.publishDate);
|
|
2544
|
+
const expireOk = !banner.expirationDate || now <= new Date(banner.expirationDate);
|
|
2545
|
+
return rulesMatch && publishOk && expireOk;
|
|
2546
|
+
});
|
|
2547
|
+
return { ...section, banners: filteredBanners };
|
|
2548
|
+
}
|
|
2549
|
+
// Filtra highlights
|
|
2550
|
+
if (section.type === ShopPageSectionType.HIGHLIGHTS && Array.isArray(section.highlights)) {
|
|
2551
|
+
const filteredHighlights = section.highlights.filter((highlight) => {
|
|
2552
|
+
// Filtra por displayRules
|
|
2553
|
+
const rulesMatch = highlight.displayRules.length
|
|
2554
|
+
? highlight.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2555
|
+
: true;
|
|
2556
|
+
return rulesMatch;
|
|
2557
|
+
});
|
|
2558
|
+
const sortedHighlights = !displayRules.beautyProfile
|
|
2559
|
+
? filteredHighlights.sort((a, b) => (a.starred === b.starred ? 0 : a.starred ? -1 : 1))
|
|
2560
|
+
: filteredHighlights;
|
|
2561
|
+
return { ...section, highlights: sortedHighlights };
|
|
2562
|
+
}
|
|
2563
|
+
// Filtra collections
|
|
2564
|
+
if (section.type === ShopPageSectionType.COLLECTION) {
|
|
2565
|
+
const rulesMatch = section.displayRules.length
|
|
2566
|
+
? section.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2567
|
+
: true;
|
|
2568
|
+
const publishOk = !section.publishDate || now >= new Date(section.publishDate);
|
|
2569
|
+
const expireOk = !section.expirationDate || now <= new Date(section.expirationDate);
|
|
2570
|
+
return rulesMatch && publishOk && expireOk ? section : null;
|
|
2571
|
+
}
|
|
2572
|
+
// Filtra banners
|
|
2573
|
+
if (section.type === ShopPageSectionType.BANNER) {
|
|
2574
|
+
const rulesMatch = section.displayRules.length
|
|
2575
|
+
? section.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2576
|
+
: true;
|
|
2577
|
+
const publishOk = !section.publishDate || now >= new Date(section.publishDate);
|
|
2578
|
+
const expireOk = !section.expirationDate || now <= new Date(section.expirationDate);
|
|
2579
|
+
return rulesMatch && publishOk && expireOk ? section : null;
|
|
2580
|
+
}
|
|
2581
|
+
if (section.type === ShopPageSectionType.LIVE) {
|
|
2582
|
+
return section.active ? section : null;
|
|
2583
|
+
}
|
|
2584
|
+
if (section.type === ShopPageSectionType.PLANS || section.type === ShopPageSectionType.SINGLE_PLAN) {
|
|
2585
|
+
return displayRules.notSubscriber ? section : null;
|
|
2586
|
+
}
|
|
2587
|
+
// Demais seções retornam normalmente
|
|
2588
|
+
return section;
|
|
2589
|
+
})
|
|
2590
|
+
.filter(Boolean);
|
|
2591
|
+
}
|
|
2252
2592
|
}
|
|
2253
2593
|
|
|
2254
2594
|
class AdyenBlockedOrderHelper {
|
|
@@ -2260,14 +2600,14 @@ class AdyenBlockedOrderHelper {
|
|
|
2260
2600
|
limiteRange: 'day',
|
|
2261
2601
|
card: params.card,
|
|
2262
2602
|
});
|
|
2263
|
-
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
|
|
2603
|
+
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', exports.ErrorsCode.paymentError, {
|
|
2264
2604
|
checkoutId: params.checkout.id,
|
|
2265
2605
|
userEmail: params.checkout.user.email,
|
|
2266
2606
|
info: params.adyenResponse,
|
|
2267
2607
|
});
|
|
2268
2608
|
}
|
|
2269
2609
|
static createPaymentError(checkout, errorInfo) {
|
|
2270
|
-
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
|
|
2610
|
+
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', exports.ErrorsCode.paymentError, {
|
|
2271
2611
|
checkoutId: checkout.id,
|
|
2272
2612
|
userEmail: checkout.user.email,
|
|
2273
2613
|
info: errorInfo,
|
|
@@ -2375,11 +2715,39 @@ class AdyenCardAxiosAdapter {
|
|
|
2375
2715
|
}
|
|
2376
2716
|
}
|
|
2377
2717
|
|
|
2718
|
+
function resolveCacheConfig(cache) {
|
|
2719
|
+
if (lodash.isNil(cache) || typeof cache !== 'object')
|
|
2720
|
+
return undefined;
|
|
2721
|
+
const candidate = cache;
|
|
2722
|
+
const cacheAdapter = candidate.cacheAdapter;
|
|
2723
|
+
if (!cacheAdapter)
|
|
2724
|
+
return undefined;
|
|
2725
|
+
if (!isCacheAdapter(cacheAdapter))
|
|
2726
|
+
return undefined;
|
|
2727
|
+
if (typeof cacheAdapter.isConfigured === 'function' && !cacheAdapter.isConfigured()) {
|
|
2728
|
+
return undefined;
|
|
2729
|
+
}
|
|
2730
|
+
return {
|
|
2731
|
+
cacheAdapter,
|
|
2732
|
+
ttlDefault: candidate.ttlDefault,
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
function isCacheAdapter(adapter) {
|
|
2736
|
+
return (typeof adapter.get === 'function' &&
|
|
2737
|
+
typeof adapter.set === 'function' &&
|
|
2738
|
+
typeof adapter.remove === 'function' &&
|
|
2739
|
+
typeof adapter.clear === 'function');
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2378
2742
|
class RestCacheAdapter {
|
|
2379
2743
|
constructor(config) {
|
|
2744
|
+
this.client = null;
|
|
2380
2745
|
this.logger = new DebugHelper('RestCacheAdapter');
|
|
2746
|
+
this.configured = this.isValidBaseURL(config.baseURL);
|
|
2747
|
+
if (!this.configured)
|
|
2748
|
+
return;
|
|
2381
2749
|
this.client = axios__default["default"].create({
|
|
2382
|
-
baseURL: config.baseURL,
|
|
2750
|
+
baseURL: config.baseURL.trim(),
|
|
2383
2751
|
headers: {
|
|
2384
2752
|
'Content-Type': 'application/json',
|
|
2385
2753
|
...(lodash.isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
|
|
@@ -2387,7 +2755,12 @@ class RestCacheAdapter {
|
|
|
2387
2755
|
},
|
|
2388
2756
|
});
|
|
2389
2757
|
}
|
|
2758
|
+
isConfigured() {
|
|
2759
|
+
return this.configured;
|
|
2760
|
+
}
|
|
2390
2761
|
async set(options) {
|
|
2762
|
+
if (!this.client)
|
|
2763
|
+
return false;
|
|
2391
2764
|
try {
|
|
2392
2765
|
const response = await this.client.post('/redis/set', {
|
|
2393
2766
|
key: options.key,
|
|
@@ -2403,6 +2776,8 @@ class RestCacheAdapter {
|
|
|
2403
2776
|
}
|
|
2404
2777
|
}
|
|
2405
2778
|
async get(key) {
|
|
2779
|
+
if (!this.client)
|
|
2780
|
+
return null;
|
|
2406
2781
|
try {
|
|
2407
2782
|
const response = await this.client.post('/redis/get', {
|
|
2408
2783
|
key,
|
|
@@ -2419,6 +2794,8 @@ class RestCacheAdapter {
|
|
|
2419
2794
|
}
|
|
2420
2795
|
}
|
|
2421
2796
|
async remove(key) {
|
|
2797
|
+
if (!this.client)
|
|
2798
|
+
return false;
|
|
2422
2799
|
try {
|
|
2423
2800
|
const response = await this.client.post('/redis/del', {
|
|
2424
2801
|
key,
|
|
@@ -2432,6 +2809,8 @@ class RestCacheAdapter {
|
|
|
2432
2809
|
}
|
|
2433
2810
|
}
|
|
2434
2811
|
async clear() {
|
|
2812
|
+
if (!this.client)
|
|
2813
|
+
return false;
|
|
2435
2814
|
try {
|
|
2436
2815
|
const response = await this.client.post('/redis/flushdb', {});
|
|
2437
2816
|
return response.data.success;
|
|
@@ -2442,6 +2821,9 @@ class RestCacheAdapter {
|
|
|
2442
2821
|
return false;
|
|
2443
2822
|
}
|
|
2444
2823
|
}
|
|
2824
|
+
isValidBaseURL(baseURL) {
|
|
2825
|
+
return lodash.isString(baseURL) && baseURL.trim().length > 0;
|
|
2826
|
+
}
|
|
2445
2827
|
}
|
|
2446
2828
|
|
|
2447
2829
|
class AxiosAdapter {
|
|
@@ -4726,6 +5108,17 @@ const withCrudFirestore = (MixinBase) => {
|
|
|
4726
5108
|
};
|
|
4727
5109
|
};
|
|
4728
5110
|
|
|
5111
|
+
class BrandCategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5112
|
+
constructor({ firestore, interceptors, }) {
|
|
5113
|
+
super({
|
|
5114
|
+
firestore,
|
|
5115
|
+
collectionName: 'brandsCategory',
|
|
5116
|
+
model: BrandCategory,
|
|
5117
|
+
interceptors,
|
|
5118
|
+
});
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
|
|
4729
5122
|
class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4730
5123
|
constructor({ firestore, interceptors }) {
|
|
4731
5124
|
super({
|
|
@@ -4801,6 +5194,9 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4801
5194
|
isChild(_id, _parentId) {
|
|
4802
5195
|
return;
|
|
4803
5196
|
}
|
|
5197
|
+
async getBrandsWithProducts() {
|
|
5198
|
+
return;
|
|
5199
|
+
}
|
|
4804
5200
|
}
|
|
4805
5201
|
tslib.__decorate([
|
|
4806
5202
|
Log(),
|
|
@@ -5014,6 +5410,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
5014
5410
|
}
|
|
5015
5411
|
}
|
|
5016
5412
|
|
|
5413
|
+
class ShopConfigsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5414
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5415
|
+
super({
|
|
5416
|
+
firestore,
|
|
5417
|
+
collectionName: 'shopConfigs',
|
|
5418
|
+
model: ShopConfigs,
|
|
5419
|
+
interceptors,
|
|
5420
|
+
cache,
|
|
5421
|
+
});
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
|
|
5017
5425
|
class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5018
5426
|
constructor({ firestore, interceptors, cache, }) {
|
|
5019
5427
|
super({
|
|
@@ -5207,6 +5615,7 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
5207
5615
|
card,
|
|
5208
5616
|
checkout,
|
|
5209
5617
|
date: new Date(),
|
|
5618
|
+
gatewayInfo: params.gatewayInfo || {},
|
|
5210
5619
|
}));
|
|
5211
5620
|
}
|
|
5212
5621
|
formatZip(zip) {
|
|
@@ -5228,6 +5637,74 @@ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
5228
5637
|
}
|
|
5229
5638
|
}
|
|
5230
5639
|
|
|
5640
|
+
class ShoppingRecurrenceEditionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5641
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5642
|
+
super({
|
|
5643
|
+
firestore,
|
|
5644
|
+
collectionName: 'shoppingRecurrenceEditions',
|
|
5645
|
+
model: ShoppingRecurrenceEdition,
|
|
5646
|
+
interceptors,
|
|
5647
|
+
cache,
|
|
5648
|
+
});
|
|
5649
|
+
}
|
|
5650
|
+
}
|
|
5651
|
+
|
|
5652
|
+
class ShoppingRecurrenceErrorLogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5653
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5654
|
+
super({
|
|
5655
|
+
firestore,
|
|
5656
|
+
collectionName: 'shoppingRecurrenceErrorLogs',
|
|
5657
|
+
model: ShoppingRecurrenceErrorLog,
|
|
5658
|
+
interceptors,
|
|
5659
|
+
cache,
|
|
5660
|
+
});
|
|
5661
|
+
}
|
|
5662
|
+
}
|
|
5663
|
+
|
|
5664
|
+
class ShoppingRecurrenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5665
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5666
|
+
super({
|
|
5667
|
+
firestore,
|
|
5668
|
+
collectionName: 'shoppingRecurrences',
|
|
5669
|
+
model: ShoppingRecurrence,
|
|
5670
|
+
interceptors,
|
|
5671
|
+
cache,
|
|
5672
|
+
});
|
|
5673
|
+
}
|
|
5674
|
+
async findByUserId(userId) {
|
|
5675
|
+
const result = await this.find({
|
|
5676
|
+
filters: {
|
|
5677
|
+
user: {
|
|
5678
|
+
id: userId,
|
|
5679
|
+
},
|
|
5680
|
+
},
|
|
5681
|
+
});
|
|
5682
|
+
return result.data;
|
|
5683
|
+
}
|
|
5684
|
+
async findByUserIdAndStatus(userId, status) {
|
|
5685
|
+
const result = await this.find({
|
|
5686
|
+
filters: {
|
|
5687
|
+
user: {
|
|
5688
|
+
id: userId,
|
|
5689
|
+
},
|
|
5690
|
+
status,
|
|
5691
|
+
},
|
|
5692
|
+
});
|
|
5693
|
+
return result.data;
|
|
5694
|
+
}
|
|
5695
|
+
async findByUserAndShop(userId, shop) {
|
|
5696
|
+
const result = await this.find({
|
|
5697
|
+
filters: {
|
|
5698
|
+
user: {
|
|
5699
|
+
id: userId,
|
|
5700
|
+
},
|
|
5701
|
+
shop,
|
|
5702
|
+
},
|
|
5703
|
+
});
|
|
5704
|
+
return result.data;
|
|
5705
|
+
}
|
|
5706
|
+
}
|
|
5707
|
+
|
|
5231
5708
|
class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5232
5709
|
constructor({ firestore, interceptors, cache, }) {
|
|
5233
5710
|
super({
|
|
@@ -5693,7 +6170,7 @@ function createHasuraGraphQLClass(MixinBase) {
|
|
|
5693
6170
|
this.model = options.model;
|
|
5694
6171
|
this.fields = options.fields || this.model.identifiersFields;
|
|
5695
6172
|
this.logger = DebugHelper.from(this);
|
|
5696
|
-
this.cache = options.cache;
|
|
6173
|
+
this.cache = resolveCacheConfig(options.cache);
|
|
5697
6174
|
}
|
|
5698
6175
|
get headers() {
|
|
5699
6176
|
return HasuraAuthHelper.buildHeaders(this.authOptions);
|
|
@@ -5811,7 +6288,10 @@ tslib.__decorate([
|
|
|
5811
6288
|
tslib.__metadata("design:type", Product)
|
|
5812
6289
|
], KitProductHasuraGraphQL.prototype, "product", void 0);
|
|
5813
6290
|
|
|
5814
|
-
class
|
|
6291
|
+
class ProductCatalogHasuraGraphQL extends Product {
|
|
6292
|
+
}
|
|
6293
|
+
|
|
6294
|
+
class ProductHasuraGraphQL extends Product {
|
|
5815
6295
|
}
|
|
5816
6296
|
tslib.__decorate([
|
|
5817
6297
|
classTransformer.Type(() => KitProductHasuraGraphQL),
|
|
@@ -5828,6 +6308,9 @@ tslib.__decorate([
|
|
|
5828
6308
|
tslib.__metadata("design:type", Object)
|
|
5829
6309
|
], ProductErrorsHasuraGraphQL.prototype, "product", void 0);
|
|
5830
6310
|
|
|
6311
|
+
class ProductStockEntryHasuraGraphQL extends ProductStockEntry {
|
|
6312
|
+
}
|
|
6313
|
+
|
|
5831
6314
|
class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5832
6315
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5833
6316
|
super({
|
|
@@ -6714,6 +7197,8 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6714
7197
|
mostRelevants: mostRelevants || {
|
|
6715
7198
|
[exports.Shops.GLAMSHOP]: null,
|
|
6716
7199
|
[exports.Shops.MENSMARKET]: null,
|
|
7200
|
+
[exports.Shops.GLAMBEAUTY]: null,
|
|
7201
|
+
[exports.Shops.ELLA]: null,
|
|
6717
7202
|
},
|
|
6718
7203
|
images: images || {
|
|
6719
7204
|
[exports.Shops.GLAMSHOP]: {
|
|
@@ -6726,6 +7211,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6726
7211
|
brandBannerMobile: null,
|
|
6727
7212
|
image: null,
|
|
6728
7213
|
},
|
|
7214
|
+
[exports.Shops.GLAMBEAUTY]: {
|
|
7215
|
+
brandBanner: null,
|
|
7216
|
+
brandBannerMobile: null,
|
|
7217
|
+
image: null,
|
|
7218
|
+
},
|
|
7219
|
+
[exports.Shops.ELLA]: {
|
|
7220
|
+
brandBanner: null,
|
|
7221
|
+
brandBannerMobile: null,
|
|
7222
|
+
image: null,
|
|
7223
|
+
},
|
|
6729
7224
|
},
|
|
6730
7225
|
});
|
|
6731
7226
|
}
|
|
@@ -6899,6 +7394,19 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6899
7394
|
categoryFilterRepository: this.categoryFilterRepository,
|
|
6900
7395
|
});
|
|
6901
7396
|
}
|
|
7397
|
+
async getBrandsWithProducts() {
|
|
7398
|
+
const fields = ['id', 'name', 'slug', 'brand_category', 'published', 'images'];
|
|
7399
|
+
const { brands_with_products_query: data, } = await this.query('brands_with_products_query', fields);
|
|
7400
|
+
return data.map((brand) => Category.toInstance({
|
|
7401
|
+
id: brand.id,
|
|
7402
|
+
name: brand.name,
|
|
7403
|
+
slug: brand.slug,
|
|
7404
|
+
brandCategory: brand.brand_category,
|
|
7405
|
+
shops: brand.shops,
|
|
7406
|
+
published: brand.published,
|
|
7407
|
+
images: brand.images,
|
|
7408
|
+
}));
|
|
7409
|
+
}
|
|
6902
7410
|
}
|
|
6903
7411
|
tslib.__decorate([
|
|
6904
7412
|
Log(),
|
|
@@ -7013,6 +7521,26 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
|
|
|
7013
7521
|
},
|
|
7014
7522
|
});
|
|
7015
7523
|
}
|
|
7524
|
+
async removeProductFromAllCategories(productId) {
|
|
7525
|
+
this.logger = DebugHelper.from(this, 'removeProductFromAllCategories');
|
|
7526
|
+
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
7527
|
+
where: {
|
|
7528
|
+
type: 'category_product_bool_exp',
|
|
7529
|
+
required: true,
|
|
7530
|
+
value: { product_id: { _eq: productId } },
|
|
7531
|
+
},
|
|
7532
|
+
});
|
|
7533
|
+
}
|
|
7534
|
+
async removeCategoryFromAllProducts(categoryId) {
|
|
7535
|
+
this.logger = DebugHelper.from(this, 'removeCategoryFromAllProducts');
|
|
7536
|
+
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
7537
|
+
where: {
|
|
7538
|
+
type: 'category_product_bool_exp',
|
|
7539
|
+
required: true,
|
|
7540
|
+
value: { category_id: { _eq: categoryId } },
|
|
7541
|
+
},
|
|
7542
|
+
});
|
|
7543
|
+
}
|
|
7016
7544
|
}
|
|
7017
7545
|
|
|
7018
7546
|
const fieldsConfiguration$3 = [
|
|
@@ -7163,83 +7691,7 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
|
|
|
7163
7691
|
}
|
|
7164
7692
|
}
|
|
7165
7693
|
|
|
7166
|
-
|
|
7167
|
-
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
7168
|
-
super({
|
|
7169
|
-
tableName: 'product_errors',
|
|
7170
|
-
model: ProductErrorsHasuraGraphQL,
|
|
7171
|
-
endpoint,
|
|
7172
|
-
authOptions,
|
|
7173
|
-
interceptors,
|
|
7174
|
-
cache,
|
|
7175
|
-
fields: [
|
|
7176
|
-
{
|
|
7177
|
-
productId: {
|
|
7178
|
-
columnName: 'product_id',
|
|
7179
|
-
to: (value) => +value,
|
|
7180
|
-
from: (value) => value.toString(),
|
|
7181
|
-
},
|
|
7182
|
-
},
|
|
7183
|
-
'source',
|
|
7184
|
-
'error',
|
|
7185
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7186
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7187
|
-
{
|
|
7188
|
-
product: {
|
|
7189
|
-
columnName: 'product',
|
|
7190
|
-
foreignKeyColumn: { id: 'productId' },
|
|
7191
|
-
fields: [
|
|
7192
|
-
{ id: { columnName: 'id', from: (value) => value.toString() } },
|
|
7193
|
-
{ productId: { columnName: 'main_product_id' } },
|
|
7194
|
-
'name',
|
|
7195
|
-
'published',
|
|
7196
|
-
'group',
|
|
7197
|
-
'validity',
|
|
7198
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7199
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7200
|
-
],
|
|
7201
|
-
},
|
|
7202
|
-
},
|
|
7203
|
-
],
|
|
7204
|
-
});
|
|
7205
|
-
this.productRepository = productRepository;
|
|
7206
|
-
}
|
|
7207
|
-
async get(params) {
|
|
7208
|
-
const result = await super.get(params);
|
|
7209
|
-
if (result instanceof VariantHasuraGraphQL) {
|
|
7210
|
-
const product = await this.productRepository.get({ id: result.productId.toString() });
|
|
7211
|
-
result.product.name = product.name;
|
|
7212
|
-
result.product.group = product.group;
|
|
7213
|
-
}
|
|
7214
|
-
return result;
|
|
7215
|
-
}
|
|
7216
|
-
async find(params) {
|
|
7217
|
-
const result = await super.find(params);
|
|
7218
|
-
const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
|
|
7219
|
-
(lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
|
|
7220
|
-
if (variantsWithNoData.length > 0) {
|
|
7221
|
-
const { data: products } = await this.productRepository.find({
|
|
7222
|
-
filters: {
|
|
7223
|
-
id: {
|
|
7224
|
-
operator: exports.Where.IN,
|
|
7225
|
-
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
7226
|
-
},
|
|
7227
|
-
},
|
|
7228
|
-
});
|
|
7229
|
-
products.forEach((product) => {
|
|
7230
|
-
result.data
|
|
7231
|
-
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
7232
|
-
.forEach((variant) => {
|
|
7233
|
-
variant.product.name = product.name;
|
|
7234
|
-
variant.product.group = product.group;
|
|
7235
|
-
});
|
|
7236
|
-
});
|
|
7237
|
-
}
|
|
7238
|
-
return result;
|
|
7239
|
-
}
|
|
7240
|
-
}
|
|
7241
|
-
|
|
7242
|
-
const commonFields = [
|
|
7694
|
+
const commonFields$1 = [
|
|
7243
7695
|
{
|
|
7244
7696
|
id: {
|
|
7245
7697
|
columnName: 'id',
|
|
@@ -7319,6 +7771,12 @@ const commonFields = [
|
|
|
7319
7771
|
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7320
7772
|
},
|
|
7321
7773
|
},
|
|
7774
|
+
{
|
|
7775
|
+
imagesCard: {
|
|
7776
|
+
columnName: 'images_card',
|
|
7777
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7778
|
+
},
|
|
7779
|
+
},
|
|
7322
7780
|
'name',
|
|
7323
7781
|
{
|
|
7324
7782
|
price: {
|
|
@@ -7380,7 +7838,6 @@ const commonFields = [
|
|
|
7380
7838
|
'weight',
|
|
7381
7839
|
'gender',
|
|
7382
7840
|
{ intGender: { columnName: 'int_gender' } },
|
|
7383
|
-
// { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7384
7841
|
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7385
7842
|
{ isKit: { columnName: 'is_kit' } },
|
|
7386
7843
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -7397,151 +7854,707 @@ const commonFields = [
|
|
|
7397
7854
|
},
|
|
7398
7855
|
},
|
|
7399
7856
|
'group',
|
|
7857
|
+
{ groupId: { columnName: 'group_id' } },
|
|
7400
7858
|
'validity',
|
|
7401
7859
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7402
7860
|
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7403
7861
|
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7862
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
7863
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7404
7864
|
];
|
|
7405
|
-
|
|
7406
|
-
...commonFields,
|
|
7407
|
-
{
|
|
7408
|
-
categories: {
|
|
7409
|
-
columnName: 'categories',
|
|
7410
|
-
fields: ['category_id'],
|
|
7411
|
-
bindPersistData: (value) => ({
|
|
7412
|
-
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
7413
|
-
}),
|
|
7414
|
-
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
7415
|
-
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
7416
|
-
},
|
|
7417
|
-
},
|
|
7418
|
-
{
|
|
7419
|
-
kitProducts: {
|
|
7420
|
-
columnName: 'kit_products',
|
|
7421
|
-
foreignKeyColumn: { productId: 'id' },
|
|
7422
|
-
fields: [
|
|
7423
|
-
{ productId: { columnName: 'product_id' } },
|
|
7424
|
-
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
7425
|
-
'quantity',
|
|
7426
|
-
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
7427
|
-
],
|
|
7428
|
-
},
|
|
7429
|
-
},
|
|
7430
|
-
{
|
|
7431
|
-
reviews: {
|
|
7432
|
-
columnName: 'reviews',
|
|
7433
|
-
foreignKeyColumn: { product_id: 'id' },
|
|
7434
|
-
fields: [
|
|
7435
|
-
'id',
|
|
7436
|
-
'shop',
|
|
7437
|
-
'rate',
|
|
7438
|
-
'author',
|
|
7439
|
-
'email',
|
|
7440
|
-
'location',
|
|
7441
|
-
'review',
|
|
7442
|
-
'status',
|
|
7443
|
-
'title',
|
|
7444
|
-
{ personId: { columnName: 'person_id' } },
|
|
7445
|
-
'points',
|
|
7446
|
-
{ orderId: { columnName: 'order_id' } },
|
|
7447
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7448
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7449
|
-
],
|
|
7450
|
-
},
|
|
7451
|
-
},
|
|
7452
|
-
{
|
|
7453
|
-
metadata: {
|
|
7454
|
-
columnName: 'metadata',
|
|
7455
|
-
fields: ['title', 'description'],
|
|
7456
|
-
bindPersistData: (value) => ({
|
|
7457
|
-
metadata: { data: value },
|
|
7458
|
-
}),
|
|
7459
|
-
},
|
|
7460
|
-
},
|
|
7461
|
-
{
|
|
7462
|
-
variants: {
|
|
7463
|
-
columnName: 'variants',
|
|
7464
|
-
foreignKeyColumn: { product_id: 'id' },
|
|
7465
|
-
fields: [
|
|
7466
|
-
'id',
|
|
7467
|
-
'ean',
|
|
7468
|
-
'grade',
|
|
7469
|
-
'price',
|
|
7470
|
-
'published',
|
|
7471
|
-
'stock',
|
|
7472
|
-
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
7473
|
-
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7474
|
-
],
|
|
7475
|
-
},
|
|
7476
|
-
},
|
|
7477
|
-
];
|
|
7478
|
-
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7479
|
-
get reviewsFields() {
|
|
7480
|
-
return [
|
|
7481
|
-
'id',
|
|
7482
|
-
'shop',
|
|
7483
|
-
'rate',
|
|
7484
|
-
'author',
|
|
7485
|
-
'email',
|
|
7486
|
-
'location',
|
|
7487
|
-
'review',
|
|
7488
|
-
'status',
|
|
7489
|
-
'title',
|
|
7490
|
-
{ personId: { columnName: 'person_id' } },
|
|
7491
|
-
'points',
|
|
7492
|
-
{ orderId: { columnName: 'order_id' } },
|
|
7493
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7494
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7495
|
-
];
|
|
7496
|
-
}
|
|
7865
|
+
class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7497
7866
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7498
7867
|
super({
|
|
7499
|
-
tableName: '
|
|
7500
|
-
model:
|
|
7868
|
+
tableName: 'product_catalog',
|
|
7869
|
+
model: ProductCatalogHasuraGraphQL,
|
|
7501
7870
|
endpoint,
|
|
7502
7871
|
authOptions,
|
|
7503
7872
|
interceptors,
|
|
7504
|
-
fields:
|
|
7873
|
+
fields: commonFields$1,
|
|
7505
7874
|
cache,
|
|
7506
7875
|
});
|
|
7507
|
-
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
7508
|
-
...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
7509
|
-
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
7510
|
-
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
7511
|
-
personId: plain.person_id,
|
|
7512
|
-
orderId: plain.order_id,
|
|
7513
|
-
});
|
|
7514
|
-
this.bindReviewToHasura = (review) => ({
|
|
7515
|
-
...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
7516
|
-
person_id: review.personId,
|
|
7517
|
-
order_id: review.orderId,
|
|
7518
|
-
});
|
|
7519
7876
|
}
|
|
7520
|
-
async
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7877
|
+
async get({ id }, options) {
|
|
7878
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7879
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7880
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7881
|
+
if (cachedData) {
|
|
7882
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7883
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7884
|
+
}
|
|
7525
7885
|
}
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7886
|
+
const product = await super
|
|
7887
|
+
.find({
|
|
7888
|
+
filters: {
|
|
7889
|
+
id,
|
|
7890
|
+
},
|
|
7891
|
+
limits: {
|
|
7892
|
+
limit: 1,
|
|
7893
|
+
},
|
|
7894
|
+
})
|
|
7895
|
+
.then((res) => res.data.at(0));
|
|
7896
|
+
if (!product)
|
|
7897
|
+
throw new NotFoundError(`Product not found`);
|
|
7898
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7899
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7900
|
+
await this.cache.cacheAdapter.set({
|
|
7901
|
+
key: cacheKey,
|
|
7902
|
+
data: serialize(product),
|
|
7903
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7904
|
+
});
|
|
7905
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7529
7906
|
}
|
|
7530
7907
|
return product;
|
|
7531
7908
|
}
|
|
7532
|
-
async
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7909
|
+
async getByEAN(EAN, options) {
|
|
7910
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7911
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7912
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7913
|
+
if (cachedData) {
|
|
7914
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7915
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
const product = await super
|
|
7919
|
+
.find({
|
|
7920
|
+
filters: {
|
|
7921
|
+
EAN,
|
|
7922
|
+
},
|
|
7923
|
+
limits: {
|
|
7924
|
+
limit: 1,
|
|
7925
|
+
},
|
|
7926
|
+
})
|
|
7927
|
+
.then((res) => res.data.at(0));
|
|
7928
|
+
if (!product)
|
|
7929
|
+
return null;
|
|
7930
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
7931
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7932
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7933
|
+
await this.cache.cacheAdapter.set({
|
|
7934
|
+
key: cacheKey,
|
|
7935
|
+
data: serialize(product),
|
|
7936
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7937
|
+
});
|
|
7938
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7939
|
+
}
|
|
7940
|
+
return product;
|
|
7941
|
+
}
|
|
7942
|
+
async find(params, optionsParams) {
|
|
7943
|
+
const { filters, fields, ...options } = params || {};
|
|
7944
|
+
const bindFields = fields ||
|
|
7945
|
+
this.fields
|
|
7946
|
+
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7947
|
+
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7948
|
+
if (options.options?.minimal?.includes('price'))
|
|
7949
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7950
|
+
if (options.options?.maximum?.includes('price'))
|
|
7951
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7952
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7953
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7954
|
+
return super.find({
|
|
7955
|
+
...options,
|
|
7956
|
+
filters: { ...filters },
|
|
7957
|
+
fields: [
|
|
7958
|
+
...bindFields,
|
|
7959
|
+
...(bindFields.includes('price')
|
|
7960
|
+
? [
|
|
7961
|
+
'subscriberPrice',
|
|
7962
|
+
'subscriberDiscountPercentage',
|
|
7963
|
+
'fullPrice',
|
|
7964
|
+
]
|
|
7965
|
+
: []),
|
|
7966
|
+
],
|
|
7967
|
+
}, optionsParams);
|
|
7968
|
+
}
|
|
7969
|
+
async findCatalog(params, mainGender, options) {
|
|
7970
|
+
const result = await this.find({
|
|
7971
|
+
...params,
|
|
7972
|
+
filters: { ...params.filters, published: true },
|
|
7973
|
+
orderBy: {
|
|
7974
|
+
hasStock: 'desc',
|
|
7975
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7976
|
+
...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7977
|
+
},
|
|
7978
|
+
}, options);
|
|
7979
|
+
return result;
|
|
7980
|
+
}
|
|
7981
|
+
}
|
|
7982
|
+
tslib.__decorate([
|
|
7983
|
+
Log(),
|
|
7984
|
+
tslib.__metadata("design:type", Function),
|
|
7985
|
+
tslib.__metadata("design:paramtypes", [Object, Object, Object]),
|
|
7986
|
+
tslib.__metadata("design:returntype", Promise)
|
|
7987
|
+
], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
|
|
7988
|
+
|
|
7989
|
+
class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7990
|
+
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
7991
|
+
super({
|
|
7992
|
+
tableName: 'product_errors',
|
|
7993
|
+
model: ProductErrorsHasuraGraphQL,
|
|
7994
|
+
endpoint,
|
|
7995
|
+
authOptions,
|
|
7996
|
+
interceptors,
|
|
7997
|
+
cache,
|
|
7998
|
+
fields: [
|
|
7999
|
+
{
|
|
8000
|
+
productId: {
|
|
8001
|
+
columnName: 'product_id',
|
|
8002
|
+
to: (value) => +value,
|
|
8003
|
+
from: (value) => value.toString(),
|
|
8004
|
+
},
|
|
8005
|
+
},
|
|
8006
|
+
'source',
|
|
8007
|
+
'error',
|
|
8008
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8009
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8010
|
+
{
|
|
8011
|
+
product: {
|
|
8012
|
+
columnName: 'product',
|
|
8013
|
+
foreignKeyColumn: { id: 'productId' },
|
|
8014
|
+
fields: [
|
|
8015
|
+
{ id: { columnName: 'id', from: (value) => value.toString() } },
|
|
8016
|
+
{ productId: { columnName: 'main_product_id' } },
|
|
8017
|
+
'name',
|
|
8018
|
+
'published',
|
|
8019
|
+
'group',
|
|
8020
|
+
'validity',
|
|
8021
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8022
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8023
|
+
],
|
|
8024
|
+
},
|
|
8025
|
+
},
|
|
8026
|
+
],
|
|
8027
|
+
});
|
|
8028
|
+
this.productRepository = productRepository;
|
|
8029
|
+
}
|
|
8030
|
+
async get(params) {
|
|
8031
|
+
const result = await super.get(params);
|
|
8032
|
+
if (result instanceof VariantHasuraGraphQL) {
|
|
8033
|
+
const product = await this.productRepository.get({ id: result.productId.toString() });
|
|
8034
|
+
result.product.name = product.name;
|
|
8035
|
+
result.product.group = product.group;
|
|
8036
|
+
}
|
|
8037
|
+
return result;
|
|
8038
|
+
}
|
|
8039
|
+
async find(params) {
|
|
8040
|
+
const result = await super.find(params);
|
|
8041
|
+
const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
|
|
8042
|
+
(lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
|
|
8043
|
+
if (variantsWithNoData.length > 0) {
|
|
8044
|
+
const { data: products } = await this.productRepository.find({
|
|
8045
|
+
filters: {
|
|
8046
|
+
id: {
|
|
8047
|
+
operator: exports.Where.IN,
|
|
8048
|
+
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
8049
|
+
},
|
|
8050
|
+
},
|
|
8051
|
+
});
|
|
8052
|
+
products.forEach((product) => {
|
|
8053
|
+
result.data
|
|
8054
|
+
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
8055
|
+
.forEach((variant) => {
|
|
8056
|
+
variant.product.name = product.name;
|
|
8057
|
+
variant.product.group = product.group;
|
|
8058
|
+
});
|
|
8059
|
+
});
|
|
8060
|
+
}
|
|
8061
|
+
return result;
|
|
8062
|
+
}
|
|
8063
|
+
}
|
|
8064
|
+
|
|
8065
|
+
class ProductGroupHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8066
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
8067
|
+
super({
|
|
8068
|
+
tableName: 'group',
|
|
8069
|
+
model: ProductGroup,
|
|
8070
|
+
endpoint,
|
|
8071
|
+
authOptions,
|
|
8072
|
+
interceptors,
|
|
8073
|
+
fields: [
|
|
8074
|
+
{
|
|
8075
|
+
id: {
|
|
8076
|
+
columnName: 'id',
|
|
8077
|
+
to: (value) => +value,
|
|
8078
|
+
from: (value) => value.toString(),
|
|
8079
|
+
},
|
|
8080
|
+
},
|
|
8081
|
+
'name',
|
|
8082
|
+
'description',
|
|
8083
|
+
{ markupMin: { columnName: 'markup_min' } },
|
|
8084
|
+
{ markupWithoutCompetitor: { columnName: 'markup_without_competitor' } },
|
|
8085
|
+
{ discountCompetitor: { columnName: 'discount_competitor' } },
|
|
8086
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
8087
|
+
{ dynamicPrecification: { columnName: 'dynamic_precification' } },
|
|
8088
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8089
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8090
|
+
],
|
|
8091
|
+
cache,
|
|
8092
|
+
});
|
|
8093
|
+
}
|
|
8094
|
+
}
|
|
8095
|
+
|
|
8096
|
+
const commonFields = [
|
|
8097
|
+
{
|
|
8098
|
+
id: {
|
|
8099
|
+
columnName: 'id',
|
|
8100
|
+
to: (value) => +value,
|
|
8101
|
+
from: (value) => value.toString(),
|
|
8102
|
+
},
|
|
8103
|
+
},
|
|
8104
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
8105
|
+
{ productId: { columnName: 'main_product_id' } },
|
|
8106
|
+
{ CEST: { columnName: 'cest' } },
|
|
8107
|
+
{ EAN: { columnName: 'ean' } },
|
|
8108
|
+
{ NCM: { columnName: 'ncm' } },
|
|
8109
|
+
'brand',
|
|
8110
|
+
{ costPrice: { columnName: 'cost_price' } },
|
|
8111
|
+
{
|
|
8112
|
+
description: {
|
|
8113
|
+
columnName: 'description',
|
|
8114
|
+
from: (description, data) => ({
|
|
8115
|
+
description,
|
|
8116
|
+
differentials: data.differentials,
|
|
8117
|
+
whoMustUse: data.who_must_use,
|
|
8118
|
+
howToUse: data.how_to_use,
|
|
8119
|
+
brand: data.brand_description,
|
|
8120
|
+
ingredients: data.ingredients,
|
|
8121
|
+
purpose: data.purpose,
|
|
8122
|
+
}),
|
|
8123
|
+
bindFindFilter: (filters) => {
|
|
8124
|
+
return {
|
|
8125
|
+
...(filters?.description && { description: filters.description }),
|
|
8126
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
8127
|
+
...(filters.whoMustUse && {
|
|
8128
|
+
who_must_use: filters.whoMustUse,
|
|
8129
|
+
}),
|
|
8130
|
+
...(filters.howToUse && {
|
|
8131
|
+
how_to_use: filters.howToUse,
|
|
8132
|
+
}),
|
|
8133
|
+
...(filters.brand && {
|
|
8134
|
+
brand_description: filters.brand,
|
|
8135
|
+
}),
|
|
8136
|
+
...(filters.ingredients && {
|
|
8137
|
+
ingredients: filters.ingredients,
|
|
8138
|
+
}),
|
|
8139
|
+
...(filters.purpose && {
|
|
8140
|
+
purpose: filters.purpose,
|
|
8141
|
+
}),
|
|
8142
|
+
};
|
|
8143
|
+
},
|
|
8144
|
+
bindPersistData: (descriptionData) => ({
|
|
8145
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
8146
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
8147
|
+
...(descriptionData.whoMustUse && {
|
|
8148
|
+
who_must_use: descriptionData.whoMustUse,
|
|
8149
|
+
}),
|
|
8150
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
8151
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
8152
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
8153
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
8154
|
+
}),
|
|
8155
|
+
},
|
|
8156
|
+
},
|
|
8157
|
+
{ differentials: { columnName: 'differentials' } },
|
|
8158
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
8159
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
8160
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
8161
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
8162
|
+
{ purpose: { columnName: 'purpose' } },
|
|
8163
|
+
{ hasVariants: { columnName: 'has_variants' } },
|
|
8164
|
+
{
|
|
8165
|
+
images: {
|
|
8166
|
+
columnName: 'images',
|
|
8167
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8168
|
+
},
|
|
8169
|
+
},
|
|
8170
|
+
{
|
|
8171
|
+
miniatures: {
|
|
8172
|
+
columnName: 'miniatures',
|
|
8173
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8174
|
+
},
|
|
8175
|
+
},
|
|
8176
|
+
{
|
|
8177
|
+
imagesCard: {
|
|
8178
|
+
columnName: 'images_card',
|
|
8179
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8180
|
+
},
|
|
8181
|
+
},
|
|
8182
|
+
'name',
|
|
8183
|
+
{
|
|
8184
|
+
price: {
|
|
8185
|
+
columnName: 'price',
|
|
8186
|
+
from: (price, data) => ({
|
|
8187
|
+
price,
|
|
8188
|
+
fullPrice: data.full_price,
|
|
8189
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
8190
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
8191
|
+
subscriberPrice: data.subscriber_price,
|
|
8192
|
+
}),
|
|
8193
|
+
bindFindFilter: (filters) => {
|
|
8194
|
+
return {
|
|
8195
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
8196
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
8197
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
8198
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
8199
|
+
}),
|
|
8200
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
8201
|
+
subscriber_price: filters.subscriberPrice,
|
|
8202
|
+
}),
|
|
8203
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
8204
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
8205
|
+
}),
|
|
8206
|
+
};
|
|
8207
|
+
},
|
|
8208
|
+
bindPersistData: (priceData) => ({
|
|
8209
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
8210
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
8211
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
8212
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8213
|
+
}),
|
|
8214
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8215
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8216
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8217
|
+
}),
|
|
8218
|
+
}),
|
|
8219
|
+
},
|
|
8220
|
+
},
|
|
8221
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
8222
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
8223
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
8224
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
8225
|
+
'published',
|
|
8226
|
+
'outlet',
|
|
8227
|
+
'label',
|
|
8228
|
+
'sku',
|
|
8229
|
+
{
|
|
8230
|
+
stock: {
|
|
8231
|
+
columnName: 'stock',
|
|
8232
|
+
from: (quantity) => ({ quantity }),
|
|
8233
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
8234
|
+
},
|
|
8235
|
+
},
|
|
8236
|
+
{ hasStock: { columnName: 'has_stock' } },
|
|
8237
|
+
'slug',
|
|
8238
|
+
'type',
|
|
8239
|
+
'video',
|
|
8240
|
+
'weight',
|
|
8241
|
+
'gender',
|
|
8242
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
8243
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8244
|
+
{ isKit: { columnName: 'is_kit' } },
|
|
8245
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8246
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8247
|
+
{ rate: { columnName: 'rating' } },
|
|
8248
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
8249
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
8250
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
8251
|
+
{
|
|
8252
|
+
category: {
|
|
8253
|
+
columnName: 'category',
|
|
8254
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
8255
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
8256
|
+
},
|
|
8257
|
+
},
|
|
8258
|
+
'group',
|
|
8259
|
+
{ groupId: { columnName: 'group_id' } },
|
|
8260
|
+
'validity',
|
|
8261
|
+
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8262
|
+
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8263
|
+
{ tagsSupply: { columnName: 'tags_supply', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8264
|
+
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
8265
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
8266
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8267
|
+
{ caixariaMinima: { columnName: 'caixaria_minima', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8268
|
+
'suppliers',
|
|
8269
|
+
'curve',
|
|
8270
|
+
];
|
|
8271
|
+
const fieldsConfiguration$2 = [
|
|
8272
|
+
...commonFields,
|
|
8273
|
+
{
|
|
8274
|
+
categories: {
|
|
8275
|
+
columnName: 'categories',
|
|
8276
|
+
fields: ['category_id'],
|
|
8277
|
+
bindPersistData: (value) => ({
|
|
8278
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
8279
|
+
}),
|
|
8280
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
8281
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
8282
|
+
},
|
|
8283
|
+
},
|
|
8284
|
+
{
|
|
8285
|
+
kitProducts: {
|
|
8286
|
+
columnName: 'kit_products',
|
|
8287
|
+
foreignKeyColumn: { productId: 'id' },
|
|
8288
|
+
fields: [
|
|
8289
|
+
{ productId: { columnName: 'product_id' } },
|
|
8290
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
8291
|
+
'quantity',
|
|
8292
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
8293
|
+
],
|
|
8294
|
+
},
|
|
8295
|
+
},
|
|
8296
|
+
{
|
|
8297
|
+
reviews: {
|
|
8298
|
+
columnName: 'reviews',
|
|
8299
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8300
|
+
fields: [
|
|
8301
|
+
'id',
|
|
8302
|
+
'shop',
|
|
8303
|
+
'rate',
|
|
8304
|
+
'author',
|
|
8305
|
+
'email',
|
|
8306
|
+
'location',
|
|
8307
|
+
'review',
|
|
8308
|
+
'status',
|
|
8309
|
+
'title',
|
|
8310
|
+
{ personId: { columnName: 'person_id' } },
|
|
8311
|
+
'points',
|
|
8312
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8313
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8314
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8315
|
+
],
|
|
8316
|
+
},
|
|
8317
|
+
},
|
|
8318
|
+
{
|
|
8319
|
+
metadata: {
|
|
8320
|
+
columnName: 'metadata',
|
|
8321
|
+
fields: ['title', 'description'],
|
|
8322
|
+
bindPersistData: (value) => ({
|
|
8323
|
+
metadata: { data: value },
|
|
8324
|
+
}),
|
|
8325
|
+
},
|
|
8326
|
+
},
|
|
8327
|
+
{
|
|
8328
|
+
variants: {
|
|
8329
|
+
columnName: 'variants',
|
|
8330
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8331
|
+
fields: [
|
|
8332
|
+
'id',
|
|
8333
|
+
'name',
|
|
8334
|
+
'ean',
|
|
8335
|
+
'sku',
|
|
8336
|
+
{
|
|
8337
|
+
description: {
|
|
8338
|
+
columnName: 'description',
|
|
8339
|
+
from: (description, data) => ({
|
|
8340
|
+
description,
|
|
8341
|
+
differentials: data.differentials,
|
|
8342
|
+
whoMustUse: data.who_must_use,
|
|
8343
|
+
howToUse: data.how_to_use,
|
|
8344
|
+
brand: data.brand_description,
|
|
8345
|
+
ingredients: data.ingredients,
|
|
8346
|
+
purpose: data.purpose,
|
|
8347
|
+
}),
|
|
8348
|
+
bindFindFilter: (filters) => {
|
|
8349
|
+
return {
|
|
8350
|
+
...(filters?.description && { description: filters.description }),
|
|
8351
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
8352
|
+
...(filters.whoMustUse && {
|
|
8353
|
+
who_must_use: filters.whoMustUse,
|
|
8354
|
+
}),
|
|
8355
|
+
...(filters.howToUse && {
|
|
8356
|
+
how_to_use: filters.howToUse,
|
|
8357
|
+
}),
|
|
8358
|
+
...(filters.brand && {
|
|
8359
|
+
brand_description: filters.brand,
|
|
8360
|
+
}),
|
|
8361
|
+
...(filters.ingredients && {
|
|
8362
|
+
ingredients: filters.ingredients,
|
|
8363
|
+
}),
|
|
8364
|
+
...(filters.purpose && {
|
|
8365
|
+
purpose: filters.purpose,
|
|
8366
|
+
}),
|
|
8367
|
+
};
|
|
8368
|
+
},
|
|
8369
|
+
bindPersistData: (descriptionData) => ({
|
|
8370
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
8371
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
8372
|
+
...(descriptionData.whoMustUse && {
|
|
8373
|
+
who_must_use: descriptionData.whoMustUse,
|
|
8374
|
+
}),
|
|
8375
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
8376
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
8377
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
8378
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
8379
|
+
}),
|
|
8380
|
+
},
|
|
8381
|
+
},
|
|
8382
|
+
{ differentials: { columnName: 'differentials' } },
|
|
8383
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
8384
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
8385
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
8386
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
8387
|
+
{ purpose: { columnName: 'purpose' } },
|
|
8388
|
+
{
|
|
8389
|
+
grade: {
|
|
8390
|
+
columnName: 'grade',
|
|
8391
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
8392
|
+
},
|
|
8393
|
+
},
|
|
8394
|
+
{
|
|
8395
|
+
price: {
|
|
8396
|
+
columnName: 'price',
|
|
8397
|
+
from: (price, data) => ({
|
|
8398
|
+
price,
|
|
8399
|
+
fullPrice: data.full_price,
|
|
8400
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
8401
|
+
subscriberPrice: data.subscriber_price,
|
|
8402
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
8403
|
+
}),
|
|
8404
|
+
bindPersistData: (priceData) => ({
|
|
8405
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
8406
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
8407
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
8408
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8409
|
+
}),
|
|
8410
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8411
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8412
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8413
|
+
}),
|
|
8414
|
+
}),
|
|
8415
|
+
},
|
|
8416
|
+
},
|
|
8417
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
8418
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
8419
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
8420
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
8421
|
+
'published',
|
|
8422
|
+
{
|
|
8423
|
+
stock: {
|
|
8424
|
+
columnName: 'stock',
|
|
8425
|
+
from: (quantity) => ({ quantity }),
|
|
8426
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
8427
|
+
},
|
|
8428
|
+
},
|
|
8429
|
+
{
|
|
8430
|
+
images: {
|
|
8431
|
+
columnName: 'images',
|
|
8432
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8433
|
+
},
|
|
8434
|
+
},
|
|
8435
|
+
{
|
|
8436
|
+
miniatures: {
|
|
8437
|
+
columnName: 'miniatures',
|
|
8438
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8439
|
+
},
|
|
8440
|
+
},
|
|
8441
|
+
{
|
|
8442
|
+
imagesCard: {
|
|
8443
|
+
columnName: 'images_card',
|
|
8444
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8445
|
+
},
|
|
8446
|
+
},
|
|
8447
|
+
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
8448
|
+
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
8449
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8450
|
+
{
|
|
8451
|
+
reviews: {
|
|
8452
|
+
columnName: 'reviews',
|
|
8453
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8454
|
+
fields: [
|
|
8455
|
+
'id',
|
|
8456
|
+
'shop',
|
|
8457
|
+
'rate',
|
|
8458
|
+
'author',
|
|
8459
|
+
'email',
|
|
8460
|
+
'location',
|
|
8461
|
+
'review',
|
|
8462
|
+
'status',
|
|
8463
|
+
'title',
|
|
8464
|
+
{ personId: { columnName: 'person_id' } },
|
|
8465
|
+
'points',
|
|
8466
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8467
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8468
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8469
|
+
],
|
|
8470
|
+
},
|
|
8471
|
+
},
|
|
8472
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8473
|
+
{
|
|
8474
|
+
metadata: {
|
|
8475
|
+
columnName: 'metadata',
|
|
8476
|
+
fields: ['title', 'description'],
|
|
8477
|
+
bindPersistData: (value) => ({
|
|
8478
|
+
metadata: { data: value },
|
|
8479
|
+
}),
|
|
8480
|
+
},
|
|
8481
|
+
},
|
|
8482
|
+
],
|
|
8483
|
+
},
|
|
8484
|
+
},
|
|
8485
|
+
];
|
|
8486
|
+
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8487
|
+
get reviewsFields() {
|
|
8488
|
+
return [
|
|
8489
|
+
'id',
|
|
8490
|
+
'shop',
|
|
8491
|
+
'rate',
|
|
8492
|
+
'author',
|
|
8493
|
+
'email',
|
|
8494
|
+
'location',
|
|
8495
|
+
'review',
|
|
8496
|
+
'status',
|
|
8497
|
+
'title',
|
|
8498
|
+
{ personId: { columnName: 'person_id' } },
|
|
8499
|
+
'points',
|
|
8500
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8501
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8502
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8503
|
+
];
|
|
8504
|
+
}
|
|
8505
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
8506
|
+
super({
|
|
8507
|
+
tableName: 'product',
|
|
8508
|
+
model: ProductHasuraGraphQL,
|
|
8509
|
+
endpoint,
|
|
8510
|
+
authOptions,
|
|
8511
|
+
interceptors,
|
|
8512
|
+
fields: fieldsConfiguration$2,
|
|
8513
|
+
cache,
|
|
8514
|
+
});
|
|
8515
|
+
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
8516
|
+
...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
8517
|
+
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
8518
|
+
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
8519
|
+
personId: plain.person_id,
|
|
8520
|
+
orderId: plain.order_id,
|
|
8521
|
+
});
|
|
8522
|
+
this.bindReviewToHasura = (review) => ({
|
|
8523
|
+
...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
8524
|
+
person_id: review.personId,
|
|
8525
|
+
order_id: review.orderId,
|
|
8526
|
+
});
|
|
8527
|
+
}
|
|
8528
|
+
async create(params) {
|
|
8529
|
+
const { metadata, ...data } = params;
|
|
8530
|
+
const product = await super.create(lodash.omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
8531
|
+
try {
|
|
8532
|
+
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
8533
|
+
}
|
|
8534
|
+
catch (error) {
|
|
8535
|
+
await this.delete({ id: product.id });
|
|
8536
|
+
throw error;
|
|
8537
|
+
}
|
|
8538
|
+
return product;
|
|
8539
|
+
}
|
|
8540
|
+
async get(identifiers, options) {
|
|
8541
|
+
const product = Number.isNaN(+identifiers.id)
|
|
8542
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
8543
|
+
.data?.[0]
|
|
8544
|
+
: await super.get(identifiers, options);
|
|
8545
|
+
if (product.productId)
|
|
8546
|
+
throw new NotFoundError('Product not found, it is a variant');
|
|
8547
|
+
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
|
|
8548
|
+
if (!product.variants?.length) {
|
|
8549
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8550
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8551
|
+
}
|
|
8552
|
+
}
|
|
8553
|
+
return product;
|
|
8554
|
+
}
|
|
8555
|
+
async find(params, optionsParams) {
|
|
8556
|
+
const { filters, fields, ...options } = params || {};
|
|
8557
|
+
const bindFields = fields ||
|
|
7545
8558
|
this.fields
|
|
7546
8559
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7547
8560
|
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
@@ -7578,6 +8591,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7578
8591
|
const result = await this.find({
|
|
7579
8592
|
filters: {
|
|
7580
8593
|
slug,
|
|
8594
|
+
productId: {
|
|
8595
|
+
operator: exports.Where.ISNULL,
|
|
8596
|
+
},
|
|
7581
8597
|
},
|
|
7582
8598
|
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
7583
8599
|
options: {
|
|
@@ -7587,6 +8603,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7587
8603
|
if (!result.data.length)
|
|
7588
8604
|
return null;
|
|
7589
8605
|
const product = result?.data?.shift();
|
|
8606
|
+
if (!product.variants?.length) {
|
|
8607
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8608
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8609
|
+
}
|
|
8610
|
+
}
|
|
7590
8611
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7591
8612
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7592
8613
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
@@ -7766,7 +8787,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7766
8787
|
const plainData = this.paramsToPlain({ metadata });
|
|
7767
8788
|
if (!plainData.metadata)
|
|
7768
8789
|
return null;
|
|
7769
|
-
|
|
8790
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8791
|
+
const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
7770
8792
|
pk_columns: {
|
|
7771
8793
|
value: { product_id: productId },
|
|
7772
8794
|
type: 'product_metadata_pk_columns_input',
|
|
@@ -7778,6 +8800,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7778
8800
|
required: true,
|
|
7779
8801
|
},
|
|
7780
8802
|
});
|
|
8803
|
+
if (!update_product_metadata_by_pk) {
|
|
8804
|
+
await this.mutation('insert_product_metadata', ['affected_rows'], {
|
|
8805
|
+
objects: {
|
|
8806
|
+
type: '[product_metadata_insert_input!]!',
|
|
8807
|
+
value: [{ product_id: productId, ...metadata }],
|
|
8808
|
+
},
|
|
8809
|
+
});
|
|
8810
|
+
}
|
|
7781
8811
|
return plainData.metadata;
|
|
7782
8812
|
}
|
|
7783
8813
|
async getId(id) {
|
|
@@ -7788,7 +8818,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7788
8818
|
return data?.[0]?.id;
|
|
7789
8819
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7790
8820
|
}
|
|
7791
|
-
async findReviewsByProduct(productId, options) {
|
|
8821
|
+
async findReviewsByProduct(productId, onlyApproved, options) {
|
|
7792
8822
|
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7793
8823
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7794
8824
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
@@ -7801,10 +8831,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7801
8831
|
where: {
|
|
7802
8832
|
value: {
|
|
7803
8833
|
product_id: { _eq: productId },
|
|
8834
|
+
...(onlyApproved && { status: { _eq: true } }),
|
|
7804
8835
|
},
|
|
7805
8836
|
type: 'product_review_bool_exp',
|
|
7806
8837
|
required: true,
|
|
7807
8838
|
},
|
|
8839
|
+
order_by: {
|
|
8840
|
+
type: '[product_review_order_by]',
|
|
8841
|
+
value: [{ createdAt: 'desc' }],
|
|
8842
|
+
required: true,
|
|
8843
|
+
},
|
|
7808
8844
|
});
|
|
7809
8845
|
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7810
8846
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
@@ -7909,10 +8945,53 @@ tslib.__decorate([
|
|
|
7909
8945
|
tslib.__decorate([
|
|
7910
8946
|
Log(),
|
|
7911
8947
|
tslib.__metadata("design:type", Function),
|
|
7912
|
-
tslib.__metadata("design:paramtypes", [Number, Object]),
|
|
8948
|
+
tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
|
|
7913
8949
|
tslib.__metadata("design:returntype", Promise)
|
|
7914
8950
|
], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
|
|
7915
8951
|
|
|
8952
|
+
class ProductPriceLogHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8953
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
8954
|
+
super({
|
|
8955
|
+
tableName: 'product_price_log',
|
|
8956
|
+
model: ProductPriceLog,
|
|
8957
|
+
endpoint,
|
|
8958
|
+
authOptions,
|
|
8959
|
+
interceptors,
|
|
8960
|
+
fields: [
|
|
8961
|
+
{
|
|
8962
|
+
id: {
|
|
8963
|
+
columnName: 'id',
|
|
8964
|
+
to: (value) => +value,
|
|
8965
|
+
from: (value) => value.toString(),
|
|
8966
|
+
},
|
|
8967
|
+
},
|
|
8968
|
+
{ productId: { columnName: 'product_id' } },
|
|
8969
|
+
{ productEAN: { columnName: 'product_ean' } },
|
|
8970
|
+
{ productSKU: { columnName: 'product_sku' } },
|
|
8971
|
+
{ productName: { columnName: 'product_name' } },
|
|
8972
|
+
{ productCostPrice: { columnName: 'product_cost_price' } },
|
|
8973
|
+
{ productPrice: { columnName: 'product_price' } },
|
|
8974
|
+
{ productSubscriberPrice: { columnName: 'product_subscriber_price' } },
|
|
8975
|
+
{ productSubscriberDiscountPercentage: { columnName: 'product_subscriber_discount_percentage' } },
|
|
8976
|
+
{ markupMin: { columnName: 'markup_min' } },
|
|
8977
|
+
{ markupWithoutCompetitor: { columnName: 'markup_without_competitor' } },
|
|
8978
|
+
{ discountCompetitor: { columnName: 'discount_competitor' } },
|
|
8979
|
+
{ minViablePrice: { columnName: 'min_viable_price' } },
|
|
8980
|
+
{ targetPrice: { columnName: 'target_price' } },
|
|
8981
|
+
{ groupId: { columnName: 'group_id' } },
|
|
8982
|
+
{ competitorsAndPrices: { columnName: 'competitors_and_prices', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8983
|
+
{ competitorsPrices: { columnName: 'competitors_prices', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8984
|
+
{ competitorsMinPrice: { columnName: 'competitors_min_price' } },
|
|
8985
|
+
{ competitorsSellerMinPrice: { columnName: 'competitors_seller_min_price' } },
|
|
8986
|
+
{ statusPrecificacao: { columnName: 'status_precificacao' } },
|
|
8987
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8988
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8989
|
+
],
|
|
8990
|
+
cache,
|
|
8991
|
+
});
|
|
8992
|
+
}
|
|
8993
|
+
}
|
|
8994
|
+
|
|
7916
8995
|
class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7917
8996
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7918
8997
|
super({
|
|
@@ -7941,7 +9020,25 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7941
9020
|
product: {
|
|
7942
9021
|
columnName: 'product',
|
|
7943
9022
|
foreignKeyColumn: { id: 'productId' },
|
|
7944
|
-
fields: [
|
|
9023
|
+
fields: [
|
|
9024
|
+
'id',
|
|
9025
|
+
{
|
|
9026
|
+
productId: {
|
|
9027
|
+
columnName: 'main_product_id',
|
|
9028
|
+
to: (value) => +value,
|
|
9029
|
+
from: (value) => value?.toString(),
|
|
9030
|
+
},
|
|
9031
|
+
},
|
|
9032
|
+
'ean',
|
|
9033
|
+
'sku',
|
|
9034
|
+
'name',
|
|
9035
|
+
'brand',
|
|
9036
|
+
'slug',
|
|
9037
|
+
'images',
|
|
9038
|
+
'grade',
|
|
9039
|
+
'gender',
|
|
9040
|
+
'',
|
|
9041
|
+
],
|
|
7945
9042
|
},
|
|
7946
9043
|
},
|
|
7947
9044
|
],
|
|
@@ -7986,6 +9083,33 @@ tslib.__decorate([
|
|
|
7986
9083
|
tslib.__metadata("design:returntype", void 0)
|
|
7987
9084
|
], ProductReviewHasuraGraphQLRepository.prototype, "disaproveReview", null);
|
|
7988
9085
|
|
|
9086
|
+
class ProductStockEntryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
9087
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
9088
|
+
super({
|
|
9089
|
+
tableName: 'product_millenium_stock_entry',
|
|
9090
|
+
model: ProductStockEntry,
|
|
9091
|
+
endpoint,
|
|
9092
|
+
authOptions,
|
|
9093
|
+
interceptors,
|
|
9094
|
+
cache,
|
|
9095
|
+
fields: [
|
|
9096
|
+
'id',
|
|
9097
|
+
{ productId: { columnName: 'product_id' } },
|
|
9098
|
+
{ codProduct: { columnName: 'cod_product' } },
|
|
9099
|
+
{ productDescription: { columnName: 'product_description' } },
|
|
9100
|
+
{ eventDescription: { columnName: 'event_description' } },
|
|
9101
|
+
{ invoiceValue: { columnName: 'invoice_value' } },
|
|
9102
|
+
'price',
|
|
9103
|
+
'quantity',
|
|
9104
|
+
{ invoiceId: { columnName: 'invoice_id' } },
|
|
9105
|
+
{ nfeKey: { columnName: 'nfe_key' } },
|
|
9106
|
+
'batch',
|
|
9107
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
9108
|
+
],
|
|
9109
|
+
});
|
|
9110
|
+
}
|
|
9111
|
+
}
|
|
9112
|
+
|
|
7989
9113
|
class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7990
9114
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7991
9115
|
super({
|
|
@@ -8134,12 +9258,153 @@ const fieldsConfiguration$1 = [
|
|
|
8134
9258
|
},
|
|
8135
9259
|
},
|
|
8136
9260
|
'group',
|
|
9261
|
+
{ groupId: { columnName: 'group_id' } },
|
|
9262
|
+
'type',
|
|
8137
9263
|
'validity',
|
|
8138
|
-
// { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8139
9264
|
'published',
|
|
8140
9265
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8141
9266
|
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
9267
|
+
{ tagsSupply: { columnName: 'tags_supply', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8142
9268
|
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
9269
|
+
{
|
|
9270
|
+
images: {
|
|
9271
|
+
columnName: 'images',
|
|
9272
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
9273
|
+
},
|
|
9274
|
+
},
|
|
9275
|
+
{
|
|
9276
|
+
miniatures: {
|
|
9277
|
+
columnName: 'miniatures',
|
|
9278
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
9279
|
+
},
|
|
9280
|
+
},
|
|
9281
|
+
{
|
|
9282
|
+
imagesCard: {
|
|
9283
|
+
columnName: 'images_card',
|
|
9284
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
9285
|
+
},
|
|
9286
|
+
},
|
|
9287
|
+
'slug',
|
|
9288
|
+
'brand',
|
|
9289
|
+
'name',
|
|
9290
|
+
'sku',
|
|
9291
|
+
{ NCM: { columnName: 'ncm' } },
|
|
9292
|
+
{ CEST: { columnName: 'cest' } },
|
|
9293
|
+
{
|
|
9294
|
+
description: {
|
|
9295
|
+
columnName: 'description',
|
|
9296
|
+
from: (description, data) => ({
|
|
9297
|
+
description,
|
|
9298
|
+
differentials: data.differentials,
|
|
9299
|
+
whoMustUse: data.who_must_use,
|
|
9300
|
+
howToUse: data.how_to_use,
|
|
9301
|
+
brand: data.brand_description,
|
|
9302
|
+
ingredients: data.ingredients,
|
|
9303
|
+
purpose: data.purpose,
|
|
9304
|
+
}),
|
|
9305
|
+
bindFindFilter: (filters) => {
|
|
9306
|
+
return {
|
|
9307
|
+
...(filters?.description && { description: filters.description }),
|
|
9308
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
9309
|
+
...(filters.whoMustUse && {
|
|
9310
|
+
who_must_use: filters.whoMustUse,
|
|
9311
|
+
}),
|
|
9312
|
+
...(filters.howToUse && {
|
|
9313
|
+
how_to_use: filters.howToUse,
|
|
9314
|
+
}),
|
|
9315
|
+
...(filters.brand && {
|
|
9316
|
+
brand_description: filters.brand,
|
|
9317
|
+
}),
|
|
9318
|
+
...(filters.ingredients && {
|
|
9319
|
+
ingredients: filters.ingredients,
|
|
9320
|
+
}),
|
|
9321
|
+
...(filters.purpose && {
|
|
9322
|
+
purpose: filters.purpose,
|
|
9323
|
+
}),
|
|
9324
|
+
};
|
|
9325
|
+
},
|
|
9326
|
+
bindPersistData: (descriptionData) => ({
|
|
9327
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
9328
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
9329
|
+
...(descriptionData.whoMustUse && {
|
|
9330
|
+
who_must_use: descriptionData.whoMustUse,
|
|
9331
|
+
}),
|
|
9332
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
9333
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
9334
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
9335
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
9336
|
+
}),
|
|
9337
|
+
},
|
|
9338
|
+
},
|
|
9339
|
+
{ differentials: { columnName: 'differentials' } },
|
|
9340
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
9341
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
9342
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
9343
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
9344
|
+
{ purpose: { columnName: 'purpose' } },
|
|
9345
|
+
'gender',
|
|
9346
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
9347
|
+
'label',
|
|
9348
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
9349
|
+
{ rate: { columnName: 'rating' } },
|
|
9350
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
9351
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
9352
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
9353
|
+
{
|
|
9354
|
+
category: {
|
|
9355
|
+
columnName: 'category',
|
|
9356
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
9357
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
9358
|
+
},
|
|
9359
|
+
},
|
|
9360
|
+
{
|
|
9361
|
+
categories: {
|
|
9362
|
+
columnName: 'categories',
|
|
9363
|
+
fields: ['category_id'],
|
|
9364
|
+
bindPersistData: (value) => ({
|
|
9365
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
9366
|
+
}),
|
|
9367
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
9368
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
9369
|
+
},
|
|
9370
|
+
},
|
|
9371
|
+
{
|
|
9372
|
+
metadata: {
|
|
9373
|
+
columnName: 'metadata',
|
|
9374
|
+
fields: ['title', 'description'],
|
|
9375
|
+
bindPersistData: (value) => ({
|
|
9376
|
+
metadata: { data: value },
|
|
9377
|
+
}),
|
|
9378
|
+
},
|
|
9379
|
+
},
|
|
9380
|
+
{
|
|
9381
|
+
reviews: {
|
|
9382
|
+
columnName: 'reviews',
|
|
9383
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
9384
|
+
fields: [
|
|
9385
|
+
'id',
|
|
9386
|
+
'shop',
|
|
9387
|
+
'rate',
|
|
9388
|
+
'author',
|
|
9389
|
+
'email',
|
|
9390
|
+
'location',
|
|
9391
|
+
'review',
|
|
9392
|
+
'status',
|
|
9393
|
+
'title',
|
|
9394
|
+
{ personId: { columnName: 'person_id' } },
|
|
9395
|
+
'points',
|
|
9396
|
+
{ orderId: { columnName: 'order_id' } },
|
|
9397
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
9398
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
9399
|
+
],
|
|
9400
|
+
},
|
|
9401
|
+
},
|
|
9402
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
9403
|
+
{ caixariaMinima: { columnName: 'caixaria_minima', type: HasuraGraphQLColumnType.Jsonb } },
|
|
9404
|
+
'suppliers',
|
|
9405
|
+
'curve',
|
|
9406
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
9407
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8143
9408
|
];
|
|
8144
9409
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8145
9410
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
@@ -8180,17 +9445,45 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8180
9445
|
return data.at(0);
|
|
8181
9446
|
}
|
|
8182
9447
|
async update(params) {
|
|
8183
|
-
const { productId, id: checkId, ...data } = params;
|
|
9448
|
+
const { productId, id: checkId, metadata, ...data } = params;
|
|
8184
9449
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
8185
9450
|
if (!dataWithProductId.id) {
|
|
8186
9451
|
throw new NotFoundError('Variant ID is required for update');
|
|
8187
9452
|
}
|
|
8188
9453
|
const id = await this.getId(dataWithProductId.id);
|
|
8189
9454
|
const product = await super.update({ id, ...data });
|
|
9455
|
+
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
8190
9456
|
if (dataWithProductId.productId) {
|
|
8191
9457
|
product.productId = dataWithProductId.productId;
|
|
8192
9458
|
}
|
|
8193
|
-
return product;
|
|
9459
|
+
return product;
|
|
9460
|
+
}
|
|
9461
|
+
async updateMetadata(productId, { metadata }) {
|
|
9462
|
+
const plainData = this.paramsToPlain({ metadata });
|
|
9463
|
+
if (!plainData.metadata)
|
|
9464
|
+
return null;
|
|
9465
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9466
|
+
const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
9467
|
+
pk_columns: {
|
|
9468
|
+
value: { product_id: productId },
|
|
9469
|
+
type: 'product_metadata_pk_columns_input',
|
|
9470
|
+
required: true,
|
|
9471
|
+
},
|
|
9472
|
+
_set: {
|
|
9473
|
+
value: lodash.omit(metadata, ['product_id']),
|
|
9474
|
+
type: 'product_metadata_set_input',
|
|
9475
|
+
required: true,
|
|
9476
|
+
},
|
|
9477
|
+
});
|
|
9478
|
+
if (!update_product_metadata_by_pk) {
|
|
9479
|
+
await this.mutation('insert_product_metadata', ['affected_rows'], {
|
|
9480
|
+
objects: {
|
|
9481
|
+
type: '[product_metadata_insert_input!]!',
|
|
9482
|
+
value: [{ product_id: productId, ...metadata }],
|
|
9483
|
+
},
|
|
9484
|
+
});
|
|
9485
|
+
}
|
|
9486
|
+
return plainData.metadata;
|
|
8194
9487
|
}
|
|
8195
9488
|
async getId(id) {
|
|
8196
9489
|
if (!Number.isNaN(+id))
|
|
@@ -8413,124 +9706,670 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8413
9706
|
async getCategoryBySlug(slug, _shop) {
|
|
8414
9707
|
return this.getWishlistBySlug(slug);
|
|
8415
9708
|
}
|
|
8416
|
-
async getCategoryByShop(shop) {
|
|
8417
|
-
if (!shop)
|
|
8418
|
-
return;
|
|
8419
|
-
const { data } = await this.find({
|
|
8420
|
-
filters: {
|
|
8421
|
-
shops: { operator: exports.Where.IN, value: [shop] },
|
|
8422
|
-
published: { operator: exports.Where.EQUALS, value: true },
|
|
8423
|
-
isWishlist: { operator: exports.Where.EQUALS, value: true },
|
|
8424
|
-
},
|
|
8425
|
-
options: {
|
|
8426
|
-
enableCount: false,
|
|
9709
|
+
async getCategoryByShop(shop) {
|
|
9710
|
+
if (!shop)
|
|
9711
|
+
return;
|
|
9712
|
+
const { data } = await this.find({
|
|
9713
|
+
filters: {
|
|
9714
|
+
shops: { operator: exports.Where.IN, value: [shop] },
|
|
9715
|
+
published: { operator: exports.Where.EQUALS, value: true },
|
|
9716
|
+
isWishlist: { operator: exports.Where.EQUALS, value: true },
|
|
9717
|
+
},
|
|
9718
|
+
options: {
|
|
9719
|
+
enableCount: false,
|
|
9720
|
+
},
|
|
9721
|
+
});
|
|
9722
|
+
return data;
|
|
9723
|
+
}
|
|
9724
|
+
async findBfluOrGlamgirlWishlists(params, shops) {
|
|
9725
|
+
return this.find({
|
|
9726
|
+
...params,
|
|
9727
|
+
filters: {
|
|
9728
|
+
...params.filters,
|
|
9729
|
+
published: true,
|
|
9730
|
+
shops: { operator: exports.Where.LIKE, value: shops },
|
|
9731
|
+
personType: params.filters?.personType ?? {
|
|
9732
|
+
operator: exports.Where.IN,
|
|
9733
|
+
value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
|
|
9734
|
+
},
|
|
9735
|
+
},
|
|
9736
|
+
orderBy: {
|
|
9737
|
+
personHasPhoto: 'desc',
|
|
9738
|
+
...lodash.omit(params.orderBy, ['personHasPhoto']),
|
|
9739
|
+
},
|
|
9740
|
+
});
|
|
9741
|
+
}
|
|
9742
|
+
getCategoriesForHome() {
|
|
9743
|
+
return;
|
|
9744
|
+
}
|
|
9745
|
+
mountCategory() {
|
|
9746
|
+
return;
|
|
9747
|
+
}
|
|
9748
|
+
getChildren(_parentId) {
|
|
9749
|
+
return;
|
|
9750
|
+
}
|
|
9751
|
+
isChild(_id, _parentId) {
|
|
9752
|
+
return;
|
|
9753
|
+
}
|
|
9754
|
+
async updateMetadata(categoryId, { metadatas }) {
|
|
9755
|
+
if (Array.isArray(metadatas) && !metadatas.length)
|
|
9756
|
+
return [];
|
|
9757
|
+
if (Array.isArray(metadatas) && metadatas.length) {
|
|
9758
|
+
const metadataUpdated = [];
|
|
9759
|
+
for (const data of metadatas) {
|
|
9760
|
+
const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
|
|
9761
|
+
pk_columns: {
|
|
9762
|
+
value: { category_id: categoryId, shop: data.shop },
|
|
9763
|
+
type: 'category_metadata_pk_columns_input',
|
|
9764
|
+
required: true,
|
|
9765
|
+
},
|
|
9766
|
+
_set: {
|
|
9767
|
+
value: lodash.omit(data, ['category_id', 'shop']),
|
|
9768
|
+
type: 'category_metadata_set_input',
|
|
9769
|
+
required: true,
|
|
9770
|
+
},
|
|
9771
|
+
});
|
|
9772
|
+
metadataUpdated.push(update);
|
|
9773
|
+
}
|
|
9774
|
+
return metadataUpdated;
|
|
9775
|
+
}
|
|
9776
|
+
if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
|
|
9777
|
+
for (let i = 0; i < metadatas.value.length; i++) {
|
|
9778
|
+
await this.mutation('delete_category_metadata', ['affected_rows'], {
|
|
9779
|
+
where: {
|
|
9780
|
+
type: 'category_metadata_bool_exp',
|
|
9781
|
+
required: true,
|
|
9782
|
+
value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
|
|
9783
|
+
},
|
|
9784
|
+
});
|
|
9785
|
+
}
|
|
9786
|
+
return [];
|
|
9787
|
+
}
|
|
9788
|
+
}
|
|
9789
|
+
async addProduct(wishlistId, productId) {
|
|
9790
|
+
await this.categoryProductRepository.create({
|
|
9791
|
+
categoryId: +wishlistId,
|
|
9792
|
+
productId: +productId,
|
|
9793
|
+
order: 0,
|
|
9794
|
+
});
|
|
9795
|
+
}
|
|
9796
|
+
async removeProduct(wishlistId, productId) {
|
|
9797
|
+
return this.categoryProductRepository.delete({
|
|
9798
|
+
categoryId: +wishlistId,
|
|
9799
|
+
productId: +productId,
|
|
9800
|
+
});
|
|
9801
|
+
}
|
|
9802
|
+
async getBrandsWithProducts() {
|
|
9803
|
+
return;
|
|
9804
|
+
}
|
|
9805
|
+
}
|
|
9806
|
+
tslib.__decorate([
|
|
9807
|
+
Log(),
|
|
9808
|
+
tslib.__metadata("design:type", Function),
|
|
9809
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
9810
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9811
|
+
], WishlistHasuraGraphQLRepository.prototype, "getWishlistBySlug", null);
|
|
9812
|
+
tslib.__decorate([
|
|
9813
|
+
Log(),
|
|
9814
|
+
tslib.__metadata("design:type", Function),
|
|
9815
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
9816
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9817
|
+
], WishlistHasuraGraphQLRepository.prototype, "getWishlistByPerson", null);
|
|
9818
|
+
tslib.__decorate([
|
|
9819
|
+
Log(),
|
|
9820
|
+
tslib.__metadata("design:type", Function),
|
|
9821
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
9822
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9823
|
+
], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
|
|
9824
|
+
tslib.__decorate([
|
|
9825
|
+
Log(),
|
|
9826
|
+
tslib.__metadata("design:type", Function),
|
|
9827
|
+
tslib.__metadata("design:paramtypes", [Object, Array]),
|
|
9828
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9829
|
+
], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
|
|
9830
|
+
|
|
9831
|
+
class MercadoPagoErrorHelper {
|
|
9832
|
+
static getErrorTypeFromResponse(errorCode) {
|
|
9833
|
+
switch (errorCode) {
|
|
9834
|
+
case 'bad_filled_card_data':
|
|
9835
|
+
case 'invalid_card_token':
|
|
9836
|
+
case 'card_disabled':
|
|
9837
|
+
case 'cc_rejected_card_disabled':
|
|
9838
|
+
case 'cc_rejected_bad_filled_card_number':
|
|
9839
|
+
case 'cc_rejected_bad_filled_date':
|
|
9840
|
+
case 'cc_rejected_bad_filled_other':
|
|
9841
|
+
case 'cc_rejected_bad_filled_security_code':
|
|
9842
|
+
return exports.ErrorsCode.invalidCardError;
|
|
9843
|
+
case 'high_risk':
|
|
9844
|
+
case 'rejected_high_risk':
|
|
9845
|
+
case 'cc_rejected_blacklist':
|
|
9846
|
+
case 'cc_rejected_call_for_authorize':
|
|
9847
|
+
case 'cc_rejected_high_risk':
|
|
9848
|
+
return exports.ErrorsCode.fraudPreventionExternal;
|
|
9849
|
+
case 'rejected_by_issuer':
|
|
9850
|
+
case 'rejected_by_bank':
|
|
9851
|
+
case 'cc_rejected_max_attempts':
|
|
9852
|
+
case 'required_call_for_authorize':
|
|
9853
|
+
case 'max_attempts_exceeded':
|
|
9854
|
+
return exports.ErrorsCode.paymentNotAuthorizedError;
|
|
9855
|
+
case 'insufficient_amount':
|
|
9856
|
+
case 'amount_limit_exceeded':
|
|
9857
|
+
case 'cc_rejected_insufficient_amount':
|
|
9858
|
+
return exports.ErrorsCode.insufficientFundsError;
|
|
9859
|
+
case 'processing_error':
|
|
9860
|
+
return exports.ErrorsCode.paymentError;
|
|
9861
|
+
case 'invalid_installments':
|
|
9862
|
+
case 'cc_rejected_invalid_installments':
|
|
9863
|
+
case 'cc_rejected_other_reason':
|
|
9864
|
+
case 'rejected_insufficient_data':
|
|
9865
|
+
return exports.ErrorsCode.businessError;
|
|
9866
|
+
default:
|
|
9867
|
+
return exports.ErrorsCode.paymentError;
|
|
9868
|
+
}
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9871
|
+
|
|
9872
|
+
class MercadoPagoRequestHelper {
|
|
9873
|
+
static build(data) {
|
|
9874
|
+
const { checkout, method, postback, card } = data;
|
|
9875
|
+
return {
|
|
9876
|
+
transaction_amount: +checkout.totalPrice.toFixed(2),
|
|
9877
|
+
notification_url: postback,
|
|
9878
|
+
metadata: {
|
|
9879
|
+
checkoutId: checkout.id,
|
|
9880
|
+
},
|
|
9881
|
+
payer: this.buildPayer(checkout, card),
|
|
9882
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'loja glam' : 'mens market',
|
|
9883
|
+
additional_info: {
|
|
9884
|
+
items: this.buildItems(checkout),
|
|
9885
|
+
},
|
|
9886
|
+
...(method === 'credit_card' && this.buildCardPayment(card)),
|
|
9887
|
+
...(method === 'pix' && this.buildPixPayment()),
|
|
9888
|
+
...(method === 'boleto' && this.buildBoletoPayment(checkout)),
|
|
9889
|
+
};
|
|
9890
|
+
}
|
|
9891
|
+
static buildItems(checkout) {
|
|
9892
|
+
return checkout.lineItems
|
|
9893
|
+
.filter((item) => !item.isGift)
|
|
9894
|
+
.map((item) => {
|
|
9895
|
+
return {
|
|
9896
|
+
id: item.EAN,
|
|
9897
|
+
title: item.name,
|
|
9898
|
+
description: item.name,
|
|
9899
|
+
picture_url: item.image ?? null,
|
|
9900
|
+
category_id: item.category?.id ?? null,
|
|
9901
|
+
quantity: item.quantity,
|
|
9902
|
+
unit_price: +item.pricePaid.toFixed(2),
|
|
9903
|
+
};
|
|
9904
|
+
});
|
|
9905
|
+
}
|
|
9906
|
+
static buildPayer(checkout, card) {
|
|
9907
|
+
return {
|
|
9908
|
+
...(card && { id: card.customerId }),
|
|
9909
|
+
first_name: checkout.user.firstName,
|
|
9910
|
+
last_name: checkout.user.lastName,
|
|
9911
|
+
email: checkout.user.email,
|
|
9912
|
+
identification: {
|
|
9913
|
+
type: 'CPF',
|
|
9914
|
+
number: checkout.user.cpf.replace(/\D/g, ''),
|
|
9915
|
+
},
|
|
9916
|
+
};
|
|
9917
|
+
}
|
|
9918
|
+
static buildFullPayer(checkout) {
|
|
9919
|
+
return {
|
|
9920
|
+
first_name: checkout.user.firstName,
|
|
9921
|
+
last_name: checkout.user.lastName,
|
|
9922
|
+
phone: {
|
|
9923
|
+
area_code: checkout.user.phone.substring(0, 2),
|
|
9924
|
+
number: checkout.user.phone.substring(2),
|
|
9925
|
+
},
|
|
9926
|
+
address: {
|
|
9927
|
+
zip_code: checkout.shippingAddress.zip,
|
|
9928
|
+
street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
9929
|
+
street_number: checkout.shippingAddress.number,
|
|
9930
|
+
neighborhood: checkout.shippingAddress.district,
|
|
9931
|
+
city: checkout.shippingAddress.city,
|
|
9932
|
+
federal_unit: checkout.shippingAddress.state,
|
|
9933
|
+
},
|
|
9934
|
+
};
|
|
9935
|
+
}
|
|
9936
|
+
static buildCardPayment(card) {
|
|
9937
|
+
return {
|
|
9938
|
+
installments: card.installments,
|
|
9939
|
+
token: card.cardId,
|
|
9940
|
+
binary_mode: true,
|
|
9941
|
+
capture: true,
|
|
9942
|
+
};
|
|
9943
|
+
}
|
|
9944
|
+
static buildPixPayment() {
|
|
9945
|
+
return {
|
|
9946
|
+
payment_method_id: 'pix',
|
|
9947
|
+
date_of_expiration: dateFns.format(dateFns.addHours(new Date(), 24), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"),
|
|
9948
|
+
};
|
|
9949
|
+
}
|
|
9950
|
+
static buildBoletoPayment(checkout) {
|
|
9951
|
+
return {
|
|
9952
|
+
payment_method_id: 'bolbradesco',
|
|
9953
|
+
date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
|
|
9954
|
+
payer: {
|
|
9955
|
+
first_name: checkout.user.firstName,
|
|
9956
|
+
last_name: checkout.user.lastName,
|
|
9957
|
+
email: checkout.user.email,
|
|
9958
|
+
identification: {
|
|
9959
|
+
type: 'CPF',
|
|
9960
|
+
number: checkout.user.cpf.replace(/\D/g, ''),
|
|
9961
|
+
},
|
|
9962
|
+
phone: {
|
|
9963
|
+
area_code: checkout.user.phone.substring(0, 2),
|
|
9964
|
+
number: checkout.user.phone.substring(2),
|
|
9965
|
+
},
|
|
9966
|
+
address: {
|
|
9967
|
+
zip_code: checkout.shippingAddress.zip.replace(/\D/g, ''),
|
|
9968
|
+
street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
9969
|
+
street_number: checkout.shippingAddress.number,
|
|
9970
|
+
neighborhood: checkout.shippingAddress.district,
|
|
9971
|
+
city: checkout.shippingAddress.city,
|
|
9972
|
+
federal_unit: checkout.shippingAddress.state,
|
|
9973
|
+
},
|
|
9974
|
+
},
|
|
9975
|
+
};
|
|
9976
|
+
}
|
|
9977
|
+
}
|
|
9978
|
+
|
|
9979
|
+
class MercadoPagoResponseHelper {
|
|
9980
|
+
static build(method, checkout, response) {
|
|
9981
|
+
return Payment.toInstance({
|
|
9982
|
+
createdAt: new Date(),
|
|
9983
|
+
updatedAt: new Date(),
|
|
9984
|
+
userId: checkout.user.id,
|
|
9985
|
+
checkoutId: checkout.id,
|
|
9986
|
+
totalPrice: checkout.totalPrice,
|
|
9987
|
+
paymentProvider: exports.PaymentProviders.MERCADOPAGO,
|
|
9988
|
+
mercadoPagoId: response.id,
|
|
9989
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
9990
|
+
});
|
|
9991
|
+
}
|
|
9992
|
+
static buildPaymentTransaction(method, response) {
|
|
9993
|
+
return PaymentTransaction.toInstance({
|
|
9994
|
+
id: response.id.toString(),
|
|
9995
|
+
acquirer_name: exports.PaymentProviders.MERCADOPAGO,
|
|
9996
|
+
amount: response.transaction_amount,
|
|
9997
|
+
status: this.statusMapping(response.status),
|
|
9998
|
+
status_reason: response.status_detail?.toString(),
|
|
9999
|
+
payment_method: method,
|
|
10000
|
+
currency: response.currency_id?.toString(),
|
|
10001
|
+
paid_amount: response.transaction_details?.total_paid_amount ?? null,
|
|
10002
|
+
paid_at: response.date_approved ?? null,
|
|
10003
|
+
charger_id: response.charges_details?.at(0)?.id?.toString() ?? null,
|
|
10004
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(response)),
|
|
10005
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(response)),
|
|
10006
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(response)),
|
|
10007
|
+
});
|
|
10008
|
+
}
|
|
10009
|
+
static getBoletoReponse(response) {
|
|
10010
|
+
return {
|
|
10011
|
+
boleto_url: response.transaction_details?.external_resource_url?.toString(),
|
|
10012
|
+
boleto_barcode: response.transaction_details?.barcode?.content?.toString(),
|
|
10013
|
+
boleto_line: response.transaction_details?.digitable_line?.toString(),
|
|
10014
|
+
boleto_expiration_date: response.date_of_expiration?.toString(),
|
|
10015
|
+
boleto_document_number: response.transaction_details?.verification_code?.toString(),
|
|
10016
|
+
};
|
|
10017
|
+
}
|
|
10018
|
+
static getPixReponse(response) {
|
|
10019
|
+
return {
|
|
10020
|
+
pix_qr_code: response.point_of_interaction?.transaction_data?.qr_code,
|
|
10021
|
+
pix_expiration_date: response.date_of_expiration?.toString(),
|
|
10022
|
+
};
|
|
10023
|
+
}
|
|
10024
|
+
static getCardReponse(response) {
|
|
10025
|
+
return {
|
|
10026
|
+
soft_descriptor: response.statement_descriptor?.toString(),
|
|
10027
|
+
installments: response.installments,
|
|
10028
|
+
card_brand: response.payment_method_id?.toString(),
|
|
10029
|
+
card_first_digits: response.card?.first_six_digits?.toString(),
|
|
10030
|
+
card_last_digits: response.card?.last_four_digits?.toString(),
|
|
10031
|
+
card_id: response.card?.id?.toString(),
|
|
10032
|
+
card_holder_name: response.card?.cardholder?.name?.toString(),
|
|
10033
|
+
card_expiration_month: response.card?.expiration_month?.toString(),
|
|
10034
|
+
card_expiration_year: response.card?.expiration_year?.toString(),
|
|
10035
|
+
capture_method: response.payment_type_id?.toString(),
|
|
10036
|
+
authorization_code: response.authorization_code?.toString(),
|
|
10037
|
+
paid_amount: this.statusMapping(response.status) == 'paid' ? response.transaction_details?.total_paid_amount : null,
|
|
10038
|
+
paid_at: this.statusMapping(response.status) == 'paid' ? response.date_approved : null,
|
|
10039
|
+
};
|
|
10040
|
+
}
|
|
10041
|
+
static statusMapping(status) {
|
|
10042
|
+
const statusMap = {
|
|
10043
|
+
approved: 'paid',
|
|
10044
|
+
pending: 'waiting_payment',
|
|
10045
|
+
in_process: 'processing',
|
|
10046
|
+
rejected: 'refused',
|
|
10047
|
+
cancelled: 'refused',
|
|
10048
|
+
refunded: 'refunded',
|
|
10049
|
+
charged_back: 'chargedback',
|
|
10050
|
+
};
|
|
10051
|
+
return statusMap[status] || status;
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
|
|
10055
|
+
class MercadoPagoBankSlipAxiosAdapter {
|
|
10056
|
+
constructor(credentials, paymentRepository) {
|
|
10057
|
+
this.credentials = credentials;
|
|
10058
|
+
this.paymentRepository = paymentRepository;
|
|
10059
|
+
}
|
|
10060
|
+
async pay(checkout) {
|
|
10061
|
+
try {
|
|
10062
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
10063
|
+
checkout,
|
|
10064
|
+
method: 'boleto',
|
|
10065
|
+
postback: this.credentials.postback,
|
|
10066
|
+
});
|
|
10067
|
+
console.warn('[MERCADO PAGO BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
10068
|
+
const { data } = await axios__default["default"]({
|
|
10069
|
+
method: 'POST',
|
|
10070
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
10071
|
+
headers: {
|
|
10072
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
10073
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10074
|
+
'Content-Type': 'application/json',
|
|
10075
|
+
},
|
|
10076
|
+
data: payload,
|
|
10077
|
+
});
|
|
10078
|
+
console.warn('[MERCADO PAGO RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
10079
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
10080
|
+
return payment;
|
|
10081
|
+
}
|
|
10082
|
+
catch (error) {
|
|
10083
|
+
if (error instanceof axios.AxiosError) {
|
|
10084
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
10085
|
+
}
|
|
10086
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
10087
|
+
checkoutId: checkout.id,
|
|
10088
|
+
userEmail: checkout.user.email,
|
|
10089
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
10090
|
+
});
|
|
10091
|
+
}
|
|
10092
|
+
}
|
|
10093
|
+
getBoletoTransaction(paymentId) {
|
|
10094
|
+
throw new Error('Method not implemented.');
|
|
10095
|
+
}
|
|
10096
|
+
}
|
|
10097
|
+
|
|
10098
|
+
exports.MercadoPagoStatusDetailEnum = void 0;
|
|
10099
|
+
(function (MercadoPagoStatusDetailEnum) {
|
|
10100
|
+
MercadoPagoStatusDetailEnum["accredited"] = "accredited";
|
|
10101
|
+
MercadoPagoStatusDetailEnum["partially_refunded"] = "partially_refunded";
|
|
10102
|
+
MercadoPagoStatusDetailEnum["pending_capture"] = "pending_capture";
|
|
10103
|
+
MercadoPagoStatusDetailEnum["offline_process"] = "offline_process";
|
|
10104
|
+
MercadoPagoStatusDetailEnum["pending_contingency"] = "pending_contingency";
|
|
10105
|
+
MercadoPagoStatusDetailEnum["pending_review_manual"] = "pending_review_manual";
|
|
10106
|
+
MercadoPagoStatusDetailEnum["pending_waiting_transfer"] = "pending_waiting_transfer";
|
|
10107
|
+
MercadoPagoStatusDetailEnum["pending_waiting_payment"] = "pending_waiting_payment";
|
|
10108
|
+
MercadoPagoStatusDetailEnum["pending_challenge"] = "pending_challenge";
|
|
10109
|
+
MercadoPagoStatusDetailEnum["bank_error"] = "bank_error";
|
|
10110
|
+
MercadoPagoStatusDetailEnum["cc_rejected_3ds_mandatory"] = "cc_rejected_3ds_mandatory";
|
|
10111
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_card_number"] = "cc_rejected_bad_filled_card_number";
|
|
10112
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_date"] = "cc_rejected_bad_filled_date";
|
|
10113
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_other"] = "cc_rejected_bad_filled_other";
|
|
10114
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_security_code"] = "cc_rejected_bad_filled_security_code";
|
|
10115
|
+
MercadoPagoStatusDetailEnum["cc_rejected_blacklist"] = "cc_rejected_blacklist";
|
|
10116
|
+
MercadoPagoStatusDetailEnum["cc_rejected_call_for_authorize"] = "cc_rejected_call_for_authorize";
|
|
10117
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_disabled"] = "cc_rejected_card_disabled";
|
|
10118
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_error"] = "cc_rejected_card_error";
|
|
10119
|
+
MercadoPagoStatusDetailEnum["cc_rejected_duplicated_payment"] = "cc_rejected_duplicated_payment";
|
|
10120
|
+
MercadoPagoStatusDetailEnum["cc_rejected_high_risk"] = "cc_rejected_high_risk";
|
|
10121
|
+
MercadoPagoStatusDetailEnum["cc_rejected_insufficient_amount"] = "cc_rejected_insufficient_amount";
|
|
10122
|
+
MercadoPagoStatusDetailEnum["cc_rejected_invalid_installments"] = "cc_rejected_invalid_installments";
|
|
10123
|
+
MercadoPagoStatusDetailEnum["cc_rejected_max_attempts"] = "cc_rejected_max_attempts";
|
|
10124
|
+
MercadoPagoStatusDetailEnum["cc_rejected_other_reason"] = "cc_rejected_other_reason";
|
|
10125
|
+
MercadoPagoStatusDetailEnum["cc_amount_rate_limit_exceeded"] = "cc_amount_rate_limit_exceeded";
|
|
10126
|
+
MercadoPagoStatusDetailEnum["rejected_insufficient_data"] = "rejected_insufficient_data";
|
|
10127
|
+
MercadoPagoStatusDetailEnum["rejected_by_bank"] = "rejected_by_bank";
|
|
10128
|
+
MercadoPagoStatusDetailEnum["rejected_by_regulations"] = "rejected_by_regulations";
|
|
10129
|
+
MercadoPagoStatusDetailEnum["insufficient_amount"] = "insufficient_amount";
|
|
10130
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_type_not_allowed"] = "cc_rejected_card_type_not_allowed";
|
|
10131
|
+
})(exports.MercadoPagoStatusDetailEnum || (exports.MercadoPagoStatusDetailEnum = {}));
|
|
10132
|
+
|
|
10133
|
+
exports.MercadoPagoStatusEnum = void 0;
|
|
10134
|
+
(function (MercadoPagoStatusEnum) {
|
|
10135
|
+
MercadoPagoStatusEnum["approved"] = "approved";
|
|
10136
|
+
MercadoPagoStatusEnum["authorized"] = "authorized";
|
|
10137
|
+
MercadoPagoStatusEnum["pending"] = "pending";
|
|
10138
|
+
MercadoPagoStatusEnum["in_process"] = "in_process";
|
|
10139
|
+
MercadoPagoStatusEnum["rejected"] = "rejected";
|
|
10140
|
+
MercadoPagoStatusEnum["cancelled"] = "cancelled";
|
|
10141
|
+
MercadoPagoStatusEnum["refunded"] = "refunded";
|
|
10142
|
+
MercadoPagoStatusEnum["charged_back"] = "charged_back";
|
|
10143
|
+
})(exports.MercadoPagoStatusEnum || (exports.MercadoPagoStatusEnum = {}));
|
|
10144
|
+
|
|
10145
|
+
class MercadoPagoBaseAxiosAdapter {
|
|
10146
|
+
constructor(credentials, paymentRepository) {
|
|
10147
|
+
this.credentials = credentials;
|
|
10148
|
+
this.paymentRepository = paymentRepository;
|
|
10149
|
+
}
|
|
10150
|
+
async refund(order, amount) {
|
|
10151
|
+
const { data } = await axios__default["default"]({
|
|
10152
|
+
method: 'POST',
|
|
10153
|
+
url: `${this.credentials.url}/v1/payments/${order.payment.id}/refunds`,
|
|
10154
|
+
headers: {
|
|
10155
|
+
'X-Idempotency-Key': `${order.payment.charger_id}-${new Date().getTime()}`,
|
|
10156
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10157
|
+
'Content-Type': 'application/json',
|
|
10158
|
+
},
|
|
10159
|
+
data: {
|
|
10160
|
+
amount: +amount.toFixed(2),
|
|
10161
|
+
},
|
|
10162
|
+
});
|
|
10163
|
+
await this.paymentRepository.create({
|
|
10164
|
+
createdAt: new Date(),
|
|
10165
|
+
updatedAt: new Date(),
|
|
10166
|
+
userId: order.user.id,
|
|
10167
|
+
orderId: order.id,
|
|
10168
|
+
totalPrice: amount,
|
|
10169
|
+
paymentProvider: exports.PaymentProviders.MERCADOPAGO,
|
|
10170
|
+
mercadoPagoId: data.id,
|
|
10171
|
+
transaction: data,
|
|
10172
|
+
});
|
|
10173
|
+
console.warn('[RESPONSE MERCADO PAGO REFUND]', JSON.stringify(data));
|
|
10174
|
+
return {
|
|
10175
|
+
status: this.getRefundStatus(data.status),
|
|
10176
|
+
success: [
|
|
10177
|
+
exports.MercadoPagoStatusEnum.approved,
|
|
10178
|
+
exports.MercadoPagoStatusEnum.refunded,
|
|
10179
|
+
exports.MercadoPagoStatusEnum.cancelled,
|
|
10180
|
+
exports.MercadoPagoStatusEnum.authorized,
|
|
10181
|
+
].includes(data.status)
|
|
10182
|
+
? true
|
|
10183
|
+
: false,
|
|
10184
|
+
};
|
|
10185
|
+
}
|
|
10186
|
+
getRefundStatus(status) {
|
|
10187
|
+
if ([exports.MercadoPagoStatusEnum.in_process, exports.MercadoPagoStatusEnum.pending].includes(status)) {
|
|
10188
|
+
return 'processing';
|
|
10189
|
+
}
|
|
10190
|
+
if ([
|
|
10191
|
+
exports.MercadoPagoStatusEnum.approved,
|
|
10192
|
+
exports.MercadoPagoStatusEnum.refunded,
|
|
10193
|
+
exports.MercadoPagoStatusEnum.cancelled,
|
|
10194
|
+
exports.MercadoPagoStatusEnum.authorized,
|
|
10195
|
+
].includes(status)) {
|
|
10196
|
+
return 'success';
|
|
10197
|
+
}
|
|
10198
|
+
return 'unknown';
|
|
10199
|
+
}
|
|
10200
|
+
}
|
|
10201
|
+
|
|
10202
|
+
class MercadoPagoCardAxiosAdapter extends MercadoPagoBaseAxiosAdapter {
|
|
10203
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
10204
|
+
super(credentials, paymentRepository);
|
|
10205
|
+
this.credentials = credentials;
|
|
10206
|
+
this.paymentRepository = paymentRepository;
|
|
10207
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
10208
|
+
}
|
|
10209
|
+
async pay(checkout, card) {
|
|
10210
|
+
try {
|
|
10211
|
+
const payload = await this.getPaymentPayload(checkout, card);
|
|
10212
|
+
console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
|
|
10213
|
+
const data = await this.requestPayment(checkout, payload);
|
|
10214
|
+
console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
|
|
10215
|
+
if (data.status == exports.MercadoPagoStatusEnum.rejected) {
|
|
10216
|
+
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
10217
|
+
checkout,
|
|
10218
|
+
blockType: 'Card not authorized',
|
|
10219
|
+
type: 'Card',
|
|
10220
|
+
limiteRange: 'day',
|
|
10221
|
+
card,
|
|
10222
|
+
gatewayInfo: {
|
|
10223
|
+
gateway: exports.PaymentProviders.MERCADOPAGO,
|
|
10224
|
+
status: data.status,
|
|
10225
|
+
statusDetail: data.status_detail,
|
|
10226
|
+
},
|
|
10227
|
+
});
|
|
10228
|
+
const errorCode = MercadoPagoErrorHelper.getErrorTypeFromResponse(data.status_detail);
|
|
10229
|
+
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', errorCode, {
|
|
10230
|
+
checkoutId: checkout.id,
|
|
10231
|
+
userEmail: checkout.user.email,
|
|
10232
|
+
info: data,
|
|
10233
|
+
});
|
|
10234
|
+
}
|
|
10235
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
10236
|
+
return payment;
|
|
10237
|
+
}
|
|
10238
|
+
catch (error) {
|
|
10239
|
+
if (error instanceof axios.AxiosError) {
|
|
10240
|
+
console.warn(JSON.stringify(error.response?.data?.message));
|
|
10241
|
+
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', exports.ErrorsCode.paymentError, {
|
|
10242
|
+
checkoutId: checkout.id,
|
|
10243
|
+
userEmail: checkout.user.email,
|
|
10244
|
+
info: error.response?.data?.message || error.message?.toString(),
|
|
10245
|
+
});
|
|
10246
|
+
}
|
|
10247
|
+
throw error;
|
|
10248
|
+
}
|
|
10249
|
+
}
|
|
10250
|
+
async requestPayment(checkout, payload) {
|
|
10251
|
+
const { data } = await axios__default["default"]({
|
|
10252
|
+
method: 'POST',
|
|
10253
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
10254
|
+
headers: {
|
|
10255
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
10256
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10257
|
+
'Content-Type': 'application/json',
|
|
8427
10258
|
},
|
|
10259
|
+
data: payload,
|
|
8428
10260
|
});
|
|
8429
10261
|
return data;
|
|
8430
10262
|
}
|
|
8431
|
-
async
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
|
|
8441
|
-
},
|
|
8442
|
-
},
|
|
8443
|
-
orderBy: {
|
|
8444
|
-
personHasPhoto: 'desc',
|
|
8445
|
-
...lodash.omit(params.orderBy, ['personHasPhoto']),
|
|
10263
|
+
async getPaymentPayload(checkout, card) {
|
|
10264
|
+
const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
|
|
10265
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
10266
|
+
checkout,
|
|
10267
|
+
method: 'credit_card',
|
|
10268
|
+
postback: this.credentials.postback,
|
|
10269
|
+
card: {
|
|
10270
|
+
...card,
|
|
10271
|
+
cardId: cardResponse.id,
|
|
8446
10272
|
},
|
|
8447
10273
|
});
|
|
10274
|
+
return payload;
|
|
8448
10275
|
}
|
|
8449
|
-
|
|
10276
|
+
async addCard(card, customer) {
|
|
8450
10277
|
return;
|
|
8451
10278
|
}
|
|
8452
|
-
|
|
8453
|
-
|
|
10279
|
+
async getCardByToken(customerId, token, cardCvv) {
|
|
10280
|
+
try {
|
|
10281
|
+
const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
|
|
10282
|
+
console.warn('payload getCardByToken', payload);
|
|
10283
|
+
const { data } = await axios__default["default"]({
|
|
10284
|
+
method: 'POST',
|
|
10285
|
+
url: `${this.credentials.url}/v1/card_tokens`,
|
|
10286
|
+
headers: {
|
|
10287
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10288
|
+
'Content-Type': 'application/json',
|
|
10289
|
+
},
|
|
10290
|
+
data: payload,
|
|
10291
|
+
});
|
|
10292
|
+
return data;
|
|
10293
|
+
}
|
|
10294
|
+
catch (error) {
|
|
10295
|
+
if (error instanceof axios.AxiosError) {
|
|
10296
|
+
console.warn(JSON.stringify(error.response.data.cause));
|
|
10297
|
+
}
|
|
10298
|
+
throw error;
|
|
10299
|
+
}
|
|
8454
10300
|
}
|
|
8455
|
-
|
|
10301
|
+
createCardHash(bu, shop, card) {
|
|
8456
10302
|
return;
|
|
8457
10303
|
}
|
|
8458
|
-
|
|
10304
|
+
createTransaction(info) {
|
|
8459
10305
|
return;
|
|
8460
10306
|
}
|
|
8461
|
-
async
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
10307
|
+
async createOrUpdateCustomer(customer) {
|
|
10308
|
+
const { data } = await axios__default["default"]({
|
|
10309
|
+
method: 'POST',
|
|
10310
|
+
url: `${this.credentials.url}/v1/customers`,
|
|
10311
|
+
headers: {
|
|
10312
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10313
|
+
'Content-Type': 'application/json',
|
|
10314
|
+
},
|
|
10315
|
+
data: {
|
|
10316
|
+
email: customer.email,
|
|
10317
|
+
first_name: customer.firstName,
|
|
10318
|
+
last_name: customer.lastName,
|
|
10319
|
+
phone: {
|
|
10320
|
+
area_code: customer.phone.substring(0, 2),
|
|
10321
|
+
number: customer.phone.substring(2),
|
|
10322
|
+
},
|
|
10323
|
+
identification: {
|
|
10324
|
+
type: 'CPF',
|
|
10325
|
+
number: customer.cpf.replace(/\D/g, ''),
|
|
10326
|
+
},
|
|
10327
|
+
},
|
|
10328
|
+
});
|
|
10329
|
+
return data;
|
|
10330
|
+
}
|
|
10331
|
+
}
|
|
10332
|
+
|
|
10333
|
+
class MercadoPagoPixAxiosAdapter extends MercadoPagoBaseAxiosAdapter {
|
|
10334
|
+
constructor(credentials, paymentRepository) {
|
|
10335
|
+
super(credentials, paymentRepository);
|
|
10336
|
+
this.credentials = credentials;
|
|
10337
|
+
this.paymentRepository = paymentRepository;
|
|
10338
|
+
}
|
|
10339
|
+
async pay(checkout) {
|
|
10340
|
+
try {
|
|
10341
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
10342
|
+
checkout,
|
|
10343
|
+
method: 'pix',
|
|
10344
|
+
postback: this.credentials.postback,
|
|
10345
|
+
});
|
|
10346
|
+
console.warn('[MERCADO PAGO PIX DATA TO SEND]', JSON.stringify(payload));
|
|
10347
|
+
const { data } = await axios__default["default"]({
|
|
10348
|
+
method: 'POST',
|
|
10349
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
10350
|
+
headers: {
|
|
10351
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
10352
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10353
|
+
'Content-Type': 'application/json',
|
|
10354
|
+
},
|
|
10355
|
+
data: payload,
|
|
10356
|
+
});
|
|
10357
|
+
console.warn('[MERCADO PAGO RESPONSE PIX DATA]', JSON.stringify(data));
|
|
10358
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
10359
|
+
return payment;
|
|
8482
10360
|
}
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
where: {
|
|
8487
|
-
type: 'category_metadata_bool_exp',
|
|
8488
|
-
required: true,
|
|
8489
|
-
value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
|
|
8490
|
-
},
|
|
8491
|
-
});
|
|
10361
|
+
catch (error) {
|
|
10362
|
+
if (error instanceof axios.AxiosError) {
|
|
10363
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
8492
10364
|
}
|
|
8493
|
-
|
|
10365
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
10366
|
+
checkoutId: checkout.id,
|
|
10367
|
+
userEmail: checkout.user.email,
|
|
10368
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
10369
|
+
});
|
|
8494
10370
|
}
|
|
8495
10371
|
}
|
|
8496
|
-
async addProduct(wishlistId, productId) {
|
|
8497
|
-
await this.categoryProductRepository.create({
|
|
8498
|
-
categoryId: +wishlistId,
|
|
8499
|
-
productId: +productId,
|
|
8500
|
-
order: 0,
|
|
8501
|
-
});
|
|
8502
|
-
}
|
|
8503
|
-
async removeProduct(wishlistId, productId) {
|
|
8504
|
-
return this.categoryProductRepository.delete({
|
|
8505
|
-
categoryId: +wishlistId,
|
|
8506
|
-
productId: +productId,
|
|
8507
|
-
});
|
|
8508
|
-
}
|
|
8509
10372
|
}
|
|
8510
|
-
tslib.__decorate([
|
|
8511
|
-
Log(),
|
|
8512
|
-
tslib.__metadata("design:type", Function),
|
|
8513
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
8514
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8515
|
-
], WishlistHasuraGraphQLRepository.prototype, "getWishlistBySlug", null);
|
|
8516
|
-
tslib.__decorate([
|
|
8517
|
-
Log(),
|
|
8518
|
-
tslib.__metadata("design:type", Function),
|
|
8519
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
8520
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8521
|
-
], WishlistHasuraGraphQLRepository.prototype, "getWishlistByPerson", null);
|
|
8522
|
-
tslib.__decorate([
|
|
8523
|
-
Log(),
|
|
8524
|
-
tslib.__metadata("design:type", Function),
|
|
8525
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
8526
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8527
|
-
], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
|
|
8528
|
-
tslib.__decorate([
|
|
8529
|
-
Log(),
|
|
8530
|
-
tslib.__metadata("design:type", Function),
|
|
8531
|
-
tslib.__metadata("design:paramtypes", [Object, Array]),
|
|
8532
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8533
|
-
], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
|
|
8534
10373
|
|
|
8535
10374
|
class PagarmeBankSlipAxiosAdapter {
|
|
8536
10375
|
constructor(credentials, paymentRepository) {
|
|
@@ -8547,7 +10386,7 @@ class PagarmeBankSlipAxiosAdapter {
|
|
|
8547
10386
|
});
|
|
8548
10387
|
console.warn('[PAGARME BOLETO DATA TO SEND]', payload);
|
|
8549
10388
|
if (result.data.status !== exports.PagarmePaymentStatus['Em processamento']) {
|
|
8550
|
-
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
10389
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
8551
10390
|
checkoutId: checkout.id,
|
|
8552
10391
|
userEmail: checkout.user.email,
|
|
8553
10392
|
info: result.data,
|
|
@@ -8565,7 +10404,7 @@ class PagarmeBankSlipAxiosAdapter {
|
|
|
8565
10404
|
return payment;
|
|
8566
10405
|
}
|
|
8567
10406
|
catch (error) {
|
|
8568
|
-
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
10407
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
8569
10408
|
checkoutId: checkout.id,
|
|
8570
10409
|
userEmail: checkout.user.email,
|
|
8571
10410
|
info: error.response.data,
|
|
@@ -8613,62 +10452,423 @@ class PagarmeBankSlipAxiosAdapter {
|
|
|
8613
10452
|
},
|
|
8614
10453
|
};
|
|
8615
10454
|
}
|
|
8616
|
-
}
|
|
8617
|
-
|
|
8618
|
-
class PagarmeBlockedOrderHelper {
|
|
8619
|
-
static async createBlockedOrderForUnauthorizedCard(params) {
|
|
8620
|
-
const { checkout, card, orderBlockedRepository } = params;
|
|
8621
|
-
await orderBlockedRepository.createBlockedOrderOrPayment({
|
|
8622
|
-
checkout,
|
|
8623
|
-
blockType: 'Card not authorized',
|
|
8624
|
-
type: 'Card',
|
|
8625
|
-
limiteRange: 'day',
|
|
8626
|
-
card,
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
10455
|
+
}
|
|
10456
|
+
|
|
10457
|
+
class PagarmeBlockedOrderHelper {
|
|
10458
|
+
static async createBlockedOrderForUnauthorizedCard(params) {
|
|
10459
|
+
const { checkout, card, orderBlockedRepository, gatewayInfo } = params;
|
|
10460
|
+
await orderBlockedRepository.createBlockedOrderOrPayment({
|
|
10461
|
+
checkout,
|
|
10462
|
+
blockType: 'Card not authorized',
|
|
10463
|
+
type: 'Card',
|
|
10464
|
+
limiteRange: 'day',
|
|
10465
|
+
card,
|
|
10466
|
+
gatewayInfo,
|
|
10467
|
+
});
|
|
10468
|
+
}
|
|
10469
|
+
static createPaymentError(checkout, errorType, resultData) {
|
|
10470
|
+
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', errorType, {
|
|
10471
|
+
checkoutId: checkout.id,
|
|
10472
|
+
userEmail: checkout.user.email,
|
|
10473
|
+
info: resultData,
|
|
10474
|
+
});
|
|
10475
|
+
}
|
|
10476
|
+
static createGenericPaymentError(checkout, errorType, errorResponseData) {
|
|
10477
|
+
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', errorType, {
|
|
10478
|
+
checkoutId: checkout.id,
|
|
10479
|
+
userEmail: checkout.user.email,
|
|
10480
|
+
info: errorResponseData,
|
|
10481
|
+
});
|
|
10482
|
+
}
|
|
10483
|
+
}
|
|
10484
|
+
|
|
10485
|
+
/* eslint-disable complexity */
|
|
10486
|
+
class PagarMeErrorHelper {
|
|
10487
|
+
static getErrorTypeFromResponse(errorCode) {
|
|
10488
|
+
switch (errorCode) {
|
|
10489
|
+
// Cartão inválido, vencido, bloqueado
|
|
10490
|
+
case '1000':
|
|
10491
|
+
case '1001':
|
|
10492
|
+
case '1011':
|
|
10493
|
+
case '1025':
|
|
10494
|
+
case '1032':
|
|
10495
|
+
case '1045':
|
|
10496
|
+
case '1068':
|
|
10497
|
+
case '1069':
|
|
10498
|
+
case '1070':
|
|
10499
|
+
case '2001':
|
|
10500
|
+
case '2004':
|
|
10501
|
+
case '5025':
|
|
10502
|
+
case '9124':
|
|
10503
|
+
return exports.ErrorsCode.invalidCardError;
|
|
10504
|
+
// Dados obrigatórios ausentes
|
|
10505
|
+
case '1044':
|
|
10506
|
+
case '5034':
|
|
10507
|
+
case '5047':
|
|
10508
|
+
case '5061':
|
|
10509
|
+
return exports.ErrorsCode.invalidCardError;
|
|
10510
|
+
// Suspeita de fraude, prevenção do banco
|
|
10511
|
+
case '1002':
|
|
10512
|
+
case '1004':
|
|
10513
|
+
case '1019':
|
|
10514
|
+
case '2002':
|
|
10515
|
+
case '2005':
|
|
10516
|
+
case '2007':
|
|
10517
|
+
case '2008':
|
|
10518
|
+
case '2009':
|
|
10519
|
+
case '2010':
|
|
10520
|
+
case '9201':
|
|
10521
|
+
return exports.ErrorsCode.fraudPreventionExternal;
|
|
10522
|
+
// Recusado pelo banco/emissor
|
|
10523
|
+
case '1007':
|
|
10524
|
+
case '1008':
|
|
10525
|
+
case '2000':
|
|
10526
|
+
case '5093':
|
|
10527
|
+
return exports.ErrorsCode.paymentNotAuthorizedError;
|
|
10528
|
+
// Saldo/limite insuficiente ou excedido
|
|
10529
|
+
case '1016':
|
|
10530
|
+
case '1021':
|
|
10531
|
+
case '1023':
|
|
10532
|
+
case '2011':
|
|
10533
|
+
case '2012':
|
|
10534
|
+
case '5051':
|
|
10535
|
+
case '5087':
|
|
10536
|
+
return exports.ErrorsCode.insufficientFundsError;
|
|
10537
|
+
// Valor solicitado inválido
|
|
10538
|
+
case '5094':
|
|
10539
|
+
case '5016':
|
|
10540
|
+
case '5092':
|
|
10541
|
+
return exports.ErrorsCode.paymentError;
|
|
10542
|
+
// Erros internos ou genéricos
|
|
10543
|
+
case '5000':
|
|
10544
|
+
case '5001':
|
|
10545
|
+
case '5003':
|
|
10546
|
+
case '5004':
|
|
10547
|
+
case '5006':
|
|
10548
|
+
case '5008':
|
|
10549
|
+
case '5009':
|
|
10550
|
+
case '5010':
|
|
10551
|
+
case '5011':
|
|
10552
|
+
case '5012':
|
|
10553
|
+
case '5013':
|
|
10554
|
+
case '5014':
|
|
10555
|
+
case '5015':
|
|
10556
|
+
case '5017':
|
|
10557
|
+
case '5018':
|
|
10558
|
+
case '5019':
|
|
10559
|
+
case '5020':
|
|
10560
|
+
case '5021':
|
|
10561
|
+
case '5022':
|
|
10562
|
+
case '5023':
|
|
10563
|
+
case '5024':
|
|
10564
|
+
case '5026':
|
|
10565
|
+
case '5027':
|
|
10566
|
+
case '5028':
|
|
10567
|
+
case '5029':
|
|
10568
|
+
case '5030':
|
|
10569
|
+
case '5031':
|
|
10570
|
+
case '5032':
|
|
10571
|
+
case '5033':
|
|
10572
|
+
case '5035':
|
|
10573
|
+
case '5036':
|
|
10574
|
+
case '5037':
|
|
10575
|
+
case '5038':
|
|
10576
|
+
case '5039':
|
|
10577
|
+
case '5040':
|
|
10578
|
+
case '5041':
|
|
10579
|
+
case '5042':
|
|
10580
|
+
case '5043':
|
|
10581
|
+
case '5044':
|
|
10582
|
+
case '5045':
|
|
10583
|
+
case '5049':
|
|
10584
|
+
case '5050':
|
|
10585
|
+
case '5052':
|
|
10586
|
+
case '5053':
|
|
10587
|
+
case '5054':
|
|
10588
|
+
case '5055':
|
|
10589
|
+
case '5056':
|
|
10590
|
+
case '5057':
|
|
10591
|
+
case '5058':
|
|
10592
|
+
case '5059':
|
|
10593
|
+
case '5060':
|
|
10594
|
+
case '5062':
|
|
10595
|
+
case '5063':
|
|
10596
|
+
case '5064':
|
|
10597
|
+
case '5065':
|
|
10598
|
+
case '5066':
|
|
10599
|
+
case '5067':
|
|
10600
|
+
case '5068':
|
|
10601
|
+
case '5069':
|
|
10602
|
+
case '5070':
|
|
10603
|
+
case '5071':
|
|
10604
|
+
case '5072':
|
|
10605
|
+
case '5073':
|
|
10606
|
+
case '5074':
|
|
10607
|
+
case '5075':
|
|
10608
|
+
case '5076':
|
|
10609
|
+
case '5077':
|
|
10610
|
+
case '5078':
|
|
10611
|
+
case '5079':
|
|
10612
|
+
case '5080':
|
|
10613
|
+
case '5081':
|
|
10614
|
+
case '5082':
|
|
10615
|
+
case '5083':
|
|
10616
|
+
case '5084':
|
|
10617
|
+
case '5085':
|
|
10618
|
+
case '5089':
|
|
10619
|
+
case '5090':
|
|
10620
|
+
case '5095':
|
|
10621
|
+
case '5096':
|
|
10622
|
+
case '5097':
|
|
10623
|
+
return exports.ErrorsCode.paymentError;
|
|
10624
|
+
// Banco/emissor inválido ou não operante
|
|
10625
|
+
case '1049':
|
|
10626
|
+
case '1050':
|
|
10627
|
+
return exports.ErrorsCode.paymentError;
|
|
10628
|
+
// Transação não suportada para o banco/emissor
|
|
10629
|
+
case '1061':
|
|
10630
|
+
return exports.ErrorsCode.paymentError;
|
|
10631
|
+
case '1010':
|
|
10632
|
+
case '1046':
|
|
10633
|
+
return exports.ErrorsCode.invalidCheckoutError;
|
|
10634
|
+
default:
|
|
10635
|
+
return exports.ErrorsCode.paymentError;
|
|
10636
|
+
}
|
|
10637
|
+
}
|
|
10638
|
+
}
|
|
10639
|
+
|
|
10640
|
+
class PagarmePaymentFactoryHelper {
|
|
10641
|
+
static async createSuccessfulPayment(params) {
|
|
10642
|
+
const { checkout, resultData, paymentRepository } = params;
|
|
10643
|
+
const payment = await paymentRepository.create({
|
|
10644
|
+
createdAt: new Date(),
|
|
10645
|
+
updatedAt: new Date(),
|
|
10646
|
+
userId: checkout.user.id,
|
|
10647
|
+
checkoutId: checkout.id,
|
|
10648
|
+
totalPrice: checkout.totalPrice,
|
|
10649
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
10650
|
+
transaction: { ...resultData, paidAt: new Date() },
|
|
10651
|
+
});
|
|
10652
|
+
return payment;
|
|
10653
|
+
}
|
|
10654
|
+
}
|
|
10655
|
+
|
|
10656
|
+
class PagarmePaymentOperationsHelper {
|
|
10657
|
+
static async executePaymentRequest(params) {
|
|
10658
|
+
const { checkout, card, credentials, createPayloadFunction } = params;
|
|
10659
|
+
const payload = createPayloadFunction(checkout, card);
|
|
10660
|
+
console.warn('[PAGARME CARD DATA TO SEND]', payload);
|
|
10661
|
+
const result = await axios__default["default"]({
|
|
10662
|
+
method: 'POST',
|
|
10663
|
+
url: `${credentials.URL}/transactions`,
|
|
10664
|
+
data: payload,
|
|
10665
|
+
});
|
|
10666
|
+
return result;
|
|
10667
|
+
}
|
|
10668
|
+
}
|
|
10669
|
+
|
|
10670
|
+
class PagarMeV5RequestHelper {
|
|
10671
|
+
static build(checkout, method, card) {
|
|
10672
|
+
return {
|
|
10673
|
+
items: this.buildItems(checkout),
|
|
10674
|
+
customer: this.buildCustomer(checkout),
|
|
10675
|
+
shipping: this.buildShipping(checkout),
|
|
10676
|
+
payments: this.buildPayment(checkout, method, card),
|
|
10677
|
+
...this.buildAdditionalInfo(checkout),
|
|
10678
|
+
};
|
|
10679
|
+
}
|
|
10680
|
+
static buildItems(checkout) {
|
|
10681
|
+
const isSubscriber = checkout.user?.isSubscriber ?? false;
|
|
10682
|
+
return checkout.lineItems
|
|
10683
|
+
.filter((item) => !item.isGift)
|
|
10684
|
+
.map((item) => {
|
|
10685
|
+
return {
|
|
10686
|
+
amount: Math.floor(item.pricePaid * 100),
|
|
10687
|
+
description: isSubscriber ? `${item.name} - ASSINANTE` : item.name,
|
|
10688
|
+
quantity: item.quantity,
|
|
10689
|
+
code: item.EAN,
|
|
10690
|
+
};
|
|
10691
|
+
});
|
|
10692
|
+
}
|
|
10693
|
+
static buildCustomer(checkout) {
|
|
10694
|
+
return {
|
|
10695
|
+
name: checkout.user.displayName,
|
|
10696
|
+
email: checkout.user.email,
|
|
10697
|
+
type: 'individual',
|
|
10698
|
+
document: checkout.user.cpf,
|
|
10699
|
+
phones: {
|
|
10700
|
+
home_phone: {
|
|
10701
|
+
country_code: '55',
|
|
10702
|
+
number: checkout.user.phone.slice(2),
|
|
10703
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
10704
|
+
},
|
|
10705
|
+
mobile_phone: {
|
|
10706
|
+
country_code: '55',
|
|
10707
|
+
number: checkout.user.phone.slice(2),
|
|
10708
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
10709
|
+
},
|
|
10710
|
+
},
|
|
10711
|
+
address: {
|
|
10712
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
10713
|
+
line_2: `${checkout.billingAddress.extension}`,
|
|
10714
|
+
zip_code: checkout.shippingAddress.zip,
|
|
10715
|
+
city: checkout.billingAddress.city,
|
|
10716
|
+
state: checkout.billingAddress.state,
|
|
10717
|
+
country: 'BR',
|
|
10718
|
+
},
|
|
10719
|
+
};
|
|
10720
|
+
}
|
|
10721
|
+
static buildShipping(checkout) {
|
|
10722
|
+
return {
|
|
10723
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
10724
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
10725
|
+
recipient_name: checkout.shippingAddress.recipient,
|
|
10726
|
+
recipient_phone: checkout.user.phone,
|
|
10727
|
+
address: {
|
|
10728
|
+
line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
10729
|
+
line_2: `${checkout.shippingAddress.extension}`,
|
|
10730
|
+
zip_code: checkout.shippingAddress.zip,
|
|
10731
|
+
city: checkout.shippingAddress.city,
|
|
10732
|
+
state: checkout.shippingAddress.state,
|
|
10733
|
+
country: 'BR',
|
|
10734
|
+
},
|
|
10735
|
+
};
|
|
10736
|
+
}
|
|
10737
|
+
static buildPayment(checkout, method, card) {
|
|
10738
|
+
return [
|
|
10739
|
+
{
|
|
10740
|
+
payment_method: method,
|
|
10741
|
+
amount: Math.floor(checkout.totalPrice * 100),
|
|
10742
|
+
...(method === 'pix' && {
|
|
10743
|
+
pix: this.getPixOrder(),
|
|
10744
|
+
}),
|
|
10745
|
+
...(method === 'boleto' && {
|
|
10746
|
+
boleto: this.getBoletoOrder(),
|
|
10747
|
+
}),
|
|
10748
|
+
...(method === 'credit_card' && {
|
|
10749
|
+
credit_card: this.getCardOrder(checkout, card),
|
|
10750
|
+
}),
|
|
10751
|
+
},
|
|
10752
|
+
];
|
|
10753
|
+
}
|
|
10754
|
+
static getPixOrder() {
|
|
10755
|
+
return {
|
|
10756
|
+
expires_at: dateFns.format(dateFns.addHours(new Date(), 24), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"),
|
|
10757
|
+
};
|
|
10758
|
+
}
|
|
10759
|
+
static getBoletoOrder() {
|
|
10760
|
+
return {
|
|
10761
|
+
due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
|
|
10762
|
+
instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
10763
|
+
type: 'DM',
|
|
10764
|
+
document_number: new Date().getTime().toString(),
|
|
10765
|
+
};
|
|
10766
|
+
}
|
|
10767
|
+
static getCardOrder(checkout, card) {
|
|
10768
|
+
return {
|
|
10769
|
+
installments: card.installments,
|
|
10770
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'loja glam' : 'mens market',
|
|
10771
|
+
card_id: card.cardId,
|
|
10772
|
+
card: {
|
|
10773
|
+
cvv: card.cardCvv,
|
|
10774
|
+
billing_address: {
|
|
10775
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
10776
|
+
zip_code: checkout.billingAddress.zip,
|
|
10777
|
+
city: checkout.billingAddress.city,
|
|
10778
|
+
state: checkout.billingAddress.state,
|
|
10779
|
+
country: 'BR',
|
|
10780
|
+
},
|
|
10781
|
+
},
|
|
10782
|
+
};
|
|
10783
|
+
}
|
|
10784
|
+
static buildAdditionalInfo(checkout) {
|
|
10785
|
+
const isSubscriber = checkout.user?.isSubscriber ?? false;
|
|
10786
|
+
if (isSubscriber)
|
|
10787
|
+
return {
|
|
10788
|
+
antifraude_enabled: false,
|
|
10789
|
+
};
|
|
10790
|
+
return {};
|
|
8642
10791
|
}
|
|
8643
10792
|
}
|
|
8644
10793
|
|
|
8645
|
-
class
|
|
8646
|
-
static
|
|
8647
|
-
|
|
8648
|
-
const payment = await paymentRepository.create({
|
|
10794
|
+
class PagarMeV5ResponseHelper {
|
|
10795
|
+
static build(method, checkout, response) {
|
|
10796
|
+
return Payment.toInstance({
|
|
8649
10797
|
createdAt: new Date(),
|
|
8650
10798
|
updatedAt: new Date(),
|
|
8651
10799
|
userId: checkout.user.id,
|
|
8652
10800
|
checkoutId: checkout.id,
|
|
8653
10801
|
totalPrice: checkout.totalPrice,
|
|
8654
10802
|
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
10803
|
+
pagarMeOrderId: response.id,
|
|
10804
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
10805
|
+
});
|
|
10806
|
+
}
|
|
10807
|
+
static buildPaymentTransaction(method, response) {
|
|
10808
|
+
const charger = response.charges.at(0);
|
|
10809
|
+
const transaction = charger.last_transaction;
|
|
10810
|
+
return PaymentTransaction.toInstance({
|
|
10811
|
+
acquirer_name: exports.PaymentProviders.PAGARME,
|
|
10812
|
+
amount: charger.amount,
|
|
10813
|
+
currency: charger.currency,
|
|
10814
|
+
gateway_id: charger.gateway_id,
|
|
10815
|
+
status: this.getPaymentStatus(transaction.status),
|
|
10816
|
+
payment_method: charger.payment_method,
|
|
10817
|
+
date_created: charger.created_at,
|
|
10818
|
+
date_updated: charger.updated_at,
|
|
10819
|
+
paid_amount: charger.paid_amount,
|
|
10820
|
+
paid_at: charger.paid_at,
|
|
10821
|
+
order_id: response.id,
|
|
10822
|
+
charger_id: charger.id,
|
|
10823
|
+
tid: charger.id,
|
|
10824
|
+
id: charger.id,
|
|
10825
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
|
|
10826
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
|
|
10827
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
|
|
10828
|
+
});
|
|
10829
|
+
}
|
|
10830
|
+
static getPaymentStatus(status) {
|
|
10831
|
+
if (status == exports.PagarMeV5PaymentStatus.Gerado)
|
|
10832
|
+
return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
|
|
10833
|
+
if (status == exports.PagarMeV5PaymentStatus.Capturada)
|
|
10834
|
+
return exports.PagarMeV5PaymentStatus.Pago;
|
|
10835
|
+
return status;
|
|
10836
|
+
}
|
|
10837
|
+
static getBoletoReponse(transaction) {
|
|
10838
|
+
return {
|
|
10839
|
+
boleto_url: transaction.url?.toString(),
|
|
10840
|
+
boleto_barcode: transaction.line?.toString(),
|
|
10841
|
+
boleto_qr_code: transaction.qr_code?.toString(),
|
|
10842
|
+
boleto_expiration_date: transaction.due_at?.toString(),
|
|
10843
|
+
boleto_instructions: transaction.instructions?.toString(),
|
|
10844
|
+
boleto_nosso_numero: transaction.nosso_numero?.toString(),
|
|
10845
|
+
boleto_type: transaction.type?.toString(),
|
|
10846
|
+
boleto_document_number: transaction.document_number?.toString(),
|
|
10847
|
+
};
|
|
8658
10848
|
}
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
10849
|
+
static getPixReponse(transaction) {
|
|
10850
|
+
return {
|
|
10851
|
+
pix_qr_code: transaction.qr_code?.toString(),
|
|
10852
|
+
pix_qr_code_url: transaction.qr_code_url?.toString(),
|
|
10853
|
+
pix_expiration_date: transaction.expires_at?.toString(),
|
|
10854
|
+
};
|
|
10855
|
+
}
|
|
10856
|
+
static getCardReponse(transaction) {
|
|
10857
|
+
return {
|
|
10858
|
+
soft_descriptor: transaction.statement_descriptor?.toString(),
|
|
10859
|
+
acquirer_name: transaction.acquirer_name?.toString(),
|
|
10860
|
+
acquirer_id: transaction.acquirer_tid?.toString(),
|
|
10861
|
+
acquirer_nsu: transaction.acquirer_nsu?.toString(),
|
|
10862
|
+
acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
|
|
10863
|
+
acquirer_message: transaction.acquirer_message?.toString(),
|
|
10864
|
+
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
10865
|
+
installments: transaction.installments ?? null,
|
|
10866
|
+
card_holder_name: transaction.card?.holder_name?.toString(),
|
|
10867
|
+
card_last_digits: transaction.card?.last_four_digits?.toString(),
|
|
10868
|
+
card_first_digits: transaction.card?.first_six_digits?.toString(),
|
|
10869
|
+
card_brand: transaction.card?.brand?.toString(),
|
|
10870
|
+
card_id: transaction.card?.id?.toString(),
|
|
10871
|
+
};
|
|
8672
10872
|
}
|
|
8673
10873
|
}
|
|
8674
10874
|
|
|
@@ -8692,7 +10892,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8692
10892
|
card,
|
|
8693
10893
|
orderBlockedRepository: this.orderBlockedRepository,
|
|
8694
10894
|
});
|
|
8695
|
-
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, result.data);
|
|
10895
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, exports.ErrorsCode.paymentError, result.data);
|
|
8696
10896
|
}
|
|
8697
10897
|
return PagarmePaymentFactoryHelper.createSuccessfulPayment({
|
|
8698
10898
|
checkout,
|
|
@@ -8704,7 +10904,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8704
10904
|
if (error instanceof PaymentError) {
|
|
8705
10905
|
throw error;
|
|
8706
10906
|
}
|
|
8707
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
10907
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, exports.ErrorsCode.paymentError, error.response?.data);
|
|
8708
10908
|
}
|
|
8709
10909
|
}
|
|
8710
10910
|
async addCard(card) {
|
|
@@ -8728,8 +10928,9 @@ class PagarmeCardAxiosAdapter {
|
|
|
8728
10928
|
});
|
|
8729
10929
|
}
|
|
8730
10930
|
}
|
|
8731
|
-
async createCardHash(bu) {
|
|
8732
|
-
const
|
|
10931
|
+
async createCardHash(bu, shop) {
|
|
10932
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
10933
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
8733
10934
|
try {
|
|
8734
10935
|
const { data } = await axios__default["default"]({
|
|
8735
10936
|
method: 'GET',
|
|
@@ -8860,7 +11061,7 @@ class PagarmePixAxiosAdapter {
|
|
|
8860
11061
|
return payment;
|
|
8861
11062
|
}
|
|
8862
11063
|
catch (error) {
|
|
8863
|
-
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
11064
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
8864
11065
|
checkoutId: checkout.id,
|
|
8865
11066
|
userEmail: checkout.user.email,
|
|
8866
11067
|
info: error.response?.data,
|
|
@@ -8892,6 +11093,347 @@ class PagarmePixAxiosAdapter {
|
|
|
8892
11093
|
}
|
|
8893
11094
|
}
|
|
8894
11095
|
|
|
11096
|
+
class PagarmeV5BankSlipAxiosAdapter {
|
|
11097
|
+
constructor(credentials, paymentRepository) {
|
|
11098
|
+
this.credentials = credentials;
|
|
11099
|
+
this.paymentRepository = paymentRepository;
|
|
11100
|
+
}
|
|
11101
|
+
async pay(checkout) {
|
|
11102
|
+
try {
|
|
11103
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
11104
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
11105
|
+
const { data } = await axios__default["default"]({
|
|
11106
|
+
method: 'POST',
|
|
11107
|
+
url: `${this.credentials.URL}/orders`,
|
|
11108
|
+
headers: {
|
|
11109
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11110
|
+
'Content-Type': 'application/json',
|
|
11111
|
+
},
|
|
11112
|
+
data: payload,
|
|
11113
|
+
});
|
|
11114
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
11115
|
+
if (data.status === exports.PagarMeV5OrderStatus.Falha ||
|
|
11116
|
+
data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
|
|
11117
|
+
(data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
|
|
11118
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
|
|
11119
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
11120
|
+
checkoutId: checkout.id,
|
|
11121
|
+
userEmail: checkout.user.email,
|
|
11122
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
11123
|
+
}));
|
|
11124
|
+
}
|
|
11125
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
11126
|
+
return payment;
|
|
11127
|
+
}
|
|
11128
|
+
catch (error) {
|
|
11129
|
+
if (error instanceof axios.AxiosError) {
|
|
11130
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
11131
|
+
}
|
|
11132
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
11133
|
+
checkoutId: checkout.id,
|
|
11134
|
+
userEmail: checkout.user.email,
|
|
11135
|
+
info: error.response?.data,
|
|
11136
|
+
});
|
|
11137
|
+
}
|
|
11138
|
+
}
|
|
11139
|
+
async getBoletoTransaction(paymentId) {
|
|
11140
|
+
try {
|
|
11141
|
+
const { data } = await axios__default["default"]({
|
|
11142
|
+
method: 'GET',
|
|
11143
|
+
url: `${this.credentials.URL}/charges/${paymentId}`,
|
|
11144
|
+
headers: {
|
|
11145
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11146
|
+
'Content-Type': 'application/json',
|
|
11147
|
+
},
|
|
11148
|
+
});
|
|
11149
|
+
const payment = await this.paymentRepository.get({
|
|
11150
|
+
id: data.id,
|
|
11151
|
+
});
|
|
11152
|
+
return payment.transaction;
|
|
11153
|
+
}
|
|
11154
|
+
catch (error) {
|
|
11155
|
+
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
11156
|
+
paymentId,
|
|
11157
|
+
info: error.response.data,
|
|
11158
|
+
});
|
|
11159
|
+
}
|
|
11160
|
+
}
|
|
11161
|
+
}
|
|
11162
|
+
|
|
11163
|
+
class PagarmeV5BaseAxiosAdapter {
|
|
11164
|
+
constructor(credentials, paymentRepository) {
|
|
11165
|
+
this.credentials = credentials;
|
|
11166
|
+
this.paymentRepository = paymentRepository;
|
|
11167
|
+
}
|
|
11168
|
+
async refund(order, amount) {
|
|
11169
|
+
try {
|
|
11170
|
+
console.warn('[PAGARME REFUND] Starting refund process for order', order.id, order.payment.payment_method, order.payment.amount, 'to refund with amount', amount);
|
|
11171
|
+
const amountInCents = toCents(amount);
|
|
11172
|
+
console.warn('[PAGARME REFUND] Amount to send in cents', amountInCents);
|
|
11173
|
+
const { data } = await axios__default["default"]({
|
|
11174
|
+
method: 'DELETE',
|
|
11175
|
+
url: `${this.credentials.URL}/charges/${order.payment.charger_id}`,
|
|
11176
|
+
headers: {
|
|
11177
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11178
|
+
'Content-Type': 'application/json',
|
|
11179
|
+
},
|
|
11180
|
+
data: {
|
|
11181
|
+
amount: amountInCents,
|
|
11182
|
+
},
|
|
11183
|
+
});
|
|
11184
|
+
console.warn('[RESPONSE PAGARME REFUND]', JSON.stringify(data));
|
|
11185
|
+
await this.paymentRepository.create({
|
|
11186
|
+
createdAt: new Date(),
|
|
11187
|
+
updatedAt: new Date(),
|
|
11188
|
+
userId: order.user.id,
|
|
11189
|
+
orderId: order.id,
|
|
11190
|
+
totalPrice: amount,
|
|
11191
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
11192
|
+
pagarMeOrderId: data.id,
|
|
11193
|
+
transaction: data,
|
|
11194
|
+
});
|
|
11195
|
+
return {
|
|
11196
|
+
status: this.getRefundStatus(data.status),
|
|
11197
|
+
success: [
|
|
11198
|
+
exports.PagarMeV5OrderStatus.Pago,
|
|
11199
|
+
exports.PagarMeV5OrderStatus.Cancelado,
|
|
11200
|
+
exports.PagarMeV5PaymentStatus['Em processamento'],
|
|
11201
|
+
].includes(data.status)
|
|
11202
|
+
? true
|
|
11203
|
+
: false,
|
|
11204
|
+
};
|
|
11205
|
+
}
|
|
11206
|
+
catch (error) {
|
|
11207
|
+
console.error('Error during refund process for order', order.id, 'with error', error);
|
|
11208
|
+
throw error;
|
|
11209
|
+
}
|
|
11210
|
+
}
|
|
11211
|
+
getRefundStatus(status) {
|
|
11212
|
+
if ([exports.PagarMeV5PaymentStatus['Em processamento']].includes(status)) {
|
|
11213
|
+
return 'processing';
|
|
11214
|
+
}
|
|
11215
|
+
if ([exports.PagarMeV5OrderStatus.Pago, exports.PagarMeV5OrderStatus.Cancelado].includes(status)) {
|
|
11216
|
+
return 'success';
|
|
11217
|
+
}
|
|
11218
|
+
return 'unknown';
|
|
11219
|
+
}
|
|
11220
|
+
}
|
|
11221
|
+
|
|
11222
|
+
class PagarmeV5CardAxiosAdapter extends PagarmeV5BaseAxiosAdapter {
|
|
11223
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
11224
|
+
super(credentials, paymentRepository);
|
|
11225
|
+
this.credentials = credentials;
|
|
11226
|
+
this.paymentRepository = paymentRepository;
|
|
11227
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
11228
|
+
}
|
|
11229
|
+
async pay(checkout, card) {
|
|
11230
|
+
try {
|
|
11231
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
|
|
11232
|
+
console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
|
|
11233
|
+
const { data } = await axios__default["default"]({
|
|
11234
|
+
method: 'POST',
|
|
11235
|
+
url: `${this.credentials.URL}/orders`,
|
|
11236
|
+
headers: {
|
|
11237
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11238
|
+
'Content-Type': 'application/json',
|
|
11239
|
+
},
|
|
11240
|
+
data: payload,
|
|
11241
|
+
});
|
|
11242
|
+
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
11243
|
+
const charge = data.charges.at(0);
|
|
11244
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha ||
|
|
11245
|
+
charge.status !== exports.PagarMeV5OrderStatus.Pago ||
|
|
11246
|
+
charge.last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
11247
|
+
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
11248
|
+
checkout,
|
|
11249
|
+
card,
|
|
11250
|
+
orderBlockedRepository: this.orderBlockedRepository,
|
|
11251
|
+
gatewayInfo: {
|
|
11252
|
+
gateway: exports.PaymentProviders.PAGARME,
|
|
11253
|
+
status: charge.status,
|
|
11254
|
+
statusDetail: charge.last_transaction?.status,
|
|
11255
|
+
},
|
|
11256
|
+
});
|
|
11257
|
+
const errorCode = PagarMeErrorHelper.getErrorTypeFromResponse(charge.last_transaction.acquirer_return_code);
|
|
11258
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, errorCode, data);
|
|
11259
|
+
}
|
|
11260
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
11261
|
+
return payment;
|
|
11262
|
+
}
|
|
11263
|
+
catch (error) {
|
|
11264
|
+
if (error instanceof axios.AxiosError) {
|
|
11265
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
11266
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, exports.ErrorsCode.paymentError, error.response?.data);
|
|
11267
|
+
}
|
|
11268
|
+
throw error;
|
|
11269
|
+
}
|
|
11270
|
+
}
|
|
11271
|
+
async addCard(card, customer) {
|
|
11272
|
+
try {
|
|
11273
|
+
const { id } = await this.createOrUpdateCustomer(customer);
|
|
11274
|
+
const { data } = await axios__default["default"]({
|
|
11275
|
+
method: 'POST',
|
|
11276
|
+
url: `${this.credentials.URL}/customers/${id}/cards`,
|
|
11277
|
+
headers: {
|
|
11278
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11279
|
+
'Content-Type': 'application/json',
|
|
11280
|
+
},
|
|
11281
|
+
data: {
|
|
11282
|
+
number: card.number,
|
|
11283
|
+
holder_name: card.name,
|
|
11284
|
+
holder_document: card.cpf,
|
|
11285
|
+
exp_month: card.expirationDate.split('/').at(0),
|
|
11286
|
+
exp_year: card.expirationDate.split('/').at(1),
|
|
11287
|
+
cvv: card.cvv,
|
|
11288
|
+
billing_address: {
|
|
11289
|
+
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
11290
|
+
line_2: `${customer.billingAddress.extension}`,
|
|
11291
|
+
zip_code: customer.billingAddress.zip,
|
|
11292
|
+
city: customer.billingAddress.city,
|
|
11293
|
+
state: customer.billingAddress.state,
|
|
11294
|
+
country: 'BR',
|
|
11295
|
+
},
|
|
11296
|
+
},
|
|
11297
|
+
});
|
|
11298
|
+
return data;
|
|
11299
|
+
}
|
|
11300
|
+
catch (error) {
|
|
11301
|
+
console.warn(JSON.stringify(error));
|
|
11302
|
+
throw error;
|
|
11303
|
+
}
|
|
11304
|
+
}
|
|
11305
|
+
async createCardHash(bu, shop) {
|
|
11306
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
11307
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
11308
|
+
try {
|
|
11309
|
+
const { data } = await axios__default["default"]({
|
|
11310
|
+
method: 'GET',
|
|
11311
|
+
headers: {
|
|
11312
|
+
'content-type': 'application/json',
|
|
11313
|
+
},
|
|
11314
|
+
url: `${this.credentials.URL}/transactions/card_hash_key`,
|
|
11315
|
+
data: JSON.stringify({
|
|
11316
|
+
api_key: key,
|
|
11317
|
+
}),
|
|
11318
|
+
});
|
|
11319
|
+
return data;
|
|
11320
|
+
}
|
|
11321
|
+
catch (error) {
|
|
11322
|
+
throw new BusinessError('Houve uma falha gerar o hash', {
|
|
11323
|
+
info: error.response.data,
|
|
11324
|
+
});
|
|
11325
|
+
}
|
|
11326
|
+
}
|
|
11327
|
+
async getCardByToken(customerId, token) {
|
|
11328
|
+
try {
|
|
11329
|
+
const { data } = await axios__default["default"]({
|
|
11330
|
+
method: 'GET',
|
|
11331
|
+
url: `${this.credentials.URL}/cards/${token}`,
|
|
11332
|
+
data: {
|
|
11333
|
+
api_key: this.credentials.API_KEY,
|
|
11334
|
+
},
|
|
11335
|
+
});
|
|
11336
|
+
return data;
|
|
11337
|
+
}
|
|
11338
|
+
catch (error) {
|
|
11339
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
|
|
11340
|
+
info: error.response.data,
|
|
11341
|
+
});
|
|
11342
|
+
}
|
|
11343
|
+
}
|
|
11344
|
+
async createTransaction(info) {
|
|
11345
|
+
return info;
|
|
11346
|
+
}
|
|
11347
|
+
async createOrUpdateCustomer(customer) {
|
|
11348
|
+
try {
|
|
11349
|
+
const { data } = await axios__default["default"]({
|
|
11350
|
+
method: 'POST',
|
|
11351
|
+
url: `${this.credentials.URL}/customers`,
|
|
11352
|
+
headers: {
|
|
11353
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11354
|
+
'Content-Type': 'application/json',
|
|
11355
|
+
},
|
|
11356
|
+
data: {
|
|
11357
|
+
name: customer.displayName,
|
|
11358
|
+
email: customer.email,
|
|
11359
|
+
document: customer.cpf,
|
|
11360
|
+
type: 'individual',
|
|
11361
|
+
document_type: 'CPF',
|
|
11362
|
+
address: {
|
|
11363
|
+
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
11364
|
+
line_2: `${customer.billingAddress.extension}`,
|
|
11365
|
+
zip_code: customer.billingAddress.zip,
|
|
11366
|
+
city: customer.billingAddress.city,
|
|
11367
|
+
state: customer.billingAddress.state,
|
|
11368
|
+
country: 'BR',
|
|
11369
|
+
},
|
|
11370
|
+
birthdate: dateFns.format(new Date(customer.birthday), 'MM/dd/yyyy'),
|
|
11371
|
+
phones: {
|
|
11372
|
+
home_phone: {
|
|
11373
|
+
country_code: '55',
|
|
11374
|
+
number: customer.phone.slice(2),
|
|
11375
|
+
area_code: customer.phone.slice(0, 2),
|
|
11376
|
+
},
|
|
11377
|
+
mobile_phone: {
|
|
11378
|
+
country_code: '55',
|
|
11379
|
+
number: customer.phone.slice(2),
|
|
11380
|
+
area_code: customer.phone.slice(0, 2),
|
|
11381
|
+
},
|
|
11382
|
+
},
|
|
11383
|
+
},
|
|
11384
|
+
});
|
|
11385
|
+
return data;
|
|
11386
|
+
}
|
|
11387
|
+
catch (error) {
|
|
11388
|
+
console.warn(error);
|
|
11389
|
+
throw error;
|
|
11390
|
+
}
|
|
11391
|
+
}
|
|
11392
|
+
}
|
|
11393
|
+
|
|
11394
|
+
class PagarmeV5PixAxiosAdapter extends PagarmeV5BaseAxiosAdapter {
|
|
11395
|
+
constructor(credentials, paymentRepository) {
|
|
11396
|
+
super(credentials, paymentRepository);
|
|
11397
|
+
this.credentials = credentials;
|
|
11398
|
+
this.paymentRepository = paymentRepository;
|
|
11399
|
+
}
|
|
11400
|
+
async pay(checkout) {
|
|
11401
|
+
try {
|
|
11402
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
11403
|
+
console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
|
|
11404
|
+
const { data } = await axios__default["default"]({
|
|
11405
|
+
method: 'POST',
|
|
11406
|
+
url: `${this.credentials.URL}/orders`,
|
|
11407
|
+
headers: {
|
|
11408
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11409
|
+
'Content-Type': 'application/json',
|
|
11410
|
+
},
|
|
11411
|
+
data: payload,
|
|
11412
|
+
});
|
|
11413
|
+
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
11414
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
|
|
11415
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
11416
|
+
checkoutId: checkout.id,
|
|
11417
|
+
userEmail: checkout.user.email,
|
|
11418
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
11419
|
+
});
|
|
11420
|
+
}
|
|
11421
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
11422
|
+
return payment;
|
|
11423
|
+
}
|
|
11424
|
+
catch (error) {
|
|
11425
|
+
if (error instanceof axios.AxiosError) {
|
|
11426
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
11427
|
+
}
|
|
11428
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
11429
|
+
checkoutId: checkout.id,
|
|
11430
|
+
userEmail: checkout.user.email,
|
|
11431
|
+
info: error.response?.data,
|
|
11432
|
+
});
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11435
|
+
}
|
|
11436
|
+
|
|
8895
11437
|
class VertexAxiosAdapter {
|
|
8896
11438
|
constructor(config) {
|
|
8897
11439
|
this.config = config;
|
|
@@ -9057,6 +11599,10 @@ Object.defineProperty(exports, 'addDays', {
|
|
|
9057
11599
|
enumerable: true,
|
|
9058
11600
|
get: function () { return dateFns.addDays; }
|
|
9059
11601
|
});
|
|
11602
|
+
Object.defineProperty(exports, 'addHours', {
|
|
11603
|
+
enumerable: true,
|
|
11604
|
+
get: function () { return dateFns.addHours; }
|
|
11605
|
+
});
|
|
9060
11606
|
Object.defineProperty(exports, 'addMonths', {
|
|
9061
11607
|
enumerable: true,
|
|
9062
11608
|
get: function () { return dateFns.addMonths; }
|
|
@@ -9093,6 +11639,10 @@ Object.defineProperty(exports, 'subDays', {
|
|
|
9093
11639
|
enumerable: true,
|
|
9094
11640
|
get: function () { return dateFns.subDays; }
|
|
9095
11641
|
});
|
|
11642
|
+
Object.defineProperty(exports, 'formatInTimeZone', {
|
|
11643
|
+
enumerable: true,
|
|
11644
|
+
get: function () { return dateFnsTz.formatInTimeZone; }
|
|
11645
|
+
});
|
|
9096
11646
|
Object.defineProperty(exports, 'chunk', {
|
|
9097
11647
|
enumerable: true,
|
|
9098
11648
|
get: function () { return lodash.chunk; }
|
|
@@ -9180,6 +11730,8 @@ exports.Base = Base;
|
|
|
9180
11730
|
exports.BaseModel = BaseModel;
|
|
9181
11731
|
exports.BeautyProfile = BeautyProfile;
|
|
9182
11732
|
exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
|
|
11733
|
+
exports.BrandCategory = BrandCategory;
|
|
11734
|
+
exports.BrandCategoryFirestoreRepository = BrandCategoryFirestoreRepository;
|
|
9183
11735
|
exports.BusinessError = BusinessError;
|
|
9184
11736
|
exports.Buy2Win = Buy2Win;
|
|
9185
11737
|
exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
|
|
@@ -9228,6 +11780,7 @@ exports.GroupFirestoreRepository = GroupFirestoreRepository;
|
|
|
9228
11780
|
exports.Home = Home;
|
|
9229
11781
|
exports.HomeFirestoreRepository = HomeFirestoreRepository;
|
|
9230
11782
|
exports.InvalidArgumentError = InvalidArgumentError;
|
|
11783
|
+
exports.InvalidCheckoutError = InvalidCheckoutError;
|
|
9231
11784
|
exports.KitProduct = KitProduct;
|
|
9232
11785
|
exports.KitProductHasuraGraphQL = KitProductHasuraGraphQL;
|
|
9233
11786
|
exports.Lead = Lead;
|
|
@@ -9238,6 +11791,13 @@ exports.Log = Log;
|
|
|
9238
11791
|
exports.LogDocument = LogDocument;
|
|
9239
11792
|
exports.LogFirestoreRepository = LogFirestoreRepository;
|
|
9240
11793
|
exports.Logger = Logger;
|
|
11794
|
+
exports.MercadoPagoBankSlipAxiosAdapter = MercadoPagoBankSlipAxiosAdapter;
|
|
11795
|
+
exports.MercadoPagoCardAxiosAdapter = MercadoPagoCardAxiosAdapter;
|
|
11796
|
+
exports.MercadoPagoErrorHelper = MercadoPagoErrorHelper;
|
|
11797
|
+
exports.MercadoPagoPaymentMethodFactory = MercadoPagoPaymentMethodFactory;
|
|
11798
|
+
exports.MercadoPagoPixAxiosAdapter = MercadoPagoPixAxiosAdapter;
|
|
11799
|
+
exports.MercadoPagoRequestHelper = MercadoPagoRequestHelper;
|
|
11800
|
+
exports.MercadoPagoResponseHelper = MercadoPagoResponseHelper;
|
|
9241
11801
|
exports.NotFoundError = NotFoundError;
|
|
9242
11802
|
exports.ObsEmitter = ObsEmitter;
|
|
9243
11803
|
exports.Order = Order;
|
|
@@ -9248,20 +11808,33 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
|
|
|
9248
11808
|
exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
|
|
9249
11809
|
exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
|
|
9250
11810
|
exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
|
|
11811
|
+
exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
|
|
11812
|
+
exports.PagarmeV5BaseAxiosAdapter = PagarmeV5BaseAxiosAdapter;
|
|
11813
|
+
exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
|
|
11814
|
+
exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
|
|
9251
11815
|
exports.Payment = Payment;
|
|
9252
11816
|
exports.PaymentError = PaymentError;
|
|
9253
11817
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|
|
9254
11818
|
exports.PaymentProviderFactory = PaymentProviderFactory;
|
|
9255
11819
|
exports.PaymentTransaction = PaymentTransaction;
|
|
9256
11820
|
exports.Product = Product;
|
|
11821
|
+
exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
|
|
11822
|
+
exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
|
|
9257
11823
|
exports.ProductErrors = ProductErrors;
|
|
9258
11824
|
exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
|
|
9259
11825
|
exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;
|
|
9260
11826
|
exports.ProductFirestoreRepository = ProductFirestoreRepository;
|
|
11827
|
+
exports.ProductGroup = ProductGroup;
|
|
11828
|
+
exports.ProductGroupHasuraGraphQLRepository = ProductGroupHasuraGraphQLRepository;
|
|
9261
11829
|
exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
|
|
9262
11830
|
exports.ProductHasuraGraphQLRepository = ProductHasuraGraphQLRepository;
|
|
11831
|
+
exports.ProductPriceLog = ProductPriceLog;
|
|
11832
|
+
exports.ProductPriceLogHasuraGraphQLRepository = ProductPriceLogHasuraGraphQLRepository;
|
|
9263
11833
|
exports.ProductReview = ProductReview;
|
|
9264
11834
|
exports.ProductReviewHasuraGraphQLRepository = ProductReviewHasuraGraphQLRepository;
|
|
11835
|
+
exports.ProductStockEntry = ProductStockEntry;
|
|
11836
|
+
exports.ProductStockEntryHasuraGraphQL = ProductStockEntryHasuraGraphQL;
|
|
11837
|
+
exports.ProductStockEntryHasuraGraphQLRepository = ProductStockEntryHasuraGraphQLRepository;
|
|
9265
11838
|
exports.ProductStockNotification = ProductStockNotification;
|
|
9266
11839
|
exports.ProductStockNotificationHasuraGraphQLRepository = ProductStockNotificationHasuraGraphQLRepository;
|
|
9267
11840
|
exports.ProductVariantFirestoreRepository = ProductVariantFirestoreRepository;
|
|
@@ -9277,10 +11850,18 @@ exports.RoundProductPricesHelper = RoundProductPricesHelper;
|
|
|
9277
11850
|
exports.Sequence = Sequence;
|
|
9278
11851
|
exports.SequenceFirestoreRepository = SequenceFirestoreRepository;
|
|
9279
11852
|
exports.ShippingMethod = ShippingMethod;
|
|
11853
|
+
exports.ShopConfigs = ShopConfigs;
|
|
11854
|
+
exports.ShopConfigsFirestoreRepository = ShopConfigsFirestoreRepository;
|
|
9280
11855
|
exports.ShopMenu = ShopMenu;
|
|
9281
11856
|
exports.ShopMenuFirestoreRepository = ShopMenuFirestoreRepository;
|
|
9282
11857
|
exports.ShopSettings = ShopSettings;
|
|
9283
11858
|
exports.ShopSettingsFirestoreRepository = ShopSettingsFirestoreRepository;
|
|
11859
|
+
exports.ShoppingRecurrence = ShoppingRecurrence;
|
|
11860
|
+
exports.ShoppingRecurrenceEdition = ShoppingRecurrenceEdition;
|
|
11861
|
+
exports.ShoppingRecurrenceEditionFirestoreRepository = ShoppingRecurrenceEditionFirestoreRepository;
|
|
11862
|
+
exports.ShoppingRecurrenceErrorLog = ShoppingRecurrenceErrorLog;
|
|
11863
|
+
exports.ShoppingRecurrenceErrorLogFirestoreRepository = ShoppingRecurrenceErrorLogFirestoreRepository;
|
|
11864
|
+
exports.ShoppingRecurrenceFirestoreRepository = ShoppingRecurrenceFirestoreRepository;
|
|
9284
11865
|
exports.SignOut = SignOut;
|
|
9285
11866
|
exports.StockLimitError = StockLimitError;
|
|
9286
11867
|
exports.StockOutError = StockOutError;
|
|
@@ -9321,8 +11902,10 @@ exports.isDebuggable = isDebuggable;
|
|
|
9321
11902
|
exports.isUUID = isUUID;
|
|
9322
11903
|
exports.parseDateTime = parseDateTime;
|
|
9323
11904
|
exports.registerClass = registerClass;
|
|
11905
|
+
exports.resolveCacheConfig = resolveCacheConfig;
|
|
9324
11906
|
exports.resolveClass = resolveClass;
|
|
9325
11907
|
exports.serialize = serialize;
|
|
11908
|
+
exports.toCents = toCents;
|
|
9326
11909
|
exports.withCreateFirestore = withCreateFirestore;
|
|
9327
11910
|
exports.withCreateHasuraGraphQL = withCreateHasuraGraphQL;
|
|
9328
11911
|
exports.withCrudFirestore = withCrudFirestore;
|