@gem-sdk/adapter-bigcommerce 2.0.0-staging.709 → 2.0.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/dist/cjs/api/operations/add-to-cart.js +1 -35
- package/dist/cjs/api/operations/create-cart.js +1 -35
- package/dist/cjs/api/operations/get-cart.js +1 -30
- package/dist/cjs/api/operations/remove-cart-item.js +1 -34
- package/dist/cjs/api/operations/update-cart-line.js +1 -38
- package/dist/cjs/graphql/fragments/cart-line.generated.js +3 -9
- package/dist/cjs/graphql/fragments/cart.generated.js +2 -6
- package/dist/cjs/graphql/fragments/media.generated.js +2 -6
- package/dist/cjs/graphql/mutations/cart-create.generated.js +2 -10
- package/dist/cjs/graphql/mutations/cart-lines-add.generated.js +2 -10
- package/dist/cjs/graphql/mutations/cart-lines-remove.generated.js +2 -10
- package/dist/cjs/graphql/mutations/cart-lines-update.generated.js +2 -10
- package/dist/cjs/graphql/queries/cart.generated.js +2 -10
- package/dist/cjs/helpers/common.js +1 -15
- package/dist/cjs/helpers/normalize.js +1 -46
- package/dist/cjs/index.js +1 -15
- package/dist/esm/api/operations/add-to-cart.js +1 -33
- package/dist/esm/api/operations/create-cart.js +1 -33
- package/dist/esm/api/operations/get-cart.js +1 -28
- package/dist/esm/api/operations/remove-cart-item.js +1 -32
- package/dist/esm/api/operations/update-cart-line.js +1 -36
- package/dist/esm/graphql/fragments/cart-line.generated.js +3 -6
- package/dist/esm/graphql/fragments/cart.generated.js +2 -4
- package/dist/esm/graphql/fragments/media.generated.js +2 -4
- package/dist/esm/graphql/mutations/cart-create.generated.js +5 -11
- package/dist/esm/graphql/mutations/cart-lines-add.generated.js +5 -11
- package/dist/esm/graphql/mutations/cart-lines-remove.generated.js +5 -11
- package/dist/esm/graphql/mutations/cart-lines-update.generated.js +5 -11
- package/dist/esm/graphql/queries/cart.generated.js +5 -11
- package/dist/esm/helpers/common.js +1 -13
- package/dist/esm/helpers/normalize.js +1 -44
- package/dist/esm/index.js +1 -5
- package/package.json +2 -2
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cartLinesAdd_generated = require('../../graphql/mutations/cart-lines-add.generated.js');
|
|
4
|
-
var common = require('../../helpers/common.js');
|
|
5
|
-
var normalize = require('../../helpers/normalize.js');
|
|
6
|
-
|
|
7
|
-
const addToCartOperation = (config)=>{
|
|
8
|
-
const addToCart = async (args)=>{
|
|
9
|
-
if (!config.storefrontUrl) {
|
|
10
|
-
throw new Error('Shop is not connected');
|
|
11
|
-
}
|
|
12
|
-
const variables = {
|
|
13
|
-
cartId: args.cartId,
|
|
14
|
-
platform: 3,
|
|
15
|
-
lines: args.lines.map((v)=>({
|
|
16
|
-
quantity: v.quantity,
|
|
17
|
-
merchandiseId: v.variantId
|
|
18
|
-
}))
|
|
19
|
-
};
|
|
20
|
-
const res = await fetch(config.storefrontUrl, {
|
|
21
|
-
...common.composeRequest(config),
|
|
22
|
-
body: JSON.stringify({
|
|
23
|
-
query: cartLinesAdd_generated.CartLinesAddDocument,
|
|
24
|
-
variables
|
|
25
|
-
})
|
|
26
|
-
}).then((res)=>res.json());
|
|
27
|
-
if (!res.data?.cartLinesAdd?.cart) {
|
|
28
|
-
return Promise.reject("Can't add to cart");
|
|
29
|
-
}
|
|
30
|
-
return normalize.normalizeCart(res.data.cartLinesAdd.cart);
|
|
31
|
-
};
|
|
32
|
-
return addToCart;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
exports.addToCartOperation = addToCartOperation;
|
|
1
|
+
"use strict";var cartLinesAdd_generated=require("../../graphql/mutations/cart-lines-add.generated.js"),common=require("../../helpers/common.js"),normalize=require("../../helpers/normalize.js");const addToCartOperation=r=>{let e=async e=>{if(!r.storefrontUrl)throw Error("Shop is not connected");let t={cartId:e.cartId,platform:3,lines:e.lines.map(r=>({quantity:r.quantity,merchandiseId:r.variantId}))},a=await fetch(r.storefrontUrl,{...common.composeRequest(r),body:JSON.stringify({query:cartLinesAdd_generated.CartLinesAddDocument,variables:t})}).then(r=>r.json());return a.data?.cartLinesAdd?.cart?normalize.normalizeCart(a.data.cartLinesAdd.cart):Promise.reject("Can't add to cart")};return e};exports.addToCartOperation=addToCartOperation;
|
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cartCreate_generated = require('../../graphql/mutations/cart-create.generated.js');
|
|
4
|
-
var common = require('../../helpers/common.js');
|
|
5
|
-
var normalize = require('../../helpers/normalize.js');
|
|
6
|
-
|
|
7
|
-
const createCartOperation = (config)=>{
|
|
8
|
-
const createCart = async (args)=>{
|
|
9
|
-
if (!config.storefrontUrl) {
|
|
10
|
-
throw new Error('Shop is not connected');
|
|
11
|
-
}
|
|
12
|
-
const variables = {
|
|
13
|
-
input: {
|
|
14
|
-
lines: args.items.map((v)=>({
|
|
15
|
-
quantity: v.quantity ?? 1,
|
|
16
|
-
merchandiseId: v.variantId
|
|
17
|
-
}))
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const res = await fetch(config.storefrontUrl, {
|
|
21
|
-
...common.composeRequest(config),
|
|
22
|
-
body: JSON.stringify({
|
|
23
|
-
query: cartCreate_generated.CartCreateDocument,
|
|
24
|
-
variables
|
|
25
|
-
})
|
|
26
|
-
}).then((res)=>res.json());
|
|
27
|
-
if (!res.data?.cartCreate?.cart) {
|
|
28
|
-
return Promise.reject("Can't create cart");
|
|
29
|
-
}
|
|
30
|
-
return normalize.normalizeCart(res.data.cartCreate.cart);
|
|
31
|
-
};
|
|
32
|
-
return createCart;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
exports.createCartOperation = createCartOperation;
|
|
1
|
+
"use strict";var cartCreate_generated=require("../../graphql/mutations/cart-create.generated.js"),common=require("../../helpers/common.js"),normalize=require("../../helpers/normalize.js");const createCartOperation=e=>{let r=async r=>{if(!e.storefrontUrl)throw Error("Shop is not connected");let t={input:{lines:r.items.map(e=>({quantity:e.quantity??1,merchandiseId:e.variantId}))}},a=await fetch(e.storefrontUrl,{...common.composeRequest(e),body:JSON.stringify({query:cartCreate_generated.CartCreateDocument,variables:t})}).then(e=>e.json());return a.data?.cartCreate?.cart?normalize.normalizeCart(a.data.cartCreate.cart):Promise.reject("Can't create cart")};return r};exports.createCartOperation=createCartOperation;
|
|
@@ -1,30 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cart_generated = require('../../graphql/queries/cart.generated.js');
|
|
4
|
-
var common = require('../../helpers/common.js');
|
|
5
|
-
var normalize = require('../../helpers/normalize.js');
|
|
6
|
-
|
|
7
|
-
const getCartOperation = (config)=>{
|
|
8
|
-
const getCart = async (args)=>{
|
|
9
|
-
if (!config.storefrontUrl) {
|
|
10
|
-
throw new Error('Shop is not connected');
|
|
11
|
-
}
|
|
12
|
-
const variables = {
|
|
13
|
-
id: args.cartId
|
|
14
|
-
};
|
|
15
|
-
const res = await fetch(config.storefrontUrl, {
|
|
16
|
-
...common.composeRequest(config),
|
|
17
|
-
body: JSON.stringify({
|
|
18
|
-
query: cart_generated.CartDocument,
|
|
19
|
-
variables
|
|
20
|
-
})
|
|
21
|
-
}).then((res)=>res.json());
|
|
22
|
-
if (!res.data?.cart) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
return normalize.normalizeCart(res.data.cart);
|
|
26
|
-
};
|
|
27
|
-
return getCart;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
exports.getCartOperation = getCartOperation;
|
|
1
|
+
"use strict";var cart_generated=require("../../graphql/queries/cart.generated.js"),common=require("../../helpers/common.js"),normalize=require("../../helpers/normalize.js");const getCartOperation=r=>{let e=async e=>{if(!r.storefrontUrl)throw Error("Shop is not connected");let t={id:e.cartId},a=await fetch(r.storefrontUrl,{...common.composeRequest(r),body:JSON.stringify({query:cart_generated.CartDocument,variables:t})}).then(r=>r.json());if(a.data?.cart)return normalize.normalizeCart(a.data.cart)};return e};exports.getCartOperation=getCartOperation;
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cartLinesRemove_generated = require('../../graphql/mutations/cart-lines-remove.generated.js');
|
|
4
|
-
var common = require('../../helpers/common.js');
|
|
5
|
-
var normalize = require('../../helpers/normalize.js');
|
|
6
|
-
|
|
7
|
-
const removeCartItemOperation = (config)=>{
|
|
8
|
-
const removeCartItem = async (args)=>{
|
|
9
|
-
if (!config.storefrontUrl) {
|
|
10
|
-
throw new Error('Shop is not connected');
|
|
11
|
-
}
|
|
12
|
-
const variables = {
|
|
13
|
-
cartId: args.cartId,
|
|
14
|
-
lineIds: [
|
|
15
|
-
args.lineId
|
|
16
|
-
],
|
|
17
|
-
platform: 3
|
|
18
|
-
};
|
|
19
|
-
const res = await fetch(config.storefrontUrl, {
|
|
20
|
-
...common.composeRequest(config),
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
query: cartLinesRemove_generated.CartLinesRemoveDocument,
|
|
23
|
-
variables
|
|
24
|
-
})
|
|
25
|
-
}).then((res)=>res.json());
|
|
26
|
-
if (!res.data?.cartLinesRemove?.cart) {
|
|
27
|
-
return Promise.reject("Can't remove cart");
|
|
28
|
-
}
|
|
29
|
-
return normalize.normalizeCart(res.data.cartLinesRemove.cart);
|
|
30
|
-
};
|
|
31
|
-
return removeCartItem;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.removeCartItemOperation = removeCartItemOperation;
|
|
1
|
+
"use strict";var cartLinesRemove_generated=require("../../graphql/mutations/cart-lines-remove.generated.js"),common=require("../../helpers/common.js"),normalize=require("../../helpers/normalize.js");const removeCartItemOperation=e=>{let r=async r=>{if(!e.storefrontUrl)throw Error("Shop is not connected");let t={cartId:r.cartId,lineIds:[r.lineId],platform:3},o=await fetch(e.storefrontUrl,{...common.composeRequest(e),body:JSON.stringify({query:cartLinesRemove_generated.CartLinesRemoveDocument,variables:t})}).then(e=>e.json());return o.data?.cartLinesRemove?.cart?normalize.normalizeCart(o.data.cartLinesRemove.cart):Promise.reject("Can't remove cart")};return r};exports.removeCartItemOperation=removeCartItemOperation;
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cartLinesUpdate_generated = require('../../graphql/mutations/cart-lines-update.generated.js');
|
|
4
|
-
var common = require('../../helpers/common.js');
|
|
5
|
-
var normalize = require('../../helpers/normalize.js');
|
|
6
|
-
|
|
7
|
-
const updateCartLineOperation = (config)=>{
|
|
8
|
-
const updateCartLine = async (args)=>{
|
|
9
|
-
if (!config.storefrontUrl) {
|
|
10
|
-
throw new Error('Shop is not connected');
|
|
11
|
-
}
|
|
12
|
-
const variables = {
|
|
13
|
-
cartId: args.cartId,
|
|
14
|
-
platform: 3,
|
|
15
|
-
lines: [
|
|
16
|
-
{
|
|
17
|
-
id: args.line.id,
|
|
18
|
-
quantity: args.line.quantity,
|
|
19
|
-
merchandiseId: args.line.variantId
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
const res = await fetch(config.storefrontUrl, {
|
|
24
|
-
...common.composeRequest(config),
|
|
25
|
-
body: JSON.stringify({
|
|
26
|
-
query: cartLinesUpdate_generated.CartLinesUpdateDocument,
|
|
27
|
-
variables
|
|
28
|
-
})
|
|
29
|
-
}).then((res)=>res.json());
|
|
30
|
-
if (!res.data?.cartLinesUpdate?.cart) {
|
|
31
|
-
return Promise.reject("Can't update cart");
|
|
32
|
-
}
|
|
33
|
-
return normalize.normalizeCart(res.data.cartLinesUpdate.cart);
|
|
34
|
-
};
|
|
35
|
-
return updateCartLine;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
exports.updateCartLineOperation = updateCartLineOperation;
|
|
1
|
+
"use strict";var cartLinesUpdate_generated=require("../../graphql/mutations/cart-lines-update.generated.js"),common=require("../../helpers/common.js"),normalize=require("../../helpers/normalize.js");const updateCartLineOperation=e=>{let t=async t=>{if(!e.storefrontUrl)throw Error("Shop is not connected");let r={cartId:t.cartId,platform:3,lines:[{id:t.line.id,quantity:t.line.quantity,merchandiseId:t.line.variantId}]},a=await fetch(e.storefrontUrl,{...common.composeRequest(e),body:JSON.stringify({query:cartLinesUpdate_generated.CartLinesUpdateDocument,variables:r})}).then(e=>e.json());return a.data?.cartLinesUpdate?.cart?normalize.normalizeCart(a.data.cartLinesUpdate.cart):Promise.reject("Can't update cart")};return t};exports.updateCartLineOperation=updateCartLineOperation;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */ const CartProductVariantSelect = `
|
|
1
|
+
"use strict";const CartProductVariantSelect=`
|
|
4
2
|
fragment CartProductVariantSelect on ProductVariant {
|
|
5
3
|
id
|
|
6
4
|
title
|
|
@@ -27,8 +25,7 @@
|
|
|
27
25
|
length
|
|
28
26
|
isDigital
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
const CartLineSelect = `
|
|
28
|
+
`,CartLineSelect=`
|
|
32
29
|
fragment CartLineSelect on CartLine {
|
|
33
30
|
id
|
|
34
31
|
quantity
|
|
@@ -38,7 +35,4 @@ const CartLineSelect = `
|
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
exports.CartLineSelect = CartLineSelect;
|
|
44
|
-
exports.CartProductVariantSelect = CartProductVariantSelect;
|
|
38
|
+
`;exports.CartLineSelect=CartLineSelect,exports.CartProductVariantSelect=CartProductVariantSelect;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */ const CartSelect = `
|
|
1
|
+
"use strict";const CartSelect=`
|
|
4
2
|
fragment CartSelect on Cart {
|
|
5
3
|
id
|
|
6
4
|
attribute {
|
|
@@ -46,6 +44,4 @@
|
|
|
46
44
|
totalTaxAmountCurrencyCode
|
|
47
45
|
updatedAt
|
|
48
46
|
}
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
exports.CartSelect = CartSelect;
|
|
47
|
+
`;exports.CartSelect=CartSelect;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */ const MediaSelect = `
|
|
1
|
+
"use strict";const MediaSelect=`
|
|
4
2
|
fragment MediaSelect on Media {
|
|
5
3
|
alt
|
|
6
4
|
src
|
|
@@ -9,6 +7,4 @@
|
|
|
9
7
|
height
|
|
10
8
|
contentType
|
|
11
9
|
}
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
exports.MediaSelect = MediaSelect;
|
|
10
|
+
`;exports.MediaSelect=MediaSelect;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cart_generated = require('../fragments/cart.generated.js');
|
|
4
|
-
var cartLine_generated = require('../fragments/cart-line.generated.js');
|
|
5
|
-
var media_generated = require('../fragments/media.generated.js');
|
|
6
|
-
|
|
7
|
-
const CartCreateDocument = `
|
|
1
|
+
"use strict";var cart_generated=require("../fragments/cart.generated.js"),cartLine_generated=require("../fragments/cart-line.generated.js"),media_generated=require("../fragments/media.generated.js");const CartCreateDocument=`
|
|
8
2
|
mutation cartCreate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $input: CartInput!) {
|
|
9
3
|
cartCreate(input: $input) {
|
|
10
4
|
cart {
|
|
@@ -20,6 +14,4 @@ const CartCreateDocument = `
|
|
|
20
14
|
${cart_generated.CartSelect}
|
|
21
15
|
${cartLine_generated.CartLineSelect}
|
|
22
16
|
${cartLine_generated.CartProductVariantSelect}
|
|
23
|
-
${media_generated.MediaSelect}`;
|
|
24
|
-
|
|
25
|
-
exports.CartCreateDocument = CartCreateDocument;
|
|
17
|
+
${media_generated.MediaSelect}`;exports.CartCreateDocument=CartCreateDocument;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cart_generated = require('../fragments/cart.generated.js');
|
|
4
|
-
var cartLine_generated = require('../fragments/cart-line.generated.js');
|
|
5
|
-
var media_generated = require('../fragments/media.generated.js');
|
|
6
|
-
|
|
7
|
-
const CartLinesAddDocument = `
|
|
1
|
+
"use strict";var cart_generated=require("../fragments/cart.generated.js"),cartLine_generated=require("../fragments/cart-line.generated.js"),media_generated=require("../fragments/media.generated.js");const CartLinesAddDocument=`
|
|
8
2
|
mutation cartLinesAdd($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineInput!]!, $platform: Int!) {
|
|
9
3
|
cartLinesAdd(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
10
4
|
cart {
|
|
@@ -20,6 +14,4 @@ const CartLinesAddDocument = `
|
|
|
20
14
|
${cart_generated.CartSelect}
|
|
21
15
|
${cartLine_generated.CartLineSelect}
|
|
22
16
|
${cartLine_generated.CartProductVariantSelect}
|
|
23
|
-
${media_generated.MediaSelect}`;
|
|
24
|
-
|
|
25
|
-
exports.CartLinesAddDocument = CartLinesAddDocument;
|
|
17
|
+
${media_generated.MediaSelect}`;exports.CartLinesAddDocument=CartLinesAddDocument;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cart_generated = require('../fragments/cart.generated.js');
|
|
4
|
-
var cartLine_generated = require('../fragments/cart-line.generated.js');
|
|
5
|
-
var media_generated = require('../fragments/media.generated.js');
|
|
6
|
-
|
|
7
|
-
const CartLinesRemoveDocument = `
|
|
1
|
+
"use strict";var cart_generated=require("../fragments/cart.generated.js"),cartLine_generated=require("../fragments/cart-line.generated.js"),media_generated=require("../fragments/media.generated.js");const CartLinesRemoveDocument=`
|
|
8
2
|
mutation cartLinesRemove($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lineIds: [ID!]!, $platform: Int!) {
|
|
9
3
|
cartLinesRemove(cartId: $cartId, lineIds: $lineIds, platform: $platform) {
|
|
10
4
|
cart {
|
|
@@ -20,6 +14,4 @@ const CartLinesRemoveDocument = `
|
|
|
20
14
|
${cart_generated.CartSelect}
|
|
21
15
|
${cartLine_generated.CartLineSelect}
|
|
22
16
|
${cartLine_generated.CartProductVariantSelect}
|
|
23
|
-
${media_generated.MediaSelect}`;
|
|
24
|
-
|
|
25
|
-
exports.CartLinesRemoveDocument = CartLinesRemoveDocument;
|
|
17
|
+
${media_generated.MediaSelect}`;exports.CartLinesRemoveDocument=CartLinesRemoveDocument;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cart_generated = require('../fragments/cart.generated.js');
|
|
4
|
-
var cartLine_generated = require('../fragments/cart-line.generated.js');
|
|
5
|
-
var media_generated = require('../fragments/media.generated.js');
|
|
6
|
-
|
|
7
|
-
const CartLinesUpdateDocument = `
|
|
1
|
+
"use strict";var cart_generated=require("../fragments/cart.generated.js"),cartLine_generated=require("../fragments/cart-line.generated.js"),media_generated=require("../fragments/media.generated.js");const CartLinesUpdateDocument=`
|
|
8
2
|
mutation cartLinesUpdate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineUpdateInput!]!, $platform: Int!) {
|
|
9
3
|
cartLinesUpdate(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
10
4
|
cart {
|
|
@@ -20,6 +14,4 @@ const CartLinesUpdateDocument = `
|
|
|
20
14
|
${cart_generated.CartSelect}
|
|
21
15
|
${cartLine_generated.CartLineSelect}
|
|
22
16
|
${cartLine_generated.CartProductVariantSelect}
|
|
23
|
-
${media_generated.MediaSelect}`;
|
|
24
|
-
|
|
25
|
-
exports.CartLinesUpdateDocument = CartLinesUpdateDocument;
|
|
17
|
+
${media_generated.MediaSelect}`;exports.CartLinesUpdateDocument=CartLinesUpdateDocument;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var cart_generated = require('../fragments/cart.generated.js');
|
|
4
|
-
var cartLine_generated = require('../fragments/cart-line.generated.js');
|
|
5
|
-
var media_generated = require('../fragments/media.generated.js');
|
|
6
|
-
|
|
7
|
-
const CartDocument = `
|
|
1
|
+
"use strict";var cart_generated=require("../fragments/cart.generated.js"),cartLine_generated=require("../fragments/cart-line.generated.js"),media_generated=require("../fragments/media.generated.js");const CartDocument=`
|
|
8
2
|
query cart($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $id: ID!) {
|
|
9
3
|
cart(id: $id) {
|
|
10
4
|
...CartSelect
|
|
@@ -13,6 +7,4 @@ const CartDocument = `
|
|
|
13
7
|
${cart_generated.CartSelect}
|
|
14
8
|
${cartLine_generated.CartLineSelect}
|
|
15
9
|
${cartLine_generated.CartProductVariantSelect}
|
|
16
|
-
${media_generated.MediaSelect}`;
|
|
17
|
-
|
|
18
|
-
exports.CartDocument = CartDocument;
|
|
10
|
+
${media_generated.MediaSelect}`;exports.CartDocument=CartDocument;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const composeRequest = (config)=>{
|
|
4
|
-
return {
|
|
5
|
-
method: 'POST',
|
|
6
|
-
headers: {
|
|
7
|
-
'Content-Type': 'application/json',
|
|
8
|
-
...config.storefrontToken ? {
|
|
9
|
-
'X-Bigcommerce-Storefront-Access-Token': config.storefrontToken
|
|
10
|
-
} : {}
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.composeRequest = composeRequest;
|
|
1
|
+
"use strict";const composeRequest=e=>({method:"POST",headers:{"Content-Type":"application/json",...e.storefrontToken?{"X-Bigcommerce-Storefront-Access-Token":e.storefrontToken}:{}}});exports.composeRequest=composeRequest;
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const normalizeLineItem = (item)=>{
|
|
4
|
-
const { quantity, id, variant } = item;
|
|
5
|
-
return {
|
|
6
|
-
id: id ?? '',
|
|
7
|
-
quantity,
|
|
8
|
-
name: variant?.title ?? '',
|
|
9
|
-
productTitle: variant?.product?.title ?? '',
|
|
10
|
-
variant: {
|
|
11
|
-
id: variant?.id ?? '',
|
|
12
|
-
sku: variant?.sku ?? '',
|
|
13
|
-
name: variant?.title ?? '',
|
|
14
|
-
image: variant?.media?.src ? {
|
|
15
|
-
url: variant.media.src
|
|
16
|
-
} : undefined,
|
|
17
|
-
requiresShipping: false,
|
|
18
|
-
price: variant?.price ?? 0,
|
|
19
|
-
listPrice: 0
|
|
20
|
-
},
|
|
21
|
-
variantId: variant?.id ?? '',
|
|
22
|
-
productId: variant?.product?.id ?? '',
|
|
23
|
-
path: variant?.product?.handle,
|
|
24
|
-
discounts: []
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const normalizeCart = (cart)=>{
|
|
28
|
-
return {
|
|
29
|
-
createdAt: cart.createdAt,
|
|
30
|
-
id: cart.id,
|
|
31
|
-
customerId: cart.customer?.id,
|
|
32
|
-
email: cart.customer?.email,
|
|
33
|
-
lineItems: cart.lines?.edges?.map((node)=>normalizeLineItem(node.node)) ?? [],
|
|
34
|
-
subtotalPrice: cart.subtotalAmount ? +cart.subtotalAmount : 0,
|
|
35
|
-
totalPrice: cart.totalAmount ? +cart.totalAmount : 0,
|
|
36
|
-
currency: {
|
|
37
|
-
code: cart.totalAmountCurrencyCode
|
|
38
|
-
},
|
|
39
|
-
taxesIncluded: true,
|
|
40
|
-
discounts: [],
|
|
41
|
-
lineItemsSubtotalPrice: cart.subtotalAmount ? +cart.subtotalAmount : 0,
|
|
42
|
-
checkoutUrl: cart.checkoutUrl
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
exports.normalizeCart = normalizeCart;
|
|
1
|
+
"use strict";const normalizeLineItem=t=>{let{quantity:e,id:i,variant:r}=t;return{id:i??"",quantity:e,name:r?.title??"",productTitle:r?.product?.title??"",variant:{id:r?.id??"",sku:r?.sku??"",name:r?.title??"",image:r?.media?.src?{url:r.media.src}:void 0,requiresShipping:!1,price:r?.price??0,listPrice:0},variantId:r?.id??"",productId:r?.product?.id??"",path:r?.product?.handle,discounts:[]}},normalizeCart=t=>({createdAt:t.createdAt,id:t.id,customerId:t.customer?.id,email:t.customer?.email,lineItems:t.lines?.edges?.map(t=>normalizeLineItem(t.node))??[],subtotalPrice:t.subtotalAmount?+t.subtotalAmount:0,totalPrice:t.totalAmount?+t.totalAmount:0,currency:{code:t.totalAmountCurrencyCode},taxesIncluded:!0,discounts:[],lineItemsSubtotalPrice:t.subtotalAmount?+t.subtotalAmount:0,checkoutUrl:t.checkoutUrl});exports.normalizeCart=normalizeCart;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,15 +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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.addToCartOperation = addToCart.addToCartOperation;
|
|
12
|
-
exports.createCartOperation = createCart.createCartOperation;
|
|
13
|
-
exports.getCartOperation = getCart.getCartOperation;
|
|
14
|
-
exports.removeCartItemOperation = removeCartItem.removeCartItemOperation;
|
|
15
|
-
exports.updateCartLineOperation = updateCartLine.updateCartLineOperation;
|
|
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");exports.addToCartOperation=addToCart.addToCartOperation,exports.createCartOperation=createCart.createCartOperation,exports.getCartOperation=getCart.getCartOperation,exports.removeCartItemOperation=removeCartItem.removeCartItemOperation,exports.updateCartLineOperation=updateCartLine.updateCartLineOperation;
|
|
@@ -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 (args)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: args.cartId,
|
|
12
|
-
platform: 3,
|
|
13
|
-
lines: args.lines.map((v)=>({
|
|
14
|
-
quantity: v.quantity,
|
|
15
|
-
merchandiseId: v.variantId
|
|
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?.cart) {
|
|
26
|
-
return Promise.reject("Can't add to cart");
|
|
27
|
-
}
|
|
28
|
-
return normalizeCart(res.data.cartLinesAdd.cart);
|
|
29
|
-
};
|
|
30
|
-
return addToCart;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export { addToCartOperation };
|
|
1
|
+
import{CartLinesAddDocument as t}from"../../graphql/mutations/cart-lines-add.generated.js";import{composeRequest as r}from"../../helpers/common.js";import{normalizeCart as a}from"../../helpers/normalize.js";let addToCartOperation=e=>{let o=async o=>{if(!e.storefrontUrl)throw Error("Shop is not connected");let n={cartId:o.cartId,platform:3,lines:o.lines.map(t=>({quantity:t.quantity,merchandiseId:t.variantId}))},d=await fetch(e.storefrontUrl,{...r(e),body:JSON.stringify({query:t,variables:n})}).then(t=>t.json());return d.data?.cartLinesAdd?.cart?a(d.data.cartLinesAdd.cart):Promise.reject("Can't add to cart")};return o};export{addToCartOperation};
|
|
@@ -1,33 +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
|
-
quantity: v.quantity ?? 1,
|
|
14
|
-
merchandiseId: v.variantId
|
|
15
|
-
}))
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const res = await fetch(config.storefrontUrl, {
|
|
19
|
-
...composeRequest(config),
|
|
20
|
-
body: JSON.stringify({
|
|
21
|
-
query: CartCreateDocument,
|
|
22
|
-
variables
|
|
23
|
-
})
|
|
24
|
-
}).then((res)=>res.json());
|
|
25
|
-
if (!res.data?.cartCreate?.cart) {
|
|
26
|
-
return Promise.reject("Can't create cart");
|
|
27
|
-
}
|
|
28
|
-
return normalizeCart(res.data.cartCreate.cart);
|
|
29
|
-
};
|
|
30
|
-
return createCart;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
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=>({quantity:t.quantity??1,merchandiseId:t.variantId}))}},i=await fetch(a.storefrontUrl,{...r(a),body:JSON.stringify({query:t,variables:n})}).then(t=>t.json());return i.data?.cartCreate?.cart?e(i.data.cartCreate.cart):Promise.reject("Can't create 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 (args)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
id: args.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,32 +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 (args)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: args.cartId,
|
|
12
|
-
lineIds: [
|
|
13
|
-
args.lineId
|
|
14
|
-
],
|
|
15
|
-
platform: 3
|
|
16
|
-
};
|
|
17
|
-
const res = await fetch(config.storefrontUrl, {
|
|
18
|
-
...composeRequest(config),
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
query: CartLinesRemoveDocument,
|
|
21
|
-
variables
|
|
22
|
-
})
|
|
23
|
-
}).then((res)=>res.json());
|
|
24
|
-
if (!res.data?.cartLinesRemove?.cart) {
|
|
25
|
-
return Promise.reject("Can't remove cart");
|
|
26
|
-
}
|
|
27
|
-
return normalizeCart(res.data.cartLinesRemove.cart);
|
|
28
|
-
};
|
|
29
|
-
return removeCartItem;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
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],platform:3},m=await fetch(o.storefrontUrl,{...e(o),body:JSON.stringify({query:r,variables:n})}).then(r=>r.json());return m.data?.cartLinesRemove?.cart?t(m.data.cartLinesRemove.cart):Promise.reject("Can't remove cart")};return a};export{removeCartItemOperation};
|
|
@@ -1,36 +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 (args)=>{
|
|
7
|
-
if (!config.storefrontUrl) {
|
|
8
|
-
throw new Error('Shop is not connected');
|
|
9
|
-
}
|
|
10
|
-
const variables = {
|
|
11
|
-
cartId: args.cartId,
|
|
12
|
-
platform: 3,
|
|
13
|
-
lines: [
|
|
14
|
-
{
|
|
15
|
-
id: args.line.id,
|
|
16
|
-
quantity: args.line.quantity,
|
|
17
|
-
merchandiseId: args.line.variantId
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
};
|
|
21
|
-
const res = await fetch(config.storefrontUrl, {
|
|
22
|
-
...composeRequest(config),
|
|
23
|
-
body: JSON.stringify({
|
|
24
|
-
query: CartLinesUpdateDocument,
|
|
25
|
-
variables
|
|
26
|
-
})
|
|
27
|
-
}).then((res)=>res.json());
|
|
28
|
-
if (!res.data?.cartLinesUpdate?.cart) {
|
|
29
|
-
return Promise.reject("Can't update cart");
|
|
30
|
-
}
|
|
31
|
-
return normalizeCart(res.data.cartLinesUpdate.cart);
|
|
32
|
-
};
|
|
33
|
-
return updateCartLine;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
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,platform:3,lines:[{id:n.line.id,quantity:n.line.quantity,merchandiseId:n.line.variantId}]},o=await fetch(a.storefrontUrl,{...r(a),body:JSON.stringify({query:t,variables:i})}).then(t=>t.json());return o.data?.cartLinesUpdate?.cart?e(o.data.cartLinesUpdate.cart):Promise.reject("Can't update 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
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
length
|
|
26
26
|
isDigital
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
const CartLineSelect = `
|
|
28
|
+
`,CartLineSelect=`
|
|
30
29
|
fragment CartLineSelect on CartLine {
|
|
31
30
|
id
|
|
32
31
|
quantity
|
|
@@ -36,6 +35,4 @@ const CartLineSelect = `
|
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
`;
|
|
40
|
-
|
|
41
|
-
export { CartLineSelect, CartProductVariantSelect };
|
|
38
|
+
`;export{CartLineSelect,CartProductVariantSelect};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
-
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
-
|
|
5
|
-
const CartCreateDocument = `
|
|
1
|
+
import{CartSelect as e}from"../fragments/cart.generated.js";import{CartLineSelect as r,CartProductVariantSelect as t}from"../fragments/cart-line.generated.js";import{MediaSelect as a}from"../fragments/media.generated.js";let CartCreateDocument=`
|
|
6
2
|
mutation cartCreate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $input: CartInput!) {
|
|
7
3
|
cartCreate(input: $input) {
|
|
8
4
|
cart {
|
|
@@ -15,9 +11,7 @@ const CartCreateDocument = `
|
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
export { CartCreateDocument };
|
|
14
|
+
${e}
|
|
15
|
+
${r}
|
|
16
|
+
${t}
|
|
17
|
+
${a}`;export{CartCreateDocument};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
-
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
-
|
|
5
|
-
const CartLinesAddDocument = `
|
|
1
|
+
import{CartSelect as r}from"../fragments/cart.generated.js";import{CartLineSelect as e,CartProductVariantSelect as t}from"../fragments/cart-line.generated.js";import{MediaSelect as a}from"../fragments/media.generated.js";let CartLinesAddDocument=`
|
|
6
2
|
mutation cartLinesAdd($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineInput!]!, $platform: Int!) {
|
|
7
3
|
cartLinesAdd(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
8
4
|
cart {
|
|
@@ -15,9 +11,7 @@ const CartLinesAddDocument = `
|
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
export { CartLinesAddDocument };
|
|
14
|
+
${r}
|
|
15
|
+
${e}
|
|
16
|
+
${t}
|
|
17
|
+
${a}`;export{CartLinesAddDocument};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
-
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
-
|
|
5
|
-
const CartLinesRemoveDocument = `
|
|
1
|
+
import{CartSelect as e}from"../fragments/cart.generated.js";import{CartLineSelect as r,CartProductVariantSelect as t}from"../fragments/cart-line.generated.js";import{MediaSelect as a}from"../fragments/media.generated.js";let CartLinesRemoveDocument=`
|
|
6
2
|
mutation cartLinesRemove($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lineIds: [ID!]!, $platform: Int!) {
|
|
7
3
|
cartLinesRemove(cartId: $cartId, lineIds: $lineIds, platform: $platform) {
|
|
8
4
|
cart {
|
|
@@ -15,9 +11,7 @@ const CartLinesRemoveDocument = `
|
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
export { CartLinesRemoveDocument };
|
|
14
|
+
${e}
|
|
15
|
+
${r}
|
|
16
|
+
${t}
|
|
17
|
+
${a}`;export{CartLinesRemoveDocument};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
-
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
-
|
|
5
|
-
const CartLinesUpdateDocument = `
|
|
1
|
+
import{CartSelect as e}from"../fragments/cart.generated.js";import{CartLineSelect as t,CartProductVariantSelect as r}from"../fragments/cart-line.generated.js";import{MediaSelect as a}from"../fragments/media.generated.js";let CartLinesUpdateDocument=`
|
|
6
2
|
mutation cartLinesUpdate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineUpdateInput!]!, $platform: Int!) {
|
|
7
3
|
cartLinesUpdate(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
8
4
|
cart {
|
|
@@ -15,9 +11,7 @@ const CartLinesUpdateDocument = `
|
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
export { CartLinesUpdateDocument };
|
|
14
|
+
${e}
|
|
15
|
+
${t}
|
|
16
|
+
${r}
|
|
17
|
+
${a}`;export{CartLinesUpdateDocument};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
-
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
-
|
|
5
|
-
const CartDocument = `
|
|
1
|
+
import{CartSelect as r}from"../fragments/cart.generated.js";import{CartLineSelect as e,CartProductVariantSelect as t}from"../fragments/cart-line.generated.js";import{MediaSelect as a}from"../fragments/media.generated.js";let CartDocument=`
|
|
6
2
|
query cart($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $id: ID!) {
|
|
7
3
|
cart(id: $id) {
|
|
8
4
|
...CartSelect
|
|
9
5
|
}
|
|
10
6
|
}
|
|
11
|
-
${
|
|
12
|
-
${
|
|
13
|
-
${
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
export { CartDocument };
|
|
7
|
+
${r}
|
|
8
|
+
${e}
|
|
9
|
+
${t}
|
|
10
|
+
${a}`;export{CartDocument};
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
return {
|
|
3
|
-
method: 'POST',
|
|
4
|
-
headers: {
|
|
5
|
-
'Content-Type': 'application/json',
|
|
6
|
-
...config.storefrontToken ? {
|
|
7
|
-
'X-Bigcommerce-Storefront-Access-Token': config.storefrontToken
|
|
8
|
-
} : {}
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { composeRequest };
|
|
1
|
+
let composeRequest=e=>({method:"POST",headers:{"Content-Type":"application/json",...e.storefrontToken?{"X-Bigcommerce-Storefront-Access-Token":e.storefrontToken}:{}}});export{composeRequest};
|
|
@@ -1,44 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const { quantity, id, variant } = item;
|
|
3
|
-
return {
|
|
4
|
-
id: id ?? '',
|
|
5
|
-
quantity,
|
|
6
|
-
name: variant?.title ?? '',
|
|
7
|
-
productTitle: variant?.product?.title ?? '',
|
|
8
|
-
variant: {
|
|
9
|
-
id: variant?.id ?? '',
|
|
10
|
-
sku: variant?.sku ?? '',
|
|
11
|
-
name: variant?.title ?? '',
|
|
12
|
-
image: variant?.media?.src ? {
|
|
13
|
-
url: variant.media.src
|
|
14
|
-
} : undefined,
|
|
15
|
-
requiresShipping: false,
|
|
16
|
-
price: variant?.price ?? 0,
|
|
17
|
-
listPrice: 0
|
|
18
|
-
},
|
|
19
|
-
variantId: variant?.id ?? '',
|
|
20
|
-
productId: variant?.product?.id ?? '',
|
|
21
|
-
path: variant?.product?.handle,
|
|
22
|
-
discounts: []
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
const normalizeCart = (cart)=>{
|
|
26
|
-
return {
|
|
27
|
-
createdAt: cart.createdAt,
|
|
28
|
-
id: cart.id,
|
|
29
|
-
customerId: cart.customer?.id,
|
|
30
|
-
email: cart.customer?.email,
|
|
31
|
-
lineItems: cart.lines?.edges?.map((node)=>normalizeLineItem(node.node)) ?? [],
|
|
32
|
-
subtotalPrice: cart.subtotalAmount ? +cart.subtotalAmount : 0,
|
|
33
|
-
totalPrice: cart.totalAmount ? +cart.totalAmount : 0,
|
|
34
|
-
currency: {
|
|
35
|
-
code: cart.totalAmountCurrencyCode
|
|
36
|
-
},
|
|
37
|
-
taxesIncluded: true,
|
|
38
|
-
discounts: [],
|
|
39
|
-
lineItemsSubtotalPrice: cart.subtotalAmount ? +cart.subtotalAmount : 0,
|
|
40
|
-
checkoutUrl: cart.checkoutUrl
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export { normalizeCart };
|
|
1
|
+
let normalizeLineItem=t=>{let{quantity:e,id:i,variant:o}=t;return{id:i??"",quantity:e,name:o?.title??"",productTitle:o?.product?.title??"",variant:{id:o?.id??"",sku:o?.sku??"",name:o?.title??"",image:o?.media?.src?{url:o.media.src}:void 0,requiresShipping:!1,price:o?.price??0,listPrice:0},variantId:o?.id??"",productId:o?.product?.id??"",path:o?.product?.handle,discounts:[]}},normalizeCart=t=>({createdAt:t.createdAt,id:t.id,customerId:t.customer?.id,email:t.customer?.email,lineItems:t.lines?.edges?.map(t=>normalizeLineItem(t.node))??[],subtotalPrice:t.subtotalAmount?+t.subtotalAmount:0,totalPrice:t.totalAmount?+t.totalAmount:0,currency:{code:t.totalAmountCurrencyCode},taxesIncluded:!0,discounts:[],lineItemsSubtotalPrice:t.subtotalAmount?+t.subtotalAmount:0,checkoutUrl:t.checkoutUrl});export{normalizeCart};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { createCartOperation } from './api/operations/create-cart.js';
|
|
3
|
-
export { getCartOperation } from './api/operations/get-cart.js';
|
|
4
|
-
export { removeCartItemOperation } from './api/operations/remove-cart-item.js';
|
|
5
|
-
export { updateCartLineOperation } from './api/operations/update-cart-line.js';
|
|
1
|
+
export{addToCartOperation}from"./api/operations/add-to-cart.js";export{createCartOperation}from"./api/operations/create-cart.js";export{getCartOperation}from"./api/operations/get-cart.js";export{removeCartItemOperation}from"./api/operations/remove-cart-item.js";export{updateCartLineOperation}from"./api/operations/update-cart-line.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/adapter-bigcommerce",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typegen": "graphql-codegen --config codegen/codegen.yml"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@gem-sdk/adapter-common": "2.0.0
|
|
26
|
+
"@gem-sdk/adapter-common": "2.0.0"
|
|
27
27
|
},
|
|
28
28
|
"module": "dist/esm/index.js",
|
|
29
29
|
"types": "dist/types/index.d.ts",
|