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