@plasmicpkgs/commerce-saleor 0.0.11

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 (69) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +1 -0
  3. package/dist/cart/index.d.ts +4 -0
  4. package/dist/cart/use-add-item.d.ts +5 -0
  5. package/dist/cart/use-cart.d.ts +13 -0
  6. package/dist/cart/use-remove-item.d.ts +11 -0
  7. package/dist/cart/use-update-item.d.ts +20 -0
  8. package/dist/commerce-saleor.cjs.development.js +2165 -0
  9. package/dist/commerce-saleor.cjs.development.js.map +1 -0
  10. package/dist/commerce-saleor.cjs.production.min.js +2 -0
  11. package/dist/commerce-saleor.cjs.production.min.js.map +1 -0
  12. package/dist/commerce-saleor.esm.js +2155 -0
  13. package/dist/commerce-saleor.esm.js.map +1 -0
  14. package/dist/const.d.ts +4 -0
  15. package/dist/fetcher.d.ts +2 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.js +8 -0
  18. package/dist/product/use-price.d.ts +2 -0
  19. package/dist/product/use-product.d.ts +13 -0
  20. package/dist/product/use-search.d.ts +30 -0
  21. package/dist/provider.d.ts +63 -0
  22. package/dist/registerCommerceProvider.d.ts +10 -0
  23. package/dist/registerable.d.ts +6 -0
  24. package/dist/saleor.d.ts +4 -0
  25. package/dist/site/use-brands.d.ts +11 -0
  26. package/dist/site/use-categories.d.ts +11 -0
  27. package/dist/types/cart.d.ts +22 -0
  28. package/dist/types/site.d.ts +7 -0
  29. package/dist/types.d.ts +24 -0
  30. package/dist/utils/checkout-attach.d.ts +2 -0
  31. package/dist/utils/checkout-create.d.ts +3 -0
  32. package/dist/utils/checkout-to-cart.d.ts +9 -0
  33. package/dist/utils/customer-token.d.ts +7 -0
  34. package/dist/utils/fragments/checkout-details.d.ts +1 -0
  35. package/dist/utils/fragments/index.d.ts +2 -0
  36. package/dist/utils/fragments/product.d.ts +1 -0
  37. package/dist/utils/get-categories.d.ts +3 -0
  38. package/dist/utils/get-checkout-id.d.ts +5 -0
  39. package/dist/utils/get-search-variables.d.ts +14 -0
  40. package/dist/utils/get-sort-variables.d.ts +1 -0
  41. package/dist/utils/get-vendors.d.ts +11 -0
  42. package/dist/utils/handle-fetch-response.d.ts +5 -0
  43. package/dist/utils/handle-login.d.ts +5 -0
  44. package/dist/utils/index.d.ts +13 -0
  45. package/dist/utils/mutations/account-create.d.ts +1 -0
  46. package/dist/utils/mutations/checkout-attach.d.ts +1 -0
  47. package/dist/utils/mutations/checkout-create.d.ts +1 -0
  48. package/dist/utils/mutations/checkout-line-add.d.ts +1 -0
  49. package/dist/utils/mutations/checkout-line-remove.d.ts +1 -0
  50. package/dist/utils/mutations/checkout-line-update.d.ts +1 -0
  51. package/dist/utils/mutations/index.d.ts +8 -0
  52. package/dist/utils/mutations/session-create.d.ts +1 -0
  53. package/dist/utils/mutations/session-destroy.d.ts +1 -0
  54. package/dist/utils/normalize.d.ts +7 -0
  55. package/dist/utils/queries/checkout-one.d.ts +1 -0
  56. package/dist/utils/queries/collection-many.d.ts +1 -0
  57. package/dist/utils/queries/collection-one.d.ts +1 -0
  58. package/dist/utils/queries/customer-current.d.ts +1 -0
  59. package/dist/utils/queries/customer-one.d.ts +1 -0
  60. package/dist/utils/queries/get-all-product-vendors-query.d.ts +1 -0
  61. package/dist/utils/queries/get-all-products-paths-query.d.ts +1 -0
  62. package/dist/utils/queries/index.d.ts +11 -0
  63. package/dist/utils/queries/page-many.d.ts +1 -0
  64. package/dist/utils/queries/page-one.d.ts +1 -0
  65. package/dist/utils/queries/product-many.d.ts +1 -0
  66. package/dist/utils/queries/product-one-by-id.d.ts +1 -0
  67. package/dist/utils/queries/product-one-by-slug.d.ts +1 -0
  68. package/dist/utils/throw-user-errors.d.ts +5 -0
  69. package/package.json +49 -0
