@infrab4a/connect 0.17.0-beta.2 → 0.17.0-beta.3

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 (99) hide show
  1. package/bundles/infrab4a-connect.umd.js +267 -198
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/catalog/models/enums/shops.enum.d.ts +2 -1
  4. package/domain/shopping/models/coupons/coupon.d.ts +5 -4
  5. package/domain/shopping/models/coupons/enums/coupon-types.enum.d.ts +2 -4
  6. package/domain/shopping/models/coupons/index.d.ts +0 -1
  7. package/domain/shopping/models/enums/checkout-types.enum.d.ts +2 -1
  8. package/domain/users/models/subscription/edition.d.ts +2 -0
  9. package/domain/users/models/user-payment-method.d.ts +1 -0
  10. package/domain/users/models/user.d.ts +1 -0
  11. package/esm2015/domain/catalog/models/enums/shops.enum.js +2 -1
  12. package/esm2015/domain/shopping/models/coupons/coupon.js +17 -2
  13. package/esm2015/domain/shopping/models/coupons/enums/coupon-subtypes.enum.js +1 -1
  14. package/esm2015/domain/shopping/models/coupons/enums/coupon-types.enum.js +7 -5
  15. package/esm2015/domain/shopping/models/coupons/index.js +1 -2
  16. package/esm2015/domain/shopping/models/enums/checkout-types.enum.js +2 -1
  17. package/esm2015/domain/users/models/subscription/edition.js +1 -1
  18. package/esm2015/domain/users/models/user-payment-method.js +1 -1
  19. package/esm2015/domain/users/models/user.js +1 -1
  20. package/esm2015/infra/firebase/auth/authentication-firebase-auth.service.js +6 -6
  21. package/esm2015/infra/firebase/auth/register-firebase-auth.service.js +4 -5
  22. package/esm2015/infra/firebase/auth/types/firebase-user-with-id.type.js +1 -1
  23. package/esm2015/infra/firebase/firestore/mixins/with-create-firestore.mixin.js +5 -7
  24. package/esm2015/infra/firebase/firestore/mixins/with-delete-firestore.mixin.js +4 -3
  25. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +25 -31
  26. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +4 -4
  27. package/esm2015/infra/firebase/firestore/mixins/with-get-firestore.mixin.js +5 -4
  28. package/esm2015/infra/firebase/firestore/mixins/with-helpers.mixin.js +1 -1
  29. package/esm2015/infra/firebase/firestore/mixins/with-sub-collection.mixin.js +1 -1
  30. package/esm2015/infra/firebase/firestore/mixins/with-update-firestore.mixin.js +10 -9
  31. package/esm2015/infra/firebase/firestore/repositories/catalog/category-firestore.repository.js +37 -19
  32. package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +1 -1
  33. package/esm2015/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.js +1 -1
  34. package/esm2015/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.js +1 -1
  35. package/esm2015/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.js +4 -4
  36. package/esm2015/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.js +1 -1
  37. package/esm2015/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.js +1 -1
  38. package/esm2015/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.js +1 -1
  39. package/esm2015/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.js +1 -1
  40. package/esm2015/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.js +1 -1
  41. package/esm2015/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.js +1 -1
  42. package/esm2015/infra/firebase/firestore/repositories/shopping/order-firestore.repository.js +1 -1
  43. package/esm2015/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.js +1 -1
  44. package/esm2015/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.js +1 -1
  45. package/esm2015/infra/firebase/firestore/repositories/users/lead-firestore.repository.js +1 -1
  46. package/esm2015/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.js +1 -1
  47. package/esm2015/infra/firebase/firestore/repositories/users/subscription-firestore.repository.js +1 -1
  48. package/esm2015/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.js +1 -1
  49. package/esm2015/infra/firebase/firestore/repositories/users/user-address-firestore.repository.js +1 -1
  50. package/esm2015/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.js +1 -1
  51. package/esm2015/infra/firebase/firestore/repositories/users/user-firestore.repository.js +12 -4
  52. package/esm2015/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.js +1 -1
  53. package/esm2015/infra/firebase/firestore/repositories/users/user-search-firestore.repository.js +1 -1
  54. package/esm2015/infra/firebase/firestore/types/firestore.helpers.type.js +1 -1
  55. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  56. package/esm2015/utils/index.js +2 -3
  57. package/fesm2015/infrab4a-connect.js +125 -105
  58. package/fesm2015/infrab4a-connect.js.map +1 -1
  59. package/infra/firebase/auth/authentication-firebase-auth.service.d.ts +2 -2
  60. package/infra/firebase/auth/register-firebase-auth.service.d.ts +5 -4
  61. package/infra/firebase/auth/types/firebase-user-with-id.type.d.ts +1 -2
  62. package/infra/firebase/firestore/mixins/with-create-firestore.mixin.d.ts +4 -4
  63. package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +8 -8
  64. package/infra/firebase/firestore/mixins/with-delete-firestore.mixin.d.ts +3 -3
  65. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +7 -7
  66. package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +2 -2
  67. package/infra/firebase/firestore/mixins/with-get-firestore.mixin.d.ts +3 -3
  68. package/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  69. package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +2 -2
  70. package/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +3 -3
  71. package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +16 -18
  72. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +16 -16
  73. package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +18 -18
  74. package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +16 -16
  75. package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +14 -14
  76. package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +16 -16
  77. package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +16 -16
  78. package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +16 -16
  79. package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +16 -16
  80. package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +14 -14
  81. package/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +3 -3
  82. package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +16 -16
  83. package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +16 -16
  84. package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +16 -16
  85. package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +16 -16
  86. package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +18 -18
  87. package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +16 -16
  88. package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +18 -18
  89. package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +18 -18
  90. package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +18 -18
  91. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +14 -14
  92. package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +18 -18
  93. package/infra/firebase/firestore/repositories/users/user-search-firestore.repository.d.ts +16 -16
  94. package/infra/firebase/firestore/types/firestore.helpers.type.d.ts +1 -1
  95. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +2 -2
  96. package/package.json +2 -2
  97. package/utils/index.d.ts +1 -1
  98. package/domain/shopping/models/coupons/financial-coupon.d.ts +0 -9
  99. package/esm2015/domain/shopping/models/coupons/financial-coupon.js +0 -28
