@plasmicpkgs/commerce-swell 0.0.166 → 0.0.167

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
2
2
  import React, { useMemo, useCallback } from 'react';
3
3
  import { CommerceError, useCart, ValidationError, getCommerceProvider as getCommerceProvider$1, useCommerce as useCommerce$1, globalActionsRegistrations, CartActionsProvider } from '@plasmicpkgs/commerce';
4
- import swell from 'swell-js';
4
+ import swell, { init } from 'swell-js';
5
5
  import Cookies from 'js-cookie';
6
6
  import debounce from 'debounce';
7
7
 
@@ -13,6 +13,307 @@ var SWELL_CHECKOUT_ID_COOKIE = 'SWELL_checkoutId';
13
13
  var SWELL_CHECKOUT_URL_COOKIE = 'swell_checkoutUrl';
14
14
  var SWELL_COOKIE_EXPIRE = 30;
15
15
 
16
+ function _regeneratorRuntime() {
17
+ _regeneratorRuntime = function () {
18
+ return e;
19
+ };
20
+ var t,
21
+ e = {},
22
+ r = Object.prototype,
23
+ n = r.hasOwnProperty,
24
+ o = Object.defineProperty || function (t, e, r) {
25
+ t[e] = r.value;
26
+ },
27
+ i = "function" == typeof Symbol ? Symbol : {},
28
+ a = i.iterator || "@@iterator",
29
+ c = i.asyncIterator || "@@asyncIterator",
30
+ u = i.toStringTag || "@@toStringTag";
31
+ function define(t, e, r) {
32
+ return Object.defineProperty(t, e, {
33
+ value: r,
34
+ enumerable: !0,
35
+ configurable: !0,
36
+ writable: !0
37
+ }), t[e];
38
+ }
39
+ try {
40
+ define({}, "");
41
+ } catch (t) {
42
+ define = function (t, e, r) {
43
+ return t[e] = r;
44
+ };
45
+ }
46
+ function wrap(t, e, r, n) {
47
+ var i = e && e.prototype instanceof Generator ? e : Generator,
48
+ a = Object.create(i.prototype),
49
+ c = new Context(n || []);
50
+ return o(a, "_invoke", {
51
+ value: makeInvokeMethod(t, r, c)
52
+ }), a;
53
+ }
54
+ function tryCatch(t, e, r) {
55
+ try {
56
+ return {
57
+ type: "normal",
58
+ arg: t.call(e, r)
59
+ };
60
+ } catch (t) {
61
+ return {
62
+ type: "throw",
63
+ arg: t
64
+ };
65
+ }
66
+ }
67
+ e.wrap = wrap;
68
+ var h = "suspendedStart",
69
+ l = "suspendedYield",
70
+ f = "executing",
71
+ s = "completed",
72
+ y = {};
73
+ function Generator() {}
74
+ function GeneratorFunction() {}
75
+ function GeneratorFunctionPrototype() {}
76
+ var p = {};
77
+ define(p, a, function () {
78
+ return this;
79
+ });
80
+ var d = Object.getPrototypeOf,
81
+ v = d && d(d(values([])));
82
+ v && v !== r && n.call(v, a) && (p = v);
83
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
84
+ function defineIteratorMethods(t) {
85
+ ["next", "throw", "return"].forEach(function (e) {
86
+ define(t, e, function (t) {
87
+ return this._invoke(e, t);
88
+ });
89
+ });
90
+ }
91
+ function AsyncIterator(t, e) {
92
+ function invoke(r, o, i, a) {
93
+ var c = tryCatch(t[r], t, o);
94
+ if ("throw" !== c.type) {
95
+ var u = c.arg,
96
+ h = u.value;
97
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
98
+ invoke("next", t, i, a);
99
+ }, function (t) {
100
+ invoke("throw", t, i, a);
101
+ }) : e.resolve(h).then(function (t) {
102
+ u.value = t, i(u);
103
+ }, function (t) {
104
+ return invoke("throw", t, i, a);
105
+ });
106
+ }
107
+ a(c.arg);
108
+ }
109
+ var r;
110
+ o(this, "_invoke", {
111
+ value: function (t, n) {
112
+ function callInvokeWithMethodAndArg() {
113
+ return new e(function (e, r) {
114
+ invoke(t, n, e, r);
115
+ });
116
+ }
117
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
118
+ }
119
+ });
120
+ }
121
+ function makeInvokeMethod(e, r, n) {
122
+ var o = h;
123
+ return function (i, a) {
124
+ if (o === f) throw new Error("Generator is already running");
125
+ if (o === s) {
126
+ if ("throw" === i) throw a;
127
+ return {
128
+ value: t,
129
+ done: !0
130
+ };
131
+ }
132
+ for (n.method = i, n.arg = a;;) {
133
+ var c = n.delegate;
134
+ if (c) {
135
+ var u = maybeInvokeDelegate(c, n);
136
+ if (u) {
137
+ if (u === y) continue;
138
+ return u;
139
+ }
140
+ }
141
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
142
+ if (o === h) throw o = s, n.arg;
143
+ n.dispatchException(n.arg);
144
+ } else "return" === n.method && n.abrupt("return", n.arg);
145
+ o = f;
146
+ var p = tryCatch(e, r, n);
147
+ if ("normal" === p.type) {
148
+ if (o = n.done ? s : l, p.arg === y) continue;
149
+ return {
150
+ value: p.arg,
151
+ done: n.done
152
+ };
153
+ }
154
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
155
+ }
156
+ };
157
+ }
158
+ function maybeInvokeDelegate(e, r) {
159
+ var n = r.method,
160
+ o = e.iterator[n];
161
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
162
+ var i = tryCatch(o, e.iterator, r.arg);
163
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
164
+ var a = i.arg;
165
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
166
+ }
167
+ function pushTryEntry(t) {
168
+ var e = {
169
+ tryLoc: t[0]
170
+ };
171
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
172
+ }
173
+ function resetTryEntry(t) {
174
+ var e = t.completion || {};
175
+ e.type = "normal", delete e.arg, t.completion = e;
176
+ }
177
+ function Context(t) {
178
+ this.tryEntries = [{
179
+ tryLoc: "root"
180
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
181
+ }
182
+ function values(e) {
183
+ if (e || "" === e) {
184
+ var r = e[a];
185
+ if (r) return r.call(e);
186
+ if ("function" == typeof e.next) return e;
187
+ if (!isNaN(e.length)) {
188
+ var o = -1,
189
+ i = function next() {
190
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
191
+ return next.value = t, next.done = !0, next;
192
+ };
193
+ return i.next = i;
194
+ }
195
+ }
196
+ throw new TypeError(typeof e + " is not iterable");
197
+ }
198
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
199
+ value: GeneratorFunctionPrototype,
200
+ configurable: !0
201
+ }), o(GeneratorFunctionPrototype, "constructor", {
202
+ value: GeneratorFunction,
203
+ configurable: !0
204
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
205
+ var e = "function" == typeof t && t.constructor;
206
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
207
+ }, e.mark = function (t) {
208
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
209
+ }, e.awrap = function (t) {
210
+ return {
211
+ __await: t
212
+ };
213
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
214
+ return this;
215
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
216
+ void 0 === i && (i = Promise);
217
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
218
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
219
+ return t.done ? t.value : a.next();
220
+ });
221
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
222
+ return this;
223
+ }), define(g, "toString", function () {
224
+ return "[object Generator]";
225
+ }), e.keys = function (t) {
226
+ var e = Object(t),
227
+ r = [];
228
+ for (var n in e) r.push(n);
229
+ return r.reverse(), function next() {
230
+ for (; r.length;) {
231
+ var t = r.pop();
232
+ if (t in e) return next.value = t, next.done = !1, next;
233
+ }
234
+ return next.done = !0, next;
235
+ };
236
+ }, e.values = values, Context.prototype = {
237
+ constructor: Context,
238
+ reset: function (e) {
239
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
240
+ },
241
+ stop: function () {
242
+ this.done = !0;
243
+ var t = this.tryEntries[0].completion;
244
+ if ("throw" === t.type) throw t.arg;
245
+ return this.rval;
246
+ },
247
+ dispatchException: function (e) {
248
+ if (this.done) throw e;
249
+ var r = this;
250
+ function handle(n, o) {
251
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
252
+ }
253
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
254
+ var i = this.tryEntries[o],
255
+ a = i.completion;
256
+ if ("root" === i.tryLoc) return handle("end");
257
+ if (i.tryLoc <= this.prev) {
258
+ var c = n.call(i, "catchLoc"),
259
+ u = n.call(i, "finallyLoc");
260
+ if (c && u) {
261
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
262
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
263
+ } else if (c) {
264
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
265
+ } else {
266
+ if (!u) throw new Error("try statement without catch or finally");
267
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
268
+ }
269
+ }
270
+ }
271
+ },
272
+ abrupt: function (t, e) {
273
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
274
+ var o = this.tryEntries[r];
275
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
276
+ var i = o;
277
+ break;
278
+ }
279
+ }
280
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
281
+ var a = i ? i.completion : {};
282
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
283
+ },
284
+ complete: function (t, e) {
285
+ if ("throw" === t.type) throw t.arg;
286
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
287
+ },
288
+ finish: function (t) {
289
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
290
+ var r = this.tryEntries[e];
291
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
292
+ }
293
+ },
294
+ catch: function (t) {
295
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
296
+ var r = this.tryEntries[e];
297
+ if (r.tryLoc === t) {
298
+ var n = r.completion;
299
+ if ("throw" === n.type) {
300
+ var o = n.arg;
301
+ resetTryEntry(r);
302
+ }
303
+ return o;
304
+ }
305
+ }
306
+ throw new Error("illegal catch attempt");
307
+ },
308
+ delegateYield: function (e, r, n) {
309
+ return this.delegate = {
310
+ iterator: values(e),
311
+ resultName: r,
312
+ nextLoc: n
313
+ }, "next" === this.method && (this.arg = t), y;
314
+ }
315
+ }, e;
316
+ }
16
317
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
318
  try {
18
319
  var info = gen[key](arg);
@@ -101,664 +402,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
101
402
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
403
  }
