@plasmicpkgs/commerce-shopify 0.0.1 → 0.0.6

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.
@@ -4,12 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
- var registerComponent = _interopDefault(require('@plasmicapp/host/registerComponent'));
8
7
  var React = require('react');
9
8
  var React__default = _interopDefault(React);
10
9
  var commerce = require('@plasmicpkgs/commerce');
11
10
  var Cookies = _interopDefault(require('js-cookie'));
12
11
  var debounce = _interopDefault(require('lodash.debounce'));
12
+ var registerGlobalContext = _interopDefault(require('@plasmicapp/host/registerGlobalContext'));
13
13
 
14
14
  /*
15
15
  Forked from https://github.com/vercel/commerce/tree/main/packages/shopify/src
@@ -180,9 +180,9 @@ var runtime = (function (exports) {
180
180
  // This is a polyfill for %IteratorPrototype% for environments that
181
181
  // don't natively support it.
182
182
  var IteratorPrototype = {};
183
- IteratorPrototype[iteratorSymbol] = function () {
183
+ define(IteratorPrototype, iteratorSymbol, function () {
184
184
  return this;
185
- };
185
+ });
186
186
 
187
187
  var getProto = Object.getPrototypeOf;
188
188
  var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
@@ -196,8 +196,9 @@ var runtime = (function (exports) {
196
196
 
197
197
  var Gp = GeneratorFunctionPrototype.prototype =
198
198
  Generator.prototype = Object.create(IteratorPrototype);
199
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
200
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
199
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
200
+ define(Gp, "constructor", GeneratorFunctionPrototype);
201
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
201
202
  GeneratorFunction.displayName = define(
202
203
  GeneratorFunctionPrototype,
203
204
  toStringTagSymbol,
@@ -311,9 +312,9 @@ var runtime = (function (exports) {
311
312
  }
312
313
 
313
314
  defineIteratorMethods(AsyncIterator.prototype);
314
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
315
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
315
316
  return this;
316
- };
317
+ });
317
318
  exports.AsyncIterator = AsyncIterator;
318
319
 
319
320
  // Note that simple async functions are implemented on top of
@@ -506,13 +507,13 @@ var runtime = (function (exports) {
506
507
  // iterator prototype chain incorrectly implement this, causing the Generator
507
508
  // object to not be returned from this call. This ensures that doesn't happen.
508
509
  // See https://github.com/facebook/regenerator/issues/274 for more details.
509
- Gp[iteratorSymbol] = function() {
510
+ define(Gp, iteratorSymbol, function() {
510
511
  return this;
511
- };
512
+ });
512
513
 
513
- Gp.toString = function() {
514
+ define(Gp, "toString", function() {
514
515
  return "[object Generator]";
515
- };
516
+ });
516
517
 
517
518
  function pushTryEntry(locs) {
518
519
  var entry = { tryLoc: locs[0] };
@@ -831,14 +832,19 @@ try {
831
832
  } catch (accidentalStrictMode) {
832
833
  // This module should not be running in strict mode, so the above
833
834
  // assignment should always work unless something is misconfigured. Just
834
- // in case runtime.js accidentally runs in strict mode, we can escape
835
+ // in case runtime.js accidentally runs in strict mode, in modern engines
836
+ // we can explicitly access globalThis. In older engines we can escape
835
837
  // strict mode using a global Function call. This could conceivably fail
836
838
  // if a Content Security Policy forbids using Function, but in that case
837
839
  // the proper solution is to fix the accidental strict mode problem. If
838
840
  // you've misconfigured your bundler to force strict mode and applied a
839
841
  // CSP to forbid Function, and you're not willing to fix either of those
840
842
  // problems, please detail your unique predicament in a GitHub issue.
841
- Function("r", "regeneratorRuntime = r")(runtime);
843
+ if (typeof globalThis === "object") {
844
+ globalThis.regeneratorRuntime = runtime;
845
+ } else {
846
+ Function("r", "regeneratorRuntime = r")(runtime);
847
+ }
842
848
  }
843
849
  });
844
850
 
@@ -1242,6 +1248,9 @@ var colorMap = {
1242
1248
  yellowgreen: '#9ACD32'
1243
1249
  };
1244
1250
 
1251
+ var _excluded = ["originalSrc"],
1252
+ _excluded2 = ["id", "title", "vendor", "images", "variants", "description", "descriptionHtml", "handle", "priceRange", "options", "metafields"];
1253
+
1245
1254
  var money = function money(_ref) {
1246
1255
  var amount = _ref.amount,
1247
1256
  currencyCode = _ref.currencyCode;
@@ -1288,7 +1297,7 @@ var normalizeProductImages = function normalizeProductImages(_ref3) {
1288
1297
  return edges == null ? void 0 : edges.map(function (_ref4) {
1289
1298
  var _ref4$node = _ref4.node,
1290
1299
  url = _ref4$node.originalSrc,
1291
- rest = _objectWithoutPropertiesLoose(_ref4$node, ["originalSrc"]);
1300
+ rest = _objectWithoutPropertiesLoose(_ref4$node, _excluded);
1292
1301
 
1293
1302
  return _extends({
1294
1303
  url: url
@@ -1343,7 +1352,7 @@ function normalizeProduct(_ref8) {
1343
1352
  handle = _ref8.handle,
1344
1353
  priceRange = _ref8.priceRange,
1345
1354
  options = _ref8.options,
1346
- rest = _objectWithoutPropertiesLoose(_ref8, ["id", "title", "vendor", "images", "variants", "description", "descriptionHtml", "handle", "priceRange", "options", "metafields"]);
1355
+ rest = _objectWithoutPropertiesLoose(_ref8, _excluded2);
1347
1356
 
1348
1357
  return _extends({
1349
1358
  id: id,
@@ -1429,19 +1438,21 @@ export const normalizePage = (
1429
1438
 
1430
1439
  export const normalizePages = (edges: PageEdge[], locale?: string): Page[] =>
1431
1440
  edges?.map((edge) => normalizePage(edge.node, locale))
1432
-
1433
- export const normalizeCategory = ({
1434
- title: name,
1435
- handle,
1436
- id,
1437
- }: Collection): Category => ({
1438
- id,
1439
- name,
1440
- slug: handle,
1441
- path: `/${handle}`,
1442
- })
1443
1441
  */
