@infrab4a/connect 3.9.0-beta.10 → 3.9.0-beta.2
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 +135 -145
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/esm2015/infra/elasticsearch/adapters/axios.adapter.js +7 -26
- package/esm2015/infra/elasticsearch/adapters/index.js +2 -1
- package/esm2015/infra/elasticsearch/indexes/products-index.js +117 -79
- package/fesm2015/infrab4a-connect.js +122 -101
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +2 -4
- package/infra/elasticsearch/indexes/products-index.d.ts +3 -5
- package/package.json +1 -1
- package/esm2015/infra/elasticsearch/adapters/elastic-search.adapter.js +0 -2
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +0 -8
|
@@ -1086,11 +1086,7 @@ class AxiosAdapter {
|
|
|
1086
1086
|
const { data } = yield axios({
|
|
1087
1087
|
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1088
1088
|
method: 'GET',
|
|
1089
|
-
|
|
1090
|
-
headers: {
|
|
1091
|
-
'Content-Type': 'application/json',
|
|
1092
|
-
Authorization: `ApiKey ${this.config.credential}`,
|
|
1093
|
-
},
|
|
1089
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1094
1090
|
});
|
|
1095
1091
|
return data._source;
|
|
1096
1092
|
}
|
|
@@ -1103,13 +1099,8 @@ class AxiosAdapter {
|
|
|
1103
1099
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1104
1100
|
const { data } = yield axios({
|
|
1105
1101
|
url: `${this.config.url}/${index}/_search`,
|
|
1106
|
-
method: '
|
|
1107
|
-
|
|
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
|
-
},
|
|
1102
|
+
method: 'GET',
|
|
1103
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1113
1104
|
data: query,
|
|
1114
1105
|
});
|
|
1115
1106
|
return {
|
|
@@ -1121,27 +1112,17 @@ class AxiosAdapter {
|
|
|
1121
1112
|
save(index, data) {
|
|
1122
1113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1123
1114
|
yield axios({
|
|
1124
|
-
url: `${this.config.url}/${index}
|
|
1125
|
-
method: 'POST',
|
|
1126
|
-
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1127
|
-
data,
|
|
1128
|
-
});
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
update(index, id, data) {
|
|
1132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1133
|
-
yield axios({
|
|
1134
|
-
url: `${this.config.url}/${index}/_update/${id}`,
|
|
1115
|
+
url: `${this.config.url}/${index}`,
|
|
1135
1116
|
method: 'PUT',
|
|
1136
1117
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1137
1118
|
data,
|
|
1138
1119
|
});
|
|
1139
1120
|
});
|
|
1140
1121
|
}
|
|
1141
|
-
delete(index
|
|
1122
|
+
delete(index) {
|
|
1142
1123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1143
1124
|
yield axios({
|
|
1144
|
-
url: `${this.config.url}/${index}
|
|
1125
|
+
url: `${this.config.url}/${index}`,
|
|
1145
1126
|
method: 'DELETE',
|
|
1146
1127
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1147
1128
|
});
|
|
@@ -1149,78 +1130,27 @@ class AxiosAdapter {
|
|
|
1149
1130
|
}
|
|
1150
1131
|
}
|
|
1151
1132
|
|
|
1133
|
+
// export * from './elastic-search.adapter'
|
|
1134
|
+
|
|
1152
1135
|
class ProductsIndex {
|
|
1153
1136
|
constructor(adapter) {
|
|
1154
1137
|
this.adapter = adapter;
|
|
1155
|
-
this.index = `products`;
|
|
1156
1138
|
}
|
|
1157
|
-
|
|
1139
|
+
get(id) {
|
|
1158
1140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1159
|
-
const data = yield this.adapter.get(
|
|
1141
|
+
const data = yield this.adapter.get('products', id);
|
|
1160
1142
|
return Product.toInstance(data);
|
|
1161
1143
|
});
|
|
1162
1144
|
}
|
|
1163
|
-
|
|
1145
|
+
search(searchTerm) {
|
|
1164
1146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1165
|
-
const
|
|
1166
|
-
query: {
|
|
1167
|
-
bool: {
|
|
1168
|
-
must: {
|
|
1169
|
-
match: {
|
|
1170
|
-
id: id,
|
|
1171
|
-
},
|
|
1172
|
-
},
|
|
1173
|
-
},
|
|
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,
|
|
1147
|
+
const search = yield this.adapter.query('products', {
|
|
1207
1148
|
query: {
|
|
1208
1149
|
bool: {
|
|
1209
1150
|
must: {
|
|
1210
1151
|
multi_match: {
|
|
1211
1152
|
query: `${searchTerm}`,
|
|
1212
|
-
|
|
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
|
-
],
|
|
1153
|
+
fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
|
|
1224
1154
|
fuzziness: 2,
|
|
1225
1155
|
},
|
|
1226
1156
|
},
|
|
@@ -1232,43 +1162,134 @@ class ProductsIndex {
|
|
|
1232
1162
|
},
|
|
1233
1163
|
},
|
|
1234
1164
|
},
|
|
1235
|
-
filter,
|
|
1165
|
+
filter: [{ term: { published: true } }],
|
|
1236
1166
|
},
|
|
1237
1167
|
},
|
|
1238
1168
|
});
|
|
1169
|
+
// const search = await this.esadapter.search(`products`, {
|
|
1170
|
+
// bool: {
|
|
1171
|
+
// must: {
|
|
1172
|
+
// multi_match: {
|
|
1173
|
+
// query: `${searchTerm}`,
|
|
1174
|
+
// fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
|
|
1175
|
+
// fuzziness: 2,
|
|
1176
|
+
// },
|
|
1177
|
+
// },
|
|
1178
|
+
// should: {
|
|
1179
|
+
// match_phrase_prefix: {
|
|
1180
|
+
// 'name.search': {
|
|
1181
|
+
// query: `${searchTerm}`,
|
|
1182
|
+
// slop: 10,
|
|
1183
|
+
// },
|
|
1184
|
+
// },
|
|
1185
|
+
// },
|
|
1186
|
+
// filter: [{ term: { published: true } }],
|
|
1187
|
+
// },
|
|
1188
|
+
// })
|
|
1189
|
+
search.hits.forEach((row) => {
|
|
1190
|
+
row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
|
|
1191
|
+
});
|
|
1239
1192
|
search.hits = search.hits.filter((e) => e._source.name !== '');
|
|
1240
1193
|
return search;
|
|
1241
1194
|
});
|
|
1242
1195
|
}
|
|
1196
|
+
// async findById(ids: string[], options?: { hasStock: boolean; size: number; shop: Shops }): Promise<Product[]> {
|
|
1197
|
+
// const fields = [
|
|
1198
|
+
// 'brand',
|
|
1199
|
+
// 'id',
|
|
1200
|
+
// 'images',
|
|
1201
|
+
// 'miniatures',
|
|
1202
|
+
// 'name',
|
|
1203
|
+
// 'price',
|
|
1204
|
+
// 'sku',
|
|
1205
|
+
// 'stock',
|
|
1206
|
+
// 'slug',
|
|
1207
|
+
// 'reviews',
|
|
1208
|
+
// 'pricePaid',
|
|
1209
|
+
// 'isGift',
|
|
1210
|
+
// 'stock',
|
|
1211
|
+
// 'weight',
|
|
1212
|
+
// 'tags',
|
|
1213
|
+
// 'filters',
|
|
1214
|
+
// 'hasVariants',
|
|
1215
|
+
// 'type',
|
|
1216
|
+
// ]
|
|
1217
|
+
// const { hits } = await this.adapter.query('products/_search', {
|
|
1218
|
+
// _source: fields,
|
|
1219
|
+
// query: {
|
|
1220
|
+
// bool: {
|
|
1221
|
+
// filter: [
|
|
1222
|
+
// {
|
|
1223
|
+
// terms: {
|
|
1224
|
+
// _id: ids,
|
|
1225
|
+
// },
|
|
1226
|
+
// },
|
|
1227
|
+
// {
|
|
1228
|
+
// term: {
|
|
1229
|
+
// published: true,
|
|
1230
|
+
// },
|
|
1231
|
+
// },
|
|
1232
|
+
// ...(options.hasStock
|
|
1233
|
+
// ? [
|
|
1234
|
+
// {
|
|
1235
|
+
// range: {
|
|
1236
|
+
// 'stock.quantity': {
|
|
1237
|
+
// gt: 0,
|
|
1238
|
+
// },
|
|
1239
|
+
// },
|
|
1240
|
+
// },
|
|
1241
|
+
// ]
|
|
1242
|
+
// : []),
|
|
1243
|
+
// ],
|
|
1244
|
+
// },
|
|
1245
|
+
// },
|
|
1246
|
+
// ...(options.size ? { size: options.size } : {}),
|
|
1247
|
+
// })
|
|
1248
|
+
// return hits.map((hit) => Product.toInstance(hit._source))
|
|
1249
|
+
// }
|
|
1243
1250
|
save(product) {
|
|
1244
1251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1252
|
+
// try {
|
|
1253
|
+
// const { createdAt, updatedAt, kitProducts, ...data } = product
|
|
1254
|
+
// this.esadapter.save(`product`, data)
|
|
1255
|
+
// } catch (error) {
|
|
1256
|
+
// console.error(error)
|
|
1257
|
+
// }
|
|
1258
|
+
delete product.createdAt;
|
|
1259
|
+
delete product.updatedAt;
|
|
1260
|
+
delete product.kitProducts;
|
|
1245
1261
|
try {
|
|
1246
|
-
|
|
1247
|
-
|
|
1262
|
+
if (!product.firestoreId)
|
|
1263
|
+
throw new Error('Is not a product from firestore');
|
|
1264
|
+
yield this.get(product.firestoreId);
|
|
1265
|
+
yield this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
|
|
1248
1266
|
}
|
|
1249
1267
|
catch (error) {
|
|
1250
|
-
console.error(error);
|
|
1268
|
+
console.error(error.message);
|
|
1269
|
+
yield this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
|
|
1251
1270
|
}
|
|
1252
1271
|
});
|
|
1253
1272
|
}
|
|
1254
1273
|
update(product) {
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
console.error(error);
|
|
1261
|
-
}
|
|
1262
|
-
});
|
|
1274
|
+
// try {
|
|
1275
|
+
// this.esadapter.update(`products`, product.id, product)
|
|
1276
|
+
// } catch (error) {
|
|
1277
|
+
// console.error(error)
|
|
1278
|
+
// }
|
|
1263
1279
|
}
|
|
1264
1280
|
delete(id) {
|
|
1265
1281
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1266
|
-
try {
|
|
1267
|
-
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1282
|
+
// try {
|
|
1283
|
+
// this.esadapter.delete(`products`, id)
|
|
1284
|
+
// } catch (error) {
|
|
1285
|
+
// console.error(error)
|
|
1286
|
+
// }
|
|
1287
|
+
// try {
|
|
1288
|
+
// await this.get(product.firestoreId)
|
|
1289
|
+
// await this.adapter.delete(`products/_doc/${product.firestoreId}`)
|
|
1290
|
+
// } catch (error) {
|
|
1291
|
+
// await this.adapter.delete(`products/_doc/${product.id}`)
|
|
1292
|
+
// }
|
|
1272
1293
|
});
|
|
1273
1294
|
}
|
|
1274
1295
|
}
|