@daffodil/driver 0.90.0 → 0.92.3-rc.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-hubspot-testing.mjs +3 -3
- package/fesm2022/daffodil-driver-hubspot-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-in-memory.mjs +100 -9
- package/fesm2022/daffodil-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-driver-magento-testing.mjs +9 -9
- package/fesm2022/daffodil-driver-magento-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-magento.mjs +359 -281
- package/fesm2022/daffodil-driver-magento.mjs.map +1 -1
- package/fesm2022/daffodil-driver-shopify-testing.mjs +128 -53
- package/fesm2022/daffodil-driver-shopify-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-shopify.mjs +1440 -1432
- package/fesm2022/daffodil-driver-shopify.mjs.map +1 -1
- package/fesm2022/daffodil-driver.mjs +3 -3
- package/fesm2022/daffodil-driver.mjs.map +1 -1
- package/in-memory/index.d.ts +80 -3
- package/magento/index.d.ts +112 -36
- package/package.json +1 -1
- package/shopify/index.d.ts +4318 -3116
- package/shopify/testing/index.d.ts +101 -36
|
@@ -1,223 +1,150 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import { InMemoryCache, from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { makeEnvironmentProviders, inject, Inject, Injectable, PLATFORM_ID, provideAppInitializer, TransferState, InjectionToken } from '@angular/core';
|
|
3
|
+
import { ApolloLink, InMemoryCache, from } from '@apollo/client/core';
|
|
4
|
+
import { onError } from '@apollo/client/link/error';
|
|
5
|
+
import { Apollo, provideApollo, gql } from 'apollo-angular';
|
|
6
6
|
import { HttpLink } from 'apollo-angular/http';
|
|
7
|
+
import { provideDaffApolloRequestHandlerFactories, DAFF_APOLLO_REQUEST_HANDLERS } from '@daffodil/core/graphql';
|
|
8
|
+
import { provideDaffDriverHttpClientCacheService, DaffDriverNetworkError } from '@daffodil/driver';
|
|
9
|
+
import { createSingleInjectionToken, createMultiInjectionToken, DaffInheritableError, daffIsError, DaffSortDirectionEnum } from '@daffodil/core';
|
|
7
10
|
import { isPlatformBrowser } from '@angular/common';
|
|
8
|
-
import { DaffInheritableError, daffIsError, createMultiInjectionToken, DaffSortDirectionEnum } from '@daffodil/core';
|
|
9
11
|
|
|
10
12
|
var possibleTypes = {
|
|
13
|
+
AggregationOptionInterface: [
|
|
14
|
+
"AggregationOption"
|
|
15
|
+
],
|
|
16
|
+
AttributeSelectedOptionInterface: [
|
|
17
|
+
"AttributeSelectedOption"
|
|
18
|
+
],
|
|
19
|
+
AttributeValueInterface: [
|
|
20
|
+
"AttributeSelectedOptions",
|
|
21
|
+
"AttributeValue"
|
|
22
|
+
],
|
|
11
23
|
CartAddressInterface: [
|
|
12
24
|
"BillingCartAddress",
|
|
13
25
|
"ShippingCartAddress"
|
|
14
26
|
],
|
|
15
27
|
CartItemInterface: [
|
|
16
|
-
"SimpleCartItem",
|
|
17
|
-
"VirtualCartItem",
|
|
18
|
-
"DownloadableCartItem",
|
|
19
28
|
"BundleCartItem",
|
|
20
|
-
"ConfigurableCartItem"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"SimpleProduct",
|
|
25
|
-
"DownloadableProduct",
|
|
26
|
-
"BundleProduct",
|
|
27
|
-
"GroupedProduct",
|
|
28
|
-
"ConfigurableProduct"
|
|
29
|
+
"ConfigurableCartItem",
|
|
30
|
+
"DownloadableCartItem",
|
|
31
|
+
"SimpleCartItem",
|
|
32
|
+
"VirtualCartItem"
|
|
29
33
|
],
|
|
30
34
|
CategoryInterface: [
|
|
31
35
|
"CategoryTree"
|
|
32
36
|
],
|
|
33
|
-
MediaGalleryInterface: [
|
|
34
|
-
"ProductImage",
|
|
35
|
-
"ProductVideo"
|
|
36
|
-
],
|
|
37
|
-
ProductLinksInterface: [
|
|
38
|
-
"ProductLinks"
|
|
39
|
-
],
|
|
40
37
|
CreditMemoItemInterface: [
|
|
41
|
-
"DownloadableCreditMemoItem",
|
|
42
38
|
"BundleCreditMemoItem",
|
|
43
|
-
"CreditMemoItem"
|
|
39
|
+
"CreditMemoItem",
|
|
40
|
+
"DownloadableCreditMemoItem"
|
|
44
41
|
],
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
42
|
+
CustomAttributeMetadataInterface: [
|
|
43
|
+
"AttributeMetadata",
|
|
44
|
+
"CatalogAttributeMetadata",
|
|
45
|
+
"CustomerAttributeMetadata"
|
|
46
|
+
],
|
|
47
|
+
CustomAttributeOptionInterface: [
|
|
48
|
+
"AttributeOptionMetadata"
|
|
49
|
+
],
|
|
50
|
+
CustomizableOptionInterface: [
|
|
51
|
+
"CustomizableAreaOption",
|
|
52
|
+
"CustomizableCheckboxOption",
|
|
53
|
+
"CustomizableDateOption",
|
|
54
|
+
"CustomizableDropDownOption",
|
|
55
|
+
"CustomizableFieldOption",
|
|
56
|
+
"CustomizableFileOption",
|
|
57
|
+
"CustomizableMultipleOption",
|
|
58
|
+
"CustomizableRadioOption"
|
|
59
|
+
],
|
|
60
|
+
CustomizableProductInterface: [
|
|
61
|
+
"BundleProduct",
|
|
62
|
+
"ConfigurableProduct",
|
|
63
|
+
"DownloadableProduct",
|
|
64
|
+
"SimpleProduct",
|
|
65
|
+
"VirtualProduct"
|
|
66
|
+
],
|
|
67
|
+
"Error": [
|
|
68
|
+
"CartUserInputError",
|
|
69
|
+
"InsufficientStockError"
|
|
70
|
+
],
|
|
71
|
+
ErrorInterface: [
|
|
72
|
+
"InternalError",
|
|
73
|
+
"NoSuchEntityUidError"
|
|
49
74
|
],
|
|
50
75
|
InvoiceItemInterface: [
|
|
51
|
-
"DownloadableInvoiceItem",
|
|
52
76
|
"BundleInvoiceItem",
|
|
77
|
+
"DownloadableInvoiceItem",
|
|
53
78
|
"InvoiceItem"
|
|
54
79
|
],
|
|
55
|
-
ShipmentItemInterface: [
|
|
56
|
-
"BundleShipmentItem",
|
|
57
|
-
"ShipmentItem"
|
|
58
|
-
],
|
|
59
|
-
AggregationOptionInterface: [
|
|
60
|
-
"AggregationOption"
|
|
61
|
-
],
|
|
62
80
|
LayerFilterItemInterface: [
|
|
63
81
|
"LayerFilterItem",
|
|
64
82
|
"SwatchLayerFilterItem"
|
|
65
83
|
],
|
|
84
|
+
MediaGalleryInterface: [
|
|
85
|
+
"ProductImage",
|
|
86
|
+
"ProductVideo"
|
|
87
|
+
],
|
|
88
|
+
OrderItemInterface: [
|
|
89
|
+
"BundleOrderItem",
|
|
90
|
+
"ConfigurableOrderItem",
|
|
91
|
+
"DownloadableOrderItem",
|
|
92
|
+
"OrderItem"
|
|
93
|
+
],
|
|
66
94
|
PhysicalProductInterface: [
|
|
67
|
-
"SimpleProduct",
|
|
68
95
|
"BundleProduct",
|
|
96
|
+
"ConfigurableProduct",
|
|
69
97
|
"GroupedProduct",
|
|
70
|
-
"
|
|
98
|
+
"SimpleProduct"
|
|
71
99
|
],
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"CustomizableDropDownOption",
|
|
76
|
-
"CustomizableMultipleOption",
|
|
77
|
-
"CustomizableFieldOption",
|
|
78
|
-
"CustomizableFileOption",
|
|
79
|
-
"CustomizableRadioOption",
|
|
80
|
-
"CustomizableCheckboxOption"
|
|
81
|
-
],
|
|
82
|
-
CustomizableProductInterface: [
|
|
83
|
-
"VirtualProduct",
|
|
84
|
-
"SimpleProduct",
|
|
100
|
+
ProductInterface: [
|
|
101
|
+
"BundleProduct",
|
|
102
|
+
"ConfigurableProduct",
|
|
85
103
|
"DownloadableProduct",
|
|
104
|
+
"GroupedProduct",
|
|
105
|
+
"SimpleProduct",
|
|
106
|
+
"VirtualProduct"
|
|
107
|
+
],
|
|
108
|
+
ProductLinksInterface: [
|
|
109
|
+
"ProductLinks"
|
|
110
|
+
],
|
|
111
|
+
RoutableInterface: [
|
|
86
112
|
"BundleProduct",
|
|
87
|
-
"
|
|
113
|
+
"CategoryTree",
|
|
114
|
+
"CmsPage",
|
|
115
|
+
"ConfigurableProduct",
|
|
116
|
+
"DownloadableProduct",
|
|
117
|
+
"GroupedProduct",
|
|
118
|
+
"RoutableUrl",
|
|
119
|
+
"SimpleProduct",
|
|
120
|
+
"VirtualProduct"
|
|
121
|
+
],
|
|
122
|
+
ShipmentItemInterface: [
|
|
123
|
+
"BundleShipmentItem",
|
|
124
|
+
"ShipmentItem"
|
|
88
125
|
],
|
|
89
126
|
SwatchDataInterface: [
|
|
127
|
+
"ColorSwatchData",
|
|
90
128
|
"ImageSwatchData",
|
|
91
|
-
"TextSwatchData"
|
|
92
|
-
"ColorSwatchData"
|
|
129
|
+
"TextSwatchData"
|
|
93
130
|
],
|
|
94
131
|
SwatchLayerFilterItemInterface: [
|
|
95
132
|
"SwatchLayerFilterItem"
|
|
133
|
+
],
|
|
134
|
+
WishlistItemInterface: [
|
|
135
|
+
"BundleWishlistItem",
|
|
136
|
+
"ConfigurableWishlistItem",
|
|
137
|
+
"DownloadableWishlistItem",
|
|
138
|
+
"GroupedProductWishlistItem",
|
|
139
|
+
"SimpleWishlistItem",
|
|
140
|
+
"VirtualWishlistItem"
|
|
96
141
|
]
|
|
97
142
|
};
|
|
98
143
|
var introspectionQueryResultData = {
|
|
99
144
|
possibleTypes: possibleTypes
|
|
100
145
|
};
|
|
101
146
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Creates an Apollo HTTP link for GraphQL requests.
|
|
106
|
-
*
|
|
107
|
-
* @param url - The Shopify Storefront API endpoint URL for GraphQL requests.
|
|
108
|
-
* @returns An ApolloLink instance configured with the provided URL.
|
|
109
|
-
*/
|
|
110
|
-
function createHttpLink(url) {
|
|
111
|
-
const httpLink = inject(HttpLink);
|
|
112
|
-
return httpLink.create({ uri: url });
|
|
113
|
-
}
|
|
114
|
-
|
|
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
|
-
};
|
|
147
|
+
const MAGENTO_POSSIBLE_TYPES = introspectionQueryResultData;
|
|
221
148
|
|
|
222
149
|
/**
|
|
223
150
|
* Custom type policies that allow us to have more granular control
|
|
@@ -515,96 +442,45 @@ const typePolicies = {
|
|
|
515
442
|
};
|
|
516
443
|
|
|
517
444
|
/**
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
* @inheritdoc
|
|
445
|
+
* A non-exhaustive list of feature kinds that exist for {@link provideMagentoDriver}.
|
|
521
446
|
*/
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
532
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, providedIn: 'root' }); }
|
|
533
|
-
}
|
|
534
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.1", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, decorators: [{
|
|
535
|
-
type: Injectable,
|
|
536
|
-
args: [{
|
|
537
|
-
providedIn: 'root',
|
|
538
|
-
}]
|
|
539
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
540
|
-
type: Inject,
|
|
541
|
-
args: [PLATFORM_ID]
|
|
542
|
-
}] }] });
|
|
447
|
+
var MagentoDriverFeatureKind;
|
|
448
|
+
(function (MagentoDriverFeatureKind) {
|
|
449
|
+
MagentoDriverFeatureKind["CacheableOperations"] = "DaffMagentoDriverCacheableOperationsFeature";
|
|
450
|
+
MagentoDriverFeatureKind["CacheHeader"] = "DaffMagentoDriverCacheHeaderFeature";
|
|
451
|
+
MagentoDriverFeatureKind["ErrorHandler"] = "DaffMagentoDriverErrorHandlerFeature";
|
|
452
|
+
MagentoDriverFeatureKind["TransferState"] = "DaffMagentoDriverTransferStateFeature";
|
|
453
|
+
MagentoDriverFeatureKind["ExtraApolloOptions"] = "DaffMagentoDriverExtraApolloOptionsFeature";
|
|
454
|
+
})(MagentoDriverFeatureKind || (MagentoDriverFeatureKind = {}));
|
|
543
455
|
|
|
544
456
|
/**
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* Under the hood, this creates an Apollo Client configuration.
|
|
548
|
-
*
|
|
549
|
-
* @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
|
|
457
|
+
* Creates a magento driver feature for {@link provideMagentoDriver}.
|
|
550
458
|
*/
|
|
551
|
-
function
|
|
552
|
-
|
|
553
|
-
typePolicies,
|
|
554
|
-
}) {
|
|
555
|
-
return [
|
|
556
|
-
provideApollo(() => ({
|
|
557
|
-
link: from([
|
|
558
|
-
createHttpLink(typeof endpoint === 'string' ? endpoint : inject(endpoint)),
|
|
559
|
-
]),
|
|
560
|
-
cache: new InMemoryCache({ typePolicies: options.typePolicies, possibleTypes: options.possibleTypes }),
|
|
561
|
-
})),
|
|
562
|
-
provideDaffDriverHttpClientCacheService(DaffDriverHttpClientCacheMagentoService),
|
|
563
|
-
];
|
|
459
|
+
function makeMagentoDriverFeature(kind, providers) {
|
|
460
|
+
return { ɵkind: kind, ɵproviders: providers };
|
|
564
461
|
}
|
|
565
462
|
|
|
566
|
-
const
|
|
463
|
+
const {
|
|
567
464
|
/**
|
|
568
|
-
* A
|
|
465
|
+
* A token to hold {@link DaffDriverMagentoExtraApolloOptions}.
|
|
569
466
|
*/
|
|
570
|
-
|
|
571
|
-
constructor(message) {
|
|
572
|
-
super(message);
|
|
573
|
-
this.code = DAFF_DRIVER_MAGENTO_ERROR_CODE;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
function daffMagentoTransformGraphQlError(error, map) {
|
|
578
|
-
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;
|
|
579
|
-
return new ErrorClass(error.message);
|
|
580
|
-
}
|
|
581
|
-
;
|
|
582
|
-
|
|
467
|
+
token: DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS,
|
|
583
468
|
/**
|
|
584
|
-
*
|
|
469
|
+
* A provider for {@link DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS}.
|
|
585
470
|
*/
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
;
|
|
602
|
-
|
|
603
|
-
var MagentoSortEnum;
|
|
604
|
-
(function (MagentoSortEnum) {
|
|
605
|
-
MagentoSortEnum["ASC"] = "ASC";
|
|
606
|
-
MagentoSortEnum["DESC"] = "DESC";
|
|
607
|
-
})(MagentoSortEnum || (MagentoSortEnum = {}));
|
|
471
|
+
provider: provideDaffDriverMagentoExtraApolloOptions,
|
|
472
|
+
/**
|
|
473
|
+
* A factory provider for {@link DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS}.
|
|
474
|
+
*/
|
|
475
|
+
factoryProvider: provideDaffDriverMagentoExtraApolloOptionsFactory, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS', {
|
|
476
|
+
factory: () => ({}),
|
|
477
|
+
});
|
|
478
|
+
/**
|
|
479
|
+
* A {@link provideMagentoDriver} feature that allow specifying {@link DaffDriverMagentoExtraApolloOptions}.
|
|
480
|
+
*/
|
|
481
|
+
const withDaffDriverMagentoExtraApolloOptions = (options) => makeMagentoDriverFeature(MagentoDriverFeatureKind.TransferState, [
|
|
482
|
+
provideDaffDriverMagentoExtraApolloOptions(options),
|
|
483
|
+
]);
|
|
608
484
|
|
|
609
485
|
const {
|
|
610
486
|
/**
|
|
@@ -629,10 +505,25 @@ function provideDaffMagentoCacheableOperation(operationName) {
|
|
|
629
505
|
};
|
|
630
506
|
}
|
|
631
507
|
|
|
508
|
+
/**
|
|
509
|
+
* A request handler provider that will convert cacheable apollo operations into a format that Magento will understand as cacheable.
|
|
510
|
+
*/
|
|
511
|
+
const provideDaffMagentoApolloCacheableOperations = () => makeEnvironmentProviders([
|
|
512
|
+
provideDaffApolloRequestHandlerFactories(() => {
|
|
513
|
+
const cacheableOperations = inject(DAFF_MAGENTO_CACHEABLE_OPERATIONS);
|
|
514
|
+
return (operation, forward) => {
|
|
515
|
+
if (cacheableOperations.indexOf(operation.operationName) > -1) {
|
|
516
|
+
operation.setContext({ method: 'GET' });
|
|
517
|
+
}
|
|
518
|
+
return forward(operation);
|
|
519
|
+
};
|
|
520
|
+
}),
|
|
521
|
+
]);
|
|
632
522
|
/**
|
|
633
523
|
* A service that will convert cacheable apollo operations into a format that Magento will understand as cacheable.
|
|
634
524
|
*
|
|
635
525
|
* @inheritdoc
|
|
526
|
+
* @deprecated Prefer using {@link provideDaffMagentoApolloCacheableOperations} instead. Deprecated in version 0.91.0. Will be removed in version 0.94.0.
|
|
636
527
|
*/
|
|
637
528
|
class DaffMagentoApolloCacheableOperationsLinkGenerator {
|
|
638
529
|
constructor(apolloGetRequests) {
|
|
@@ -646,10 +537,10 @@ class DaffMagentoApolloCacheableOperationsLinkGenerator {
|
|
|
646
537
|
return forward(operation);
|
|
647
538
|
});
|
|
648
539
|
}
|
|
649
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.
|
|
650
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.
|
|
540
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffMagentoApolloCacheableOperationsLinkGenerator, deps: [{ token: DAFF_MAGENTO_CACHEABLE_OPERATIONS }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
541
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffMagentoApolloCacheableOperationsLinkGenerator, providedIn: 'root' }); }
|
|
651
542
|
}
|
|
652
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.
|
|
543
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffMagentoApolloCacheableOperationsLinkGenerator, decorators: [{
|
|
653
544
|
type: Injectable,
|
|
654
545
|
args: [{
|
|
655
546
|
providedIn: 'root',
|
|
@@ -885,13 +776,68 @@ const DAFF_MAGENTO_2_4_3_TYPE_POLICIES = {
|
|
|
885
776
|
},
|
|
886
777
|
};
|
|
887
778
|
|
|
779
|
+
/**
|
|
780
|
+
* Interacts with the Apollo client.
|
|
781
|
+
*
|
|
782
|
+
* @inheritdoc
|
|
783
|
+
*/
|
|
784
|
+
class DaffDriverHttpClientCacheMagentoService {
|
|
785
|
+
constructor(platformId) {
|
|
786
|
+
this.platformId = platformId;
|
|
787
|
+
}
|
|
788
|
+
reset() {
|
|
789
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
790
|
+
location.reload();
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
794
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, providedIn: 'root' }); }
|
|
795
|
+
}
|
|
796
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, decorators: [{
|
|
797
|
+
type: Injectable,
|
|
798
|
+
args: [{
|
|
799
|
+
providedIn: 'root',
|
|
800
|
+
}]
|
|
801
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
802
|
+
type: Inject,
|
|
803
|
+
args: [PLATFORM_ID]
|
|
804
|
+
}] }] });
|
|
805
|
+
|
|
888
806
|
const MAGENTO_CUSTOMER_CACHE_ID_HEADER = 'X-Magento-Cache-Id';
|
|
807
|
+
/**
|
|
808
|
+
* Stores and sets the Magento cache ID header.
|
|
809
|
+
* This will set the `X-Magento-Cache-Id` header from the most recent value encountered
|
|
810
|
+
* on a response, if there was a response with that header set.
|
|
811
|
+
*/
|
|
812
|
+
const provideDaffMagentoCacheHeader = () => makeEnvironmentProviders([
|
|
813
|
+
provideDaffApolloRequestHandlerFactories(() => {
|
|
814
|
+
let cacheHeader;
|
|
815
|
+
return (operation, forward) => {
|
|
816
|
+
if (cacheHeader) {
|
|
817
|
+
operation.setContext({
|
|
818
|
+
headers: {
|
|
819
|
+
...operation.getContext().headers,
|
|
820
|
+
[MAGENTO_CUSTOMER_CACHE_ID_HEADER]: cacheHeader,
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
return forward(operation).map((response) => {
|
|
825
|
+
const { headers } = operation.getContext().response;
|
|
826
|
+
if (headers.get(MAGENTO_CUSTOMER_CACHE_ID_HEADER)) {
|
|
827
|
+
cacheHeader = headers.get(MAGENTO_CUSTOMER_CACHE_ID_HEADER);
|
|
828
|
+
}
|
|
829
|
+
return response;
|
|
830
|
+
});
|
|
831
|
+
};
|
|
832
|
+
}),
|
|
833
|
+
]);
|
|
889
834
|
/**
|
|
890
835
|
* Stores and sets the Magento cache ID header.
|
|
891
836
|
* This will set the `X-Magento-Cache-Id` header from the most recent value encountered
|
|
892
837
|
* on a response, if there was a response with that header set.
|
|
893
838
|
*
|
|
894
839
|
* @inheritdoc
|
|
840
|
+
* @deprecated Prefer using {@link provideDaffMagentoCacheHeader} instead. Deprecated in version 0.91.0. Will be removed in version 0.94.0.
|
|
895
841
|
*/
|
|
896
842
|
class DaffMagentoCacheHeaderApolloLinkGenerator {
|
|
897
843
|
getLink() {
|
|
@@ -913,16 +859,167 @@ class DaffMagentoCacheHeaderApolloLinkGenerator {
|
|
|
913
859
|
});
|
|
914
860
|
});
|
|
915
861
|
}
|
|
916
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.
|
|
917
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.
|
|
862
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffMagentoCacheHeaderApolloLinkGenerator, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
863
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffMagentoCacheHeaderApolloLinkGenerator, providedIn: 'root' }); }
|
|
918
864
|
}
|
|
919
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.
|
|
865
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DaffMagentoCacheHeaderApolloLinkGenerator, decorators: [{
|
|
920
866
|
type: Injectable,
|
|
921
867
|
args: [{
|
|
922
868
|
providedIn: 'root',
|
|
923
869
|
}]
|
|
924
870
|
}] });
|
|
925
871
|
|
|
872
|
+
/**
|
|
873
|
+
* A {@link provideMagentoDriver} feature that sets up {@link provideDaffMagentoApolloCacheableOperations}.
|
|
874
|
+
*/
|
|
875
|
+
const withOperationCache = (...extraOperations) => makeMagentoDriverFeature(MagentoDriverFeatureKind.CacheableOperations, [
|
|
876
|
+
provideDaffMagentoApolloCacheableOperations(),
|
|
877
|
+
makeEnvironmentProviders(provideManyDaffMagentoCacheableOperations(...extraOperations)),
|
|
878
|
+
]);
|
|
879
|
+
|
|
880
|
+
const {
|
|
881
|
+
/**
|
|
882
|
+
* Holds the error handler for {@link provideMagentoDriver}.
|
|
883
|
+
*/
|
|
884
|
+
token: DAFF_DRIVER_MAGENTO_ERROR_HANDLER,
|
|
885
|
+
/**
|
|
886
|
+
* Provider function for {@link DAFF_DRIVER_MAGENTO_ERROR_HANDLER}.
|
|
887
|
+
*/
|
|
888
|
+
provider: provideDaffDriverMagentoErrorHandler, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_ERROR_HANDLER', {
|
|
889
|
+
factory: () => ({ graphQLErrors, networkError }) => {
|
|
890
|
+
if (graphQLErrors) {
|
|
891
|
+
graphQLErrors.map(({ message, locations, path }) => console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
|
|
892
|
+
}
|
|
893
|
+
if (networkError) {
|
|
894
|
+
console.error(`[Network error]: ${networkError}`);
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
});
|
|
898
|
+
/**
|
|
899
|
+
* A {@link provideMagentoDriver} feature that specifies the error handler.
|
|
900
|
+
*/
|
|
901
|
+
const withDaffDriverMagentoErrorHandler = (handler) => makeMagentoDriverFeature(MagentoDriverFeatureKind.ErrorHandler, [
|
|
902
|
+
provideDaffDriverMagentoErrorHandler(handler),
|
|
903
|
+
]);
|
|
904
|
+
|
|
905
|
+
const {
|
|
906
|
+
/**
|
|
907
|
+
* Holds the `StateKey` with which {@link provideMagentoDriver} can use to transfer Apollo state from the server to the client.
|
|
908
|
+
*/
|
|
909
|
+
token: DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY,
|
|
910
|
+
/**
|
|
911
|
+
* Provider for {@link DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY}.
|
|
912
|
+
*/
|
|
913
|
+
provider: provideDaffDriverMagentoTransferStateKey, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY');
|
|
914
|
+
/**
|
|
915
|
+
* A {@link provideMagentoDriver} feature that sets up transfer state with the specified key.
|
|
916
|
+
*
|
|
917
|
+
* @param stateKey The key under which the Apollo state is stored.
|
|
918
|
+
*/
|
|
919
|
+
const withDaffDriverMagentoTransferState = (stateKey) => makeMagentoDriverFeature(MagentoDriverFeatureKind.TransferState, [
|
|
920
|
+
provideDaffDriverMagentoTransferStateKey(stateKey),
|
|
921
|
+
]);
|
|
922
|
+
/**
|
|
923
|
+
* Holds the logic for hydrating the Apollo cache with the server's transferred state.
|
|
924
|
+
* It is recommended to use {@link withDaffDriverMagentoTransferState} with {@link provideMagentoDriver}
|
|
925
|
+
* to provide this functionality automatically.
|
|
926
|
+
*/
|
|
927
|
+
const provideDaffDriverMagentoTransferState = () => makeEnvironmentProviders([
|
|
928
|
+
provideAppInitializer(() => {
|
|
929
|
+
const cache = inject(Apollo).client.cache;
|
|
930
|
+
const transferState = inject(TransferState);
|
|
931
|
+
const stateKey = inject(DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY);
|
|
932
|
+
const hasStateKey = transferState.hasKey(stateKey);
|
|
933
|
+
if (hasStateKey) {
|
|
934
|
+
const state = transferState.get(stateKey, null);
|
|
935
|
+
cache.restore(state);
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
transferState.onSerialize(stateKey, () => cache.extract());
|
|
939
|
+
}
|
|
940
|
+
}),
|
|
941
|
+
]);
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Sets up the Magento Daffodil driver configuration for Magento's GraphQl API.
|
|
945
|
+
*
|
|
946
|
+
* Under the hood, this creates an Apollo Client configuration.
|
|
947
|
+
*
|
|
948
|
+
* @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
|
|
949
|
+
*/
|
|
950
|
+
function provideMagentoDriver(options, ...features) {
|
|
951
|
+
const providers = [
|
|
952
|
+
...features.flatMap(({ ɵproviders }) => ɵproviders),
|
|
953
|
+
provideApollo(() => {
|
|
954
|
+
const opts = {
|
|
955
|
+
possibleTypes: MAGENTO_POSSIBLE_TYPES.possibleTypes,
|
|
956
|
+
typePolicies,
|
|
957
|
+
...(options instanceof InjectionToken ? inject(options) : options),
|
|
958
|
+
};
|
|
959
|
+
return {
|
|
960
|
+
...inject(DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS),
|
|
961
|
+
link: from([
|
|
962
|
+
...inject(DAFF_APOLLO_REQUEST_HANDLERS),
|
|
963
|
+
onError(inject(DAFF_DRIVER_MAGENTO_ERROR_HANDLER)),
|
|
964
|
+
inject(HttpLink).create(opts),
|
|
965
|
+
]),
|
|
966
|
+
cache: new InMemoryCache({ typePolicies: opts.typePolicies, possibleTypes: opts.possibleTypes }),
|
|
967
|
+
};
|
|
968
|
+
}),
|
|
969
|
+
provideDaffDriverHttpClientCacheService(DaffDriverHttpClientCacheMagentoService),
|
|
970
|
+
// enable caching by default
|
|
971
|
+
provideDaffMagentoApolloCacheableOperations(),
|
|
972
|
+
provideDaffMagentoCacheHeader(),
|
|
973
|
+
];
|
|
974
|
+
if (features.find(({ ɵkind }) => ɵkind === MagentoDriverFeatureKind.TransferState)) {
|
|
975
|
+
providers.push(provideDaffDriverMagentoTransferState());
|
|
976
|
+
}
|
|
977
|
+
return makeEnvironmentProviders(providers);
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
const DAFF_DRIVER_MAGENTO_ERROR_CODE = 'DAFF_DRIVER_MAGENTO_ERROR';
|
|
981
|
+
/**
|
|
982
|
+
* A very general error thrown when a more specific error type cannot be determined.
|
|
983
|
+
*/
|
|
984
|
+
class DaffDriverMagentoError extends DaffInheritableError {
|
|
985
|
+
constructor(message) {
|
|
986
|
+
super(message);
|
|
987
|
+
this.code = DAFF_DRIVER_MAGENTO_ERROR_CODE;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function daffMagentoTransformGraphQlError(error, map) {
|
|
992
|
+
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;
|
|
993
|
+
return new ErrorClass(error.message);
|
|
994
|
+
}
|
|
995
|
+
;
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Transforms the passed error according to the lookup in the passed map.
|
|
999
|
+
*/
|
|
1000
|
+
// TODO: return array of errors
|
|
1001
|
+
function daffTransformMagentoError(error, map) {
|
|
1002
|
+
if (error.graphQLErrors?.length > 0) {
|
|
1003
|
+
return error.graphQLErrors.map(err => daffMagentoTransformGraphQlError(err, map))[0];
|
|
1004
|
+
}
|
|
1005
|
+
else if (error.networkError) {
|
|
1006
|
+
return new DaffDriverNetworkError(error.networkError.message);
|
|
1007
|
+
}
|
|
1008
|
+
else if (daffIsError(error)) {
|
|
1009
|
+
return error;
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
return new DaffDriverMagentoError(error.message);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
;
|
|
1016
|
+
|
|
1017
|
+
var MagentoSortEnum;
|
|
1018
|
+
(function (MagentoSortEnum) {
|
|
1019
|
+
MagentoSortEnum["ASC"] = "ASC";
|
|
1020
|
+
MagentoSortEnum["DESC"] = "DESC";
|
|
1021
|
+
})(MagentoSortEnum || (MagentoSortEnum = {}));
|
|
1022
|
+
|
|
926
1023
|
function magentoPageInfoTransform(pageInfo) {
|
|
927
1024
|
return {
|
|
928
1025
|
pageSize: pageInfo.page_size,
|
|
@@ -962,28 +1059,9 @@ const magentoMoneyFragment = gql `
|
|
|
962
1059
|
}
|
|
963
1060
|
`;
|
|
964
1061
|
|
|
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
1062
|
/**
|
|
985
1063
|
* Generated bundle index. Do not edit.
|
|
986
1064
|
*/
|
|
987
1065
|
|
|
988
|
-
export { DAFF_DRIVER_MAGENTO_ERROR_CODE, DAFF_MAGENTO_2_4_3_TYPE_POLICIES, DAFF_MAGENTO_CACHEABLE_OPERATIONS, DaffDriverHttpClientCacheMagentoService, DaffDriverMagentoError,
|
|
1066
|
+
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, provideDaffDriverMagentoExtraApolloOptionsFactory, provideDaffDriverMagentoTransferState, provideDaffDriverMagentoTransferStateKey, provideDaffMagentoApolloCacheableOperations, provideDaffMagentoCacheHeader, provideDaffMagentoCacheableOperation, provideMagentoDriver, provideManyDaffMagentoCacheableOperations, MAGENTO_POSSIBLE_TYPES as schema, withDaffDriverMagentoErrorHandler, withDaffDriverMagentoExtraApolloOptions, withDaffDriverMagentoTransferState, withOperationCache };
|
|
989
1067
|
//# sourceMappingURL=daffodil-driver-magento.mjs.map
|