@shopkit/data-layer 1.5.0 → 1.7.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.
- package/README.md +31 -0
- package/dist/adapters/index.js +27 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +27 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +53 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -2
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.mts +15 -4
- package/dist/models/index.d.ts +15 -4
- package/dist/static-params/index.js +7 -0
- package/dist/static-params/index.js.map +1 -1
- package/dist/static-params/index.mjs +7 -0
- package/dist/static-params/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/adapters/index.mjs
CHANGED
|
@@ -160,7 +160,7 @@ function createDomainLogger(domain, adapter, config = {}) {
|
|
|
160
160
|
function isUpstreamUnavailable(error) {
|
|
161
161
|
const status = error?.status;
|
|
162
162
|
if (typeof status !== "number") return true;
|
|
163
|
-
return status >= 500;
|
|
163
|
+
return status >= 500 || status === 429;
|
|
164
164
|
}
|
|
165
165
|
function formatResponse(params) {
|
|
166
166
|
const { success, message, data = null, error = null, meta = {} } = params;
|
|
@@ -4390,6 +4390,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4390
4390
|
async queryCollections(params, options) {
|
|
4391
4391
|
try {
|
|
4392
4392
|
const payload = buildCollectionsQueryPayload(params);
|
|
4393
|
+
if (selectedHandles(params)?.length === 0) {
|
|
4394
|
+
return formatResponse({
|
|
4395
|
+
success: true,
|
|
4396
|
+
message: "No collections selected.",
|
|
4397
|
+
data: [],
|
|
4398
|
+
meta: { pagination: { limit: 0, skip: 0, has_more: false, total: 0, next_cursor: null } }
|
|
4399
|
+
});
|
|
4400
|
+
}
|
|
4393
4401
|
const handles = handlesNamedBy(payload.filter);
|
|
4394
4402
|
const result = await this.request(
|
|
4395
4403
|
PRODUCT_ENDPOINTS.queryCollections(options?.version),
|
|
@@ -4483,12 +4491,30 @@ function buildCollectionsQueryPayload(params) {
|
|
|
4483
4491
|
if (source[key] !== void 0) payload[key] = source[key];
|
|
4484
4492
|
}
|
|
4485
4493
|
const filter = payload.filter && typeof payload.filter === "object" ? payload.filter : {};
|
|
4494
|
+
const handles = selectedHandles(params);
|
|
4495
|
+
if (handles) {
|
|
4496
|
+
payload.filter = { ...filter, handle: { $in: handles } };
|
|
4497
|
+
if (typeof payload.limit === "number" && payload.limit < handles.length) {
|
|
4498
|
+
payload.limit = handles.length;
|
|
4499
|
+
}
|
|
4500
|
+
return payload;
|
|
4501
|
+
}
|
|
4486
4502
|
const routeHandle = source.useRouteHandle === true ? source.handle : void 0;
|
|
4487
4503
|
if (typeof routeHandle === "string" && routeHandle.trim() !== "" && filter.handle === void 0) {
|
|
4488
4504
|
payload.filter = { ...filter, handle: routeHandle };
|
|
4489
4505
|
}
|
|
4490
4506
|
return payload;
|
|
4491
4507
|
}
|
|
4508
|
+
var MAX_COLLECTIONS_PER_QUERY = 10;
|
|
4509
|
+
function selectedHandles(params) {
|
|
4510
|
+
const source = params || {};
|
|
4511
|
+
if (!Array.isArray(source.handles)) return void 0;
|
|
4512
|
+
const filter = source.filter;
|
|
4513
|
+
if (filter && typeof filter === "object" && filter.handle !== void 0) {
|
|
4514
|
+
return void 0;
|
|
4515
|
+
}
|
|
4516
|
+
return source.handles.filter((h) => typeof h === "string").map((h) => h.trim()).filter((h) => h !== "").slice(0, MAX_COLLECTIONS_PER_QUERY);
|
|
4517
|
+
}
|
|
4492
4518
|
function handlesNamedBy(filter) {
|
|
4493
4519
|
const handle = filter?.handle;
|
|
4494
4520
|
const candidates = typeof handle === "string" ? [handle] : handle && typeof handle === "object" ? [
|