@@ -2,11 +2,11 @@ import 'reflect-metadata';
2
2
  import { plainToClass, classToPlain, Expose, Type } from 'class-transformer';
3
3
  import { __decorate, __metadata, __awaiter } from 'tslib';
4
4
  export { add, sub } from 'date-fns';
5
- import lodash from 'lodash';
6
- import { Md5 } from 'ts-md5';
5
+ import { isNil, isNumber, isString, isDate, set, isObject, isEmpty, chunk } from 'lodash';
6
+ export { chunk, get, isDate, isEmpty, isNil, isNumber, isObject, isString, pick, set } from 'lodash';
7
7
  import axios from 'axios';
8
- import { collection, Timestamp, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc } from 'firebase/firestore';
9
- import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
8
+ import firebase from 'firebase';
9
+ import firebase$1 from 'firebase/app';
10
10
 
11
11
  class BaseModel {
12
12
  constructor(args) {
@@ -450,6 +450,7 @@ var CheckoutTypes;
450
450
  (function (CheckoutTypes) {
451
451
  CheckoutTypes[CheckoutTypes["ECOMMERCE"] = 1] = "ECOMMERCE";
452
452
  CheckoutTypes[CheckoutTypes["SUBSCRIPTION"] = 2] = "SUBSCRIPTION";
453
+ CheckoutTypes[CheckoutTypes["ALL"] = 3] = "ALL";
453
454
  })(CheckoutTypes || (CheckoutTypes = {}));
454
455
 
455
456
  class Base {
@@ -458,14 +459,14 @@ class Base {
458
459
  }
459
460
  }
460
461
 
461
- const { chunk, get, isDate, isEmpty, isNil, isNumber, isObject, isString, pick, set } = lodash;
462
-
463
462
  var CouponTypes;
464
463
  (function (CouponTypes) {
465
- CouponTypes[CouponTypes["FINANCIAL"] = 1] = "FINANCIAL";
466
- CouponTypes[CouponTypes["PRODUCT"] = 2] = "PRODUCT";
467
- CouponTypes[CouponTypes["GIFTCARD"] = 3] = "GIFTCARD";
468
- CouponTypes[CouponTypes["VOUCHER"] = 4] = "VOUCHER";
464
+ CouponTypes[CouponTypes["ABSOLUTE"] = 1] = "ABSOLUTE";
465
+ CouponTypes[CouponTypes["PERCENTAGE"] = 2] = "PERCENTAGE";
466
+ // FINANCIAL = 1,
467
+ // PRODUCT,
468
+ // GIFTCARD,
469
+ // VOUCHER,
469
470
  })(CouponTypes || (CouponTypes = {}));
470
471
 
471
472
  var CouponSubtypes;
@@ -481,6 +482,7 @@ var Exclusivities;
481
482
  Exclusivities[Exclusivities["COLLABORATORS"] = 3] = "COLLABORATORS";
482
483
  })(Exclusivities || (Exclusivities = {}));