103
404
 
104
- function createCommonjsModule(fn, module) {
105
- return module = { exports: {} }, fn(module, module.exports), module.exports;
106
- }
107
-
108
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
109
- /**
110
- * Copyright (c) 2014-present, Facebook, Inc.
111
- *
112
- * This source code is licensed under the MIT license found in the
113
- * LICENSE file in the root directory of this source tree.
114
- */
115
-
116
- var runtime = function (exports) {
117
-
118
- var Op = Object.prototype;
119
- var hasOwn = Op.hasOwnProperty;
120
- var undefined$1; // More compressible than void 0.
121
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
122
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
123
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
124
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
125
- function define(obj, key, value) {
126
- Object.defineProperty(obj, key, {
127
- value: value,
128
- enumerable: true,
129
- configurable: true,
130
- writable: true
131
- });
132
- return obj[key];
133
- }
134
- try {
135
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
136
- define({}, "");
137
- } catch (err) {
138
- define = function define(obj, key, value) {
139
- return obj[key] = value;
140
- };
141
- }
142
- function wrap(innerFn, outerFn, self, tryLocsList) {
143
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
144
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
145
- var generator = Object.create(protoGenerator.prototype);
146
- var context = new Context(tryLocsList || []);
147
-
148
- // The ._invoke method unifies the implementations of the .next,
149
- // .throw, and .return methods.
150
- generator._invoke = makeInvokeMethod(innerFn, self, context);
151
- return generator;
152
- }
153
- exports.wrap = wrap;
154
-
155
- // Try/catch helper to minimize deoptimizations. Returns a completion
156
- // record like context.tryEntries[i].completion. This interface could
157
- // have been (and was previously) designed to take a closure to be
158
- // invoked without arguments, but in all the cases we care about we
159
- // already have an existing method we want to call, so there's no need
160
- // to create a new function object. We can even get away with assuming
161
- // the method takes exactly one argument, since that happens to be true
162
- // in every case, so we don't have to touch the arguments object. The
163
- // only additional allocation required is the completion record, which
164
- // has a stable shape and so hopefully should be cheap to allocate.
165
- function tryCatch(fn, obj, arg) {
166
- try {
167
- return {
168
- type: "normal",
169
- arg: fn.call(obj, arg)
170
- };
171
- } catch (err) {
172
- return {
173
- type: "throw",
174
- arg: err
175
- };
176
- }
177
- }
178
- var GenStateSuspendedStart = "suspendedStart";
179
- var GenStateSuspendedYield = "suspendedYield";
180
- var GenStateExecuting = "executing";
181
- var GenStateCompleted = "completed";
182
-
183
- // Returning this object from the innerFn has the same effect as
184
- // breaking out of the dispatch switch statement.
185
- var ContinueSentinel = {};
186
-
187
- // Dummy constructor functions that we use as the .constructor and
188
- // .constructor.prototype properties for functions that return Generator
189
- // objects. For full spec compliance, you may wish to configure your
190
- // minifier not to mangle the names of these two functions.
191
- function Generator() {}
192
- function GeneratorFunction() {}
193
- function GeneratorFunctionPrototype() {}
194
-
195
- // This is a polyfill for %IteratorPrototype% for environments that
196
- // don't natively support it.
197
- var IteratorPrototype = {};
198
- define(IteratorPrototype, iteratorSymbol, function () {
199
- return this;
200
- });
201
- var getProto = Object.getPrototypeOf;
202
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
203
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
204
- // This environment has a native %IteratorPrototype%; use it instead
205
- // of the polyfill.
206
- IteratorPrototype = NativeIteratorPrototype;
207
- }
208
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
209
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
210
- define(Gp, "constructor", GeneratorFunctionPrototype);
211
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
212
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
213
-
214
- // Helper for defining the .next, .throw, and .return methods of the
215
- // Iterator interface in terms of a single ._invoke method.
216
- function defineIteratorMethods(prototype) {
217
- ["next", "throw", "return"].forEach(function (method) {
218
- define(prototype, method, function (arg) {
219
- return this._invoke(method, arg);
220
- });
221
- });
222
- }
223
- exports.isGeneratorFunction = function (genFun) {
224
- var ctor = typeof genFun === "function" && genFun.constructor;
225
- return ctor ? ctor === GeneratorFunction ||
226
- // For the native GeneratorFunction constructor, the best we can
227
- // do is to check its .name property.
228
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
229
- };
230
- exports.mark = function (genFun) {
231
- if (Object.setPrototypeOf) {
232
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
233
- } else {
234
- genFun.__proto__ = GeneratorFunctionPrototype;
235
- define(genFun, toStringTagSymbol, "GeneratorFunction");
236
- }
237
- genFun.prototype = Object.create(Gp);
238
- return genFun;
239
- };
240
-
241
- // Within the body of any async function, `await x` is transformed to
242
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
243
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
244
- // meant to be awaited.
245
- exports.awrap = function (arg) {
246
- return {
247
- __await: arg
248
- };
249
- };
250
- function AsyncIterator(generator, PromiseImpl) {
251
- function invoke(method, arg, resolve, reject) {
252
- var record = tryCatch(generator[method], generator, arg);
253
- if (record.type === "throw") {
254
- reject(record.arg);
255
- } else {
256
- var result = record.arg;
257
- var value = result.value;
258
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
259
- return PromiseImpl.resolve(value.__await).then(function (value) {
260
- invoke("next", value, resolve, reject);
261
- }, function (err) {
262
- invoke("throw", err, resolve, reject);
263
- });
264
- }
265
- return PromiseImpl.resolve(value).then(function (unwrapped) {
266
- // When a yielded Promise is resolved, its final value becomes
267
- // the .value of the Promise<{value,done}> result for the
268
- // current iteration.
269
- result.value = unwrapped;
270
- resolve(result);
271
- }, function (error) {
272
- // If a rejected Promise was yielded, throw the rejection back
273
- // into the async generator function so it can be handled there.
274
- return invoke("throw", error, resolve, reject);
275
- });
276
- }
277
- }
278
- var previousPromise;
279
- function enqueue(method, arg) {
280
- function callInvokeWithMethodAndArg() {
281
- return new PromiseImpl(function (resolve, reject) {
282
- invoke(method, arg, resolve, reject);
283
- });
284
- }
285
- return previousPromise =
286
- // If enqueue has been called before, then we want to wait until
287
- // all previous Promises have been resolved before calling invoke,
288
- // so that results are always delivered in the correct order. If
289
- // enqueue has not been called before, then it is important to
290
- // call invoke immediately, without waiting on a callback to fire,
291
- // so that the async generator function has the opportunity to do
292
- // any necessary setup in a predictable way. This predictability
293
- // is why the Promise constructor synchronously invokes its
294
- // executor callback, and why async functions synchronously
295
- // execute code before the first await. Since we implement simple
296
- // async functions in terms of async generators, it is especially
297
- // important to get this right, even though it requires care.
298
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg,
299
- // Avoid propagating failures to Promises returned by later
300
- // invocations of the iterator.
301
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
302
- }
303
-
304
- // Define the unified helper method that is used to implement .next,
305
- // .throw, and .return (see defineIteratorMethods).
306
- this._invoke = enqueue;
307
- }
308
- defineIteratorMethods(AsyncIterator.prototype);
309
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
310
- return this;
311
- });
312
- exports.AsyncIterator = AsyncIterator;
313
-
314
- // Note that simple async functions are implemented on top of
315
- // AsyncIterator objects; they just return a Promise for the value of
316
- // the final result produced by the iterator.
317
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
318
- if (PromiseImpl === void 0) PromiseImpl = Promise;
319
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
320
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
321
- : iter.next().then(function (result) {
322
- return result.done ? result.value : iter.next();
323
- });
324
- };
325
- function makeInvokeMethod(innerFn, self, context) {
326
- var state = GenStateSuspendedStart;
327
- return function invoke(method, arg) {
328
- if (state === GenStateExecuting) {
329
- throw new Error("Generator is already running");
330
- }
331
- if (state === GenStateCompleted) {
332
- if (method === "throw") {
333
- throw arg;
334
- }
335
-
336
- // Be forgiving, per 25.3.3.3.3 of the spec:
337
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
338
- return doneResult();
339
- }
340
- context.method = method;
341
- context.arg = arg;
342
- while (true) {
343
- var delegate = context.delegate;
344
- if (delegate) {
345
- var delegateResult = maybeInvokeDelegate(delegate, context);
346
- if (delegateResult) {
347
- if (delegateResult === ContinueSentinel) continue;
348
- return delegateResult;
349
- }
350
- }
351
- if (context.method === "next") {
352
- // Setting context._sent for legacy support of Babel's
353
- // function.sent implementation.
354
- context.sent = context._sent = context.arg;
355
- } else if (context.method === "throw") {
356
- if (state === GenStateSuspendedStart) {
357
- state = GenStateCompleted;
358
- throw context.arg;
359
- }
360
- context.dispatchException(context.arg);
361
- } else if (context.method === "return") {
362
- context.abrupt("return", context.arg);
363
- }
364
- state = GenStateExecuting;
365
- var record = tryCatch(innerFn, self, context);
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
- if (record.arg === ContinueSentinel) {
371
- continue;
372
- }
373
- return {
374
- value: record.arg,
375
- done: context.done
376
- };
377
- } else if (record.type === "throw") {
378
- state = GenStateCompleted;
379
- // Dispatch the exception by looping back around to the
380
- // context.dispatchException(context.arg) call above.
381
- context.method = "throw";
382
- context.arg = record.arg;
383
- }
384
- }
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
- function maybeInvokeDelegate(delegate, context) {
393
- var method = delegate.iterator[context.method];
394
- if (method === undefined$1) {
395
- // A .throw or .return when the delegate iterator has no .throw
396
- // method always terminates the yield* loop.
397
- context.delegate = null;
398
- if (context.method === "throw") {
399
- // Note: ["return"] must be used for ES3 parsing compatibility.
400
- if (delegate.iterator["return"]) {
401
- // If the delegate iterator has a return method, give it a
402
- // chance to clean up.
403
- context.method = "return";
404
- context.arg = undefined$1;
405
- maybeInvokeDelegate(delegate, context);
406
- if (context.method === "throw") {
407
- // If maybeInvokeDelegate(context) changed context.method from
408
- // "return" to "throw", let that override the TypeError below.
409
- return ContinueSentinel;
410
- }
411
- }
412
- context.method = "throw";
413
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
414
- }
415
- return ContinueSentinel;
416
- }
417
- var record = tryCatch(method, delegate.iterator, context.arg);
418
- if (record.type === "throw") {
419
- context.method = "throw";
420
- context.arg = record.arg;
421
- context.delegate = null;
422
- return ContinueSentinel;
423
- }
424
- var info = record.arg;
425
- if (!info) {
426
- context.method = "throw";
427
- context.arg = new TypeError("iterator result is not an object");
428
- context.delegate = null;
429
- return ContinueSentinel;
430
- }
431
- if (info.done) {
432
- // Assign the result of the finished delegate to the temporary
433
- // variable specified by delegate.resultName (see delegateYield).
434
- context[delegate.resultName] = info.value;
435
-
436
- // Resume execution at the desired location (see delegateYield).
437
- context.next = delegate.nextLoc;
438
-
439
- // If context.method was "throw" but the delegate handled the
440
- // exception, let the outer generator proceed normally. If
441
- // context.method was "next", forget context.arg since it has been
442
- // "consumed" by the delegate iterator. If context.method was
443
- // "return", allow the original .return call to continue in the
444
- // outer generator.
445
- if (context.method !== "return") {
446
- context.method = "next";
447
- context.arg = undefined$1;
448
- }
449
- } else {
450
- // Re-yield the result returned by the delegate method.
451
- return info;
452
- }
453
-
454
- // The delegate iterator is finished, so forget it and continue with
455
- // the outer generator.
456
- context.delegate = null;
457
- return ContinueSentinel;
458
- }
459
-
460
- // Define Generator.prototype.{next,throw,return} in terms of the
461
- // unified ._invoke helper method.
462
- defineIteratorMethods(Gp);
463
- define(Gp, toStringTagSymbol, "Generator");
464
-
465
- // A Generator should always return itself as the iterator object when the
466
- // @@iterator function is called on it. Some browsers' implementations of the
467
- // iterator prototype chain incorrectly implement this, causing the Generator
468
- // object to not be returned from this call. This ensures that doesn't happen.
469
- // See https://github.com/facebook/regenerator/issues/274 for more details.
470
- define(Gp, iteratorSymbol, function () {
471
- return this;
472
- });
473
- define(Gp, "toString", function () {
474
- return "[object Generator]";
475
- });
476
- function pushTryEntry(locs) {
477
- var entry = {
478
- tryLoc: locs[0]
479
- };
480
- if (1 in locs) {
481
- entry.catchLoc = locs[1];
482
- }
483
- if (2 in locs) {
484
- entry.finallyLoc = locs[2];
485
- entry.afterLoc = locs[3];
486
- }
487
- this.tryEntries.push(entry);
488
- }
489
- function resetTryEntry(entry) {
490
- var record = entry.completion || {};
491
- record.type = "normal";
492
- delete record.arg;
493
- entry.completion = record;
494
- }
495
- function Context(tryLocsList) {
496
- // The root entry object (effectively a try statement without a catch
497
- // or a finally block) gives us a place to store values thrown from
498
- // locations where there is no enclosing try statement.
499
- this.tryEntries = [{
500
- tryLoc: "root"
501
- }];
502
- tryLocsList.forEach(pushTryEntry, this);
503
- this.reset(true);
504
- }
505
- exports.keys = function (object) {
506
- var keys = [];
507
- for (var key in object) {
508
- keys.push(key);
509
- }
510
- keys.reverse();
511
-
512
- // Rather than returning an object with a next method, we keep
513
- // things simple and return the next function itself.
514
- return function next() {
515
- while (keys.length) {
516
- var key = keys.pop();
517
- if (key in object) {
518
- next.value = key;
519
- next.done = false;
520
- return next;
521
- }
522
- }
523
-
524
- // To avoid creating an additional object, we just hang the .value
525
- // and .done properties off the next function object itself. This
526
- // also ensures that the minifier will not anonymize the function.
527
- next.done = true;
528
- return next;
529
- };
530
- };
531
- function values(iterable) {
532
- if (iterable) {
533
- var iteratorMethod = iterable[iteratorSymbol];
534
- if (iteratorMethod) {
535
- return iteratorMethod.call(iterable);
536
- }
537
- if (typeof iterable.next === "function") {
538
- return iterable;
539
- }
540
- if (!isNaN(iterable.length)) {
541
- var i = -1,
542
- next = function next() {
543
- while (++i < iterable.length) {
544
- if (hasOwn.call(iterable, i)) {
545
- next.value = iterable[i];
546
- next.done = false;
547
- return next;
548
- }
549
- }
550
- next.value = undefined$1;
551
- next.done = true;
552
- return next;
553
- };
554
- return next.next = next;
555
- }
556
- }
557
-
558
- // Return an iterator with no values.
559
- return {
560
- next: doneResult
561
- };
562
- }
563
- exports.values = values;
564
- function doneResult() {
565
- return {
566
- value: undefined$1,
567
- done: true
568
- };
569
- }
570
- Context.prototype = {
571
- constructor: Context,
572
- reset: function reset(skipTempReset) {
573
- this.prev = 0;
574
- this.next = 0;
575
- // Resetting context._sent for legacy support of Babel's
576
- // function.sent implementation.
577
- this.sent = this._sent = undefined$1;
578
- this.done = false;
579
- this.delegate = null;
580
- this.method = "next";
581
- this.arg = undefined$1;
582
- this.tryEntries.forEach(resetTryEntry);
583
- if (!skipTempReset) {
584
- for (var name in this) {
585
- // Not sure about the optimal order of these conditions:
586
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
587
- this[name] = undefined$1;
588
- }
589
- }
590
- }
591
- },
592
- stop: function stop() {
593
- this.done = true;
594
- var rootEntry = this.tryEntries[0];
595
- var rootRecord = rootEntry.completion;
596
- if (rootRecord.type === "throw") {
597
- throw rootRecord.arg;
598
- }
599
- return this.rval;
600
- },
601
- dispatchException: function dispatchException(exception) {
602
- if (this.done) {
603
- throw exception;
604
- }
605
- var context = this;
606
- function handle(loc, caught) {
607
- record.type = "throw";
608
- record.arg = exception;
609
- context.next = loc;
610
- if (caught) {
611
- // If the dispatched exception was caught by a catch block,
612
- // then let that catch block handle the exception normally.
613
- context.method = "next";
614
- context.arg = undefined$1;
615
- }
616
- return !!caught;
617
- }
618
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
619
- var entry = this.tryEntries[i];
620
- var record = entry.completion;
621
- if (entry.tryLoc === "root") {
622
- // Exception thrown outside of any try block that could handle
623
- // it, so set the completion value of the entire function to
624
- // throw the exception.
625
- return handle("end");
626
- }
627
- if (entry.tryLoc <= this.prev) {
628
- var hasCatch = hasOwn.call(entry, "catchLoc");
629
- var hasFinally = hasOwn.call(entry, "finallyLoc");
630
- if (hasCatch && hasFinally) {
631
- if (this.prev < entry.catchLoc) {
632
- return handle(entry.catchLoc, true);
633
- } else if (this.prev < entry.finallyLoc) {
634
- return handle(entry.finallyLoc);
635
- }
636
- } else if (hasCatch) {
637
- if (this.prev < entry.catchLoc) {
638
- return handle(entry.catchLoc, true);
639
- }
640
- } else if (hasFinally) {
641
- if (this.prev < entry.finallyLoc) {
642
- return handle(entry.finallyLoc);
643
- }
644
- } else {
645
- throw new Error("try statement without catch or finally");
646
- }
647
- }
648
- }
649
- },
650
- abrupt: function abrupt(type, arg) {
651
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
652
- var entry = this.tryEntries[i];
653
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
654
- var finallyEntry = entry;
655
- break;
656
- }
657
- }
658
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
659
- // Ignore the finally entry if control is not jumping to a
660
- // location outside the try/catch block.
661
- finallyEntry = null;
662
- }
663
- var record = finallyEntry ? finallyEntry.completion : {};
664
- record.type = type;
665
- record.arg = arg;
666
- if (finallyEntry) {
667
- this.method = "next";
668
- this.next = finallyEntry.finallyLoc;
669
- return ContinueSentinel;
670
- }
671
- return this.complete(record);
672
- },
673
- complete: function complete(record, afterLoc) {
674
- if (record.type === "throw") {
675
- throw record.arg;
676
- }
677
- if (record.type === "break" || record.type === "continue") {
678
- this.next = record.arg;
679
- } else if (record.type === "return") {
680
- this.rval = this.arg = record.arg;
681
- this.method = "return";
682
- this.next = "end";
683
- } else if (record.type === "normal" && afterLoc) {
684
- this.next = afterLoc;
685
- }
686
- return ContinueSentinel;
687
- },
688
- finish: function finish(finallyLoc) {
689
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
690
- var entry = this.tryEntries[i];
691
- if (entry.finallyLoc === finallyLoc) {
692
- this.complete(entry.completion, entry.afterLoc);
693
- resetTryEntry(entry);
694
- return ContinueSentinel;
695
- }
696
- }
697
- },
698
- "catch": function _catch(tryLoc) {
699
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
700
- var entry = this.tryEntries[i];
701
- if (entry.tryLoc === tryLoc) {
702
- var record = entry.completion;
703
- if (record.type === "throw") {
704
- var thrown = record.arg;
705
- resetTryEntry(entry);
706
- }
707
- return thrown;
708
- }
709
- }
710
-
711
- // The context.catch method must only be called with a location
712
- // argument that corresponds to a known catch block.
713
- throw new Error("illegal catch attempt");
714
- },
715
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
716
- this.delegate = {
717
- iterator: values(iterable),
718
- resultName: resultName,
719
- nextLoc: nextLoc
720
- };
721
- if (this.method === "next") {
722
- // Deliberately forget the last sent value so that we don't
723
- // accidentally pass it on to the delegate.
724
- this.arg = undefined$1;
725
- }
726
- return ContinueSentinel;
727
- }
728
- };
729
-
730
- // Regardless of whether this script is executing as a CommonJS module
731
- // or not, return the runtime object so that we can declare the variable
732
- // regeneratorRuntime in the outer scope, which allows this module to be
733
- // injected easily by `bin/regenerator --include-runtime script.js`.
734
- return exports;
735
- }(
736
- // If this script is executing as a CommonJS module, use module.exports
737
- // as the regeneratorRuntime namespace. Otherwise create a new empty
738
- // object. Either way, the resulting object will be used to initialize
739
- // the regeneratorRuntime variable at the top of this file.
740
- module.exports );
741
- try {
742
- regeneratorRuntime = runtime;
743
- } catch (accidentalStrictMode) {
744
- // This module should not be running in strict mode, so the above
745
- // assignment should always work unless something is misconfigured. Just
746
- // in case runtime.js accidentally runs in strict mode, in modern engines
747
- // we can explicitly access globalThis. In older engines we can escape
748
- // strict mode using a global Function call. This could conceivably fail
749
- // if a Content Security Policy forbids using Function, but in that case
750
- // the proper solution is to fix the accidental strict mode problem. If
751
- // you've misconfigured your bundler to force strict mode and applied a
752
- // CSP to forbid Function, and you're not willing to fix either of those
753
- // problems, please detail your unique predicament in a GitHub issue.
754
- if (typeof globalThis === "object") {
755
- globalThis.regeneratorRuntime = runtime;
756
- } else {
757
- Function("r", "regeneratorRuntime = r")(runtime);
758
- }
759
- }
760
- });
761
-
762
405
  var _excluded = ["file"];
