@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.
Files changed (30) hide show
  1. package/index.cjs.js +296 -65
  2. package/index.esm.js +288 -66
  3. package/package.json +1 -1
  4. package/src/domain/shop-settings/models/shop-configs.d.ts +3 -12
  5. package/src/domain/shop-settings/models/types/antifraud-config.type.d.ts +21 -0
  6. package/src/domain/shop-settings/models/types/index.d.ts +1 -0
  7. package/src/domain/shop-settings/models/types/limit-orders.type.d.ts +3 -2
  8. package/src/domain/shopping/helpers/antifraud-enabled.helper.d.ts +8 -0
  9. package/src/domain/shopping/helpers/antifraud-volume-limits.helper.d.ts +6 -0
  10. package/src/domain/shopping/helpers/index.d.ts +2 -0
  11. package/src/domain/shopping/index.d.ts +1 -0
  12. package/src/domain/shopping/models/campaign-hashtag-posts.d.ts +23 -0
  13. package/src/domain/shopping/models/campaign-hashtag.d.ts +12 -10
  14. package/src/domain/shopping/models/coupons/coupon.d.ts +1 -0
  15. package/src/domain/shopping/models/index.d.ts +2 -0
  16. package/src/domain/shopping/models/pending-order.d.ts +21 -0
  17. package/src/domain/shopping/models/shipping-method.d.ts +1 -0
  18. package/src/domain/shopping/repositories/campaign-hashtag-posts.repository.d.ts +4 -0
  19. package/src/domain/shopping/repositories/index.d.ts +2 -0
  20. package/src/domain/shopping/repositories/pending-order.repository.d.ts +4 -0
  21. package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +3 -1
  22. package/src/domain/shopping/services/antifraud-card.service.d.ts +6 -6
  23. package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +4 -2
  24. package/src/domain/shopping/services/antifraud-pix.service.d.ts +4 -2
  25. package/src/domain/shopping/types/antifraud-card-validation.type.d.ts +40 -0
  26. package/src/domain/shopping/types/antifraud-volume-limits.type.d.ts +24 -0
  27. package/src/domain/shopping/types/index.d.ts +2 -0
  28. package/src/infra/firebase/firestore/repositories/shopping/campaign-hashtag-posts-firestore.repository.d.ts +8 -0
  29. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +2 -0
  30. package/src/infra/firebase/firestore/repositories/shopping/pending-order-firestore.repository.d.ts +7 -0
package/index.esm.js CHANGED
@@ -151,6 +151,123 @@ class PaymentProviderFactory {
151
151
  }
152
152
  }
153
153
 
