@cmssy/next 2.0.0 → 2.2.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 CHANGED
@@ -1133,6 +1133,8 @@ var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
1133
1133
  orderNumber
1134
1134
  status
1135
1135
  subtotal
1136
+ discount
1137
+ appliedDiscount { code type value amount }
1136
1138
  tax
1137
1139
  total
1138
1140
  currency
@@ -1377,24 +1379,42 @@ function plainObject2(value) {
1377
1379
  function optionalStr(value) {
1378
1380
  return typeof value === "string" && value.trim() ? value.trim() : null;
1379
1381
  }
1382
+ var ADDRESS_REQUIRED = [
1383
+ "name",
1384
+ "line1",
1385
+ "postalCode",
1386
+ "city",
1387
+ "country"
1388
+ ];
1389
+ var CmssyAddressError = class extends Error {
1390
+ constructor(missing) {
1391
+ super(
1392
+ `cmssy: shippingAddress is missing required field(s): ${missing.join(
1393
+ ", "
1394
+ )}. Expected { name, line1, postalCode, city, country } (plus optional company, line2, region, phone, vatId).`
1395
+ );
1396
+ this.missing = missing;
1397
+ this.name = "CmssyAddressError";
1398
+ }
1399
+ missing;
1400
+ };
1380
1401
  function shippingAddress(value) {
1381
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
1402
+ if (value === void 0 || value === null) return null;
1403
+ if (typeof value !== "object" || Array.isArray(value)) {
1404
+ throw new CmssyAddressError([...ADDRESS_REQUIRED]);
1405
+ }
1382
1406
  const raw = value;
1383
- const 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;
1407
+ const missing = ADDRESS_REQUIRED.filter((key) => !optionalStr(raw[key]));
1408
+ if (missing.length > 0) throw new CmssyAddressError(missing);
1389
1409
  return {
1390
- name,
1410
+ name: optionalStr(raw.name),
1391
1411
  company: optionalStr(raw.company),
1392
- line1,
1412
+ line1: optionalStr(raw.line1),
1393
1413
  line2: optionalStr(raw.line2),
1394
- postalCode,
1395
- city,
1414
+ postalCode: optionalStr(raw.postalCode),
1415
+ city: optionalStr(raw.city),
1396
1416
  region: optionalStr(raw.region),
1397
- country,
1417
+ country: optionalStr(raw.country),
1398
1418
  phone: optionalStr(raw.phone),
1399
1419
  vatId: optionalStr(raw.vatId)
1400
1420
  };
@@ -1505,6 +1525,9 @@ function createCmssyCartRoute(config) {
1505
1525
  return json2({ message: "Not found." }, 404);
1506
1526
  }
1507
1527
  } catch (err) {
1528
+ if (err instanceof CmssyAddressError) {
1529
+ return json2({ message: err.message, missing: err.missing }, 400);
1530
+ }
1508
1531
  return json2(
1509
1532
  {
1510
1533
  message: err instanceof Error ? err.message : "Commerce request failed"
@@ -1564,10 +1587,10 @@ function createCmssyAuthMiddleware(config) {
1564
1587
  return refreshed;
1565
1588
  };
1566
1589
  }
1567
- var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
1590
+ var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $stockState: String, $limit: Int, $offset: Int, $sort: String) {
1568
1591
  public {
1569
1592
  model {
1570
- records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit, offset: $offset, sort: $sort) {
1593
+ records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, stockState: $stockState, limit: $limit, offset: $offset, sort: $sort) {
1571
1594
  total
1572
1595
  hasMore
1573
1596
  items {
@@ -1589,6 +1612,7 @@ async function fetchProducts(config, options) {
1589
1612
  workspaceId,
1590
1613
  modelSlug: options.modelSlug,
1591
1614
  filter: options.filter ?? {},
1615
+ stockState: options.stockState ?? null,
1592
1616
  limit: options.limit ?? 50,
1593
1617
  offset: options.offset ?? 0,
1594
1618
  sort: options.sort ?? null
@@ -1610,6 +1634,8 @@ var ORDER_FIELDS = `
1610
1634
  id
1611
1635
  status
1612
1636
  subtotal
1637
+ discount
1638
+ appliedDiscount { code type value amount }
1613
1639
  tax
1614
1640
  total
1615
1641
  pricesIncludeTax
@@ -1647,6 +1673,8 @@ var PUBLIC_ORDER_FIELDS = `
1647
1673
  paymentStatus
1648
1674
  fulfillmentStatus
1649
1675
  subtotal
1676
+ discount
1677
+ appliedDiscount { code type value amount }
1650
1678
  tax
1651
1679
  total
1652
1680
  pricesIncludeTax
package/dist/index.d.cts CHANGED
@@ -286,9 +286,17 @@ declare function getCmssyAccessToken(config: CmssyNextConfig): Promise<string |
286
286
  type CmssyAuthMiddleware = (request: NextRequest) => Promise<NextResponse>;
287
287
  declare function createCmssyAuthMiddleware(config: CmssyNextConfig): CmssyAuthMiddleware;
288
288
 
289
+ type CmssyStockState = "in" | "low" | "out";
289
290
  interface FetchProductsOptions {
290
291
  modelSlug: string;
291
292
  filter?: Record<string, unknown>;
293
+ /**
294
+ * Availability facet: "in", "low" or "out". Stock is not a data field -
295
+ * availability is onHand minus reserved, summed across variants - so it
296
+ * cannot go through `filter`. The backend applies the same rule the admin
297
+ * catalog uses, so this facet cannot contradict the stock badge.
298
+ */
299
+ stockState?: CmssyStockState;
292
300
  limit?: number;
293
301
  offset?: number;
294
302
  sort?: string;
@@ -385,4 +393,4 @@ declare class CmssyWebhookError extends Error {
385
393
  */
386
394
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
387
395
 
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 };
396
+ 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, type CmssyStockState, 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
@@ -286,9 +286,17 @@ declare function getCmssyAccessToken(config: CmssyNextConfig): Promise<string |
286
286
  type CmssyAuthMiddleware = (request: NextRequest) => Promise<NextResponse>;
287
287
  declare function createCmssyAuthMiddleware(config: CmssyNextConfig): CmssyAuthMiddleware;
288
288
 
289
+ type CmssyStockState = "in" | "low" | "out";
289
290
  interface FetchProductsOptions {
290
291
  modelSlug: string;
291
292
  filter?: Record<string, unknown>;
293
+ /**
294
+ * Availability facet: "in", "low" or "out". Stock is not a data field -
295
+ * availability is onHand minus reserved, summed across variants - so it
296
+ * cannot go through `filter`. The backend applies the same rule the admin
297
+ * catalog uses, so this facet cannot contradict the stock badge.
298
+ */
299
+ stockState?: CmssyStockState;
292
300
  limit?: number;
293
301
  offset?: number;
294
302
  sort?: string;
@@ -385,4 +393,4 @@ declare class CmssyWebhookError extends Error {
385
393
  */
386
394
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
387
395
 
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 };
396
+ 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, type CmssyStockState, 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
@@ -1132,6 +1132,8 @@ var CHECKOUT = `mutation Checkout($input: CheckoutInput!) {
1132
1132
  orderNumber
1133
1133
  status
1134
1134
  subtotal
1135
+ discount
1136
+ appliedDiscount { code type value amount }
1135
1137
  tax
1136
1138
  total
1137
1139
  currency
@@ -1376,24 +1378,42 @@ function plainObject2(value) {
1376
1378
  function optionalStr(value) {
1377
1379
  return typeof value === "string" && value.trim() ? value.trim() : null;
1378
1380
  }
1381
+ var ADDRESS_REQUIRED = [
1382
+ "name",
1383
+ "line1",
1384
+ "postalCode",
1385
+ "city",
1386
+ "country"
1387
+ ];
1388
+ var CmssyAddressError = class extends Error {
1389
+ constructor(missing) {
1390
+ super(
1391
+ `cmssy: shippingAddress is missing required field(s): ${missing.join(
1392
+ ", "
1393
+ )}. Expected { name, line1, postalCode, city, country } (plus optional company, line2, region, phone, vatId).`
1394
+ );
1395
+ this.missing = missing;
1396
+ this.name = "CmssyAddressError";
1397
+ }
1398
+ missing;
1399
+ };
1379
1400
  function shippingAddress(value) {
1380
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
1401
+ if (value === void 0 || value === null) return null;
1402
+ if (typeof value !== "object" || Array.isArray(value)) {
1403
+ throw new CmssyAddressError([...ADDRESS_REQUIRED]);
1404
+ }
1381
1405
  const raw = value;
1382
- const 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;
1406
+ const missing = ADDRESS_REQUIRED.filter((key) => !optionalStr(raw[key]));
1407
+ if (missing.length > 0) throw new CmssyAddressError(missing);
1388
1408
  return {
1389
- name,
1409
+ name: optionalStr(raw.name),
1390
1410
  company: optionalStr(raw.company),
1391
- line1,
1411
+ line1: optionalStr(raw.line1),
1392
1412
  line2: optionalStr(raw.line2),
1393
- postalCode,
1394
- city,
1413
+ postalCode: optionalStr(raw.postalCode),
1414
+ city: optionalStr(raw.city),
1395
1415
  region: optionalStr(raw.region),
1396
- country,
1416
+ country: optionalStr(raw.country),
1397
1417
  phone: optionalStr(raw.phone),
1398
1418
  vatId: optionalStr(raw.vatId)
1399
1419
  };
@@ -1504,6 +1524,9 @@ function createCmssyCartRoute(config) {
1504
1524
  return json2({ message: "Not found." }, 404);
1505
1525
  }
1506
1526
  } catch (err) {
1527
+ if (err instanceof CmssyAddressError) {
1528
+ return json2({ message: err.message, missing: err.missing }, 400);
1529
+ }
1507
1530
  return json2(
1508
1531
  {
1509
1532
  message: err instanceof Error ? err.message : "Commerce request failed"
@@ -1563,10 +1586,10 @@ function createCmssyAuthMiddleware(config) {
1563
1586
  return refreshed;
1564
1587
  };
1565
1588
  }
1566
- var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int, $offset: Int, $sort: String) {
1589
+ var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $stockState: String, $limit: Int, $offset: Int, $sort: String) {
1567
1590
  public {
1568
1591
  model {
1569
- records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit, offset: $offset, sort: $sort) {
1592
+ records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, stockState: $stockState, limit: $limit, offset: $offset, sort: $sort) {
1570
1593
  total
1571
1594
  hasMore
1572
1595
  items {
@@ -1588,6 +1611,7 @@ async function fetchProducts(config, options) {
1588
1611
  workspaceId,
1589
1612
  modelSlug: options.modelSlug,
1590
1613
  filter: options.filter ?? {},
1614
+ stockState: options.stockState ?? null,
1591
1615
  limit: options.limit ?? 50,
1592
1616
  offset: options.offset ?? 0,
1593
1617
  sort: options.sort ?? null
@@ -1609,6 +1633,8 @@ var ORDER_FIELDS = `
1609
1633
  id
1610
1634
  status
1611
1635
  subtotal
1636
+ discount
1637
+ appliedDiscount { code type value amount }
1612
1638
  tax
1613
1639
  total
1614
1640
  pricesIncludeTax
@@ -1646,6 +1672,8 @@ var PUBLIC_ORDER_FIELDS = `
1646
1672
  paymentStatus
1647
1673
  fulfillmentStatus
1648
1674
  subtotal
1675
+ discount
1676
+ appliedDiscount { code type value amount }
1649
1677
  tax
1650
1678
  total
1651
1679
  pricesIncludeTax
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/next",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -41,7 +41,7 @@
41
41
  "dist"
42
42
  ],
43
43
  "peerDependencies": {
44
- "@cmssy/react": "^2.0.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": "2.0.0"
58
+ "@cmssy/react": "2.2.0"
59
59
  },
60
60
  "dependencies": {
61
61
  "jose": "^6.2.3"