@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/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as ICommerceClient } from './interface-
|
|
2
|
-
import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-
|
|
3
|
-
export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest } from './models/index.mjs';
|
|
1
|
+
import { I as ICommerceClient } from './interface-CgPiwpPe.mjs';
|
|
2
|
+
import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-BPzeuSLS.mjs';
|
|
3
|
+
export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IQueryCollectionsInclude, IQueryCollectionsRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest, QueryCollectionsErrorCode, QuerySortDirection } from './models/index.mjs';
|
|
4
4
|
export { createCollectionProductStaticParams, createCollectionStaticParams, createProductStaticParams, createProductViaCollectionsStaticParams } from './static-params/index.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as ICommerceClient } from './interface-
|
|
2
|
-
import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-
|
|
3
|
-
export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest } from './models/index.js';
|
|
1
|
+
import { I as ICommerceClient } from './interface-BGV7d5F8.js';
|
|
2
|
+
import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-Cb074q9F.js';
|
|
3
|
+
export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IQueryCollectionsInclude, IQueryCollectionsRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest, QueryCollectionsErrorCode, QuerySortDirection } from './models/index.js';
|
|
4
4
|
export { createCollectionProductStaticParams, createCollectionStaticParams, createProductStaticParams, createProductViaCollectionsStaticParams } from './static-params/index.js';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/index.js
CHANGED
|
@@ -298,6 +298,16 @@ var BaseCommerceClient = class {
|
|
|
298
298
|
getCollectionFilters(params, options) {
|
|
299
299
|
this.throwNotImplemented("getCollectionFilters");
|
|
300
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Read a page of collections, with their products and variants, from one query document
|
|
303
|
+
* @param params - Query document (filter, fields, include, sort, paging)
|
|
304
|
+
* @param options - Request options (headers, timeout, etc.)
|
|
305
|
+
* @returns Promise resolving to collections, with paging in meta.pagination
|
|
306
|
+
* @throws NotImplementedError if not implemented in adapter
|
|
307
|
+
*/
|
|
308
|
+
queryCollections(params, options) {
|
|
309
|
+
this.throwNotImplemented("queryCollections");
|
|
310
|
+
}
|
|
301
311
|
// ========================================
|
|
302
312
|
// ORDER OPERATIONS
|
|
303
313
|
// ========================================
|
|
@@ -3732,6 +3742,11 @@ var BaseCustomService = class {
|
|
|
3732
3742
|
`Request failed: ${response.status} ${response.statusText}`
|
|
3733
3743
|
);
|
|
3734
3744
|
error.status = response.status;
|
|
3745
|
+
try {
|
|
3746
|
+
error.body = await response.json();
|
|
3747
|
+
} catch {
|
|
3748
|
+
error.body = void 0;
|
|
3749
|
+
}
|
|
3735
3750
|
throw error;
|
|
3736
3751
|
}
|
|
3737
3752
|
this.logger.info("API request successful", {
|
|
@@ -3772,6 +3787,9 @@ function mapGetCollectionsByHandelsResponse(response) {
|
|
|
3772
3787
|
function mapGetCollectionFiltersResponse(response) {
|
|
3773
3788
|
return response;
|
|
3774
3789
|
}
|
|
3790
|
+
function mapQueryCollectionsResponse(response) {
|
|
3791
|
+
return response?.collections || [];
|
|
3792
|
+
}
|
|
3775
3793
|
|
|
3776
3794
|
// src/adapters/custom/product/urls.ts
|
|
3777
3795
|
var DEFAULT_VERSION = "v1";
|
|
@@ -3783,7 +3801,8 @@ var PRODUCT_ENDPOINTS = {
|
|
|
3783
3801
|
getCollectionByHandle: (v = DEFAULT_VERSION, h) => `/api/${v}/collections/handle/${encodeURIComponent(h)}`,
|
|
3784
3802
|
getCollectionById: (v = DEFAULT_VERSION, id) => `/api/${v}/collections/${encodeURIComponent(id)}`,
|
|
3785
3803
|
getCollectionsByHandles: (v = DEFAULT_VERSION) => `/api/${v}/collections/details`,
|
|
3786
|
-
getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${encodeURIComponent(collectionHandle)}/filters
|
|
3804
|
+
getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${encodeURIComponent(collectionHandle)}/filters`,
|
|
3805
|
+
queryCollections: (v = DEFAULT_VERSION) => `/api/${v}/collections/query`
|
|
3787
3806
|
};
|
|
3788
3807
|
|
|
3789
3808
|
// src/adapters/custom/product/service.ts
|
|
@@ -4360,7 +4379,149 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4360
4379
|
});
|
|
4361
4380
|
}
|
|
4362
4381
|
}
|
|
4382
|
+
/**
|
|
4383
|
+
* Read a page of collections, with their products and variants, from one
|
|
4384
|
+
* query document. A POST because the document is too nested for a URL; it is
|
|
4385
|
+
* still a read and answers 200.
|
|
4386
|
+
*/
|
|
4387
|
+
async queryCollections(params, options) {
|
|
4388
|
+
try {
|
|
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
|
+
}
|
|
4398
|
+
const handles = handlesNamedBy(payload.filter);
|
|
4399
|
+
const result = await this.request(
|
|
4400
|
+
PRODUCT_ENDPOINTS.queryCollections(options?.version),
|
|
4401
|
+
"POST",
|
|
4402
|
+
payload,
|
|
4403
|
+
{
|
|
4404
|
+
...options || {},
|
|
4405
|
+
// Same coverage as the other collection reads: the broad tag for
|
|
4406
|
+
// catalog-wide purges, plus one per handle the filter names, so a
|
|
4407
|
+
// collection.updated / product.updated webhook reaches every page built
|
|
4408
|
+
// from this read. A filter that names no handle (published: true, a
|
|
4409
|
+
// $like, ...) cannot know its result set in advance — broad tag only.
|
|
4410
|
+
// No `revalidate`, as with getCollectionsByHandles.
|
|
4411
|
+
next: {
|
|
4412
|
+
...options?.next || {},
|
|
4413
|
+
tags: [
|
|
4414
|
+
cacheTags.CacheTags.collections(),
|
|
4415
|
+
...handles.map((h) => cacheTags.CacheTags.collection(h)),
|
|
4416
|
+
...options?.next?.tags || []
|
|
4417
|
+
]
|
|
4418
|
+
}
|
|
4419
|
+
}
|
|
4420
|
+
);
|
|
4421
|
+
const errors = Array.isArray(result?.errors) ? result.errors : [];
|
|
4422
|
+
if (!result?.data) {
|
|
4423
|
+
return formatResponse({
|
|
4424
|
+
success: false,
|
|
4425
|
+
message: "Collections query returned no data.",
|
|
4426
|
+
error: {
|
|
4427
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
4428
|
+
message: "No data in collections query response."
|
|
4429
|
+
},
|
|
4430
|
+
meta: { requestId: result?.request_id }
|
|
4431
|
+
});
|
|
4432
|
+
}
|
|
4433
|
+
return formatResponse({
|
|
4434
|
+
success: true,
|
|
4435
|
+
message: "Collections retrieved successfully.",
|
|
4436
|
+
data: mapQueryCollectionsResponse(result.data),
|
|
4437
|
+
meta: {
|
|
4438
|
+
pagination: result.data.paging,
|
|
4439
|
+
requestId: result.request_id,
|
|
4440
|
+
...errors.length > 0 ? { errors } : {}
|
|
4441
|
+
}
|
|
4442
|
+
});
|
|
4443
|
+
} catch (error) {
|
|
4444
|
+
this.logger.error("Error in queryCollections", void 0, { error });
|
|
4445
|
+
const body = error?.body;
|
|
4446
|
+
if (isUpstreamUnavailable(error)) {
|
|
4447
|
+
return formatResponse({
|
|
4448
|
+
success: false,
|
|
4449
|
+
message: "An error occurred while processing the request.",
|
|
4450
|
+
error: {
|
|
4451
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
4452
|
+
message: typeof error?.status === "number" ? `Request failed: ${error.status}` : "Collections query did not complete."
|
|
4453
|
+
},
|
|
4454
|
+
meta: { requestId: body?.request_id }
|
|
4455
|
+
});
|
|
4456
|
+
}
|
|
4457
|
+
const upstreamErrors = Array.isArray(body?.errors) ? body.errors : [];
|
|
4458
|
+
return formatResponse({
|
|
4459
|
+
success: false,
|
|
4460
|
+
message: "The collections query was rejected.",
|
|
4461
|
+
error: {
|
|
4462
|
+
code: "QUERY_REJECTED",
|
|
4463
|
+
message: upstreamErrors[0]?.message || error.message,
|
|
4464
|
+
details: upstreamErrors
|
|
4465
|
+
},
|
|
4466
|
+
meta: { requestId: body?.request_id }
|
|
4467
|
+
});
|
|
4468
|
+
}
|
|
4469
|
+
}
|
|
4363
4470
|
};
|
|
4471
|
+
var COLLECTIONS_QUERY_KEYS = [
|
|
4472
|
+
"filter",
|
|
4473
|
+
"fields",
|
|
4474
|
+
"include",
|
|
4475
|
+
"sort",
|
|
4476
|
+
"limit",
|
|
4477
|
+
"skip",
|
|
4478
|
+
"after",
|
|
4479
|
+
"count",
|
|
4480
|
+
"metafields",
|
|
4481
|
+
"availability",
|
|
4482
|
+
"ratings"
|
|
4483
|
+
];
|
|
4484
|
+
function buildCollectionsQueryPayload(params) {
|
|
4485
|
+
const source = params || {};
|
|
4486
|
+
const payload = {};
|
|
4487
|
+
for (const key of COLLECTIONS_QUERY_KEYS) {
|
|
4488
|
+
if (source[key] !== void 0) payload[key] = source[key];
|
|
4489
|
+
}
|
|
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
|
+
}
|
|
4499
|
+
const routeHandle = source.useRouteHandle === true ? source.handle : void 0;
|
|
4500
|
+
if (typeof routeHandle === "string" && routeHandle.trim() !== "" && filter.handle === void 0) {
|
|
4501
|
+
payload.filter = { ...filter, handle: routeHandle };
|
|
4502
|
+
}
|
|
4503
|
+
return payload;
|
|
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
|
+
}
|
|
4515
|
+
function handlesNamedBy(filter) {
|
|
4516
|
+
const handle = filter?.handle;
|
|
4517
|
+
const candidates = typeof handle === "string" ? [handle] : handle && typeof handle === "object" ? [
|
|
4518
|
+
handle.$eq,
|
|
4519
|
+
...Array.isArray(handle.$in) ? handle.$in : []
|
|
4520
|
+
] : [];
|
|
4521
|
+
return candidates.filter(
|
|
4522
|
+
(h) => typeof h === "string" && h.trim() !== ""
|
|
4523
|
+
);
|
|
4524
|
+
}
|
|
4364
4525
|
|
|
4365
4526
|
// src/adapters/custom/order/urls.ts
|
|
4366
4527
|
var DEFAULT_VERSION2 = "v1";
|
|
@@ -4942,6 +5103,12 @@ var CustomBackendClient = class extends BaseCommerceClient {
|
|
|
4942
5103
|
filterRestOptions(options)
|
|
4943
5104
|
);
|
|
4944
5105
|
}
|
|
5106
|
+
async queryCollections(params, options) {
|
|
5107
|
+
return this.productService.queryCollections(
|
|
5108
|
+
params,
|
|
5109
|
+
filterRestOptions(options)
|
|
5110
|
+
);
|
|
5111
|
+
}
|
|
4945
5112
|
// ========================================
|
|
4946
5113
|
// CART OPERATIONS
|
|
4947
5114
|
// ========================================
|