@infrab4a/connect 0.11.0 → 0.12.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 (41) hide show
  1. package/bundles/infrab4a-connect.umd.js +116 -4
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/esm2015/lib/domain/catalog/models/product.js +1 -1
  4. package/esm2015/lib/domain/catalog/models/types/product-review.type.js +1 -1
  5. package/esm2015/lib/domain/general/repository/enums/where.enum.js +2 -1
  6. package/esm2015/lib/domain/users/errors/index.js +3 -1
  7. package/esm2015/lib/domain/users/errors/user-already-registered.error.js +7 -0
  8. package/esm2015/lib/domain/users/errors/weak-password.error.js +7 -0
  9. package/esm2015/lib/domain/users/models/subscription/enums/edition-status.enum.js +2 -1
  10. package/esm2015/lib/domain/users/services/authentication.service.js +1 -1
  11. package/esm2015/lib/domain/users/services/index.js +3 -1
  12. package/esm2015/lib/domain/users/services/register.service.js +2 -0
  13. package/esm2015/lib/domain/users/services/types/basic-user-data.type.js +2 -0
  14. package/esm2015/lib/domain/users/services/types/index.js +2 -0
  15. package/esm2015/lib/domain/users/use-cases/index.js +2 -1
  16. package/esm2015/lib/domain/users/use-cases/register.js +29 -0
  17. package/esm2015/lib/infra/firebase/auth/authentication-firebase-auth.service.js +18 -4
  18. package/esm2015/lib/infra/firebase/auth/index.js +2 -1
  19. package/esm2015/lib/infra/firebase/auth/register-firebase-auth.service.js +26 -0
  20. package/esm2015/lib/infra/firebase/auth/types/firebase-user-with-id.type.js +2 -0
  21. package/fesm2015/infrab4a-connect.js +85 -4
  22. package/fesm2015/infrab4a-connect.js.map +1 -1
  23. package/lib/domain/catalog/models/product.d.ts +0 -1
  24. package/lib/domain/catalog/models/types/product-review.type.d.ts +1 -1
  25. package/lib/domain/general/repository/enums/where.enum.d.ts +1 -0
  26. package/lib/domain/users/errors/index.d.ts +2 -0
  27. package/lib/domain/users/errors/user-already-registered.error.d.ts +4 -0
  28. package/lib/domain/users/errors/weak-password.error.d.ts +4 -0
  29. package/lib/domain/users/models/subscription/enums/edition-status.enum.d.ts +2 -1
  30. package/lib/domain/users/services/authentication.service.d.ts +4 -5
  31. package/lib/domain/users/services/index.d.ts +2 -0
  32. package/lib/domain/users/services/register.service.d.ts +7 -0
  33. package/lib/domain/users/services/types/basic-user-data.type.d.ts +4 -0
  34. package/lib/domain/users/services/types/index.d.ts +1 -0
  35. package/lib/domain/users/use-cases/index.d.ts +1 -0
  36. package/lib/domain/users/use-cases/register.d.ts +13 -0
  37. package/lib/infra/firebase/auth/authentication-firebase-auth.service.d.ts +5 -4
  38. package/lib/infra/firebase/auth/index.d.ts +1 -0
  39. package/lib/infra/firebase/auth/register-firebase-auth.service.d.ts +8 -0
  40. package/lib/infra/firebase/auth/types/firebase-user-with-id.type.d.ts +3 -0
  41. package/package.json +1 -1
@@ -25,6 +25,7 @@
25
25
  exports.Where = void 0;
26
26
  (function (Where) {
27
27
  Where["EQUALS"] = "==";
28
+ Where["NOTEQUALS"] = "!=";
28
29
  Where["GT"] = ">";
29
30
  Where["GTE"] = ">=";
30
31
  Where["IN"] = "in";
@@ -246,6 +247,7 @@
246
247
  exports.EditionStatus = void 0;
247
248
  (function (EditionStatus) {
248
249
  EditionStatus["ALLOCATION_WAITING"] = "Aguardando aloca\u00E7\u00E3o";
250
+ EditionStatus["SHIPPED"] = "Enviado";
249
251
  })(exports.EditionStatus || (exports.EditionStatus = {}));
250
252
 
251
253
  exports.PaymentType = void 0;
@@ -1004,6 +1006,44 @@
1004
1006
  return Authentication;
1005
1007
  }());