763
406
  var normalizeProductOption = function normalizeProductOption(_ref2) {
764
407
  var id = _ref2.id,
@@ -977,36 +620,32 @@ function normalizeCategory(_ref7) {
977
620
  };
978
621
  }
979
622
 
980
- var handleFetchResponse = /*#__PURE__*/function () {
981
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(res) {
982
- return runtime_1.wrap(function _callee$(_context) {
983
- while (1) {
984
- switch (_context.prev = _context.next) {
985
- case 0:
986
- if (!res) {
987
- _context.next = 4;
988
- break;
989
- }
990
- if (!res.error) {
991
- _context.next = 3;
992
- break;
993
- }
994
- throw new CommerceError(res.error);
995
- case 3:
996
- return _context.abrupt("return", res);
997
- case 4:
998
- return _context.abrupt("return", null);
999
- case 5:
1000
- case "end":
1001
- return _context.stop();
1002
- }
623
+ var _ref;
624
+ var handleFetchResponse = function handleFetchResponse(_x) {
625
+ return (_ref = _ref || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
626
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
627
+ while (1) switch (_context.prev = _context.next) {
628
+ case 0:
629
+ if (!res) {
630
+ _context.next = 4;
631
+ break;
632
+ }
633
+ if (!res.error) {
634
+ _context.next = 3;
635
+ break;
636
+ }
637
+ throw new CommerceError(res.error);
638
+ case 3:
639
+ return _context.abrupt("return", res);
640
+ case 4:
641
+ return _context.abrupt("return", null);
642
+ case 5:
643
+ case "end":
644
+ return _context.stop();
1003
645
  }
1004
646
  }, _callee);
1005
- }));
1006
- return function handleFetchResponse(_x) {
1007
- return _ref.apply(this, arguments);
1008
- };
1009
- }();
647
+ }))).apply(this, arguments);
648
+ };
1010
649
 
