@cmssy/next 1.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 +218 -20
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +218 -21
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -221,11 +221,12 @@ function createCmssyPage(config, blocks, options) {
|
|
|
221
221
|
workspaceSlug: config.workspaceSlug
|
|
222
222
|
};
|
|
223
223
|
const client$1 = react.createCmssyClient(clientConfig);
|
|
224
|
+
const fixedPath = options?.path?.split("/").map((segment) => segment.trim()).filter(Boolean);
|
|
224
225
|
return async function CmssyCatchAllPage({
|
|
225
226
|
params,
|
|
226
227
|
searchParams
|
|
227
228
|
}) {
|
|
228
|
-
const
|
|
229
|
+
const path = fixedPath ?? (params ? (await params).path ?? void 0 : void 0);
|
|
229
230
|
const { isEnabled } = await headers.draftMode();
|
|
230
231
|
const query = searchParams ? await searchParams : {};
|
|
231
232
|
const editMode = isEnabled || hasEditFlag(query[EDIT_QUERY_PARAM]);
|
|
@@ -1095,15 +1096,23 @@ var CART_FIELDS = `
|
|
|
1095
1096
|
subtotal
|
|
1096
1097
|
currency
|
|
1097
1098
|
discountedTotal
|
|
1099
|
+
tax
|
|
1100
|
+
totalGross
|
|
1101
|
+
pricesIncludeTax
|
|
1102
|
+
shippingTotal
|
|
1103
|
+
taxSummary { rateId name rate base amount }
|
|
1104
|
+
shippingMethod { id label price etaLabel }
|
|
1105
|
+
availableShippingMethods { id label price etaLabel }
|
|
1098
1106
|
appliedDiscount { code type value computedAmount }
|
|
1099
1107
|
items {
|
|
1100
1108
|
id
|
|
1101
1109
|
recordId
|
|
1102
1110
|
quantity
|
|
1103
1111
|
variantSelections
|
|
1112
|
+
unitPrice
|
|
1104
1113
|
currentPrice
|
|
1105
1114
|
priceMismatch
|
|
1106
|
-
snapshot { name price currency imageUrl sku }
|
|
1115
|
+
snapshot { name price currency imageUrl sku tiers { minQty price } }
|
|
1107
1116
|
}
|
|
1108
1117
|
`;
|
|
1109
1118
|
var CART_QUERY = `query Cart($workspaceId: ID!) { cart { get(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
@@ -1113,14 +1122,45 @@ var REMOVE_ITEM = `mutation RemoveCartItem($workspaceId: ID!, $itemId: ID!) { ca
|
|
|
1113
1122
|
var CLEAR_CART = `mutation ClearCart($workspaceId: ID!) { cart { clear(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1114
1123
|
var APPLY_DISCOUNT = `mutation ApplyDiscount($workspaceId: ID!, $code: String!) { cart { applyDiscount(workspaceId: $workspaceId, code: $code) { ${CART_FIELDS} } } }`;
|
|
1115
1124
|
var REMOVE_DISCOUNT = `mutation RemoveDiscount($workspaceId: ID!) { cart { removeDiscount(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1125
|
+
var SET_SHIPPING_METHOD = `mutation SetShippingMethod($workspaceId: ID!, $shippingMethodId: String) {
|
|
1126
|
+
cart { setShippingMethod(workspaceId: $workspaceId, shippingMethodId: $shippingMethodId) { ${CART_FIELDS} } }
|
|
1127
|
+
}`;
|
|
1128
|
+
var MERGE_CART = `mutation MergeCart($workspaceId: ID!) { cart { merge(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1116
1129
|
var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
|
|
1117
|
-
cart {
|
|
1130
|
+
cart {
|
|
1131
|
+
checkout(input: $input) {
|
|
1132
|
+
id
|
|
1133
|
+
orderNumber
|
|
1134
|
+
status
|
|
1135
|
+
subtotal
|
|
1136
|
+
discount
|
|
1137
|
+
appliedDiscount { code type value amount }
|
|
1138
|
+
tax
|
|
1139
|
+
total
|
|
1140
|
+
currency
|
|
1141
|
+
customerEmail
|
|
1142
|
+
accessToken
|
|
1143
|
+
poNumber
|
|
1144
|
+
customerNote
|
|
1145
|
+
shippingTotal
|
|
1146
|
+
pricesIncludeTax
|
|
1147
|
+
shippingMethod { id label price }
|
|
1148
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1149
|
+
taxSummary { rateId name rate base amount }
|
|
1150
|
+
items { name sku quantity price listPrice tierMinQty currency taxRate taxAmount }
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1118
1153
|
}`;
|
|
1119
1154
|
var PRODUCT = `query Product($workspaceId: String!, $modelSlug: String!, $filter: JSON) {
|
|
1120
1155
|
public {
|
|
1121
1156
|
model {
|
|
1122
1157
|
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: 1) {
|
|
1123
|
-
items {
|
|
1158
|
+
items {
|
|
1159
|
+
id
|
|
1160
|
+
data
|
|
1161
|
+
priceTiers { minQty price }
|
|
1162
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1163
|
+
}
|
|
1124
1164
|
}
|
|
1125
1165
|
}
|
|
1126
1166
|
}
|
|
@@ -1236,14 +1276,38 @@ async function backendRemoveDiscount(config, ctx) {
|
|
|
1236
1276
|
);
|
|
1237
1277
|
return data.cart.removeDiscount;
|
|
1238
1278
|
}
|
|
1239
|
-
async function
|
|
1279
|
+
async function backendSetShippingMethod(config, ctx, shippingMethodId) {
|
|
1280
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1281
|
+
const data = await request(
|
|
1282
|
+
config,
|
|
1283
|
+
ctx,
|
|
1284
|
+
workspaceId,
|
|
1285
|
+
SET_SHIPPING_METHOD,
|
|
1286
|
+
{ workspaceId, shippingMethodId },
|
|
1287
|
+
"set shipping method"
|
|
1288
|
+
);
|
|
1289
|
+
return data.cart.setShippingMethod;
|
|
1290
|
+
}
|
|
1291
|
+
async function backendMergeCart(config, ctx) {
|
|
1292
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1293
|
+
const data = await request(
|
|
1294
|
+
config,
|
|
1295
|
+
ctx,
|
|
1296
|
+
workspaceId,
|
|
1297
|
+
MERGE_CART,
|
|
1298
|
+
{ workspaceId },
|
|
1299
|
+
"merge cart"
|
|
1300
|
+
);
|
|
1301
|
+
return data.cart.merge;
|
|
1302
|
+
}
|
|
1303
|
+
async function backendCheckout(config, ctx, input) {
|
|
1240
1304
|
const workspaceId = await workspaceIdFor2(config);
|
|
1241
1305
|
const data = await request(
|
|
1242
1306
|
config,
|
|
1243
1307
|
ctx,
|
|
1244
1308
|
workspaceId,
|
|
1245
1309
|
CHECKOUT,
|
|
1246
|
-
{ input: { workspaceId,
|
|
1310
|
+
{ input: { workspaceId, ...input } },
|
|
1247
1311
|
"checkout"
|
|
1248
1312
|
);
|
|
1249
1313
|
return data.cart.checkout;
|
|
@@ -1312,6 +1376,49 @@ function plainObject2(value) {
|
|
|
1312
1376
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1313
1377
|
return value;
|
|
1314
1378
|
}
|
|
1379
|
+
function optionalStr(value) {
|
|
1380
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
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
|
+
};
|
|
1401
|
+
function shippingAddress(value) {
|
|
1402
|
+
if (value === void 0 || value === null) return null;
|
|
1403
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
1404
|
+
throw new CmssyAddressError([...ADDRESS_REQUIRED]);
|
|
1405
|
+
}
|
|
1406
|
+
const raw = value;
|
|
1407
|
+
const missing = ADDRESS_REQUIRED.filter((key) => !optionalStr(raw[key]));
|
|
1408
|
+
if (missing.length > 0) throw new CmssyAddressError(missing);
|
|
1409
|
+
return {
|
|
1410
|
+
name: optionalStr(raw.name),
|
|
1411
|
+
company: optionalStr(raw.company),
|
|
1412
|
+
line1: optionalStr(raw.line1),
|
|
1413
|
+
line2: optionalStr(raw.line2),
|
|
1414
|
+
postalCode: optionalStr(raw.postalCode),
|
|
1415
|
+
city: optionalStr(raw.city),
|
|
1416
|
+
region: optionalStr(raw.region),
|
|
1417
|
+
country: optionalStr(raw.country),
|
|
1418
|
+
phone: optionalStr(raw.phone),
|
|
1419
|
+
vatId: optionalStr(raw.vatId)
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1315
1422
|
function createCmssyCartRoute(config) {
|
|
1316
1423
|
async function ensureCartToken() {
|
|
1317
1424
|
const jar = await headers.cookies();
|
|
@@ -1385,12 +1492,23 @@ function createCmssyCartRoute(config) {
|
|
|
1385
1492
|
});
|
|
1386
1493
|
case "remove-discount":
|
|
1387
1494
|
return json2({ cart: await backendRemoveDiscount(config, ctx) });
|
|
1495
|
+
case "set-shipping":
|
|
1496
|
+
return json2({
|
|
1497
|
+
cart: await backendSetShippingMethod(
|
|
1498
|
+
config,
|
|
1499
|
+
ctx,
|
|
1500
|
+
optionalStr(body.shippingMethodId)
|
|
1501
|
+
)
|
|
1502
|
+
});
|
|
1503
|
+
case "merge":
|
|
1504
|
+
return json2({ cart: await backendMergeCart(config, ctx) });
|
|
1388
1505
|
case "checkout": {
|
|
1389
|
-
const order = await backendCheckout(
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1506
|
+
const order = await backendCheckout(config, ctx, {
|
|
1507
|
+
customerEmail: str2(body.customerEmail),
|
|
1508
|
+
poNumber: optionalStr(body.poNumber),
|
|
1509
|
+
customerNote: optionalStr(body.customerNote),
|
|
1510
|
+
shippingAddress: shippingAddress(body.shippingAddress)
|
|
1511
|
+
});
|
|
1394
1512
|
await clearCartToken();
|
|
1395
1513
|
return json2({ order });
|
|
1396
1514
|
}
|
|
@@ -1407,6 +1525,9 @@ function createCmssyCartRoute(config) {
|
|
|
1407
1525
|
return json2({ message: "Not found." }, 404);
|
|
1408
1526
|
}
|
|
1409
1527
|
} catch (err) {
|
|
1528
|
+
if (err instanceof CmssyAddressError) {
|
|
1529
|
+
return json2({ message: err.message, missing: err.missing }, 400);
|
|
1530
|
+
}
|
|
1410
1531
|
return json2(
|
|
1411
1532
|
{
|
|
1412
1533
|
message: err instanceof Error ? err.message : "Commerce request failed"
|
|
@@ -1466,11 +1587,18 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1466
1587
|
return refreshed;
|
|
1467
1588
|
};
|
|
1468
1589
|
}
|
|
1469
|
-
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1590
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
|
|
1470
1591
|
public {
|
|
1471
1592
|
model {
|
|
1472
|
-
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit) {
|
|
1473
|
-
|
|
1593
|
+
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit, offset: $offset, sort: $sort) {
|
|
1594
|
+
total
|
|
1595
|
+
hasMore
|
|
1596
|
+
items {
|
|
1597
|
+
id
|
|
1598
|
+
data
|
|
1599
|
+
priceTiers { minQty price }
|
|
1600
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1601
|
+
}
|
|
1474
1602
|
}
|
|
1475
1603
|
}
|
|
1476
1604
|
}
|
|
@@ -1484,25 +1612,29 @@ async function fetchProducts(config, options) {
|
|
|
1484
1612
|
workspaceId,
|
|
1485
1613
|
modelSlug: options.modelSlug,
|
|
1486
1614
|
filter: options.filter ?? {},
|
|
1487
|
-
limit: options.limit ?? 50
|
|
1615
|
+
limit: options.limit ?? 50,
|
|
1616
|
+
offset: options.offset ?? 0,
|
|
1617
|
+
sort: options.sort ?? null
|
|
1488
1618
|
},
|
|
1489
1619
|
{ headers: { "x-workspace-id": workspaceId } },
|
|
1490
1620
|
"products query"
|
|
1491
1621
|
);
|
|
1492
|
-
return data.public.model.records
|
|
1622
|
+
return data.public.model.records;
|
|
1493
1623
|
}
|
|
1494
1624
|
async function fetchProduct(config, options) {
|
|
1495
|
-
const
|
|
1625
|
+
const page = await fetchProducts(config, {
|
|
1496
1626
|
modelSlug: options.modelSlug,
|
|
1497
1627
|
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1498
1628
|
limit: 1
|
|
1499
1629
|
});
|
|
1500
|
-
return
|
|
1630
|
+
return page.items[0] ?? null;
|
|
1501
1631
|
}
|
|
1502
1632
|
var ORDER_FIELDS = `
|
|
1503
1633
|
id
|
|
1504
1634
|
status
|
|
1505
1635
|
subtotal
|
|
1636
|
+
discount
|
|
1637
|
+
appliedDiscount { code type value amount }
|
|
1506
1638
|
tax
|
|
1507
1639
|
total
|
|
1508
1640
|
pricesIncludeTax
|
|
@@ -1524,9 +1656,47 @@ var ORDER_FIELDS = `
|
|
|
1524
1656
|
paidAt
|
|
1525
1657
|
fulfilledAt
|
|
1526
1658
|
createdAt
|
|
1527
|
-
|
|
1659
|
+
orderNumber
|
|
1660
|
+
poNumber
|
|
1661
|
+
customerNote
|
|
1662
|
+
shippingTotal
|
|
1663
|
+
shippingMethod { id label price }
|
|
1664
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1665
|
+
items { name price listPrice tierMinQty currency quantity sku }
|
|
1528
1666
|
payments { amount reference provider at }
|
|
1529
1667
|
`;
|
|
1668
|
+
var PUBLIC_ORDER_FIELDS = `
|
|
1669
|
+
id
|
|
1670
|
+
orderNumber
|
|
1671
|
+
status
|
|
1672
|
+
paymentStatus
|
|
1673
|
+
fulfillmentStatus
|
|
1674
|
+
subtotal
|
|
1675
|
+
discount
|
|
1676
|
+
appliedDiscount { code type value amount }
|
|
1677
|
+
tax
|
|
1678
|
+
total
|
|
1679
|
+
pricesIncludeTax
|
|
1680
|
+
taxSummary { rateId name rate base amount }
|
|
1681
|
+
currency
|
|
1682
|
+
customerEmail
|
|
1683
|
+
poNumber
|
|
1684
|
+
customerNote
|
|
1685
|
+
shippingTotal
|
|
1686
|
+
shippingMethod { id label price }
|
|
1687
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1688
|
+
amountPaid
|
|
1689
|
+
balanceDue
|
|
1690
|
+
refundedAmount
|
|
1691
|
+
trackingNumber
|
|
1692
|
+
trackingCarrier
|
|
1693
|
+
invoiceNumber
|
|
1694
|
+
invoiceUrl
|
|
1695
|
+
paidAt
|
|
1696
|
+
fulfilledAt
|
|
1697
|
+
createdAt
|
|
1698
|
+
items { name price listPrice tierMinQty currency quantity sku taxRate taxAmount }
|
|
1699
|
+
`;
|
|
1530
1700
|
var MY_ORDERS = `query MyOrders($workspaceId: ID!, $skip: Int, $limit: Int) {
|
|
1531
1701
|
account {
|
|
1532
1702
|
orders(workspaceId: $workspaceId, skip: $skip, limit: $limit) {
|
|
@@ -1541,6 +1711,15 @@ var MY_ORDER = `query MyOrder($workspaceId: ID!, $id: ID!) {
|
|
|
1541
1711
|
order(workspaceId: $workspaceId, id: $id) { ${ORDER_FIELDS} }
|
|
1542
1712
|
}
|
|
1543
1713
|
}`;
|
|
1714
|
+
var PUBLIC_ORDER_BY_TOKEN = `query PublicOrder($workspaceId: ID!, $orderId: ID!, $accessToken: String!) {
|
|
1715
|
+
public {
|
|
1716
|
+
order {
|
|
1717
|
+
byToken(workspaceId: $workspaceId, orderId: $orderId, accessToken: $accessToken) {
|
|
1718
|
+
${PUBLIC_ORDER_FIELDS}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}`;
|
|
1544
1723
|
var workspaceIdCache3 = /* @__PURE__ */ new Map();
|
|
1545
1724
|
function workspaceIdFor3(config) {
|
|
1546
1725
|
const key = `${react.resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
@@ -1581,8 +1760,26 @@ async function backendMyOrder(config, accessToken, id) {
|
|
|
1581
1760
|
);
|
|
1582
1761
|
return data.account.order;
|
|
1583
1762
|
}
|
|
1763
|
+
async function backendOrderByToken(config, options) {
|
|
1764
|
+
const workspaceId = await workspaceIdFor3(config);
|
|
1765
|
+
const data = await react.graphqlRequest(
|
|
1766
|
+
config,
|
|
1767
|
+
PUBLIC_ORDER_BY_TOKEN,
|
|
1768
|
+
{
|
|
1769
|
+
workspaceId,
|
|
1770
|
+
orderId: options.orderId,
|
|
1771
|
+
accessToken: options.accessToken
|
|
1772
|
+
},
|
|
1773
|
+
{ headers: { "x-workspace-id": workspaceId } },
|
|
1774
|
+
"public order lookup"
|
|
1775
|
+
);
|
|
1776
|
+
return data.public.order.byToken;
|
|
1777
|
+
}
|
|
1584
1778
|
|
|
1585
|
-
// src/
|
|
1779
|
+
// src/order-server.ts
|
|
1780
|
+
async function fetchOrderByToken(config, options) {
|
|
1781
|
+
return backendOrderByToken(config, options);
|
|
1782
|
+
}
|
|
1586
1783
|
var DEFAULT_LIMIT = 20;
|
|
1587
1784
|
var MAX_LIMIT = 100;
|
|
1588
1785
|
function json3(body, status = 200) {
|
|
@@ -1730,6 +1927,7 @@ exports.createCmssyRobots = createCmssyRobots;
|
|
|
1730
1927
|
exports.createCmssySitemap = createCmssySitemap;
|
|
1731
1928
|
exports.createDraftRoute = createDraftRoute;
|
|
1732
1929
|
exports.defineCmssyConfig = defineCmssyConfig;
|
|
1930
|
+
exports.fetchOrderByToken = fetchOrderByToken;
|
|
1733
1931
|
exports.fetchProduct = fetchProduct;
|
|
1734
1932
|
exports.fetchProducts = fetchProducts;
|
|
1735
1933
|
exports.getCmssyAccessToken = getCmssyAccessToken;
|
package/dist/index.d.cts
CHANGED
|
@@ -80,13 +80,14 @@ interface CmssyEditorProps {
|
|
|
80
80
|
}
|
|
81
81
|
interface CreateCmssyPageOptions {
|
|
82
82
|
editor?: ComponentType<CmssyEditorProps>;
|
|
83
|
+
path?: string;
|
|
83
84
|
}
|
|
84
85
|
interface CatchAllParams {
|
|
85
86
|
path?: string[];
|
|
86
87
|
}
|
|
87
88
|
type SearchParams = Record<string, string | string[] | undefined>;
|
|
88
89
|
interface CatchAllProps {
|
|
89
|
-
params
|
|
90
|
+
params?: Promise<CatchAllParams>;
|
|
90
91
|
searchParams?: Promise<SearchParams>;
|
|
91
92
|
}
|
|
92
93
|
declare function createCmssyPage(config: CmssyNextConfig, blocks: BlockDefinition[], options?: CreateCmssyPageOptions): ({ params, searchParams, }: CatchAllProps) => Promise<react_jsx_runtime.JSX.Element>;
|
|
@@ -289,8 +290,15 @@ interface FetchProductsOptions {
|
|
|
289
290
|
modelSlug: string;
|
|
290
291
|
filter?: Record<string, unknown>;
|
|
291
292
|
limit?: number;
|
|
293
|
+
offset?: number;
|
|
294
|
+
sort?: string;
|
|
292
295
|
}
|
|
293
|
-
|
|
296
|
+
interface CmssyProductPage {
|
|
297
|
+
items: CmssyProduct[];
|
|
298
|
+
total: number;
|
|
299
|
+
hasMore: boolean;
|
|
300
|
+
}
|
|
301
|
+
declare function fetchProducts(config: CmssyNextConfig, options: FetchProductsOptions): Promise<CmssyProductPage>;
|
|
294
302
|
interface FetchProductOptions {
|
|
295
303
|
modelSlug: string;
|
|
296
304
|
slug: string;
|
|
@@ -298,6 +306,12 @@ interface FetchProductOptions {
|
|
|
298
306
|
}
|
|
299
307
|
declare function fetchProduct(config: CmssyNextConfig, options: FetchProductOptions): Promise<CmssyProduct | null>;
|
|
300
308
|
|
|
309
|
+
interface FetchOrderByTokenOptions {
|
|
310
|
+
orderId: string;
|
|
311
|
+
accessToken: string;
|
|
312
|
+
}
|
|
313
|
+
declare function fetchOrderByToken(config: CmssyNextConfig, options: FetchOrderByTokenOptions): Promise<CmssyOrder>;
|
|
314
|
+
|
|
301
315
|
interface CmssyOrdersRouteHandlers {
|
|
302
316
|
GET(request: Request): Promise<Response>;
|
|
303
317
|
}
|
|
@@ -371,4 +385,4 @@ declare class CmssyWebhookError extends Error {
|
|
|
371
385
|
*/
|
|
372
386
|
declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
|
|
373
387
|
|
|
374
|
-
export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyEnvConfig, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGINS, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, defineCmssyConfig, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
|
|
388
|
+
export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyEnvConfig, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssyProductPage, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGINS, type FetchOrderByTokenOptions, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, defineCmssyConfig, fetchOrderByToken, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -80,13 +80,14 @@ interface CmssyEditorProps {
|
|
|
80
80
|
}
|
|
81
81
|
interface CreateCmssyPageOptions {
|
|
82
82
|
editor?: ComponentType<CmssyEditorProps>;
|
|
83
|
+
path?: string;
|
|
83
84
|
}
|
|
84
85
|
interface CatchAllParams {
|
|
85
86
|
path?: string[];
|
|
86
87
|
}
|
|
87
88
|
type SearchParams = Record<string, string | string[] | undefined>;
|
|
88
89
|
interface CatchAllProps {
|
|
89
|
-
params
|
|
90
|
+
params?: Promise<CatchAllParams>;
|
|
90
91
|
searchParams?: Promise<SearchParams>;
|
|
91
92
|
}
|
|
92
93
|
declare function createCmssyPage(config: CmssyNextConfig, blocks: BlockDefinition[], options?: CreateCmssyPageOptions): ({ params, searchParams, }: CatchAllProps) => Promise<react_jsx_runtime.JSX.Element>;
|
|
@@ -289,8 +290,15 @@ interface FetchProductsOptions {
|
|
|
289
290
|
modelSlug: string;
|
|
290
291
|
filter?: Record<string, unknown>;
|
|
291
292
|
limit?: number;
|
|
293
|
+
offset?: number;
|
|
294
|
+
sort?: string;
|
|
292
295
|
}
|
|
293
|
-
|
|
296
|
+
interface CmssyProductPage {
|
|
297
|
+
items: CmssyProduct[];
|
|
298
|
+
total: number;
|
|
299
|
+
hasMore: boolean;
|
|
300
|
+
}
|
|
301
|
+
declare function fetchProducts(config: CmssyNextConfig, options: FetchProductsOptions): Promise<CmssyProductPage>;
|
|
294
302
|
interface FetchProductOptions {
|
|
295
303
|
modelSlug: string;
|
|
296
304
|
slug: string;
|
|
@@ -298,6 +306,12 @@ interface FetchProductOptions {
|
|
|
298
306
|
}
|
|
299
307
|
declare function fetchProduct(config: CmssyNextConfig, options: FetchProductOptions): Promise<CmssyProduct | null>;
|
|
300
308
|
|
|
309
|
+
interface FetchOrderByTokenOptions {
|
|
310
|
+
orderId: string;
|
|
311
|
+
accessToken: string;
|
|
312
|
+
}
|
|
313
|
+
declare function fetchOrderByToken(config: CmssyNextConfig, options: FetchOrderByTokenOptions): Promise<CmssyOrder>;
|
|
314
|
+
|
|
301
315
|
interface CmssyOrdersRouteHandlers {
|
|
302
316
|
GET(request: Request): Promise<Response>;
|
|
303
317
|
}
|
|
@@ -371,4 +385,4 @@ declare class CmssyWebhookError extends Error {
|
|
|
371
385
|
*/
|
|
372
386
|
declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
|
|
373
387
|
|
|
374
|
-
export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyEnvConfig, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGINS, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, defineCmssyConfig, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
|
|
388
|
+
export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyEnvConfig, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssyProductPage, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGINS, type FetchOrderByTokenOptions, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, defineCmssyConfig, fetchOrderByToken, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -220,11 +220,12 @@ function createCmssyPage(config, blocks, options) {
|
|
|
220
220
|
workspaceSlug: config.workspaceSlug
|
|
221
221
|
};
|
|
222
222
|
const client = createCmssyClient(clientConfig);
|
|
223
|
+
const fixedPath = options?.path?.split("/").map((segment) => segment.trim()).filter(Boolean);
|
|
223
224
|
return async function CmssyCatchAllPage({
|
|
224
225
|
params,
|
|
225
226
|
searchParams
|
|
226
227
|
}) {
|
|
227
|
-
const
|
|
228
|
+
const path = fixedPath ?? (params ? (await params).path ?? void 0 : void 0);
|
|
228
229
|
const { isEnabled } = await draftMode();
|
|
229
230
|
const query = searchParams ? await searchParams : {};
|
|
230
231
|
const editMode = isEnabled || hasEditFlag(query[EDIT_QUERY_PARAM]);
|
|
@@ -1094,15 +1095,23 @@ var CART_FIELDS = `
|
|
|
1094
1095
|
subtotal
|
|
1095
1096
|
currency
|
|
1096
1097
|
discountedTotal
|
|
1098
|
+
tax
|
|
1099
|
+
totalGross
|
|
1100
|
+
pricesIncludeTax
|
|
1101
|
+
shippingTotal
|
|
1102
|
+
taxSummary { rateId name rate base amount }
|
|
1103
|
+
shippingMethod { id label price etaLabel }
|
|
1104
|
+
availableShippingMethods { id label price etaLabel }
|
|
1097
1105
|
appliedDiscount { code type value computedAmount }
|
|
1098
1106
|
items {
|
|
1099
1107
|
id
|
|
1100
1108
|
recordId
|
|
1101
1109
|
quantity
|
|
1102
1110
|
variantSelections
|
|
1111
|
+
unitPrice
|
|
1103
1112
|
currentPrice
|
|
1104
1113
|
priceMismatch
|
|
1105
|
-
snapshot { name price currency imageUrl sku }
|
|
1114
|
+
snapshot { name price currency imageUrl sku tiers { minQty price } }
|
|
1106
1115
|
}
|
|
1107
1116
|
`;
|
|
1108
1117
|
var CART_QUERY = `query Cart($workspaceId: ID!) { cart { get(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
@@ -1112,14 +1121,45 @@ var REMOVE_ITEM = `mutation RemoveCartItem($workspaceId: ID!, $itemId: ID!) { ca
|
|
|
1112
1121
|
var CLEAR_CART = `mutation ClearCart($workspaceId: ID!) { cart { clear(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1113
1122
|
var APPLY_DISCOUNT = `mutation ApplyDiscount($workspaceId: ID!, $code: String!) { cart { applyDiscount(workspaceId: $workspaceId, code: $code) { ${CART_FIELDS} } } }`;
|
|
1114
1123
|
var REMOVE_DISCOUNT = `mutation RemoveDiscount($workspaceId: ID!) { cart { removeDiscount(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1124
|
+
var SET_SHIPPING_METHOD = `mutation SetShippingMethod($workspaceId: ID!, $shippingMethodId: String) {
|
|
1125
|
+
cart { setShippingMethod(workspaceId: $workspaceId, shippingMethodId: $shippingMethodId) { ${CART_FIELDS} } }
|
|
1126
|
+
}`;
|
|
1127
|
+
var MERGE_CART = `mutation MergeCart($workspaceId: ID!) { cart { merge(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1115
1128
|
var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
|
|
1116
|
-
cart {
|
|
1129
|
+
cart {
|
|
1130
|
+
checkout(input: $input) {
|
|
1131
|
+
id
|
|
1132
|
+
orderNumber
|
|
1133
|
+
status
|
|
1134
|
+
subtotal
|
|
1135
|
+
discount
|
|
1136
|
+
appliedDiscount { code type value amount }
|
|
1137
|
+
tax
|
|
1138
|
+
total
|
|
1139
|
+
currency
|
|
1140
|
+
customerEmail
|
|
1141
|
+
accessToken
|
|
1142
|
+
poNumber
|
|
1143
|
+
customerNote
|
|
1144
|
+
shippingTotal
|
|
1145
|
+
pricesIncludeTax
|
|
1146
|
+
shippingMethod { id label price }
|
|
1147
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1148
|
+
taxSummary { rateId name rate base amount }
|
|
1149
|
+
items { name sku quantity price listPrice tierMinQty currency taxRate taxAmount }
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1117
1152
|
}`;
|
|
1118
1153
|
var PRODUCT = `query Product($workspaceId: String!, $modelSlug: String!, $filter: JSON) {
|
|
1119
1154
|
public {
|
|
1120
1155
|
model {
|
|
1121
1156
|
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: 1) {
|
|
1122
|
-
items {
|
|
1157
|
+
items {
|
|
1158
|
+
id
|
|
1159
|
+
data
|
|
1160
|
+
priceTiers { minQty price }
|
|
1161
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1162
|
+
}
|
|
1123
1163
|
}
|
|
1124
1164
|
}
|
|
1125
1165
|
}
|
|
@@ -1235,14 +1275,38 @@ async function backendRemoveDiscount(config, ctx) {
|
|
|
1235
1275
|
);
|
|
1236
1276
|
return data.cart.removeDiscount;
|
|
1237
1277
|
}
|
|
1238
|
-
async function
|
|
1278
|
+
async function backendSetShippingMethod(config, ctx, shippingMethodId) {
|
|
1279
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1280
|
+
const data = await request(
|
|
1281
|
+
config,
|
|
1282
|
+
ctx,
|
|
1283
|
+
workspaceId,
|
|
1284
|
+
SET_SHIPPING_METHOD,
|
|
1285
|
+
{ workspaceId, shippingMethodId },
|
|
1286
|
+
"set shipping method"
|
|
1287
|
+
);
|
|
1288
|
+
return data.cart.setShippingMethod;
|
|
1289
|
+
}
|
|
1290
|
+
async function backendMergeCart(config, ctx) {
|
|
1291
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1292
|
+
const data = await request(
|
|
1293
|
+
config,
|
|
1294
|
+
ctx,
|
|
1295
|
+
workspaceId,
|
|
1296
|
+
MERGE_CART,
|
|
1297
|
+
{ workspaceId },
|
|
1298
|
+
"merge cart"
|
|
1299
|
+
);
|
|
1300
|
+
return data.cart.merge;
|
|
1301
|
+
}
|
|
1302
|
+
async function backendCheckout(config, ctx, input) {
|
|
1239
1303
|
const workspaceId = await workspaceIdFor2(config);
|
|
1240
1304
|
const data = await request(
|
|
1241
1305
|
config,
|
|
1242
1306
|
ctx,
|
|
1243
1307
|
workspaceId,
|
|
1244
1308
|
CHECKOUT,
|
|
1245
|
-
{ input: { workspaceId,
|
|
1309
|
+
{ input: { workspaceId, ...input } },
|
|
1246
1310
|
"checkout"
|
|
1247
1311
|
);
|
|
1248
1312
|
return data.cart.checkout;
|
|
@@ -1311,6 +1375,49 @@ function plainObject2(value) {
|
|
|
1311
1375
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1312
1376
|
return value;
|
|
1313
1377
|
}
|
|
1378
|
+
function optionalStr(value) {
|
|
1379
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
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
|
+
};
|
|
1400
|
+
function shippingAddress(value) {
|
|
1401
|
+
if (value === void 0 || value === null) return null;
|
|
1402
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
1403
|
+
throw new CmssyAddressError([...ADDRESS_REQUIRED]);
|
|
1404
|
+
}
|
|
1405
|
+
const raw = value;
|
|
1406
|
+
const missing = ADDRESS_REQUIRED.filter((key) => !optionalStr(raw[key]));
|
|
1407
|
+
if (missing.length > 0) throw new CmssyAddressError(missing);
|
|
1408
|
+
return {
|
|
1409
|
+
name: optionalStr(raw.name),
|
|
1410
|
+
company: optionalStr(raw.company),
|
|
1411
|
+
line1: optionalStr(raw.line1),
|
|
1412
|
+
line2: optionalStr(raw.line2),
|
|
1413
|
+
postalCode: optionalStr(raw.postalCode),
|
|
1414
|
+
city: optionalStr(raw.city),
|
|
1415
|
+
region: optionalStr(raw.region),
|
|
1416
|
+
country: optionalStr(raw.country),
|
|
1417
|
+
phone: optionalStr(raw.phone),
|
|
1418
|
+
vatId: optionalStr(raw.vatId)
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1314
1421
|
function createCmssyCartRoute(config) {
|
|
1315
1422
|
async function ensureCartToken() {
|
|
1316
1423
|
const jar = await cookies();
|
|
@@ -1384,12 +1491,23 @@ function createCmssyCartRoute(config) {
|
|
|
1384
1491
|
});
|
|
1385
1492
|
case "remove-discount":
|
|
1386
1493
|
return json2({ cart: await backendRemoveDiscount(config, ctx) });
|
|
1494
|
+
case "set-shipping":
|
|
1495
|
+
return json2({
|
|
1496
|
+
cart: await backendSetShippingMethod(
|
|
1497
|
+
config,
|
|
1498
|
+
ctx,
|
|
1499
|
+
optionalStr(body.shippingMethodId)
|
|
1500
|
+
)
|
|
1501
|
+
});
|
|
1502
|
+
case "merge":
|
|
1503
|
+
return json2({ cart: await backendMergeCart(config, ctx) });
|
|
1387
1504
|
case "checkout": {
|
|
1388
|
-
const order = await backendCheckout(
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1505
|
+
const order = await backendCheckout(config, ctx, {
|
|
1506
|
+
customerEmail: str2(body.customerEmail),
|
|
1507
|
+
poNumber: optionalStr(body.poNumber),
|
|
1508
|
+
customerNote: optionalStr(body.customerNote),
|
|
1509
|
+
shippingAddress: shippingAddress(body.shippingAddress)
|
|
1510
|
+
});
|
|
1393
1511
|
await clearCartToken();
|
|
1394
1512
|
return json2({ order });
|
|
1395
1513
|
}
|
|
@@ -1406,6 +1524,9 @@ function createCmssyCartRoute(config) {
|
|
|
1406
1524
|
return json2({ message: "Not found." }, 404);
|
|
1407
1525
|
}
|
|
1408
1526
|
} catch (err) {
|
|
1527
|
+
if (err instanceof CmssyAddressError) {
|
|
1528
|
+
return json2({ message: err.message, missing: err.missing }, 400);
|
|
1529
|
+
}
|
|
1409
1530
|
return json2(
|
|
1410
1531
|
{
|
|
1411
1532
|
message: err instanceof Error ? err.message : "Commerce request failed"
|
|
@@ -1465,11 +1586,18 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1465
1586
|
return refreshed;
|
|
1466
1587
|
};
|
|
1467
1588
|
}
|
|
1468
|
-
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1589
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
|
|
1469
1590
|
public {
|
|
1470
1591
|
model {
|
|
1471
|
-
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit) {
|
|
1472
|
-
|
|
1592
|
+
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit, offset: $offset, sort: $sort) {
|
|
1593
|
+
total
|
|
1594
|
+
hasMore
|
|
1595
|
+
items {
|
|
1596
|
+
id
|
|
1597
|
+
data
|
|
1598
|
+
priceTiers { minQty price }
|
|
1599
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1600
|
+
}
|
|
1473
1601
|
}
|
|
1474
1602
|
}
|
|
1475
1603
|
}
|
|
@@ -1483,25 +1611,29 @@ async function fetchProducts(config, options) {
|
|
|
1483
1611
|
workspaceId,
|
|
1484
1612
|
modelSlug: options.modelSlug,
|
|
1485
1613
|
filter: options.filter ?? {},
|
|
1486
|
-
limit: options.limit ?? 50
|
|
1614
|
+
limit: options.limit ?? 50,
|
|
1615
|
+
offset: options.offset ?? 0,
|
|
1616
|
+
sort: options.sort ?? null
|
|
1487
1617
|
},
|
|
1488
1618
|
{ headers: { "x-workspace-id": workspaceId } },
|
|
1489
1619
|
"products query"
|
|
1490
1620
|
);
|
|
1491
|
-
return data.public.model.records
|
|
1621
|
+
return data.public.model.records;
|
|
1492
1622
|
}
|
|
1493
1623
|
async function fetchProduct(config, options) {
|
|
1494
|
-
const
|
|
1624
|
+
const page = await fetchProducts(config, {
|
|
1495
1625
|
modelSlug: options.modelSlug,
|
|
1496
1626
|
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1497
1627
|
limit: 1
|
|
1498
1628
|
});
|
|
1499
|
-
return
|
|
1629
|
+
return page.items[0] ?? null;
|
|
1500
1630
|
}
|
|
1501
1631
|
var ORDER_FIELDS = `
|
|
1502
1632
|
id
|
|
1503
1633
|
status
|
|
1504
1634
|
subtotal
|
|
1635
|
+
discount
|
|
1636
|
+
appliedDiscount { code type value amount }
|
|
1505
1637
|
tax
|
|
1506
1638
|
total
|
|
1507
1639
|
pricesIncludeTax
|
|
@@ -1523,9 +1655,47 @@ var ORDER_FIELDS = `
|
|
|
1523
1655
|
paidAt
|
|
1524
1656
|
fulfilledAt
|
|
1525
1657
|
createdAt
|
|
1526
|
-
|
|
1658
|
+
orderNumber
|
|
1659
|
+
poNumber
|
|
1660
|
+
customerNote
|
|
1661
|
+
shippingTotal
|
|
1662
|
+
shippingMethod { id label price }
|
|
1663
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1664
|
+
items { name price listPrice tierMinQty currency quantity sku }
|
|
1527
1665
|
payments { amount reference provider at }
|
|
1528
1666
|
`;
|
|
1667
|
+
var PUBLIC_ORDER_FIELDS = `
|
|
1668
|
+
id
|
|
1669
|
+
orderNumber
|
|
1670
|
+
status
|
|
1671
|
+
paymentStatus
|
|
1672
|
+
fulfillmentStatus
|
|
1673
|
+
subtotal
|
|
1674
|
+
discount
|
|
1675
|
+
appliedDiscount { code type value amount }
|
|
1676
|
+
tax
|
|
1677
|
+
total
|
|
1678
|
+
pricesIncludeTax
|
|
1679
|
+
taxSummary { rateId name rate base amount }
|
|
1680
|
+
currency
|
|
1681
|
+
customerEmail
|
|
1682
|
+
poNumber
|
|
1683
|
+
customerNote
|
|
1684
|
+
shippingTotal
|
|
1685
|
+
shippingMethod { id label price }
|
|
1686
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1687
|
+
amountPaid
|
|
1688
|
+
balanceDue
|
|
1689
|
+
refundedAmount
|
|
1690
|
+
trackingNumber
|
|
1691
|
+
trackingCarrier
|
|
1692
|
+
invoiceNumber
|
|
1693
|
+
invoiceUrl
|
|
1694
|
+
paidAt
|
|
1695
|
+
fulfilledAt
|
|
1696
|
+
createdAt
|
|
1697
|
+
items { name price listPrice tierMinQty currency quantity sku taxRate taxAmount }
|
|
1698
|
+
`;
|
|
1529
1699
|
var MY_ORDERS = `query MyOrders($workspaceId: ID!, $skip: Int, $limit: Int) {
|
|
1530
1700
|
account {
|
|
1531
1701
|
orders(workspaceId: $workspaceId, skip: $skip, limit: $limit) {
|
|
@@ -1540,6 +1710,15 @@ var MY_ORDER = `query MyOrder($workspaceId: ID!, $id: ID!) {
|
|
|
1540
1710
|
order(workspaceId: $workspaceId, id: $id) { ${ORDER_FIELDS} }
|
|
1541
1711
|
}
|
|
1542
1712
|
}`;
|
|
1713
|
+
var PUBLIC_ORDER_BY_TOKEN = `query PublicOrder($workspaceId: ID!, $orderId: ID!, $accessToken: String!) {
|
|
1714
|
+
public {
|
|
1715
|
+
order {
|
|
1716
|
+
byToken(workspaceId: $workspaceId, orderId: $orderId, accessToken: $accessToken) {
|
|
1717
|
+
${PUBLIC_ORDER_FIELDS}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
}`;
|
|
1543
1722
|
var workspaceIdCache3 = /* @__PURE__ */ new Map();
|
|
1544
1723
|
function workspaceIdFor3(config) {
|
|
1545
1724
|
const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
@@ -1580,8 +1759,26 @@ async function backendMyOrder(config, accessToken, id) {
|
|
|
1580
1759
|
);
|
|
1581
1760
|
return data.account.order;
|
|
1582
1761
|
}
|
|
1762
|
+
async function backendOrderByToken(config, options) {
|
|
1763
|
+
const workspaceId = await workspaceIdFor3(config);
|
|
1764
|
+
const data = await graphqlRequest(
|
|
1765
|
+
config,
|
|
1766
|
+
PUBLIC_ORDER_BY_TOKEN,
|
|
1767
|
+
{
|
|
1768
|
+
workspaceId,
|
|
1769
|
+
orderId: options.orderId,
|
|
1770
|
+
accessToken: options.accessToken
|
|
1771
|
+
},
|
|
1772
|
+
{ headers: { "x-workspace-id": workspaceId } },
|
|
1773
|
+
"public order lookup"
|
|
1774
|
+
);
|
|
1775
|
+
return data.public.order.byToken;
|
|
1776
|
+
}
|
|
1583
1777
|
|
|
1584
|
-
// src/
|
|
1778
|
+
// src/order-server.ts
|
|
1779
|
+
async function fetchOrderByToken(config, options) {
|
|
1780
|
+
return backendOrderByToken(config, options);
|
|
1781
|
+
}
|
|
1585
1782
|
var DEFAULT_LIMIT = 20;
|
|
1586
1783
|
var MAX_LIMIT = 100;
|
|
1587
1784
|
function json3(body, status = 200) {
|
|
@@ -1695,4 +1892,4 @@ function verifyCmssyWebhook(options) {
|
|
|
1695
1892
|
return parsed;
|
|
1696
1893
|
}
|
|
1697
1894
|
|
|
1698
|
-
export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, CmssyWebhookError, DEFAULT_CMSSY_EDITOR_ORIGINS, SESSION_MAX_AGE_SECONDS, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, defineCmssyConfig, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
|
|
1895
|
+
export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, CmssyWebhookError, DEFAULT_CMSSY_EDITOR_ORIGINS, SESSION_MAX_AGE_SECONDS, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, defineCmssyConfig, fetchOrderByToken, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/next",
|
|
3
|
-
"version": "1.0
|
|
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": "^1.0
|
|
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": "1.0
|
|
58
|
+
"@cmssy/react": "2.1.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"jose": "^6.2.3"
|