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

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.cjs.js CHANGED
@@ -3,15 +3,16 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('reflect-metadata');
6
- var classTransformer = require('class-transformer');
7
6
  var tslib_1 = require('tslib');
7
+ var classTransformer = require('class-transformer');
8
8
  var dateFns = require('date-fns');
9
9
  var lodash = require('lodash');
10
10
  var debug = require('debug');
11
11
  var tsCustomError = require('ts-custom-error');
12
12
  var axios = require('axios');
13
- var firestore = require('firebase/firestore');
14
13
  var auth = require('firebase/auth');
14
+ var firestore = require('firebase/firestore');
15
+ var storage = require('firebase/storage');
15
16
  var gqlQueryBuilder = require('gql-query-builder');
16
17
 
17
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -60,6 +61,187 @@ class BaseModel {
60
61
  }
61
62
  }
62
63
 
64
+ class Filter extends BaseModel {
65
+ static get identifiersFields() {
66
+ return ['id'];
67
+ }
68
+ }
69
+
70
+ class CategoryBase extends BaseModel {
71
+ static get identifiersFields() {
72
+ return ['id'];
73
+ }
74
+ }
75
+ tslib_1.__decorate([
76
+ classTransformer.Type(() => CategoryBase),
77
+ tslib_1.__metadata("design:type", CategoryBase)
78
+ ], CategoryBase.prototype, "parent", void 0);
79
+ tslib_1.__decorate([
80
+ classTransformer.Type(() => Filter),
81
+ tslib_1.__metadata("design:type", Array)
82
+ ], CategoryBase.prototype, "filters", void 0);
83
+
84
+ class CategoryForProduct extends CategoryBase {
85
+ static get identifiersFields() {
86
+ return ['id'];
87
+ }
88
+ }
89
+
90
+ class ProductBase extends BaseModel {
91
+ get evaluation() {
92
+ return {
93
+ reviews: this.reviews,
94
+ count: this.reviewsTotal,
95
+ rating: this.rate,
96
+ };
97
+ }
98
+ set evaluation(evaluation) {
99
+ if (!evaluation) {
100
+ this.reviews = null;
101
+ this.reviewsTotal = null;
102
+ this.rate = null;
103
+ return;
104
+ }
105
+ this.reviews = evaluation.reviews || this.reviews;
106
+ this.reviewsTotal = evaluation.count || this.reviewsTotal;
107
+ this.rate = evaluation.rating || this.rate;
108
+ }
109
+ static get identifiersFields() {
110
+ return ['id'];
111
+ }
112
+ }
113
+
114
+ class ProductForKit extends ProductBase {
115
+ static get identifiersFields() {
116
+ return ['id'];
117
+ }
118
+ }
119
+ tslib_1.__decorate([
120
+ classTransformer.Type(() => CategoryForProduct),
121
+ tslib_1.__metadata("design:type", CategoryForProduct)
122
+ ], ProductForKit.prototype, "category", void 0);
123
+
124
+ class KitProduct extends BaseModel {
125
+ static get identifiersFields() {
126
+ return ['productId', 'kitProductId'];
127
+ }
128
+ }
129
+ tslib_1.__decorate([
130
+ classTransformer.Type(() => ProductForKit),
131
+ tslib_1.__metadata("design:type", ProductForKit)
132
+ ], KitProduct.prototype, "kit", void 0);
133
+ tslib_1.__decorate([
134
+ classTransformer.Type(() => ProductForKit),
135
+ tslib_1.__metadata("design:type", ProductForKit)
136
+ ], KitProduct.prototype, "product", void 0);
137
+
138
+ class ProductForCategory extends ProductBase {
139
+ static get identifiersFields() {
140
+ return ['id'];
141
+ }
142
+ }
143
+ tslib_1.__decorate([
144
+ classTransformer.Type(() => KitProduct),
145
+ tslib_1.__metadata("design:type", Array)
146
+ ], ProductForCategory.prototype, "kitProducts", void 0);
147
+
148
+ class Category extends CategoryBase {
149
+ static get identifiersFields() {
150
+ return ['id'];
151
+ }
152
+ }
153
+ tslib_1.__decorate([
154
+ classTransformer.Type(() => ProductForCategory),
155
+ tslib_1.__metadata("design:type", Array)
156
+ ], Category.prototype, "childrenProducts", void 0);
157
+
158
+ class CategoryCollectionChildren extends BaseModel {
159
+ static get identifiersFields() {
160
+ return ['collectionId', 'categoryId'];
161
+ }
162
+ }
163
+ tslib_1.__decorate([
164
+ classTransformer.Type(() => CategoryCollectionChildren),
165
+ tslib_1.__metadata("design:type", CategoryCollectionChildren)
166
+ ], CategoryCollectionChildren.prototype, "parent", void 0);
167
+
168
+ class CategoryFilter extends BaseModel {
169
+ static get identifiersFields() {
170
+ return ['id'];
171
+ }
172
+ }
173
+ tslib_1.__decorate([
174
+ classTransformer.Type(() => Filter),
175
+ tslib_1.__metadata("design:type", Filter)
176
+ ], CategoryFilter.prototype, "filter", void 0);
177
+ tslib_1.__decorate([
178
+ classTransformer.Type(() => Category),
179
+ tslib_1.__metadata("design:type", Category)
180
+ ], CategoryFilter.prototype, "category", void 0);
181
+
182
+ exports.GenderDestination = void 0;
183
+ (function (GenderDestination) {
184
+ GenderDestination["FEMALE"] = "female";
185
+ GenderDestination["MALE"] = "male";
186
+ GenderDestination["UNISEX"] = "unisex";
187
+ })(exports.GenderDestination || (exports.GenderDestination = {}));
188
+
189
+ exports.Shops = void 0;
190
+ (function (Shops) {
191
+ Shops["MENSMARKET"] = "mensmarket";
192
+ Shops["GLAMSHOP"] = "Glamshop";
193
+ Shops["GLAMPOINTS"] = "Glampoints";
194
+ Shops["ALL"] = "ALL";
195
+ })(exports.Shops || (exports.Shops = {}));
196
+
197
+ class FilterOption extends BaseModel {
198
+ static get identifiersFields() {
199
+ return ['id'];
200
+ }
201
+ }
202
+
203
+ class Product extends ProductBase {
204
+ static get identifiersFields() {
205
+ return ['id'];
206
+ }
207
+ }
208
+ tslib_1.__decorate([
209
+ classTransformer.Type(() => CategoryForProduct),
210
+ tslib_1.__metadata("design:type", CategoryForProduct)
211
+ ], Product.prototype, "category", void 0);
212
+ tslib_1.__decorate([
213
+ classTransformer.Type(() => KitProduct),
214
+ tslib_1.__metadata("design:type", Array)
215
+ ], Product.prototype, "kitProducts", void 0);
216
+
217
+ class ProductReviews extends BaseModel {
218
+ static get identifiersFields() {
219
+ return ['id'];
220
+ }
221
+ }
222
+
223
+ class Variant extends BaseModel {
224
+ static get identifiersFields() {
225
+ return ['id', 'productId'];
226
+ }
227
+ }
228
+
229
+ class Wishlist extends Category {
230
+ static get identifiersFields() {
231
+ return ['id'];
232
+ }
233
+ }
234
+
235
+ class Buy2Win extends BaseModel {
236
+ static get identifiersFields() {
237
+ return ['id'];
238
+ }
239
+ }
240
+ tslib_1.__decorate([
241
+ classTransformer.Type(() => Category),
242
+ tslib_1.__metadata("design:type", Array)
243
+ ], Buy2Win.prototype, "categories", void 0);
244
+
63
245
  exports.Where = void 0;