1011
650
  /*
1012
651
  Forked from https://github.com/vercel/commerce/tree/main/packages/swell/src
@@ -1029,52 +668,48 @@ var checkoutToCart = function checkoutToCart(checkoutPayload) {
1029
668
  return normalizeCart(checkoutPayload);
1030
669
  };
1031
670
 
1032
- var checkoutCreate = /*#__PURE__*/function () {
1033
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(fetch) {
671
+ var _ref$1;
672
+ var checkoutCreate = function checkoutCreate(_x) {
673
+ return (_ref$1 = _ref$1 || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(fetch) {
1034
674
  var cart, checkoutUrl, options;
1035
- return runtime_1.wrap(function _callee$(_context) {
1036
- while (1) {
1037
- switch (_context.prev = _context.next) {
1038
- case 0:
1039
- _context.next = 2;
1040
- return fetch({
1041
- query: 'cart',
1042
- method: 'get'
1043
- });
1044
- case 2:
1045
- cart = _context.sent;
1046
- if (cart) {
1047
- _context.next = 6;
1048
- break;
1049
- }
675
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
676
+ while (1) switch (_context.prev = _context.next) {
677
+ case 0:
678
+ _context.next = 2;
679
+ return fetch({
680
+ query: 'cart',
681
+ method: 'get'
682
+ });
683
+ case 2:
684
+ cart = _context.sent;
685
+ if (cart) {
1050
686
  _context.next = 6;
1051
- return fetch({
1052
- query: 'cart',
1053
- method: 'setItems',
1054
- variables: [[]]
1055
- });
1056
- case 6:
1057
- checkoutUrl = cart == null ? void 0 : cart.checkout_url;
1058
- options = {
1059
- expires: SWELL_COOKIE_EXPIRE,
1060
- sameSite: "none",
1061
- secure: true
1062
- };
1063
- if (checkoutUrl) {
1064
- Cookies.set(SWELL_CHECKOUT_URL_COOKIE, checkoutUrl, options);
1065
- }
1066
- return _context.abrupt("return", cart);
1067
- case 10:
1068
- case "end":
1069
- return _context.stop();
1070
- }
687
+ break;
688
+ }
689
+ _context.next = 6;
690
+ return fetch({
691
+ query: 'cart',
692
+ method: 'setItems',
693
+ variables: [[]]
694
+ });
695
+ case 6:
696
+ checkoutUrl = cart == null ? void 0 : cart.checkout_url;
697
+ options = {
698
+ expires: SWELL_COOKIE_EXPIRE,
699
+ sameSite: "none",
700
+ secure: true
701
+ };
702
+ if (checkoutUrl) {
703
+ Cookies.set(SWELL_CHECKOUT_URL_COOKIE, checkoutUrl, options);
704
+ }
705
+ return _context.abrupt("return", cart);
706
+ case 10:
707
+ case "end":
708
+ return _context.stop();
1071
709
  }
1072
710
  }, _callee);
1073
- }));
1074
- return function checkoutCreate(_x) {
1075
- return _ref.apply(this, arguments);
1076
- };
1077
- }();
711
+ }))).apply(this, arguments);
712
+ };
1078
713
 
