@daffodil/driver 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-driver-hubspot-testing.mjs +53 -38
- package/fesm2022/daffodil-driver-hubspot-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-hubspot.mjs +41 -60
- package/fesm2022/daffodil-driver-hubspot.mjs.map +1 -1
- package/fesm2022/daffodil-driver-in-memory.mjs +186 -258
- package/fesm2022/daffodil-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-driver-magento-2.4.7-testing.mjs +139 -0
- package/fesm2022/daffodil-driver-magento-2.4.7-testing.mjs.map +1 -0
- package/fesm2022/daffodil-driver-magento-2.4.7.mjs +543 -0
- package/fesm2022/daffodil-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-driver-magento-auto-testing.mjs +7 -0
- package/fesm2022/daffodil-driver-magento-auto-testing.mjs.map +1 -0
- package/fesm2022/daffodil-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-driver-shopify-testing.mjs +359 -216
- package/fesm2022/daffodil-driver-shopify-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-shopify.mjs +1090 -2289
- package/fesm2022/daffodil-driver-shopify.mjs.map +1 -1
- package/fesm2022/daffodil-driver.mjs +55 -54
- package/fesm2022/daffodil-driver.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-driver-hubspot-testing.d.ts +12 -15
- package/types/daffodil-driver-hubspot.d.ts +44 -52
- package/types/daffodil-driver-in-memory.d.ts +104 -121
- package/types/daffodil-driver-magento-2.4.7-testing.d.ts +18 -0
- package/types/daffodil-driver-magento-2.4.7.d.ts +189 -0
- package/types/daffodil-driver-magento-auto-testing.d.ts +1 -0
- package/types/daffodil-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-driver-shopify-testing.d.ts +112 -121
- package/types/daffodil-driver-shopify.d.ts +6902 -6943
- package/types/daffodil-driver.d.ts +32 -42
- package/fesm2022/daffodil-driver-magento-testing.mjs +0 -79
- package/fesm2022/daffodil-driver-magento-testing.mjs.map +0 -1
- package/fesm2022/daffodil-driver-magento.mjs +0 -998
- package/fesm2022/daffodil-driver-magento.mjs.map +0 -1
- package/types/daffodil-driver-magento-testing.d.ts +0 -23
- package/types/daffodil-driver-magento.d.ts +0 -225
|
@@ -1,998 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { makeEnvironmentProviders, inject, PLATFORM_ID, Inject, Injectable, provideAppInitializer, TransferState, InjectionToken } from '@angular/core';
|
|
3
|
-
import { InMemoryCache, ApolloLink } from '@apollo/client/core';
|
|
4
|
-
import { ErrorLink } from '@apollo/client/link/error';
|
|
5
|
-
import { Apollo, provideApollo, gql } from 'apollo-angular';
|
|
6
|
-
import { HttpLink } from 'apollo-angular/http';
|
|
7
|
-
import { provideDaffApolloRequestHandlerFactories, getApolloOperationHeaders, DAFF_APOLLO_REQUEST_HANDLERS } from '@daffodil/core/graphql';
|
|
8
|
-
import { provideDaffDriverHttpClientCacheService } from '@daffodil/driver';
|
|
9
|
-
import { createSingleInjectionToken, createMultiInjectionToken, DaffInheritableError, daffIsError, DaffSortDirectionEnum } from '@daffodil/core';
|
|
10
|
-
import { isPlatformBrowser } from '@angular/common';
|
|
11
|
-
import { map as map$2 } from 'rxjs';
|
|
12
|
-
import { CombinedGraphQLErrors } from '@apollo/client';
|
|
13
|
-
|
|
14
|
-
var possibleTypes = {
|
|
15
|
-
AggregationOptionInterface: [
|
|
16
|
-
"AggregationOption"
|
|
17
|
-
],
|
|
18
|
-
AttributeSelectedOptionInterface: [
|
|
19
|
-
"AttributeSelectedOption"
|
|
20
|
-
],
|
|
21
|
-
AttributeValueInterface: [
|
|
22
|
-
"AttributeSelectedOptions",
|
|
23
|
-
"AttributeValue"
|
|
24
|
-
],
|
|
25
|
-
CartAddressInterface: [
|
|
26
|
-
"BillingCartAddress",
|
|
27
|
-
"ShippingCartAddress"
|
|
28
|
-
],
|
|
29
|
-
CartItemInterface: [
|
|
30
|
-
"BundleCartItem",
|
|
31
|
-
"ConfigurableCartItem",
|
|
32
|
-
"DownloadableCartItem",
|
|
33
|
-
"SimpleCartItem",
|
|
34
|
-
"VirtualCartItem"
|
|
35
|
-
],
|
|
36
|
-
CategoryInterface: [
|
|
37
|
-
"CategoryTree"
|
|
38
|
-
],
|
|
39
|
-
CreditMemoItemInterface: [
|
|
40
|
-
"BundleCreditMemoItem",
|
|
41
|
-
"CreditMemoItem",
|
|
42
|
-
"DownloadableCreditMemoItem"
|
|
43
|
-
],
|
|
44
|
-
CustomAttributeMetadataInterface: [
|
|
45
|
-
"AttributeMetadata",
|
|
46
|
-
"CatalogAttributeMetadata",
|
|
47
|
-
"CustomerAttributeMetadata"
|
|
48
|
-
],
|
|
49
|
-
CustomAttributeOptionInterface: [
|
|
50
|
-
"AttributeOptionMetadata"
|
|
51
|
-
],
|
|
52
|
-
CustomizableOptionInterface: [
|
|
53
|
-
"CustomizableAreaOption",
|
|
54
|
-
"CustomizableCheckboxOption",
|
|
55
|
-
"CustomizableDateOption",
|
|
56
|
-
"CustomizableDropDownOption",
|
|
57
|
-
"CustomizableFieldOption",
|
|
58
|
-
"CustomizableFileOption",
|
|
59
|
-
"CustomizableMultipleOption",
|
|
60
|
-
"CustomizableRadioOption"
|
|
61
|
-
],
|
|
62
|
-
CustomizableProductInterface: [
|
|
63
|
-
"BundleProduct",
|
|
64
|
-
"ConfigurableProduct",
|
|
65
|
-
"DownloadableProduct",
|
|
66
|
-
"SimpleProduct",
|
|
67
|
-
"VirtualProduct"
|
|
68
|
-
],
|
|
69
|
-
"Error": [
|
|
70
|
-
"CartUserInputError",
|
|
71
|
-
"InsufficientStockError"
|
|
72
|
-
],
|
|
73
|
-
ErrorInterface: [
|
|
74
|
-
"InternalError",
|
|
75
|
-
"NoSuchEntityUidError"
|
|
76
|
-
],
|
|
77
|
-
InvoiceItemInterface: [
|
|
78
|
-
"BundleInvoiceItem",
|
|
79
|
-
"DownloadableInvoiceItem",
|
|
80
|
-
"InvoiceItem"
|
|
81
|
-
],
|
|
82
|
-
LayerFilterItemInterface: [
|
|
83
|
-
"LayerFilterItem",
|
|
84
|
-
"SwatchLayerFilterItem"
|
|
85
|
-
],
|
|
86
|
-
MediaGalleryInterface: [
|
|
87
|
-
"ProductImage",
|
|
88
|
-
"ProductVideo"
|
|
89
|
-
],
|
|
90
|
-
OrderItemInterface: [
|
|
91
|
-
"BundleOrderItem",
|
|
92
|
-
"ConfigurableOrderItem",
|
|
93
|
-
"DownloadableOrderItem",
|
|
94
|
-
"OrderItem"
|
|
95
|
-
],
|
|
96
|
-
PhysicalProductInterface: [
|
|
97
|
-
"BundleProduct",
|
|
98
|
-
"ConfigurableProduct",
|
|
99
|
-
"GroupedProduct",
|
|
100
|
-
"SimpleProduct"
|
|
101
|
-
],
|
|
102
|
-
ProductInterface: [
|
|
103
|
-
"BundleProduct",
|
|
104
|
-
"ConfigurableProduct",
|
|
105
|
-
"DownloadableProduct",
|
|
106
|
-
"GroupedProduct",
|
|
107
|
-
"SimpleProduct",
|
|
108
|
-
"VirtualProduct"
|
|
109
|
-
],
|
|
110
|
-
ProductLinksInterface: [
|
|
111
|
-
"ProductLinks"
|
|
112
|
-
],
|
|
113
|
-
RoutableInterface: [
|
|
114
|
-
"BundleProduct",
|
|
115
|
-
"CategoryTree",
|
|
116
|
-
"CmsPage",
|
|
117
|
-
"ConfigurableProduct",
|
|
118
|
-
"DownloadableProduct",
|
|
119
|
-
"GroupedProduct",
|
|
120
|
-
"RoutableUrl",
|
|
121
|
-
"SimpleProduct",
|
|
122
|
-
"VirtualProduct"
|
|
123
|
-
],
|
|
124
|
-
ShipmentItemInterface: [
|
|
125
|
-
"BundleShipmentItem",
|
|
126
|
-
"ShipmentItem"
|
|
127
|
-
],
|
|
128
|
-
SwatchDataInterface: [
|
|
129
|
-
"ColorSwatchData",
|
|
130
|
-
"ImageSwatchData",
|
|
131
|
-
"TextSwatchData"
|
|
132
|
-
],
|
|
133
|
-
SwatchLayerFilterItemInterface: [
|
|
134
|
-
"SwatchLayerFilterItem"
|
|
135
|
-
],
|
|
136
|
-
WishlistItemInterface: [
|
|
137
|
-
"BundleWishlistItem",
|
|
138
|
-
"ConfigurableWishlistItem",
|
|
139
|
-
"DownloadableWishlistItem",
|
|
140
|
-
"GroupedProductWishlistItem",
|
|
141
|
-
"SimpleWishlistItem",
|
|
142
|
-
"VirtualWishlistItem"
|
|
143
|
-
]
|
|
144
|
-
};
|
|
145
|
-
var introspectionQueryResultData = {
|
|
146
|
-
possibleTypes: possibleTypes
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const MAGENTO_POSSIBLE_TYPES = introspectionQueryResultData;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Custom type policies that allow us to have more granular control
|
|
153
|
-
* over how ApolloClient reads from and writes to the cache.
|
|
154
|
-
*
|
|
155
|
-
* https://www.apollographql.com/docs/react/caching/cache-configuration/#typepolicy-fields
|
|
156
|
-
* https://www.apollographql.com/docs/react/caching/cache-field-behavior/
|
|
157
|
-
*/
|
|
158
|
-
const typePolicies = {
|
|
159
|
-
// Query/Mutation are "types" just like "Cart".
|
|
160
|
-
Query: {
|
|
161
|
-
fields: {
|
|
162
|
-
cart: {
|
|
163
|
-
// Replaces @connection(key: "Cart")
|
|
164
|
-
keyArgs: () => 'Cart',
|
|
165
|
-
},
|
|
166
|
-
customer: {
|
|
167
|
-
keyArgs: () => 'Customer',
|
|
168
|
-
},
|
|
169
|
-
customerCart: {
|
|
170
|
-
keyArgs: () => 'Cart',
|
|
171
|
-
},
|
|
172
|
-
customerWishlistProducts: {
|
|
173
|
-
read: existing => existing || [],
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
AppliedGiftCard: {
|
|
178
|
-
keyFields: ['code'],
|
|
179
|
-
},
|
|
180
|
-
AvailablePaymentMethod: {
|
|
181
|
-
keyFields: ['code'],
|
|
182
|
-
},
|
|
183
|
-
AvailableShippingMethod: {
|
|
184
|
-
// The combination of these fields makes an instance of
|
|
185
|
-
// AvailableShippingMethod unique.
|
|
186
|
-
keyFields: ['carrier_code', 'method_code'],
|
|
187
|
-
},
|
|
188
|
-
Breadcrumb: {
|
|
189
|
-
// Uses provided fields on the object as the `uid`.
|
|
190
|
-
keyFields: ['category_uid'],
|
|
191
|
-
},
|
|
192
|
-
Cart: {
|
|
193
|
-
keyFields: () => 'Cart',
|
|
194
|
-
fields: {
|
|
195
|
-
applied_gift_cards: {
|
|
196
|
-
merge(existing, incoming) {
|
|
197
|
-
return incoming;
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
available_payment_methods: {
|
|
201
|
-
merge(existing, incoming) {
|
|
202
|
-
return incoming;
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
items: {
|
|
206
|
-
merge(existing, incoming) {
|
|
207
|
-
return incoming;
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
prices: {
|
|
211
|
-
// `merge: true` can be used for an object field.
|
|
212
|
-
merge: true,
|
|
213
|
-
},
|
|
214
|
-
shipping_addresses: {
|
|
215
|
-
merge(existing = [], incoming, { readField, mergeObjects }) {
|
|
216
|
-
// street makes these things unique
|
|
217
|
-
const mergeResult = new Set();
|
|
218
|
-
const streetToIndex = new Map();
|
|
219
|
-
existing.forEach((existingShippingAddress, index) => {
|
|
220
|
-
// Use readField instead of existingShippingAddress.street directly because it will follow cache references.
|
|
221
|
-
const street = readField('street', existingShippingAddress);
|
|
222
|
-
streetToIndex.set(street, index);
|
|
223
|
-
});
|
|
224
|
-
incoming.forEach(incomingShippingAddress => {
|
|
225
|
-
const street = readField('street', incomingShippingAddress);
|
|
226
|
-
if (streetToIndex.has(street)) {
|
|
227
|
-
const targetIndex = streetToIndex.get(street);
|
|
228
|
-
const existingShippingAddress = existing[targetIndex];
|
|
229
|
-
const merged = mergeObjects(existingShippingAddress, incomingShippingAddress);
|
|
230
|
-
mergeResult.add(merged);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
// We do not have an address with this street yet, add it on to the end.
|
|
234
|
-
streetToIndex.set(street, streetToIndex.size);
|
|
235
|
-
mergeResult.add(incomingShippingAddress);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
return Array.from(mergeResult);
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
Customer: {
|
|
244
|
-
keyFields: () => 'Customer',
|
|
245
|
-
merge: true,
|
|
246
|
-
fields: {
|
|
247
|
-
addresses: {
|
|
248
|
-
merge(existing, incoming) {
|
|
249
|
-
return incoming;
|
|
250
|
-
},
|
|
251
|
-
read(cachedAddresses, { toReference }) {
|
|
252
|
-
if (cachedAddresses) {
|
|
253
|
-
return cachedAddresses.map(address => {
|
|
254
|
-
// Update v2 identifiers to new references. Previous
|
|
255
|
-
// entries had `id: CustomerAddress:1` which caused
|
|
256
|
-
// v3's lookup to fail. If we find a legacy id,
|
|
257
|
-
// point it at the object using a reference.
|
|
258
|
-
if (address.id &&
|
|
259
|
-
address.id.includes('CustomerAddress')) {
|
|
260
|
-
return toReference(address.id);
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
return address;
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
// If there are no cached addresses that's fine - the schema
|
|
268
|
-
// shows that it is a nullable field.
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
orders: {
|
|
272
|
-
keyArgs: ['filter'],
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
CustomerAddress: {
|
|
277
|
-
fields: {
|
|
278
|
-
street: {
|
|
279
|
-
merge(existing, incoming) {
|
|
280
|
-
return incoming;
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
CustomerPaymentTokens: {
|
|
286
|
-
keyFields: () => 'CustomerPaymentTokens',
|
|
287
|
-
fields: {
|
|
288
|
-
items: {
|
|
289
|
-
merge(existing, incoming) {
|
|
290
|
-
return incoming;
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
Currency: {
|
|
296
|
-
merge: true,
|
|
297
|
-
},
|
|
298
|
-
ProductImage: {
|
|
299
|
-
keyFields: ['url'],
|
|
300
|
-
},
|
|
301
|
-
ConfigurableProductOptions: {
|
|
302
|
-
keyFields: ['uid'],
|
|
303
|
-
},
|
|
304
|
-
SelectedConfigurableOption: {
|
|
305
|
-
// id alone is not enough to identify a selected option as it can refer
|
|
306
|
-
// to something like "size" where value_id refers to "large".
|
|
307
|
-
// TODO: Use configurable_product_option_uid for ConfigurableWishlistItem when available in 2.4.5
|
|
308
|
-
keyFields: fields => fields.configurable_product_option_uid
|
|
309
|
-
? [
|
|
310
|
-
'configurable_product_option_uid',
|
|
311
|
-
'configurable_product_option_value_uid',
|
|
312
|
-
]
|
|
313
|
-
: ['id', 'value_id'],
|
|
314
|
-
},
|
|
315
|
-
SelectedPaymentMethod: {
|
|
316
|
-
keyFields: ['code'],
|
|
317
|
-
},
|
|
318
|
-
ShippingCartAddress: {
|
|
319
|
-
keyFields: ['street'],
|
|
320
|
-
fields: {
|
|
321
|
-
available_shipping_methods: {
|
|
322
|
-
merge(existing = [], incoming, { readField, mergeObjects }) {
|
|
323
|
-
// carrier_code + method_code makes these things unique
|
|
324
|
-
const mergeResult = new Set();
|
|
325
|
-
const carrierToIndex = new Map();
|
|
326
|
-
existing.forEach((existingShippingMethod, index) => {
|
|
327
|
-
// Use readField because it will follow cache references.
|
|
328
|
-
const carrierCode = readField('carrier_code', existingShippingMethod);
|
|
329
|
-
const methodCode = readField('method_code', existingShippingMethod);
|
|
330
|
-
const carrierKey = `${carrierCode}|${methodCode}`;
|
|
331
|
-
carrierToIndex.set(carrierKey, index);
|
|
332
|
-
});
|
|
333
|
-
incoming.forEach(incomingShippingMethod => {
|
|
334
|
-
// Use readField because it will follow cache references.
|
|
335
|
-
const carrierCode = readField('carrier_code', incomingShippingMethod);
|
|
336
|
-
const methodCode = readField('method_code', incomingShippingMethod);
|
|
337
|
-
const carrierKey = `${carrierCode}|${methodCode}`;
|
|
338
|
-
if (carrierToIndex.has(carrierKey)) {
|
|
339
|
-
const targetIndex = carrierToIndex.get(carrierKey);
|
|
340
|
-
const existingShippingMethod = existing[targetIndex];
|
|
341
|
-
const merged = mergeObjects(existingShippingMethod, incomingShippingMethod);
|
|
342
|
-
mergeResult.add(merged);
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
// We do not have a method with this key yet, add it on to the end.
|
|
346
|
-
carrierToIndex.set(carrierKey, carrierToIndex.size);
|
|
347
|
-
mergeResult.add(incomingShippingMethod);
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
return Array.from(mergeResult);
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
country: {
|
|
354
|
-
merge: true,
|
|
355
|
-
},
|
|
356
|
-
region: {
|
|
357
|
-
merge: true,
|
|
358
|
-
},
|
|
359
|
-
selected_shipping_method: {
|
|
360
|
-
merge: true,
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
},
|
|
364
|
-
CategoryTree: {
|
|
365
|
-
keyFields: ['uid'],
|
|
366
|
-
fields: {
|
|
367
|
-
children: {
|
|
368
|
-
merge(existing, incoming) {
|
|
369
|
-
return incoming;
|
|
370
|
-
},
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
Wishlist: {
|
|
375
|
-
keyFields: ({ id }) => `CustomerWishlist:${id}`,
|
|
376
|
-
fields: {
|
|
377
|
-
items_v2: {
|
|
378
|
-
keyArgs: false,
|
|
379
|
-
merge: false,
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
|
-
WishlistItem: {
|
|
384
|
-
keyFields: ({ id }) => `CustomerWishlistItem:${id}`,
|
|
385
|
-
},
|
|
386
|
-
WishlistItems: {
|
|
387
|
-
fields: {
|
|
388
|
-
items: {
|
|
389
|
-
merge: (existing = [], incoming, { variables }) => {
|
|
390
|
-
if (variables) {
|
|
391
|
-
const { currentPage = 1 } = variables;
|
|
392
|
-
// reset cache collection if we're on the first page
|
|
393
|
-
if (currentPage === 1) {
|
|
394
|
-
return incoming;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return [...existing, ...incoming];
|
|
398
|
-
},
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
SimpleWishlistItem: {
|
|
403
|
-
keyFields: ({ id }) => `CustomerSimpleWishlistItem:${id}`,
|
|
404
|
-
},
|
|
405
|
-
VirtualWishlistItem: {
|
|
406
|
-
keyFields: ({ id }) => `CustomerVirtualWishlistItem:${id}`,
|
|
407
|
-
},
|
|
408
|
-
DownloadableWishlistItem: {
|
|
409
|
-
keyFields: ({ id }) => `CustomerDownloadableWishlistItem:${id}`,
|
|
410
|
-
},
|
|
411
|
-
BundleWishlistItem: {
|
|
412
|
-
keyFields: ({ id }) => `CustomerBundleWishlistItem:${id}`,
|
|
413
|
-
},
|
|
414
|
-
GroupedProductWishlistItem: {
|
|
415
|
-
keyFields: ({ id }) => `CustomerGroupedProductWishlistItem:${id}`,
|
|
416
|
-
},
|
|
417
|
-
ConfigurableWishlistItem: {
|
|
418
|
-
keyFields: ({ id }) => `CustomerConfigurableWishlistItem:${id}`,
|
|
419
|
-
},
|
|
420
|
-
GiftCardWishlistItem: {
|
|
421
|
-
keyFields: ({ id }) => `CustomerGiftCardWishlistItem:${id}`,
|
|
422
|
-
},
|
|
423
|
-
SimpleProduct: {
|
|
424
|
-
keyFields: ['uid'],
|
|
425
|
-
},
|
|
426
|
-
ConfigurableProduct: {
|
|
427
|
-
keyFields: ['uid'],
|
|
428
|
-
},
|
|
429
|
-
BundleProduct: {
|
|
430
|
-
keyFields: ['uid'],
|
|
431
|
-
},
|
|
432
|
-
GroupedProduct: {
|
|
433
|
-
keyFields: ['uid'],
|
|
434
|
-
},
|
|
435
|
-
VirtualProduct: {
|
|
436
|
-
keyFields: ['uid'],
|
|
437
|
-
},
|
|
438
|
-
CartItemInterface: {
|
|
439
|
-
keyFields: ['uid'],
|
|
440
|
-
},
|
|
441
|
-
StoreConfig: {
|
|
442
|
-
keyFields: ['store_code'],
|
|
443
|
-
},
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* A non-exhaustive list of feature kinds that exist for {@link provideMagentoDriver}.
|
|
448
|
-
*/
|
|
449
|
-
var MagentoDriverFeatureKind;
|
|
450
|
-
(function (MagentoDriverFeatureKind) {
|
|
451
|
-
MagentoDriverFeatureKind["CacheableOperations"] = "DaffMagentoDriverCacheableOperationsFeature";
|
|
452
|
-
MagentoDriverFeatureKind["CacheHeader"] = "DaffMagentoDriverCacheHeaderFeature";
|
|
453
|
-
MagentoDriverFeatureKind["ErrorHandler"] = "DaffMagentoDriverErrorHandlerFeature";
|
|
454
|
-
MagentoDriverFeatureKind["TransferState"] = "DaffMagentoDriverTransferStateFeature";
|
|
455
|
-
MagentoDriverFeatureKind["ExtraApolloOptions"] = "DaffMagentoDriverExtraApolloOptionsFeature";
|
|
456
|
-
})(MagentoDriverFeatureKind || (MagentoDriverFeatureKind = {}));
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Creates a magento driver feature for {@link provideMagentoDriver}.
|
|
460
|
-
*/
|
|
461
|
-
function makeMagentoDriverFeature(kind, providers) {
|
|
462
|
-
return { ɵkind: kind, ɵproviders: providers };
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const {
|
|
466
|
-
/**
|
|
467
|
-
* A token to hold {@link DaffDriverMagentoExtraApolloOptions}.
|
|
468
|
-
*/
|
|
469
|
-
token: DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS,
|
|
470
|
-
/**
|
|
471
|
-
* A provider for {@link DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS}.
|
|
472
|
-
*/
|
|
473
|
-
provider: provideDaffDriverMagentoExtraApolloOptions,
|
|
474
|
-
/**
|
|
475
|
-
* A factory provider for {@link DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS}.
|
|
476
|
-
*/
|
|
477
|
-
factoryProvider: provideDaffDriverMagentoExtraApolloOptionsFactory, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS', {
|
|
478
|
-
factory: () => ({}),
|
|
479
|
-
});
|
|
480
|
-
/**
|
|
481
|
-
* A {@link provideMagentoDriver} feature that allow specifying {@link DaffDriverMagentoExtraApolloOptions}.
|
|
482
|
-
*/
|
|
483
|
-
const withDaffDriverMagentoExtraApolloOptions = (options) => makeMagentoDriverFeature(MagentoDriverFeatureKind.TransferState, [
|
|
484
|
-
provideDaffDriverMagentoExtraApolloOptions(options),
|
|
485
|
-
]);
|
|
486
|
-
|
|
487
|
-
const {
|
|
488
|
-
/**
|
|
489
|
-
* A multi-provider injection token of the operation names of magento queries that should
|
|
490
|
-
* be cached. This is needed because queries need to be converted into GET queries in order for Magento
|
|
491
|
-
* to cache them. This token should be used by daffodil driver platform modules to register operation names that are cacheable, and is
|
|
492
|
-
* intended for internal daffodil use only.
|
|
493
|
-
*/
|
|
494
|
-
token: DAFF_MAGENTO_CACHEABLE_OPERATIONS,
|
|
495
|
-
/**
|
|
496
|
-
* Adds many operation names to the list of cacheable Magento operations. Use only with Angular 9+.
|
|
497
|
-
*/
|
|
498
|
-
provider: provideManyDaffMagentoCacheableOperations, } = createMultiInjectionToken('DAFF_MAGENTO_CACHEABLE_OPERATIONS');
|
|
499
|
-
/**
|
|
500
|
-
* Adds an operation name to the list of cacheable Magento operations. Use only with Angular 9+.
|
|
501
|
-
*/
|
|
502
|
-
function provideDaffMagentoCacheableOperation(operationName) {
|
|
503
|
-
return {
|
|
504
|
-
provide: DAFF_MAGENTO_CACHEABLE_OPERATIONS,
|
|
505
|
-
useValue: operationName,
|
|
506
|
-
multi: true,
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* A request handler provider that will convert cacheable apollo operations into a format that Magento will understand as cacheable.
|
|
512
|
-
*/
|
|
513
|
-
const provideDaffMagentoApolloCacheableOperations = () => makeEnvironmentProviders([
|
|
514
|
-
provideDaffApolloRequestHandlerFactories(() => {
|
|
515
|
-
const cacheableOperations = inject(DAFF_MAGENTO_CACHEABLE_OPERATIONS);
|
|
516
|
-
return (operation, forward) => {
|
|
517
|
-
if (cacheableOperations.indexOf(operation.operationName) > -1) {
|
|
518
|
-
operation.setContext({ method: 'GET' });
|
|
519
|
-
}
|
|
520
|
-
return forward(operation);
|
|
521
|
-
};
|
|
522
|
-
}),
|
|
523
|
-
]);
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* Custom type policies that allow us to have more granular control
|
|
527
|
-
* over how ApolloClient reads from and writes to the cache.
|
|
528
|
-
*
|
|
529
|
-
* This is applicable to Magento 2.4.3 and up.
|
|
530
|
-
* Heavily based on https://github.com/magento/pwa-studio/blob/99270701b2b607551f2e5881af272ed48ba7064c/packages/peregrine/lib/Apollo/policies/index.js.
|
|
531
|
-
*
|
|
532
|
-
* https://www.apollographql.com/docs/react/caching/cache-configuration/#typepolicy-fields
|
|
533
|
-
* https://www.apollographql.com/docs/react/caching/cache-field-behavior/
|
|
534
|
-
*/
|
|
535
|
-
const DAFF_MAGENTO_2_4_3_TYPE_POLICIES = {
|
|
536
|
-
Query: {
|
|
537
|
-
fields: {
|
|
538
|
-
cart: {
|
|
539
|
-
// Replaces @connection(key: "Cart")
|
|
540
|
-
keyArgs: () => 'Cart',
|
|
541
|
-
},
|
|
542
|
-
customer: {
|
|
543
|
-
keyArgs: () => 'Customer',
|
|
544
|
-
},
|
|
545
|
-
customerCart: {
|
|
546
|
-
keyArgs: () => 'Cart',
|
|
547
|
-
},
|
|
548
|
-
},
|
|
549
|
-
},
|
|
550
|
-
AppliedGiftCard: {
|
|
551
|
-
keyFields: ['code'],
|
|
552
|
-
},
|
|
553
|
-
AvailablePaymentMethod: {
|
|
554
|
-
keyFields: ['code'],
|
|
555
|
-
},
|
|
556
|
-
AvailableShippingMethod: {
|
|
557
|
-
// The combination of these fields makes an instance of
|
|
558
|
-
// AvailableShippingMethod unique.
|
|
559
|
-
keyFields: ['carrier_code', 'method_code'],
|
|
560
|
-
},
|
|
561
|
-
Breadcrumb: {
|
|
562
|
-
// Uses provided fields on the object as the `id`.
|
|
563
|
-
keyFields: ['category_uid'],
|
|
564
|
-
},
|
|
565
|
-
Cart: {
|
|
566
|
-
keyFields: () => 'Cart',
|
|
567
|
-
fields: {
|
|
568
|
-
applied_gift_cards: {
|
|
569
|
-
merge: (existing, incoming) => incoming,
|
|
570
|
-
},
|
|
571
|
-
available_payment_methods: {
|
|
572
|
-
merge: (existing, incoming) => incoming,
|
|
573
|
-
},
|
|
574
|
-
items: {
|
|
575
|
-
merge: (existing, incoming) => incoming,
|
|
576
|
-
},
|
|
577
|
-
prices: {
|
|
578
|
-
// `merge: true` can be used for an object field.
|
|
579
|
-
merge: true,
|
|
580
|
-
},
|
|
581
|
-
shipping_addresses: {
|
|
582
|
-
merge: (existing = [], incoming, { readField, mergeObjects }) => {
|
|
583
|
-
// street makes these things unique
|
|
584
|
-
const mergeResult = new Set();
|
|
585
|
-
const streetToIndex = new Map();
|
|
586
|
-
existing.forEach((existingShippingAddress, index) => {
|
|
587
|
-
// Use readField instead of existingShippingAddress.street directly because it will follow cache references.
|
|
588
|
-
const street = readField('street', existingShippingAddress);
|
|
589
|
-
streetToIndex.set(street, index);
|
|
590
|
-
});
|
|
591
|
-
incoming.forEach(incomingShippingAddress => {
|
|
592
|
-
const street = readField('street', incomingShippingAddress);
|
|
593
|
-
if (streetToIndex.has(street)) {
|
|
594
|
-
const targetIndex = streetToIndex.get(street);
|
|
595
|
-
const existingShippingAddress = existing[targetIndex];
|
|
596
|
-
const merged = mergeObjects(existingShippingAddress, incomingShippingAddress);
|
|
597
|
-
mergeResult.add(merged);
|
|
598
|
-
}
|
|
599
|
-
else {
|
|
600
|
-
// We do not have an address with this street yet, add it on to the end.
|
|
601
|
-
streetToIndex.set(street, streetToIndex.size);
|
|
602
|
-
mergeResult.add(incomingShippingAddress);
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
return Array.from(mergeResult);
|
|
606
|
-
},
|
|
607
|
-
},
|
|
608
|
-
},
|
|
609
|
-
},
|
|
610
|
-
Customer: {
|
|
611
|
-
keyFields: () => 'Customer',
|
|
612
|
-
fields: {
|
|
613
|
-
addresses: {
|
|
614
|
-
merge: (existing, incoming) => incoming,
|
|
615
|
-
read: (cachedAddresses, { toReference }) => {
|
|
616
|
-
if (cachedAddresses) {
|
|
617
|
-
return cachedAddresses.map(address => {
|
|
618
|
-
// Update v2 identifiers to new references. Previous
|
|
619
|
-
// entries had `id: CustomerAddress:1` which caused
|
|
620
|
-
// v3's lookup to fail. If we find a legacy id,
|
|
621
|
-
// point it at the object using a reference.
|
|
622
|
-
if (address.id?.includes('CustomerAddress')) {
|
|
623
|
-
return toReference(address.id);
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
return address;
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
// If there are no cached addresses that's fine - the schema
|
|
631
|
-
// shows that it is a nullable field.
|
|
632
|
-
},
|
|
633
|
-
},
|
|
634
|
-
orders: {
|
|
635
|
-
keyArgs: ['filter'],
|
|
636
|
-
// TODO: write merge function that handles pagination
|
|
637
|
-
// items: {
|
|
638
|
-
// merge: true,
|
|
639
|
-
// },
|
|
640
|
-
},
|
|
641
|
-
},
|
|
642
|
-
},
|
|
643
|
-
CustomerAddress: {
|
|
644
|
-
fields: {
|
|
645
|
-
street: {
|
|
646
|
-
merge: (existing, incoming) => incoming,
|
|
647
|
-
},
|
|
648
|
-
},
|
|
649
|
-
},
|
|
650
|
-
CustomerPaymentTokens: {
|
|
651
|
-
keyFields: () => 'CustomerPaymentTokens',
|
|
652
|
-
fields: {
|
|
653
|
-
items: {
|
|
654
|
-
merge: (existing, incoming) => incoming,
|
|
655
|
-
},
|
|
656
|
-
},
|
|
657
|
-
},
|
|
658
|
-
ProductImage: {
|
|
659
|
-
keyFields: ['url'],
|
|
660
|
-
},
|
|
661
|
-
SelectedConfigurableOption: {
|
|
662
|
-
// id alone is not enough to identify a selected option as it can refer
|
|
663
|
-
// to something like "size" where value_id refers to "large".
|
|
664
|
-
keyFields: ['id', 'value_id'],
|
|
665
|
-
},
|
|
666
|
-
SelectedPaymentMethod: {
|
|
667
|
-
keyFields: ['code'],
|
|
668
|
-
},
|
|
669
|
-
ShippingCartAddress: {
|
|
670
|
-
keyFields: ['street'],
|
|
671
|
-
fields: {
|
|
672
|
-
available_shipping_methods: {
|
|
673
|
-
merge: (existing = [], incoming, { readField, mergeObjects }) => {
|
|
674
|
-
// carrier_code + method_code makes these things unique
|
|
675
|
-
const mergeResult = new Set();
|
|
676
|
-
const carrierToIndex = new Map();
|
|
677
|
-
existing.forEach((existingShippingMethod, index) => {
|
|
678
|
-
// Use readField because it will follow cache references.
|
|
679
|
-
const carrierCode = readField('carrier_code', existingShippingMethod);
|
|
680
|
-
const methodCode = readField('method_code', existingShippingMethod);
|
|
681
|
-
const carrierKey = `${carrierCode}|${methodCode}`;
|
|
682
|
-
carrierToIndex.set(carrierKey, index);
|
|
683
|
-
});
|
|
684
|
-
incoming.forEach(incomingShippingMethod => {
|
|
685
|
-
// Use readField because it will follow cache references.
|
|
686
|
-
const carrierCode = readField('carrier_code', incomingShippingMethod);
|
|
687
|
-
const methodCode = readField('method_code', incomingShippingMethod);
|
|
688
|
-
const carrierKey = `${carrierCode}|${methodCode}`;
|
|
689
|
-
if (carrierToIndex.has(carrierKey)) {
|
|
690
|
-
const targetIndex = carrierToIndex.get(carrierKey);
|
|
691
|
-
const existingShippingMethod = existing[targetIndex];
|
|
692
|
-
const merged = mergeObjects(existingShippingMethod, incomingShippingMethod);
|
|
693
|
-
mergeResult.add(merged);
|
|
694
|
-
}
|
|
695
|
-
else {
|
|
696
|
-
// We do not have a method with this key yet, add it on to the end.
|
|
697
|
-
carrierToIndex.set(carrierKey, carrierToIndex.size);
|
|
698
|
-
mergeResult.add(incomingShippingMethod);
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
return Array.from(mergeResult);
|
|
702
|
-
},
|
|
703
|
-
},
|
|
704
|
-
country: {
|
|
705
|
-
merge: true,
|
|
706
|
-
},
|
|
707
|
-
region: {
|
|
708
|
-
merge: true,
|
|
709
|
-
},
|
|
710
|
-
selected_shipping_method: {
|
|
711
|
-
merge: true,
|
|
712
|
-
},
|
|
713
|
-
},
|
|
714
|
-
},
|
|
715
|
-
CategoryTree: {
|
|
716
|
-
fields: {
|
|
717
|
-
children: {
|
|
718
|
-
merge: (existing, incoming) => incoming,
|
|
719
|
-
},
|
|
720
|
-
},
|
|
721
|
-
},
|
|
722
|
-
Wishlist: {
|
|
723
|
-
keyFields: ({ id }) => `CustomerWishlist:${id}`,
|
|
724
|
-
},
|
|
725
|
-
WishlistItem: {
|
|
726
|
-
keyFields: ({ id }) => `CustomerWishlistItem:${id}`,
|
|
727
|
-
},
|
|
728
|
-
SimpleWishlistItem: {
|
|
729
|
-
keyFields: ({ id }) => `CustomerSimpleWishlistItem:${id}`,
|
|
730
|
-
},
|
|
731
|
-
VirtualWishlistItem: {
|
|
732
|
-
keyFields: ({ id }) => `CustomerVirtualWishlistItem:${id}`,
|
|
733
|
-
},
|
|
734
|
-
DownloadableWishlistItem: {
|
|
735
|
-
keyFields: ({ id }) => `CustomerDownloadableWishlistItem:${id}`,
|
|
736
|
-
},
|
|
737
|
-
BundleWishlistItem: {
|
|
738
|
-
keyFields: ({ id }) => `CustomerBundleWishlistItem:${id}`,
|
|
739
|
-
},
|
|
740
|
-
GroupedProductWishlistItem: {
|
|
741
|
-
keyFields: ({ id }) => `CustomerGroupedProductWishlistItem:${id}`,
|
|
742
|
-
},
|
|
743
|
-
ConfigurableWishlistItem: {
|
|
744
|
-
keyFields: ({ id }) => `CustomerConfigurableWishlistItem:${id}`,
|
|
745
|
-
},
|
|
746
|
-
GiftCardWishlistItem: {
|
|
747
|
-
keyFields: ({ id }) => `CustomerGiftCardWishlistItem:${id}`,
|
|
748
|
-
},
|
|
749
|
-
};
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* Interacts with the Apollo client.
|
|
753
|
-
*
|
|
754
|
-
* @inheritdoc
|
|
755
|
-
*/
|
|
756
|
-
class DaffDriverHttpClientCacheMagentoService {
|
|
757
|
-
constructor(platformId) {
|
|
758
|
-
this.platformId = platformId;
|
|
759
|
-
}
|
|
760
|
-
reset() {
|
|
761
|
-
if (isPlatformBrowser(this.platformId)) {
|
|
762
|
-
location.reload();
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
766
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, providedIn: 'root' }); }
|
|
767
|
-
}
|
|
768
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffDriverHttpClientCacheMagentoService, decorators: [{
|
|
769
|
-
type: Injectable,
|
|
770
|
-
args: [{
|
|
771
|
-
providedIn: 'root',
|
|
772
|
-
}]
|
|
773
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
774
|
-
type: Inject,
|
|
775
|
-
args: [PLATFORM_ID]
|
|
776
|
-
}] }] });
|
|
777
|
-
|
|
778
|
-
const MAGENTO_CUSTOMER_CACHE_ID_HEADER = 'X-Magento-Cache-Id';
|
|
779
|
-
/**
|
|
780
|
-
* Stores and sets the Magento cache ID header.
|
|
781
|
-
* This will set the `X-Magento-Cache-Id` header from the most recent value encountered
|
|
782
|
-
* on a response, if there was a response with that header set.
|
|
783
|
-
*/
|
|
784
|
-
const provideDaffMagentoCacheHeader = () => makeEnvironmentProviders([
|
|
785
|
-
provideDaffApolloRequestHandlerFactories(() => {
|
|
786
|
-
let cacheHeader;
|
|
787
|
-
return (operation, forward) => {
|
|
788
|
-
if (cacheHeader) {
|
|
789
|
-
operation.setContext({
|
|
790
|
-
headers: getApolloOperationHeaders(operation).append(MAGENTO_CUSTOMER_CACHE_ID_HEADER, cacheHeader),
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
return forward(operation).pipe(map$2((response) => {
|
|
794
|
-
const { headers } = operation.getContext().response;
|
|
795
|
-
if (headers.get(MAGENTO_CUSTOMER_CACHE_ID_HEADER)) {
|
|
796
|
-
cacheHeader = headers.get(MAGENTO_CUSTOMER_CACHE_ID_HEADER);
|
|
797
|
-
}
|
|
798
|
-
return response;
|
|
799
|
-
}));
|
|
800
|
-
};
|
|
801
|
-
}),
|
|
802
|
-
]);
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* A {@link provideMagentoDriver} feature that sets up {@link provideDaffMagentoApolloCacheableOperations}.
|
|
806
|
-
*/
|
|
807
|
-
const withOperationCache = (...extraOperations) => makeMagentoDriverFeature(MagentoDriverFeatureKind.CacheableOperations, [
|
|
808
|
-
provideDaffMagentoApolloCacheableOperations(),
|
|
809
|
-
makeEnvironmentProviders(provideManyDaffMagentoCacheableOperations(...extraOperations)),
|
|
810
|
-
]);
|
|
811
|
-
|
|
812
|
-
const {
|
|
813
|
-
/**
|
|
814
|
-
* Holds the error handler for {@link provideMagentoDriver}.
|
|
815
|
-
*/
|
|
816
|
-
token: DAFF_DRIVER_MAGENTO_ERROR_HANDLER,
|
|
817
|
-
/**
|
|
818
|
-
* Provider function for {@link DAFF_DRIVER_MAGENTO_ERROR_HANDLER}.
|
|
819
|
-
*/
|
|
820
|
-
provider: provideDaffDriverMagentoErrorHandler, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_ERROR_HANDLER', {
|
|
821
|
-
factory: () => ({ error }) => {
|
|
822
|
-
if (CombinedGraphQLErrors.is(error)) {
|
|
823
|
-
error.errors.map(({ message, locations, path }) => console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
|
|
824
|
-
}
|
|
825
|
-
else {
|
|
826
|
-
console.error(`[Network error]: ${error.message}`);
|
|
827
|
-
}
|
|
828
|
-
},
|
|
829
|
-
});
|
|
830
|
-
/**
|
|
831
|
-
* A {@link provideMagentoDriver} feature that specifies the error handler.
|
|
832
|
-
*/
|
|
833
|
-
const withDaffDriverMagentoErrorHandler = (handler) => makeMagentoDriverFeature(MagentoDriverFeatureKind.ErrorHandler, [
|
|
834
|
-
provideDaffDriverMagentoErrorHandler(handler),
|
|
835
|
-
]);
|
|
836
|
-
|
|
837
|
-
const {
|
|
838
|
-
/**
|
|
839
|
-
* Holds the `StateKey` with which {@link provideMagentoDriver} can use to transfer Apollo state from the server to the client.
|
|
840
|
-
*/
|
|
841
|
-
token: DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY,
|
|
842
|
-
/**
|
|
843
|
-
* Provider for {@link DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY}.
|
|
844
|
-
*/
|
|
845
|
-
provider: provideDaffDriverMagentoTransferStateKey, } = createSingleInjectionToken('DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY');
|
|
846
|
-
/**
|
|
847
|
-
* A {@link provideMagentoDriver} feature that sets up transfer state with the specified key.
|
|
848
|
-
*
|
|
849
|
-
* @param stateKey The key under which the Apollo state is stored.
|
|
850
|
-
*/
|
|
851
|
-
const withDaffDriverMagentoTransferState = (stateKey) => makeMagentoDriverFeature(MagentoDriverFeatureKind.TransferState, [
|
|
852
|
-
provideDaffDriverMagentoTransferStateKey(stateKey),
|
|
853
|
-
]);
|
|
854
|
-
/**
|
|
855
|
-
* Holds the logic for hydrating the Apollo cache with the server's transferred state.
|
|
856
|
-
* It is recommended to use {@link withDaffDriverMagentoTransferState} with {@link provideMagentoDriver}
|
|
857
|
-
* to provide this functionality automatically.
|
|
858
|
-
*/
|
|
859
|
-
const provideDaffDriverMagentoTransferState = () => makeEnvironmentProviders([
|
|
860
|
-
provideAppInitializer(() => {
|
|
861
|
-
const cache = inject(Apollo).client.cache;
|
|
862
|
-
const transferState = inject(TransferState);
|
|
863
|
-
const stateKey = inject(DAFF_DRIVER_MAGENTO_TRANSFER_STATE_KEY);
|
|
864
|
-
const hasStateKey = transferState.hasKey(stateKey);
|
|
865
|
-
if (hasStateKey) {
|
|
866
|
-
const state = transferState.get(stateKey, null);
|
|
867
|
-
cache.restore(state);
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
transferState.onSerialize(stateKey, () => cache.extract());
|
|
871
|
-
}
|
|
872
|
-
}),
|
|
873
|
-
]);
|
|
874
|
-
|
|
875
|
-
/**
|
|
876
|
-
* Sets up the Magento Daffodil driver configuration for Magento's GraphQl API.
|
|
877
|
-
*
|
|
878
|
-
* Under the hood, this creates an Apollo Client configuration.
|
|
879
|
-
*
|
|
880
|
-
* @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
|
|
881
|
-
*/
|
|
882
|
-
function provideMagentoDriver(options, ...features) {
|
|
883
|
-
const providers = [
|
|
884
|
-
...features.flatMap(({ ɵproviders }) => ɵproviders),
|
|
885
|
-
provideApollo(() => {
|
|
886
|
-
const opts = {
|
|
887
|
-
possibleTypes: MAGENTO_POSSIBLE_TYPES.possibleTypes,
|
|
888
|
-
typePolicies,
|
|
889
|
-
...(options instanceof InjectionToken ? inject(options) : options),
|
|
890
|
-
};
|
|
891
|
-
return {
|
|
892
|
-
...inject(DAFF_DRIVER_MAGENTO_EXTRA_APOLLO_OPTIONS),
|
|
893
|
-
link: ApolloLink.from([
|
|
894
|
-
...inject(DAFF_APOLLO_REQUEST_HANDLERS).map((handler) => new ApolloLink(handler)),
|
|
895
|
-
new ErrorLink(inject(DAFF_DRIVER_MAGENTO_ERROR_HANDLER)),
|
|
896
|
-
inject(HttpLink).create(opts),
|
|
897
|
-
]),
|
|
898
|
-
cache: new InMemoryCache({ typePolicies: opts.typePolicies, possibleTypes: opts.possibleTypes }),
|
|
899
|
-
};
|
|
900
|
-
}),
|
|
901
|
-
provideDaffDriverHttpClientCacheService(DaffDriverHttpClientCacheMagentoService),
|
|
902
|
-
// enable caching by default
|
|
903
|
-
provideDaffMagentoApolloCacheableOperations(),
|
|
904
|
-
provideDaffMagentoCacheHeader(),
|
|
905
|
-
];
|
|
906
|
-
if (features.find(({ ɵkind }) => ɵkind === MagentoDriverFeatureKind.TransferState)) {
|
|
907
|
-
providers.push(provideDaffDriverMagentoTransferState());
|
|
908
|
-
}
|
|
909
|
-
return makeEnvironmentProviders(providers);
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
const DAFF_DRIVER_MAGENTO_ERROR_CODE = 'DAFF_DRIVER_MAGENTO_ERROR';
|
|
913
|
-
/**
|
|
914
|
-
* A very general error thrown when a more specific error type cannot be determined.
|
|
915
|
-
*/
|
|
916
|
-
class DaffDriverMagentoError extends DaffInheritableError {
|
|
917
|
-
constructor(message) {
|
|
918
|
-
super(message);
|
|
919
|
-
this.code = DAFF_DRIVER_MAGENTO_ERROR_CODE;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
function daffMagentoTransformGraphQlError(error, map) {
|
|
924
|
-
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;
|
|
925
|
-
return new ErrorClass(error.message);
|
|
926
|
-
}
|
|
927
|
-
;
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* Transforms the passed error according to the lookup in the passed map.
|
|
931
|
-
*/
|
|
932
|
-
// TODO: return array of errors
|
|
933
|
-
function daffTransformMagentoError(error, map) {
|
|
934
|
-
if (CombinedGraphQLErrors.is(error)) {
|
|
935
|
-
return error.errors.map(err => daffMagentoTransformGraphQlError(err, map))[0];
|
|
936
|
-
}
|
|
937
|
-
else if (daffIsError(error)) {
|
|
938
|
-
return error;
|
|
939
|
-
}
|
|
940
|
-
else {
|
|
941
|
-
// TODO: how do we determine which error to return?
|
|
942
|
-
// https://www.apollographql.com/docs/react/data/error-handling#identifying-error-types
|
|
943
|
-
// return new DaffDriverNetworkError((<ApolloError>error).networkError.message);
|
|
944
|
-
return new DaffDriverMagentoError(error.message);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
var MagentoSortEnum;
|
|
949
|
-
(function (MagentoSortEnum) {
|
|
950
|
-
MagentoSortEnum["ASC"] = "ASC";
|
|
951
|
-
MagentoSortEnum["DESC"] = "DESC";
|
|
952
|
-
})(MagentoSortEnum || (MagentoSortEnum = {}));
|
|
953
|
-
|
|
954
|
-
function magentoPageInfoTransform(pageInfo) {
|
|
955
|
-
return {
|
|
956
|
-
pageSize: pageInfo.page_size,
|
|
957
|
-
currentPage: pageInfo.current_page,
|
|
958
|
-
totalPages: pageInfo.total_pages,
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
const map$1 = {
|
|
963
|
-
[MagentoSortEnum.ASC]: DaffSortDirectionEnum.Ascending,
|
|
964
|
-
[MagentoSortEnum.DESC]: DaffSortDirectionEnum.Descending,
|
|
965
|
-
};
|
|
966
|
-
function magentoSortDirectionResponseTransform(direction) {
|
|
967
|
-
return map$1[direction];
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
const map = {
|
|
971
|
-
[DaffSortDirectionEnum.Ascending]: MagentoSortEnum.ASC,
|
|
972
|
-
[DaffSortDirectionEnum.Descending]: MagentoSortEnum.DESC,
|
|
973
|
-
};
|
|
974
|
-
function magentoSortDirectionRequestTransform(direction) {
|
|
975
|
-
return map[direction];
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
const magentoSearchResultPageInfoFragment = gql `
|
|
979
|
-
fragment magentoSearchResultPageInfo on SearchResultPageInfo {
|
|
980
|
-
page_size
|
|
981
|
-
current_page
|
|
982
|
-
total_pages
|
|
983
|
-
}
|
|
984
|
-
`;
|
|
985
|
-
|
|
986
|
-
const magentoMoneyFragment = gql `
|
|
987
|
-
fragment moneyFragment on Money {
|
|
988
|
-
value
|
|
989
|
-
currency
|
|
990
|
-
}
|
|
991
|
-
`;
|
|
992
|
-
|
|
993
|
-
/**
|
|
994
|
-
* Generated bundle index. Do not edit.
|
|
995
|
-
*/
|
|
996
|
-
|
|
997
|
-
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, 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, withDaffDriverMagentoErrorHandler, withDaffDriverMagentoExtraApolloOptions, withDaffDriverMagentoTransferState, withOperationCache };
|
|
998
|
-
//# sourceMappingURL=daffodil-driver-magento.mjs.map
|