@sixtyninecommerce/client 0.24.0 → 0.25.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.
Files changed (293) hide show
  1. package/README.md +21 -0
  2. package/dist/admin/forms.js +19 -0
  3. package/dist/admin/forms.js.map +1 -1
  4. package/dist/admin/http.d.ts +9 -0
  5. package/dist/admin/http.d.ts.map +1 -1
  6. package/dist/admin/http.js +3 -0
  7. package/dist/admin/http.js.map +1 -1
  8. package/dist/admin/index.d.ts +63 -0
  9. package/dist/admin/index.d.ts.map +1 -1
  10. package/dist/admin/index.js +67 -0
  11. package/dist/admin/index.js.map +1 -1
  12. package/dist/admin/redirects.d.ts +6 -0
  13. package/dist/admin/redirects.d.ts.map +1 -1
  14. package/dist/admin/redirects.js +12 -0
  15. package/dist/admin/redirects.js.map +1 -1
  16. package/dist/admin/types.d.ts +63 -0
  17. package/dist/admin/types.d.ts.map +1 -1
  18. package/dist/cache-tags.d.ts +19 -0
  19. package/dist/cache-tags.d.ts.map +1 -1
  20. package/dist/cache-tags.js +19 -0
  21. package/dist/cache-tags.js.map +1 -1
  22. package/dist/client.d.ts +17 -0
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +17 -0
  25. package/dist/client.js.map +1 -1
  26. package/dist/commerce/age-verification.js +3 -3
  27. package/dist/commerce/age-verification.js.map +1 -1
  28. package/dist/commerce/branding.js +7 -0
  29. package/dist/commerce/branding.js.map +1 -1
  30. package/dist/commerce/cart.js +25 -0
  31. package/dist/commerce/cart.js.map +1 -1
  32. package/dist/commerce/checkout.d.ts +68 -0
  33. package/dist/commerce/checkout.d.ts.map +1 -1
  34. package/dist/commerce/checkout.js +83 -0
  35. package/dist/commerce/checkout.js.map +1 -1
  36. package/dist/commerce/customer.d.ts +58 -0
  37. package/dist/commerce/customer.d.ts.map +1 -1
  38. package/dist/commerce/customer.js +65 -0
  39. package/dist/commerce/customer.js.map +1 -1
  40. package/dist/commerce/pickup-location-parser.d.ts +18 -0
  41. package/dist/commerce/pickup-location-parser.d.ts.map +1 -1
  42. package/dist/commerce/pickup-location-parser.js +28 -0
  43. package/dist/commerce/pickup-location-parser.js.map +1 -1
  44. package/dist/commerce/placement-error.d.ts +52 -0
  45. package/dist/commerce/placement-error.d.ts.map +1 -1
  46. package/dist/commerce/placement-error.js +87 -0
  47. package/dist/commerce/placement-error.js.map +1 -1
  48. package/dist/commerce/products.d.ts +48 -0
  49. package/dist/commerce/products.d.ts.map +1 -1
  50. package/dist/commerce/products.js +92 -0
  51. package/dist/commerce/products.js.map +1 -1
  52. package/dist/commerce/queries.d.ts +113 -27
  53. package/dist/commerce/queries.d.ts.map +1 -1
  54. package/dist/commerce/queries.js +188 -2
  55. package/dist/commerce/queries.js.map +1 -1
  56. package/dist/commerce/quotes.js +33 -0
  57. package/dist/commerce/quotes.js.map +1 -1
  58. package/dist/commerce/saved-lists.d.ts +7 -7
  59. package/dist/commerce/saved-lists.d.ts.map +1 -1
  60. package/dist/commerce/saved-lists.js +1 -1
  61. package/dist/commerce/search.js +3 -0
  62. package/dist/commerce/search.js.map +1 -1
  63. package/dist/commerce/shipping.js +3 -3
  64. package/dist/commerce/shipping.js.map +1 -1
  65. package/dist/commerce/stock-notifications.d.ts +11 -0
  66. package/dist/commerce/stock-notifications.d.ts.map +1 -1
  67. package/dist/commerce/stock-notifications.js +11 -0
  68. package/dist/commerce/stock-notifications.js.map +1 -1
  69. package/dist/commerce/vat-validation.js +4 -4
  70. package/dist/commerce/vat-validation.js.map +1 -1
  71. package/dist/constants.d.ts +31 -0
  72. package/dist/constants.d.ts.map +1 -1
  73. package/dist/constants.js +32 -0
  74. package/dist/constants.js.map +1 -1
  75. package/dist/content/asset-urls.d.ts +50 -0
  76. package/dist/content/asset-urls.d.ts.map +1 -1
  77. package/dist/content/asset-urls.js +92 -0
  78. package/dist/content/asset-urls.js.map +1 -1
  79. package/dist/content/assets.d.ts +15 -0
  80. package/dist/content/assets.d.ts.map +1 -1
  81. package/dist/content/assets.js +15 -0
  82. package/dist/content/assets.js.map +1 -1
  83. package/dist/content/collection-pages.d.ts +5 -0
  84. package/dist/content/collection-pages.d.ts.map +1 -1
  85. package/dist/content/collection-pages.js +8 -0
  86. package/dist/content/collection-pages.js.map +1 -1
  87. package/dist/content/collections.d.ts +14 -0
  88. package/dist/content/collections.d.ts.map +1 -1
  89. package/dist/content/collections.js +16 -0
  90. package/dist/content/collections.js.map +1 -1
  91. package/dist/content/filtered-products.d.ts +18 -0
  92. package/dist/content/filtered-products.d.ts.map +1 -1
  93. package/dist/content/filtered-products.js +16 -0
  94. package/dist/content/filtered-products.js.map +1 -1
  95. package/dist/content/form-field-types.d.ts +6 -0
  96. package/dist/content/form-field-types.d.ts.map +1 -1
  97. package/dist/content/form-field-types.js +12 -0
  98. package/dist/content/form-field-types.js.map +1 -1
  99. package/dist/content/forms.d.ts +16 -0
  100. package/dist/content/forms.d.ts.map +1 -1
  101. package/dist/content/forms.js +23 -0
  102. package/dist/content/forms.js.map +1 -1
  103. package/dist/content/items.d.ts +26 -0
  104. package/dist/content/items.d.ts.map +1 -1
  105. package/dist/content/items.js +33 -0
  106. package/dist/content/items.js.map +1 -1
  107. package/dist/content/resolve.js +6 -0
  108. package/dist/content/resolve.js.map +1 -1
  109. package/dist/content/sitemap.d.ts +5 -0
  110. package/dist/content/sitemap.d.ts.map +1 -1
  111. package/dist/content/sitemap.js +5 -0
  112. package/dist/content/sitemap.js.map +1 -1
  113. package/dist/core/context.js +6 -0
  114. package/dist/core/context.js.map +1 -1
  115. package/dist/core/headers.js +2 -0
  116. package/dist/core/headers.js.map +1 -1
  117. package/dist/core/http.d.ts +8 -0
  118. package/dist/core/http.d.ts.map +1 -1
  119. package/dist/core/http.js +89 -1
  120. package/dist/core/http.js.map +1 -1
  121. package/dist/credit/credit-status.js +2 -2
  122. package/dist/credit/credit-status.js.map +1 -1
  123. package/dist/credit/payment-terms.js +2 -2
  124. package/dist/credit/payment-terms.js.map +1 -1
  125. package/dist/currency/exchange.d.ts +11 -0
  126. package/dist/currency/exchange.d.ts.map +1 -1
  127. package/dist/currency/exchange.js +11 -0
  128. package/dist/currency/exchange.js.map +1 -1
  129. package/dist/errors.d.ts +50 -2
  130. package/dist/errors.d.ts.map +1 -1
  131. package/dist/errors.js +48 -2
  132. package/dist/errors.js.map +1 -1
  133. package/dist/events/envelope.d.ts +36 -0
  134. package/dist/events/envelope.d.ts.map +1 -1
  135. package/dist/events/envelope.js +12 -0
  136. package/dist/events/envelope.js.map +1 -1
  137. package/dist/events/index.d.ts +13 -0
  138. package/dist/events/index.d.ts.map +1 -1
  139. package/dist/events/index.js +13 -0
  140. package/dist/events/index.js.map +1 -1
  141. package/dist/events/payloads.d.ts +19 -0
  142. package/dist/events/payloads.d.ts.map +1 -1
  143. package/dist/events/payloads.js +12 -0
  144. package/dist/events/payloads.js.map +1 -1
  145. package/dist/index.d.ts +7 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +7 -0
  148. package/dist/index.js.map +1 -1
  149. package/dist/media/index.js +2 -0
  150. package/dist/media/index.js.map +1 -1
  151. package/dist/media/urls.d.ts +52 -0
  152. package/dist/media/urls.d.ts.map +1 -1
  153. package/dist/media/urls.js +38 -0
  154. package/dist/media/urls.js.map +1 -1
  155. package/dist/media/video.d.ts +16 -0
  156. package/dist/media/video.d.ts.map +1 -1
  157. package/dist/media/video.js +16 -0
  158. package/dist/media/video.js.map +1 -1
  159. package/dist/next/artifact-handler.d.ts +22 -0
  160. package/dist/next/artifact-handler.d.ts.map +1 -1
  161. package/dist/next/artifact-handler.js +22 -0
  162. package/dist/next/artifact-handler.js.map +1 -1
  163. package/dist/next/event-revalidate-handler.d.ts +67 -0
  164. package/dist/next/event-revalidate-handler.d.ts.map +1 -1
  165. package/dist/next/event-revalidate-handler.js +48 -0
  166. package/dist/next/event-revalidate-handler.js.map +1 -1
  167. package/dist/next/index.d.ts +6 -0
  168. package/dist/next/index.d.ts.map +1 -1
  169. package/dist/next/index.js +6 -0
  170. package/dist/next/index.js.map +1 -1
  171. package/dist/next/json-ld.d.ts +9 -0
  172. package/dist/next/json-ld.d.ts.map +1 -1
  173. package/dist/next/json-ld.js +9 -0
  174. package/dist/next/json-ld.js.map +1 -1
  175. package/dist/next/metadata.d.ts +18 -0
  176. package/dist/next/metadata.d.ts.map +1 -1
  177. package/dist/next/metadata.js +21 -0
  178. package/dist/next/metadata.js.map +1 -1
  179. package/dist/next/redirect-middleware.d.ts +39 -0
  180. package/dist/next/redirect-middleware.d.ts.map +1 -1
  181. package/dist/next/redirect-middleware.js +32 -0
  182. package/dist/next/redirect-middleware.js.map +1 -1
  183. package/dist/next/revalidate-handler.d.ts +30 -0
  184. package/dist/next/revalidate-handler.d.ts.map +1 -1
  185. package/dist/next/revalidate-handler.js +22 -0
  186. package/dist/next/revalidate-handler.js.map +1 -1
  187. package/dist/order-scope.d.ts +27 -0
  188. package/dist/order-scope.d.ts.map +1 -1
  189. package/dist/order-scope.js +29 -0
  190. package/dist/order-scope.js.map +1 -1
  191. package/dist/pricing/format.d.ts +17 -0
  192. package/dist/pricing/format.d.ts.map +1 -1
  193. package/dist/pricing/format.js +19 -0
  194. package/dist/pricing/format.js.map +1 -1
  195. package/dist/pricing/index.d.ts +8 -1
  196. package/dist/pricing/index.d.ts.map +1 -1
  197. package/dist/pricing/index.js +18 -2
  198. package/dist/pricing/index.js.map +1 -1
  199. package/dist/pricing/tax-display.d.ts +77 -0
  200. package/dist/pricing/tax-display.d.ts.map +1 -1
  201. package/dist/pricing/tax-display.js +85 -0
  202. package/dist/pricing/tax-display.js.map +1 -1
  203. package/dist/pricing/tiers.d.ts +9 -0
  204. package/dist/pricing/tiers.d.ts.map +1 -1
  205. package/dist/pricing/tiers.js +9 -0
  206. package/dist/pricing/tiers.js.map +1 -1
  207. package/dist/pricing/validation.d.ts +56 -1
  208. package/dist/pricing/validation.d.ts.map +1 -1
  209. package/dist/pricing/validation.js +61 -0
  210. package/dist/pricing/validation.js.map +1 -1
  211. package/dist/redirects/index.d.ts +1 -0
  212. package/dist/redirects/index.d.ts.map +1 -1
  213. package/dist/redirects/index.js +1 -0
  214. package/dist/redirects/index.js.map +1 -1
  215. package/dist/redirects/store.d.ts +20 -0
  216. package/dist/redirects/store.d.ts.map +1 -1
  217. package/dist/redirects/store.js +57 -0
  218. package/dist/redirects/store.js.map +1 -1
  219. package/dist/redirects/types.d.ts +24 -0
  220. package/dist/redirects/types.d.ts.map +1 -1
  221. package/dist/redirects/types.js +1 -0
  222. package/dist/redirects/types.js.map +1 -1
  223. package/dist/revalidation/event-plan.d.ts +48 -0
  224. package/dist/revalidation/event-plan.d.ts.map +1 -1
  225. package/dist/revalidation/event-plan.js +61 -0
  226. package/dist/revalidation/event-plan.js.map +1 -1
  227. package/dist/revalidation/event-verify.d.ts +25 -0
  228. package/dist/revalidation/event-verify.d.ts.map +1 -1
  229. package/dist/revalidation/event-verify.js +27 -0
  230. package/dist/revalidation/event-verify.js.map +1 -1
  231. package/dist/revalidation/types.d.ts +20 -0
  232. package/dist/revalidation/types.d.ts.map +1 -1
  233. package/dist/revalidation/types.js +10 -0
  234. package/dist/revalidation/types.js.map +1 -1
  235. package/dist/revalidation/url-context.d.ts +25 -0
  236. package/dist/revalidation/url-context.d.ts.map +1 -1
  237. package/dist/revalidation/url-context.js +17 -0
  238. package/dist/revalidation/url-context.js.map +1 -1
  239. package/dist/revalidation/verify.d.ts +8 -0
  240. package/dist/revalidation/verify.d.ts.map +1 -1
  241. package/dist/revalidation/verify.js +8 -0
  242. package/dist/revalidation/verify.js.map +1 -1
  243. package/dist/seo/ai.d.ts +17 -0
  244. package/dist/seo/ai.d.ts.map +1 -1
  245. package/dist/seo/ai.js +12 -0
  246. package/dist/seo/ai.js.map +1 -1
  247. package/dist/seo/alternates.js +13 -0
  248. package/dist/seo/alternates.js.map +1 -1
  249. package/dist/seo/artifacts.d.ts +13 -0
  250. package/dist/seo/artifacts.d.ts.map +1 -1
  251. package/dist/seo/artifacts.js +19 -0
  252. package/dist/seo/artifacts.js.map +1 -1
  253. package/dist/seo/canonical.d.ts +15 -0
  254. package/dist/seo/canonical.d.ts.map +1 -1
  255. package/dist/seo/canonical.js +24 -0
  256. package/dist/seo/canonical.js.map +1 -1
  257. package/dist/seo/index.js +6 -0
  258. package/dist/seo/index.js.map +1 -1
  259. package/dist/seo/json-ld.d.ts +13 -0
  260. package/dist/seo/json-ld.d.ts.map +1 -1
  261. package/dist/seo/json-ld.js +32 -0
  262. package/dist/seo/json-ld.js.map +1 -1
  263. package/dist/seo/locale-tag.d.ts +31 -0
  264. package/dist/seo/locale-tag.d.ts.map +1 -1
  265. package/dist/seo/locale-tag.js +31 -0
  266. package/dist/seo/locale-tag.js.map +1 -1
  267. package/dist/seo/meta-tags.d.ts +29 -0
  268. package/dist/seo/meta-tags.d.ts.map +1 -1
  269. package/dist/seo/meta-tags.js +28 -0
  270. package/dist/seo/meta-tags.js.map +1 -1
  271. package/dist/seo/metadata-parser.d.ts +24 -0
  272. package/dist/seo/metadata-parser.d.ts.map +1 -1
  273. package/dist/seo/metadata-parser.js +38 -0
  274. package/dist/seo/metadata-parser.js.map +1 -1
  275. package/dist/seo/metadata-types.d.ts +16 -0
  276. package/dist/seo/metadata-types.d.ts.map +1 -1
  277. package/dist/seo/product-path.d.ts +96 -0
  278. package/dist/seo/product-path.d.ts.map +1 -1
  279. package/dist/seo/product-path.js +96 -0
  280. package/dist/seo/product-path.js.map +1 -1
  281. package/dist/seo/robots.d.ts +17 -0
  282. package/dist/seo/robots.d.ts.map +1 -1
  283. package/dist/seo/robots.js +12 -0
  284. package/dist/seo/robots.js.map +1 -1
  285. package/dist/seo/types.d.ts +39 -0
  286. package/dist/seo/types.d.ts.map +1 -1
  287. package/dist/seo/url-builder.d.ts +31 -0
  288. package/dist/seo/url-builder.d.ts.map +1 -1
  289. package/dist/seo/url-builder.js +36 -0
  290. package/dist/seo/url-builder.js.map +1 -1
  291. package/dist/types.d.ts +1163 -0
  292. package/dist/types.d.ts.map +1 -1
  293. package/package.json +1 -1
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Route-handler factory for the storefront's /api/revalidate endpoint.
3
+ * Framework functions (`revalidatePath`/`revalidateTag` from `next/cache`)
4
+ * are INJECTED so this package never imports `next`; the handler itself uses
5
+ * only web-standard Request/Response and is unit-testable anywhere.
6
+ *
7
+ * Requires ISR-capable hosting (the default Next server build) — under
8
+ * `output: 'export'` there is nothing to revalidate at request time.
9
+ *
10
+ * It speaks only the legacy SEO revalidation webhook, which the platform no
11
+ * longer sends (its sender is retired) — a route mounted with it receives
12
+ * nothing. A platform event envelope is refused here with a 400 (no `paths`),
13
+ * so point an event subscription at `createEventRevalidateHandler` instead,
14
+ * on its own route.
15
+ */
1
16
  import { verifyWebhookSignature } from '../revalidation/verify.js';