1079
714
  var handler = {
1080
715
  fetchOptions: {
@@ -1082,22 +717,20 @@ var handler = {
1082
717
  method: 'get'
1083
718
  },
1084
719
  fetcher: function fetcher(_ref) {
1085
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
720
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1086
721
  var fetch, cart;
1087
- return runtime_1.wrap(function _callee$(_context) {
1088
- while (1) {
1089
- switch (_context.prev = _context.next) {
1090
- case 0:
1091
- fetch = _ref.fetch;
1092
- _context.next = 3;
1093
- return checkoutCreate(fetch);
1094
- case 3:
1095
- cart = _context.sent;
1096
- return _context.abrupt("return", cart ? normalizeCart(cart) : null);
1097
- case 5:
1098
- case "end":
1099
- return _context.stop();
1100
- }
722
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
723
+ while (1) switch (_context.prev = _context.next) {
724
+ case 0:
725
+ fetch = _ref.fetch;
726
+ _context.next = 3;
727
+ return checkoutCreate(fetch);
728
+ case 3:
729
+ cart = _context.sent;
730
+ return _context.abrupt("return", cart ? normalizeCart(cart) : null);
731
+ case 5:
732
+ case "end":
733
+ return _context.stop();
1101
734
  }
1102
735
  }, _callee);
1103
736
  }))();
@@ -1131,40 +764,38 @@ var handler$1 = {
1131
764
  method: 'addItem'
1132
765
  },
1133
766
  fetcher: function fetcher(_ref) {
1134
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
767
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1135
768
  var item, options, fetch, variables, response;
1136
- return runtime_1.wrap(function _callee$(_context) {
1137
- while (1) {
1138
- switch (_context.prev = _context.next) {
1139
- case 0:
1140
- item = _ref.input, options = _ref.options, fetch = _ref.fetch;
1141
- if (!(item.quantity && (!Number.isInteger(item.quantity) || item.quantity < 1))) {
1142
- _context.next = 3;
1143
- break;
1144
- }
1145
- throw new CommerceError({
1146
- message: 'The item quantity has to be a valid integer greater than 0'
1147
- });
1148
- case 3:
1149
- variables = {
1150
- checkoutId: getCheckoutId(),
1151
- product_id: item.productId,
1152
- quantity: item.quantity
1153
- };
1154
- if (item.productId !== item.variantId) {
1155
- variables.variant_id = item.variantId;
1156
- }
1157
- _context.next = 7;
1158
- return fetch(_extends({}, options, {
1159
- variables: variables
1160
- }));
1161
- case 7:
1162
- response = _context.sent;
1163
- return _context.abrupt("return", checkoutToCart(response));
1164
- case 9:
1165
- case "end":
1166
- return _context.stop();
1167
- }
769
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
770
+ while (1) switch (_context.prev = _context.next) {
771
+ case 0:
772
+ item = _ref.input, options = _ref.options, fetch = _ref.fetch;
773
+ if (!(item.quantity && (!Number.isInteger(item.quantity) || item.quantity < 1))) {
774
+ _context.next = 3;
775
+ break;
776
+ }
777
+ throw new CommerceError({
778
+ message: 'The item quantity has to be a valid integer greater than 0'
779
+ });
780
+ case 3:
781
+ variables = {
782
+ checkoutId: getCheckoutId(),
783
+ product_id: item.productId,
784
+ quantity: item.quantity
785
+ };
786
+ if (item.productId !== item.variantId) {
787
+ variables.variant_id = item.variantId;
788
+ }
789
+ _context.next = 7;
790
+ return fetch(_extends({}, options, {
791
+ variables: variables
792
+ }));
793
+ case 7:
794
+ response = _context.sent;
795
+ return _context.abrupt("return", checkoutToCart(response));
796
+ case 9:
797
+ case "end":
798
+ return _context.stop();
1168
799
  }
1169
800
  }, _callee);
1170
801
  }))();
@@ -1172,37 +803,32 @@ var handler$1 = {
1172
803
  useHook: function useHook(_ref2) {
1173
804
  var fetch = _ref2.fetch;
1174
805
  return function () {
806
+ var _addItem;
1175
807
  var _useCart = useCart(),
1176
808
  mutate = _useCart.mutate;
1177
- return useCallback( /*#__PURE__*/function () {
1178
- var _addItem = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
809
+ return useCallback(function addItem(_x) {
810
+ return (_addItem = _addItem || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
1179
811
  var data;
1180
- return runtime_1.wrap(function _callee2$(_context2) {
1181
- while (1) {
1182
- switch (_context2.prev = _context2.next) {
1183
- case 0:
1184
- _context2.next = 2;
1185
- return fetch({
1186
- input: input
1187
- });
1188
- case 2:
1189
- data = _context2.sent;
1190
- _context2.next = 5;
1191
- return mutate(data, false);
1192
- case 5:
1193
- return _context2.abrupt("return", data);
1194
- case 6:
1195
- case "end":
1196
- return _context2.stop();
1197
- }
812
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
813
+ while (1) switch (_context2.prev = _context2.next) {
814
+ case 0:
815
+ _context2.next = 2;
816
+ return fetch({
817
+ input: input
818
+ });
819
+ case 2:
820
+ data = _context2.sent;
821
+ _context2.next = 5;
822
+ return mutate(data, false);
823
+ case 5:
824
+ return _context2.abrupt("return", data);
825
+ case 6:
826
+ case "end":
827
+ return _context2.stop();
1198
828
  }
1199
829
  }, _callee2);
1200
- }));
1201
- function addItem(_x) {
1202
- return _addItem.apply(this, arguments);
1203
- }
1204
- return addItem;
1205
- }(), [fetch, mutate]);
830
+ }))).apply(this, arguments);
831
+ }, [fetch, mutate]);
1206
832
  };
1207
833
  }
1208
834
  };
@@ -1213,24 +839,22 @@ var handler$2 = {
1213
839
  method: "removeItem"
1214
840
  },
1215
841
  fetcher: function fetcher(_ref) {
1216
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
842
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1217
843
  var itemId, options, fetch, response;
1218
- return runtime_1.wrap(function _callee$(_context) {
1219
- while (1) {
1220
- switch (_context.prev = _context.next) {
1221
- case 0:
1222
- itemId = _ref.input.itemId, options = _ref.options, fetch = _ref.fetch;
1223
- _context.next = 3;
1224
- return fetch(_extends({}, options, {
1225
- variables: [itemId]
1226
- }));
1227
- case 3:
1228
- response = _context.sent;
1229
- return _context.abrupt("return", checkoutToCart(response));
1230
- case 5:
1231
- case "end":
1232
- return _context.stop();
1233
- }
844
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
845
+ while (1) switch (_context.prev = _context.next) {
846
+ case 0:
847
+ itemId = _ref.input.itemId, options = _ref.options, fetch = _ref.fetch;
848
+ _context.next = 3;
849
+ return fetch(_extends({}, options, {
850
+ variables: [itemId]
851
+ }));
852
+ case 3:
853
+ response = _context.sent;
854
+ return _context.abrupt("return", checkoutToCart(response));
855
+ case 5:
856
+ case "end":
857
+ return _context.stop();
1234
858
  }
1235
859
  }, _callee);
1236
860
  }))();
@@ -1238,39 +862,34 @@ var handler$2 = {
1238
862
  useHook: function useHook(_ref2) {
1239
863
  var fetch = _ref2.fetch;
1240
864
  return function () {
865
+ var _removeItem;
1241
866
  var _useCart = useCart(),
1242
867
  mutate = _useCart.mutate;
1243
- return useCallback( /*#__PURE__*/function () {
1244
- var _removeItem = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
868
+ return useCallback(function removeItem(_x) {
869
+ return (_removeItem = _removeItem || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
1245
870
  var data;
1246
- return runtime_1.wrap(function _callee2$(_context2) {
1247
- while (1) {
1248
- switch (_context2.prev = _context2.next) {
1249
- case 0:
1250
- _context2.next = 2;
1251
- return fetch({
1252
- input: {
1253
- itemId: input.id
1254
- }
1255
- });
1256
- case 2:
1257
- data = _context2.sent;
1258
- _context2.next = 5;
1259
- return mutate(data, false);
1260
- case 5:
1261
- return _context2.abrupt("return", data);
1262
- case 6:
1263
- case "end":
1264
- return _context2.stop();
1265
- }
871
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
872
+ while (1) switch (_context2.prev = _context2.next) {
873
+ case 0:
874
+ _context2.next = 2;
875
+ return fetch({
876
+ input: {
877
+ itemId: input.id
878
+ }
879
+ });
880
+ case 2:
881
+ data = _context2.sent;
882
+ _context2.next = 5;
883
+ return mutate(data, false);
884
+ case 5:
885
+ return _context2.abrupt("return", data);
886
+ case 6:
887
+ case "end":
888
+ return _context2.stop();
1266
889
  }
1267
890
  }, _callee2);
1268
- }));
1269
- function removeItem(_x) {
1270
- return _removeItem.apply(this, arguments);
1271
- }
1272
- return removeItem;
1273
- }(), [fetch, mutate]);
891
+ }))).apply(this, arguments);
892
+ }, [fetch, mutate]);
1274
893
  };
1275
894
  }
1276
895
  };
