@shopkit/data-layer 1.5.0 → 1.6.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/dist/adapters/index.js +26 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +26 -0
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.mts +11 -0
- package/dist/models/index.d.ts +11 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4387,6 +4387,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4387
4387
|
async queryCollections(params, options) {
|
|
4388
4388
|
try {
|
|
4389
4389
|
const payload = buildCollectionsQueryPayload(params);
|
|
4390
|
+
if (selectedHandles(params)?.length === 0) {
|
|
4391
|
+
return formatResponse({
|
|
4392
|
+
success: true,
|
|
4393
|
+
message: "No collections selected.",
|
|
4394
|
+
data: [],
|
|
4395
|
+
meta: { pagination: { limit: 0, skip: 0, has_more: false, total: 0, next_cursor: null } }
|
|
4396
|
+
});
|
|
4397
|
+
}
|
|
4390
4398
|
const handles = handlesNamedBy(payload.filter);
|
|
4391
4399
|
const result = await this.request(
|
|
4392
4400
|
PRODUCT_ENDPOINTS.queryCollections(options?.version),
|
|
@@ -4480,12 +4488,30 @@ function buildCollectionsQueryPayload(params) {
|
|
|
4480
4488
|
if (source[key] !== void 0) payload[key] = source[key];
|
|
4481
4489
|
}
|
|
4482
4490
|
const filter = payload.filter && typeof payload.filter === "object" ? payload.filter : {};
|
|
4491
|
+
const handles = selectedHandles(params);
|
|
4492
|
+
if (handles) {
|
|
4493
|
+
payload.filter = { ...filter, handle: { $in: handles } };
|
|
4494
|
+
if (typeof payload.limit === "number" && payload.limit < handles.length) {
|
|
4495
|
+
payload.limit = handles.length;
|
|
4496
|
+
}
|
|
4497
|
+
return payload;
|
|
4498
|
+
}
|
|
4483
4499
|
const routeHandle = source.useRouteHandle === true ? source.handle : void 0;
|
|
4484
4500
|
if (typeof routeHandle === "string" && routeHandle.trim() !== "" && filter.handle === void 0) {
|
|
4485
4501
|
payload.filter = { ...filter, handle: routeHandle };
|
|
4486
4502
|
}
|
|
4487
4503
|
return payload;
|
|
4488
4504
|
}
|
|
4505
|
+
var MAX_COLLECTIONS_PER_QUERY = 10;
|
|
4506
|
+
function selectedHandles(params) {
|
|
4507
|
+
const source = params || {};
|
|
4508
|
+
if (!Array.isArray(source.handles)) return void 0;
|
|
4509
|
+
const filter = source.filter;
|
|
4510
|
+
if (filter && typeof filter === "object" && filter.handle !== void 0) {
|
|
4511
|
+
return void 0;
|
|
4512
|
+
}
|
|
4513
|
+
return source.handles.filter((h) => typeof h === "string").map((h) => h.trim()).filter((h) => h !== "").slice(0, MAX_COLLECTIONS_PER_QUERY);
|
|
4514
|
+
}
|
|
4489
4515
|
function handlesNamedBy(filter) {
|
|
4490
4516
|
const handle = filter?.handle;
|
|
4491
4517
|
const candidates = typeof handle === "string" ? [handle] : handle && typeof handle === "object" ? [
|