@decocms/apps-shopify 7.2.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/package.json +48 -0
- package/src/actions/cart/addItems.ts +36 -0
- package/src/actions/cart/updateCoupons.ts +31 -0
- package/src/actions/cart/updateItems.ts +31 -0
- package/src/actions/user/signIn.ts +40 -0
- package/src/actions/user/signUp.ts +31 -0
- package/src/client.ts +58 -0
- package/src/index.ts +43 -0
- package/src/init.ts +39 -0
- package/src/loaders/ProductDetailsPage.ts +31 -0
- package/src/loaders/ProductList.ts +102 -0
- package/src/loaders/ProductListingPage.ts +172 -0
- package/src/loaders/RelatedProducts.ts +42 -0
- package/src/loaders/cart.ts +74 -0
- package/src/loaders/shop.ts +35 -0
- package/src/loaders/user.ts +39 -0
- package/src/mod.ts +67 -0
- package/src/registry.ts +9 -0
- package/src/utils/__tests__/graphqlOperationName.test.ts +80 -0
- package/src/utils/__tests__/instrumentedFetch.test.ts +84 -0
- package/src/utils/__tests__/operationRouter.test.ts +56 -0
- package/src/utils/__tests__/transform.test.ts +216 -0
- package/src/utils/admin/admin.ts +57 -0
- package/src/utils/admin/queries.ts +29 -0
- package/src/utils/cart.ts +32 -0
- package/src/utils/cookies.ts +82 -0
- package/src/utils/enums.ts +438 -0
- package/src/utils/graphql.ts +69 -0
- package/src/utils/graphqlOperationName.ts +67 -0
- package/src/utils/instrumentedFetch.ts +55 -0
- package/src/utils/operationRouter.ts +70 -0
- package/src/utils/storefront/queries.ts +525 -0
- package/src/utils/transform.ts +430 -0
- package/src/utils/types.ts +191 -0
- package/src/utils/user.ts +23 -0
- package/src/utils/utils.ts +159 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { gql } from "../graphql";
|
|
2
|
+
|
|
3
|
+
const ProductVariant = gql`
|
|
4
|
+
fragment ProductVariant on ProductVariant {
|
|
5
|
+
availableForSale
|
|
6
|
+
barcode
|
|
7
|
+
compareAtPrice {
|
|
8
|
+
amount
|
|
9
|
+
currencyCode
|
|
10
|
+
}
|
|
11
|
+
currentlyNotInStock
|
|
12
|
+
id
|
|
13
|
+
image {
|
|
14
|
+
altText
|
|
15
|
+
url
|
|
16
|
+
}
|
|
17
|
+
price {
|
|
18
|
+
amount
|
|
19
|
+
currencyCode
|
|
20
|
+
}
|
|
21
|
+
quantityAvailable
|
|
22
|
+
requiresShipping
|
|
23
|
+
selectedOptions {
|
|
24
|
+
name
|
|
25
|
+
value
|
|
26
|
+
}
|
|
27
|
+
sku
|
|
28
|
+
title
|
|
29
|
+
unitPrice {
|
|
30
|
+
amount
|
|
31
|
+
currencyCode
|
|
32
|
+
}
|
|
33
|
+
unitPriceMeasurement {
|
|
34
|
+
measuredType
|
|
35
|
+
quantityValue
|
|
36
|
+
referenceUnit
|
|
37
|
+
quantityUnit
|
|
38
|
+
}
|
|
39
|
+
weight
|
|
40
|
+
weightUnit
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const Collection = gql`
|
|
45
|
+
fragment Collection on Collection {
|
|
46
|
+
description
|
|
47
|
+
descriptionHtml
|
|
48
|
+
handle
|
|
49
|
+
id
|
|
50
|
+
image {
|
|
51
|
+
altText
|
|
52
|
+
url
|
|
53
|
+
}
|
|
54
|
+
title
|
|
55
|
+
updatedAt
|
|
56
|
+
}`;
|
|
57
|
+
|
|
58
|
+
const Product = gql`
|
|
59
|
+
fragment Product on Product {
|
|
60
|
+
availableForSale
|
|
61
|
+
createdAt
|
|
62
|
+
description
|
|
63
|
+
descriptionHtml
|
|
64
|
+
featuredImage {
|
|
65
|
+
altText
|
|
66
|
+
url
|
|
67
|
+
}
|
|
68
|
+
handle
|
|
69
|
+
id
|
|
70
|
+
images(first: 10) {
|
|
71
|
+
nodes {
|
|
72
|
+
altText
|
|
73
|
+
url
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
isGiftCard
|
|
77
|
+
media(first: 10) {
|
|
78
|
+
nodes {
|
|
79
|
+
alt
|
|
80
|
+
previewImage {
|
|
81
|
+
altText
|
|
82
|
+
url
|
|
83
|
+
}
|
|
84
|
+
mediaContentType
|
|
85
|
+
... on Video {
|
|
86
|
+
alt
|
|
87
|
+
sources {
|
|
88
|
+
url
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
onlineStoreUrl
|
|
94
|
+
options {
|
|
95
|
+
name
|
|
96
|
+
values
|
|
97
|
+
}
|
|
98
|
+
priceRange {
|
|
99
|
+
minVariantPrice {
|
|
100
|
+
amount
|
|
101
|
+
currencyCode
|
|
102
|
+
}
|
|
103
|
+
maxVariantPrice {
|
|
104
|
+
amount
|
|
105
|
+
currencyCode
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
productType
|
|
109
|
+
publishedAt
|
|
110
|
+
requiresSellingPlan
|
|
111
|
+
seo {
|
|
112
|
+
title
|
|
113
|
+
description
|
|
114
|
+
}
|
|
115
|
+
tags
|
|
116
|
+
title
|
|
117
|
+
totalInventory
|
|
118
|
+
updatedAt
|
|
119
|
+
variants(first: 250) {
|
|
120
|
+
nodes {
|
|
121
|
+
...ProductVariant
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
vendor
|
|
125
|
+
collections(first: 250) {
|
|
126
|
+
nodes {
|
|
127
|
+
...Collection
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
metafields(identifiers: $identifiers) {
|
|
131
|
+
description
|
|
132
|
+
key
|
|
133
|
+
namespace
|
|
134
|
+
type
|
|
135
|
+
value
|
|
136
|
+
reference {
|
|
137
|
+
... on MediaImage {
|
|
138
|
+
image {
|
|
139
|
+
url
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
references(first: 250) {
|
|
144
|
+
edges {
|
|
145
|
+
node {
|
|
146
|
+
... on MediaImage {
|
|
147
|
+
image {
|
|
148
|
+
url
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
|
|
158
|
+
const Filter = gql`
|
|
159
|
+
fragment Filter on Filter{
|
|
160
|
+
id
|
|
161
|
+
label
|
|
162
|
+
type
|
|
163
|
+
values {
|
|
164
|
+
count
|
|
165
|
+
id
|
|
166
|
+
input
|
|
167
|
+
label
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
const Cart = gql`
|
|
173
|
+
fragment Cart on Cart {
|
|
174
|
+
id
|
|
175
|
+
checkoutUrl
|
|
176
|
+
totalQuantity
|
|
177
|
+
lines(first: 100) {
|
|
178
|
+
nodes {
|
|
179
|
+
id
|
|
180
|
+
quantity
|
|
181
|
+
merchandise {
|
|
182
|
+
...on ProductVariant {
|
|
183
|
+
id
|
|
184
|
+
title
|
|
185
|
+
image {
|
|
186
|
+
url
|
|
187
|
+
altText
|
|
188
|
+
}
|
|
189
|
+
product {
|
|
190
|
+
title
|
|
191
|
+
onlineStoreUrl
|
|
192
|
+
handle
|
|
193
|
+
}
|
|
194
|
+
price {
|
|
195
|
+
amount
|
|
196
|
+
currencyCode
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
discountAllocations {
|
|
201
|
+
...on CartCodeDiscountAllocation {
|
|
202
|
+
code
|
|
203
|
+
discountedAmount {
|
|
204
|
+
amount
|
|
205
|
+
currencyCode
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
cost {
|
|
210
|
+
totalAmount {
|
|
211
|
+
amount
|
|
212
|
+
currencyCode
|
|
213
|
+
}
|
|
214
|
+
subtotalAmount {
|
|
215
|
+
amount
|
|
216
|
+
currencyCode
|
|
217
|
+
}
|
|
218
|
+
amountPerQuantity {
|
|
219
|
+
amount
|
|
220
|
+
currencyCode
|
|
221
|
+
}
|
|
222
|
+
compareAtAmountPerQuantity {
|
|
223
|
+
amount
|
|
224
|
+
currencyCode
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
cost {
|
|
230
|
+
totalTaxAmount {
|
|
231
|
+
amount
|
|
232
|
+
currencyCode
|
|
233
|
+
}
|
|
234
|
+
subtotalAmount {
|
|
235
|
+
amount
|
|
236
|
+
currencyCode
|
|
237
|
+
}
|
|
238
|
+
totalAmount {
|
|
239
|
+
amount
|
|
240
|
+
currencyCode
|
|
241
|
+
}
|
|
242
|
+
checkoutChargeAmount {
|
|
243
|
+
amount
|
|
244
|
+
currencyCode
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
discountCodes {
|
|
248
|
+
code
|
|
249
|
+
applicable
|
|
250
|
+
}
|
|
251
|
+
discountAllocations {
|
|
252
|
+
discountedAmount {
|
|
253
|
+
amount
|
|
254
|
+
currencyCode
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}`;
|
|
258
|
+
|
|
259
|
+
const Customer = gql`
|
|
260
|
+
fragment Customer on Customer {
|
|
261
|
+
id
|
|
262
|
+
email
|
|
263
|
+
firstName
|
|
264
|
+
lastName
|
|
265
|
+
}
|
|
266
|
+
`;
|
|
267
|
+
|
|
268
|
+
export const CreateCart = {
|
|
269
|
+
query: gql`mutation CreateCart {
|
|
270
|
+
payload: cartCreate {
|
|
271
|
+
cart { id }
|
|
272
|
+
}
|
|
273
|
+
}`,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export const GetCart = {
|
|
277
|
+
fragments: [Cart],
|
|
278
|
+
query: gql`query GetCart($id: ID!) { cart(id: $id) { ...Cart } }`,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export const GetProduct = {
|
|
282
|
+
fragments: [Product, ProductVariant, Collection],
|
|
283
|
+
query: gql`query GetProduct($handle: String, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
284
|
+
product(handle: $handle) { ...Product }
|
|
285
|
+
}`,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export const ListProducts = {
|
|
289
|
+
fragments: [Product, ProductVariant, Collection],
|
|
290
|
+
query: gql`query ListProducts($first: Int, $after: String, $query: String, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
291
|
+
products(first: $first, after: $after, query: $query) {
|
|
292
|
+
nodes {
|
|
293
|
+
...Product
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}`,
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export const SearchProducts = {
|
|
300
|
+
fragments: [Product, ProductVariant, Filter, Collection],
|
|
301
|
+
query: gql`query searchWithFilters(
|
|
302
|
+
$first: Int,
|
|
303
|
+
$last: Int,
|
|
304
|
+
$after: String,
|
|
305
|
+
$before: String,
|
|
306
|
+
$query: String!,
|
|
307
|
+
$productFilters: [ProductFilter!]
|
|
308
|
+
$sortKey: SearchSortKeys,
|
|
309
|
+
$reverse: Boolean,
|
|
310
|
+
$identifiers: [HasMetafieldsIdentifier!]!
|
|
311
|
+
){
|
|
312
|
+
search(
|
|
313
|
+
first: $first,
|
|
314
|
+
last: $last,
|
|
315
|
+
after: $after,
|
|
316
|
+
before: $before,
|
|
317
|
+
query: $query,
|
|
318
|
+
productFilters: $productFilters,
|
|
319
|
+
types: PRODUCT,
|
|
320
|
+
sortKey: $sortKey,
|
|
321
|
+
reverse: $reverse,
|
|
322
|
+
){
|
|
323
|
+
totalCount
|
|
324
|
+
pageInfo {
|
|
325
|
+
hasNextPage
|
|
326
|
+
hasPreviousPage
|
|
327
|
+
endCursor
|
|
328
|
+
startCursor
|
|
329
|
+
}
|
|
330
|
+
productFilters {
|
|
331
|
+
...Filter
|
|
332
|
+
}
|
|
333
|
+
nodes {
|
|
334
|
+
...Product
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}`,
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export const ProductsByCollection = {
|
|
341
|
+
fragments: [Product, ProductVariant, Collection, Filter],
|
|
342
|
+
query: gql`query AllProducts(
|
|
343
|
+
$first: Int,
|
|
344
|
+
$last: Int,
|
|
345
|
+
$after: String,
|
|
346
|
+
$before: String,
|
|
347
|
+
$handle: String,
|
|
348
|
+
$sortKey: ProductCollectionSortKeys,
|
|
349
|
+
$reverse: Boolean,
|
|
350
|
+
$filters: [ProductFilter!],
|
|
351
|
+
$identifiers: [HasMetafieldsIdentifier!]!
|
|
352
|
+
){
|
|
353
|
+
collection(handle: $handle) {
|
|
354
|
+
handle
|
|
355
|
+
description
|
|
356
|
+
title
|
|
357
|
+
products(
|
|
358
|
+
first: $first,
|
|
359
|
+
last: $last,
|
|
360
|
+
after: $after,
|
|
361
|
+
before: $before,
|
|
362
|
+
sortKey: $sortKey,
|
|
363
|
+
reverse: $reverse,
|
|
364
|
+
filters: $filters
|
|
365
|
+
){
|
|
366
|
+
pageInfo {
|
|
367
|
+
hasNextPage
|
|
368
|
+
hasPreviousPage
|
|
369
|
+
endCursor
|
|
370
|
+
startCursor
|
|
371
|
+
}
|
|
372
|
+
filters {
|
|
373
|
+
...Filter
|
|
374
|
+
}
|
|
375
|
+
nodes {
|
|
376
|
+
...Product
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}`,
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
export const ProductRecommendations = {
|
|
384
|
+
fragments: [Product, ProductVariant, Collection],
|
|
385
|
+
query: gql`query productRecommendations($productId: ID!, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
386
|
+
productRecommendations(productId: $productId) {
|
|
387
|
+
...Product
|
|
388
|
+
}
|
|
389
|
+
}`,
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export const GetShopInfo = {
|
|
393
|
+
query: gql`query GetShopInfo($identifiers: [HasMetafieldsIdentifier!]!) {
|
|
394
|
+
shop {
|
|
395
|
+
name
|
|
396
|
+
description
|
|
397
|
+
privacyPolicy {
|
|
398
|
+
title
|
|
399
|
+
body
|
|
400
|
+
}
|
|
401
|
+
refundPolicy {
|
|
402
|
+
title
|
|
403
|
+
body
|
|
404
|
+
}
|
|
405
|
+
shippingPolicy {
|
|
406
|
+
title
|
|
407
|
+
body
|
|
408
|
+
}
|
|
409
|
+
subscriptionPolicy {
|
|
410
|
+
title
|
|
411
|
+
body
|
|
412
|
+
}
|
|
413
|
+
termsOfService {
|
|
414
|
+
title
|
|
415
|
+
body
|
|
416
|
+
}
|
|
417
|
+
metafields(identifiers: $identifiers) {
|
|
418
|
+
description
|
|
419
|
+
key
|
|
420
|
+
namespace
|
|
421
|
+
type
|
|
422
|
+
value
|
|
423
|
+
reference {
|
|
424
|
+
... on MediaImage {
|
|
425
|
+
image {
|
|
426
|
+
url
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
references(first: 250) {
|
|
431
|
+
edges {
|
|
432
|
+
node {
|
|
433
|
+
... on MediaImage {
|
|
434
|
+
image {
|
|
435
|
+
url
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}`,
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export const FetchCustomerInfo = {
|
|
447
|
+
fragments: [Customer],
|
|
448
|
+
query: gql`query FetchCustomerInfo($customerAccessToken: String!) {
|
|
449
|
+
customer(customerAccessToken: $customerAccessToken) {
|
|
450
|
+
...Customer
|
|
451
|
+
}
|
|
452
|
+
}`,
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export const AddItemToCart = {
|
|
456
|
+
fragments: [Cart],
|
|
457
|
+
query: gql`mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) {
|
|
458
|
+
payload: cartLinesAdd(cartId: $cartId, lines: $lines) {
|
|
459
|
+
cart { ...Cart }
|
|
460
|
+
}
|
|
461
|
+
}`,
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
export const RegisterAccount = {
|
|
465
|
+
query: gql`mutation RegisterAccount(
|
|
466
|
+
$email: String!,
|
|
467
|
+
$password: String!,
|
|
468
|
+
$firstName: String,
|
|
469
|
+
$lastName: String,
|
|
470
|
+
$acceptsMarketing: Boolean = false
|
|
471
|
+
) {
|
|
472
|
+
customerCreate(input: {
|
|
473
|
+
email: $email,
|
|
474
|
+
password: $password,
|
|
475
|
+
firstName: $firstName,
|
|
476
|
+
lastName: $lastName,
|
|
477
|
+
acceptsMarketing: $acceptsMarketing,
|
|
478
|
+
}) {
|
|
479
|
+
customer {
|
|
480
|
+
id
|
|
481
|
+
}
|
|
482
|
+
customerUserErrors {
|
|
483
|
+
code
|
|
484
|
+
message
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}`,
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
export const AddCoupon = {
|
|
491
|
+
fragments: [Cart],
|
|
492
|
+
query: gql`mutation AddCoupon($cartId: ID!, $discountCodes: [String!]!) {
|
|
493
|
+
payload: cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
|
|
494
|
+
cart { ...Cart }
|
|
495
|
+
userErrors {
|
|
496
|
+
field
|
|
497
|
+
message
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}`,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
export const UpdateItems = {
|
|
504
|
+
fragments: [Cart],
|
|
505
|
+
query: gql`mutation UpdateItems($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
|
|
506
|
+
payload: cartLinesUpdate(cartId: $cartId, lines: $lines) {
|
|
507
|
+
cart { ...Cart }
|
|
508
|
+
}
|
|
509
|
+
}`,
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
export const SignInWithEmailAndPassword = {
|
|
513
|
+
query: gql`mutation SignInWithEmailAndPassword($email: String!, $password: String!) {
|
|
514
|
+
customerAccessTokenCreate(input: { email: $email, password: $password }) {
|
|
515
|
+
customerAccessToken {
|
|
516
|
+
accessToken
|
|
517
|
+
expiresAt
|
|
518
|
+
}
|
|
519
|
+
customerUserErrors {
|
|
520
|
+
code
|
|
521
|
+
message
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}`,
|
|
525
|
+
};
|