1006
1008
 
1009
+ var Register = /** @class */ (function () {
1010
+ function Register(registerService, userRepository) {
1011
+ this.registerService = registerService;
1012
+ this.userRepository = userRepository;
1013
+ }
1014
+ Register.prototype.register = function (params) {
1015
+ return __awaiter(this, void 0, void 0, function () {
1016
+ var email, displayName, auth, user;
1017
+ return __generator(this, function (_a) {
1018
+ switch (_a.label) {
1019
+ case 0:
1020
+ email = params.email.toLocaleLowerCase();
1021
+ displayName = params.firstName + " " + params.lastName;
1022
+ return [4 /*yield*/, this.registerService.register({
1023
+ birthday: params.birthday,
1024
+ email: email,
1025
+ firstName: params.firstName,
1026
+ lastName: params.lastName,
1027
+ cpf: params.cpf,
1028
+ displayName: displayName,
1029
+ phone: params.phone,
1030
+ password: params.password,
1031
+ })];
1032
+ case 1:
1033
+ auth = _a.sent();
1034
+ delete params.password;
1035
+ return [4 /*yield*/, this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email: email,
1036
+ displayName: displayName, type: exports.UserType.B2C, dateCreated: new Date(), dateModified: new Date() }))];
1037
+ case 2:
1038
+ user = _a.sent();
1039
+ return [2 /*return*/, user];
1040
+ }
1041
+ });
1042
+ });
1043
+ };
1044
+ return Register;
1045
+ }());
1046
+
1007
1047
  var SignOut = /** @class */ (function () {
1008
1048
  function SignOut(authService) {
1009
1049
  this.authService = authService;
@@ -1023,6 +1063,27 @@
1023
1063
  return SignOut;
1024
1064
  }());
1025
1065
 
1066
+ var UserAlreadyRegisteredError = /** @class */ (function (_super) {
1067
+ __extends(UserAlreadyRegisteredError, _super);
1068
+ function UserAlreadyRegisteredError(message) {
1069
+ var _this = _super.call(this, message) || this;
1070
+ _this.message = message;
1071
+ return _this;
1072
+ }
1073
+ return UserAlreadyRegisteredError;
1074
+ }(Error));
1075
+
1076
+ var WeakPasswordError = /** @class */ (function (_super) {
1077
+ __extends(WeakPasswordError, _super);
1078
+ function WeakPasswordError(message) {
1079
+ if (message === void 0) { message = 'Weak password'; }
1080
+ var _this = _super.call(this, message) || this;
1081
+ _this.message = message;
1082
+ return _this;
1083
+ }
1084
+ return WeakPasswordError;
1085
+ }(Error));
1086
+
1026
1087
  exports.Shops = void 0;
1027
1088
  (function (Shops) {
1028
1089
  Shops["MENSMARKET"] = "mensmarket";
@@ -2254,7 +2315,13 @@
2254
2315
  case 1:
2255
2316
  credentials = _a.sent();
2256
2317
  user = credentials.user;
2257
- return [2 /*return*/, { id: user.uid, displayName: user.displayName, email: user.email, phone: user.phoneNumber }];
2318
+ return [2 /*return*/, {
2319
+ id: user.uid,
2320
+ displayName: user.displayName,
2321
+ email: user.email,
2322
+ phone: user.phoneNumber,
2323
+ isAnonymous: false,
2324
+ }];
2258
2325
  }
2259
2326
  });
2260
2327
  });
@@ -2268,7 +2335,13 @@
2268
2335
  case 1:
2269
2336
  credentials = _a.sent();
2270
2337
  user = credentials.user;
2271
- return [2 /*return*/, { id: user.uid, displayName: user.displayName, email: user.email, phone: user.phoneNumber }];
2338
+ return [2 /*return*/, {
2339
+ id: user.uid,
2340
+ displayName: user.displayName,
2341
+ email: user.email,
2342
+ phone: user.phoneNumber,
2343
+ isAnonymous: false,
2344
+ }];
2272
2345
  }
2273
2346
  });
2274
2347
  });
