@plasmicpkgs/commerce-saleor 0.0.111 → 0.0.113

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.
@@ -1,6 +1,6 @@
1
1
  import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
2
2
  import React, { useMemo, useCallback } from 'react';
3
- import { FetcherError, ValidationError, CommerceError, useCart, useCommerce as useCommerce$1, getCommerceProvider as getCommerceProvider$1 } from '@plasmicpkgs/commerce';
3
+ import { FetcherError, ValidationError, CommerceError, useCart, useCommerce as useCommerce$1, getCommerceProvider as getCommerceProvider$1, CartActionsProvider, globalActionsRegistrations } from '@plasmicpkgs/commerce';
4
4
  import Cookies from 'js-cookie';
5
5
  import debounce from 'debounce';
6
6
 
@@ -878,7 +878,7 @@ var ProductConnection = /* GraphQL */"\n fragment ProductConnection on ProductC
878
878
  Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
879
879
  Changes: None
880
880
  */
881
- var CheckoutDetails = /* GraphQL */"\n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n";
881
+ var CheckoutDetails = /* GraphQL */"\n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n id\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n";
882
882
 
883
883
  /*
884
884
  Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
@@ -944,18 +944,19 @@ var checkoutCreate = /*#__PURE__*/function () {
944
944
  }();
945
945
 
946
946
  var _excluded = ["id", "name", "media", "variants", "description", "slug", "pricing"];
947
+ /* eslint-disable */
947
948
  /*
948
949
  Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
949
950
  Changes: None
950
951
  */
951
952
  // TODO: Check nextjs-commerce bug if no images are added for a product
952
- var placeholderImg = '/product-img-placeholder.svg';
953
+ var placeholderImg = "/product-img-placeholder.svg";
953
954
  var money = function money(_ref) {
954
955
  var amount = _ref.amount,
955
956
  currency = _ref.currency;
956
957
  return {
957
958
  value: +amount,
958
- currencyCode: currency || 'USD'
959
+ currencyCode: currency || "USD"
959
960
  };
960
961
  };
961
962
  var normalizeProductOptions = function normalizeProductOptions(options) {
@@ -977,9 +978,9 @@ var normalizeProductOptions = function normalizeProductOptions(options) {
977
978
  });
978
979
  }
