@gem-sdk/adapter-shopify 1.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/README.md +1 -0
- package/dist/cjs/api/operations/add-to-cart.js +32 -0
- package/dist/cjs/api/operations/cart-discount-codes-update.js +29 -0
- package/dist/cjs/api/operations/cart-note-update.js +28 -0
- package/dist/cjs/api/operations/create-cart.js +33 -0
- package/dist/cjs/api/operations/get-cart.js +27 -0
- package/dist/cjs/api/operations/remove-cart-item.js +28 -0
- package/dist/cjs/api/operations/update-cart-line.js +34 -0
- package/dist/cjs/graphql/fragments/cart-line.generated.js +54 -0
- package/dist/cjs/graphql/fragments/cart-user-error.generated.js +11 -0
- package/dist/cjs/graphql/fragments/cart.generated.js +46 -0
- package/dist/cjs/graphql/fragments/country.generated.js +14 -0
- package/dist/cjs/graphql/fragments/currency.generated.js +11 -0
- package/dist/cjs/graphql/fragments/image.generated.js +13 -0
- package/dist/cjs/graphql/fragments/money-v2.generated.js +10 -0
- package/dist/cjs/graphql/fragments/product.generated.js +52 -0
- package/dist/cjs/graphql/mutations/cart-create.generated.js +27 -0
- package/dist/cjs/graphql/mutations/cart-discount-codes-update.generated.js +27 -0
- package/dist/cjs/graphql/mutations/cart-lines-add.generated.js +27 -0
- package/dist/cjs/graphql/mutations/cart-lines-remove.generated.js +27 -0
- package/dist/cjs/graphql/mutations/cart-lines-update.generated.js +27 -0
- package/dist/cjs/graphql/mutations/cart-note-update.generated.js +27 -0
- package/dist/cjs/graphql/queries/cart.generated.js +20 -0
- package/dist/cjs/graphql/queries/product.generated.js +13 -0
- package/dist/cjs/graphql/queries/shop-meta.generated.js +21 -0
- package/dist/cjs/helpers/common.js +15 -0
- package/dist/cjs/helpers/normalize.js +58 -0
- package/dist/cjs/index.js +35 -0
- package/dist/esm/api/operations/add-to-cart.js +30 -0
- package/dist/esm/api/operations/cart-discount-codes-update.js +27 -0
- package/dist/esm/api/operations/cart-note-update.js +26 -0
- package/dist/esm/api/operations/create-cart.js +31 -0
- package/dist/esm/api/operations/get-cart.js +25 -0
- package/dist/esm/api/operations/remove-cart-item.js +26 -0
- package/dist/esm/api/operations/update-cart-line.js +32 -0
- package/dist/esm/graphql/fragments/cart-line.generated.js +51 -0
- package/dist/esm/graphql/fragments/cart-user-error.generated.js +9 -0
- package/dist/esm/graphql/fragments/cart.generated.js +44 -0
- package/dist/esm/graphql/fragments/country.generated.js +12 -0
- package/dist/esm/graphql/fragments/currency.generated.js +9 -0
- package/dist/esm/graphql/fragments/image.generated.js +11 -0
- package/dist/esm/graphql/fragments/money-v2.generated.js +8 -0
- package/dist/esm/graphql/fragments/product.generated.js +50 -0
- package/dist/esm/graphql/mutations/cart-create.generated.js +25 -0
- package/dist/esm/graphql/mutations/cart-discount-codes-update.generated.js +25 -0
- package/dist/esm/graphql/mutations/cart-lines-add.generated.js +25 -0
- package/dist/esm/graphql/mutations/cart-lines-remove.generated.js +25 -0
- package/dist/esm/graphql/mutations/cart-lines-update.generated.js +25 -0
- package/dist/esm/graphql/mutations/cart-note-update.generated.js +25 -0
- package/dist/esm/graphql/queries/cart.generated.js +18 -0
- package/dist/esm/graphql/queries/product.generated.js +11 -0
- package/dist/esm/graphql/queries/shop-meta.generated.js +19 -0
- package/dist/esm/helpers/common.js +13 -0
- package/dist/esm/helpers/normalize.js +56 -0
- package/dist/esm/index.js +15 -0
- package/dist/types/index.d.ts +3686 -0
- package/package.json +38 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CartSelect } from '../fragments/cart.generated.js';
|
|
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
|
+
|
|
6
|
+
const CartDocument = `
|
|
7
|
+
query cart($id: ID!) {
|
|
8
|
+
cart(id: $id) {
|
|
9
|
+
...CartSelect
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
${CartSelect}
|
|
13
|
+
${MoneyV2Select}
|
|
14
|
+
${CartLineSelect}
|
|
15
|
+
${CartProductVariantSelect}
|
|
16
|
+
${ImageSelect}`;
|
|
17
|
+
|
|
18
|
+
export { CartDocument };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ProductSelect } from '../fragments/product.generated.js';
|
|
2
|
+
|
|
3
|
+
const ProductDocument = `
|
|
4
|
+
query product($handle: String, $id: ID) {
|
|
5
|
+
product(handle: $handle, id: $id) {
|
|
6
|
+
...ProductSelect
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
${ProductSelect}`;
|
|
10
|
+
|
|
11
|
+
export { ProductDocument };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CountrySelect } from '../fragments/country.generated.js';
|
|
2
|
+
import { CurrencySelect } from '../fragments/currency.generated.js';
|
|
3
|
+
|
|
4
|
+
const ShopMetaDocument = `
|
|
5
|
+
query shopMeta {
|
|
6
|
+
localization {
|
|
7
|
+
country {
|
|
8
|
+
...CountrySelect
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
shop {
|
|
12
|
+
name
|
|
13
|
+
description
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
${CountrySelect}
|
|
17
|
+
${CurrencySelect}`;
|
|
18
|
+
|
|
19
|
+
export { ShopMetaDocument };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const composeRequest = (config) => {
|
|
2
|
+
return {
|
|
3
|
+
method: 'POST',
|
|
4
|
+
headers: {
|
|
5
|
+
'Content-Type': 'application/json',
|
|
6
|
+
...(config.storefrontToken
|
|
7
|
+
? { 'X-Shopify-Storefront-Access-Token': config.storefrontToken }
|
|
8
|
+
: {}),
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { composeRequest };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const normalizeCartProductVariant = (variant) => {
|
|
2
|
+
const { compareAtPriceV2, priceV2, weight, weightUnit, id, sku, image } = variant;
|
|
3
|
+
return {
|
|
4
|
+
id,
|
|
5
|
+
requiresShipping: variant.requiresShipping,
|
|
6
|
+
availableForSale: variant.availableForSale,
|
|
7
|
+
sku: sku ?? id,
|
|
8
|
+
name: variant.title,
|
|
9
|
+
listPrice: compareAtPriceV2?.amount ? +compareAtPriceV2?.amount : 0,
|
|
10
|
+
price: +priceV2.amount,
|
|
11
|
+
weight: {
|
|
12
|
+
value: weight ?? 0,
|
|
13
|
+
unit: weightUnit,
|
|
14
|
+
},
|
|
15
|
+
image,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const normalizeLineItem = (lineItem) => {
|
|
19
|
+
const { quantity, id, merchandise } = lineItem;
|
|
20
|
+
const variant = normalizeCartProductVariant(merchandise);
|
|
21
|
+
return {
|
|
22
|
+
id,
|
|
23
|
+
quantity,
|
|
24
|
+
variant,
|
|
25
|
+
attributes: lineItem.attributes,
|
|
26
|
+
variantId: variant.id,
|
|
27
|
+
name: variant.name,
|
|
28
|
+
productTitle: merchandise.product.title,
|
|
29
|
+
productId: variant.id,
|
|
30
|
+
path: merchandise.product.handle,
|
|
31
|
+
discounts: [],
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const normalizeCart = (cart) => {
|
|
35
|
+
const { cost } = cart;
|
|
36
|
+
return {
|
|
37
|
+
createdAt: cart.createdAt,
|
|
38
|
+
id: cart.id,
|
|
39
|
+
lineItems: cart.lines.nodes.map(normalizeLineItem),
|
|
40
|
+
subtotalPrice: +cost.subtotalAmount.amount,
|
|
41
|
+
totalPrice: +cost.totalAmount.amount,
|
|
42
|
+
currency: {
|
|
43
|
+
code: cost.totalAmount.currencyCode,
|
|
44
|
+
},
|
|
45
|
+
taxesIncluded: true,
|
|
46
|
+
lineItemsSubtotalPrice: +cost.subtotalAmount.amount,
|
|
47
|
+
checkoutUrl: cart.checkoutUrl,
|
|
48
|
+
note: cart.note,
|
|
49
|
+
discounts: cart.discountCodes.map((v) => ({
|
|
50
|
+
code: v.code,
|
|
51
|
+
applicable: v.applicable,
|
|
52
|
+
})),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { normalizeCart };
|
|
@@ -0,0 +1,15 @@
|
|
|
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';
|
|
6
|
+
export { cartDiscountCodesUpdateOperation } from './api/operations/cart-discount-codes-update.js';
|
|
7
|
+
export { cartNoteUpdateOperation } from './api/operations/cart-note-update.js';
|
|
8
|
+
export { ProductDocument } from './graphql/queries/product.generated.js';
|
|
9
|
+
export { ShopMetaDocument } from './graphql/queries/shop-meta.generated.js';
|
|
10
|
+
export { CartCreateDocument } from './graphql/mutations/cart-create.generated.js';
|
|
11
|
+
export { CartDiscountCodesUpdateDocument } from './graphql/mutations/cart-discount-codes-update.generated.js';
|
|
12
|
+
export { CartLinesAddDocument } from './graphql/mutations/cart-lines-add.generated.js';
|
|
13
|
+
export { CartLinesRemoveDocument } from './graphql/mutations/cart-lines-remove.generated.js';
|
|
14
|
+
export { CartLinesUpdateDocument } from './graphql/mutations/cart-lines-update.generated.js';
|
|
15
|
+
export { CartNoteUpdateDocument } from './graphql/mutations/cart-note-update.generated.js';
|