@shopkit/data-layer 1.4.2 → 1.4.4
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/adapters/index.js +101 -4
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +101 -4
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.js +101 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/adapters/index.mjs
CHANGED
|
@@ -157,6 +157,11 @@ function createDomainLogger(domain, adapter, config = {}) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// src/core/utils.ts
|
|
160
|
+
function isUpstreamUnavailable(error) {
|
|
161
|
+
const status = error?.status;
|
|
162
|
+
if (typeof status !== "number") return true;
|
|
163
|
+
return status >= 500;
|
|
164
|
+
}
|
|
160
165
|
function formatResponse(params) {
|
|
161
166
|
const { success, message, data = null, error = null, meta = {} } = params;
|
|
162
167
|
return {
|
|
@@ -3726,9 +3731,11 @@ var BaseCustomService = class {
|
|
|
3726
3731
|
statusText: response.statusText,
|
|
3727
3732
|
duration
|
|
3728
3733
|
});
|
|
3729
|
-
|
|
3734
|
+
const error = new Error(
|
|
3730
3735
|
`Request failed: ${response.status} ${response.statusText}`
|
|
3731
3736
|
);
|
|
3737
|
+
error.status = response.status;
|
|
3738
|
+
throw error;
|
|
3732
3739
|
}
|
|
3733
3740
|
this.logger.info("API request successful", {
|
|
3734
3741
|
method,
|
|
@@ -3803,7 +3810,31 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
3803
3810
|
PRODUCT_ENDPOINTS.getProducts(options?.version),
|
|
3804
3811
|
"POST",
|
|
3805
3812
|
requestParams,
|
|
3806
|
-
|
|
3813
|
+
{
|
|
3814
|
+
...options || {},
|
|
3815
|
+
// A list read cannot know which products come back before it runs, so it
|
|
3816
|
+
// takes the broad `products` tag — the one place a broad tag is the correct
|
|
3817
|
+
// answer rather than a blunt one. Per-product reads deliberately omit it
|
|
3818
|
+
// (see getProduct), which is what keeps `revalidateTag("products")` from
|
|
3819
|
+
// becoming a catalog-wide PDP purge: it lands only on the surfaces that
|
|
3820
|
+
// actually render a list — sitemaps, search endpoints, PLP rails.
|
|
3821
|
+
//
|
|
3822
|
+
// This is the producer that tag had been missing. Merchant inventory routes
|
|
3823
|
+
// have been calling `revalidateTag("products")` all along, against nothing:
|
|
3824
|
+
// no read attached it, so those deliveries returned 200 having invalidated
|
|
3825
|
+
// nothing. Same failure the removed `search.reindex` event had, mirrored to
|
|
3826
|
+
// the producer side.
|
|
3827
|
+
//
|
|
3828
|
+
// No `search` tag on a query-bearing read: it would be attached only
|
|
3829
|
+
// alongside `products` and purged only alongside `products`, so it could
|
|
3830
|
+
// never invalidate anything `products` did not already reach. See the note
|
|
3831
|
+
// on CACHE_INVALIDATION_TYPES in @shopkit/webhooks — a tag with no
|
|
3832
|
+
// independent effect is the same dead weight as one with no producer.
|
|
3833
|
+
next: {
|
|
3834
|
+
...options?.next || {},
|
|
3835
|
+
tags: [CacheTags.products(), ...options?.next?.tags || []]
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3807
3838
|
);
|
|
3808
3839
|
if (!result || !result.products) {
|
|
3809
3840
|
return formatResponse({
|
|
@@ -3904,6 +3935,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
3904
3935
|
});
|
|
3905
3936
|
} catch (error) {
|
|
3906
3937
|
this.logger.error("Error in getProduct", void 0, { error });
|
|
3938
|
+
if (!isUpstreamUnavailable(error)) {
|
|
3939
|
+
return formatResponse({
|
|
3940
|
+
success: true,
|
|
3941
|
+
message: "Request completed successfully. No product found.",
|
|
3942
|
+
data: null,
|
|
3943
|
+
meta: void 0
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3907
3946
|
const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
|
|
3908
3947
|
return formatResponse({
|
|
3909
3948
|
success: false,
|
|
@@ -4117,6 +4156,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4117
4156
|
});
|
|
4118
4157
|
} catch (error) {
|
|
4119
4158
|
this.logger.error("Error in getCollection", void 0, { error });
|
|
4159
|
+
if (!isUpstreamUnavailable(error)) {
|
|
4160
|
+
return formatResponse({
|
|
4161
|
+
success: true,
|
|
4162
|
+
message: "Request completed successfully. No collection found.",
|
|
4163
|
+
data: null,
|
|
4164
|
+
meta: void 0
|
|
4165
|
+
});
|
|
4166
|
+
}
|
|
4120
4167
|
const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
|
|
4121
4168
|
return formatResponse({
|
|
4122
4169
|
success: false,
|
|
@@ -4170,7 +4217,40 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4170
4217
|
PRODUCT_ENDPOINTS.getCollectionsByHandles(options?.version),
|
|
4171
4218
|
"POST",
|
|
4172
4219
|
payload,
|
|
4173
|
-
|
|
4220
|
+
{
|
|
4221
|
+
...options || {},
|
|
4222
|
+
// The same tags the single-collection `getCollection` attaches, one set
|
|
4223
|
+
// per requested handle. This is the batch form of that read, so it has to
|
|
4224
|
+
// carry the same invalidation coverage: without it, moving a template from
|
|
4225
|
+
// COLLECTION to COLLECTION_BY_HANDLES silently opts the page out of
|
|
4226
|
+
// webhook invalidation, and it stays stale until its own `revalidate`
|
|
4227
|
+
// window elapses.
|
|
4228
|
+
//
|
|
4229
|
+
// Not hypothetical: home pages render their product grids through this
|
|
4230
|
+
// read, so `revalidateTag(collection:<handle>)` from a product.updated
|
|
4231
|
+
// webhook — which did purge that product's PDP and its collection page —
|
|
4232
|
+
// matched nothing on the home page, and an edited title sat there for the
|
|
4233
|
+
// rest of the ISR window.
|
|
4234
|
+
//
|
|
4235
|
+
// Same rationale and the same deliberate omission of `revalidate` as
|
|
4236
|
+
// getProductsByHandles above. Tagging a POST works: Next records a fetch's
|
|
4237
|
+
// tags on the enclosing page's cache entry before it decides whether the
|
|
4238
|
+
// response itself is cacheable.
|
|
4239
|
+
//
|
|
4240
|
+
// The type guard mirrors getProductsByHandles — CacheTags.collection()
|
|
4241
|
+
// calls .trim() on its argument and this array is widget-supplied, so a
|
|
4242
|
+
// stray null would throw and fail the whole read, not just one tag.
|
|
4243
|
+
next: {
|
|
4244
|
+
...options?.next || {},
|
|
4245
|
+
tags: [
|
|
4246
|
+
CacheTags.collections(),
|
|
4247
|
+
...handles.filter(
|
|
4248
|
+
(h) => typeof h === "string" && h.trim() !== ""
|
|
4249
|
+
).map((h) => CacheTags.collection(h)),
|
|
4250
|
+
...options?.next?.tags || []
|
|
4251
|
+
]
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4174
4254
|
);
|
|
4175
4255
|
if (!result || !result.collections) {
|
|
4176
4256
|
return formatResponse({
|
|
@@ -4228,7 +4308,24 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4228
4308
|
PRODUCT_ENDPOINTS.getCollectionFilters(options?.version, handle),
|
|
4229
4309
|
"GET",
|
|
4230
4310
|
void 0,
|
|
4231
|
-
|
|
4311
|
+
{
|
|
4312
|
+
...options || {},
|
|
4313
|
+
// Facets are derived from this collection's products — price range, brands,
|
|
4314
|
+
// availability — so anything that invalidates the collection invalidates its
|
|
4315
|
+
// filters. One tag, keyed on the same handle, means the existing
|
|
4316
|
+
// product.updated / collection.updated purges already cover them.
|
|
4317
|
+
//
|
|
4318
|
+
// No broad `collections` tag here, unlike getCollection: a filter set belongs
|
|
4319
|
+
// to exactly one collection, and bulk collection events already purge every
|
|
4320
|
+
// affected handle individually.
|
|
4321
|
+
next: {
|
|
4322
|
+
...options?.next || {},
|
|
4323
|
+
tags: [
|
|
4324
|
+
CacheTags.collection(handle),
|
|
4325
|
+
...options?.next?.tags || []
|
|
4326
|
+
]
|
|
4327
|
+
}
|
|
4328
|
+
}
|
|
4232
4329
|
);
|
|
4233
4330
|
if (!result) {
|
|
4234
4331
|
return formatResponse({
|