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