@infrab4a/connect 5.3.0-beta.31 → 5.3.0-beta.33
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 +296 -65
- package/index.esm.js +288 -66
- package/package.json +1 -1
- package/src/domain/shop-settings/models/shop-configs.d.ts +3 -12
- package/src/domain/shop-settings/models/types/antifraud-config.type.d.ts +21 -0
- package/src/domain/shop-settings/models/types/index.d.ts +1 -0
- package/src/domain/shop-settings/models/types/limit-orders.type.d.ts +3 -2
- package/src/domain/shopping/helpers/antifraud-enabled.helper.d.ts +8 -0
- package/src/domain/shopping/helpers/antifraud-volume-limits.helper.d.ts +6 -0
- package/src/domain/shopping/helpers/index.d.ts +2 -0
- package/src/domain/shopping/index.d.ts +1 -0
- package/src/domain/shopping/models/campaign-hashtag-posts.d.ts +23 -0
- package/src/domain/shopping/models/campaign-hashtag.d.ts +12 -10
- package/src/domain/shopping/models/coupons/coupon.d.ts +1 -0
- package/src/domain/shopping/models/index.d.ts +2 -0
- package/src/domain/shopping/models/pending-order.d.ts +21 -0
- package/src/domain/shopping/models/shipping-method.d.ts +1 -0
- package/src/domain/shopping/repositories/campaign-hashtag-posts.repository.d.ts +4 -0
- package/src/domain/shopping/repositories/index.d.ts +2 -0
- package/src/domain/shopping/repositories/pending-order.repository.d.ts +4 -0
- package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +3 -1
- package/src/domain/shopping/services/antifraud-card.service.d.ts +6 -6
- package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +4 -2
- package/src/domain/shopping/services/antifraud-pix.service.d.ts +4 -2
- package/src/domain/shopping/types/antifraud-card-validation.type.d.ts +40 -0
- package/src/domain/shopping/types/antifraud-volume-limits.type.d.ts +24 -0
- package/src/domain/shopping/types/index.d.ts +2 -0
- package/src/infra/firebase/firestore/repositories/shopping/campaign-hashtag-posts-firestore.repository.d.ts +8 -0
- package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +2 -0
- package/src/infra/firebase/firestore/repositories/shopping/pending-order-firestore.repository.d.ts +7 -0
package/index.cjs.js
CHANGED
|
@@ -157,6 +157,123 @@ class PaymentProviderFactory {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
const ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS = 60;
|
|
161
|
+
/**
|
|
162
|
+
* Lê `shopConfigs.antifraude.enabled`.
|
|
163
|
+
* - `false` explícito → antifraude desligado
|
|
164
|
+
* - ausente / erro / inválido → `true` (mantém comportamento histórico)
|
|
165
|
+
*/
|
|
166
|
+
async function isAntifraudEnabled(shopConfigsRepository) {
|
|
167
|
+
if (!shopConfigsRepository) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const result = await shopConfigsRepository.find({}, { cache: { enabled: true, ttl: ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS } });
|
|
172
|
+
const enabled = result?.data?.at(0)?.antifraude?.enabled;
|
|
173
|
+
if (typeof enabled === 'boolean') {
|
|
174
|
+
return enabled;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
console.warn(JSON.stringify({
|
|
180
|
+
msg: 'antifraud_enabled_config_load_failed',
|
|
181
|
+
enabled: true,
|
|
182
|
+
error: error instanceof Error ? error.message : String(error),
|
|
183
|
+
}));
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Defaults de runtime (week.zip = Infinity). Usados só como fallback no checkout. */
|
|
189
|
+
const DEFAULT_ANTIFRAUD_VOLUME_LIMITS = {
|
|
190
|
+
enabled: true,
|
|
191
|
+
source: 'fallback',
|
|
192
|
+
day: {
|
|
193
|
+
subscriber: { cpf: 4, email: 4, phone: 4, card: 4, zip: 4 },
|
|
194
|
+
nonSubscriber: { cpf: 2, email: 2, phone: 2, card: 2, zip: 2 },
|
|
195
|
+
},
|
|
196
|
+
week: {
|
|
197
|
+
subscriber: { cpf: 12, email: 12, phone: 12, card: 12, zip: Infinity },
|
|
198
|
+
nonSubscriber: { cpf: 7, email: 7, phone: 7, card: 7, zip: Infinity },
|
|
199
|
+
},
|
|
200
|
+
blockedAttemptsDay: {
|
|
201
|
+
subscriber: 7,
|
|
202
|
+
nonSubscriber: 5,
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
function isPositiveInteger(value) {
|
|
206
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 1 && Number.isInteger(value);
|
|
207
|
+
}
|
|
208
|
+
function normalizeLimitOrders(raw, allowInfiniteZip) {
|
|
209
|
+
if (!raw)
|
|
210
|
+
return null;
|
|
211
|
+
const zip = allowInfiniteZip && (raw.zip === null || raw.zip === undefined || raw.zip === Infinity) ? Infinity : raw.zip;
|
|
212
|
+
const normalized = {
|
|
213
|
+
cpf: raw.cpf,
|
|
214
|
+
email: raw.email,
|
|
215
|
+
phone: raw.phone,
|
|
216
|
+
zip: zip,
|
|
217
|
+
card: raw.card,
|
|
218
|
+
};
|
|
219
|
+
for (const key of ['cpf', 'email', 'phone', 'zip', 'card']) {
|
|
220
|
+
if (key === 'zip' && normalized.zip === Infinity)
|
|
221
|
+
continue;
|
|
222
|
+
if (!isPositiveInteger(normalized[key]))
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
return normalized;
|
|
226
|
+
}
|
|
227
|
+
function cloneFallbackLimits() {
|
|
228
|
+
return {
|
|
229
|
+
...DEFAULT_ANTIFRAUD_VOLUME_LIMITS,
|
|
230
|
+
day: {
|
|
231
|
+
subscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.day.subscriber },
|
|
232
|
+
nonSubscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.day.nonSubscriber },
|
|
233
|
+
},
|
|
234
|
+
week: {
|
|
235
|
+
subscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.week.subscriber },
|
|
236
|
+
nonSubscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.week.nonSubscriber },
|
|
237
|
+
},
|
|
238
|
+
blockedAttemptsDay: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.blockedAttemptsDay },
|
|
239
|
+
source: 'fallback',
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** Config inválida/ausente → fallback (comportamento histórico). */
|
|
243
|
+
function resolveAntifraudVolumeLimits(antifraude) {
|
|
244
|
+
if (!antifraude || typeof antifraude.enabled !== 'boolean') {
|
|
245
|
+
return cloneFallbackLimits();
|
|
246
|
+
}
|
|
247
|
+
const daySubscriber = normalizeLimitOrders(antifraude.day?.subscriber, false);
|
|
248
|
+
const dayNonSubscriber = normalizeLimitOrders(antifraude.day?.nonSubscriber, false);
|
|
249
|
+
const weekSubscriber = normalizeLimitOrders(antifraude.week?.subscriber, true);
|
|
250
|
+
const weekNonSubscriber = normalizeLimitOrders(antifraude.week?.nonSubscriber, true);
|
|
251
|
+
const blocked = antifraude.blockedAttemptsDay;
|
|
252
|
+
if (!daySubscriber ||
|
|
253
|
+
!dayNonSubscriber ||
|
|
254
|
+
!weekSubscriber ||
|
|
255
|
+
!weekNonSubscriber ||
|
|
256
|
+
!blocked ||
|
|
257
|
+
!isPositiveInteger(blocked.subscriber) ||
|
|
258
|
+
!isPositiveInteger(blocked.nonSubscriber)) {
|
|
259
|
+
// Kill-switch explícito prevalece mesmo com payload inválido.
|
|
260
|
+
if (antifraude.enabled === false) {
|
|
261
|
+
return { ...cloneFallbackLimits(), enabled: false, source: 'fallback' };
|
|
262
|
+
}
|
|
263
|
+
return cloneFallbackLimits();
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
enabled: antifraude.enabled,
|
|
267
|
+
source: 'config',
|
|
268
|
+
day: { subscriber: daySubscriber, nonSubscriber: dayNonSubscriber },
|
|
269
|
+
week: { subscriber: weekSubscriber, nonSubscriber: weekNonSubscriber },
|
|
270
|
+
blockedAttemptsDay: {
|
|
271
|
+
subscriber: blocked.subscriber,
|
|
272
|
+
nonSubscriber: blocked.nonSubscriber,
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
160
277
|
const registry = new Map();
|
|
161
278
|
function registerClass(name, classConstructor) {
|
|
162
279
|
registry.set(name, classConstructor);
|
|
@@ -1038,6 +1155,12 @@ class CampaignHashtag extends BaseModel {
|
|
|
1038
1155
|
}
|
|
1039
1156
|
}
|
|
1040
1157
|
|
|
1158
|
+
class CampaignHashtagPosts extends BaseModel {
|
|
1159
|
+
static get identifiersFields() {
|
|
1160
|
+
return ['id'];
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1041
1164
|
class BeautyProfile extends BaseModel {
|
|
1042
1165
|
toPlain() {
|
|
1043
1166
|
const plain = super.toPlain();
|
|
@@ -1757,6 +1880,27 @@ class OrderBlocked extends BaseModel {
|
|
|
1757
1880
|
}
|
|
1758
1881
|
}
|
|
1759
1882
|
|
|
1883
|
+
/**
|
|
1884
|
+
* Queue document for millenium shop-order send/retry.
|
|
1885
|
+
* Firestore collection remains `transId` (see PendingOrderFirestoreRepository).
|
|
1886
|
+
*/
|
|
1887
|
+
class PendingOrder extends BaseModel {
|
|
1888
|
+
static get identifiersFields() {
|
|
1889
|
+
return ['id'];
|
|
1890
|
+
}
|
|
1891
|
+
get firstErrorMessage() {
|
|
1892
|
+
if (!Array.isArray(this.errorMessage) || this.errorMessage.length === 0) {
|
|
1893
|
+
return null;
|
|
1894
|
+
}
|
|
1895
|
+
const first = this.errorMessage[0];
|
|
1896
|
+
if (typeof first !== 'string') {
|
|
1897
|
+
return null;
|
|
1898
|
+
}
|
|
1899
|
+
const trimmed = first.trim();
|
|
1900
|
+
return trimmed ? trimmed : null;
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1760
1904
|
class ShoppingRecurrence extends BaseModel {
|
|
1761
1905
|
static get identifiersFields() {
|
|
1762
1906
|
return ['id'];
|
|
@@ -1906,12 +2050,23 @@ class StockOutError extends BusinessError {
|
|
|
1906
2050
|
}
|
|
1907
2051
|
}
|
|
1908
2052
|
|
|
2053
|
+
/* eslint-disable no-console */
|
|
1909
2054
|
class AntifraudBankSlipService {
|
|
1910
|
-
constructor(orderBlockedRepository) {
|
|
2055
|
+
constructor(orderBlockedRepository, shopConfigsRepository) {
|
|
1911
2056
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
2057
|
+
this.shopConfigsRepository = shopConfigsRepository;
|
|
1912
2058
|
this.MAX_ORDER_VALUE = 5000;
|
|
1913
2059
|
}
|
|
1914
2060
|
async validate(checkout) {
|
|
2061
|
+
const enabled = await isAntifraudEnabled(this.shopConfigsRepository);
|
|
2062
|
+
if (!enabled) {
|
|
2063
|
+
console.info(JSON.stringify({
|
|
2064
|
+
msg: 'antifraud_bankslip_skipped',
|
|
2065
|
+
enabled: false,
|
|
2066
|
+
checkoutId: checkout.id,
|
|
2067
|
+
}));
|
|
2068
|
+
return true;
|
|
2069
|
+
}
|
|
1915
2070
|
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
|
|
1916
2071
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
1917
2072
|
checkout,
|
|
@@ -1933,62 +2088,67 @@ class AntifraudBankSlipService {
|
|
|
1933
2088
|
}
|
|
1934
2089
|
}
|
|
1935
2090
|
|
|
2091
|
+
/* eslint-disable max-params */
|
|
1936
2092
|
class AntifraudCardService {
|
|
1937
|
-
constructor(orderRepository, orderBlockedRepository) {
|
|
2093
|
+
constructor(orderRepository, orderBlockedRepository, shopConfigsRepository) {
|
|
1938
2094
|
this.orderRepository = orderRepository;
|
|
1939
2095
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
1940
|
-
this.
|
|
1941
|
-
this.LIMIT_ORDERS_WEEK = null;
|
|
2096
|
+
this.shopConfigsRepository = shopConfigsRepository;
|
|
1942
2097
|
}
|
|
1943
2098
|
async validate(checkout, card) {
|
|
1944
|
-
|
|
1945
|
-
await this.
|
|
1946
|
-
|
|
2099
|
+
// Limites locais por request — evita race em provider Nest singleton entre awaits.
|
|
2100
|
+
const resolved = await this.loadResolvedLimits();
|
|
2101
|
+
const isSubscriber = !!checkout.user?.isSubscriber;
|
|
2102
|
+
const dayLimits = isSubscriber ? resolved.day.subscriber : resolved.day.nonSubscriber;
|
|
2103
|
+
const weekLimits = isSubscriber ? resolved.week.subscriber : resolved.week.nonSubscriber;
|
|
2104
|
+
const blockedAttemptsDay = isSubscriber
|
|
2105
|
+
? resolved.blockedAttemptsDay.subscriber
|
|
2106
|
+
: resolved.blockedAttemptsDay.nonSubscriber;
|
|
2107
|
+
if (!resolved.enabled) {
|
|
2108
|
+
console.info(JSON.stringify({
|
|
2109
|
+
msg: 'antifraud_card_volume_skipped',
|
|
2110
|
+
source: resolved.source,
|
|
2111
|
+
enabled: false,
|
|
2112
|
+
checkoutId: checkout.id,
|
|
2113
|
+
isSubscriber,
|
|
2114
|
+
}));
|
|
2115
|
+
return true;
|
|
2116
|
+
}
|
|
2117
|
+
console.info(JSON.stringify({
|
|
2118
|
+
msg: 'antifraud_card_volume_limits',
|
|
2119
|
+
source: resolved.source,
|
|
2120
|
+
enabled: true,
|
|
2121
|
+
checkoutId: checkout.id,
|
|
2122
|
+
isSubscriber,
|
|
2123
|
+
blockedAttemptsDay,
|
|
2124
|
+
day: dayLimits,
|
|
2125
|
+
week: weekLimits,
|
|
2126
|
+
}));
|
|
2127
|
+
await this.validateBlockedOrderAttempts(checkout, card, blockedAttemptsDay);
|
|
2128
|
+
await this.validateDayAndWeekOrderLimits(checkout, card, dayLimits, weekLimits);
|
|
1947
2129
|
return true;
|
|
1948
2130
|
}
|
|
1949
|
-
|
|
1950
|
-
this.
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
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'];
|
|
2131
|
+
async loadResolvedLimits() {
|
|
2132
|
+
if (!this.shopConfigsRepository) {
|
|
2133
|
+
return resolveAntifraudVolumeLimits(null);
|
|
2134
|
+
}
|
|
2135
|
+
try {
|
|
2136
|
+
const result = await this.shopConfigsRepository.find({}, { cache: { enabled: true, ttl: ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS } });
|
|
2137
|
+
return resolveAntifraudVolumeLimits(result?.data?.at(0)?.antifraude);
|
|
2138
|
+
}
|
|
2139
|
+
catch (error) {
|
|
2140
|
+
console.warn(JSON.stringify({
|
|
2141
|
+
msg: 'antifraud_card_volume_config_load_failed',
|
|
2142
|
+
source: 'fallback',
|
|
2143
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2144
|
+
}));
|
|
2145
|
+
return resolveAntifraudVolumeLimits(null);
|
|
2146
|
+
}
|
|
1987
2147
|
}
|
|
1988
|
-
async validateBlockedOrderAttempts(checkout, card) {
|
|
1989
|
-
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
2148
|
+
async validateBlockedOrderAttempts(checkout, card, blockedAttemptsDay) {
|
|
2149
|
+
const isValid = await this.verifyBlockedOrderAttempts(checkout, card, blockedAttemptsDay);
|
|
1990
2150
|
if (!isValid) {
|
|
1991
|
-
throw new FraudValidationError(`Cliente com mais de ${
|
|
2151
|
+
throw new FraudValidationError(`Cliente com mais de ${blockedAttemptsDay} compras negadas/bloqueadas no dia`, exports.ErrorsCode.fraudPreventionInternal, {
|
|
1992
2152
|
checkoutId: checkout.id,
|
|
1993
2153
|
userEmail: checkout.user.email,
|
|
1994
2154
|
info: {
|
|
@@ -1999,8 +2159,8 @@ class AntifraudCardService {
|
|
|
1999
2159
|
});
|
|
2000
2160
|
}
|
|
2001
2161
|
}
|
|
2002
|
-
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
2003
|
-
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
2162
|
+
async validateDayAndWeekOrderLimits(checkout, card, dayLimits, weekLimits) {
|
|
2163
|
+
const isValid = await this.verifyDayAndWeekOrders(checkout, card, dayLimits, weekLimits);
|
|
2004
2164
|
if (!isValid) {
|
|
2005
2165
|
throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', exports.ErrorsCode.fraudPreventionInternal, {
|
|
2006
2166
|
checkoutId: checkout.id,
|
|
@@ -2013,15 +2173,15 @@ class AntifraudCardService {
|
|
|
2013
2173
|
});
|
|
2014
2174
|
}
|
|
2015
2175
|
}
|
|
2016
|
-
async verifyBlockedOrderAttempts(checkout, card) {
|
|
2176
|
+
async verifyBlockedOrderAttempts(checkout, card, blockedAttemptsDay) {
|
|
2017
2177
|
const dateRange = this.getTodayDateRange();
|
|
2018
2178
|
const blockedOrders = await this.getBlockedOrdersByMultipleCriteria(checkout, dateRange);
|
|
2019
2179
|
const totalBlockedAttempts = this.calculateUniqueBlockedAttempts(blockedOrders, checkout);
|
|
2020
|
-
if (totalBlockedAttempts >=
|
|
2180
|
+
if (totalBlockedAttempts >= blockedAttemptsDay) {
|
|
2021
2181
|
await this.createBlockedOrderRecord({
|
|
2022
2182
|
checkout,
|
|
2023
2183
|
card,
|
|
2024
|
-
reason: `More than ${
|
|
2184
|
+
reason: `More than ${blockedAttemptsDay} attempts have failed`,
|
|
2025
2185
|
key: 'Failed attempts',
|
|
2026
2186
|
period: 'day',
|
|
2027
2187
|
});
|
|
@@ -2123,12 +2283,12 @@ class AntifraudCardService {
|
|
|
2123
2283
|
card,
|
|
2124
2284
|
});
|
|
2125
2285
|
}
|
|
2126
|
-
async verifyDayAndWeekOrders(checkout, card) {
|
|
2286
|
+
async verifyDayAndWeekOrders(checkout, card, dayLimits, weekLimits) {
|
|
2127
2287
|
const validationParams = this.buildValidationParams(checkout, card);
|
|
2128
|
-
const isDayLimitValid = await this.validateDayOrderLimits(checkout, validationParams);
|
|
2288
|
+
const isDayLimitValid = await this.validateDayOrderLimits(checkout, validationParams, dayLimits);
|
|
2129
2289
|
if (!isDayLimitValid)
|
|
2130
2290
|
return false;
|
|
2131
|
-
const isWeekLimitValid = await this.validateWeekOrderLimits(checkout, validationParams);
|
|
2291
|
+
const isWeekLimitValid = await this.validateWeekOrderLimits(checkout, validationParams, weekLimits);
|
|
2132
2292
|
return isWeekLimitValid;
|
|
2133
2293
|
}
|
|
2134
2294
|
buildValidationParams(checkout, card) {
|
|
@@ -2140,9 +2300,8 @@ class AntifraudCardService {
|
|
|
2140
2300
|
card,
|
|
2141
2301
|
};
|
|
2142
2302
|
}
|
|
2143
|
-
async validateDayOrderLimits(checkout, params) {
|
|
2303
|
+
async validateDayOrderLimits(checkout, params, limits) {
|
|
2144
2304
|
const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
|
|
2145
|
-
const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
|
|
2146
2305
|
return this.checkOrderLimitsAndBlock({
|
|
2147
2306
|
checkout,
|
|
2148
2307
|
orderCounts: ordersPerDay,
|
|
@@ -2150,9 +2309,8 @@ class AntifraudCardService {
|
|
|
2150
2309
|
period: 'day',
|
|
2151
2310
|
});
|
|
2152
2311
|
}
|
|
2153
|
-
async validateWeekOrderLimits(checkout, params) {
|
|
2312
|
+
async validateWeekOrderLimits(checkout, params, limits) {
|
|
2154
2313
|
const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
|
|
2155
|
-
const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
|
|
2156
2314
|
return this.checkOrderLimitsAndBlock({
|
|
2157
2315
|
checkout,
|
|
2158
2316
|
orderCounts: ordersPerWeek,
|
|
@@ -2229,15 +2387,35 @@ class AntifraudCardService {
|
|
|
2229
2387
|
}
|
|
2230
2388
|
|
|
2231
2389
|
class AntifraudGlampointsService {
|
|
2232
|
-
constructor() {
|
|
2233
|
-
|
|
2390
|
+
constructor(shopConfigsRepository) {
|
|
2391
|
+
this.shopConfigsRepository = shopConfigsRepository;
|
|
2392
|
+
}
|
|
2393
|
+
async validate(checkout) {
|
|
2394
|
+
const enabled = await isAntifraudEnabled(this.shopConfigsRepository);
|
|
2395
|
+
if (!enabled) {
|
|
2396
|
+
console.info(JSON.stringify({
|
|
2397
|
+
msg: 'antifraud_glampoints_skipped',
|
|
2398
|
+
enabled: false,
|
|
2399
|
+
checkoutId: checkout.id,
|
|
2400
|
+
}));
|
|
2401
|
+
}
|
|
2234
2402
|
return true;
|
|
2235
2403
|
}
|
|
2236
2404
|
}
|
|
2237
2405
|
|
|
2238
2406
|
class AntifraudPixService {
|
|
2239
|
-
constructor() {
|
|
2240
|
-
|
|
2407
|
+
constructor(shopConfigsRepository) {
|
|
2408
|
+
this.shopConfigsRepository = shopConfigsRepository;
|
|
2409
|
+
}
|
|
2410
|
+
async validate(checkout) {
|
|
2411
|
+
const enabled = await isAntifraudEnabled(this.shopConfigsRepository);
|
|
2412
|
+
if (!enabled) {
|
|
2413
|
+
console.info(JSON.stringify({
|
|
2414
|
+
msg: 'antifraud_pix_skipped',
|
|
2415
|
+
enabled: false,
|
|
2416
|
+
checkoutId: checkout.id,
|
|
2417
|
+
}));
|
|
2418
|
+
}
|
|
2241
2419
|
return true;
|
|
2242
2420
|
}
|
|
2243
2421
|
}
|
|
@@ -2591,6 +2769,26 @@ class ShopSettings extends BaseModel {
|
|
|
2591
2769
|
}
|
|
2592
2770
|
}
|
|
2593
2771
|
|
|
2772
|
+
/**
|
|
2773
|
+
* Defaults iguais ao hardcode histórico do checkout.
|
|
2774
|
+
* `week.*.zip = null` → Infinity no runtime do volume de cartão.
|
|
2775
|
+
*/
|
|
2776
|
+
const DEFAULT_SHOP_ANTIFRAUD_CONFIG = {
|
|
2777
|
+
enabled: true,
|
|
2778
|
+
day: {
|
|
2779
|
+
subscriber: { cpf: 4, email: 4, phone: 4, card: 4, zip: 4 },
|
|
2780
|
+
nonSubscriber: { cpf: 2, email: 2, phone: 2, card: 2, zip: 2 },
|
|
2781
|
+
},
|
|
2782
|
+
week: {
|
|
2783
|
+
subscriber: { cpf: 12, email: 12, phone: 12, card: 12, zip: null },
|
|
2784
|
+
nonSubscriber: { cpf: 7, email: 7, phone: 7, card: 7, zip: null },
|
|
2785
|
+
},
|
|
2786
|
+
blockedAttemptsDay: {
|
|
2787
|
+
subscriber: 7,
|
|
2788
|
+
nonSubscriber: 5,
|
|
2789
|
+
},
|
|
2790
|
+
};
|
|
2791
|
+
|
|
2594
2792
|
class AdyenBlockedOrderHelper {
|
|
2595
2793
|
static async handleUnauthorizedPayment(params) {
|
|
2596
2794
|
await params.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
@@ -5474,7 +5672,7 @@ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(w
|
|
|
5474
5672
|
constructor({ firestore, interceptors, cache, }) {
|
|
5475
5673
|
super({
|
|
5476
5674
|
firestore,
|
|
5477
|
-
collectionName: '
|
|
5675
|
+
collectionName: 'CampaignsHashtags',
|
|
5478
5676
|
model: CampaignHashtag,
|
|
5479
5677
|
interceptors,
|
|
5480
5678
|
cache,
|
|
@@ -5482,6 +5680,18 @@ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(w
|
|
|
5482
5680
|
}
|
|
5483
5681
|
}
|
|
5484
5682
|
|
|
5683
|
+
class CampaignHashtagPostsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5684
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5685
|
+
super({
|
|
5686
|
+
firestore,
|
|
5687
|
+
collectionName: 'CampaignsHashtagsPosts',
|
|
5688
|
+
model: CampaignHashtagPosts,
|
|
5689
|
+
interceptors,
|
|
5690
|
+
cache,
|
|
5691
|
+
});
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
|
|
5485
5695
|
class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5486
5696
|
constructor({ firestore, interceptors, cache, }) {
|
|
5487
5697
|
super({
|
|
@@ -5637,6 +5847,18 @@ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
5637
5847
|
}
|
|
5638
5848
|
}
|
|
5639
5849
|
|
|
5850
|
+
class PendingOrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5851
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5852
|
+
super({
|
|
5853
|
+
firestore,
|
|
5854
|
+
collectionName: 'transId',
|
|
5855
|
+
model: PendingOrder,
|
|
5856
|
+
interceptors,
|
|
5857
|
+
cache,
|
|
5858
|
+
});
|
|
5859
|
+
}
|
|
5860
|
+
}
|
|
5861
|
+
|
|
5640
5862
|
class ShoppingRecurrenceEditionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5641
5863
|
constructor({ firestore, interceptors, cache, }) {
|
|
5642
5864
|
super({
|
|
@@ -11715,6 +11937,7 @@ Object.defineProperty(exports, 'unset', {
|
|
|
11715
11937
|
enumerable: true,
|
|
11716
11938
|
get: function () { return lodash.unset; }
|
|
11717
11939
|
});
|
|
11940
|
+
exports.ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS = ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS;
|
|
11718
11941
|
exports.Address = Address;
|
|
11719
11942
|
exports.AdyenCardAxiosAdapter = AdyenCardAxiosAdapter;
|
|
11720
11943
|
exports.AdyenPaymentMethodFactory = AdyenPaymentMethodFactory;
|
|
@@ -11741,6 +11964,8 @@ exports.CampaignDashboard = CampaignDashboard;
|
|
|
11741
11964
|
exports.CampaignDashboardFirestoreRepository = CampaignDashboardFirestoreRepository;
|
|
11742
11965
|
exports.CampaignHashtag = CampaignHashtag;
|
|
11743
11966
|
exports.CampaignHashtagFirestoreRepository = CampaignHashtagFirestoreRepository;
|
|
11967
|
+
exports.CampaignHashtagPosts = CampaignHashtagPosts;
|
|
11968
|
+
exports.CampaignHashtagPostsFirestoreRepository = CampaignHashtagPostsFirestoreRepository;
|
|
11744
11969
|
exports.Category = Category;
|
|
11745
11970
|
exports.CategoryCollectionChildren = CategoryCollectionChildren;
|
|
11746
11971
|
exports.CategoryCollectionChildrenHasuraGraphQLRepository = CategoryCollectionChildrenHasuraGraphQLRepository;
|
|
@@ -11762,6 +11987,8 @@ exports.ConnectDocumentService = ConnectDocumentService;
|
|
|
11762
11987
|
exports.ConnectFirestoreService = ConnectFirestoreService;
|
|
11763
11988
|
exports.Coupon = Coupon;
|
|
11764
11989
|
exports.CouponFirestoreRepository = CouponFirestoreRepository;
|
|
11990
|
+
exports.DEFAULT_ANTIFRAUD_VOLUME_LIMITS = DEFAULT_ANTIFRAUD_VOLUME_LIMITS;
|
|
11991
|
+
exports.DEFAULT_SHOP_ANTIFRAUD_CONFIG = DEFAULT_SHOP_ANTIFRAUD_CONFIG;
|
|
11765
11992
|
exports.Debug = Debug;
|
|
11766
11993
|
exports.DebugDecoratorHelper = DebugDecoratorHelper;
|
|
11767
11994
|
exports.DebugHelper = DebugHelper;
|
|
@@ -11817,6 +12044,8 @@ exports.PaymentError = PaymentError;
|
|
|
11817
12044
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|
|
11818
12045
|
exports.PaymentProviderFactory = PaymentProviderFactory;
|
|
11819
12046
|
exports.PaymentTransaction = PaymentTransaction;
|
|
12047
|
+
exports.PendingOrder = PendingOrder;
|
|
12048
|
+
exports.PendingOrderFirestoreRepository = PendingOrderFirestoreRepository;
|
|
11820
12049
|
exports.Product = Product;
|
|
11821
12050
|
exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
|
|
11822
12051
|
exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
|
|
@@ -11898,10 +12127,12 @@ exports.WishlistHasuraGraphQLRepository = WishlistHasuraGraphQLRepository;
|
|
|
11898
12127
|
exports.deserialize = deserialize;
|
|
11899
12128
|
exports.getClass = getClass;
|
|
11900
12129
|
exports.is = is;
|
|
12130
|
+
exports.isAntifraudEnabled = isAntifraudEnabled;
|
|
11901
12131
|
exports.isDebuggable = isDebuggable;
|
|
11902
12132
|
exports.isUUID = isUUID;
|
|
11903
12133
|
exports.parseDateTime = parseDateTime;
|
|
11904
12134
|
exports.registerClass = registerClass;
|
|
12135
|
+
exports.resolveAntifraudVolumeLimits = resolveAntifraudVolumeLimits;
|
|
11905
12136
|
exports.resolveCacheConfig = resolveCacheConfig;
|
|
11906
12137
|
exports.resolveClass = resolveClass;
|
|
11907
12138
|
exports.serialize = serialize;
|