@daouypkgs/commerce-saleor 0.0.197
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 +5 -0
- package/dist/cart/use-remove-item.d.ts +15 -0
- package/dist/cart/use-update-item.d.ts +27 -0
- package/dist/commerce-saleor.cjs.development.js +1284 -0
- package/dist/commerce-saleor.cjs.development.js.map +1 -0
- package/dist/commerce-saleor.cjs.production.min.js +2 -0
- package/dist/commerce-saleor.cjs.production.min.js.map +1 -0
- package/dist/commerce-saleor.esm.js +1273 -0
- package/dist/commerce-saleor.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-product.d.ts +9 -0
- package/dist/product/use-search.d.ts +16 -0
- package/dist/provider.d.ts +68 -0
- package/dist/registerCommerceProvider.d.ts +11 -0
- package/dist/registerable.d.ts +6 -0
- package/dist/saleor.d.ts +5 -0
- package/dist/site/use-brands.d.ts +5 -0
- package/dist/site/use-categories.d.ts +5 -0
- package/dist/types/cart.d.ts +22 -0
- package/dist/types/site.d.ts +7 -0
- package/dist/types.d.ts +24 -0
- package/dist/utils/checkout-attach.d.ts +2 -0
- package/dist/utils/checkout-create.d.ts +3 -0
- package/dist/utils/checkout-to-cart.d.ts +9 -0
- package/dist/utils/customer-token.d.ts +7 -0
- package/dist/utils/fragments/checkout-details.d.ts +1 -0
- package/dist/utils/fragments/index.d.ts +2 -0
- package/dist/utils/fragments/product.d.ts +1 -0
- package/dist/utils/get-categories.d.ts +3 -0
- package/dist/utils/get-checkout-id.d.ts +5 -0
- package/dist/utils/get-search-variables.d.ts +14 -0
- package/dist/utils/get-sort-variables.d.ts +1 -0
- package/dist/utils/get-vendors.d.ts +11 -0
- package/dist/utils/handle-fetch-response.d.ts +5 -0
- package/dist/utils/handle-login.d.ts +5 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/mutations/account-create.d.ts +1 -0
- package/dist/utils/mutations/checkout-attach.d.ts +1 -0
- package/dist/utils/mutations/checkout-create.d.ts +1 -0
- package/dist/utils/mutations/checkout-line-add.d.ts +1 -0
- package/dist/utils/mutations/checkout-line-remove.d.ts +1 -0
- package/dist/utils/mutations/checkout-line-update.d.ts +1 -0
- package/dist/utils/mutations/index.d.ts +8 -0
- package/dist/utils/mutations/session-create.d.ts +1 -0
- package/dist/utils/mutations/session-destroy.d.ts +1 -0
- package/dist/utils/normalize.d.ts +7 -0
- package/dist/utils/queries/checkout-one.d.ts +1 -0
- package/dist/utils/queries/collection-many.d.ts +1 -0
- package/dist/utils/queries/collection-one.d.ts +1 -0
- package/dist/utils/queries/customer-current.d.ts +1 -0
- package/dist/utils/queries/customer-one.d.ts +1 -0
- package/dist/utils/queries/get-all-product-vendors-query.d.ts +1 -0
- package/dist/utils/queries/get-all-products-paths-query.d.ts +1 -0
- package/dist/utils/queries/index.d.ts +11 -0
- package/dist/utils/queries/page-many.d.ts +1 -0
- package/dist/utils/queries/page-one.d.ts +1 -0
- package/dist/utils/queries/product-many.d.ts +1 -0
- package/dist/utils/queries/product-one-by-id.d.ts +1 -0
- package/dist/utils/queries/product-one-by-slug.d.ts +1 -0
- package/dist/utils/throw-user-errors.d.ts +5 -0
- package/package.json +44 -0
|
@@ -0,0 +1,1284 @@
|
|
|
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 registerGlobalContext = _interopDefault(require('@daouy/host/registerGlobalContext'));
|
|
8
|
+
var commerce = require('@daouypkgs/commerce');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var React__default = _interopDefault(React);
|
|
11
|
+
var Cookies = _interopDefault(require('js-cookie'));
|
|
12
|
+
var debounce = _interopDefault(require('debounce'));
|
|
13
|
+
|
|
14
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
15
|
+
try {
|
|
16
|
+
var i = n[a](c),
|
|
17
|
+
u = i.value;
|
|
18
|
+
} catch (n) {
|
|
19
|
+
return void e(n);
|
|
20
|
+
}
|
|
21
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
22
|
+
}
|
|
23
|
+
function _asyncToGenerator(n) {
|
|
24
|
+
return function () {
|
|
25
|
+
var t = this,
|
|
26
|
+
e = arguments;
|
|
27
|
+
return new Promise(function (r, o) {
|
|
28
|
+
var a = n.apply(t, e);
|
|
29
|
+
function _next(n) {
|
|
30
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
31
|
+
}
|
|
32
|
+
function _throw(n) {
|
|
33
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
34
|
+
}
|
|
35
|
+
_next(void 0);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _extends() {
|
|
40
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
41
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
42
|
+
var t = arguments[e];
|
|
43
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
44
|
+
}
|
|
45
|
+
return n;
|
|
46
|
+
}, _extends.apply(null, arguments);
|
|
47
|
+
}
|
|
48
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
49
|
+
if (null == r) return {};
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
52
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
53
|
+
t[n] = r[n];
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
}
|
|
57
|
+
function _regenerator() {
|
|
58
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
59
|
+
var e,
|
|
60
|
+
t,
|
|
61
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
62
|
+
n = r.iterator || "@@iterator",
|
|
63
|
+
o = r.toStringTag || "@@toStringTag";
|
|
64
|
+
function i(r, n, o, i) {
|
|
65
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
66
|
+
u = Object.create(c.prototype);
|
|
67
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
68
|
+
var i,
|
|
69
|
+
c,
|
|
70
|
+
u,
|
|
71
|
+
f = 0,
|
|
72
|
+
p = o || [],
|
|
73
|
+
y = !1,
|
|
74
|
+
G = {
|
|
75
|
+
p: 0,
|
|
76
|
+
n: 0,
|
|
77
|
+
v: e,
|
|
78
|
+
a: d,
|
|
79
|
+
f: d.bind(e, 4),
|
|
80
|
+
d: function (t, r) {
|
|
81
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function d(r, n) {
|
|
85
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
86
|
+
var o,
|
|
87
|
+
i = p[t],
|
|
88
|
+
d = G.p,
|
|
89
|
+
l = i[2];
|
|
90
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
91
|
+
}
|
|
92
|
+
if (o || r > 1) return a;
|
|
93
|
+
throw y = !0, n;
|
|
94
|
+
}
|
|
95
|
+
return function (o, p, l) {
|
|
96
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
97
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
98
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
99
|
+
try {
|
|
100
|
+
if (f = 2, i) {
|
|
101
|
+
if (c || (o = "next"), t = i[o]) {
|
|
102
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
103
|
+
if (!t.done) return t;
|
|
104
|
+
u = t.value, c < 2 && (c = 0);
|
|
105
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
106
|
+
i = e;
|
|
107
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
108
|
+
} catch (t) {
|
|
109
|
+
i = e, c = 1, u = t;
|
|
110
|
+
} finally {
|
|
111
|
+
f = 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
value: t,
|
|
116
|
+
done: y
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}(r, o, i), !0), u;
|
|
120
|
+
}
|
|
121
|
+
var a = {};
|
|
122
|
+
function Generator() {}
|
|
123
|
+
function GeneratorFunction() {}
|
|
124
|
+
function GeneratorFunctionPrototype() {}
|
|
125
|
+
t = Object.getPrototypeOf;
|
|
126
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
127
|
+
return this;
|
|
128
|
+
}), t),
|
|
129
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
130
|
+
function f(e) {
|
|
131
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
132
|
+
}
|
|
133
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
134
|
+
return this;
|
|
135
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
136
|
+
return "[object Generator]";
|
|
137
|
+
}), (_regenerator = function () {
|
|
138
|
+
return {
|
|
139
|
+
w: i,
|
|
140
|
+
m: f
|
|
141
|
+
};
|
|
142
|
+
})();
|
|
143
|
+
}
|
|
144
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
145
|
+
var i = Object.defineProperty;
|
|
146
|
+
try {
|
|
147
|
+
i({}, "", {});
|
|
148
|
+
} catch (e) {
|
|
149
|
+
i = 0;
|
|
150
|
+
}
|
|
151
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
152
|
+
function o(r, n) {
|
|
153
|
+
_regeneratorDefine(e, r, function (e) {
|
|
154
|
+
return this._invoke(r, n, e);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
r ? i ? i(e, r, {
|
|
158
|
+
value: n,
|
|
159
|
+
enumerable: !t,
|
|
160
|
+
configurable: !t,
|
|
161
|
+
writable: !t
|
|
162
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
163
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/*
|
|
167
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
168
|
+
Changes: Removed api_url
|
|
169
|
+
*/
|
|
170
|
+
var CHECKOUT_ID_COOKIE = 'saleor.CheckoutID';
|
|
171
|
+
var SALEOR_TOKEN = 'saleor.Token';
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
175
|
+
Changes: None
|
|
176
|
+
*/
|
|
177
|
+
var getSortVariables = function getSortVariables(sort, isCategory) {
|
|
178
|
+
var output = {};
|
|
179
|
+
switch (sort) {
|
|
180
|
+
case 'price-asc':
|
|
181
|
+
output = {
|
|
182
|
+
field: 'PRICE',
|
|
183
|
+
direction: 'ASC'
|
|
184
|
+
};
|
|
185
|
+
break;
|
|
186
|
+
case 'price-desc':
|
|
187
|
+
output = {
|
|
188
|
+
field: 'PRICE',
|
|
189
|
+
direction: 'DESC'
|
|
190
|
+
};
|
|
191
|
+
break;
|
|
192
|
+
case 'trending-desc':
|
|
193
|
+
//default
|
|
194
|
+
output = {};
|
|
195
|
+
break;
|
|
196
|
+
case 'latest-desc':
|
|
197
|
+
output = {
|
|
198
|
+
field: 'DATE',
|
|
199
|
+
direction: 'DESC'
|
|
200
|
+
};
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
return output;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
function getError(errors, status) {
|
|
207
|
+
errors = errors != null ? errors : [{
|
|
208
|
+
message: 'Failed to fetch Saleor API'
|
|
209
|
+
}];
|
|
210
|
+
return new commerce.FetcherError({
|
|
211
|
+
errors: errors,
|
|
212
|
+
status: status
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function getAsyncError(_x) {
|
|
216
|
+
return _getAsyncError.apply(this, arguments);
|
|
217
|
+
}
|
|
218
|
+
function _getAsyncError() {
|
|
219
|
+
_getAsyncError = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(res) {
|
|
220
|
+
var data;
|
|
221
|
+
return _regenerator().w(function (_context2) {
|
|
222
|
+
while (1) switch (_context2.n) {
|
|
223
|
+
case 0:
|
|
224
|
+
_context2.n = 1;
|
|
225
|
+
return res.json();
|
|
226
|
+
case 1:
|
|
227
|
+
data = _context2.v;
|
|
228
|
+
return _context2.a(2, getError(data.errors, res.status));
|
|
229
|
+
}
|
|
230
|
+
}, _callee2);
|
|
231
|
+
}));
|
|
232
|
+
return _getAsyncError.apply(this, arguments);
|
|
233
|
+
}
|
|
234
|
+
var handleFetchResponse = /*#__PURE__*/function () {
|
|
235
|
+
var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(res) {
|
|
236
|
+
var _yield$res$json, data, errors;
|
|
237
|
+
return _regenerator().w(function (_context) {
|
|
238
|
+
while (1) switch (_context.n) {
|
|
239
|
+
case 0:
|
|
240
|
+
if (!res.ok) {
|
|
241
|
+
_context.n = 3;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
_context.n = 1;
|
|
245
|
+
return res.json();
|
|
246
|
+
case 1:
|
|
247
|
+
_yield$res$json = _context.v;
|
|
248
|
+
data = _yield$res$json.data;
|
|
249
|
+
errors = _yield$res$json.errors;
|
|
250
|
+
if (!(errors && errors.length)) {
|
|
251
|
+
_context.n = 2;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
throw getError(errors, res.status);
|
|
255
|
+
case 2:
|
|
256
|
+
return _context.a(2, data);
|
|
257
|
+
case 3:
|
|
258
|
+
_context.n = 4;
|
|
259
|
+
return getAsyncError(res);
|
|
260
|
+
case 4:
|
|
261
|
+
throw _context.v;
|
|
262
|
+
case 5:
|
|
263
|
+
return _context.a(2);
|
|
264
|
+
}
|
|
265
|
+
}, _callee);
|
|
266
|
+
}));
|
|
267
|
+
return function handleFetchResponse(_x2) {
|
|
268
|
+
return _ref.apply(this, arguments);
|
|
269
|
+
};
|
|
270
|
+
}();
|
|
271
|
+
|
|
272
|
+
var getSearchVariables = function getSearchVariables(_ref) {
|
|
273
|
+
var search = _ref.search,
|
|
274
|
+
categoryId = _ref.categoryId,
|
|
275
|
+
sort = _ref.sort,
|
|
276
|
+
count = _ref.count;
|
|
277
|
+
var sortBy = _extends({
|
|
278
|
+
field: 'NAME',
|
|
279
|
+
direction: 'ASC'
|
|
280
|
+
}, getSortVariables(sort), {
|
|
281
|
+
channel: 'default-channel'
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
categoryId: categoryId,
|
|
285
|
+
filter: {
|
|
286
|
+
search: search
|
|
287
|
+
},
|
|
288
|
+
sortBy: sortBy,
|
|
289
|
+
first: count
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/*
|
|
294
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
295
|
+
Changes: None
|
|
296
|
+
*/
|
|
297
|
+
var getCheckoutId = function getCheckoutId(id) {
|
|
298
|
+
var _Cookies$get;
|
|
299
|
+
var r = ((_Cookies$get = Cookies.get(CHECKOUT_ID_COOKIE)) == null ? void 0 : _Cookies$get.split(':')) || [];
|
|
300
|
+
return {
|
|
301
|
+
checkoutId: r[0],
|
|
302
|
+
checkoutToken: r[1]
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/*
|
|
307
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
308
|
+
Changes: None
|
|
309
|
+
*/
|
|
310
|
+
var ProductConnection = /* GraphQL */"\n fragment ProductConnection on ProductCountableConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n name\n description\n slug\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n media {\n url\n alt\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n }\n }\n }\n";
|
|
311
|
+
|
|
312
|
+
/*
|
|
313
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
314
|
+
Changes: None
|
|
315
|
+
*/
|
|
316
|
+
var CheckoutDetails = /* GraphQL */"\n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n id\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n";
|
|
317
|
+
|
|
318
|
+
/*
|
|
319
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
320
|
+
Changes: None
|
|
321
|
+
*/
|
|
322
|
+
var CheckoutCreate = /* GraphQL */"\n mutation CheckoutCreate {\n checkoutCreate(input: { email: \"customer@example.com\", lines: [], channel: \"default-channel\" }) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
|
|
323
|
+
|
|
324
|
+
/*
|
|
325
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
326
|
+
Changes: None
|
|
327
|
+
*/
|
|
328
|
+
var CheckoutLineAdd = /* GraphQL */"\n mutation CheckoutLineAdd($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesAdd(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
|
|
329
|
+
|
|
330
|
+
/*
|
|
331
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
332
|
+
Changes: None
|
|
333
|
+
*/
|
|
334
|
+
var CheckoutLineUpdate = /* GraphQL */"\n mutation CheckoutLineUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
|
|
335
|
+
|
|
336
|
+
/*
|
|
337
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
338
|
+
Changes: None
|
|
339
|
+
*/
|
|
340
|
+
var CheckoutLineDelete = /* GraphQL */"\n mutation CheckoutLineDelete($checkoutId: ID!, $lineId: ID!) {\n checkoutLineDelete(checkoutId: $checkoutId, lineId: $lineId) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
|
|
341
|
+
|
|
342
|
+
var checkoutCreate = /*#__PURE__*/function () {
|
|
343
|
+
var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fetch) {
|
|
344
|
+
var _data$checkoutCreate;
|
|
345
|
+
var data, checkout, checkoutId, checkoutToken, value, options;
|
|
346
|
+
return _regenerator().w(function (_context) {
|
|
347
|
+
while (1) switch (_context.n) {
|
|
348
|
+
case 0:
|
|
349
|
+
_context.n = 1;
|
|
350
|
+
return fetch({
|
|
351
|
+
query: CheckoutCreate
|
|
352
|
+
});
|
|
353
|
+
case 1:
|
|
354
|
+
data = _context.v;
|
|
355
|
+
checkout = (_data$checkoutCreate = data.checkoutCreate) == null ? void 0 : _data$checkoutCreate.checkout;
|
|
356
|
+
checkoutId = checkout == null ? void 0 : checkout.id;
|
|
357
|
+
checkoutToken = checkout == null ? void 0 : checkout.token;
|
|
358
|
+
value = checkoutId + ":" + checkoutToken;
|
|
359
|
+
if (checkoutId) {
|
|
360
|
+
options = {
|
|
361
|
+
expires: 60 * 60 * 24 * 30,
|
|
362
|
+
sameSite: "none",
|
|
363
|
+
secure: true
|
|
364
|
+
};
|
|
365
|
+
Cookies.set(CHECKOUT_ID_COOKIE, value, options);
|
|
366
|
+
}
|
|
367
|
+
return _context.a(2, checkout);
|
|
368
|
+
}
|
|
369
|
+
}, _callee);
|
|
370
|
+
}));
|
|
371
|
+
return function checkoutCreate(_x) {
|
|
372
|
+
return _ref.apply(this, arguments);
|
|
373
|
+
};
|
|
374
|
+
}();
|
|
375
|
+
|
|
376
|
+
var _excluded = ["id", "name", "media", "variants", "description", "slug", "pricing"];
|
|
377
|
+
/* eslint-disable */
|
|
378
|
+
/*
|
|
379
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
380
|
+
Changes: None
|
|
381
|
+
*/
|
|
382
|
+
// TODO: Check nextjs-commerce bug if no images are added for a product
|
|
383
|
+
var placeholderImg = "/product-img-placeholder.svg";
|
|
384
|
+
var money = function money(_ref) {
|
|
385
|
+
var amount = _ref.amount,
|
|
386
|
+
currency = _ref.currency;
|
|
387
|
+
return {
|
|
388
|
+
value: +amount,
|
|
389
|
+
currencyCode: currency || "USD"
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
var normalizeProductOptions = function normalizeProductOptions(options) {
|
|
393
|
+
return options == null ? void 0 : options.map(function (option) {
|
|
394
|
+
return option == null ? void 0 : option.attributes;
|
|
395
|
+
}).flat(1).reduce(function (acc, x) {
|
|
396
|
+
if (acc.find(function (_ref2) {
|
|
397
|
+
var displayName = _ref2.displayName;
|
|
398
|
+
return displayName === x.attribute.name;
|
|
399
|
+
})) {
|
|
400
|
+
return acc.map(function (opt) {
|
|
401
|
+
return opt.displayName === x.attribute.name ? _extends({}, opt, {
|
|
402
|
+
values: [].concat(opt.values, x.values.map(function (value) {
|
|
403
|
+
return {
|
|
404
|
+
label: value == null ? void 0 : value.name
|
|
405
|
+
};
|
|
406
|
+
}))
|
|
407
|
+
}) : opt;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return acc.concat({
|
|
411
|
+
__typename: "MultipleChoiceOption",
|
|
412
|
+
displayName: x.attribute.name,
|
|
413
|
+
variant: "size",
|
|
414
|
+
values: x.values.map(function (value) {
|
|
415
|
+
return {
|
|
416
|
+
label: value == null ? void 0 : value.name
|
|
417
|
+
};
|
|
418
|
+
})
|
|
419
|
+
});
|
|
420
|
+
}, []);
|
|
421
|
+
};
|
|
422
|
+
var normalizeProductVariants = function normalizeProductVariants(variants) {
|
|
423
|
+
return variants == null ? void 0 : variants.map(function (variant) {
|
|
424
|
+
var _pricing$price, _money;
|
|
425
|
+
var id = variant.id,
|
|
426
|
+
sku = variant.sku,
|
|
427
|
+
name = variant.name,
|
|
428
|
+
pricing = variant.pricing;
|
|
429
|
+
var price = (pricing == null || (_pricing$price = pricing.price) == null ? void 0 : _pricing$price.net) && ((_money = money(pricing.price.net)) == null ? void 0 : _money.value);
|
|
430
|
+
return {
|
|
431
|
+
id: id,
|
|
432
|
+
name: name,
|
|
433
|
+
sku: sku != null ? sku : id,
|
|
434
|
+
price: price,
|
|
435
|
+
listPrice: price,
|
|
436
|
+
requiresShipping: true,
|
|
437
|
+
options: normalizeProductOptions([variant])
|
|
438
|
+
};
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
function normalizeProduct(productNode) {
|
|
442
|
+
var _JSON$parse, _pricing$priceRange;
|
|
443
|
+
var id = productNode.id,
|
|
444
|
+
name = productNode.name,
|
|
445
|
+
_productNode$media = productNode.media,
|
|
446
|
+
media = _productNode$media === void 0 ? [] : _productNode$media,
|
|
447
|
+
variants = productNode.variants,
|
|
448
|
+
description = productNode.description,
|
|
449
|
+
slug = productNode.slug,
|
|
450
|
+
pricing = productNode.pricing,
|
|
451
|
+
rest = _objectWithoutPropertiesLoose(productNode, _excluded);
|
|
452
|
+
var product = _extends({
|
|
453
|
+
id: id,
|
|
454
|
+
name: name,
|
|
455
|
+
vendor: "",
|
|
456
|
+
description: description ? (_JSON$parse = JSON.parse(description)) == null || (_JSON$parse = _JSON$parse.blocks[0]) == null ? void 0 : _JSON$parse.data.text : "",
|
|
457
|
+
path: "/" + slug,
|
|
458
|
+
slug: slug == null ? void 0 : slug.replace(/^\/+|\/+$/g, ""),
|
|
459
|
+
price: (pricing == null || (_pricing$priceRange = pricing.priceRange) == null || (_pricing$priceRange = _pricing$priceRange.start) == null ? void 0 : _pricing$priceRange.net) && money(pricing.priceRange.start.net) || {
|
|
460
|
+
value: 0,
|
|
461
|
+
currencyCode: "USD"
|
|
462
|
+
},
|
|
463
|
+
// TODO: Check nextjs-commerce bug if no images are added for a product
|
|
464
|
+
images: media != null && media.length ? media : [{
|
|
465
|
+
url: placeholderImg
|
|
466
|
+
}],
|
|
467
|
+
variants: variants && variants.length > 0 ? normalizeProductVariants(variants) : [],
|
|
468
|
+
options: variants && variants.length > 0 ? normalizeProductOptions(variants) : []
|
|
469
|
+
}, rest);
|
|
470
|
+
return product;
|
|
471
|
+
}
|
|
472
|
+
function normalizeCart(checkout) {
|
|
473
|
+
var _checkout$totalPrice, _checkout$subtotalPri, _checkout$subtotalPri2, _checkout$totalPrice2;
|
|
474
|
+
var lines = checkout.lines;
|
|
475
|
+
var lineItems = lines.length > 0 ? lines == null ? void 0 : lines.map(normalizeLineItem) : [];
|
|
476
|
+
return {
|
|
477
|
+
id: checkout.id,
|
|
478
|
+
customerId: "",
|
|
479
|
+
email: "",
|
|
480
|
+
createdAt: checkout.created,
|
|
481
|
+
currency: {
|
|
482
|
+
code: (_checkout$totalPrice = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice.currency
|
|
483
|
+
},
|
|
484
|
+
taxesIncluded: false,
|
|
485
|
+
lineItems: lineItems,
|
|
486
|
+
lineItemsSubtotalPrice: (_checkout$subtotalPri = checkout.subtotalPrice) == null || (_checkout$subtotalPri = _checkout$subtotalPri.gross) == null ? void 0 : _checkout$subtotalPri.amount,
|
|
487
|
+
subtotalPrice: (_checkout$subtotalPri2 = checkout.subtotalPrice) == null || (_checkout$subtotalPri2 = _checkout$subtotalPri2.gross) == null ? void 0 : _checkout$subtotalPri2.amount,
|
|
488
|
+
totalPrice: (_checkout$totalPrice2 = checkout.totalPrice) == null ? void 0 : _checkout$totalPrice2.gross.amount,
|
|
489
|
+
discounts: []
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function normalizeLineItem(_ref3) {
|
|
493
|
+
var _variant$product, _variant$sku, _variant$pricing, _variant$product2;
|
|
494
|
+
var id = _ref3.id,
|
|
495
|
+
variant = _ref3.variant,
|
|
496
|
+
quantity = _ref3.quantity;
|
|
497
|
+
return {
|
|
498
|
+
id: id,
|
|
499
|
+
variantId: String(variant == null ? void 0 : variant.id),
|
|
500
|
+
productId: String(variant == null || (_variant$product = variant.product) == null ? void 0 : _variant$product.id),
|
|
501
|
+
name: "" + variant.product.name,
|
|
502
|
+
quantity: quantity,
|
|
503
|
+
variant: {
|
|
504
|
+
id: String(variant == null ? void 0 : variant.id),
|
|
505
|
+
sku: (_variant$sku = variant == null ? void 0 : variant.sku) != null ? _variant$sku : "",
|
|
506
|
+
name: variant == null ? void 0 : variant.name,
|
|
507
|
+
image: {
|
|
508
|
+
url: variant != null && variant.media[0] ? variant == null ? void 0 : variant.media[0].url : placeholderImg
|
|
509
|
+
},
|
|
510
|
+
requiresShipping: false,
|
|
511
|
+
price: variant == null || (_variant$pricing = variant.pricing) == null || (_variant$pricing = _variant$pricing.price) == null ? void 0 : _variant$pricing.gross.amount,
|
|
512
|
+
listPrice: 0
|
|
513
|
+
},
|
|
514
|
+
path: String(variant == null || (_variant$product2 = variant.product) == null ? void 0 : _variant$product2.slug),
|
|
515
|
+
discounts: [],
|
|
516
|
+
options: []
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
var normalizeCategory = function normalizeCategory(_ref4) {
|
|
520
|
+
var name = _ref4.name,
|
|
521
|
+
slug = _ref4.slug,
|
|
522
|
+
id = _ref4.id;
|
|
523
|
+
return {
|
|
524
|
+
id: id,
|
|
525
|
+
name: name,
|
|
526
|
+
slug: slug,
|
|
527
|
+
path: "/" + slug
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
/*
|
|
532
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
533
|
+
Changes: None
|
|
534
|
+
*/
|
|
535
|
+
var throwUserErrors = function throwUserErrors(errors) {
|
|
536
|
+
if (errors && errors.length) {
|
|
537
|
+
throw new commerce.ValidationError({
|
|
538
|
+
errors: errors.map(function (_ref) {
|
|
539
|
+
var code = _ref.code,
|
|
540
|
+
message = _ref.message;
|
|
541
|
+
return {
|
|
542
|
+
code: code != null ? code : 'validation_error',
|
|
543
|
+
message: message || ''
|
|
544
|
+
};
|
|
545
|
+
})
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
/*
|
|
551
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
552
|
+
Changes: None
|
|
553
|
+
*/
|
|
554
|
+
var checkoutToCart = function checkoutToCart(checkoutPayload) {
|
|
555
|
+
var _checkoutPayload$erro;
|
|
556
|
+
if (!checkoutPayload) {
|
|
557
|
+
throw new commerce.CommerceError({
|
|
558
|
+
message: 'Missing checkout payload from response'
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
var checkout = checkoutPayload == null ? void 0 : checkoutPayload.checkout;
|
|
562
|
+
if ((checkoutPayload == null || (_checkoutPayload$erro = checkoutPayload.errors) == null ? void 0 : _checkoutPayload$erro.length) === 1 && checkoutPayload.errors[0].code === "PRODUCT_UNAVAILABLE_FOR_PURCHASE") {
|
|
563
|
+
console.error(checkoutPayload.errors[0]);
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
if (checkoutPayload != null && checkoutPayload.errors) {
|
|
567
|
+
throwUserErrors(checkoutPayload == null ? void 0 : checkoutPayload.errors);
|
|
568
|
+
}
|
|
569
|
+
if (!checkout) {
|
|
570
|
+
throw new commerce.CommerceError({
|
|
571
|
+
message: 'Missing checkout object from response'
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
return normalizeCart(checkout);
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
/*
|
|
578
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
579
|
+
Changes: None
|
|
580
|
+
*/
|
|
581
|
+
var getToken = function getToken() {
|
|
582
|
+
return Cookies.get(SALEOR_TOKEN);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/*
|
|
586
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
587
|
+
Changes: None
|
|
588
|
+
*/
|
|
589
|
+
var CollectionMany = /* GraphQL */"\n query CollectionMany( $channel: String = \"default-channel\") {\n collections(first:100, channel: $channel) {\n edges {\n node {\n id\n name\n slug\n }\n }\n }\n }\n";
|
|
590
|
+
|
|
591
|
+
/*
|
|
592
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
593
|
+
Changes: None
|
|
594
|
+
*/
|
|
595
|
+
var ProductOneBySlug = /* GraphQL */"\n query ProductOneBySlug($slug: String!, $channel: String = \"default-channel\") {\n product(slug: $slug, channel: $channel) {\n id\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }\n";
|
|
596
|
+
|
|
597
|
+
/*
|
|
598
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
599
|
+
Changes: None
|
|
600
|
+
*/
|
|
601
|
+
var ProductMany = /* GraphQL */"\n query ProductMany(\n $first: Int = 100\n $filter: ProductFilterInput\n $sortBy: ProductOrder\n $channel: String = \"default-channel\"\n ) {\n products(first: $first, channel: $channel, filter: $filter, sortBy: $sortBy) {\n ...ProductConnection\n }\n }\n " + ProductConnection + "\n";
|
|
602
|
+
|
|
603
|
+
/*
|
|
604
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
605
|
+
Changes: None
|
|
606
|
+
*/
|
|
607
|
+
var CollectionOne = /* GraphQL */"\n query getProductsFromCollection($categoryId: ID!, $first: Int = 100, $channel: String = \"default-channel\") {\n collection(id: $categoryId, channel: $channel) {\n id\n name\n slug\n products(first: $first) {\n ...ProductConnection\n }\n }\n }\n " + ProductConnection + "\n";
|
|
608
|
+
|
|
609
|
+
/*
|
|
610
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
611
|
+
Changes: None
|
|
612
|
+
*/
|
|
613
|
+
var CheckoutOne = /* GraphQL */"\n query CheckoutOne($checkoutId: UUID!) {\n checkout(token: $checkoutId) {\n ... on Checkout {\n ...CheckoutDetails\n }\n }\n }\n " + CheckoutDetails + "\n";
|
|
614
|
+
|
|
615
|
+
/*
|
|
616
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
617
|
+
Changes: None
|
|
618
|
+
*/
|
|
619
|
+
var getAllProductVendors = /* GraphQL */"\n query getAllProductVendors($cursor: String, $channel: String = \"default-channel\") {\n products(first:100,channel: $channel, after: $cursor) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n slug\n }\n cursor\n }\n }\n }\n";
|
|
620
|
+
|
|
621
|
+
var handler = {
|
|
622
|
+
fetchOptions: {
|
|
623
|
+
query: CheckoutOne
|
|
624
|
+
},
|
|
625
|
+
fetcher: function fetcher(_ref) {
|
|
626
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
627
|
+
var _checkout;
|
|
628
|
+
var checkoutId, options, fetch, checkout, _checkoutId, data;
|
|
629
|
+
return _regenerator().w(function (_context) {
|
|
630
|
+
while (1) switch (_context.n) {
|
|
631
|
+
case 0:
|
|
632
|
+
checkoutId = _ref.input.cartId, options = _ref.options, fetch = _ref.fetch;
|
|
633
|
+
if (!checkoutId) {
|
|
634
|
+
_context.n = 2;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
_checkoutId = getCheckoutId().checkoutToken;
|
|
638
|
+
_context.n = 1;
|
|
639
|
+
return fetch(_extends({}, options, {
|
|
640
|
+
variables: {
|
|
641
|
+
checkoutId: _checkoutId
|
|
642
|
+
}
|
|
643
|
+
}));
|
|
644
|
+
case 1:
|
|
645
|
+
data = _context.v;
|
|
646
|
+
checkout = data;
|
|
647
|
+
case 2:
|
|
648
|
+
if (!((_checkout = checkout) != null && _checkout.completedAt || !checkoutId)) {
|
|
649
|
+
_context.n = 4;
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
_context.n = 3;
|
|
653
|
+
return checkoutCreate(fetch);
|
|
654
|
+
case 3:
|
|
655
|
+
checkout = _context.v;
|
|
656
|
+
case 4:
|
|
657
|
+
return _context.a(2, checkoutToCart(checkout));
|
|
658
|
+
}
|
|
659
|
+
}, _callee);
|
|
660
|
+
}))();
|
|
661
|
+
},
|
|
662
|
+
useHook: function useHook(_ref2) {
|
|
663
|
+
var useData = _ref2.useData;
|
|
664
|
+
return function (input) {
|
|
665
|
+
var response = useData({
|
|
666
|
+
swrOptions: _extends({
|
|
667
|
+
revalidateOnFocus: false
|
|
668
|
+
}, input == null ? void 0 : input.swrOptions)
|
|
669
|
+
});
|
|
670
|
+
return React.useMemo(function () {
|
|
671
|
+
return Object.create(response, {
|
|
672
|
+
isEmpty: {
|
|
673
|
+
get: function get() {
|
|
674
|
+
var _response$data$lineIt, _response$data;
|
|
675
|
+
return ((_response$data$lineIt = (_response$data = response.data) == null ? void 0 : _response$data.lineItems.length) != null ? _response$data$lineIt : 0) <= 0;
|
|
676
|
+
},
|
|
677
|
+
enumerable: true
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}, [response]);
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
var handler$1 = {
|
|
686
|
+
fetchOptions: {
|
|
687
|
+
query: CheckoutLineAdd
|
|
688
|
+
},
|
|
689
|
+
fetcher: function fetcher(_ref) {
|
|
690
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
691
|
+
var _item$quantity;
|
|
692
|
+
var item, options, fetch, _yield$fetch, checkoutLinesAdd;
|
|
693
|
+
return _regenerator().w(function (_context) {
|
|
694
|
+
while (1) switch (_context.n) {
|
|
695
|
+
case 0:
|
|
696
|
+
item = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
697
|
+
if (!(item.quantity && (!Number.isInteger(item.quantity) || item.quantity < 1))) {
|
|
698
|
+
_context.n = 1;
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
throw new commerce.CommerceError({
|
|
702
|
+
message: "The item quantity has to be a valid integer greater than 0"
|
|
703
|
+
});
|
|
704
|
+
case 1:
|
|
705
|
+
_context.n = 2;
|
|
706
|
+
return fetch(_extends({}, options, {
|
|
707
|
+
variables: {
|
|
708
|
+
checkoutId: getCheckoutId().checkoutId,
|
|
709
|
+
lineItems: [{
|
|
710
|
+
variantId: item.variantId,
|
|
711
|
+
quantity: (_item$quantity = item.quantity) != null ? _item$quantity : 1
|
|
712
|
+
}]
|
|
713
|
+
}
|
|
714
|
+
}));
|
|
715
|
+
case 2:
|
|
716
|
+
_yield$fetch = _context.v;
|
|
717
|
+
checkoutLinesAdd = _yield$fetch.checkoutLinesAdd;
|
|
718
|
+
return _context.a(2, checkoutToCart(checkoutLinesAdd));
|
|
719
|
+
}
|
|
720
|
+
}, _callee);
|
|
721
|
+
}))();
|
|
722
|
+
},
|
|
723
|
+
useHook: function useHook(_ref2) {
|
|
724
|
+
var fetch = _ref2.fetch;
|
|
725
|
+
return function () {
|
|
726
|
+
var _useCart = commerce.useCart(),
|
|
727
|
+
mutate = _useCart.mutate;
|
|
728
|
+
return React.useCallback(/*#__PURE__*/function () {
|
|
729
|
+
var _addItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input) {
|
|
730
|
+
var data;
|
|
731
|
+
return _regenerator().w(function (_context2) {
|
|
732
|
+
while (1) switch (_context2.n) {
|
|
733
|
+
case 0:
|
|
734
|
+
_context2.n = 1;
|
|
735
|
+
return fetch({
|
|
736
|
+
input: input
|
|
737
|
+
});
|
|
738
|
+
case 1:
|
|
739
|
+
data = _context2.v;
|
|
740
|
+
if (!data) {
|
|
741
|
+
_context2.n = 3;
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
744
|
+
_context2.n = 2;
|
|
745
|
+
return mutate(data, false);
|
|
746
|
+
case 2:
|
|
747
|
+
_context2.n = 4;
|
|
748
|
+
break;
|
|
749
|
+
case 3:
|
|
750
|
+
_context2.n = 4;
|
|
751
|
+
return mutate();
|
|
752
|
+
case 4:
|
|
753
|
+
return _context2.a(2, data);
|
|
754
|
+
}
|
|
755
|
+
}, _callee2);
|
|
756
|
+
}));
|
|
757
|
+
function addItem(_x) {
|
|
758
|
+
return _addItem.apply(this, arguments);
|
|
759
|
+
}
|
|
760
|
+
return addItem;
|
|
761
|
+
}(), [fetch, mutate]);
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
var handler$2 = {
|
|
767
|
+
fetchOptions: {
|
|
768
|
+
query: CheckoutLineDelete
|
|
769
|
+
},
|
|
770
|
+
fetcher: function fetcher(_ref) {
|
|
771
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
772
|
+
var itemId, options, fetch, data;
|
|
773
|
+
return _regenerator().w(function (_context) {
|
|
774
|
+
while (1) switch (_context.n) {
|
|
775
|
+
case 0:
|
|
776
|
+
itemId = _ref.input.itemId, options = _ref.options, fetch = _ref.fetch;
|
|
777
|
+
_context.n = 1;
|
|
778
|
+
return fetch(_extends({}, options, {
|
|
779
|
+
variables: {
|
|
780
|
+
checkoutId: getCheckoutId().checkoutId,
|
|
781
|
+
lineId: itemId
|
|
782
|
+
}
|
|
783
|
+
}));
|
|
784
|
+
case 1:
|
|
785
|
+
data = _context.v;
|
|
786
|
+
return _context.a(2, checkoutToCart(data.checkoutLineDelete));
|
|
787
|
+
}
|
|
788
|
+
}, _callee);
|
|
789
|
+
}))();
|
|
790
|
+
},
|
|
791
|
+
useHook: function useHook(_ref2) {
|
|
792
|
+
var fetch = _ref2.fetch;
|
|
793
|
+
return function () {
|
|
794
|
+
var _useCart = commerce.useCart(),
|
|
795
|
+
mutate = _useCart.mutate;
|
|
796
|
+
return React.useCallback(/*#__PURE__*/function () {
|
|
797
|
+
var _removeItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input) {
|
|
798
|
+
var data;
|
|
799
|
+
return _regenerator().w(function (_context2) {
|
|
800
|
+
while (1) switch (_context2.n) {
|
|
801
|
+
case 0:
|
|
802
|
+
_context2.n = 1;
|
|
803
|
+
return fetch({
|
|
804
|
+
input: {
|
|
805
|
+
itemId: input.id
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
case 1:
|
|
809
|
+
data = _context2.v;
|
|
810
|
+
_context2.n = 2;
|
|
811
|
+
return mutate(data, false);
|
|
812
|
+
case 2:
|
|
813
|
+
return _context2.a(2, data);
|
|
814
|
+
}
|
|
815
|
+
}, _callee2);
|
|
816
|
+
}));
|
|
817
|
+
function removeItem(_x) {
|
|
818
|
+
return _removeItem.apply(this, arguments);
|
|
819
|
+
}
|
|
820
|
+
return removeItem;
|
|
821
|
+
}(), [fetch, mutate]);
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
var handler$3 = {
|
|
827
|
+
fetchOptions: {
|
|
828
|
+
query: CheckoutLineUpdate
|
|
829
|
+
},
|
|
830
|
+
fetcher: function fetcher(_ref) {
|
|
831
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
832
|
+
var _ref$input, itemId, item, options, fetch, checkoutId, _yield$fetch, checkoutLinesUpdate;
|
|
833
|
+
return _regenerator().w(function (_context) {
|
|
834
|
+
while (1) switch (_context.n) {
|
|
835
|
+
case 0:
|
|
836
|
+
_ref$input = _ref.input, itemId = _ref$input.itemId, item = _ref$input.item, options = _ref.options, fetch = _ref.fetch;
|
|
837
|
+
if (!Number.isInteger(item.quantity)) {
|
|
838
|
+
_context.n = 2;
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
if (!(item.quantity < 1)) {
|
|
842
|
+
_context.n = 1;
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
return _context.a(2, handler$2.fetcher({
|
|
846
|
+
options: handler$2.fetchOptions,
|
|
847
|
+
input: {
|
|
848
|
+
itemId: itemId
|
|
849
|
+
},
|
|
850
|
+
fetch: fetch
|
|
851
|
+
}));
|
|
852
|
+
case 1:
|
|
853
|
+
_context.n = 3;
|
|
854
|
+
break;
|
|
855
|
+
case 2:
|
|
856
|
+
if (!item.quantity) {
|
|
857
|
+
_context.n = 3;
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
throw new commerce.ValidationError({
|
|
861
|
+
message: "The item quantity has to be a valid integer"
|
|
862
|
+
});
|
|
863
|
+
case 3:
|
|
864
|
+
checkoutId = getCheckoutId().checkoutId;
|
|
865
|
+
_context.n = 4;
|
|
866
|
+
return fetch(_extends({}, options, {
|
|
867
|
+
variables: {
|
|
868
|
+
checkoutId: checkoutId,
|
|
869
|
+
lineItems: [{
|
|
870
|
+
itemId: itemId,
|
|
871
|
+
quantity: item.quantity
|
|
872
|
+
}]
|
|
873
|
+
}
|
|
874
|
+
}));
|
|
875
|
+
case 4:
|
|
876
|
+
_yield$fetch = _context.v;
|
|
877
|
+
checkoutLinesUpdate = _yield$fetch.checkoutLinesUpdate;
|
|
878
|
+
return _context.a(2, checkoutToCart(checkoutLinesUpdate));
|
|
879
|
+
}
|
|
880
|
+
}, _callee);
|
|
881
|
+
}))();
|
|
882
|
+
},
|
|
883
|
+
useHook: function useHook(_ref2) {
|
|
884
|
+
var fetch = _ref2.fetch;
|
|
885
|
+
return function (ctx) {
|
|
886
|
+
var _ctx$wait;
|
|
887
|
+
if (ctx === void 0) {
|
|
888
|
+
ctx = {};
|
|
889
|
+
}
|
|
890
|
+
var _ctx = ctx,
|
|
891
|
+
item = _ctx.item;
|
|
892
|
+
var _useCart = commerce.useCart(),
|
|
893
|
+
mutate = _useCart.mutate;
|
|
894
|
+
return React.useCallback(debounce(/*#__PURE__*/function () {
|
|
895
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input) {
|
|
896
|
+
var _input$id;
|
|
897
|
+
var itemId, data;
|
|
898
|
+
return _regenerator().w(function (_context2) {
|
|
899
|
+
while (1) switch (_context2.n) {
|
|
900
|
+
case 0:
|
|
901
|
+
itemId = (_input$id = input.id) != null ? _input$id : item == null ? void 0 : item.id;
|
|
902
|
+
if (itemId) {
|
|
903
|
+
_context2.n = 1;
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
throw new commerce.ValidationError({
|
|
907
|
+
message: "Invalid input used for this operation"
|
|
908
|
+
});
|
|
909
|
+
case 1:
|
|
910
|
+
_context2.n = 2;
|
|
911
|
+
return fetch({
|
|
912
|
+
input: {
|
|
913
|
+
item: {
|
|
914
|
+
quantity: input.quantity
|
|
915
|
+
},
|
|
916
|
+
itemId: itemId
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
case 2:
|
|
920
|
+
data = _context2.v;
|
|
921
|
+
_context2.n = 3;
|
|
922
|
+
return mutate(data, false);
|
|
923
|
+
case 3:
|
|
924
|
+
return _context2.a(2, data);
|
|
925
|
+
}
|
|
926
|
+
}, _callee2);
|
|
927
|
+
}));
|
|
928
|
+
return function (_x) {
|
|
929
|
+
return _ref3.apply(this, arguments);
|
|
930
|
+
};
|
|
931
|
+
}(), (_ctx$wait = ctx.wait) != null ? _ctx$wait : 500), [fetch, mutate]);
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
var handler$4 = {
|
|
937
|
+
fetchOptions: {
|
|
938
|
+
query: CollectionMany
|
|
939
|
+
},
|
|
940
|
+
fetcher: function fetcher(_ref) {
|
|
941
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
942
|
+
var input, fetch, categoryId, _data$collections$edg, _data$collections, data, _data;
|
|
943
|
+
return _regenerator().w(function (_context) {
|
|
944
|
+
while (1) switch (_context.n) {
|
|
945
|
+
case 0:
|
|
946
|
+
input = _ref.input, fetch = _ref.fetch;
|
|
947
|
+
categoryId = input.categoryId;
|
|
948
|
+
if (categoryId) {
|
|
949
|
+
_context.n = 2;
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
_context.n = 1;
|
|
953
|
+
return fetch({
|
|
954
|
+
query: CollectionMany,
|
|
955
|
+
variables: {
|
|
956
|
+
first: 250
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
case 1:
|
|
960
|
+
data = _context.v;
|
|
961
|
+
return _context.a(2, (_data$collections$edg = (_data$collections = data.collections) == null || (_data$collections = _data$collections.edges) == null ? void 0 : _data$collections.map(function (_ref2) {
|
|
962
|
+
var node = _ref2.node;
|
|
963
|
+
return normalizeCategory(node);
|
|
964
|
+
})) != null ? _data$collections$edg : []);
|
|
965
|
+
case 2:
|
|
966
|
+
_context.n = 3;
|
|
967
|
+
return fetch({
|
|
968
|
+
query: CollectionOne,
|
|
969
|
+
variables: {
|
|
970
|
+
categoryId: categoryId
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
case 3:
|
|
974
|
+
_data = _context.v;
|
|
975
|
+
return _context.a(2, !!(_data != null && _data.collection) ? [normalizeCategory(_data == null ? void 0 : _data.collection)] : []);
|
|
976
|
+
case 4:
|
|
977
|
+
return _context.a(2);
|
|
978
|
+
}
|
|
979
|
+
}, _callee);
|
|
980
|
+
}))();
|
|
981
|
+
},
|
|
982
|
+
useHook: function useHook(_ref3) {
|
|
983
|
+
var useData = _ref3.useData;
|
|
984
|
+
return function (input) {
|
|
985
|
+
var response = useData({
|
|
986
|
+
input: [["categoryId", input == null ? void 0 : input.categoryId]],
|
|
987
|
+
swrOptions: _extends({
|
|
988
|
+
revalidateOnFocus: false
|
|
989
|
+
}, input == null ? void 0 : input.swrOptions)
|
|
990
|
+
});
|
|
991
|
+
return React.useMemo(function () {
|
|
992
|
+
return Object.create(response, {
|
|
993
|
+
isEmpty: {
|
|
994
|
+
get: function get() {
|
|
995
|
+
var _response$data$length, _response$data;
|
|
996
|
+
return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
|
|
997
|
+
},
|
|
998
|
+
enumerable: true
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
}, [response]);
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
var handler$5 = {
|
|
1007
|
+
fetchOptions: {
|
|
1008
|
+
query: getAllProductVendors
|
|
1009
|
+
},
|
|
1010
|
+
fetcher: function fetcher(_ref) {
|
|
1011
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1012
|
+
return _regenerator().w(function (_context) {
|
|
1013
|
+
while (1) switch (_context.n) {
|
|
1014
|
+
case 0:
|
|
1015
|
+
return _context.a(2, []);
|
|
1016
|
+
}
|
|
1017
|
+
}, _callee);
|
|
1018
|
+
}))();
|
|
1019
|
+
},
|
|
1020
|
+
useHook: function useHook(_ref2) {
|
|
1021
|
+
var useData = _ref2.useData;
|
|
1022
|
+
return function (input) {
|
|
1023
|
+
var response = useData({
|
|
1024
|
+
swrOptions: _extends({
|
|
1025
|
+
revalidateOnFocus: false
|
|
1026
|
+
}, input == null ? void 0 : input.swrOptions)
|
|
1027
|
+
});
|
|
1028
|
+
return React.useMemo(function () {
|
|
1029
|
+
return Object.create(response, {
|
|
1030
|
+
isEmpty: {
|
|
1031
|
+
get: function get() {
|
|
1032
|
+
var _response$data$length, _response$data;
|
|
1033
|
+
return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
|
|
1034
|
+
},
|
|
1035
|
+
enumerable: true
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}, [response]);
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
var handler$6 = {
|
|
1044
|
+
fetchOptions: {
|
|
1045
|
+
query: ProductMany
|
|
1046
|
+
},
|
|
1047
|
+
fetcher: function fetcher(_ref) {
|
|
1048
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1049
|
+
var input, options, fetch, categoryId, brandId, data, edges, _data$collection$prod, _data$collection, _data$products$edges, _data$products;
|
|
1050
|
+
return _regenerator().w(function (_context) {
|
|
1051
|
+
while (1) switch (_context.n) {
|
|
1052
|
+
case 0:
|
|
1053
|
+
input = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
1054
|
+
categoryId = input.categoryId, brandId = input.brandId;
|
|
1055
|
+
_context.n = 1;
|
|
1056
|
+
return fetch({
|
|
1057
|
+
query: categoryId ? CollectionOne : options.query,
|
|
1058
|
+
method: options == null ? void 0 : options.method,
|
|
1059
|
+
variables: getSearchVariables(input)
|
|
1060
|
+
});
|
|
1061
|
+
case 1:
|
|
1062
|
+
data = _context.v;
|
|
1063
|
+
if (categoryId) {
|
|
1064
|
+
edges = (_data$collection$prod = (_data$collection = data.collection) == null || (_data$collection = _data$collection.products) == null ? void 0 : _data$collection.edges) != null ? _data$collection$prod : [];
|
|
1065
|
+
// FIXME @zaiste, no `vendor` in Saleor
|
|
1066
|
+
// if (brandId) {
|
|
1067
|
+
// edges = edges.filter(
|
|
1068
|
+
// ({ node: { vendor } }: ProductCountableEdge) =>
|
|
1069
|
+
// vendor.replace(/\s+/g, '-').toLowerCase() === brandId
|
|
1070
|
+
// )
|
|
1071
|
+
// }
|
|
1072
|
+
} else {
|
|
1073
|
+
edges = (_data$products$edges = (_data$products = data.products) == null ? void 0 : _data$products.edges) != null ? _data$products$edges : [];
|
|
1074
|
+
}
|
|
1075
|
+
return _context.a(2, {
|
|
1076
|
+
products: edges.map(function (_ref2) {
|
|
1077
|
+
var node = _ref2.node;
|
|
1078
|
+
return normalizeProduct(node);
|
|
1079
|
+
}),
|
|
1080
|
+
found: !!edges.length
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
}, _callee);
|
|
1084
|
+
}))();
|
|
1085
|
+
},
|
|
1086
|
+
useHook: function useHook(_ref3) {
|
|
1087
|
+
var useData = _ref3.useData;
|
|
1088
|
+
return function (input) {
|
|
1089
|
+
if (input === void 0) {
|
|
1090
|
+
input = {};
|
|
1091
|
+
}
|
|
1092
|
+
return useData({
|
|
1093
|
+
input: [["search", input.search], ["categoryId", input.categoryId], ["brandId", input.brandId], ["sort", input.sort], ["count", input.count]],
|
|
1094
|
+
swrOptions: _extends({
|
|
1095
|
+
revalidateOnFocus: false
|
|
1096
|
+
}, input.swrOptions)
|
|
1097
|
+
});
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
var ProductOneById = /* GraphQL */"\n query ProductOneById($id: ID!, $channel: String = \"default-channel\") {\n product(id: $id, channel: $channel) {\n\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }";
|
|
1103
|
+
|
|
1104
|
+
var handler$7 = {
|
|
1105
|
+
fetchOptions: {
|
|
1106
|
+
query: ProductOneById
|
|
1107
|
+
},
|
|
1108
|
+
fetcher: function fetcher(_ref) {
|
|
1109
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1110
|
+
var input, fetch, id, data, response;
|
|
1111
|
+
return _regenerator().w(function (_context) {
|
|
1112
|
+
while (1) switch (_context.n) {
|
|
1113
|
+
case 0:
|
|
1114
|
+
input = _ref.input, fetch = _ref.fetch;
|
|
1115
|
+
id = input.id;
|
|
1116
|
+
if (id) {
|
|
1117
|
+
_context.n = 1;
|
|
1118
|
+
break;
|
|
1119
|
+
}
|
|
1120
|
+
return _context.a(2, null);
|
|
1121
|
+
case 1:
|
|
1122
|
+
_context.n = 2;
|
|
1123
|
+
return fetch({
|
|
1124
|
+
query: ProductOneById,
|
|
1125
|
+
variables: {
|
|
1126
|
+
id: id
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
case 2:
|
|
1130
|
+
data = _context.v;
|
|
1131
|
+
if (data.product) {
|
|
1132
|
+
_context.n = 4;
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
_context.n = 3;
|
|
1136
|
+
return fetch({
|
|
1137
|
+
query: ProductOneBySlug,
|
|
1138
|
+
variables: {
|
|
1139
|
+
slug: id
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
case 3:
|
|
1143
|
+
response = _context.v;
|
|
1144
|
+
return _context.a(2, response.product ? normalizeProduct(response.product) : null);
|
|
1145
|
+
case 4:
|
|
1146
|
+
return _context.a(2, data.product ? normalizeProduct(data.product) : null);
|
|
1147
|
+
}
|
|
1148
|
+
}, _callee);
|
|
1149
|
+
}))();
|
|
1150
|
+
},
|
|
1151
|
+
useHook: function useHook(_ref2) {
|
|
1152
|
+
var useData = _ref2.useData;
|
|
1153
|
+
return function (input) {
|
|
1154
|
+
if (input === void 0) {
|
|
1155
|
+
input = {};
|
|
1156
|
+
}
|
|
1157
|
+
return useData({
|
|
1158
|
+
input: [["id", input.id]],
|
|
1159
|
+
swrOptions: _extends({
|
|
1160
|
+
revalidateOnFocus: false
|
|
1161
|
+
}, input.swrOptions)
|
|
1162
|
+
});
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
|
|
1167
|
+
var _excluded$1 = ["locale"];
|
|
1168
|
+
var getFetcher = function getFetcher(saleorApiUrl) {
|
|
1169
|
+
return /*#__PURE__*/function () {
|
|
1170
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
1171
|
+
var _ref$url, url, _ref$method, method, query, variables, _ref3, vars, token, _t;
|
|
1172
|
+
return _regenerator().w(function (_context) {
|
|
1173
|
+
while (1) switch (_context.n) {
|
|
1174
|
+
case 0:
|
|
1175
|
+
_ref$url = _ref.url, url = _ref$url === void 0 ? saleorApiUrl : _ref$url, _ref$method = _ref.method, method = _ref$method === void 0 ? 'POST' : _ref$method, query = _ref.query, variables = _ref.variables;
|
|
1176
|
+
_ref3 = variables != null ? variables : {}, vars = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
|
|
1177
|
+
token = getToken();
|
|
1178
|
+
_t = handleFetchResponse;
|
|
1179
|
+
_context.n = 1;
|
|
1180
|
+
return fetch(url, {
|
|
1181
|
+
method: method,
|
|
1182
|
+
body: JSON.stringify({
|
|
1183
|
+
query: query,
|
|
1184
|
+
variables: vars
|
|
1185
|
+
}),
|
|
1186
|
+
headers: {
|
|
1187
|
+
Authorization: "JWT " + token,
|
|
1188
|
+
'Content-Type': 'application/json'
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
case 1:
|
|
1192
|
+
return _context.a(2, _t(_context.v));
|
|
1193
|
+
}
|
|
1194
|
+
}, _callee);
|
|
1195
|
+
}));
|
|
1196
|
+
return function (_x) {
|
|
1197
|
+
return _ref2.apply(this, arguments);
|
|
1198
|
+
};
|
|
1199
|
+
}();
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
/*
|
|
1203
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
1204
|
+
Changes:
|
|
1205
|
+
- Removed customer and auth hooks.
|
|
1206
|
+
- Added saleor_api_url parameters.
|
|
1207
|
+
*/
|
|
1208
|
+
var getSaleorProvider = function getSaleorProvider(saleorApiUrl) {
|
|
1209
|
+
return {
|
|
1210
|
+
locale: 'en-us',
|
|
1211
|
+
cartCookie: CHECKOUT_ID_COOKIE,
|
|
1212
|
+
fetcher: getFetcher(saleorApiUrl),
|
|
1213
|
+
cart: {
|
|
1214
|
+
useCart: handler,
|
|
1215
|
+
useAddItem: handler$1,
|
|
1216
|
+
useUpdateItem: handler$3,
|
|
1217
|
+
useRemoveItem: handler$2
|
|
1218
|
+
},
|
|
1219
|
+
products: {
|
|
1220
|
+
useSearch: handler$6,
|
|
1221
|
+
useProduct: handler$7
|
|
1222
|
+
},
|
|
1223
|
+
site: {
|
|
1224
|
+
useCategories: handler$4,
|
|
1225
|
+
useBrands: handler$5
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
/*
|
|
1231
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/saleor/src
|
|
1232
|
+
Changes:
|
|
1233
|
+
- Added saleor_api_url parameter.
|
|
1234
|
+
*/
|
|
1235
|
+
var useCommerce = function useCommerce() {
|
|
1236
|
+
return commerce.useCommerce();
|
|
1237
|
+
};
|
|
1238
|
+
var getCommerceProvider = function getCommerceProvider(saleorApiUrl) {
|
|
1239
|
+
return commerce.getCommerceProvider(getSaleorProvider(saleorApiUrl));
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
var globalContextName = "daouy-commerce-saleor-provider";
|
|
1243
|
+
var commerceProviderMeta = /*#__PURE__*/_extends({
|
|
1244
|
+
name: globalContextName,
|
|
1245
|
+
displayName: "Saleor Provider",
|
|
1246
|
+
props: {
|
|
1247
|
+
saleorApiUrl: {
|
|
1248
|
+
type: "string",
|
|
1249
|
+
defaultValue: "https://vercel.saleor.cloud/graphql/"
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}, {
|
|
1253
|
+
globalActions: commerce.globalActionsRegistrations
|
|
1254
|
+
}, {
|
|
1255
|
+
importPath: "@daouypkgs/commerce-saleor",
|
|
1256
|
+
importName: "CommerceProviderComponent"
|
|
1257
|
+
});
|
|
1258
|
+
function CommerceProviderComponent(props) {
|
|
1259
|
+
var saleorApiUrl = props.saleorApiUrl,
|
|
1260
|
+
children = props.children;
|
|
1261
|
+
var CommerceProvider = React__default.useMemo(function () {
|
|
1262
|
+
return getCommerceProvider(saleorApiUrl);
|
|
1263
|
+
}, [saleorApiUrl]);
|
|
1264
|
+
return React__default.createElement(CommerceProvider, null, React__default.createElement(commerce.CartActionsProvider, {
|
|
1265
|
+
globalContextName: globalContextName
|
|
1266
|
+
}, children));
|
|
1267
|
+
}
|
|
1268
|
+
function registerCommerceProvider(loader, customCommerceProviderMeta) {
|
|
1269
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1270
|
+
return loader ? loader.registerGlobalContext.apply(loader, arguments) : registerGlobalContext.apply(void 0, arguments);
|
|
1271
|
+
};
|
|
1272
|
+
doRegisterComponent(CommerceProviderComponent, customCommerceProviderMeta != null ? customCommerceProviderMeta : commerceProviderMeta);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
function registerAll(loader) {
|
|
1276
|
+
registerCommerceProvider(loader);
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
exports.CommerceProviderComponent = CommerceProviderComponent;
|
|
1280
|
+
exports.getCommerceProvider = getCommerceProvider;
|
|
1281
|
+
exports.registerAll = registerAll;
|
|
1282
|
+
exports.registerCommerceProvider = registerCommerceProvider;
|
|
1283
|
+
exports.useCommerce = useCommerce;
|
|
1284
|
+
//# sourceMappingURL=commerce-saleor.cjs.development.js.map
|