@plasmicpkgs/commerce 0.0.1 → 0.0.2

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