979
980
  return acc.concat({
980
- __typename: 'MultipleChoiceOption',
981
+ __typename: "MultipleChoiceOption",
981
982
  displayName: x.attribute.name,
982
- variant: 'size',
983
+ variant: "size",
983
984
  values: x.values.map(function (value) {
984
985
  return {
985
986
  label: value == null ? void 0 : value.name
@@ -1021,13 +1022,13 @@ function normalizeProduct(productNode) {
1021
1022
  var product = _extends({
1022
1023
  id: id,
1023
1024
  name: name,
1024
- vendor: '',
1025
- description: description ? (_JSON$parse = JSON.parse(description)) == null ? void 0 : (_JSON$parse$blocks$ = _JSON$parse.blocks[0]) == null ? void 0 : _JSON$parse$blocks$.data.text : '',
1025
+ vendor: "",
1026
+ description: description ? (_JSON$parse = JSON.parse(description)) == null ? void 0 : (_JSON$parse$blocks$ = _JSON$parse.blocks[0]) == null ? void 0 : _JSON$parse$blocks$.data.text : "",
1026
1027
  path: "/" + slug,
1027
- slug: slug == null ? void 0 : slug.replace(/^\/+|\/+$/g, ''),
1028
+ slug: slug == null ? void 0 : slug.replace(/^\/+|\/+$/g, ""),
1028
1029
  price: (pricing == null ? void 0 : (_pricing$priceRange = pricing.priceRange) == null ? void 0 : (_pricing$priceRange$s = _pricing$priceRange.start) == null ? void 0 : _pricing$priceRange$s.net) && money(pricing.priceRange.start.net) || {
1029
1030
  value: 0,
1030
- currencyCode: 'USD'
1031
+ currencyCode: "USD"
1031
1032
  },
1032
1033
  // TODO: Check nextjs-commerce bug if no images are added for a product
1033
1034
  images: media != null && media.length ? media : [{
@@ -1044,8 +1045,8 @@ function normalizeCart(checkout) {
1044
1045
  var lineItems = lines.length > 0 ? lines == null ? void 0 : lines.map(normalizeLineItem) : [];
1045
1046
  return {
1046
1047
  id: checkout.id,
1047
- customerId: '',
1048
- email: '',
1048
+ customerId: "",
1049
+ email: "",
1049
1050
  createdAt: checkout.created,
1050
1051
  currency: {
1051
1052
  code: (_checkout$totalPrice = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice.currency
@@ -1059,19 +1060,19 @@ function normalizeCart(checkout) {
1059
1060
  };
1060
1061
  }
1061
1062
  function normalizeLineItem(_ref3) {
1062
- var _variant$sku, _variant$pricing, _variant$pricing$pric, _variant$product;
1063
+ var _variant$product, _variant$sku, _variant$pricing, _variant$pricing$pric, _variant$product2;
1063
1064
  var id = _ref3.id,
1064
1065
  variant = _ref3.variant,
1065
1066
  quantity = _ref3.quantity;
1066
1067
  return {
1067
1068
  id: id,
1068
1069
  variantId: String(variant == null ? void 0 : variant.id),
1069
- productId: String(variant == null ? void 0 : variant.id),
1070
+ productId: String(variant == null ? void 0 : (_variant$product = variant.product) == null ? void 0 : _variant$product.id),
1070
1071
  name: "" + variant.product.name,
1071
1072
  quantity: quantity,
1072
1073
  variant: {
1073
1074
  id: String(variant == null ? void 0 : variant.id),
1074
- sku: (_variant$sku = variant == null ? void 0 : variant.sku) != null ? _variant$sku : '',
1075
+ sku: (_variant$sku = variant == null ? void 0 : variant.sku) != null ? _variant$sku : "",
1075
1076
  name: variant == null ? void 0 : variant.name,
1076
1077
  image: {
1077
1078
  url: variant != null && variant.media[0] ? variant == null ? void 0 : variant.media[0].url : placeholderImg
@@ -1080,7 +1081,7 @@ function normalizeLineItem(_ref3) {
1080
1081
  price: variant == null ? void 0 : (_variant$pricing = variant.pricing) == null ? void 0 : (_variant$pricing$pric = _variant$pricing.price) == null ? void 0 : _variant$pricing$pric.gross.amount,
1081
1082
  listPrice: 0
1082
1083
  },
1083
- path: String(variant == null ? void 0 : (_variant$product = variant.product) == null ? void 0 : _variant$product.slug),
1084
+ path: String(variant == null ? void 0 : (_variant$product2 = variant.product) == null ? void 0 : _variant$product2.slug),
1084
1085
  discounts: [],
1085
1086
  options: []
1086
1087
  };
@@ -1462,7 +1463,7 @@ var handler$3 = {
1462
1463
  variables: {
1463
1464
  checkoutId: checkoutId,
1464
1465
  lineItems: [{
1465
- variantId: item.variantId,
1466
+ itemId: itemId,
1466
1467
  quantity: item.quantity
1467
1468
  }]
1468
1469
  }
@@ -1492,41 +1493,37 @@ var handler$3 = {
1492
1493
  mutate = _useCart.mutate;
1493
1494
  return useCallback(debounce( /*#__PURE__*/function () {
1494
1495
  var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
1495
- var _input$id, _input$productId, _input$productId2;
1496
- var itemId, productId, variantId, data;
1496
+ var _input$id;
1497
+ var itemId, data;
1497
1498
  return runtime_1.wrap(function _callee2$(_context2) {
1498
1499
  while (1) {
1499
1500
  switch (_context2.prev = _context2.next) {
1500
1501
  case 0:
1501
1502
  itemId = (_input$id = input.id) != null ? _input$id : item == null ? void 0 : item.id;
1502
- productId = (_input$productId = input.productId) != null ? _input$productId : item == null ? void 0 : item.productId;
1503
- variantId = (_input$productId2 = input.productId) != null ? _input$productId2 : item == null ? void 0 : item.variantId;
1504
- if (!(!itemId || !productId || !variantId)) {
1505
- _context2.next = 5;
1503
+ if (itemId) {
1504
+ _context2.next = 3;
1506
1505
  break;
1507
1506
  }
1508
1507
  throw new ValidationError({
1509
1508
  message: "Invalid input used for this operation"
1510
1509
  });
1511
- case 5:
1512
- _context2.next = 7;
1510
+ case 3:
1511
+ _context2.next = 5;
1513
1512
  return fetch({
1514
1513
  input: {
1515
1514
  item: {
1516
- productId: productId,
1517
- variantId: variantId,
1518
1515
  quantity: input.quantity
1519
1516
  },
1520
1517
  itemId: itemId
1521
1518
  }
1522
1519
  });
1523
- case 7:
1520
+ case 5:
1524
1521
  data = _context2.sent;
1525
- _context2.next = 10;
1522
+ _context2.next = 8;
1526
1523
  return mutate(data, false);
1527
- case 10:
1524
+ case 8:
1528
1525
  return _context2.abrupt("return", data);
1529
- case 11:
1526
+ case 9:
1530
1527
  case "end":
1531
1528
  return _context2.stop();
1532
1529
  }
@@ -1871,8 +1868,9 @@ var getCommerceProvider = function getCommerceProvider(saleorApiUrl) {
1871
1868
  return getCommerceProvider$1(getSaleorProvider(saleorApiUrl));
1872
1869
  };
1873
1870
 
1871
+ var globalContextName = "plasmic-commerce-saleor-provider";
1874
1872
  var commerceProviderMeta = {
1875
- name: "plasmic-commerce-saleor-provider",
1873
+ name: globalContextName,
1876
1874
  displayName: "Saleor Provider",
1877
1875
  props: {
1878
1876
  saleorApiUrl: {
@@ -1880,6 +1878,7 @@ var commerceProviderMeta = {
1880
1878
  defaultValue: "https://vercel.saleor.cloud/graphql/"
1881
1879
  }
1882
1880
  },
1881
+ unstable__globalActions: globalActionsRegistrations,
1883
1882
  importPath: "@plasmicpkgs/commerce-saleor",
1884
1883
  importName: "CommerceProviderComponent"
1885
1884
  };
@@ -1889,7 +1888,9 @@ function CommerceProviderComponent(props) {
1889
1888
  var CommerceProvider = React.useMemo(function () {
1890
1889
  return getCommerceProvider(saleorApiUrl);
1891
1890
  }, [saleorApiUrl]);
1892
- return React.createElement(CommerceProvider, null, children);
1891
+ return React.createElement(CommerceProvider, null, React.createElement(CartActionsProvider, {
1892
+ globalContextName: globalContextName
1893
+ }, children));
1893
1894
  }
1894
1895
  function registerCommerceProvider(loader, customCommerceProviderMeta) {
1895
1896
  var doRegisterComponent = function doRegisterComponent() {