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