@infrab4a/connect 0.2.2 → 0.3.0

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 (44) hide show
  1. package/bundles/infrab4a-connect.umd.js +47 -13
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/esm2015/lib/domain/catalog/models/category.js +1 -1
  4. package/esm2015/lib/domain/general/repository/enums/index.js +2 -1
  5. package/esm2015/lib/domain/general/repository/enums/update-option-actions.enum.js +9 -0
  6. package/esm2015/lib/domain/general/repository/types/index.js +2 -1
  7. package/esm2015/lib/domain/general/repository/types/repository-find-filters.type.js +1 -1
  8. package/esm2015/lib/domain/general/repository/types/repository-update-params.type.js +2 -0
  9. package/esm2015/lib/domain/general/repository/update.repository.js +1 -1
  10. package/esm2015/lib/infra/firebase/firestore/mixins/with-update-firestore.mixin.js +28 -4
  11. package/esm2015/lib/utils/index.js +2 -1
  12. package/esm2015/lib/utils/types/index.js +2 -0
  13. package/esm2015/lib/utils/types/prop.type.js +2 -0
  14. package/fesm2015/infrab4a-connect.js +37 -6
  15. package/fesm2015/infrab4a-connect.js.map +1 -1
  16. package/lib/domain/catalog/models/category.d.ts +2 -0
  17. package/lib/domain/general/repository/enums/index.d.ts +1 -0
  18. package/lib/domain/general/repository/enums/update-option-actions.enum.d.ts +7 -0
  19. package/lib/domain/general/repository/types/index.d.ts +1 -0
  20. package/lib/domain/general/repository/types/repository-find-filters.type.d.ts +1 -2
  21. package/lib/domain/general/repository/types/repository-update-params.type.d.ts +11 -0
  22. package/lib/domain/general/repository/update.repository.d.ts +2 -1
  23. package/lib/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +3 -2
  24. package/lib/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +4 -3
  25. package/lib/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +3 -2
  26. package/lib/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +3 -2
  27. package/lib/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +3 -2
  28. package/lib/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +3 -2
  29. package/lib/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +3 -2
  30. package/lib/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +3 -2
  31. package/lib/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +3 -2
  32. package/lib/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +3 -2
  33. package/lib/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +3 -2
  34. package/lib/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +3 -2
  35. package/lib/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +3 -2
  36. package/lib/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +3 -2
  37. package/lib/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +3 -2
  38. package/lib/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +3 -2
  39. package/lib/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +3 -2
  40. package/lib/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +3 -2
  41. package/lib/utils/index.d.ts +1 -0
  42. package/lib/utils/types/index.d.ts +1 -0
  43. package/lib/utils/types/prop.type.d.ts +1 -0
  44. package/package.json +1 -1
