@daffodil/driver 0.90.0 → 0.91.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/README.md +16 -1
- package/fesm2022/daffodil-driver-in-memory.mjs +93 -2
- package/fesm2022/daffodil-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-driver-magento.mjs +297 -217
- package/fesm2022/daffodil-driver-magento.mjs.map +1 -1
- package/fesm2022/daffodil-driver-shopify-testing.mjs +65 -16
- package/fesm2022/daffodil-driver-shopify-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-shopify.mjs +1149 -1282
- package/fesm2022/daffodil-driver-shopify.mjs.map +1 -1
- package/in-memory/index.d.ts +80 -3
- package/magento/index.d.ts +114 -32
- package/package.json +1 -1
- package/shopify/index.d.ts +1836 -2037
- package/shopify/testing/index.d.ts +53 -14
|
@@ -1,105 +1,149 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, PLATFORM_ID, Inject, Injectable,
|
|
2
|
+
import { inject, PLATFORM_ID, Inject, Injectable, makeEnvironmentProviders, provideAppInitializer, TransferState } from '@angular/core';
|
|
3
3
|
import { InMemoryCache, from, ApolloLink } from '@apollo/client/core';
|
|
4
4
|
import { provideApollo, gql } from 'apollo-angular';
|
|
5
5
|
import { provideDaffDriverHttpClientCacheService, DaffDriverNetworkError } from '@daffodil/driver';
|
|
6
6
|
import { HttpLink } from 'apollo-angular/http';
|
|
7
7
|
import { isPlatformBrowser } from '@angular/common';
|
|
8
|
-
import { DaffInheritableError, daffIsError,
|
|
8
|
+
import { createSingleInjectionToken, createMultiInjectionToken, DaffInheritableError, daffIsError, DaffSortDirectionEnum } from '@daffodil/core';
|
|
9
|
+
import { provideDaffApolloRequestHandlerFactories } from '@daffodil/core/graphql';
|
|
9
10
|
|
|
10
11
|
var possibleTypes = {
|
|
12
|
+
AggregationOptionInterface: [
|
|
13
|
+
"AggregationOption"
|
|
14
|
+
],
|
|
15
|
+
AttributeSelectedOptionInterface: [
|
|
16
|
+
"AttributeSelectedOption"
|
|
17
|
+
],
|
|
18
|
+
AttributeValueInterface: [
|
|
19
|
+
"AttributeSelectedOptions",
|
|
20
|
+
"AttributeValue"
|
|
21
|
+
],
|
|
11
22
|
CartAddressInterface: [
|
|
12
23
|
"BillingCartAddress",
|
|
13
24
|
"ShippingCartAddress"
|
|
14
25
|
],
|
|
15
26
|
CartItemInterface: [
|
|
16
|
-
"SimpleCartItem",
|
|
17
|
-
"VirtualCartItem",
|
|
18
|
-
"DownloadableCartItem",
|
|
19
27
|
"BundleCartItem",
|
|
20
|
-
"ConfigurableCartItem"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"SimpleProduct",
|
|
25
|
-
"DownloadableProduct",
|
|
26
|
-
"BundleProduct",
|
|
27
|
-
"GroupedProduct",
|
|
28
|
-
"ConfigurableProduct"
|
|
28
|
+
"ConfigurableCartItem",
|
|
29
|
+
"DownloadableCartItem",
|
|
30
|
+
"SimpleCartItem",
|
|
31
|
+
"VirtualCartItem"
|
|
29
32
|
],
|
|
30
33
|
CategoryInterface: [
|
|
31
34
|
"CategoryTree"
|
|
32
35
|
],
|
|
33
|
-
MediaGalleryInterface: [
|
|
34
|
-
"ProductImage",
|
|
35
|
-
"ProductVideo"
|
|
36
|
-
],
|
|
37
|
-
ProductLinksInterface: [
|
|
38
|
-
"ProductLinks"
|
|
39
|
-
],
|
|
40
36
|
CreditMemoItemInterface: [
|
|
41
|
-
"DownloadableCreditMemoItem",
|
|
42
37
|
"BundleCreditMemoItem",
|
|
43
|
-
"CreditMemoItem"
|
|
38
|
+
"CreditMemoItem",
|
|
39
|
+
"DownloadableCreditMemoItem"
|
|
44
40
|
],
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
41
|
+
CustomAttributeMetadataInterface: [
|
|
42
|
+
"AttributeMetadata",
|
|
43
|
+
"CatalogAttributeMetadata",
|
|
44
|
+
"CustomerAttributeMetadata"
|
|
45
|
+
],
|
|
46
|
+
CustomAttributeOptionInterface: [
|
|
47
|
+
"AttributeOptionMetadata"
|
|
48
|
+
],
|
|
49
|
+
CustomizableOptionInterface: [
|
|
50
|
+
"CustomizableAreaOption",
|
|
51
|
+
"CustomizableCheckboxOption",
|
|
52
|
+
"CustomizableDateOption",
|
|
53
|
+
"CustomizableDropDownOption",
|
|
54
|
+
"CustomizableFieldOption",
|
|
55
|
+
"CustomizableFileOption",
|
|
56
|
+
"CustomizableMultipleOption",
|
|
57
|
+
"CustomizableRadioOption"
|
|
58
|
+
],
|
|
59
|
+
CustomizableProductInterface: [
|
|
60
|
+
"BundleProduct",
|
|
61
|
+
"ConfigurableProduct",
|
|
62
|
+
"DownloadableProduct",
|
|
63
|
+
"SimpleProduct",
|
|
64
|
+
"VirtualProduct"
|
|
65
|
+
],
|
|
66
|
+
"Error": [
|
|
67
|
+
"CartUserInputError",
|
|
68
|
+
"InsufficientStockError"
|
|
69
|
+
],
|
|
70
|
+
ErrorInterface: [
|
|
71
|
+
"InternalError",
|
|
72
|
+
"NoSuchEntityUidError"
|
|
49
73
|
],
|
|
50
74
|
InvoiceItemInterface: [
|
|
51
|
-
"DownloadableInvoiceItem",
|
|
52
75
|
"BundleInvoiceItem",
|
|
76
|
+
"DownloadableInvoiceItem",
|
|
53
77
|
"InvoiceItem"
|
|
54
78
|
],
|
|
55
|
-
ShipmentItemInterface: [
|
|
56
|
-
"BundleShipmentItem",
|
|
57
|
-
"ShipmentItem"
|
|
58
|
-
],
|
|
59
|
-
AggregationOptionInterface: [
|
|
60
|
-
"AggregationOption"
|
|
61
|
-
],
|
|
62
79
|
LayerFilterItemInterface: [
|
|
63
80
|
"LayerFilterItem",
|
|
64
81
|
"SwatchLayerFilterItem"
|
|
65
82
|
],
|
|
83
|
+
MediaGalleryInterface: [
|
|
84
|
+
"ProductImage",
|
|
85
|
+
"ProductVideo"
|
|
86
|
+
],
|
|
87
|
+
OrderItemInterface: [
|
|
88
|
+
"BundleOrderItem",
|
|
89
|
+
"ConfigurableOrderItem",
|
|
90
|
+
"DownloadableOrderItem",
|
|
91
|
+
"OrderItem"
|
|
92
|
+
],
|
|
66
93
|
PhysicalProductInterface: [
|
|
67
|
-
"SimpleProduct",
|
|
68
94
|
"BundleProduct",
|
|
95
|
+
"ConfigurableProduct",
|
|
69
96
|
"GroupedProduct",
|
|
70
|
-
"
|
|
97
|
+
"SimpleProduct"
|
|
71
98
|
],
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"CustomizableDropDownOption",
|
|
76
|
-
"CustomizableMultipleOption",
|
|
77
|
-
"CustomizableFieldOption",
|
|
78
|
-
"CustomizableFileOption",
|
|
79
|
-
"CustomizableRadioOption",
|
|
80
|
-
"CustomizableCheckboxOption"
|
|
81
|
-
],
|
|
82
|
-
CustomizableProductInterface: [
|
|
83
|
-
"VirtualProduct",
|
|
84
|
-
"SimpleProduct",
|
|
99
|
+
ProductInterface: [
|
|
100
|
+
"BundleProduct",
|
|
101
|
+
"ConfigurableProduct",
|
|
85
102
|
"DownloadableProduct",
|
|
103
|
+
"GroupedProduct",
|
|
104
|
+
"SimpleProduct",
|
|
105
|
+
"VirtualProduct"
|
|
106
|
+
],
|
|
107
|
+
ProductLinksInterface: [
|
|
108
|
+
"ProductLinks"
|
|
109
|
+
],
|
|
110
|
+
RoutableInterface: [
|
|
86
111
|
"BundleProduct",
|
|
87
|
-
"
|
|
112
|
+
"CategoryTree",
|
|
113
|
+
"CmsPage",
|
|
114
|
+
"ConfigurableProduct",
|
|
115
|
+
"DownloadableProduct",
|
|
116
|
+
"GroupedProduct",
|
|
117
|
+
"RoutableUrl",
|
|
118
|
+
"SimpleProduct",
|
|
119
|
+
"VirtualProduct"
|
|
120
|
+
],
|
|
121
|
+
ShipmentItemInterface: [
|
|
122
|
+
"BundleShipmentItem",
|
|
123
|
+
"ShipmentItem"
|
|
88
124
|
],
|
|
89
125
|
SwatchDataInterface: [
|
|
126
|
+
"ColorSwatchData",
|
|
90
127
|
"ImageSwatchData",
|
|
91
|
-
"TextSwatchData"
|
|
92
|
-
"ColorSwatchData"
|
|
128
|
+
"TextSwatchData"
|
|
93
129
|
],
|
|
94
130
|
SwatchLayerFilterItemInterface: [
|
|
95
131
|
"SwatchLayerFilterItem"
|
|
132
|
+
],
|
|
133
|
+
WishlistItemInterface: [
|
|
134
|
+
"BundleWishlistItem",
|
|
135
|
+
"ConfigurableWishlistItem",
|
|
136
|
+
"DownloadableWishlistItem",
|
|
137
|
+
"GroupedProductWishlistItem",
|
|
138
|
+
"SimpleWishlistItem",
|
|
139
|
+
"VirtualWishlistItem"
|
|
96
140
|
]
|
|
97
141
|
};
|
|
98
142
|
var introspectionQueryResultData = {
|
|
99
143
|
possibleTypes: possibleTypes
|
|
100
144
|
};
|
|
101
145
|
|
|
102
|
-
const
|
|
146
|
+
const MAGENTO_POSSIBLE_TYPES = introspectionQueryResultData;
|
|
103
147
|
|
|
104
148
|
/**
|
|
105
149
|
* Creates an Apollo HTTP link for GraphQL requests.
|
|
@@ -112,113 +156,6 @@ function createHttpLink(url) {
|
|
|
112
156
|
return httpLink.create({ uri: url });
|
|
113
157
|
}
|
|
114
158
|
|
|
115
|
-
/**
|
|
116
|
-
* Magento GraphQL possible types configuration for Apollo Client.
|
|
117
|
-
*
|
|
118
|
-
* This object defines the possible concrete types for each GraphQL interface
|
|
119
|
-
* used in Magento's GraphQL API. Apollo Client uses this information for
|
|
120
|
-
* proper fragment matching and union/interface type resolution.
|
|
121
|
-
*
|
|
122
|
-
* When Apollo Client encounters a GraphQL interface or union type in a query,
|
|
123
|
-
* it needs to know which concrete types can implement that interface to
|
|
124
|
-
* properly cache and normalize the data.
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* new InMemoryCache({
|
|
129
|
-
* possibleTypes: MAGENTO_POSSIBLE_TYPES
|
|
130
|
-
* })
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
const MAGENTO_POSSIBLE_TYPES = {
|
|
134
|
-
CartAddressInterface: [
|
|
135
|
-
'BillingCartAddress',
|
|
136
|
-
'ShippingCartAddress',
|
|
137
|
-
],
|
|
138
|
-
CartItemInterface: [
|
|
139
|
-
'SimpleCartItem',
|
|
140
|
-
'VirtualCartItem',
|
|
141
|
-
'DownloadableCartItem',
|
|
142
|
-
'BundleCartItem',
|
|
143
|
-
'ConfigurableCartItem',
|
|
144
|
-
],
|
|
145
|
-
ProductInterface: [
|
|
146
|
-
'VirtualProduct',
|
|
147
|
-
'SimpleProduct',
|
|
148
|
-
'DownloadableProduct',
|
|
149
|
-
'BundleProduct',
|
|
150
|
-
'GroupedProduct',
|
|
151
|
-
'ConfigurableProduct',
|
|
152
|
-
],
|
|
153
|
-
CategoryInterface: [
|
|
154
|
-
'CategoryTree',
|
|
155
|
-
],
|
|
156
|
-
MediaGalleryInterface: [
|
|
157
|
-
'ProductImage',
|
|
158
|
-
'ProductVideo',
|
|
159
|
-
],
|
|
160
|
-
ProductLinksInterface: [
|
|
161
|
-
'ProductLinks',
|
|
162
|
-
],
|
|
163
|
-
CreditMemoItemInterface: [
|
|
164
|
-
'DownloadableCreditMemoItem',
|
|
165
|
-
'BundleCreditMemoItem',
|
|
166
|
-
'CreditMemoItem',
|
|
167
|
-
],
|
|
168
|
-
OrderItemInterface: [
|
|
169
|
-
'DownloadableOrderItem',
|
|
170
|
-
'BundleOrderItem',
|
|
171
|
-
'OrderItem',
|
|
172
|
-
],
|
|
173
|
-
InvoiceItemInterface: [
|
|
174
|
-
'DownloadableInvoiceItem',
|
|
175
|
-
'BundleInvoiceItem',
|
|
176
|
-
'InvoiceItem',
|
|
177
|
-
],
|
|
178
|
-
ShipmentItemInterface: [
|
|
179
|
-
'BundleShipmentItem',
|
|
180
|
-
'ShipmentItem',
|
|
181
|
-
],
|
|
182
|
-
AggregationOptionInterface: [
|
|
183
|
-
'AggregationOption',
|
|
184
|
-
],
|
|
185
|
-
LayerFilterItemInterface: [
|
|
186
|
-
'LayerFilterItem',
|
|
187
|
-
'SwatchLayerFilterItem',
|
|
188
|
-
],
|
|
189
|
-
PhysicalProductInterface: [
|
|
190
|
-
'SimpleProduct',
|
|
191
|
-
'BundleProduct',
|
|
192
|
-
'GroupedProduct',
|
|
193
|
-
'ConfigurableProduct',
|
|
194
|
-
],
|
|
195
|
-
CustomizableOptionInterface: [
|
|
196
|
-
'CustomizableAreaOption',
|
|
197
|
-
'CustomizableDateOption',
|
|
198
|
-
'CustomizableDropDownOption',
|
|
199
|
-
'CustomizableMultipleOption',
|
|
200
|
-
'CustomizableFieldOption',
|
|
201
|
-
'CustomizableFileOption',
|
|
202
|
-
'CustomizableRadioOption',
|
|
203
|
-
'CustomizableCheckboxOption',
|
|
204
|
-
],
|
|
205
|
-
CustomizableProductInterface: [
|
|
206
|
-
'VirtualProduct',
|
|
207
|
-
'SimpleProduct',
|
|
208
|
-
'DownloadableProduct',
|
|
209
|
-
'BundleProduct',
|
|
210
|
-
'ConfigurableProduct',
|
|
211
|
-
],
|
|
212
|
-
SwatchDataInterface: [
|
|
213
|
-
'ImageSwatchData',
|
|
214
|
-
'TextSwatchData',
|
|
215
|
-
'ColorSwatchData',
|
|
216
|
-
],
|
|
217
|
-
SwatchLayerFilterItemInterface: [
|
|
218
|
-
'SwatchLayerFilterItem',
|
|
219
|
-
],
|
|
220
|
-
};
|
|
221
|
-
|
|
222
159
|
/**
|
|
223
160
|
* Custom type policies that allow us to have more granular control
|
|
224
161
|
* over how ApolloClient reads from and writes to the cache.
|
|
@@ -549,7 +486,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.1", ngImpor
|
|
|
549
486
|
* @param endpoint - The Magento store domain (e.g. "https://www.my-store.com/graphql") or an injection token for a string or function that returns a string
|
|
550
487
|
*/
|
|
551
488
|
function provideMagentoDriver(endpoint, options = {
|
|
552
|
-
possibleTypes: MAGENTO_POSSIBLE_TYPES,
|
|
489
|
+
possibleTypes: MAGENTO_POSSIBLE_TYPES.possibleTypes,
|
|
553
490
|
typePolicies,
|
|
554
491
|
}) {
|
|
555
492
|
return [
|
|
@@ -563,48 +500,42 @@ function provideMagentoDriver(endpoint, options = {
|
|
|
563
500
|
];
|
|
564
501
|
}
|
|
565
502
|
|
|
566
|
-
const DAFF_DRIVER_MAGENTO_ERROR_CODE = 'DAFF_DRIVER_MAGENTO_ERROR';
|
|
567
503
|
/**
|
|
568
|
-
* A
|
|
504
|
+
* A non-exhaustive list of feature kinds that exist for {@link provideMagentoDriver}.
|
|
569
505
|
*/
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;
|
|
579
|
-
return new ErrorClass(error.message);
|
|
580
|
-
}
|
|
581
|
-
;
|
|
506
|
+
var MagentoDriverFeatureKind;
|
|
507
|
+
(function (MagentoDriverFeatureKind) {
|
|
508
|
+
MagentoDriverFeatureKind["CacheableOperations"] = "DaffMagentoDriverCacheableOperationsFeature";
|
|
509
|
+
MagentoDriverFeatureKind["CacheHeader"] = "DaffMagentoDriverCacheHeaderFeature";
|
|
510
|
+
MagentoDriverFeatureKind["ErrorHandler"] = "DaffMagentoDriverErrorHandlerFeature";
|
|
511
|
+
MagentoDriverFeatureKind["TransferState"] = "DaffMagentoDriverTransferStateFeature";
|
|
512
|
+
MagentoDriverFeatureKind["ExtraApolloOptions"] = "DaffMagentoDriverExtraApolloOptionsFeature";
|
|
513
|
+
})(MagentoDriverFeatureKind || (MagentoDriverFeatureKind = {}));
|
|
582
514
|
|
|
583
515
|
/**
|
|
584
|
-
*
|
|
516
|
+
* Creates a magento driver feature for {@link provideMagentoDriver}.
|
|
585
517
|
*/
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
if (error.graphQLErrors?.length > 0) {
|
|
589
|
-
return error.graphQLErrors.map(err => daffMagentoTransformGraphQlError(err, map))[0];
|
|
590
|
-
}
|
|
591
|
-
else if (error.networkError) {
|
|
592
|
-
return new DaffDriverNetworkError(error.networkError.message);
|
|
593
|
-
}
|
|
594
|
-
else if (daffIsError(error)) {
|
|
595
|
-
return error;
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
return new DaffDriverMagentoError(error.message);
|
|
599
|
-
}
|
|
518
|
+
function makeMagentoDriverFeature(kind, providers) {
|
|
519
|
+
return { ɵkind: kind, ɵproviders: providers };
|
|
600
520
|
}
|
|
601
|
-
;
|
|
602
521
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
522
|
+
const {
|
|
523
|
+
/**
|
|
524
|
+
* A token to hold {@link DaffDriverMagentoExtraApolloOptions}.
|
|
525
|
+
*/
|
|
526
|
+
token: DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS,
|
|
527
|
+
/**
|
|
528
|
+
* A provider for {@link DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS}.
|
|
529
|
+
*/
|
|
530
|
+
provider: provideDaffDriverMagentoExtraApolloOptions, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS', {
|
|
531
|
+
factory: () => ({}),
|
|
532
|
+
});
|
|
533
|
+
/**
|
|
534
|
+
* A {@link provideMagentoDriver} feature that allow specifying {@link DaffDriverMagentoExtraApolloOptions}.
|
|
535
|
+
*/
|
|
536
|
+
const withDaffDriverMagentoExtraApolloOptions = (options) => makeMagentoDriverFeature(MagentoDriverFeatureKind.TransferState, [
|
|
537
|
+
provideDaffDriverMagentoExtraApolloOptions(options),
|
|
538
|
+
]);
|
|
608
539
|
|
|
609
540
|
const {
|
|
610
541
|
/**
|
|
@@ -629,10 +560,25 @@ function provideDaffMagentoCacheableOperation(operationName) {
|
|
|
629
560
|
};
|
|
630
561
|
}
|
|
631
562
|
|
|
563
|
+
/**
|
|
564
|
+
* A request handler provider that will convert cacheable apollo operations into a format that Magento will understand as cacheable.
|
|
565
|
+
*/
|
|
566
|
+
const provideDaffMagentoApolloCacheableOperations = () => makeEnvironmentProviders([
|
|
567
|
+
provideDaffApolloRequestHandlerFactories(() => {
|
|
568
|
+
const cacheableOperations = inject(DAFF_MAGENTO_CACHEABLE_OPERATIONS);
|
|
569
|
+
return (operation, forward) => {
|
|
570
|
+
if (cacheableOperations.indexOf(operation.operationName) > -1) {
|
|
571
|
+
operation.setContext({ method: 'GET' });
|
|
572
|
+
}
|
|
573
|
+
return forward(operation);
|
|
574
|
+
};
|
|
575
|
+
}),
|
|
576
|
+
]);
|
|
632
577
|
/**
|
|
633
578
|
* A service that will convert cacheable apollo operations into a format that Magento will understand as cacheable.
|
|
634
579
|
*
|
|
635
580
|
* @inheritdoc
|
|
581
|
+
* @deprecated Prefer using {@link provideDaffMagentoApolloCacheableOperations} instead. Deprecated in version 0.91.0. Will be removed in version 0.94.0.
|
|
636
582
|
*/
|
|
637
583
|
class DaffMagentoApolloCacheableOperationsLinkGenerator {
|
|
638
584
|
constructor(apolloGetRequests) {
|
|
@@ -886,12 +832,40 @@ const DAFF_MAGENTO_2_4_3_TYPE_POLICIES = {
|
|
|
886
832
|
};
|
|
887
833
|
|
|
888
834
|
const MAGENTO_CUSTOMER_CACHE_ID_HEADER = 'X-Magento-Cache-Id';
|
|
835
|
+
/**
|
|
836
|
+
* Stores and sets the Magento cache ID header.
|
|
837
|
+
* This will set the `X-Magento-Cache-Id` header from the most recent value encountered
|
|
838
|
+
* on a response, if there was a response with that header set.
|
|
839
|
+
*/
|
|
840
|
+
const provideDaffMagentoCacheHeader = () => makeEnvironmentProviders([
|
|
841
|
+
provideDaffApolloRequestHandlerFactories(() => {
|
|
842
|
+
let cacheHeader;
|
|
843
|
+
return (operation, forward) => {
|
|
844
|
+
if (cacheHeader) {
|
|
845
|
+
operation.setContext({
|
|
846
|
+
headers: {
|
|
847
|
+
...operation.getContext().headers,
|
|
848
|
+
[MAGENTO_CUSTOMER_CACHE_ID_HEADER]: cacheHeader,
|
|
849
|
+
},
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
return forward(operation).map((response) => {
|
|
853
|
+
const { headers } = operation.getContext().response;
|
|
854
|
+
if (headers.get(MAGENTO_CUSTOMER_CACHE_ID_HEADER)) {
|
|
855
|
+
cacheHeader = headers.get(MAGENTO_CUSTOMER_CACHE_ID_HEADER);
|
|
856
|
+
}
|
|
857
|
+
return response;
|
|
858
|
+
});
|
|
859
|
+
};
|
|
860
|
+
}),
|
|
861
|
+
]);
|
|
889
862
|
/**
|
|
890
863
|
* Stores and sets the Magento cache ID header.
|
|
891
864
|
* This will set the `X-Magento-Cache-Id` header from the most recent value encountered
|
|
892
865
|
* on a response, if there was a response with that header set.
|
|
893
866
|
*
|
|
894
867
|
* @inheritdoc
|
|
868
|
+
* @deprecated Prefer using {@link provideDaffMagentoCacheHeader} instead. Deprecated in version 0.91.0. Will be removed in version 0.94.0.
|
|
895
869
|
*/
|
|
896
870
|
class DaffMagentoCacheHeaderApolloLinkGenerator {
|
|
897
871
|
getLink() {
|
|
@@ -923,6 +897,131 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.1", ngImpor
|
|
|
923
897
|
}]
|
|
924
898
|
}] });
|
|
925
899
|
|
|
900
|
+
/**
|
|
901
|
+
* A {@link provideMagentoDriver} feature that sets up {@link provideDaffMagentoCacheHeader}.
|
|
902
|
+
*/
|
|
903
|
+
const withDaffMagentoCacheHeader = () => makeMagentoDriverFeature(MagentoDriverFeatureKind.CacheHeader, [
|
|
904
|
+
provideDaffMagentoCacheHeader(),
|
|
905
|
+
]);
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* A {@link provideMagentoDriver} feature that sets up {@link provideDaffMagentoApolloCacheableOperations}.
|
|
909
|
+
*/
|
|
910
|
+
const withDaffMagentoCacheableOperations = (...extraOperations) => makeMagentoDriverFeature(MagentoDriverFeatureKind.CacheableOperations, [
|
|
911
|
+
provideDaffMagentoApolloCacheableOperations(),
|
|
912
|
+
makeEnvironmentProviders(provideManyDaffMagentoCacheableOperations(...extraOperations)),
|
|
913
|
+
]);
|
|
914
|
+
|
|
915
|
+
const {
|
|
916
|
+
/**
|
|
917
|
+
* Holds the error handler for {@link provideMagentoDriver}.
|
|
918
|
+
*/
|
|
919
|
+
token: DAFF_DRIVER_MAGENTO_ERROR_HANDLER,
|
|
920
|
+
/**
|
|
921
|
+
* Provider function for {@link DAFF_DRIVER_MAGENTO_ERROR_HANDLER}.
|
|
922
|
+
*/
|
|
923
|
+
provider: provideDaffDriverMagentoErrorHandler, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_ERROR_HANDLER', {
|
|
924
|
+
factory: () => ({ graphQLErrors, networkError }) => {
|
|
925
|
+
if (graphQLErrors) {
|
|
926
|
+
graphQLErrors.map(({ message, locations, path }) => console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
|
|
927
|
+
}
|
|
928
|
+
if (networkError) {
|
|
929
|
+
console.error(`[Network error]: ${networkError}`);
|
|
930
|
+
}
|
|
931
|
+
},
|
|
932
|
+
});
|
|
933
|
+
/**
|
|
934
|
+
* A {@link provideMagentoDriver} feature that specifies the error handler.
|
|
935
|
+
*/
|
|
936
|
+
const withDaffDriverMagentoErrorHandler = (handler) => makeMagentoDriverFeature(MagentoDriverFeatureKind.ErrorHandler, [
|
|
937
|
+
provideDaffDriverMagentoErrorHandler(handler),
|
|
938
|
+
]);
|
|
939
|
+
|
|
940
|
+
const {
|
|
941
|
+
/**
|
|
942
|
+
* Holds the `StateKey` with which {@link provideMagentoDriver} can use to transfer Apollo state from the server to the client.
|
|
943
|
+
*/
|
|
944
|
+
token: DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY,
|
|
945
|
+
/**
|
|
946
|
+
* Provider for {@link DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY}.
|
|
947
|
+
*/
|
|
948
|
+
provider: provideDaffDriverMagentoTransferStateKey, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY');
|
|
949
|
+
/**
|
|
950
|
+
* A {@link provideMagentoDriver} feature that sets up transfer state with the specified key.
|
|
951
|
+
*
|
|
952
|
+
* @param stateKey The key under which the Apollo state is stored.
|
|
953
|
+
*/
|
|
954
|
+
const withDaffDriverMagentoTransferState = (stateKey) => makeMagentoDriverFeature(MagentoDriverFeatureKind.TransferState, [
|
|
955
|
+
provideDaffDriverMagentoTransferStateKey(stateKey),
|
|
956
|
+
]);
|
|
957
|
+
/**
|
|
958
|
+
* Holds the logic for hydrating the Apollo cache with the server's transferred state.
|
|
959
|
+
* It is recommended to use {@link withDaffDriverMagentoTransferState} with {@link provideMagentoDriver}
|
|
960
|
+
* to provide this functionality automatically.
|
|
961
|
+
*
|
|
962
|
+
* @param cache The Apollo cache instance.
|
|
963
|
+
*/
|
|
964
|
+
const provideDaffDriverMagentoTransferState = (cache) => makeEnvironmentProviders([
|
|
965
|
+
provideAppInitializer(() => {
|
|
966
|
+
const transferState = inject(TransferState);
|
|
967
|
+
const stateKey = inject(DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY);
|
|
968
|
+
const hasStateKey = transferState.hasKey(stateKey);
|
|
969
|
+
if (hasStateKey) {
|
|
970
|
+
// reads the serialized cache
|
|
971
|
+
const state = transferState.get(stateKey, null);
|
|
972
|
+
// and puts it in the Apollo
|
|
973
|
+
cache.restore(state);
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
// serializes the cache and puts it under a key
|
|
977
|
+
transferState.onSerialize(stateKey, () => cache.extract());
|
|
978
|
+
}
|
|
979
|
+
}),
|
|
980
|
+
]);
|
|
981
|
+
|
|
982
|
+
const DAFF_DRIVER_MAGENTO_ERROR_CODE = 'DAFF_DRIVER_MAGENTO_ERROR';
|
|
983
|
+
/**
|
|
984
|
+
* A very general error thrown when a more specific error type cannot be determined.
|
|
985
|
+
*/
|
|
986
|
+
class DaffDriverMagentoError extends DaffInheritableError {
|
|
987
|
+
constructor(message) {
|
|
988
|
+
super(message);
|
|
989
|
+
this.code = DAFF_DRIVER_MAGENTO_ERROR_CODE;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function daffMagentoTransformGraphQlError(error, map) {
|
|
994
|
+
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;
|
|
995
|
+
return new ErrorClass(error.message);
|
|
996
|
+
}
|
|
997
|
+
;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Transforms the passed error according to the lookup in the passed map.
|
|
1001
|
+
*/
|
|
1002
|
+
// TODO: return array of errors
|
|
1003
|
+
function daffTransformMagentoError(error, map) {
|
|
1004
|
+
if (error.graphQLErrors?.length > 0) {
|
|
1005
|
+
return error.graphQLErrors.map(err => daffMagentoTransformGraphQlError(err, map))[0];
|
|
1006
|
+
}
|
|
1007
|
+
else if (error.networkError) {
|
|
1008
|
+
return new DaffDriverNetworkError(error.networkError.message);
|
|
1009
|
+
}
|
|
1010
|
+
else if (daffIsError(error)) {
|
|
1011
|
+
return error;
|
|
1012
|
+
}
|
|
1013
|
+
else {
|
|
1014
|
+
return new DaffDriverMagentoError(error.message);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
;
|
|
1018
|
+
|
|
1019
|
+
var MagentoSortEnum;
|
|
1020
|
+
(function (MagentoSortEnum) {
|
|
1021
|
+
MagentoSortEnum["ASC"] = "ASC";
|
|
1022
|
+
MagentoSortEnum["DESC"] = "DESC";
|
|
1023
|
+
})(MagentoSortEnum || (MagentoSortEnum = {}));
|
|
1024
|
+
|
|
926
1025
|
function magentoPageInfoTransform(pageInfo) {
|
|
927
1026
|
return {
|
|
928
1027
|
pageSize: pageInfo.page_size,
|
|
@@ -962,28 +1061,9 @@ const magentoMoneyFragment = gql `
|
|
|
962
1061
|
}
|
|
963
1062
|
`;
|
|
964
1063
|
|
|
965
|
-
/**
|
|
966
|
-
* @deprecated in favor of {@link provideMagentoDriver} Deprecated in version 0.88.0. Will be removed in version 0.91.0.
|
|
967
|
-
*/
|
|
968
|
-
class DaffDriverMagentoModule {
|
|
969
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverMagentoModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
970
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverMagentoModule }); }
|
|
971
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverMagentoModule, providers: [
|
|
972
|
-
provideDaffDriverHttpClientCacheService(DaffDriverHttpClientCacheMagentoService),
|
|
973
|
-
] }); }
|
|
974
|
-
}
|
|
975
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverMagentoModule, decorators: [{
|
|
976
|
-
type: NgModule,
|
|
977
|
-
args: [{
|
|
978
|
-
providers: [
|
|
979
|
-
provideDaffDriverHttpClientCacheService(DaffDriverHttpClientCacheMagentoService),
|
|
980
|
-
],
|
|
981
|
-
}]
|
|
982
|
-
}] });
|
|
983
|
-
|
|
984
1064
|
/**
|
|
985
1065
|
* Generated bundle index. Do not edit.
|
|
986
1066
|
*/
|
|
987
1067
|
|
|
988
|
-
export { DAFF_DRIVER_MAGENTO_ERROR_CODE, DAFF_MAGENTO_2_4_3_TYPE_POLICIES, DAFF_MAGENTO_CACHEABLE_OPERATIONS, DaffDriverHttpClientCacheMagentoService, DaffDriverMagentoError,
|
|
1068
|
+
export { DAFF_DRIVER_MAGENTO_ERROR_CODE, DAFF_DRIVER_MAGENTO_ERROR_HANDLER, DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS, DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY, DAFF_MAGENTO_2_4_3_TYPE_POLICIES, DAFF_MAGENTO_CACHEABLE_OPERATIONS, DaffDriverHttpClientCacheMagentoService, DaffDriverMagentoError, DaffMagentoApolloCacheableOperationsLinkGenerator, DaffMagentoCacheHeaderApolloLinkGenerator, MAGENTO_CUSTOMER_CACHE_ID_HEADER, MAGENTO_POSSIBLE_TYPES, MagentoDriverFeatureKind, MagentoSortEnum, daffMagentoTransformGraphQlError, daffTransformMagentoError, magentoMoneyFragment, magentoPageInfoTransform, magentoSearchResultPageInfoFragment, magentoSortDirectionRequestTransform, magentoSortDirectionResponseTransform, makeMagentoDriverFeature, provideDaffDriverMagentoErrorHandler, provideDaffDriverMagentoExtraApolloOptions, provideDaffDriverMagentoTransferState, provideDaffDriverMagentoTransferStateKey, provideDaffMagentoApolloCacheableOperations, provideDaffMagentoCacheHeader, provideDaffMagentoCacheableOperation, provideMagentoDriver, provideManyDaffMagentoCacheableOperations, MAGENTO_POSSIBLE_TYPES as schema, withDaffDriverMagentoErrorHandler, withDaffDriverMagentoExtraApolloOptions, withDaffDriverMagentoTransferState, withDaffMagentoCacheHeader, withDaffMagentoCacheableOperations };
|
|
989
1069
|
//# sourceMappingURL=daffodil-driver-magento.mjs.map
|