@shopkit/data-layer 1.4.6 → 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.d.mts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.js +168 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +168 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +168 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{interface-NJcjuqaL.d.mts → interface-BGV7d5F8.d.ts} +9 -1
- package/dist/{interface-dqoKc63z.d.ts → interface-CgPiwpPe.d.mts} +9 -1
- package/dist/models/index.d.mts +108 -1
- package/dist/models/index.d.ts +108 -1
- package/dist/{service-BHCLUEim.d.ts → service-BPzeuSLS.d.mts} +11 -2
- package/dist/{service-DBKEK2oS.d.mts → service-Cb074q9F.d.ts} +11 -2
- package/dist/static-params/index.d.mts +1 -1
- package/dist/static-params/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/adapters/index.mjs
CHANGED
|
@@ -296,6 +296,16 @@ var BaseCommerceClient = class {
|
|
|
296
296
|
getCollectionFilters(params, options) {
|
|
297
297
|
this.throwNotImplemented("getCollectionFilters");
|
|
298
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Read a page of collections, with their products and variants, from one query document
|
|
301
|
+
* @param params - Query document (filter, fields, include, sort, paging)
|
|
302
|
+
* @param options - Request options (headers, timeout, etc.)
|
|
303
|
+
* @returns Promise resolving to collections, with paging in meta.pagination
|
|
304
|
+
* @throws NotImplementedError if not implemented in adapter
|
|
305
|
+
*/
|
|
306
|
+
queryCollections(params, options) {
|
|
307
|
+
this.throwNotImplemented("queryCollections");
|
|
308
|
+
}
|
|
299
309
|
// ========================================
|
|
300
310
|
// ORDER OPERATIONS
|
|
301
311
|
// ========================================
|
|
@@ -3735,6 +3745,11 @@ var BaseCustomService = class {
|
|
|
3735
3745
|
`Request failed: ${response.status} ${response.statusText}`
|
|
3736
3746
|
);
|
|
3737
3747
|
error.status = response.status;
|
|
3748
|
+
try {
|
|
3749
|
+
error.body = await response.json();
|
|
3750
|
+
} catch {
|
|
3751
|
+
error.body = void 0;
|
|
3752
|
+
}
|
|
3738
3753
|
throw error;
|
|
3739
3754
|
}
|
|
3740
3755
|
this.logger.info("API request successful", {
|
|
@@ -3775,6 +3790,9 @@ function mapGetCollectionsByHandelsResponse(response) {
|
|
|
3775
3790
|
function mapGetCollectionFiltersResponse(response) {
|
|
3776
3791
|
return response;
|
|
3777
3792
|
}
|
|
3793
|
+
function mapQueryCollectionsResponse(response) {
|
|
3794
|
+
return response?.collections || [];
|
|
3795
|
+
}
|
|
3778
3796
|
|
|
3779
3797
|
// src/adapters/custom/product/urls.ts
|
|
3780
3798
|
var DEFAULT_VERSION = "v1";
|
|
@@ -3786,7 +3804,8 @@ var PRODUCT_ENDPOINTS = {
|
|
|
3786
3804
|
getCollectionByHandle: (v = DEFAULT_VERSION, h) => `/api/${v}/collections/handle/${encodeURIComponent(h)}`,
|
|
3787
3805
|
getCollectionById: (v = DEFAULT_VERSION, id) => `/api/${v}/collections/${encodeURIComponent(id)}`,
|
|
3788
3806
|
getCollectionsByHandles: (v = DEFAULT_VERSION) => `/api/${v}/collections/details`,
|
|
3789
|
-
getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${encodeURIComponent(collectionHandle)}/filters
|
|
3807
|
+
getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${encodeURIComponent(collectionHandle)}/filters`,
|
|
3808
|
+
queryCollections: (v = DEFAULT_VERSION) => `/api/${v}/collections/query`
|
|
3790
3809
|
};
|
|
3791
3810
|
|
|
3792
3811
|
// src/adapters/custom/product/service.ts
|
|
@@ -4363,7 +4382,149 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4363
4382
|
});
|
|
4364
4383
|
}
|
|
4365
4384
|
}
|
|
4385
|
+
/**
|
|
4386
|
+
* Read a page of collections, with their products and variants, from one
|
|
4387
|
+
* query document. A POST because the document is too nested for a URL; it is
|
|
4388
|
+
* still a read and answers 200.
|
|
4389
|
+
*/
|
|
4390
|
+
async queryCollections(params, options) {
|
|
4391
|
+
try {
|
|
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
|
+
}
|
|
4401
|
+
const handles = handlesNamedBy(payload.filter);
|
|
4402
|
+
const result = await this.request(
|
|
4403
|
+
PRODUCT_ENDPOINTS.queryCollections(options?.version),
|
|
4404
|
+
"POST",
|
|
4405
|
+
payload,
|
|
4406
|
+
{
|
|
4407
|
+
...options || {},
|
|
4408
|
+
// Same coverage as the other collection reads: the broad tag for
|
|
4409
|
+
// catalog-wide purges, plus one per handle the filter names, so a
|
|
4410
|
+
// collection.updated / product.updated webhook reaches every page built
|
|
4411
|
+
// from this read. A filter that names no handle (published: true, a
|
|
4412
|
+
// $like, ...) cannot know its result set in advance — broad tag only.
|
|
4413
|
+
// No `revalidate`, as with getCollectionsByHandles.
|
|
4414
|
+
next: {
|
|
4415
|
+
...options?.next || {},
|
|
4416
|
+
tags: [
|
|
4417
|
+
CacheTags.collections(),
|
|
4418
|
+
...handles.map((h) => CacheTags.collection(h)),
|
|
4419
|
+
...options?.next?.tags || []
|
|
4420
|
+
]
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
);
|
|
4424
|
+
const errors = Array.isArray(result?.errors) ? result.errors : [];
|
|
4425
|
+
if (!result?.data) {
|
|
4426
|
+
return formatResponse({
|
|
4427
|
+
success: false,
|
|
4428
|
+
message: "Collections query returned no data.",
|
|
4429
|
+
error: {
|
|
4430
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
4431
|
+
message: "No data in collections query response."
|
|
4432
|
+
},
|
|
4433
|
+
meta: { requestId: result?.request_id }
|
|
4434
|
+
});
|
|
4435
|
+
}
|
|
4436
|
+
return formatResponse({
|
|
4437
|
+
success: true,
|
|
4438
|
+
message: "Collections retrieved successfully.",
|
|
4439
|
+
data: mapQueryCollectionsResponse(result.data),
|
|
4440
|
+
meta: {
|
|
4441
|
+
pagination: result.data.paging,
|
|
4442
|
+
requestId: result.request_id,
|
|
4443
|
+
...errors.length > 0 ? { errors } : {}
|
|
4444
|
+
}
|
|
4445
|
+
});
|
|
4446
|
+
} catch (error) {
|
|
4447
|
+
this.logger.error("Error in queryCollections", void 0, { error });
|
|
4448
|
+
const body = error?.body;
|
|
4449
|
+
if (isUpstreamUnavailable(error)) {
|
|
4450
|
+
return formatResponse({
|
|
4451
|
+
success: false,
|
|
4452
|
+
message: "An error occurred while processing the request.",
|
|
4453
|
+
error: {
|
|
4454
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
4455
|
+
message: typeof error?.status === "number" ? `Request failed: ${error.status}` : "Collections query did not complete."
|
|
4456
|
+
},
|
|
4457
|
+
meta: { requestId: body?.request_id }
|
|
4458
|
+
});
|
|
4459
|
+
}
|
|
4460
|
+
const upstreamErrors = Array.isArray(body?.errors) ? body.errors : [];
|
|
4461
|
+
return formatResponse({
|
|
4462
|
+
success: false,
|
|
4463
|
+
message: "The collections query was rejected.",
|
|
4464
|
+
error: {
|
|
4465
|
+
code: "QUERY_REJECTED",
|
|
4466
|
+
message: upstreamErrors[0]?.message || error.message,
|
|
4467
|
+
details: upstreamErrors
|
|
4468
|
+
},
|
|
4469
|
+
meta: { requestId: body?.request_id }
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4366
4473
|
};
|
|
4474
|
+
var COLLECTIONS_QUERY_KEYS = [
|
|
4475
|
+
"filter",
|
|
4476
|
+
"fields",
|
|
4477
|
+
"include",
|
|
4478
|
+
"sort",
|
|
4479
|
+
"limit",
|
|
4480
|
+
"skip",
|
|
4481
|
+
"after",
|
|
4482
|
+
"count",
|
|
4483
|
+
"metafields",
|
|
4484
|
+
"availability",
|
|
4485
|
+
"ratings"
|
|
4486
|
+
];
|
|
4487
|
+
function buildCollectionsQueryPayload(params) {
|
|
4488
|
+
const source = params || {};
|
|
4489
|
+
const payload = {};
|
|
4490
|
+
for (const key of COLLECTIONS_QUERY_KEYS) {
|
|
4491
|
+
if (source[key] !== void 0) payload[key] = source[key];
|
|
4492
|
+
}
|
|
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
|
+
}
|
|
4502
|
+
const routeHandle = source.useRouteHandle === true ? source.handle : void 0;
|
|
4503
|
+
if (typeof routeHandle === "string" && routeHandle.trim() !== "" && filter.handle === void 0) {
|
|
4504
|
+
payload.filter = { ...filter, handle: routeHandle };
|
|
4505
|
+
}
|
|
4506
|
+
return payload;
|
|
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
|
+
}
|
|
4518
|
+
function handlesNamedBy(filter) {
|
|
4519
|
+
const handle = filter?.handle;
|
|
4520
|
+
const candidates = typeof handle === "string" ? [handle] : handle && typeof handle === "object" ? [
|
|
4521
|
+
handle.$eq,
|
|
4522
|
+
...Array.isArray(handle.$in) ? handle.$in : []
|
|
4523
|
+
] : [];
|
|
4524
|
+
return candidates.filter(
|
|
4525
|
+
(h) => typeof h === "string" && h.trim() !== ""
|
|
4526
|
+
);
|
|
4527
|
+
}
|
|
4367
4528
|
|
|
4368
4529
|
// src/adapters/custom/order/urls.ts
|
|
4369
4530
|
var DEFAULT_VERSION2 = "v1";
|
|
@@ -4945,6 +5106,12 @@ var CustomBackendClient = class extends BaseCommerceClient {
|
|
|
4945
5106
|
filterRestOptions(options)
|
|
4946
5107
|
);
|
|
4947
5108
|
}
|
|
5109
|
+
async queryCollections(params, options) {
|
|
5110
|
+
return this.productService.queryCollections(
|
|
5111
|
+
params,
|
|
5112
|
+
filterRestOptions(options)
|
|
5113
|
+
);
|
|
5114
|
+
}
|
|
4948
5115
|
// ========================================
|
|
4949
5116
|
// CART OPERATIONS
|
|
4950
5117
|
// ========================================
|