@@ -1,12 +1,13 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('class-transformer'), require('lodash'), require('ts-md5'), require('firebase/app')) :
3
- typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'class-transformer', 'lodash', 'ts-md5', 'firebase/app'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), global["class-transformer"], global.lodash, global.tsMd5, global.firebase));
5
- })(this, (function (exports, classTransformer, lodash, tsMd5, firebase) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('class-transformer'), require('lodash'), require('ts-md5'), require('firebase'), require('firebase/app')) :
3
+ typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'class-transformer', 'lodash', 'ts-md5', 'firebase', 'firebase/app'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), global["class-transformer"], global.lodash, global.tsMd5, global.firebase, global.firebase$1));
5
+ })(this, (function (exports, classTransformer, lodash, tsMd5, firebase, firebase$1) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
10
+ var firebase__default$1 = /*#__PURE__*/_interopDefaultLegacy(firebase$1);
10
11
 
11
12
  var BaseModel = /** @class */ (function () {
12
13
  function BaseModel(args) {
@@ -32,6 +33,15 @@
32
33
  Where["LIKE"] = "like";
33
34
  })(exports.Where || (exports.Where = {}));
34
35
 
36
+ exports.UpdateOptionActions = void 0;
37
+ (function (UpdateOptionActions) {
38
+ UpdateOptionActions["UPDATE"] = "update";
39
+ UpdateOptionActions["MERGE"] = "merge";
40
+ UpdateOptionActions["REMOVE"] = "remove";
41
+ UpdateOptionActions["REMOVE_FIELD"] = "removeField";
42
+ UpdateOptionActions["NULL"] = "null";
43
+ })(exports.UpdateOptionActions || (exports.UpdateOptionActions = {}));
44
+
35
45
  exports.UserType = void 0;
36
46
  (function (UserType) {
37
47
  UserType["B2C"] = "Cliente Transacional";
@@ -1154,6 +1164,19 @@
1154
1164
  };
1155
1165
 
1156
1166
  var withUpdateFirestore = function (MixinBase) {
1167
+ var getValueFromParams = function (params, field) { var _a; return (lodash.isNil((_a = params[field]) === null || _a === void 0 ? void 0 : _a.value) ? params[field] : params[field].value) || null; };
1168
+ var getValueByAction = function (options) {
1169
+ var fieldValues = firebase__default["default"].firestore.FieldValue;
1170
+ if (options.action === exports.UpdateOptionActions.REMOVE_FIELD)
1171
+ return fieldValues.delete();
1172
+ if (Array.isArray(options.value)) {
1173
+ if (options.action === exports.UpdateOptionActions.MERGE)
1174
+ return fieldValues.arrayUnion(options.value);
1175
+ if (options.action === exports.UpdateOptionActions.REMOVE)
1176
+ return fieldValues.arrayRemove(options.value);
1177
+ }
1178
+ return options.value;
1179
+ };
1157
1180
  return /** @class */ (function (_super) {
1158
1181
  __extends(UpdateFirestore, _super);
1159
1182
  function UpdateFirestore() {
@@ -1161,17 +1184,19 @@
1161
1184
  }
1162
1185
  UpdateFirestore.prototype.update = function (data) {
1163
1186
  return __awaiter(this, void 0, void 0, function () {
1164
- var docRef, doc;
1165
- return __generator(this, function (_a) {
1166
- switch (_a.label) {
1187
+ var model, keyField, docRef, doc;
1188
+ return __generator(this, function (_b) {
1189
+ switch (_b.label) {
1167
1190
  case 0:
1168
- docRef = this.collection(this.buildCollectionPathForUpdate(data)).doc(data[data.identifierFields().shift().toString()]);
1169
- return [4 /*yield*/, docRef.update(data.toPlain())];
1191
+ model = new this.model();
1192
+ keyField = model.identifierFields().shift();
1193
+ docRef = this.collection(this.buildCollectionPathForUpdate(data)).doc(getValueFromParams(data, keyField).toString());
1194
+ return [4 /*yield*/, docRef.update(this.paramsToPlain(data))];
1170
1195
  case 1:
1171
- _a.sent();
1196
+ _b.sent();
1172
1197
  return [4 /*yield*/, docRef.get()];
1173
1198
  case 2:
1174
- doc = _a.sent();
1199
+ doc = _b.sent();
1175
1200
  return [2 /*return*/, doc.data()];
1176
1201
  }
1177
1202
  });
@@ -1179,9 +1204,18 @@
1179
1204
  };
1180
1205
  UpdateFirestore.prototype.buildCollectionPathForUpdate = function (identifiers) {
1181
1206
  return this.isSubCollection(this)
1182
- ? this.parentRepository.collectionName + "/" + identifiers[this.parentIdField] + "/" + this.collectionName
1207
+ ? this.parentRepository.collectionName + "/" + getValueFromParams(identifiers, this.parentIdField) + "/" + this.collectionName
1183
1208
  : this.collectionName;
1184
1209
  };
1210
+ UpdateFirestore.prototype.paramsToPlain = function (params) {
1211
+ var model = this.model;
1212
+ if (params instanceof model)
1213
+ return params.toPlain();
1214
+ return Object.keys(params).reduce(function (data, currentKey) {
1215
+ var _b;
1216
+ return (Object.assign(Object.assign({}, data), (_b = {}, _b[currentKey] = getValueByAction(data[currentKey]), _b)));
1217
+ }, {});
1218
+ };
1185
1219
  return UpdateFirestore;
1186
1220
  }(MixinBase));
1187
1221
  };
@@ -1511,7 +1545,7 @@
1511
1545
  var credentials, user;
1512
1546
  return __generator(this, function (_a) {
1513
1547
  switch (_a.label) {
1514
- case 0: return [4 /*yield*/, this.firebaseAuth.signInWithPopup(new firebase__default["default"].auth.GoogleAuthProvider())];
1548
+ case 0: return [4 /*yield*/, this.firebaseAuth.signInWithPopup(new firebase__default$1["default"].auth.GoogleAuthProvider())];
1515
1549
  case 1:
1516
1550
  credentials = _a.sent();
1517
1551
  user = credentials.user;