@infrab4a/connect 4.3.0-beta.3 → 4.3.0-beta.5

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/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'reflect-metadata';
2
- import { plainToInstance, instanceToPlain, Expose, Type } from 'class-transformer';
3
2
  import * as tslib_1 from 'tslib';
4
3
  import { __decorate, __metadata, __rest } from 'tslib';
4
+ import { plainToInstance, instanceToPlain, Type, Expose } from 'class-transformer';
5
5
  import { parseISO } from 'date-fns';
6
6
  export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
7
7
  import { isNil, isArray as isArray$1, first, last, flatten, compact, get, isString, each, unset, isObject as isObject$1, set, isNumber, isEmpty, chunk, isDate, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
@@ -9,8 +9,9 @@ export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil,
9
9
  import { debug } from 'debug';
10
10
  import { CustomError } from 'ts-custom-error';
11
11
  import axios from 'axios';
12
- import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
13
12
  import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
13
+ import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
14
+ import { ref, uploadBytes } from 'firebase/storage';
14
15
  import { mutation, query as query$1 } from 'gql-query-builder';
15
16
 
16
17
  class BaseModel {
@@ -36,6 +37,187 @@ class BaseModel {
36
37
  }
37
38
  }
38
39
 
40
+ class Filter extends BaseModel {
41
+ static get identifiersFields() {
42
+ return ['id'];
43
+ }
44
+ }
45
+
46
+ class CategoryBase extends BaseModel {
47
+ static get identifiersFields() {
48
+ return ['id'];
49
+ }
50
+ }
51
+ __decorate([
52
+ Type(() => CategoryBase),
53
+ __metadata("design:type", CategoryBase)
54
+ ], CategoryBase.prototype, "parent", void 0);
55
+ __decorate([
56
+ Type(() => Filter),
57
+ __metadata("design:type", Array)
58
+ ], CategoryBase.prototype, "filters", void 0);
59
+
60
+ class CategoryForProduct extends CategoryBase {
61
+ static get identifiersFields() {
62
+ return ['id'];
63
+ }
64
+ }
65
+
66
+ class ProductBase extends BaseModel {
67
+ get evaluation() {
68
+ return {
69
+ reviews: this.reviews,
70
+ count: this.reviewsTotal,
71
+ rating: this.rate,
72
+ };
73
+ }
74
+ set evaluation(evaluation) {
75
+ if (!evaluation) {
76
+ this.reviews = null;
77
+ this.reviewsTotal = null;
78
+ this.rate = null;
79
+ return;
80
+ }
81
+ this.reviews = evaluation.reviews || this.reviews;
82
+ this.reviewsTotal = evaluation.count || this.reviewsTotal;
83
+ this.rate = evaluation.rating || this.rate;
84
+ }
85
+ static get identifiersFields() {
86
+ return ['id'];
87
+ }
88
+ }
89
+
90
+ class ProductForKit extends ProductBase {
91
+ static get identifiersFields() {
92
+ return ['id'];
93
+ }
94
+ }
95
+ __decorate([
96
+ Type(() => CategoryForProduct),
97
+ __metadata("design:type", CategoryForProduct)
98
+ ], ProductForKit.prototype, "category", void 0);
99
+
100
+ class KitProduct extends BaseModel {
101
+ static get identifiersFields() {
102
+ return ['productId', 'kitProductId'];
103
+ }
104
+ }
105
+ __decorate([
106
+ Type(() => ProductForKit),
107
+ __metadata("design:type", ProductForKit)
108
+ ], KitProduct.prototype, "kit", void 0);
109
+ __decorate([
110
+ Type(() => ProductForKit),
111
+ __metadata("design:type", ProductForKit)
112
+ ], KitProduct.prototype, "product", void 0);
113
+
114
+ class ProductForCategory extends ProductBase {
115
+ static get identifiersFields() {
116
+ return ['id'];
117
+ }
118
+ }
119
+ __decorate([
120
+ Type(() => KitProduct),
121
+ __metadata("design:type", Array)
122
+ ], ProductForCategory.prototype, "kitProducts", void 0);
123
+
124
+ class Category extends CategoryBase {
125
+ static get identifiersFields() {
126
+ return ['id'];
127
+ }
128
+ }
129
+ __decorate([
130
+ Type(() => ProductForCategory),
131
+ __metadata("design:type", Array)
132
+ ], Category.prototype, "childrenProducts", void 0);
133
+
134
+ class CategoryCollectionChildren extends BaseModel {
135
+ static get identifiersFields() {
136
+ return ['collectionId', 'categoryId'];
137
+ }
138
+ }
139
+ __decorate([
140
+ Type(() => CategoryCollectionChildren),
141
+ __metadata("design:type", CategoryCollectionChildren)
142
+ ], CategoryCollectionChildren.prototype, "parent", void 0);
143
+
144
+ class CategoryFilter extends BaseModel {
145
+ static get identifiersFields() {
146
+ return ['id'];
147
+ }
148
+ }
149
+ __decorate([
150
+ Type(() => Filter),
151
+ __metadata("design:type", Filter)
152
+ ], CategoryFilter.prototype, "filter", void 0);
153
+ __decorate([
154
+ Type(() => Category),
155
+ __metadata("design:type", Category)
156
+ ], CategoryFilter.prototype, "category", void 0);
157
+
158
+ var GenderDestination;
159
+ (function (GenderDestination) {
160
+ GenderDestination["FEMALE"] = "female";
161
+ GenderDestination["MALE"] = "male";
162
+ GenderDestination["UNISEX"] = "unisex";
163
+ })(GenderDestination || (GenderDestination = {}));
164
+
165
+ var Shops;
166
+ (function (Shops) {
167
+ Shops["MENSMARKET"] = "mensmarket";
168
+ Shops["GLAMSHOP"] = "Glamshop";
169
+ Shops["GLAMPOINTS"] = "Glampoints";
170
+ Shops["ALL"] = "ALL";
171
+ })(Shops || (Shops = {}));
172
+
173
+ class FilterOption extends BaseModel {
174
+ static get identifiersFields() {
175
+ return ['id'];
176
+ }
177
+ }
178
+
179
+ class Product extends ProductBase {
180
+ static get identifiersFields() {
181
+ return ['id'];
182
+ }
183
+ }
184
+ __decorate([
185
+ Type(() => CategoryForProduct),
186
+ __metadata("design:type", CategoryForProduct)
187
+ ], Product.prototype, "category", void 0);
188
+ __decorate([
189
+ Type(() => KitProduct),
190
+ __metadata("design:type", Array)
191
+ ], Product.prototype, "kitProducts", void 0);
192
+
193
+ class ProductReviews extends BaseModel {
194
+ static get identifiersFields() {
195
+ return ['id'];
196
+ }
197
+ }
198
+
199
+ class Variant extends BaseModel {
200
+ static get identifiersFields() {
201
+ return ['id', 'productId'];
202
+ }
203
+ }
204
+
205
+ class Wishlist extends Category {
206
+ static get identifiersFields() {
207
+ return ['id'];
208
+ }
209
+ }
210
+
211
+ class Buy2Win extends BaseModel {
212
+ static get identifiersFields() {
213
+ return ['id'];
214
+ }
215
+ }
216
+ __decorate([
217
+ Type(() => Category),
218
+ __metadata("design:type", Array)
219
+ ], Buy2Win.prototype, "categories", void 0);
220
+
39
221
  var Where;
40
222
  (function (Where) {
41
223
  Where["EQUALS"] = "==";
@@ -61,6 +243,18 @@ var UpdateOptionActions;
61
243
  UpdateOptionActions["NULL"] = "null";
62
244
  })(UpdateOptionActions || (UpdateOptionActions = {}));
63
245
 
246
+ class CampaignDashboard extends BaseModel {
247
+ static get identifiersFields() {
248
+ return ['id'];
249
+ }
250
+ }
251
+
252
+ class CampaignHashtag extends BaseModel {
253
+ static get identifiersFields() {
254
+ return ['id'];
255
+ }
256
+ }
257
+
64
258
  var AccessoryImportances;
65
259
  (function (AccessoryImportances) {
66
260
  AccessoryImportances["NOT_INTERESTED"] = "N\u00E3o tenho interesse";
@@ -1854,196 +2048,166 @@ __decorate([
1854
2048
  __metadata("design:type", Array)
1855
2049
  ], Subscription.prototype, "payment", void 0);
1856
2050
 
1857
- class Filter extends BaseModel {
1858
- static get identifiersFields() {
1859
- return ['id'];
1860
- }
1861
- }
1862
-
1863
- class CategoryBase extends BaseModel {
2051
+ class SubscriptionMaterialization extends BaseModel {
1864
2052
  static get identifiersFields() {
1865
2053
  return ['id'];
1866
2054
  }
1867
2055
  }
1868
2056
  __decorate([
1869
- Type(() => CategoryBase),
1870
- __metadata("design:type", CategoryBase)
1871
- ], CategoryBase.prototype, "parent", void 0);
2057
+ Type(() => User),
2058
+ __metadata("design:type", User)
2059
+ ], SubscriptionMaterialization.prototype, "user", void 0);
1872
2060
  __decorate([
1873
- Type(() => Filter),
2061
+ Type(() => SubscriptionPlan),
2062
+ __metadata("design:type", SubscriptionPlan)
2063
+ ], SubscriptionMaterialization.prototype, "subscriptionPlan", void 0);
2064
+ __decorate([
2065
+ Type(() => UserAddress),
2066
+ __metadata("design:type", UserAddress)
2067
+ ], SubscriptionMaterialization.prototype, "shippingAddress", void 0);
2068
+ __decorate([
2069
+ Type(() => UserAddress),
2070
+ __metadata("design:type", UserAddress)
2071
+ ], SubscriptionMaterialization.prototype, "billingAddress", void 0);
2072
+ __decorate([
2073
+ Type(() => Coupon),
2074
+ __metadata("design:type", Coupon)
2075
+ ], SubscriptionMaterialization.prototype, "coupon", void 0);
2076
+ __decorate([
2077
+ Type(() => Edition),
1874
2078
  __metadata("design:type", Array)
1875
- ], CategoryBase.prototype, "filters", void 0);
2079
+ ], SubscriptionMaterialization.prototype, "editions", void 0);
2080
+ __decorate([
2081
+ Type(() => SubscriptionPayment),
2082
+ __metadata("design:type", SubscriptionPayment)
2083
+ ], SubscriptionMaterialization.prototype, "payment", void 0);
1876
2084
 