154
+ const ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS = 60;
155
+ /**
156
+ * Lê `shopConfigs.antifraude.enabled`.
157
+ * - `false` explícito → antifraude desligado
158
+ * - ausente / erro / inválido → `true` (mantém comportamento histórico)
159
+ */
160
+ async function isAntifraudEnabled(shopConfigsRepository) {
161
+ if (!shopConfigsRepository) {
162
+ return true;
163
+ }
164
+ try {
165
+ const result = await shopConfigsRepository.find({}, { cache: { enabled: true, ttl: ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS } });
166
+ const enabled = result?.data?.at(0)?.antifraude?.enabled;
167
+ if (typeof enabled === 'boolean') {
168
+ return enabled;
169
+ }
170
+ return true;
171
+ }
172
+ catch (error) {
173
+ console.warn(JSON.stringify({
174
+ msg: 'antifraud_enabled_config_load_failed',
175
+ enabled: true,
176
+ error: error instanceof Error ? error.message : String(error),
177
+ }));
178
+ return true;
179
+ }
180
+ }
181
+
182
+ /** Defaults de runtime (week.zip = Infinity). Usados só como fallback no checkout. */
183
+ const DEFAULT_ANTIFRAUD_VOLUME_LIMITS = {
184
+ enabled: true,
185
+ source: 'fallback',
186
+ day: {
187
+ subscriber: { cpf: 4, email: 4, phone: 4, card: 4, zip: 4 },
188
+ nonSubscriber: { cpf: 2, email: 2, phone: 2, card: 2, zip: 2 },
189
+ },
190
+ week: {
191
+ subscriber: { cpf: 12, email: 12, phone: 12, card: 12, zip: Infinity },
192
+ nonSubscriber: { cpf: 7, email: 7, phone: 7, card: 7, zip: Infinity },
193
+ },
194
+ blockedAttemptsDay: {
195
+ subscriber: 7,
196
+ nonSubscriber: 5,
197
+ },
198
+ };
199
+ function isPositiveInteger(value) {
200
+ return typeof value === 'number' && Number.isFinite(value) && value >= 1 && Number.isInteger(value);
201
+ }
202
+ function normalizeLimitOrders(raw, allowInfiniteZip) {
203
+ if (!raw)
204
+ return null;
205
+ const zip = allowInfiniteZip && (raw.zip === null || raw.zip === undefined || raw.zip === Infinity) ? Infinity : raw.zip;
206
+ const normalized = {
207
+ cpf: raw.cpf,
208
+ email: raw.email,
209
+ phone: raw.phone,
210
+ zip: zip,
211
+ card: raw.card,
212
+ };
213
+ for (const key of ['cpf', 'email', 'phone', 'zip', 'card']) {
214
+ if (key === 'zip' && normalized.zip === Infinity)
215
+ continue;
216
+ if (!isPositiveInteger(normalized[key]))
217
+ return null;
218
+ }
219
+ return normalized;
220
+ }
221
+ function cloneFallbackLimits() {
222
+ return {
223
+ ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS,
224
+ day: {
225
+ subscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.day.subscriber },
226
+ nonSubscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.day.nonSubscriber },
227
+ },
228
+ week: {
229
+ subscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.week.subscriber },
230
+ nonSubscriber: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.week.nonSubscriber },
231
+ },
232
+ blockedAttemptsDay: { ...DEFAULT_ANTIFRAUD_VOLUME_LIMITS.blockedAttemptsDay },
233
+ source: 'fallback',
234
+ };
235
+ }
236
+ /** Config inválida/ausente → fallback (comportamento histórico). */
237
+ function resolveAntifraudVolumeLimits(antifraude) {
238
+ if (!antifraude || typeof antifraude.enabled !== 'boolean') {
239
+ return cloneFallbackLimits();
240
+ }
241
+ const daySubscriber = normalizeLimitOrders(antifraude.day?.subscriber, false);
242
+ const dayNonSubscriber = normalizeLimitOrders(antifraude.day?.nonSubscriber, false);
243
+ const weekSubscriber = normalizeLimitOrders(antifraude.week?.subscriber, true);
244
+ const weekNonSubscriber = normalizeLimitOrders(antifraude.week?.nonSubscriber, true);
245
+ const blocked = antifraude.blockedAttemptsDay;
246
+ if (!daySubscriber ||
247
+ !dayNonSubscriber ||
248
+ !weekSubscriber ||
249
+ !weekNonSubscriber ||
250
+ !blocked ||
251
+ !isPositiveInteger(blocked.subscriber) ||
252
+ !isPositiveInteger(blocked.nonSubscriber)) {
253
+ // Kill-switch explícito prevalece mesmo com payload inválido.
254
+ if (antifraude.enabled === false) {
255
+ return { ...cloneFallbackLimits(), enabled: false, source: 'fallback' };
256
+ }
257
+ return cloneFallbackLimits();
258
+ }
259
+ return {
260
+ enabled: antifraude.enabled,
261
+ source: 'config',
262
+ day: { subscriber: daySubscriber, nonSubscriber: dayNonSubscriber },
263
+ week: { subscriber: weekSubscriber, nonSubscriber: weekNonSubscriber },
264
+ blockedAttemptsDay: {
265
+ subscriber: blocked.subscriber,
266
+ nonSubscriber: blocked.nonSubscriber,
267
+ },
268
+ };
269
+ }
270
+
154
271
  const registry = new Map();
155
272
  function registerClass(name, classConstructor) {
156
273
  registry.set(name, classConstructor);
@@ -1032,6 +1149,12 @@ class CampaignHashtag extends BaseModel {
1032
1149
  }
1033
1150
  }
1034
1151
 
