@cmssy/next 2.0.0 → 2.1.0
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/index.cjs +39 -12
- package/dist/index.js +39 -12
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1133,6 +1133,8 @@ var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
|
|
|
1133
1133
|
orderNumber
|
|
1134
1134
|
status
|
|
1135
1135
|
subtotal
|
|
1136
|
+
discount
|
|
1137
|
+
appliedDiscount { code type value amount }
|
|
1136
1138
|
tax
|
|
1137
1139
|
total
|
|
1138
1140
|
currency
|
|
@@ -1377,24 +1379,42 @@ function plainObject2(value) {
|
|
|
1377
1379
|
function optionalStr(value) {
|
|
1378
1380
|
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
1379
1381
|
}
|
|
1382
|
+
var ADDRESS_REQUIRED = [
|
|
1383
|
+
"name",
|
|
1384
|
+
"line1",
|
|
1385
|
+
"postalCode",
|
|
1386
|
+
"city",
|
|
1387
|
+
"country"
|
|
1388
|
+
];
|
|
1389
|
+
var CmssyAddressError = class extends Error {
|
|
1390
|
+
constructor(missing) {
|
|
1391
|
+
super(
|
|
1392
|
+
`cmssy: shippingAddress is missing required field(s): ${missing.join(
|
|
1393
|
+
", "
|
|
1394
|
+
)}. Expected { name, line1, postalCode, city, country } (plus optional company, line2, region, phone, vatId).`
|
|
1395
|
+
);
|
|
1396
|
+
this.missing = missing;
|
|
1397
|
+
this.name = "CmssyAddressError";
|
|
1398
|
+
}
|
|
1399
|
+
missing;
|
|
1400
|
+
};
|
|
1380
1401
|
function shippingAddress(value) {
|
|
1381
|
-
if (
|
|
1402
|
+
if (value === void 0 || value === null) return null;
|
|
1403
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
1404
|
+
throw new CmssyAddressError([...ADDRESS_REQUIRED]);
|
|
1405
|
+
}
|
|
1382
1406
|
const raw = value;
|
|
1383
|
-
const
|
|
1384
|
-
|
|
1385
|
-
const postalCode = optionalStr(raw.postalCode);
|
|
1386
|
-
const city = optionalStr(raw.city);
|
|
1387
|
-
const country = optionalStr(raw.country);
|
|
1388
|
-
if (!name || !line1 || !postalCode || !city || !country) return null;
|
|
1407
|
+
const missing = ADDRESS_REQUIRED.filter((key) => !optionalStr(raw[key]));
|
|
1408
|
+
if (missing.length > 0) throw new CmssyAddressError(missing);
|
|
1389
1409
|
return {
|
|
1390
|
-
name,
|
|
1410
|
+
name: optionalStr(raw.name),
|
|
1391
1411
|
company: optionalStr(raw.company),
|
|
1392
|
-
line1,
|
|
1412
|
+
line1: optionalStr(raw.line1),
|
|
1393
1413
|
line2: optionalStr(raw.line2),
|
|
1394
|
-
postalCode,
|
|
1395
|
-
city,
|
|
1414
|
+
postalCode: optionalStr(raw.postalCode),
|
|
1415
|
+
city: optionalStr(raw.city),
|
|
1396
1416
|
region: optionalStr(raw.region),
|
|
1397
|
-
country,
|
|
1417
|
+
country: optionalStr(raw.country),
|
|
1398
1418
|
phone: optionalStr(raw.phone),
|
|
1399
1419
|
vatId: optionalStr(raw.vatId)
|
|
1400
1420
|
};
|
|
@@ -1505,6 +1525,9 @@ function createCmssyCartRoute(config) {
|
|
|
1505
1525
|
return json2({ message: "Not found." }, 404);
|
|
1506
1526
|
}
|
|
1507
1527
|
} catch (err) {
|
|
1528
|
+
if (err instanceof CmssyAddressError) {
|
|
1529
|
+
return json2({ message: err.message, missing: err.missing }, 400);
|
|
1530
|
+
}
|
|
1508
1531
|
return json2(
|
|
1509
1532
|
{
|
|
1510
1533
|
message: err instanceof Error ? err.message : "Commerce request failed"
|
|
@@ -1610,6 +1633,8 @@ var ORDER_FIELDS = `
|
|
|
1610
1633
|
id
|
|
1611
1634
|
status
|
|
1612
1635
|
subtotal
|
|
1636
|
+
discount
|
|
1637
|
+
appliedDiscount { code type value amount }
|
|
1613
1638
|
tax
|
|
1614
1639
|
total
|
|
1615
1640
|
pricesIncludeTax
|
|
@@ -1647,6 +1672,8 @@ var PUBLIC_ORDER_FIELDS = `
|
|
|
1647
1672
|
paymentStatus
|
|
1648
1673
|
fulfillmentStatus
|
|
1649
1674
|
subtotal
|
|
1675
|
+
discount
|
|
1676
|
+
appliedDiscount { code type value amount }
|
|
1650
1677
|
tax
|
|
1651
1678
|
total
|
|
1652
1679
|
pricesIncludeTax
|
package/dist/index.js
CHANGED
|
@@ -1132,6 +1132,8 @@ var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
|
|
|
1132
1132
|
orderNumber
|
|
1133
1133
|
status
|
|
1134
1134
|
subtotal
|
|
1135
|
+
discount
|
|
1136
|
+
appliedDiscount { code type value amount }
|
|
1135
1137
|
tax
|
|
1136
1138
|
total
|
|
1137
1139
|
currency
|
|
@@ -1376,24 +1378,42 @@ function plainObject2(value) {
|
|
|
1376
1378
|
function optionalStr(value) {
|
|
1377
1379
|
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
1378
1380
|
}
|
|
1381
|
+
var ADDRESS_REQUIRED = [
|
|
1382
|
+
"name",
|
|
1383
|
+
"line1",
|
|
1384
|
+
"postalCode",
|
|
1385
|
+
"city",
|
|
1386
|
+
"country"
|
|
1387
|
+
];
|
|
1388
|
+
var CmssyAddressError = class extends Error {
|
|
1389
|
+
constructor(missing) {
|
|
1390
|
+
super(
|
|
1391
|
+
`cmssy: shippingAddress is missing required field(s): ${missing.join(
|
|
1392
|
+
", "
|
|
1393
|
+
)}. Expected { name, line1, postalCode, city, country } (plus optional company, line2, region, phone, vatId).`
|
|
1394
|
+
);
|
|
1395
|
+
this.missing = missing;
|
|
1396
|
+
this.name = "CmssyAddressError";
|
|
1397
|
+
}
|
|
1398
|
+
missing;
|
|
1399
|
+
};
|
|
1379
1400
|
function shippingAddress(value) {
|
|
1380
|
-
if (
|
|
1401
|
+
if (value === void 0 || value === null) return null;
|
|
1402
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
1403
|
+
throw new CmssyAddressError([...ADDRESS_REQUIRED]);
|
|
1404
|
+
}
|
|
1381
1405
|
const raw = value;
|
|
1382
|
-
const
|
|
1383
|
-
|
|
1384
|
-
const postalCode = optionalStr(raw.postalCode);
|
|
1385
|
-
const city = optionalStr(raw.city);
|
|
1386
|
-
const country = optionalStr(raw.country);
|
|
1387
|
-
if (!name || !line1 || !postalCode || !city || !country) return null;
|
|
1406
|
+
const missing = ADDRESS_REQUIRED.filter((key) => !optionalStr(raw[key]));
|
|
1407
|
+
if (missing.length > 0) throw new CmssyAddressError(missing);
|
|
1388
1408
|
return {
|
|
1389
|
-
name,
|
|
1409
|
+
name: optionalStr(raw.name),
|
|
1390
1410
|
company: optionalStr(raw.company),
|
|
1391
|
-
line1,
|
|
1411
|
+
line1: optionalStr(raw.line1),
|
|
1392
1412
|
line2: optionalStr(raw.line2),
|
|
1393
|
-
postalCode,
|
|
1394
|
-
city,
|
|
1413
|
+
postalCode: optionalStr(raw.postalCode),
|
|
1414
|
+
city: optionalStr(raw.city),
|
|
1395
1415
|
region: optionalStr(raw.region),
|
|
1396
|
-
country,
|
|
1416
|
+
country: optionalStr(raw.country),
|
|
1397
1417
|
phone: optionalStr(raw.phone),
|
|
1398
1418
|
vatId: optionalStr(raw.vatId)
|
|
1399
1419
|
};
|
|
@@ -1504,6 +1524,9 @@ function createCmssyCartRoute(config) {
|
|
|
1504
1524
|
return json2({ message: "Not found." }, 404);
|
|
1505
1525
|
}
|
|
1506
1526
|
} catch (err) {
|
|
1527
|
+
if (err instanceof CmssyAddressError) {
|
|
1528
|
+
return json2({ message: err.message, missing: err.missing }, 400);
|
|
1529
|
+
}
|
|
1507
1530
|
return json2(
|
|
1508
1531
|
{
|
|
1509
1532
|
message: err instanceof Error ? err.message : "Commerce request failed"
|
|
@@ -1609,6 +1632,8 @@ var ORDER_FIELDS = `
|
|
|
1609
1632
|
id
|
|
1610
1633
|
status
|
|
1611
1634
|
subtotal
|
|
1635
|
+
discount
|
|
1636
|
+
appliedDiscount { code type value amount }
|
|
1612
1637
|
tax
|
|
1613
1638
|
total
|
|
1614
1639
|
pricesIncludeTax
|
|
@@ -1646,6 +1671,8 @@ var PUBLIC_ORDER_FIELDS = `
|
|
|
1646
1671
|
paymentStatus
|
|
1647
1672
|
fulfillmentStatus
|
|
1648
1673
|
subtotal
|
|
1674
|
+
discount
|
|
1675
|
+
appliedDiscount { code type value amount }
|
|
1649
1676
|
tax
|
|
1650
1677
|
total
|
|
1651
1678
|
pricesIncludeTax
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/next",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@cmssy/react": "^2.
|
|
44
|
+
"@cmssy/react": "^2.1.0",
|
|
45
45
|
"next": ">=15",
|
|
46
46
|
"react": "^18.2.0 || ^19.0.0",
|
|
47
47
|
"react-dom": "^18.2.0 || ^19.0.0"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"tsup": "^8.3.0",
|
|
56
56
|
"typescript": "^5.6.0",
|
|
57
57
|
"vitest": "^2.1.0",
|
|
58
|
-
"@cmssy/react": "2.
|
|
58
|
+
"@cmssy/react": "2.1.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"jose": "^6.2.3"
|