@daffodil/product 0.94.1 → 0.95.0
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/fesm2022/daffodil-product-driver-in-memory.mjs +200 -227
- package/fesm2022/daffodil-product-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-product-driver-magento-2.4.7-testing.mjs +444 -0
- package/fesm2022/daffodil-product-driver-magento-2.4.7-testing.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-magento-2.4.7.mjs +704 -0
- package/fesm2022/daffodil-product-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-magento-auto-testing.mjs +7 -0
- package/fesm2022/daffodil-product-driver-magento-auto-testing.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-product-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-shopify.mjs +99 -127
- package/fesm2022/daffodil-product-driver-shopify.mjs.map +1 -1
- package/fesm2022/daffodil-product-driver-testing.mjs +117 -87
- package/fesm2022/daffodil-product-driver-testing.mjs.map +1 -1
- package/fesm2022/daffodil-product-driver.mjs +22 -45
- package/fesm2022/daffodil-product-driver.mjs.map +1 -1
- package/fesm2022/daffodil-product-routing.mjs +347 -285
- package/fesm2022/daffodil-product-routing.mjs.map +1 -1
- package/fesm2022/daffodil-product-state-testing.mjs +189 -106
- package/fesm2022/daffodil-product-state-testing.mjs.map +1 -1
- package/fesm2022/daffodil-product-state.mjs +566 -659
- package/fesm2022/daffodil-product-state.mjs.map +1 -1
- package/fesm2022/daffodil-product-testing.mjs +316 -276
- package/fesm2022/daffodil-product-testing.mjs.map +1 -1
- package/fesm2022/daffodil-product.mjs +8 -29
- package/fesm2022/daffodil-product.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-product-driver-in-memory.d.ts +65 -75
- package/types/daffodil-product-driver-magento-2.4.7-testing.d.ts +105 -0
- package/types/daffodil-product-driver-magento-2.4.7.d.ts +337 -0
- package/types/daffodil-product-driver-magento-auto-testing.d.ts +1 -0
- package/types/daffodil-product-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-product-driver-shopify.d.ts +31 -43
- package/types/daffodil-product-driver-testing.d.ts +28 -26
- package/types/daffodil-product-driver.d.ts +50 -61
- package/types/daffodil-product-routing.d.ts +101 -110
- package/types/daffodil-product-state-testing.d.ts +45 -43
- package/types/daffodil-product-state.d.ts +347 -375
- package/types/daffodil-product-testing.d.ts +82 -89
- package/types/daffodil-product.d.ts +93 -102
- package/fesm2022/daffodil-product-driver-magento-testing.mjs +0 -275
- package/fesm2022/daffodil-product-driver-magento-testing.mjs.map +0 -1
- package/fesm2022/daffodil-product-driver-magento.mjs +0 -855
- package/fesm2022/daffodil-product-driver-magento.mjs.map +0 -1
- package/types/daffodil-product-driver-magento-testing.d.ts +0 -114
- package/types/daffodil-product-driver-magento.d.ts +0 -396
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, inject, Inject, NgModule } from '@angular/core';
|
|
3
|
-
import * as i1 from 'apollo-angular';
|
|
4
|
-
import { gql } from 'apollo-angular';
|
|
5
|
-
import { map } from 'rxjs/operators';
|
|
6
|
-
import { daffUriTruncateQueryFragment } from '@daffodil/core/routing';
|
|
7
|
-
import { createMultiInjectionToken, DaffFilterType, createSingleInjectionToken, DaffSortDirectionEnum, daffFilterArrayToDict, createConfigInjectionToken } from '@daffodil/core';
|
|
8
|
-
import { DaffProductTypeEnum } from '@daffodil/product';
|
|
9
|
-
import { daffBuildFragmentNameSpread, daffBuildFragmentDefinition } from '@daffodil/core/graphql';
|
|
10
|
-
import { DaffProductInvalidAPIResponseError, provideDaffProductDriver } from '@daffodil/product/driver';
|
|
11
|
-
import { CommonModule } from '@angular/common';
|
|
12
|
-
import { provideManyDaffMagentoCacheableOperations } from '@daffodil/driver/magento';
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
/**
|
|
16
|
-
* A multi-provider injection token for providing extra transform logic in the Product Magento driver.
|
|
17
|
-
* It is run after the standard transforms and passed both the current transformed Daffodil response and the Magento product response.
|
|
18
|
-
*/
|
|
19
|
-
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_RESPONSE_TRANSFORMS,
|
|
20
|
-
/**
|
|
21
|
-
* Provides extra product transforms for the Magento product driver.
|
|
22
|
-
*
|
|
23
|
-
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_RESPONSE_TRANSFORMS}.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* providers: [
|
|
28
|
-
* ...provideDaffProductMagentoExtraProductResponseTransforms(
|
|
29
|
-
* myExtraProductTransform
|
|
30
|
-
* )
|
|
31
|
-
* ]
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
provider: provideDaffProductMagentoExtraProductResponseTransforms, } = createMultiInjectionToken('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_RESPONSE_TRANSFORMS');
|
|
35
|
-
|
|
36
|
-
var MagentoProductTypeEnum;
|
|
37
|
-
(function (MagentoProductTypeEnum) {
|
|
38
|
-
MagentoProductTypeEnum["BundledProduct"] = "BundleProduct";
|
|
39
|
-
MagentoProductTypeEnum["ConfigurableProduct"] = "ConfigurableProduct";
|
|
40
|
-
MagentoProductTypeEnum["SimpleProduct"] = "SimpleProduct";
|
|
41
|
-
})(MagentoProductTypeEnum || (MagentoProductTypeEnum = {}));
|
|
42
|
-
|
|
43
|
-
var MagentoProductStockStatusEnum;
|
|
44
|
-
(function (MagentoProductStockStatusEnum) {
|
|
45
|
-
MagentoProductStockStatusEnum["InStock"] = "IN_STOCK";
|
|
46
|
-
MagentoProductStockStatusEnum["OutOfStock"] = "OUT_OF_STOCK";
|
|
47
|
-
})(MagentoProductStockStatusEnum || (MagentoProductStockStatusEnum = {}));
|
|
48
|
-
|
|
49
|
-
var MagentoProductFilterActionEnum;
|
|
50
|
-
(function (MagentoProductFilterActionEnum) {
|
|
51
|
-
MagentoProductFilterActionEnum["Equal"] = "eq";
|
|
52
|
-
MagentoProductFilterActionEnum["To"] = "to";
|
|
53
|
-
MagentoProductFilterActionEnum["From"] = "from";
|
|
54
|
-
MagentoProductFilterActionEnum["In"] = "in";
|
|
55
|
-
MagentoProductFilterActionEnum["Match"] = "match";
|
|
56
|
-
})(MagentoProductFilterActionEnum || (MagentoProductFilterActionEnum = {}));
|
|
57
|
-
|
|
58
|
-
var MagentoProductFilterType;
|
|
59
|
-
(function (MagentoProductFilterType) {
|
|
60
|
-
MagentoProductFilterType["Equal"] = "FilterEqualTypeInput";
|
|
61
|
-
MagentoProductFilterType["Match"] = "FilterMatchTypeInput";
|
|
62
|
-
MagentoProductFilterType["Range"] = "FilterRangeTypeInput";
|
|
63
|
-
})(MagentoProductFilterType || (MagentoProductFilterType = {}));
|
|
64
|
-
|
|
65
|
-
var MagentoSortDirectionEnum;
|
|
66
|
-
(function (MagentoSortDirectionEnum) {
|
|
67
|
-
MagentoSortDirectionEnum["Ascending"] = "ASC";
|
|
68
|
-
MagentoSortDirectionEnum["Decending"] = "DESC";
|
|
69
|
-
})(MagentoSortDirectionEnum || (MagentoSortDirectionEnum = {}));
|
|
70
|
-
|
|
71
|
-
class MagentoProductAppliedFiltersTransformService {
|
|
72
|
-
transform(daffFilters) {
|
|
73
|
-
const magentoFilters = {};
|
|
74
|
-
if (!daffFilters) {
|
|
75
|
-
return magentoFilters;
|
|
76
|
-
}
|
|
77
|
-
daffFilters.forEach(filter => {
|
|
78
|
-
// The FromTo filter needs special treatment, because Magento accepts the "from" and "to" filters
|
|
79
|
-
// separately (it also outputs FromTo filter pairs together)
|
|
80
|
-
if (filter.type === DaffFilterType.RangeNumeric) {
|
|
81
|
-
magentoFilters[filter.name] = {
|
|
82
|
-
...magentoFilters[filter.name],
|
|
83
|
-
...this.getRangeFromValue(filter.value.min.toString()),
|
|
84
|
-
...this.getRangeToValue(filter.value.max.toString()),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
magentoFilters[filter.name] = {
|
|
89
|
-
...magentoFilters[filter.name],
|
|
90
|
-
[this.getFilterAction(filter.type)]: this.getFilterValue(filter.type, filter.value),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return magentoFilters;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Returns an In action for Equal type and a Match action for Match type.
|
|
98
|
-
*/
|
|
99
|
-
getFilterAction(type) {
|
|
100
|
-
return type === DaffFilterType.Equal
|
|
101
|
-
? MagentoProductFilterActionEnum.In
|
|
102
|
-
: MagentoProductFilterActionEnum.Match;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns an array for Equal type and a string for Match type.
|
|
106
|
-
*/
|
|
107
|
-
getFilterValue(type, value) {
|
|
108
|
-
return type === DaffFilterType.Equal ? value : value[0];
|
|
109
|
-
}
|
|
110
|
-
getRangeFromValue(fromValue) {
|
|
111
|
-
return fromValue !== '*' ? { [MagentoProductFilterActionEnum.From]: fromValue } : null;
|
|
112
|
-
}
|
|
113
|
-
getRangeToValue(toValue) {
|
|
114
|
-
return toValue !== '*' ? { [MagentoProductFilterActionEnum.To]: toValue } : null;
|
|
115
|
-
}
|
|
116
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: MagentoProductAppliedFiltersTransformService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
117
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: MagentoProductAppliedFiltersTransformService, providedIn: 'root' }); }
|
|
118
|
-
}
|
|
119
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: MagentoProductAppliedFiltersTransformService, decorators: [{
|
|
120
|
-
type: Injectable,
|
|
121
|
-
args: [{
|
|
122
|
-
providedIn: 'root',
|
|
123
|
-
}]
|
|
124
|
-
}] });
|
|
125
|
-
|
|
126
|
-
const {
|
|
127
|
-
/**
|
|
128
|
-
* A multi-provider injection token for providing extra transform logic in the Product Magento driver.
|
|
129
|
-
* It is run after the standard transforms for each product preview and passed both the current transformed Daffodil product and the Magento product.
|
|
130
|
-
*
|
|
131
|
-
* See {@link MagentoProductPreview} for more info.
|
|
132
|
-
*/
|
|
133
|
-
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_TRANSFORMS, provider: provider$1, } = createMultiInjectionToken('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_TRANSFORMS');
|
|
134
|
-
/**
|
|
135
|
-
* Provides extra product preview transforms for the Magento product driver.
|
|
136
|
-
*
|
|
137
|
-
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_TRANSFORMS}.
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* providers: [
|
|
142
|
-
* ...provideDaffProductMagentoExtraProductPreviewTransforms(
|
|
143
|
-
* myExtraProductTransform
|
|
144
|
-
* )
|
|
145
|
-
* ]
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
function provideDaffProductMagentoExtraProductPreviewTransforms(...transforms) {
|
|
149
|
-
return provider$1(...transforms);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Transforms a Magento product into a product preview.
|
|
154
|
-
* Handles all product types.
|
|
155
|
-
*/
|
|
156
|
-
function transformMagentoProductPreview(product) {
|
|
157
|
-
return transformMagentoSimpleProductPreview(product);
|
|
158
|
-
}
|
|
159
|
-
const getType = (product) => {
|
|
160
|
-
switch (product.__typename) {
|
|
161
|
-
case MagentoProductTypeEnum.BundledProduct:
|
|
162
|
-
return DaffProductTypeEnum.Composite;
|
|
163
|
-
case MagentoProductTypeEnum.ConfigurableProduct:
|
|
164
|
-
return DaffProductTypeEnum.Configurable;
|
|
165
|
-
default:
|
|
166
|
-
return DaffProductTypeEnum.Simple;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Transforms a Magento simple product into a product preview.
|
|
171
|
-
*/
|
|
172
|
-
function transformMagentoSimpleProductPreview(product) {
|
|
173
|
-
return {
|
|
174
|
-
type: getType(product),
|
|
175
|
-
id: product.sku,
|
|
176
|
-
url: `/${product.url_key}${product.url_suffix}`,
|
|
177
|
-
name: product.name,
|
|
178
|
-
thumbnail: transformThumbnail(product.image),
|
|
179
|
-
price: getPrice(product),
|
|
180
|
-
discount: getDiscount(product),
|
|
181
|
-
in_stock: product.stock_status === MagentoProductStockStatusEnum.InStock,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function transformThumbnail(image) {
|
|
185
|
-
return {
|
|
186
|
-
url: image.url,
|
|
187
|
-
label: image.label,
|
|
188
|
-
id: null,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* A function for null checking an object.
|
|
193
|
-
*/
|
|
194
|
-
function getPrice(product) {
|
|
195
|
-
return product.price_range?.maximum_price?.regular_price?.value;
|
|
196
|
-
}
|
|
197
|
-
function getDiscount(product) {
|
|
198
|
-
return product.price_range?.maximum_price?.discount
|
|
199
|
-
? {
|
|
200
|
-
amount: product.price_range.maximum_price.discount.amount_off,
|
|
201
|
-
percent: product.price_range.maximum_price.discount.percent_off,
|
|
202
|
-
} : { amount: null, percent: null };
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const {
|
|
206
|
-
/**
|
|
207
|
-
* An internal token to combine the Magento preview transform with the injected transforms.
|
|
208
|
-
*/
|
|
209
|
-
token: DAFF_PRODUCT_MAGENTO_PRODUCT_PREVIEW_TRANSFORM,
|
|
210
|
-
/**
|
|
211
|
-
* Provider function for {@link DAFF_PRODUCT_MAGENTO_PRODUCT_PREVIEW_TRANSFORM}.
|
|
212
|
-
*/
|
|
213
|
-
provider: provideDaffProductMagentoProductPreviewTransform, } = createSingleInjectionToken('DAFF_PRODUCT_MAGENTO_PRODUCT_PREVIEW_TRANSFORM', {
|
|
214
|
-
factory: () => {
|
|
215
|
-
const transforms = inject(DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_TRANSFORMS);
|
|
216
|
-
return (magentoProduct, mediaUrl) => transforms.reduce((daffProduct, transform) => transform(daffProduct, magentoProduct, mediaUrl), transformMagentoProductPreview(magentoProduct));
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Transforms the magento MagentoProduct from the magento product query into a DaffProduct.
|
|
222
|
-
*
|
|
223
|
-
* @param product a magento product
|
|
224
|
-
*/
|
|
225
|
-
class DaffMagentoSimpleProductTransformers {
|
|
226
|
-
constructor(productPreviewTransform) {
|
|
227
|
-
this.productPreviewTransform = productPreviewTransform;
|
|
228
|
-
}
|
|
229
|
-
transformMagentoSimpleProduct(product, mediaUrl) {
|
|
230
|
-
return {
|
|
231
|
-
...this.productPreviewTransform(product, mediaUrl),
|
|
232
|
-
...product.description?.html && { description: product.description?.html },
|
|
233
|
-
...product.short_description?.html && { short_description: product.short_description?.html },
|
|
234
|
-
...product.meta_title && { meta_title: product.meta_title },
|
|
235
|
-
...product.meta_description && { meta_description: product.meta_description },
|
|
236
|
-
...product.canonical_url && { canonicalUrl: product.canonical_url },
|
|
237
|
-
...product.media_gallery_entries && { images: transformMediaGalleryEntries(product, mediaUrl) },
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoSimpleProductTransformers, deps: [{ token: DAFF_PRODUCT_MAGENTO_PRODUCT_PREVIEW_TRANSFORM }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
241
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoSimpleProductTransformers, providedIn: 'root' }); }
|
|
242
|
-
}
|
|
243
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoSimpleProductTransformers, decorators: [{
|
|
244
|
-
type: Injectable,
|
|
245
|
-
args: [{
|
|
246
|
-
providedIn: 'root',
|
|
247
|
-
}]
|
|
248
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
249
|
-
type: Inject,
|
|
250
|
-
args: [DAFF_PRODUCT_MAGENTO_PRODUCT_PREVIEW_TRANSFORM]
|
|
251
|
-
}] }] });
|
|
252
|
-
function transformMediaGalleryEntries(product, mediaUrl) {
|
|
253
|
-
return product.media_gallery_entries?.map(image => ({
|
|
254
|
-
url: mediaUrl + 'catalog/product' + image.file,
|
|
255
|
-
label: image.label,
|
|
256
|
-
id: image.uid.toString(),
|
|
257
|
-
})) || [];
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Transforms the magento MagentoProduct from the magento product query into a DaffProduct.
|
|
262
|
-
*
|
|
263
|
-
* @param product a magento product
|
|
264
|
-
*/
|
|
265
|
-
class DaffMagentoProductsTransformer {
|
|
266
|
-
constructor(magentoSimpleProductTransformers) {
|
|
267
|
-
this.magentoSimpleProductTransformers = magentoSimpleProductTransformers;
|
|
268
|
-
}
|
|
269
|
-
transformMagentoProduct(product, mediaUrl) {
|
|
270
|
-
return this.magentoSimpleProductTransformers.transformMagentoSimpleProduct(product, mediaUrl);
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Transforms many magento MagentoProducts from the magento product query into DaffProducts.
|
|
274
|
-
*/
|
|
275
|
-
transformManyMagentoProducts(products, mediaUrl) {
|
|
276
|
-
return products.map(product => this.transformMagentoProduct(product, mediaUrl));
|
|
277
|
-
}
|
|
278
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductsTransformer, deps: [{ token: DaffMagentoSimpleProductTransformers }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
279
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductsTransformer, providedIn: 'root' }); }
|
|
280
|
-
}
|
|
281
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductsTransformer, decorators: [{
|
|
282
|
-
type: Injectable,
|
|
283
|
-
args: [{
|
|
284
|
-
providedIn: 'root',
|
|
285
|
-
}]
|
|
286
|
-
}], ctorParameters: () => [{ type: DaffMagentoSimpleProductTransformers }] });
|
|
287
|
-
|
|
288
|
-
const {
|
|
289
|
-
/**
|
|
290
|
-
* A multi-provider injection token for providing extra transform logic in the Product Magento driver.
|
|
291
|
-
* It is run after the standard transforms for each product preview and passed both the current transformed Daffodil product and the Magento product.
|
|
292
|
-
*
|
|
293
|
-
* See {@link MagentoProduct} for more info.
|
|
294
|
-
*/
|
|
295
|
-
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_TRANSFORMS, provider, } = createMultiInjectionToken('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_TRANSFORMS');
|
|
296
|
-
/**
|
|
297
|
-
* Provides extra product preview transforms for the Magento product driver.
|
|
298
|
-
*
|
|
299
|
-
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_TRANSFORMS}.
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* ```ts
|
|
303
|
-
* providers: [
|
|
304
|
-
* ...provideDaffProductMagentoExtraProductTransforms(
|
|
305
|
-
* myExtraProductTransform
|
|
306
|
-
* )
|
|
307
|
-
* ]
|
|
308
|
-
* ```
|
|
309
|
-
*/
|
|
310
|
-
function provideDaffProductMagentoExtraProductTransforms(...transforms) {
|
|
311
|
-
return provider(...transforms);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const {
|
|
315
|
-
/**
|
|
316
|
-
* An internal token to combine the Magento preview transform with the injected transforms.
|
|
317
|
-
*/
|
|
318
|
-
token: DAFF_PRODUCT_MAGENTO_PRODUCT_TRANSFORM,
|
|
319
|
-
/**
|
|
320
|
-
* Provider function for {@link DAFF_PRODUCT_MAGENTO_PRODUCT_TRANSFORM}.
|
|
321
|
-
*/
|
|
322
|
-
provider: provideDaffProductMagentoProductTransform, } = createSingleInjectionToken('DAFF_PRODUCT_MAGENTO_PRODUCT_TRANSFORM', {
|
|
323
|
-
factory: () => {
|
|
324
|
-
const transforms = inject(DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_TRANSFORMS);
|
|
325
|
-
const transformer = inject(DaffMagentoProductsTransformer);
|
|
326
|
-
return (magentoProduct, mediaUrl) => transforms.reduce((daffProduct, transform) => transform(daffProduct, magentoProduct, mediaUrl), transformer.transformMagentoProduct(magentoProduct, mediaUrl));
|
|
327
|
-
},
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Transforms the MagentoProduct from the magento product query into a DaffProductDriverResponse.
|
|
332
|
-
*
|
|
333
|
-
* @param product a magento product
|
|
334
|
-
*
|
|
335
|
-
*/
|
|
336
|
-
class DaffMagentoProductResponseTransformers {
|
|
337
|
-
constructor(transformMagentoProduct) {
|
|
338
|
-
this.transformMagentoProduct = transformMagentoProduct;
|
|
339
|
-
}
|
|
340
|
-
transformMagentoProductResponse(product, mediaUrl) {
|
|
341
|
-
const daffProduct = this.transformMagentoProduct(product, mediaUrl);
|
|
342
|
-
return {
|
|
343
|
-
id: daffProduct.id,
|
|
344
|
-
products: [daffProduct],
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductResponseTransformers, deps: [{ token: DAFF_PRODUCT_MAGENTO_PRODUCT_TRANSFORM }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
348
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductResponseTransformers, providedIn: 'root' }); }
|
|
349
|
-
}
|
|
350
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductResponseTransformers, decorators: [{
|
|
351
|
-
type: Injectable,
|
|
352
|
-
args: [{
|
|
353
|
-
providedIn: 'root',
|
|
354
|
-
}]
|
|
355
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
356
|
-
type: Inject,
|
|
357
|
-
args: [DAFF_PRODUCT_MAGENTO_PRODUCT_TRANSFORM]
|
|
358
|
-
}] }] });
|
|
359
|
-
|
|
360
|
-
const transformAggregateEqual = (aggregate) => ({
|
|
361
|
-
label: aggregate.label,
|
|
362
|
-
type: DaffFilterType.Equal,
|
|
363
|
-
name: aggregate.attribute_code,
|
|
364
|
-
options: aggregate.options.reduce((acc, option) => {
|
|
365
|
-
acc[option.value] = {
|
|
366
|
-
applied: false,
|
|
367
|
-
label: option.label,
|
|
368
|
-
count: option.count,
|
|
369
|
-
value: option.value,
|
|
370
|
-
};
|
|
371
|
-
return acc;
|
|
372
|
-
}, {}),
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* The char that Magento uses to separate individual elements of the buckets
|
|
377
|
-
* they return for range elements
|
|
378
|
-
*/
|
|
379
|
-
const magentoBucketSeparator = '-';
|
|
380
|
-
const transformAggregateRange = (aggregate) => ({
|
|
381
|
-
label: aggregate.label,
|
|
382
|
-
type: DaffFilterType.RangeNumeric,
|
|
383
|
-
name: aggregate.attribute_code,
|
|
384
|
-
min: parseInt(aggregate.options[0].value.split('-')[0], 10),
|
|
385
|
-
max: parseInt(aggregate.options[aggregate.options.length - 1].value.split(magentoBucketSeparator)[1], 10),
|
|
386
|
-
options: {},
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
const magentoProductTransformAggregate = (aggregate) => {
|
|
390
|
-
switch (aggregate.type) {
|
|
391
|
-
case MagentoProductFilterType.Range:
|
|
392
|
-
return transformAggregateRange(aggregate);
|
|
393
|
-
case MagentoProductFilterType.Equal:
|
|
394
|
-
case MagentoProductFilterType.Match:
|
|
395
|
-
default:
|
|
396
|
-
return transformAggregateEqual(aggregate);
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const magentoProductGetMatchedAttributeType = (aggregate, inputFields) => inputFields.find(item => item.name === aggregate.attribute_code).type.name;
|
|
401
|
-
|
|
402
|
-
function magentoProductAddMetadataTypesToAggregates(inputFields, aggregations) {
|
|
403
|
-
return aggregations.map((aggregate) => ({
|
|
404
|
-
...aggregate,
|
|
405
|
-
type: magentoProductGetMatchedAttributeType(aggregate, inputFields),
|
|
406
|
-
}));
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const transformDirection = (direction) => {
|
|
410
|
-
if (direction === DaffSortDirectionEnum.Ascending) {
|
|
411
|
-
return MagentoSortDirectionEnum.Ascending;
|
|
412
|
-
}
|
|
413
|
-
else if (direction === DaffSortDirectionEnum.Descending) {
|
|
414
|
-
return MagentoSortDirectionEnum.Decending;
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
const magentoAppliedSortOptionTransform = (appliedOption, appliedDirection) => ({
|
|
418
|
-
[appliedOption]: transformDirection(appliedDirection),
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
function coerceDefaultSortOptionFirst(sort_fields) {
|
|
422
|
-
const index = sort_fields.options.findIndex(option => sort_fields.default === option.value);
|
|
423
|
-
return {
|
|
424
|
-
...sort_fields,
|
|
425
|
-
options: [
|
|
426
|
-
sort_fields.options[index],
|
|
427
|
-
...sort_fields.options.slice(0, index),
|
|
428
|
-
...sort_fields.options.slice(index + 1),
|
|
429
|
-
],
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Builds a product collection metadata object.
|
|
435
|
-
*/
|
|
436
|
-
// TODO: make a single param?
|
|
437
|
-
const magentoProductCollectionMetadataTransform = (aggregates, pageInfo, sortFields, products, count, appliedSortOption, appliedSortDirection) => ({
|
|
438
|
-
ids: products.map(({ sku }) => sku),
|
|
439
|
-
count,
|
|
440
|
-
pageSize: pageInfo.page_size,
|
|
441
|
-
currentPage: pageInfo.current_page,
|
|
442
|
-
totalPages: pageInfo.total_pages,
|
|
443
|
-
filters: daffFilterArrayToDict(aggregates.map(magentoProductTransformAggregate)),
|
|
444
|
-
sortOptions: {
|
|
445
|
-
default: sortFields.default,
|
|
446
|
-
options: coerceDefaultSortOptionFirst(sortFields).options,
|
|
447
|
-
},
|
|
448
|
-
appliedSortDirection,
|
|
449
|
-
appliedSortOption: appliedSortOption || sortFields.default,
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
const {
|
|
453
|
-
/**
|
|
454
|
-
* An internal token to combine the Magento response transform with the injected transforms.
|
|
455
|
-
*/
|
|
456
|
-
token: DAFF_PRODUCT_MAGENTO_PRODUCT_RESPONSE_TRANSFORM,
|
|
457
|
-
/**
|
|
458
|
-
* Provider function for {@link DAFF_PRODUCT_MAGENTO_PRODUCT_RESPONSE_TRANSFORM}.
|
|
459
|
-
*/
|
|
460
|
-
provider: provideDaffProductMagentoProductResponseTransform, } = createSingleInjectionToken('DAFF_PRODUCT_MAGENTO_PRODUCT_RESPONSE_TRANSFORM', {
|
|
461
|
-
factory: () => {
|
|
462
|
-
const transforms = inject(DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_RESPONSE_TRANSFORMS);
|
|
463
|
-
const daffResponseTransformer = inject(DaffMagentoProductResponseTransformers);
|
|
464
|
-
return (magentoProduct, mediaUrl) => transforms.reduce((daffProductResponse, transform) => transform(daffProductResponse, magentoProduct, mediaUrl), daffResponseTransformer.transformMagentoProductResponse(magentoProduct, mediaUrl));
|
|
465
|
-
},
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
const {
|
|
469
|
-
/**
|
|
470
|
-
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product queries.
|
|
471
|
-
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
|
|
472
|
-
*
|
|
473
|
-
* Fragment structure is platform-specific and this feature should be used with care.
|
|
474
|
-
*
|
|
475
|
-
* This can increase query complexity above the Magento default of 300.
|
|
476
|
-
* Daffodil only guarantees that stock queries don't exceed the limit of 300.
|
|
477
|
-
* Apps using this token should therefore increase the query complexity limit
|
|
478
|
-
* to accommodate the extra complexity contributed by the provided fragments.
|
|
479
|
-
*/
|
|
480
|
-
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS,
|
|
481
|
-
/**
|
|
482
|
-
* Provides extra GraphQL fragments for the Magento product driver.
|
|
483
|
-
*
|
|
484
|
-
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS}.
|
|
485
|
-
*
|
|
486
|
-
* @example
|
|
487
|
-
* ```ts
|
|
488
|
-
* providers: [
|
|
489
|
-
* ...provideDaffProductMagentoExtraProductPageFragments(
|
|
490
|
-
* myExtraProductFragment
|
|
491
|
-
* )
|
|
492
|
-
* ]
|
|
493
|
-
* ```
|
|
494
|
-
*/
|
|
495
|
-
provider: provideDaffProductMagentoExtraProductPageFragments, } = createMultiInjectionToken('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS');
|
|
496
|
-
|
|
497
|
-
const {
|
|
498
|
-
/**
|
|
499
|
-
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product preview queries.
|
|
500
|
-
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
|
|
501
|
-
* Fragments provided here will also be included in the {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS}.
|
|
502
|
-
* The same fragment should not be provided for both of these tokens.
|
|
503
|
-
*
|
|
504
|
-
* See {@link MagentoProductPreview} for more info.
|
|
505
|
-
*
|
|
506
|
-
* Fragment structure is platform-specific and this feature should be used with care.
|
|
507
|
-
*
|
|
508
|
-
* This can increase query complexity above the Magento default of 300.
|
|
509
|
-
* Daffodil only guarantees that stock queries don't exceed the limit of 300.
|
|
510
|
-
* Apps using this token should therefore increase the query complexity limit
|
|
511
|
-
* to accommodate the extra complexity contributed by the provided fragments.
|
|
512
|
-
*/
|
|
513
|
-
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS,
|
|
514
|
-
/**
|
|
515
|
-
* Provides extra GraphQL fragments for the Magento product preview query.
|
|
516
|
-
*
|
|
517
|
-
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS}.
|
|
518
|
-
*
|
|
519
|
-
* @example
|
|
520
|
-
* ```ts
|
|
521
|
-
* providers: [
|
|
522
|
-
* ...provideDaffProductMagentoExtraProductPreviewFragments(
|
|
523
|
-
* myExtraProductPreviewFragment
|
|
524
|
-
* )
|
|
525
|
-
* ]
|
|
526
|
-
* ```
|
|
527
|
-
*/
|
|
528
|
-
provider: provideDaffProductMagentoExtraProductPreviewFragments, } = createMultiInjectionToken('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS');
|
|
529
|
-
|
|
530
|
-
const {
|
|
531
|
-
/**
|
|
532
|
-
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product queries.
|
|
533
|
-
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
|
|
534
|
-
*
|
|
535
|
-
* Fragment structure is platform-specific and this feature should be used with care.
|
|
536
|
-
*
|
|
537
|
-
* This can increase query complexity above the Magento default of 300.
|
|
538
|
-
* Daffodil only guarantees that stock queries don't exceed the limit of 300.
|
|
539
|
-
* Apps using this token should therefore increase the query complexity limit
|
|
540
|
-
* to accommodate the extra complexity contributed by the provided fragments.
|
|
541
|
-
*/
|
|
542
|
-
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS,
|
|
543
|
-
/**
|
|
544
|
-
* Provides extra GraphQL fragments for the Magento product driver.
|
|
545
|
-
*
|
|
546
|
-
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS}.
|
|
547
|
-
*
|
|
548
|
-
* @example
|
|
549
|
-
* ```ts
|
|
550
|
-
* providers: [
|
|
551
|
-
* ...provideDaffProductMagentoExtraProductFragments(
|
|
552
|
-
* myExtraProductFragment
|
|
553
|
-
* )
|
|
554
|
-
* ]
|
|
555
|
-
* ```
|
|
556
|
-
*/
|
|
557
|
-
provider: provideDaffProductMagentoExtraProductFragments, } = createMultiInjectionToken('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS');
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* The default configuration for the {@link DaffProductMagentoDriverConfig}.
|
|
561
|
-
*/
|
|
562
|
-
const MAGENTO_PRODUCT_CONFIG_DEFAULT = {
|
|
563
|
-
baseMediaUrl: '',
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
const {
|
|
567
|
-
/**
|
|
568
|
-
* The token used to provide @daffodil/product/driver/magento config data.
|
|
569
|
-
* Mandatory for the Magento driver.
|
|
570
|
-
*/
|
|
571
|
-
token: MAGENTO_PRODUCT_CONFIG_TOKEN,
|
|
572
|
-
/**
|
|
573
|
-
* Provider function for {@link MAGENTO_PRODUCT_CONFIG_TOKEN}.
|
|
574
|
-
*/
|
|
575
|
-
provider: provideMagentoProductConfig, } = createConfigInjectionToken(MAGENTO_PRODUCT_CONFIG_DEFAULT, 'MAGENTO_PRODUCT_CONFIG_TOKEN');
|
|
576
|
-
|
|
577
|
-
const magentoProductPreviewFragment = gql `
|
|
578
|
-
fragment magentoProductPreview on ProductInterface {
|
|
579
|
-
__typename
|
|
580
|
-
uid
|
|
581
|
-
url_key
|
|
582
|
-
url_suffix
|
|
583
|
-
name
|
|
584
|
-
sku
|
|
585
|
-
stock_status
|
|
586
|
-
price_range {
|
|
587
|
-
maximum_price {
|
|
588
|
-
regular_price {
|
|
589
|
-
value
|
|
590
|
-
currency
|
|
591
|
-
}
|
|
592
|
-
discount {
|
|
593
|
-
amount_off
|
|
594
|
-
percent_off
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
image {
|
|
599
|
-
url
|
|
600
|
-
label
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
`;
|
|
604
|
-
|
|
605
|
-
const magentoProductFragment = gql `
|
|
606
|
-
fragment product on ProductInterface {
|
|
607
|
-
...magentoProductPreview
|
|
608
|
-
__typename
|
|
609
|
-
name
|
|
610
|
-
meta_title
|
|
611
|
-
meta_description
|
|
612
|
-
canonical_url
|
|
613
|
-
stock_status
|
|
614
|
-
short_description {
|
|
615
|
-
html
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
${magentoProductPreviewFragment}
|
|
619
|
-
`;
|
|
620
|
-
|
|
621
|
-
const magentoProductPageFragment = gql `
|
|
622
|
-
fragment magentoProductPage on ProductInterface {
|
|
623
|
-
...product
|
|
624
|
-
__typename
|
|
625
|
-
media_gallery_entries {
|
|
626
|
-
label
|
|
627
|
-
file
|
|
628
|
-
position
|
|
629
|
-
disabled
|
|
630
|
-
uid
|
|
631
|
-
}
|
|
632
|
-
description {
|
|
633
|
-
html
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
${magentoProductFragment}
|
|
637
|
-
`;
|
|
638
|
-
|
|
639
|
-
const magentoProductAggregationsFragment = gql `
|
|
640
|
-
fragment magentoProductAggregations on Aggregation {
|
|
641
|
-
label
|
|
642
|
-
count
|
|
643
|
-
attribute_code
|
|
644
|
-
options {
|
|
645
|
-
count
|
|
646
|
-
label
|
|
647
|
-
value
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
`;
|
|
651
|
-
|
|
652
|
-
const magentoProductSortFieldsFragment = gql `
|
|
653
|
-
fragment magentoProductSortFields on SortFields {
|
|
654
|
-
default
|
|
655
|
-
options {
|
|
656
|
-
label
|
|
657
|
-
value
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
`;
|
|
661
|
-
|
|
662
|
-
const DAFF_MAGENTO_GET_ALL_PRODUCTS_QUERY_NAME = 'MagentoGetAllProducts';
|
|
663
|
-
const getAllProducts = (extraProductFragments = []) => gql `
|
|
664
|
-
query ${DAFF_MAGENTO_GET_ALL_PRODUCTS_QUERY_NAME}($pageSize: Int) {
|
|
665
|
-
products(pageSize: $pageSize, search: "") {
|
|
666
|
-
total_count
|
|
667
|
-
items {
|
|
668
|
-
...magentoProductPage
|
|
669
|
-
${daffBuildFragmentNameSpread(...extraProductFragments)}
|
|
670
|
-
}
|
|
671
|
-
page_info {
|
|
672
|
-
page_size
|
|
673
|
-
current_page
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
${magentoProductPageFragment}
|
|
678
|
-
${daffBuildFragmentDefinition(...extraProductFragments)}
|
|
679
|
-
`;
|
|
680
|
-
|
|
681
|
-
const DAFF_MAGENTO_GET_A_PRODUCT_QUERY_NAME = 'MagentoGetAProduct';
|
|
682
|
-
const getProduct = (extraProductFragments = []) => gql `
|
|
683
|
-
query ${DAFF_MAGENTO_GET_A_PRODUCT_QUERY_NAME}($sku: String!){
|
|
684
|
-
products(filter: {
|
|
685
|
-
sku: {
|
|
686
|
-
eq: $sku
|
|
687
|
-
}
|
|
688
|
-
}){
|
|
689
|
-
items {
|
|
690
|
-
...magentoProductPage
|
|
691
|
-
${daffBuildFragmentNameSpread(...extraProductFragments)}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
${magentoProductPageFragment}
|
|
696
|
-
${daffBuildFragmentDefinition(...extraProductFragments)}
|
|
697
|
-
`;
|
|
698
|
-
|
|
699
|
-
const DAFF_MAGENTO_GET_A_PRODUCT_BY_URL_QUERY_NAME = 'MagentoGetAProductByUrl';
|
|
700
|
-
const getProductByUrl = (extraProductFragments = []) => gql `
|
|
701
|
-
query ${DAFF_MAGENTO_GET_A_PRODUCT_BY_URL_QUERY_NAME}($url: String!){
|
|
702
|
-
route(url: $url) {
|
|
703
|
-
... on ProductInterface {
|
|
704
|
-
...magentoProductPage
|
|
705
|
-
${daffBuildFragmentNameSpread(...extraProductFragments)}
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
${magentoProductPageFragment}
|
|
710
|
-
${daffBuildFragmentDefinition(...extraProductFragments)}
|
|
711
|
-
`;
|
|
712
|
-
|
|
713
|
-
const isValid$1 = (response) => !!response.data?.route?.sku;
|
|
714
|
-
const magentoProductGetByUrlValidator = (response) => {
|
|
715
|
-
if (isValid$1(response)) {
|
|
716
|
-
return response;
|
|
717
|
-
}
|
|
718
|
-
throw new DaffProductInvalidAPIResponseError('The platform did not respond with a product.');
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
const DAFF_MAGENTO_GET_FILTER_TYPES_QUERY_NAME = 'MagentoGetProductFilterFieldTypes';
|
|
722
|
-
const MagentoProductGetFilterTypes = gql `
|
|
723
|
-
query ${DAFF_MAGENTO_GET_FILTER_TYPES_QUERY_NAME} {
|
|
724
|
-
__type (name: "ProductAttributeFilterInput") {
|
|
725
|
-
inputFields {
|
|
726
|
-
name
|
|
727
|
-
type {
|
|
728
|
-
name
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
`;
|
|
734
|
-
|
|
735
|
-
const isValid = (response) => !!response.data?.products?.items;
|
|
736
|
-
const magentoProductGetAllValidator = (response) => {
|
|
737
|
-
if (isValid(response)) {
|
|
738
|
-
return response;
|
|
739
|
-
}
|
|
740
|
-
throw new DaffProductInvalidAPIResponseError('The platform did not respond with products.');
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* A service for making magento apollo queries for products of type, {@link DaffProduct}.
|
|
745
|
-
*
|
|
746
|
-
* @inheritdoc
|
|
747
|
-
*/
|
|
748
|
-
class DaffMagentoProductService {
|
|
749
|
-
constructor(apollo, config, responseTransform, extraPageFragments, extraFragments, extraPreviewFragments, magentoProductsTransformer) {
|
|
750
|
-
this.apollo = apollo;
|
|
751
|
-
this.config = config;
|
|
752
|
-
this.responseTransform = responseTransform;
|
|
753
|
-
this.extraPageFragments = extraPageFragments;
|
|
754
|
-
this.extraFragments = extraFragments;
|
|
755
|
-
this.extraPreviewFragments = extraPreviewFragments;
|
|
756
|
-
this.magentoProductsTransformer = magentoProductsTransformer;
|
|
757
|
-
}
|
|
758
|
-
get(productId) {
|
|
759
|
-
return this.apollo.query({
|
|
760
|
-
query: getProduct([
|
|
761
|
-
...this.extraPreviewFragments,
|
|
762
|
-
...this.extraFragments,
|
|
763
|
-
...this.extraPageFragments,
|
|
764
|
-
]),
|
|
765
|
-
variables: {
|
|
766
|
-
sku: productId,
|
|
767
|
-
},
|
|
768
|
-
}).pipe(map(result => this.responseTransform(result.data.products.items[0], this.config.baseMediaUrl)));
|
|
769
|
-
}
|
|
770
|
-
getByUrl(url) {
|
|
771
|
-
return this.apollo.query({
|
|
772
|
-
query: getProductByUrl([
|
|
773
|
-
...this.extraPreviewFragments,
|
|
774
|
-
...this.extraFragments,
|
|
775
|
-
...this.extraPageFragments,
|
|
776
|
-
]),
|
|
777
|
-
variables: {
|
|
778
|
-
url: daffUriTruncateQueryFragment(url),
|
|
779
|
-
},
|
|
780
|
-
}).pipe(map(magentoProductGetByUrlValidator), map(result => this.responseTransform(result.data.route, this.config.baseMediaUrl)));
|
|
781
|
-
}
|
|
782
|
-
getAll() {
|
|
783
|
-
return this.apollo.query({
|
|
784
|
-
query: getAllProducts([
|
|
785
|
-
...this.extraPreviewFragments,
|
|
786
|
-
...this.extraFragments,
|
|
787
|
-
...this.extraPageFragments,
|
|
788
|
-
]),
|
|
789
|
-
}).pipe(map(magentoProductGetAllValidator), map(result => this.magentoProductsTransformer.transformManyMagentoProducts(result.data.products.items, this.config.baseMediaUrl)));
|
|
790
|
-
}
|
|
791
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductService, deps: [{ token: i1.Apollo }, { token: MAGENTO_PRODUCT_CONFIG_TOKEN }, { token: DAFF_PRODUCT_MAGENTO_PRODUCT_RESPONSE_TRANSFORM }, { token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS }, { token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS }, { token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS }, { token: DaffMagentoProductsTransformer }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
792
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductService, providedIn: 'root' }); }
|
|
793
|
-
}
|
|
794
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffMagentoProductService, decorators: [{
|
|
795
|
-
type: Injectable,
|
|
796
|
-
args: [{
|
|
797
|
-
providedIn: 'root',
|
|
798
|
-
}]
|
|
799
|
-
}], ctorParameters: () => [{ type: i1.Apollo }, { type: undefined, decorators: [{
|
|
800
|
-
type: Inject,
|
|
801
|
-
args: [MAGENTO_PRODUCT_CONFIG_TOKEN]
|
|
802
|
-
}] }, { type: undefined, decorators: [{
|
|
803
|
-
type: Inject,
|
|
804
|
-
args: [DAFF_PRODUCT_MAGENTO_PRODUCT_RESPONSE_TRANSFORM]
|
|
805
|
-
}] }, { type: undefined, decorators: [{
|
|
806
|
-
type: Inject,
|
|
807
|
-
args: [DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS]
|
|
808
|
-
}] }, { type: undefined, decorators: [{
|
|
809
|
-
type: Inject,
|
|
810
|
-
args: [DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS]
|
|
811
|
-
}] }, { type: undefined, decorators: [{
|
|
812
|
-
type: Inject,
|
|
813
|
-
args: [DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS]
|
|
814
|
-
}] }, { type: DaffMagentoProductsTransformer }] });
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* A module that provides the {@link DaffProductDriver} and {@link DaffProductMagentoDriverConfig} as the {@link DaffMagentoProductService} and
|
|
818
|
-
* {@link MAGENTO_PRODUCT_CONFIG_DEFAULT} respectively
|
|
819
|
-
*/
|
|
820
|
-
class DaffProductMagentoDriverModule {
|
|
821
|
-
static forRoot(config = MAGENTO_PRODUCT_CONFIG_DEFAULT) {
|
|
822
|
-
return {
|
|
823
|
-
ngModule: DaffProductMagentoDriverModule,
|
|
824
|
-
providers: [
|
|
825
|
-
provideDaffProductDriver(DaffMagentoProductService),
|
|
826
|
-
provideManyDaffMagentoCacheableOperations(DAFF_MAGENTO_GET_ALL_PRODUCTS_QUERY_NAME, DAFF_MAGENTO_GET_A_PRODUCT_QUERY_NAME, DAFF_MAGENTO_GET_A_PRODUCT_BY_URL_QUERY_NAME),
|
|
827
|
-
provideMagentoProductConfig(config),
|
|
828
|
-
],
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffProductMagentoDriverModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
832
|
-
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DaffProductMagentoDriverModule, imports: [CommonModule] }); }
|
|
833
|
-
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffProductMagentoDriverModule, imports: [CommonModule] }); }
|
|
834
|
-
}
|
|
835
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffProductMagentoDriverModule, decorators: [{
|
|
836
|
-
type: NgModule,
|
|
837
|
-
args: [{
|
|
838
|
-
imports: [
|
|
839
|
-
CommonModule,
|
|
840
|
-
],
|
|
841
|
-
}]
|
|
842
|
-
}] });
|
|
843
|
-
|
|
844
|
-
const provideDaffProductMagentoDriver = (config = MAGENTO_PRODUCT_CONFIG_DEFAULT) => [
|
|
845
|
-
provideDaffProductDriver(DaffMagentoProductService),
|
|
846
|
-
provideManyDaffMagentoCacheableOperations(DAFF_MAGENTO_GET_ALL_PRODUCTS_QUERY_NAME, DAFF_MAGENTO_GET_A_PRODUCT_QUERY_NAME, DAFF_MAGENTO_GET_A_PRODUCT_BY_URL_QUERY_NAME),
|
|
847
|
-
provideMagentoProductConfig(config),
|
|
848
|
-
];
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* Generated bundle index. Do not edit.
|
|
852
|
-
*/
|
|
853
|
-
|
|
854
|
-
export { DAFF_MAGENTO_GET_ALL_PRODUCTS_QUERY_NAME, DAFF_MAGENTO_GET_A_PRODUCT_BY_URL_QUERY_NAME, DAFF_MAGENTO_GET_A_PRODUCT_QUERY_NAME, DAFF_MAGENTO_GET_FILTER_TYPES_QUERY_NAME, DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS, DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS, DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS, DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_TRANSFORMS, DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_TRANSFORMS, DAFF_PRODUCT_MAGENTO_PRODUCT_PREVIEW_TRANSFORM, DAFF_PRODUCT_MAGENTO_PRODUCT_RESPONSE_TRANSFORM, DAFF_PRODUCT_MAGENTO_PRODUCT_TRANSFORM, DaffMagentoProductResponseTransformers, DaffMagentoProductService, DaffMagentoProductsTransformer, DaffMagentoSimpleProductTransformers, DaffProductMagentoDriverModule, MAGENTO_PRODUCT_CONFIG_DEFAULT, MAGENTO_PRODUCT_CONFIG_TOKEN, MagentoProductAppliedFiltersTransformService, MagentoProductFilterActionEnum, MagentoProductFilterType, MagentoProductGetFilterTypes, MagentoProductStockStatusEnum, MagentoProductTypeEnum, MagentoSortDirectionEnum, getAllProducts, getProduct, getProductByUrl, magentoAppliedSortOptionTransform, magentoProductAddMetadataTypesToAggregates, magentoProductAggregationsFragment, magentoProductCollectionMetadataTransform, magentoProductFragment, magentoProductGetAllValidator, magentoProductGetByUrlValidator, magentoProductGetMatchedAttributeType, magentoProductPageFragment, magentoProductPreviewFragment, magentoProductSortFieldsFragment, magentoProductTransformAggregate, provideDaffProductMagentoDriver, provideDaffProductMagentoExtraProductFragments, provideDaffProductMagentoExtraProductPageFragments, provideDaffProductMagentoExtraProductPreviewFragments, provideDaffProductMagentoExtraProductPreviewTransforms, provideDaffProductMagentoExtraProductResponseTransforms, provideDaffProductMagentoExtraProductTransforms, provideMagentoProductConfig };
|
|
855
|
-
//# sourceMappingURL=daffodil-product-driver-magento.mjs.map
|