@@ -1281,53 +900,51 @@ var handler$3 = {
1281
900
  method: "updateItem"
1282
901
  },
1283
902
  fetcher: function fetcher(_ref) {
1284
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
903
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1285
904
  var _ref$input, itemId, item, options, fetch, response;
1286
- return runtime_1.wrap(function _callee$(_context) {
1287
- while (1) {
1288
- switch (_context.prev = _context.next) {
1289
- case 0:
1290
- _ref$input = _ref.input, itemId = _ref$input.itemId, item = _ref$input.item, options = _ref.options, fetch = _ref.fetch;
1291
- if (!Number.isInteger(item.quantity)) {
1292
- _context.next = 6;
1293
- break;
1294
- }
1295
- if (!(item.quantity < 1)) {
1296
- _context.next = 4;
1297
- break;
1298
- }
1299
- return _context.abrupt("return", handler$2.fetcher({
1300
- options: handler$2.fetchOptions,
1301
- input: {
1302
- itemId: itemId
1303
- },
1304
- fetch: fetch
1305
- }));
1306
- case 4:
905
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
906
+ while (1) switch (_context.prev = _context.next) {
907
+ case 0:
908
+ _ref$input = _ref.input, itemId = _ref$input.itemId, item = _ref$input.item, options = _ref.options, fetch = _ref.fetch;
909
+ if (!Number.isInteger(item.quantity)) {
910
+ _context.next = 6;
911
+ break;
912
+ }
913
+ if (!(item.quantity < 1)) {
914
+ _context.next = 4;
915
+ break;
916
+ }
917
+ return _context.abrupt("return", handler$2.fetcher({
918
+ options: handler$2.fetchOptions,
919
+ input: {
920
+ itemId: itemId
921
+ },
922
+ fetch: fetch
923
+ }));
924
+ case 4:
925
+ _context.next = 8;
926
+ break;
927
+ case 6:
928
+ if (!item.quantity) {
1307
929
  _context.next = 8;
1308
930
  break;
1309
- case 6:
1310
- if (!item.quantity) {
1311
- _context.next = 8;
1312
- break;
1313
- }
1314
- throw new ValidationError({
1315
- message: "The item quantity has to be a valid integer"
1316
- });
1317
- case 8:
1318
- _context.next = 10;
1319
- return fetch(_extends({}, options, {
1320
- variables: [itemId, {
1321
- quantity: item.quantity
1322
- }]
1323
- }));
1324
- case 10:
1325
- response = _context.sent;
1326
- return _context.abrupt("return", checkoutToCart(response));
1327
- case 12:
1328
- case "end":
1329
- return _context.stop();
1330
- }
931
+ }
932
+ throw new ValidationError({
933
+ message: "The item quantity has to be a valid integer"
934
+ });
935
+ case 8:
936
+ _context.next = 10;
937
+ return fetch(_extends({}, options, {
938
+ variables: [itemId, {
939
+ quantity: item.quantity
940
+ }]
941
+ }));
942
+ case 10:
943
+ response = _context.sent;
944
+ return _context.abrupt("return", checkoutToCart(response));
945
+ case 12:
946
+ case "end":
947
+ return _context.stop();
1331
948
  }
1332
949
  }, _callee);
1333
950
  }))();
@@ -1335,7 +952,7 @@ var handler$3 = {
1335
952
  useHook: function useHook(_ref2) {
1336
953
  var fetch = _ref2.fetch;
1337
954
  return function (ctx) {
1338
- var _ctx$wait;
955
+ var _ref3, _ctx$wait;
1339
956
  if (ctx === void 0) {
1340
957
  ctx = {};
1341
958
  }
@@ -1343,49 +960,44 @@ var handler$3 = {
1343
960
  item = _ctx.item;
1344
961
  var _useCart = useCart(),
1345
962
  mutate = _useCart.mutate;
1346
- return useCallback(debounce( /*#__PURE__*/function () {
1347
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(input) {
963
+ return useCallback(debounce(function (_x) {
964
+ return (_ref3 = _ref3 || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input) {
1348
965
  var _input$id;
1349
966
  var itemId, data;
1350
- return runtime_1.wrap(function _callee2$(_context2) {
1351
- while (1) {
1352
- switch (_context2.prev = _context2.next) {
1353
- case 0:
1354
- itemId = (_input$id = input.id) != null ? _input$id : item == null ? void 0 : item.id;
1355
- if (itemId) {
1356
- _context2.next = 3;
1357
- break;
967
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
968
+ while (1) switch (_context2.prev = _context2.next) {
969
+ case 0:
970
+ itemId = (_input$id = input.id) != null ? _input$id : item == null ? void 0 : item.id;
971
+ if (itemId) {
972
+ _context2.next = 3;
973
+ break;
974
+ }
975
+ throw new ValidationError({
976
+ message: "Invalid input used for this operation"
977
+ });
978
+ case 3:
979
+ _context2.next = 5;
980
+ return fetch({
981
+ input: {
982
+ item: {
983
+ quantity: input.quantity
984
+ },
985
+ itemId: itemId
1358
986
  }
1359
- throw new ValidationError({
1360
- message: "Invalid input used for this operation"
1361
- });
1362
- case 3:
1363
- _context2.next = 5;
1364
- return fetch({
1365
- input: {
1366
- item: {
1367
- quantity: input.quantity
1368
- },
1369
- itemId: itemId
1370
- }
1371
- });
1372
- case 5:
1373
- data = _context2.sent;
1374
- _context2.next = 8;
1375
- return mutate(data, false);
1376
- case 8:
1377
- return _context2.abrupt("return", data);
1378
- case 9:
1379
- case "end":
1380
- return _context2.stop();
1381
- }
987
+ });
988
+ case 5:
989
+ data = _context2.sent;
990
+ _context2.next = 8;
991
+ return mutate(data, false);
992
+ case 8:
993
+ return _context2.abrupt("return", data);
994
+ case 9:
995
+ case "end":
996
+ return _context2.stop();
1382
997
  }
1383
998
  }, _callee2);
1384
- }));
1385
- return function (_x) {
1386
- return _ref3.apply(this, arguments);
1387
- };
1388
- }(), (_ctx$wait = ctx.wait) != null ? _ctx$wait : 500), [fetch, mutate]);
999
+ }))).apply(this, arguments);
1000
+ }, (_ctx$wait = ctx.wait) != null ? _ctx$wait : 500), [fetch, mutate]);
1389
1001
  };
1390
1002
  }
1391
1003
  };
@@ -1440,50 +1052,48 @@ var handler$4 = {
1440
1052
  method: "list"
1441
1053
  },
1442
1054
  fetcher: function fetcher(_ref) {
1443
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1055
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1444
1056
  var input, options, fetch, sortMap, categoryId, includeSubCategories, categories, brandId, search, _input$sort, sort, count, mappedSort, includedCategories, _yield$fetch, products;
1445
- return runtime_1.wrap(function _callee$(_context) {
1446
- while (1) {
1447
- switch (_context.prev = _context.next) {
1448
- case 0:
1449
- input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1450
- sortMap = new Map([["latest-desc", ""], ["price-asc", "price asc"], ["price-desc", "price desc"], ["trending-desc", "popularity"]]);
1451
- categoryId = input.categoryId, includeSubCategories = input.includeSubCategories, categories = input.categories, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? "latest-desc" : _input$sort, count = input.count;
1452
- mappedSort = sortMap.get(sort);
1453
- includedCategories = includeSubCategories ? walkCategoryTree(categories == null ? void 0 : categories.find(function (category) {
1454
- return category.id === categoryId;
1455
- }), categories) : undefined;
1456
- _context.next = 7;
1457
- return fetch({
1458
- query: options.query,
1459
- method: options.method,
1460
- variables: ensureNoNilFields({
1461
- category: !includeSubCategories ? categoryId : undefined,
1462
- brand: brandId,
1463
- search: search,
1464
- sort: mappedSort,
1465
- expand: ["variants"],
1466
- limit: count,
1467
- $filters: _extends({}, includeSubCategories ? {
1468
- category: includedCategories == null ? void 0 : includedCategories.map(function (c) {
1469
- return c.id;
1470
- })
1471
- } : {})
1472
- })
1473
- });
1474
- case 7:
1475
- _yield$fetch = _context.sent;
1476
- products = _yield$fetch.results;
1477
- return _context.abrupt("return", {
1478
- products: products.map(function (product) {
1479
- return normalizeProduct(product);
1480
- }),
1481
- found: products.length > 0
1482
- });
1483
- case 10:
1484
- case "end":
1485
- return _context.stop();
1486
- }
1057
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1058
+ while (1) switch (_context.prev = _context.next) {
1059
+ case 0:
1060
+ input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1061
+ sortMap = new Map([["latest-desc", ""], ["price-asc", "price asc"], ["price-desc", "price desc"], ["trending-desc", "popularity"]]);
1062
+ categoryId = input.categoryId, includeSubCategories = input.includeSubCategories, categories = input.categories, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? "latest-desc" : _input$sort, count = input.count;
1063
+ mappedSort = sortMap.get(sort);
1064
+ includedCategories = includeSubCategories ? walkCategoryTree(categories == null ? void 0 : categories.find(function (category) {
1065
+ return category.id === categoryId;
1066
+ }), categories) : undefined;
1067
+ _context.next = 7;
1068
+ return fetch({
1069
+ query: options.query,
1070
+ method: options.method,
1071
+ variables: ensureNoNilFields({
1072
+ category: !includeSubCategories ? categoryId : undefined,
1073
+ brand: brandId,
1074
+ search: search,
1075
+ sort: mappedSort,
1076
+ expand: ["variants"],
1077
+ limit: count,
1078
+ $filters: _extends({}, includeSubCategories ? {
1079
+ category: includedCategories == null ? void 0 : includedCategories.map(function (c) {
1080
+ return c.id;
1081
+ })
1082
+ } : {})
1083
+ })
1084
+ });
1085
+ case 7:
1086
+ _yield$fetch = _context.sent;
1087
+ products = _yield$fetch.results;
1088
+ return _context.abrupt("return", {
1089
+ products: products.map(function (product) {
1090
+ return normalizeProduct(product);
1091
+ }),
1092
+ found: products.length > 0
1093
+ });
1094
+ case 10:
1095
+ case "end":
1096
+ return _context.stop();
1487
1097
  }
1488
1098
  }, _callee);
1489
1099
  }))();
