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