@daouypkgs/commerce-saleor 0.0.197

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.
Files changed (68) hide show
  1. package/README.md +1 -0
  2. package/dist/cart/index.d.ts +4 -0
  3. package/dist/cart/use-add-item.d.ts +5 -0
  4. package/dist/cart/use-cart.d.ts +5 -0
  5. package/dist/cart/use-remove-item.d.ts +15 -0
  6. package/dist/cart/use-update-item.d.ts +27 -0
  7. package/dist/commerce-saleor.cjs.development.js +1284 -0
  8. package/dist/commerce-saleor.cjs.development.js.map +1 -0
  9. package/dist/commerce-saleor.cjs.production.min.js +2 -0
  10. package/dist/commerce-saleor.cjs.production.min.js.map +1 -0
  11. package/dist/commerce-saleor.esm.js +1273 -0
  12. package/dist/commerce-saleor.esm.js.map +1 -0
  13. package/dist/const.d.ts +4 -0
  14. package/dist/fetcher.d.ts +2 -0
  15. package/dist/index.d.ts +6 -0
  16. package/dist/index.js +8 -0
  17. package/dist/product/use-price.d.ts +2 -0
  18. package/dist/product/use-product.d.ts +9 -0
  19. package/dist/product/use-search.d.ts +16 -0
  20. package/dist/provider.d.ts +68 -0
  21. package/dist/registerCommerceProvider.d.ts +11 -0
  22. package/dist/registerable.d.ts +6 -0
  23. package/dist/saleor.d.ts +5 -0
  24. package/dist/site/use-brands.d.ts +5 -0
  25. package/dist/site/use-categories.d.ts +5 -0
  26. package/dist/types/cart.d.ts +22 -0
  27. package/dist/types/site.d.ts +7 -0
  28. package/dist/types.d.ts +24 -0
  29. package/dist/utils/checkout-attach.d.ts +2 -0
  30. package/dist/utils/checkout-create.d.ts +3 -0
  31. package/dist/utils/checkout-to-cart.d.ts +9 -0
  32. package/dist/utils/customer-token.d.ts +7 -0
  33. package/dist/utils/fragments/checkout-details.d.ts +1 -0
  34. package/dist/utils/fragments/index.d.ts +2 -0
  35. package/dist/utils/fragments/product.d.ts +1 -0
  36. package/dist/utils/get-categories.d.ts +3 -0
  37. package/dist/utils/get-checkout-id.d.ts +5 -0
  38. package/dist/utils/get-search-variables.d.ts +14 -0
  39. package/dist/utils/get-sort-variables.d.ts +1 -0
  40. package/dist/utils/get-vendors.d.ts +11 -0
  41. package/dist/utils/handle-fetch-response.d.ts +5 -0
  42. package/dist/utils/handle-login.d.ts +5 -0
  43. package/dist/utils/index.d.ts +13 -0
  44. package/dist/utils/mutations/account-create.d.ts +1 -0
  45. package/dist/utils/mutations/checkout-attach.d.ts +1 -0
  46. package/dist/utils/mutations/checkout-create.d.ts +1 -0
  47. package/dist/utils/mutations/checkout-line-add.d.ts +1 -0
  48. package/dist/utils/mutations/checkout-line-remove.d.ts +1 -0
  49. package/dist/utils/mutations/checkout-line-update.d.ts +1 -0
  50. package/dist/utils/mutations/index.d.ts +8 -0
  51. package/dist/utils/mutations/session-create.d.ts +1 -0
  52. package/dist/utils/mutations/session-destroy.d.ts +1 -0
  53. package/dist/utils/normalize.d.ts +7 -0
  54. package/dist/utils/queries/checkout-one.d.ts +1 -0
  55. package/dist/utils/queries/collection-many.d.ts +1 -0
  56. package/dist/utils/queries/collection-one.d.ts +1 -0
  57. package/dist/utils/queries/customer-current.d.ts +1 -0
  58. package/dist/utils/queries/customer-one.d.ts +1 -0
  59. package/dist/utils/queries/get-all-product-vendors-query.d.ts +1 -0
  60. package/dist/utils/queries/get-all-products-paths-query.d.ts +1 -0
  61. package/dist/utils/queries/index.d.ts +11 -0
  62. package/dist/utils/queries/page-many.d.ts +1 -0
  63. package/dist/utils/queries/page-one.d.ts +1 -0
  64. package/dist/utils/queries/product-many.d.ts +1 -0
  65. package/dist/utils/queries/product-one-by-id.d.ts +1 -0
  66. package/dist/utils/queries/product-one-by-slug.d.ts +1 -0
  67. package/dist/utils/throw-user-errors.d.ts +5 -0
  68. package/package.json +44 -0