@@ -1510,33 +1120,31 @@ var handler$5 = {
1510
1120
  method: 'get'
1511
1121
  },
1512
1122
  fetcher: function fetcher(_ref) {
1513
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1123
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1514
1124
  var input, options, fetch, id, product;
1515
- return runtime_1.wrap(function _callee$(_context) {
1516
- while (1) {
1517
- switch (_context.prev = _context.next) {
1518
- case 0:
1519
- input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1520
- id = input.id;
1521
- _context.next = 4;
1522
- return fetch({
1523
- query: options.query,
1524
- method: options.method,
1525
- variables: [id]
1526
- });
1527
- case 4:
1528
- product = _context.sent;
1529
- if (product) {
1530
- _context.next = 7;
1531
- break;
1532
- }
1533
- return _context.abrupt("return", null);
1534
- case 7:
1535
- return _context.abrupt("return", normalizeProduct(product));
1536
- case 8:
1537
- case "end":
1538
- return _context.stop();
1539
- }
1125
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1126
+ while (1) switch (_context.prev = _context.next) {
1127
+ case 0:
1128
+ input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1129
+ id = input.id;
1130
+ _context.next = 4;
1131
+ return fetch({
1132
+ query: options.query,
1133
+ method: options.method,
1134
+ variables: [id]
1135
+ });
1136
+ case 4:
1137
+ product = _context.sent;
1138
+ if (product) {
1139
+ _context.next = 7;
1140
+ break;
1141
+ }
1142
+ return _context.abrupt("return", null);
1143
+ case 7:
1144
+ return _context.abrupt("return", normalizeProduct(product));
1145
+ case 8:
1146
+ case "end":
1147
+ return _context.stop();
1540
1148
  }
1541
1149
  }, _callee);
1542
1150
  }))();
@@ -1563,86 +1171,96 @@ var handler$6 = {
1563
1171
  method: "get"
1564
1172
  },
1565
1173
  fetcher: function fetcher(_ref) {
1566
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1174
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1567
1175
  var _data$results;
1568
- var input, options, fetch, addIsEmptyField, categoryId, data, categories, normalizedCategories, _loop, _iterator, _step;
1569
- return runtime_1.wrap(function _callee2$(_context2) {
1570
- while (1) {
1571
- switch (_context2.prev = _context2.next) {
1572
- case 0:
1573
- input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1574
- addIsEmptyField = input.addIsEmptyField, categoryId = input.categoryId;
1575
- _context2.next = 4;
1576
- return fetch({
1577
- query: options.query,
1578
- method: options.method,
1579
- variables: ensureNoNilFields({
1580
- expand: ["children", "parent_id"],
1581
- id: categoryId
1582
- })
1583
- });
1584
- case 4:
1585
- data = _context2.sent;
1586
- categories = (_data$results = data == null ? void 0 : data.results) != null ? _data$results : [];
1587
- if (!addIsEmptyField) {
1588
- _context2.next = 10;
1589
- break;
1590
- }
1591
- _context2.next = 9;
1592
- return Promise.all(categories.map( /*#__PURE__*/function () {
1593
- var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(category) {
1594
- return runtime_1.wrap(function _callee$(_context) {
1595
- while (1) {
1596
- switch (_context.prev = _context.next) {
1597
- case 0:
1598
- _context.t0 = _extends;
1599
- _context.t1 = {};
1600
- _context.t2 = category;
1601
- _context.next = 5;
1602
- return fetch({
1603
- query: "products",
1604
- method: "list",
1605
- variables: ensureNoNilFields({
1606
- limit: 1,
1607
- category: category.id
1608
- })
1609
- });
1610
- case 5:
1611
- _context.t3 = _context.sent.results;
1612
- _context.t4 = {
1613
- products: _context.t3
1614
- };
1615
- return _context.abrupt("return", (0, _context.t0)(_context.t1, _context.t2, _context.t4));
1616
- case 8:
1617
- case "end":
1618
- return _context.stop();
1619
- }
1620
- }
1621
- }, _callee);
1622
- }));
1623
- return function (_x) {
1624
- return _ref2.apply(this, arguments);
1625
- };
1626
- }()));
1627
- case 9:
1628
- categories = _context2.sent;
1629
- case 10:
1630
- normalizedCategories = !categoryId ? topologicalSortForCategoryTree(categories.map(normalizeCategory)) : categories.map(normalizeCategory);
1631
- _loop = function _loop() {
1632
- var _normalizedCategories, _normalizedCategories2;
1633
- var category = _step.value;
1634
- category.depth = ((_normalizedCategories = (_normalizedCategories2 = normalizedCategories.find(function (c) {
1635
- return c.id === category.parentId;
1636
- })) == null ? void 0 : _normalizedCategories2.depth) != null ? _normalizedCategories : -1) + 1;
1637
- };
1638
- for (_iterator = _createForOfIteratorHelperLoose(normalizedCategories); !(_step = _iterator()).done;) {
1639
- _loop();
1640
- }
1641
- return _context2.abrupt("return", normalizedCategories);
1642
- case 14:
1643
- case "end":
1644
- return _context2.stop();
1645
- }
1176
+ var input, options, fetch, addIsEmptyField, categoryId, data, categories, _ref2, normalizedCategories, _loop, _iterator, _step;
1177
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
1178
+ while (1) switch (_context3.prev = _context3.next) {
1179
+ case 0:
1180
+ input = _ref.input, options = _ref.options, fetch = _ref.fetch;
1181
+ addIsEmptyField = input.addIsEmptyField, categoryId = input.categoryId;
1182
+ _context3.next = 4;
1183
+ return fetch({
1184
+ query: options.query,
1185
+ method: options.method,
1186
+ variables: ensureNoNilFields({
1187
+ expand: ["children", "parent_id"],
1188
+ id: categoryId
1189
+ })
1190
+ });
1191
+ case 4:
1192
+ data = _context3.sent;
1193
+ categories = (_data$results = data == null ? void 0 : data.results) != null ? _data$results : [];
1194
+ if (!addIsEmptyField) {
1195
+ _context3.next = 10;
1196
+ break;
1197
+ }
1198
+ _context3.next = 9;
1199
+ return Promise.all(categories.map(function (_x) {
1200
+ return (_ref2 = _ref2 || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(category) {
1201
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1202
+ while (1) switch (_context.prev = _context.next) {
1203
+ case 0:
1204
+ _context.t0 = _extends;
1205
+ _context.t1 = {};
1206
+ _context.t2 = category;
1207
+ _context.next = 5;
1208
+ return fetch({
1209
+ query: "products",
1210
+ method: "list",
1211
+ variables: ensureNoNilFields({
1212
+ limit: 1,
1213
+ category: category.id
1214
+ })
1215
+ });
1216
+ case 5:
1217
+ _context.t3 = _context.sent.results;
1218
+ _context.t4 = {
1219
+ products: _context.t3
1220
+ };
1221
+ return _context.abrupt("return", (0, _context.t0)(_context.t1, _context.t2, _context.t4));
1222
+ case 8:
1223
+ case "end":
1224
+ return _context.stop();
1225
+ }
1226
+ }, _callee);
1227
+ }))).apply(this, arguments);
1228
+ }));
1229
+ case 9:
1230
+ categories = _context3.sent;
1231
+ case 10:
1232
+ normalizedCategories = !categoryId ? topologicalSortForCategoryTree(categories.map(normalizeCategory)) : categories.map(normalizeCategory);
1233
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1234
+ var _normalizedCategories, _normalizedCategories2;
1235
+ var category;
1236
+ return _regeneratorRuntime().wrap(function _loop$(_context2) {
1237
+ while (1) switch (_context2.prev = _context2.next) {
1238
+ case 0:
1239
+ category = _step.value;
1240
+ category.depth = ((_normalizedCategories = (_normalizedCategories2 = normalizedCategories.find(function (c) {
1241
+ return c.id === category.parentId;
1242
+ })) == null ? void 0 : _normalizedCategories2.depth) != null ? _normalizedCategories : -1) + 1;
1243
+ case 2:
1244
+ case "end":
1245
+ return _context2.stop();
1246
+ }
1247
+ }, _loop);
1248
+ });
1249
+ _iterator = _createForOfIteratorHelperLoose(normalizedCategories);
1250
+ case 13:
1251
+ if ((_step = _iterator()).done) {
1252
+ _context3.next = 17;
1253
+ break;
1254
+ }
1255
+ return _context3.delegateYield(_loop(), "t0", 15);
1256
+ case 15:
1257
+ _context3.next = 13;
1258
+ break;
1259
+ case 17:
1260
+ return _context3.abrupt("return", normalizedCategories);
1261
+ case 18:
1262
+ case "end":
1263
+ return _context3.stop();
1646
1264
  }
