@infrab4a/connect 3.11.0-beta.0 → 3.11.1-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/infrab4a-connect.umd.js +290 -233
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/domain/users/models/subscription/index.d.ts +2 -1
- package/domain/users/models/subscription/subscription-materialization.d.ts +30 -0
- package/domain/users/models/subscription/subscription.d.ts +2 -1
- package/domain/users/repositories/index.d.ts +6 -5
- package/domain/users/repositories/subscription-materialization.repository.d.ts +4 -0
- package/esm2015/domain/users/models/subscription/index.js +3 -2
- package/esm2015/domain/users/models/subscription/subscription-materialization.js +42 -0
- package/esm2015/domain/users/models/subscription/subscription.js +2 -2
- package/esm2015/domain/users/repositories/index.js +7 -6
- package/esm2015/domain/users/repositories/subscription-materialization.repository.js +2 -0
- package/esm2015/infra/firebase/firestore/repositories/users/index.js +2 -1
- package/esm2015/infra/firebase/firestore/repositories/users/subscription-materialization-firestore.repository.js +12 -0
- package/fesm2015/infrab4a-connect.js +178 -135
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/firebase/firestore/repositories/users/index.d.ts +1 -0
- package/infra/firebase/firestore/repositories/users/subscription-materialization-firestore.repository.d.ts +8 -0
- package/package.json +1 -1
|
@@ -265,30 +265,6 @@
|
|
|
265
265
|
UserType["Influencer"] = "Influencer";
|
|
266
266
|
})(exports.UserType || (exports.UserType = {}));
|
|
267
267
|
|
|
268
|
-
exports.BillingStatus = void 0;
|
|
269
|
-
(function (BillingStatus) {
|
|
270
|
-
BillingStatus["PAYED"] = "PAGO";
|
|
271
|
-
})(exports.BillingStatus || (exports.BillingStatus = {}));
|
|
272
|
-
|
|
273
|
-
exports.EditionStatus = void 0;
|
|
274
|
-
(function (EditionStatus) {
|
|
275
|
-
EditionStatus["ALLOCATION_WAITING"] = "Aguardando aloca\u00E7\u00E3o";
|
|
276
|
-
EditionStatus["SHIPPED"] = "Enviado";
|
|
277
|
-
})(exports.EditionStatus || (exports.EditionStatus = {}));
|
|
278
|
-
|
|
279
|
-
exports.PaymentType = void 0;
|
|
280
|
-
(function (PaymentType) {
|
|
281
|
-
PaymentType["AQUISITION"] = "Aquisi\u00E7\u00E3o";
|
|
282
|
-
PaymentType["RENEWAL"] = "Renova\u00E7\u00E3o";
|
|
283
|
-
PaymentType["FREIGHT"] = "mudan\u00E7a de endere\u00E7o, Frete";
|
|
284
|
-
})(exports.PaymentType || (exports.PaymentType = {}));
|
|
285
|
-
|
|
286
|
-
exports.Status = void 0;
|
|
287
|
-
(function (Status) {
|
|
288
|
-
Status["ACTIVE"] = "active";
|
|
289
|
-
Status["CANCELLED"] = "Cancelado";
|
|
290
|
-
})(exports.Status || (exports.Status = {}));
|
|
291
|
-
|
|
292
268
|
/*! *****************************************************************************
|
|
293
269
|
Copyright (c) Microsoft Corporation.
|
|
294
270
|
|
|
@@ -622,6 +598,30 @@
|
|
|
622
598
|
return Edition;
|
|
623
599
|
}(BaseModel));
|
|
624
600
|
|
|
601
|
+
exports.BillingStatus = void 0;
|
|
602
|
+
(function (BillingStatus) {
|
|
603
|
+
BillingStatus["PAYED"] = "PAGO";
|
|
604
|
+
})(exports.BillingStatus || (exports.BillingStatus = {}));
|
|
605
|
+
|
|
606
|
+
exports.EditionStatus = void 0;
|
|
607
|
+
(function (EditionStatus) {
|
|
608
|
+
EditionStatus["ALLOCATION_WAITING"] = "Aguardando aloca\u00E7\u00E3o";
|
|
609
|
+
EditionStatus["SHIPPED"] = "Enviado";
|
|
610
|
+
})(exports.EditionStatus || (exports.EditionStatus = {}));
|
|
611
|
+
|
|
612
|
+
exports.PaymentType = void 0;
|
|
613
|
+
(function (PaymentType) {
|
|
614
|
+
PaymentType["AQUISITION"] = "Aquisi\u00E7\u00E3o";
|
|
615
|
+
PaymentType["RENEWAL"] = "Renova\u00E7\u00E3o";
|
|
616
|
+
PaymentType["FREIGHT"] = "mudan\u00E7a de endere\u00E7o, Frete";
|
|
617
|
+
})(exports.PaymentType || (exports.PaymentType = {}));
|
|
618
|
+
|
|
619
|
+
exports.Status = void 0;
|
|
620
|
+
(function (Status) {
|
|
621
|
+
Status["ACTIVE"] = "active";
|
|
622
|
+
Status["CANCELLED"] = "Cancelado";
|
|
623
|
+
})(exports.Status || (exports.Status = {}));
|
|
624
|
+
|
|
625
625
|
var Payment = /** @class */ (function (_super) {
|
|
626
626
|
__extends(Payment, _super);
|
|
627
627
|
function Payment() {
|
|
@@ -1042,215 +1042,6 @@
|
|
|
1042
1042
|
__metadata("design:type", Array)
|
|
1043
1043
|
], Subscription.prototype, "payment", void 0);
|
|
1044
1044
|
|
|
1045
|
-
var UserAddress = /** @class */ (function (_super) {
|
|
1046
|
-
__extends(UserAddress, _super);
|
|
1047
|
-
function UserAddress() {
|
|
1048
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1049
|
-
}
|
|
1050
|
-
Object.defineProperty(UserAddress, "identifiersFields", {
|
|
1051
|
-
get: function () {
|
|
1052
|
-
return ['id', 'userId'];
|
|
1053
|
-
},
|
|
1054
|
-
enumerable: false,
|
|
1055
|
-
configurable: true
|
|
1056
|
-
});
|
|
1057
|
-
return UserAddress;
|
|
1058
|
-
}(Address));
|
|
1059
|
-
|
|
1060
|
-
var UserPaymentMethod = /** @class */ (function (_super) {
|
|
1061
|
-
__extends(UserPaymentMethod, _super);
|
|
1062
|
-
function UserPaymentMethod() {
|
|
1063
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1064
|
-
}
|
|
1065
|
-
Object.defineProperty(UserPaymentMethod, "identifiersFields", {
|
|
1066
|
-
get: function () {
|
|
1067
|
-
return ['id', 'userId'];
|
|
1068
|
-
},
|
|
1069
|
-
enumerable: false,
|
|
1070
|
-
configurable: true
|
|
1071
|
-
});
|
|
1072
|
-
return UserPaymentMethod;
|
|
1073
|
-
}(BaseModel));
|
|
1074
|
-
|
|
1075
|
-
var Lead = /** @class */ (function (_super) {
|
|
1076
|
-
__extends(Lead, _super);
|
|
1077
|
-
function Lead() {
|
|
1078
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1079
|
-
}
|
|
1080
|
-
Object.defineProperty(Lead, "identifiersFields", {
|
|
1081
|
-
get: function () {
|
|
1082
|
-
return ['id'];
|
|
1083
|
-
},
|
|
1084
|
-
enumerable: false,
|
|
1085
|
-
configurable: true
|
|
1086
|
-
});
|
|
1087
|
-
return Lead;
|
|
1088
|
-
}(BaseModel));
|
|
1089
|
-
|
|
1090
|
-
var UnauthorizedError = /** @class */ (function (_super) {
|
|
1091
|
-
__extends(UnauthorizedError, _super);
|
|
1092
|
-
function UnauthorizedError(message) {
|
|
1093
|
-
var _this = _super.call(this, message) || this;
|
|
1094
|
-
_this.message = message;
|
|
1095
|
-
return _this;
|
|
1096
|
-
}
|
|
1097
|
-
return UnauthorizedError;
|
|
1098
|
-
}(tsCustomError.CustomError));
|
|
1099
|
-
|
|
1100
|
-
exports.SignInMethods = void 0;
|
|
1101
|
-
(function (SignInMethods) {
|
|
1102
|
-
SignInMethods["EMAIL_PASSWORD"] = "email_password";
|
|
1103
|
-
SignInMethods["GOOGLE"] = "google";
|
|
1104
|
-
})(exports.SignInMethods || (exports.SignInMethods = {}));
|
|
1105
|
-
var Authentication = /** @class */ (function () {
|
|
1106
|
-
function Authentication(authService, userRepository) {
|
|
1107
|
-
this.authService = authService;
|
|
1108
|
-
this.userRepository = userRepository;
|
|
1109
|
-
}
|
|
1110
|
-
Authentication.prototype.signIn = function (_b, signInMethod) {
|
|
1111
|
-
var email = _b.email, password = _b.password;
|
|
1112
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1113
|
-
var method, userAuth, user;
|
|
1114
|
-
return __generator(this, function (_b) {
|
|
1115
|
-
switch (_b.label) {
|
|
1116
|
-
case 0:
|
|
1117
|
-
method = this.getServiceByMethod(signInMethod);
|
|
1118
|
-
return [4 /*yield*/, this.authService[method]({ email: email, password: password })];
|
|
1119
|
-
case 1:
|
|
1120
|
-
userAuth = _b.sent();
|
|
1121
|
-
user = this.userRepository.get(userAuth);
|
|
1122
|
-
if (!lodash.isNil(user))
|
|
1123
|
-
return [2 /*return*/, user];
|
|
1124
|
-
if (/^.+@b4a.com.br$/.test(userAuth.email))
|
|
1125
|
-
return [2 /*return*/, this.createsUserByCredential(userAuth)];
|
|
1126
|
-
throw new UnauthorizedError('Invalid credentials');
|
|
1127
|
-
}
|
|
1128
|
-
});
|
|
1129
|
-
});
|
|
1130
|
-
};
|
|
1131
|
-
Authentication.prototype.getServiceByMethod = function (signInMethod) {
|
|
1132
|
-
return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
|
|
1133
|
-
};
|
|
1134
|
-
Authentication.prototype.createsUserByCredential = function (user) {
|
|
1135
|
-
var _a;
|
|
1136
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1137
|
-
var _b, firstName, lastName, person;
|
|
1138
|
-
return __generator(this, function (_c) {
|
|
1139
|
-
_b = __read((_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/), 2), firstName = _b[0], lastName = _b[1];
|
|
1140
|
-
person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName: firstName,
|
|
1141
|
-
lastName: lastName, acceptsNewsletter: false, area: exports.Area.Transactional, officePosition: exports.OfficePosition.Intern, type: exports.UserType.Collaborator }));
|
|
1142
|
-
return [2 /*return*/, this.userRepository.create(person)];
|
|
1143
|
-
});
|
|
1144
|
-
});
|
|
1145
|
-
};
|
|
1146
|
-
return Authentication;
|
|
1147
|
-
}());
|
|
1148
|
-
|
|
1149
|
-
var UserAlreadyRegisteredError = /** @class */ (function (_super) {
|
|
1150
|
-
__extends(UserAlreadyRegisteredError, _super);
|
|
1151
|
-
function UserAlreadyRegisteredError(message) {
|
|
1152
|
-
var _this = _super.call(this, message) || this;
|
|
1153
|
-
_this.message = message;
|
|
1154
|
-
return _this;
|
|
1155
|
-
}
|
|
1156
|
-
return UserAlreadyRegisteredError;
|
|
1157
|
-
}(tsCustomError.CustomError));
|
|
1158
|
-
|
|
1159
|
-
var WeakPasswordError = /** @class */ (function (_super) {
|
|
1160
|
-
__extends(WeakPasswordError, _super);
|
|
1161
|
-
function WeakPasswordError(message) {
|
|
1162
|
-
if (message === void 0) { message = 'Weak password'; }
|
|
1163
|
-
var _this = _super.call(this, message) || this;
|
|
1164
|
-
_this.message = message;
|
|
1165
|
-
return _this;
|
|
1166
|
-
}
|
|
1167
|
-
return WeakPasswordError;
|
|
1168
|
-
}(tsCustomError.CustomError));
|
|
1169
|
-
|
|
1170
|
-
var Register = /** @class */ (function () {
|
|
1171
|
-
function Register(registerService, userRepository) {
|
|
1172
|
-
this.registerService = registerService;
|
|
1173
|
-
this.userRepository = userRepository;
|
|
1174
|
-
}
|
|
1175
|
-
Register.prototype.register = function (params) {
|
|
1176
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1177
|
-
var email, displayName, auth, user;
|
|
1178
|
-
return __generator(this, function (_a) {
|
|
1179
|
-
switch (_a.label) {
|
|
1180
|
-
case 0:
|
|
1181
|
-
email = params.email.toLocaleLowerCase();
|
|
1182
|
-
displayName = params.firstName + " " + params.lastName;
|
|
1183
|
-
return [4 /*yield*/, this.userRepository.checkIfExistsByField('cpf', params.cpf)];
|
|
1184
|
-
case 1:
|
|
1185
|
-
if (_a.sent())
|
|
1186
|
-
throw new UserAlreadyRegisteredError("Usu\u00E1rio com CPF " + params.cpf + " j\u00E1 registrado.");
|
|
1187
|
-
return [4 /*yield*/, this.userRepository.checkIfExistsByField('email', params.email)];
|
|
1188
|
-
case 2:
|
|
1189
|
-
if (_a.sent())
|
|
1190
|
-
throw new UserAlreadyRegisteredError("Usu\u00E1rio com e-mail " + params.email + " j\u00E1 registrado.");
|
|
1191
|
-
return [4 /*yield*/, this.registerService.register({
|
|
1192
|
-
birthday: params.birthday,
|
|
1193
|
-
email: email,
|
|
1194
|
-
firstName: params.firstName,
|
|
1195
|
-
lastName: params.lastName,
|
|
1196
|
-
cpf: params.cpf,
|
|
1197
|
-
displayName: displayName,
|
|
1198
|
-
phone: params.phone,
|
|
1199
|
-
password: params.password,
|
|
1200
|
-
})];
|
|
1201
|
-
case 3:
|
|
1202
|
-
auth = _a.sent();
|
|
1203
|
-
delete params.password;
|
|
1204
|
-
return [4 /*yield*/, this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email: email,
|
|
1205
|
-
displayName: displayName, type: exports.UserType.B2C, dateCreated: new Date(), dateModified: new Date() }))];
|
|
1206
|
-
case 4:
|
|
1207
|
-
user = _a.sent();
|
|
1208
|
-
return [2 /*return*/, user];
|
|
1209
|
-
}
|
|
1210
|
-
});
|
|
1211
|
-
});
|
|
1212
|
-
};
|
|
1213
|
-
return Register;
|
|
1214
|
-
}());
|
|
1215
|
-
|
|
1216
|
-
var SignOut = /** @class */ (function () {
|
|
1217
|
-
function SignOut(authService) {
|
|
1218
|
-
this.authService = authService;
|
|
1219
|
-
}
|
|
1220
|
-
SignOut.prototype.signOut = function () {
|
|
1221
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1222
|
-
return __generator(this, function (_a) {
|
|
1223
|
-
switch (_a.label) {
|
|
1224
|
-
case 0: return [4 /*yield*/, this.authService.signOut()];
|
|
1225
|
-
case 1:
|
|
1226
|
-
_a.sent();
|
|
1227
|
-
return [2 /*return*/];
|
|
1228
|
-
}
|
|
1229
|
-
});
|
|
1230
|
-
});
|
|
1231
|
-
};
|
|
1232
|
-
return SignOut;
|
|
1233
|
-
}());
|
|
1234
|
-
|
|
1235
|
-
var RecoveryPassword = /** @class */ (function () {
|
|
1236
|
-
function RecoveryPassword(authService) {
|
|
1237
|
-
this.authService = authService;
|
|
1238
|
-
}
|
|
1239
|
-
RecoveryPassword.prototype.sendEmail = function (email) {
|
|
1240
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1241
|
-
return __generator(this, function (_a) {
|
|
1242
|
-
switch (_a.label) {
|
|
1243
|
-
case 0: return [4 /*yield*/, this.authService.sendPasswordResetEmail(email)];
|
|
1244
|
-
case 1:
|
|
1245
|
-
_a.sent();
|
|
1246
|
-
return [2 /*return*/];
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
|
-
});
|
|
1250
|
-
};
|
|
1251
|
-
return RecoveryPassword;
|
|
1252
|
-
}());
|
|
1253
|
-
|
|
1254
1045
|
var Filter = /** @class */ (function (_super) {
|
|
1255
1046
|
__extends(Filter, _super);
|
|
1256
1047
|
function Filter() {
|
|
@@ -1601,6 +1392,258 @@
|
|
|
1601
1392
|
__metadata("design:type", Coupon)
|
|
1602
1393
|
], CheckoutSubscription.prototype, "coupon", void 0);
|
|
1603
1394
|
|
|
1395
|
+
var SubscriptionMaterialization = /** @class */ (function (_super) {
|
|
1396
|
+
__extends(SubscriptionMaterialization, _super);
|
|
1397
|
+
function SubscriptionMaterialization() {
|
|
1398
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1399
|
+
}
|
|
1400
|
+
Object.defineProperty(SubscriptionMaterialization, "identifiersFields", {
|
|
1401
|
+
get: function () {
|
|
1402
|
+
return ['id'];
|
|
1403
|
+
},
|
|
1404
|
+
enumerable: false,
|
|
1405
|
+
configurable: true
|
|
1406
|
+
});
|
|
1407
|
+
return SubscriptionMaterialization;
|
|
1408
|
+
}(BaseModel));
|
|
1409
|
+
__decorate([
|
|
1410
|
+
classTransformer.Type(function () { return User; }),
|
|
1411
|
+
__metadata("design:type", User)
|
|
1412
|
+
], SubscriptionMaterialization.prototype, "user", void 0);
|
|
1413
|
+
__decorate([
|
|
1414
|
+
classTransformer.Type(function () { return SubscriptionPlan; }),
|
|
1415
|
+
__metadata("design:type", SubscriptionPlan)
|
|
1416
|
+
], SubscriptionMaterialization.prototype, "subscriptionPlan", void 0);
|
|
1417
|
+
__decorate([
|
|
1418
|
+
classTransformer.Type(function () { return Address; }),
|
|
1419
|
+
__metadata("design:type", Address)
|
|
1420
|
+
], SubscriptionMaterialization.prototype, "shippingAddress", void 0);
|
|
1421
|
+
__decorate([
|
|
1422
|
+
classTransformer.Type(function () { return Address; }),
|
|
1423
|
+
__metadata("design:type", Address)
|
|
1424
|
+
], SubscriptionMaterialization.prototype, "billingAddress", void 0);
|
|
1425
|
+
__decorate([
|
|
1426
|
+
classTransformer.Type(function () { return Coupon; }),
|
|
1427
|
+
__metadata("design:type", Coupon)
|
|
1428
|
+
], SubscriptionMaterialization.prototype, "coupon", void 0);
|
|
1429
|
+
__decorate([
|
|
1430
|
+
classTransformer.Type(function () { return Edition; }),
|
|
1431
|
+
__metadata("design:type", Array)
|
|
1432
|
+
], SubscriptionMaterialization.prototype, "editions", void 0);
|
|
1433
|
+
__decorate([
|
|
1434
|
+
classTransformer.Type(function () { return SubscriptionPayment; }),
|
|
1435
|
+
__metadata("design:type", SubscriptionPayment)
|
|
1436
|
+
], SubscriptionMaterialization.prototype, "payment", void 0);
|
|
1437
|
+
|
|
1438
|
+
var UserAddress = /** @class */ (function (_super) {
|
|
1439
|
+
__extends(UserAddress, _super);
|
|
1440
|
+
function UserAddress() {
|
|
1441
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1442
|
+
}
|
|
1443
|
+
Object.defineProperty(UserAddress, "identifiersFields", {
|
|
1444
|
+
get: function () {
|
|
1445
|
+
return ['id', 'userId'];
|
|
1446
|
+
},
|
|
1447
|
+
enumerable: false,
|
|
1448
|
+
configurable: true
|
|
1449
|
+
});
|
|
1450
|
+
return UserAddress;
|
|
1451
|
+
}(Address));
|
|
1452
|
+
|
|
1453
|
+
var UserPaymentMethod = /** @class */ (function (_super) {
|
|
1454
|
+
__extends(UserPaymentMethod, _super);
|
|
1455
|
+
function UserPaymentMethod() {
|
|
1456
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1457
|
+
}
|
|
1458
|
+
Object.defineProperty(UserPaymentMethod, "identifiersFields", {
|
|
1459
|
+
get: function () {
|
|
1460
|
+
return ['id', 'userId'];
|
|
1461
|
+
},
|
|
1462
|
+
enumerable: false,
|
|
1463
|
+
configurable: true
|
|
1464
|
+
});
|
|
1465
|
+
return UserPaymentMethod;
|
|
1466
|
+
}(BaseModel));
|
|
1467
|
+
|
|
1468
|
+
var Lead = /** @class */ (function (_super) {
|
|
1469
|
+
__extends(Lead, _super);
|
|
1470
|
+
function Lead() {
|
|
1471
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1472
|
+
}
|
|
1473
|
+
Object.defineProperty(Lead, "identifiersFields", {
|
|
1474
|
+
get: function () {
|
|
1475
|
+
return ['id'];
|
|
1476
|
+
},
|
|
1477
|
+
enumerable: false,
|
|
1478
|
+
configurable: true
|
|
1479
|
+
});
|
|
1480
|
+
return Lead;
|
|
1481
|
+
}(BaseModel));
|
|
1482
|
+
|
|
1483
|
+
var UnauthorizedError = /** @class */ (function (_super) {
|
|
1484
|
+
__extends(UnauthorizedError, _super);
|
|
1485
|
+
function UnauthorizedError(message) {
|
|
1486
|
+
var _this = _super.call(this, message) || this;
|
|
1487
|
+
_this.message = message;
|
|
1488
|
+
return _this;
|
|
1489
|
+
}
|
|
1490
|
+
return UnauthorizedError;
|
|
1491
|
+
}(tsCustomError.CustomError));
|
|
1492
|
+
|
|
1493
|
+
exports.SignInMethods = void 0;
|
|
1494
|
+
(function (SignInMethods) {
|
|
1495
|
+
SignInMethods["EMAIL_PASSWORD"] = "email_password";
|
|
1496
|
+
SignInMethods["GOOGLE"] = "google";
|
|
1497
|
+
})(exports.SignInMethods || (exports.SignInMethods = {}));
|
|
1498
|
+
var Authentication = /** @class */ (function () {
|
|
1499
|
+
function Authentication(authService, userRepository) {
|
|
1500
|
+
this.authService = authService;
|
|
1501
|
+
this.userRepository = userRepository;
|
|
1502
|
+
}
|
|
1503
|
+
Authentication.prototype.signIn = function (_b, signInMethod) {
|
|
1504
|
+
var email = _b.email, password = _b.password;
|
|
1505
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1506
|
+
var method, userAuth, user;
|
|
1507
|
+
return __generator(this, function (_b) {
|
|
1508
|
+
switch (_b.label) {
|
|
1509
|
+
case 0:
|
|
1510
|
+
method = this.getServiceByMethod(signInMethod);
|
|
1511
|
+
return [4 /*yield*/, this.authService[method]({ email: email, password: password })];
|
|
1512
|
+
case 1:
|
|
1513
|
+
userAuth = _b.sent();
|
|
1514
|
+
user = this.userRepository.get(userAuth);
|
|
1515
|
+
if (!lodash.isNil(user))
|
|
1516
|
+
return [2 /*return*/, user];
|
|
1517
|
+
if (/^.+@b4a.com.br$/.test(userAuth.email))
|
|
1518
|
+
return [2 /*return*/, this.createsUserByCredential(userAuth)];
|
|
1519
|
+
throw new UnauthorizedError('Invalid credentials');
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1522
|
+
});
|
|
1523
|
+
};
|
|
1524
|
+
Authentication.prototype.getServiceByMethod = function (signInMethod) {
|
|
1525
|
+
return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
|
|
1526
|
+
};
|
|
1527
|
+
Authentication.prototype.createsUserByCredential = function (user) {
|
|
1528
|
+
var _a;
|
|
1529
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1530
|
+
var _b, firstName, lastName, person;
|
|
1531
|
+
return __generator(this, function (_c) {
|
|
1532
|
+
_b = __read((_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/), 2), firstName = _b[0], lastName = _b[1];
|
|
1533
|
+
person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName: firstName,
|
|
1534
|
+
lastName: lastName, acceptsNewsletter: false, area: exports.Area.Transactional, officePosition: exports.OfficePosition.Intern, type: exports.UserType.Collaborator }));
|
|
1535
|
+
return [2 /*return*/, this.userRepository.create(person)];
|
|
1536
|
+
});
|
|
1537
|
+
});
|
|
1538
|
+
};
|
|
1539
|
+
return Authentication;
|
|
1540
|
+
}());
|
|
1541
|
+
|
|
1542
|
+
var UserAlreadyRegisteredError = /** @class */ (function (_super) {
|
|
1543
|
+
__extends(UserAlreadyRegisteredError, _super);
|
|
1544
|
+
function UserAlreadyRegisteredError(message) {
|
|
1545
|
+
var _this = _super.call(this, message) || this;
|
|
1546
|
+
_this.message = message;
|
|
1547
|
+
return _this;
|
|
1548
|
+
}
|
|
1549
|
+
return UserAlreadyRegisteredError;
|
|
1550
|
+
}(tsCustomError.CustomError));
|
|
1551
|
+
|
|
1552
|
+
var WeakPasswordError = /** @class */ (function (_super) {
|
|
1553
|
+
__extends(WeakPasswordError, _super);
|
|
1554
|
+
function WeakPasswordError(message) {
|
|
1555
|
+
if (message === void 0) { message = 'Weak password'; }
|
|
1556
|
+
var _this = _super.call(this, message) || this;
|
|
1557
|
+
_this.message = message;
|
|
1558
|
+
return _this;
|
|
1559
|
+
}
|
|
1560
|
+
return WeakPasswordError;
|
|
1561
|
+
}(tsCustomError.CustomError));
|
|
1562
|
+
|
|
1563
|
+
var Register = /** @class */ (function () {
|
|
1564
|
+
function Register(registerService, userRepository) {
|
|
1565
|
+
this.registerService = registerService;
|
|
1566
|
+
this.userRepository = userRepository;
|
|
1567
|
+
}
|
|
1568
|
+
Register.prototype.register = function (params) {
|
|
1569
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1570
|
+
var email, displayName, auth, user;
|
|
1571
|
+
return __generator(this, function (_a) {
|
|
1572
|
+
switch (_a.label) {
|
|
1573
|
+
case 0:
|
|
1574
|
+
email = params.email.toLocaleLowerCase();
|
|
1575
|
+
displayName = params.firstName + " " + params.lastName;
|
|
1576
|
+
return [4 /*yield*/, this.userRepository.checkIfExistsByField('cpf', params.cpf)];
|
|
1577
|
+
case 1:
|
|
1578
|
+
if (_a.sent())
|
|
1579
|
+
throw new UserAlreadyRegisteredError("Usu\u00E1rio com CPF " + params.cpf + " j\u00E1 registrado.");
|
|
1580
|
+
return [4 /*yield*/, this.userRepository.checkIfExistsByField('email', params.email)];
|
|
1581
|
+
case 2:
|
|
1582
|
+
if (_a.sent())
|
|
1583
|
+
throw new UserAlreadyRegisteredError("Usu\u00E1rio com e-mail " + params.email + " j\u00E1 registrado.");
|
|
1584
|
+
return [4 /*yield*/, this.registerService.register({
|
|
1585
|
+
birthday: params.birthday,
|
|
1586
|
+
email: email,
|
|
1587
|
+
firstName: params.firstName,
|
|
1588
|
+
lastName: params.lastName,
|
|
1589
|
+
cpf: params.cpf,
|
|
1590
|
+
displayName: displayName,
|
|
1591
|
+
phone: params.phone,
|
|
1592
|
+
password: params.password,
|
|
1593
|
+
})];
|
|
1594
|
+
case 3:
|
|
1595
|
+
auth = _a.sent();
|
|
1596
|
+
delete params.password;
|
|
1597
|
+
return [4 /*yield*/, this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email: email,
|
|
1598
|
+
displayName: displayName, type: exports.UserType.B2C, dateCreated: new Date(), dateModified: new Date() }))];
|
|
1599
|
+
case 4:
|
|
1600
|
+
user = _a.sent();
|
|
1601
|
+
return [2 /*return*/, user];
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
});
|
|
1605
|
+
};
|
|
1606
|
+
return Register;
|
|
1607
|
+
}());
|
|
1608
|
+
|
|
1609
|
+
var SignOut = /** @class */ (function () {
|
|
1610
|
+
function SignOut(authService) {
|
|
1611
|
+
this.authService = authService;
|
|
1612
|
+
}
|
|
1613
|
+
SignOut.prototype.signOut = function () {
|
|
1614
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1615
|
+
return __generator(this, function (_a) {
|
|
1616
|
+
switch (_a.label) {
|
|
1617
|
+
case 0: return [4 /*yield*/, this.authService.signOut()];
|
|
1618
|
+
case 1:
|
|
1619
|
+
_a.sent();
|
|
1620
|
+
return [2 /*return*/];
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
};
|
|
1625
|
+
return SignOut;
|
|
1626
|
+
}());
|
|
1627
|
+
|
|
1628
|
+
var RecoveryPassword = /** @class */ (function () {
|
|
1629
|
+
function RecoveryPassword(authService) {
|
|
1630
|
+
this.authService = authService;
|
|
1631
|
+
}
|
|
1632
|
+
RecoveryPassword.prototype.sendEmail = function (email) {
|
|
1633
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1634
|
+
return __generator(this, function (_a) {
|
|
1635
|
+
switch (_a.label) {
|
|
1636
|
+
case 0: return [4 /*yield*/, this.authService.sendPasswordResetEmail(email)];
|
|
1637
|
+
case 1:
|
|
1638
|
+
_a.sent();
|
|
1639
|
+
return [2 /*return*/];
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
});
|
|
1643
|
+
};
|
|
1644
|
+
return RecoveryPassword;
|
|
1645
|
+
}());
|
|
1646
|
+
|
|
1604
1647
|
exports.FilterType = void 0;
|
|
1605
1648
|
(function (FilterType) {
|
|
1606
1649
|
FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
|
|
@@ -2483,6 +2526,18 @@
|
|
|
2483
2526
|
return SubscriptionFirestoreRepository;
|
|
2484
2527
|
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2485
2528
|
|
|
2529
|
+
var SubscriptionMaterializationFirestoreRepository = /** @class */ (function (_super) {
|
|
2530
|
+
__extends(SubscriptionMaterializationFirestoreRepository, _super);
|
|
2531
|
+
function SubscriptionMaterializationFirestoreRepository(firestore) {
|
|
2532
|
+
var _this = _super.call(this) || this;
|
|
2533
|
+
_this.firestore = firestore;
|
|
2534
|
+
_this.collectionName = 'subscriptionMaterialization';
|
|
2535
|
+
_this.model = SubscriptionMaterialization;
|
|
2536
|
+
return _this;
|
|
2537
|
+
}
|
|
2538
|
+
return SubscriptionMaterializationFirestoreRepository;
|
|
2539
|
+
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2540
|
+
|
|
2486
2541
|
var SubscriptionPaymentFirestoreRepository = /** @class */ (function (_super) {
|
|
2487
2542
|
__extends(SubscriptionPaymentFirestoreRepository, _super);
|
|
2488
2543
|
function SubscriptionPaymentFirestoreRepository(firestore, parentRepository) {
|
|
@@ -5670,6 +5725,8 @@
|
|
|
5670
5725
|
exports.Subscription = Subscription;
|
|
5671
5726
|
exports.SubscriptionEditionFirestoreRepository = SubscriptionEditionFirestoreRepository;
|
|
5672
5727
|
exports.SubscriptionFirestoreRepository = SubscriptionFirestoreRepository;
|
|
5728
|
+
exports.SubscriptionMaterialization = SubscriptionMaterialization;
|
|
5729
|
+
exports.SubscriptionMaterializationFirestoreRepository = SubscriptionMaterializationFirestoreRepository;
|
|
5673
5730
|
exports.SubscriptionPayment = SubscriptionPayment;
|
|
5674
5731
|
exports.SubscriptionPaymentFirestoreRepository = SubscriptionPaymentFirestoreRepository;
|
|
5675
5732
|
exports.SubscriptionPlan = SubscriptionPlan;
|