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