@plasmicpkgs/commerce-swell 0.0.234 → 0.0.235
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/dist/commerce-swell.cjs.development.js +178 -176
- package/dist/commerce-swell.cjs.development.js.map +1 -1
- package/dist/commerce-swell.cjs.production.min.js +1 -1
- package/dist/commerce-swell.cjs.production.min.js.map +1 -1
- package/dist/commerce-swell.esm.js +178 -175
- package/dist/commerce-swell.esm.js.map +1 -1
- package/dist/provider.d.ts +4 -5
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
|
|
2
2
|
import { CommerceError, useCart, ValidationError, getCommerceProvider as getCommerceProvider$1, useCommerce as useCommerce$1, CartActionsProvider, globalActionsRegistrations } from '@plasmicpkgs/commerce';
|
|
3
3
|
import React, { useMemo, useCallback } from 'react';
|
|
4
|
-
import swell
|
|
4
|
+
import swell from 'swell-js';
|
|
5
5
|
import Cookies from 'js-cookie';
|
|
6
6
|
import debounce from 'debounce';
|
|
7
7
|
|
|
@@ -1000,6 +1000,121 @@ var handler$3 = {
|
|
|
1000
1000
|
}
|
|
1001
1001
|
};
|
|
1002
1002
|
|
|
1003
|
+
var fetcher = /*#__PURE__*/function () {
|
|
1004
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
1005
|
+
var _ref$method, method, variables, query, callSwell, _callSwell;
|
|
1006
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1007
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1008
|
+
case 0:
|
|
1009
|
+
_callSwell = function _callSwell3() {
|
|
1010
|
+
_callSwell = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1011
|
+
var arg1, arg2, response, _response;
|
|
1012
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1013
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1014
|
+
case 0:
|
|
1015
|
+
if (!Array.isArray(variables)) {
|
|
1016
|
+
_context.next = 9;
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
arg1 = variables[0];
|
|
1020
|
+
arg2 = variables[1];
|
|
1021
|
+
_context.next = 5;
|
|
1022
|
+
return swell[query][method](arg1, arg2);
|
|
1023
|
+
case 5:
|
|
1024
|
+
response = _context.sent;
|
|
1025
|
+
return _context.abrupt("return", handleFetchResponse(response));
|
|
1026
|
+
case 9:
|
|
1027
|
+
_context.next = 11;
|
|
1028
|
+
return swell[query][method](variables);
|
|
1029
|
+
case 11:
|
|
1030
|
+
_response = _context.sent;
|
|
1031
|
+
return _context.abrupt("return", handleFetchResponse(_response));
|
|
1032
|
+
case 13:
|
|
1033
|
+
case "end":
|
|
1034
|
+
return _context.stop();
|
|
1035
|
+
}
|
|
1036
|
+
}, _callee);
|
|
1037
|
+
}));
|
|
1038
|
+
return _callSwell.apply(this, arguments);
|
|
1039
|
+
};
|
|
1040
|
+
callSwell = function _callSwell2() {
|
|
1041
|
+
return _callSwell.apply(this, arguments);
|
|
1042
|
+
};
|
|
1043
|
+
_ref$method = _ref.method, method = _ref$method === void 0 ? 'get' : _ref$method, variables = _ref.variables, query = _ref.query;
|
|
1044
|
+
if (!(query && query in swell)) {
|
|
1045
|
+
_context2.next = 9;
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
_context2.next = 6;
|
|
1049
|
+
return callSwell();
|
|
1050
|
+
case 6:
|
|
1051
|
+
return _context2.abrupt("return", _context2.sent);
|
|
1052
|
+
case 9:
|
|
1053
|
+
throw new CommerceError({
|
|
1054
|
+
message: 'Invalid query argument!'
|
|
1055
|
+
});
|
|
1056
|
+
case 10:
|
|
1057
|
+
case "end":
|
|
1058
|
+
return _context2.stop();
|
|
1059
|
+
}
|
|
1060
|
+
}, _callee2);
|
|
1061
|
+
}));
|
|
1062
|
+
return function fetcher(_x) {
|
|
1063
|
+
return _ref2.apply(this, arguments);
|
|
1064
|
+
};
|
|
1065
|
+
}();
|
|
1066
|
+
|
|
1067
|
+
var handler$4 = {
|
|
1068
|
+
fetchOptions: {
|
|
1069
|
+
query: 'products',
|
|
1070
|
+
method: 'get'
|
|
1071
|
+
},
|
|
1072
|
+
fetcher: function fetcher(_ref) {
|
|
1073
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1074
|
+
var input, options, fetch, id, product;
|
|
1075
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1076
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1077
|
+
case 0:
|
|
1078
|
+
input = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
1079
|
+
id = input.id;
|
|
1080
|
+
_context.next = 4;
|
|
1081
|
+
return fetch({
|
|
1082
|
+
query: options.query,
|
|
1083
|
+
method: options.method,
|
|
1084
|
+
variables: [id]
|
|
1085
|
+
});
|
|
1086
|
+
case 4:
|
|
1087
|
+
product = _context.sent;
|
|
1088
|
+
if (product) {
|
|
1089
|
+
_context.next = 7;
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
return _context.abrupt("return", null);
|
|
1093
|
+
case 7:
|
|
1094
|
+
return _context.abrupt("return", normalizeProduct(product));
|
|
1095
|
+
case 8:
|
|
1096
|
+
case "end":
|
|
1097
|
+
return _context.stop();
|
|
1098
|
+
}
|
|
1099
|
+
}, _callee);
|
|
1100
|
+
}))();
|
|
1101
|
+
},
|
|
1102
|
+
useHook: function useHook(_ref2) {
|
|
1103
|
+
var useData = _ref2.useData;
|
|
1104
|
+
return function (input) {
|
|
1105
|
+
if (input === void 0) {
|
|
1106
|
+
input = {};
|
|
1107
|
+
}
|
|
1108
|
+
return useData({
|
|
1109
|
+
input: [['id', input.id]],
|
|
1110
|
+
swrOptions: _extends({
|
|
1111
|
+
revalidateOnFocus: false
|
|
1112
|
+
}, input.swrOptions)
|
|
1113
|
+
});
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1003
1118
|
function ensure(x, msg) {
|
|
1004
1119
|
if (msg === void 0) {
|
|
1005
1120
|
msg = "";
|
|
@@ -1044,7 +1159,7 @@ var topologicalSortForCategoryTree = function topologicalSortForCategoryTree(cat
|
|
|
1044
1159
|
});
|
|
1045
1160
|
};
|
|
1046
1161
|
|
|
1047
|
-
var handler$
|
|
1162
|
+
var handler$5 = {
|
|
1048
1163
|
fetchOptions: {
|
|
1049
1164
|
query: "products",
|
|
1050
1165
|
method: "list"
|
|
@@ -1112,35 +1227,57 @@ var handler$4 = {
|
|
|
1112
1227
|
}
|
|
1113
1228
|
};
|
|
1114
1229
|
|
|
1115
|
-
var handler$
|
|
1230
|
+
var handler$6 = {
|
|
1116
1231
|
fetchOptions: {
|
|
1117
|
-
query:
|
|
1118
|
-
method:
|
|
1232
|
+
query: "attributes",
|
|
1233
|
+
method: "get"
|
|
1119
1234
|
},
|
|
1120
1235
|
fetcher: function fetcher(_ref) {
|
|
1121
1236
|
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1122
|
-
var
|
|
1237
|
+
var _yield$fetch$values, _yield$fetch;
|
|
1238
|
+
var fetch, vendors;
|
|
1123
1239
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1124
1240
|
while (1) switch (_context.prev = _context.next) {
|
|
1125
1241
|
case 0:
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
_context.next = 4;
|
|
1242
|
+
fetch = _ref.fetch;
|
|
1243
|
+
_context.next = 3;
|
|
1129
1244
|
return fetch({
|
|
1130
|
-
query:
|
|
1131
|
-
method:
|
|
1132
|
-
variables:
|
|
1245
|
+
query: "attributes",
|
|
1246
|
+
method: "get",
|
|
1247
|
+
variables: "brand"
|
|
1133
1248
|
});
|
|
1134
|
-
case
|
|
1135
|
-
|
|
1136
|
-
if (
|
|
1137
|
-
_context.next =
|
|
1249
|
+
case 3:
|
|
1250
|
+
_context.t0 = _yield$fetch = _context.sent;
|
|
1251
|
+
if (!(_context.t0 == null)) {
|
|
1252
|
+
_context.next = 8;
|
|
1138
1253
|
break;
|
|
1139
1254
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1255
|
+
_context.t1 = void 0;
|
|
1256
|
+
_context.next = 9;
|
|
1257
|
+
break;
|
|
1143
1258
|
case 8:
|
|
1259
|
+
_context.t1 = _yield$fetch.values;
|
|
1260
|
+
case 9:
|
|
1261
|
+
_context.t2 = _yield$fetch$values = _context.t1;
|
|
1262
|
+
if (!(_context.t2 != null)) {
|
|
1263
|
+
_context.next = 14;
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
_context.t3 = _yield$fetch$values;
|
|
1267
|
+
_context.next = 15;
|
|
1268
|
+
break;
|
|
1269
|
+
case 14:
|
|
1270
|
+
_context.t3 = [];
|
|
1271
|
+
case 15:
|
|
1272
|
+
vendors = _context.t3;
|
|
1273
|
+
return _context.abrupt("return", Array.from(new Set(vendors).values()).map(function (v) {
|
|
1274
|
+
return {
|
|
1275
|
+
entityId: v,
|
|
1276
|
+
name: v,
|
|
1277
|
+
path: "brands/" + v
|
|
1278
|
+
};
|
|
1279
|
+
}));
|
|
1280
|
+
case 17:
|
|
1144
1281
|
case "end":
|
|
1145
1282
|
return _context.stop();
|
|
1146
1283
|
}
|
|
@@ -1150,20 +1287,27 @@ var handler$5 = {
|
|
|
1150
1287
|
useHook: function useHook(_ref2) {
|
|
1151
1288
|
var useData = _ref2.useData;
|
|
1152
1289
|
return function (input) {
|
|
1153
|
-
|
|
1154
|
-
input = {};
|
|
1155
|
-
}
|
|
1156
|
-
return useData({
|
|
1157
|
-
input: [['id', input.id]],
|
|
1290
|
+
var response = useData({
|
|
1158
1291
|
swrOptions: _extends({
|
|
1159
1292
|
revalidateOnFocus: false
|
|
1160
|
-
}, input.swrOptions)
|
|
1293
|
+
}, input == null ? void 0 : input.swrOptions)
|
|
1161
1294
|
});
|
|
1295
|
+
return useMemo(function () {
|
|
1296
|
+
return Object.create(response, {
|
|
1297
|
+
isEmpty: {
|
|
1298
|
+
get: function get() {
|
|
1299
|
+
var _response$data$length, _response$data;
|
|
1300
|
+
return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
|
|
1301
|
+
},
|
|
1302
|
+
enumerable: true
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
}, [response]);
|
|
1162
1306
|
};
|
|
1163
1307
|
}
|
|
1164
1308
|
};
|
|
1165
1309
|
|
|
1166
|
-
var handler$
|
|
1310
|
+
var handler$7 = {
|
|
1167
1311
|
fetchOptions: {
|
|
1168
1312
|
query: "categories",
|
|
1169
1313
|
method: "get"
|
|
@@ -1290,156 +1434,15 @@ var handler$6 = {
|
|
|
1290
1434
|
}
|
|
1291
1435
|
};
|
|
1292
1436
|
|
|
1293
|
-
var handler$7 = {
|
|
1294
|
-
fetchOptions: {
|
|
1295
|
-
query: "attributes",
|
|
1296
|
-
method: "get"
|
|
1297
|
-
},
|
|
1298
|
-
fetcher: function fetcher(_ref) {
|
|
1299
|
-
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1300
|
-
var _yield$fetch$values, _yield$fetch;
|
|
1301
|
-
var fetch, vendors;
|
|
1302
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1303
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1304
|
-
case 0:
|
|
1305
|
-
fetch = _ref.fetch;
|
|
1306
|
-
_context.next = 3;
|
|
1307
|
-
return fetch({
|
|
1308
|
-
query: "attributes",
|
|
1309
|
-
method: "get",
|
|
1310
|
-
variables: "brand"
|
|
1311
|
-
});
|
|
1312
|
-
case 3:
|
|
1313
|
-
_context.t0 = _yield$fetch = _context.sent;
|
|
1314
|
-
if (!(_context.t0 == null)) {
|
|
1315
|
-
_context.next = 8;
|
|
1316
|
-
break;
|
|
1317
|
-
}
|
|
1318
|
-
_context.t1 = void 0;
|
|
1319
|
-
_context.next = 9;
|
|
1320
|
-
break;
|
|
1321
|
-
case 8:
|
|
1322
|
-
_context.t1 = _yield$fetch.values;
|
|
1323
|
-
case 9:
|
|
1324
|
-
_context.t2 = _yield$fetch$values = _context.t1;
|
|
1325
|
-
if (!(_context.t2 != null)) {
|
|
1326
|
-
_context.next = 14;
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
_context.t3 = _yield$fetch$values;
|
|
1330
|
-
_context.next = 15;
|
|
1331
|
-
break;
|
|
1332
|
-
case 14:
|
|
1333
|
-
_context.t3 = [];
|
|
1334
|
-
case 15:
|
|
1335
|
-
vendors = _context.t3;
|
|
1336
|
-
return _context.abrupt("return", Array.from(new Set(vendors).values()).map(function (v) {
|
|
1337
|
-
return {
|
|
1338
|
-
entityId: v,
|
|
1339
|
-
name: v,
|
|
1340
|
-
path: "brands/" + v
|
|
1341
|
-
};
|
|
1342
|
-
}));
|
|
1343
|
-
case 17:
|
|
1344
|
-
case "end":
|
|
1345
|
-
return _context.stop();
|
|
1346
|
-
}
|
|
1347
|
-
}, _callee);
|
|
1348
|
-
}))();
|
|
1349
|
-
},
|
|
1350
|
-
useHook: function useHook(_ref2) {
|
|
1351
|
-
var useData = _ref2.useData;
|
|
1352
|
-
return function (input) {
|
|
1353
|
-
var response = useData({
|
|
1354
|
-
swrOptions: _extends({
|
|
1355
|
-
revalidateOnFocus: false
|
|
1356
|
-
}, input == null ? void 0 : input.swrOptions)
|
|
1357
|
-
});
|
|
1358
|
-
return useMemo(function () {
|
|
1359
|
-
return Object.create(response, {
|
|
1360
|
-
isEmpty: {
|
|
1361
|
-
get: function get() {
|
|
1362
|
-
var _response$data$length, _response$data;
|
|
1363
|
-
return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
|
|
1364
|
-
},
|
|
1365
|
-
enumerable: true
|
|
1366
|
-
}
|
|
1367
|
-
});
|
|
1368
|
-
}, [response]);
|
|
1369
|
-
};
|
|
1370
|
-
}
|
|
1371
|
-
};
|
|
1372
|
-
|
|
1373
|
-
var fetcher = /*#__PURE__*/function () {
|
|
1374
|
-
var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
1375
|
-
var _ref$method, method, variables, query, callSwell, _callSwell;
|
|
1376
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1377
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1378
|
-
case 0:
|
|
1379
|
-
_callSwell = function _callSwell3() {
|
|
1380
|
-
_callSwell = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1381
|
-
var arg1, arg2, response, _response;
|
|
1382
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1383
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1384
|
-
case 0:
|
|
1385
|
-
if (!Array.isArray(variables)) {
|
|
1386
|
-
_context.next = 9;
|
|
1387
|
-
break;
|
|
1388
|
-
}
|
|
1389
|
-
arg1 = variables[0];
|
|
1390
|
-
arg2 = variables[1];
|
|
1391
|
-
_context.next = 5;
|
|
1392
|
-
return swell[query][method](arg1, arg2);
|
|
1393
|
-
case 5:
|
|
1394
|
-
response = _context.sent;
|
|
1395
|
-
return _context.abrupt("return", handleFetchResponse(response));
|
|
1396
|
-
case 9:
|
|
1397
|
-
_context.next = 11;
|
|
1398
|
-
return swell[query][method](variables);
|
|
1399
|
-
case 11:
|
|
1400
|
-
_response = _context.sent;
|
|
1401
|
-
return _context.abrupt("return", handleFetchResponse(_response));
|
|
1402
|
-
case 13:
|
|
1403
|
-
case "end":
|
|
1404
|
-
return _context.stop();
|
|
1405
|
-
}
|
|
1406
|
-
}, _callee);
|
|
1407
|
-
}));
|
|
1408
|
-
return _callSwell.apply(this, arguments);
|
|
1409
|
-
};
|
|
1410
|
-
callSwell = function _callSwell2() {
|
|
1411
|
-
return _callSwell.apply(this, arguments);
|
|
1412
|
-
};
|
|
1413
|
-
_ref$method = _ref.method, method = _ref$method === void 0 ? 'get' : _ref$method, variables = _ref.variables, query = _ref.query;
|
|
1414
|
-
if (!(query && query in swell)) {
|
|
1415
|
-
_context2.next = 9;
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1418
|
-
_context2.next = 6;
|
|
1419
|
-
return callSwell();
|
|
1420
|
-
case 6:
|
|
1421
|
-
return _context2.abrupt("return", _context2.sent);
|
|
1422
|
-
case 9:
|
|
1423
|
-
throw new CommerceError({
|
|
1424
|
-
message: 'Invalid query argument!'
|
|
1425
|
-
});
|
|
1426
|
-
case 10:
|
|
1427
|
-
case "end":
|
|
1428
|
-
return _context2.stop();
|
|
1429
|
-
}
|
|
1430
|
-
}, _callee2);
|
|
1431
|
-
}));
|
|
1432
|
-
return function fetcher(_x) {
|
|
1433
|
-
return _ref2.apply(this, arguments);
|
|
1434
|
-
};
|
|
1435
|
-
}();
|
|
1436
|
-
|
|
1437
1437
|
/*
|
|
1438
1438
|
Forked from https://github.com/vercel/commerce/tree/main/packages/swell/src
|
|
1439
1439
|
Changes: Added storeId and publicKey parameters
|
|
1440
1440
|
*/
|
|
1441
1441
|
var getSwellProvider = function getSwellProvider(storeId, publicKey) {
|
|
1442
|
-
init
|
|
1442
|
+
// Their types claim `init` is a named export, but examining the JS files in
|
|
1443
|
+
// dist/, you can see it's actually a function on the default export.
|
|
1444
|
+
// @ts-expect-error swell-js types are wrong
|
|
1445
|
+
swell.init(storeId, publicKey);
|
|
1443
1446
|
return {
|
|
1444
1447
|
locale: "en-us",
|
|
1445
1448
|
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
|
|
@@ -1452,12 +1455,12 @@ var getSwellProvider = function getSwellProvider(storeId, publicKey) {
|
|
|
1452
1455
|
useRemoveItem: handler$2
|
|
1453
1456
|
},
|
|
1454
1457
|
products: {
|
|
1455
|
-
useSearch: handler$
|
|
1456
|
-
useProduct: handler$
|
|
1458
|
+
useSearch: handler$5,
|
|
1459
|
+
useProduct: handler$4
|
|
1457
1460
|
},
|
|
1458
1461
|
site: {
|
|
1459
|
-
useCategories: handler$
|
|
1460
|
-
useBrands: handler$
|
|
1462
|
+
useCategories: handler$7,
|
|
1463
|
+
useBrands: handler$6
|
|
1461
1464
|
},
|
|
1462
1465
|
extraFeatures: {
|
|
1463
1466
|
includeSubCategories: true
|