@plasmicpkgs/commerce-swell 0.0.1

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