@cmssy/next 1.0.0 → 2.0.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 +191 -20
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +191 -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,43 @@ 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
|
+
tax
|
|
1137
|
+
total
|
|
1138
|
+
currency
|
|
1139
|
+
customerEmail
|
|
1140
|
+
accessToken
|
|
1141
|
+
poNumber
|
|
1142
|
+
customerNote
|
|
1143
|
+
shippingTotal
|
|
1144
|
+
pricesIncludeTax
|
|
1145
|
+
shippingMethod { id label price }
|
|
1146
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1147
|
+
taxSummary { rateId name rate base amount }
|
|
1148
|
+
items { name sku quantity price listPrice tierMinQty currency taxRate taxAmount }
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1118
1151
|
}`;
|
|
1119
1152
|
var PRODUCT = `query Product($workspaceId: String!, $modelSlug: String!, $filter: JSON) {
|
|
1120
1153
|
public {
|
|
1121
1154
|
model {
|
|
1122
1155
|
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: 1) {
|
|
1123
|
-
items {
|
|
1156
|
+
items {
|
|
1157
|
+
id
|
|
1158
|
+
data
|
|
1159
|
+
priceTiers { minQty price }
|
|
1160
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1161
|
+
}
|
|
1124
1162
|
}
|
|
1125
1163
|
}
|
|
1126
1164
|
}
|
|
@@ -1236,14 +1274,38 @@ async function backendRemoveDiscount(config, ctx) {
|
|
|
1236
1274
|
);
|
|
1237
1275
|
return data.cart.removeDiscount;
|
|
1238
1276
|
}
|
|
1239
|
-
async function
|
|
1277
|
+
async function backendSetShippingMethod(config, ctx, shippingMethodId) {
|
|
1278
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1279
|
+
const data = await request(
|
|
1280
|
+
config,
|
|
1281
|
+
ctx,
|
|
1282
|
+
workspaceId,
|
|
1283
|
+
SET_SHIPPING_METHOD,
|
|
1284
|
+
{ workspaceId, shippingMethodId },
|
|
1285
|
+
"set shipping method"
|
|
1286
|
+
);
|
|
1287
|
+
return data.cart.setShippingMethod;
|
|
1288
|
+
}
|
|
1289
|
+
async function backendMergeCart(config, ctx) {
|
|
1290
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1291
|
+
const data = await request(
|
|
1292
|
+
config,
|
|
1293
|
+
ctx,
|
|
1294
|
+
workspaceId,
|
|
1295
|
+
MERGE_CART,
|
|
1296
|
+
{ workspaceId },
|
|
1297
|
+
"merge cart"
|
|
1298
|
+
);
|
|
1299
|
+
return data.cart.merge;
|
|
1300
|
+
}
|
|
1301
|
+
async function backendCheckout(config, ctx, input) {
|
|
1240
1302
|
const workspaceId = await workspaceIdFor2(config);
|
|
1241
1303
|
const data = await request(
|
|
1242
1304
|
config,
|
|
1243
1305
|
ctx,
|
|
1244
1306
|
workspaceId,
|
|
1245
1307
|
CHECKOUT,
|
|
1246
|
-
{ input: { workspaceId,
|
|
1308
|
+
{ input: { workspaceId, ...input } },
|
|
1247
1309
|
"checkout"
|
|
1248
1310
|
);
|
|
1249
1311
|
return data.cart.checkout;
|
|
@@ -1312,6 +1374,31 @@ function plainObject2(value) {
|
|
|
1312
1374
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1313
1375
|
return value;
|
|
1314
1376
|
}
|
|
1377
|
+
function optionalStr(value) {
|
|
1378
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
1379
|
+
}
|
|
1380
|
+
function shippingAddress(value) {
|
|
1381
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
1382
|
+
const raw = value;
|
|
1383
|
+
const name = optionalStr(raw.name);
|
|
1384
|
+
const line1 = optionalStr(raw.line1);
|
|
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;
|
|
1389
|
+
return {
|
|
1390
|
+
name,
|
|
1391
|
+
company: optionalStr(raw.company),
|
|
1392
|
+
line1,
|
|
1393
|
+
line2: optionalStr(raw.line2),
|
|
1394
|
+
postalCode,
|
|
1395
|
+
city,
|
|
1396
|
+
region: optionalStr(raw.region),
|
|
1397
|
+
country,
|
|
1398
|
+
phone: optionalStr(raw.phone),
|
|
1399
|
+
vatId: optionalStr(raw.vatId)
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1315
1402
|
function createCmssyCartRoute(config) {
|
|
1316
1403
|
async function ensureCartToken() {
|
|
1317
1404
|
const jar = await headers.cookies();
|
|
@@ -1385,12 +1472,23 @@ function createCmssyCartRoute(config) {
|
|
|
1385
1472
|
});
|
|
1386
1473
|
case "remove-discount":
|
|
1387
1474
|
return json2({ cart: await backendRemoveDiscount(config, ctx) });
|
|
1475
|
+
case "set-shipping":
|
|
1476
|
+
return json2({
|
|
1477
|
+
cart: await backendSetShippingMethod(
|
|
1478
|
+
config,
|
|
1479
|
+
ctx,
|
|
1480
|
+
optionalStr(body.shippingMethodId)
|
|
1481
|
+
)
|
|
1482
|
+
});
|
|
1483
|
+
case "merge":
|
|
1484
|
+
return json2({ cart: await backendMergeCart(config, ctx) });
|
|
1388
1485
|
case "checkout": {
|
|
1389
|
-
const order = await backendCheckout(
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1486
|
+
const order = await backendCheckout(config, ctx, {
|
|
1487
|
+
customerEmail: str2(body.customerEmail),
|
|
1488
|
+
poNumber: optionalStr(body.poNumber),
|
|
1489
|
+
customerNote: optionalStr(body.customerNote),
|
|
1490
|
+
shippingAddress: shippingAddress(body.shippingAddress)
|
|
1491
|
+
});
|
|
1394
1492
|
await clearCartToken();
|
|
1395
1493
|
return json2({ order });
|
|
1396
1494
|
}
|
|
@@ -1466,11 +1564,18 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1466
1564
|
return refreshed;
|
|
1467
1565
|
};
|
|
1468
1566
|
}
|
|
1469
|
-
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1567
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
|
|
1470
1568
|
public {
|
|
1471
1569
|
model {
|
|
1472
|
-
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit) {
|
|
1473
|
-
|
|
1570
|
+
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit, offset: $offset, sort: $sort) {
|
|
1571
|
+
total
|
|
1572
|
+
hasMore
|
|
1573
|
+
items {
|
|
1574
|
+
id
|
|
1575
|
+
data
|
|
1576
|
+
priceTiers { minQty price }
|
|
1577
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1578
|
+
}
|
|
1474
1579
|
}
|
|
1475
1580
|
}
|
|
1476
1581
|
}
|
|
@@ -1484,20 +1589,22 @@ async function fetchProducts(config, options) {
|
|
|
1484
1589
|
workspaceId,
|
|
1485
1590
|
modelSlug: options.modelSlug,
|
|
1486
1591
|
filter: options.filter ?? {},
|
|
1487
|
-
limit: options.limit ?? 50
|
|
1592
|
+
limit: options.limit ?? 50,
|
|
1593
|
+
offset: options.offset ?? 0,
|
|
1594
|
+
sort: options.sort ?? null
|
|
1488
1595
|
},
|
|
1489
1596
|
{ headers: { "x-workspace-id": workspaceId } },
|
|
1490
1597
|
"products query"
|
|
1491
1598
|
);
|
|
1492
|
-
return data.public.model.records
|
|
1599
|
+
return data.public.model.records;
|
|
1493
1600
|
}
|
|
1494
1601
|
async function fetchProduct(config, options) {
|
|
1495
|
-
const
|
|
1602
|
+
const page = await fetchProducts(config, {
|
|
1496
1603
|
modelSlug: options.modelSlug,
|
|
1497
1604
|
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1498
1605
|
limit: 1
|
|
1499
1606
|
});
|
|
1500
|
-
return
|
|
1607
|
+
return page.items[0] ?? null;
|
|
1501
1608
|
}
|
|
1502
1609
|
var ORDER_FIELDS = `
|
|
1503
1610
|
id
|
|
@@ -1524,9 +1631,45 @@ var ORDER_FIELDS = `
|
|
|
1524
1631
|
paidAt
|
|
1525
1632
|
fulfilledAt
|
|
1526
1633
|
createdAt
|
|
1527
|
-
|
|
1634
|
+
orderNumber
|
|
1635
|
+
poNumber
|
|
1636
|
+
customerNote
|
|
1637
|
+
shippingTotal
|
|
1638
|
+
shippingMethod { id label price }
|
|
1639
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1640
|
+
items { name price listPrice tierMinQty currency quantity sku }
|
|
1528
1641
|
payments { amount reference provider at }
|
|
1529
1642
|
`;
|
|
1643
|
+
var PUBLIC_ORDER_FIELDS = `
|
|
1644
|
+
id
|
|
1645
|
+
orderNumber
|
|
1646
|
+
status
|
|
1647
|
+
paymentStatus
|
|
1648
|
+
fulfillmentStatus
|
|
1649
|
+
subtotal
|
|
1650
|
+
tax
|
|
1651
|
+
total
|
|
1652
|
+
pricesIncludeTax
|
|
1653
|
+
taxSummary { rateId name rate base amount }
|
|
1654
|
+
currency
|
|
1655
|
+
customerEmail
|
|
1656
|
+
poNumber
|
|
1657
|
+
customerNote
|
|
1658
|
+
shippingTotal
|
|
1659
|
+
shippingMethod { id label price }
|
|
1660
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1661
|
+
amountPaid
|
|
1662
|
+
balanceDue
|
|
1663
|
+
refundedAmount
|
|
1664
|
+
trackingNumber
|
|
1665
|
+
trackingCarrier
|
|
1666
|
+
invoiceNumber
|
|
1667
|
+
invoiceUrl
|
|
1668
|
+
paidAt
|
|
1669
|
+
fulfilledAt
|
|
1670
|
+
createdAt
|
|
1671
|
+
items { name price listPrice tierMinQty currency quantity sku taxRate taxAmount }
|
|
1672
|
+
`;
|
|
1530
1673
|
var MY_ORDERS = `query MyOrders($workspaceId: ID!, $skip: Int, $limit: Int) {
|
|
1531
1674
|
account {
|
|
1532
1675
|
orders(workspaceId: $workspaceId, skip: $skip, limit: $limit) {
|
|
@@ -1541,6 +1684,15 @@ var MY_ORDER = `query MyOrder($workspaceId: ID!, $id: ID!) {
|
|
|
1541
1684
|
order(workspaceId: $workspaceId, id: $id) { ${ORDER_FIELDS} }
|
|
1542
1685
|
}
|
|
1543
1686
|
}`;
|
|
1687
|
+
var PUBLIC_ORDER_BY_TOKEN = `query PublicOrder($workspaceId: ID!, $orderId: ID!, $accessToken: String!) {
|
|
1688
|
+
public {
|
|
1689
|
+
order {
|
|
1690
|
+
byToken(workspaceId: $workspaceId, orderId: $orderId, accessToken: $accessToken) {
|
|
1691
|
+
${PUBLIC_ORDER_FIELDS}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}`;
|
|
1544
1696
|
var workspaceIdCache3 = /* @__PURE__ */ new Map();
|
|
1545
1697
|
function workspaceIdFor3(config) {
|
|
1546
1698
|
const key = `${react.resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
@@ -1581,8 +1733,26 @@ async function backendMyOrder(config, accessToken, id) {
|
|
|
1581
1733
|
);
|
|
1582
1734
|
return data.account.order;
|
|
1583
1735
|
}
|
|
1736
|
+
async function backendOrderByToken(config, options) {
|
|
1737
|
+
const workspaceId = await workspaceIdFor3(config);
|
|
1738
|
+
const data = await react.graphqlRequest(
|
|
1739
|
+
config,
|
|
1740
|
+
PUBLIC_ORDER_BY_TOKEN,
|
|
1741
|
+
{
|
|
1742
|
+
workspaceId,
|
|
1743
|
+
orderId: options.orderId,
|
|
1744
|
+
accessToken: options.accessToken
|
|
1745
|
+
},
|
|
1746
|
+
{ headers: { "x-workspace-id": workspaceId } },
|
|
1747
|
+
"public order lookup"
|
|
1748
|
+
);
|
|
1749
|
+
return data.public.order.byToken;
|
|
1750
|
+
}
|
|
1584
1751
|
|
|
1585
|
-
// src/
|
|
1752
|
+
// src/order-server.ts
|
|
1753
|
+
async function fetchOrderByToken(config, options) {
|
|
1754
|
+
return backendOrderByToken(config, options);
|
|
1755
|
+
}
|
|
1586
1756
|
var DEFAULT_LIMIT = 20;
|
|
1587
1757
|
var MAX_LIMIT = 100;
|
|
1588
1758
|
function json3(body, status = 200) {
|
|
@@ -1730,6 +1900,7 @@ exports.createCmssyRobots = createCmssyRobots;
|
|
|
1730
1900
|
exports.createCmssySitemap = createCmssySitemap;
|
|
1731
1901
|
exports.createDraftRoute = createDraftRoute;
|
|
1732
1902
|
exports.defineCmssyConfig = defineCmssyConfig;
|
|
1903
|
+
exports.fetchOrderByToken = fetchOrderByToken;
|
|
1733
1904
|
exports.fetchProduct = fetchProduct;
|
|
1734
1905
|
exports.fetchProducts = fetchProducts;
|
|
1735
1906
|
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,43 @@ 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
|
+
tax
|
|
1136
|
+
total
|
|
1137
|
+
currency
|
|
1138
|
+
customerEmail
|
|
1139
|
+
accessToken
|
|
1140
|
+
poNumber
|
|
1141
|
+
customerNote
|
|
1142
|
+
shippingTotal
|
|
1143
|
+
pricesIncludeTax
|
|
1144
|
+
shippingMethod { id label price }
|
|
1145
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1146
|
+
taxSummary { rateId name rate base amount }
|
|
1147
|
+
items { name sku quantity price listPrice tierMinQty currency taxRate taxAmount }
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1117
1150
|
}`;
|
|
1118
1151
|
var PRODUCT = `query Product($workspaceId: String!, $modelSlug: String!, $filter: JSON) {
|
|
1119
1152
|
public {
|
|
1120
1153
|
model {
|
|
1121
1154
|
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: 1) {
|
|
1122
|
-
items {
|
|
1155
|
+
items {
|
|
1156
|
+
id
|
|
1157
|
+
data
|
|
1158
|
+
priceTiers { minQty price }
|
|
1159
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1160
|
+
}
|
|
1123
1161
|
}
|
|
1124
1162
|
}
|
|
1125
1163
|
}
|
|
@@ -1235,14 +1273,38 @@ async function backendRemoveDiscount(config, ctx) {
|
|
|
1235
1273
|
);
|
|
1236
1274
|
return data.cart.removeDiscount;
|
|
1237
1275
|
}
|
|
1238
|
-
async function
|
|
1276
|
+
async function backendSetShippingMethod(config, ctx, shippingMethodId) {
|
|
1277
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1278
|
+
const data = await request(
|
|
1279
|
+
config,
|
|
1280
|
+
ctx,
|
|
1281
|
+
workspaceId,
|
|
1282
|
+
SET_SHIPPING_METHOD,
|
|
1283
|
+
{ workspaceId, shippingMethodId },
|
|
1284
|
+
"set shipping method"
|
|
1285
|
+
);
|
|
1286
|
+
return data.cart.setShippingMethod;
|
|
1287
|
+
}
|
|
1288
|
+
async function backendMergeCart(config, ctx) {
|
|
1289
|
+
const workspaceId = await workspaceIdFor2(config);
|
|
1290
|
+
const data = await request(
|
|
1291
|
+
config,
|
|
1292
|
+
ctx,
|
|
1293
|
+
workspaceId,
|
|
1294
|
+
MERGE_CART,
|
|
1295
|
+
{ workspaceId },
|
|
1296
|
+
"merge cart"
|
|
1297
|
+
);
|
|
1298
|
+
return data.cart.merge;
|
|
1299
|
+
}
|
|
1300
|
+
async function backendCheckout(config, ctx, input) {
|
|
1239
1301
|
const workspaceId = await workspaceIdFor2(config);
|
|
1240
1302
|
const data = await request(
|
|
1241
1303
|
config,
|
|
1242
1304
|
ctx,
|
|
1243
1305
|
workspaceId,
|
|
1244
1306
|
CHECKOUT,
|
|
1245
|
-
{ input: { workspaceId,
|
|
1307
|
+
{ input: { workspaceId, ...input } },
|
|
1246
1308
|
"checkout"
|
|
1247
1309
|
);
|
|
1248
1310
|
return data.cart.checkout;
|
|
@@ -1311,6 +1373,31 @@ function plainObject2(value) {
|
|
|
1311
1373
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1312
1374
|
return value;
|
|
1313
1375
|
}
|
|
1376
|
+
function optionalStr(value) {
|
|
1377
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
1378
|
+
}
|
|
1379
|
+
function shippingAddress(value) {
|
|
1380
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
1381
|
+
const raw = value;
|
|
1382
|
+
const name = optionalStr(raw.name);
|
|
1383
|
+
const line1 = optionalStr(raw.line1);
|
|
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;
|
|
1388
|
+
return {
|
|
1389
|
+
name,
|
|
1390
|
+
company: optionalStr(raw.company),
|
|
1391
|
+
line1,
|
|
1392
|
+
line2: optionalStr(raw.line2),
|
|
1393
|
+
postalCode,
|
|
1394
|
+
city,
|
|
1395
|
+
region: optionalStr(raw.region),
|
|
1396
|
+
country,
|
|
1397
|
+
phone: optionalStr(raw.phone),
|
|
1398
|
+
vatId: optionalStr(raw.vatId)
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1314
1401
|
function createCmssyCartRoute(config) {
|
|
1315
1402
|
async function ensureCartToken() {
|
|
1316
1403
|
const jar = await cookies();
|
|
@@ -1384,12 +1471,23 @@ function createCmssyCartRoute(config) {
|
|
|
1384
1471
|
});
|
|
1385
1472
|
case "remove-discount":
|
|
1386
1473
|
return json2({ cart: await backendRemoveDiscount(config, ctx) });
|
|
1474
|
+
case "set-shipping":
|
|
1475
|
+
return json2({
|
|
1476
|
+
cart: await backendSetShippingMethod(
|
|
1477
|
+
config,
|
|
1478
|
+
ctx,
|
|
1479
|
+
optionalStr(body.shippingMethodId)
|
|
1480
|
+
)
|
|
1481
|
+
});
|
|
1482
|
+
case "merge":
|
|
1483
|
+
return json2({ cart: await backendMergeCart(config, ctx) });
|
|
1387
1484
|
case "checkout": {
|
|
1388
|
-
const order = await backendCheckout(
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1485
|
+
const order = await backendCheckout(config, ctx, {
|
|
1486
|
+
customerEmail: str2(body.customerEmail),
|
|
1487
|
+
poNumber: optionalStr(body.poNumber),
|
|
1488
|
+
customerNote: optionalStr(body.customerNote),
|
|
1489
|
+
shippingAddress: shippingAddress(body.shippingAddress)
|
|
1490
|
+
});
|
|
1393
1491
|
await clearCartToken();
|
|
1394
1492
|
return json2({ order });
|
|
1395
1493
|
}
|
|
@@ -1465,11 +1563,18 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1465
1563
|
return refreshed;
|
|
1466
1564
|
};
|
|
1467
1565
|
}
|
|
1468
|
-
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1566
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
|
|
1469
1567
|
public {
|
|
1470
1568
|
model {
|
|
1471
|
-
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit) {
|
|
1472
|
-
|
|
1569
|
+
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit, offset: $offset, sort: $sort) {
|
|
1570
|
+
total
|
|
1571
|
+
hasMore
|
|
1572
|
+
items {
|
|
1573
|
+
id
|
|
1574
|
+
data
|
|
1575
|
+
priceTiers { minQty price }
|
|
1576
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1577
|
+
}
|
|
1473
1578
|
}
|
|
1474
1579
|
}
|
|
1475
1580
|
}
|
|
@@ -1483,20 +1588,22 @@ async function fetchProducts(config, options) {
|
|
|
1483
1588
|
workspaceId,
|
|
1484
1589
|
modelSlug: options.modelSlug,
|
|
1485
1590
|
filter: options.filter ?? {},
|
|
1486
|
-
limit: options.limit ?? 50
|
|
1591
|
+
limit: options.limit ?? 50,
|
|
1592
|
+
offset: options.offset ?? 0,
|
|
1593
|
+
sort: options.sort ?? null
|
|
1487
1594
|
},
|
|
1488
1595
|
{ headers: { "x-workspace-id": workspaceId } },
|
|
1489
1596
|
"products query"
|
|
1490
1597
|
);
|
|
1491
|
-
return data.public.model.records
|
|
1598
|
+
return data.public.model.records;
|
|
1492
1599
|
}
|
|
1493
1600
|
async function fetchProduct(config, options) {
|
|
1494
|
-
const
|
|
1601
|
+
const page = await fetchProducts(config, {
|
|
1495
1602
|
modelSlug: options.modelSlug,
|
|
1496
1603
|
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1497
1604
|
limit: 1
|
|
1498
1605
|
});
|
|
1499
|
-
return
|
|
1606
|
+
return page.items[0] ?? null;
|
|
1500
1607
|
}
|
|
1501
1608
|
var ORDER_FIELDS = `
|
|
1502
1609
|
id
|
|
@@ -1523,9 +1630,45 @@ var ORDER_FIELDS = `
|
|
|
1523
1630
|
paidAt
|
|
1524
1631
|
fulfilledAt
|
|
1525
1632
|
createdAt
|
|
1526
|
-
|
|
1633
|
+
orderNumber
|
|
1634
|
+
poNumber
|
|
1635
|
+
customerNote
|
|
1636
|
+
shippingTotal
|
|
1637
|
+
shippingMethod { id label price }
|
|
1638
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1639
|
+
items { name price listPrice tierMinQty currency quantity sku }
|
|
1527
1640
|
payments { amount reference provider at }
|
|
1528
1641
|
`;
|
|
1642
|
+
var PUBLIC_ORDER_FIELDS = `
|
|
1643
|
+
id
|
|
1644
|
+
orderNumber
|
|
1645
|
+
status
|
|
1646
|
+
paymentStatus
|
|
1647
|
+
fulfillmentStatus
|
|
1648
|
+
subtotal
|
|
1649
|
+
tax
|
|
1650
|
+
total
|
|
1651
|
+
pricesIncludeTax
|
|
1652
|
+
taxSummary { rateId name rate base amount }
|
|
1653
|
+
currency
|
|
1654
|
+
customerEmail
|
|
1655
|
+
poNumber
|
|
1656
|
+
customerNote
|
|
1657
|
+
shippingTotal
|
|
1658
|
+
shippingMethod { id label price }
|
|
1659
|
+
shippingAddress { name company line1 line2 postalCode city region country phone vatId }
|
|
1660
|
+
amountPaid
|
|
1661
|
+
balanceDue
|
|
1662
|
+
refundedAmount
|
|
1663
|
+
trackingNumber
|
|
1664
|
+
trackingCarrier
|
|
1665
|
+
invoiceNumber
|
|
1666
|
+
invoiceUrl
|
|
1667
|
+
paidAt
|
|
1668
|
+
fulfilledAt
|
|
1669
|
+
createdAt
|
|
1670
|
+
items { name price listPrice tierMinQty currency quantity sku taxRate taxAmount }
|
|
1671
|
+
`;
|
|
1529
1672
|
var MY_ORDERS = `query MyOrders($workspaceId: ID!, $skip: Int, $limit: Int) {
|
|
1530
1673
|
account {
|
|
1531
1674
|
orders(workspaceId: $workspaceId, skip: $skip, limit: $limit) {
|
|
@@ -1540,6 +1683,15 @@ var MY_ORDER = `query MyOrder($workspaceId: ID!, $id: ID!) {
|
|
|
1540
1683
|
order(workspaceId: $workspaceId, id: $id) { ${ORDER_FIELDS} }
|
|
1541
1684
|
}
|
|
1542
1685
|
}`;
|
|
1686
|
+
var PUBLIC_ORDER_BY_TOKEN = `query PublicOrder($workspaceId: ID!, $orderId: ID!, $accessToken: String!) {
|
|
1687
|
+
public {
|
|
1688
|
+
order {
|
|
1689
|
+
byToken(workspaceId: $workspaceId, orderId: $orderId, accessToken: $accessToken) {
|
|
1690
|
+
${PUBLIC_ORDER_FIELDS}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}`;
|
|
1543
1695
|
var workspaceIdCache3 = /* @__PURE__ */ new Map();
|
|
1544
1696
|
function workspaceIdFor3(config) {
|
|
1545
1697
|
const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
@@ -1580,8 +1732,26 @@ async function backendMyOrder(config, accessToken, id) {
|
|
|
1580
1732
|
);
|
|
1581
1733
|
return data.account.order;
|
|
1582
1734
|
}
|
|
1735
|
+
async function backendOrderByToken(config, options) {
|
|
1736
|
+
const workspaceId = await workspaceIdFor3(config);
|
|
1737
|
+
const data = await graphqlRequest(
|
|
1738
|
+
config,
|
|
1739
|
+
PUBLIC_ORDER_BY_TOKEN,
|
|
1740
|
+
{
|
|
1741
|
+
workspaceId,
|
|
1742
|
+
orderId: options.orderId,
|
|
1743
|
+
accessToken: options.accessToken
|
|
1744
|
+
},
|
|
1745
|
+
{ headers: { "x-workspace-id": workspaceId } },
|
|
1746
|
+
"public order lookup"
|
|
1747
|
+
);
|
|
1748
|
+
return data.public.order.byToken;
|
|
1749
|
+
}
|
|
1583
1750
|
|
|
1584
|
-
// src/
|
|
1751
|
+
// src/order-server.ts
|
|
1752
|
+
async function fetchOrderByToken(config, options) {
|
|
1753
|
+
return backendOrderByToken(config, options);
|
|
1754
|
+
}
|
|
1585
1755
|
var DEFAULT_LIMIT = 20;
|
|
1586
1756
|
var MAX_LIMIT = 100;
|
|
1587
1757
|
function json3(body, status = 200) {
|
|
@@ -1695,4 +1865,4 @@ function verifyCmssyWebhook(options) {
|
|
|
1695
1865
|
return parsed;
|
|
1696
1866
|
}
|
|
1697
1867
|
|
|
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 };
|
|
1868
|
+
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": "
|
|
3
|
+
"version": "2.0.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": "^
|
|
44
|
+
"@cmssy/react": "^2.0.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": "
|
|
58
|
+
"@cmssy/react": "2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"jose": "^6.2.3"
|