@cmssy/next 0.18.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 +233 -38
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +233 -39
- 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]);
|
|
@@ -691,32 +692,48 @@ function createCmssyLocaleMiddleware(config) {
|
|
|
691
692
|
};
|
|
692
693
|
}
|
|
693
694
|
var LOGIN_MUTATION = `mutation SiteMemberLogin($input: SiteMemberLoginInput!) {
|
|
694
|
-
|
|
695
|
-
|
|
695
|
+
siteMember {
|
|
696
|
+
login(input: $input) {
|
|
697
|
+
success message accessToken refreshToken accessTokenExpiresIn
|
|
698
|
+
}
|
|
696
699
|
}
|
|
697
700
|
}`;
|
|
698
701
|
var REGISTER_MUTATION = `mutation SiteMemberRegister($input: SiteMemberRegisterInput!) {
|
|
699
|
-
|
|
702
|
+
siteMember {
|
|
703
|
+
register(input: $input) { success message }
|
|
704
|
+
}
|
|
700
705
|
}`;
|
|
701
706
|
var REFRESH_MUTATION = `mutation SiteMemberRefresh($refreshToken: String!) {
|
|
702
|
-
|
|
703
|
-
|
|
707
|
+
siteMember {
|
|
708
|
+
refresh(refreshToken: $refreshToken) {
|
|
709
|
+
success message accessToken refreshToken accessTokenExpiresIn
|
|
710
|
+
}
|
|
704
711
|
}
|
|
705
712
|
}`;
|
|
706
713
|
var LOGOUT_MUTATION = `mutation SiteMemberLogout($refreshToken: String!) {
|
|
707
|
-
|
|
714
|
+
siteMember {
|
|
715
|
+
logout(refreshToken: $refreshToken) { success message }
|
|
716
|
+
}
|
|
708
717
|
}`;
|
|
709
718
|
var LOGOUT_EVERYWHERE_MUTATION = `mutation SiteMemberLogoutEverywhere {
|
|
710
|
-
|
|
719
|
+
siteMember {
|
|
720
|
+
logoutEverywhere { success message }
|
|
721
|
+
}
|
|
711
722
|
}`;
|
|
712
723
|
var FORGOT_MUTATION = `mutation SiteMemberForgotPassword($modelSlug: String!, $identity: String!) {
|
|
713
|
-
|
|
724
|
+
siteMember {
|
|
725
|
+
forgotPassword(modelSlug: $modelSlug, identity: $identity) { success message }
|
|
726
|
+
}
|
|
714
727
|
}`;
|
|
715
728
|
var RESET_MUTATION = `mutation SiteMemberResetPassword($token: String!, $newPassword: String!) {
|
|
716
|
-
|
|
729
|
+
siteMember {
|
|
730
|
+
resetPassword(token: $token, newPassword: $newPassword) { success message }
|
|
731
|
+
}
|
|
717
732
|
}`;
|
|
718
733
|
var VERIFY_MUTATION = `mutation SiteMemberVerifyEmail($token: String!) {
|
|
719
|
-
|
|
734
|
+
siteMember {
|
|
735
|
+
verifyEmail(token: $token) { success message }
|
|
736
|
+
}
|
|
720
737
|
}`;
|
|
721
738
|
var workspaceIdCache = /* @__PURE__ */ new Map();
|
|
722
739
|
function workspaceIdFor(config) {
|
|
@@ -782,7 +799,7 @@ async function backendSignIn(config, modelSlug, identity, password) {
|
|
|
782
799
|
},
|
|
783
800
|
"site member login"
|
|
784
801
|
);
|
|
785
|
-
return data.
|
|
802
|
+
return data.siteMember.login;
|
|
786
803
|
}
|
|
787
804
|
async function backendRegister(config, modelSlug, identity, password, fields) {
|
|
788
805
|
const data = await authRequest(
|
|
@@ -793,7 +810,7 @@ async function backendRegister(config, modelSlug, identity, password, fields) {
|
|
|
793
810
|
},
|
|
794
811
|
"site member register"
|
|
795
812
|
);
|
|
796
|
-
return data.
|
|
813
|
+
return data.siteMember.register;
|
|
797
814
|
}
|
|
798
815
|
async function backendRefresh(config, refreshToken) {
|
|
799
816
|
const data = await authRequest(
|
|
@@ -802,7 +819,7 @@ async function backendRefresh(config, refreshToken) {
|
|
|
802
819
|
{ refreshToken },
|
|
803
820
|
"site member refresh"
|
|
804
821
|
);
|
|
805
|
-
return data.
|
|
822
|
+
return data.siteMember.refresh;
|
|
806
823
|
}
|
|
807
824
|
async function backendSignOut(config, refreshToken) {
|
|
808
825
|
try {
|
|
@@ -836,7 +853,7 @@ async function backendForgotPassword(config, modelSlug, identity) {
|
|
|
836
853
|
{ modelSlug, identity },
|
|
837
854
|
"site member forgot password"
|
|
838
855
|
);
|
|
839
|
-
return data.
|
|
856
|
+
return data.siteMember.forgotPassword;
|
|
840
857
|
}
|
|
841
858
|
async function backendResetPassword(config, token, newPassword) {
|
|
842
859
|
const data = await authRequest(
|
|
@@ -845,7 +862,7 @@ async function backendResetPassword(config, token, newPassword) {
|
|
|
845
862
|
{ token, newPassword },
|
|
846
863
|
"site member reset password"
|
|
847
864
|
);
|
|
848
|
-
return data.
|
|
865
|
+
return data.siteMember.resetPassword;
|
|
849
866
|
}
|
|
850
867
|
async function backendVerifyEmail(config, token) {
|
|
851
868
|
const data = await authRequest(
|
|
@@ -854,7 +871,7 @@ async function backendVerifyEmail(config, token) {
|
|
|
854
871
|
{ token },
|
|
855
872
|
"site member verify email"
|
|
856
873
|
);
|
|
857
|
-
return data.
|
|
874
|
+
return data.siteMember.verifyEmail;
|
|
858
875
|
}
|
|
859
876
|
|
|
860
877
|
// src/create-auth-route.ts
|
|
@@ -1079,15 +1096,23 @@ var CART_FIELDS = `
|
|
|
1079
1096
|
subtotal
|
|
1080
1097
|
currency
|
|
1081
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 }
|
|
1082
1106
|
appliedDiscount { code type value computedAmount }
|
|
1083
1107
|
items {
|
|
1084
1108
|
id
|
|
1085
1109
|
recordId
|
|
1086
1110
|
quantity
|
|
1087
1111
|
variantSelections
|
|
1112
|
+
unitPrice
|
|
1088
1113
|
currentPrice
|
|
1089
1114
|
priceMismatch
|
|
1090
|
-
snapshot { name price currency imageUrl sku }
|
|
1115
|
+
snapshot { name price currency imageUrl sku tiers { minQty price } }
|
|
1091
1116
|
}
|
|
1092
1117
|
`;
|
|
1093
1118
|
var CART_QUERY = `query Cart($workspaceId: ID!) { cart { get(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
@@ -1097,12 +1122,45 @@ var REMOVE_ITEM = `mutation RemoveCartItem($workspaceId: ID!, $itemId: ID!) { ca
|
|
|
1097
1122
|
var CLEAR_CART = `mutation ClearCart($workspaceId: ID!) { cart { clear(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1098
1123
|
var APPLY_DISCOUNT = `mutation ApplyDiscount($workspaceId: ID!, $code: String!) { cart { applyDiscount(workspaceId: $workspaceId, code: $code) { ${CART_FIELDS} } } }`;
|
|
1099
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} } } }`;
|
|
1100
1129
|
var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
|
|
1101
|
-
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
|
+
}
|
|
1102
1151
|
}`;
|
|
1103
1152
|
var PRODUCT = `query Product($workspaceId: String!, $modelSlug: String!, $filter: JSON) {
|
|
1104
|
-
|
|
1105
|
-
|
|
1153
|
+
public {
|
|
1154
|
+
model {
|
|
1155
|
+
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: 1) {
|
|
1156
|
+
items {
|
|
1157
|
+
id
|
|
1158
|
+
data
|
|
1159
|
+
priceTiers { minQty price }
|
|
1160
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1106
1164
|
}
|
|
1107
1165
|
}`;
|
|
1108
1166
|
var workspaceIdCache2 = /* @__PURE__ */ new Map();
|
|
@@ -1216,14 +1274,38 @@ async function backendRemoveDiscount(config, ctx) {
|
|
|
1216
1274
|
);
|
|
1217
1275
|
return data.cart.removeDiscount;
|
|
1218
1276
|
}
|
|
1219
|
-
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) {
|
|
1220
1302
|
const workspaceId = await workspaceIdFor2(config);
|
|
1221
1303
|
const data = await request(
|
|
1222
1304
|
config,
|
|
1223
1305
|
ctx,
|
|
1224
1306
|
workspaceId,
|
|
1225
1307
|
CHECKOUT,
|
|
1226
|
-
{ input: { workspaceId,
|
|
1308
|
+
{ input: { workspaceId, ...input } },
|
|
1227
1309
|
"checkout"
|
|
1228
1310
|
);
|
|
1229
1311
|
return data.cart.checkout;
|
|
@@ -1238,7 +1320,7 @@ async function backendProduct(config, ctx, modelSlug, filter) {
|
|
|
1238
1320
|
{ workspaceId, modelSlug, filter },
|
|
1239
1321
|
"product query"
|
|
1240
1322
|
);
|
|
1241
|
-
return data.
|
|
1323
|
+
return data.public.model.records.items[0] ?? null;
|
|
1242
1324
|
}
|
|
1243
1325
|
|
|
1244
1326
|
// src/create-cart-route.ts
|
|
@@ -1292,6 +1374,31 @@ function plainObject2(value) {
|
|
|
1292
1374
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1293
1375
|
return value;
|
|
1294
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
|
+
}
|
|
1295
1402
|
function createCmssyCartRoute(config) {
|
|
1296
1403
|
async function ensureCartToken() {
|
|
1297
1404
|
const jar = await headers.cookies();
|
|
@@ -1365,12 +1472,23 @@ function createCmssyCartRoute(config) {
|
|
|
1365
1472
|
});
|
|
1366
1473
|
case "remove-discount":
|
|
1367
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) });
|
|
1368
1485
|
case "checkout": {
|
|
1369
|
-
const order = await backendCheckout(
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
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
|
+
});
|
|
1374
1492
|
await clearCartToken();
|
|
1375
1493
|
return json2({ order });
|
|
1376
1494
|
}
|
|
@@ -1446,9 +1564,20 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1446
1564
|
return refreshed;
|
|
1447
1565
|
};
|
|
1448
1566
|
}
|
|
1449
|
-
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1450
|
-
|
|
1451
|
-
|
|
1567
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
|
|
1568
|
+
public {
|
|
1569
|
+
model {
|
|
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
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1452
1581
|
}
|
|
1453
1582
|
}`;
|
|
1454
1583
|
async function fetchProducts(config, options) {
|
|
@@ -1460,20 +1589,22 @@ async function fetchProducts(config, options) {
|
|
|
1460
1589
|
workspaceId,
|
|
1461
1590
|
modelSlug: options.modelSlug,
|
|
1462
1591
|
filter: options.filter ?? {},
|
|
1463
|
-
limit: options.limit ?? 50
|
|
1592
|
+
limit: options.limit ?? 50,
|
|
1593
|
+
offset: options.offset ?? 0,
|
|
1594
|
+
sort: options.sort ?? null
|
|
1464
1595
|
},
|
|
1465
1596
|
{ headers: { "x-workspace-id": workspaceId } },
|
|
1466
1597
|
"products query"
|
|
1467
1598
|
);
|
|
1468
|
-
return data.
|
|
1599
|
+
return data.public.model.records;
|
|
1469
1600
|
}
|
|
1470
1601
|
async function fetchProduct(config, options) {
|
|
1471
|
-
const
|
|
1602
|
+
const page = await fetchProducts(config, {
|
|
1472
1603
|
modelSlug: options.modelSlug,
|
|
1473
1604
|
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1474
1605
|
limit: 1
|
|
1475
1606
|
});
|
|
1476
|
-
return
|
|
1607
|
+
return page.items[0] ?? null;
|
|
1477
1608
|
}
|
|
1478
1609
|
var ORDER_FIELDS = `
|
|
1479
1610
|
id
|
|
@@ -1500,9 +1631,45 @@ var ORDER_FIELDS = `
|
|
|
1500
1631
|
paidAt
|
|
1501
1632
|
fulfilledAt
|
|
1502
1633
|
createdAt
|
|
1503
|
-
|
|
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 }
|
|
1504
1641
|
payments { amount reference provider at }
|
|
1505
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
|
+
`;
|
|
1506
1673
|
var MY_ORDERS = `query MyOrders($workspaceId: ID!, $skip: Int, $limit: Int) {
|
|
1507
1674
|
account {
|
|
1508
1675
|
orders(workspaceId: $workspaceId, skip: $skip, limit: $limit) {
|
|
@@ -1517,6 +1684,15 @@ var MY_ORDER = `query MyOrder($workspaceId: ID!, $id: ID!) {
|
|
|
1517
1684
|
order(workspaceId: $workspaceId, id: $id) { ${ORDER_FIELDS} }
|
|
1518
1685
|
}
|
|
1519
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
|
+
}`;
|
|
1520
1696
|
var workspaceIdCache3 = /* @__PURE__ */ new Map();
|
|
1521
1697
|
function workspaceIdFor3(config) {
|
|
1522
1698
|
const key = `${react.resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
@@ -1557,8 +1733,26 @@ async function backendMyOrder(config, accessToken, id) {
|
|
|
1557
1733
|
);
|
|
1558
1734
|
return data.account.order;
|
|
1559
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
|
+
}
|
|
1560
1751
|
|
|
1561
|
-
// src/
|
|
1752
|
+
// src/order-server.ts
|
|
1753
|
+
async function fetchOrderByToken(config, options) {
|
|
1754
|
+
return backendOrderByToken(config, options);
|
|
1755
|
+
}
|
|
1562
1756
|
var DEFAULT_LIMIT = 20;
|
|
1563
1757
|
var MAX_LIMIT = 100;
|
|
1564
1758
|
function json3(body, status = 200) {
|
|
@@ -1706,6 +1900,7 @@ exports.createCmssyRobots = createCmssyRobots;
|
|
|
1706
1900
|
exports.createCmssySitemap = createCmssySitemap;
|
|
1707
1901
|
exports.createDraftRoute = createDraftRoute;
|
|
1708
1902
|
exports.defineCmssyConfig = defineCmssyConfig;
|
|
1903
|
+
exports.fetchOrderByToken = fetchOrderByToken;
|
|
1709
1904
|
exports.fetchProduct = fetchProduct;
|
|
1710
1905
|
exports.fetchProducts = fetchProducts;
|
|
1711
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]);
|
|
@@ -690,32 +691,48 @@ function createCmssyLocaleMiddleware(config) {
|
|
|
690
691
|
};
|
|
691
692
|
}
|
|
692
693
|
var LOGIN_MUTATION = `mutation SiteMemberLogin($input: SiteMemberLoginInput!) {
|
|
693
|
-
|
|
694
|
-
|
|
694
|
+
siteMember {
|
|
695
|
+
login(input: $input) {
|
|
696
|
+
success message accessToken refreshToken accessTokenExpiresIn
|
|
697
|
+
}
|
|
695
698
|
}
|
|
696
699
|
}`;
|
|
697
700
|
var REGISTER_MUTATION = `mutation SiteMemberRegister($input: SiteMemberRegisterInput!) {
|
|
698
|
-
|
|
701
|
+
siteMember {
|
|
702
|
+
register(input: $input) { success message }
|
|
703
|
+
}
|
|
699
704
|
}`;
|
|
700
705
|
var REFRESH_MUTATION = `mutation SiteMemberRefresh($refreshToken: String!) {
|
|
701
|
-
|
|
702
|
-
|
|
706
|
+
siteMember {
|
|
707
|
+
refresh(refreshToken: $refreshToken) {
|
|
708
|
+
success message accessToken refreshToken accessTokenExpiresIn
|
|
709
|
+
}
|
|
703
710
|
}
|
|
704
711
|
}`;
|
|
705
712
|
var LOGOUT_MUTATION = `mutation SiteMemberLogout($refreshToken: String!) {
|
|
706
|
-
|
|
713
|
+
siteMember {
|
|
714
|
+
logout(refreshToken: $refreshToken) { success message }
|
|
715
|
+
}
|
|
707
716
|
}`;
|
|
708
717
|
var LOGOUT_EVERYWHERE_MUTATION = `mutation SiteMemberLogoutEverywhere {
|
|
709
|
-
|
|
718
|
+
siteMember {
|
|
719
|
+
logoutEverywhere { success message }
|
|
720
|
+
}
|
|
710
721
|
}`;
|
|
711
722
|
var FORGOT_MUTATION = `mutation SiteMemberForgotPassword($modelSlug: String!, $identity: String!) {
|
|
712
|
-
|
|
723
|
+
siteMember {
|
|
724
|
+
forgotPassword(modelSlug: $modelSlug, identity: $identity) { success message }
|
|
725
|
+
}
|
|
713
726
|
}`;
|
|
714
727
|
var RESET_MUTATION = `mutation SiteMemberResetPassword($token: String!, $newPassword: String!) {
|
|
715
|
-
|
|
728
|
+
siteMember {
|
|
729
|
+
resetPassword(token: $token, newPassword: $newPassword) { success message }
|
|
730
|
+
}
|
|
716
731
|
}`;
|
|
717
732
|
var VERIFY_MUTATION = `mutation SiteMemberVerifyEmail($token: String!) {
|
|
718
|
-
|
|
733
|
+
siteMember {
|
|
734
|
+
verifyEmail(token: $token) { success message }
|
|
735
|
+
}
|
|
719
736
|
}`;
|
|
720
737
|
var workspaceIdCache = /* @__PURE__ */ new Map();
|
|
721
738
|
function workspaceIdFor(config) {
|
|
@@ -781,7 +798,7 @@ async function backendSignIn(config, modelSlug, identity, password) {
|
|
|
781
798
|
},
|
|
782
799
|
"site member login"
|
|
783
800
|
);
|
|
784
|
-
return data.
|
|
801
|
+
return data.siteMember.login;
|
|
785
802
|
}
|
|
786
803
|
async function backendRegister(config, modelSlug, identity, password, fields) {
|
|
787
804
|
const data = await authRequest(
|
|
@@ -792,7 +809,7 @@ async function backendRegister(config, modelSlug, identity, password, fields) {
|
|
|
792
809
|
},
|
|
793
810
|
"site member register"
|
|
794
811
|
);
|
|
795
|
-
return data.
|
|
812
|
+
return data.siteMember.register;
|
|
796
813
|
}
|
|
797
814
|
async function backendRefresh(config, refreshToken) {
|
|
798
815
|
const data = await authRequest(
|
|
@@ -801,7 +818,7 @@ async function backendRefresh(config, refreshToken) {
|
|
|
801
818
|
{ refreshToken },
|
|
802
819
|
"site member refresh"
|
|
803
820
|
);
|
|
804
|
-
return data.
|
|
821
|
+
return data.siteMember.refresh;
|
|
805
822
|
}
|
|
806
823
|
async function backendSignOut(config, refreshToken) {
|
|
807
824
|
try {
|
|
@@ -835,7 +852,7 @@ async function backendForgotPassword(config, modelSlug, identity) {
|
|
|
835
852
|
{ modelSlug, identity },
|
|
836
853
|
"site member forgot password"
|
|
837
854
|
);
|
|
838
|
-
return data.
|
|
855
|
+
return data.siteMember.forgotPassword;
|
|
839
856
|
}
|
|
840
857
|
async function backendResetPassword(config, token, newPassword) {
|
|
841
858
|
const data = await authRequest(
|
|
@@ -844,7 +861,7 @@ async function backendResetPassword(config, token, newPassword) {
|
|
|
844
861
|
{ token, newPassword },
|
|
845
862
|
"site member reset password"
|
|
846
863
|
);
|
|
847
|
-
return data.
|
|
864
|
+
return data.siteMember.resetPassword;
|
|
848
865
|
}
|
|
849
866
|
async function backendVerifyEmail(config, token) {
|
|
850
867
|
const data = await authRequest(
|
|
@@ -853,7 +870,7 @@ async function backendVerifyEmail(config, token) {
|
|
|
853
870
|
{ token },
|
|
854
871
|
"site member verify email"
|
|
855
872
|
);
|
|
856
|
-
return data.
|
|
873
|
+
return data.siteMember.verifyEmail;
|
|
857
874
|
}
|
|
858
875
|
|
|
859
876
|
// src/create-auth-route.ts
|
|
@@ -1078,15 +1095,23 @@ var CART_FIELDS = `
|
|
|
1078
1095
|
subtotal
|
|
1079
1096
|
currency
|
|
1080
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 }
|
|
1081
1105
|
appliedDiscount { code type value computedAmount }
|
|
1082
1106
|
items {
|
|
1083
1107
|
id
|
|
1084
1108
|
recordId
|
|
1085
1109
|
quantity
|
|
1086
1110
|
variantSelections
|
|
1111
|
+
unitPrice
|
|
1087
1112
|
currentPrice
|
|
1088
1113
|
priceMismatch
|
|
1089
|
-
snapshot { name price currency imageUrl sku }
|
|
1114
|
+
snapshot { name price currency imageUrl sku tiers { minQty price } }
|
|
1090
1115
|
}
|
|
1091
1116
|
`;
|
|
1092
1117
|
var CART_QUERY = `query Cart($workspaceId: ID!) { cart { get(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
@@ -1096,12 +1121,45 @@ var REMOVE_ITEM = `mutation RemoveCartItem($workspaceId: ID!, $itemId: ID!) { ca
|
|
|
1096
1121
|
var CLEAR_CART = `mutation ClearCart($workspaceId: ID!) { cart { clear(workspaceId: $workspaceId) { ${CART_FIELDS} } } }`;
|
|
1097
1122
|
var APPLY_DISCOUNT = `mutation ApplyDiscount($workspaceId: ID!, $code: String!) { cart { applyDiscount(workspaceId: $workspaceId, code: $code) { ${CART_FIELDS} } } }`;
|
|
1098
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} } } }`;
|
|
1099
1128
|
var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
|
|
1100
|
-
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
|
+
}
|
|
1101
1150
|
}`;
|
|
1102
1151
|
var PRODUCT = `query Product($workspaceId: String!, $modelSlug: String!, $filter: JSON) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1152
|
+
public {
|
|
1153
|
+
model {
|
|
1154
|
+
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: 1) {
|
|
1155
|
+
items {
|
|
1156
|
+
id
|
|
1157
|
+
data
|
|
1158
|
+
priceTiers { minQty price }
|
|
1159
|
+
variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1105
1163
|
}
|
|
1106
1164
|
}`;
|
|
1107
1165
|
var workspaceIdCache2 = /* @__PURE__ */ new Map();
|
|
@@ -1215,14 +1273,38 @@ async function backendRemoveDiscount(config, ctx) {
|
|
|
1215
1273
|
);
|
|
1216
1274
|
return data.cart.removeDiscount;
|
|
1217
1275
|
}
|
|
1218
|
-
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) {
|
|
1219
1301
|
const workspaceId = await workspaceIdFor2(config);
|
|
1220
1302
|
const data = await request(
|
|
1221
1303
|
config,
|
|
1222
1304
|
ctx,
|
|
1223
1305
|
workspaceId,
|
|
1224
1306
|
CHECKOUT,
|
|
1225
|
-
{ input: { workspaceId,
|
|
1307
|
+
{ input: { workspaceId, ...input } },
|
|
1226
1308
|
"checkout"
|
|
1227
1309
|
);
|
|
1228
1310
|
return data.cart.checkout;
|
|
@@ -1237,7 +1319,7 @@ async function backendProduct(config, ctx, modelSlug, filter) {
|
|
|
1237
1319
|
{ workspaceId, modelSlug, filter },
|
|
1238
1320
|
"product query"
|
|
1239
1321
|
);
|
|
1240
|
-
return data.
|
|
1322
|
+
return data.public.model.records.items[0] ?? null;
|
|
1241
1323
|
}
|
|
1242
1324
|
|
|
1243
1325
|
// src/create-cart-route.ts
|
|
@@ -1291,6 +1373,31 @@ function plainObject2(value) {
|
|
|
1291
1373
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1292
1374
|
return value;
|
|
1293
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
|
+
}
|
|
1294
1401
|
function createCmssyCartRoute(config) {
|
|
1295
1402
|
async function ensureCartToken() {
|
|
1296
1403
|
const jar = await cookies();
|
|
@@ -1364,12 +1471,23 @@ function createCmssyCartRoute(config) {
|
|
|
1364
1471
|
});
|
|
1365
1472
|
case "remove-discount":
|
|
1366
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) });
|
|
1367
1484
|
case "checkout": {
|
|
1368
|
-
const order = await backendCheckout(
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
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
|
+
});
|
|
1373
1491
|
await clearCartToken();
|
|
1374
1492
|
return json2({ order });
|
|
1375
1493
|
}
|
|
@@ -1445,9 +1563,20 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1445
1563
|
return refreshed;
|
|
1446
1564
|
};
|
|
1447
1565
|
}
|
|
1448
|
-
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1449
|
-
|
|
1450
|
-
|
|
1566
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
|
|
1567
|
+
public {
|
|
1568
|
+
model {
|
|
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
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1451
1580
|
}
|
|
1452
1581
|
}`;
|
|
1453
1582
|
async function fetchProducts(config, options) {
|
|
@@ -1459,20 +1588,22 @@ async function fetchProducts(config, options) {
|
|
|
1459
1588
|
workspaceId,
|
|
1460
1589
|
modelSlug: options.modelSlug,
|
|
1461
1590
|
filter: options.filter ?? {},
|
|
1462
|
-
limit: options.limit ?? 50
|
|
1591
|
+
limit: options.limit ?? 50,
|
|
1592
|
+
offset: options.offset ?? 0,
|
|
1593
|
+
sort: options.sort ?? null
|
|
1463
1594
|
},
|
|
1464
1595
|
{ headers: { "x-workspace-id": workspaceId } },
|
|
1465
1596
|
"products query"
|
|
1466
1597
|
);
|
|
1467
|
-
return data.
|
|
1598
|
+
return data.public.model.records;
|
|
1468
1599
|
}
|
|
1469
1600
|
async function fetchProduct(config, options) {
|
|
1470
|
-
const
|
|
1601
|
+
const page = await fetchProducts(config, {
|
|
1471
1602
|
modelSlug: options.modelSlug,
|
|
1472
1603
|
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1473
1604
|
limit: 1
|
|
1474
1605
|
});
|
|
1475
|
-
return
|
|
1606
|
+
return page.items[0] ?? null;
|
|
1476
1607
|
}
|
|
1477
1608
|
var ORDER_FIELDS = `
|
|
1478
1609
|
id
|
|
@@ -1499,9 +1630,45 @@ var ORDER_FIELDS = `
|
|
|
1499
1630
|
paidAt
|
|
1500
1631
|
fulfilledAt
|
|
1501
1632
|
createdAt
|
|
1502
|
-
|
|
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 }
|
|
1503
1640
|
payments { amount reference provider at }
|
|
1504
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
|
+
`;
|
|
1505
1672
|
var MY_ORDERS = `query MyOrders($workspaceId: ID!, $skip: Int, $limit: Int) {
|
|
1506
1673
|
account {
|
|
1507
1674
|
orders(workspaceId: $workspaceId, skip: $skip, limit: $limit) {
|
|
@@ -1516,6 +1683,15 @@ var MY_ORDER = `query MyOrder($workspaceId: ID!, $id: ID!) {
|
|
|
1516
1683
|
order(workspaceId: $workspaceId, id: $id) { ${ORDER_FIELDS} }
|
|
1517
1684
|
}
|
|
1518
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
|
+
}`;
|
|
1519
1695
|
var workspaceIdCache3 = /* @__PURE__ */ new Map();
|
|
1520
1696
|
function workspaceIdFor3(config) {
|
|
1521
1697
|
const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
@@ -1556,8 +1732,26 @@ async function backendMyOrder(config, accessToken, id) {
|
|
|
1556
1732
|
);
|
|
1557
1733
|
return data.account.order;
|
|
1558
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
|
+
}
|
|
1559
1750
|
|
|
1560
|
-
// src/
|
|
1751
|
+
// src/order-server.ts
|
|
1752
|
+
async function fetchOrderByToken(config, options) {
|
|
1753
|
+
return backendOrderByToken(config, options);
|
|
1754
|
+
}
|
|
1561
1755
|
var DEFAULT_LIMIT = 20;
|
|
1562
1756
|
var MAX_LIMIT = 100;
|
|
1563
1757
|
function json3(body, status = 200) {
|
|
@@ -1671,4 +1865,4 @@ function verifyCmssyWebhook(options) {
|
|
|
1671
1865
|
return parsed;
|
|
1672
1866
|
}
|
|
1673
1867
|
|
|
1674
|
-
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": "0.
|
|
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": "^0.
|
|
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": "0.
|
|
58
|
+
"@cmssy/react": "2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"jose": "^6.2.3"
|