@@ -2283,13 +2356,15 @@
2283
2356
  };
2284
2357
  AuthenticationFirebaseAuthService.prototype.signInAnonymously = function () {
2285
2358
  return __awaiter(this, void 0, void 0, function () {
2286
- var auth;
2359
+ var auth, user;
2287
2360
  return __generator(this, function (_a) {
2288
2361
  switch (_a.label) {
2289
2362
  case 0: return [4 /*yield*/, this.firebaseAuth.signInAnonymously()];
2290
2363
  case 1:
2291
2364
  auth = _a.sent();
2292
- return [2 /*return*/, auth.user];
2365
+ user = auth.user;
2366
+ user.id = auth.user.uid;
2367
+ return [2 /*return*/, user];
2293
2368
  }
2294
2369
  });
2295
2370
  });
@@ -2297,6 +2372,39 @@
2297
2372
  return AuthenticationFirebaseAuthService;
2298
2373
  }());
2299
2374
 
2375
+ var RegisterFirebaseAuthService = /** @class */ (function () {
2376
+ function RegisterFirebaseAuthService(firebaseAuth) {
2377
+ this.firebaseAuth = firebaseAuth;
2378
+ }
2379
+ RegisterFirebaseAuthService.prototype.register = function (params) {
2380
+ return __awaiter(this, void 0, void 0, function () {
2381
+ var auth, user, error_1;
2382
+ return __generator(this, function (_a) {
2383
+ switch (_a.label) {
2384
+ case 0:
2385
+ _a.trys.push([0, 2, , 3]);
2386
+ return [4 /*yield*/, this.firebaseAuth.createUserWithEmailAndPassword(params.email, params.password)];
2387
+ case 1:
2388
+ auth = _a.sent();
2389
+ user = auth.user;
2390
+ user.sendEmailVerification();
2391
+ user.id = auth.user.uid;
2392
+ return [2 /*return*/, user];
2393
+ case 2:
2394
+ error_1 = _a.sent();
2395
+ if (error_1.code === 'auth/email-already-in-use')
2396
+ throw new UserAlreadyRegisteredError('Email already registered');
2397
+ if (error_1.code === 'auth/weak-password')
2398
+ throw new WeakPasswordError();
2399
+ throw error_1;
2400
+ case 3: return [2 /*return*/];
2401
+ }
2402
+ });
2403
+ });
2404
+ };
2405
+ return RegisterFirebaseAuthService;
2406
+ }());
2407
+
2300
2408
  /**
2301
2409
  * Generated bundle index. Do not edit.
2302
2410
  */
@@ -2364,6 +2472,8 @@
2364
2472
  exports.Product = Product;
2365
2473
  exports.ProductFirestoreRepository = ProductFirestoreRepository;
2366
2474
  exports.ProductVariantFirestoreRepository = ProductVariantFirestoreRepository;
2475
+ exports.Register = Register;
2476
+ exports.RegisterFirebaseAuthService = RegisterFirebaseAuthService;
2367
2477
  exports.RequiredArgumentError = RequiredArgumentError;
2368
2478
  exports.ShippingMethod = ShippingMethod;
2369
2479
  exports.ShopMenu = ShopMenu;
@@ -2381,11 +2491,13 @@
2381
2491
  exports.User = User;
2382
2492
  exports.UserAddress = UserAddress;
2383
2493
  exports.UserAddressFirestoreRepository = UserAddressFirestoreRepository;
2494
+ exports.UserAlreadyRegisteredError = UserAlreadyRegisteredError;
2384
2495
  exports.UserBeautyProfileFirestoreRepository = UserBeautyProfileFirestoreRepository;
2385
2496
  exports.UserFirestoreRepository = UserFirestoreRepository;
2386
2497
  exports.UserPaymentMethod = UserPaymentMethod;
2387
2498
  exports.UserPaymentMethodFirestoreRepository = UserPaymentMethodFirestoreRepository;
2388
2499
  exports.Variant = Variant;
2500
+ exports.WeakPasswordError = WeakPasswordError;
2389
2501
  exports.withCreateFirestore = withCreateFirestore;
2390
2502
  exports.withCrudFirestore = withCrudFirestore;
2391
2503
  exports.withDeleteFirestore = withDeleteFirestore;