64
246
  (function (Where) {
65
247
  Where["EQUALS"] = "==";
@@ -85,6 +267,18 @@ exports.UpdateOptionActions = void 0;
85
267
  UpdateOptionActions["NULL"] = "null";
86
268
  })(exports.UpdateOptionActions || (exports.UpdateOptionActions = {}));
87
269
 
270
+ class CampaignDashboard extends BaseModel {
271
+ static get identifiersFields() {
272
+ return ['id'];
273
+ }
274
+ }
275
+
276
+ class CampaignHashtag extends BaseModel {
277
+ static get identifiersFields() {
278
+ return ['id'];
279
+ }
280
+ }
281
+
88
282
  exports.AccessoryImportances = void 0;
89
283
  (function (AccessoryImportances) {
90
284
  AccessoryImportances["NOT_INTERESTED"] = "N\u00E3o tenho interesse";
@@ -1878,196 +2072,152 @@ tslib_1.__decorate([
1878
2072
  tslib_1.__metadata("design:type", Array)
1879
2073
  ], Subscription.prototype, "payment", void 0);
1880
2074
 
1881
- class Filter extends BaseModel {
1882
- static get identifiersFields() {
1883
- return ['id'];
1884
- }
1885
- }
1886
-
1887
- class CategoryBase extends BaseModel {
2075
+ class SubscriptionMaterialization extends BaseModel {
1888
2076
  static get identifiersFields() {
1889
2077
  return ['id'];
1890
2078
  }
1891
2079
  }
1892
2080
  tslib_1.__decorate([
1893
- classTransformer.Type(() => CategoryBase),
1894
- tslib_1.__metadata("design:type", CategoryBase)
1895
- ], CategoryBase.prototype, "parent", void 0);
2081
+ classTransformer.Type(() => User),
2082
+ tslib_1.__metadata("design:type", User)
2083
+ ], SubscriptionMaterialization.prototype, "user", void 0);
1896
2084
  tslib_1.__decorate([
1897
- classTransformer.Type(() => Filter),
2085
+ classTransformer.Type(() => SubscriptionPlan),
2086
+ tslib_1.__metadata("design:type", SubscriptionPlan)
2087
+ ], SubscriptionMaterialization.prototype, "subscriptionPlan", void 0);
2088
+ tslib_1.__decorate([
2089
+ classTransformer.Type(() => UserAddress),
2090
+ tslib_1.__metadata("design:type", UserAddress)
2091
+ ], SubscriptionMaterialization.prototype, "shippingAddress", void 0);
2092
+ tslib_1.__decorate([
2093
+ classTransformer.Type(() => UserAddress),
2094
+ tslib_1.__metadata("design:type", UserAddress)
2095
+ ], SubscriptionMaterialization.prototype, "billingAddress", void 0);
2096
+ tslib_1.__decorate([
2097
+ classTransformer.Type(() => Coupon),
2098
+ tslib_1.__metadata("design:type", Coupon)
2099
+ ], SubscriptionMaterialization.prototype, "coupon", void 0);
2100
+ tslib_1.__decorate([
2101
+ classTransformer.Type(() => Edition),
1898
2102
  tslib_1.__metadata("design:type", Array)
1899
- ], CategoryBase.prototype, "filters", void 0);
2103
+ ], SubscriptionMaterialization.prototype, "editions", void 0);
2104
+ tslib_1.__decorate([
2105
+ classTransformer.Type(() => SubscriptionPayment),
2106
+ tslib_1.__metadata("design:type", SubscriptionPayment)
2107
+ ], SubscriptionMaterialization.prototype, "payment", void 0);
1900
2108
 
1901
- class CategoryForProduct extends CategoryBase {
2109
+ class SubscriptionSummary extends BaseModel {
1902
2110
  static get identifiersFields() {
1903
2111
  return ['id'];
1904
2112
  }
1905
2113
  }
1906
2114
 
1907
- class ProductBase extends BaseModel {
1908
- get evaluation() {
1909
- return {
1910
- reviews: this.reviews,
1911
- count: this.reviewsTotal,
1912
- rating: this.rate,
1913
- };
1914
- }
1915
- set evaluation(evaluation) {
1916
- if (!evaluation) {
1917
- this.reviews = null;
1918
- this.reviewsTotal = null;
1919
- this.rate = null;
1920
- return;
1921
- }
1922
- this.reviews = evaluation.reviews || this.reviews;
1923
- this.reviewsTotal = evaluation.count || this.reviewsTotal;
1924
- this.rate = evaluation.rating || this.rate;
1925
- }
1926
- static get identifiersFields() {
1927
- return ['id'];
2115
+ class UserPaymentMethod extends BaseModel {
2116
+ static get identifiersFields() {
2117
+ return ['id', 'userId'];
1928
2118
  }
1929
2119
  }
1930
2120
 
1931
- class ProductForKit extends ProductBase {
2121
+ class Lead extends BaseModel {
1932
2122
  static get identifiersFields() {
1933
2123
  return ['id'];
1934
2124
  }
1935
- }
1936
- tslib_1.__decorate([
1937
- classTransformer.Type(() => CategoryForProduct),
1938
- tslib_1.__metadata("design:type", CategoryForProduct)
1939
- ], ProductForKit.prototype, "category", void 0);
1940
-
1941
- class KitProduct extends BaseModel {
1942
- static get identifiersFields() {
1943
- return ['productId', 'kitProductId'];
1944
- }
1945
- }
1946
- tslib_1.__decorate([
1947
- classTransformer.Type(() => ProductForKit),
1948
- tslib_1.__metadata("design:type", ProductForKit)
1949
- ], KitProduct.prototype, "kit", void 0);
1950
- tslib_1.__decorate([
1951
- classTransformer.Type(() => ProductForKit),
1952
- tslib_1.__metadata("design:type", ProductForKit)
1953
- ], KitProduct.prototype, "product", void 0);
2125
+ }
1954
2126
 
1955
- class ProductForCategory extends ProductBase {
1956
- static get identifiersFields() {
1957
- return ['id'];
2127
+ class UnauthorizedError extends tsCustomError.CustomError {
2128
+ constructor(message) {
2129
+ super(message);
1958
2130
  }
1959
- }
1960
- tslib_1.__decorate([
1961
- classTransformer.Type(() => KitProduct),
1962
- tslib_1.__metadata("design:type", Array)
1963
- ], ProductForCategory.prototype, "kitProducts", void 0);
2131
+ }
1964
2132
 
1965
- class Category extends CategoryBase {
1966
- static get identifiersFields() {
1967
- return ['id'];
2133
+ exports.SignInMethods = void 0;
2134
+ (function (SignInMethods) {
2135
+ SignInMethods["EMAIL_PASSWORD"] = "email_password";
2136
+ SignInMethods["GOOGLE"] = "google";
2137
+ })(exports.SignInMethods || (exports.SignInMethods = {}));
2138
+ class Authentication {
2139
+ constructor(authService, userRepository) {
2140
+ this.authService = authService;
2141
+ this.userRepository = userRepository;
1968
2142
  }
1969
- }
1970
- tslib_1.__decorate([
1971
- classTransformer.Type(() => ProductForCategory),
1972
- tslib_1.__metadata("design:type", Array)
1973
- ], Category.prototype, "childrenProducts", void 0);
1974
-
1975
- class CategoryCollectionChildren extends BaseModel {
1976
- static get identifiersFields() {
1977
- return ['collectionId', 'categoryId'];
2143
+ async signIn({ email, password }, signInMethod) {
2144
+ const method = this.getServiceByMethod(signInMethod);
2145
+ const userAuth = await this.authService[method]({ email, password });
2146
+ const user = this.userRepository.get({ id: userAuth.id });
2147
+ if (!lodash.isNil(user))
2148
+ return user;
2149
+ if (/^.+@b4a.com.br$/.test(userAuth.email))
2150
+ return this.createsUserByCredential(userAuth);
2151
+ throw new UnauthorizedError('Invalid credentials');
1978
2152
  }
1979
- }
1980
- tslib_1.__decorate([
1981
- classTransformer.Type(() => CategoryCollectionChildren),
1982
- tslib_1.__metadata("design:type", CategoryCollectionChildren)
1983
- ], CategoryCollectionChildren.prototype, "parent", void 0);
1984
-
1985
- class CategoryFilter extends BaseModel {
1986
- static get identifiersFields() {
1987
- return ['id'];
2153
+ getServiceByMethod(signInMethod) {
2154
+ return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
1988
2155
  }
1989
- }
1990
- tslib_1.__decorate([
1991
- classTransformer.Type(() => Filter),
1992
- tslib_1.__metadata("design:type", Filter)
1993
- ], CategoryFilter.prototype, "filter", void 0);
1994
- tslib_1.__decorate([
1995
- classTransformer.Type(() => Category),
1996
- tslib_1.__metadata("design:type", Category)
1997
- ], CategoryFilter.prototype, "category", void 0);
1998
-
1999
- exports.GenderDestination = void 0;
2000
- (function (GenderDestination) {
2001
- GenderDestination["FEMALE"] = "female";
2002
- GenderDestination["MALE"] = "male";
2003
- GenderDestination["UNISEX"] = "unisex";
2004
- })(exports.GenderDestination || (exports.GenderDestination = {}));
2005
-
2006
- exports.Shops = void 0;
2007
- (function (Shops) {
2008
- Shops["MENSMARKET"] = "mensmarket";
2009
- Shops["GLAMSHOP"] = "Glamshop";
2010
- Shops["GLAMPOINTS"] = "Glampoints";
2011
- Shops["ALL"] = "ALL";
2012
- })(exports.Shops || (exports.Shops = {}));
2013
-
2014
- class FilterOption extends BaseModel {
2015
- static get identifiersFields() {
2016
- return ['id'];
2156
+ async createsUserByCredential(user) {
2157
+ var _a;
2158
+ const [firstName, lastName] = (_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/);
2159
+ const person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName,
2160
+ lastName, acceptsNewsletter: false, area: exports.Area.Transactional, officePosition: exports.OfficePosition.Intern, type: exports.UserType.Collaborator }));
2161
+ return this.userRepository.create(person);
2017
2162
  }
2018
2163
  }
2019
2164
 
2020
- class Product extends ProductBase {
2021
- static get identifiersFields() {
2022
- return ['id'];
2023
- }
2024
- }
2025
- tslib_1.__decorate([
2026
- classTransformer.Type(() => CategoryForProduct),
2027
- tslib_1.__metadata("design:type", CategoryForProduct)
2028
- ], Product.prototype, "category", void 0);
2029
- tslib_1.__decorate([
2030
- classTransformer.Type(() => KitProduct),
2031
- tslib_1.__metadata("design:type", Array)
2032
- ], Product.prototype, "kitProducts", void 0);
2033
-
2034
- class ProductReviews extends BaseModel {
2035
- static get identifiersFields() {
2036
- return ['id'];
2165
+ class UserAlreadyRegisteredError extends tsCustomError.CustomError {
2166
+ constructor(message) {
2167
+ super(message);
2037
2168
  }
2038
2169
  }
2039
2170
 
2040
- class Variant extends BaseModel {
2041
- static get identifiersFields() {
2042
- return ['id', 'productId'];
2171
+ class WeakPasswordError extends tsCustomError.CustomError {
2172
+ constructor(message = 'Weak password') {
2173
+ super(message);
2043
2174
  }
2044
2175
  }
2045
2176
 
2046
- class Wishlist extends Category {
2047
- static get identifiersFields() {
2048
- return ['id'];
2177
+ class Register {
2178
+ constructor(registerService, userRepository) {
2179
+ this.registerService = registerService;
2180
+ this.userRepository = userRepository;
2181
+ }
2182
+ async register(params) {
2183
+ const email = params.email.toLocaleLowerCase();
2184
+ const displayName = `${params.firstName} ${params.lastName}`;
2185
+ if (await this.userRepository.checkIfExistsByField('cpf', params.cpf))
2186
+ throw new UserAlreadyRegisteredError(`Usuário com CPF ${params.cpf} já registrado.`);
2187
+ if (await this.userRepository.checkIfExistsByField('email', params.email))
2188
+ throw new UserAlreadyRegisteredError(`Usuário com e-mail ${params.email} já registrado.`);
2189
+ const auth = await this.registerService.register({
2190
+ birthday: params.birthday,
2191
+ email,
2192
+ firstName: params.firstName,
2193
+ lastName: params.lastName,
2194
+ cpf: params.cpf,
2195
+ displayName,
2196
+ phone: params.phone,
2197
+ password: params.password,
2198
+ });
2199
+ delete params.password;
2200
+ const user = await this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email,
2201
+ displayName, type: exports.UserType.B2C, dateCreated: new Date(), dateModified: new Date() }));
2202
+ return user;
2049
2203
  }
2050
2204
  }
2051
2205
 
2052
- class Buy2Win extends BaseModel {
2053
- static get identifiersFields() {
2054
- return ['id'];
2206
+ class SignOut {
2207
+ constructor(authService) {
2208
+ this.authService = authService;
2055
2209
  }
2056
- }
2057
- tslib_1.__decorate([
2058
- classTransformer.Type(() => Category),
2059
- tslib_1.__metadata("design:type", Array)
2060
- ], Buy2Win.prototype, "categories", void 0);
2061
-
2062
- class CampaignDashboard extends BaseModel {
2063
- static get identifiersFields() {
2064
- return ['id'];
2210
+ async signOut() {
2211
+ await this.authService.signOut();
2065
2212
  }
2066
2213
  }
2067
2214
 
2068
- class CampaignHashtag extends BaseModel {
2069
- static get identifiersFields() {
2070
- return ['id'];
2215
+ class RecoveryPassword {
2216
+ constructor(authService) {
2217
+ this.authService = authService;
2218
+ }
2219
+ async sendEmail(email) {
2220
+ await this.authService.sendPasswordResetEmail(email);
2071
2221
  }
2072
2222
  }
2073
2223
 
@@ -2151,155 +2301,6 @@ tslib_1.__decorate([
2151
2301
  tslib_1.__metadata("design:type", Coupon)
2152
2302
  ], CheckoutSubscription.prototype, "coupon", void 0);
2153
2303
 
2154
- class SubscriptionMaterialization extends BaseModel {
2155
- static get identifiersFields() {
2156
- return ['id'];
2157
- }
2158
- }
2159
- tslib_1.__decorate([
2160
- classTransformer.Type(() => User),
2161
- tslib_1.__metadata("design:type", User)
2162
- ], SubscriptionMaterialization.prototype, "user", void 0);
2163
- tslib_1.__decorate([
2164
- classTransformer.Type(() => SubscriptionPlan),
2165
- tslib_1.__metadata("design:type", SubscriptionPlan)
2166
- ], SubscriptionMaterialization.prototype, "subscriptionPlan", void 0);
2167
- tslib_1.__decorate([
2168
- classTransformer.Type(() => UserAddress),
2169
- tslib_1.__metadata("design:type", UserAddress)
2170
- ], SubscriptionMaterialization.prototype, "shippingAddress", void 0);
2171
- tslib_1.__decorate([
2172
- classTransformer.Type(() => UserAddress),
2173
- tslib_1.__metadata("design:type", UserAddress)
2174
- ], SubscriptionMaterialization.prototype, "billingAddress", void 0);
2175
- tslib_1.__decorate([
2176
- classTransformer.Type(() => Coupon),
2177
- tslib_1.__metadata("design:type", Coupon)
2178
- ], SubscriptionMaterialization.prototype, "coupon", void 0);
2179
- tslib_1.__decorate([
2180
- classTransformer.Type(() => Edition),
2181
- tslib_1.__metadata("design:type", Array)
2182
- ], SubscriptionMaterialization.prototype, "editions", void 0);
2183
- tslib_1.__decorate([
2184
- classTransformer.Type(() => SubscriptionPayment),
2185
- tslib_1.__metadata("design:type", SubscriptionPayment)
2186
- ], SubscriptionMaterialization.prototype, "payment", void 0);
2187
-
2188
- class SubscriptionSummary extends BaseModel {
2189
- static get identifiersFields() {
2190
- return ['id'];
2191
- }
2192
- }
2193
-
2194
- class UserPaymentMethod extends BaseModel {
2195
- static get identifiersFields() {
2196
- return ['id', 'userId'];
2197
- }
2198
- }
2199
-
2200
- class Lead extends BaseModel {
2201
- static get identifiersFields() {
2202
- return ['id'];
2203
- }
2204
- }
2205
-
2206
- class UnauthorizedError extends tsCustomError.CustomError {
2207
- constructor(message) {
2208
- super(message);
2209
- }
2210
- }
2211
-
2212
- exports.SignInMethods = void 0;
2213
- (function (SignInMethods) {
2214
- SignInMethods["EMAIL_PASSWORD"] = "email_password";
2215
- SignInMethods["GOOGLE"] = "google";
2216
- })(exports.SignInMethods || (exports.SignInMethods = {}));
2217
- class Authentication {
2218
- constructor(authService, userRepository) {
2219
- this.authService = authService;
2220
- this.userRepository = userRepository;
2221
- }
2222
- async signIn({ email, password }, signInMethod) {
2223
- const method = this.getServiceByMethod(signInMethod);
2224
- const userAuth = await this.authService[method]({ email, password });
2225
- const user = this.userRepository.get({ id: userAuth.id });
2226
- if (!lodash.isNil(user))
2227
- return user;
2228
- if (/^.+@b4a.com.br$/.test(userAuth.email))
2229
- return this.createsUserByCredential(userAuth);
2230
- throw new UnauthorizedError('Invalid credentials');
2231
- }
2232
- getServiceByMethod(signInMethod) {
2233
- return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
2234
- }
2235
- async createsUserByCredential(user) {
2236
- var _a;
2237
- const [firstName, lastName] = (_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/);
2238
- const person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName,
2239
- lastName, acceptsNewsletter: false, area: exports.Area.Transactional, officePosition: exports.OfficePosition.Intern, type: exports.UserType.Collaborator }));
2240
- return this.userRepository.create(person);
2241
- }
2242
- }
2243
-
2244
- class UserAlreadyRegisteredError extends tsCustomError.CustomError {
2245
- constructor(message) {
2246
- super(message);
2247
- }
2248
- }
2249
-
2250
- class WeakPasswordError extends tsCustomError.CustomError {
2251
- constructor(message = 'Weak password') {
2252
- super(message);
2253
- }
2254
- }
2255
-
2256
- class Register {
2257
- constructor(registerService, userRepository) {
2258
- this.registerService = registerService;
2259
- this.userRepository = userRepository;
2260
- }
2261
- async register(params) {
2262
- const email = params.email.toLocaleLowerCase();
2263
- const displayName = `${params.firstName} ${params.lastName}`;
2264
- if (await this.userRepository.checkIfExistsByField('cpf', params.cpf))
2265
- throw new UserAlreadyRegisteredError(`Usuário com CPF ${params.cpf} já registrado.`);
2266
- if (await this.userRepository.checkIfExistsByField('email', params.email))
2267
- throw new UserAlreadyRegisteredError(`Usuário com e-mail ${params.email} já registrado.`);
2268
- const auth = await this.registerService.register({
2269
- birthday: params.birthday,
2270
- email,
2271
- firstName: params.firstName,
2272
- lastName: params.lastName,
2273
- cpf: params.cpf,
2274
- displayName,
2275
- phone: params.phone,
2276
- password: params.password,
2277
- });
2278
- delete params.password;
2279
- const user = await this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email,
2280
- displayName, type: exports.UserType.B2C, dateCreated: new Date(), dateModified: new Date() }));
2281
- return user;
2282
- }
2283
- }
2284
-
2285
- class SignOut {
2286
- constructor(authService) {
2287
- this.authService = authService;
2288
- }
2289
- async signOut() {
2290
- await this.authService.signOut();
2291
- }
2292
- }
2293
-
2294
- class RecoveryPassword {
2295
- constructor(authService) {
2296
- this.authService = authService;
2297
- }
2298
- async sendEmail(email) {
2299
- await this.authService.sendPasswordResetEmail(email);
2300
- }
2301
- }
2302
-
2303
2304
  class RoundProductPricesHelper {
2304
2305
  static roundProductPrices(product) {
2305
2306
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2633,6 +2634,75 @@ class ProductsIndex {
2633
2634
  }
2634
2635
  }
2635
2636
 
2637
+ class AuthenticationFirebaseAuthService {
2638
+ constructor(firebaseAuth) {
2639
+ this.firebaseAuth = firebaseAuth;
2640
+ }
2641
+ async signInWithEmailAndPassword(data) {
2642
+ const credentials = await auth.signInWithEmailAndPassword(this.firebaseAuth, data.email, data.password);
2643
+ const user = credentials.user;
2644
+ return {
2645
+ id: user.uid,
2646
+ displayName: user.displayName,
2647
+ email: user.email,
2648
+ phone: user.phoneNumber,
2649
+ isAnonymous: false,
2650
+ };
2651
+ }
2652
+ async signInWithGoogle() {
2653
+ const credentials = await auth.signInWithPopup(this.firebaseAuth, new auth.GoogleAuthProvider());
2654
+ const user = credentials.user;
2655
+ return {
2656
+ id: user.uid,
2657
+ displayName: user.displayName,
2658
+ email: user.email,
2659
+ phone: user.phoneNumber,
2660
+ isAnonymous: false,
2661
+ };
2662
+ }
2663
+ async signOut() {
2664
+ this.firebaseAuth.signOut();
2665
+ }
2666
+ async signInAnonymously() {
2667
+ const auth$1 = await auth.signInAnonymously(this.firebaseAuth);
2668
+ const user = auth$1.user;
2669
+ user.id = auth$1.user.uid;
2670
+ return user;
2671
+ }
2672
+ async sendPasswordResetEmail(email) {
2673
+ return auth.sendPasswordResetEmail(this.firebaseAuth, email);
2674
+ }
2675
+ }
2676
+
2677
+ class RegisterFirebaseAuthService {
2678
+ constructor(firebaseAuth) {
2679
+ this.firebaseAuth = firebaseAuth;
2680
+ }
2681
+ async register(params) {
2682
+ if (!params.email)
2683
+ throw new RequiredArgumentError(['email']);
2684
+ try {
2685
+ const auth$1 = await auth.createUserWithEmailAndPassword(this.firebaseAuth, params.email, params.password);
2686
+ const user = is(auth$1.user);
2687
+ if (!user)
2688
+ throw new Error('User not created');
2689
+ await auth.sendEmailVerification(user);
2690
+ user.id = user.uid;
2691
+ return user;
2692
+ }
2693
+ catch (error) {
2694
+ if (!(error instanceof Error))
2695
+ throw error;
2696
+ const firebaseError = error;
2697
+ if (firebaseError.code === 'auth/email-already-in-use')
2698
+ throw new UserAlreadyRegisteredError('Email already registered');
2699
+ if (firebaseError.code === 'auth/weak-password')
2700
+ throw new WeakPasswordError();
2701
+ throw error;
2702
+ }
2703
+ }
2704
+ }
2705
+
2636
2706
  const withFirestore = (MixinBase) => {
2637
2707
  const isObjectsAndNoDate = (data) => data &&
2638
2708
  !Array.isArray(data) &&
@@ -3503,72 +3573,14 @@ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(with
3503
3573
  }
3504
3574
  }
3505
3575
 
3506
- class AuthenticationFirebaseAuthService {
3507
- constructor(firebaseAuth) {
3508
- this.firebaseAuth = firebaseAuth;
3576
+ class FirebaseFileUploaderService {
3577
+ constructor(storage, baseUrl) {
3578
+ this.storage = storage;
3579
+ this.baseUrl = baseUrl;
3509
3580
  }
3510
- async signInWithEmailAndPassword(data) {
3511
- const credentials = await auth.signInWithEmailAndPassword(this.firebaseAuth, data.email, data.password);
3512
- const user = credentials.user;
3513
- return {
3514
- id: user.uid,
3515
- displayName: user.displayName,
3516
- email: user.email,
3517
- phone: user.phoneNumber,
3518
- isAnonymous: false,
3519
- };
3520
- }
3521
- async signInWithGoogle() {
3522
- const credentials = await auth.signInWithPopup(this.firebaseAuth, new auth.GoogleAuthProvider());
3523
- const user = credentials.user;
3524
- return {
3525
- id: user.uid,
3526
- displayName: user.displayName,
3527
- email: user.email,
3528
- phone: user.phoneNumber,
3529
- isAnonymous: false,
3530
- };
3531
- }
3532
- async signOut() {
3533
- this.firebaseAuth.signOut();
3534
- }
3535
- async signInAnonymously() {
3536
- const auth$1 = await auth.signInAnonymously(this.firebaseAuth);
3537
- const user = auth$1.user;
3538
- user.id = auth$1.user.uid;
3539
- return user;
3540
- }
3541
- async sendPasswordResetEmail(email) {
3542
- return auth.sendPasswordResetEmail(this.firebaseAuth, email);
3543
- }
3544
- }
3545
-
3546
- class RegisterFirebaseAuthService {
3547
- constructor(firebaseAuth) {
3548
- this.firebaseAuth = firebaseAuth;
3549
- }
3550
- async register(params) {
3551
- if (!params.email)
3552
- throw new RequiredArgumentError(['email']);
3553
- try {
3554
- const auth$1 = await auth.createUserWithEmailAndPassword(this.firebaseAuth, params.email, params.password);
3555
- const user = is(auth$1.user);
3556
- if (!user)
3557
- throw new Error('User not created');
3558
- await auth.sendEmailVerification(user);
3559
- user.id = user.uid;
3560
- return user;
3561
- }
3562
- catch (error) {
3563
- if (!(error instanceof Error))
3564
- throw error;
3565
- const firebaseError = error;
3566
- if (firebaseError.code === 'auth/email-already-in-use')
3567
- throw new UserAlreadyRegisteredError('Email already registered');
3568
- if (firebaseError.code === 'auth/weak-password')
3569
- throw new WeakPasswordError();
3570
- throw error;
3571
- }
3581
+ async upload(path, file) {
3582
+ const storageRef = storage.ref(this.storage, path);
3583
+ return storage.uploadBytes(storageRef, file).then((reference) => `${this.baseUrl}/${reference.ref.bucket}/${reference.ref.fullPath}`);
3572
3584
  }
3573
3585
  }
3574
3586
 
@@ -5795,6 +5807,7 @@ exports.Filter = Filter;
5795
5807
  exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
5796
5808
  exports.FilterOption = FilterOption;
5797
5809
  exports.FilterOptionHasuraGraphQLRepository = FilterOptionHasuraGraphQLRepository;
5810
+ exports.FirebaseFileUploaderService = FirebaseFileUploaderService;
5798
5811
  exports.Home = Home;
5799
5812
  exports.HomeFirestoreRepository = HomeFirestoreRepository;
5800
5813
  exports.InvalidArgumentError = InvalidArgumentError;