@infrab4a/connect 3.9.0-beta.1 → 3.9.0-beta.10
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 +150 -178
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/esm2015/infra/elasticsearch/adapters/axios.adapter.js +30 -11
- package/esm2015/infra/elasticsearch/adapters/elastic-search.adapter.js +2 -62
- package/esm2015/infra/elasticsearch/adapters/index.js +1 -2
- package/esm2015/infra/elasticsearch/indexes/products-index.js +84 -104
- package/fesm2015/infrab4a-connect.js +110 -171
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +5 -3
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +7 -21
- package/infra/elasticsearch/adapters/index.d.ts +0 -1
- package/infra/elasticsearch/indexes/products-index.d.ts +8 -9
- package/package.json +1 -2
|
@@ -7,7 +7,6 @@ import { isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoo
|
|
|
7
7
|
export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
|
|
8
8
|
import { CustomError } from 'ts-custom-error';
|
|
9
9
|
import axios from 'axios';
|
|
10
|
-
import { Client } from '@elastic/elasticsearch';
|
|
11
10
|
import firebase from 'firebase';
|
|
12
11
|
import { mutation, query } from 'gql-query-builder';
|
|
13
12
|
|
|
@@ -1081,13 +1080,17 @@ class AxiosAdapter {
|
|
|
1081
1080
|
constructor(config) {
|
|
1082
1081
|
this.config = config;
|
|
1083
1082
|
}
|
|
1084
|
-
get(index) {
|
|
1083
|
+
get(index, id) {
|
|
1085
1084
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1086
1085
|
try {
|
|
1087
1086
|
const { data } = yield axios({
|
|
1088
|
-
url: `${this.config.url}/${index}`,
|
|
1087
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1089
1088
|
method: 'GET',
|
|
1090
|
-
|
|
1089
|
+
responseType: 'json',
|
|
1090
|
+
headers: {
|
|
1091
|
+
'Content-Type': 'application/json',
|
|
1092
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
1093
|
+
},
|
|
1091
1094
|
});
|
|
1092
1095
|
return data._source;
|
|
1093
1096
|
}
|
|
@@ -1099,9 +1102,14 @@ class AxiosAdapter {
|
|
|
1099
1102
|
query(index, query) {
|
|
1100
1103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1101
1104
|
const { data } = yield axios({
|
|
1102
|
-
url: `${this.config.url}/${index}`,
|
|
1105
|
+
url: `${this.config.url}/${index}/_search`,
|
|
1103
1106
|
method: 'POST',
|
|
1104
|
-
|
|
1107
|
+
responseType: 'json',
|
|
1108
|
+
headers: {
|
|
1109
|
+
Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1110
|
+
'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1111
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
1112
|
+
},
|
|
1105
1113
|
data: query,
|
|
1106
1114
|
});
|
|
1107
1115
|
return {
|
|
@@ -1113,223 +1121,154 @@ class AxiosAdapter {
|
|
|
1113
1121
|
save(index, data) {
|
|
1114
1122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1115
1123
|
yield axios({
|
|
1116
|
-
url: `${this.config.url}/${index}`,
|
|
1117
|
-
method: '
|
|
1118
|
-
headers: { Authorization: `
|
|
1124
|
+
url: `${this.config.url}/${index}/_doc`,
|
|
1125
|
+
method: 'POST',
|
|
1126
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1119
1127
|
data,
|
|
1120
1128
|
});
|
|
1121
1129
|
});
|
|
1122
1130
|
}
|
|
1123
|
-
|
|
1131
|
+
update(index, id, data) {
|
|
1124
1132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1125
1133
|
yield axios({
|
|
1126
|
-
url: `${this.config.url}/${index}`,
|
|
1127
|
-
method: '
|
|
1128
|
-
headers: { Authorization: `
|
|
1134
|
+
url: `${this.config.url}/${index}/_update/${id}`,
|
|
1135
|
+
method: 'PUT',
|
|
1136
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1137
|
+
data,
|
|
1129
1138
|
});
|
|
1130
1139
|
});
|
|
1131
1140
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
class ElasticSearchAdapter {
|
|
1135
|
-
constructor(config) {
|
|
1136
|
-
this.client = new Client(config);
|
|
1137
|
-
}
|
|
1138
|
-
getById(index, id) {
|
|
1139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1140
|
-
try {
|
|
1141
|
-
const data = yield this.client.get({ index, id });
|
|
1142
|
-
return data._source;
|
|
1143
|
-
}
|
|
1144
|
-
catch (erro) {
|
|
1145
|
-
throw new NotFoundError(erro.message);
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1149
|
-
search(indice, query) {
|
|
1141
|
+
delete(index, id) {
|
|
1150
1142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1143
|
+
yield axios({
|
|
1144
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1145
|
+
method: 'DELETE',
|
|
1146
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1154
1147
|
});
|
|
1155
|
-
return {
|
|
1156
|
-
total: result.hits.total,
|
|
1157
|
-
hits: result.hits.hits,
|
|
1158
|
-
};
|
|
1159
1148
|
});
|
|
1160
1149
|
}
|
|
1161
|
-
save(index, data) {
|
|
1162
|
-
return this.client.index({
|
|
1163
|
-
index,
|
|
1164
|
-
document: data,
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
update(index, id, data) {
|
|
1168
|
-
try {
|
|
1169
|
-
return this.client.update({
|
|
1170
|
-
index,
|
|
1171
|
-
id,
|
|
1172
|
-
doc: data,
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
catch (error) {
|
|
1176
|
-
console.log(error);
|
|
1177
|
-
throw new Error(error.message);
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
delete(index, id) {
|
|
1181
|
-
try {
|
|
1182
|
-
this.client.delete({
|
|
1183
|
-
index,
|
|
1184
|
-
id,
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
catch (error) {
|
|
1188
|
-
console.log(error);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
1150
|
}
|
|
1192
1151
|
|
|
1193
1152
|
class ProductsIndex {
|
|
1194
|
-
constructor(
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
this.esadapter = esadapter;
|
|
1153
|
+
constructor(adapter) {
|
|
1154
|
+
this.adapter = adapter;
|
|
1155
|
+
this.index = `products`;
|
|
1198
1156
|
}
|
|
1199
|
-
|
|
1157
|
+
getById(id) {
|
|
1200
1158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1201
|
-
const data = yield this.
|
|
1202
|
-
// const data = await this.adapter.get(`products/_doc/${id}`)
|
|
1159
|
+
const data = yield this.adapter.get(this.index, id);
|
|
1203
1160
|
return Product.toInstance(data);
|
|
1204
1161
|
});
|
|
1205
1162
|
}
|
|
1206
|
-
|
|
1163
|
+
getByAlloyId(id) {
|
|
1207
1164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1165
|
+
const data = yield this.adapter.query(this.index, {
|
|
1166
|
+
query: {
|
|
1167
|
+
bool: {
|
|
1168
|
+
must: {
|
|
1169
|
+
match: {
|
|
1170
|
+
id: id,
|
|
1171
|
+
},
|
|
1215
1172
|
},
|
|
1216
1173
|
},
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1174
|
+
},
|
|
1175
|
+
});
|
|
1176
|
+
return Product.toInstance(data.hits[0]._source);
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
search(searchTerm, total, shop) {
|
|
1180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1181
|
+
const size = total >= 10 ? 500 : 9;
|
|
1182
|
+
const fields = [
|
|
1183
|
+
'EAN',
|
|
1184
|
+
'brand',
|
|
1185
|
+
'id',
|
|
1186
|
+
'images',
|
|
1187
|
+
'miniatures',
|
|
1188
|
+
'name',
|
|
1189
|
+
'price',
|
|
1190
|
+
'sku',
|
|
1191
|
+
'stock',
|
|
1192
|
+
'slug',
|
|
1193
|
+
'reviews',
|
|
1194
|
+
'hasVariants',
|
|
1195
|
+
'rate',
|
|
1196
|
+
];
|
|
1197
|
+
const filter = [{ term: { published: true } }];
|
|
1198
|
+
if (size > 9) {
|
|
1199
|
+
fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
|
|
1200
|
+
}
|
|
1201
|
+
else {
|
|
1202
|
+
filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
|
|
1203
|
+
}
|
|
1204
|
+
const search = yield this.adapter.query(this.index, {
|
|
1205
|
+
size,
|
|
1206
|
+
_source: fields,
|
|
1207
|
+
query: {
|
|
1208
|
+
bool: {
|
|
1209
|
+
must: {
|
|
1210
|
+
multi_match: {
|
|
1220
1211
|
query: `${searchTerm}`,
|
|
1221
|
-
|
|
1212
|
+
type: 'bool_prefix',
|
|
1213
|
+
fields: [
|
|
1214
|
+
'name',
|
|
1215
|
+
'name.folded',
|
|
1216
|
+
'name.search',
|
|
1217
|
+
'description',
|
|
1218
|
+
'description.search',
|
|
1219
|
+
'description.folded',
|
|
1220
|
+
'brand',
|
|
1221
|
+
'brand.search',
|
|
1222
|
+
'brand.folded',
|
|
1223
|
+
],
|
|
1224
|
+
fuzziness: 2,
|
|
1225
|
+
},
|
|
1226
|
+
},
|
|
1227
|
+
should: {
|
|
1228
|
+
match_phrase_prefix: {
|
|
1229
|
+
'name.search': {
|
|
1230
|
+
query: `${searchTerm}`,
|
|
1231
|
+
slop: 10,
|
|
1232
|
+
},
|
|
1222
1233
|
},
|
|
1223
1234
|
},
|
|
1235
|
+
filter,
|
|
1224
1236
|
},
|
|
1225
|
-
filter: [{ term: { published: true } }],
|
|
1226
1237
|
},
|
|
1227
1238
|
});
|
|
1228
|
-
search.hits.forEach((row) => {
|
|
1229
|
-
row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
|
|
1230
|
-
});
|
|
1231
1239
|
search.hits = search.hits.filter((e) => e._source.name !== '');
|
|
1232
1240
|
return search;
|
|
1233
1241
|
});
|
|
1234
1242
|
}
|
|
1235
|
-
// async findById(ids: string[], options?: { hasStock: boolean; size: number; shop: Shops }): Promise<Product[]> {
|
|
1236
|
-
// const fields = [
|
|
1237
|
-
// 'brand',
|
|
1238
|
-
// 'id',
|
|
1239
|
-
// 'images',
|
|
1240
|
-
// 'miniatures',
|
|
1241
|
-
// 'name',
|
|
1242
|
-
// 'price',
|
|
1243
|
-
// 'sku',
|
|
1244
|
-
// 'stock',
|
|
1245
|
-
// 'slug',
|
|
1246
|
-
// 'reviews',
|
|
1247
|
-
// 'pricePaid',
|
|
1248
|
-
// 'isGift',
|
|
1249
|
-
// 'stock',
|
|
1250
|
-
// 'weight',
|
|
1251
|
-
// 'tags',
|
|
1252
|
-
// 'filters',
|
|
1253
|
-
// 'hasVariants',
|
|
1254
|
-
// 'type',
|
|
1255
|
-
// ]
|
|
1256
|
-
// const { hits } = await this.adapter.query('products/_search', {
|
|
1257
|
-
// _source: fields,
|
|
1258
|
-
// query: {
|
|
1259
|
-
// bool: {
|
|
1260
|
-
// filter: [
|
|
1261
|
-
// {
|
|
1262
|
-
// terms: {
|
|
1263
|
-
// _id: ids,
|
|
1264
|
-
// },
|
|
1265
|
-
// },
|
|
1266
|
-
// {
|
|
1267
|
-
// term: {
|
|
1268
|
-
// published: true,
|
|
1269
|
-
// },
|
|
1270
|
-
// },
|
|
1271
|
-
// ...(options.hasStock
|
|
1272
|
-
// ? [
|
|
1273
|
-
// {
|
|
1274
|
-
// range: {
|
|
1275
|
-
// 'stock.quantity': {
|
|
1276
|
-
// gt: 0,
|
|
1277
|
-
// },
|
|
1278
|
-
// },
|
|
1279
|
-
// },
|
|
1280
|
-
// ]
|
|
1281
|
-
// : []),
|
|
1282
|
-
// ],
|
|
1283
|
-
// },
|
|
1284
|
-
// },
|
|
1285
|
-
// ...(options.size ? { size: options.size } : {}),
|
|
1286
|
-
// })
|
|
1287
|
-
// return hits.map((hit) => Product.toInstance(hit._source))
|
|
1288
|
-
// }
|
|
1289
1243
|
save(product) {
|
|
1290
1244
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1291
1245
|
try {
|
|
1292
1246
|
const { createdAt, updatedAt, kitProducts } = product, data = __rest(product, ["createdAt", "updatedAt", "kitProducts"]);
|
|
1293
|
-
this.
|
|
1247
|
+
this.adapter.save(this.index, data);
|
|
1294
1248
|
}
|
|
1295
1249
|
catch (error) {
|
|
1296
1250
|
console.error(error);
|
|
1297
1251
|
}
|
|
1298
|
-
// delete product.createdAt
|
|
1299
|
-
// delete product.updatedAt
|
|
1300
|
-
// delete product.kitProducts
|
|
1301
|
-
// try {
|
|
1302
|
-
// if (!product.firestoreId) throw new Error('Is not a product from firestore')
|
|
1303
|
-
// await this.get(product.firestoreId)
|
|
1304
|
-
// await this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain())
|
|
1305
|
-
// } catch (error) {
|
|
1306
|
-
// console.error(error.message)
|
|
1307
|
-
// await this.adapter.save(`products/_doc/${product.id}`, product.toPlain())
|
|
1308
|
-
// }
|
|
1309
1252
|
});
|
|
1310
1253
|
}
|
|
1311
1254
|
update(product) {
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1256
|
+
try {
|
|
1257
|
+
yield this.adapter.update(this.index, product.id, product);
|
|
1258
|
+
}
|
|
1259
|
+
catch (error) {
|
|
1260
|
+
console.error(error);
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1318
1263
|
}
|
|
1319
1264
|
delete(id) {
|
|
1320
1265
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1321
1266
|
try {
|
|
1322
|
-
this.
|
|
1267
|
+
yield this.adapter.delete(this.index, id);
|
|
1323
1268
|
}
|
|
1324
1269
|
catch (error) {
|
|
1325
1270
|
console.error(error);
|
|
1326
1271
|
}
|
|
1327
|
-
// try {
|
|
1328
|
-
// await this.get(product.firestoreId)
|
|
1329
|
-
// await this.adapter.delete(`products/_doc/${product.firestoreId}`)
|
|
1330
|
-
// } catch (error) {
|
|
1331
|
-
// await this.adapter.delete(`products/_doc/${product.id}`)
|
|
1332
|
-
// }
|
|
1333
1272
|
});
|
|
1334
1273
|
}
|
|
1335
1274
|
}
|
|
@@ -3771,5 +3710,5 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3771
3710
|
* Generated bundle index. Do not edit.
|
|
3772
3711
|
*/
|
|
3773
3712
|
|
|
3774
|
-
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus,
|
|
3713
|
+
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, 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, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
|
3775
3714
|
//# sourceMappingURL=infrab4a-connect.js.map
|