1877
- class CategoryForProduct extends CategoryBase {
2085
+ class SubscriptionSummary extends BaseModel {
1878
2086
  static get identifiersFields() {
1879
2087
  return ['id'];
1880
2088
  }
1881
2089
  }
1882
2090
 
1883
- class ProductBase extends BaseModel {
1884
- get evaluation() {
1885
- return {
1886
- reviews: this.reviews,
1887
- count: this.reviewsTotal,
1888
- rating: this.rate,
1889
- };
1890
- }
1891
- set evaluation(evaluation) {
1892
- if (!evaluation) {
1893
- this.reviews = null;
1894
- this.reviewsTotal = null;
1895
- this.rate = null;
1896
- return;
1897
- }
1898
- this.reviews = evaluation.reviews || this.reviews;
1899
- this.reviewsTotal = evaluation.count || this.reviewsTotal;
1900
- this.rate = evaluation.rating || this.rate;
1901
- }
2091
+ class UserPaymentMethod extends BaseModel {
1902
2092
  static get identifiersFields() {
1903
- return ['id'];
2093
+ return ['id', 'userId'];
1904
2094
  }
1905
2095
  }
1906
2096
 
1907
- class ProductForKit extends ProductBase {
2097
+ class Lead extends BaseModel {
1908
2098
  static get identifiersFields() {
1909
2099
  return ['id'];
1910
2100
  }
1911
- }
1912
- __decorate([
1913
- Type(() => CategoryForProduct),
1914
- __metadata("design:type", CategoryForProduct)
1915
- ], ProductForKit.prototype, "category", void 0);
1916
-
1917
- class KitProduct extends BaseModel {
1918
- static get identifiersFields() {
1919
- return ['productId', 'kitProductId'];
1920
- }
1921
- }
1922
- __decorate([
1923
- Type(() => ProductForKit),
1924
- __metadata("design:type", ProductForKit)
1925
- ], KitProduct.prototype, "kit", void 0);
1926
- __decorate([
1927
- Type(() => ProductForKit),
1928
- __metadata("design:type", ProductForKit)
1929
- ], KitProduct.prototype, "product", void 0);
2101
+ }
1930
2102
 
1931
- class ProductForCategory extends ProductBase {
1932
- static get identifiersFields() {
1933
- return ['id'];
2103
+ class UnauthorizedError extends CustomError {
2104
+ constructor(message) {
2105
+ super(message);
1934
2106
  }
1935
- }
1936
- __decorate([
1937
- Type(() => KitProduct),
1938
- __metadata("design:type", Array)
1939
- ], ProductForCategory.prototype, "kitProducts", void 0);
2107
+ }
1940
2108
 
1941
- class Category extends CategoryBase {
1942
- static get identifiersFields() {
1943
- return ['id'];
2109
+ var SignInMethods;
2110
+ (function (SignInMethods) {
2111
+ SignInMethods["EMAIL_PASSWORD"] = "email_password";
2112
+ SignInMethods["GOOGLE"] = "google";
2113
+ })(SignInMethods || (SignInMethods = {}));
2114
+ class Authentication {
2115
+ constructor(authService, userRepository) {
2116
+ this.authService = authService;
2117
+ this.userRepository = userRepository;
1944
2118
  }
1945
- }
1946
- __decorate([
1947
- Type(() => ProductForCategory),
1948
- __metadata("design:type", Array)
1949
- ], Category.prototype, "childrenProducts", void 0);
1950
-
1951
- class CategoryCollectionChildren extends BaseModel {
1952
- static get identifiersFields() {
1953
- return ['collectionId', 'categoryId'];
2119
+ async signIn({ email, password }, signInMethod) {
2120
+ const method = this.getServiceByMethod(signInMethod);
2121
+ const userAuth = await this.authService[method]({ email, password });
2122
+ const user = this.userRepository.get({ id: userAuth.id });
2123
+ if (!isNil(user))
2124
+ return user;
2125
+ if (/^.+@b4a.com.br$/.test(userAuth.email))
2126
+ return this.createsUserByCredential(userAuth);
2127
+ throw new UnauthorizedError('Invalid credentials');
1954
2128
  }
1955
- }
1956
- __decorate([
1957
- Type(() => CategoryCollectionChildren),
1958
- __metadata("design:type", CategoryCollectionChildren)
1959
- ], CategoryCollectionChildren.prototype, "parent", void 0);
1960
-
1961
- class CategoryFilter extends BaseModel {
1962
- static get identifiersFields() {
1963
- return ['id'];
2129
+ getServiceByMethod(signInMethod) {
2130
+ return signInMethod === SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
1964
2131
  }
1965
- }
1966
- __decorate([
1967
- Type(() => Filter),
1968
- __metadata("design:type", Filter)
1969
- ], CategoryFilter.prototype, "filter", void 0);
1970
- __decorate([
1971
- Type(() => Category),
1972
- __metadata("design:type", Category)
1973
- ], CategoryFilter.prototype, "category", void 0);
1974
-
1975
- var GenderDestination;
1976
- (function (GenderDestination) {
1977
- GenderDestination["FEMALE"] = "female";
1978
- GenderDestination["MALE"] = "male";
1979
- GenderDestination["UNISEX"] = "unisex";
1980
- })(GenderDestination || (GenderDestination = {}));
1981
-
1982
- var Shops;
1983
- (function (Shops) {
1984
- Shops["MENSMARKET"] = "mensmarket";
1985
- Shops["GLAMSHOP"] = "Glamshop";
1986
- Shops["GLAMPOINTS"] = "Glampoints";
1987
- Shops["ALL"] = "ALL";
1988
- })(Shops || (Shops = {}));
1989
-
1990
- class FilterOption extends BaseModel {
1991
- static get identifiersFields() {
1992
- return ['id'];
2132
+ async createsUserByCredential(user) {
2133
+ var _a;
2134
+ const [firstName, lastName] = (_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/);
2135
+ const person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName,
2136
+ lastName, acceptsNewsletter: false, area: Area.Transactional, officePosition: OfficePosition.Intern, type: UserType.Collaborator }));
2137
+ return this.userRepository.create(person);
1993
2138
  }
1994
2139
  }
1995
2140
 
1996
- class Product extends ProductBase {
1997
- static get identifiersFields() {
1998
- return ['id'];
2141
+ class RecoveryPassword {
2142
+ constructor(authService) {
2143
+ this.authService = authService;
1999
2144
  }
2000
- }
2001
- __decorate([
2002
- Type(() => CategoryForProduct),
2003
- __metadata("design:type", CategoryForProduct)
2004
- ], Product.prototype, "category", void 0);
2005
- __decorate([
2006
- Type(() => KitProduct),
2007
- __metadata("design:type", Array)
2008
- ], Product.prototype, "kitProducts", void 0);
2009
-
2010
- class ProductReviews extends BaseModel {
2011
- static get identifiersFields() {
2012
- return ['id'];
2145
+ async sendEmail(email) {
2146
+ await this.authService.sendPasswordResetEmail(email);
2013
2147
  }
2014
2148
  }
2015
2149
 
2016
- class Variant extends BaseModel {
2017
- static get identifiersFields() {
2018
- return ['id', 'productId'];
2150
+ class UserAlreadyRegisteredError extends CustomError {
2151
+ constructor(message) {
2152
+ super(message);
2019
2153
  }
2020
2154
  }
2021
2155
 
2022
- class Wishlist extends Category {
2023
- static get identifiersFields() {
2024
- return ['id'];
2156
+ class WeakPasswordError extends CustomError {
2157
+ constructor(message = 'Weak password') {
2158
+ super(message);
2025
2159
  }
2026
2160
  }
2027
2161
 
2028
- class Buy2Win extends BaseModel {
2029
- static get identifiersFields() {
2030
- return ['id'];
2162
+ class Register {
2163
+ constructor(registerService, userRepository) {
2164
+ this.registerService = registerService;
2165
+ this.userRepository = userRepository;
2031
2166
  }
2032
- }
2033
- __decorate([
2034
- Type(() => Category),
2035
- __metadata("design:type", Array)
2036
- ], Buy2Win.prototype, "categories", void 0);
2167
+ async register(params) {
2168
+ const email = params.email.toLocaleLowerCase();
2169
+ const displayName = `${params.firstName} ${params.lastName}`;
2170
+ if (await this.userRepository.checkIfExistsByField('cpf', params.cpf))
2171
+ throw new UserAlreadyRegisteredError(`Usuário com CPF ${params.cpf} registrado.`);
2172
+ if (await this.userRepository.checkIfExistsByField('email', params.email))
2173
+ throw new UserAlreadyRegisteredError(`Usuário com e-mail ${params.email} já registrado.`);
2174
+ const auth = await this.registerService.register({
2175
+ birthday: params.birthday,
2176
+ email,
2177
+ firstName: params.firstName,
2178
+ lastName: params.lastName,
2179
+ cpf: params.cpf,
2180
+ displayName,
2181
+ phone: params.phone,
2182
+ password: params.password,
2183
+ });
2184
+ delete params.password;
2185
+ const user = await this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email,
2186
+ displayName, type: UserType.B2C, dateCreated: new Date(), dateModified: new Date() }));
2187
+ return user;
2188
+ }
2189
+ }
2037
2190
 
2038
- class CampaignDashboard extends BaseModel {
2039
- static get identifiersFields() {
2040
- return ['id'];
2191
+ class SignOut {
2192
+ constructor(authService) {
2193
+ this.authService = authService;
2194
+ }
2195
+ async signOut() {
2196
+ await this.authService.signOut();
2041
2197
  }
2042
2198
  }
2043
2199
 
2044
- class CampaignHashtag extends BaseModel {
2045
- static get identifiersFields() {
2046
- return ['id'];
2200
+ class UpdateUserImage {
2201
+ constructor(userRepository, fileUploader) {
2202
+ this.userRepository = userRepository;
2203
+ this.fileUploader = fileUploader;
2204
+ }
2205
+ async execute(file, user) {
2206
+ const extension = file.type.split('/').pop();
2207
+ const path = `users/${user.id}/profile.${extension}`;
2208
+ const url = await this.fileUploader.upload(path, file);
2209
+ user.urlImageProfile = url;
2210
+ return this.userRepository.update(user);
2047
2211
  }
2048
2212
  }
2049
2213
 
@@ -2127,155 +2291,6 @@ __decorate([
2127
2291
  __metadata("design:type", Coupon)
2128
2292
  ], CheckoutSubscription.prototype, "coupon", void 0);
2129
2293
 
2130
- class SubscriptionMaterialization extends BaseModel {
2131
- static get identifiersFields() {
2132
- return ['id'];
2133
- }
2134
- }
2135
- __decorate([
2136
- Type(() => User),
2137
- __metadata("design:type", User)
2138
- ], SubscriptionMaterialization.prototype, "user", void 0);
2139
- __decorate([
2140
- Type(() => SubscriptionPlan),
2141
- __metadata("design:type", SubscriptionPlan)
2142
- ], SubscriptionMaterialization.prototype, "subscriptionPlan", void 0);
2143
- __decorate([
2144
- Type(() => UserAddress),
2145
- __metadata("design:type", UserAddress)
2146
- ], SubscriptionMaterialization.prototype, "shippingAddress", void 0);
2147
- __decorate([
2148
- Type(() => UserAddress),
2149
- __metadata("design:type", UserAddress)
2150
- ], SubscriptionMaterialization.prototype, "billingAddress", void 0);
2151
- __decorate([
2152
- Type(() => Coupon),
2153
- __metadata("design:type", Coupon)
2154
- ], SubscriptionMaterialization.prototype, "coupon", void 0);
2155
- __decorate([
2156
- Type(() => Edition),
2157
- __metadata("design:type", Array)
2158
- ], SubscriptionMaterialization.prototype, "editions", void 0);
2159
- __decorate([
2160
- Type(() => SubscriptionPayment),
2161
- __metadata("design:type", SubscriptionPayment)
2162
- ], SubscriptionMaterialization.prototype, "payment", void 0);
2163
-
2164
- class SubscriptionSummary extends BaseModel {
2165
- static get identifiersFields() {
2166
- return ['id'];
2167
- }
2168
- }
2169
-
2170
- class UserPaymentMethod extends BaseModel {
2171
- static get identifiersFields() {
2172
- return ['id', 'userId'];
2173
- }
2174
- }
2175
-
2176
- class Lead extends BaseModel {
2177
- static get identifiersFields() {
2178
- return ['id'];
2179
- }
2180
- }
2181
-
2182
- class UnauthorizedError extends CustomError {
2183
- constructor(message) {
2184
- super(message);
2185
- }
2186
- }
2187
-
2188
- var SignInMethods;
2189
- (function (SignInMethods) {
2190
- SignInMethods["EMAIL_PASSWORD"] = "email_password";
2191
- SignInMethods["GOOGLE"] = "google";
2192
- })(SignInMethods || (SignInMethods = {}));
2193
- class Authentication {
2194
- constructor(authService, userRepository) {
2195
- this.authService = authService;
2196
- this.userRepository = userRepository;
2197
- }
2198
- async signIn({ email, password }, signInMethod) {
2199
- const method = this.getServiceByMethod(signInMethod);
2200
- const userAuth = await this.authService[method]({ email, password });
2201
- const user = this.userRepository.get({ id: userAuth.id });
2202
- if (!isNil(user))
2203
- return user;
2204
- if (/^.+@b4a.com.br$/.test(userAuth.email))
2205
- return this.createsUserByCredential(userAuth);
2206
- throw new UnauthorizedError('Invalid credentials');
2207
- }
2208
- getServiceByMethod(signInMethod) {
2209
- return signInMethod === SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
2210
- }
2211
- async createsUserByCredential(user) {
2212
- var _a;
2213
- const [firstName, lastName] = (_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/);
2214
- const person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName,
2215
- lastName, acceptsNewsletter: false, area: Area.Transactional, officePosition: OfficePosition.Intern, type: UserType.Collaborator }));
2216
- return this.userRepository.create(person);
2217
- }
2218
- }
2219
-
2220
- class UserAlreadyRegisteredError extends CustomError {
2221
- constructor(message) {
2222
- super(message);
2223
- }
2224
- }
2225
-
2226
- class WeakPasswordError extends CustomError {
2227
- constructor(message = 'Weak password') {
2228
- super(message);
2229
- }
2230
- }
2231
-
2232
- class Register {
2233
- constructor(registerService, userRepository) {
2234
- this.registerService = registerService;
2235
- this.userRepository = userRepository;
2236
- }
2237
- async register(params) {
2238
- const email = params.email.toLocaleLowerCase();
2239
- const displayName = `${params.firstName} ${params.lastName}`;
2240
- if (await this.userRepository.checkIfExistsByField('cpf', params.cpf))
2241
- throw new UserAlreadyRegisteredError(`Usuário com CPF ${params.cpf} já registrado.`);
2242
- if (await this.userRepository.checkIfExistsByField('email', params.email))
2243
- throw new UserAlreadyRegisteredError(`Usuário com e-mail ${params.email} já registrado.`);
2244
- const auth = await this.registerService.register({
2245
- birthday: params.birthday,
2246
- email,
2247
- firstName: params.firstName,
2248
- lastName: params.lastName,
2249
- cpf: params.cpf,
2250
- displayName,
2251
- phone: params.phone,
2252
- password: params.password,
2253
- });
2254
- delete params.password;
2255
- const user = await this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email,
2256
- displayName, type: UserType.B2C, dateCreated: new Date(), dateModified: new Date() }));
2257
- return user;
2258
- }
2259
- }
2260
-
2261
- class SignOut {
2262
- constructor(authService) {
2263
- this.authService = authService;
2264
- }
2265
- async signOut() {
2266
- await this.authService.signOut();
2267
- }
2268
- }
2269
-
2270
- class RecoveryPassword {
2271
- constructor(authService) {
2272
- this.authService = authService;
2273
- }
2274
- async sendEmail(email) {
2275
- await this.authService.sendPasswordResetEmail(email);
2276
- }
2277
- }
2278
-
2279
2294
  class RoundProductPricesHelper {
2280
2295
  static roundProductPrices(product) {
2281
2296
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2609,6 +2624,75 @@ class ProductsIndex {
2609
2624
  }
2610
2625
  }
2611
2626
 
2627
+ class AuthenticationFirebaseAuthService {
2628
+ constructor(firebaseAuth) {
2629
+ this.firebaseAuth = firebaseAuth;
2630
+ }
2631
+ async signInWithEmailAndPassword(data) {
2632
+ const credentials = await signInWithEmailAndPassword(this.firebaseAuth, data.email, data.password);
2633
+ const user = credentials.user;
2634
+ return {
2635
+ id: user.uid,
2636
+ displayName: user.displayName,
2637
+ email: user.email,
2638
+ phone: user.phoneNumber,
2639
+ isAnonymous: false,
2640
+ };
2641
+ }
2642
+ async signInWithGoogle() {
2643
+ const credentials = await signInWithPopup(this.firebaseAuth, new GoogleAuthProvider());
2644
+ const user = credentials.user;
2645
+ return {
2646
+ id: user.uid,
2647
+ displayName: user.displayName,
2648
+ email: user.email,
2649
+ phone: user.phoneNumber,
2650
+ isAnonymous: false,
2651
+ };
2652
+ }
2653
+ async signOut() {
2654
+ this.firebaseAuth.signOut();
2655
+ }
2656
+ async signInAnonymously() {
2657
+ const auth = await signInAnonymously(this.firebaseAuth);
2658
+ const user = auth.user;
2659
+ user.id = auth.user.uid;
2660
+ return user;
2661
+ }
2662
+ async sendPasswordResetEmail(email) {
2663
+ return sendPasswordResetEmail(this.firebaseAuth, email);
2664
+ }
2665
+ }
2666
+
2667
+ class RegisterFirebaseAuthService {
2668
+ constructor(firebaseAuth) {
2669
+ this.firebaseAuth = firebaseAuth;
2670
+ }
2671
+ async register(params) {
2672
+ if (!params.email)
2673
+ throw new RequiredArgumentError(['email']);
2674
+ try {
2675
+ const auth = await createUserWithEmailAndPassword(this.firebaseAuth, params.email, params.password);
2676
+ const user = is(auth.user);
2677
+ if (!user)
2678
+ throw new Error('User not created');
2679
+ await sendEmailVerification(user);
2680
+ user.id = user.uid;
2681
+ return user;
2682
+ }
2683
+ catch (error) {
2684
+ if (!(error instanceof Error))
2685
+ throw error;
2686
+ const firebaseError = error;
2687
+ if (firebaseError.code === 'auth/email-already-in-use')
2688
+ throw new UserAlreadyRegisteredError('Email already registered');
2689
+ if (firebaseError.code === 'auth/weak-password')
2690
+ throw new WeakPasswordError();
2691
+ throw error;
2692
+ }
2693
+ }
2694
+ }
2695
+
2612
2696
  const withFirestore = (MixinBase) => {
2613
2697
  const isObjectsAndNoDate = (data) => data &&
2614
2698
  !Array.isArray(data) &&
@@ -3479,72 +3563,14 @@ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(with
3479
3563
  }
3480
3564
  }
3481
3565
 
3482
- class AuthenticationFirebaseAuthService {
3483
- constructor(firebaseAuth) {
3484
- this.firebaseAuth = firebaseAuth;
3485
- }
3486
- async signInWithEmailAndPassword(data) {
3487
- const credentials = await signInWithEmailAndPassword(this.firebaseAuth, data.email, data.password);
3488
- const user = credentials.user;
3489
- return {
3490
- id: user.uid,
3491
- displayName: user.displayName,
3492
- email: user.email,
3493
- phone: user.phoneNumber,
3494
- isAnonymous: false,
3495
- };
3496
- }
3497
- async signInWithGoogle() {
3498
- const credentials = await signInWithPopup(this.firebaseAuth, new GoogleAuthProvider());
3499
- const user = credentials.user;
3500
- return {
3501
- id: user.uid,
3502
- displayName: user.displayName,
3503
- email: user.email,
3504
- phone: user.phoneNumber,
3505
- isAnonymous: false,
3506
- };
3507
- }
3508
- async signOut() {
3509
- this.firebaseAuth.signOut();
3510
- }
3511
- async signInAnonymously() {
3512
- const auth = await signInAnonymously(this.firebaseAuth);
3513
- const user = auth.user;
3514
- user.id = auth.user.uid;
3515
- return user;
3516
- }
3517
- async sendPasswordResetEmail(email) {
3518
- return sendPasswordResetEmail(this.firebaseAuth, email);
3519
- }
3520
- }
3521
-
3522
- class RegisterFirebaseAuthService {
3523
- constructor(firebaseAuth) {
3524
- this.firebaseAuth = firebaseAuth;
3566
+ class FirebaseFileUploaderService {
3567
+ constructor(storage, baseUrl) {
3568
+ this.storage = storage;
3569
+ this.baseUrl = baseUrl;
3525
3570
  }
3526
- async register(params) {
3527
- if (!params.email)
3528
- throw new RequiredArgumentError(['email']);
3529
- try {
3530
- const auth = await createUserWithEmailAndPassword(this.firebaseAuth, params.email, params.password);
3531
- const user = is(auth.user);
3532
- if (!user)
3533
- throw new Error('User not created');
3534
- await sendEmailVerification(user);
3535
- user.id = user.uid;
3536
- return user;
3537
- }
3538
- catch (error) {
3539
- if (!(error instanceof Error))
3540
- throw error;
3541
- const firebaseError = error;
3542
- if (firebaseError.code === 'auth/email-already-in-use')
3543
- throw new UserAlreadyRegisteredError('Email already registered');
3544
- if (firebaseError.code === 'auth/weak-password')
3545
- throw new WeakPasswordError();
3546
- throw error;
3547
- }
3571
+ async upload(path, file) {
3572
+ const storageRef = ref(this.storage, path);
3573
+ return uploadBytes(storageRef, file).then((reference) => `${this.baseUrl}/${reference.ref.bucket}/${reference.ref.fullPath}`);
3548
3574
  }
3549
3575
  }
3550
3576
 
@@ -5619,4 +5645,4 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5619
5645
  }
5620
5646
  }
5621
5647
 
5622
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
5648
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };