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