2
17
  const DEFAULT_TOLERANCE_SECONDS = 300;
3
18
  function json(status, body) {
@@ -6,6 +21,12 @@ function json(status, body) {
6
21
  headers: { 'Content-Type': 'application/json' },
7
22
  });
8
23
  }
24
+ /**
25
+ * @deprecated The legacy SEO revalidation webhook, which the platform no longer
26
+ * sends. Kept, unchanged, so existing `/api/revalidate` routes still compile.
27
+ * Storefronts subscribe to platform events and mount
28
+ * `createEventRevalidateHandler` at `/api/revalidate/events`.
29
+ */
9
30
  export function createRevalidateHandler(options) {
10
31
  const tolerance = (options.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS) * 1000;
11
32
  return async (request) => {
@@ -56,6 +77,7 @@ export function createRevalidateHandler(options) {
56
77
  await options.onEvent(payload);
57
78
  }
58
79
  catch {
80
+ // observer errors must not fail the delivery
59
81
  }
60
82
  }
61
83
  return json(200, { revalidated: true, paths, tags });
@@ -1 +1 @@
1
- {"version":3,"file":"revalidate-handler.js","sourceRoot":"","sources":["../../src/next/revalidate-handler.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAmBtC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,EAAE,CAAC;wBACrD,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;wBAC7B,KAAK,EAAE,CAAC;oBACV,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,IAAI,GAAG,CAAC,CAAC;YACb,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBAC1B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;oBACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC9C,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;wBAC3B,IAAI,EAAE,CAAC;oBACT,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpB,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACjC,CAAC;gBAAC,MAAM,CAAC;oBACP,6CAA6C;gBAC/C,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,GAAG,EAAE;gBACf,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB;aACtE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -1,3 +1,30 @@
1
1
  import type { OrderScope } from './types.js';
2
+ /**
3
+ * Does an order belong to `scope`?
4
+ *
5
+ * THE CASE DIFFERS ON PURPOSE, and this helper is the one place that has to
6
+ * know. The wire and storage value is lower-case (`'consumer'` / `'trade'`) —
7
+ * it is a Vendure `string` custom field with a `varchar(16)` column and a
8
+ * `'consumer'` default — while the client-side {@link OrderScope} union and the
9
+ * `OrderScope` GraphQL enum are upper-case, because that is what a GraphQL enum
10
+ * looks like. So the obvious comparison,
11
+ *
12
+ * order.customFields.orderScope === client.getOrderScope() // never true
13
+ *
14
+ * silently never matches, and a storefront filtering its own order list on it
15
+ * shows an empty page with no error anywhere.
16
+ *
17
+ * Two rules, both mirroring the engine (`scopeOf` in
18
+ * `services/vendure/src/order-scope/order-scope.ts`):
19
+ *
20
+ * - the comparison is case-insensitive;
21
+ * - an ABSENT, null or unrecognised value reads as `CONSUMER`. Every order
22
+ * placed before the scope existed has no value, and the engine treats those
23
+ * as consumer orders — so must a storefront, or a consumer shop's history
24
+ * page loses everything the customer bought before the feature shipped.
25
+ *
26
+ * @example
27
+ * const mine = orders.filter((o) => orderScopeMatches(o.customFields?.orderScope, 'TRADE'));
28
+ */
2
29
  export declare function orderScopeMatches(customFieldValue: string | null | undefined, scope: OrderScope | string): boolean;
3
30
  //# sourceMappingURL=order-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"order-scope.d.ts","sourceRoot":"","sources":["../src/order-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA6B7C,wBAAgB,iBAAiB,CAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC3C,KAAK,EAAE,UAAU,GAAG,MAAM,GACzB,OAAO,CAOT"}
1
+ {"version":3,"file":"order-scope.d.ts","sourceRoot":"","sources":["../src/order-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC3C,KAAK,EAAE,UAAU,GAAG,MAAM,GACzB,OAAO,CAOT"}
@@ -1,6 +1,35 @@
1
+ /**
2
+ * Does an order belong to `scope`?
3
+ *
4
+ * THE CASE DIFFERS ON PURPOSE, and this helper is the one place that has to
5
+ * know. The wire and storage value is lower-case (`'consumer'` / `'trade'`) —
6
+ * it is a Vendure `string` custom field with a `varchar(16)` column and a
7
+ * `'consumer'` default — while the client-side {@link OrderScope} union and the
8
+ * `OrderScope` GraphQL enum are upper-case, because that is what a GraphQL enum
9
+ * looks like. So the obvious comparison,
10
+ *
11
+ * order.customFields.orderScope === client.getOrderScope() // never true
12
+ *
13
+ * silently never matches, and a storefront filtering its own order list on it
14
+ * shows an empty page with no error anywhere.
15
+ *
16
+ * Two rules, both mirroring the engine (`scopeOf` in
17
+ * `services/vendure/src/order-scope/order-scope.ts`):
18
+ *
19
+ * - the comparison is case-insensitive;
20
+ * - an ABSENT, null or unrecognised value reads as `CONSUMER`. Every order
21
+ * placed before the scope existed has no value, and the engine treats those
22
+ * as consumer orders — so must a storefront, or a consumer shop's history
23
+ * page loses everything the customer bought before the feature shipped.
24
+ *
25
+ * @example
26
+ * const mine = orders.filter((o) => orderScopeMatches(o.customFields?.orderScope, 'TRADE'));
27
+ */
1
28
  export function orderScopeMatches(customFieldValue, scope) {
2
29
  const normalized = typeof customFieldValue === 'string' ? customFieldValue.trim().toUpperCase() : '';
3
30
  const effective = normalized === 'CONSUMER' || normalized === 'TRADE' ? normalized : 'CONSUMER';
31
+ // Both sides are normalised: a JS caller passing 'trade' must match — the helper
32
+ // exists to absorb exactly this casing split, on either argument.
4
33
  return effective === String(scope).trim().toUpperCase();
5
34
  }
6
35
  //# sourceMappingURL=order-scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"order-scope.js","sourceRoot":"","sources":["../src/order-scope.ts"],"names":[],"mappings":"AA6BA,MAAM,UAAU,iBAAiB,CAC/B,gBAA2C,EAC3C,KAA0B;IAE1B,MAAM,UAAU,GACd,OAAO,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpF,MAAM,SAAS,GAAG,UAAU,KAAK,UAAU,IAAI,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;IAGhG,OAAO,SAAS,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAC1D,CAAC"}
1
+ {"version":3,"file":"order-scope.js","sourceRoot":"","sources":["../src/order-scope.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,iBAAiB,CAC/B,gBAA2C,EAC3C,KAA0B;IAE1B,MAAM,UAAU,GACd,OAAO,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpF,MAAM,SAAS,GAAG,UAAU,KAAK,UAAU,IAAI,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;IAChG,iFAAiF;IACjF,kEAAkE;IAClE,OAAO,SAAS,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAC1D,CAAC"}
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Format a price in minor units to a human-readable string.
3
+ * Uses Intl.NumberFormat for locale-aware formatting.
4
+ *
5
+ * The platform stores money in a currency's minor units, so the divisor is
6
+ * `10 ** fractionDigits`, NOT a hardcoded 100: EUR/USD have 2 digits (÷100),
7
+ * JPY 0 (÷1 — `2999` is ¥2,999, not ¥30), BHD 3 (÷1000). The digit count comes
8
+ * from the same Intl formatter, so it always matches how the value is rendered.
9
+ *
10
+ * Vendure `LanguageCode` region variants use underscores (`pt_BR`, `zh_Hans`),
11
+ * which are not valid BCP-47 separators and make `Intl.NumberFormat` throw —
12
+ * normalize to hyphens so a channel default language can be passed straight in.
13
+ */
1
14
  export declare function formatPrice(amount: number, currencyCode: string, locale?: string): string;
15
+ /**
16
+ * Format a price range from two minor-unit amounts.
17
+ * Returns "€10.00 - €20.00" or the single price if min === max.
18
+ */
2
19
  export declare function formatPriceRange(min: number, max: number, currencyCode: string, locale?: string): string;
3
20
  //# sourceMappingURL=format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/pricing/format.ts"],"names":[],"mappings":"AAaA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CASzF;AAMD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAKR"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/pricing/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CASzF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAKR"}
@@ -1,11 +1,30 @@
1
+ /**
2
+ * Format a price in minor units to a human-readable string.
3
+ * Uses Intl.NumberFormat for locale-aware formatting.
4
+ *
5
+ * The platform stores money in a currency's minor units, so the divisor is
6
+ * `10 ** fractionDigits`, NOT a hardcoded 100: EUR/USD have 2 digits (÷100),
7
+ * JPY 0 (÷1 — `2999` is ¥2,999, not ¥30), BHD 3 (÷1000). The digit count comes
8
+ * from the same Intl formatter, so it always matches how the value is rendered.
9
+ *
10
+ * Vendure `LanguageCode` region variants use underscores (`pt_BR`, `zh_Hans`),
11
+ * which are not valid BCP-47 separators and make `Intl.NumberFormat` throw —
12
+ * normalize to hyphens so a channel default language can be passed straight in.
13
+ */
1
14
  export function formatPrice(amount, currencyCode, locale) {
2
15
  const format = new Intl.NumberFormat((locale ?? 'en').replace(/_/g, '-'), {
3
16
  style: 'currency',
4
17
  currency: currencyCode,
5
18
  });
19
+ // `currency` style always resolves a digit count; `?? 2` is a defensive
20
+ // fallback for the base type only (`maximumFractionDigits` is `number | undefined`).
6
21
  const fractionDigits = format.resolvedOptions().maximumFractionDigits ?? 2;
7
22
  return format.format(amount / 10 ** fractionDigits);
8
23
  }
24
+ /**
25
+ * Format a price range from two minor-unit amounts.
26
+ * Returns "€10.00 - €20.00" or the single price if min === max.
27
+ */
9
28
  export function formatPriceRange(min, max, currencyCode, locale) {
10
29
  if (min === max) {
11
30
  return formatPrice(min, currencyCode, locale);
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/pricing/format.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,YAAoB,EAAE,MAAe;IAC/E,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;QACxE,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;IAGH,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,qBAAqB,IAAI,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,IAAI,cAAc,CAAC,CAAC;AACtD,CAAC;AAMD,MAAM,UAAU,gBAAgB,CAC9B,GAAW,EACX,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC;AACjG,CAAC"}
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/pricing/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,YAAoB,EAAE,MAAe;IAC/E,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;QACxE,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;IACH,wEAAwE;IACxE,qFAAqF;IACrF,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,qBAAqB,IAAI,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,IAAI,cAAc,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAW,EACX,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC;AACjG,CAAC"}
@@ -3,6 +3,13 @@ import type { PricingModule, StoreContext } from '../types.js';
3
3
  export { formatPrice, formatPriceRange } from './format.js';
4
4
  export { ACTIVE_TAX_DISPLAY_MODE, DEFAULT_TAX_DISPLAY_POLICY, identityStamp, parseTaxDisplayPolicy, parseTaxExclusiveCountries, resolveTaxDisplayMode, taxDisplayModeFromEnum, } from './tax-display.js';
5
5
  export { computeTierTable, getTierForQuantity } from './tiers.js';
6
- export { validateOrderMinimums } from './validation.js';
6
+ export { backorderedQuantityForCart, isBackorderOnly, maxOrderableQuantity, type OrderableStockInput, validateOrderMinimums, } from './validation.js';
7
+ /**
8
+ * @param http Optional Shop API client. Without it the module is fully offline
9
+ * (formatting, tier maths, the pure policy helpers) and
10
+ * `getTaxDisplayMode()` degrades to the channel storage mode rather than
11
+ * failing — which is what the `@sixtyninecommerce/client/pricing` subpath and
12
+ * the existing single-argument callers get.
13
+ */
7
14
  export declare function createPricingModule(ctx: StoreContext, http?: HttpClient): PricingModule;
8
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAEV,aAAa,EACb,YAAY,EAGb,MAAM,aAAa,CAAC;AAYrB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,aAAa,EACb,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AASxD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,aAAa,CA2GvF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAEV,aAAa,EACb,YAAY,EAGb,MAAM,aAAa,CAAC;AAiBrB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,aAAa,EACb,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,aAAa,CA8GvF"}
@@ -1,13 +1,22 @@
1
1
  import { formatPrice, formatPriceRange } from './format.js';
2
2
  import { ACTIVE_TAX_DISPLAY_MODE, identityStamp, parseTaxDisplayPolicy, resolveTaxDisplayMode, taxDisplayModeFromEnum, } from './tax-display.js';
3
3
  import { computeTierTable, getTierForQuantity } from './tiers.js';
4
- import { validateOrderMinimums } from './validation.js';
4
+ import { backorderedQuantityForCart, isBackorderOnly, maxOrderableQuantity, validateOrderMinimums, } from './validation.js';
5
5
  export { formatPrice, formatPriceRange } from './format.js';
6
6
  export { ACTIVE_TAX_DISPLAY_MODE, DEFAULT_TAX_DISPLAY_POLICY, identityStamp, parseTaxDisplayPolicy, parseTaxExclusiveCountries, resolveTaxDisplayMode, taxDisplayModeFromEnum, } from './tax-display.js';
7
7
  export { computeTierTable, getTierForQuantity } from './tiers.js';
8
- export { validateOrderMinimums } from './validation.js';
8
+ export { backorderedQuantityForCart, isBackorderOnly, maxOrderableQuantity, validateOrderMinimums, } from './validation.js';
9
+ /**
10
+ * @param http Optional Shop API client. Without it the module is fully offline
11
+ * (formatting, tier maths, the pure policy helpers) and
12
+ * `getTaxDisplayMode()` degrades to the channel storage mode rather than
13
+ * failing — which is what the `@sixtyninecommerce/client/pricing` subpath and
14
+ * the existing single-argument callers get.
15
+ */
9
16
  export function createPricingModule(ctx, http) {
17
+ /** The pre-policy behaviour: display in whatever basis the channel stores. */
10
18
  const storageMode = () => (ctx.pricesIncludeTax ? 'gross' : 'net');
19
+ /** The cached mode, but only while it belongs to the current identity. */
11
20
  const cachedMode = () => {
12
21
  const cached = ctx.taxDisplay;
13
22
  return cached && cached.stamp === identityStamp(ctx) ? cached.mode : null;
@@ -28,10 +37,14 @@ export function createPricingModule(ctx, http) {
28
37
  mode = taxDisplayModeFromEnum(data?.activeTaxDisplayMode);
29
38
  }
30
39
  catch {
40
+ // Unreachable engine, an expired session, an engine predating the
41
+ // query — never fail a render over the display mode.
31
42
  mode = null;
32
43
  }
33
44
  if (mode === null)
34
45
  return storageMode();
46
+ // Stamp AFTER the round-trip: the response may have rotated the session
47
+ // token, and the answer belongs to the identity that now holds.
35
48
  ctx.taxDisplay = { stamp: identityStamp(ctx), mode };
36
49
  return mode;
37
50
  },
@@ -85,6 +98,9 @@ export function createPricingModule(ctx, http) {
85
98
  };
86
99
  },
87
100
  validateOrderMinimums,
101
+ maxOrderableQuantity,
102
+ isBackorderOnly,
103
+ backorderedQuantityForCart,
88
104
  };
89
105
  }
90
106
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,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AkB,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;gBAC3C,CAAC,CAAC,IAAI,CAAC;YAET,OAAO;gBACL,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI;gBACxC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,IAAI;gBACtD,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,IAAI;gBAC5C,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE,KAAK,IAAI,IAAI;gBAC9C,WAAW;gBACX,kBAAkB;gBAClB,UAAU;aACX,CAAC;QACJ,CAAC;QAED,qBAAqB;QACrB,oBAAoB;QACpB,eAAe;QACf,0BAA0B;KAC3B,CAAC;AACJ,CAAC"}
@@ -1,9 +1,86 @@
1
+ /**
2
+ * Which tax figure a shopper sees: incl. (`gross`) or excl. (`net`) tax.
3
+ *
4
+ * `Channel.pricesIncludeTax` is a STORAGE mode — it says which of `price` /
5
+ * `priceWithTax` the merchant typed in, not which one this shopper should be
6
+ * quoted. Those differ in real shops: US sales tax varies by state and even by
7
+ * district, so a US shopper must never be quoted a tax-inclusive price, and
8
+ * Dutch B2B buyers work in ex-VAT numbers, while Dutch consumers keep seeing
9
+ * the gross price the law requires. One channel, three audiences.
10
+ *
11
+ * So the engine resolves the mode per request and exposes it as
12
+ * `Query.activeTaxDisplayMode` — that query is the authority, and
13
+ * `client.pricing.getTaxDisplayMode()` is how a storefront reads it. The pure
14
+ * helpers below mirror the engine's rules
15
+ * (`services/vendure/src/tax-display/tax-display-policy.ts`) RULE FOR RULE so a
16
+ * client can preview a mode — a "who sees what" table, an SSR guess before the
17
+ * first round-trip — without one. Change one, change both.
18
+ *
19
+ * The channel policy behind it (three `public: true` Channel customFields, all
20
+ * defaulting to today's behaviour):
21
+ *
22
+ * taxDisplayDefault channel | gross | net (default `channel`)
23
+ * taxDisplayB2b inherit | gross | net (default `inherit`)
24
+ * taxExclusiveCountries JSON ["US"] (default empty)
25
+ */
1
26
  import type { StoreContext, TaxDisplayInputs, TaxDisplayMode, TaxDisplayPolicy } from '../types.js';
27
+ /** Every channel reads this until a merchant changes something. */
2
28
  export declare const DEFAULT_TAX_DISPLAY_POLICY: TaxDisplayPolicy;
29
+ /**
30
+ * The resolved mode for the active shopper. Public, anonymous-safe, and it
31
+ * never errors server-side — a lookup failure there falls back to the channel
32
+ * default rather than failing the request.
33
+ *
34
+ * The answer depends on the request's identity, so the SDK sends it with the
35
+ * same `Authorization` / `x-order-scope` headers as every other call.
36
+ */
3
37
  export declare const ACTIVE_TAX_DISPLAY_MODE = "\n query ActiveTaxDisplayMode {\n activeTaxDisplayMode\n }\n";
38
+ /**
39
+ * Resolve the mode for one shopper — the engine's rule, offline.
40
+ *
41
+ * Precedence — country, then B2B, then the default — and the order is the
42
+ * point. A US dealer is a US shopper first: their state's sales tax is the
43
+ * reason the price cannot be quoted gross, and that reason does not go away
44
+ * because they also happen to be a trade account.
45
+ *
46
+ * This is a PREVIEW. `getTaxDisplayMode()` is what a storefront renders from;
47
+ * only the server knows the shopper's resolved country (active order shipping
48
+ * address, else their default shipping address).
49
+ */
4
50
  export declare function resolveTaxDisplayMode(policy: TaxDisplayPolicy, inputs: TaxDisplayInputs): TaxDisplayMode;
51
+ /**
52
+ * Read the policy off `activeChannel.customFields`. LENIENT by design: an
53
+ * unreadable value degrades to the pre-policy default rather than throwing
54
+ * while a catalogue page renders. The dashboard's write-side validation is what
55
+ * stops a bad value being stored.
56
+ */
5
57
  export declare function parseTaxDisplayPolicy(fields: unknown): TaxDisplayPolicy;
58
+ /**
59
+ * The tax-exclusive country list, normalised to upper-case alpha-2 with
60
+ * duplicates dropped. Anything unreadable is an EMPTY list — the rule is
61
+ * opt-in, so falling open means "no country override", never "every country".
62
+ */
6
63
  export declare function parseTaxExclusiveCountries(raw: unknown): readonly string[];
64
+ /**
65
+ * Map the Shop API enum (`GROSS` / `NET`, upper-case like `OrderScope`) to the
66
+ * SDK's lower-case union. Returns `null` for anything else — an engine that
67
+ * predates the enum, a null, a typo — so the caller can fall back to the
68
+ * channel storage mode instead of rendering a guess.
69
+ */
7
70
  export declare function taxDisplayModeFromEnum(value: unknown): TaxDisplayMode | null;
71
+ /**
72
+ * Identity fingerprint of the current request context — the cache key for a
73
+ * resolved mode.
74
+ *
75
+ * The mode is a function of WHO is asking: the session (`Authorization`) and
76
+ * the storefront scope (`x-order-scope`) are the two things the SDK can change
77
+ * mid-session that also change the answer. Sign in, sign out, or switch to the
78
+ * trade portal and the stamp changes, so the next read re-resolves instead of
79
+ * showing the previous shopper's mode.
80
+ *
81
+ * A country change is the one non-identity input that can flip the mode; it is
82
+ * handled by clearing the cache in `setShippingAddress`, since the stamp cannot
83
+ * see it.
84
+ */
8
85
  export declare function identityStamp(ctx: Pick<StoreContext, 'authToken' | 'orderScope'>): string;
9
86
  //# sourceMappingURL=tax-display.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax-display.d.ts","sourceRoot":"","sources":["../../src/pricing/tax-display.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EACV,YAAY,EAGZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAYrB,eAAO,MAAM,0BAA0B,EAAE,gBAIxC,CAAC;AAUF,eAAO,MAAM,uBAAuB,sEAInC,CAAC;AAyBF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,gBAAgB,GACvB,cAAc,CAShB;AAQD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAWvE;AAOD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAoB1E;AAQD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAM5E;AAgBD,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,YAAY,CAAC,GAAG,MAAM,CAEzF"}
1
+ {"version":3,"file":"tax-display.d.ts","sourceRoot":"","sources":["../../src/pricing/tax-display.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EACV,YAAY,EAGZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAWrB,mEAAmE;AACnE,eAAO,MAAM,0BAA0B,EAAE,gBAIxC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,sEAInC,CAAC;AAaF;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,gBAAgB,GACvB,cAAc,CAShB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAWvE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAoB1E;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAM5E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,YAAY,CAAC,GAAG,MAAM,CAEzF"}
@@ -1,22 +1,76 @@
1
+ /**
2
+ * Which tax figure a shopper sees: incl. (`gross`) or excl. (`net`) tax.
3
+ *
4
+ * `Channel.pricesIncludeTax` is a STORAGE mode — it says which of `price` /
5
+ * `priceWithTax` the merchant typed in, not which one this shopper should be
6
+ * quoted. Those differ in real shops: US sales tax varies by state and even by
7
+ * district, so a US shopper must never be quoted a tax-inclusive price, and
8
+ * Dutch B2B buyers work in ex-VAT numbers, while Dutch consumers keep seeing
9
+ * the gross price the law requires. One channel, three audiences.
10
+ *
11
+ * So the engine resolves the mode per request and exposes it as
12
+ * `Query.activeTaxDisplayMode` — that query is the authority, and
13
+ * `client.pricing.getTaxDisplayMode()` is how a storefront reads it. The pure
14
+ * helpers below mirror the engine's rules
15
+ * (`services/vendure/src/tax-display/tax-display-policy.ts`) RULE FOR RULE so a
16
+ * client can preview a mode — a "who sees what" table, an SSR guess before the
17
+ * first round-trip — without one. Change one, change both.
18
+ *
19
+ * The channel policy behind it (three `public: true` Channel customFields, all
20
+ * defaulting to today's behaviour):
21
+ *
22
+ * taxDisplayDefault channel | gross | net (default `channel`)
23
+ * taxDisplayB2b inherit | gross | net (default `inherit`)
24
+ * taxExclusiveCountries JSON ["US"] (default empty)
25
+ */
26
+ /** ISO-3166 alpha-2: exactly two ASCII letters. */
1
27
  const ALPHA2 = /^[A-Za-z]{2}$/;
28
+ /** Channel-wide default. `channel` follows `Channel.pricesIncludeTax`. */
2
29
  const TAX_DISPLAY_DEFAULTS = ['channel', 'gross', 'net'];
30
+ /** B2B override. `inherit` leaves B2B shoppers on the channel default. */
3
31
  const TAX_DISPLAY_B2B_MODES = ['inherit', 'gross', 'net'];
32
+ /** Every channel reads this until a merchant changes something. */
4
33
  export const DEFAULT_TAX_DISPLAY_POLICY = {
5
34
  default: 'channel',
6
35
  b2b: 'inherit',
7
36
  countries: [],
8
37
  };
38
+ /**
39
+ * The resolved mode for the active shopper. Public, anonymous-safe, and it
40
+ * never errors server-side — a lookup failure there falls back to the channel
41
+ * default rather than failing the request.
42
+ *
43
+ * The answer depends on the request's identity, so the SDK sends it with the
44
+ * same `Authorization` / `x-order-scope` headers as every other call.
45
+ */
9
46
  export const ACTIVE_TAX_DISPLAY_MODE = `
10
47
  query ActiveTaxDisplayMode {
11
48
  activeTaxDisplayMode
12
49
  }
13
50
  `;
51
+ /**
52
+ * Trim and upper-case one country code, or `null` when it is not a plausible
53
+ * alpha-2 code. Applied to both the stored list and the country being judged,
54
+ * so `"us"` and `" US "` can never disagree with `"US"`.
55
+ */
14
56
  function normalizeCountryCode(raw) {
15
57
  if (typeof raw !== 'string')
16
58
  return null;
17
59
  const trimmed = raw.trim();
18
60
  return ALPHA2.test(trimmed) ? trimmed.toUpperCase() : null;
19
61
  }
62
+ /**
63
+ * Resolve the mode for one shopper — the engine's rule, offline.
64
+ *
65
+ * Precedence — country, then B2B, then the default — and the order is the
66
+ * point. A US dealer is a US shopper first: their state's sales tax is the
67
+ * reason the price cannot be quoted gross, and that reason does not go away
68
+ * because they also happen to be a trade account.
69
+ *
70
+ * This is a PREVIEW. `getTaxDisplayMode()` is what a storefront renders from;
71
+ * only the server knows the shopper's resolved country (active order shipping
72
+ * address, else their default shipping address).
73
+ */
20
74
  export function resolveTaxDisplayMode(policy, inputs) {
21
75
  const country = normalizeCountryCode(inputs.countryCode);
22
76
  if (country !== null && policy.countries.includes(country))
@@ -27,6 +81,12 @@ export function resolveTaxDisplayMode(policy, inputs) {
27
81
  return policy.default;
28
82
  return inputs.pricesIncludeTax ? 'gross' : 'net';
29
83
  }
84
+ /**
85
+ * Read the policy off `activeChannel.customFields`. LENIENT by design: an
86
+ * unreadable value degrades to the pre-policy default rather than throwing
87
+ * while a catalogue page renders. The dashboard's write-side validation is what
88
+ * stops a bad value being stored.
89
+ */
30
90
  export function parseTaxDisplayPolicy(fields) {
31
91
  const raw = (fields ?? {});
32
92
  return {
@@ -35,6 +95,11 @@ export function parseTaxDisplayPolicy(fields) {
35
95
  countries: parseTaxExclusiveCountries(raw.taxExclusiveCountries),
36
96
  };
37
97
  }
98
+ /**
99
+ * The tax-exclusive country list, normalised to upper-case alpha-2 with
100
+ * duplicates dropped. Anything unreadable is an EMPTY list — the rule is
101
+ * opt-in, so falling open means "no country override", never "every country".
102
+ */
38
103
  export function parseTaxExclusiveCountries(raw) {
39
104
  if (typeof raw !== 'string')
40
105
  return [];
@@ -59,6 +124,12 @@ export function parseTaxExclusiveCountries(raw) {
59
124
  }
60
125
  return codes;
61
126
  }
127
+ /**
128
+ * Map the Shop API enum (`GROSS` / `NET`, upper-case like `OrderScope`) to the
129
+ * SDK's lower-case union. Returns `null` for anything else — an engine that
130
+ * predates the enum, a null, a typo — so the caller can fall back to the
131
+ * channel storage mode instead of rendering a guess.
132
+ */
62
133
  export function taxDisplayModeFromEnum(value) {
63
134
  if (typeof value !== 'string')
64
135
  return null;
@@ -69,6 +140,20 @@ export function taxDisplayModeFromEnum(value) {
69
140
  return 'net';
70
141
  return null;
71
142
  }
143
+ /**
144
+ * Identity fingerprint of the current request context — the cache key for a
145
+ * resolved mode.
146
+ *
147
+ * The mode is a function of WHO is asking: the session (`Authorization`) and
148
+ * the storefront scope (`x-order-scope`) are the two things the SDK can change
149
+ * mid-session that also change the answer. Sign in, sign out, or switch to the
150
+ * trade portal and the stamp changes, so the next read re-resolves instead of
151
+ * showing the previous shopper's mode.
152
+ *
153
+ * A country change is the one non-identity input that can flip the mode; it is
154
+ * handled by clearing the cache in `setShippingAddress`, since the stamp cannot
155
+ * see it.
156
+ */
72
157
  export function identityStamp(ctx) {
73
158
  return `${ctx.authToken ?? ''}|${ctx.orderScope ?? ''}`;
74
159
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tax-display.js","sourceRoot":"","sources":["../../src/pricing/tax-display.ts"],"names":[],"mappings":"AAoCA,MAAM,MAAM,GAAG,eAAe,CAAC;AAG/B,MAAM,oBAAoB,GAAiC,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAGvF,MAAM,qBAAqB,GAAiC,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAGxF,MAAM,CAAC,MAAM,0BAA0B,GAAqB;IAC1D,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,SAAS;IACd,SAAS,EAAE,EAAE;CACd,CAAC;AAUF,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;CAItC,CAAC;AAOF,SAAS,oBAAoB,CAAC,GAAY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TableEntry, VariantPriceData } from '../types.js';
2
+ /**
3
+ * Find the active price tier for a given quantity.
4
+ * Tiers are matched by the highest minQuantity that does not exceed the given quantity.
5
+ * Returns null if no tiers or quantity is below all thresholds.
6
+ */
2
7
  export declare function getTierForQuantity(tiers: PriceTier[], quantity: number): PriceTier | null;
8
+ /**
9
+ * Build a tier table with savings percentages relative to the retail price.
10
+ * If no retail price is available, savings are computed relative to the variant's base price.
11
+ */
3
12
  export declare function computeTierTable(variant: VariantPriceData): TierTableEntry[];
4
13
  //# sourceMappingURL=tiers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiers.d.ts","sourceRoot":"","sources":["../../src/pricing/tiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAO/E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAYzF;AAMD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,EAAE,CAkB5E"}
1
+ {"version":3,"file":"tiers.d.ts","sourceRoot":"","sources":["../../src/pricing/tiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAYzF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,EAAE,CAkB5E"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Find the active price tier for a given quantity.
3
+ * Tiers are matched by the highest minQuantity that does not exceed the given quantity.
4
+ * Returns null if no tiers or quantity is below all thresholds.
5
+ */
1
6
  export function getTierForQuantity(tiers, quantity) {
2
7
  if (!tiers.length)
3
8
  return null;
@@ -11,6 +16,10 @@ export function getTierForQuantity(tiers, quantity) {
11
16
  }
12
17
  return matched;
13
18
  }
19
+ /**
20
+ * Build a tier table with savings percentages relative to the retail price.
21
+ * If no retail price is available, savings are computed relative to the variant's base price.
22
+ */
14
23
  export function computeTierTable(variant) {
15
24
  const tiers = variant.priceTiers;
16
25
  if (!tiers?.length)
@@ -1 +1 @@
1
- {"version":3,"file":"tiers.js","sourceRoot":"","sources":["../../src/pricing/tiers.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,kBAAkB,CAAC,KAAkB,EAAE,QAAgB;IACrE,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAE/B,IAAI,OAAO,GAAqB,IAAI,CAAC;IACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;gBACvD,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAMD,MAAM,UAAU,gBAAgB,CAAC,OAAyB;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IAE9B,MAAM,cAAc,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,KAAK,CAAC;IAC5D,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,YAAY,EAAE,I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