@@ -0,0 +1,1273 @@
1
+ import registerGlobalContext from '@daouy/host/registerGlobalContext';
2
+ import { FetcherError, ValidationError, CommerceError, useCart, useCommerce as useCommerce$1, getCommerceProvider as getCommerceProvider$1, CartActionsProvider, globalActionsRegistrations } from '@daouypkgs/commerce';
3
+ import React, { useMemo, useCallback } from 'react';
4
+ import Cookies from 'js-cookie';
5
+ import debounce from 'debounce';
6
+
7
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
8
+ try {
9
+ var i = n[a](c),
10
+ u = i.value;
11
+ } catch (n) {
12
+ return void e(n);
13
+ }
14
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
15
+ }
16
+ function _asyncToGenerator(n) {
17
+ return function () {
18
+ var t = this,
19
+ e = arguments;
20
+ return new Promise(function (r, o) {
21
+ var a = n.apply(t, e);
22
+ function _next(n) {
23
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
24
+ }
25
+ function _throw(n) {
26
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
27
+ }
28
+ _next(void 0);
29
+ });
30
+ };
31
+ }
32
+ function _extends() {
33
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
34
+ for (var e = 1; e < arguments.length; e++) {
35
+ var t = arguments[e];
36
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
37
+ }
38
+ return n;
39
+ }, _extends.apply(null, arguments);
40
+ }
41
+ function _objectWithoutPropertiesLoose(r, e) {
42
+ if (null == r) return {};
43
+ var t = {};
44
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
45
+ if (-1 !== e.indexOf(n)) continue;
46
+ t[n] = r[n];
47
+ }
48
+ return t;
49
+ }
50
+ function _regenerator() {
51
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
52
+ var e,
53
+ t,
54
+ r = "function" == typeof Symbol ? Symbol : {},
55
+ n = r.iterator || "@@iterator",
56
+ o = r.toStringTag || "@@toStringTag";
57
+ function i(r, n, o, i) {
58
+ var c = n && n.prototype instanceof Generator ? n : Generator,
59
+ u = Object.create(c.prototype);
60
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
61
+ var i,
62
+ c,
63
+ u,
64
+ f = 0,
65
+ p = o || [],
66
+ y = !1,
67
+ G = {
68
+ p: 0,
69
+ n: 0,
70
+ v: e,
71
+ a: d,
72
+ f: d.bind(e, 4),
73
+ d: function (t, r) {
74
+ return i = t, c = 0, u = e, G.n = r, a;
75
+ }
76
+ };
77
+ function d(r, n) {
78
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
79
+ var o,
80
+ i = p[t],
81
+ d = G.p,
82
+ l = i[2];
83
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
84
+ }
85
+ if (o || r > 1) return a;
86
+ throw y = !0, n;
87
+ }
88
+ return function (o, p, l) {
89
+ if (f > 1) throw TypeError("Generator is already running");
90
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
91
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
92
+ try {
93
+ if (f = 2, i) {
94
+ if (c || (o = "next"), t = i[o]) {
95
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
96
+ if (!t.done) return t;
97
+ u = t.value, c < 2 && (c = 0);
98
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
99
+ i = e;
100
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
101
+ } catch (t) {
102
+ i = e, c = 1, u = t;
103
+ } finally {
104
+ f = 1;
105
+ }
106
+ }
107
+ return {
108
+ value: t,
109
+ done: y
110
+ };
111
+ };
112
+ }(r, o, i), !0), u;
113
+ }
114
+ var a = {};
115
+ function Generator() {}
116
+ function GeneratorFunction() {}
117
+ function GeneratorFunctionPrototype() {}
118
+ t = Object.getPrototypeOf;
119
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
120
+ return this;
121
+ }), t),
122
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
123
+ function f(e) {
124
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
125
+ }
126
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
127
+ return this;
128
+ }), _regeneratorDefine(u, "toString", function () {
129
+ return "[object Generator]";
130
+ }), (_regenerator = function () {
131
+ return {
132
+ w: i,
133
+ m: f
134
+ };
135
+ })();
136
+ }
137
+ function _regeneratorDefine(e, r, n, t) {
138
+ var i = Object.defineProperty;
139
+ try {
140
+ i({}, "", {});
141
+ } catch (e) {
142
+ i = 0;
143
+ }
144
+ _regeneratorDefine = function (e, r, n, t) {
145
+ function o(r, n) {
146
+ _regeneratorDefine(e, r, function (e) {
147
+ return this._invoke(r, n, e);
148
+ });
149
+ }
150
+ r ? i ? i(e, r, {
151
+ value: n,
152
+ enumerable: !t,
153
+ configurable: !t,
154
+ writable: !t
155
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
156
+ }, _regeneratorDefine(e, r, n, t);
157
+ }
158
+
159
+ /*
160
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
161
+ Changes: Removed api_url
162
+ */
163
+ var CHECKOUT_ID_COOKIE = 'saleor.CheckoutID';
164
+ var SALEOR_TOKEN = 'saleor.Token';
165
+
166
+ /*
167
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
168
+ Changes: None
169
+ */
170
+ var getSortVariables = function getSortVariables(sort, isCategory) {
171
+ var output = {};
172
+ switch (sort) {
173
+ case 'price-asc':
174
+ output = {
175
+ field: 'PRICE',
176
+ direction: 'ASC'
177
+ };
178
+ break;
179
+ case 'price-desc':
180
+ output = {
181
+ field: 'PRICE',
182
+ direction: 'DESC'
183
+ };
184
+ break;
185
+ case 'trending-desc':
186
+ //default
187
+ output = {};
188
+ break;
189
+ case 'latest-desc':
190
+ output = {
191
+ field: 'DATE',
192
+ direction: 'DESC'
193
+ };
194
+ break;
195
+ }
196
+ return output;
197
+ };
198
+
199
+ function getError(errors, status) {
200
+ errors = errors != null ? errors : [{
201
+ message: 'Failed to fetch Saleor API'
202
+ }];
203
+ return new FetcherError({
204
+ errors: errors,
205
+ status: status
206
+ });
207
+ }
208
+ function getAsyncError(_x) {
209
+ return _getAsyncError.apply(this, arguments);
210
+ }
211
+ function _getAsyncError() {
212
+ _getAsyncError = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(res) {
213
+ var data;
214
+ return _regenerator().w(function (_context2) {
215
+ while (1) switch (_context2.n) {
216
+ case 0:
217
+ _context2.n = 1;
218
+ return res.json();
219
+ case 1:
220
+ data = _context2.v;
221
+ return _context2.a(2, getError(data.errors, res.status));
222
+ }
223
+ }, _callee2);
224
+ }));
225
+ return _getAsyncError.apply(this, arguments);
226
+ }
227
+ var handleFetchResponse = /*#__PURE__*/function () {
228
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(res) {
229
+ var _yield$res$json, data, errors;
230
+ return _regenerator().w(function (_context) {
231
+ while (1) switch (_context.n) {
232
+ case 0:
233
+ if (!res.ok) {
234
+ _context.n = 3;
235
+ break;
236
+ }
237
+ _context.n = 1;
238
+ return res.json();
239
+ case 1:
240
+ _yield$res$json = _context.v;
241
+ data = _yield$res$json.data;
242
+ errors = _yield$res$json.errors;
243
+ if (!(errors && errors.length)) {
244
+ _context.n = 2;
245
+ break;
246
+ }
247
+ throw getError(errors, res.status);
248
+ case 2:
249
+ return _context.a(2, data);
250
+ case 3:
251
+ _context.n = 4;
252
+ return getAsyncError(res);
253
+ case 4:
254
+ throw _context.v;
255
+ case 5:
256
+ return _context.a(2);
257
+ }
258
+ }, _callee);
259
+ }));
260
+ return function handleFetchResponse(_x2) {
261
+ return _ref.apply(this, arguments);
262
+ };
263
+ }();
264
+
265
+ var getSearchVariables = function getSearchVariables(_ref) {
266
+ var search = _ref.search,
267
+ categoryId = _ref.categoryId,
268
+ sort = _ref.sort,
269
+ count = _ref.count;
270
+ var sortBy = _extends({
271
+ field: 'NAME',
272
+ direction: 'ASC'
273
+ }, getSortVariables(sort), {
274
+ channel: 'default-channel'
275
+ });
276
+ return {
277
+ categoryId: categoryId,
278
+ filter: {
279
+ search: search
280
+ },
281
+ sortBy: sortBy,
282
+ first: count
283
+ };
284
+ };
285
+
286
+ /*
287
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
288
+ Changes: None
289
+ */
290
+ var getCheckoutId = function getCheckoutId(id) {
291
+ var _Cookies$get;
292
+ var r = ((_Cookies$get = Cookies.get(CHECKOUT_ID_COOKIE)) == null ? void 0 : _Cookies$get.split(':')) || [];
293
+ return {
294
+ checkoutId: r[0],
295
+ checkoutToken: r[1]
296
+ };
297
+ };
298
+
299
+ /*
300
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
301
+ Changes: None
302
+ */
303
+ var ProductConnection = /* GraphQL */"\n fragment ProductConnection on ProductCountableConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n name\n description\n slug\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n media {\n url\n alt\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n }\n }\n }\n";
304
+
305
+ /*
306
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
307
+ Changes: None
308
+ */
309
+ 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";
310
+
311
+ /*
312
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
313
+ Changes: None
314
+ */
315
+ var CheckoutCreate = /* GraphQL */"\n mutation CheckoutCreate {\n checkoutCreate(input: { email: \"customer@example.com\", lines: [], channel: \"default-channel\" }) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
316
+
317
+ /*
318
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
319
+ Changes: None
320
+ */
321
+ var CheckoutLineAdd = /* GraphQL */"\n mutation CheckoutLineAdd($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesAdd(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
322
+
323
+ /*
324
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
325
+ Changes: None
326
+ */
327
+ var CheckoutLineUpdate = /* GraphQL */"\n mutation CheckoutLineUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
328
+
329
+ /*
330
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
331
+ Changes: None
332
+ */
333
+ var CheckoutLineDelete = /* GraphQL */"\n mutation CheckoutLineDelete($checkoutId: ID!, $lineId: ID!) {\n checkoutLineDelete(checkoutId: $checkoutId, lineId: $lineId) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
334
+
335
+ var checkoutCreate = /*#__PURE__*/function () {
336
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fetch) {
337
+ var _data$checkoutCreate;
338
+ var data, checkout, checkoutId, checkoutToken, value, options;
339
+ return _regenerator().w(function (_context) {
340
+ while (1) switch (_context.n) {
341
+ case 0:
342
+ _context.n = 1;
343
+ return fetch({
344
+ query: CheckoutCreate
345
+ });
346
+ case 1:
347
+ data = _context.v;
348
+ checkout = (_data$checkoutCreate = data.checkoutCreate) == null ? void 0 : _data$checkoutCreate.checkout;
349
+ checkoutId = checkout == null ? void 0 : checkout.id;
350
+ checkoutToken = checkout == null ? void 0 : checkout.token;
351
+ value = checkoutId + ":" + checkoutToken;
352
+ if (checkoutId) {
353
+ options = {
354
+ expires: 60 * 60 * 24 * 30,
355
+ sameSite: "none",
356
+ secure: true
357
+ };
358
+ Cookies.set(CHECKOUT_ID_COOKIE, value, options);
359
+ }
360
+ return _context.a(2, checkout);
361
+ }
362
+ }, _callee);
363
+ }));
364
+ return function checkoutCreate(_x) {
365
+ return _ref.apply(this, arguments);
366
+ };
367
+ }();
368
+
369
+ var _excluded = ["id", "name", "media", "variants", "description", "slug", "pricing"];
370
+ /* eslint-disable */
371
+ /*
372
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
373
+ Changes: None
374
+ */
375
+ // TODO: Check nextjs-commerce bug if no images are added for a product
376
+ var placeholderImg = "/product-img-placeholder.svg";
377
+ var money = function money(_ref) {
378
+ var amount = _ref.amount,
379
+ currency = _ref.currency;
380
+ return {
381
+ value: +amount,
382
+ currencyCode: currency || "USD"
383
+ };
384
+ };
385
+ var normalizeProductOptions = function normalizeProductOptions(options) {
386
+ return options == null ? void 0 : options.map(function (option) {
387
+ return option == null ? void 0 : option.attributes;
388
+ }).flat(1).reduce(function (acc, x) {
389
+ if (acc.find(function (_ref2) {
390
+ var displayName = _ref2.displayName;
391
+ return displayName === x.attribute.name;
392
+ })) {
393
+ return acc.map(function (opt) {
394
+ return opt.displayName === x.attribute.name ? _extends({}, opt, {
395
+ values: [].concat(opt.values, x.values.map(function (value) {
396
+ return {
397
+ label: value == null ? void 0 : value.name
398
+ };
399
+ }))
400
+ }) : opt;
401
+ });
402
+ }
403
+ return acc.concat({
404
+ __typename: "MultipleChoiceOption",
405
+ displayName: x.attribute.name,
406
+ variant: "size",
407
+ values: x.values.map(function (value) {
408
+ return {
409
+ label: value == null ? void 0 : value.name
410
+ };
411
+ })
412
+ });
413
+ }, []);
414
+ };
415
+ var normalizeProductVariants = function normalizeProductVariants(variants) {
416
+ return variants == null ? void 0 : variants.map(function (variant) {
417
+ var _pricing$price, _money;
418
+ var id = variant.id,
419
+ sku = variant.sku,
420
+ name = variant.name,
421
+ pricing = variant.pricing;
422
+ var price = (pricing == null || (_pricing$price = pricing.price) == null ? void 0 : _pricing$price.net) && ((_money = money(pricing.price.net)) == null ? void 0 : _money.value);
423
+ return {
424
+ id: id,
425
+ name: name,
426
+ sku: sku != null ? sku : id,
427
+ price: price,
428
+ listPrice: price,
429
+ requiresShipping: true,
430
+ options: normalizeProductOptions([variant])
431
+ };
432
+ });
433
+ };
434
+ function normalizeProduct(productNode) {
435
+ var _JSON$parse, _pricing$priceRange;
436
+ var id = productNode.id,
437
+ name = productNode.name,
438
+ _productNode$media = productNode.media,
439
+ media = _productNode$media === void 0 ? [] : _productNode$media,
440
+ variants = productNode.variants,
441
+ description = productNode.description,
442
+ slug = productNode.slug,
443
+ pricing = productNode.pricing,
444
+ rest = _objectWithoutPropertiesLoose(productNode, _excluded);
445
+ var product = _extends({
446
+ id: id,
447
+ name: name,
448
+ vendor: "",
449
+ description: description ? (_JSON$parse = JSON.parse(description)) == null || (_JSON$parse = _JSON$parse.blocks[0]) == null ? void 0 : _JSON$parse.data.text : "",
450
+ path: "/" + slug,
451
+ slug: slug == null ? void 0 : slug.replace(/^\/+|\/+$/g, ""),
452
+ price: (pricing == null || (_pricing$priceRange = pricing.priceRange) == null || (_pricing$priceRange = _pricing$priceRange.start) == null ? void 0 : _pricing$priceRange.net) && money(pricing.priceRange.start.net) || {
453
+ value: 0,
454
+ currencyCode: "USD"
455
+ },
456
+ // TODO: Check nextjs-commerce bug if no images are added for a product
457
+ images: media != null && media.length ? media : [{
458
+ url: placeholderImg
459
+ }],
460
+ variants: variants && variants.length > 0 ? normalizeProductVariants(variants) : [],
461
+ options: variants && variants.length > 0 ? normalizeProductOptions(variants) : []
462
+ }, rest);
463
+ return product;
464
+ }
465
+ function normalizeCart(checkout) {
466
+ var _checkout$totalPrice, _checkout$subtotalPri, _checkout$subtotalPri2, _checkout$totalPrice2;
467
+ var lines = checkout.lines;
468
+ var lineItems = lines.length > 0 ? lines == null ? void 0 : lines.map(normalizeLineItem) : [];
469
+ return {
470
+ id: checkout.id,
471
+ customerId: "",
472
+ email: "",
473
+ createdAt: checkout.created,
474
+ currency: {
475
+ code: (_checkout$totalPrice = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice.currency
476
+ },
477
+ taxesIncluded: false,
478
+ lineItems: lineItems,
479
+ lineItemsSubtotalPrice: (_checkout$subtotalPri = checkout.subtotalPrice) == null || (_checkout$subtotalPri = _checkout$subtotalPri.gross) == null ? void 0 : _checkout$subtotalPri.amount,
480
+ subtotalPrice: (_checkout$subtotalPri2 = checkout.subtotalPrice) == null || (_checkout$subtotalPri2 = _checkout$subtotalPri2.gross) == null ? void 0 : _checkout$subtotalPri2.amount,
481
+ totalPrice: (_checkout$totalPrice2 = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice2.gross.amount,
482
+ discounts: []
483
+ };
484
+ }
485
+ function normalizeLineItem(_ref3) {
486
+ var _variant$product, _variant$sku, _variant$pricing, _variant$product2;
487
+ var id = _ref3.id,
488
+ variant = _ref3.variant,
489
+ quantity = _ref3.quantity;
490
+ return {
491
+ id: id,
492
+ variantId: String(variant == null ? void 0 : variant.id),
493
+ productId: String(variant == null || (_variant$product = variant.product) == null ? void 0 : _variant$product.id),
494
+ name: "" + variant.product.name,
495
+ quantity: quantity,
496
+ variant: {
497
+ id: String(variant == null ? void 0 : variant.id),
498
+ sku: (_variant$sku = variant == null ? void 0 : variant.sku) != null ? _variant$sku : "",
499
+ name: variant == null ? void 0 : variant.name,
500
+ image: {
501
+ url: variant != null && variant.media[0] ? variant == null ? void 0 : variant.media[0].url : placeholderImg
502
+ },
503
+ requiresShipping: false,
504
+ price: variant == null || (_variant$pricing = variant.pricing) == null || (_variant$pricing = _variant$pricing.price) == null ? void 0 : _variant$pricing.gross.amount,
505
+ listPrice: 0
506
+ },
507
+ path: String(variant == null || (_variant$product2 = variant.product) == null ? void 0 : _variant$product2.slug),
508
+ discounts: [],
509
+ options: []
510
+ };
511
+ }
512
+ var normalizeCategory = function normalizeCategory(_ref4) {
513
+ var name = _ref4.name,
514
+ slug = _ref4.slug,
515
+ id = _ref4.id;
516
+ return {
517
+ id: id,
518
+ name: name,
519
+ slug: slug,
520
+ path: "/" + slug
521
+ };
522
+ };
523
+
524
+ /*
525
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
526
+ Changes: None
527
+ */
528
+ var throwUserErrors = function throwUserErrors(errors) {
529
+ if (errors && errors.length) {
530
+ throw new ValidationError({
531
+ errors: errors.map(function (_ref) {
532
+ var code = _ref.code,
533
+ message = _ref.message;
534
+ return {
535
+ code: code != null ? code : 'validation_error',
536
+ message: message || ''
537
+ };
538
+ })
539
+ });
540
+ }
541
+ };
542
+
543
+ /*
544
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
545
+ Changes: None
546
+ */
547
+ var checkoutToCart = function checkoutToCart(checkoutPayload) {
548
+ var _checkoutPayload$erro;
549
+ if (!checkoutPayload) {
550
+ throw new CommerceError({
551
+ message: 'Missing checkout payload from response'
552
+ });
553
+ }
554
+ var checkout = checkoutPayload == null ? void 0 : checkoutPayload.checkout;
555
+ if ((checkoutPayload == null || (_checkoutPayload$erro = checkoutPayload.errors) == null ? void 0 : _checkoutPayload$erro.length) === 1 && checkoutPayload.errors[0].code === "PRODUCT_UNAVAILABLE_FOR_PURCHASE") {
556
+ console.error(checkoutPayload.errors[0]);
557
+ return undefined;
558
+ }
559
+ if (checkoutPayload != null && checkoutPayload.errors) {
560
+ throwUserErrors(checkoutPayload == null ? void 0 : checkoutPayload.errors);
561
+ }
562
+ if (!checkout) {
563
+ throw new CommerceError({
564
+ message: 'Missing checkout object from response'
565
+ });
566
+ }
567
+ return normalizeCart(checkout);
568
+ };
569
+
570
+ /*
571
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
572
+ Changes: None
573
+ */
574
+ var getToken = function getToken() {
575
+ return Cookies.get(SALEOR_TOKEN);
576
+ };
577
+
578
+ /*
579
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
580
+ Changes: None
581
+ */
582
+ var CollectionMany = /* GraphQL */"\n query CollectionMany( $channel: String = \"default-channel\") {\n collections(first:100, channel: $channel) {\n edges {\n node {\n id\n name\n slug\n }\n }\n }\n }\n";
583
+
584
+ /*
585
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
586
+ Changes: None
587
+ */
588
+ var ProductOneBySlug = /* GraphQL */"\n query ProductOneBySlug($slug: String!, $channel: String = \"default-channel\") {\n product(slug: $slug, channel: $channel) {\n id\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }\n";
589
+
590
+ /*
591
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
592
+ Changes: None
593
+ */
594
+ var ProductMany = /* GraphQL */"\n query ProductMany(\n $first: Int = 100\n $filter: ProductFilterInput\n $sortBy: ProductOrder\n $channel: String = \"default-channel\"\n ) {\n products(first: $first, channel: $channel, filter: $filter, sortBy: $sortBy) {\n ...ProductConnection\n }\n }\n " + ProductConnection + "\n";
595
+
596
+ /*
597
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
598
+ Changes: None
599
+ */
600
+ var CollectionOne = /* GraphQL */"\n query getProductsFromCollection($categoryId: ID!, $first: Int = 100, $channel: String = \"default-channel\") {\n collection(id: $categoryId, channel: $channel) {\n id\n name\n slug\n products(first: $first) {\n ...ProductConnection\n }\n }\n }\n " + ProductConnection + "\n";
601
+
602
+ /*
603
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
604
+ Changes: None
605
+ */
606
+ var CheckoutOne = /* GraphQL */"\n query CheckoutOne($checkoutId: UUID!) {\n checkout(token: $checkoutId) {\n ... on Checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
607
+
608
+ /*
609
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
610
+ Changes: None
611
+ */
612
+ var getAllProductVendors = /* GraphQL */"\n query getAllProductVendors($cursor: String, $channel: String = \"default-channel\") {\n products(first:100,channel: $channel, after: $cursor) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n slug\n }\n cursor\n }\n }\n }\n";
613
+
614
+ var handler = {
615
+ fetchOptions: {
616
+ query: CheckoutOne
617
+ },
618
+ fetcher: function fetcher(_ref) {
619
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
620
+ var _checkout;
621
+ var checkoutId, options, fetch, checkout, _checkoutId, data;
622
+ return _regenerator().w(function (_context) {
623
+ while (1) switch (_context.n) {
624
+ case 0:
625
+ checkoutId = _ref.input.cartId, options = _ref.options, fetch = _ref.fetch;
626
+ if (!checkoutId) {
627
+ _context.n = 2;
628
+ break;
629
+ }
630
+ _checkoutId = getCheckoutId().checkoutToken;
631
+ _context.n = 1;
632
+ return fetch(_extends({}, options, {
633
+ variables: {
634
+ checkoutId: _checkoutId
635
+ }
636
+ }));
637
+ case 1:
638
+ data = _context.v;
639
+ checkout = data;
640
+ case 2:
641
+ if (!((_checkout = checkout) != null && _checkout.completedAt || !checkoutId)) {
642
+ _context.n = 4;
643
+ break;
644
+ }
645
+ _context.n = 3;
646
+ return checkoutCreate(fetch);
647
+ case 3:
648
+ checkout = _context.v;
649
+ case 4:
650
+ return _context.a(2, checkoutToCart(checkout));
651
+ }
652
+ }, _callee);
653
+ }))();
654
+ },
655
+ useHook: function useHook(_ref2) {
656
+ var useData = _ref2.useData;
657
+ return function (input) {
658
+ var response = useData({
659
+ swrOptions: _extends({
660
+ revalidateOnFocus: false
661
+ }, input == null ? void 0 : input.swrOptions)
662
+ });
663
+ return useMemo(function () {
664
+ return Object.create(response, {
665
+ isEmpty: {
666
+ get: function get() {
667
+ var _response$data$lineIt, _response$data;
668
+ return ((_response$data$lineIt = (_response$data = response.data) == null ? void 0 : _response$data.lineItems.length) != null ? _response$data$lineIt : 0) <= 0;
669
+ },
670
+ enumerable: true
671
+ }
672
+ });
673
+ }, [response]);
674
+ };
675
+ }
676
+ };
677
+
678
+ var handler$1 = {
679
+ fetchOptions: {
680
+ query: CheckoutLineAdd
681
+ },
682
+ fetcher: function fetcher(_ref) {
683
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
684
+ var _item$quantity;
685
+ var item, options, fetch, _yield$fetch, checkoutLinesAdd;
686
+ return _regenerator().w(function (_context) {
687
+ while (1) switch (_context.n) {
688
+ case 0:
689
+ item = _ref.input, options = _ref.options, fetch = _ref.fetch;
690
+ if (!(item.quantity && (!Number.isInteger(item.quantity) || item.quantity < 1))) {
691
+ _context.n = 1;
692
+ break;
693
+ }
694
+ throw new CommerceError({
695
+ message: "The item quantity has to be a valid integer greater than 0"
696
+ });
697
+ case 1:
698
+ _context.n = 2;
699
+ return fetch(_extends({}, options, {
700
+ variables: {
701
+ checkoutId: getCheckoutId().checkoutId,
702
+ lineItems: [{
703
+ variantId: item.variantId,
704
+ quantity: (_item$quantity = item.quantity) != null ? _item$quantity : 1
705
+ }]
706
+ }
707
+ }));
708
+ case 2:
709
+ _yield$fetch = _context.v;
710
+ checkoutLinesAdd = _yield$fetch.checkoutLinesAdd;
711
+ return _context.a(2, checkoutToCart(checkoutLinesAdd));
712
+ }
713
+ }, _callee);
714
+ }))();
715
+ },
716
+ useHook: function useHook(_ref2) {
717
+ var fetch = _ref2.fetch;
718
+ return function () {
719
+ var _useCart = useCart(),
720
+ mutate = _useCart.mutate;
721
+ return useCallback(/*#__PURE__*/function () {
722
+ var _addItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input) {
723
+ var data;
724
+ return _regenerator().w(function (_context2) {
725
+ while (1) switch (_context2.n) {
726
+ case 0:
727
+ _context2.n = 1;
728
+ return fetch({
729
+ input: input
730
+ });
731
+ case 1:
732
+ data = _context2.v;
733
+ if (!data) {
734
+ _context2.n = 3;
735
+ break;
736
+ }
737
+ _context2.n = 2;
738
+ return mutate(data, false);
739
+ case 2:
740
+ _context2.n = 4;
741
+ break;
742
+ case 3:
743
+ _context2.n = 4;
744
+ return mutate();
745
+ case 4:
746
+ return _context2.a(2, data);
747
+ }
748
+ }, _callee2);
749
+ }));
750
+ function addItem(_x) {
751
+ return _addItem.apply(this, arguments);
752
+ }
753
+ return addItem;
754
+ }(), [fetch, mutate]);
755
+ };
756
+ }
757
+ };
758
+
759
+ var handler$2 = {
760
+ fetchOptions: {
761
+ query: CheckoutLineDelete
762
+ },
763
+ fetcher: function fetcher(_ref) {
764
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
765
+ var itemId, options, fetch, data;
766
+ return _regenerator().w(function (_context) {
767
+ while (1) switch (_context.n) {
768
+ case 0:
769
+ itemId = _ref.input.itemId, options = _ref.options, fetch = _ref.fetch;
770
+ _context.n = 1;
771
+ return fetch(_extends({}, options, {
772
+ variables: {
773
+ checkoutId: getCheckoutId().checkoutId,
774
+ lineId: itemId
775
+ }
776
+ }));
777
+ case 1:
778
+ data = _context.v;
779
+ return _context.a(2, checkoutToCart(data.checkoutLineDelete));
780
+ }
781
+ }, _callee);
782
+ }))();
783
+ },
784
+ useHook: function useHook(_ref2) {
785
+ var fetch = _ref2.fetch;
786
+ return function () {
787
+ var _useCart = useCart(),
788
+ mutate = _useCart.mutate;
789
+ return useCallback(/*#__PURE__*/function () {
790
+ var _removeItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input) {
791
+ var data;
792
+ return _regenerator().w(function (_context2) {
793
+ while (1) switch (_context2.n) {
794
+ case 0:
795
+ _context2.n = 1;
796
+ return fetch({
797
+ input: {
798
+ itemId: input.id
799
+ }
800
+ });
801
+ case 1:
802
+ data = _context2.v;
803
+ _context2.n = 2;
804
+ return mutate(data, false);
805
+ case 2:
806
+ return _context2.a(2, data);
807
+ }
808
+ }, _callee2);
809
+ }));
810
+ function removeItem(_x) {
811
+ return _removeItem.apply(this, arguments);
812
+ }
813
+ return removeItem;
814
+ }(), [fetch, mutate]);
815
+ };
816
+ }
817
+ };
818
+
819
+ var handler$3 = {
820
+ fetchOptions: {
821
+ query: CheckoutLineUpdate
822
+ },
823
+ fetcher: function fetcher(_ref) {
824
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
825
+ var _ref$input, itemId, item, options, fetch, checkoutId, _yield$fetch, checkoutLinesUpdate;
826
+ return _regenerator().w(function (_context) {
827
+ while (1) switch (_context.n) {
828
+ case 0:
829
+ _ref$input = _ref.input, itemId = _ref$input.itemId, item = _ref$input.item, options = _ref.options, fetch = _ref.fetch;
830
+ if (!Number.isInteger(item.quantity)) {
831
+ _context.n = 2;
832
+ break;
833
+ }
834
+ if (!(item.quantity < 1)) {
835
+ _context.n = 1;
836
+ break;
837
+ }
838
+ return _context.a(2, handler$2.fetcher({
839
+ options: handler$2.fetchOptions,
840
+ input: {
841
+ itemId: itemId
842
+ },
843
+ fetch: fetch
844
+ }));
845
+ case 1:
846
+ _context.n = 3;
847
+ break;
848
+ case 2:
849
+ if (!item.quantity) {
850
+ _context.n = 3;
851
+ break;
852
+ }
853
+ throw new ValidationError({
854
+ message: "The item quantity has to be a valid integer"
855
+ });
856
+ case 3:
857
+ checkoutId = getCheckoutId().checkoutId;
858
+ _context.n = 4;
859
+ return fetch(_extends({}, options, {
860
+ variables: {
861
+ checkoutId: checkoutId,
862
+ lineItems: [{
863
+ itemId: itemId,
864
+ quantity: item.quantity
865
+ }]
866
+ }
867
+ }));
868
+ case 4:
869
+ _yield$fetch = _context.v;
870
+ checkoutLinesUpdate = _yield$fetch.checkoutLinesUpdate;
871
+ return _context.a(2, checkoutToCart(checkoutLinesUpdate));
872
+ }
873
+ }, _callee);
874
+ }))();
875
+ },
876
+ useHook: function useHook(_ref2) {
877
+ var fetch = _ref2.fetch;
878
+ return function (ctx) {
879
+ var _ctx$wait;
880
+ if (ctx === void 0) {
881
+ ctx = {};
882
+ }
883
+ var _ctx = ctx,
884
+ item = _ctx.item;
885
+ var _useCart = useCart(),
886
+ mutate = _useCart.mutate;
887
+ return useCallback(debounce(/*#__PURE__*/function () {
888
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input) {
889
+ var _input$id;
890
+ var itemId, data;
891
+ return _regenerator().w(function (_context2) {
892
+ while (1) switch (_context2.n) {
893
+ case 0:
894
+ itemId = (_input$id = input.id) != null ? _input$id : item == null ? void 0 : item.id;
895
+ if (itemId) {
896
+ _context2.n = 1;
897
+ break;
898
+ }
899
+ throw new ValidationError({
900
+ message: "Invalid input used for this operation"
901
+ });
902
+ case 1:
903
+ _context2.n = 2;
904
+ return fetch({
905
+ input: {
906
+ item: {
907
+ quantity: input.quantity
908
+ },
909
+ itemId: itemId
910
+ }
911
+ });
912
+ case 2:
913
+ data = _context2.v;
914
+ _context2.n = 3;
915
+ return mutate(data, false);
916
+ case 3:
917
+ return _context2.a(2, data);
918
+ }
919
+ }, _callee2);
920
+ }));
921
+ return function (_x) {
922
+ return _ref3.apply(this, arguments);
923
+ };
924
+ }(), (_ctx$wait = ctx.wait) != null ? _ctx$wait : 500), [fetch, mutate]);
925
+ };
926
+ }
927
+ };
928
+
929
+ var handler$4 = {
930
+ fetchOptions: {
931
+ query: CollectionMany
932
+ },
933
+ fetcher: function fetcher(_ref) {
934
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
935
+ var input, fetch, categoryId, _data$collections$edg, _data$collections, data, _data;
936
+ return _regenerator().w(function (_context) {
937
+ while (1) switch (_context.n) {
938
+ case 0:
939
+ input = _ref.input, fetch = _ref.fetch;
940
+ categoryId = input.categoryId;
941
+ if (categoryId) {
942
+ _context.n = 2;
943
+ break;
944
+ }
945
+ _context.n = 1;
946
+ return fetch({
947
+ query: CollectionMany,
948
+ variables: {
949
+ first: 250
950
+ }
951
+ });
952
+ case 1:
953
+ data = _context.v;
954
+ return _context.a(2, (_data$collections$edg = (_data$collections = data.collections) == null || (_data$collections = _data$collections.edges) == null ? void 0 : _data$collections.map(function (_ref2) {
955
+ var node = _ref2.node;
956
+ return normalizeCategory(node);
957
+ })) != null ? _data$collections$edg : []);
958
+ case 2:
959
+ _context.n = 3;
960
+ return fetch({
961
+ query: CollectionOne,
962
+ variables: {
963
+ categoryId: categoryId
964
+ }
965
+ });
966
+ case 3:
967
+ _data = _context.v;
968
+ return _context.a(2, !!(_data != null && _data.collection) ? [normalizeCategory(_data == null ? void 0 : _data.collection)] : []);
969
+ case 4:
970
+ return _context.a(2);
971
+ }
972
+ }, _callee);
973
+ }))();
974
+ },
975
+ useHook: function useHook(_ref3) {
976
+ var useData = _ref3.useData;
977
+ return function (input) {
978
+ var response = useData({
979
+ input: [["categoryId", input == null ? void 0 : input.categoryId]],
980
+ swrOptions: _extends({
981
+ revalidateOnFocus: false
982
+ }, input == null ? void 0 : input.swrOptions)
983
+ });
984
+ return useMemo(function () {
985
+ return Object.create(response, {
986
+ isEmpty: {
987
+ get: function get() {
988
+ var _response$data$length, _response$data;
989
+ return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
990
+ },
991
+ enumerable: true
992
+ }
993
+ });
994
+ }, [response]);
995
+ };
996
+ }
997
+ };
998
+
999
+ var handler$5 = {
1000
+ fetchOptions: {
1001
+ query: getAllProductVendors
1002
+ },
1003
+ fetcher: function fetcher(_ref) {
1004
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1005
+ return _regenerator().w(function (_context) {
1006
+ while (1) switch (_context.n) {
1007
+ case 0:
1008
+ return _context.a(2, []);
1009
+ }
1010
+ }, _callee);
1011
+ }))();
1012
+ },
1013
+ useHook: function useHook(_ref2) {
1014
+ var useData = _ref2.useData;
1015
+ return function (input) {
1016
+ var response = useData({
1017
+ swrOptions: _extends({
1018
+ revalidateOnFocus: false
1019
+ }, input == null ? void 0 : input.swrOptions)
1020
+ });
1021
+ return useMemo(function () {
1022
+ return Object.create(response, {
1023
+ isEmpty: {
1024
+ get: function get() {
1025
+ var _response$data$length, _response$data;
1026
+ return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
1027
+ },
1028
+ enumerable: true
1029
+ }
1030
+ });
1031
+ }, [response]);
1032
+ };
1033
+ }
1034
+ };
1035
+
1036
+ var handler$6 = {
1037
+ fetchOptions: {
1038
+ query: ProductMany
1039
+ },
1040
+ fetcher: function fetcher(_ref) {
1041
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1042
+ var input, options, fetch, categoryId, brandId, data, edges, _data$collection$prod, _data$collection, _data$products$edges, _data$products;
1043
+ return _regenerator().w(function (_context) {
1044
+ while (1) switch (_context.n) {
1045
+ case 0:
1046
+ input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1047
+ categoryId = input.categoryId, brandId = input.brandId;
1048
+ _context.n = 1;
1049
+ return fetch({
1050
+ query: categoryId ? CollectionOne : options.query,
1051
+ method: options == null ? void 0 : options.method,
1052
+ variables: getSearchVariables(input)
1053
+ });
1054
+ case 1:
1055
+ data = _context.v;
1056
+ if (categoryId) {
1057
+ edges = (_data$collection$prod = (_data$collection = data.collection) == null || (_data$collection = _data$collection.products) == null ? void 0 : _data$collection.edges) != null ? _data$collection$prod : [];
1058
+ // FIXME @zaiste, no `vendor` in Saleor
1059
+ // if (brandId) {
1060
+ // edges = edges.filter(
1061
+ // ({ node: { vendor } }: ProductCountableEdge) =>
1062
+ // vendor.replace(/\s+/g, '-').toLowerCase() === brandId
1063
+ // )
1064
+ // }
1065
+ } else {
1066
+ edges = (_data$products$edges = (_data$products = data.products) == null ? void 0 : _data$products.edges) != null ? _data$products$edges : [];
1067
+ }
1068
+ return _context.a(2, {
1069
+ products: edges.map(function (_ref2) {
1070
+ var node = _ref2.node;
1071
+ return normalizeProduct(node);
1072
+ }),
1073
+ found: !!edges.length
1074
+ });
1075
+ }
1076
+ }, _callee);
1077
+ }))();
1078
+ },
1079
+ useHook: function useHook(_ref3) {
1080
+ var useData = _ref3.useData;
1081
+ return function (input) {
1082
+ if (input === void 0) {
1083
+ input = {};
1084
+ }
1085
+ return useData({
1086
+ input: [["search", input.search], ["categoryId", input.categoryId], ["brandId", input.brandId], ["sort", input.sort], ["count", input.count]],
1087
+ swrOptions: _extends({
1088
+ revalidateOnFocus: false
1089
+ }, input.swrOptions)
1090
+ });
1091
+ };
1092
+ }
1093
+ };
1094
+
1095
+ var ProductOneById = /* GraphQL */"\n query ProductOneById($id: ID!, $channel: String = \"default-channel\") {\n product(id: $id, channel: $channel) {\n\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }";
1096
+
1097
+ var handler$7 = {
1098
+ fetchOptions: {
1099
+ query: ProductOneById
1100
+ },
1101
+ fetcher: function fetcher(_ref) {
1102
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1103
+ var input, fetch, id, data, response;
1104
+ return _regenerator().w(function (_context) {
1105
+ while (1) switch (_context.n) {
1106
+ case 0:
1107
+ input = _ref.input, fetch = _ref.fetch;
1108
+ id = input.id;
1109
+ if (id) {
1110
+ _context.n = 1;
1111
+ break;
1112
+ }
1113
+ return _context.a(2, null);
1114
+ case 1:
1115
+ _context.n = 2;
1116
+ return fetch({
1117
+ query: ProductOneById,
1118
+ variables: {
1119
+ id: id
1120
+ }
1121
+ });
1122
+ case 2:
1123
+ data = _context.v;
1124
+ if (data.product) {
1125
+ _context.n = 4;
1126
+ break;
1127
+ }
1128
+ _context.n = 3;
1129
+ return fetch({
1130
+ query: ProductOneBySlug,
1131
+ variables: {
1132
+ slug: id
1133
+ }
1134
+ });
1135
+ case 3:
1136
+ response = _context.v;
1137
+ return _context.a(2, response.product ? normalizeProduct(response.product) : null);
1138
+ case 4:
1139
+ return _context.a(2, data.product ? normalizeProduct(data.product) : null);
1140
+ }
1141
+ }, _callee);
1142
+ }))();
1143
+ },
1144
+ useHook: function useHook(_ref2) {
1145
+ var useData = _ref2.useData;
1146
+ return function (input) {
1147
+ if (input === void 0) {
1148
+ input = {};
1149
+ }
1150
+ return useData({
1151
+ input: [["id", input.id]],
1152
+ swrOptions: _extends({
1153
+ revalidateOnFocus: false
1154
+ }, input.swrOptions)
1155
+ });
1156
+ };
1157
+ }
1158
+ };
1159
+
1160
+ var _excluded$1 = ["locale"];
1161
+ var getFetcher = function getFetcher(saleorApiUrl) {
1162
+ return /*#__PURE__*/function () {
1163
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
1164
+ var _ref$url, url, _ref$method, method, query, variables, _ref3, vars, token, _t;
1165
+ return _regenerator().w(function (_context) {
1166
+ while (1) switch (_context.n) {
1167
+ case 0:
1168
+ _ref$url = _ref.url, url = _ref$url === void 0 ? saleorApiUrl : _ref$url, _ref$method = _ref.method, method = _ref$method === void 0 ? 'POST' : _ref$method, query = _ref.query, variables = _ref.variables;
1169
+ _ref3 = variables != null ? variables : {}, vars = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
1170
+ token = getToken();
1171
+ _t = handleFetchResponse;
1172
+ _context.n = 1;
1173
+ return fetch(url, {
1174
+ method: method,
1175
+ body: JSON.stringify({
1176
+ query: query,
1177
+ variables: vars
1178
+ }),
1179
+ headers: {
1180
+ Authorization: "JWT " + token,
1181
+ 'Content-Type': 'application/json'
1182
+ }
1183
+ });
1184
+ case 1:
1185
+ return _context.a(2, _t(_context.v));
1186
+ }
1187
+ }, _callee);
1188
+ }));
1189
+ return function (_x) {
1190
+ return _ref2.apply(this, arguments);
1191
+ };
1192
+ }();
1193
+ };
1194
+
1195
+ /*
1196
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1197
+ Changes:
1198
+ - Removed customer and auth hooks.
1199
+ - Added saleor_api_url parameters.
1200
+ */
1201
+ var getSaleorProvider = function getSaleorProvider(saleorApiUrl) {
1202
+ return {
1203
+ locale: 'en-us',
1204
+ cartCookie: CHECKOUT_ID_COOKIE,
1205
+ fetcher: getFetcher(saleorApiUrl),
1206
+ cart: {
1207
+ useCart: handler,
1208
+ useAddItem: handler$1,
1209
+ useUpdateItem: handler$3,
1210
+ useRemoveItem: handler$2
1211
+ },
1212
+ products: {
1213
+ useSearch: handler$6,
1214
+ useProduct: handler$7
1215
+ },
1216
+ site: {
1217
+ useCategories: handler$4,
1218
+ useBrands: handler$5
1219
+ }
1220
+ };
1221
+ };
1222
+
1223
+ /*
1224
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1225
+ Changes:
1226
+ - Added saleor_api_url parameter.
1227
+ */
1228
+ var useCommerce = function useCommerce() {
1229
+ return useCommerce$1();
1230
+ };
1231
+ var getCommerceProvider = function getCommerceProvider(saleorApiUrl) {
1232
+ return getCommerceProvider$1(getSaleorProvider(saleorApiUrl));
1233
+ };
1234
+
1235
+ var globalContextName = "daouy-commerce-saleor-provider";
1236
+ var commerceProviderMeta = /*#__PURE__*/_extends({
1237
+ name: globalContextName,
1238
+ displayName: "Saleor Provider",
1239
+ props: {
1240
+ saleorApiUrl: {
1241
+ type: "string",
1242
+ defaultValue: "https://vercel.saleor.cloud/graphql/"
1243
+ }
1244
+ }
1245
+ }, {
1246
+ globalActions: globalActionsRegistrations
1247
+ }, {
1248
+ importPath: "@daouypkgs/commerce-saleor",
1249
+ importName: "CommerceProviderComponent"
1250
+ });
1251
+ function CommerceProviderComponent(props) {
1252
+ var saleorApiUrl = props.saleorApiUrl,
1253
+ children = props.children;
1254
+ var CommerceProvider = React.useMemo(function () {
1255
+ return getCommerceProvider(saleorApiUrl);
1256
+ }, [saleorApiUrl]);
1257
+ return React.createElement(CommerceProvider, null, React.createElement(CartActionsProvider, {
1258
+ globalContextName: globalContextName
1259
+ }, children));
1260
+ }
1261
+ function registerCommerceProvider(loader, customCommerceProviderMeta) {
1262
+ var doRegisterComponent = function doRegisterComponent() {
1263
+ return loader ? loader.registerGlobalContext.apply(loader, arguments) : registerGlobalContext.apply(void 0, arguments);
1264
+ };
1265
+ doRegisterComponent(CommerceProviderComponent, customCommerceProviderMeta != null ? customCommerceProviderMeta : commerceProviderMeta);
1266
+ }
1267
+
1268
+ function registerAll(loader) {
1269
+ registerCommerceProvider(loader);
1270
+ }
1271
+
1272
+ export { CommerceProviderComponent, getCommerceProvider, registerAll, registerCommerceProvider, useCommerce };
1273
+ //# sourceMappingURL=commerce-saleor.esm.js.map