1444
1442
 
1443
+
1444
+ var normalizeCategory = function normalizeCategory(_ref10) {
1445
+ var name = _ref10.title,
1446
+ handle = _ref10.handle,
1447
+ id = _ref10.id;
1448
+ return {
1449
+ id: id,
1450
+ name: name,
1451
+ slug: handle,
1452
+ path: "/" + handle
1453
+ };
1454
+ };
1455
+
1445
1456
  /*
1446
1457
  Forked from https://github.com/vercel/commerce/tree/main/packages/shopify/src
1447
1458
  Changes: None
@@ -1484,6 +1495,14 @@ var checkoutToCart = function checkoutToCart(checkoutPayload) {
1484
1495
  return normalizeCart(checkoutPayload == null ? void 0 : checkoutPayload.checkout);
1485
1496
  };
1486
1497
 
1498
+ /*
1499
+ Forked from https://github.com/vercel/commerce/tree/main/packages/shopify/src
1500
+ Changes: None
1501
+ */
1502
+ var getSiteCollectionsQuery =
1503
+ /* GraphQL */
1504
+ "\n query getSiteCollections($first: Int!) {\n collections(first: $first) {\n edges {\n node {\n id\n title\n handle\n }\n }\n }\n }\n";
1505
+
1487
1506
  /*
1488
1507
  Forked from https://github.com/vercel/commerce/tree/main/packages/shopify/src
1489
1508
  Changes:
@@ -1491,11 +1510,19 @@ var checkoutToCart = function checkoutToCart(checkoutPayload) {
1491
1510
  */
1492
1511
  var productConnectionFragment =
1493
1512
  /* GraphQL */
1494
- "\n fragment productConnection on ProductConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n title\n vendor\n handle\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n }\n options {\n id\n name\n values\n }\n variants(first: 250) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n title\n sku\n availableForSale\n requiresShipping\n selectedOptions {\n name\n value\n }\n priceV2 {\n amount\n currencyCode\n }\n compareAtPriceV2 {\n amount\n currencyCode\n }\n }\n }\n }\n images(first: 250) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n originalSrc\n altText\n width\n height\n }\n }\n }\n }\n }\n }\n";
1513
+ "\n fragment productConnection on ProductConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n title\n vendor\n handle\n description\n descriptionHtml\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n }\n options {\n id\n name\n values\n }\n variants(first: 250) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n title\n sku\n availableForSale\n requiresShipping\n selectedOptions {\n name\n value\n }\n priceV2 {\n amount\n currencyCode\n }\n compareAtPriceV2 {\n amount\n currencyCode\n }\n }\n }\n }\n images(first: 250) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n originalSrc\n altText\n width\n height\n }\n }\n }\n }\n }\n }\n";
1495
1514
  var getAllProductsQuery =
1496
1515
  /* GraphQL */
1497
1516
  "\n query getAllProducts(\n $first: Int = 250\n $query: String = \"\"\n $sortKey: ProductSortKeys = RELEVANCE\n $reverse: Boolean = false\n ) {\n products(\n first: $first\n sortKey: $sortKey\n reverse: $reverse\n query: $query\n ) {\n ...productConnection\n }\n }\n\n " + productConnectionFragment + "\n";