@@ -0,0 +1,2165 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var React = require('react');
8
+ var React__default = _interopDefault(React);
9
+ var commerce = require('@plasmicpkgs/commerce');
10
+ var Cookies = _interopDefault(require('js-cookie'));
11
+ var debounce = _interopDefault(require('lodash/debounce'));
12
+ var registerGlobalContext = _interopDefault(require('@plasmicapp/host/registerGlobalContext'));
13
+
14
+ /*
15
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
16
+ Changes: Removed api_url
17
+ */
18
+ var CHECKOUT_ID_COOKIE = 'saleor.CheckoutID';
19
+ var SALEOR_TOKEN = 'saleor.Token';
20
+
21
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
22
+ try {
23
+ var info = gen[key](arg);
24
+ var value = info.value;
25
+ } catch (error) {
26
+ reject(error);
27
+ return;
28
+ }
29
+
30
+ if (info.done) {
31
+ resolve(value);
32
+ } else {
33
+ Promise.resolve(value).then(_next, _throw);
34
+ }
35
+ }
36
+
37
+ function _asyncToGenerator(fn) {
38
+ return function () {
39
+ var self = this,
40
+ args = arguments;
41
+ return new Promise(function (resolve, reject) {
42
+ var gen = fn.apply(self, args);
43
+
44
+ function _next(value) {
45
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
46
+ }
47
+
48
+ function _throw(err) {
49
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
50
+ }
51
+
52
+ _next(undefined);
53
+ });
54
+ };
55
+ }
56
+
57
+ function _extends() {
58
+ _extends = Object.assign || function (target) {
59
+ for (var i = 1; i < arguments.length; i++) {
60
+ var source = arguments[i];
61
+
62
+ for (var key in source) {
63
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
64
+ target[key] = source[key];
65
+ }
66
+ }
67
+ }
68
+
69
+ return target;
70
+ };
71
+
72
+ return _extends.apply(this, arguments);
73
+ }
74
+
75
+ function _objectWithoutPropertiesLoose(source, excluded) {
76
+ if (source == null) return {};
77
+ var target = {};
78
+ var sourceKeys = Object.keys(source);
79
+ var key, i;
80
+
81
+ for (i = 0; i < sourceKeys.length; i++) {
82
+ key = sourceKeys[i];
83
+ if (excluded.indexOf(key) >= 0) continue;
84
+ target[key] = source[key];
85
+ }
86
+
87
+ return target;
88
+ }
89
+
90
+ function createCommonjsModule(fn, module) {
91
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
92
+ }
93
+
94
+ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
95
+ /**
96
+ * Copyright (c) 2014-present, Facebook, Inc.
97
+ *
98
+ * This source code is licensed under the MIT license found in the
99
+ * LICENSE file in the root directory of this source tree.
100
+ */
101
+ var runtime = function (exports) {
102
+
103
+ var Op = Object.prototype;
104
+ var hasOwn = Op.hasOwnProperty;
105
+ var undefined$1; // More compressible than void 0.
106
+
107
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
108
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
109
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
110
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
111
+
112
+ function define(obj, key, value) {
113
+ Object.defineProperty(obj, key, {
114
+ value: value,
115
+ enumerable: true,
116
+ configurable: true,
117
+ writable: true
118
+ });
119
+ return obj[key];
120
+ }
121
+
122
+ try {
123
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
124
+ define({}, "");
125
+ } catch (err) {
126
+ define = function define(obj, key, value) {
127
+ return obj[key] = value;
128
+ };
129
+ }
130
+
131
+ function wrap(innerFn, outerFn, self, tryLocsList) {
132
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
133
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
134
+ var generator = Object.create(protoGenerator.prototype);
135
+ var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
136
+ // .throw, and .return methods.
137
+
138
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
139
+ return generator;
140
+ }
141
+
142
+ exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
143
+ // record like context.tryEntries[i].completion. This interface could
144
+ // have been (and was previously) designed to take a closure to be
145
+ // invoked without arguments, but in all the cases we care about we
146
+ // already have an existing method we want to call, so there's no need
147
+ // to create a new function object. We can even get away with assuming
148
+ // the method takes exactly one argument, since that happens to be true
149
+ // in every case, so we don't have to touch the arguments object. The
150
+ // only additional allocation required is the completion record, which
151
+ // has a stable shape and so hopefully should be cheap to allocate.
152
+
153
+ function tryCatch(fn, obj, arg) {
154
+ try {
155
+ return {
156
+ type: "normal",
157
+ arg: fn.call(obj, arg)
158
+ };
159
+ } catch (err) {
160
+ return {
161
+ type: "throw",
162
+ arg: err
163
+ };
164
+ }
165
+ }
166
+
167
+ var GenStateSuspendedStart = "suspendedStart";
168
+ var GenStateSuspendedYield = "suspendedYield";
169
+ var GenStateExecuting = "executing";
170
+ var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
171
+ // breaking out of the dispatch switch statement.
172
+
173
+ var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
174
+ // .constructor.prototype properties for functions that return Generator
175
+ // objects. For full spec compliance, you may wish to configure your
176
+ // minifier not to mangle the names of these two functions.
177
+
178
+ function Generator() {}
179
+
180
+ function GeneratorFunction() {}
181
+
182
+ function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
183
+ // don't natively support it.
184
+
185
+
186
+ var IteratorPrototype = {};
187
+ define(IteratorPrototype, iteratorSymbol, function () {
188
+ return this;
189
+ });
190
+ var getProto = Object.getPrototypeOf;
191
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
192
+
193
+ if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
194
+ // This environment has a native %IteratorPrototype%; use it instead
195
+ // of the polyfill.
196
+ IteratorPrototype = NativeIteratorPrototype;
197
+ }
198
+
199
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
200
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
201
+ define(Gp, "constructor", GeneratorFunctionPrototype);
202
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
203
+ GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
204
+ // Iterator interface in terms of a single ._invoke method.
205
+
206
+ function defineIteratorMethods(prototype) {
207
+ ["next", "throw", "return"].forEach(function (method) {
208
+ define(prototype, method, function (arg) {
209
+ return this._invoke(method, arg);
210
+ });
211
+ });
212
+ }
213
+
214
+ exports.isGeneratorFunction = function (genFun) {
215
+ var ctor = typeof genFun === "function" && genFun.constructor;
216
+ return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
217
+ // do is to check its .name property.
218
+ (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
219
+ };
220
+
221
+ exports.mark = function (genFun) {
222
+ if (Object.setPrototypeOf) {
223
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
224
+ } else {
225
+ genFun.__proto__ = GeneratorFunctionPrototype;
226
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
227
+ }
228
+
229
+ genFun.prototype = Object.create(Gp);
230
+ return genFun;
231
+ }; // Within the body of any async function, `await x` is transformed to
232
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
233
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
234
+ // meant to be awaited.
235
+
236
+
237
+ exports.awrap = function (arg) {
238
+ return {
239
+ __await: arg
240
+ };
241
+ };
242
+
243
+ function AsyncIterator(generator, PromiseImpl) {
244
+ function invoke(method, arg, resolve, reject) {
245
+ var record = tryCatch(generator[method], generator, arg);
246
+
247
+ if (record.type === "throw") {
248
+ reject(record.arg);
249
+ } else {
250
+ var result = record.arg;
251
+ var value = result.value;
252
+
253
+ if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
254
+ return PromiseImpl.resolve(value.__await).then(function (value) {
255
+ invoke("next", value, resolve, reject);
256
+ }, function (err) {
257
+ invoke("throw", err, resolve, reject);
258
+ });
259
+ }
260
+
261
+ return PromiseImpl.resolve(value).then(function (unwrapped) {
262
+ // When a yielded Promise is resolved, its final value becomes
263
+ // the .value of the Promise<{value,done}> result for the
264
+ // current iteration.
265
+ result.value = unwrapped;
266
+ resolve(result);
267
+ }, function (error) {
268
+ // If a rejected Promise was yielded, throw the rejection back
269
+ // into the async generator function so it can be handled there.
270
+ return invoke("throw", error, resolve, reject);
271
+ });
272
+ }
273
+ }
274
+
275
+ var previousPromise;
276
+
277
+ function enqueue(method, arg) {
278
+ function callInvokeWithMethodAndArg() {
279
+ return new PromiseImpl(function (resolve, reject) {
280
+ invoke(method, arg, resolve, reject);
281
+ });
282
+ }
283
+
284
+ return previousPromise = // If enqueue has been called before, then we want to wait until
285
+ // all previous Promises have been resolved before calling invoke,
286
+ // so that results are always delivered in the correct order. If
287
+ // enqueue has not been called before, then it is important to
288
+ // call invoke immediately, without waiting on a callback to fire,
289
+ // so that the async generator function has the opportunity to do
290
+ // any necessary setup in a predictable way. This predictability
291
+ // is why the Promise constructor synchronously invokes its
292
+ // executor callback, and why async functions synchronously
293
+ // execute code before the first await. Since we implement simple
294
+ // async functions in terms of async generators, it is especially
295
+ // important to get this right, even though it requires care.
296
+ previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
297
+ // invocations of the iterator.
298
+ callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
299
+ } // Define the unified helper method that is used to implement .next,
300
+ // .throw, and .return (see defineIteratorMethods).
301
+
302
+
303
+ this._invoke = enqueue;
304
+ }
305
+
306
+ defineIteratorMethods(AsyncIterator.prototype);
307
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
308
+ return this;
309
+ });
310
+ exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
311
+ // AsyncIterator objects; they just return a Promise for the value of
312
+ // the final result produced by the iterator.
313
+
314
+ exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
315
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
316
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
317
+ return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
318
+ : iter.next().then(function (result) {
319
+ return result.done ? result.value : iter.next();
320
+ });
321
+ };
322
+
323
+ function makeInvokeMethod(innerFn, self, context) {
324
+ var state = GenStateSuspendedStart;
325
+ return function invoke(method, arg) {
326
+ if (state === GenStateExecuting) {
327
+ throw new Error("Generator is already running");
328
+ }
329
+
330
+ if (state === GenStateCompleted) {
331
+ if (method === "throw") {
332
+ throw arg;
333
+ } // Be forgiving, per 25.3.3.3.3 of the spec:
334
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
335
+
336
+
337
+ return doneResult();
338
+ }
339
+
340
+ context.method = method;
341
+ context.arg = arg;
342
+
343
+ while (true) {
344
+ var delegate = context.delegate;
345
+
346
+ if (delegate) {
347
+ var delegateResult = maybeInvokeDelegate(delegate, context);
348
+
349
+ if (delegateResult) {
350
+ if (delegateResult === ContinueSentinel) continue;
351
+ return delegateResult;
352
+ }
353
+ }
354
+
355
+ if (context.method === "next") {
356
+ // Setting context._sent for legacy support of Babel's
357
+ // function.sent implementation.
358
+ context.sent = context._sent = context.arg;
359
+ } else if (context.method === "throw") {
360
+ if (state === GenStateSuspendedStart) {
361
+ state = GenStateCompleted;
362
+ throw context.arg;
363
+ }
364
+
365
+ context.dispatchException(context.arg);
366
+ } else if (context.method === "return") {
367
+ context.abrupt("return", context.arg);
368
+ }
369
+
370
+ state = GenStateExecuting;
371
+ var record = tryCatch(innerFn, self, context);
372
+
373
+ if (record.type === "normal") {
374
+ // If an exception is thrown from innerFn, we leave state ===
375
+ // GenStateExecuting and loop back for another invocation.
376
+ state = context.done ? GenStateCompleted : GenStateSuspendedYield;
377
+
378
+ if (record.arg === ContinueSentinel) {
379
+ continue;
380
+ }
381
+
382
+ return {
383
+ value: record.arg,
384
+ done: context.done
385
+ };
386
+ } else if (record.type === "throw") {
387
+ state = GenStateCompleted; // Dispatch the exception by looping back around to the
388
+ // context.dispatchException(context.arg) call above.
389
+
390
+ context.method = "throw";
391
+ context.arg = record.arg;
392
+ }
393
+ }
394
+ };
395
+ } // Call delegate.iterator[context.method](context.arg) and handle the
396
+ // result, either by returning a { value, done } result from the
397
+ // delegate iterator, or by modifying context.method and context.arg,
398
+ // setting context.delegate to null, and returning the ContinueSentinel.
399
+
400
+
401
+ function maybeInvokeDelegate(delegate, context) {
402
+ var method = delegate.iterator[context.method];
403
+
404
+ if (method === undefined$1) {
405
+ // A .throw or .return when the delegate iterator has no .throw
406
+ // method always terminates the yield* loop.
407
+ context.delegate = null;
408
+
409
+ if (context.method === "throw") {
410
+ // Note: ["return"] must be used for ES3 parsing compatibility.
411
+ if (delegate.iterator["return"]) {
412
+ // If the delegate iterator has a return method, give it a
413
+ // chance to clean up.
414
+ context.method = "return";
415
+ context.arg = undefined$1;
416
+ maybeInvokeDelegate(delegate, context);
417
+
418
+ if (context.method === "throw") {
419
+ // If maybeInvokeDelegate(context) changed context.method from
420
+ // "return" to "throw", let that override the TypeError below.
421
+ return ContinueSentinel;
422
+ }
423
+ }
424
+
425
+ context.method = "throw";
426
+ context.arg = new TypeError("The iterator does not provide a 'throw' method");
427
+ }
428
+
429
+ return ContinueSentinel;
430
+ }
431
+
432
+ var record = tryCatch(method, delegate.iterator, context.arg);
433
+
434
+ if (record.type === "throw") {
435
+ context.method = "throw";
436
+ context.arg = record.arg;
437
+ context.delegate = null;
438
+ return ContinueSentinel;
439
+ }
440
+
441
+ var info = record.arg;
442
+
443
+ if (!info) {
444
+ context.method = "throw";
445
+ context.arg = new TypeError("iterator result is not an object");
446
+ context.delegate = null;
447
+ return ContinueSentinel;
448
+ }
449
+
450
+ if (info.done) {
451
+ // Assign the result of the finished delegate to the temporary
452
+ // variable specified by delegate.resultName (see delegateYield).
453
+ context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
454
+
455
+ context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
456
+ // exception, let the outer generator proceed normally. If
457
+ // context.method was "next", forget context.arg since it has been
458
+ // "consumed" by the delegate iterator. If context.method was
459
+ // "return", allow the original .return call to continue in the
460
+ // outer generator.
461
+
462
+ if (context.method !== "return") {
463
+ context.method = "next";
464
+ context.arg = undefined$1;
465
+ }
466
+ } else {
467
+ // Re-yield the result returned by the delegate method.
468
+ return info;
469
+ } // The delegate iterator is finished, so forget it and continue with
470
+ // the outer generator.
471
+
472
+
473
+ context.delegate = null;
474
+ return ContinueSentinel;
475
+ } // Define Generator.prototype.{next,throw,return} in terms of the
476
+ // unified ._invoke helper method.
477
+
478
+
479
+ defineIteratorMethods(Gp);
480
+ define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
481
+ // @@iterator function is called on it. Some browsers' implementations of the
482
+ // iterator prototype chain incorrectly implement this, causing the Generator
483
+ // object to not be returned from this call. This ensures that doesn't happen.
484
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
485
+
486
+ define(Gp, iteratorSymbol, function () {
487
+ return this;
488
+ });
489
+ define(Gp, "toString", function () {
490
+ return "[object Generator]";
491
+ });
492
+
493
+ function pushTryEntry(locs) {
494
+ var entry = {
495
+ tryLoc: locs[0]
496
+ };
497
+
498
+ if (1 in locs) {
499
+ entry.catchLoc = locs[1];
500
+ }
501
+
502
+ if (2 in locs) {
503
+ entry.finallyLoc = locs[2];
504
+ entry.afterLoc = locs[3];
505
+ }
506
+
507
+ this.tryEntries.push(entry);
508
+ }
509
+
510
+ function resetTryEntry(entry) {
511
+ var record = entry.completion || {};
512
+ record.type = "normal";
513
+ delete record.arg;
514
+ entry.completion = record;
515
+ }
516
+
517
+ function Context(tryLocsList) {
518
+ // The root entry object (effectively a try statement without a catch
519
+ // or a finally block) gives us a place to store values thrown from
520
+ // locations where there is no enclosing try statement.
521
+ this.tryEntries = [{
522
+ tryLoc: "root"
523
+ }];
524
+ tryLocsList.forEach(pushTryEntry, this);
525
+ this.reset(true);
526
+ }
527
+
528
+ exports.keys = function (object) {
529
+ var keys = [];
530
+
531
+ for (var key in object) {
532
+ keys.push(key);
533
+ }
534
+
535
+ keys.reverse(); // Rather than returning an object with a next method, we keep
536
+ // things simple and return the next function itself.
537
+
538
+ return function next() {
539
+ while (keys.length) {
540
+ var key = keys.pop();
541
+
542
+ if (key in object) {
543
+ next.value = key;
544
+ next.done = false;
545
+ return next;
546
+ }
547
+ } // To avoid creating an additional object, we just hang the .value
548
+ // and .done properties off the next function object itself. This
549
+ // also ensures that the minifier will not anonymize the function.
550
+
551
+
552
+ next.done = true;
553
+ return next;
554
+ };
555
+ };
556
+
557
+ function values(iterable) {
558
+ if (iterable) {
559
+ var iteratorMethod = iterable[iteratorSymbol];
560
+
561
+ if (iteratorMethod) {
562
+ return iteratorMethod.call(iterable);
563
+ }
564
+
565
+ if (typeof iterable.next === "function") {
566
+ return iterable;
567
+ }
568
+
569
+ if (!isNaN(iterable.length)) {
570
+ var i = -1,
571
+ next = function next() {
572
+ while (++i < iterable.length) {
573
+ if (hasOwn.call(iterable, i)) {
574
+ next.value = iterable[i];
575
+ next.done = false;
576
+ return next;
577
+ }
578
+ }
579
+
580
+ next.value = undefined$1;
581
+ next.done = true;
582
+ return next;
583
+ };
584
+
585
+ return next.next = next;
586
+ }
587
+ } // Return an iterator with no values.
588
+
589
+
590
+ return {
591
+ next: doneResult
592
+ };
593
+ }
594
+
595
+ exports.values = values;
596
+
597
+ function doneResult() {
598
+ return {
599
+ value: undefined$1,
600
+ done: true
601
+ };
602
+ }
603
+
604
+ Context.prototype = {
605
+ constructor: Context,
606
+ reset: function reset(skipTempReset) {
607
+ this.prev = 0;
608
+ this.next = 0; // Resetting context._sent for legacy support of Babel's
609
+ // function.sent implementation.
610
+
611
+ this.sent = this._sent = undefined$1;
612
+ this.done = false;
613
+ this.delegate = null;
614
+ this.method = "next";
615
+ this.arg = undefined$1;
616
+ this.tryEntries.forEach(resetTryEntry);
617
+
618
+ if (!skipTempReset) {
619
+ for (var name in this) {
620
+ // Not sure about the optimal order of these conditions:
621
+ if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
622
+ this[name] = undefined$1;
623
+ }
624
+ }
625
+ }
626
+ },
627
+ stop: function stop() {
628
+ this.done = true;
629
+ var rootEntry = this.tryEntries[0];
630
+ var rootRecord = rootEntry.completion;
631
+
632
+ if (rootRecord.type === "throw") {
633
+ throw rootRecord.arg;
634
+ }
635
+
636
+ return this.rval;
637
+ },
638
+ dispatchException: function dispatchException(exception) {
639
+ if (this.done) {
640
+ throw exception;
641
+ }
642
+
643
+ var context = this;
644
+
645
+ function handle(loc, caught) {
646
+ record.type = "throw";
647
+ record.arg = exception;
648
+ context.next = loc;
649
+
650
+ if (caught) {
651
+ // If the dispatched exception was caught by a catch block,
652
+ // then let that catch block handle the exception normally.
653
+ context.method = "next";
654
+ context.arg = undefined$1;
655
+ }
656
+
657
+ return !!caught;
658
+ }
659
+
660
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
661
+ var entry = this.tryEntries[i];
662
+ var record = entry.completion;
663
+
664
+ if (entry.tryLoc === "root") {
665
+ // Exception thrown outside of any try block that could handle
666
+ // it, so set the completion value of the entire function to
667
+ // throw the exception.
668
+ return handle("end");
669
+ }
670
+
671
+ if (entry.tryLoc <= this.prev) {
672
+ var hasCatch = hasOwn.call(entry, "catchLoc");
673
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
674
+
675
+ if (hasCatch && hasFinally) {
676
+ if (this.prev < entry.catchLoc) {
677
+ return handle(entry.catchLoc, true);
678
+ } else if (this.prev < entry.finallyLoc) {
679
+ return handle(entry.finallyLoc);
680
+ }
681
+ } else if (hasCatch) {
682
+ if (this.prev < entry.catchLoc) {
683
+ return handle(entry.catchLoc, true);
684
+ }
685
+ } else if (hasFinally) {
686
+ if (this.prev < entry.finallyLoc) {
687
+ return handle(entry.finallyLoc);
688
+ }
689
+ } else {
690
+ throw new Error("try statement without catch or finally");
691
+ }
692
+ }
693
+ }
694
+ },
695
+ abrupt: function abrupt(type, arg) {
696
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
697
+ var entry = this.tryEntries[i];
698
+
699
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
700
+ var finallyEntry = entry;
701
+ break;
702
+ }
703
+ }
704
+
705
+ if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
706
+ // Ignore the finally entry if control is not jumping to a
707
+ // location outside the try/catch block.
708
+ finallyEntry = null;
709
+ }
710
+
711
+ var record = finallyEntry ? finallyEntry.completion : {};
712
+ record.type = type;
713
+ record.arg = arg;
714
+
715
+ if (finallyEntry) {
716
+ this.method = "next";
717
+ this.next = finallyEntry.finallyLoc;
718
+ return ContinueSentinel;
719
+ }
720
+
721
+ return this.complete(record);
722
+ },
723
+ complete: function complete(record, afterLoc) {
724
+ if (record.type === "throw") {
725
+ throw record.arg;
726
+ }
727
+
728
+ if (record.type === "break" || record.type === "continue") {
729
+ this.next = record.arg;
730
+ } else if (record.type === "return") {
731
+ this.rval = this.arg = record.arg;
732
+ this.method = "return";
733
+ this.next = "end";
734
+ } else if (record.type === "normal" && afterLoc) {
735
+ this.next = afterLoc;
736
+ }
737
+
738
+ return ContinueSentinel;
739
+ },
740
+ finish: function finish(finallyLoc) {
741
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
742
+ var entry = this.tryEntries[i];
743
+
744
+ if (entry.finallyLoc === finallyLoc) {
745
+ this.complete(entry.completion, entry.afterLoc);
746
+ resetTryEntry(entry);
747
+ return ContinueSentinel;
748
+ }
749
+ }
750
+ },
751
+ "catch": function _catch(tryLoc) {
752
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
753
+ var entry = this.tryEntries[i];
754
+
755
+ if (entry.tryLoc === tryLoc) {
756
+ var record = entry.completion;
757
+
758
+ if (record.type === "throw") {
759
+ var thrown = record.arg;
760
+ resetTryEntry(entry);
761
+ }
762
+
763
+ return thrown;
764
+ }
765
+ } // The context.catch method must only be called with a location
766
+ // argument that corresponds to a known catch block.
767
+
768
+
769
+ throw new Error("illegal catch attempt");
770
+ },
771
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
772
+ this.delegate = {
773
+ iterator: values(iterable),
774
+ resultName: resultName,
775
+ nextLoc: nextLoc
776
+ };
777
+
778
+ if (this.method === "next") {
779
+ // Deliberately forget the last sent value so that we don't
780
+ // accidentally pass it on to the delegate.
781
+ this.arg = undefined$1;
782
+ }
783
+
784
+ return ContinueSentinel;
785
+ }
786
+ }; // Regardless of whether this script is executing as a CommonJS module
787
+ // or not, return the runtime object so that we can declare the variable
788
+ // regeneratorRuntime in the outer scope, which allows this module to be
789
+ // injected easily by `bin/regenerator --include-runtime script.js`.
790
+
791
+ return exports;
792
+ }( // If this script is executing as a CommonJS module, use module.exports
793
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
794
+ // object. Either way, the resulting object will be used to initialize
795
+ // the regeneratorRuntime variable at the top of this file.
796
+ module.exports );
797
+
798
+ try {
799
+ regeneratorRuntime = runtime;
800
+ } catch (accidentalStrictMode) {
801
+ // This module should not be running in strict mode, so the above
802
+ // assignment should always work unless something is misconfigured. Just
803
+ // in case runtime.js accidentally runs in strict mode, in modern engines
804
+ // we can explicitly access globalThis. In older engines we can escape
805
+ // strict mode using a global Function call. This could conceivably fail
806
+ // if a Content Security Policy forbids using Function, but in that case
807
+ // the proper solution is to fix the accidental strict mode problem. If
808
+ // you've misconfigured your bundler to force strict mode and applied a
809
+ // CSP to forbid Function, and you're not willing to fix either of those
810
+ // problems, please detail your unique predicament in a GitHub issue.
811
+ if (typeof globalThis === "object") {
812
+ globalThis.regeneratorRuntime = runtime;
813
+ } else {
814
+ Function("r", "regeneratorRuntime = r")(runtime);
815
+ }
816
+ }
817
+ });
818
+
819
+ /*
820
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
821
+ Changes: None
822
+ */
823
+ var getSortVariables = function getSortVariables(sort, isCategory) {
824
+
825
+ var output = {};
826
+
827
+ switch (sort) {
828
+ case 'price-asc':
829
+ output = {
830
+ field: 'PRICE',
831
+ direction: 'ASC'
832
+ };
833
+ break;
834
+
835
+ case 'price-desc':
836
+ output = {
837
+ field: 'PRICE',
838
+ direction: 'DESC'
839
+ };
840
+ break;
841
+
842
+ case 'trending-desc':
843
+ //default
844
+ output = {};
845
+ break;
846
+
847
+ case 'latest-desc':
848
+ output = {
849
+ field: 'DATE',
850
+ direction: 'DESC'
851
+ };
852
+ break;
853
+ }
854
+
855
+ return output;
856
+ };
857
+
858
+ function getError(errors, status) {
859
+ var _errors;
860
+
861
+ errors = (_errors = errors) != null ? _errors : [{
862
+ message: 'Failed to fetch Saleor API'
863
+ }];
864
+ return new commerce.FetcherError({
865
+ errors: errors,
866
+ status: status
867
+ });
868
+ }
869
+ function getAsyncError(_x) {
870
+ return _getAsyncError.apply(this, arguments);
871
+ }
872
+
873
+ function _getAsyncError() {
874
+ _getAsyncError = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(res) {
875
+ var data;
876
+ return runtime_1.wrap(function _callee2$(_context2) {
877
+ while (1) {
878
+ switch (_context2.prev = _context2.next) {
879
+ case 0:
880
+ _context2.next = 2;
881
+ return res.json();
882
+
883
+ case 2:
884
+ data = _context2.sent;
885
+ return _context2.abrupt("return", getError(data.errors, res.status));
886
+
887
+ case 4:
888
+ case "end":
889
+ return _context2.stop();
890
+ }
891
+ }
892
+ }, _callee2);
893
+ }));
894
+ return _getAsyncError.apply(this, arguments);
895
+ }
896
+
897
+ var handleFetchResponse = /*#__PURE__*/function () {
898
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(res) {
899
+ var _yield$res$json, data, errors;
900
+
901
+ return runtime_1.wrap(function _callee$(_context) {
902
+ while (1) {
903
+ switch (_context.prev = _context.next) {
904
+ case 0:
905
+ if (!res.ok) {
906
+ _context.next = 9;
907
+ break;
908
+ }
909
+
910
+ _context.next = 3;
911
+ return res.json();
912
+
913
+ case 3:
914
+ _yield$res$json = _context.sent;
915
+ data = _yield$res$json.data;
916
+ errors = _yield$res$json.errors;
917
+
918
+ if (!(errors && errors.length)) {
919
+ _context.next = 8;
920
+ break;
921
+ }
922
+
923
+ throw getError(errors, res.status);
924
+
925
+ case 8:
926
+ return _context.abrupt("return", data);
927
+
928
+ case 9:
929
+ _context.next = 11;
930
+ return getAsyncError(res);
931
+
932
+ case 11:
933
+ throw _context.sent;
934
+
935
+ case 12:
936
+ case "end":
937
+ return _context.stop();
938
+ }
939
+ }
940
+ }, _callee);
941
+ }));
942
+
943
+ return function handleFetchResponse(_x2) {
944
+ return _ref.apply(this, arguments);
945
+ };
946
+ }();
947
+
948
+ var getSearchVariables = function getSearchVariables(_ref) {
949
+ var search = _ref.search,
950
+ categoryId = _ref.categoryId,
951
+ sort = _ref.sort,
952
+ count = _ref.count;
953
+
954
+ var sortBy = _extends({
955
+ field: 'NAME',
956
+ direction: 'ASC'
957
+ }, getSortVariables(sort), {
958
+ channel: 'default-channel'
959
+ });
960
+
961
+ return {
962
+ categoryId: categoryId,
963
+ filter: {
964
+ search: search
965
+ },
966
+ sortBy: sortBy,
967
+ first: count
968
+ };
969
+ };
970
+
971
+ /*
972
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
973
+ Changes: None
974
+ */
975
+
976
+ var getCheckoutId = function getCheckoutId(id) {
977
+ var _Cookies$get;
978
+
979
+ var r = ((_Cookies$get = Cookies.get(CHECKOUT_ID_COOKIE)) == null ? void 0 : _Cookies$get.split(':')) || [];
980
+ return {
981
+ checkoutId: r[0],
982
+ checkoutToken: r[1]
983
+ };
984
+ };
985
+
986
+ /*
987
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
988
+ Changes: None
989
+ */
990
+ var ProductConnection =
991
+ /* GraphQL */
992
+ "\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";
993
+
994
+ /*
995
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
996
+ Changes: None
997
+ */
998
+ var CheckoutDetails =
999
+ /* GraphQL */
1000
+ "\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";
1001
+
1002
+ /*
1003
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1004
+ Changes: None
1005
+ */
1006
+ var CheckoutCreate =
1007
+ /* GraphQL */
1008
+ "\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";
1009
+
1010
+ /*
1011
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1012
+ Changes: None
1013
+ */
1014
+ var CheckoutLineAdd =
1015
+ /* GraphQL */
1016
+ "\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";
1017
+
1018
+ /*
1019
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1020
+ Changes: None
1021
+ */
1022
+ var CheckoutLineUpdate =
1023
+ /* GraphQL */
1024
+ "\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";
1025
+
1026
+ /*
1027
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1028
+ Changes: None
1029
+ */
1030
+ var CheckoutLineDelete =
1031
+ /* GraphQL */
1032
+ "\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";
1033
+
1034
+ var checkoutCreate = /*#__PURE__*/function () {
1035
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(fetch) {
1036
+ var _data$checkoutCreate;
1037
+
1038
+ var data, checkout, checkoutId, checkoutToken, value, options;
1039
+ return runtime_1.wrap(function _callee$(_context) {
1040
+ while (1) {
1041
+ switch (_context.prev = _context.next) {
1042
+ case 0:
1043
+ _context.next = 2;
1044
+ return fetch({
1045
+ query: CheckoutCreate
1046
+ });
1047
+
1048
+ case 2:
1049
+ data = _context.sent;
1050
+ checkout = (_data$checkoutCreate = data.checkoutCreate) == null ? void 0 : _data$checkoutCreate.checkout;
1051
+ checkoutId = checkout == null ? void 0 : checkout.id;
1052
+ checkoutToken = checkout == null ? void 0 : checkout.token;
1053
+ value = checkoutId + ":" + checkoutToken;
1054
+
1055
+ if (checkoutId) {
1056
+ options = {
1057
+ expires: 60 * 60 * 24 * 30,
1058
+ sameSite: "none",
1059
+ secure: true
1060
+ };
1061
+ Cookies.set(CHECKOUT_ID_COOKIE, value, options);
1062
+ }
1063
+
1064
+ return _context.abrupt("return", checkout);
1065
+
1066
+ case 9:
1067
+ case "end":
1068
+ return _context.stop();
1069
+ }
1070
+ }
1071
+ }, _callee);
1072
+ }));
1073
+
1074
+ return function checkoutCreate(_x) {
1075
+ return _ref.apply(this, arguments);
1076
+ };
1077
+ }();
1078
+
1079
+ var _excluded = ["id", "name", "media", "variants", "description", "slug", "pricing"];
1080
+
1081
+ /*
1082
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1083
+ Changes: None
1084
+ */
1085
+ // TODO: Check nextjs-commerce bug if no images are added for a product
1086
+ var placeholderImg = '/product-img-placeholder.svg';
1087
+
1088
+ var money = function money(_ref) {
1089
+ var amount = _ref.amount,
1090
+ currency = _ref.currency;
1091
+ return {
1092
+ value: +amount,
1093
+ currencyCode: currency || 'USD'
1094
+ };
1095
+ };
1096
+
1097
+ var normalizeProductOptions = function normalizeProductOptions(options) {
1098
+ return options == null ? void 0 : options.map(function (option) {
1099
+ return option == null ? void 0 : option.attributes;
1100
+ }).flat(1).reduce(function (acc, x) {
1101
+ if (acc.find(function (_ref2) {
1102
+ var displayName = _ref2.displayName;
1103
+ return displayName === x.attribute.name;
1104
+ })) {
1105
+ return acc.map(function (opt) {
1106
+ return opt.displayName === x.attribute.name ? _extends({}, opt, {
1107
+ values: [].concat(opt.values, x.values.map(function (value) {
1108
+ return {
1109
+ label: value == null ? void 0 : value.name
1110
+ };
1111
+ }))
1112
+ }) : opt;
1113
+ });
1114
+ }
1115
+
1116
+ return acc.concat({
1117
+ __typename: 'MultipleChoiceOption',
1118
+ displayName: x.attribute.name,
1119
+ variant: 'size',
1120
+ values: x.values.map(function (value) {
1121
+ return {
1122
+ label: value == null ? void 0 : value.name
1123
+ };
1124
+ })
1125
+ });
1126
+ }, []);
1127
+ };
1128
+
1129
+ var normalizeProductVariants = function normalizeProductVariants(variants) {
1130
+ return variants == null ? void 0 : variants.map(function (variant) {
1131
+ var _pricing$price, _money;
1132
+
1133
+ var id = variant.id,
1134
+ sku = variant.sku,
1135
+ name = variant.name,
1136
+ pricing = variant.pricing;
1137
+ var price = (pricing == null ? void 0 : (_pricing$price = pricing.price) == null ? void 0 : _pricing$price.net) && ((_money = money(pricing.price.net)) == null ? void 0 : _money.value);
1138
+ return {
1139
+ id: id,
1140
+ name: name,
1141
+ sku: sku != null ? sku : id,
1142
+ price: price,
1143
+ listPrice: price,
1144
+ requiresShipping: true,
1145
+ options: normalizeProductOptions([variant])
1146
+ };
1147
+ });
1148
+ };
1149
+
1150
+ function normalizeProduct(productNode) {
1151
+ var _JSON$parse, _JSON$parse$blocks$, _pricing$priceRange, _pricing$priceRange$s;
1152
+
1153
+ var id = productNode.id,
1154
+ name = productNode.name,
1155
+ _productNode$media = productNode.media,
1156
+ media = _productNode$media === void 0 ? [] : _productNode$media,
1157
+ variants = productNode.variants,
1158
+ description = productNode.description,
1159
+ slug = productNode.slug,
1160
+ pricing = productNode.pricing,
1161
+ rest = _objectWithoutPropertiesLoose(productNode, _excluded);
1162
+
1163
+ var product = _extends({
1164
+ id: id,
1165
+ name: name,
1166
+ vendor: '',
1167
+ 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 : '',
1168
+ path: "/" + slug,
1169
+ slug: slug == null ? void 0 : slug.replace(/^\/+|\/+$/g, ''),
1170
+ 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) || {
1171
+ value: 0,
1172
+ currencyCode: 'USD'
1173
+ },
1174
+ // TODO: Check nextjs-commerce bug if no images are added for a product
1175
+ images: media != null && media.length ? media : [{
1176
+ url: placeholderImg
1177
+ }],
1178
+ variants: variants && variants.length > 0 ? normalizeProductVariants(variants) : [],
1179
+ options: variants && variants.length > 0 ? normalizeProductOptions(variants) : []
1180
+ }, rest);
1181
+
1182
+ return product;
1183
+ }
1184
+ function normalizeCart(checkout) {
1185
+ var _checkout$totalPrice, _checkout$subtotalPri, _checkout$subtotalPri2, _checkout$subtotalPri3, _checkout$subtotalPri4, _checkout$totalPrice2;
1186
+
1187
+ var lines = checkout.lines;
1188
+ var lineItems = lines.length > 0 ? lines == null ? void 0 : lines.map(normalizeLineItem) : [];
1189
+ return {
1190
+ id: checkout.id,
1191
+ customerId: '',
1192
+ email: '',
1193
+ createdAt: checkout.created,
1194
+ currency: {
1195
+ code: (_checkout$totalPrice = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice.currency
1196
+ },
1197
+ taxesIncluded: false,
1198
+ lineItems: lineItems,
1199
+ lineItemsSubtotalPrice: (_checkout$subtotalPri = checkout.subtotalPrice) == null ? void 0 : (_checkout$subtotalPri2 = _checkout$subtotalPri.gross) == null ? void 0 : _checkout$subtotalPri2.amount,
1200
+ subtotalPrice: (_checkout$subtotalPri3 = checkout.subtotalPrice) == null ? void 0 : (_checkout$subtotalPri4 = _checkout$subtotalPri3.gross) == null ? void 0 : _checkout$subtotalPri4.amount,
1201
+ totalPrice: (_checkout$totalPrice2 = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice2.gross.amount,
1202
+ discounts: []
1203
+ };
1204
+ }
1205
+
1206
+ function normalizeLineItem(_ref3) {
1207
+ var _variant$sku, _variant$pricing, _variant$pricing$pric, _variant$product;
1208
+
1209
+ var id = _ref3.id,
1210
+ variant = _ref3.variant,
1211
+ quantity = _ref3.quantity;
1212
+ return {
1213
+ id: id,
1214
+ variantId: String(variant == null ? void 0 : variant.id),
1215
+ productId: String(variant == null ? void 0 : variant.id),
1216
+ name: "" + variant.product.name,
1217
+ quantity: quantity,
1218
+ variant: {
1219
+ id: String(variant == null ? void 0 : variant.id),
1220
+ sku: (_variant$sku = variant == null ? void 0 : variant.sku) != null ? _variant$sku : '',
1221
+ name: variant == null ? void 0 : variant.name,
1222
+ image: {
1223
+ url: variant != null && variant.media[0] ? variant == null ? void 0 : variant.media[0].url : placeholderImg
1224
+ },
1225
+ requiresShipping: false,
1226
+ 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,
1227
+ listPrice: 0
1228
+ },
1229
+ path: String(variant == null ? void 0 : (_variant$product = variant.product) == null ? void 0 : _variant$product.slug),
1230
+ discounts: [],
1231
+ options: []
1232
+ };
1233
+ }
1234
+
1235
+ var normalizeCategory = function normalizeCategory(_ref4) {
1236
+ var name = _ref4.name,
1237
+ slug = _ref4.slug,
1238
+ id = _ref4.id;
1239
+ return {
1240
+ id: id,
1241
+ name: name,
1242
+ slug: slug,
1243
+ path: "/" + slug
1244
+ };
1245
+ };
1246
+
1247
+ /*
1248
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1249
+ Changes: None
1250
+ */
1251
+ var throwUserErrors = function throwUserErrors(errors) {
1252
+ if (errors && errors.length) {
1253
+ throw new commerce.ValidationError({
1254
+ errors: errors.map(function (_ref) {
1255
+ var code = _ref.code,
1256
+ message = _ref.message;
1257
+ return {
1258
+ code: code != null ? code : 'validation_error',
1259
+ message: message || ''
1260
+ };
1261
+ })
1262
+ });
1263
+ }
1264
+ };
1265
+
1266
+ /*
1267
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1268
+ Changes: None
1269
+ */
1270
+
1271
+ var checkoutToCart = function checkoutToCart(checkoutPayload) {
1272
+ var _checkoutPayload$erro;
1273
+
1274
+ if (!checkoutPayload) {
1275
+ throw new commerce.CommerceError({
1276
+ message: 'Missing checkout payload from response'
1277
+ });
1278
+ }
1279
+
1280
+ var checkout = checkoutPayload == null ? void 0 : checkoutPayload.checkout;
1281
+
1282
+ if ((checkoutPayload == null ? void 0 : (_checkoutPayload$erro = checkoutPayload.errors) == null ? void 0 : _checkoutPayload$erro.length) === 1 && checkoutPayload.errors[0].code === "PRODUCT_UNAVAILABLE_FOR_PURCHASE") {
1283
+ console.error(checkoutPayload.errors[0]);
1284
+ return undefined;
1285
+ }
1286
+
1287
+ if (checkoutPayload != null && checkoutPayload.errors) {
1288
+ throwUserErrors(checkoutPayload == null ? void 0 : checkoutPayload.errors);
1289
+ }
1290
+
1291
+ if (!checkout) {
1292
+ throw new commerce.CommerceError({
1293
+ message: 'Missing checkout object from response'
1294
+ });
1295
+ }
1296
+
1297
+ return normalizeCart(checkout);
1298
+ };
1299
+
1300
+ /*
1301
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1302
+ Changes: None
1303
+ */
1304
+ var getToken = function getToken() {
1305
+ return Cookies.get(SALEOR_TOKEN);
1306
+ };
1307
+
1308
+ /*
1309
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1310
+ Changes: None
1311
+ */
1312
+ var CollectionMany =
1313
+ /* GraphQL */
1314
+ "\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";
1315
+
1316
+ /*
1317
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1318
+ Changes: None
1319
+ */
1320
+ var ProductOneBySlug =
1321
+ /* GraphQL */
1322
+ "\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";
1323
+
1324
+ /*
1325
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1326
+ Changes: None
1327
+ */
1328
+ var ProductMany =
1329
+ /* GraphQL */
1330
+ "\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";
1331
+
1332
+ /*
1333
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1334
+ Changes: None
1335
+ */
1336
+ var CollectionOne =
1337
+ /* GraphQL */
1338
+ "\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";
1339
+
1340
+ /*
1341
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1342
+ Changes: None
1343
+ */
1344
+ var CheckoutOne =
1345
+ /* GraphQL */
1346
+ "\n query CheckoutOne($checkoutId: UUID!) {\n checkout(token: $checkoutId) {\n ... on Checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
1347
+
1348
+ /*
1349
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
1350
+ Changes: None
1351
+ */
1352
+ var getAllProductVendors =
1353
+ /* GraphQL */
1354
+ "\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";
1355
+
1356
+ var handler = {
1357
+ fetchOptions: {
1358
+ query: CheckoutOne
1359
+ },
1360
+ fetcher: function fetcher(_ref) {
1361
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1362
+ var _checkout;
1363
+
1364
+ var checkoutId, options, fetch, checkout, _checkoutId, data;
1365
+
1366
+ return runtime_1.wrap(function _callee$(_context) {
1367
+ while (1) {
1368
+ switch (_context.prev = _context.next) {
1369
+ case 0:
1370
+ checkoutId = _ref.input.cartId, options = _ref.options, fetch = _ref.fetch;
1371
+
1372
+ if (!checkoutId) {
1373
+ _context.next = 7;
1374
+ break;
1375
+ }
1376
+
1377
+ _checkoutId = getCheckoutId().checkoutToken;
1378
+ _context.next = 5;
1379
+ return fetch(_extends({}, options, {
1380
+ variables: {
1381
+ checkoutId: _checkoutId
1382
+ }
1383
+ }));
1384
+
1385
+ case 5:
1386
+ data = _context.sent;
1387
+ checkout = data;
1388
+
1389
+ case 7:
1390
+ if (!((_checkout = checkout) != null && _checkout.completedAt || !checkoutId)) {
1391
+ _context.next = 11;
1392
+ break;
1393
+ }
1394
+
1395
+ _context.next = 10;
1396
+ return checkoutCreate(fetch);
1397
+
1398
+ case 10:
1399
+ checkout = _context.sent;
1400
+
1401
+ case 11:
1402
+ return _context.abrupt("return", checkoutToCart(checkout));
1403
+
1404
+ case 12:
1405
+ case "end":
1406
+ return _context.stop();
1407
+ }
1408
+ }
1409
+ }, _callee);
1410
+ }))();
1411
+ },
1412
+ useHook: function useHook(_ref2) {
1413
+ var useData = _ref2.useData;
1414
+ return function (input) {
1415
+ var response = useData({
1416
+ swrOptions: _extends({
1417
+ revalidateOnFocus: false
1418
+ }, input == null ? void 0 : input.swrOptions)
1419
+ });
1420
+ return React.useMemo(function () {
1421
+ return Object.create(response, {
1422
+ isEmpty: {
1423
+ get: function get() {
1424
+ var _response$data$lineIt, _response$data;
1425
+
1426
+ return ((_response$data$lineIt = (_response$data = response.data) == null ? void 0 : _response$data.lineItems.length) != null ? _response$data$lineIt : 0) <= 0;
1427
+ },
1428
+ enumerable: true
1429
+ }
1430
+ });
1431
+ }, [response]);
1432
+ };
1433
+ }
1434
+ };
1435
+
1436
+ var handler$1 = {
1437
+ fetchOptions: {
1438
+ query: CheckoutLineAdd
1439
+ },
1440
+ fetcher: function fetcher(_ref) {
1441
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1442
+ var _item$quantity;
1443
+
1444
+ var item, options, fetch, _yield$fetch, checkoutLinesAdd;
1445
+
1446
+ return runtime_1.wrap(function _callee$(_context) {
1447
+ while (1) {
1448
+ switch (_context.prev = _context.next) {
1449
+ case 0:
1450
+ item = _ref.input, options = _ref.options, fetch = _ref.fetch;
1451
+
1452
+ if (!(item.quantity && (!Number.isInteger(item.quantity) || item.quantity < 1))) {
1453
+ _context.next = 3;
1454
+ break;
1455
+ }
1456
+
1457
+ throw new commerce.CommerceError({
1458
+ message: "The item quantity has to be a valid integer greater than 0"
1459
+ });
1460
+
1461
+ case 3:
1462
+ _context.next = 5;
1463
+ return fetch(_extends({}, options, {
1464
+ variables: {
1465
+ checkoutId: getCheckoutId().checkoutId,
1466
+ lineItems: [{
1467
+ variantId: item.variantId,
1468
+ quantity: (_item$quantity = item.quantity) != null ? _item$quantity : 1
1469
+ }]
1470
+ }
1471
+ }));
1472
+
1473
+ case 5:
1474
+ _yield$fetch = _context.sent;
1475
+ checkoutLinesAdd = _yield$fetch.checkoutLinesAdd;
1476
+ return _context.abrupt("return", checkoutToCart(checkoutLinesAdd));
1477
+
1478
+ case 8:
1479
+ case "end":
1480
+ return _context.stop();
1481
+ }
1482
+ }
1483
+ }, _callee);
1484
+ }))();
1485
+ },
1486
+ useHook: function useHook(_ref2) {
1487
+ var fetch = _ref2.fetch;
1488
+ return function () {
1489
+ var _useCart = commerce.useCart(),
1490
+ mutate = _useCart.mutate;
1491
+
1492
+ return React.useCallback( /*#__PURE__*/function () {
1493
+ var _addItem = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
1494
+ var data;
1495
+ return runtime_1.wrap(function _callee2$(_context2) {
1496
+ while (1) {
1497
+ switch (_context2.prev = _context2.next) {
1498
+ case 0:
1499
+ _context2.next = 2;
1500
+ return fetch({
1501
+ input: input
1502
+ });
1503
+
1504
+ case 2:
1505
+ data = _context2.sent;
1506
+
1507
+ if (!data) {
1508
+ _context2.next = 8;
1509
+ break;
1510
+ }
1511
+
1512
+ _context2.next = 6;
1513
+ return mutate(data, false);
1514
+
1515
+ case 6:
1516
+ _context2.next = 10;
1517
+ break;
1518
+
1519
+ case 8:
1520
+ _context2.next = 10;
1521
+ return mutate();
1522
+
1523
+ case 10:
1524
+ return _context2.abrupt("return", data);
1525
+
1526
+ case 11:
1527
+ case "end":
1528
+ return _context2.stop();
1529
+ }
1530
+ }
1531
+ }, _callee2);
1532
+ }));
1533
+
1534
+ function addItem(_x) {
1535
+ return _addItem.apply(this, arguments);
1536
+ }
1537
+
1538
+ return addItem;
1539
+ }(), [fetch, mutate]);
1540
+ };
1541
+ }
1542
+ };
1543
+
1544
+ var handler$2 = {
1545
+ fetchOptions: {
1546
+ query: CheckoutLineDelete
1547
+ },
1548
+ fetcher: function fetcher(_ref) {
1549
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1550
+ var itemId, options, fetch, data;
1551
+ return runtime_1.wrap(function _callee$(_context) {
1552
+ while (1) {
1553
+ switch (_context.prev = _context.next) {
1554
+ case 0:
1555
+ itemId = _ref.input.itemId, options = _ref.options, fetch = _ref.fetch;
1556
+ _context.next = 3;
1557
+ return fetch(_extends({}, options, {
1558
+ variables: {
1559
+ checkoutId: getCheckoutId().checkoutId,
1560
+ lineId: itemId
1561
+ }
1562
+ }));
1563
+
1564
+ case 3:
1565
+ data = _context.sent;
1566
+ return _context.abrupt("return", checkoutToCart(data.checkoutLineDelete));
1567
+
1568
+ case 5:
1569
+ case "end":
1570
+ return _context.stop();
1571
+ }
1572
+ }
1573
+ }, _callee);
1574
+ }))();
1575
+ },
1576
+ useHook: function useHook(_ref2) {
1577
+ var fetch = _ref2.fetch;
1578
+ return function () {
1579
+ var _useCart = commerce.useCart(),
1580
+ mutate = _useCart.mutate;
1581
+
1582
+ return React.useCallback( /*#__PURE__*/function () {
1583
+ var _removeItem = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
1584
+ var data;
1585
+ return runtime_1.wrap(function _callee2$(_context2) {
1586
+ while (1) {
1587
+ switch (_context2.prev = _context2.next) {
1588
+ case 0:
1589
+ _context2.next = 2;
1590
+ return fetch({
1591
+ input: {
1592
+ itemId: input.id
1593
+ }
1594
+ });
1595
+
1596
+ case 2:
1597
+ data = _context2.sent;
1598
+ _context2.next = 5;
1599
+ return mutate(data, false);
1600
+
1601
+ case 5:
1602
+ return _context2.abrupt("return", data);
1603
+
1604
+ case 6:
1605
+ case "end":
1606
+ return _context2.stop();
1607
+ }
1608
+ }
1609
+ }, _callee2);
1610
+ }));
1611
+
1612
+ function removeItem(_x) {
1613
+ return _removeItem.apply(this, arguments);
1614
+ }
1615
+
1616
+ return removeItem;
1617
+ }(), [fetch, mutate]);
1618
+ };
1619
+ }
1620
+ };
1621
+
1622
+ var handler$3 = {
1623
+ fetchOptions: {
1624
+ query: CheckoutLineUpdate
1625
+ },
1626
+ fetcher: function fetcher(_ref) {
1627
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1628
+ var _ref$input, itemId, item, options, fetch, checkoutId, _yield$fetch, checkoutLinesUpdate;
1629
+
1630
+ return runtime_1.wrap(function _callee$(_context) {
1631
+ while (1) {
1632
+ switch (_context.prev = _context.next) {
1633
+ case 0:
1634
+ _ref$input = _ref.input, itemId = _ref$input.itemId, item = _ref$input.item, options = _ref.options, fetch = _ref.fetch;
1635
+
1636
+ if (!Number.isInteger(item.quantity)) {
1637
+ _context.next = 6;
1638
+ break;
1639
+ }
1640
+
1641
+ if (!(item.quantity < 1)) {
1642
+ _context.next = 4;
1643
+ break;
1644
+ }
1645
+
1646
+ return _context.abrupt("return", handler$2.fetcher({
1647
+ options: handler$2.fetchOptions,
1648
+ input: {
1649
+ itemId: itemId
1650
+ },
1651
+ fetch: fetch
1652
+ }));
1653
+
1654
+ case 4:
1655
+ _context.next = 8;
1656
+ break;
1657
+
1658
+ case 6:
1659
+ if (!item.quantity) {
1660
+ _context.next = 8;
1661
+ break;
1662
+ }
1663
+
1664
+ throw new commerce.ValidationError({
1665
+ message: "The item quantity has to be a valid integer"
1666
+ });
1667
+
1668
+ case 8:
1669
+ checkoutId = getCheckoutId().checkoutId;
1670
+ _context.next = 11;
1671
+ return fetch(_extends({}, options, {
1672
+ variables: {
1673
+ checkoutId: checkoutId,
1674
+ lineItems: [{
1675
+ variantId: item.variantId,
1676
+ quantity: item.quantity
1677
+ }]
1678
+ }
1679
+ }));
1680
+
1681
+ case 11:
1682
+ _yield$fetch = _context.sent;
1683
+ checkoutLinesUpdate = _yield$fetch.checkoutLinesUpdate;
1684
+ return _context.abrupt("return", checkoutToCart(checkoutLinesUpdate));
1685
+
1686
+ case 14:
1687
+ case "end":
1688
+ return _context.stop();
1689
+ }
1690
+ }
1691
+ }, _callee);
1692
+ }))();
1693
+ },
1694
+ useHook: function useHook(_ref2) {
1695
+ var fetch = _ref2.fetch;
1696
+ return function (ctx) {
1697
+ var _ctx$wait;
1698
+
1699
+ if (ctx === void 0) {
1700
+ ctx = {};
1701
+ }
1702
+
1703
+ var _ctx = ctx,
1704
+ item = _ctx.item;
1705
+
1706
+ var _useCart = commerce.useCart(),
1707
+ mutate = _useCart.mutate;
1708
+
1709
+ return React.useCallback(debounce( /*#__PURE__*/function () {
1710
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
1711
+ var _input$id, _input$productId, _input$productId2;
1712
+
1713
+ var itemId, productId, variantId, data;
1714
+ return runtime_1.wrap(function _callee2$(_context2) {
1715
+ while (1) {
1716
+ switch (_context2.prev = _context2.next) {
1717
+ case 0:
1718
+ itemId = (_input$id = input.id) != null ? _input$id : item == null ? void 0 : item.id;
1719
+ productId = (_input$productId = input.productId) != null ? _input$productId : item == null ? void 0 : item.productId;
1720
+ variantId = (_input$productId2 = input.productId) != null ? _input$productId2 : item == null ? void 0 : item.variantId;
1721
+
1722
+ if (!(!itemId || !productId || !variantId)) {
1723
+ _context2.next = 5;
1724
+ break;
1725
+ }
1726
+
1727
+ throw new commerce.ValidationError({
1728
+ message: "Invalid input used for this operation"
1729
+ });
1730
+
1731
+ case 5:
1732
+ _context2.next = 7;
1733
+ return fetch({
1734
+ input: {
1735
+ item: {
1736
+ productId: productId,
1737
+ variantId: variantId,
1738
+ quantity: input.quantity
1739
+ },
1740
+ itemId: itemId
1741
+ }
1742
+ });
1743
+
1744
+ case 7:
1745
+ data = _context2.sent;
1746
+ _context2.next = 10;
1747
+ return mutate(data, false);
1748
+
1749
+ case 10:
1750
+ return _context2.abrupt("return", data);
1751
+
1752
+ case 11:
1753
+ case "end":
1754
+ return _context2.stop();
1755
+ }
1756
+ }
1757
+ }, _callee2);
1758
+ }));
1759
+
1760
+ return function (_x) {
1761
+ return _ref3.apply(this, arguments);
1762
+ };
1763
+ }(), (_ctx$wait = ctx.wait) != null ? _ctx$wait : 500), [fetch, mutate]);
1764
+ };
1765
+ }
1766
+ };
1767
+
1768
+ var handler$4 = {
1769
+ fetchOptions: {
1770
+ query: CollectionMany
1771
+ },
1772
+ fetcher: function fetcher(_ref) {
1773
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1774
+ var input, fetch, categoryId, _data$collections$edg, _data$collections, _data$collections$edg2, data, _data;
1775
+
1776
+ return runtime_1.wrap(function _callee$(_context) {
1777
+ while (1) {
1778
+ switch (_context.prev = _context.next) {
1779
+ case 0:
1780
+ input = _ref.input, fetch = _ref.fetch;
1781
+ categoryId = input.categoryId;
1782
+
1783
+ if (categoryId) {
1784
+ _context.next = 9;
1785
+ break;
1786
+ }
1787
+
1788
+ _context.next = 5;
1789
+ return fetch({
1790
+ query: CollectionMany,
1791
+ variables: {
1792
+ first: 250
1793
+ }
1794
+ });
1795
+
1796
+ case 5:
1797
+ data = _context.sent;
1798
+ 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) {
1799
+ var node = _ref2.node;
1800
+ return normalizeCategory(node);
1801
+ })) != null ? _data$collections$edg : []);
1802
+
1803
+ case 9:
1804
+ _context.next = 11;
1805
+ return fetch({
1806
+ query: CollectionOne,
1807
+ variables: {
1808
+ categoryId: categoryId
1809
+ }
1810
+ });
1811
+
1812
+ case 11:
1813
+ _data = _context.sent;
1814
+ return _context.abrupt("return", !!(_data != null && _data.collection) ? [normalizeCategory(_data == null ? void 0 : _data.collection)] : []);
1815
+
1816
+ case 13:
1817
+ case "end":
1818
+ return _context.stop();
1819
+ }
1820
+ }
1821
+ }, _callee);
1822
+ }))();
1823
+ },
1824
+ useHook: function useHook(_ref3) {
1825
+ var useData = _ref3.useData;
1826
+ return function (input) {
1827
+ var response = useData({
1828
+ input: [["categoryId", input == null ? void 0 : input.categoryId]],
1829
+ swrOptions: _extends({
1830
+ revalidateOnFocus: false
1831
+ }, input == null ? void 0 : input.swrOptions)
1832
+ });
1833
+ return React.useMemo(function () {
1834
+ return Object.create(response, {
1835
+ isEmpty: {
1836
+ get: function get() {
1837
+ var _response$data$length, _response$data;
1838
+
1839
+ return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
1840
+ },
1841
+ enumerable: true
1842
+ }
1843
+ });
1844
+ }, [response]);
1845
+ };
1846
+ }
1847
+ };
1848
+
1849
+ var handler$5 = {
1850
+ fetchOptions: {
1851
+ query: getAllProductVendors
1852
+ },
1853
+ fetcher: function fetcher(_ref) {
1854
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1855
+ return runtime_1.wrap(function _callee$(_context) {
1856
+ while (1) {
1857
+ switch (_context.prev = _context.next) {
1858
+ case 0:
1859
+ return _context.abrupt("return", []);
1860
+
1861
+ case 2:
1862
+ case "end":
1863
+ return _context.stop();
1864
+ }
1865
+ }
1866
+ }, _callee);
1867
+ }))();
1868
+ },
1869
+ useHook: function useHook(_ref2) {
1870
+ var useData = _ref2.useData;
1871
+ return function (input) {
1872
+ var response = useData({
1873
+ swrOptions: _extends({
1874
+ revalidateOnFocus: false
1875
+ }, input == null ? void 0 : input.swrOptions)
1876
+ });
1877
+ return React.useMemo(function () {
1878
+ return Object.create(response, {
1879
+ isEmpty: {
1880
+ get: function get() {
1881
+ var _response$data$length, _response$data;
1882
+
1883
+ return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
1884
+ },
1885
+ enumerable: true
1886
+ }
1887
+ });
1888
+ }, [response]);
1889
+ };
1890
+ }
1891
+ };
1892
+
1893
+ var handler$6 = {
1894
+ fetchOptions: {
1895
+ query: ProductMany
1896
+ },
1897
+ fetcher: function fetcher(_ref) {
1898
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1899
+ var input, options, fetch, categoryId, brandId, data, edges, _data$collection$prod, _data$collection, _data$collection$prod2, _data$products$edges, _data$products;
1900
+
1901
+ return runtime_1.wrap(function _callee$(_context) {
1902
+ while (1) {
1903
+ switch (_context.prev = _context.next) {
1904
+ case 0:
1905
+ input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1906
+ categoryId = input.categoryId, brandId = input.brandId;
1907
+ _context.next = 4;
1908
+ return fetch({
1909
+ query: categoryId ? CollectionOne : options.query,
1910
+ method: options == null ? void 0 : options.method,
1911
+ variables: getSearchVariables(input)
1912
+ });
1913
+
1914
+ case 4:
1915
+ data = _context.sent;
1916
+
1917
+ if (categoryId) {
1918
+ edges = (_data$collection$prod = (_data$collection = data.collection) == null ? void 0 : (_data$collection$prod2 = _data$collection.products) == null ? void 0 : _data$collection$prod2.edges) != null ? _data$collection$prod : []; // FIXME @zaiste, no `vendor` in Saleor
1919
+ // if (brandId) {
1920
+ // edges = edges.filter(
1921
+ // ({ node: { vendor } }: ProductCountableEdge) =>
1922
+ // vendor.replace(/\s+/g, '-').toLowerCase() === brandId
1923
+ // )
1924
+ // }
1925
+ } else {
1926
+ edges = (_data$products$edges = (_data$products = data.products) == null ? void 0 : _data$products.edges) != null ? _data$products$edges : [];
1927
+ }
1928
+
1929
+ return _context.abrupt("return", {
1930
+ products: edges.map(function (_ref2) {
1931
+ var node = _ref2.node;
1932
+ return normalizeProduct(node);
1933
+ }),
1934
+ found: !!edges.length
1935
+ });
1936
+
1937
+ case 7:
1938
+ case "end":
1939
+ return _context.stop();
1940
+ }
1941
+ }
1942
+ }, _callee);
1943
+ }))();
1944
+ },
1945
+ useHook: function useHook(_ref3) {
1946
+ var useData = _ref3.useData;
1947
+ return function (input) {
1948
+ if (input === void 0) {
1949
+ input = {};
1950
+ }
1951
+
1952
+ return useData({
1953
+ input: [["search", input.search], ["categoryId", input.categoryId], ["brandId", input.brandId], ["sort", input.sort], ["count", input.count]],
1954
+ swrOptions: _extends({
1955
+ revalidateOnFocus: false
1956
+ }, input.swrOptions)
1957
+ });
1958
+ };
1959
+ }
1960
+ };
1961
+
1962
+ var ProductOneById =
1963
+ /* GraphQL */
1964
+ "\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 }";
1965
+
1966
+ var handler$7 = {
1967
+ fetchOptions: {
1968
+ query: ProductOneById
1969
+ },
1970
+ fetcher: function fetcher(_ref) {
1971
+ return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1972
+ var input, fetch, id, data, response;
1973
+ return runtime_1.wrap(function _callee$(_context) {
1974
+ while (1) {
1975
+ switch (_context.prev = _context.next) {
1976
+ case 0:
1977
+ input = _ref.input, fetch = _ref.fetch;
1978
+ id = input.id;
1979
+
1980
+ if (id) {
1981
+ _context.next = 4;
1982
+ break;
1983
+ }
1984
+
1985
+ return _context.abrupt("return", null);
1986
+
1987
+ case 4:
1988
+ _context.next = 6;
1989
+ return fetch({
1990
+ query: ProductOneById,
1991
+ variables: {
1992
+ id: id
1993
+ }
1994
+ });
1995
+
1996
+ case 6:
1997
+ data = _context.sent;
1998
+
1999
+ if (data.product) {
2000
+ _context.next = 12;
2001
+ break;
2002
+ }
2003
+
2004
+ _context.next = 10;
2005
+ return fetch({
2006
+ query: ProductOneBySlug,
2007
+ variables: {
2008
+ slug: id
2009
+ }
2010
+ });
2011
+
2012
+ case 10:
2013
+ response = _context.sent;
2014
+ return _context.abrupt("return", response.product ? normalizeProduct(response.product) : null);
2015
+
2016
+ case 12:
2017
+ return _context.abrupt("return", data.product ? normalizeProduct(data.product) : null);
2018
+
2019
+ case 13:
2020
+ case "end":
2021
+ return _context.stop();
2022
+ }
2023
+ }
2024
+ }, _callee);
2025
+ }))();
2026
+ },
2027
+ useHook: function useHook(_ref2) {
2028
+ var useData = _ref2.useData;
2029
+ return function (input) {
2030
+ if (input === void 0) {
2031
+ input = {};
2032
+ }
2033
+
2034
+ return useData({
2035
+ input: [["id", input.id]],
2036
+ swrOptions: _extends({
2037
+ revalidateOnFocus: false
2038
+ }, input.swrOptions)
2039
+ });
2040
+ };
2041
+ }
2042
+ };
2043
+
2044
+ var _excluded$1 = ["locale"];
2045
+ var getFetcher = function getFetcher(saleorApiUrl) {
2046
+ return /*#__PURE__*/function () {
2047
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
2048
+ var _ref$url, url, _ref$method, method, query, variables, _ref3, vars, token;
2049
+
2050
+ return runtime_1.wrap(function _callee$(_context) {
2051
+ while (1) {
2052
+ switch (_context.prev = _context.next) {
2053
+ case 0:
2054
+ _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;
2055
+ _ref3 = variables != null ? variables : {}, vars = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
2056
+ token = getToken();
2057
+ _context.t0 = handleFetchResponse;
2058
+ _context.next = 6;
2059
+ return fetch(url, {
2060
+ method: method,
2061
+ body: JSON.stringify({
2062
+ query: query,
2063
+ variables: vars
2064
+ }),
2065
+ headers: {
2066
+ Authorization: "JWT " + token,
2067
+ 'Content-Type': 'application/json'
2068
+ }
2069
+ });
2070
+
2071
+ case 6:
2072
+ _context.t1 = _context.sent;
2073
+ return _context.abrupt("return", (0, _context.t0)(_context.t1));
2074
+
2075
+ case 8:
2076
+ case "end":
2077
+ return _context.stop();
2078
+ }
2079
+ }
2080
+ }, _callee);
2081
+ }));
2082
+
2083
+ return function (_x) {
2084
+ return _ref2.apply(this, arguments);
2085
+ };
2086
+ }();
2087
+ };
2088
+
2089
+ /*
2090
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
2091
+ Changes:
2092
+ - Removed customer and auth hooks.
2093
+ - Added saleor_api_url parameters.
2094
+ */
2095
+ var getSaleorProvider = function getSaleorProvider(saleorApiUrl) {
2096
+ return {
2097
+ locale: 'en-us',
2098
+ cartCookie: CHECKOUT_ID_COOKIE,
2099
+ fetcher: getFetcher(saleorApiUrl),
2100
+ cart: {
2101
+ useCart: handler,
2102
+ useAddItem: handler$1,
2103
+ useUpdateItem: handler$3,
2104
+ useRemoveItem: handler$2
2105
+ },
2106
+ products: {
2107
+ useSearch: handler$6,
2108
+ useProduct: handler$7
2109
+ },
2110
+ site: {
2111
+ useCategories: handler$4,
2112
+ useBrands: handler$5
2113
+ }
2114
+ };
2115
+ };
2116
+
2117
+ /*
2118
+ Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
2119
+ Changes:
2120
+ - Added saleor_api_url parameter.
2121
+ */
2122
+ var useCommerce = function useCommerce() {
2123
+ return commerce.useCommerce();
2124
+ };
2125
+ var getCommerceProvider = function getCommerceProvider(saleorApiUrl) {
2126
+ return commerce.getCommerceProvider(getSaleorProvider(saleorApiUrl));
2127
+ };
2128
+
2129
+ var commerceProviderMeta = {
2130
+ name: "plasmic-commerce-saleor-provider",
2131
+ displayName: "Saleor Provider",
2132
+ props: {
2133
+ saleorApiUrl: {
2134
+ type: "string",
2135
+ defaultValue: 'https://vercel.saleor.cloud/graphql/'
2136
+ }
2137
+ },
2138
+ importPath: "commerce-providers/saleor",
2139
+ importName: "SaleorProvider"
2140
+ };
2141
+
2142
+ function CommerceProviderComponent(props) {
2143
+ var saleorApiUrl = props.saleorApiUrl,
2144
+ children = props.children;
2145
+ var CommerceProvider = getCommerceProvider(saleorApiUrl);
2146
+ return React__default.createElement(CommerceProvider, null, children);
2147
+ }
2148
+
2149
+ function registerCommerceProvider(loader, customCommerceProviderMeta) {
2150
+ var doRegisterComponent = function doRegisterComponent() {
2151
+ return loader ? loader.registerGlobalContext.apply(loader, arguments) : registerGlobalContext.apply(void 0, arguments);
2152
+ };
2153
+
2154
+ doRegisterComponent(CommerceProviderComponent, customCommerceProviderMeta != null ? customCommerceProviderMeta : commerceProviderMeta);
2155
+ }
2156
+
2157
+ function registerAll(loader) {
2158
+ registerCommerceProvider(loader);
2159
+ }
2160
+
2161
+ exports.getCommerceProvider = getCommerceProvider;
2162
+ exports.registerAll = registerAll;
2163
+ exports.registerCommerceProvider = registerCommerceProvider;
2164
+ exports.useCommerce = useCommerce;
2165
+ //# sourceMappingURL=commerce-saleor.cjs.development.js.map