483
484
 
485
+ const COUPON_EXPIRATION = 60 * 60 * 24 * 30;
484
486
  class Coupon extends BaseModel {
485
487
  get isInfluencer() {
486
488
  return !isNil(this.influencerEmail);
@@ -488,6 +490,20 @@ class Coupon extends BaseModel {
488
490
  identifierFields() {
489
491
  return ['id'];
490
492
  }
493
+ static createCoupon(userId) {
494
+ return this.toInstance({
495
+ nickname: `${Date.now()}`,
496
+ type: CouponTypes.ABSOLUTE,
497
+ checkoutType: CheckoutTypes.ECOMMERCE,
498
+ discount: 30,
499
+ user: userId,
500
+ useLimit: 1,
501
+ useLimitPerUser: 1,
502
+ createdAt: new Date(Date.now()),
503
+ beginAt: new Date(Date.now()),
504
+ expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
505
+ });
506
+ }
491
507
  }
492
508
  __decorate([
493
509
  Expose({ name: 'checkout_type' }),
@@ -703,6 +719,7 @@ var Shops;
703
719
  Shops["MENSMARKET"] = "mensmarket";
704
720
  Shops["GLAMSHOP"] = "Glamshop";
705
721
  Shops["GLAMPOINTS"] = "Glampoints";
722
+ Shops["ALL"] = "ALL";
706
723
  })(Shops || (Shops = {}));
707
724
 
708
725
  class Category extends BaseModel {
@@ -727,30 +744,6 @@ class Variant extends BaseModel {
727
744
  }
728
745
  }
729
746
 
730
- const COUPON_EXPIRATION = 60 * 60 * 24 * 30;
731
- class FinancialCoupon extends Coupon {
732
- constructor() {
733
- super(...arguments);
734
- this.type = CouponTypes.FINANCIAL;
735
- }
736
- static isFinancialCoupon(coupon) {
737
- return coupon.type === CouponTypes.FINANCIAL && !!coupon.subtype;
738
- }
739
- static createCoupon(userId) {
740
- return this.toInstance({
741
- name: Md5.hashStr(`${userId}_${Date.now}`).toString(),
742
- nickname: `${Date.now()}`,
743
- type: CouponTypes.FINANCIAL,
744
- subtype: CouponSubtypes.PERCENTAGE,
745
- checkoutType: CheckoutTypes.ECOMMERCE,
746
- discount: 30,
747
- user: userId,
748
- createdAt: new Date(Date.now()),
749
- expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
750
- });
751
- }
752
- }
753
-
754
747
  var OrderStatus;
755
748
  (function (OrderStatus) {
756
749
  OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
@@ -1051,7 +1044,7 @@ const withFirestore = (MixinBase) => {
1051
1044
  super(args);
1052
1045
  }
1053
1046
  collection(path) {
1054
- return collection(this.firestore, path || this.collectionName).withConverter(this.buildModelInstance());
1047
+ return this.firestore.collection(path || this.collectionName).withConverter(this.buildModelInstance());
1055
1048
  }
1056
1049
  buildModelInstance() {
1057
1050
  return {
@@ -1059,7 +1052,7 @@ const withFirestore = (MixinBase) => {
1059
1052
  fromFirestore: (snap) => {
1060
1053
  const data = snap.data();
1061
1054
  Object.keys(data).forEach((key) => {
1062
- if (data[key] instanceof Timestamp) {
1055
+ if (data[key] instanceof firebase.firestore.Timestamp) {
1063
1056
  data[key] = data[key].toDate();
1064
1057
  }
1065
1058
  });
@@ -1090,8 +1083,10 @@ const withGetFirestore = (MixinBase) => {
1090
1083
  return class GetFirestore extends MixinBase {
1091
1084
  get(identifiers) {
1092
1085
  return __awaiter(this, void 0, void 0, function* () {
1093
- const docRef = yield getDoc(doc(yield this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(identifiers).shift().toString()));
1094
- const data = docRef.data();
1086
+ const doc = yield this.collection(this.buildCollectionPathForGet(identifiers))
1087
+ .doc(Object.values(identifiers).shift().toString())
1088
+ .get();
1089
+ const data = doc.data();
1095
1090
  if (isNil(data))
1096
1091
  throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
1097
1092
  return data;
@@ -1116,13 +1111,10 @@ const withFindFirestore = (MixinBase) => {
1116
1111
  return class FindFirestore extends MixinBase {
1117
1112
  constructor() {
1118
1113
  super(...arguments);
1119
- this.makeFirestoreWhere = (filter) => Object.keys(filter).reduce((queries, fieldName) => [
1120
- ...queries,
1121
- ...this.buildWhereSentence(fieldName, filter[fieldName]),
1122
- ], []);
1123
- this.buildWhereSentence = (fieldName, options) => {
1114
+ this.makeFirestoreWhere = (queryReference, filter) => Object.keys(filter).reduce((query, fieldName) => this.buildWhereSentence(query, fieldName, filter[fieldName]), queryReference);
1115
+ this.buildWhereSentence = (queryReference, fieldName, options) => {
1124
1116
  if (this.isSubCollection(this) && fieldName === this.parentIdField)
1125
- [];
1117
+ return queryReference;
1126
1118
  const value = (options === null || options === void 0 ? void 0 : options.value) || options;
1127
1119
  const object = {};
1128
1120
  set(object, fieldName, value);
@@ -1132,33 +1124,30 @@ const withFindFirestore = (MixinBase) => {
1132
1124
  : Object.keys(plainInstance).find((key) => plainInstance[key]);
1133
1125
  if ((options === null || options === void 0 ? void 0 : options.operator) === Where.LIKE) {
1134
1126
  if (Array.isArray(options === null || options === void 0 ? void 0 : options.value))
1135
- return [where(firestoreFieldName, 'array-contains-any', options.value)];
1136
- return [where(firestoreFieldName, '>=', options.value), where(firestoreFieldName, '<=', `${options.value}~`)];
1127
+ return queryReference.where(firestoreFieldName, 'array-contains-any', options.value);
1128
+ queryReference = queryReference.where(firestoreFieldName, '>=', options.value);
1129
+ queryReference = queryReference.where(firestoreFieldName, '<=', `${options.value}~`);
1130
+ return queryReference;
1137
1131
  }
1138
1132
  if ((options === null || options === void 0 ? void 0 : options.operator) === Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
1139
- return [where(firestoreFieldName, 'array-contains', options.value)];
1133
+ return queryReference.where(firestoreFieldName, 'array-contains', options.value);
1140
1134
  if (isObject(options) && isNil(options === null || options === void 0 ? void 0 : options.operator) && isNil(options === null || options === void 0 ? void 0 : options.value)) {
1141
- return Object.keys(options).reduce((queries, key) => [...queries, ...this.buildWhereSentence(`${fieldName.toString()}.${key}`, options[key])], []);
1135
+ return Object.keys(options).reduce((queryReferenceWithWhere, key) => this.buildWhereSentence(queryReferenceWithWhere, `${fieldName}.${key}`, options[key]), queryReference);
1142
1136
  }
1143
- return [where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options)];
1137
+ return queryReference.where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
1144
1138
  };
1145
1139
  }
1146
- find(filters, limitList, orderByList) {
1140
+ find(filters, limits, orderBy) {
1147
1141
  return __awaiter(this, void 0, void 0, function* () {
1148
- const collection = this.collection(this.buildCollectionPathForFind(filters));
1149
- const queries = (filters === null || filters === void 0 ? void 0 : filters.reduce((queriesBuilded, filterer) => [...queriesBuilded, ...this.makeFirestoreWhere(filterer)], [])) ||
1150
- [];
1151
- const ordination = (orderByList === null || orderByList === void 0 ? void 0 : orderByList.reduce((ordinationBuilded, sort) => [
1152
- ...ordinationBuilded,
1153
- ...Object.keys(sort).map((fieldName) => orderBy(fieldName, sort[fieldName])),
1154
- ], [])) || [];
1155
- const limits = yield this.defineLimits(filters, limitList);
1156
- const queryArgumments = [...queries, ...ordination, ...limits];
1157
- const docs = yield getDocs(query(collection, ...queryArgumments));
1142
+ let query = this.collection(this.buildCollectionPathForFind(filters));
1143
+ filters === null || filters === void 0 ? void 0 : filters.forEach((filterer) => (query = this.makeFirestoreWhere(query, filterer)));
1144
+ orderBy === null || orderBy === void 0 ? void 0 : orderBy.forEach((orderer) => Object.keys(orderer).forEach((fieldName) => (query = query.orderBy(fieldName, orderer[fieldName]))));
1145
+ query = yield this.defineLimits(query, filters, limits);
1146
+ const docs = yield query.get();
1158
1147
  const data = docs.docs.map((doc) => doc.data());
1159
1148
  return {
1160
1149
  data,
1161
- count: this.calculateCount(data, limitList),
1150
+ count: this.calculateCount(data, limits),
1162
1151
  };
1163
1152
  });
1164
1153
  }
@@ -1170,18 +1159,19 @@ const withFindFirestore = (MixinBase) => {
1170
1159
  const parentId = getValueFromFilter((_a = filters.find((groupFilter) => Boolean(getValueFromFilter(groupFilter[parentIdField])))) === null || _a === void 0 ? void 0 : _a[parentIdField]);
1171
1160
  return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
1172
1161
  }
1173
- defineLimits(filters, limits) {
1162
+ defineLimits(query, filters, limits) {
1174
1163
  return __awaiter(this, void 0, void 0, function* () {
1175
- const queries = [];
1176
1164
  if (limits === null || limits === void 0 ? void 0 : limits.offset) {
1177
1165
  if (limits.offset instanceof this.model)
1178
- queries.push(startAfter(yield getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), limits.offset[limits.offset.identifierFields().shift()]))));
1166
+ query = query.startAfter(yield this.collection(this.buildCollectionPathForFind(filters))
1167
+ .doc(limits.offset[limits.offset.identifierFields().shift()])
1168
+ .get());
1179
1169
  else if (isNumber(limits.offset) || isString(limits.offset))
1180
- queries.push(startAt(limits.offset));
1170
+ query = query.startAt(limits.offset);
1181
1171
  }
1182
1172
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
1183
- queries.push(limit(limits.limit));
1184
- return queries;
1173
+ query = query.limit(limits.limit);
1174
+ return query;
1185
1175
  });
1186
1176
  }
1187
1177
  calculateCount(data, limits) {
@@ -1199,7 +1189,7 @@ const withCreateFirestore = (MixinBase) => {
1199
1189
  create(data) {
1200
1190
  return __awaiter(this, void 0, void 0, function* () {
1201
1191
  const docRef = yield this.save(this.model.toInstance(data));
1202
- const doc = yield getDoc(docRef);
1192
+ const doc = yield docRef.get();
1203
1193
  return doc.data();
1204
1194
  });
1205
1195
  }
@@ -1208,11 +1198,10 @@ const withCreateFirestore = (MixinBase) => {
1208
1198
  return __awaiter(this, void 0, void 0, function* () {
1209
1199
  const id = (_a = data[data.identifierFields().shift()]) === null || _a === void 0 ? void 0 : _a.toString();
1210
1200
  const collectionPath = this.buildCollectionPathForAdd(data);
1211
- const collection = this.collection(collectionPath);
1212
1201
  if (isEmpty(id))
1213
- return addDoc(collection, data);
1214
- const docRef = doc(collection, id);
1215
- yield setDoc(docRef, data);
1202
+ return this.collection(collectionPath).add(data);
1203
+ const docRef = this.collection(collectionPath).doc(id);
1204
+ yield docRef.set(data);
1216
1205
  return docRef;
1217
1206
  });
1218
1207
  }
@@ -1227,15 +1216,16 @@ const withCreateFirestore = (MixinBase) => {
1227
1216
  const withUpdateFirestore = (MixinBase) => {
1228
1217
  const getValueFromParams = (params, field) => { var _a; return (isNil((_a = params[field]) === null || _a === void 0 ? void 0 : _a.value) ? params[field] : params[field].value) || null; };
1229
1218
  const getValueByAction = (options) => {
1219
+ const fieldValues = firebase.firestore.FieldValue;
1230
1220
  if (isNil(options.action))
1231
1221
  return options;
1232
1222
  if (options.action === UpdateOptionActions.REMOVE_FIELD)
1233
- return deleteField();
1223
+ return fieldValues.delete();
1234
1224
  if (Array.isArray(options.value)) {
1235
1225
  if (options.action === UpdateOptionActions.MERGE)
1236
- return arrayUnion(...options.value);
1226
+ return fieldValues.arrayUnion(...options.value);
1237
1227
  if (options.action === UpdateOptionActions.REMOVE)
1238
- return arrayRemove(...options.value);
1228
+ return fieldValues.arrayRemove(...options.value);
1239
1229
  }
1240
1230
  return options.value;
1241
1231
  };
@@ -1244,10 +1234,10 @@ const withUpdateFirestore = (MixinBase) => {
1244
1234
  return __awaiter(this, void 0, void 0, function* () {
1245
1235
  const model = new this.model();
1246
1236
  const keyField = model.identifierFields().shift();
1247
- const docRef = doc(this.collection(this.buildCollectionPathForUpdate(data)), getValueFromParams(data, keyField).toString());
1248
- yield setDoc(docRef, this.paramsToPlain(data), { merge: true });
1249
- const docData = yield getDoc(docRef);
1250
- return docData.data();
1237
+ const docRef = this.collection(this.buildCollectionPathForUpdate(data)).doc(getValueFromParams(data, keyField).toString());
1238
+ yield docRef.set(this.paramsToPlain(data), { merge: true });
1239
+ const doc = yield docRef.get();
1240
+ return doc.data();
1251
1241
  });
1252
1242
  }
1253
1243
  buildCollectionPathForUpdate(identifiers) {
@@ -1268,7 +1258,9 @@ const withDeleteFirestore = (MixinBase) => {
1268
1258
  return class DeleteFirestore extends MixinBase {
1269
1259
  delete(identifiers) {
1270
1260
  return __awaiter(this, void 0, void 0, function* () {
1271
- yield deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(identifiers).shift().toString()));
1261
+ yield this.collection(this.buildCollectionPathForRemove(identifiers))
1262
+ .doc(Object.values(identifiers).shift().toString())
1263
+ .delete();
1272
1264
  });
1273
1265
  }
1274
1266
  buildCollectionPathForRemove(identifiers) {
@@ -1357,13 +1349,22 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1357
1349
  }
1358
1350
  getBeautyProfile(userId) {
1359
1351
  return __awaiter(this, void 0, void 0, function* () {
1360
- const beautyProfile = yield getDoc(doc(this.collection(`${this.collectionName}/${userId}/CX`).withConverter(this.buildBeautyProfileModelInstance()), 'beautyProfile'));
1352
+ const beautyProfile = yield this.collection()
1353
+ .doc(userId)
1354
+ .collection('CX')
1355
+ .withConverter(this.buildBeautyProfileModelInstance())
1356
+ .doc('beautyProfile')
1357
+ .get();
1361
1358
  return beautyProfile.data();
1362
1359
  });
1363
1360
  }
1364
1361
  checkIfIsSubscriber(userId) {
1365
1362
  return __awaiter(this, void 0, void 0, function* () {
1366
- const docs = yield getDocs(query(this.collection('subscription'), where('user.id', '==', userId), where('status', '==', 'active')));
1363
+ const docs = yield this.firestore
1364
+ .collection('subscription')
1365
+ .where('user.id', '==', userId)
1366
+ .where('status', '==', 'active')
1367
+ .get();
1367
1368
  return !!docs && !!docs.size;
1368
1369
  });
1369
1370
  }
@@ -1440,26 +1441,33 @@ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1440
1441
  }
1441
1442
 
1442
1443
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1443
- constructor(firestore, productsIndex) {
1444
+ constructor(firestore) {
1444
1445
  super();
1445
1446
  this.firestore = firestore;
1446
- this.productsIndex = productsIndex;
1447
1447
  this.collectionName = 'categories';
1448
1448
  this.model = Category;
1449
1449
  }
1450
1450
  getCategoryBySlug(slug, shop) {
1451
- return __awaiter(this, void 0, void 0, function* () {
1452
- const categoryDocs = yield getDocs(query(this.collection(this.collectionName), where('slug', '==', slug), where('shop', '==', shop), where('published', '==', true)));
1453
- if (categoryDocs.size > 1)
1451
+ return this.collection(this.collectionName)
1452
+ .where('slug', '==', slug)
1453
+ .where('shop', '==', shop)
1454
+ .where('published', '==', true)
1455
+ .get()
1456
+ .then((snap) => {
1457
+ if (snap.size > 1)
1454
1458
  throw new DuplicatedResultsError('Query returned duplicated values');
1455
- if (categoryDocs.empty)
1459
+ if (snap.empty)
1456
1460
  throw new NotFoundError(`Document with slug ${slug} not found`);
1457
- return categoryDocs.docs[0].data();
1458
- });
1461
+ return snap.docs[0].data();
1462
+ })
1463
+ .catch((error) => error);
1459
1464
  }
1460
1465
  getCategoriesForHome(categoryIds, limit = 4) {
1461
1466
  return __awaiter(this, void 0, void 0, function* () {
1462
- const categorySnap = yield getDocs(query(this.collection(this.collectionName), where('id', 'in', categoryIds.filter(Boolean)), where('published', '==', true)));
1467
+ const categorySnap = yield this.collection(this.collectionName)
1468
+ .where('id', 'in', categoryIds.filter(Boolean))
1469
+ .where('published', '==', true)
1470
+ .get();
1463
1471
  if (categorySnap.empty)
1464
1472
  throw new NotFoundError('Categories not found');
1465
1473
  const categories = categorySnap.docs.map((doc) => doc.data());
@@ -1476,11 +1484,23 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1476
1484
  return __awaiter(this, void 0, void 0, function* () {
1477
1485
  if (!category.products)
1478
1486
  throw new RequiredArgumentError(['Category products is empty']);
1479
- return this.productsIndex.findById(category.products, {
1480
- hasStock: options === null || options === void 0 ? void 0 : options.hasStock,
1481
- size: options === null || options === void 0 ? void 0 : options.limit,
1482
- shop: category.shop,
1483
- });
1487
+ const chunks = chunk(category.products, 10);
1488
+ const products = [];
1489
+ const publishedField = category.shop === Shops.GLAMSHOP ? 'publishedGlam' : 'published';
1490
+ for (const productIds of chunks) {
1491
+ if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
1492
+ break;
1493
+ let query = yield this.collection('products').where(publishedField, '==', true).where('id', 'in', productIds);
1494
+ if (options === null || options === void 0 ? void 0 : options.hasStock)
1495
+ query = query.where('stock.quantity', '>', 0);
1496
+ if (options === null || options === void 0 ? void 0 : options.limit)
1497
+ query = query.limit(options === null || options === void 0 ? void 0 : options.limit);
1498
+ const productSnap = yield query.get();
1499
+ if (productSnap.empty)
1500
+ continue;
1501
+ products.push(...productSnap.docs.map((doc) => doc.data()));
1502
+ }
1503
+ return products;
1484
1504
  });
1485
1505
  }
1486
1506
  }
@@ -1636,9 +1656,9 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1636
1656
  home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
1637
1657
  home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
1638
1658
  home.data.createdAt =
1639
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
1659
+ home.data.createdAt instanceof firebase.firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
1640
1660
  home.data.expiresAt =
1641
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
1661
+ home.data.expiresAt instanceof firebase.firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
1642
1662
  }
1643
1663
  return home;
1644
1664
  };
@@ -1679,7 +1699,7 @@ class AuthenticationFirebaseAuthService {
1679
1699
  }
1680
1700
  signInWithEmailAndPassword(data) {
1681
1701
  return __awaiter(this, void 0, void 0, function* () {
1682
- const credentials = yield signInWithEmailAndPassword(this.firebaseAuth, data.email, data.password);
1702
+ const credentials = yield this.firebaseAuth.signInWithEmailAndPassword(data.email, data.password);
1683
1703
  const user = credentials.user;
1684
1704
  return {
1685
1705
  id: user.uid,
@@ -1692,7 +1712,7 @@ class AuthenticationFirebaseAuthService {
1692
1712
  }
1693
1713
  signInWithGoogle() {
1694
1714
  return __awaiter(this, void 0, void 0, function* () {
1695
- const credentials = yield signInWithPopup(this.firebaseAuth, new GoogleAuthProvider());
1715
+ const credentials = yield this.firebaseAuth.signInWithPopup(new firebase$1.auth.GoogleAuthProvider());
1696
1716
  const user = credentials.user;
1697
1717
  return {
1698
1718
  id: user.uid,
@@ -1710,7 +1730,7 @@ class AuthenticationFirebaseAuthService {
1710
1730
  }
1711
1731
  signInAnonymously() {
1712
1732
  return __awaiter(this, void 0, void 0, function* () {
1713
- const auth = yield signInAnonymously(this.firebaseAuth);
1733
+ const auth = yield this.firebaseAuth.signInAnonymously();
1714
1734
  const user = auth.user;
1715
1735
  user.id = auth.user.uid;
1716
1736
  return user;
@@ -1718,7 +1738,7 @@ class AuthenticationFirebaseAuthService {
1718
1738
  }
1719
1739
  sendPasswordResetEmail(email) {
1720
1740
  return __awaiter(this, void 0, void 0, function* () {
1721
- return sendPasswordResetEmail(this.firebaseAuth, email);
1741
+ return this.firebaseAuth.sendPasswordResetEmail(email);
1722
1742
  });
1723
1743
  }
1724
1744
  }
@@ -1730,9 +1750,9 @@ class RegisterFirebaseAuthService {
1730
1750
  register(params) {
1731
1751
  return __awaiter(this, void 0, void 0, function* () {
1732
1752
  try {
1733
- const auth = yield createUserWithEmailAndPassword(this.firebaseAuth, params.email, params.password);
1753
+ const auth = yield this.firebaseAuth.createUserWithEmailAndPassword(params.email, params.password);
1734
1754
  const user = auth.user;
1735
- yield sendEmailVerification(user);
1755
+ user.sendEmailVerification();
1736
1756
  user.id = auth.user.uid;
1737
1757
  return user;
1738
1758
  }
@@ -1751,5 +1771,5 @@ class RegisterFirebaseAuthService {
1751
1771
  * Generated bundle index. Do not edit.
1752
1772
  */
1753
1773
 
1754
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FinancialCoupon, FragranceImportances, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserSearchFirestoreRepository, UserType, Variant, WeakPasswordError, Where, chunk, get, isDate, isEmpty, isNil, isNumber, isObject, isString, pick, set, withCreateFirestore, withCrudFirestore, withDeleteFirestore, withFindFirestore, withFirestore, withGetFirestore, withHelpers, withSubCollection, withUpdateFirestore };
1774
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserSearchFirestoreRepository, UserType, Variant, WeakPasswordError, Where, withCreateFirestore, withCrudFirestore, withDeleteFirestore, withFindFirestore, withFirestore, withGetFirestore, withHelpers, withSubCollection, withUpdateFirestore };
1755
1775
  //# sourceMappingURL=infrab4a-connect.js.map