1647
1265
  }, _callee2);
1648
1266
  }))();
@@ -1677,55 +1295,53 @@ var handler$7 = {
1677
1295
  method: "get"
1678
1296
  },
1679
1297
  fetcher: function fetcher(_ref) {
1680
- return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1298
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1681
1299
  var _yield$fetch$values, _yield$fetch;
1682
1300
  var fetch, vendors;
1683
- return runtime_1.wrap(function _callee$(_context) {
1684
- while (1) {
1685
- switch (_context.prev = _context.next) {
1686
- case 0:
1687
- fetch = _ref.fetch;
1688
- _context.next = 3;
1689
- return fetch({
1690
- query: "attributes",
1691
- method: "get",
1692
- variables: "brand"
1693
- });
1694
- case 3:
1695
- _context.t0 = _yield$fetch = _context.sent;
1696
- if (!(_context.t0 == null)) {
1697
- _context.next = 8;
1698
- break;
1699
- }
1700
- _context.t1 = void 0;
1701
- _context.next = 9;
1301
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1302
+ while (1) switch (_context.prev = _context.next) {
1303
+ case 0:
1304
+ fetch = _ref.fetch;
1305
+ _context.next = 3;
1306
+ return fetch({
1307
+ query: "attributes",
1308
+ method: "get",
1309
+ variables: "brand"
1310
+ });
1311
+ case 3:
1312
+ _context.t0 = _yield$fetch = _context.sent;
1313
+ if (!(_context.t0 == null)) {
1314
+ _context.next = 8;
1702
1315
  break;
1703
- case 8:
1704
- _context.t1 = _yield$fetch.values;
1705
- case 9:
1706
- _context.t2 = _yield$fetch$values = _context.t1;
1707
- if (!(_context.t2 != null)) {
1708
- _context.next = 14;
1709
- break;
1710
- }
1711
- _context.t3 = _yield$fetch$values;
1712
- _context.next = 15;
1316
+ }
1317
+ _context.t1 = void 0;
1318
+ _context.next = 9;
1319
+ break;
1320
+ case 8:
1321
+ _context.t1 = _yield$fetch.values;
1322
+ case 9:
1323
+ _context.t2 = _yield$fetch$values = _context.t1;
1324
+ if (!(_context.t2 != null)) {
1325
+ _context.next = 14;
1713
1326
  break;
1714
- case 14:
1715
- _context.t3 = [];
1716
- case 15:
1717
- vendors = _context.t3;
1718
- return _context.abrupt("return", Array.from(new Set(vendors).values()).map(function (v) {
1719
- return {
1720
- entityId: v,
1721
- name: v,
1722
- path: "brands/" + v
1723
- };
1724
- }));
1725
- case 17:
1726
- case "end":
1727
- return _context.stop();
1728
- }
1327
+ }
1328
+ _context.t3 = _yield$fetch$values;
1329
+ _context.next = 15;
1330
+ break;
1331
+ case 14:
1332
+ _context.t3 = [];
1333
+ case 15:
1334
+ vendors = _context.t3;
1335
+ return _context.abrupt("return", Array.from(new Set(vendors).values()).map(function (v) {
1336
+ return {
1337
+ entityId: v,
1338
+ name: v,
1339
+ path: "brands/" + v
1340
+ };
1341
+ }));
1342
+ case 17:
1343
+ case "end":
1344
+ return _context.stop();
1729
1345
  }
1730
1346
  }, _callee);
1731
1347
  }))();
@@ -1753,82 +1369,73 @@ var handler$7 = {
1753
1369
  }
1754
1370
  };
1755
1371
 
1756
- var fetcher = /*#__PURE__*/function () {
1757
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref) {
1758
- var _ref$method, method, variables, query, callSwell, _callSwell;
1759
- return runtime_1.wrap(function _callee2$(_context2) {
1760
- while (1) {
1761
- switch (_context2.prev = _context2.next) {
1762
- case 0:
1763
- _callSwell = function _callSwell3() {
1764
- _callSwell = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1765
- var arg1, arg2, response, _response;
1766
- return runtime_1.wrap(function _callee$(_context) {
1767
- while (1) {
1768
- switch (_context.prev = _context.next) {
1769
- case 0:
1770
- if (!Array.isArray(variables)) {
1771
- _context.next = 9;
1772
- break;
1773
- }
1774
- arg1 = variables[0];
1775
- arg2 = variables[1];
1776
- _context.next = 5;
1777
- return swell[query][method](arg1, arg2);
1778
- case 5:
1779
- response = _context.sent;
1780
- return _context.abrupt("return", handleFetchResponse(response));
1781
- case 9:
1782
- _context.next = 11;
1783
- return swell[query][method](variables);
1784
- case 11:
1785
- _response = _context.sent;
1786
- return _context.abrupt("return", handleFetchResponse(_response));
1787
- case 13:
1788
- case "end":
1789
- return _context.stop();
1372
+ var _ref2;
1373
+ var fetcher = function fetcher(_x) {
1374
+ return (_ref2 = _ref2 || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
1375
+ var _callSwell;
1376
+ var _ref$method, method, variables, query, callSwell;
1377
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1378
+ while (1) switch (_context2.prev = _context2.next) {
1379
+ case 0:
1380
+ callSwell = function _callSwell2() {
1381
+ return (_callSwell = _callSwell || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1382
+ var arg1, arg2, response, _response;
1383
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1384
+ while (1) switch (_context.prev = _context.next) {
1385
+ case 0:
1386
+ if (!Array.isArray(variables)) {
1387
+ _context.next = 9;
1388
+ break;
1790
1389
  }
1791
- }
1792
- }, _callee);
1793
- }));
1794
- return _callSwell.apply(this, arguments);
1795
- };
1796
- callSwell = function _callSwell2() {
1797
- return _callSwell.apply(this, arguments);
1798
- };
1799
- _ref$method = _ref.method, method = _ref$method === void 0 ? 'get' : _ref$method, variables = _ref.variables, query = _ref.query;
1800
- if (!(query && query in swell)) {
1801
- _context2.next = 9;
1802
- break;
1803
- }
1804
- _context2.next = 6;
1805
- return callSwell();
1806
- case 6:
1807
- return _context2.abrupt("return", _context2.sent);
1808
- case 9:
1809
- throw new CommerceError({
1810
- message: 'Invalid query argument!'
1811
- });
1812
- case 10:
1813
- case "end":
1814
- return _context2.stop();
1815
- }
1390
+ arg1 = variables[0];
1391
+ arg2 = variables[1];
1392
+ _context.next = 5;
1393
+ return swell[query][method](arg1, arg2);
1394
+ case 5:
1395
+ response = _context.sent;
1396
+ return _context.abrupt("return", handleFetchResponse(response));
1397
+ case 9:
1398
+ _context.next = 11;
1399
+ return swell[query][method](variables);
1400
+ case 11:
1401
+ _response = _context.sent;
1402
+ return _context.abrupt("return", handleFetchResponse(_response));
1403
+ case 13:
1404
+ case "end":
1405
+ return _context.stop();
1406
+ }
1407
+ }, _callee);
1408
+ }))).apply(this, arguments);
1409
+ };
1410
+ _ref$method = _ref.method, method = _ref$method === void 0 ? 'get' : _ref$method, variables = _ref.variables, query = _ref.query;
1411
+ if (!(query && query in swell)) {
1412
+ _context2.next = 8;
1413
+ break;
1414
+ }
1415
+ _context2.next = 5;
1416
+ return callSwell();
1417
+ case 5:
1418
+ return _context2.abrupt("return", _context2.sent);
1419
+ case 8:
1420
+ throw new CommerceError({
1421
+ message: 'Invalid query argument!'
1422
+ });
1423
+ case 9:
1424
+ case "end":
1425
+ return _context2.stop();
1816
1426
  }
1817
1427
  }, _callee2);
1818
- }));
1819
- return function fetcher(_x) {
1820
- return _ref2.apply(this, arguments);
1821
- };
1822
- }();
1428
+ }))).apply(this, arguments);
1429
+ };
1823
1430
 
1824
1431
  /*
1825
1432
  Forked from https://github.com/vercel/commerce/tree/main/packages/swell/src
1826
1433
  Changes: Added storeId and publicKey parameters
1827
1434
  */
1828
1435
  var getSwellProvider = function getSwellProvider(storeId, publicKey) {
1829
- swell.init(storeId, publicKey);
1436
+ init(storeId, publicKey);
1830
1437
  return {
1831
- locale: 'en-us',
1438
+ locale: "en-us",
1832
1439
  cartCookie: SWELL_CHECKOUT_ID_COOKIE,
1833
1440
  swell: swell,
1834
1441
  fetcher: fetcher,