1152
+ class CampaignHashtagPosts extends BaseModel {
1153
+ static get identifiersFields() {
1154
+ return ['id'];
1155
+ }
1156
+ }
1157
+
1035
1158
  class BeautyProfile extends BaseModel {
1036
1159
  toPlain() {
1037
1160
  const plain = super.toPlain();
@@ -1751,6 +1874,27 @@ class OrderBlocked extends BaseModel {
1751
1874
  }
1752
1875
  }
1753
1876
 
1877
+ /**
1878
+ * Queue document for millenium shop-order send/retry.
1879
+ * Firestore collection remains `transId` (see PendingOrderFirestoreRepository).
1880
+ */
1881
+ class PendingOrder extends BaseModel {
1882
+ static get identifiersFields() {
1883
+ return ['id'];
1884
+ }
1885
+ get firstErrorMessage() {
1886
+ if (!Array.isArray(this.errorMessage) || this.errorMessage.length === 0) {
1887
+ return null;
1888
+ }
1889
+ const first = this.errorMessage[0];
1890
+ if (typeof first !== 'string') {
1891
+ return null;
1892
+ }
1893
+ const trimmed = first.trim();
1894
+ return trimmed ? trimmed : null;
1895
+ }
1896
+ }
1897
+
1754
1898
  class ShoppingRecurrence extends BaseModel {
1755
1899
  static get identifiersFields() {
1756
1900
  return ['id'];
@@ -1900,12 +2044,23 @@ class StockOutError extends BusinessError {
1900
2044
  }
1901
2045
  }
1902
2046
 
2047
+ /* eslint-disable no-console */
1903
2048
  class AntifraudBankSlipService {
1904
- constructor(orderBlockedRepository) {
2049
+ constructor(orderBlockedRepository, shopConfigsRepository) {
1905
2050
  this.orderBlockedRepository = orderBlockedRepository;
2051
+ this.shopConfigsRepository = shopConfigsRepository;
1906
2052
  this.MAX_ORDER_VALUE = 5000;
1907
2053
  }
1908
2054
  async validate(checkout) {
2055
+ const enabled = await isAntifraudEnabled(this.shopConfigsRepository);
2056
+ if (!enabled) {
2057
+ console.info(JSON.stringify({
2058
+ msg: 'antifraud_bankslip_skipped',
2059
+ enabled: false,
2060
+ checkoutId: checkout.id,
2061
+ }));
2062
+ return true;
2063
+ }
1909
2064
  if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
1910
2065
  await this.orderBlockedRepository.createBlockedOrderOrPayment({
1911
2066
  checkout,
@@ -1927,62 +2082,67 @@ class AntifraudBankSlipService {
1927
2082
  }
1928
2083
  }
1929
2084
 
2085
+ /* eslint-disable max-params */
1930
2086
  class AntifraudCardService {
1931
- constructor(orderRepository, orderBlockedRepository) {
2087
+ constructor(orderRepository, orderBlockedRepository, shopConfigsRepository) {
1932
2088
  this.orderRepository = orderRepository;
1933
2089
  this.orderBlockedRepository = orderBlockedRepository;
1934
- this.LIMIT_ORDERS_DAY = null;
1935
- this.LIMIT_ORDERS_WEEK = null;
2090
+ this.shopConfigsRepository = shopConfigsRepository;
1936
2091
  }
1937
2092
  async validate(checkout, card) {
1938
- this.setLimitsByUserType(checkout.user.isSubscriber);
1939
- await this.validateBlockedOrderAttempts(checkout, card);
1940
- await this.validateDayAndWeekOrderLimits(checkout, card);
2093
+ // Limites locais por request — evita race em provider Nest singleton entre awaits.
2094
+ const resolved = await this.loadResolvedLimits();
2095
+ const isSubscriber = !!checkout.user?.isSubscriber;
2096
+ const dayLimits = isSubscriber ? resolved.day.subscriber : resolved.day.nonSubscriber;
2097
+ const weekLimits = isSubscriber ? resolved.week.subscriber : resolved.week.nonSubscriber;
2098
+ const blockedAttemptsDay = isSubscriber
2099
+ ? resolved.blockedAttemptsDay.subscriber
2100
+ : resolved.blockedAttemptsDay.nonSubscriber;
2101
+ if (!resolved.enabled) {
2102
+ console.info(JSON.stringify({
2103
+ msg: 'antifraud_card_volume_skipped',
2104
+ source: resolved.source,
2105
+ enabled: false,
2106
+ checkoutId: checkout.id,
2107
+ isSubscriber,
2108
+ }));
2109
+ return true;
2110
+ }
2111
+ console.info(JSON.stringify({
2112
+ msg: 'antifraud_card_volume_limits',
2113
+ source: resolved.source,
2114
+ enabled: true,
2115
+ checkoutId: checkout.id,
2116
+ isSubscriber,
2117
+ blockedAttemptsDay,
2118
+ day: dayLimits,
2119
+ week: weekLimits,
2120
+ }));
2121
+ await this.validateBlockedOrderAttempts(checkout, card, blockedAttemptsDay);
2122
+ await this.validateDayAndWeekOrderLimits(checkout, card, dayLimits, weekLimits);
1941
2123
  return true;
1942
2124
  }
1943
- setLimitsByUserType(isSubscriber) {
1944
- this.LIMIT_ORDERS_DAY = {
1945
- subscriber: {
1946
- cpf: 4,
1947
- email: 4,
1948
- phone: 4,
1949
- card: 4,
1950
- zip: 4,
1951
- },
1952
- nonSubscriber: {
1953
- cpf: 2,
1954
- email: 2,
1955
- phone: 2,
1956
- card: 2,
1957
- zip: 2,
1958
- },
1959
- };
1960
- this.LIMIT_ORDERS_WEEK = {
1961
- subscriber: {
1962
- cpf: 12,
1963
- email: 12,
1964
- phone: 12,
1965
- card: 12,
1966
- zip: Infinity,
1967
- },
1968
- nonSubscriber: {
1969
- cpf: 7,
1970
- email: 7,
1971
- phone: 7,
1972
- card: 7,
1973
- zip: Infinity,
1974
- },
1975
- };
1976
- this.LIMIT_BLOCKED_ORDERS_DAY = isSubscriber ? 7 : 5;
1977
- }
1978
- getLimitsByUserType(type, isSubscriber) {
1979
- const limits = type === 'day' ? this.LIMIT_ORDERS_DAY : this.LIMIT_ORDERS_WEEK;
1980
- return isSubscriber ? limits['subscriber'] : limits['nonSubscriber'];
2125
+ async loadResolvedLimits() {
2126
+ if (!this.shopConfigsRepository) {
2127
+ return resolveAntifraudVolumeLimits(null);
2128
+ }
2129
+ try {
2130
+ const result = await this.shopConfigsRepository.find({}, { cache: { enabled: true, ttl: ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS } });
2131
+ return resolveAntifraudVolumeLimits(result?.data?.at(0)?.antifraude);
2132
+ }
2133
+ catch (error) {
2134
+ console.warn(JSON.stringify({
2135
+ msg: 'antifraud_card_volume_config_load_failed',
2136
+ source: 'fallback',
2137
+ error: error instanceof Error ? error.message : String(error),
2138
+ }));
2139
+ return resolveAntifraudVolumeLimits(null);
2140
+ }
1981
2141
  }
1982
- async validateBlockedOrderAttempts(checkout, card) {
1983
- const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
2142
+ async validateBlockedOrderAttempts(checkout, card, blockedAttemptsDay) {
2143
+ const isValid = await this.verifyBlockedOrderAttempts(checkout, card, blockedAttemptsDay);
1984
2144
  if (!isValid) {
1985
- throw new FraudValidationError(`Cliente com mais de ${this.LIMIT_BLOCKED_ORDERS_DAY} compras negadas/bloqueadas no dia`, ErrorsCode.fraudPreventionInternal, {
2145
+ throw new FraudValidationError(`Cliente com mais de ${blockedAttemptsDay} compras negadas/bloqueadas no dia`, ErrorsCode.fraudPreventionInternal, {
1986
2146
  checkoutId: checkout.id,
1987
2147
  userEmail: checkout.user.email,
1988
2148
  info: {
@@ -1993,8 +2153,8 @@ class AntifraudCardService {
1993
2153
  });
1994
2154
  }
1995
2155
  }
1996
- async validateDayAndWeekOrderLimits(checkout, card) {
1997
- const isValid = await this.verifyDayAndWeekOrders(checkout, card);
2156
+ async validateDayAndWeekOrderLimits(checkout, card, dayLimits, weekLimits) {
2157
+ const isValid = await this.verifyDayAndWeekOrders(checkout, card, dayLimits, weekLimits);
1998
2158
  if (!isValid) {
1999
2159
  throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', ErrorsCode.fraudPreventionInternal, {
2000
2160
  checkoutId: checkout.id,
@@ -2007,15 +2167,15 @@ class AntifraudCardService {
2007
2167
  });
2008
2168
  }
2009
2169
  }
2010
- async verifyBlockedOrderAttempts(checkout, card) {
2170
+ async verifyBlockedOrderAttempts(checkout, card, blockedAttemptsDay) {
2011
2171
  const dateRange = this.getTodayDateRange();
2012
2172
  const blockedOrders = await this.getBlockedOrdersByMultipleCriteria(checkout, dateRange);
2013
2173
  const totalBlockedAttempts = this.calculateUniqueBlockedAttempts(blockedOrders, checkout);
2014
- if (totalBlockedAttempts >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2174
+ if (totalBlockedAttempts >= blockedAttemptsDay) {
2015
2175
  await this.createBlockedOrderRecord({
2016
2176
  checkout,
2017
2177
  card,
2018
- reason: `More than ${this.LIMIT_BLOCKED_ORDERS_DAY} attempts have failed`,
2178
+ reason: `More than ${blockedAttemptsDay} attempts have failed`,
2019
2179
  key: 'Failed attempts',
2020
2180
  period: 'day',
2021
2181
  });
@@ -2117,12 +2277,12 @@ class AntifraudCardService {
2117
2277
  card,
2118
2278
  });
2119
2279
  }
2120
- async verifyDayAndWeekOrders(checkout, card) {
2280
+ async verifyDayAndWeekOrders(checkout, card, dayLimits, weekLimits) {
2121
2281
  const validationParams = this.buildValidationParams(checkout, card);
2122
- const isDayLimitValid = await this.validateDayOrderLimits(checkout, validationParams);
2282
+ const isDayLimitValid = await this.validateDayOrderLimits(checkout, validationParams, dayLimits);
2123
2283
  if (!isDayLimitValid)
2124
2284
  return false;
2125
- const isWeekLimitValid = await this.validateWeekOrderLimits(checkout, validationParams);
2285
+ const isWeekLimitValid = await this.validateWeekOrderLimits(checkout, validationParams, weekLimits);
2126
2286
  return isWeekLimitValid;
2127
2287
  }
2128
2288
  buildValidationParams(checkout, card) {
@@ -2134,9 +2294,8 @@ class AntifraudCardService {
2134
2294
  card,
2135
2295
  };
2136
2296
  }
2137
- async validateDayOrderLimits(checkout, params) {
2297
+ async validateDayOrderLimits(checkout, params, limits) {
2138
2298
  const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
2139
- const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
2140
2299
  return this.checkOrderLimitsAndBlock({
2141
2300
  checkout,
2142
2301
  orderCounts: ordersPerDay,
@@ -2144,9 +2303,8 @@ class AntifraudCardService {
2144
2303
  period: 'day',
2145
2304
  });
2146
2305
  }
2147
- async validateWeekOrderLimits(checkout, params) {
2306
+ async validateWeekOrderLimits(checkout, params, limits) {
2148
2307
  const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
2149
- const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
2150
2308
  return this.checkOrderLimitsAndBlock({
2151
2309
  checkout,
2152
2310
  orderCounts: ordersPerWeek,
@@ -2223,15 +2381,35 @@ class AntifraudCardService {
2223
2381
  }
2224
2382
 
2225
2383
  class AntifraudGlampointsService {
2226
- constructor() { }
2227
- async validate(_checkout) {
2384
+ constructor(shopConfigsRepository) {
2385
+ this.shopConfigsRepository = shopConfigsRepository;
2386
+ }
2387
+ async validate(checkout) {
2388
+ const enabled = await isAntifraudEnabled(this.shopConfigsRepository);
2389
+ if (!enabled) {
2390
+ console.info(JSON.stringify({
2391
+ msg: 'antifraud_glampoints_skipped',
2392
+ enabled: false,
2393
+ checkoutId: checkout.id,
2394
+ }));
2395
+ }
2228
2396
  return true;
2229
2397
  }
2230
2398
  }
2231
2399
 
2232
2400
  class AntifraudPixService {
2233
- constructor() { }
2234
- async validate(_checkout) {
2401
+ constructor(shopConfigsRepository) {
2402
+ this.shopConfigsRepository = shopConfigsRepository;
2403
+ }
2404
+ async validate(checkout) {
2405
+ const enabled = await isAntifraudEnabled(this.shopConfigsRepository);
2406
+ if (!enabled) {
2407
+ console.info(JSON.stringify({
2408
+ msg: 'antifraud_pix_skipped',
2409
+ enabled: false,
2410
+ checkoutId: checkout.id,
2411
+ }));
2412
+ }
2235
2413
  return true;
2236
2414
  }
2237
2415
  }
@@ -2585,6 +2763,26 @@ class ShopSettings extends BaseModel {
2585
2763
  }
2586
2764
  }
2587
2765
 
2766
+ /**
2767
+ * Defaults iguais ao hardcode histórico do checkout.
2768
+ * `week.*.zip = null` → Infinity no runtime do volume de cartão.
2769
+ */
2770
+ const DEFAULT_SHOP_ANTIFRAUD_CONFIG = {
2771
+ enabled: true,
2772
+ day: {
2773
+ subscriber: { cpf: 4, email: 4, phone: 4, card: 4, zip: 4 },
2774
+ nonSubscriber: { cpf: 2, email: 2, phone: 2, card: 2, zip: 2 },
2775
+ },
2776
+ week: {
2777
+ subscriber: { cpf: 12, email: 12, phone: 12, card: 12, zip: null },
2778
+ nonSubscriber: { cpf: 7, email: 7, phone: 7, card: 7, zip: null },
2779
+ },
2780
+ blockedAttemptsDay: {
2781
+ subscriber: 7,
2782
+ nonSubscriber: 5,
2783
+ },
2784
+ };
2785
+
2588
2786
  class AdyenBlockedOrderHelper {
2589
2787
  static async handleUnauthorizedPayment(params) {
2590
2788
  await params.orderBlockedRepository.createBlockedOrderOrPayment({
@@ -5468,7 +5666,7 @@ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(w
5468
5666
  constructor({ firestore, interceptors, cache, }) {
5469
5667
  super({
5470
5668
  firestore,
5471
- collectionName: 'hashtagCampaignsAuto',
5669
+ collectionName: 'CampaignsHashtags',
5472
5670
  model: CampaignHashtag,
5473
5671
  interceptors,
5474
5672
  cache,
@@ -5476,6 +5674,18 @@ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(w
5476
5674
  }
5477
5675
  }
5478
5676
 
5677
+ class CampaignHashtagPostsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
5678
+ constructor({ firestore, interceptors, cache, }) {
5679
+ super({
5680
+ firestore,
5681
+ collectionName: 'CampaignsHashtagsPosts',
5682
+ model: CampaignHashtagPosts,
5683
+ interceptors,
5684
+ cache,
5685
+ });
5686
+ }
5687
+ }
5688
+
5479
5689
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
5480
5690
  constructor({ firestore, interceptors, cache, }) {
5481
5691
  super({
@@ -5631,6 +5841,18 @@ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFires
5631
5841
  }
5632
5842
  }
5633
5843
 
5844
+ class PendingOrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
5845
+ constructor({ firestore, interceptors, cache, }) {
5846
+ super({
5847
+ firestore,
5848
+ collectionName: 'transId',
5849
+ model: PendingOrder,
5850
+ interceptors,
5851
+ cache,
5852
+ });
5853
+ }
5854
+ }
5855
+
5634
5856
  class ShoppingRecurrenceEditionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
5635
5857
  constructor({ firestore, interceptors, cache, }) {
5636
5858
  super({
@@ -11581,4 +11803,4 @@ class ProductsVertexSearch {
11581
11803
  }
11582
11804
  }
11583
11805
 
11584
- export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandCategory, BrandCategoryFirestoreRepository, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, ErrorsCode, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, InvalidCheckoutError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, MercadoPagoBankSlipAxiosAdapter, MercadoPagoCardAxiosAdapter, MercadoPagoErrorHelper, MercadoPagoPaymentMethodFactory, MercadoPagoPixAxiosAdapter, MercadoPagoRequestHelper, MercadoPagoResponseHelper, MercadoPagoStatusDetailEnum, MercadoPagoStatusEnum, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderPaymentStatus, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5BaseAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductCatalogHasuraGraphQL, ProductCatalogHasuraGraphQLRepository, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductGroup, ProductGroupHasuraGraphQLRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductPriceLog, ProductPriceLogHasuraGraphQLRepository, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockEntry, ProductStockEntryHasuraGraphQL, ProductStockEntryHasuraGraphQLRepository, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopConfigs, ShopConfigsFirestoreRepository, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, ShoppingRecurrence, ShoppingRecurrenceCycle, ShoppingRecurrenceEdition, ShoppingRecurrenceEditionFirestoreRepository, ShoppingRecurrenceEditionStatus, ShoppingRecurrenceErrorLog, ShoppingRecurrenceErrorLogFirestoreRepository, ShoppingRecurrenceFirestoreRepository, ShoppingRecurrenceStatus, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveCacheConfig, resolveClass, serialize, toCents, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
11806
+ export { ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS, AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandCategory, BrandCategoryFirestoreRepository, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, CampaignHashtagPosts, CampaignHashtagPostsFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, DEFAULT_ANTIFRAUD_VOLUME_LIMITS, DEFAULT_SHOP_ANTIFRAUD_CONFIG, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, ErrorsCode, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, InvalidCheckoutError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, MercadoPagoBankSlipAxiosAdapter, MercadoPagoCardAxiosAdapter, MercadoPagoErrorHelper, MercadoPagoPaymentMethodFactory, MercadoPagoPixAxiosAdapter, MercadoPagoRequestHelper, MercadoPagoResponseHelper, MercadoPagoStatusDetailEnum, MercadoPagoStatusEnum, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderPaymentStatus, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5BaseAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PendingOrder, PendingOrderFirestoreRepository, PersonTypes, Plans, Product, ProductCatalogHasuraGraphQL, ProductCatalogHasuraGraphQLRepository, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductGroup, ProductGroupHasuraGraphQLRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductPriceLog, ProductPriceLogHasuraGraphQLRepository, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockEntry, ProductStockEntryHasuraGraphQL, ProductStockEntryHasuraGraphQLRepository, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopConfigs, ShopConfigsFirestoreRepository, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, ShoppingRecurrence, ShoppingRecurrenceCycle, ShoppingRecurrenceEdition, ShoppingRecurrenceEditionFirestoreRepository, ShoppingRecurrenceEditionStatus, ShoppingRecurrenceErrorLog, ShoppingRecurrenceErrorLogFirestoreRepository, ShoppingRecurrenceFirestoreRepository, ShoppingRecurrenceStatus, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isAntifraudEnabled, isDebuggable, isUUID, parseDateTime, registerClass, resolveAntifraudVolumeLimits, resolveCacheConfig, resolveClass, serialize, toCents, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.3.0-beta.31",
3
+ "version": "5.3.0-beta.33",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1,18 +1,9 @@
1
1
  import { BaseModel, GenericIdentifier } from '../../generic/model';
2
- import { LimitOrders, ShopErrorMessages, ShopSameDayNotAvailable } from './types';
2
+ import { ShopAntifraudConfig, ShopErrorMessages, ShopSameDayNotAvailable } from './types';
3
3
  export declare class ShopConfigs extends BaseModel<ShopConfigs> {
4
+ id: string;
4
5
  errors?: ShopErrorMessages[];
5
- antifraude?: {
6
- enabled: boolean;
7
- week: {
8
- subscriber: LimitOrders;
9
- nonSubscriber: LimitOrders;
10
- };
11
- day: {
12
- subscriber: LimitOrders;
13
- nonSubscriber: LimitOrders;
14
- };
15
- };
6
+ antifraude?: ShopAntifraudConfig;
16
7
  sameDayNotAvaliable?: ShopSameDayNotAvailable;
17
8
  static get identifiersFields(): GenericIdentifier[];
18
9
  }
@@ -0,0 +1,21 @@
1
+ import { LimitOrders } from './limit-orders.type';
2
+ export type AntifraudBlockedAttemptsDay = {
3
+ subscriber: number;
4
+ nonSubscriber: number;
5
+ };
6
+ export type AntifraudPeriodLimits = {
7
+ subscriber: LimitOrders;
8
+ nonSubscriber: LimitOrders;
9
+ };
10
+ /** Shape persistido em Firestore `shopConfigs.antifraude`. */
11
+ export type ShopAntifraudConfig = {
12
+ enabled: boolean;
13
+ day: AntifraudPeriodLimits;
14
+ week: AntifraudPeriodLimits;
15
+ blockedAttemptsDay: AntifraudBlockedAttemptsDay;
16
+ };
17
+ /**
18
+ * Defaults iguais ao hardcode histórico do checkout.
19
+ * `week.*.zip = null` → Infinity no runtime do volume de cartão.
20
+ */
21
+ export declare const DEFAULT_SHOP_ANTIFRAUD_CONFIG: ShopAntifraudConfig;
@@ -1,3 +1,4 @@
1
+ export * from './antifraud-config.type';
1
2
  export * from './banner.type';
2
3
  export * from './benefit.type';
3
4
  export * from './brands-carousel.type';
@@ -2,6 +2,7 @@ export type LimitOrders = {
2
2
  cpf: number;
3
3
  email: number;
4
4
  phone: number;
5
- zip: number;
6
- card?: number;
5
+ /** Na semana, `null` no Firestore vira Infinity no runtime do antifraude. */
6
+ zip: number | null;
7
+ card: number;
7
8
  };
@@ -0,0 +1,8 @@
1
+ import { ShopConfigsRepository } from '../../shop-settings';
2
+ export declare const ANTIFRAUD_CONFIG_CACHE_TTL_SECONDS = 60;
3
+ /**
4
+ * Lê `shopConfigs.antifraude.enabled`.
5
+ * - `false` explícito → antifraude desligado
6
+ * - ausente / erro / inválido → `true` (mantém comportamento histórico)
7
+ */
8
+ export declare function isAntifraudEnabled(shopConfigsRepository?: ShopConfigsRepository): Promise<boolean>;
@@ -0,0 +1,6 @@
1
+ import { ShopAntifraudConfig } from '../../shop-settings/models/types';
2
+ import { ResolvedAntifraudVolumeLimits } from '../types/antifraud-volume-limits.type';
3
+ /** Defaults de runtime (week.zip = Infinity). Usados só como fallback no checkout. */
4
+ export declare const DEFAULT_ANTIFRAUD_VOLUME_LIMITS: ResolvedAntifraudVolumeLimits;
5
+ /** Config inválida/ausente → fallback (comportamento histórico). */
6
+ export declare function resolveAntifraudVolumeLimits(antifraude: ShopAntifraudConfig | undefined | null): ResolvedAntifraudVolumeLimits;
@@ -0,0 +1,2 @@
1
+ export * from './antifraud-enabled.helper';
2
+ export * from './antifraud-volume-limits.helper';
@@ -1,5 +1,6 @@
1
1
  export * from './enums';
2
2
  export * from './factories';
3
+ export * from './helpers';
3
4
  export * from './interfaces';
4
5
  export * from './models';
5
6
  export * from './repositories';
@@ -0,0 +1,23 @@
1
+ import { BaseModel, GenericIdentifier } from '../../generic';
2
+ export declare class CampaignHashtagPosts extends BaseModel<CampaignHashtagPosts> {
3
+ id: string;
4
+ campaignId: string;
5
+ postUrl: string;
6
+ status: string;
7
+ approved: boolean;
8
+ rating: number;
9
+ personId: number;
10
+ personAccount: string;
11
+ postAnalysis: string;
12
+ postEvaluationDate?: Date;
13
+ consent?: boolean;
14
+ consentDate?: Date;
15
+ metadata: {
16
+ IPAddress: string;
17
+ UserAgent: string;
18
+ Platform: string;
19
+ };
20
+ createdAt?: Date;
21
+ updatedAt?: Date;
22
+ static get identifiersFields(): GenericIdentifier[];
23
+ }
@@ -1,18 +1,20 @@
1
1
  import { BaseModel, GenericIdentifier } from '../../generic';
2
2
  export declare class CampaignHashtag extends BaseModel<CampaignHashtag> {
3
3
  id: string;
4
- status?: string;
5
- updatedAt?: string;
6
- environment: string;
7
- campaignName?: string;
8
- campaignImage?: string;
9
- campaignMinGlampoints?: number;
10
- campaignMaxGlampoints?: number;
11
- campaignReferCode?: string;
12
- campaignDescription?: string;
4
+ active: boolean;
5
+ title: string;
6
+ hashtagCode: string;
7
+ image?: string;
8
+ minimumGlampoints: number;
9
+ maximumGlampoints: number;
10
+ description?: string;
13
11
  startDate?: Date;
14
12
  endDate?: Date;
15
- campaignSubscribed: boolean;
13
+ steps?: string[];
16
14
  rules?: string[];
15
+ postsToShowInHome?: number;
16
+ topPosts?: string[];
17
+ createdAt?: Date;
18
+ updatedAt?: Date;
17
19
  static get identifiersFields(): GenericIdentifier[];
18
20
  }