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