@gem-sdk/adapter-shopify 1.58.0 → 2.0.0-dev.1082
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/dist/cjs/api/operations/add-to-cart.js +1 -35
- package/dist/cjs/api/operations/cart-discount-codes-update.js +1 -31
- package/dist/cjs/api/operations/cart-note-update.js +1 -31
- package/dist/cjs/api/operations/create-cart.js +1 -36
- package/dist/cjs/api/operations/get-cart.js +1 -30
- package/dist/cjs/api/operations/remove-cart-item.js +1 -33
- package/dist/cjs/api/operations/update-cart-line.js +1 -37
- package/dist/cjs/graphql/fragments/cart-line.generated.js +6 -12
- package/dist/cjs/graphql/fragments/cart-user-error.generated.js +2 -6
- package/dist/cjs/graphql/fragments/cart.generated.js +2 -6
- package/dist/cjs/graphql/fragments/country.generated.js +2 -6
- package/dist/cjs/graphql/fragments/currency.generated.js +2 -6
- package/dist/cjs/graphql/fragments/image.generated.js +2 -6
- package/dist/cjs/graphql/fragments/language.generated.js +2 -6
- package/dist/cjs/graphql/fragments/money-v2.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product.generated.js +2 -6
- package/dist/cjs/graphql/mutations/cart-create.generated.js +2 -12
- package/dist/cjs/graphql/mutations/cart-discount-codes-update.generated.js +2 -12
- package/dist/cjs/graphql/mutations/cart-lines-add.generated.js +2 -12
- package/dist/cjs/graphql/mutations/cart-lines-remove.generated.js +2 -12
- package/dist/cjs/graphql/mutations/cart-lines-update.generated.js +2 -12
- package/dist/cjs/graphql/mutations/cart-note-update.generated.js +2 -12
- package/dist/cjs/graphql/queries/cart.generated.js +2 -11
- package/dist/cjs/graphql/queries/product.generated.js +2 -8
- package/dist/cjs/graphql/queries/shop-meta.generated.js +2 -10
- package/dist/cjs/helpers/common.js +1 -15
- package/dist/cjs/helpers/normalize.js +1 -58
- package/dist/cjs/index.js +1 -35
- package/dist/esm/api/operations/add-to-cart.js +1 -33
- package/dist/esm/api/operations/cart-discount-codes-update.js +1 -29
- package/dist/esm/api/operations/cart-note-update.js +1 -29
- package/dist/esm/api/operations/create-cart.js +1 -34
- package/dist/esm/api/operations/get-cart.js +1 -28
- package/dist/esm/api/operations/remove-cart-item.js +1 -31
- package/dist/esm/api/operations/update-cart-line.js +1 -35
- package/dist/esm/graphql/fragments/cart-line.generated.js +6 -9
- package/dist/esm/graphql/fragments/cart-user-error.generated.js +2 -4
- package/dist/esm/graphql/fragments/cart.generated.js +2 -4
- package/dist/esm/graphql/fragments/country.generated.js +2 -4
- package/dist/esm/graphql/fragments/currency.generated.js +2 -4
- package/dist/esm/graphql/fragments/image.generated.js +2 -4
- package/dist/esm/graphql/fragments/language.generated.js +2 -4
- package/dist/esm/graphql/fragments/money-v2.generated.js +2 -4
- package/dist/esm/graphql/fragments/product.generated.js +2 -4
- package/dist/esm/graphql/mutations/cart-create.generated.js +7 -15
- package/dist/esm/graphql/mutations/cart-discount-codes-update.generated.js +7 -15
- package/dist/esm/graphql/mutations/cart-lines-add.generated.js +7 -15
- package/dist/esm/graphql/mutations/cart-lines-remove.generated.js +7 -15
- package/dist/esm/graphql/mutations/cart-lines-update.generated.js +7 -15
- package/dist/esm/graphql/mutations/cart-note-update.generated.js +7 -15
- package/dist/esm/graphql/queries/cart.generated.js +6 -13
- package/dist/esm/graphql/queries/product.generated.js +2 -6
- package/dist/esm/graphql/queries/shop-meta.generated.js +4 -10
- package/dist/esm/helpers/common.js +1 -13
- package/dist/esm/helpers/normalize.js +1 -56
- package/dist/esm/index.js +1 -15
- package/dist/types/index.d.ts +816 -407
- package/package.json +2 -2
|
@@ -1,58 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const normalizeCartProductVariant = (variant)=>{
|
|
4
|
-
const { compareAtPriceV2, priceV2, weight, weightUnit, id, sku, image } = variant;
|
|
5
|
-
return {
|
|
6
|
-
id,
|
|
7
|
-
requiresShipping: variant.requiresShipping,
|
|
8
|
-
availableForSale: variant.availableForSale,
|
|
9
|
-
sku: sku ?? id,
|
|
10
|
-
name: variant.title,
|
|
11
|
-
listPrice: compareAtPriceV2?.amount ? +compareAtPriceV2?.amount : 0,
|
|
12
|
-
price: +priceV2.amount,
|
|
13
|
-
weight: {
|
|
14
|
-
value: weight ?? 0,
|
|
15
|
-
unit: weightUnit
|
|
16
|
-
},
|
|
17
|
-
image
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const normalizeLineItem = (lineItem)=>{
|
|
21
|
-
const { quantity, id, merchandise } = lineItem;
|
|
22
|
-
const variant = normalizeCartProductVariant(merchandise);
|
|
23
|
-
return {
|
|
24
|
-
id,
|
|
25
|
-
quantity,
|
|
26
|
-
variant,
|
|
27
|
-
attributes: lineItem.attributes,
|
|
28
|
-
variantId: variant.id,
|
|
29
|
-
name: variant.name,
|
|
30
|
-
productTitle: merchandise.product.title,
|
|
31
|
-
productId: variant.id,
|
|
32
|
-
path: merchandise.product.handle,
|
|
33
|
-
discounts: []
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const normalizeCart = (cart)=>{
|
|
37
|
-
const { cost } = cart;
|
|
38
|
-
return {
|
|
39
|
-
createdAt: cart.createdAt,
|
|
40
|
-
id: cart.id,
|
|
41
|
-
lineItems: cart.lines.nodes.map(normalizeLineItem),
|
|
42
|
-
subtotalPrice: +cost.subtotalAmount.amount,
|
|
43
|
-
totalPrice: +cost.totalAmount.amount,
|
|
44
|
-
currency: {
|
|
45
|
-
code: cost.totalAmount.currencyCode
|
|
46
|
-
},
|
|
47
|
-
taxesIncluded: true,
|
|
48
|
-
lineItemsSubtotalPrice: +cost.subtotalAmount.amount,
|
|
49
|
-
checkoutUrl: cart.checkoutUrl,
|
|
50
|
-
note: cart.note,
|
|
51
|
-
discounts: cart.discountCodes.map((v)=>({
|
|
52
|
-
code: v.code,
|
|
53
|
-
applicable: v.applicable
|
|
54
|
-
}))
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports.normalizeCart = normalizeCart;
|
|
1
|
+
"use strict";const normalizeCartProductVariant=t=>{let{compareAtPrice:e,price:a,weight:r,weightUnit:o,id:i,sku:n,image:l}=t;return{id:i,requiresShipping:t.requiresShipping,availableForSale:t.availableForSale,sku:n??i,name:t.title,listPrice:e?.amount?+e?.amount:0,price:+a.amount,weight:{value:r??0,unit:o},image:l}},normalizeLineItem=t=>{let{quantity:e,id:a,merchandise:r}=t,o=normalizeCartProductVariant(r);return{id:a,quantity:e,variant:o,attributes:t.attributes,variantId:o.id,name:o.name,productTitle:r.product.title,productId:o.id,path:r.product.handle,discounts:[]}},normalizeCart=t=>{let{cost:e}=t;return{createdAt:t.createdAt,id:t.id,lineItems:t.lines.nodes.map(normalizeLineItem),subtotalPrice:+e.subtotalAmount.amount,totalPrice:+e.totalAmount.amount,currency:{code:e.totalAmount.currencyCode},taxesIncluded:!0,lineItemsSubtotalPrice:+e.subtotalAmount.amount,checkoutUrl:t.checkoutUrl,note:t.note,discounts:t.discountCodes.map(t=>({code:t.code,applicable:t.applicable}))}};exports.normalizeCart=normalizeCart;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var addToCart = require('./api/operations/add-to-cart.js');
|
|
4
|
-
var createCart = require('./api/operations/create-cart.js');
|
|
5
|
-
var getCart = require('./api/operations/get-cart.js');
|
|
6
|
-
var removeCartItem = require('./api/operations/remove-cart-item.js');
|
|
7
|
-
var updateCartLine = require('./api/operations/update-cart-line.js');
|
|
8
|
-
var cartDiscountCodesUpdate = require('./api/operations/cart-discount-codes-update.js');
|
|
9
|
-
var cartNoteUpdate = require('./api/operations/cart-note-update.js');
|
|
10
|
-
var product_generated = require('./graphql/queries/product.generated.js');
|
|
11
|
-
var shopMeta_generated = require('./graphql/queries/shop-meta.generated.js');
|
|
12
|
-
var cartCreate_generated = require('./graphql/mutations/cart-create.generated.js');
|
|
13
|
-
var cartDiscountCodesUpdate_generated = require('./graphql/mutations/cart-discount-codes-update.generated.js');
|
|
14
|
-
var cartLinesAdd_generated = require('./graphql/mutations/cart-lines-add.generated.js');
|
|
15
|
-
var cartLinesRemove_generated = require('./graphql/mutations/cart-lines-remove.generated.js');
|
|
16
|
-
var cartLinesUpdate_generated = require('./graphql/mutations/cart-lines-update.generated.js');
|
|
17
|
-
var cartNoteUpdate_generated = require('./graphql/mutations/cart-note-update.generated.js');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports.addToCartOperation = addToCart.addToCartOperation;
|
|
22
|
-
exports.createCartOperation = createCart.createCartOperation;
|
|
23
|
-
exports.getCartOperation = getCart.getCartOperation;
|
|
24
|
-
exports.removeCartItemOperation = removeCartItem.removeCartItemOperation;
|
|
25
|
-
exports.updateCartLineOperation = updateCartLine.updateCartLineOperation;
|
|
26
|
-
exports.cartDiscountCodesUpdateOperation = cartDiscountCodesUpdate.cartDiscountCodesUpdateOperation;
|
|
27
|
-
exports.cartNoteUpdateOperation = cartNoteUpdate.cartNoteUpdateOperation;
|
|
28
|
-
exports.ProductDocument = product_generated.ProductDocument;
|
|
29
|
-
exports.ShopMetaDocument = shopMeta_generated.ShopMetaDocument;
|
|
30
|
-
exports.CartCreateDocument = cartCreate_generated.CartCreateDocument;
|
|
31
|
-
exports.CartDiscountCodesUpdateDocument = cartDiscountCodesUpdate_generated.CartDiscountCodesUpdateDocument;
|
|
32
|
-
exports.CartLinesAddDocument = cartLinesAdd_generated.CartLinesAddDocument;
|
|
33
|
-
exports.CartLinesRemoveDocument = cartLinesRemove_generated.CartLinesRemoveDocument;
|
|
34
|
-
exports.CartLinesUpdateDocument = cartLinesUpdate_generated.CartLinesUpdateDocument;
|
|
35
|
-
exports.CartNoteUpdateDocument = cartNoteUpdate_generated.CartNoteUpdateDocument;
|
|
1
|
+
"use strict";var addToCart=require("./api/operations/add-to-cart.js"),createCart=require("./api/operations/create-cart.js"),getCart=require("./api/operations/get-cart.js"),removeCartItem=require("./api/operations/remove-cart-item.js"),updateCartLine=require("./api/operations/update-cart-line.js"),cartDiscountCodesUpdate=require("./api/operations/cart-discount-codes-update.js"),cartNoteUpdate=require("./api/operations/cart-note-update.js"),product_generated=require("./graphql/queries/product.generated.js"),shopMeta_generated=require("./graphql/queries/shop-meta.generated.js"),cartCreate_generated=require("./graphql/mutations/cart-create.generated.js"),cartDiscountCodesUpdate_generated=require("./graphql/mutations/cart-discount-codes-update.generated.js"),cartLinesAdd_generated=require("./graphql/mutations/cart-lines-add.generated.js"),cartLinesRemove_generated=require("./graphql/mutations/cart-lines-remove.generated.js"),cartLinesUpdate_generated=require("./graphql/mutations/cart-lines-update.generated.js"),cartNoteUpdate_generated=require("./graphql/mutations/cart-note-update.generated.js");exports.addToCartOperation=addToCart.addToCartOperation,exports.createCartOperation=createCart.createCartOperation,exports.getCartOperation=getCart.getCartOperation,exports.removeCartItemOperation=removeCartItem.removeCartItemOperation,exports.updateCartLineOperation=updateCartLine.updateCartLineOperation,exports.cartDiscountCodesUpdateOperation=cartDiscountCodesUpdate.cartDiscountCodesUpdateOperation,exports.cartNoteUpdateOperation=cartNoteUpdate.cartNoteUpdateOperation,exports.ProductDocument=product_generated.ProductDocument,exports.ShopMetaDocument=shopMeta_generated.ShopMetaDocument,exports.CartCreateDocument=cartCreate_generated.CartCreateDocument,exports.CartDiscountCodesUpdateDocument=cartDiscountCodesUpdate_generated.CartDiscountCodesUpdateDocument,exports.CartLinesAddDocument=cartLinesAdd_generated.CartLinesAddDocument,exports.CartLinesRemoveDocument=cartLinesRemove_generated.CartLinesRemoveDocument,exports.CartLinesUpdateDocument=cartLinesUpdate_generated.CartLinesUpdateDocument,exports.CartNoteUpdateDocument=cartNoteUpdate_generated.CartNoteUpdateDocument;
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const addToCartOperation = (config)=>{
|
|
6
|
-
const addToCart = async (input)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: input.cartId,
|
|
12
|
-
lines: input.lines.map((v)=>({
|
|
13
|
-
merchandiseId: v.variantId,
|
|
14
|
-
quantity: v.quantity,
|
|
15
|
-
attributes: v.attributes
|
|
16
|
-
}))
|
|
17
|
-
};
|
|
18
|
-
const res = await fetch(config.storefrontUrl, {
|
|
19
|
-
...composeRequest(config),
|
|
20
|
-
body: JSON.stringify({
|
|
21
|
-
query: CartLinesAddDocument,
|
|
22
|
-
variables
|
|
23
|
-
})
|
|
24
|
-
}).then((res)=>res.json());
|
|
25
|
-
if (res.data?.cartLinesAdd?.userErrors.length || !res.data?.cartLinesAdd?.cart) {
|
|
26
|
-
throw res.data?.cartLinesAdd?.userErrors;
|
|
27
|
-
}
|
|
28
|
-
return normalizeCart(res.data.cartLinesAdd.cart);
|
|
29
|
-
};
|
|
30
|
-
return addToCart;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export { addToCartOperation };
|
|
1
|
+
import{CartLinesAddDocument as r}from"../../graphql/mutations/cart-lines-add.generated.js";import{composeRequest as t}from"../../helpers/common.js";import{normalizeCart as a}from"../../helpers/normalize.js";let addToCartOperation=e=>{let n=async n=>{if(!e.storefrontUrl)throw Error("Shop is not connected");let o={cartId:n.cartId,lines:n.lines.map(r=>({merchandiseId:r.variantId,quantity:r.quantity,attributes:r.attributes}))},d=await fetch(e.storefrontUrl,{...t(e),body:JSON.stringify({query:r,variables:o})}).then(r=>r.json());if(d.data?.cartLinesAdd?.userErrors.length||!d.data?.cartLinesAdd?.cart)throw d.data?.cartLinesAdd?.userErrors;return a(d.data.cartLinesAdd.cart)};return n};export{addToCartOperation};
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const cartDiscountCodesUpdateOperation = (config)=>{
|
|
6
|
-
const cartNoteUpdate = async (input)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: input.cartId,
|
|
12
|
-
discountCodes: input.discountCodes
|
|
13
|
-
};
|
|
14
|
-
const res = await fetch(config.storefrontUrl, {
|
|
15
|
-
...composeRequest(config),
|
|
16
|
-
body: JSON.stringify({
|
|
17
|
-
query: CartDiscountCodesUpdateDocument,
|
|
18
|
-
variables
|
|
19
|
-
})
|
|
20
|
-
}).then((res)=>res.json());
|
|
21
|
-
if (res.data?.cartDiscountCodesUpdate?.userErrors.length || !res.data?.cartDiscountCodesUpdate?.cart) {
|
|
22
|
-
throw res.data?.cartDiscountCodesUpdate?.userErrors;
|
|
23
|
-
}
|
|
24
|
-
return normalizeCart(res.data.cartDiscountCodesUpdate.cart);
|
|
25
|
-
};
|
|
26
|
-
return cartNoteUpdate;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { cartDiscountCodesUpdateOperation };
|
|
1
|
+
import{CartDiscountCodesUpdateDocument as t}from"../../graphql/mutations/cart-discount-codes-update.generated.js";import{composeRequest as r}from"../../helpers/common.js";import{normalizeCart as o}from"../../helpers/normalize.js";let cartDiscountCodesUpdateOperation=e=>{let a=async a=>{if(!e.storefrontUrl)throw Error("Shop is not connected");let s={cartId:a.cartId,discountCodes:a.discountCodes},d=await fetch(e.storefrontUrl,{...r(e),body:JSON.stringify({query:t,variables:s})}).then(t=>t.json());if(d.data?.cartDiscountCodesUpdate?.userErrors.length||!d.data?.cartDiscountCodesUpdate?.cart)throw d.data?.cartDiscountCodesUpdate?.userErrors;return o(d.data.cartDiscountCodesUpdate.cart)};return a};export{cartDiscountCodesUpdateOperation};
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const cartNoteUpdateOperation = (config)=>{
|
|
6
|
-
const cartNoteUpdate = async (input)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: input.cartId,
|
|
12
|
-
note: input.note
|
|
13
|
-
};
|
|
14
|
-
const res = await fetch(config.storefrontUrl, {
|
|
15
|
-
...composeRequest(config),
|
|
16
|
-
body: JSON.stringify({
|
|
17
|
-
query: CartNoteUpdateDocument,
|
|
18
|
-
variables
|
|
19
|
-
})
|
|
20
|
-
}).then((res)=>res.json());
|
|
21
|
-
if (res.data?.cartNoteUpdate?.userErrors.length || !res.data?.cartNoteUpdate?.cart) {
|
|
22
|
-
throw res.data?.cartNoteUpdate?.userErrors;
|
|
23
|
-
}
|
|
24
|
-
return normalizeCart(res.data.cartNoteUpdate.cart);
|
|
25
|
-
};
|
|
26
|
-
return cartNoteUpdate;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { cartNoteUpdateOperation };
|
|
1
|
+
import{CartNoteUpdateDocument as t}from"../../graphql/mutations/cart-note-update.generated.js";import{composeRequest as r}from"../../helpers/common.js";import{normalizeCart as e}from"../../helpers/normalize.js";let cartNoteUpdateOperation=o=>{let a=async a=>{if(!o.storefrontUrl)throw Error("Shop is not connected");let n={cartId:a.cartId,note:a.note},p=await fetch(o.storefrontUrl,{...r(o),body:JSON.stringify({query:t,variables:n})}).then(t=>t.json());if(p.data?.cartNoteUpdate?.userErrors.length||!p.data?.cartNoteUpdate?.cart)throw p.data?.cartNoteUpdate?.userErrors;return e(p.data.cartNoteUpdate.cart)};return a};export{cartNoteUpdateOperation};
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const createCartOperation = (config)=>{
|
|
6
|
-
const createCart = async (args)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
input: {
|
|
12
|
-
lines: args.items.map((v)=>({
|
|
13
|
-
merchandiseId: v.variantId,
|
|
14
|
-
quantity: v.quantity,
|
|
15
|
-
attributes: v.attributes
|
|
16
|
-
}))
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const res = await fetch(config.storefrontUrl, {
|
|
20
|
-
...composeRequest(config),
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
query: CartCreateDocument,
|
|
23
|
-
variables
|
|
24
|
-
})
|
|
25
|
-
}).then((res)=>res.json());
|
|
26
|
-
if (res.data?.cartCreate?.userErrors.length || !res.data?.cartCreate?.cart) {
|
|
27
|
-
throw res.data?.cartCreate?.userErrors;
|
|
28
|
-
}
|
|
29
|
-
return normalizeCart(res.data.cartCreate.cart);
|
|
30
|
-
};
|
|
31
|
-
return createCart;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export { createCartOperation };
|
|
1
|
+
import{CartCreateDocument as t}from"../../graphql/mutations/cart-create.generated.js";import{composeRequest as r}from"../../helpers/common.js";import{normalizeCart as e}from"../../helpers/normalize.js";let createCartOperation=a=>{let o=async o=>{if(!a.storefrontUrl)throw Error("Shop is not connected");let n={input:{lines:o.items.map(t=>({merchandiseId:t.variantId,quantity:t.quantity,attributes:t.attributes}))}},i=await fetch(a.storefrontUrl,{...r(a),body:JSON.stringify({query:t,variables:n})}).then(t=>t.json());if(i.data?.cartCreate?.userErrors.length||!i.data?.cartCreate?.cart)throw i.data?.cartCreate?.userErrors;return e(i.data.cartCreate.cart)};return o};export{createCartOperation};
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const getCartOperation = (config)=>{
|
|
6
|
-
const getCart = async (input)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
id: input.cartId
|
|
12
|
-
};
|
|
13
|
-
const res = await fetch(config.storefrontUrl, {
|
|
14
|
-
...composeRequest(config),
|
|
15
|
-
body: JSON.stringify({
|
|
16
|
-
query: CartDocument,
|
|
17
|
-
variables
|
|
18
|
-
})
|
|
19
|
-
}).then((res)=>res.json());
|
|
20
|
-
if (!res.data?.cart) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
return normalizeCart(res.data.cart);
|
|
24
|
-
};
|
|
25
|
-
return getCart;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { getCartOperation };
|
|
1
|
+
import{CartDocument as r}from"../../graphql/queries/cart.generated.js";import{composeRequest as t}from"../../helpers/common.js";import{normalizeCart as e}from"../../helpers/normalize.js";let getCartOperation=o=>{let a=async a=>{if(!o.storefrontUrl)throw Error("Shop is not connected");let n={id:a.cartId},i=await fetch(o.storefrontUrl,{...t(o),body:JSON.stringify({query:r,variables:n})}).then(r=>r.json());if(i.data?.cart)return e(i.data.cart)};return a};export{getCartOperation};
|
|
@@ -1,31 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const removeCartItemOperation = (config)=>{
|
|
6
|
-
const removeCartItem = async (input)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: input.cartId,
|
|
12
|
-
lineIds: [
|
|
13
|
-
input.lineId
|
|
14
|
-
]
|
|
15
|
-
};
|
|
16
|
-
const res = await fetch(config.storefrontUrl, {
|
|
17
|
-
...composeRequest(config),
|
|
18
|
-
body: JSON.stringify({
|
|
19
|
-
query: CartLinesRemoveDocument,
|
|
20
|
-
variables
|
|
21
|
-
})
|
|
22
|
-
}).then((res)=>res.json());
|
|
23
|
-
if (res.data?.cartLinesRemove?.userErrors.length || !res.data?.cartLinesRemove?.cart) {
|
|
24
|
-
throw res.data?.cartLinesRemove?.userErrors;
|
|
25
|
-
}
|
|
26
|
-
return normalizeCart(res.data.cartLinesRemove.cart);
|
|
27
|
-
};
|
|
28
|
-
return removeCartItem;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export { removeCartItemOperation };
|
|
1
|
+
import{CartLinesRemoveDocument as r}from"../../graphql/mutations/cart-lines-remove.generated.js";import{composeRequest as e}from"../../helpers/common.js";import{normalizeCart as t}from"../../helpers/normalize.js";let removeCartItemOperation=o=>{let a=async a=>{if(!o.storefrontUrl)throw Error("Shop is not connected");let n={cartId:a.cartId,lineIds:[a.lineId]},s=await fetch(o.storefrontUrl,{...e(o),body:JSON.stringify({query:r,variables:n})}).then(r=>r.json());if(s.data?.cartLinesRemove?.userErrors.length||!s.data?.cartLinesRemove?.cart)throw s.data?.cartLinesRemove?.userErrors;return t(s.data.cartLinesRemove.cart)};return a};export{removeCartItemOperation};
|
|
@@ -1,35 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { composeRequest } from '../../helpers/common.js';
|
|
3
|
-
import { normalizeCart } from '../../helpers/normalize.js';
|
|
4
|
-
|
|
5
|
-
const updateCartLineOperation = (config)=>{
|
|
6
|
-
const updateCartLine = async (input)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: input.cartId,
|
|
12
|
-
lines: [
|
|
13
|
-
{
|
|
14
|
-
id: input.line.id,
|
|
15
|
-
merchandiseId: input.line.variantId,
|
|
16
|
-
quantity: input.line.quantity
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
};
|
|
20
|
-
const res = await fetch(config.storefrontUrl, {
|
|
21
|
-
...composeRequest(config),
|
|
22
|
-
body: JSON.stringify({
|
|
23
|
-
query: CartLinesUpdateDocument,
|
|
24
|
-
variables
|
|
25
|
-
})
|
|
26
|
-
}).then((res)=>res.json());
|
|
27
|
-
if (res.data?.cartLinesUpdate?.userErrors.length || !res.data?.cartLinesUpdate?.cart) {
|
|
28
|
-
throw res.data?.cartLinesUpdate?.userErrors;
|
|
29
|
-
}
|
|
30
|
-
return normalizeCart(res.data?.cartLinesUpdate.cart);
|
|
31
|
-
};
|
|
32
|
-
return updateCartLine;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export { updateCartLineOperation };
|
|
1
|
+
import{CartLinesUpdateDocument as t}from"../../graphql/mutations/cart-lines-update.generated.js";import{composeRequest as r}from"../../helpers/common.js";import{normalizeCart as e}from"../../helpers/normalize.js";let updateCartLineOperation=a=>{let n=async n=>{if(!a.storefrontUrl)throw Error("Shop is not connected");let i={cartId:n.cartId,lines:[{id:n.line.id,merchandiseId:n.line.variantId,quantity:n.line.quantity}]},o=await fetch(a.storefrontUrl,{...r(a),body:JSON.stringify({query:t,variables:i})}).then(t=>t.json());if(o.data?.cartLinesUpdate?.userErrors.length||!o.data?.cartLinesUpdate?.cart)throw o.data?.cartLinesUpdate?.userErrors;return e(o.data?.cartLinesUpdate.cart)};return n};export{updateCartLineOperation};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
let CartProductVariantSelect=`
|
|
2
2
|
fragment CartProductVariantSelect on ProductVariant {
|
|
3
3
|
id
|
|
4
4
|
title
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
quantityUnit
|
|
11
11
|
quantityValue
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
price {
|
|
14
14
|
...MoneyV2Select
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
compareAtPrice {
|
|
17
17
|
...MoneyV2Select
|
|
18
18
|
}
|
|
19
19
|
selectedOptions {
|
|
@@ -31,9 +31,8 @@
|
|
|
31
31
|
weight
|
|
32
32
|
weightUnit
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fragment CartLineSelect on CartLine {
|
|
34
|
+
`,CartLineSelect=`
|
|
35
|
+
fragment CartLineSelect on BaseCartLine {
|
|
37
36
|
id
|
|
38
37
|
quantity
|
|
39
38
|
attributes {
|
|
@@ -46,6 +45,4 @@ const CartLineSelect = `
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
export { CartLineSelect, CartProductVariantSelect };
|
|
48
|
+
`;export{CartLineSelect,CartProductVariantSelect};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
let ProductSelect=`
|
|
2
2
|
fragment ProductSelect on Product {
|
|
3
3
|
availableForSale
|
|
4
4
|
compareAtPriceRange {
|
|
@@ -45,6 +45,4 @@
|
|
|
45
45
|
totalInventory
|
|
46
46
|
updatedAt
|
|
47
47
|
}
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
export { ProductSelect };
|
|
48
|
+
`;export{ProductSelect};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MoneyV2Select } from '../fragments/money-v2.generated.js';
|
|
3
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
4
|
-
import { ImageSelect } from '../fragments/image.generated.js';
|
|
5
|
-
import { CartUserErrorSelect } from '../fragments/cart-user-error.generated.js';
|
|
6
|
-
|
|
7
|
-
const CartCreateDocument = `
|
|
1
|
+
import{CartSelect as r}from"../fragments/cart.generated.js";import{MoneyV2Select as e}from"../fragments/money-v2.generated.js";import{CartLineSelect as t,CartProductVariantSelect as a}from"../fragments/cart-line.generated.js";import{ImageSelect as m}from"../fragments/image.generated.js";import{CartUserErrorSelect as n}from"../fragments/cart-user-error.generated.js";let CartCreateDocument=`
|
|
8
2
|
mutation cartCreate($input: CartInput) {
|
|
9
3
|
cartCreate(input: $input) {
|
|
10
4
|
cart {
|
|
@@ -15,11 +9,9 @@ const CartCreateDocument = `
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
|
|
25
|
-
export { CartCreateDocument };
|
|
12
|
+
${r}
|
|
13
|
+
${e}
|
|
14
|
+
${t}
|
|
15
|
+
${a}
|
|
16
|
+
${m}
|
|
17
|
+
${n}`;export{CartCreateDocument};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MoneyV2Select } from '../fragments/money-v2.generated.js';
|
|
3
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
4
|
-
import { ImageSelect } from '../fragments/image.generated.js';
|
|
5
|
-
import { CartUserErrorSelect } from '../fragments/cart-user-error.generated.js';
|
|
6
|
-
|
|
7
|
-
const CartDiscountCodesUpdateDocument = `
|
|
1
|
+
import{CartSelect as t}from"../fragments/cart.generated.js";import{MoneyV2Select as r}from"../fragments/money-v2.generated.js";import{CartLineSelect as e,CartProductVariantSelect as o}from"../fragments/cart-line.generated.js";import{ImageSelect as a}from"../fragments/image.generated.js";import{CartUserErrorSelect as s}from"../fragments/cart-user-error.generated.js";let CartDiscountCodesUpdateDocument=`
|
|
8
2
|
mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]) {
|
|
9
3
|
cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
|
|
10
4
|
cart {
|
|
@@ -15,11 +9,9 @@ const CartDiscountCodesUpdateDocument = `
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
|
|
25
|
-
export { CartDiscountCodesUpdateDocument };
|
|
12
|
+
${t}
|
|
13
|
+
${r}
|
|
14
|
+
${e}
|
|
15
|
+
${o}
|
|
16
|
+
${a}
|
|
17
|
+
${s}`;export{CartDiscountCodesUpdateDocument};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MoneyV2Select } from '../fragments/money-v2.generated.js';
|
|
3
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
4
|
-
import { ImageSelect } from '../fragments/image.generated.js';
|
|
5
|
-
import { CartUserErrorSelect } from '../fragments/cart-user-error.generated.js';
|
|
6
|
-
|
|
7
|
-
const CartLinesAddDocument = `
|
|
1
|
+
import{CartSelect as r}from"../fragments/cart.generated.js";import{MoneyV2Select as e}from"../fragments/money-v2.generated.js";import{CartLineSelect as t,CartProductVariantSelect as a}from"../fragments/cart-line.generated.js";import{ImageSelect as n}from"../fragments/image.generated.js";import{CartUserErrorSelect as s}from"../fragments/cart-user-error.generated.js";let CartLinesAddDocument=`
|
|
8
2
|
mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {
|
|
9
3
|
cartLinesAdd(cartId: $cartId, lines: $lines) {
|
|
10
4
|
cart {
|
|
@@ -15,11 +9,9 @@ const CartLinesAddDocument = `
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
|
|
25
|
-
export { CartLinesAddDocument };
|
|
12
|
+
${r}
|
|
13
|
+
${e}
|
|
14
|
+
${t}
|
|
15
|
+
${a}
|
|
16
|
+
${n}
|
|
17
|
+
${s}`;export{CartLinesAddDocument};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MoneyV2Select } from '../fragments/money-v2.generated.js';
|
|
3
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
4
|
-
import { ImageSelect } from '../fragments/image.generated.js';
|
|
5
|
-
import { CartUserErrorSelect } from '../fragments/cart-user-error.generated.js';
|
|
6
|
-
|
|
7
|
-
const CartLinesRemoveDocument = `
|
|
1
|
+
import{CartSelect as e}from"../fragments/cart.generated.js";import{MoneyV2Select as r}from"../fragments/money-v2.generated.js";import{CartLineSelect as t,CartProductVariantSelect as a}from"../fragments/cart-line.generated.js";import{ImageSelect as m}from"../fragments/image.generated.js";import{CartUserErrorSelect as n}from"../fragments/cart-user-error.generated.js";let CartLinesRemoveDocument=`
|
|
8
2
|
mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {
|
|
9
3
|
cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {
|
|
10
4
|
cart {
|
|
@@ -15,11 +9,9 @@ const CartLinesRemoveDocument = `
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
|
|
25
|
-
export { CartLinesRemoveDocument };
|
|
12
|
+
${e}
|
|
13
|
+
${r}
|
|
14
|
+
${t}
|
|
15
|
+
${a}
|
|
16
|
+
${m}
|
|
17
|
+
${n}`;export{CartLinesRemoveDocument};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MoneyV2Select } from '../fragments/money-v2.generated.js';
|
|
3
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
4
|
-
import { ImageSelect } from '../fragments/image.generated.js';
|
|
5
|
-
import { CartUserErrorSelect } from '../fragments/cart-user-error.generated.js';
|
|
6
|
-
|
|
7
|
-
const CartLinesUpdateDocument = `
|
|
1
|
+
import{CartSelect as e}from"../fragments/cart.generated.js";import{MoneyV2Select as r}from"../fragments/money-v2.generated.js";import{CartLineSelect as t,CartProductVariantSelect as a}from"../fragments/cart-line.generated.js";import{ImageSelect as n}from"../fragments/image.generated.js";import{CartUserErrorSelect as s}from"../fragments/cart-user-error.generated.js";let CartLinesUpdateDocument=`
|
|
8
2
|
mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
|
|
9
3
|
cartLinesUpdate(cartId: $cartId, lines: $lines) {
|
|
10
4
|
cart {
|
|
@@ -15,11 +9,9 @@ const CartLinesUpdateDocument = `
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
|
|
25
|
-
export { CartLinesUpdateDocument };
|
|
12
|
+
${e}
|
|
13
|
+
${r}
|
|
14
|
+
${t}
|
|
15
|
+
${a}
|
|
16
|
+
${n}
|
|
17
|
+
${s}`;export{CartLinesUpdateDocument};
|