@gem-sdk/adapter-bigcommerce 1.14.0-dev.284 → 1.22.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 +35 -1
- package/dist/cjs/api/operations/create-cart.js +35 -1
- package/dist/cjs/api/operations/get-cart.js +30 -1
- package/dist/cjs/api/operations/remove-cart-item.js +34 -1
- package/dist/cjs/api/operations/update-cart-line.js +38 -1
- package/dist/cjs/graphql/fragments/cart-line.generated.js +9 -3
- package/dist/cjs/graphql/fragments/cart.generated.js +6 -2
- package/dist/cjs/graphql/fragments/media.generated.js +6 -2
- package/dist/cjs/graphql/mutations/cart-create.generated.js +10 -2
- package/dist/cjs/graphql/mutations/cart-lines-add.generated.js +10 -2
- package/dist/cjs/graphql/mutations/cart-lines-remove.generated.js +10 -2
- package/dist/cjs/graphql/mutations/cart-lines-update.generated.js +10 -2
- package/dist/cjs/graphql/queries/cart.generated.js +10 -2
- package/dist/cjs/helpers/common.js +15 -1
- package/dist/cjs/helpers/normalize.js +46 -1
- package/dist/cjs/index.js +15 -1
- package/dist/esm/api/operations/add-to-cart.js +33 -1
- package/dist/esm/api/operations/create-cart.js +33 -1
- package/dist/esm/api/operations/get-cart.js +28 -1
- package/dist/esm/api/operations/remove-cart-item.js +32 -1
- package/dist/esm/api/operations/update-cart-line.js +36 -1
- package/dist/esm/graphql/fragments/cart-line.generated.js +6 -3
- package/dist/esm/graphql/fragments/cart.generated.js +4 -2
- package/dist/esm/graphql/fragments/media.generated.js +4 -2
- package/dist/esm/graphql/mutations/cart-create.generated.js +11 -5
- package/dist/esm/graphql/mutations/cart-lines-add.generated.js +11 -5
- package/dist/esm/graphql/mutations/cart-lines-remove.generated.js +11 -5
- package/dist/esm/graphql/mutations/cart-lines-update.generated.js +11 -5
- package/dist/esm/graphql/queries/cart.generated.js +11 -5
- package/dist/esm/helpers/common.js +13 -1
- package/dist/esm/helpers/normalize.js +44 -1
- package/dist/esm/index.js +5 -1
- package/package.json +2 -2
|
@@ -1 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */ const CartProductVariantSelect = `
|
|
2
4
|
fragment CartProductVariantSelect on ProductVariant {
|
|
3
5
|
id
|
|
4
6
|
title
|
|
@@ -25,7 +27,8 @@
|
|
|
25
27
|
length
|
|
26
28
|
isDigital
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
`;
|
|
31
|
+
const CartLineSelect = `
|
|
29
32
|
fragment CartLineSelect on CartLine {
|
|
30
33
|
id
|
|
31
34
|
quantity
|
|
@@ -35,4 +38,7 @@
|
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
|
-
`;
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
exports.CartLineSelect = CartLineSelect;
|
|
44
|
+
exports.CartProductVariantSelect = CartProductVariantSelect;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */ const CartSelect = `
|
|
2
4
|
fragment CartSelect on Cart {
|
|
3
5
|
id
|
|
4
6
|
attribute {
|
|
@@ -44,4 +46,6 @@
|
|
|
44
46
|
totalTaxAmountCurrencyCode
|
|
45
47
|
updatedAt
|
|
46
48
|
}
|
|
47
|
-
`;
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
exports.CartSelect = CartSelect;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */ const MediaSelect = `
|
|
2
4
|
fragment MediaSelect on Media {
|
|
3
5
|
alt
|
|
4
6
|
src
|
|
@@ -7,4 +9,6 @@
|
|
|
7
9
|
height
|
|
8
10
|
contentType
|
|
9
11
|
}
|
|
10
|
-
`;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
exports.MediaSelect = MediaSelect;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 = `
|
|
2
8
|
mutation cartCreate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $input: CartInput!) {
|
|
3
9
|
cartCreate(input: $input) {
|
|
4
10
|
cart {
|
|
@@ -14,4 +20,6 @@
|
|
|
14
20
|
${cart_generated.CartSelect}
|
|
15
21
|
${cartLine_generated.CartLineSelect}
|
|
16
22
|
${cartLine_generated.CartProductVariantSelect}
|
|
17
|
-
${media_generated.MediaSelect}`;
|
|
23
|
+
${media_generated.MediaSelect}`;
|
|
24
|
+
|
|
25
|
+
exports.CartCreateDocument = CartCreateDocument;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 = `
|
|
2
8
|
mutation cartLinesAdd($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineInput!]!, $platform: Int!) {
|
|
3
9
|
cartLinesAdd(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
4
10
|
cart {
|
|
@@ -14,4 +20,6 @@
|
|
|
14
20
|
${cart_generated.CartSelect}
|
|
15
21
|
${cartLine_generated.CartLineSelect}
|
|
16
22
|
${cartLine_generated.CartProductVariantSelect}
|
|
17
|
-
${media_generated.MediaSelect}`;
|
|
23
|
+
${media_generated.MediaSelect}`;
|
|
24
|
+
|
|
25
|
+
exports.CartLinesAddDocument = CartLinesAddDocument;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 = `
|
|
2
8
|
mutation cartLinesRemove($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lineIds: [ID!]!, $platform: Int!) {
|
|
3
9
|
cartLinesRemove(cartId: $cartId, lineIds: $lineIds, platform: $platform) {
|
|
4
10
|
cart {
|
|
@@ -14,4 +20,6 @@
|
|
|
14
20
|
${cart_generated.CartSelect}
|
|
15
21
|
${cartLine_generated.CartLineSelect}
|
|
16
22
|
${cartLine_generated.CartProductVariantSelect}
|
|
17
|
-
${media_generated.MediaSelect}`;
|
|
23
|
+
${media_generated.MediaSelect}`;
|
|
24
|
+
|
|
25
|
+
exports.CartLinesRemoveDocument = CartLinesRemoveDocument;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 = `
|
|
2
8
|
mutation cartLinesUpdate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineUpdateInput!]!, $platform: Int!) {
|
|
3
9
|
cartLinesUpdate(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
4
10
|
cart {
|
|
@@ -14,4 +20,6 @@
|
|
|
14
20
|
${cart_generated.CartSelect}
|
|
15
21
|
${cartLine_generated.CartLineSelect}
|
|
16
22
|
${cartLine_generated.CartProductVariantSelect}
|
|
17
|
-
${media_generated.MediaSelect}`;
|
|
23
|
+
${media_generated.MediaSelect}`;
|
|
24
|
+
|
|
25
|
+
exports.CartLinesUpdateDocument = CartLinesUpdateDocument;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 = `
|
|
2
8
|
query cart($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $id: ID!) {
|
|
3
9
|
cart(id: $id) {
|
|
4
10
|
...CartSelect
|
|
@@ -7,4 +13,6 @@
|
|
|
7
13
|
${cart_generated.CartSelect}
|
|
8
14
|
${cartLine_generated.CartLineSelect}
|
|
9
15
|
${cartLine_generated.CartProductVariantSelect}
|
|
10
|
-
${media_generated.MediaSelect}`;
|
|
16
|
+
${media_generated.MediaSelect}`;
|
|
17
|
+
|
|
18
|
+
exports.CartDocument = CartDocument;
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
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 +1,33 @@
|
|
|
1
|
-
import{CartLinesAddDocument
|
|
1
|
+
import { CartLinesAddDocument } from '../../graphql/mutations/cart-lines-add.generated.js';
|
|
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 +1,33 @@
|
|
|
1
|
-
import{CartCreateDocument
|
|
1
|
+
import { CartCreateDocument } from '../../graphql/mutations/cart-create.generated.js';
|
|
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 +1,28 @@
|
|
|
1
|
-
import{CartDocument
|
|
1
|
+
import { CartDocument } from '../../graphql/queries/cart.generated.js';
|
|
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 +1,32 @@
|
|
|
1
|
-
import{CartLinesRemoveDocument
|
|
1
|
+
import { CartLinesRemoveDocument } from '../../graphql/mutations/cart-lines-remove.generated.js';
|
|
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 +1,36 @@
|
|
|
1
|
-
import{CartLinesUpdateDocument
|
|
1
|
+
import { CartLinesUpdateDocument } from '../../graphql/mutations/cart-lines-update.generated.js';
|
|
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,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable */ const CartProductVariantSelect = `
|
|
2
2
|
fragment CartProductVariantSelect on ProductVariant {
|
|
3
3
|
id
|
|
4
4
|
title
|
|
@@ -25,7 +25,8 @@ let CartProductVariantSelect=`
|
|
|
25
25
|
length
|
|
26
26
|
isDigital
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
`;
|
|
29
|
+
const CartLineSelect = `
|
|
29
30
|
fragment CartLineSelect on CartLine {
|
|
30
31
|
id
|
|
31
32
|
quantity
|
|
@@ -35,4 +36,6 @@ let CartProductVariantSelect=`
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
`;
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export { CartLineSelect, CartProductVariantSelect };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import{CartSelect
|
|
1
|
+
import { CartSelect } from '../fragments/cart.generated.js';
|
|
2
|
+
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
+
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
+
|
|
5
|
+
const CartCreateDocument = `
|
|
2
6
|
mutation cartCreate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $input: CartInput!) {
|
|
3
7
|
cartCreate(input: $input) {
|
|
4
8
|
cart {
|
|
@@ -11,7 +15,9 @@ import{CartSelect as e}from"../fragments/cart.generated.js";import{CartLineSelec
|
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
|
-
${
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
+
${CartSelect}
|
|
19
|
+
${CartLineSelect}
|
|
20
|
+
${CartProductVariantSelect}
|
|
21
|
+
${MediaSelect}`;
|
|
22
|
+
|
|
23
|
+
export { CartCreateDocument };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import{CartSelect
|
|
1
|
+
import { CartSelect } from '../fragments/cart.generated.js';
|
|
2
|
+
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
+
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
+
|
|
5
|
+
const CartLinesAddDocument = `
|
|
2
6
|
mutation cartLinesAdd($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineInput!]!, $platform: Int!) {
|
|
3
7
|
cartLinesAdd(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
4
8
|
cart {
|
|
@@ -11,7 +15,9 @@ import{CartSelect as r}from"../fragments/cart.generated.js";import{CartLineSelec
|
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
|
-
${
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
+
${CartSelect}
|
|
19
|
+
${CartLineSelect}
|
|
20
|
+
${CartProductVariantSelect}
|
|
21
|
+
${MediaSelect}`;
|
|
22
|
+
|
|
23
|
+
export { CartLinesAddDocument };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import{CartSelect
|
|
1
|
+
import { CartSelect } from '../fragments/cart.generated.js';
|
|
2
|
+
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
+
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
+
|
|
5
|
+
const CartLinesRemoveDocument = `
|
|
2
6
|
mutation cartLinesRemove($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lineIds: [ID!]!, $platform: Int!) {
|
|
3
7
|
cartLinesRemove(cartId: $cartId, lineIds: $lineIds, platform: $platform) {
|
|
4
8
|
cart {
|
|
@@ -11,7 +15,9 @@ import{CartSelect as e}from"../fragments/cart.generated.js";import{CartLineSelec
|
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
|
-
${
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
+
${CartSelect}
|
|
19
|
+
${CartLineSelect}
|
|
20
|
+
${CartProductVariantSelect}
|
|
21
|
+
${MediaSelect}`;
|
|
22
|
+
|
|
23
|
+
export { CartLinesRemoveDocument };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import{CartSelect
|
|
1
|
+
import { CartSelect } from '../fragments/cart.generated.js';
|
|
2
|
+
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
+
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
+
|
|
5
|
+
const CartLinesUpdateDocument = `
|
|
2
6
|
mutation cartLinesUpdate($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $cartId: ID!, $lines: [CartLineUpdateInput!]!, $platform: Int!) {
|
|
3
7
|
cartLinesUpdate(cartId: $cartId, lines: $lines, platform: $platform) {
|
|
4
8
|
cart {
|
|
@@ -11,7 +15,9 @@ import{CartSelect as e}from"../fragments/cart.generated.js";import{CartLineSelec
|
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
|
-
${
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
+
${CartSelect}
|
|
19
|
+
${CartLineSelect}
|
|
20
|
+
${CartProductVariantSelect}
|
|
21
|
+
${MediaSelect}`;
|
|
22
|
+
|
|
23
|
+
export { CartLinesUpdateDocument };
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import{CartSelect
|
|
1
|
+
import { CartSelect } from '../fragments/cart.generated.js';
|
|
2
|
+
import { CartLineSelect, CartProductVariantSelect } from '../fragments/cart-line.generated.js';
|
|
3
|
+
import { MediaSelect } from '../fragments/media.generated.js';
|
|
4
|
+
|
|
5
|
+
const CartDocument = `
|
|
2
6
|
query cart($after: Cursor, $before: Cursor, $first: Int = 50, $last: Int, $query: CartLineWhereInput, $id: ID!) {
|
|
3
7
|
cart(id: $id) {
|
|
4
8
|
...CartSelect
|
|
5
9
|
}
|
|
6
10
|
}
|
|
7
|
-
${
|
|
8
|
-
${
|
|
9
|
-
${
|
|
10
|
-
${
|
|
11
|
+
${CartSelect}
|
|
12
|
+
${CartLineSelect}
|
|
13
|
+
${CartProductVariantSelect}
|
|
14
|
+
${MediaSelect}`;
|
|
15
|
+
|
|
16
|
+
export { CartDocument };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
const composeRequest = (config)=>{
|
|
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 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
const normalizeLineItem = (item)=>{
|
|
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 };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export{addToCartOperation}from
|
|
1
|
+
export { addToCartOperation } from './api/operations/add-to-cart.js';
|
|
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/adapter-bigcommerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.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": "
|
|
26
|
+
"@gem-sdk/adapter-common": "*"
|
|
27
27
|
},
|
|
28
28
|
"module": "dist/esm/index.js",
|
|
29
29
|
"types": "dist/types/index.d.ts",
|