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