@shopkit/data-layer 1.4.1 → 1.4.2

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.js CHANGED
@@ -3855,7 +3855,35 @@ var ProductService2 = class extends BaseCustomService {
3855
3855
  PRODUCT_ENDPOINTS.getProduct(options?.version),
3856
3856
  "POST",
3857
3857
  payload,
3858
- options
3858
+ {
3859
+ ...options || {},
3860
+ // Tag the read so `revalidateTag(CacheTags.product(handle))` reaches every
3861
+ // page that rendered this product, at any URL. A product is reachable at
3862
+ // six routes here (/products, /products-b, and the nested
3863
+ // /collections[-b]/[collectionname]/... variants); the webhook knows only
3864
+ // the handle, so it cannot enumerate those paths, and purging the route
3865
+ // pattern would take out every product under every collection.
3866
+ //
3867
+ // Tags apply even though this is a POST: Next records them on the page's
3868
+ // cache entry before it decides whether the fetch itself is cacheable.
3869
+ //
3870
+ // No `revalidate` on purpose — that would cache the response and freeze
3871
+ // `template_suffix`, which drives Page Template assignment and must be
3872
+ // read live. Invalidation and caching are separate knobs; we want only
3873
+ // the first. No broad CacheTags.products() either: callers already fire
3874
+ // `revalidateTag("products")` on routine inventory events, which would
3875
+ // become a catalog-wide purge.
3876
+ //
3877
+ // Handle-keyed to match the taxonomy — the webhook purges by handle, so
3878
+ // an id-keyed tag could never match.
3879
+ next: {
3880
+ ...options?.next || {},
3881
+ tags: [
3882
+ ...handle ? [cacheTags.CacheTags.product(handle)] : [],
3883
+ ...options?.next?.tags || []
3884
+ ]
3885
+ }
3886
+ }
3859
3887
  );
3860
3888
  if (!result || !result.product) {
3861
3889
  return formatResponse({
@@ -3905,7 +3933,28 @@ var ProductService2 = class extends BaseCustomService {
3905
3933
  PRODUCT_ENDPOINTS.getProductsByHandles(options?.version),
3906
3934
  "POST",
3907
3935
  payload,
3908
- options
3936
+ {
3937
+ ...options || {},
3938
+ // One tag per requested handle, so a single-product webhook invalidates
3939
+ // every multi-product surface that included it (bundles, FBT rails,
3940
+ // hand-picked grids) — not just that product's own page. Same rationale
3941
+ // and same deliberate omission of `revalidate` as getProduct above.
3942
+ //
3943
+ // The type guard is not defensive padding: CacheTags.product() calls
3944
+ // .trim() on its argument, and this array is widget-supplied, so a stray
3945
+ // null would throw here and fail the whole read. Length/count limits are
3946
+ // Next's job — validateTags() drops over-long tags, caps the list, and
3947
+ // logs what it dropped.
3948
+ next: {
3949
+ ...options?.next || {},
3950
+ tags: [
3951
+ ...handles.filter(
3952
+ (h) => typeof h === "string" && h.trim() !== ""
3953
+ ).map((h) => cacheTags.CacheTags.product(h)),
3954
+ ...options?.next?.tags || []
3955
+ ]
3956
+ }
3957
+ }
3909
3958
  );
3910
3959
  if (!result || !result.products) {
3911
3960
  return formatResponse({
@@ -4030,8 +4079,14 @@ var ProductService2 = class extends BaseCustomService {
4030
4079
  params: queryParams,
4031
4080
  ...options || {},
4032
4081
  // Tag the collection read so a webhook can revalidateTag() it, refreshing
4033
- // the collection page AND every grid built from it. GET only — Next caches
4034
- // GET; the handle keys the entity. See @shopkit/core/cache-tags.
4082
+ // the collection page AND every grid built from it — including the home
4083
+ // page, whose entry carries a tag per collection it renders. The handle
4084
+ // keys the entity. See @shopkit/core/cache-tags.
4085
+ //
4086
+ // ("GET only" used to be noted here as if tagging depended on the method.
4087
+ // It does not — see getProduct above, which tags a POST. The method only
4088
+ // affects whether the RESPONSE is cached, not whether the tag is recorded
4089
+ // on the page.)
4035
4090
  next: {
4036
4091
  ...options?.next || {},
4037
4092
  tags: [