1498
1517
 
1518
+ /*
1519
+ Forked from https://github.com/vercel/commerce/tree/main/packages/shopify/src
1520
+ Changes: None
1521
+ */
1522
+ var getAllProductVendors =
1523
+ /* GraphQL */
1524
+ "\n query getAllProductVendors($first: Int = 250, $cursor: String) {\n products(first: $first, after: $cursor) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n vendor\n }\n cursor\n }\n }\n }\n";
1525
+
1499
1526
  /*
1500
1527
  Forked from https://github.com/vercel/commerce/tree/main/packages/shopify/src
1501
1528
  Changes: None
@@ -1567,7 +1594,7 @@ var handler = {
1567
1594
  products = brandId ? (_data$node = data.node) == null ? void 0 : (_data$node$products = _data$node.products) == null ? void 0 : (_data$node$products$e = _data$node$products.edges) == null ? void 0 : _data$node$products$e.filter(function (_ref2) {
1568
1595
  var vendor = _ref2.node.vendor;
1569
1596
  return vendor.replace(/\s+/g, '-').toLowerCase() === ("" + brandId).toLowerCase();
1570
- }).slice(0, input.count) : (_data$node2 = data.node) == null ? void 0 : (_data$node2$products = _data$node2.products) == null ? void 0 : _data$node2$products.edges;
1597
+ }).slice(0, input.count) : (_data$node2 = data.node) == null ? void 0 : (_data$node2$products = _data$node2.products) == null ? void 0 : _data$node2$products.edges.slice(0, input.count);
1571
1598
  _context.next = 15;
1572
1599
  break;
1573
1600
 
@@ -2051,6 +2078,136 @@ var handler$4 = {
2051
2078
  }
2052
2079
  };
2053
2080
 
2081
+ var handler$5 = {
2082
+ fetchOptions: {
2083
+ query: getSiteCollectionsQuery
2084
+ },
2085
+ fetcher: function fetcher(_ref) {
2086
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2087
+ var _data$collections$edg, _data$collections, _data$collections$edg2;
2088
+
2089
+ var fetch, data;
2090
+ return runtime_1.wrap(function _callee$(_context) {
2091
+ while (1) {
2092
+ switch (_context.prev = _context.next) {
2093
+ case 0:
2094
+ fetch = _ref.fetch;
2095
+ _context.next = 3;
2096
+ return fetch({
2097
+ query: getSiteCollectionsQuery,
2098
+ variables: {
2099
+ first: 250
2100
+ }
2101
+ });
2102
+
2103
+ case 3:
2104
+ data = _context.sent;
2105
+ console.log("dale", "useCategories", data);
2106
+ return _context.abrupt("return", (_data$collections$edg = (_data$collections = data.collections) == null ? void 0 : (_data$collections$edg2 = _data$collections.edges) == null ? void 0 : _data$collections$edg2.map(function (_ref2) {
2107
+ var node = _ref2.node;
2108
+ return normalizeCategory(node);
2109
+ })) != null ? _data$collections$edg : []);
2110
+
2111
+ case 6:
2112
+ case "end":
2113
+ return _context.stop();
2114
+ }
2115
+ }
2116
+ }, _callee);
2117
+ }))();
2118
+ },
2119
+ useHook: function useHook(_ref3) {
2120
+ var useData = _ref3.useData;
2121
+ return function (input) {
2122
+ var response = useData({
2123
+ swrOptions: _extends({
2124
+ revalidateOnFocus: false
2125
+ }, input == null ? void 0 : input.swrOptions)
2126
+ });
2127
+ return React.useMemo(function () {
2128
+ return Object.create(response, {
2129
+ isEmpty: {
2130
+ get: function get() {
2131
+ var _response$data$length, _response$data;
2132
+
2133
+ return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
2134
+ },
2135
+ enumerable: true
2136
+ }
2137
+ });
2138
+ }, [response]);
2139
+ };
2140
+ }
2141
+ };
2142
+
2143
+ var handler$6 = {
2144
+ fetchOptions: {
2145
+ query: getAllProductVendors
2146
+ },
2147
+ fetcher: function fetcher(_ref) {
2148
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2149
+ var fetch, data, vendorsStrings;
2150
+ return runtime_1.wrap(function _callee$(_context) {
2151
+ while (1) {
2152
+ switch (_context.prev = _context.next) {
2153
+ case 0:
2154
+ fetch = _ref.fetch;
2155
+ _context.next = 3;
2156
+ return fetch({
2157
+ query: getAllProductVendors,
2158
+ variables: {
2159
+ first: 250
2160
+ }
2161
+ });
2162
+
2163
+ case 3:
2164
+ data = _context.sent;
2165
+ vendorsStrings = data.products.edges.map(function (_ref2) {
2166
+ var vendor = _ref2.node.vendor;
2167
+ return vendor;
2168
+ });
2169
+ return _context.abrupt("return", Array.from(new Set(vendorsStrings).values()).map(function (v) {
2170
+ var id = v.replace(/\s+/g, '-').toLowerCase();
2171
+ return {
2172
+ entityId: id,
2173
+ name: v,
2174
+ path: "brands/" + id
2175
+ };
2176
+ }));
2177
+
2178
+ case 6:
2179
+ case "end":
2180
+ return _context.stop();
2181
+ }
2182
+ }
2183
+ }, _callee);
2184
+ }))();
2185
+ },
2186
+ useHook: function useHook(_ref3) {
2187
+ var useData = _ref3.useData;
2188
+ return function (input) {
2189
+ var response = useData({
2190
+ swrOptions: _extends({
2191
+ revalidateOnFocus: false
2192
+ }, input == null ? void 0 : input.swrOptions)
2193
+ });
2194
+ return React.useMemo(function () {
2195
+ return Object.create(response, {
2196
+ isEmpty: {
2197
+ get: function get() {
2198
+ var _response$data$length, _response$data;
2199
+
2200
+ return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
2201
+ },
2202
+ enumerable: true
2203
+ }
2204
+ });
2205
+ }, [response]);
2206
+ };
2207
+ }
2208
+ };
2209
+
2210
+ var _excluded$1 = ["locale"];
2054
2211
  var getFetcher = function getFetcher(storeDomain, accessToken) {
2055
2212
  return /*#__PURE__*/function () {
2056
2213
  var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
@@ -2061,7 +2218,7 @@ var getFetcher = function getFetcher(storeDomain, accessToken) {
2061
2218
  switch (_context.prev = _context.next) {
2062
2219
  case 0:
2063
2220
  _ref$url = _ref.url, url = _ref$url === void 0 ? "https://" + storeDomain + "/api/2021-07/graphql.json" : _ref$url, _ref$method = _ref.method, method = _ref$method === void 0 ? 'POST' : _ref$method, variables = _ref.variables, query = _ref.query;
2064
- _ref3 = variables != null ? variables : {}, locale = _ref3.locale, vars = _objectWithoutPropertiesLoose(_ref3, ["locale"]);
2221
+ _ref3 = variables != null ? variables : {}, locale = _ref3.locale, vars = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
2065
2222
  _context.t0 = handleFetchResponse;
2066
2223
  _context.next = 5;
2067
2224
  return fetch(url, {
@@ -2115,6 +2272,10 @@ var getShopifyProvider = function getShopifyProvider(storeDomain, accessToken) {
2115
2272
  fetcher: getFetcher(storeDomain, accessToken),
2116
2273
  products: {
2117
2274
  useSearch: handler
2275
+ },
2276
+ site: {
2277
+ useCategories: handler$5,
2278
+ useBrands: handler$6
2118
2279
  }
2119
2280
  };
2120
2281
  };
@@ -2135,9 +2296,6 @@ var commerceProviderMeta = {
2135
2296
  name: "plasmic-commerce-shopify-provider",
2136
2297
  displayName: "Shopify Provider",
2137
2298
  props: {
2138
- children: {
2139
- type: "slot"
2140
- },
2141
2299
  storeDomain: "string",
2142
2300
  accessToken: "string"
2143
2301
  },
@@ -2149,20 +2307,13 @@ function CommerceProviderComponent(props) {
2149
2307
  var storeDomain = props.storeDomain,
2150
2308
  accessToken = props.accessToken,
2151
2309
  children = props.children;
2152
-
2153
- if (!storeDomain) {
2154
- return React__default.createElement("p", null, " You must set the store domain url ");
2155
- } else if (!accessToken) {
2156
- return React__default.createElement("p", null, " You must set the access token ");
2157
- }
2158
-
2159
2310
  var CommerceProvider = getCommerceProvider(storeDomain, accessToken);
2160
- return React__default.createElement(CommerceProvider, null, React__default.createElement("div", null, children));
2311
+ return React__default.createElement(CommerceProvider, null, children);
2161
2312
  }
2162
2313
 
2163
2314
  function registerCommerceProvider(loader, customCommerceProviderMeta) {
2164
2315
  var doRegisterComponent = function doRegisterComponent() {
2165
- return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
2316
+ return loader ? loader.registerGlobalContext.apply(loader, arguments) : registerGlobalContext.apply(void 0, arguments);
2166
2317
  };
2167
2318
 
2168
2319
  doRegisterComponent(CommerceProviderComponent, customCommerceProviderMeta != null ? customCommerceProviderMeta : commerceProviderMeta);